etopay_sdk/types/
users.rs

1use super::newtypes::{EncryptedPassword, EncryptionSalt};
2use crate::{
3    tx_version::VersionedWalletTransaction,
4    types::viviswap::ViviswapState,
5    wallet_manager::{WalletManager, WalletManagerImpl},
6};
7use etopay_wallet::{MnemonicDerivationOption, types::WalletTxInfo};
8use serde::{Deserialize, Serialize};
9
10/// Struct for storing a user in the database
11#[derive(Debug, Deserialize, Serialize, Clone)]
12#[cfg_attr(test, derive(PartialEq))]
13pub struct UserEntity {
14    /// User ID for backend (remove or use for telemetry?)
15    pub user_id: Option<String>,
16    /// Username for DB
17    pub username: String,
18    /// Encrypted Password
19    pub encrypted_password: Option<EncryptedPassword>,
20    /// Salt
21    pub salt: EncryptionSalt,
22    /// User KYC status
23    pub is_kyc_verified: bool,
24    /// User KYC Type
25    pub kyc_type: KycType,
26    /// User Viviswap state
27    pub viviswap_state: Option<ViviswapState>,
28
29    /// The local share from the SSS scheme, stored as a string (same as in the backend)
30    pub local_share: Option<String>,
31
32    /// User wallet transactions (deprecated)
33    pub wallet_transactions: Vec<WalletTxInfo>,
34
35    /// User wallet transactions (versioned)
36    #[serde(default)]
37    pub wallet_transactions_versioned: Vec<VersionedWalletTransaction>,
38}
39
40/// Struct to manage the state of the currently active (initialized) user
41#[derive(Debug)]
42pub struct ActiveUser {
43    /// Username
44    pub username: String,
45
46    /// The user's wallet manager that can create a WalletUser instance from shares.
47    pub wallet_manager: Box<dyn WalletManager + Send + Sync + 'static>,
48
49    /// The currently active [`MnemonicDerivationOption`]
50    pub mnemonic_derivation_options: MnemonicDerivationOption,
51}
52
53impl From<UserEntity> for ActiveUser {
54    fn from(entity: UserEntity) -> Self {
55        ActiveUser {
56            wallet_manager: Box::new(WalletManagerImpl::new(&entity.username)),
57            username: entity.username,
58            mnemonic_derivation_options: Default::default(),
59        }
60    }
61}
62
63/// Represents which kyc method the user uses
64#[derive(Debug, Eq, PartialEq, Deserialize, Serialize, Clone)]
65pub enum KycType {
66    /// Kyc process not selected
67    Undefined,
68
69    /// User use postident for kyc
70    #[cfg(feature = "postident")]
71    Postident,
72
73    /// User use viviswap for kyc
74    #[cfg(feature = "viviswap-kyc")]
75    Viviswap,
76}