@@ -5,7 +5,7 @@ const buffer_1 = require('buffer');
55const networks_1 = require ( '../networks' ) ;
66const bscript = require ( '../script' ) ;
77const types_1 = require ( '../types' ) ;
8- const taproot_1 = require ( '../taproot ' ) ;
8+ const taprootutils_1 = require ( './taprootutils ' ) ;
99const lazy = require ( './lazy' ) ;
1010const bech32_1 = require ( 'bech32' ) ;
1111const OPS = bscript . OPS ;
@@ -75,14 +75,15 @@ function p2tr(ecc) {
7575 } ) ;
7676 lazy . prop ( o , 'hash' , ( ) => {
7777 if ( a . hash ) return a . hash ;
78- if ( a . scriptsTree ) return ( 0 , taproot_1 . toHashTree ) ( a . scriptsTree ) . hash ;
78+ if ( a . scriptsTree )
79+ return ( 0 , taprootutils_1 . toHashTree ) ( a . scriptsTree ) . hash ;
7980 const w = _witness ( ) ;
8081 if ( w && w . length > 1 ) {
8182 const controlBlock = w [ w . length - 1 ] ;
8283 const leafVersion = controlBlock [ 0 ] & 0b11111110 ;
8384 const script = w [ w . length - 2 ] ;
84- const leafHash = ( 0 , taproot_1 . tapLeafHash ) ( script , leafVersion ) ;
85- return ( 0 , taproot_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
85+ const leafHash = ( 0 , taprootutils_1 . tapLeafHash ) ( script , leafVersion ) ;
86+ return ( 0 , taprootutils_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
8687 }
8788 return null ;
8889 } ) ;
@@ -119,12 +120,12 @@ function p2tr(ecc) {
119120 if ( a . witness ) return a . witness ;
120121 if ( a . scriptsTree && a . scriptLeaf && a . internalPubkey ) {
121122 // todo: optimize/cache
122- const hashTree = ( 0 , taproot_1 . toHashTree ) ( a . scriptsTree ) ;
123- const leafHash = ( 0 , taproot_1 . tapLeafHash ) (
123+ const hashTree = ( 0 , taprootutils_1 . toHashTree ) ( a . scriptsTree ) ;
124+ const leafHash = ( 0 , taprootutils_1 . tapLeafHash ) (
124125 a . scriptLeaf . output ,
125126 a . scriptLeaf . version ,
126127 ) ;
127- const path = ( 0 , taproot_1 . findScriptPath ) ( hashTree , leafHash ) ;
128+ const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
128129 const outputKey = tweakKey ( a . internalPubkey , hashTree . hash ) ;
129130 if ( ! outputKey ) return ;
130131 const version = a . scriptLeaf . version || 0xc0 ;
@@ -177,7 +178,7 @@ function p2tr(ecc) {
177178 throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
178179 }
179180 if ( a . hash && a . scriptsTree ) {
180- const hash = ( 0 , taproot_1 . toHashTree ) ( a . scriptsTree ) . hash ;
181+ const hash = ( 0 , taprootutils_1 . toHashTree ) ( a . scriptsTree ) . hash ;
181182 if ( ! a . hash . equals ( hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
182183 }
183184 const witness = _witness ( ) ;
@@ -216,8 +217,11 @@ function p2tr(ecc) {
216217 throw new TypeError ( 'Invalid internalPubkey for p2tr witness' ) ;
217218 const leafVersion = controlBlock [ 0 ] & 0b11111110 ;
218219 const script = witness [ witness . length - 2 ] ;
219- const leafHash = ( 0 , taproot_1 . tapLeafHash ) ( script , leafVersion ) ;
220- const hash = ( 0 , taproot_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
220+ const leafHash = ( 0 , taprootutils_1 . tapLeafHash ) ( script , leafVersion ) ;
221+ const hash = ( 0 , taprootutils_1 . rootHashFromPath ) (
222+ controlBlock ,
223+ leafHash ,
224+ ) ;
221225 const outputKey = tweakKey ( internalPubkey , hash ) ;
222226 if ( ! outputKey )
223227 // todo: needs test data
@@ -235,7 +239,7 @@ function p2tr(ecc) {
235239 if ( ! buffer_1 . Buffer . isBuffer ( pubKey ) ) return null ;
236240 if ( pubKey . length !== 32 ) return null ;
237241 if ( h && h . length !== 32 ) return null ;
238- const tweakHash = ( 0 , taproot_1 . tapTweakHash ) ( pubKey , h ) ;
242+ const tweakHash = ( 0 , taprootutils_1 . tapTweakHash ) ( pubKey , h ) ;
239243 const res = ecc . xOnlyPointAddTweak ( pubKey , tweakHash ) ;
240244 if ( ! res || res . xOnlyPubkey === null ) return null ;
241245 return {
0 commit comments