@@ -6,7 +6,7 @@ const networks_1 = require('../networks');
66const bscript = require ( '../script' ) ;
77const types_1 = require ( '../types' ) ;
88const ecc_lib_1 = require ( '../ecc_lib' ) ;
9- const taprootutils_1 = require ( './taprootutils ' ) ;
9+ const bip341_1 = require ( './bip341 ' ) ;
1010const lazy = require ( './lazy' ) ;
1111const bech32_1 = require ( 'bech32' ) ;
1212const OPS = bscript . OPS ;
@@ -69,7 +69,7 @@ function p2tr(a, opts) {
6969 return a . witness . slice ( ) ;
7070 } ) ;
7171 const _hashTree = lazy . value ( ( ) => {
72- if ( a . scriptTree ) return ( 0 , taprootutils_1 . toHashTree ) ( a . scriptTree ) ;
72+ if ( a . scriptTree ) return ( 0 , bip341_1 . toHashTree ) ( a . scriptTree ) ;
7373 if ( a . hash ) return { hash : a . hash } ;
7474 return ;
7575 } ) ;
@@ -89,11 +89,11 @@ function p2tr(a, opts) {
8989 const controlBlock = w [ w . length - 1 ] ;
9090 const leafVersion = controlBlock [ 0 ] & types_1 . TAPLEAF_VERSION_MASK ;
9191 const script = w [ w . length - 2 ] ;
92- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
92+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
9393 output : script ,
9494 version : leafVersion ,
9595 } ) ;
96- return ( 0 , taprootutils_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
96+ return ( 0 , bip341_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
9797 }
9898 return null ;
9999 } ) ;
@@ -110,7 +110,7 @@ function p2tr(a, opts) {
110110 ) {
111111 return a . redeem . redeemVersion ;
112112 }
113- return taprootutils_1 . LEAF_VERSION_TAPSCRIPT ;
113+ return bip341_1 . LEAF_VERSION_TAPSCRIPT ;
114114 } ) ;
115115 lazy . prop ( o , 'redeem' , ( ) => {
116116 const witness = _witness ( ) ; // witness without annex
@@ -127,7 +127,7 @@ function p2tr(a, opts) {
127127 if ( a . output ) return a . output . slice ( 2 ) ;
128128 if ( a . address ) return _address ( ) . data ;
129129 if ( o . internalPubkey ) {
130- const tweakedKey = ( 0 , taprootutils_1 . tweakKey ) ( o . internalPubkey , o . hash ) ;
130+ const tweakedKey = ( 0 , bip341_1 . tweakKey ) ( o . internalPubkey , o . hash ) ;
131131 if ( tweakedKey ) return tweakedKey . x ;
132132 }
133133 } ) ;
@@ -147,16 +147,13 @@ function p2tr(a, opts) {
147147 if ( a . witness ) return a . witness ;
148148 const hashTree = _hashTree ( ) ;
149149 if ( hashTree && a . redeem && a . redeem . output && a . internalPubkey ) {
150- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
150+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
151151 output : a . redeem . output ,
152152 version : o . redeemVersion ,
153153 } ) ;
154- const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
154+ const path = ( 0 , bip341_1 . findScriptPath ) ( hashTree , leafHash ) ;
155155 if ( ! path ) return ;
156- const outputKey = ( 0 , taprootutils_1 . tweakKey ) (
157- a . internalPubkey ,
158- hashTree . hash ,
159- ) ;
156+ const outputKey = ( 0 , bip341_1 . tweakKey ) ( a . internalPubkey , hashTree . hash ) ;
160157 if ( ! outputKey ) return ;
161158 const controlBock = buffer_1 . Buffer . concat (
162159 [
@@ -197,7 +194,7 @@ function p2tr(a, opts) {
197194 else pubkey = a . output . slice ( 2 ) ;
198195 }
199196 if ( a . internalPubkey ) {
200- const tweakedKey = ( 0 , taprootutils_1 . tweakKey ) ( a . internalPubkey , o . hash ) ;
197+ const tweakedKey = ( 0 , bip341_1 . tweakKey ) ( a . internalPubkey , o . hash ) ;
201198 if ( pubkey . length > 0 && ! pubkey . equals ( tweakedKey . x ) )
202199 throw new TypeError ( 'Pubkey mismatch' ) ;
203200 else pubkey = tweakedKey . x ;
@@ -211,11 +208,11 @@ function p2tr(a, opts) {
211208 if ( ! a . hash . equals ( hashTree . hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
212209 }
213210 if ( a . redeem && a . redeem . output && hashTree ) {
214- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
211+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
215212 output : a . redeem . output ,
216213 version : o . redeemVersion ,
217214 } ) ;
218- if ( ! ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) )
215+ if ( ! ( 0 , bip341_1 . findScriptPath ) ( hashTree , leafHash ) )
219216 throw new TypeError ( 'Redeem script not in tree' ) ;
220217 }
221218 const witness = _witness ( ) ;
@@ -270,15 +267,12 @@ function p2tr(a, opts) {
270267 throw new TypeError ( 'Invalid internalPubkey for p2tr witness' ) ;
271268 const leafVersion = controlBlock [ 0 ] & types_1 . TAPLEAF_VERSION_MASK ;
272269 const script = witness [ witness . length - 2 ] ;
273- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
270+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
274271 output : script ,
275272 version : leafVersion ,
276273 } ) ;
277- const hash = ( 0 , taprootutils_1 . rootHashFromPath ) (
278- controlBlock ,
279- leafHash ,
280- ) ;
281- const outputKey = ( 0 , taprootutils_1 . tweakKey ) ( internalPubkey , hash ) ;
274+ const hash = ( 0 , bip341_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
275+ const outputKey = ( 0 , bip341_1 . tweakKey ) ( internalPubkey , hash ) ;
282276 if ( ! outputKey )
283277 // todo: needs test data
284278 throw new TypeError ( 'Invalid outputKey for p2tr witness' ) ;
0 commit comments