Skip to main content

world_id_authenticator/
error.rs

1use reqwest::StatusCode;
2use world_id_primitives::{PrimitiveError, ValidationError};
3use world_id_proof::ProofError;
4
5/// Errors that can occur when interacting with the Authenticator.
6#[derive(Debug, thiserror::Error)]
7pub enum AuthenticatorError {
8    /// Primitive error
9    #[error(transparent)]
10    PrimitiveError(#[from] PrimitiveError),
11
12    /// This operation requires a registered account and an account is not registered
13    /// for this authenticator. Call `create_account` first to register it.
14    #[error("Account is not registered for this authenticator.")]
15    AccountDoesNotExist,
16
17    /// An error occurred while interacting with the EVM contract.
18    #[error("Error interacting with EVM contract: {0}")]
19    ContractError(#[from] alloy::contract::Error),
20
21    /// Network/HTTP request error.
22    #[error("Network error: {0}")]
23    NetworkError(#[from] reqwest::Error),
24
25    /// Public key not found in the Authenticator public key set. Usually indicates the local state is out of sync with the registry.
26    #[error("Public key not found.")]
27    PublicKeyNotFound,
28
29    /// Gateway returned an error response.
30    #[error("Gateway error (status {status}): {body}")]
31    GatewayError {
32        /// HTTP status code
33        status: StatusCode,
34        /// Response body
35        body: String,
36    },
37
38    /// Indexer returned an error response.
39    #[error("Indexer error (status {status}): {body}")]
40    IndexerError {
41        /// HTTP status code
42        status: StatusCode,
43        /// Response body
44        body: String,
45    },
46
47    /// Account creation timed out while polling for confirmation.
48    #[error("Account creation timed out")]
49    Timeout,
50
51    /// Configuration is invalid or missing required values.
52    #[error("Invalid configuration for {attribute}: {reason}")]
53    InvalidConfig {
54        /// The config attribute that is invalid.
55        attribute: String,
56        /// Description of why it is invalid.
57        reason: String,
58    },
59
60    /// The provided credential is not valid for the provided proof request.
61    #[error("The provided credential is not valid for the provided proof request")]
62    InvalidCredentialForProofRequest,
63
64    /// The provided credentials do not satisfy the proof request.
65    ///
66    /// This usually means the authenticator made an incorrect selection of credentials.
67    #[error("Proof request cannot be fulfilled with the provided credentials.")]
68    UnfullfilableRequest,
69
70    /// Error during the World ID registration process.
71    ///
72    /// This usually occurs from an on-chain revert.
73    #[error("Registration error ({error_code}): {error_message}")]
74    RegistrationError {
75        /// Error code from the registration process.
76        error_code: String,
77        /// Detailed error message.
78        error_message: String,
79    },
80
81    /// Error on proof generation
82    #[error(transparent)]
83    ProofError(#[from] ProofError),
84
85    /// Indexer returned an authenticator key slot that exceeds supported key capacity.
86    #[error(
87        "Invalid indexer authenticator pubkey slot {slot_index}; max supported slot is {max_supported_slot}"
88    )]
89    InvalidIndexerPubkeySlot {
90        /// Slot index returned by the indexer.
91        slot_index: usize,
92        /// Highest supported slot index.
93        max_supported_slot: usize,
94    },
95
96    /// OHTTP encapsulation or decapsulation error.
97    #[error("OHTTP encapsulation error: {0}")]
98    OhttpEncapsulationError(#[from] ohttp::Error),
99
100    /// Binary HTTP framing error.
101    #[error("Binary HTTP error: {0}")]
102    BhttpError(#[from] bhttp::Error),
103
104    /// The OHTTP relay itself returned a non-success status.
105    #[error("OHTTP relay error (status {status}): {body}")]
106    OhttpRelayError {
107        /// HTTP status code from the relay.
108        status: StatusCode,
109        /// Response body from the relay.
110        body: String,
111    },
112
113    /// A service returned a success status but the response body could not be
114    /// deserialized into the expected type.
115    #[error("Invalid service response: {0}")]
116    InvalidServiceResponse(String),
117
118    /// The assembled proof response failed self-validation against the request.
119    #[error(transparent)]
120    ResponseValidationError(#[from] ValidationError),
121
122    /// Proof materials not loaded. Call `with_proof_materials` before generating proofs.
123    #[error("Proof materials not loaded. Call `with_proof_materials` before generating proofs.")]
124    ProofMaterialsNotLoaded,
125
126    /// The session ID computed for this proof does not match the expected session ID from the proof request.
127    ///
128    /// This indicates the `session_id` provided by the RP is invalid or compromised, or
129    /// the authenticator cached the wrong `session_id_r_seed` for the `oprf_seed`.
130    #[error("the expected session id and the generated session id do not match")]
131    SessionIdMismatch,
132
133    /// Generic error for other unexpected issues.
134    #[error("{0}")]
135    Generic(String),
136}
137
138#[derive(Debug)]
139pub(crate) enum PollResult {
140    Retryable,
141    TerminalError(AuthenticatorError),
142}