1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("Invalid configuration: {0}")]
14 InvalidConfig(String),
15
16 #[error("Invalid party ID: {0}")]
18 InvalidPartyId(usize),
19
20 #[error("Invalid party role: {0}")]
22 InvalidPartyRole(String),
23
24 #[error("Threshold not met: required {required}, got {actual}")]
27 ThresholdNotMet { required: usize, actual: usize },
28
29 #[error("Invalid signing party combination: {0}")]
31 InvalidSigningParties(String),
32
33 #[error("Policy violation: {0}")]
36 PolicyViolation(String),
37
38 #[error("Spending limit exceeded: {limit} {currency} (attempted: {attempted})")]
40 SpendingLimitExceeded {
41 limit: String,
42 attempted: String,
43 currency: String,
44 },
45
46 #[error("Address not whitelisted: {0}")]
48 AddressNotWhitelisted(String),
49
50 #[error("Address is blacklisted: {0}")]
52 AddressBlacklisted(String),
53
54 #[error("Transaction outside allowed time window: {0}")]
56 TimeWindowViolation(String),
57
58 #[error("Contract interaction not allowed: {0}")]
60 ContractNotAllowed(String),
61
62 #[error("Message verification failed: {0}")]
65 VerificationFailed(String),
66
67 #[error("Cryptographic error: {0}")]
69 Crypto(String),
70
71 #[error("Invalid signature: {0}")]
73 InvalidSignature(String),
74
75 #[error("Key share not found: {0}")]
78 KeyShareNotFound(String),
79
80 #[error("Storage error: {0}")]
82 Storage(String),
83
84 #[error("Encryption error: {0}")]
86 Encryption(String),
87
88 #[error("Serialization error: {0}")]
91 Serialization(String),
92
93 #[error("Deserialization error: {0}")]
95 Deserialization(String),
96
97 #[error("Relay error: {0}")]
100 Relay(String),
101
102 #[error("Timeout waiting for {0}")]
104 Timeout(String),
105
106 #[error("Session not found: {0}")]
108 SessionNotFound(String),
109
110 #[error("Session expired: {0}")]
112 SessionExpired(String),
113
114 #[error("Key derivation error: {0}")]
117 Derivation(String),
118
119 #[error("Hardened derivation not supported in threshold setting")]
121 HardenedDerivationNotSupported,
122
123 #[error("Unsupported chain: {0}")]
126 UnsupportedChain(String),
127
128 #[error("Chain error: {0}")]
130 ChainError(String),
131
132 #[error("Internal error: {0}")]
135 Internal(String),
136
137 #[error("IO error: {0}")]
139 Io(#[from] std::io::Error),
140}
141
142impl From<serde_json::Error> for Error {
143 fn from(e: serde_json::Error) -> Self {
144 Error::Serialization(e.to_string())
145 }
146}
147
148impl From<hex::FromHexError> for Error {
149 fn from(e: hex::FromHexError) -> Self {
150 Error::Deserialization(e.to_string())
151 }
152}
153
154#[cfg(test)]
155mod tests {
156 use super::*;
157
158 #[test]
159 fn test_error_display() {
160 let err = Error::SpendingLimitExceeded {
161 limit: "1.0".to_string(),
162 attempted: "2.0".to_string(),
163 currency: "ETH".to_string(),
164 };
165 assert!(err.to_string().contains("1.0"));
166 assert!(err.to_string().contains("2.0"));
167 assert!(err.to_string().contains("ETH"));
168 }
169
170 #[test]
171 fn test_policy_violation() {
172 let err = Error::PolicyViolation("daily limit exceeded".to_string());
173 assert!(err.to_string().contains("daily limit"));
174 }
175}