File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,10 @@ function p2tr(a, opts) {
122
122
if ( ( 0 , types_1 . liftX ) ( pubkey ) === null )
123
123
throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
124
124
}
125
+ if ( a . hash && a . scriptsTree ) {
126
+ const hash = ( 0 , merkle_1 . computeMastRoot ) ( a . scriptsTree ) ;
127
+ if ( ! a . hash . equals ( hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
128
+ }
125
129
if ( a . witness ) {
126
130
if ( a . witness . length !== 1 ) throw new TypeError ( 'Witness is invalid' ) ;
127
131
// todo: recheck
Original file line number Diff line number Diff line change 375
375
"pubkey" : " ab610d22c801def8a1e02368d1b92018970eb52a729919705e8a1a2f60c750f5"
376
376
}
377
377
},
378
+ {
379
+ "description" : " Hash mismatch between scriptsTree and hash" ,
380
+ "exception" : " Hash mismatch" ,
381
+ "options" : {},
382
+ "arguments" : {
383
+ "internalPubkey" : " 9fa5ffb68821cf559001caa0577eeea4978b29416def328a707b15e91701a2f7" ,
384
+ "scriptsTree" : [
385
+ {
386
+ "output" : " 83d8ee77a0f3a32a5cea96fd1624d623b836c1e5d1ac2dcde46814b619320c18 OP_CHECKSIG"
387
+ }
388
+ ],
389
+ "hash" : " b76077013c8e303085e300000000000000000000000000000000000000000000"
390
+ }
391
+ },
378
392
{
379
393
"exception" : " Invalid internalPubkey for p2t" ,
380
394
"options" : {},
Original file line number Diff line number Diff line change @@ -133,6 +133,12 @@ export function p2tr(a: Payment, opts?: PaymentOpts): Payment {
133
133
throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
134
134
}
135
135
136
+ if ( a . hash && a . scriptsTree ) {
137
+ const hash = computeMastRoot ( a . scriptsTree )
138
+ if ( ! a . hash . equals ( hash ) )
139
+ throw new TypeError ( 'Hash mismatch' ) ;
140
+ }
141
+
136
142
if ( a . witness ) {
137
143
if ( a . witness . length !== 1 ) throw new TypeError ( 'Witness is invalid' ) ;
138
144
You can’t perform that action at this time.
0 commit comments