feat: Complete PSBT Implementation with BIP-371 Taproot Support, Testnet4 Examples, and Comprehensive Tests#172
Open
JAGADISHSUNILPEDNEKAR wants to merge 14 commits into
Conversation
JAGADISHSUNILPEDNEKAR
force-pushed
the
psbtinitialstr
branch
from
July 18, 2025 07:31
cffe232 to
e7c6cba
Compare
…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
Resolved conflicts in bitcoinutils/script.py, bitcoinutils/transactions.py, and bitcoinutils/psbt.py by integrating BIP-371 Taproot features into the master PSBT implementation.
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
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
PSBTInputandPSBTOutput(tap_key_sig,tap_script_sigs,tap_leaf_scripts,tap_bip32_derivation,tap_internal_key,tap_merkle_root,tap_tree)0x13–0x18for inputs,0x05–0x07for outputs)Taproot Key-Path Signing
sign_input()using Schnorr signatures viasign_taproot_input()SIGHASH_ALL→SIGHASH_DEFAULTmapping for Taproot_finalize_p2tr()to usetap_key_sigand clear intermediate BIP-371 fieldsTest Suite
test_psbt_taproot.py: 27 tests covering full lifecycle, sighash types, BIP-371 field round-trips, combine, finalize, mixed input types, and validationtest_psbt_bip371_vectors.py: 17 official BIP-371 test vectors from the specification (valid round-trips + invalid rejection)Educational Testnet4 Examples
examples/psbt/psbt_p2wpkh_testnet4.pyexamples/psbt/psbt_multisig_testnet4.pyexamples/psbt/psbt_p2tr_testnet4.pyexamples/psbt/psbt_p2tr_hd_testnet4.pyexamples/psbt/README.mdexamples/verify_testnet4.pyCompatibility Matrix
Explicitly Out of Scope
BIP-370, script-path spending, MuSig2, hardware wallets, descriptor wallets.