1
2mod std_mod {
3 use saa_schema::saa_error;
4
5 #[cfg(feature = "session")]
6 #[saa_error]
7 pub enum SessionError {
8 #[error("The session key has already expired")]
9 Expired,
10
11 #[error("No session key found")]
12 NotFound,
13
14 #[error("Only the owner or session key granter can perform this operation")]
15 NotOwner,
16
17 #[error("This session key wasn't granted to the given grantee")]
18 NotGrantee,
19
20 #[error("Must have both id and name specified")]
21 InvalidGrantee,
22
23 #[error("Invalid data or indifferent from the grantee")]
24 InvalidGranter,
25
26 #[error("Passed a list with no actions. Use AllowedActions::All() if you want to allow all of them")]
27 EmptyCreateActions,
28
29 #[error("No actions passed to execute")]
30 EmptyPassedActions,
31
32 #[error("Couldn't derivate a String result from given message and method")]
33 DerivationError,
34
35 #[error("Invalid actions provided. Check that there are no empty results not dublicates")]
36 InvalidActions,
37
38 #[error("Session creation messages aren't allowed to be in allowed message list")]
39 InnerSessionAction,
40
41 #[error("Current item cant't be used with the given session key")]
42 NotAllowedAction,
43 }
44
45
46 #[cfg(feature = "replay")]
47 #[saa_error]
48 pub enum ReplayError {
49 #[error("{0} is invalid as nonce. Expected: {1}")]
50 DifferentNonce(u64, u64),
51
52 #[error("The provided credential was meant for a different chain")]
53 ChainIdMismatch,
54
55 #[error("The provided credential was meant for a different contract address")]
56 ContractMismatch,
57
58 #[error("Error converting binary to {0}")]
59 Convertion(String),
60 }
61
62
63
64 #[saa_error]
65 pub enum StorageError {
66 #[error("Error reading {0} from storage: {1}")]
67 Read(String, String),
68
69 #[error("Error writing {0} to storage: {1}")]
70 Write(String, String),
71
72 #[error("The given credential already exists on this account")]
73 AlreadyExists,
74
75 #[error("The given credential was not found on this account")]
76 NotFound,
77
78 #[cfg(feature = "wasm")]
79 #[error("Standard error: {0}")]
80 Std(#[from] crate::wasm::StdError),
81
82 #[error("Generic error: {0}")]
83 Generic(String)
84 }
85
86
87
88
89 #[saa_error]
90 pub enum AuthError {
91
92 #[error("No credentials provided or credentials are partially missing")]
93 NoCredentials,
94
95 #[error("{0}")]
96 MissingData(String),
97
98 #[error("Invalid length of {0}. Expected: {1}; Received: {2}")]
99 InvalidLength(String, u16, u16),
100
101 #[error("Values of v other than 27 and 28 not supported. Replay protection (EIP-155) cannot be used here.")]
102 RecoveryParam,
103
104 #[error("Error recovering from the signature: Addresses do not match")]
105 RecoveryMismatch,
106
107 #[error("The signed data is expected to be a replay attach protection envelope")]
108 InvalidSignedData,
109
110 #[error("Passkey challenge must be base64url to base64 encoded string")]
111 PasskeyChallenge,
112
113 #[error("Unauthorized: {0}")]
114 Unauthorized(String),
115
116 #[error("{0}")]
117 Signature(String),
118
119 #[error("{0}")]
120 Recovery(String),
121
122 #[error("{0}")]
123 Generic(String),
124
125 #[error("{0}")]
126 Crypto(String),
127
128 #[error("Error converting binary to {0}")]
129 Convertation(String),
130
131 #[error("Semver parsing error: {0}")]
132 SemVer(String),
133
134 #[cfg(feature = "replay")]
135 #[error("Replay Protection Error: {0}")]
136 Replay(#[from] ReplayError),
137
138 #[cfg(feature = "session")]
139 #[error("Session Error: {0}")]
140 Session(#[from] SessionError),
141
142 #[cfg(feature = "wasm")]
143 #[error("{0}")]
144 Storage(#[from] StorageError),
145 }
146
147
148 impl From<std::string::FromUtf8Error> for AuthError {
149 fn from(err: std::string::FromUtf8Error) -> Self {
150 Self::Recovery(err.to_string())
151 }
152 }
153
154
155 #[cfg(feature = "wasm")]
156 mod wasm {
157 use crate::AuthError;
158
159 impl From<crate::wasm::RecoverPubkeyError> for AuthError {
160 fn from(err: crate::wasm::RecoverPubkeyError) -> Self {
161 Self::Recovery(err.to_string())
162 }
163 }
164
165 impl From<crate::wasm::StdError> for AuthError {
166 fn from(err: crate::wasm::StdError) -> Self {
167 Self::Generic(err.to_string())
168 }
169 }
170
171 impl From<crate::wasm::VerificationError> for AuthError {
172 fn from(err: crate::wasm::VerificationError) -> Self {
173 Self::Crypto(err.to_string())
174 }
175 }
176 }
177
178 #[cfg(feature = "native")]
179 impl From<cosmwasm_crypto::CryptoError> for AuthError {
180 fn from(err: cosmwasm_crypto::CryptoError) -> Self {
181 Self::Crypto(err.to_string())
182 }
183 }
184
185
186}
187
188
189
190#[cfg(not(feature = "std"))]
191mod no_std_mod {
192 use crate::String;
193 use saa_schema::{saa_error, saa_type, strum_macros};
194
195
196 #[cfg(feature = "replay")]
197 pub enum ReplayError {
198 DifferentNonce(u64, u64),
199 ChainIdMismatch,
200 ContractMismatch,
201 }
202
203 #[cfg(feature = "session")]
204 pub enum SessionError {
205 Expired,
206 InvalidGrantee,
207 InvalidGranter,
208 EmptyCreateActions,
209 EmptyPassedActions,
210 DerivationError,
211 InvalidActions,
212 InnerSessionAction,
213 NotAllowedAction,
214 }
215
216
217 #[saa_error]
218 pub enum AuthError {
219 NoCredentials,
220 MissingData(String),
221 InvalidLength(String, u16, u16),
222 RecoveryParam,
223 RecoveryMismatch,
224 InvalidSignedData,
225 PasskeyChallenge,
226 Unauthorized(String),
227 Signature(String),
228 Recovery(String),
229 Generic(String),
230 Convertation(String),
231 Crypto(String),
232 SemVer(String),
233 #[cfg(feature = "replay")]
234 Replay(String),
235 #[cfg(feature = "session")]
236 Session(String),
237 }
238
239 #[cfg(feature = "replay")]
240 impl From<ReplayError> for AuthError {
241 fn from(err: ReplayError) -> Self {
242 Self::Replay(err.to_string())
243 }
244 }
245
246 #[cfg(feature = "session")]
247 impl From<SessionError> for AuthError {
248 fn from(err: SessionError) -> Self {
249 Self::Session(err.to_string())
250 }
251 }
252
253}
254
255
256#[cfg(feature = "std")]
257pub use std_mod::*;
258
259
260#[cfg(not(feature = "std"))]
261pub use no_std_mod::*;
262
263
264
265
266
267impl AuthError {
268 pub fn generic<M: Into<String>>(msg: M) -> Self {
269 AuthError::Generic(msg.into())
270 }
271}
272
273impl From<bech32::primitives::hrp::Error> for AuthError {
274 fn from(err: bech32::primitives::hrp::Error) -> Self {
275 Self::Crypto(err.to_string())
276 }
277}
278
279
280impl From<bech32::EncodeError> for AuthError {
281 fn from(err: bech32::EncodeError) -> Self {
282 Self::Crypto(err.to_string())
283 }
284}
285