vectis_wallet/types/wallet.rs
1use crate::types::{
2 authenticator::{Authenticator, AuthenticatorType},
3 entity::Entity,
4 error::RelayTxError,
5 factory::CreateWalletMsg,
6};
7use cosmwasm_schema::cw_serde;
8use cosmwasm_std::{Addr, Binary, CanonicalAddr, Coin, CosmosMsg, Deps, StdError};
9
10/// The message sent for instantiation
11/// In this case, it is the same field as what user has input.
12// We are keeping this struct for now because it used to contain other default info from the
13// factory, like the guardian multisig code id etc.
14#[cw_serde]
15pub struct ProxyCreateMsg {
16 pub create_wallet_msg: CreateWalletMsg,
17}
18
19/// Sylvia creates the instantiate message in this format - same as instantiate function signature
20#[cw_serde]
21pub struct ProxyInstantiateMsg {
22 pub msg: ProxyCreateMsg,
23}
24
25/// The main controller of the account
26pub type Controller = Entity;
27
28/// Struct for representing a CosmosEOA as an authenticator
29#[cw_serde]
30pub struct CosmosEOA {
31 pub addr: CanonicalAddr,
32}
33
34impl CosmosEOA {
35 /// Set new controller address
36 pub fn set_address(&mut self, address: CanonicalAddr) {
37 self.addr = address;
38 }
39
40 /// Get human addr
41 pub fn to_human(&self, deps: Deps) -> Result<Addr, StdError> {
42 deps.api.addr_humanize(&self.addr)
43 }
44}
45
46impl Controller {
47 /// Increase nonce by 1
48 pub fn increment_nonce(&mut self) {
49 self.nonce += 1;
50 }
51
52 /// Ensure nonces are equal
53 pub fn ensure_nonces_are_equal(&self, nonce: &Nonce) -> Result<(), RelayTxError> {
54 if self.nonce.eq(nonce) {
55 Ok(())
56 } else {
57 Err(RelayTxError::NoncesAreNotEqual {})
58 }
59 }
60
61 /// Returns the AuthenicatorType
62 pub fn auth_type(&self) -> &AuthenticatorType {
63 self.auth.ty()
64 }
65
66 /// Returns the Authenicator
67 pub fn authenticator(&self) -> &Authenticator {
68 &self.auth
69 }
70
71 /// Serialise into a unique slice to be stored as `previous_controller`
72 pub fn to_type_data_slice(&self) -> Vec<u8> {
73 let auth = match self.auth_type() {
74 AuthenticatorType::Webauthn => "Webauthn".as_bytes(),
75 AuthenticatorType::Other(x) => x.as_bytes(),
76 };
77 return [self.data.as_slice(), auth].concat();
78 }
79}
80
81/// Controller nonce
82pub type Nonce = u64;
83
84/// Representation of the wallet address in both form used in migration
85#[cw_serde]
86pub struct WalletAddrs {
87 /// The chain id / name of the remote chain
88 pub chain_id: String,
89 /// The address associated on the remote chain
90 pub addr: Option<String>,
91}
92
93#[cw_serde]
94pub struct WalletInfo {
95 /// The controlling entity for this wallet
96 pub controller: Controller,
97 /// The deployer of Vectis
98 pub deployer: Addr,
99 /// The version of this wallet
100 pub version: cw2::ContractVersion,
101 /// The code-id of this wallet,
102 /// MUST always be returned for frontend
103 pub code_id: u64,
104 /// The relayers for wallet tx
105 pub relayers: Vec<Addr>,
106 /// Time of creation
107 pub created_at: u64,
108 /// Vectis Id
109 pub vid: String,
110 /// Addresses on other chains
111 pub addresses: Vec<WalletAddrs>,
112 /// The wallet policy
113 pub policy: Option<Binary>,
114}
115
116#[cw_serde]
117pub struct RelayTransaction {
118 /// Message to verify,
119 /// Encoding depends on the authenticator,
120 /// but must contain the actual Vec<CosmosMsg> to execute
121 /// e.g. the structure of WebauthnRelayedTxMsg
122 pub message: Binary,
123 /// Serialized signature (message + nonce).
124 /// If authenticator is CosmosEOA: 64 bytes - secp256k1 verification scheme
125 /// See `AuthenticatorType` for more info
126 pub signature: Binary,
127}
128
129/// Data to be signed by the controlling entity
130#[cw_serde]
131pub struct VectisRelayedTx {
132 /// messages to be executed on the entity's behalf
133 pub messages: Vec<CosmosMsg>,
134 /// nonce of the entity for relayed tx
135 pub nonce: Nonce,
136 /// fee for the relaying party
137 /// We skip serializing on none because this is turned into json string to be hashed / signed
138 /// must align between rust and ts tests
139 #[serde(default, skip_serializing_if = "Option::is_none")]
140 pub sponsor_fee: Option<Coin>,
141}
142
143/// The struct that RelayTransaction.message should decode to
144/// for Webauthn
145#[cw_serde]
146pub struct WebauthnRelayedTxMsg {
147 /// This is the JSON string of the `VectisRelayTx`
148 /// We parse this string in the contract for the correct type
149 /// This is because we need this string to ensure fields are in the
150 /// same order when hashing
151 pub signed_data: String,
152 pub auth_data: Binary,
153 pub client_data: Binary,
154}
155
156#[cw_serde]
157pub struct TestMigrateMsg {
158 pub name: String,
159 pub version: String,
160}