Skip to content

Commit f262f7c

Browse files
authored
chore: pin eciesjs to 0.4.17, remove dead ECIES.ts (#26626)
## **Description** Upgrades eciesjs from `^0.3.15` (resolved 0.3.21, native C addon) to exact pin `0.4.17` (pure-JS `@noble/*` libraries). This aligns metamask-mobile with the connect-monorepo and mobile-wallet-protocol repos, which are already on eciesjs 0.4.x. **Why:** The version split between mobile (0.3.x) and the dApp side (0.4.x) risked silent decryption failures in cross-platform relay communication. The wire format is identical between versions, so this is a safe upgrade. **Changes:** - **package.json**: Pin eciesjs to exact `0.4.17` (no caret). Remove two `lavamoat.allowScripts` entries for `eciesjs>secp256k1` (0.4.x has no native dependencies). - **key-manager.ts**: Update API calls: `.compressed` -> `.toBytes(true)`, remove unnecessary `Buffer.from()` wrapping on inputs, add `Buffer.from()` wrapping on return values for type safety. - **ECIES.ts**: Deleted. This file was dead code - nothing in the codebase imported it. The V1 SDK Connect path uses the ECIES class bundled inside the `@metamask/sdk-communication-layer`. Part of a cross-repo eciesjs version alignment effort (companion PRs in [connect-monorepo](https://github.com/MetaMask/connect-monorepo) and [mobile-wallet-protocol](https://github.com/MetaMask/mobile-wallet-protocol)). ## **Changelog** CHANGELOG entry: null ## **Related issues** Refs: WAPI-1131 ## **Manual testing steps** No manual steps ## **Screenshots/Recordings** No UI changes. https://github.com/user-attachments/assets/a5c73bd9-3d90-4780-84a3-acfbeed0cc85 ## **Pre-merge author checklist** - [x] 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). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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 because it upgrades and rewires ECIES encryption key handling (a compatibility- and data-path-sensitive area) and adds custom Metro resolution for cipher subpaths that could affect bundling/runtime on React Native. > > **Overview** > Pins `eciesjs` to `0.4.17` (bringing in `@noble/*` + `@ecies/ciphers`) and updates `yarn.lock`/`lavamoat` entries to reflect removal of the prior native `secp256k1` dependency. > > Updates `SDKConnectV2` `KeyManager` to use the new `eciesjs` key/public-key byte APIs and to pass `Uint8Array` keys directly to `encrypt`/`decrypt`, with explicit `Buffer.from(...)` wrapping on outputs for consistent base64/utf8 conversions. > > Deletes the unused legacy `ECIES.ts` implementation, and adds Metro `resolveRequest` overrides to map `@ecies/ciphers` export subpaths (`@ecies/ciphers/aes`, `@ecies/ciphers/chacha`) to RN-friendly bundle targets. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8e07b1c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5afb352 commit f262f7c

5 files changed

Lines changed: 49 additions & 177 deletions

File tree

app/core/SDKConnect/ECIES/ECIES.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export class KeyManager implements IKeyManager {
55
generateKeyPair(): KeyPair {
66
const privateKey = new PrivateKey();
77
return {
8-
privateKey: Uint8Array.from(privateKey.secret),
9-
publicKey: Uint8Array.from(privateKey.publicKey.compressed),
8+
privateKey: new Uint8Array(privateKey.secret),
9+
publicKey: privateKey.publicKey.toBytes(true),
1010
};
1111
}
1212

@@ -15,18 +15,16 @@ export class KeyManager implements IKeyManager {
1515
theirPublicKey: Uint8Array,
1616
): Promise<string> {
1717
const plaintextBuffer = Buffer.from(plaintext, 'utf8');
18-
const theirPublicKeyBuffer = Buffer.from(theirPublicKey);
19-
const encryptedBuffer = encrypt(theirPublicKeyBuffer, plaintextBuffer);
20-
return encryptedBuffer.toString('base64');
18+
const encryptedBuffer = encrypt(theirPublicKey, plaintextBuffer);
19+
return Buffer.from(encryptedBuffer).toString('base64');
2120
}
2221

2322
async decrypt(
2423
encryptedB64: string,
2524
myPrivateKey: Uint8Array,
2625
): Promise<string> {
2726
const encryptedBuffer = Buffer.from(encryptedB64, 'base64');
28-
const myPrivateKeyBuffer = Buffer.from(myPrivateKey);
29-
const decryptedBuffer = decrypt(myPrivateKeyBuffer, encryptedBuffer);
30-
return decryptedBuffer.toString('utf8');
27+
const decryptedBuffer = decrypt(myPrivateKey, encryptedBuffer);
28+
return Buffer.from(decryptedBuffer).toString('utf8');
3129
}
3230
}

metro.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ module.exports = function (baseConfig) {
9898
'node:buffer': '@craftzdog/react-native-buffer',
9999
},
100100
resolveRequest: (context, moduleName, platform) => {
101+
// @ecies/ciphers uses package.json "exports" subpaths that Metro
102+
// can't resolve without unstable_enablePackageExports. Map them to
103+
// the react-native condition targets manually.
104+
// Note: require.resolve can't be used here because the package's
105+
// "exports" field blocks direct dist/ access.
106+
if (moduleName === '@ecies/ciphers/aes') {
107+
return {
108+
filePath: path.resolve(
109+
__dirname,
110+
'node_modules/@ecies/ciphers/dist/aes/noble.js',
111+
),
112+
type: 'sourceFile',
113+
};
114+
}
115+
if (moduleName === '@ecies/ciphers/chacha') {
116+
return {
117+
filePath: path.resolve(
118+
__dirname,
119+
'node_modules/@ecies/ciphers/dist/chacha/noble.js',
120+
),
121+
type: 'sourceFile',
122+
};
123+
}
101124
// Use axios browser build so Node-only deps (e.g. http2) are never pulled in
102125
if (
103126
moduleName === 'axios' ||

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
"cross-spawn": "7.0.6",
364364
"d3-shape": "^3.2.0",
365365
"dayjs": "^1.11.13",
366-
"eciesjs": "^0.3.15",
366+
"eciesjs": "0.4.17",
367367
"eth-ens-namehash": "2.0.8",
368368
"eth-url-parser": "1.0.4",
369369
"ethereumjs-abi": "^0.6.8",
@@ -683,7 +683,6 @@
683683
"chromedriver": false,
684684
"detox": true,
685685
"detox>bunyan>dtrace-provider": false,
686-
"eciesjs>secp256k1": true,
687686
"ethereumjs-util>keccak": true,
688687
"ethereumjs-util>secp256k1": true,
689688
"ganache>@trufflesuite/bigint-buffer": false,
@@ -700,7 +699,6 @@
700699
"@metamask/sdk-communication-layer>utf-8-validate": false,
701700
"detox>ws>bufferutil": false,
702701
"@metamask/notification-services-controller>firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false,
703-
"@metamask/sdk-communication-layer>eciesjs>secp256k1": false,
704702
"detox>ws>utf-8-validate": false,
705703
"ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false,
706704
"@react-native-firebase/app>firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false,

yarn.lock

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,15 @@ __metadata:
22702270
languageName: node
22712271
linkType: hard
22722272

2273+
"@ecies/ciphers@npm:^0.2.5":
2274+
version: 0.2.5
2275+
resolution: "@ecies/ciphers@npm:0.2.5"
2276+
peerDependencies:
2277+
"@noble/ciphers": ^1.0.0
2278+
checksum: 10/af90636ee51812c9ead6e2c4be006f334bd6e12c5840de9c673b974b1ff3f79776747059257da3cb1731fcbc2d435a67b86dfb18fa90e07a6962c8816e6ab596
2279+
languageName: node
2280+
linkType: hard
2281+
22732282
"@egjs/hammerjs@npm:^2.0.17":
22742283
version: 2.0.17
22752284
resolution: "@egjs/hammerjs@npm:2.0.17"
@@ -10447,7 +10456,7 @@ __metadata:
1044710456
languageName: node
1044810457
linkType: hard
1044910458

10450-
"@noble/curves@npm:1.9.7, @noble/curves@npm:^1.0.0, @noble/curves@npm:^1.2.0, @noble/curves@npm:^1.4.2, @noble/curves@npm:^1.8.0, @noble/curves@npm:^1.8.1, @noble/curves@npm:^1.9.1, @noble/curves@npm:^1.9.2, @noble/curves@npm:~1.9.0":
10459+
"@noble/curves@npm:1.9.7, @noble/curves@npm:^1.0.0, @noble/curves@npm:^1.2.0, @noble/curves@npm:^1.4.2, @noble/curves@npm:^1.8.0, @noble/curves@npm:^1.8.1, @noble/curves@npm:^1.9.1, @noble/curves@npm:^1.9.2, @noble/curves@npm:^1.9.7, @noble/curves@npm:~1.9.0":
1045110460
version: 1.9.7
1045210461
resolution: "@noble/curves@npm:1.9.7"
1045310462
dependencies:
@@ -26726,13 +26735,15 @@ __metadata:
2672626735
languageName: node
2672726736
linkType: hard
2672826737

26729-
"eciesjs@npm:^0.3.15":
26730-
version: 0.3.21
26731-
resolution: "eciesjs@npm:0.3.21"
26738+
"eciesjs@npm:0.4.17":
26739+
version: 0.4.17
26740+
resolution: "eciesjs@npm:0.4.17"
2673226741
dependencies:
26733-
futoin-hkdf: "npm:^1.5.3"
26734-
secp256k1: "npm:^5.0.1"
26735-
checksum: 10/7f10709d20c0f65a887ba6d4a4b01685b3a18b933e4296a232372f9e8dc7b957cd68d339457737bf358be8a68ff4fcc8501cb617437e142ac483b0ba04fbc26c
26742+
"@ecies/ciphers": "npm:^0.2.5"
26743+
"@noble/ciphers": "npm:^1.3.0"
26744+
"@noble/curves": "npm:^1.9.7"
26745+
"@noble/hashes": "npm:^1.8.0"
26746+
checksum: 10/89e3db5d916e9b4badb516f0a89514300ce7bbc4e1a8a0b8f1e0ef4ac1d88c5aef622a65cb277b6a020e423c3b04f981398eeb349d5bd7e3e42a35132e871e7f
2673626747
languageName: node
2673726748
linkType: hard
2673826749

@@ -30362,13 +30373,6 @@ __metadata:
3036230373
languageName: node
3036330374
linkType: hard
3036430375

30365-
"futoin-hkdf@npm:^1.5.3":
30366-
version: 1.5.3
30367-
resolution: "futoin-hkdf@npm:1.5.3"
30368-
checksum: 10/aa64b93b4fdca77e6e9c7f045c539dd912f10077bc31d933e219eb5784e88e90a6d830b5d34431da840cc7477c0ed5f2d504dec49718b9f57941de5f23c20471
30369-
languageName: node
30370-
linkType: hard
30371-
3037230376
"fwd-stream@npm:^1.0.4":
3037330377
version: 1.0.4
3037430378
resolution: "fwd-stream@npm:1.0.4"
@@ -35590,7 +35594,7 @@ __metadata:
3559035594
dotenv: "npm:^16.0.3"
3559135595
dpdm: "npm:^3.14.0"
3559235596
eas-cli: "npm:^12.6.1"
35593-
eciesjs: "npm:^0.3.15"
35597+
eciesjs: "npm:0.4.17"
3559435598
enzyme: "npm:3.9.0"
3559535599
enzyme-adapter-react-16: "npm:1.10.0"
3559635600
enzyme-to-json: "npm:3.3.5"
@@ -42493,18 +42497,6 @@ __metadata:
4249342497
languageName: node
4249442498
linkType: hard
4249542499

42496-
"secp256k1@npm:^5.0.1":
42497-
version: 5.0.1
42498-
resolution: "secp256k1@npm:5.0.1"
42499-
dependencies:
42500-
elliptic: "npm:^6.5.7"
42501-
node-addon-api: "npm:^5.0.0"
42502-
node-gyp: "npm:latest"
42503-
node-gyp-build: "npm:^4.2.0"
42504-
checksum: 10/63fbd35624be4fd9cf3d39e5f79c5471b4a8aea6944453b2bea7b100bb1c77a25c55e6e08e2210cdabdf478c4c62d34c408b34214f2afd9367e19a52a3a4236c
42505-
languageName: node
42506-
linkType: hard
42507-
4250842500
"seedrandom@npm:^3.0.5":
4250942501
version: 3.0.5
4251042502
resolution: "seedrandom@npm:3.0.5"

0 commit comments

Comments
 (0)