@@ -201,6 +201,54 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
201
201
pub fn max_satisfaction_size ( & self ) -> Result < usize , Error > {
202
202
Ctx :: max_satisfaction_size ( self ) . ok_or ( Error :: ImpossibleSatisfaction )
203
203
}
204
+ /// Attempt to produce non-malleable satisfying witness for the
205
+ /// witness script represented by the parse tree
206
+ pub fn satisfy < S : satisfy:: Satisfier < Pk > > ( & self , satisfier : S ) -> Result < Vec < Vec < u8 > > , Error >
207
+ where
208
+ Pk : ToPublicKey ,
209
+ {
210
+ // Only satisfactions for default versions (0xc0) are allowed.
211
+ let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , LeafVersion :: TapScript ) ;
212
+ match satisfy:: Satisfaction :: satisfy ( & self . node , & satisfier, self . ty . mall . safe , & leaf_hash)
213
+ . stack
214
+ {
215
+ satisfy:: Witness :: Stack ( stack) => {
216
+ Ctx :: check_witness :: < Pk > ( & stack) ?;
217
+ Ok ( stack)
218
+ }
219
+ satisfy:: Witness :: Unavailable | satisfy:: Witness :: Impossible => {
220
+ Err ( Error :: CouldNotSatisfy )
221
+ }
222
+ }
223
+ }
224
+
225
+ /// Attempt to produce a malleable satisfying witness for the
226
+ /// witness script represented by the parse tree
227
+ pub fn satisfy_malleable < S : satisfy:: Satisfier < Pk > > (
228
+ & self ,
229
+ satisfier : S ,
230
+ ) -> Result < Vec < Vec < u8 > > , Error >
231
+ where
232
+ Pk : ToPublicKey ,
233
+ {
234
+ let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , LeafVersion :: TapScript ) ;
235
+ match satisfy:: Satisfaction :: satisfy_mall (
236
+ & self . node ,
237
+ & satisfier,
238
+ self . ty . mall . safe ,
239
+ & leaf_hash,
240
+ )
241
+ . stack
242
+ {
243
+ satisfy:: Witness :: Stack ( stack) => {
244
+ Ctx :: check_witness :: < Pk > ( & stack) ?;
245
+ Ok ( stack)
246
+ }
247
+ satisfy:: Witness :: Unavailable | satisfy:: Witness :: Impossible => {
248
+ Err ( Error :: CouldNotSatisfy )
249
+ }
250
+ }
251
+ }
204
252
}
205
253
206
254
/// `PartialOrd` of `Miniscript` must depend only on node and not the type information.
@@ -499,57 +547,6 @@ impl_block_str!(
499
547
}
500
548
) ;
501
549
502
- impl < Pk : MiniscriptKey , Ctx : ScriptContext > Miniscript < Pk , Ctx > {
503
- /// Attempt to produce non-malleable satisfying witness for the
504
- /// witness script represented by the parse tree
505
- pub fn satisfy < S : satisfy:: Satisfier < Pk > > ( & self , satisfier : S ) -> Result < Vec < Vec < u8 > > , Error >
506
- where
507
- Pk : ToPublicKey ,
508
- {
509
- // Only satisfactions for default versions (0xc0) are allowed.
510
- let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , LeafVersion :: TapScript ) ;
511
- match satisfy:: Satisfaction :: satisfy ( & self . node , & satisfier, self . ty . mall . safe , & leaf_hash)
512
- . stack
513
- {
514
- satisfy:: Witness :: Stack ( stack) => {
515
- Ctx :: check_witness :: < Pk > ( & stack) ?;
516
- Ok ( stack)
517
- }
518
- satisfy:: Witness :: Unavailable | satisfy:: Witness :: Impossible => {
519
- Err ( Error :: CouldNotSatisfy )
520
- }
521
- }
522
- }
523
-
524
- /// Attempt to produce a malleable satisfying witness for the
525
- /// witness script represented by the parse tree
526
- pub fn satisfy_malleable < S : satisfy:: Satisfier < Pk > > (
527
- & self ,
528
- satisfier : S ,
529
- ) -> Result < Vec < Vec < u8 > > , Error >
530
- where
531
- Pk : ToPublicKey ,
532
- {
533
- let leaf_hash = TapLeafHash :: from_script ( & self . encode ( ) , LeafVersion :: TapScript ) ;
534
- match satisfy:: Satisfaction :: satisfy_mall (
535
- & self . node ,
536
- & satisfier,
537
- self . ty . mall . safe ,
538
- & leaf_hash,
539
- )
540
- . stack
541
- {
542
- satisfy:: Witness :: Stack ( stack) => {
543
- Ctx :: check_witness :: < Pk > ( & stack) ?;
544
- Ok ( stack)
545
- }
546
- satisfy:: Witness :: Unavailable | satisfy:: Witness :: Impossible => {
547
- Err ( Error :: CouldNotSatisfy )
548
- }
549
- }
550
- }
551
- }
552
-
553
550
impl_from_tree ! (
554
551
; Ctx ; ScriptContext ,
555
552
Arc <Miniscript <Pk , Ctx >>,
0 commit comments