@@ -74,6 +74,14 @@ pub enum ScriptContextError {
7474 MultiANotAllowed ,
7575}
7676
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+
7785impl fmt:: Display for ScriptContextError {
7886 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
7987 match * self {
@@ -285,12 +293,10 @@ where
285293 Self :: other_top_level_checks ( ms)
286294 }
287295
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 ;
294300
295301 /// Get the len of public key when serialized based on context
296302 /// Note that this includes the serialization prefix. Returns
@@ -395,6 +401,10 @@ impl ScriptContext for Legacy {
395401 fn name_str ( ) -> & ' static str {
396402 "Legacy/p2sh"
397403 }
404+
405+ fn sig_type ( ) -> SigType {
406+ SigType :: Ecdsa
407+ }
398408}
399409
400410/// Segwitv0 ScriptContext
@@ -503,6 +513,10 @@ impl ScriptContext for Segwitv0 {
503513 fn name_str ( ) -> & ' static str {
504514 "Segwitv0"
505515 }
516+
517+ fn sig_type ( ) -> SigType {
518+ SigType :: Ecdsa
519+ }
506520}
507521
508522/// Tap ScriptContext
@@ -600,8 +614,8 @@ impl ScriptContext for Tap {
600614 ms. ext . max_sat_size . map ( |x| x. 0 )
601615 }
602616
603- fn is_tap ( ) -> bool {
604- true
617+ fn sig_type ( ) -> SigType {
618+ SigType :: Schnorr
605619 }
606620
607621 fn pk_len < Pk : MiniscriptKey > ( _pk : & Pk ) -> usize {
@@ -684,6 +698,10 @@ impl ScriptContext for BareCtx {
684698 fn name_str ( ) -> & ' static str {
685699 "BareCtx"
686700 }
701+
702+ fn sig_type ( ) -> SigType {
703+ SigType :: Ecdsa
704+ }
687705}
688706
689707/// "No Checks" Context
@@ -738,6 +756,51 @@ impl ScriptContext for NoChecks {
738756 // Internally used code
739757 "Nochecks"
740758 }
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+ }
741804}
742805
743806/// Private Mod to prevent downstream from implementing this public trait
0 commit comments