Commit 3faae22
committed
feat: add P2MR Merkle tree, WASM bindings, and BIP-360 spec tests
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-32411 parent e2330d5 commit 3faae22
9 files changed
Lines changed: 1416 additions & 3 deletions
File tree
- packages/wasm-utxo
- js
- src
- fixed_script_wallet/bitgo_psbt
- p2mr
- wasm
- test
- fixtures/p2mr
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4969 | 4969 | | |
4970 | 4970 | | |
4971 | 4971 | | |
4972 | | - | |
4973 | | - | |
4974 | | - | |
| 4972 | + | |
| 4973 | + | |
| 4974 | + | |
4975 | 4975 | | |
4976 | 4976 | | |
4977 | 4977 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
0 commit comments