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 |
| 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
Breaking keyring RPC contract and new private-key export path are security-critical; clients must adopt v2 methods and capabilities before upgrade.
Overview
Breaking migration to MetaMask Keyring API v2:
onKeyringRequestnow delegates tohandleKeyringRequestfrom@metamask/keyring-snap-sdk/v2instead of a customroute()switch on v1 method names.KeyringHandlerimplementsKeyringSnapRpcwith v2 names (getAccounts,getAccountTransactions, etc.) and drops v1-only paths (createAccount,discoverAccounts,filterAccountChains,updateAccount). Account creation is unified underkeyring_createAccounts:bip44:derive-path(via newparseDerivationPath), index/range batching across manifestSUPPORTED_SCOPES, andbip44:discover(discover, delete if no txs, return[]when done).exportAccountadds WIF (base58) export with guarded error handling so keys do not leak in validation messages.The snap manifest gains
endowment:keyring.capabilities(scopes, BIP44 derive/discover, private-key export). Mapped accounts areexportable: true. Dependencies bump keyring/snaps packages; integration tests expect v2 methods, array results, and updated error codes/messages.Reviewed by Cursor Bugbot for commit a22b242. Bugbot is set up for automated code reviews on this repo. Configure here.