🦀 Rust support library for semaphore
Go to file
Remco Bloemen 67b7f2f9ed Remove cargo lock 2022-03-11 10:54:20 -08:00
snarkfiles remove example circuits 2022-02-08 16:03:11 -10:00
src Fix dep clippies 2022-03-11 10:44:33 -08:00
.gitignore Remove cargo lock 2022-03-11 10:54:20 -08:00
Cargo.toml Fix dep clippies 2022-03-11 10:44:33 -08:00
README.md Fix clippies 2022-03-10 16:06:26 -08:00
criterion.rs Add benchmark 2022-02-28 19:44:30 -08:00
cspell.json Fix clippies 2022-03-10 16:06:26 -08:00
mit-license.md Update crate info 2022-02-01 12:17:05 -08:00
rustfmt.toml Add formating rules 2022-02-01 11:40:49 -08:00

README.md

Semaphore-rs

Rust support library for Semaphore

Example

use semaphore::{
    identity::Identity, hash::Hash, poseidon_tree::PoseidonTree,
    protocol::* };
use num_bigint::BigInt;

// generate identity
let id = Identity::new(b"hello");

// generate merkle tree
const LEAF: Hash = Hash::from_bytes_be([0u8; 32]);

let mut tree = PoseidonTree::new(21, LEAF);
let (_, leaf) = id.commitment().to_bytes_be();
tree.set(0, leaf.into());

let root: BigInt = tree.root().into();
dbg!(root);

let merkle_proof = tree.proof(0).expect("proof should exist");
let root = tree.root().into();

// change signal and external_nullifier here
let signal = b"hello";
let external_nullifier = b"123";

let nullifier_hash = generate_nullifier_hash(&id, external_nullifier);

let config = SnarkFileConfig {
    zkey: "./snarkfiles/semaphore.zkey".to_string(),
    wasm: "./snarkfiles/semaphore.wasm".to_string(),
};

let proof = generate_proof(&config, &id, &merkle_proof, external_nullifier, signal).unwrap();
let success = verify_proof(&config, &root, &nullifier_hash, signal, external_nullifier, &proof).unwrap();