Skip to content

Commit 0438fc4

Browse files
committed
Merge branch 'develop' into move-unit-tests-to-github-actions
2 parents e63bc82 + 56c9dc2 commit 0438fc4

File tree

71 files changed

+1508
-627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1508
-627
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
diff --git a/dist/ledger-keyring.js b/dist/ledger-keyring.js
2+
index 2386b2e7fe36d1e65ef74f0a19d3b41450dcfa48..f999a0ab465cce7a450a5812f1d7aa6e39b74aed 100644
3+
--- a/dist/ledger-keyring.js
4+
+++ b/dist/ledger-keyring.js
5+
@@ -150,7 +150,12 @@ class LedgerKeyring extends events_1.EventEmitter {
6+
});
7+
}
8+
catch (error) {
9+
- throw error instanceof Error ? error : new Error('Unknown error');
10+
+
11+
+ /**
12+
+ * For Fixing issue 22837, when ledger is locked and didnt open the ethereum app in ledger,
13+
+ * The extension will always show `unknown error`, below change will transform the error to something meaningful.
14+
+ */
15+
+ throw error instanceof Error ? error : new Error('Unlock your Ledger device and open the ETH app');
16+
}
17+
if (updateHdk && payload.chainCode) {
18+
this.hdk.publicKey = buffer_1.Buffer.from(payload.publicKey, 'hex');

app/_locales/en/messages.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
21.6 KB
Loading

app/scripts/lib/accounts/BalancesController.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const mockBtcAccount = createMockInternalAccount({
2121
name: 'Btc Account',
2222
// @ts-expect-error - account type may be btc or eth, mock file is not typed
2323
type: BtcAccountType.P2wpkh,
24+
// @ts-expect-error - snap options is not typed and defaults to undefined
2425
snapOptions: {
2526
id: 'mock-btc-snap',
2627
name: 'mock-btc-snap',

app/scripts/lib/ppom/ppom-middleware.test.ts

+48-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
JsonRpcRequestStruct,
44
JsonRpcResponseStruct,
55
} from '@metamask/utils';
6+
import * as ControllerUtils from '@metamask/controller-utils';
7+
68
import { CHAIN_IDS } from '../../../../shared/constants/network';
79

810
import {
@@ -48,8 +50,7 @@ const createMiddleware = (
4850
const preferenceController = {
4951
store: {
5052
getState: () => ({
51-
securityAlertsEnabled:
52-
securityAlertsEnabled === undefined ?? securityAlertsEnabled,
53+
securityAlertsEnabled: securityAlertsEnabled ?? true,
5354
}),
5455
},
5556
};
@@ -205,6 +206,51 @@ describe('PPOMMiddleware', () => {
205206
expect(validateRequestWithPPOM).not.toHaveBeenCalled();
206207
});
207208

209+
it('does not do validation for SIWE signature', async () => {
210+
const middlewareFunction = createMiddleware({
211+
securityAlertsEnabled: true,
212+
});
213+
214+
const req = {
215+
method: 'personal_sign',
216+
params: [
217+
'0x6d6574616d61736b2e6769746875622e696f2077616e747320796f7520746f207369676e20696e207769746820796f757220457468657265756d206163636f756e743a0a3078393335653733656462396666353265323362616337663765303433613165636430366430353437370a0a492061636365707420746865204d6574614d61736b205465726d73206f6620536572766963653a2068747470733a2f2f636f6d6d756e6974792e6d6574616d61736b2e696f2f746f730a0a5552493a2068747470733a2f2f6d6574616d61736b2e6769746875622e696f0a56657273696f6e3a20310a436861696e2049443a20310a4e6f6e63653a2033323839313735370a4973737565642041743a20323032312d30392d33305431363a32353a32342e3030305a',
218+
'0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
219+
'Example password',
220+
],
221+
jsonrpc: '2.0',
222+
id: 2974202441,
223+
origin: 'https://metamask.github.io',
224+
networkClientId: 'mainnet',
225+
tabId: 1048745900,
226+
securityAlertResponse: undefined,
227+
};
228+
jest.spyOn(ControllerUtils, 'detectSIWE').mockReturnValue({
229+
isSIWEMessage: true,
230+
parsedMessage: {
231+
address: '0x935e73edb9ff52e23bac7f7e049a1ecd06d05477',
232+
chainId: 1,
233+
domain: 'metamask.github.io',
234+
expirationTime: null,
235+
issuedAt: '2021-09-30T16:25:24.000Z',
236+
nonce: '32891757',
237+
notBefore: '2022-03-17T12:45:13.610Z',
238+
requestId: 'some_id',
239+
scheme: null,
240+
statement:
241+
'I accept the MetaMask Terms of Service: https://community.metamask.io/tos',
242+
uri: 'https://metamask.github.io',
243+
version: '1',
244+
resources: null,
245+
},
246+
});
247+
248+
await middlewareFunction(req, undefined, () => undefined);
249+
250+
expect(req.securityAlertResponse).toBeUndefined();
251+
expect(validateRequestWithPPOM).not.toHaveBeenCalled();
252+
});
253+
208254
it('calls next method', async () => {
209255
const middlewareFunction = createMiddleware();
210256
const nextMock = jest.fn();

app/scripts/lib/ppom/ppom-middleware.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
JsonRpcRequest,
77
JsonRpcResponse,
88
} from '@metamask/utils';
9+
import { detectSIWE } from '@metamask/controller-utils';
910

1011
import { SIGNING_METHODS } from '../../../../shared/constants/transaction';
1112
import { PreferencesController } from '../../controllers/preferences';
@@ -76,6 +77,11 @@ export function createPPOMMiddleware<
7677
return;
7778
}
7879

80+
const { isSIWEMessage } = detectSIWE({ data: req?.params?.[0] });
81+
if (isSIWEMessage) {
82+
return;
83+
}
84+
7985
const securityAlertId = generateSecurityAlertId();
8086

8187
validateRequestWithPPOM({

app/scripts/lib/snap-keyring/keyring-snaps-permissions.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,37 @@ describe('keyringSnapPermissionsBuilder', () => {
2525
subjectType: SubjectType.Website,
2626
});
2727

28+
describe('Portfolio origin', () => {
29+
it('returns the methods Portfolio can call', () => {
30+
const permissions = keyringSnapPermissionsBuilder(
31+
mockController,
32+
'https://portfolio.metamask.io',
33+
);
34+
expect(permissions()).toStrictEqual([
35+
KeyringRpcMethod.ListAccounts,
36+
KeyringRpcMethod.GetAccount,
37+
KeyringRpcMethod.GetAccountBalances,
38+
KeyringRpcMethod.SubmitRequest,
39+
]);
40+
});
41+
42+
it('cannot create an account', () => {
43+
const permissions = keyringSnapPermissionsBuilder(
44+
mockController,
45+
'https://portfolio.metamask.io',
46+
);
47+
expect(permissions()).not.toContain(KeyringRpcMethod.CreateAccount);
48+
});
49+
50+
it('can submit a request', () => {
51+
const permissions = keyringSnapPermissionsBuilder(
52+
mockController,
53+
'https://portfolio.metamask.io',
54+
);
55+
expect(permissions()).toContain(KeyringRpcMethod.SubmitRequest);
56+
});
57+
});
58+
2859
it('returns the methods metamask can call', () => {
2960
const permissions = keyringSnapPermissionsBuilder(
3061
mockController,

app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import {
44
} from '@metamask/permission-controller';
55
import { KeyringRpcMethod } from '@metamask/keyring-api';
66

7+
/**
8+
* The origin of the Portfolio dapp.
9+
*/
10+
const PORTFOLIO_ORIGIN = 'https://portfolio.metamask.io';
11+
712
/**
813
* List of keyring methods MetaMask can call.
914
*/
@@ -36,6 +41,16 @@ const WEBSITE_ALLOWED_METHODS: string[] = [
3641
KeyringRpcMethod.SubmitRequest,
3742
];
3843

44+
/**
45+
* List of keyring methods that Portfolio can call.
46+
*/
47+
const PORTFOLIO_ALLOWED_METHODS: string[] = [
48+
KeyringRpcMethod.ListAccounts,
49+
KeyringRpcMethod.GetAccount,
50+
KeyringRpcMethod.GetAccountBalances,
51+
KeyringRpcMethod.SubmitRequest,
52+
];
53+
3954
/**
4055
* List of allowed protocols. On Flask, HTTP is also allowed for testing.
4156
*/
@@ -79,6 +94,10 @@ export function keyringSnapPermissionsBuilder(
7994
return METAMASK_ALLOWED_METHODS;
8095
}
8196

97+
if (origin === PORTFOLIO_ORIGIN) {
98+
return PORTFOLIO_ALLOWED_METHODS;
99+
}
100+
82101
const originMetadata = controller.getSubjectMetadata(origin);
83102
if (originMetadata?.subjectType === SubjectType.Website) {
84103
return isProtocolAllowed(origin) ? WEBSITE_ALLOWED_METHODS : [];

0 commit comments

Comments
 (0)