1use core::fmt;
2
3use kdk_entropy::EntropyError;
4
5#[derive(Debug)]
7pub enum MnemonicError {
8 InvalidWordCount(u8),
11
12 InvalidEntropyLength(usize),
16
17 Bip39(bip39::Error),
21
22 Entropy(EntropyError),
24}
25
26impl fmt::Display for MnemonicError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 MnemonicError::InvalidWordCount(w) => {
30 write!(f, "invalid or feature-gated BIP39 word count: {w}")
31 }
32 MnemonicError::InvalidEntropyLength(n) => {
33 write!(
34 f,
35 "invalid or feature-gated BIP39 entropy length: {n} bytes"
36 )
37 }
38 MnemonicError::Bip39(_) => write!(f, "bip39 mnemonic conversion failed"),
39 MnemonicError::Entropy(e) => write!(f, "{e}"),
40 }
41 }
42}
43
44impl From<EntropyError> for MnemonicError {
45 fn from(e: EntropyError) -> Self {
46 MnemonicError::Entropy(e)
47 }
48}
49
50impl core::error::Error for MnemonicError {}