Skip to content

feat(bitcoin-snap): update to keyring v2 - #43

Merged
hmalik88 merged 47 commits into
mainfrom
hm/add-v2-methods
Jul 30, 2026
Merged

feat(bitcoin-snap): update to keyring v2#43
hmalik88 merged 47 commits into
mainfrom
hm/add-v2-methods

Conversation

@hmalik88

@hmalik88 hmalik88 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Explanation

Original PR & reviewer comments here: MetaMask/snap-bitcoin-wallet#645

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.

Rewrites KeyringHandler to implement KeyringSnapRpc (from @metamask/keyring-api/v2): adds getAccounts, getAccount, createAccounts, exportAccount, getAccountBalances, getAccountAssets, getAccountTransactions, deleteAccount, submitRequest, setSelectedAccounts, and resolveAccountAddress
Removes v1-only flows (createAccount, discoverAccounts, filterAccountChains, updateAccount) and stops emitting AccountCreated / AccountDeleted events
Folds bip44:discover into createAccounts: calls AccountUseCases.discover(), deletes the account from state if no transactions are found, and returns [] to signal end-of-discovery
Adds exportAccount with WIF private-key export (Base58Check, version byte 0x80/0xEF); uses is() not assert() to prevent the private key from appearing in a StructError message on encoding failure
Reads SUPPORTED_SCOPES directly from snap.manifest.json capabilities block (same pattern as Solana snap) instead of hardcoding the network
Switches handleKeyringRequest to the v2 dispatcher (@metamask/keyring-snap-sdk/v2)
Adds endowment:keyring.capabilities to snap.manifest.json: scopes, privateKey.exportFormats, and bip44 derive/discover flags
Sets module: "ESNext" and moduleResolution: "bundler" in packages/snap/tsconfig.json so /v2 subpath exports resolve correctly
Bumps @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.0
Updates KeyringHandler.test.ts: removes v1-only describe blocks, adds exportAccount and bip44:discover coverage, mocks wif module, adds beforeEach(() => jest.resetAllMocks()) to fix mock-call accumulation between tests

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@hmalik88
hmalik88 requested review from a team as code owners July 22, 2026 14:15
@hmalik88
hmalik88 temporarily deployed to default-branch July 22, 2026 14:15 — with GitHub Actions Inactive
@socket-security

socket-security Bot commented Jul 22, 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.

View full report

Comment thread packages/bitcoin-wallet-snap/src/handlers/parsers.ts Fixed
Comment thread packages/bitcoin-wallet-snap/src/handlers/parsers.ts Fixed
Comment thread packages/bitcoin-wallet-snap/src/handlers/parsers.ts Fixed
@hmalik88 hmalik88 changed the title Hm/add v2 methods feat(bitcoin-snap): update to keyring v2 Jul 24, 2026
@hmalik88

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/@metamask/snaps-controllers@21.0.0

transaction: 'notAPsbt',
},
code: -32603,
message: 'Invalid PSBT',

@hmalik88 hmalik88 Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because handleKeyringRequest either throws SnapError or Error , the middleware doesn't catch it as FormatError, hence the "Invalid format: " prefix gets stripped

Comment thread packages/bitcoin-wallet-snap/CHANGELOG.md
Comment thread packages/bitcoin-wallet-snap/src/handlers/KeyringHandler.ts Outdated
Comment thread packages/bitcoin-wallet-snap/src/handlers/KeyringHandler.ts Outdated
Comment thread packages/bitcoin-wallet-snap/package.json Outdated
@ulissesferreira

Copy link
Copy Markdown
Contributor

@metamaskbot publish-preview

@github-actions

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/bitcoin-wallet-snap@1.15.2-preview-31d9fde
@metamask-previews/tron-wallet-snap@1.33.1-preview-31d9fde

@hmalik88

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

ccharly
ccharly previously approved these changes Jul 29, 2026
@github-actions

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/bitcoin-wallet-snap@1.15.2-preview-06663c3
@metamask-previews/tron-wallet-snap@1.33.1-preview-06663c3

@hmalik88

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

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/bitcoin-wallet-snap@1.15.2-preview-777c1a48
@metamask-previews/tron-wallet-snap@1.33.2-preview-777c1a48

@hmalik88
hmalik88 enabled auto-merge July 30, 2026 10:21
@hmalik88
hmalik88 added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 6023928 Jul 30, 2026
43 checks passed
@hmalik88
hmalik88 deleted the hm/add-v2-methods branch July 30, 2026 12:14
Battambang added a commit that referenced this pull request Jul 30, 2026
Sync with bitcoin keyring v2 (#43) and regenerate yarn.lock after
resolving the lockfile conflict.
Battambang added a commit that referenced this pull request Jul 30, 2026
Bump snaps-cli, snaps-sdk, superstruct, keyring-api, and
keyring-snap-sdk declarations to match bitcoin-/tron-wallet-snap
after #43 (installed versions unchanged).
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.

6 participants