saa_common/types/
signed.rs

1use saa_schema::saa_type;
2use crate::PayloadExtension;
3
4
5/// Payload message used for telling which credential to use
6/// or how to modify it
7#[saa_type]
8pub struct AuthPayload {
9    /// Which credential to use if multiple are available
10    pub credential_id   :   Option<crate::CredentialId>,
11    /// Human readable prefix to use to derive an address
12    pub hrp             :   Option<String>,
13    /// Additional arguments to pass depending on a credential in question
14    pub extension       :   Option<PayloadExtension>,
15}
16
17
18
19/// A wrapper for signed data used for constructing credentials and verifying them
20/// `data` is base64 encoded JSON string that contains the data to be verified.  
21/// When `replay` feature tag is enabled, must be a JSON object corresponding to `MsgDataToSign` struct.
22#[saa_type]
23pub struct SignedDataMsg {
24    /// Base64 encoded JSON string of replay envelope, serialized actions messages, both of them or none of them
25    pub data        :   crate::Binary,
26    /// Signature to verify the data
27    pub signature   :   crate::Binary,
28    /// Optional payload to use customize the verification flow if possible
29    pub payload     :   Option<AuthPayload>,
30}
31
32
33
34#[saa_type(no_deny)]
35pub struct MsgDataToVerify {
36    pub chain_id: String,
37    pub contract_address: String,
38    pub nonce: crate::Uint64,
39}
40
41
42
43#[derive(Debug, serde::Serialize)]
44pub struct MsgDataToSign {
45    pub chain_id: String,
46    pub contract_address: String,
47    #[serde(skip_serializing_if = "Vec::is_empty")]
48    pub messages: Vec<String>,
49    pub nonce: crate::Uint64,
50}
51
52
53impl MsgDataToSign {
54    pub fn new(cid: String, addr: String, msgs: Vec<String>, nonce: u64) -> Self {
55        Self {
56            chain_id: cid,
57            messages: msgs,
58            contract_address: addr,
59            nonce: nonce.into(),
60        }
61    }
62}
63