#![cfg_attr(not(test), warn(unused_crate_dependencies))]
use eddsa_babyjubjub::EdDSAPrivateKey;
use groth16_material::Groth16Error;
use world_id_primitives::{
AuthenticatorPublicKeySet, TREE_DEPTH, merkle::MerkleInclusionProof,
oprf::WorldIdRequestAuthError,
};
use zeroize::{Zeroize, ZeroizeOnDrop};
pub mod circuit_inputs;
pub mod compress;
pub use compress::ProofCompression;
pub(crate) mod oprf_query;
pub use oprf_query::{FullOprfOutput, OprfEntrypoint};
pub mod proof;
pub use proof::*;
use provekit_common::{InputMap, InputValue, NoirElement};
use world_id_primitives::FieldElement;
#[cfg(any(feature = "zk-ownership-prove", feature = "zk-ownership-verify"))]
pub mod ownership_proof;
pub use provekit_common::{NoirProof, WhirR1CSProof};
#[derive(Debug, thiserror::Error)]
pub enum ProofError {
#[error(transparent)]
RequestAuthError(#[from] WorldIdRequestAuthError),
#[error(transparent)]
OprfError(taceo_oprf::client::Error),
#[error(transparent)]
ProofInputError(#[from] errors::ProofInputError),
#[error(transparent)]
ZkError(#[from] Groth16Error),
#[error("proof generation error: {0}")]
GenerationError(String),
#[error("proof verification error: {0}")]
Verification(String),
#[error(transparent)]
InternalError(#[from] eyre::Report),
}
pub trait NoirCircuitInput {
fn into_witness(self) -> Result<InputMap, ProofError>;
}
pub trait NoirRepresentable {
fn into_noir_value(self) -> InputValue;
}
impl NoirRepresentable for FieldElement {
fn into_noir_value(self) -> InputValue {
InputValue::Field(NoirElement::from_repr(*self))
}
}
impl From<taceo_oprf::client::Error> for ProofError {
fn from(err: taceo_oprf::client::Error) -> Self {
if let taceo_oprf::client::Error::ThresholdServiceError(ref svc) = err
&& svc.kind.is_auth()
{
return Self::RequestAuthError(WorldIdRequestAuthError::from(svc.error_code));
}
Self::OprfError(err)
}
}
#[derive(Zeroize, ZeroizeOnDrop)]
pub struct AuthenticatorProofInput {
#[zeroize(skip)]
pub key_set: AuthenticatorPublicKeySet,
#[zeroize(skip)]
pub inclusion_proof: MerkleInclusionProof<TREE_DEPTH>,
private_key: EdDSAPrivateKey,
pub key_index: u64,
}
impl AuthenticatorProofInput {
#[must_use]
pub const fn new(
key_set: AuthenticatorPublicKeySet,
inclusion_proof: MerkleInclusionProof<TREE_DEPTH>,
private_key: EdDSAPrivateKey,
key_index: u64,
) -> Self {
Self {
key_set,
inclusion_proof,
private_key,
key_index,
}
}
}