etopay_sdk/wallet/
error.rs

1use super::{kdbx::KdbxStorageError, share::ShareError};
2use crate::{backend::error::ApiError, types::error::TypeError, user::error::UserKvStorageError};
3use serde::Serialize;
4
5/// A [`core::result::Result`] with [`WalletError`] as its error variant.
6pub type Result<T> = core::result::Result<T, WalletError>;
7
8#[derive(Debug, Serialize, PartialEq, Clone, Copy)]
9/// Kind of error contained in [`WalletError`]
10pub enum ErrorKind {
11    /// You need to set the password before you can initialize the wallet.
12    MissingPassword,
13    /// You need to set / upload the recovery share before you can initialize the wallet.
14    SetRecoveryShare,
15    /// You need to use the mnemonic or create a wallet before you can use the wallet.
16    UseMnemonic,
17}
18
19/// Wrapper for wallet errors
20#[derive(thiserror::Error, Debug)]
21pub enum WalletError {
22    /// Error occurs if password is missing
23    #[error("Password is missing")]
24    MissingPassword,
25
26    /// Wrong pin or password
27    #[error("Pin or password incorrect.")]
28    WrongPinOrPassword,
29
30    /// Error occurs if the wallet is not initialized
31    #[error("Wallet init error: {0:?}")]
32    WalletNotInitialized(ErrorKind),
33
34    /// Error raises if authentication token is outdated or invalid
35    #[error("Unauthorized: Missing Access Token")]
36    MissingAccessToken,
37
38    /// Error occurs is the transaction is invalid
39    #[error("InvalidTransaction: {0}")]
40    InvalidTransaction(String),
41
42    /// Errors related to the kdbx storage
43    #[error("KdbxStorage error: {0}")]
44    KdbxStorage(#[from] KdbxStorageError),
45
46    /// Error occurs in sdk types
47    #[error("Type errors: {0}")]
48    Type(#[from] TypeError),
49
50    /// User repository error
51    #[error("User repository error: {0}")]
52    UserRepository(#[from] UserKvStorageError),
53
54    /// Error occurred while creating or reconstructing shares
55    #[error("Share error: {0}")]
56    Share(#[from] ShareError),
57
58    /// Error occurred while handling bip39 compliant mnemonics
59    #[error("Bip39 error: {0:?}")]
60    Bip39(#[from] etopay_wallet::bip39::ErrorKind),
61
62    /// Error occurs in sdk backend (api)
63    #[error("BackendApi errors: {0}")]
64    BackendApi(#[from] ApiError),
65
66    /// Error from the wallet impl
67    #[error("WalletImplError: {0}")]
68    WalletImplError(#[from] etopay_wallet::WalletError),
69}