Skip to main content

kobe_primitives/
error.rs

1//! Error types for core wallet operations.
2
3#[cfg(feature = "alloc")]
4use alloc::string::String;
5
6/// Errors produced by core wallet and key-derivation operations.
7///
8/// The four variants partition errors by domain:
9///
10/// - [`Mnemonic`](Self::Mnemonic): BIP-39 decode / encode failures.
11/// - [`Path`](Self::Path): invalid or malformed derivation paths.
12/// - [`Crypto`](Self::Crypto): underlying cryptographic primitive failures
13///   (HMAC, SLIP-10 / BIP-32 key math, PBKDF2).
14/// - [`Input`](Self::Input): caller-supplied inputs that fail validation
15///   (word count, hex encoding, empty password, prefix expansion, index overflow).
16#[derive(Debug, thiserror::Error)]
17#[non_exhaustive]
18pub enum DeriveError {
19    /// BIP-39 mnemonic decoding / encoding failed.
20    #[error("mnemonic: {0}")]
21    Mnemonic(#[cfg_attr(feature = "std", from)] bip39::Error),
22
23    /// Derivation path is malformed or unsupported.
24    #[cfg(feature = "alloc")]
25    #[error("derivation path: {0}")]
26    Path(String),
27
28    /// A cryptographic primitive (HMAC, SLIP-10, BIP-32, PBKDF2) failed.
29    #[cfg(feature = "alloc")]
30    #[error("cryptographic operation failed: {0}")]
31    Crypto(String),
32
33    /// Caller-supplied input failed validation (word count, hex, index, etc.).
34    #[cfg(feature = "alloc")]
35    #[error("invalid input: {0}")]
36    Input(String),
37}
38
39#[cfg(not(feature = "std"))]
40impl From<bip39::Error> for DeriveError {
41    fn from(e: bip39::Error) -> Self {
42        Self::Mnemonic(e)
43    }
44}