use crate::base::misc::brorand::Brorand;
use crate::base::data::constants::PASSWORD_LEN;
use crate::WalletType;
use crate::base::wallet::generate_str;
use crate::base::wallet::keypair::*;
static H_SECP256K1: &[u8] = &[33];
static H_ED25519: &[u8] = &[33];
pub struct Seed {}
impl Seed {
pub fn build(wtype: &WalletType) -> String {
let u: Vec<u8> = Brorand::brorand(PASSWORD_LEN);
let mut version: Vec<u8>; match wtype {
&WalletType::ED25519 => {
version = H_ED25519.to_vec();
},
&WalletType::SECP256K1 => {
version = H_SECP256K1.to_vec();
},
}
generate_str(&mut version, &u)
}
}
impl Seed {
pub fn check_secret(seed: &String) -> Option<bool> {
let key_pair = KeypairBuilder::new(&seed, &WalletType::SECP256K1).build();
if key_pair.is_ok() {
return Some(true);
}
let key_pair = KeypairBuilder::new(&seed, &WalletType::ED25519).build();
if key_pair.is_ok() {
return Some(true);
}
None
}
}