@@ -74,6 +74,14 @@ pub enum ScriptContextError {
74
74
MultiANotAllowed ,
75
75
}
76
76
77
+ #[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
78
+ pub enum SigType {
79
+ /// Ecdsa signature
80
+ Ecdsa ,
81
+ /// Schnorr Signature
82
+ Schnorr ,
83
+ }
84
+
77
85
impl fmt:: Display for ScriptContextError {
78
86
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
79
87
match * self {
@@ -285,12 +293,10 @@ where
285
293
Self :: other_top_level_checks ( ms)
286
294
}
287
295
288
- /// Reverse lookup to store whether the context is tapscript.
289
- /// pk(33-byte key) is a valid under both tapscript context and segwitv0 context
290
- /// We need to context decide whether the serialize pk to 33 byte or 32 bytes.
291
- fn is_tap ( ) -> bool {
292
- return false ;
293
- }
296
+ /// The type of signature required for satisfaction
297
+ // We need to context decide whether the serialize pk to 33 byte or 32 bytes.
298
+ // And to decide which type of signatures to look for during satisfaction
299
+ fn sig_type ( ) -> SigType ;
294
300
295
301
/// Get the len of public key when serialized based on context
296
302
/// Note that this includes the serialization prefix. Returns
@@ -395,6 +401,10 @@ impl ScriptContext for Legacy {
395
401
fn name_str ( ) -> & ' static str {
396
402
"Legacy/p2sh"
397
403
}
404
+
405
+ fn sig_type ( ) -> SigType {
406
+ SigType :: Ecdsa
407
+ }
398
408
}
399
409
400
410
/// Segwitv0 ScriptContext
@@ -503,6 +513,10 @@ impl ScriptContext for Segwitv0 {
503
513
fn name_str ( ) -> & ' static str {
504
514
"Segwitv0"
505
515
}
516
+
517
+ fn sig_type ( ) -> SigType {
518
+ SigType :: Ecdsa
519
+ }
506
520
}
507
521
508
522
/// Tap ScriptContext
@@ -600,8 +614,8 @@ impl ScriptContext for Tap {
600
614
ms. ext . max_sat_size . map ( |x| x. 0 )
601
615
}
602
616
603
- fn is_tap ( ) -> bool {
604
- true
617
+ fn sig_type ( ) -> SigType {
618
+ SigType :: Schnorr
605
619
}
606
620
607
621
fn pk_len < Pk : MiniscriptKey > ( _pk : & Pk ) -> usize {
@@ -684,6 +698,10 @@ impl ScriptContext for BareCtx {
684
698
fn name_str ( ) -> & ' static str {
685
699
"BareCtx"
686
700
}
701
+
702
+ fn sig_type ( ) -> SigType {
703
+ SigType :: Ecdsa
704
+ }
687
705
}
688
706
689
707
/// "No Checks" Context
@@ -738,6 +756,51 @@ impl ScriptContext for NoChecks {
738
756
// Internally used code
739
757
"Nochecks"
740
758
}
759
+
760
+ fn check_witness < Pk : MiniscriptKey > ( _witness : & [ Vec < u8 > ] ) -> Result < ( ) , ScriptContextError > {
761
+ // Only really need to do this for segwitv0 and legacy
762
+ // Bare is already restrcited by standardness rules
763
+ // and would reach these limits.
764
+ Ok ( ( ) )
765
+ }
766
+
767
+ fn check_global_validity < Pk : MiniscriptKey > (
768
+ ms : & Miniscript < Pk , Self > ,
769
+ ) -> Result < ( ) , ScriptContextError > {
770
+ Self :: check_global_consensus_validity ( ms) ?;
771
+ Self :: check_global_policy_validity ( ms) ?;
772
+ Ok ( ( ) )
773
+ }
774
+
775
+ fn check_local_validity < Pk : MiniscriptKey > (
776
+ ms : & Miniscript < Pk , Self > ,
777
+ ) -> Result < ( ) , ScriptContextError > {
778
+ Self :: check_global_consensus_validity ( ms) ?;
779
+ Self :: check_global_policy_validity ( ms) ?;
780
+ Self :: check_local_consensus_validity ( ms) ?;
781
+ Self :: check_local_policy_validity ( ms) ?;
782
+ Ok ( ( ) )
783
+ }
784
+
785
+ fn top_level_type_check < Pk : MiniscriptKey > ( ms : & Miniscript < Pk , Self > ) -> Result < ( ) , Error > {
786
+ if ms. ty . corr . base != types:: Base :: B {
787
+ return Err ( Error :: NonTopLevel ( format ! ( "{:?}" , ms) ) ) ;
788
+ }
789
+ Ok ( ( ) )
790
+ }
791
+
792
+ fn other_top_level_checks < Pk : MiniscriptKey > ( _ms : & Miniscript < Pk , Self > ) -> Result < ( ) , Error > {
793
+ Ok ( ( ) )
794
+ }
795
+
796
+ fn top_level_checks < Pk : MiniscriptKey > ( ms : & Miniscript < Pk , Self > ) -> Result < ( ) , Error > {
797
+ Self :: top_level_type_check ( ms) ?;
798
+ Self :: other_top_level_checks ( ms)
799
+ }
800
+
801
+ fn sig_type ( ) -> SigType {
802
+ unreachable ! ( "Tried to call sig type on no-checks Miniscript" )
803
+ }
741
804
}
742
805
743
806
/// Private Mod to prevent downstream from implementing this public trait
0 commit comments