Skip to main content

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