Error

Enum Error 

Source
pub enum Error {
    InvalidEntropyLength {
        length: usize,
    },
    InvalidMnemonic {
        reason: String,
    },
    InvalidWordCount {
        count: usize,
    },
    InvalidWord {
        word: String,
        position: usize,
    },
    InvalidChecksum,
    RandomGeneration,
    Bip39Error {
        message: String,
    },
}
Expand description

Comprehensive error types for BIP39 mnemonic operations.

This enum represents all possible errors that can occur when working with BIP39 mnemonics, from entropy generation to seed derivation.

§Error Categories

Variants§

§

InvalidEntropyLength

The provided entropy has an invalid length.

BIP39 requires entropy to be one of the following lengths:

  • 16 bytes (128 bits) → 12 words
  • 20 bytes (160 bits) → 15 words
  • 24 bytes (192 bits) → 18 words
  • 28 bytes (224 bits) → 21 words
  • 32 bytes (256 bits) → 24 words

§Example

let error = Error::InvalidEntropyLength { length: 10 };
println!("{}", error); // "Invalid entropy length: 10 bytes. Valid lengths are..."

Fields

§length: usize

The actual length of the invalid entropy in bytes

§

InvalidMnemonic

The provided mnemonic phrase is invalid.

This error occurs when a mnemonic phrase fails general validation, such as having the wrong format, length, or structure.

§Example

let error = Error::InvalidMnemonic {
    reason: "Too few words".to_string()
};

Fields

§reason: String

Detailed reason why the mnemonic is invalid

§

InvalidWordCount

The provided word count is not supported.

BIP39 supports only specific word counts that correspond to valid entropy lengths. See InvalidEntropyLength for the mapping.

Fields

§count: usize

The invalid word count provided

§

InvalidWord

A word in the mnemonic phrase is not in the BIP39 word list.

Each word in a BIP39 mnemonic must be from the official 2048-word list. This error provides both the invalid word and its position for debugging.

§Example

let error = Error::InvalidWord {
    word: "invalidword".to_string(),
    position: 5,
};
println!("{}", error); // "Invalid word 'invalidword' at position 5"

Fields

§word: String

The invalid word that was found

§position: usize

Zero-based position of the invalid word in the phrase

§

InvalidChecksum

The mnemonic phrase has an invalid checksum.

BIP39 mnemonics include a checksum derived from the entropy. This error occurs when the checksum verification fails, indicating the mnemonic may be corrupted or incorrectly generated.

§

RandomGeneration

Error occurred during random number generation.

This error is automatically converted from rand::Error and indicates a failure in the random number generator used for entropy generation.

§

Bip39Error

Error from the underlying BIP39 crate.

This error wraps errors from the external bip39 crate that we use for some low-level operations.

Fields

§message: String

Error message from the underlying BIP39 crate

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Convert from rand::Error to our Error type.

Source§

fn from(_error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Convert from bip39_upstream::Error to our Error type.

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Error

Custom equality implementation for Error.

This implementation allows comparing errors for equality, which is useful in tests and error matching. For errors containing external types (like rand::Error or bip39_upstream::Error), we compare only by error type since the wrapped errors may not implement PartialEq.

§Examples

let error1 = Error::InvalidWordCount { count: 12 };
let error2 = Error::InvalidWordCount { count: 12 };
let error3 = Error::InvalidWordCount { count: 15 };

assert_eq!(error1, error2);  // Same variant and data
assert_ne!(error1, error3);  // Same variant, different data
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Error

Marker trait indicating that Error can be compared for equality.

This is automatically implemented since we provide PartialEq.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V