#[cfg(not(feature = "std"))]
use alloc::{borrow::Cow, format};
#[cfg(feature = "std")]
use std::borrow::Cow;
use hmac::Hmac;
use sha2::Sha512;
use super::normalize_utf8;
const PBKDF2_ROUNDS: u32 = 2048;
const PBKDF2_BYTES: usize = 64;
pub fn to_seed(normalized_phrase: &str, passphrase: &str) -> [u8; 64] {
let normalized_password = normalized_phrase;
let normalized_salt = {
let mut salt = Cow::Owned(format!("mnemonic{}", passphrase));
normalize_utf8(&mut salt);
salt
};
let mut seed = [0u8; PBKDF2_BYTES];
pbkdf2::pbkdf2::<Hmac<Sha512>>(
normalized_password.as_bytes(),
normalized_salt.as_bytes(),
PBKDF2_ROUNDS,
&mut seed,
)
.expect("HMAC can be initialized with any key length");
seed
}