defuse_core/payload/
mod.rs1pub 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 defuse_serde_utils::base64::Base64;
13use impl_tools::autoimpl;
14use near_sdk::{AccountId, near};
15use serde_with::serde_as;
16
17use crate::{Deadline, Nonce};
18
19#[cfg_attr(
21 all(feature = "abi", not(target_arch = "wasm32")),
22 serde_as(schemars = true)
23)]
24#[cfg_attr(
25 not(all(feature = "abi", not(target_arch = "wasm32"))),
26 serde_as(schemars = false)
27)]
28#[near(serializers = [json])]
29#[autoimpl(Deref using self.message)]
30#[autoimpl(DerefMut using self.message)]
31#[derive(Debug, Clone)]
32pub struct DefusePayload<T> {
33 pub signer_id: AccountId,
34 pub verifying_contract: AccountId,
35 pub deadline: Deadline,
36 #[serde_as(as = "Base64")]
37 #[cfg_attr(
38 all(feature = "abi", not(target_arch = "wasm32")),
39 schemars(example = "self::examples::nonce")
40 )]
41 pub nonce: Nonce,
42
43 #[serde(flatten)]
44 pub message: T,
45}
46
47pub trait ExtractDefusePayload<T> {
48 type Error;
49
50 fn extract_defuse_payload(self) -> Result<DefusePayload<T>, Self::Error>;
51}
52
53impl<T> ExtractDefusePayload<T> for DefusePayload<T> {
54 type Error = Infallible;
55
56 #[inline]
57 fn extract_defuse_payload(self) -> Result<Self, Self::Error> {
58 Ok(self)
59 }
60}
61
62#[cfg(all(feature = "abi", not(target_arch = "wasm32")))]
63mod examples {
64 use super::*;
65
66 use near_sdk::base64::{self, Engine};
67
68 pub fn nonce() -> String {
69 base64::engine::general_purpose::STANDARD.encode(Nonce::default())
70 }
71}