Skip to main content

bsv/auth/
error.rs

1//! Error types for the auth module.
2
3use thiserror::Error;
4
5/// Unified error type for all authentication operations.
6#[derive(Debug, Error)]
7pub enum AuthError {
8    /// Session not found for the given identity key.
9    #[error("session not found: {0}")]
10    SessionNotFound(String),
11
12    /// Peer is not authenticated.
13    #[error("not authenticated: {0}")]
14    NotAuthenticated(String),
15
16    /// Authentication handshake failed.
17    #[error("authentication failed: {0}")]
18    AuthFailed(String),
19
20    /// Received an invalid or malformed message.
21    #[error("invalid message: {0}")]
22    InvalidMessage(String),
23
24    /// Signature verification failed.
25    #[error("invalid signature: {0}")]
26    InvalidSignature(String),
27
28    /// Operation timed out.
29    #[error("timeout: {0}")]
30    Timeout(String),
31
32    /// Transport is not connected.
33    #[error("transport not connected: {0}")]
34    TransportNotConnected(String),
35
36    /// Nonce verification failed.
37    #[error("invalid nonce: {0}")]
38    InvalidNonce(String),
39
40    /// A message replay was detected: this exact `(session, message-nonce)`
41    /// pair has already been accepted. Receiver-side anti-replay guard.
42    #[error("replay detected: {0}")]
43    ReplayDetected(String),
44
45    /// Required certificate is missing.
46    #[error("missing certificate: {0}")]
47    MissingCertificate(String),
48
49    /// Certificate validation failed.
50    #[error("certificate validation error: {0}")]
51    CertificateValidation(String),
52
53    /// Transport-level error.
54    #[error("transport error: {0}")]
55    TransportError(String),
56
57    /// Serialization or deserialization error.
58    #[error("serialization error: {0}")]
59    SerializationError(String),
60
61    /// Error from the wallet layer.
62    #[error("wallet error: {0}")]
63    Wallet(#[from] crate::wallet::WalletError),
64
65    /// Error from the primitives layer.
66    #[error("primitives error: {0}")]
67    Primitives(#[from] crate::primitives::PrimitivesError),
68
69    /// Generic payment flow error (bad header, missing tx, etc.).
70    #[error("payment flow error: {0}")]
71    Payment(String),
72
73    /// Paid request exhausted all retry attempts.
74    #[error("paid request failed after {attempts}/{max_attempts} attempts: {message}")]
75    PaymentFailed {
76        attempts: u32,
77        max_attempts: u32,
78        message: String,
79    },
80}