Skip to content

Conversation

@0xsatoshi99
Copy link

Summary

Add support for tapBip32Derivation in HD signing methods, enabling taproot inputs to be signed using HD wallets.

Problem

Currently, signInputHD, signInputHDAsync, and signAllInputsHD only check bip32Derivation for deriving signing keys. This means taproot inputs that use tapBip32Derivation (as specified in BIP-371) cannot be signed using these HD methods.

Users have to manually iterate over inputs and handle taproot derivation separately, which defeats the purpose of the convenience HD signing methods.

Solution

  • Modified getSignersFromHD to detect taproot inputs and delegate to new getSignersFromHDTaproot helper
  • Added getSignersFromHDTaproot function that:
    • Filters tapBip32Derivation by master fingerprint
    • Derives child keys using the BIP32 path
    • Validates x-only pubkeys (32-byte) against derivation data
  • Updated inputHasHDKey and outputHasHDKey to also check tapBip32Derivation
  • Updated error message to mention both derivation types

Changes

  • ts_src/psbt.ts: Core implementation (~60 lines added)
  • test/fixtures/psbt.json: Updated error message in test fixture

Testing

All 2660 existing tests pass. The implementation follows the same pattern as existing HD signing code but handles the x-only pubkey format used in taproot.

Fixes #2000
Fixes #2132


Contribution by Gittensor, learn more at https://gittensor.io/

Add support for tapBip32Derivation in HD signing methods:
- signInputHD and signInputHDAsync now work with taproot inputs
- inputHasHDKey and outputHasHDKey check tapBip32Derivation
- New getSignersFromHDTaproot helper for taproot-specific derivation

This enables signing taproot inputs using HD wallets with the
standard signAllInputsHD and signInputHD methods.

Fixes bitcoinjs#2000
Fixes bitcoinjs#2132
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.

Feature Request: Taproot support for signAllInputsHD PSBT HD signing does not support taproot

1 participant