feat: update to keyring v2#645
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
Ignoring alerts on:
|
|
@SocketSecurity ignore npm/@metamask/snaps-controllers@21.0.0 |
|
@SocketSecurity ignore npm/ses@2.2.0 |
|
@SocketSecurity ignore npm/@ethersproject/web@5.8.0 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 54d5d1f. Configure here.
| writeFileSync( | ||
| join(__dirname, '../locales/en.json'), | ||
| JSON.stringify(englishLocale, null, 2), | ||
| `${JSON.stringify(englishLocale, null, 2)}\n`, |
There was a problem hiding this comment.
CI seemed to been have failing on it
…discovery and account creation instead of hardcoding

Summary
Migrates the Bitcoin snap to the v2 Keyring API and declares the corresponding capabilities in the manifest. Also removes all v1-only keyring methods and replaces the manual routing table with the v2 dispatcher.
KeyringHandlerto implementKeyringSnapRpc(from@metamask/keyring-api/v2): addsgetAccounts,getAccount,createAccounts,exportAccount,getAccountBalances,getAccountAssets,getAccountTransactions,deleteAccount,submitRequest,setSelectedAccounts, andresolveAccountAddresscreateAccount,discoverAccounts,filterAccountChains,updateAccount) and stops emittingAccountCreated/AccountDeletedeventsbip44:discoverintocreateAccounts: callsAccountUseCases.discover(), deletes the account from state if no transactions are found, and returns[]to signal end-of-discoveryexportAccountwith WIF private-key export (Base58Check, version byte 0x80/0xEF); usesis()notassert()to prevent the private key from appearing in aStructErrormessage on encoding failureSUPPORTED_SCOPESdirectly fromsnap.manifest.jsoncapabilities block (same pattern as Solana snap) instead of hardcoding the networkhandleKeyringRequestto the v2 dispatcher (@metamask/keyring-snap-sdk/v2)endowment:keyring.capabilitiestosnap.manifest.json:scopes,privateKey.exportFormats, andbip44derive/discover flagsmodule: "ESNext"andmoduleResolution: "bundler"inpackages/snap/tsconfig.jsonso/v2subpath exports resolve correctly@metamask/keyring-api→ ^23.5.0,keyring-snap-sdk→ ^9.2.0,snaps-sdk→ ^11.2.0,snaps-cli→ ^8.4.1,snaps-jest→ ^10.2.0KeyringHandler.test.ts: removes v1-only describe blocks, addsexportAccountandbip44:discovercoverage, mockswifmodule, addsbeforeEach(() => jest.resetAllMocks())to fix mock-call accumulation between testsReferences
N/A
Checklist
Note
High Risk
Touches keyring account lifecycle, discovery, and private-key export—security-sensitive paths—with breaking RPC and manifest contract changes for MetaMask clients.
Overview
Migrates the Bitcoin snap from the v1 keyring RPC surface to Keyring API v2, driven by
handleKeyringRequestfrom@metamask/keyring-snap-sdk/v2instead of a customrouteswitch on legacy method names.KeyringHandlernow implementsKeyringSnapRpc: v2 names such askeyring_getAccounts,keyring_createAccounts, and related getters replacelistAccounts,createAccount, anddiscoverAccounts. Account creation usesbip44:derive-path, index/range, andbip44:discover(inactive discovered accounts are deleted; an empty result ends discovery).exportAccountreturns WIF (base58) with guarded error handling so private material does not leak in validation messages. Supported networks for batch/discover flows come fromendowment:keyring.capabilitiesinsnap.manifest.json. Mapped accounts are markedexportable: true.The manifest gains keyring capabilities (scopes, private-key export format, bip44 derive/discover). Dependencies bump keyring-api, keyring-snap-sdk, and snaps tooling; integration/unit tests and expected RPC error codes are updated for v2.
Reviewed by Cursor Bugbot for commit 3934e33. Bugbot is set up for automated code reviews on this repo. Configure here.