Skip to content

feat: Complete PSBT Implementation with BIP-371 Taproot Support, Testnet4 Examples, and Comprehensive Tests#172

Open
JAGADISHSUNILPEDNEKAR wants to merge 14 commits into
karask:masterfrom
JAGADISHSUNILPEDNEKAR:psbtinitialstr
Open

feat: Complete PSBT Implementation with BIP-371 Taproot Support, Testnet4 Examples, and Comprehensive Tests#172
JAGADISHSUNILPEDNEKAR wants to merge 14 commits into
karask:masterfrom
JAGADISHSUNILPEDNEKAR:psbtinitialstr

Conversation

@JAGADISHSUNILPEDNEKAR

@JAGADISHSUNILPEDNEKAR JAGADISHSUNILPEDNEKAR commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR extends the existing PSBT implementation with BIP-371 Taproot key-path signing support, Testnet4 educational examples, and a comprehensive test suite including official BIP-371 test vectors.

BIP-371 Serialization & Validation

  • All BIP-371 Taproot fields added to PSBTInput and PSBTOutput (tap_key_sig, tap_script_sigs, tap_leaf_scripts, tap_bip32_derivation, tap_internal_key, tap_merkle_root, tap_tree)
  • Full parsing and serialization for BIP-371 key types (0x130x18 for inputs, 0x050x07 for outputs)
  • Strict validation: rejects invalid signature lengths, control block sizes, and key lengths

Taproot Key-Path Signing

  • P2TR branch in sign_input() using Schnorr signatures via sign_taproot_input()
  • Automatic SIGHASH_ALLSIGHASH_DEFAULT mapping for Taproot
  • Updated _finalize_p2tr() to use tap_key_sig and clear intermediate BIP-371 fields

Test Suite

  • test_psbt_taproot.py: 27 tests covering full lifecycle, sighash types, BIP-371 field round-trips, combine, finalize, mixed input types, and validation
  • test_psbt_bip371_vectors.py: 17 official BIP-371 test vectors from the specification (valid round-trips + invalid rejection)

Educational Testnet4 Examples

File Description
examples/psbt/psbt_p2wpkh_testnet4.py P2WPKH PSBT lifecycle
examples/psbt/psbt_multisig_testnet4.py 2-of-3 P2WSH multisig PSBT
examples/psbt/psbt_p2tr_testnet4.py Taproot key-path PSBT
examples/psbt/psbt_p2tr_hd_testnet4.py Deterministic HD wallet Taproot PSBT
examples/psbt/README.md Workflow diagrams, faucet instructions, compatibility matrix
examples/verify_testnet4.py Live testnet4 verification script

Compatibility Matrix

Feature Status
BIP-174 Core PSBT
BIP-371 Key-path
BIP-371 Script-path
BIP-370 (PSBTv2)
P2PKH
P2WPKH
P2WSH (multisig)
P2SH-P2WPKH
P2TR Key-path
P2TR Script-path

Explicitly Out of Scope

BIP-370, script-path spending, MuSig2, hardware wallets, descriptor wallets.

…mprehensive tests

BIP-371 Serialization:
- Add all BIP-371 Taproot fields to PSBTInput/PSBTOutput (tap_key_sig,
  tap_script_sigs, tap_leaf_scripts, tap_bip32_derivation, tap_internal_key,
  tap_merkle_root, tap_tree)
- Add parsing and serialization for all BIP-371 key types (0x13-0x18 inputs,
  0x05-0x07 outputs)
- Strict validation: reject invalid tap_key_sig/tap_script_sig lengths,
  invalid control block sizes, and invalid tap_internal_key lengths

Taproot Key-Path Signing:
- Add P2TR branch to sign_input() using Schnorr signatures and
  get_transaction_taproot_digest()
- Map SIGHASH_ALL(1) to SIGHASH_DEFAULT(0) for Taproot
- Update _finalize_p2tr() to use tap_key_sig and clear BIP-371 fields
- Update _finalize_input() to handle P2TR before checking partial_sigs

Tests:
- test_psbt_taproot.py: 27 tests covering lifecycle, sighash types,
  BIP-371 field round-trips, combine, finalize, mixed types, validation
- test_psbt_bip371_vectors.py: 17 official BIP-371 test vectors from
  the specification (valid round-trips + invalid rejection)

Educational Examples:
- examples/psbt/psbt_p2wpkh_testnet4.py: P2WPKH PSBT lifecycle
- examples/psbt/psbt_multisig_testnet4.py: 2-of-3 multisig PSBT
- examples/psbt/psbt_p2tr_testnet4.py: Taproot key-path PSBT
- examples/psbt/psbt_p2tr_hd_testnet4.py: HD wallet Taproot PSBT
- examples/psbt/README.md: Workflow diagrams, compatibility matrix
- examples/verify_testnet4.py: Live testnet4 verification script
@JAGADISHSUNILPEDNEKAR JAGADISHSUNILPEDNEKAR changed the title Complete PSBT Workflow Implementation Including Multisig Support and Script Enhancements feat: Complete PSBT Implementation with BIP-371 Taproot Support, Testnet4 Examples, and Comprehensive Tests Jul 15, 2026
Resolved conflicts in bitcoinutils/script.py, bitcoinutils/transactions.py, and bitcoinutils/psbt.py by integrating BIP-371 Taproot features into the master PSBT implementation.
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.

1 participant