Thanks to visit codestin.com
Credit goes to lib.rs

7 releases (4 breaking)

0.5.0 Jun 2, 2025
0.4.0 May 8, 2025
0.3.2 Mar 18, 2025
0.3.1 Feb 10, 2025
0.1.0 Jan 27, 2025

#6 in #worldcoin

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

2,580 downloads per month
Used in 2 crates (via walletkit-core)

MIT license

1.5MB
7.5K SLoC

🦀 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:

semaphore = { git = "https://github.com/worldcoin/semaphore-rs" }

Building semaphore circuits

  1. Check out submodule (if not done before already): git submodule update --init --recursive
  2. Install semaphore dependencies cd semaphore && npm install
  3. Compile circuits npm exec ts-node ./scripts/compile-circuits.ts
  4. You'll find the zkey and wasm file in semaphore/build/snark

Example

Example as in src/lib.rs, run with cargo test.

use semaphore_rs::{get_supported_depths, hash_to_field, Field, identity::Identity,
                poseidon_tree::LazyPoseidonTree, protocol::*};
use num_bigint::BigInt;

// generate identity
let mut secret = *b"secret";
let id = Identity::from_secret(&mut secret, None);

// Get the first available tree depth. This is controlled by the crate features.
let depth = get_supported_depths()[0];

// generate merkle tree
let leaf = Field::from(0);
let mut tree = LazyPoseidonTree::new(depth, leaf).derived();
tree = tree.update(0, &id.commitment());

let merkle_proof = tree.proof(0);
let root = tree.root();

// change signal and external_nullifier here
let signal_hash = hash_to_field(b"xxx");
let external_nullifier_hash = hash_to_field(b"appId");

let nullifier_hash = generate_nullifier_hash(&id, external_nullifier_hash);

let proof = generate_proof(&id, &merkle_proof, external_nullifier_hash, signal_hash).unwrap();
let success = verify_proof(root, nullifier_hash, signal_hash, external_nullifier_hash, &proof, depth).unwrap();

assert!(success);

Dependencies

~19–53MB
~826K SLoC