Skip to content

Commit 033777f

Browse files
authored
chore: bump @metamask/mobile-wallet-protocol-core & @metamask/mobile-wallet-protocol-wallet-client to latest versions and absorb breaking changes (MetaMask#27215)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## Summary - Update the mobile SDKConnect integration to match the latest `mobile-wallet-protocol` APIs. - Switch connection setup to `SessionStore.create(...)` and add peer public key validation support in the mobile `KeyManager`. - Align the SDKConnect unit tests with the new async session store factory and key validation behavior. ## Test plan - [ ] Run `yarn jest app/core/SDKConnectV2/services/connection.test.ts app/core/SDKConnectV2/services/key-manager.test.ts --runInBand` - [ ] Verify SDKConnect deeplink connection flow still initializes and resumes sessions correctly - [ ] Smoke test trusted and untrusted connection flows if needed <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null MetaMask Connect not released to public officially yet ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Medium risk due to a breaking dependency upgrade in the Mobile Wallet Protocol stack and changes to connection/session-store initialization and peer key validation that could affect SDKConnect session persistence or handshake failures. > > **Overview** > Updates SDKConnectV2 to the latest `@metamask/mobile-wallet-protocol-core`/`wallet-client` versions and absorbs API breaking changes. > > `Connection.create` now initializes the session store via async `SessionStore.create(...)` (instead of `new SessionStore(...)`), with unit tests updated to mock/expect the factory call. > > Adds `KeyManager.validatePeerKey` (using `eciesjs` `PublicKey` parsing) plus new tests covering acceptance/rejection of peer public keys. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9d63dbd. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9975c8c commit 033777f

6 files changed

Lines changed: 40 additions & 28 deletions

File tree

app/core/SDKConnectV2/services/connection.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ jest.mock('@metamask/mobile-wallet-protocol-core', () => ({
2323
WebSocketTransport: {
2424
create: jest.fn(),
2525
},
26-
SessionStore: jest.fn(),
26+
SessionStore: Object.assign(jest.fn(), {
27+
create: jest.fn(),
28+
}),
2729
}));
2830
jest.mock('../store/kv-store');
2931
jest.mock('../adapters/rpc-bridge-adapter');
@@ -47,6 +49,9 @@ const MockedWalletClient = WalletClient as jest.MockedClass<
4749
const MockedWebSocketTransport = WebSocketTransport as jest.Mocked<
4850
typeof WebSocketTransport
4951
>;
52+
const MockedSessionStore = SessionStore as jest.Mocked<typeof SessionStore> & {
53+
create: jest.Mock;
54+
};
5055
const MockedRPCBridgeAdapter = RPCBridgeAdapter as jest.MockedClass<
5156
typeof RPCBridgeAdapter
5257
>;
@@ -139,6 +144,7 @@ describe('Connection', () => {
139144

140145
// eslint-disable-next-line @typescript-eslint/no-explicit-any
141146
(MockedWebSocketTransport.create as jest.Mock).mockResolvedValue({} as any);
147+
MockedSessionStore.create.mockResolvedValue({} as SessionStore);
142148
});
143149

144150
describe('create', () => {
@@ -155,7 +161,7 @@ describe('Connection', () => {
155161
kvstore: expect.any(KVStore),
156162
useSharedConnection: true,
157163
});
158-
expect(SessionStore).toHaveBeenCalledWith(expect.any(KVStore));
164+
expect(SessionStore.create).toHaveBeenCalledWith(expect.any(KVStore));
159165
expect(WalletClient).toHaveBeenCalledWith({
160166
transport: expect.anything(),
161167
sessionstore: expect.anything(),

app/core/SDKConnectV2/services/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class Connection {
180180
kvstore: new KVStore(`mwp/transport/${connInfo.id}`),
181181
useSharedConnection: true,
182182
});
183-
const sessionstore = new SessionStore(
183+
const sessionstore = await SessionStore.create(
184184
new KVStore(`mwp/session-store/${connInfo.id}`),
185185
);
186186
const client = new WalletClient({ transport, sessionstore, keymanager });

app/core/SDKConnectV2/services/key-manager.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,16 @@ describe('KeyManager', () => {
3939
// Verify the round-trip encryption/decryption
4040
expect(decryptedMessage).toBe(originalMessage);
4141
});
42+
43+
it('should accept a valid peer public key', () => {
44+
const keyPair = keyManager.generateKeyPair();
45+
46+
expect(() => keyManager.validatePeerKey(keyPair.publicKey)).not.toThrow();
47+
});
48+
49+
it('should reject an invalid peer public key', () => {
50+
const invalidKey = new Uint8Array([1, 2, 3]);
51+
52+
expect(() => keyManager.validatePeerKey(invalidKey)).toThrow();
53+
});
4254
});

app/core/SDKConnectV2/services/key-manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IKeyManager, KeyPair } from '@metamask/mobile-wallet-protocol-core';
2-
import { PrivateKey, encrypt, decrypt } from 'eciesjs';
2+
import { PrivateKey, PublicKey, encrypt, decrypt } from 'eciesjs';
33

44
export class KeyManager implements IKeyManager {
55
generateKeyPair(): KeyPair {
@@ -10,6 +10,10 @@ export class KeyManager implements IKeyManager {
1010
};
1111
}
1212

13+
validatePeerKey(key: Uint8Array): void {
14+
PublicKey.fromHex(Buffer.from(key).toString('hex'));
15+
}
16+
1317
async encrypt(
1418
plaintext: string,
1519
theirPublicKey: Uint8Array,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@
252252
"@metamask/message-signing-snap": "^1.1.2",
253253
"@metamask/messenger": "^0.3.0",
254254
"@metamask/metamask-eth-abis": "3.1.1",
255-
"@metamask/mobile-wallet-protocol-core": "^0.3.1",
256-
"@metamask/mobile-wallet-protocol-wallet-client": "^0.2.1",
255+
"@metamask/mobile-wallet-protocol-core": "^0.4.0",
256+
"@metamask/mobile-wallet-protocol-wallet-client": "^0.3.0",
257257
"@metamask/multichain-account-service": "^7.0.0",
258258
"@metamask/multichain-api-client": "^0.10.1",
259259
"@metamask/multichain-api-middleware": "1.2.5",

yarn.lock

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8987,36 +8987,26 @@ __metadata:
89878987
languageName: node
89888988
linkType: hard
89898989

8990-
"@metamask/mobile-wallet-protocol-core@npm:^0.2.0":
8991-
version: 0.2.0
8992-
resolution: "@metamask/mobile-wallet-protocol-core@npm:0.2.0"
8993-
dependencies:
8994-
centrifuge: "npm:^5.3.5"
8995-
eventemitter3: "npm:^5.0.1"
8996-
uuid: "npm:^11.1.0"
8997-
checksum: 10/55bbdf85f6231b6f11a0156e0db878ebe33bb9e8aa13445d111853d153a85c0e7e621b05a74d76e58bba6c3c0c3d8961c2dad89393af1b0ddfb2f2b9c7694f07
8998-
languageName: node
8999-
linkType: hard
9000-
9001-
"@metamask/mobile-wallet-protocol-core@npm:^0.3.1":
9002-
version: 0.3.1
9003-
resolution: "@metamask/mobile-wallet-protocol-core@npm:0.3.1"
8990+
"@metamask/mobile-wallet-protocol-core@npm:^0.4.0":
8991+
version: 0.4.0
8992+
resolution: "@metamask/mobile-wallet-protocol-core@npm:0.4.0"
90048993
dependencies:
8994+
async-mutex: "npm:^0.5.0"
90058995
centrifuge: "npm:^5.3.5"
90068996
eventemitter3: "npm:^5.0.1"
90078997
uuid: "npm:^11.1.0"
9008-
checksum: 10/2de5aab19913c31f6cfcd6dd97c8217207a511c20535fc2b44c91fdd4b553f63cb96d12bcfc248a9f1c357ddb1e29dd996752be89aa77a64229c52aba8d34625
8998+
checksum: 10/f81523ebc0c37ab548891df1a2bb65e41c13cacb6d1034f5ea63e4ef251d2783bc2d2216a3ee7542a87240be612d97dc7c4ab6105c8632818c6c9f5e77463815
90098999
languageName: node
90109000
linkType: hard
90119001

9012-
"@metamask/mobile-wallet-protocol-wallet-client@npm:^0.2.1":
9013-
version: 0.2.1
9014-
resolution: "@metamask/mobile-wallet-protocol-wallet-client@npm:0.2.1"
9002+
"@metamask/mobile-wallet-protocol-wallet-client@npm:^0.3.0":
9003+
version: 0.3.0
9004+
resolution: "@metamask/mobile-wallet-protocol-wallet-client@npm:0.3.0"
90159005
dependencies:
9016-
"@metamask/mobile-wallet-protocol-core": "npm:^0.2.0"
9006+
"@metamask/mobile-wallet-protocol-core": "npm:^0.4.0"
90179007
"@metamask/utils": "npm:^9.1.0"
90189008
uuid: "npm:^11.1.0"
9019-
checksum: 10/e3a82e7bf4673940ef433a0b16d8622a3d74cf69aa2c236c47b60f5f6e71d3da99c8ea8845a2635be592fd4ec5805d05a69bb31a2e13a00333c3ec455e18b9da
9009+
checksum: 10/0d44efb8b066517d61139eef7b047e68d92210c3db4bb9add8f51733d88aaaa2ddff3d766036f8e55361229216188772556a3c1fb46a8bdd1d8fc49a63023adf
90209010
languageName: node
90219011
linkType: hard
90229012

@@ -35466,8 +35456,8 @@ __metadata:
3546635456
"@metamask/messenger": "npm:^0.3.0"
3546735457
"@metamask/metamask-eth-abis": "npm:3.1.1"
3546835458
"@metamask/mobile-provider": "npm:^3.0.0"
35469-
"@metamask/mobile-wallet-protocol-core": "npm:^0.3.1"
35470-
"@metamask/mobile-wallet-protocol-wallet-client": "npm:^0.2.1"
35459+
"@metamask/mobile-wallet-protocol-core": "npm:^0.4.0"
35460+
"@metamask/mobile-wallet-protocol-wallet-client": "npm:^0.3.0"
3547135461
"@metamask/multichain-account-service": "npm:^7.0.0"
3547235462
"@metamask/multichain-api-client": "npm:^0.10.1"
3547335463
"@metamask/multichain-api-middleware": "npm:1.2.5"

0 commit comments

Comments
 (0)