@@ -6,7 +6,7 @@ const networks_1 = require('../networks');
6
6
const bscript = require ( '../script' ) ;
7
7
const types_1 = require ( '../types' ) ;
8
8
const ecc_lib_1 = require ( '../ecc_lib' ) ;
9
- const taprootutils_1 = require ( './taprootutils ' ) ;
9
+ const bip341_1 = require ( './bip341 ' ) ;
10
10
const lazy = require ( './lazy' ) ;
11
11
const bech32_1 = require ( 'bech32' ) ;
12
12
const OPS = bscript . OPS ;
@@ -69,7 +69,7 @@ function p2tr(a, opts) {
69
69
return a . witness . slice ( ) ;
70
70
} ) ;
71
71
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 ) ;
73
73
if ( a . hash ) return { hash : a . hash } ;
74
74
return ;
75
75
} ) ;
@@ -89,11 +89,11 @@ function p2tr(a, opts) {
89
89
const controlBlock = w [ w . length - 1 ] ;
90
90
const leafVersion = controlBlock [ 0 ] & types_1 . TAPLEAF_VERSION_MASK ;
91
91
const script = w [ w . length - 2 ] ;
92
- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
92
+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
93
93
output : script ,
94
94
version : leafVersion ,
95
95
} ) ;
96
- return ( 0 , taprootutils_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
96
+ return ( 0 , bip341_1 . rootHashFromPath ) ( controlBlock , leafHash ) ;
97
97
}
98
98
return null ;
99
99
} ) ;
@@ -110,7 +110,7 @@ function p2tr(a, opts) {
110
110
) {
111
111
return a . redeem . redeemVersion ;
112
112
}
113
- return taprootutils_1 . LEAF_VERSION_TAPSCRIPT ;
113
+ return bip341_1 . LEAF_VERSION_TAPSCRIPT ;
114
114
} ) ;
115
115
lazy . prop ( o , 'redeem' , ( ) => {
116
116
const witness = _witness ( ) ; // witness without annex
@@ -127,7 +127,7 @@ function p2tr(a, opts) {
127
127
if ( a . output ) return a . output . slice ( 2 ) ;
128
128
if ( a . address ) return _address ( ) . data ;
129
129
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 ) ;
131
131
if ( tweakedKey ) return tweakedKey . x ;
132
132
}
133
133
} ) ;
@@ -147,16 +147,13 @@ function p2tr(a, opts) {
147
147
if ( a . witness ) return a . witness ;
148
148
const hashTree = _hashTree ( ) ;
149
149
if ( hashTree && a . redeem && a . redeem . output && a . internalPubkey ) {
150
- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
150
+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
151
151
output : a . redeem . output ,
152
152
version : o . redeemVersion ,
153
153
} ) ;
154
- const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
154
+ const path = ( 0 , bip341_1 . findScriptPath ) ( hashTree , leafHash ) ;
155
155
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 ) ;
160
157
if ( ! outputKey ) return ;
161
158
const controlBock = buffer_1 . Buffer . concat (
162
159
[
@@ -197,7 +194,7 @@ function p2tr(a, opts) {
197
194
else pubkey = a . output . slice ( 2 ) ;
198
195
}
199
196
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 ) ;
201
198
if ( pubkey . length > 0 && ! pubkey . equals ( tweakedKey . x ) )
202
199
throw new TypeError ( 'Pubkey mismatch' ) ;
203
200
else pubkey = tweakedKey . x ;
@@ -211,11 +208,11 @@ function p2tr(a, opts) {
211
208
if ( ! a . hash . equals ( hashTree . hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
212
209
}
213
210
if ( a . redeem && a . redeem . output && hashTree ) {
214
- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
211
+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
215
212
output : a . redeem . output ,
216
213
version : o . redeemVersion ,
217
214
} ) ;
218
- if ( ! ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) )
215
+ if ( ! ( 0 , bip341_1 . findScriptPath ) ( hashTree , leafHash ) )
219
216
throw new TypeError ( 'Redeem script not in tree' ) ;
220
217
}
221
218
const witness = _witness ( ) ;
@@ -270,15 +267,12 @@ function p2tr(a, opts) {
270
267
throw new TypeError ( 'Invalid internalPubkey for p2tr witness' ) ;
271
268
const leafVersion = controlBlock [ 0 ] & types_1 . TAPLEAF_VERSION_MASK ;
272
269
const script = witness [ witness . length - 2 ] ;
273
- const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
270
+ const leafHash = ( 0 , bip341_1 . tapleafHash ) ( {
274
271
output : script ,
275
272
version : leafVersion ,
276
273
} ) ;
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 ) ;
282
276
if ( ! outputKey )
283
277
// todo: needs test data
284
278
throw new TypeError ( 'Invalid outputKey for p2tr witness' ) ;
0 commit comments