File tree 3 files changed +38
-6
lines changed
3 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -207,9 +207,17 @@ function p2tr(a, opts) {
207
207
if ( ! _ecc ( ) . isXOnlyPoint ( pubkey ) )
208
208
throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
209
209
}
210
- if ( a . hash && a . scriptTree ) {
211
- const hash = _hashTree ( ) . hash ;
212
- if ( ! a . hash . equals ( hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
210
+ const hashTree = _hashTree ( ) ;
211
+ if ( a . hash && hashTree ) {
212
+ if ( ! a . hash . equals ( hashTree . hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
213
+ }
214
+ if ( a . redeem && a . redeem . output && hashTree ) {
215
+ const leafHash = ( 0 , taprootutils_1 . tapleafHash ) ( {
216
+ output : a . redeem . output ,
217
+ version : o . redeemVersion ,
218
+ } ) ;
219
+ if ( ! ( 0 , taprootutils_1 . findScriptPath ) ( hashTree , leafHash ) )
220
+ throw new TypeError ( 'Redeem script not in tree' ) ;
213
221
}
214
222
const witness = _witness ( ) ;
215
223
// compare the provided redeem data with the one computed from witness
Original file line number Diff line number Diff line change 1175
1175
]
1176
1176
}
1177
1177
}
1178
+ },
1179
+ {
1180
+ "description" : " Redeem script not in tree" ,
1181
+ "exception" : " Redeem script not in tree" ,
1182
+ "options" : {},
1183
+ "arguments" : {
1184
+ "internalPubkey" : " 9fa5ffb68821cf559001caa0577eeea4978b29416def328a707b15e91701a2f7" ,
1185
+ "scriptTree" : {
1186
+ "output" : " 83d8ee77a0f3a32a5cea96fd1624d623b836c1e5d1ac2dcde46814b619320c18 OP_CHECKSIG"
1187
+ },
1188
+ "redeem" : {
1189
+ "output" : " 83d8ee77a0f3a32a5cea96fd1624d623b836c1e5d1ac2dcde46814b619320c19 OP_CHECKSIG"
1190
+ }
1191
+ }
1178
1192
}
1179
1193
],
1180
1194
"dynamic" : {
Original file line number Diff line number Diff line change @@ -231,9 +231,19 @@ export function p2tr(a: Payment, opts?: PaymentOpts): Payment {
231
231
throw new TypeError ( 'Invalid pubkey for p2tr' ) ;
232
232
}
233
233
234
- if ( a . hash && a . scriptTree ) {
235
- const hash = _hashTree ( ) ! . hash ;
236
- if ( ! a . hash . equals ( hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
234
+ const hashTree = _hashTree ( ) ;
235
+
236
+ if ( a . hash && hashTree ) {
237
+ if ( ! a . hash . equals ( hashTree . hash ) ) throw new TypeError ( 'Hash mismatch' ) ;
238
+ }
239
+
240
+ if ( a . redeem && a . redeem . output && hashTree ) {
241
+ const leafHash = tapleafHash ( {
242
+ output : a . redeem . output ,
243
+ version : o . redeemVersion ,
244
+ } ) ;
245
+ if ( ! findScriptPath ( hashTree , leafHash ) )
246
+ throw new TypeError ( 'Redeem script not in tree' ) ;
237
247
}
238
248
239
249
const witness = _witness ( ) ;
You can’t perform that action at this time.
0 commit comments