1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Wallet types for Tenzro Network
//!
//! This module defines types for wallet management, key storage,
//! and account access.
use crate::primitives::{Address, Timestamp};
use serde::{Deserialize, Serialize};
/// Information about a wallet on Tenzro Network
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WalletInfo {
/// Wallet identifier
pub wallet_id: String,
/// Wallet type
pub wallet_type: WalletType,
/// Accounts associated with this wallet
pub accounts: Vec<Address>,
/// Wallet label/name
pub label: Option<String>,
/// Wallet creation timestamp
pub created_at: Timestamp,
/// Last access timestamp
pub last_accessed: Option<Timestamp>,
}
impl WalletInfo {
/// Creates a new wallet info
pub fn new(wallet_id: String, wallet_type: WalletType) -> Self {
Self {
wallet_id,
wallet_type,
accounts: Vec::new(),
label: None,
created_at: Timestamp::now(),
last_accessed: None,
}
}
/// Adds a label to the wallet
pub fn with_label(mut self, label: String) -> Self {
self.label = Some(label);
self
}
/// Adds an account to the wallet
pub fn add_account(&mut self, address: Address) {
if !self.accounts.contains(&address) {
self.accounts.push(address);
}
}
/// Updates the last accessed timestamp
pub fn update_last_accessed(&mut self) {
self.last_accessed = Some(Timestamp::now());
}
/// Returns the number of accounts in the wallet
pub fn account_count(&self) -> usize {
self.accounts.len()
}
}
/// Type of wallet
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum WalletType {
/// HD (Hierarchical Deterministic) wallet
HD,
/// Single-key wallet
SingleKey,
/// Multi-signature wallet
MultiSig,
/// Hardware wallet
Hardware,
/// Smart contract wallet
SmartContract,
/// Custodial wallet
Custodial,
}
impl WalletType {
/// Returns the wallet type name
pub fn as_str(&self) -> &str {
match self {
Self::HD => "HD",
Self::SingleKey => "Single Key",
Self::MultiSig => "Multi-Signature",
Self::Hardware => "Hardware",
Self::SmartContract => "Smart Contract",
Self::Custodial => "Custodial",
}
}
/// Checks if this wallet type supports multiple accounts
pub fn supports_multiple_accounts(&self) -> bool {
matches!(self, Self::HD | Self::MultiSig | Self::SmartContract | Self::Custodial)
}
}
/// Multi-signature wallet configuration
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MultiSigConfig {
/// Required number of signatures
pub threshold: u32,
/// Total number of signers
pub total_signers: u32,
/// Signer addresses
pub signers: Vec<Address>,
}
impl MultiSigConfig {
/// Creates a new multi-sig configuration
pub fn new(threshold: u32, signers: Vec<Address>) -> Self {
Self {
threshold,
total_signers: signers.len() as u32,
signers,
}
}
/// Validates the configuration
pub fn is_valid(&self) -> bool {
self.threshold > 0
&& self.threshold <= self.total_signers
&& self.signers.len() == self.total_signers as usize
}
/// Checks if an address is a signer
pub fn is_signer(&self, address: &Address) -> bool {
self.signers.contains(address)
}
}