@@ -5,10 +5,10 @@ const buffer_1 = require('buffer');
55const networks_1 = require ( '../networks' ) ;
66const bscript = require ( '../script' ) ;
77const types_1 = require ( '../types' ) ;
8+ const ecc_lib_1 = require ( '../ecc_lib' ) ;
89const taprootutils_1 = require ( './taprootutils' ) ;
910const lazy = require ( './lazy' ) ;
1011const bech32_1 = require ( 'bech32' ) ;
11- const verifyecc_1 = require ( './verifyecc' ) ;
1212const OPS = bscript . OPS ;
1313const TAPROOT_WITNESS_VERSION = 0x01 ;
1414const ANNEX_PREFIX = 0x50 ;
@@ -22,11 +22,6 @@ function p2tr(a, opts) {
2222 )
2323 throw new TypeError ( 'Not enough data' ) ;
2424 opts = Object . assign ( { validate : true } , opts || { } ) ;
25- const _ecc = lazy . value ( ( ) => {
26- if ( ! opts . eccLib ) throw new Error ( 'ECC Library is missing for p2tr.' ) ;
27- ( 0 , verifyecc_1 . verifyEcc ) ( opts . eccLib ) ;
28- return opts . eccLib ;
29- } ) ;
3025 ( 0 , types_1 . typeforce ) (
3126 {
3227 address : types_1 . typeforce . maybe ( types_1 . typeforce . String ) ,
@@ -132,7 +127,7 @@ function p2tr(a, opts) {
132127 if ( a . output ) return a . output . slice ( 2 ) ;
133128 if ( a . address ) return _address ( ) . data ;
134129 if ( o . internalPubkey ) {
135- const tweakedKey = tweakKey ( o . internalPubkey , o . hash , _ecc ( ) ) ;
130+ const tweakedKey = tweakKey ( o . internalPubkey , o . hash ) ;
136131 if ( tweakedKey ) return tweakedKey . x ;
137132 }
138133 } ) ;
@@ -157,7 +152,7 @@ function p2tr(a, opts) {
157152 } ) ;
158153 const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
159154 if ( ! path ) return ;
160- const outputKey = tweakKey ( a . internalPubkey , hashTree . hash , _ecc ( ) ) ;
155+ const outputKey = tweakKey ( a . internalPubkey , hashTree . hash ) ;
161156 if ( ! outputKey ) return ;
162157 const controlBock = buffer_1 . Buffer . concat (
163158 [
@@ -198,13 +193,13 @@ function p2tr(a, opts) {
198193 else pubkey = a . output . slice ( 2 ) ;
199194 }
200195 if ( a . internalPubkey ) {
201- const tweakedKey = tweakKey ( a . internalPubkey , o . hash , _ecc ( ) ) ;
196+ const tweakedKey = tweakKey ( a . internalPubkey , o . hash ) ;
202197 if ( pubkey . length > 0 && ! pubkey . equals ( tweakedKey . x ) )
203198 throw new TypeError ( 'Pubkey mismatch' ) ;
204199 else pubkey = tweakedKey . x ;
205200 }
206201 if ( pubkey && pubkey . length ) {
207- if ( ! _ecc ( ) . isXOnlyPoint ( pubkey ) )
202+ if ( ! ( 0 , ecc_lib_1 . getEccLib ) ( ) . isXOnlyPoint ( pubkey ) )
208203 throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
209204 }
210205 const hashTree = _hashTree ( ) ;
@@ -267,7 +262,7 @@ function p2tr(a, opts) {
267262 const internalPubkey = controlBlock . slice ( 1 , 33 ) ;
268263 if ( a . internalPubkey && ! a . internalPubkey . equals ( internalPubkey ) )
269264 throw new TypeError ( 'Internal pubkey mismatch' ) ;
270- if ( ! _ecc ( ) . isXOnlyPoint ( internalPubkey ) )
265+ if ( ! ( 0 , ecc_lib_1 . getEccLib ) ( ) . isXOnlyPoint ( internalPubkey ) )
271266 throw new TypeError ( 'Invalid internalPubkey for p2tr witness' ) ;
272267 const leafVersion = controlBlock [ 0 ] & types_1 . TAPLEAF_VERSION_MASK ;
273268 const script = witness [ witness . length - 2 ] ;
@@ -279,7 +274,7 @@ function p2tr(a, opts) {
279274 controlBlock ,
280275 leafHash ,
281276 ) ;
282- const outputKey = tweakKey ( internalPubkey , hash , _ecc ( ) ) ;
277+ const outputKey = tweakKey ( internalPubkey , hash ) ;
283278 if ( ! outputKey )
284279 // todo: needs test data
285280 throw new TypeError ( 'Invalid outputKey for p2tr witness' ) ;
@@ -293,12 +288,12 @@ function p2tr(a, opts) {
293288 return Object . assign ( o , a ) ;
294289}
295290exports . p2tr = p2tr ;
296- function tweakKey ( pubKey , h , eccLib ) {
291+ function tweakKey ( pubKey , h ) {
297292 if ( ! buffer_1 . Buffer . isBuffer ( pubKey ) ) return null ;
298293 if ( pubKey . length !== 32 ) return null ;
299294 if ( h && h . length !== 32 ) return null ;
300295 const tweakHash = ( 0 , taprootutils_1 . tapTweakHash ) ( pubKey , h ) ;
301- const res = eccLib . xOnlyPointAddTweak ( pubKey , tweakHash ) ;
296+ const res = ( 0 , ecc_lib_1 . getEccLib ) ( ) . xOnlyPointAddTweak ( pubKey , tweakHash ) ;
302297 if ( ! res || res . xOnlyPubkey === null ) return null ;
303298 return {
304299 parity : res . parity ,
0 commit comments