subxt_signer/crypto/
seed_from_entropy.rs1use alloc::string::String;
6use hmac::Hmac;
7use pbkdf2::pbkdf2;
8use sha2::Sha512;
9use zeroize::Zeroize;
10
11#[allow(dead_code)]
15pub fn seed_from_entropy(entropy: &[u8], password: &str) -> Option<[u8; 64]> {
16 if entropy.len() < 16 || entropy.len() > 32 || entropy.len() % 4 != 0 {
17 return None;
18 }
19
20 let mut salt = String::with_capacity(8 + password.len());
21 salt.push_str("mnemonic");
22 salt.push_str(password);
23
24 let mut seed = [0u8; 64];
25
26 pbkdf2::<Hmac<Sha512>>(entropy, salt.as_bytes(), 2048, &mut seed).ok()?;
27
28 salt.zeroize();
29
30 Some(seed)
31}