diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 97e9090..0b17703 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -170,6 +170,24 @@ impl LightWallet { (extsk, extfvk, address) } + fn get_sietch_from_bip39seed(config: &LightClientConfig, bip39_seed: &[u8], pos: u32) -> + PaymentAddress { + assert_eq!(bip39_seed.len(), 64); + + let extsk: ExtendedSpendingKey = ExtendedSpendingKey::from_path( + &ExtendedSpendingKey::master(bip39_seed), + &[ + ChildIndex::Hardened(32), + ChildIndex::Hardened(config.get_coin_type()), + ChildIndex::Hardened(pos) + ], + ); + let extfvk = ExtendedFullViewingKey::from(&extsk); + let address = extfvk.default_address().unwrap().1; + + (address) +} + pub fn is_shielded_address(addr: &String, config: &LightClientConfig) -> bool { match address::RecipientAddress::from_str(addr, config.hrp_sapling_address(), @@ -469,10 +487,12 @@ impl LightWallet { zaddr } + + // Add a new Sietch Addr. This will derive a new zdust address from manipluated seed pub fn add_zaddrdust(&self) -> String { - + let mut seed_bytes = [0u8; 32]; let pos = self.extsks.read().unwrap().len() as u32; // Use random generator to create a new Sietch seed every time when call. @@ -485,16 +505,18 @@ impl LightWallet { let dust: &str = &my_string; + let mut system_rng = OsRng; + system_rng.fill(&mut seed_bytes); + + let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&seed_bytes, Language::English).unwrap(), dust); - let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&self.seed, Language::English).unwrap(), dust); + let address = + LightWallet::get_sietch_from_bip39seed(&self.config, &bip39_seed.as_bytes(), pos); - let (_extsk, _extfvk, address) = - LightWallet::get_zaddr_from_bip39seed(&self.config, &bip39_seed.as_bytes(), pos); - - let zaddr = encode_payment_address(self.config.hrp_sapling_address(), &address); + let zdust = encode_payment_address(self.config.hrp_sapling_address(), &address); - zaddr + zdust } /// Add a new t address to the wallet. This will derive a new address from the seed