smart_account_auth/credential.rs
1
2#[cfg(feature = "eth_personal")]
3pub use saa_auth::ethereum::EthPersonalSign;
4#[cfg(feature = "eth_typed_data")]
5pub use saa_auth::ethereum::{Eip712Types, EthTypedData};
6#[cfg(any(feature = "cosmos_arb", feature = "cosmos_arb_addr"))]
7pub use saa_auth::cosmos::CosmosArbitrary;
8#[cfg(feature = "passkeys")]
9pub use saa_passkeys::PasskeyCredential;
10#[cfg(feature = "secp256r1")]
11pub use saa_passkeys::Secp256r1;
12#[cfg(feature = "secp256k1")]
13pub use saa_curves::secp256k1::Secp256k1;
14#[cfg(feature = "ed25519")]
15pub use saa_curves::ed25519::Ed25519;
16pub use saa_common::{CredentialId, CredentialName, CredentialAddress, CredentialInfo, CredentialRecord};
17pub use crate::caller::Caller;
18
19
20
21#[saa_schema::saa_type]
22pub enum Credential {
23 Native(Caller),
24 #[cfg(feature = "eth_personal")]
25 EthPersonalSign(EthPersonalSign),
26 #[cfg(feature = "eth_typed_data")]
27 EthTypedData(EthTypedData),
28 #[cfg(any(feature = "cosmos_arb", feature = "cosmos_arb_addr"))]
29 CosmosArbitrary(CosmosArbitrary),
30 #[cfg(feature = "passkeys")]
31 Passkey(PasskeyCredential),
32 #[cfg(feature = "secp256r1")]
33 Secp256r1(Secp256r1),
34 #[cfg(feature = "secp256k1")]
35 Secp256k1(Secp256k1),
36 #[cfg(feature = "ed25519")]
37 Ed25519(Ed25519),
38}
39
40
41#[allow(unused, dead_code)]
42#[cfg(feature = "wasm")]
43pub fn build_credential(
44 record : CredentialRecord,
45 msg : crate::msgs::SignedDataMsg,
46 payload : Option<saa_common::PayloadExtension>,
47) -> Result<Credential, saa_common::AuthError> {
48 return Err(saa_common::AuthError::generic("Not implemented"));
49 /*
50 let (id, info) = record;
51 let message = msg.data;
52 let signature = msg.signature;
53 let name = info.name;
54
55 let credential = match name {
56
57 CredentialName::Native => Credential::Native(Caller(id)),
58
59 #[cfg(feature = "secp256r1")]
60 CredentialName::Secp256r1 => Credential::Secp256r1(Secp256r1 {
61 pubkey: saa_common::Binary::from_base64(&id)?,
62 signature,
63 message,
64 }),
65 #[cfg(feature = "secp256k1")]
66 CredentialName::Secp256k1 => Credential::Secp256k1(Secp256k1 {
67 pubkey: saa_common::Binary::from_base64(&id)?,
68 signature,
69 message,
70 hrp: info.hrp,
71 }),
72 #[cfg(feature = "ed25519")]
73 CredentialName::Ed25519 => Credential::Ed25519(Ed25519 {
74 pubkey: saa_common::Binary::from_base64(&id)?,
75 signature,
76 message,
77 }),
78
79 #[cfg(feature = "eth_personal")]
80 CredentialName::EthPersonalSign => Credential::EthPersonalSign(EthPersonalSign {
81 message,
82 signature,
83 signer: id,
84 }),
85
86 #[cfg(any(feature = "cosmos_arb", feature = "cosmos_arb_addr"))]
87 CredentialName::CosmosArbitrary => Credential::CosmosArbitrary(CosmosArbitrary {
88 pubkey: saa_common::Binary::from_base64(&id)?,
89 message,
90 signature,
91 #[cfg(not(feature = "cosmos_arb_addr"))]
92 hrp: info.hrp,
93 #[cfg(feature = "cosmos_arb_addr")]
94 address: info.address
95 .ok_or_else(|| saa_common::CredentialError::NoInfoProperty(
96 CredentialName::CosmosArbitrary, "address".into()))?
97 .to_string(),
98 }),
99
100 #[cfg(feature = "passkeys")]
101 CredentialName::Passkey => {
102 use saa_common::{InfoExtension, PayloadExtension};
103 use saa_passkeys::{ClientData, PasskeyInfo, PasskeyPayload, utils::base64_to_url};
104
105 let Some(InfoExtension::Passkey(info_ext)) = info.extension else {
106 return Err(saa_common::CredentialError::NoInfoExt(CredentialName::Passkey))
107 };
108
109 let (origin, other_keys) = match payload {
110 Some(PayloadExtension::Passkey(PasskeyPayload {
111 origin, other_keys
112 })) => (origin, other_keys),
113 _ => (None, None),
114 };
115
116 let client_data = ClientData::new(
117 base64_to_url(message.to_base64().as_str()),
118 origin.unwrap_or(info_ext.origin),
119 info_ext.cross_origin,
120 other_keys
121 );
122
123 Credential::Passkey(PasskeyCredential {
124 id,
125 signature,
126 client_data,
127 pubkey: Some(info_ext.pubkey),
128 authenticator_data: info_ext.authenticator_data,
129 user_handle: info_ext.user_handle,
130 })
131 },
132 #[cfg(feature = "eth_typed_data")]
133 CredentialName::EthTypedData => {
134 use saa_auth::eth::{Eip712Domain, EthTypedData};
135 use saa_common::{from_json, InfoExtension, PayloadExtension};
136
137 let Some(InfoExtension::EthTypedData(info_ext)) = info.extension else {
138 return Err(saa_common::CredentialError::NoInfoExt(CredentialName::EthTypedData))
139 };
140
141 let (
142 types,
143 primary_type,
144 domain
145 ) = if let Some(PayloadExtension::EthTypedData(pay_ext)) = payload {
146 (
147 pay_ext.types,
148 pay_ext.primary_type,
149 pay_ext.domain
150 )
151 } else {
152 (None, None, None)
153 };
154
155
156 let types = types
157 .ok_or_else(|| saa_common::CredentialError::InvalidProperty(
158 CredentialName::EthTypedData, "types".into(), "Payload is missing or has invalid Eip712 types".into()
159 ))?;
160
161 let domain = domain
162 .ok_or_else(|| saa_common::CredentialError::InvalidProperty(
163 CredentialName::EthTypedData, "domain".into(), "Payload is missing or has invalid Eip712 domain".into()
164 ))?;
165
166 Credential::EthTypedData(EthTypedData {
167 signer: id,
168 types,
169 signature,
170 domain,
171 primary_type: primary_type.ok_or(
172 saa_common::CredentialError::NoInfoProperty(
173 CredentialName::EthTypedData, "primary_type".into()
174 )
175 )?,
176 message: from_json(&message)
177 .map_err(|e| saa_common::CredentialError::InvalidProperty(
178 CredentialName::EthTypedData, "message".into(), e.to_string()
179 ))?,
180 message_property: None,
181 cache: Some(info_ext),
182 #[cfg(all(feature = "wasm", target_arch = "wasm32"))]
183 check_cw2 : None,
184 })
185 },
186
187 };
188
189 Ok(credential) */
190}
191
192