Skip to content

fix(bitcoin-wallet-snap): return Json directly from onKeyringRequest - #100

Merged
hmalik88 merged 8 commits into
mainfrom
hm/fix-bitcoin-v2
Aug 4, 2026
Merged

fix(bitcoin-wallet-snap): return Json directly from onKeyringRequest#100
hmalik88 merged 8 commits into
mainfrom
hm/fix-bitcoin-v2

Conversation

@hmalik88

@hmalik88 hmalik88 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Explanation

Bitcoin wallet snap v2.0.0 incorrectly wrapped all onKeyringRequest responses in the v1 { pending: false, result } envelope. MetaMask detects v2 snaps via the capabilities field in the manifest and skips envelope unwrapping, so callers received the wrapper as the result instead of the inner value. This broke signMessage, signPsbt, sendTransaction, and other signing operations.

Removes #toKeyringResponse and updates all handlers to return Json directly, as the v2 keyring protocol requires.

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 marked this pull request as ready for review August 4, 2026 02:33
@hmalik88
hmalik88 requested a review from a team as a code owner August 4, 2026 02:33

@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.

My bad for not paying attention on this one! Looks like we only use the Solana Snap to do submitRequest calls!

Comment thread packages/bitcoin-wallet-snap/src/handlers/KeyringRequestHandler.ts
ccharly
ccharly previously approved these changes Aug 4, 2026
psbtBase64: string,
feeRate?: number,
): Promise<KeyringResponse> {
): Promise<Json> {

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.

I have one concern with these type transformations, Json takes away a lot of information about what the objects actually have. Is this the only way? Isn't there a more fitting type?

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.

@ulissesferreira

Copy link
Copy Markdown
Contributor

To add to my comment above: wouldn't it make sense that the Keyring respecting methods return a type that is all-encompassing, like Json but then the private methods inside actually return a specific Json of what is happening?

@ccharly

ccharly commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

To add to my comment above: wouldn't it make sense that the Keyring respecting methods return a type that is all-encompassing, like Json but then the private methods inside actually return a specific Json of what is happening?

IMO that makes total sense, and that's much better if we use stricter types! As long as those types are Json compatible, we should be good!

@taran-a

taran-a commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@hmalik88 does it mean that we have to deprecate v2.0.0 of the bitcoin snap ?

Also I was testing preview build, including the send bitcoin flow, and that trx was signed, sent and confirmed ? I can see from the description that it should fail with v2.0.0

@hmalik88

hmalik88 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@hmalik88 does it mean that we have to deprecate v2.0.0 of the bitcoin snap ?

Also I was testing preview build, including the send bitcoin flow, and that trx was signed, sent and confirmed ? I can see from the description that it should fail with v2.0.0

Yes we should deprecate once the fix is released to avoid anyone pinning to the wrong version. Could you share which extension build/version you were testing against? Depending on that, it might explain why send appeared to work. The behavior of v2.0.0 differs based on whether the extension was doing envelope unwrapping or not

@hmalik88

hmalik88 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Aug 4, 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/bitcoin-wallet-snap@2.0.0-preview-be6d7f2c
@metamask-previews/snap-networks-utils@0.0.0-preview-be6d7f2c
@metamask-previews/tron-wallet-snap@2.0.0-preview-be6d7f2c

@taran-a

taran-a commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@hmalik88 does it mean that we have to deprecate v2.0.0 of the bitcoin snap ?
Also I was testing preview build, including the send bitcoin flow, and that trx was signed, sent and confirmed ? I can see from the description that it should fail with v2.0.0

Yes we should deprecate once the fix is released to avoid anyone pinning to the wrong version. Could you share which extension build/version you were testing against? Depending on that, it might explain why send appeared to work. The behavior of v2.0.0 differs based on whether the extension was doing envelope unwrapping or not

I usually test with the latest main branch of the extension or mobile app so I can't tell which commit, sorry (

@hmalik88
hmalik88 added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit 88b3999 Aug 4, 2026
46 checks passed
@hmalik88
hmalik88 deleted the hm/fix-bitcoin-v2 branch August 4, 2026 12:54
@ulissesferreira ulissesferreira mentioned this pull request Aug 5, 2026
4 tasks
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