Skip to main content

kobe_eth/
error.rs

1//! Error types for Ethereum wallet operations.
2//!
3//! This module defines all errors that can occur during Ethereum
4//! wallet creation, key derivation, and address generation.
5
6#[cfg(feature = "alloc")]
7use alloc::string::String;
8
9use core::fmt;
10
11/// Errors that can occur during Ethereum wallet operations.
12#[derive(Debug, Clone, PartialEq, Eq)]
13#[non_exhaustive]
14pub enum Error {
15    /// Invalid private key format or value.
16    InvalidPrivateKey,
17    /// Invalid hex string format.
18    InvalidHex,
19    /// Key derivation error with details.
20    #[cfg(feature = "alloc")]
21    Derivation(String),
22    /// Invalid derivation path.
23    #[cfg(feature = "alloc")]
24    InvalidPath(String),
25}
26
27impl fmt::Display for Error {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            Self::InvalidPrivateKey => write!(f, "invalid private key"),
31            Self::InvalidHex => write!(f, "invalid hex string"),
32            #[cfg(feature = "alloc")]
33            Self::Derivation(msg) => write!(f, "key derivation error: {msg}"),
34            #[cfg(feature = "alloc")]
35            Self::InvalidPath(path) => write!(f, "invalid derivation path: {path}"),
36        }
37    }
38}
39
40#[cfg(feature = "std")]
41impl std::error::Error for Error {}