etopay_sdk/types/
users.rs

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