Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): Bump @metamask/eth-json-rpc-middleware to ^14.0.0, @metamask/transaction-controller to ^35.1.1 #26143

Merged
merged 27 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
76972b0
Bump `@metamask/eth-json-rpc-middleware` from `^12.1.1` to `^14.0.0`
MajorLift Aug 14, 2024
8976cf2
Fix type error regressions
MajorLift Aug 12, 2024
9599905
Bump `@trezor/connect-web` to `9.3.0`, update patch, fix type errors …
MajorLift Aug 14, 2024
633fe35
Fix tests
MajorLift Aug 13, 2024
f72b7c4
Allow `null` in params object of snaps requests
MajorLift Aug 13, 2024
72206df
Define `PPOMMiddlewareRequest` type
MajorLift Aug 14, 2024
26f4b63
Fix failing ppom-middleware tests
MajorLift Aug 14, 2024
4e69823
Fix tests by reverting `importTime` field addition in migration 105
MajorLift Aug 14, 2024
05432ed
Make `securityAlertResponse` property of `PPOMMiddlewareRequest` both…
MajorLift Aug 14, 2024
548dde8
Rename `SecurityAlertsApiRequest` to `SecurityAlertsApiRequestBody` a…
MajorLift Aug 14, 2024
c4f4466
Fix misdefined `PPOMRequest` type
MajorLift Aug 14, 2024
dbfa9dd
minor test refactor for dry-ness
MajorLift Aug 14, 2024
5f9b683
More concise generic parameter typing for `handleSnapRequest` calls
MajorLift Aug 14, 2024
99bf3cd
Add generic constraint to `Params` generic parameter of `handleSnapRe…
MajorLift Aug 14, 2024
c91d976
Update LavaMoat policies
metamaskbot Aug 14, 2024
f09f100
Merge branch 'develop' into bump/eth-json-rpc-provider-14.0.0
MajorLift Aug 14, 2024
be27eee
Revert narrowing of `rawSnapRequestFunction` `value` parameter from `…
MajorLift Aug 14, 2024
460d7b7
Merge branch 'develop' into bump/eth-json-rpc-provider-14.0.0
MajorLift Aug 15, 2024
1433121
Update LavaMoat policies
metamaskbot Aug 15, 2024
7ddf6e7
Merge branch 'develop' into bump/eth-json-rpc-provider-14.0.0
MajorLift Aug 19, 2024
e0f9925
Revert `rawSnapRequestFunction` allowing `null` type for `name`, `val…
MajorLift Aug 19, 2024
e653cc8
Restore commit lost during rebase: "Bump `@metamask/eth-json-rpc-midd…
MajorLift Aug 19, 2024
31c95c6
Update LavaMoat policies
metamaskbot Aug 19, 2024
9a159cf
Restore `as unknown as` casting for `BitcoinWalletSnap`
MajorLift Aug 19, 2024
3c40934
Bump `@metamask/transaction-controller` from `^34.0.0` to `^35.1.1`
MajorLift Aug 20, 2024
fb5ffd3
Merge branch 'develop' into bump/eth-json-rpc-provider-14.0.0
MajorLift Aug 20, 2024
4d13778
Dedupe lockfile
MajorLift Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .yarn/patches/@trezor-connect-web-npm-9.3.0-040ab10d9a.patch
Copy link
Contributor Author

@MajorLift MajorLift Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No user-facing changes other than the version bump.

The locations of the diffs have changed because the package has been refactored, but the applied changes are the same as those in the previous patch.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/lib/impl/core-in-iframe.js b/lib/impl/core-in-iframe.js
index c47cf3bff860d6b1855341c00b80fc6c40f9d6d5..275eb0f312ff396819fa406c154a3562842db49d 100644
--- a/lib/impl/core-in-iframe.js
+++ b/lib/impl/core-in-iframe.js
@@ -116,7 +116,9 @@ class CoreInIframe {
this._log.enabled = !!this._settings.debug;
window.addEventListener('message', this.boundHandleMessage);
window.addEventListener('unload', this.boundDispose);
- await iframe.init(this._settings);
+ const modifiedSettings = Object.assign({}, this.settings);
+ modifiedSettings.env = 'webextension';
+ await iframe.init(modifiedSettings);
if (this._settings.sharedLogger !== false) {
iframe.initIframeLogger();
}
diff --git a/lib/popup/index.js b/lib/popup/index.js
index 9b13c370a5ac8b4e4fc0315ed40cdf615d0bb0cb..4dbd97fc28df49beb73379451974ec48a8a42ea7 100644
--- a/lib/popup/index.js
+++ b/lib/popup/index.js
@@ -229,10 +229,12 @@ class PopupManager extends events_1.default {
}
else if (message.type === events_2.POPUP.LOADED) {
this.handleMessage(message);
+ const modifiedSettings = Object.assign({}, this.settings);
+ modifiedSettings.env = 'webextension';
this.channel.postMessage({
type: events_2.POPUP.INIT,
payload: {
- settings: this.settings,
+ settings: modifiedSettings,
useCore: true,
},
});
25 changes: 14 additions & 11 deletions app/scripts/lib/accounts/BalancesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ export class BalancesController extends BaseController<
* @param accountId - The account ID.
*/
#getAccount(accountId: string): InternalAccount {
const account: InternalAccount = this.#listMultichainAccounts().find(
(multichainAccount) => multichainAccount.id === accountId,
);
const account: InternalAccount | undefined =
this.#listMultichainAccounts().find(
(multichainAccount) => multichainAccount.id === accountId,
);

if (!account) {
throw new Error(`Unknown account: ${accountId}`);
Expand All @@ -247,13 +248,15 @@ export class BalancesController extends BaseController<
const account = this.#getAccount(accountId);
const partialState: BalancesControllerState = { balances: {} };

partialState.balances[account.id] = await this.#getBalances(
account.id,
account.metadata.snap.id,
isBtcMainnetAddress(account.address)
? BTC_MAINNET_ASSETS
: BTC_TESTNET_ASSETS,
);
if (account.metadata.snap) {
partialState.balances[account.id] = await this.#getBalances(
account.id,
account.metadata.snap.id,
isBtcMainnetAddress(account.address)
? BTC_MAINNET_ASSETS
: BTC_TESTNET_ASSETS,
);
}

this.update((state: Draft<BalancesControllerState>) => ({
...state,
Expand Down Expand Up @@ -292,7 +295,7 @@ export class BalancesController extends BaseController<
return (
!isEvmAccountType(account.type) &&
// Non-EVM accounts are backed by a Snap for now
account.metadata.snap
account.metadata.snap !== undefined
);
}

Expand Down
27 changes: 17 additions & 10 deletions app/scripts/lib/createDupeReqFilterStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import OurReadableStream from 'readable-stream';
import ReadableStream2 from 'readable-stream-2';
import ReadableStream3 from 'readable-stream-3';

import type { JsonRpcRequest } from '@metamask/utils';
import type { JsonRpcNotification, JsonRpcRequest } from '@metamask/utils';
import createDupeReqFilterStream, {
THREE_MINUTES,
} from './createDupeReqFilterStream';
Expand All @@ -26,7 +26,7 @@ function createTestStream(output: JsonRpcRequest[] = [], S = Transform) {
}

function runStreamTest(
requests: JsonRpcRequest[] = [],
requests: (JsonRpcRequest | JsonRpcNotification)[] = [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock requests with no id property are used in this test file, which are JsonRpcNotification by definition.

advanceTimersTime = 10,
S = Transform,
) {
Expand Down Expand Up @@ -54,12 +54,12 @@ describe('createDupeReqFilterStream', () => {
const requests = [
{ id: 1, method: 'foo' },
{ id: 2, method: 'bar' },
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [
{ id: 1, method: 'foo' },
{ id: 2, method: 'bar' },
];
].map((output) => ({ ...output, jsonrpc: '2.0' }));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand All @@ -69,18 +69,25 @@ describe('createDupeReqFilterStream', () => {
const requests = [
{ id: 1, method: 'foo' },
{ id: 1, method: 'foo' }, // duplicate
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [{ id: 1, method: 'foo' }];
const expectedOutput = [{ id: 1, method: 'foo' }].map((output) => ({
...output,
jsonrpc: '2.0',
}));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
});

it("lets through requests if they don't have an id", async () => {
const requests = [{ method: 'notify1' }, { method: 'notify2' }];
const requests = [{ method: 'notify1' }, { method: 'notify2' }].map(
(request) => ({ ...request, jsonrpc: '2.0' as const }),
);

const expectedOutput = [{ method: 'notify1' }, { method: 'notify2' }];
const expectedOutput = [{ method: 'notify1' }, { method: 'notify2' }].map(
(output) => ({ ...output, jsonrpc: '2.0' }),
);

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand All @@ -95,15 +102,15 @@ describe('createDupeReqFilterStream', () => {
{ method: 'notify2' },
{ id: 2, method: 'bar' },
{ id: 3, method: 'baz' },
];
].map((request) => ({ ...request, jsonrpc: '2.0' as const }));

const expectedOutput = [
{ id: 1, method: 'foo' },
{ method: 'notify1' },
{ id: 2, method: 'bar' },
{ method: 'notify2' },
{ id: 3, method: 'baz' },
];
].map((output) => ({ ...output, jsonrpc: '2.0' }));

const output = await runStreamTest(requests);
expect(output).toEqual(expectedOutput);
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/lib/createDupeReqFilterStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function createDupeReqFilterStream() {
transform(chunk: JsonRpcRequest, _, cb) {
// JSON-RPC notifications have no ids; our only recourse is to let them through.
const hasNoId = chunk.id === undefined;
const requestNotYetSeen = seenRequestIds.add(chunk.id);
const requestNotYetSeen =
chunk.id !== null && seenRequestIds.add(chunk.id);

if (hasNoId || requestNotYetSeen) {
cb(null, chunk);
Expand Down
54 changes: 29 additions & 25 deletions app/scripts/lib/ppom/ppom-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
type Hex,
JsonRpcRequestStruct,
JsonRpcResponseStruct,
} from '@metamask/utils';
import { type Hex, JsonRpcResponseStruct } from '@metamask/utils';
import * as ControllerUtils from '@metamask/controller-utils';

import { CHAIN_IDS } from '../../../../shared/constants/network';
Expand All @@ -12,7 +8,7 @@ import {
BlockaidResultType,
} from '../../../../shared/constants/security-provider';
import { flushPromises } from '../../../../test/lib/timer-helpers';
import { createPPOMMiddleware } from './ppom-middleware';
import { createPPOMMiddleware, PPOMMiddlewareRequest } from './ppom-middleware';
import {
generateSecurityAlertId,
handlePPOMError,
Expand All @@ -32,6 +28,12 @@ const SECURITY_ALERT_RESPONSE_MOCK: SecurityAlertResponse = {
reason: BlockaidReason.permitFarming,
};

const REQUEST_MOCK = {
params: [],
id: '',
jsonrpc: '2.0' as const,
};

const createMiddleware = (
options: {
chainId?: Hex;
Expand Down Expand Up @@ -117,14 +119,14 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -141,20 +143,20 @@ describe('PPOMMiddleware', () => {
it('adds loading response to confirmation requests while validation is in progress', async () => {
const middlewareFunction = createMiddleware();

const req = {
...JsonRpcRequestStruct,
const req: PPOMMiddlewareRequest<(string | { to: string })[]> = {
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

expect(req.securityAlertResponse.reason).toBe(BlockaidReason.inProgress);
expect(req.securityAlertResponse.result_type).toBe(
expect(req.securityAlertResponse?.reason).toBe(BlockaidReason.inProgress);
expect(req.securityAlertResponse?.result_type).toBe(
BlockaidResultType.Loading,
);
});
Expand All @@ -165,11 +167,12 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

// @ts-expect-error Passing in invalid input for testing purposes
await middlewareFunction(req, undefined, () => undefined);

expect(req.securityAlertResponse).toBeUndefined();
Expand All @@ -183,14 +186,14 @@ describe('PPOMMiddleware', () => {
});

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -202,14 +205,14 @@ describe('PPOMMiddleware', () => {
const middlewareFunction = createMiddleware();

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_someRequest',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -221,15 +224,15 @@ describe('PPOMMiddleware', () => {
const middlewareFunction = createMiddleware();

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
params: [{ to: INTERNAL_ACCOUNT_ADDRESS }],
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(
req,
{ ...JsonRpcResponseStruct },
{ ...JsonRpcResponseStruct.TYPE },
() => undefined,
);

Expand All @@ -249,7 +252,7 @@ describe('PPOMMiddleware', () => {
'0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
'Example password',
],
jsonrpc: '2.0',
jsonrpc: '2.0' as const,
id: 2974202441,
origin: 'https://metamask.github.io',
networkClientId: 'mainnet',
Expand All @@ -276,6 +279,7 @@ describe('PPOMMiddleware', () => {
},
});

// @ts-expect-error Passing invalid input for testing purposes
await middlewareFunction(req, undefined, () => undefined);

expect(req.securityAlertResponse).toBeUndefined();
Expand All @@ -287,8 +291,8 @@ describe('PPOMMiddleware', () => {
const nextMock = jest.fn();

await middlewareFunction(
{ ...JsonRpcRequestStruct, method: 'eth_sendTransaction' },
{ ...JsonRpcResponseStruct },
{ ...REQUEST_MOCK, method: 'eth_sendTransaction' },
{ ...JsonRpcResponseStruct.TYPE },
nextMock,
);

Expand All @@ -304,12 +308,12 @@ describe('PPOMMiddleware', () => {
const middlewareFunction = createMiddleware({ error });

const req = {
...JsonRpcRequestStruct,
...REQUEST_MOCK,
method: 'eth_sendTransaction',
securityAlertResponse: undefined,
};

await middlewareFunction(req, { ...JsonRpcResponseStruct }, nextMock);
await middlewareFunction(req, { ...JsonRpcResponseStruct.TYPE }, nextMock);

expect(req.securityAlertResponse).toStrictEqual(
SECURITY_ALERT_RESPONSE_MOCK,
Expand Down
Loading