From 1db9c3198b0308fe24fa2ac0e07adf06527d9f67 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:01:51 +0100 Subject: [PATCH 1/4] add dummy function for random generated Sietch addresses in SDL --- lib/src/commands.rs | 31 +++++++++++++++++++++++++++++++ lib/src/lightclient.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/lib/src/commands.rs b/lib/src/commands.rs index 9fb69c6..99bd275 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -721,6 +721,36 @@ impl Command for NewAddressCommand { } } +struct NewSietchAddressCommand {} +impl Command for NewSietchAddressCommand { + fn help(&self) -> String { + let mut h = vec![]; + h.push("New Sietch Address"); + h.push("Usage:"); + h.push("sietch [zs]"); + h.push(""); + h.push("Example:"); + h.push("To create a new zdust:"); + h.push("sietch zs"); + h.join("\n") + } + + fn short_help(&self) -> String { + "Create a sietch Address".to_string() + } + + fn exec(&self, args: &[&str], lightclient: &LightClient) -> String { + if args.len() != 1 { + return format!("No address type specified\n{}", self.help()); + } + + match lightclient.do_new_sietchaddress(args[0]) { + Ok(j) => j, + Err(e) => object!{ "error" => e } + }.pretty(2) + } +} + struct NotesCommand {} impl Command for NotesCommand { fn help(&self) -> String { @@ -831,6 +861,7 @@ pub fn get_commands() -> Box>> { map.insert("list".to_string(), Box::new(TransactionsCommand{})); map.insert("notes".to_string(), Box::new(NotesCommand{})); map.insert("new".to_string(), Box::new(NewAddressCommand{})); + map.insert("sietch".to_string(), Box::new(NewSietchAddressCommand{})); map.insert("seed".to_string(), Box::new(SeedCommand{})); map.insert("encrypt".to_string(), Box::new(EncryptCommand{})); map.insert("decrypt".to_string(), Box::new(DecryptCommand{})); diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 7075170..b57b469 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -37,7 +37,7 @@ use crate::ANCHOR_OFFSET; mod checkpoints; -pub const DEFAULT_SERVER: &str = "https://hush-lightwallet.de:443"; +pub const DEFAULT_SERVER: &str = "https://lite.myhush.org"; pub const WALLET_NAME: &str = "silentdragonlite-wallet.dat"; pub const LOGFILE_NAME: &str = "silentdragonlite-wallet.debug.log"; @@ -867,6 +867,31 @@ impl LightClient { Ok(array![new_address]) } + pub fn do_new_sietchaddress(&self, addr_type: &str) -> Result { + if !self.wallet.read().unwrap().is_unlocked_for_spending() { + error!("Wallet is locked"); + return Err("Wallet is locked".to_string()); + } + + let new_address = { + let wallet = self.wallet.write().unwrap(); + + match addr_type { + "zs" => wallet.add_zaddr(), + + _ => { + let e = format!("Unrecognized address type: {}", addr_type); + error!("{}", e); + return Err(e); + } + } + }; + + self.do_save()?; + + Ok(array![new_address]) + } + pub fn clear_state(&self) { // First, clear the state from the wallet self.wallet.read().unwrap().clear_blocks(); From 0ae0994978b1372084e11d650d42cd0e12eaed29 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Mon, 6 Jan 2020 21:38:49 +0100 Subject: [PATCH 2/4] dont store any info for sietch zaddr --- lib/src/lightclient.rs | 2 +- lib/src/lightwallet.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index b57b469..34a76fd 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -877,7 +877,7 @@ impl LightClient { let wallet = self.wallet.write().unwrap(); match addr_type { - "zs" => wallet.add_zaddr(), + "zs" => wallet.add_zaddrdust(), _ => { let e = format!("Unrecognized address type: {}", addr_type); diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 97a7e99..ddd8e6b 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -458,6 +458,22 @@ impl LightWallet { self.extfvks.write().unwrap().push(extfvk); self.zaddress.write().unwrap().push(address); + zaddr + } + pub fn add_zaddrdust(&self) -> String { + if !self.unlocked { + return "".to_string(); + } + + let pos = self.extsks.read().unwrap().len() as u32; + let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&self.seed, Language::English).unwrap(), ""); + + 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); + + zaddr } From 8cf83fae7dab1bc88bc62b36ed7c5527d642122f Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Tue, 7 Jan 2020 16:34:10 +0100 Subject: [PATCH 3/4] create function to add random sietch zaddr --- lib/src/lightwallet.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index ddd8e6b..a70cead 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -4,9 +4,7 @@ use std::cmp; use std::collections::{HashMap, HashSet}; use std::sync::{Arc, RwLock}; use std::io::{Error, ErrorKind}; - use rand::{Rng, rngs::OsRng}; - use log::{info, warn, error}; use protobuf::parse_from_bytes; @@ -199,7 +197,7 @@ impl LightWallet { seed_bytes.copy_from_slice(&phrase.entropy()); } - + // The seed bytes is the raw entropy. To pass it to HD wallet generation, // we need to get the 64 byte bip39 entropy let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&seed_bytes, Language::English).unwrap(), ""); @@ -466,7 +464,23 @@ impl LightWallet { } let pos = self.extsks.read().unwrap().len() as u32; - let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&self.seed, Language::English).unwrap(), ""); + + // Radnom Generator benutzen!!!!!! + + let mut rng = rand::thread_rng(); + let letter: String = rng.gen_range(b'A', b'Z').to_string(); + let number: String = rng.gen_range(0, 999999).to_string(); + // let combi: String = letter.to_string() + number.to_string(); + let s = format!("{}{:06}", letter, number); + //println!("{}", s); + + let my_string = String::from(s); + // let my_immutable_string = &my_string; //This is a &String type + let dust: &str = &my_string; //This is an &str type + + + + let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&self.seed, Language::English).unwrap(), dust); let (_extsk, _extfvk, address) = LightWallet::get_zaddr_from_bip39seed(&self.config, &bip39_seed.as_bytes(), pos); From cf0e418f422f337035af261df4e20d7c9a24ad54 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Wed, 15 Jan 2020 21:48:06 +0100 Subject: [PATCH 4/4] add sietch call --- lib/src/lightclient.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 34a76fd..f3e3211 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -889,7 +889,7 @@ impl LightClient { self.do_save()?; - Ok(array![new_address]) + Ok(array!["sietch",new_address]) } pub fn clear_state(&self) {