world_id_core/oprf/mod.rs
1//! vOPRF (Verifiable Threshold Oblivious Pseudorandom Function) client implementation.
2//!
3//! Provides functionality for performing OPRF queries with multiple nodes,
4//! including signing queries, managing sessions, and computing `DLog` equality challenges.
5//!
6//! The vOPRF protocol is used to generate nullifiers in a privacy-preserving manner while
7//! not requiring the user to maintain a single secret that cannot be rotated.
8
9use groth16_material::Groth16Error;
10use reqwest::StatusCode;
11
12mod http;
13mod query;
14pub(crate) mod session;
15
16pub use http::{finish_sessions, init_sessions};
17pub use query::{sign_oprf_query, SignedOprfQuery};
18pub use session::{compute_challenges, verify_challenges, Challenge, OprfSessions};
19
20/// Error type for OPRF operations and proof generation.
21#[derive(Debug, thiserror::Error)]
22pub enum ProofError {
23 /// API error returned by the OPRF service.
24 #[error("API error {status}: {message}")]
25 ApiError {
26 /// the HTTP status code
27 status: StatusCode,
28 /// the error message
29 message: String,
30 },
31 /// HTTP or network errors from OPRF service requests.
32 #[error(transparent)]
33 Request(#[from] reqwest::Error),
34 /// Not enough OPRF responses received to satisfy the required threshold.
35 #[error("expected degree {threshold} responses, got {n}")]
36 NotEnoughOprfResponses {
37 /// actual amount responses
38 n: usize,
39 /// expected threshold
40 threshold: usize,
41 },
42 /// The `DLog` equality proof failed verification.
43 #[error("DLog proof could not be verified")]
44 InvalidDLogProof,
45 /// Provided public key index is invalid or out of bounds.
46 #[error("Index in public key is invalid or out of bounds.")]
47 InvalidPublicKeyIndex,
48 /// Errors originating from Groth16 proof generation or verification.
49 #[error(transparent)]
50 ZkError(#[from] Groth16Error),
51 /// Catch-all for other internal errors.
52 #[error(transparent)]
53 InternalError(#[from] eyre::Report),
54}