2024-02-19 15:55:46 +00:00
|
|
|
use cosmwasm_schema::cw_serde;
|
|
|
|
use cosmwasm_std::{HexBinary, StdError};
|
|
|
|
|
2024-05-07 22:34:09 +00:00
|
|
|
use crate::{
|
|
|
|
msg::{execute::attested::HasUserData, HasDomainType},
|
|
|
|
state::{Nonce, UserData},
|
|
|
|
};
|
2024-02-19 15:55:46 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
pub struct SessionCreate {
|
|
|
|
nonce: Nonce,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SessionCreate {
|
2024-03-19 21:19:38 +00:00
|
|
|
pub fn new(nonce: Nonce) -> Self {
|
|
|
|
Self { nonce }
|
|
|
|
}
|
|
|
|
|
2024-02-19 15:55:46 +00:00
|
|
|
pub fn into_nonce(self) -> Nonce {
|
|
|
|
self.nonce
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cw_serde]
|
|
|
|
pub struct RawSessionCreate {
|
|
|
|
nonce: HexBinary,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<RawSessionCreate> for SessionCreate {
|
|
|
|
type Error = StdError;
|
|
|
|
|
|
|
|
fn try_from(value: RawSessionCreate) -> Result<Self, Self::Error> {
|
|
|
|
let nonce = value.nonce.to_array()?;
|
|
|
|
Ok(Self { nonce })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SessionCreate> for RawSessionCreate {
|
|
|
|
fn from(value: SessionCreate) -> Self {
|
|
|
|
Self {
|
|
|
|
nonce: value.nonce.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasDomainType for RawSessionCreate {
|
|
|
|
type DomainType = SessionCreate;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasUserData for SessionCreate {
|
|
|
|
fn user_data(&self) -> UserData {
|
|
|
|
let mut user_data = [0u8; 64];
|
|
|
|
user_data[0..32].copy_from_slice(&self.nonce);
|
|
|
|
user_data
|
|
|
|
}
|
|
|
|
}
|