Browse Source

Fix bip39

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
12c712278e
  1. 2
      Cargo.toml
  2. 13
      src/lightwallet/mod.rs

2
Cargo.toml

@ -25,7 +25,7 @@ byteorder = "1"
rand = "0.5.6"
json = "0.12.0"
shellwords = "1.0.0"
bip39 = "0.6.0-beta.1"
tiny-bip39 = "0.6.2"
clap = "2.33"
secp256k1 = "=0.15.0"
sha2 = "0.8.0"

13
src/lightwallet/mod.rs

@ -151,6 +151,7 @@ impl LightWallet {
pub fn new(seed_phrase: Option<String>, config: &LightClientConfig) -> io::Result<Self> {
use rand::{FromEntropy, ChaChaRng, Rng};
// This is the source entropy that corresponds to the 24-word seed phrase
let mut seed_bytes = [0u8; 32];
if seed_phrase.is_none() {
@ -159,12 +160,15 @@ impl LightWallet {
system_rng.fill(&mut seed_bytes);
} else {
seed_bytes.copy_from_slice(&Mnemonic::from_phrase(seed_phrase.expect("should have a seed phrase"),
Language::English).unwrap().entropy());
Language::English).unwrap().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(), "");
// TODO: This only reads one key for now
println!("{}", hex::encode(seed_bytes));
let ext_t_key = ExtendedPrivKey::with_seed(&seed_bytes).unwrap();
let ext_t_key = ExtendedPrivKey::with_seed(&bip39_seed.as_bytes()).unwrap();
let tpk = ext_t_key
.derive_private_key(KeyIndex::hardened_from_normalize_index(44).unwrap()).unwrap()
.derive_private_key(KeyIndex::hardened_from_normalize_index(1).unwrap()).unwrap() // TODO: Cointype
@ -381,8 +385,7 @@ impl LightWallet {
// Encode into t address
let mut hash160 = ripemd160::Ripemd160::new();
hash160.input(Sha256::digest(&pk.serialize()[..].to_vec()));
// TODO: The taddr version prefix needs to be different for testnet and mainnet
hash160.result().to_base58check(&self.config.base58_pubkey_address(), &[])
}

Loading…
Cancel
Save