2 releases
Uses new Rust 2024
| 0.1.0 | Oct 7, 2025 |
|---|---|
| 0.1.0-alpha.0 | Oct 6, 2025 |
#30 in #zk
309 downloads per month
5MB
1.5K
SLoC
Rust
| Semaphore is a generic privacy layer. Leveraging zero-knowledge technology, users can prove their membership in groups and send messages (extending from votes to endorsements) off-chain or across EVM-compatible blockchains, all without revealing their personal identity. |
|---|
Semaphore Rust board
All tasks related to the Semaphore Rust implementation are public. You can track their progress, statuses, and additional details in the Semaphore Rust view.
Semaphore Rust Package
🛠 Install
Add this to your Cargo.toml:
[dependencies]
semaphore-protocol = "0.1"
📜 Usage
Semaphore Identity
- Generate a semaphore identity from a string
use semaphore::identity::Identity; let identity = Identity::new("secret".as_bytes()); - Get the identity commitment
identity.commitment() - Get the identity private key
identity.private_key()
Semaphore Group
-
Generate a group member from an identity
use semaphore::utils::to_element; let member = to_element(*identity.commitment()) -
Generate a semaphore group from members
use semaphore::group::{Element, Group}; const MEMBER1: Element = [1; 32]; const MEMBER2: Element = [2; 32]; let group = Group::new(&[ MEMBER1, MEMBER2, to_element(*identity.commitment()) ]).unwrap(); -
Get the group root
let root = group.root();
Semaphore Proof
-
Generate a semaphore proof
use semaphore::proof::GroupOrMerkleProof; use semaphore::proof::Proof; let message = "message"; let scope = "scope"; let tree_depth = 20; let proof = Proof::generate_proof( identity, GroupOrMerkleProof::Group(group), message.to_string(), scope.to_string(), tree_depth as u16, ) .unwrap(); -
Verify a semaphore proof
let valid = Proof::verify_proof(proof);
Serde
-
Please enable the feature in the
Cargo.tomlsemaphore-rs = { version = "0.1", features = ["serde"] } -
Serialize a semaphore proof
let proof_json = proof.export().unwrap(); -
Deserialize a semaphore proof
use semaphore::proof::SemaphoreProof; let proof_imported = SemaphoreProof::import(&proof_json).unwrap();
Development
🛠 Install
Clone this repository:
git clone https://github.com/semaphore-protocol/semaphore-rs
📜 Usage
Code quality and formatting
Run Rustfmt to automatically format the code
cargo fmt --all
Run rust-clippy to catch common mistakes and improve your Rust code.
cargo clippy
Testing
cargo test
Update witness_graph with circom-witnesscalc
./script build_witness_graph.sh
Dependencies
~36–59MB
~1M SLoC