etopay_sdk/types/
users.rs

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