Skip to content

semaphore-protocol/semaphore-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

62 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Semaphore icon Rust

Github license GitHub Workflow test Coveralls DeepScan grade Linter eslint Code style prettier Repository top language Commitizen friendly

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.toml

    semaphore-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

About

Semaphore v4 implemented in Rust

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •