Skip to main content

defuse_core/payload/
mod.rs

1pub mod erc191;
2pub mod multi;
3pub mod nep413;
4pub mod raw;
5pub mod sep53;
6pub mod tip191;
7pub mod ton_connect;
8pub mod webauthn;
9
10use core::convert::Infallible;
11
12use impl_tools::autoimpl;
13use near_sdk::{AccountId, near};
14use serde_with::base64::Base64;
15
16use crate::{Deadline, Nonce};
17
18// TODO: add version
19#[near(serializers = [json])]
20#[autoimpl(Deref using self.message)]
21#[autoimpl(DerefMut using self.message)]
22#[derive(Debug, Clone)]
23pub struct DefusePayload<T> {
24    pub signer_id: AccountId,
25    pub verifying_contract: AccountId,
26    pub deadline: Deadline,
27    #[serde_as(as = "Base64")]
28    #[cfg_attr(feature = "abi", schemars(example = "self::examples::nonce"))]
29    pub nonce: Nonce,
30
31    #[serde(flatten)]
32    pub message: T,
33}
34
35pub trait ExtractDefusePayload<T> {
36    type Error;
37
38    fn extract_defuse_payload(self) -> Result<DefusePayload<T>, Self::Error>;
39}
40
41impl<T> ExtractDefusePayload<T> for DefusePayload<T> {
42    type Error = Infallible;
43
44    #[inline]
45    fn extract_defuse_payload(self) -> Result<Self, Self::Error> {
46        Ok(self)
47    }
48}
49
50#[cfg(feature = "abi")]
51mod examples {
52    use super::Nonce;
53
54    use near_sdk::base64::{self, Engine};
55
56    pub fn nonce() -> String {
57        base64::engine::general_purpose::STANDARD.encode(Nonce::default())
58    }
59}