semaphore_rs/protocol/
authentication.rs

1use crate::{
2    identity::Identity,
3    poseidon_tree::LazyPoseidonTree,
4    protocol::{Proof, ProofError},
5    Field,
6};
7
8pub fn generate_proof(
9    depth: usize,
10    identity: &Identity,
11    ext_nullifier_hash: Field,
12    signal_hash: Field,
13) -> Result<Proof, ProofError> {
14    let merkle_proof = LazyPoseidonTree::new(depth, Field::from(0))
15        .update(0, &identity.commitment())
16        .proof(0);
17    super::generate_proof(identity, &merkle_proof, ext_nullifier_hash, signal_hash)
18}
19
20pub fn verify_proof(
21    depth: usize,
22    id_commitment: Field,
23    nullifier_hash: Field,
24    signal_hash: Field,
25    ext_nullifier_hash: Field,
26    proof: &Proof,
27) -> Result<bool, ProofError> {
28    let root = LazyPoseidonTree::new(depth, Field::from(0))
29        .update(0, &id_commitment)
30        .root();
31    super::verify_proof(
32        root,
33        nullifier_hash,
34        signal_hash,
35        ext_nullifier_hash,
36        proof,
37        depth,
38    )
39}