1- //https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#user-content-Address_derivation
1+ // BIP86: Taproot BIP32 Derivation Path and Extended Key Version
2+ // https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki
23
34import * as ecc from '@bitcoinerlab/secp256k1' ;
45import { networks } from 'bitcoinjs-lib' ;
@@ -13,16 +14,58 @@ const masterNode = BIP32.fromSeed(
1314 ) ,
1415 network
1516) ;
16- describe ( 'BIP86' , ( ) => {
17- test ( 'BIP86' , ( ) => {
17+
18+ describe ( 'BIP86 Taproot Derivation Path Tests' , ( ) => {
19+ // Test vector from BIP86 specification
20+ // https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#test-vectors
21+
22+ test ( 'First receiving address m/86\'/0\'/0\'/0/0' , ( ) => {
23+ // Account 0, first receiving address = m/86'/0'/0'/0/0
24+ // Expected values from BIP86 specification:
25+ // xprv = xprvA449goEeU9okwCzzZaxiy475EQGQzBkc65su82nXEvcwzfSskb2hAt2WymrjyRL6kpbVTGL3cKtp9herYXSjjQ1j4stsXXiRF7kXkCacK3T
26+ // xpub = xpub6H3W6JmYJXN49h5TfcVjLC3onS6uPeUTTJoVvRC8oG9vsTn2J8LwigLzq5tHbrwAzH9DGo6ThGUdWsqce8dGfwHVBxSbixjDADGGdzF7t2B
27+ // internal_key = cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115
28+ // output_key = a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c
29+ // scriptPubKey = 5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c
30+ // address = bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr
31+
32+ const descriptor = trBIP32 ( {
33+ masterNode,
34+ network,
35+ account : 0 ,
36+ change : 0 ,
37+ index : 0
38+ } ) ;
39+
40+ const output = new Output ( { descriptor, network } ) ;
41+ const address = output . getAddress ( ) ;
42+ const scriptPubKey = output . getScriptPubKey ( ) . toString ( 'hex' ) ;
43+
44+ // Verify the generated address matches the expected value from BIP86 spec
45+ expect ( address ) . toBe ( 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr' ) ;
46+
47+ // Verify the scriptPubKey matches the expected value (with 5120 prefix for OP_PUSHBYTES_32 + 32-byte key)
48+ expect ( scriptPubKey ) . toBe ( '5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c' ) ;
49+ } ) ;
50+
51+ test ( 'Basic Taproot descriptor functionality' , ( ) => {
1852 const descriptor = trBIP32 ( {
1953 masterNode,
2054 network,
2155 account : 0 ,
2256 change : 0 ,
2357 index : 0
2458 } ) ;
59+
2560 const output = new Output ( { descriptor, network } ) ;
26- console . log ( output . getAddress ( ) ) ;
61+
62+ // Verify we can get an address
63+ expect ( output . getAddress ( ) ) . toBeTruthy ( ) ;
64+
65+ // Verify it's a Taproot address (starts with bc1p for mainnet)
66+ expect ( output . getAddress ( ) . startsWith ( 'bc1p' ) ) . toBe ( true ) ;
67+
68+ // Verify it's recognized as Taproot
69+ expect ( output . isTaproot ( ) ) . toBe ( true ) ;
2770 } ) ;
2871} ) ;
0 commit comments