Skip to main content

kobe_core/
error.rs

1//! Error types for core wallet operations.
2
3#[cfg(feature = "alloc")]
4use alloc::{string::String, vec::Vec};
5
6/// Errors that can occur during wallet operations.
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// Invalid mnemonic phrase.
11    #[error("invalid mnemonic: {0}")]
12    Mnemonic(#[from] bip39::Error),
13
14    /// Invalid word count for mnemonic.
15    #[error("invalid word count {0}, must be 12, 15, 18, 21, or 24")]
16    InvalidWordCount(usize),
17
18    /// Empty password provided for camouflage operation.
19    #[cfg(feature = "camouflage")]
20    #[error("password must not be empty")]
21    EmptyPassword,
22
23    /// PBKDF2 key derivation failed.
24    #[cfg(feature = "camouflage")]
25    #[error("PBKDF2 key derivation failed")]
26    KeyDerivation,
27
28    /// Mnemonic prefix is too short for unambiguous expansion.
29    #[cfg(feature = "alloc")]
30    #[error("prefix \"{prefix}\" is too short (minimum {min_len} characters)")]
31    PrefixTooShort {
32        /// The prefix that was too short.
33        prefix: String,
34        /// Minimum required prefix length.
35        min_len: usize,
36    },
37
38    /// Mnemonic prefix does not match any word in the wordlist.
39    #[cfg(feature = "alloc")]
40    #[error("prefix \"{0}\" does not match any BIP-39 word")]
41    UnknownPrefix(String),
42
43    /// Mnemonic prefix matches multiple words in the wordlist.
44    #[cfg(feature = "alloc")]
45    #[error("prefix \"{prefix}\" is ambiguous, matches: {}", candidates.join(", "))]
46    AmbiguousPrefix {
47        /// The ambiguous prefix.
48        prefix: String,
49        /// Words that match the prefix.
50        candidates: Vec<String>,
51    },
52
53    /// Index overflow in batch derivation.
54    #[error("index overflow")]
55    IndexOverflow,
56
57    /// SLIP-10 Ed25519 derivation: invalid seed.
58    #[cfg(feature = "slip10")]
59    #[error("SLIP-10: invalid seed length")]
60    Slip10InvalidSeed,
61
62    /// SLIP-10 Ed25519 derivation: invalid path.
63    #[cfg(feature = "slip10")]
64    #[error("SLIP-10: {0}")]
65    Slip10InvalidPath(String),
66
67    /// BIP-32 secp256k1 derivation error.
68    #[cfg(feature = "bip32")]
69    #[error("BIP-32: {0}")]
70    Bip32Derivation(String),
71}