Skip to content

feat: update to keyring v2#606

Merged
hmalik88 merged 50 commits into
mainfrom
hm/add-v2-methods
Jul 13, 2026
Merged

feat: update to keyring v2#606
hmalik88 merged 50 commits into
mainfrom
hm/add-v2-methods

Conversation

@hmalik88

@hmalik88 hmalik88 commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates the Solana snap to the v2 Keyring API and declares the corresponding capabilities in the manifest. Also removes all v1-only keyring methods and fixes a latent test-isolation bug surfaced while validating the migration.

  • Rewrites SolanaKeyring to implement KeyringSnapRpc (from @metamask/keyring-api/v2): adds getAccounts, getAccount (throws on missing IDs instead of returning undefined), and exportAccount (base58 only); renames listAccountAssets / listAccountTransactionsgetAccountAssets / getAccountTransactions
  • Removes v1-only flows (createAccount, listAccounts, discoverAccounts, updateAccount, filterAccountChains) and stops emitting AccountCreated / AccountDeleted events
  • Folds bip44:discover into createAccounts via on-chain activity checks
  • Wraps all public keyring method errors in a single SnapError
  • Switches handleKeyringRequest to the v2 dispatcher (@metamask/keyring-snap-sdk/v2)
  • Adds endowment:keyring.capabilities to snap.manifest.json
  • Bumps @metamask/snaps-sdk → 11.1.1, snaps-cli → 8.4.1, snaps-jest → 10.1.3, keyring-snap-sdk → 9.1.0, and updates the root resolutions to match; snaps-utils resolves to 12.2.0 which is required to validate the new manifest field
  • Sets moduleResolution: "bundler" in packages/snap/tsconfig.json so v2 subpath types resolve correctly
  • Fixes a flaky jest --runInBand failure: replaces an incomplete jest.mock('@noble/ed25519', ...) in index.test.ts with jest.mock('./polyfills', ...). The previous mock was captured by the ed25519 polyfill's closure when it patched globalThis.crypto.subtle, leaking into other test files via shared global state under --runInBand

Note

High Risk
Touches account creation/deletion, private key export, and keyring RPC contracts—security-sensitive paths with breaking behavior changes for v1 callers and clients that relied on keyring events or getAccount returning undefined.

Overview
Migrates the Solana wallet snap from the v1 keyring protocol to Keyring API v2, with dependency bumps and manifest updates so MetaMask can drive account lifecycle through the new RPC surface.

SolanaKeyring now implements KeyringSnapRpc instead of v1 Keyring. Entry point uses handleKeyringRequest from @metamask/keyring-snap-sdk/v2. Added: getAccounts, exportAccount (base58 64-byte secret key), and bip44:discover inside createAccounts via on-chain activity. Renamed: listAccountAssets / listAccountTransactionsgetAccountAssets / getAccountTransactions. Removed: createAccount, listAccounts, discoverAccounts, updateAccount, filterAccountChains, and AccountCreated / AccountDeleted events; deleteAccount only clears snap state. getAccount now throws when the id is missing (no undefined). Public keyring errors are wrapped in a single SnapError.

snap.manifest.json adds endowment:keyring.capabilities (scopes, privateKey export, bip44 derive/discover) and bumps platformVersion to 11.1.1. permissions.ts allows v2 KeyringSnapRpcMethods plus a subset of v1 method names for compatibility.

Tooling: @metamask/keyring-api ^23.5.0, keyring-snap-sdk ^9.2.0, snaps-sdk ^11.1.1; root resolutions and .yarnrc.yml preapproved packages for fresh MetaMask releases; snap tsconfig uses moduleResolution: "bundler".

Tests: keyring suite aligned to v2 APIs and exportAccount; index.test.ts mocks ./polyfills instead of @noble/ed25519 to avoid flaky globalThis.crypto.subtle leakage under jest --runInBand.

Reviewed by Cursor Bugbot for commit 754dc86. Bugbot is set up for automated code reviews on this repo. Configure here.

@socket-security

socket-security Bot commented May 27, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​keyring-api@​23.5.01001001009850
Updated@​metamask/​keyring-snap-sdk@​8.0.0 ⏵ 9.2.099 +110075 +197 +2100
Updated@​metamask/​snaps-cli@​8.3.0 ⏵ 8.4.176100100 +187 +1100
Updated@​metamask/​snaps-jest@​9.8.0 ⏵ 10.1.476 +110010095100
Updated@​metamask/​snaps-sdk@​10.3.0 ⏵ 11.1.199 +11007892 -1100

View full report

@socket-security

socket-security Bot commented May 27, 2026

Copy link
Copy Markdown

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

  • @ethersproject/web@5.8.0
  • @metamask/snaps-rpc-methods@17.0.0
  • @metamask/snaps-controllers@20.0.6
  • ses@1.15.0

View full report

@hmalik88 hmalik88 changed the title feat: add v2 methods feat: update to keyring v2 May 27, 2026
@hmalik88

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/ses@1.15.0

@hmalik88
hmalik88 marked this pull request as ready for review May 27, 2026 01:57
@hmalik88
hmalik88 requested a review from a team as a code owner May 27, 2026 01:57
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts Outdated
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts Outdated
Comment thread packages/snap/src/index.ts Outdated
Comment thread packages/snap/tsconfig.json
Comment thread package.json
Comment thread packages/snap/CHANGELOG.md Outdated
Comment thread packages/snap/snap.manifest.json
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Comment thread packages/snap/src/core/validation/structs.ts
Comment thread packages/snap/src/permissions.ts Outdated
ccharly
ccharly previously approved these changes Jun 2, 2026

@ccharly ccharly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for v2!

One thing though, I wonder if we should really expose exportAccount for hexadecimal, it seems base58 is the way to go for Solana.

We could keep it if we wish to export them in "raw format", but I would strip the 0x prefix then (I'm not sure this is commonly used outside of Ethereum, but I could be wrong about that 😄)

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/solana-wallet-snap@2.9.1-preview-646cf65

@hmalik88

hmalik88 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/solana-wallet-snap@2.10.0-preview-7971550

@hmalik88

hmalik88 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/solana-wallet-snap@2.10.0-preview-fecb555

Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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 dac2ffa. Configure here.

Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts Outdated
@hmalik88

hmalik88 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/solana-wallet-snap@2.10.0-preview-adbfe18

Comment thread packages/snap/CHANGELOG.md Outdated
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts Outdated
Comment thread yarn.lock
languageName: node
linkType: hard

"@ethersproject/abi@npm:^5.7.0":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Looks like that's being pulled by @metamask/controller-utils.

Comment thread packages/snap/src/permissions.ts
@sonarqubecloud

Copy link
Copy Markdown

@ccharly ccharly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM + tested on extension e2e, see:

@stanleyyconsensys stanleyyconsensys left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

just 1 question and 1 nit review

@ulissesferreira would you mind to give another review, as it has a lot of changes, which im not pretty sure

Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
Comment thread packages/snap/src/core/handlers/onKeyringRequest/Keyring.ts
@hmalik88
hmalik88 merged commit c7c5613 into main Jul 13, 2026
10 checks passed
@hmalik88
hmalik88 deleted the hm/add-v2-methods branch July 13, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants