semaphore_rs/protocol/
authentication.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{
    identity::Identity,
    poseidon_tree::LazyPoseidonTree,
    protocol::{Proof, ProofError},
    Field,
};

pub fn generate_proof(
    depth: usize,
    identity: &Identity,
    ext_nullifier_hash: Field,
    signal_hash: Field,
) -> Result<Proof, ProofError> {
    let merkle_proof = LazyPoseidonTree::new(depth, Field::from(0))
        .update(0, &identity.commitment())
        .proof(0);
    super::generate_proof(identity, &merkle_proof, ext_nullifier_hash, signal_hash)
}

pub fn verify_proof(
    depth: usize,
    id_commitment: Field,
    nullifier_hash: Field,
    signal_hash: Field,
    ext_nullifier_hash: Field,
    proof: &Proof,
) -> Result<bool, ProofError> {
    let root = LazyPoseidonTree::new(depth, Field::from(0))
        .update(0, &id_commitment)
        .root();
    super::verify_proof(
        root,
        nullifier_hash,
        signal_hash,
        ext_nullifier_hash,
        proof,
        depth,
    )
}