feat(psbt): add taproot support for HD signing methods#2331
Open
dripsmvcp wants to merge 1 commit intobitcoinjs:masterfrom
Open
feat(psbt): add taproot support for HD signing methods#2331dripsmvcp wants to merge 1 commit intobitcoinjs:masterfrom
dripsmvcp wants to merge 1 commit intobitcoinjs:masterfrom
Conversation
Author
|
@jasonandjay @junderw Would you check this PR? |
Taproot inputs using tapBip32Derivation now work with signInputHD, signInputHDAsync, signAllInputsHD, and signAllInputsHDAsync. - Detect taproot inputs in getSignersFromHD and delegate to new getTaprootSignersFromHD helper - Key-path spend (empty leafHashes): derive child key and apply tap tweak using tapMerkleRoot from the PSBT input - Script-path spend (non-empty leafHashes): derive child key untweaked, existing _signTaprootInput handles the rest - Change sighashTypes default from [SIGHASH_ALL] to optional on HD methods, matching signAllInputs — inner methods pick the correct default per input type (SIGHASH_DEFAULT for taproot, SIGHASH_ALL for legacy/segwit) - Extend HDSigner / HDSignerAsync interfaces with optional signSchnorr and tweak methods Closes bitcoinjs#2132
51455f3 to
02f7fcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
signInputHD/signAllInputsHD(and their async variants) silently fail on taproot inputs because they only look atbip32Derivation, nottapBip32Derivation. This patch teaches the HD signing flow to recognize taproot inputs and derive the correct signers.What changed
getSignersFromHDnow detects taproot inputs viaisTaprootInput()and delegates to a newgetTaprootSignersFromHDhelperleafHashesis empty): derives the child key fromtapBip32Derivation, then tweaks it withtapTweakHash(internalKey, tapMerkleRoot)— the tweaked signer produces a validtapKeySigleafHashesis non-empty): derives the child key untweaked and hands it off to the existing_signTaprootInputmachinery, which matches the pubkey againsttapLeafScriptentriessighashTypesparameter on all four HD methods changed from= [SIGHASH_ALL]tooptional— this removes a conflict where taproot'sSIGHASH_DEFAULT (0x00)was being rejected by a hardcodedSIGHASH_ALLfilter. Inner methods (_signInput/_signTaprootInput) already default correctly per input typeHDSigner/HDSignerAsyncinterfaces extended with optionalsignSchnorr?andtweak?— no breaking change for existing implementationsWhy this approach
PR #2329 tackled the same problem. This takes a slightly different approach:
ts_src/psbt.ts— compiledsrc/cjs/andsrc/esm/output is generated by the build, not hand-edited.filter()instead of.map().filter()for fingerprint matchingcheckForInputcall — passes the already-resolved input directly togetTaprootSignersFromHDUint8Arrayconsistently in tests (v7-compatible)Test plan
signInputHDsignInputHDsignAllInputsHDtapBip32DerivationCloses #2132