3
3
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
4
4
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki
5
5
Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
6
- exports . getTaptreeRoot = exports . getTapleafHash = exports . parseControlBlock = exports . parseTaprootWitness = exports . getControlBlock = exports . getHuffmanTaptree = exports . tapTweakPubkey = exports . tapTweakPrivkey = exports . hashTapBranch = exports . hashTapLeaf = exports . serializeScriptSize = exports . aggregateMuSigPubkeys = exports . EVEN_Y_COORD_PREFIX = void 0 ;
6
+ exports . getTaptreeRoot = exports . getTapleafHash = exports . parseControlBlock = exports . parseTaprootWitness = exports . getControlBlock = exports . getHuffmanTaptree = exports . tapTweakPubkey = exports . tapTweakPrivkey = exports . hashTapBranch = exports . hashTapLeaf = exports . serializeScriptSize = exports . aggregateMuSigPubkeys = exports . INITIAL_TAPSCRIPT_VERSION = exports . EVEN_Y_COORD_PREFIX = void 0 ;
7
7
const assert = require ( 'assert' ) ;
8
8
const FastPriorityQueue = require ( 'fastpriorityqueue' ) ;
9
9
const bcrypto = require ( './crypto' ) ;
@@ -14,7 +14,7 @@ const varuint = require('varuint-bitcoin');
14
14
* on all 32 byte x-only pub keys as defined in BIP340.
15
15
*/
16
16
exports . EVEN_Y_COORD_PREFIX = Buffer . of ( 0x02 ) ;
17
- const INITIAL_TAPSCRIPT_VERSION = Buffer . of ( 0xc0 ) ;
17
+ exports . INITIAL_TAPSCRIPT_VERSION = 0xc0 ;
18
18
/**
19
19
* Aggregates a list of public keys into a single MuSig2* public key
20
20
* according to the MuSig2 paper.
@@ -82,11 +82,11 @@ exports.serializeScriptSize = serializeScriptSize;
82
82
* @param script
83
83
* @returns
84
84
*/
85
- function hashTapLeaf ( script ) {
85
+ function hashTapLeaf ( script , leafVersion = exports . INITIAL_TAPSCRIPT_VERSION ) {
86
86
const size = serializeScriptSize ( script ) ;
87
87
return bcrypto . taggedHash (
88
88
'TapLeaf' ,
89
- Buffer . concat ( [ INITIAL_TAPSCRIPT_VERSION , size , script ] ) ,
89
+ Buffer . concat ( [ Buffer . of ( leafVersion ) , size , script ] ) ,
90
90
) ;
91
91
}
92
92
exports . hashTapLeaf = hashTapLeaf ;
@@ -217,8 +217,13 @@ function getHuffmanTaptree(scripts, weights) {
217
217
return { root : rootNode . taggedHash , paths } ;
218
218
}
219
219
exports . getHuffmanTaptree = getHuffmanTaptree ;
220
- function getControlBlock ( parity , pubkey , path ) {
221
- const parityVersion = INITIAL_TAPSCRIPT_VERSION [ 0 ] + parity ;
220
+ function getControlBlock (
221
+ parity ,
222
+ pubkey ,
223
+ path ,
224
+ leafVersion = exports . INITIAL_TAPSCRIPT_VERSION ,
225
+ ) {
226
+ const parityVersion = leafVersion + parity ;
222
227
return Buffer . concat ( [ Buffer . of ( parityVersion ) , pubkey , ...path ] ) ;
223
228
}
224
229
exports . getControlBlock = getControlBlock ;
0 commit comments