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