feat: add BIP-360 P2MR address encoding and Merkle tree support#246
Open
feat: add BIP-360 P2MR address encoding and Merkle tree support#246
Conversation
95389bd to
5a099bf
Compare
OttoAllmendinger
requested changes
Apr 8, 2026
Contributor
OttoAllmendinger
left a comment
There was a problem hiding this comment.
do we really need to expose the JS api? if we add this to fixed-script wallets it will be just another chain code with the script internals hidden from the user
5a099bf to
3bf0bc7
Compare
Contributor
Author
removed |
b19bd0e to
eeae358
Compare
Add witness v2 (P2MR) support to the address encoding layer: - Generic bech32 segwit::encode() for all witness versions (v0-v2+) - P2MR script detection (34 bytes, witness v2, OP_PUSHBYTES_32) - OutputScriptSupport.p2mr flag on all Bitcoin networks - P2MR address test vectors (bc1z mainnet, tb1z testnet) validated against BIP-360 spec fixtures BTC-3241
Add internal P2MR tree construction module (not exposed to JS): - Tagged hash computation (TapLeaf, TapBranch per BIP-341) - Script tree building with DFS traversal and per-leaf control blocks - Control block generation (leaf_version | 0x01 parity) and verification - Merkle proof verification against expected root Rust tests cover all 6 BIP-360 construction vectors (single leaf, two-leaf same/different versions, lightning contract, two three-leaf variants). TS tests validate mainnet bc1z address encoding against BIP-360 fixture addresses. BTC-3241
eeae358 to
ac5e692
Compare
OttoAllmendinger
approved these changes
Apr 10, 2026
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.
Add Pay-to-Merkle-Root (BIP-360) support to wasm-utxo covering address
encoding/decoding (witness v2, bech32m bc1z/tb1z) and internal Merkle
tree construction with control block generation.
Address encoding (commit 1):
segwit::encode()for all witness versions (v0-v2+)OutputScriptSupport.p2mrflag on all Bitcoin networksMerkle tree core (commit 2):
p2mrmodule using bitcoin crate'sTapLeafHash/TapNodeHash(not exposed to JS, used internally by fixed-script wallet)
bips/bip-0360/p2mr_construction.json,covering all 6 construction vectors + mainnet address validation
BTC-3241