1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Error types for core wallet operations.
#[cfg(feature = "alloc")]
use alloc::{string::String, vec::Vec};
/// Errors that can occur during wallet operations.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DeriveError {
/// Invalid mnemonic phrase.
#[error("invalid mnemonic: {0}")]
Mnemonic(#[cfg_attr(feature = "std", from)] bip39::Error),
/// Invalid word count for mnemonic.
#[error("invalid word count {0}, must be 12, 15, 18, 21, or 24")]
InvalidWordCount(usize),
/// Empty password provided for camouflage operation.
#[cfg(feature = "camouflage")]
#[error("password must not be empty")]
EmptyPassword,
/// PBKDF2 key derivation failed.
#[cfg(feature = "camouflage")]
#[error("PBKDF2 key derivation failed")]
KeyDerivation,
/// Mnemonic prefix is too short for unambiguous expansion.
#[cfg(feature = "alloc")]
#[error("prefix \"{prefix}\" is too short (minimum {min_len} characters)")]
PrefixTooShort {
/// The prefix that was too short.
prefix: String,
/// Minimum required prefix length.
min_len: usize,
},
/// Mnemonic prefix does not match any word in the wordlist.
#[cfg(feature = "alloc")]
#[error("prefix \"{0}\" does not match any BIP-39 word")]
UnknownPrefix(String),
/// Mnemonic prefix matches multiple words in the wordlist.
#[cfg(feature = "alloc")]
#[error("prefix \"{prefix}\" is ambiguous, matches: {}", candidates.join(", "))]
AmbiguousPrefix {
/// The ambiguous prefix.
prefix: String,
/// Words that match the prefix.
candidates: Vec<String>,
},
/// Index overflow in batch derivation.
#[error("index overflow")]
IndexOverflow,
/// SLIP-10 Ed25519 derivation: invalid seed.
#[cfg(feature = "slip10")]
#[error("SLIP-10: invalid seed length")]
Slip10InvalidSeed,
/// SLIP-10 Ed25519 derivation: invalid path.
#[cfg(feature = "slip10")]
#[error("SLIP-10: {0}")]
Slip10InvalidPath(String),
/// BIP-32 secp256k1 derivation error.
#[cfg(feature = "bip32")]
#[error("BIP-32: {0}")]
Bip32Derivation(String),
/// Stored hex material is malformed.
///
/// Produced by the byte-level accessors on `DerivedAccount` /
/// `DerivedAddress` when decoding their hex fields. Derivers in this
/// workspace never produce malformed hex, so this error indicates
/// externally-constructed data.
#[cfg(feature = "alloc")]
#[error("invalid hex: {0}")]
InvalidHex(String),
}
#[cfg(not(feature = "std"))]
impl From<bip39::Error> for DeriveError {
fn from(e: bip39::Error) -> Self {
Self::Mnemonic(e)
}
}