🦀 semaphore-rs
Rust support library for using semaphore. It's mostly a Rust rewrite of zk-kit, but just focuses on semaphore (for now) and still covers a much smaller scope. It's using ark-circom under the hood for generating the groth16 proofs.
Usage
Add this line to your cargo.toml
:
= { = "https://github.com/worldcoin/semaphore-rs" }
Building semaphore circuits
- Check out submodule (if not done before already):
git submodule update --init --recursive
- Install semaphore dependencies
cd semaphore && npm install
- Compile circuits
npm exec ts-node ./scripts/compile-circuits.ts
- You'll find the
zkey
andwasm
file insemaphore/build/snark
Example
Example as in src/lib.rs
, run with cargo test
.
use ;
use BigInt;
// generate identity
let mut secret = *b"secret";
let id = from_secret;
// Get the first available tree depth. This is controlled by the crate features.
let depth = get_supported_depths;
// generate merkle tree
let leaf = from;
let mut tree = new.derived;
tree = tree.update;
let merkle_proof = tree.proof;
let root = tree.root;
// change signal and external_nullifier here
let signal_hash = hash_to_field;
let external_nullifier_hash = hash_to_field;
let nullifier_hash = generate_nullifier_hash;
let proof = generate_proof.unwrap;
let success = verify_proof.unwrap;
assert!;