40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
|
|
use crate::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
pub struct SavedWallet {
|
||
|
|
pub long_address: String,
|
||
|
|
pub short_address: String,
|
||
|
|
pub vanity_address: Option<String>,
|
||
|
|
pub public_key: String,
|
||
|
|
pub private_key: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||
|
|
pub struct Wallet {
|
||
|
|
pub saved: SavedWallet,
|
||
|
|
pub encryption_key: String,
|
||
|
|
}
|
||
|
|
impl Wallet {
|
||
|
|
pub const FN_DSA_LOGN: u32 = 9;
|
||
|
|
pub const PUBLIC_KEY_LENGTH: usize = 897;
|
||
|
|
pub const PRIVATE_KEY_LENGTH: usize = 1281;
|
||
|
|
pub const SIGNATURE_LENGTH: usize = 666;
|
||
|
|
pub const ADDRESS_BYTES_LENGTH: usize = 1 + Self::PUBLIC_KEY_LENGTH;
|
||
|
|
pub const ADDRESS_HEX_LENGTH: usize = Self::PUBLIC_KEY_LENGTH * 2;
|
||
|
|
pub const SHORT_ADDRESS_HASH_BYTES_LENGTH: usize = 20;
|
||
|
|
pub const SHORT_ADDRESS_BYTES_LENGTH: usize = Self::SHORT_ADDRESS_HASH_BYTES_LENGTH + 2;
|
||
|
|
pub const SHORT_ADDRESS_SEPARATOR: u8 = b'.';
|
||
|
|
|
||
|
|
pub fn display_wallet(&self) -> String {
|
||
|
|
let mut output = format!(
|
||
|
|
"Long Address: {}\nShort Address: {}",
|
||
|
|
self.saved.long_address, self.saved.short_address
|
||
|
|
);
|
||
|
|
if let Some(vanity_address) = &self.saved.vanity_address {
|
||
|
|
output.push_str(&format!("\nVanity Address: {vanity_address}"));
|
||
|
|
}
|
||
|
|
output.push_str(&format!("\nPublic Key: {}", self.saved.public_key));
|
||
|
|
output
|
||
|
|
}
|
||
|
|
}
|