Skip to main content

bulk_keychain/
error.rs

1//! Error types for bulk-keychain
2
3use thiserror::Error;
4
5/// All errors that can occur in bulk-keychain
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Invalid base58 encoding
9    #[error("invalid base58: {0}")]
10    InvalidBase58(String),
11
12    /// Invalid key length (expected 32 bytes for public key, 64 for secret key)
13    #[error("invalid key length: expected {expected}, got {got}")]
14    InvalidKeyLength { expected: usize, got: usize },
15
16    /// Invalid hash length (expected 32 bytes)
17    #[error("invalid hash length: expected 32 bytes, got {0}")]
18    InvalidHashLength(usize),
19
20    /// Invalid signature length (expected 64 bytes)
21    #[error("invalid signature length: expected 64 bytes, got {0}")]
22    InvalidSignatureLength(usize),
23
24    /// Invalid BULK network signature domain
25    #[error("invalid signature domain '{0}'; expected mainnet, testnet, or devnet")]
26    InvalidSignatureDomain(String),
27
28    /// Invalid decimal-string transaction nonce
29    #[error("invalid nonce '{0}'; expected an unsigned 64-bit decimal string")]
30    InvalidNonce(String),
31
32    /// Signing failed
33    #[error("signing failed: {0}")]
34    SigningFailed(String),
35
36    /// Empty orders array
37    #[error("orders array cannot be empty")]
38    EmptyOrders,
39
40    /// Signature count mismatch (for batch finalization)
41    #[error("signature count mismatch: expected {expected}, got {got}")]
42    SignatureMismatch { expected: usize, got: usize },
43
44    /// Invalid order parameters
45    #[error("invalid order: {0}")]
46    InvalidOrder(String),
47
48    /// Serialization error
49    #[error("serialization error: {0}")]
50    SerializationError(String),
51
52    /// JSON parsing error
53    #[error("json error: {0}")]
54    JsonError(#[from] serde_json::Error),
55}
56
57/// Result type alias for bulk-keychain operations
58pub type Result<T> = std::result::Result<T, Error>;