@@ -5,7 +5,7 @@ const buffer_1 = require('buffer');
5
5
const networks_1 = require ( '../networks' ) ;
6
6
const bscript = require ( '../script' ) ;
7
7
const types_1 = require ( '../types' ) ;
8
- const taproot_1 = require ( '../taproot ' ) ;
8
+ const taprootutils_1 = require ( './taprootutils ' ) ;
9
9
const lazy = require ( './lazy' ) ;
10
10
const bech32_1 = require ( 'bech32' ) ;
11
11
const OPS = bscript . OPS ;
@@ -75,14 +75,15 @@ function p2tr(ecc) {
75
75
} ) ;
76
76
lazy . prop ( o , 'hash' , ( ) => {
77
77
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 ;
79
80
const w = _witness ( ) ;
80
81
if ( w && w . length > 1 ) {
81
82
const controlBlock = w [ w . length - 1 ] ;
82
83
const leafVersion = controlBlock [ 0 ] & 0b11111110 ;
83
84
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 ) ;
86
87
}
87
88
return null ;
88
89
} ) ;
@@ -119,12 +120,12 @@ function p2tr(ecc) {
119
120
if ( a . witness ) return a . witness ;
120
121
if ( a . scriptsTree && a . scriptLeaf && a . internalPubkey ) {
121
122
// 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 ) (
124
125
a . scriptLeaf . output ,
125
126
a . scriptLeaf . version ,
126
127
) ;
127
- const path = ( 0 , taproot_1 . findScriptPath ) ( hashTree , leafHash ) ;
128
+ const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
128
129
const outputKey = tweakKey ( a . internalPubkey , hashTree . hash ) ;
129
130
if ( ! outputKey ) return ;
130
131
const version = a . scriptLeaf . version || 0xc0 ;
@@ -177,7 +178,7 @@ function p2tr(ecc) {
177
178
throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
178
179
}
179
180
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 ;
181
182
if ( ! a . hash . equals ( hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
182
183
}
183
184
const witness = _witness ( ) ;
@@ -216,8 +217,11 @@ function p2tr(ecc) {
216
217
throw new TypeError ( 'Invalid internalPubkey for p2tr witness' ) ;
217
218
const leafVersion = controlBlock [ 0 ] & 0b11111110 ;
218
219
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
+ ) ;
221
225
const outputKey = tweakKey ( internalPubkey , hash ) ;
222
226
if ( ! outputKey )
223
227
// todo: needs test data
@@ -235,7 +239,7 @@ function p2tr(ecc) {
235
239
if ( ! buffer_1 . Buffer . isBuffer ( pubKey ) ) return null ;
236
240
if ( pubKey . length !== 32 ) return null ;
237
241
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 ) ;
239
243
const res = ecc . xOnlyPointAddTweak ( pubKey , tweakHash ) ;
240
244
if ( ! res || res . xOnlyPubkey === null ) return null ;
241
245
return {
0 commit comments