@@ -11,6 +11,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
11
11
loop { }
12
12
}
13
13
14
+ mod types;
15
+ use types:: { GuardianSet , GuardianSignature , VerifiedVM , WormholeError } ;
14
16
15
17
use alloc:: { vec, vec:: Vec } ;
16
18
use stylus_sdk:: {
@@ -21,77 +23,6 @@ use stylus_sdk::{
21
23
22
24
use k256:: ecdsa:: { RecoveryId , Signature , VerifyingKey } ;
23
25
24
- #[ derive( Clone , PartialEq , Default ) ]
25
- pub struct GuardianSet {
26
- pub keys : Vec < Address > ,
27
- pub expiration_time : u32 ,
28
- }
29
-
30
- #[ derive( Clone ) ]
31
- pub struct GuardianSignature {
32
- pub guardian_index : u8 ,
33
- pub signature : FixedBytes < 65 > ,
34
- }
35
-
36
- #[ derive( Clone ) ]
37
- pub struct VerifiedVM {
38
- pub version : u8 ,
39
- pub guardian_set_index : u32 ,
40
- pub signatures : Vec < GuardianSignature > ,
41
- pub timestamp : u32 ,
42
- pub nonce : u32 ,
43
- pub emitter_chain_id : u16 ,
44
- pub emitter_address : FixedBytes < 32 > ,
45
- pub sequence : u64 ,
46
- pub consistency_level : u8 ,
47
- pub payload : Vec < u8 > ,
48
- pub hash : FixedBytes < 32 > ,
49
- }
50
-
51
- pub enum WormholeError {
52
- InvalidGuardianSetIndex ,
53
- GuardianSetExpired ,
54
- NoQuorum ,
55
- InvalidSignatureOrder ,
56
- InvalidSignature ,
57
- InvalidVAAFormat ,
58
- GovernanceActionConsumed ,
59
- AlreadyInitialized ,
60
- NotInitialized ,
61
- InvalidInput ,
62
- InsufficientSignatures ,
63
- InvalidGuardianIndex ,
64
- InvalidAddressLength ,
65
- VerifyVAAError ,
66
- }
67
-
68
- impl core:: fmt:: Debug for WormholeError {
69
- fn fmt ( & self , _: & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
70
- Ok ( ( ) )
71
- }
72
- }
73
-
74
- impl From < WormholeError > for Vec < u8 > {
75
- fn from ( error : WormholeError ) -> Vec < u8 > {
76
- vec ! [ match error {
77
- WormholeError :: InvalidGuardianSetIndex => 1 ,
78
- WormholeError :: GuardianSetExpired => 2 ,
79
- WormholeError :: NoQuorum => 3 ,
80
- WormholeError :: InvalidSignatureOrder => 4 ,
81
- WormholeError :: InvalidSignature => 5 ,
82
- WormholeError :: InvalidVAAFormat => 6 ,
83
- WormholeError :: GovernanceActionConsumed => 7 ,
84
- WormholeError :: AlreadyInitialized => 8 ,
85
- WormholeError :: NotInitialized => 9 ,
86
- WormholeError :: InvalidInput => 10 ,
87
- WormholeError :: InsufficientSignatures => 11 ,
88
- WormholeError :: InvalidGuardianIndex => 12 ,
89
- WormholeError :: InvalidAddressLength => 13 ,
90
- WormholeError :: VerifyVAAError => 14 ,
91
- } ]
92
- }
93
- }
94
-
95
26
pub trait IWormhole {
96
27
fn parse_and_verify_vm ( & self , encoded_vaa : Vec < u8 > ) -> Result < VerifiedVM , WormholeError > ;
97
28
fn get_guardian_set ( & self , index : u32 ) -> Option < GuardianSet > ;
0 commit comments