Skip to main content

kobe_sol/
error.rs

1//! Error types for Solana wallet operations.
2//!
3//! This module defines all errors that can occur during Solana
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 Solana wallet operations.
12#[derive(Debug, Clone, PartialEq, Eq)]
13#[non_exhaustive]
14pub enum Error {
15    /// Key derivation failed with details.
16    #[cfg(feature = "alloc")]
17    Derivation(String),
18    /// Key derivation failed (no details in no_std).
19    #[cfg(not(feature = "alloc"))]
20    Derivation,
21    /// Invalid seed length.
22    InvalidSeedLength,
23    /// Invalid hex string format.
24    InvalidHex,
25    /// Ed25519 signature error.
26    Signature,
27}
28
29impl fmt::Display for Error {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            #[cfg(feature = "alloc")]
33            Self::Derivation(msg) => write!(f, "derivation error: {msg}"),
34            #[cfg(not(feature = "alloc"))]
35            Self::Derivation => write!(f, "derivation error"),
36            Self::InvalidSeedLength => write!(f, "invalid seed length"),
37            Self::InvalidHex => write!(f, "invalid hex string"),
38            Self::Signature => write!(f, "signature error"),
39        }
40    }
41}
42
43#[cfg(feature = "std")]
44impl std::error::Error for Error {}