use super::funejson::Value; use super::auth_recovery_codes_normalise_recovery_code::normalise_recovery_code; use super::crypto_sha256::sha256; use super::encoding_hex_hex_encode::hex_encode; use super::encoding_utf8_utf8_encode::utf8_encode; /// The hex SHA-256 of "fune.recovery-code:" and the normalised code: what to /// store. A fast unsalted hash is enough because each code carries 80 random /// bits. /// /// # Panics /// Panics with "not a recovery code" when the code cannot be normalised. pub fn hash_recovery_code(code: &str) -> String { let normal = match normalise_recovery_code(code) { Some(n) => n, None => panic!("not a recovery code"), }; hex_encode(&sha256(&utf8_encode(&format!("fune.recovery-code:{}", normal)))) } pub fn fune_vector(args: &[Value]) -> Value { let code = match &args[0] { Value::Str(s) => s.clone(), _ => panic!("code must be a string"), }; Value::Str(hash_recovery_code(&code)) }