33// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
44// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki
55Object . 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 ;
77const assert = require ( 'assert' ) ;
88const FastPriorityQueue = require ( 'fastpriorityqueue' ) ;
99const bcrypto = require ( './crypto' ) ;
@@ -14,7 +14,7 @@ const varuint = require('varuint-bitcoin');
1414 * on all 32 byte x-only pub keys as defined in BIP340.
1515 */
1616exports . EVEN_Y_COORD_PREFIX = Buffer . of ( 0x02 ) ;
17- const INITIAL_TAPSCRIPT_VERSION = Buffer . of ( 0xc0 ) ;
17+ exports . INITIAL_TAPSCRIPT_VERSION = 0xc0 ;
1818/**
1919 * Aggregates a list of public keys into a single MuSig2* public key
2020 * according to the MuSig2 paper.
@@ -82,11 +82,11 @@ exports.serializeScriptSize = serializeScriptSize;
8282 * @param script
8383 * @returns
8484 */
85- function hashTapLeaf ( script ) {
85+ function hashTapLeaf ( script , leafVersion = exports . INITIAL_TAPSCRIPT_VERSION ) {
8686 const size = serializeScriptSize ( script ) ;
8787 return bcrypto . taggedHash (
8888 'TapLeaf' ,
89- Buffer . concat ( [ INITIAL_TAPSCRIPT_VERSION , size , script ] ) ,
89+ Buffer . concat ( [ Buffer . of ( leafVersion ) , size , script ] ) ,
9090 ) ;
9191}
9292exports . hashTapLeaf = hashTapLeaf ;
@@ -217,8 +217,13 @@ function getHuffmanTaptree(scripts, weights) {
217217 return { root : rootNode . taggedHash , paths } ;
218218}
219219exports . 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 ;
222227 return Buffer . concat ( [ Buffer . of ( parityVersion ) , pubkey , ...path ] ) ;
223228}
224229exports . getControlBlock = getControlBlock ;
0 commit comments