1#![cfg_attr(not(feature = "std"), no_std)]
2
3use saa_schema::wasm_serde;
4mod binary;
5mod errors;
6pub mod utils;
7pub mod messages;
8pub mod hashes;
9pub use errors::*;
10pub use binary::{Binary, to_json_binary, from_json};
11
12
13#[cfg(not(feature = "native"))]
14mod identity;
15
16#[cfg(feature = "storage")]
17pub mod storage;
18
19
20
21#[cfg(any(feature = "std", not(feature = "substrate")))]
22pub use std::{
23 string::{ToString, String},
24 vec, vec::Vec,
25 format
26};
27
28#[cfg(all(not(feature = "std"), feature = "substrate"))]
29pub use ink::prelude::{
30 string::{ToString, String},
31 vec, vec::Vec,
32 format,
33};
34
35#[cfg(feature = "native")]
36pub mod crypto {
37 pub use cosmwasm_crypto::*;
38}
39
40
41
42#[cfg(feature = "cosmwasm")]
43pub mod cosmwasm {
44 pub use cosmwasm_std::{
45 Api, Env, Addr, CanonicalAddr, MessageInfo, Binary,
46 from_json, to_json_binary, CustomMsg,
47 StdError, VerificationError, RecoverPubkeyError
48 };
49 #[cfg(feature = "storage")]
50 pub use cosmwasm_std::Storage;
51 #[cfg(feature = "iterator")]
52 pub use cosmwasm_std::Order;
53}
54
55
56#[cfg(all(feature = "secretwasm", not(feature = "cosmwasm")))]
57pub mod cosmwasm {
58 pub use secretwasm_std::{
59 Api, Env, Addr, CanonicalAddr, MessageInfo, Binary,
60 from_binary as from_json, to_binary as to_json_binary,
61 StdError, VerificationError, RecoverPubkeyError,
62 CustomMsg
63 };
64 #[cfg(feature = "storage")]
65 pub use secretwasm_std::Storage;
66 #[cfg(feature = "iterator")]
67 pub use secretwasm_std::Order;
68}
69
70
71
72
73#[cfg(feature = "substrate")]
74pub mod substrate {
75 pub use ink::env as ink_env;
76 pub use {
77 ink_env::Environment as InkEnvironment,
78 ink::EnvAccess as InkApi,
79 };
80
81 pub mod default {
82 use ink::env as ink_env;
83 pub use ink_env::DefaultEnvironment;
84 pub type AccountId = <DefaultEnvironment as ink_env::Environment>::AccountId;
85 pub type EnvAccess<'a> = ink::EnvAccess<'a, DefaultEnvironment>;
86 }
87}
88
89#[cfg(feature = "wasm")]
90use cosmwasm::*;
91
92#[cfg(feature = "substrate")]
93use substrate::*;
94
95
96#[macro_export]
97macro_rules! ensure {
98 ($cond:expr, $e:expr) => {
99 if !($cond) {
100 return Err(core::convert::From::from($e));
101 }
102 };
103}
104
105
106
107pub trait Verifiable {
108
109 fn id(&self) -> CredentialId;
110
111 fn hrp(&self) -> Option<String> {
112 None
113 }
114
115 fn validate(&self) -> Result<(), AuthError>;
116
117 #[cfg(feature = "native")]
118 fn verify(&self) -> Result<(), AuthError>;
119
120
121 #[cfg(feature = "substrate")]
122 fn verify_ink<'a>(&self, _ : InkApi<'a, impl InkEnvironment>) -> Result<(), AuthError>
123 where Self: Sized
124 {
125 #[cfg(feature = "native")]
126 {
127 self.verify()?;
128 return Ok(());
129 }
130 #[cfg(not(feature = "native"))]
131 Err(AuthError::generic("Not implemented"))
132 }
133
134
135 #[cfg(feature = "wasm")]
136 fn verify_cosmwasm(&self, _: &dyn Api) -> Result<(), AuthError>
137 where Self: Sized
138 {
139 #[cfg(feature = "native")]
140 {
141 self.verify()?;
142 return Ok(());
143 }
144 #[cfg(not(feature = "native"))]
145 Err(AuthError::generic("Not implemented"))
146 }
147
148}
149
150
151#[wasm_serde]
152pub struct CredentialInfo {
153 pub name: CredentialName,
155 pub hrp: Option<String>,
157 pub extension: Option<Binary>,
159}
160
161
162
163#[wasm_serde]
164pub enum CredentialName {
165 Caller,
166 CosmosArbitrary,
167 EthPersonalSign,
168 Passkey,
169 Secp256k1,
170 Secp256r1,
171 Ed25519,
172}
173
174
175pub type CredentialId = Vec<u8>;