kobe_primitives/error.rs
1//! Unified error type for the entire workspace.
2//!
3//! Every chain crate (`kobe-evm`, `kobe-btc`, `kobe-svm`, …) surfaces its
4//! failures through this single [`DeriveError`] enum, so callers can write
5//! one `match` to handle errors from any chain. No chain defines its own
6//! error type.
7
8#[cfg(feature = "alloc")]
9use alloc::string::String;
10
11/// Errors produced by HD derivation, mnemonic handling, and address encoding.
12///
13/// Variants partition failures by domain:
14///
15/// - [`Mnemonic`](Self::Mnemonic) — BIP-39 decode / encode failures.
16/// - [`Path`](Self::Path) — invalid or malformed derivation paths.
17/// - [`Crypto`](Self::Crypto) — underlying cryptographic primitive failures
18/// (HMAC, BIP-32 / SLIP-10 key math, PBKDF2, BLAKE2, secp256k1, etc.).
19/// - [`Input`](Self::Input) — caller-supplied inputs that fail validation
20/// (word count, hex encoding, empty password, prefix expansion, index
21/// overflow, unknown derivation style).
22/// - [`AddressEncoding`](Self::AddressEncoding) — chain-specific address
23/// encoding failures (Bech32 / Bech32m HRP, base58check, base32, …).
24#[derive(Debug, thiserror::Error)]
25#[non_exhaustive]
26pub enum DeriveError {
27 /// BIP-39 mnemonic decoding / encoding failed.
28 #[error("mnemonic: {0}")]
29 Mnemonic(#[cfg_attr(feature = "std", from)] bip39::Error),
30
31 /// Derivation path is malformed or unsupported.
32 #[cfg(feature = "alloc")]
33 #[error("derivation path: {0}")]
34 Path(String),
35
36 /// A cryptographic primitive (HMAC, BIP-32 / SLIP-10, PBKDF2, BLAKE2,
37 /// secp256k1, …) failed.
38 #[cfg(feature = "alloc")]
39 #[error("cryptographic operation failed: {0}")]
40 Crypto(String),
41
42 /// Caller-supplied input failed validation (word count, hex, index,
43 /// unknown derivation style, …).
44 #[cfg(feature = "alloc")]
45 #[error("invalid input: {0}")]
46 Input(String),
47
48 /// Chain-specific address encoding failed (Bech32 / Bech32m, base58,
49 /// base32, …).
50 #[cfg(feature = "alloc")]
51 #[error("address encoding: {0}")]
52 AddressEncoding(String),
53}
54
55#[cfg(not(feature = "std"))]
56impl From<bip39::Error> for DeriveError {
57 fn from(e: bip39::Error) -> Self {
58 Self::Mnemonic(e)
59 }
60}