@@ -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 = tweakKey ( o . internalPubkey , o . hash ) ;
130+ const tweakedKey = ( 0 , taprootutils_1 . tweakKey ) ( o . internalPubkey , o . hash ) ;
131131 if ( tweakedKey ) return tweakedKey . x ;
132132 }
133133 } ) ;
@@ -152,7 +152,10 @@ function p2tr(a, opts) {
152152 } ) ;
153153 const path = ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) ;
154154 if ( ! path ) return ;
155- const outputKey = tweakKey ( a . internalPubkey , hashTree . hash ) ;
155+ const outputKey = ( 0 , taprootutils_1 . tweakKey ) (
156+ a . internalPubkey ,
157+ hashTree . hash ,
158+ ) ;
156159 if ( ! outputKey ) return ;
157160 const controlBock = buffer_1 . Buffer . concat (
158161 [
@@ -193,7 +196,7 @@ function p2tr(a, opts) {
193196 else pubkey = a . output . slice ( 2 ) ;
194197 }
195198 if ( a . internalPubkey ) {
196- const tweakedKey = tweakKey ( a . internalPubkey , o . hash ) ;
199+ const tweakedKey = ( 0 , taprootutils_1 . tweakKey ) ( a . internalPubkey , o . hash ) ;
197200 if ( pubkey . length > 0 && ! pubkey . equals ( tweakedKey . x ) )
198201 throw new TypeError ( 'Pubkey mismatch' ) ;
199202 else pubkey = tweakedKey . x ;
@@ -274,7 +277,7 @@ function p2tr(a, opts) {
274277 controlBlock ,
275278 leafHash ,
276279 ) ;
277- const outputKey = tweakKey ( internalPubkey , hash ) ;
280+ const outputKey = ( 0 , taprootutils_1 . tweakKey ) ( internalPubkey , hash ) ;
278281 if ( ! outputKey )
279282 // todo: needs test data
280283 throw new TypeError ( 'Invalid outputKey for p2tr witness' ) ;
@@ -288,18 +291,6 @@ function p2tr(a, opts) {
288291 return Object . assign ( o , a ) ;
289292}
290293exports . p2tr = p2tr ;
291- function tweakKey ( pubKey , h ) {
292- if ( ! buffer_1 . Buffer . isBuffer ( pubKey ) ) return null ;
293- if ( pubKey . length !== 32 ) return null ;
294- if ( h && h . length !== 32 ) return null ;
295- const tweakHash = ( 0 , taprootutils_1 . tapTweakHash ) ( pubKey , h ) ;
296- const res = ( 0 , ecc_lib_1 . getEccLib ) ( ) . xOnlyPointAddTweak ( pubKey , tweakHash ) ;
297- if ( ! res || res . xOnlyPubkey === null ) return null ;
298- return {
299- parity : res . parity ,
300- x : buffer_1 . Buffer . from ( res . xOnlyPubkey ) ,
301- } ;
302- }
303294function stacksEqual ( a , b ) {
304295 if ( a . length !== b . length ) return false ;
305296 return a . every ( ( x , i ) => {
0 commit comments