feat(keyring): enable P2TR taproot account creation#598
Conversation
Remove v1 P2WPKH-only guards from createAccount, extractAddressType, and discoverAccounts. The full P2TR pipeline (BDK descriptors, CAIP type mappings, BIP-86 derivation paths, extension UI) already exists; only the whitelist checks blocked taproot. Widen address type validation to accept P2TR alongside P2WPKH. Accept BIP-86 (purpose 86) derivation paths. Include P2TR in account discovery so existing taproot UTXOs are found during wallet setup. Test coverage: unskip existing BIP-86 vector, add P2TR derivation path extraction, P2TR-only creation, P2TR+path combined validation, and P2TR account discovery with history filtering.
|
I would Love to see this. This is Massive TBH P2TR taproot account creation system on MetaMask is personally needed... |
Nabilislam722
left a comment
There was a problem hiding this comment.
Utilizing it.each for the derivation path tests is a great way to handle the matrix of Bitcoin address types BIP-84 for p2wpkh
|
FWIW, I tested all of this code using metamask flask and I was able to send and move ordinals. |
|
There is already this Taproot PR #578 opened. Pending due to updates in MM clients to QA. |
|
@Battambang Aware of #578, but this PR is complete and tested end-to-end: I ran it with MetaMask Flask, created P2TR accounts, and sent and moved ordinals with it. From my side this code works and is ready to deploy. If #578 is still pending on client QA, this one is ready to go now — happy to coordinate on any overlap. |
Explanation
The snap currently restricts account creation to P2WPKH only, enforced
by three guards in
KeyringHandlerdocumented as v1 restrictions. Thefull P2TR pipeline already exists:
@metamask/bitcoindevkithandlestaproot natively,
caipToAddressTypemapsP2tr → 'p2tr',Purpose.Taproot = 86andpurposeToAddressTypeare defined inentities/account.ts, and the extension UI mapsP2trto 'Taproot'.Only the whitelist checks block taproot.
This PR widens the whitelist to accept P2TR alongside P2WPKH:
createAccount: acceptBtcAccountType.P2trin address type validation#extractAddressType: accept BIP-86 (purpose 86) derivation pathsdiscoverAccounts: include P2TR in the address type discovery listNo new dependencies. No changes to BDK integration, CAIP mappings, or
account infrastructure. Existing P2WPKH behavior is unchanged.
References
Checklist
Note
Medium Risk
Expands supported account types and derivation-path validation, and doubles discovery calls (P2WPKH + P2TR) which can impact account creation/discovery behavior across networks. While scoped to whitelisting/validation, it touches keyring account flows that affect wallet state and UX.
Overview
Enables Taproot (
P2TR) accounts alongside existingP2WPKHinKeyringHandler.createAccountnow acceptsBtcAccountType.P2tr, validates defaults accordingly, and#extractAddressTypepermits BIP-86 (purpose86) derivation paths (updating related error messages).discoverAccountsis expanded to includeP2TRin discovery, and tests/changelog are updated to cover the new behavior.Reviewed by Cursor Bugbot for commit ed91b3b. Bugbot is set up for automated code reviews on this repo. Configure here.