Skip to main content

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