[keys] Less convoluted entropy generation

Since const generics aren't in rust yet you have to find some awkward
workarounds. This improves the workaround for specifying entropy length.
This commit is contained in:
LLFourn
2020-09-30 08:17:49 +10:00
parent eae15563d8
commit 490c88934e
2 changed files with 16 additions and 23 deletions

View File

@@ -77,14 +77,14 @@ impl<Ctx: ScriptContext> DerivableKey<Ctx> for Mnemonic {
}
impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic {
const ENTROPY_LENGTH: usize = 32;
type Entropy = [u8; 32];
type Options = (MnemonicType, Language);
type Error = Option<bip39::ErrorKind>;
fn generate_with_entropy<E: AsRef<[u8]>>(
fn generate_with_entropy(
(mnemonic_type, language): Self::Options,
entropy: E,
entropy: Self::Entropy,
) -> Result<GeneratedKey<Self, Ctx>, Self::Error> {
let entropy = &entropy.as_ref()[..(mnemonic_type.entropy_bits() / 8)];
let mnemonic = Mnemonic::from_entropy(entropy, language).map_err(|e| e.downcast().ok())?;