crypto.rs
crypto.rs copied to clipboard
mnemonic_to_seed() accepts any str and verify() also doesn't check for spaces
https://github.com/iotaledger/crypto.rs/blob/752321d556ab7f391d7f3afb98b71adeef6d23b3/src/keys/bip39.rs#L16
accepts any str
and https://github.com/iotaledger/crypto.rs/blob/752321d556ab7f391d7f3afb98b71adeef6d23b3/src/keys/bip39.rs#L195 also accepts mnemonics with a space added.
Should the verify function return an error if there is a space added or should the mnemonic_to_seed function trim spaces? Also speaks anything against calling the verify function inside of mnemonic_to_seed
?
use crypto::{
keys::bip39::{mnemonic_to_seed, wordlist},
utils::rand,
};
fn main() {
let mut entropy = [0u8; 32];
rand::fill(&mut entropy).unwrap();
let mnemonic = wordlist::encode(&entropy, &wordlist::ENGLISH).unwrap();
let mut seed1 = [0u8; 64];
mnemonic_to_seed(&mnemonic, "", &mut seed1);
println!("seed {:?}", seed1);
// add space after mnemonic
let mnemonic_with_space = format!("{} ", mnemonic);
crypto::keys::bip39::wordlist::verify(
&mnemonic_with_space,
&crypto::keys::bip39::wordlist::ENGLISH,
)
.unwrap();
let mut seed2 = [0u8; 64];
mnemonic_to_seed(&mnemonic_with_space, "", &mut seed2);
println!("seed2 {:?}", seed2);
}
returns
seed1 [117, 243, 116, 246, 236, 156, 24, 14, 156, 200, 253, 204, 198, 202, 93, 73, 218, 90, 144, 218, 171, 118, 103, 134, 223, 233, 111, 3, 249, 194, 39, 111, 20, 138, 223, 95, 177, 16, 97, 85, 146, 32, 74, 73, 109, 52, 212, 83, 145, 199, 171, 231, 165, 26, 98, 187, 147, 181, 143, 212, 188, 113, 252, 9]
seed2 [143, 70, 253, 26, 35, 87, 146, 146, 203, 134, 198, 38, 253, 47, 231, 16, 251, 71, 22, 111, 152, 155, 144, 195, 196, 121, 232, 104, 20, 12, 235, 5, 55, 22, 182, 253, 135, 183, 123, 196, 29, 253, 63, 205, 194, 11, 219, 117, 4, 188, 126, 238, 27, 185, 159, 162, 132, 81, 48, 6, 249, 173, 170, 11]