feat: add BIP-360 P2MR address encoding and Merkle tree support#246
Draft
feat: add BIP-360 P2MR address encoding and Merkle tree support#246
Conversation
Add witness v2 (P2MR) support to the address encoding layer: - Switch bech32 encoding from version-specific to generic segwit::encode() supporting all witness versions (v0-v2+) - Add P2MR script detection (34 bytes, witness v2, OP_PUSHBYTES_32) - Add OutputScriptSupport.p2mr flag, enabled only on BitGo Signet - Create separate bitcoinBitGoSignet.json fixture file with P2MR address test vectors (tb1z prefix) - Filter P2MR from utxolib compat test path (not supported there) BTC-3241
Add core P2MR tree construction module with WASM bindings and
comprehensive tests against BIP-360 specification test vectors.
Rust core (src/p2mr/mod.rs):
- 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
WASM bindings (src/wasm/p2mr.rs):
- P2mrNamespace with computeLeafHash, computeBranchHash, buildTree,
buildScriptPubkey, verifyControlBlock
- Uses wasm-utxo TryIntoJsValue/get_field pattern (not serde_wasm_bindgen)
- Tree deserialization: leaf = {script, leafVersion?}, branch = [left, right]
TypeScript (js/p2mr.ts):
- Typed wrapper with ScriptTreeNode, P2mrLeafInfo, P2mrTreeInfo types
Tests:
- Fixture-driven tests against all 8 BIP-360 p2mr_construction vectors
BTC-3241
- Export p2mr namespace from js/index.ts - Fix clippy unnecessary_unwrap in bitgo_psbt test code (use if-let) BTC-3241
95389bd to
5a099bf
Compare
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 script tree
construction with control block generation.
Address encoding (commit 1):
segwit::encode()for all witness versions (v0-v2+)OutputScriptSupport.p2mrflag, enabled only on BitGo SignetbitcoinBitGoSignet.jsonfixture file with P2MR test vectorsMerkle tree + WASM bindings (commit 2):
p2mrmodule: tagged hashes, tree building, control block generation/verificationP2mrNamespaceWASM bindings usingTryIntoJsValue/get_fieldpatternjs/p2mr.ts) with full typesBTC-3241