saa_common/types/
cred.rs

1use core::fmt::Display;
2
3use saa_schema::{saa_type, strum_macros::{Display, EnumString}};
4pub type CredentialId = String;
5
6#[saa_type]
7#[derive(Display, EnumString)]
8#[strum(serialize_all = "snake_case")]
9pub enum CredentialName {
10    Native,
11    #[cfg(feature = "cosmos_arb")]
12    CosmosArbitrary,
13    #[cfg(feature = "eth_personal")]
14    EthPersonalSign,
15    #[cfg(feature = "eth_typed_data")]
16    EthTypedData, 
17    #[cfg(feature = "passkeys")]
18    Passkey,
19    #[cfg(feature = "secp256r1")]
20    Secp256r1,
21    #[cfg(feature = "secp256k1")]
22    Secp256k1,
23    #[cfg(feature = "ed25519")]
24    Ed25519,
25}
26
27
28#[saa_type]
29pub enum CredentialAddress {
30    Evm(String),
31    #[cfg(not(feature = "wasm"))]
32    Bech32(String),
33    #[cfg(feature = "wasm")]
34    Bech32(crate::wasm::Addr),
35}
36
37
38
39#[saa_type]
40pub struct CredentialInfo {
41    /// name of the used credential
42    pub name: CredentialName,
43    /// human readable prefix to encode from a public key
44    pub hrp: Option<String>,
45    /// extension data
46    pub extension: Option<crate::InfoExtension>,
47    /// address derived from credential
48    pub address: Option<CredentialAddress>,
49}
50
51
52
53pub type CredentialRecord = (CredentialId, CredentialInfo);
54
55
56
57impl Display for CredentialAddress {
58    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59        match self {
60            CredentialAddress::Evm(addr) => write!(f, "{}", addr),
61            #[cfg(not(feature = "wasm"))]
62            CredentialAddress::Bech32(addr) => write!(f, "{}", addr),
63            #[cfg(feature = "wasm")]
64            CredentialAddress::Bech32(addr) => write!(f, "{}", addr.as_str()),
65        }
66    }
67    
68}
69
70
71#[cfg(feature = "wasm")]
72impl From<crate::wasm::Addr> for CredentialInfo {
73    fn from(addr: crate::wasm::Addr) -> Self {
74        CredentialInfo {
75            name: CredentialName::Native,
76            extension: None,
77            hrp: addr.as_str().split("1").next().map(|s| s.to_string()),
78            address: Some(CredentialAddress::Bech32(addr)),
79        }
80    }
81}