use crate::types::{
authenticator::{Authenticator, AuthenticatorType},
entity::Entity,
error::RelayTxError,
factory::CreateWalletMsg,
};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Binary, CanonicalAddr, Coin, CosmosMsg, Deps, StdError};
#[cw_serde]
pub struct ProxyCreateMsg {
pub create_wallet_msg: CreateWalletMsg,
}
#[cw_serde]
pub struct ProxyInstantiateMsg {
pub msg: ProxyCreateMsg,
}
pub type Controller = Entity;
#[cw_serde]
pub struct CosmosEOA {
pub addr: CanonicalAddr,
}
impl CosmosEOA {
pub fn set_address(&mut self, address: CanonicalAddr) {
self.addr = address;
}
pub fn to_human(&self, deps: Deps) -> Result<Addr, StdError> {
deps.api.addr_humanize(&self.addr)
}
}
impl Controller {
pub fn increment_nonce(&mut self) {
self.nonce += 1;
}
pub fn ensure_nonces_are_equal(&self, nonce: &Nonce) -> Result<(), RelayTxError> {
if self.nonce.eq(nonce) {
Ok(())
} else {
Err(RelayTxError::NoncesAreNotEqual {})
}
}
pub fn auth_type(&self) -> &AuthenticatorType {
self.auth.ty()
}
pub fn authenticator(&self) -> &Authenticator {
&self.auth
}
pub fn to_type_data_slice(&self) -> Vec<u8> {
let auth = match self.auth_type() {
AuthenticatorType::Webauthn => "Webauthn".as_bytes(),
AuthenticatorType::Other(x) => x.as_bytes(),
};
return [self.data.as_slice(), auth].concat();
}
}
pub type Nonce = u64;
#[cw_serde]
pub struct WalletAddrs {
pub chain_id: String,
pub addr: Option<String>,
}
#[cw_serde]
pub struct WalletInfo {
pub controller: Controller,
pub deployer: Addr,
pub version: cw2::ContractVersion,
pub code_id: u64,
pub relayers: Vec<Addr>,
pub created_at: u64,
pub vid: String,
pub addresses: Vec<WalletAddrs>,
pub policy: Option<Binary>,
}
#[cw_serde]
pub struct RelayTransaction {
pub message: Binary,
pub signature: Binary,
}
#[cw_serde]
pub struct VectisRelayedTx {
pub messages: Vec<CosmosMsg>,
pub nonce: Nonce,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sponsor_fee: Option<Coin>,
}
#[cw_serde]
pub struct WebauthnRelayedTxMsg {
pub signed_data: String,
pub auth_data: Binary,
pub client_data: Binary,
}
#[cw_serde]
pub struct TestMigrateMsg {
pub name: String,
pub version: String,
}