Skip to content

Add Signature Hash Annex Support (BIP-341) #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JAGADISHSUNILPEDNEKAR
Copy link
Contributor

Description

This PR implements support for the signature hash annex as defined in BIP-341 (Taproot). The annex feature allows for future extensions to the signature validation system by providing a way to include additional data in transaction signature hashes.

Key Changes

  • Added an optional annex parameter to the get_transaction_taproot_digest method
  • Implemented the annex prefix and hashing logic per BIP-341 specifications
  • Fixed an index out of range error in the from_raw method by adding proper boundary checking during transaction parsing
  • Added comprehensive unit tests and integration tests for annex functionality

Implementation Details

  • The signature hash calculation now includes the annex when provided, with the appropriate bit set in the spend type byte
  • The annex is formatted according to BIP-341 with a 0x50 prefix and proper length encoding
  • Transaction parsing is now more robust with checks to prevent reading beyond data boundaries

Testing

  • Added unit tests that verify the transaction digests change correctly with different annexes
  • Created integration tests that verify:
    • Transactions with annexes can be created and broadcast to the network
    • Transactions with annexes can be spent
    • Transactions with annexes can be imported and parsed correctly
  • Integration tests require a running Bitcoin Core instance in regtest mode

Notes

  • All existing tests continue to pass
  • The integration test automatically skips when Bitcoin Core isn't available
  • Docstrings have been updated to document the annex parameter for Sphinx auto-documentation

This implementation enhances compatibility with the Taproot soft fork and is a prerequisite for full Partially Signed Bitcoin Transaction (PSBT) support.

@JAGADISHSUNILPEDNEKAR
Copy link
Contributor Author

JAGADISHSUNILPEDNEKAR commented Apr 5, 2025

This is the extension of PR #128
I had some issue while working with the previous branch so shifted to a new branch with the implementation of the same thing covering your feedback :)

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