6767
6868All tasks related to the Semaphore Rust implementation are public. You can track their progress, statuses, and additional details in the [ Semaphore Rust view] ( https://github.com/orgs/semaphore-protocol/projects/10/views/29 ) .
6969
70- ## 🛠 Install
70+ ## Semaphore Rust Package
71+
72+ ### 🛠 Install
73+
74+ Add this to your ` Cargo.toml ` :
75+
76+ ``` toml
77+ [dependencies ]
78+ semaphore-rs = " 0.1"
79+ ```
80+
81+ ### Semaphore Identity
82+
83+ - Generate a semaphore identity from a string
84+ ``` rust
85+ use semaphore_rs :: identity :: Identity ;
86+ let identity = Identity :: new (" secret" . as_bytes ());
87+ ```
88+ - Get the identity commitment
89+ ```rust
90+ identity . commitment ()
91+ ```
92+ - Get the identity private key
93+ ```rust
94+ identity . private_key ()
95+ ```
96+
97+ ### Semaphore Group
98+
99+ - Generate a group member from an identity
100+
101+ ```rust
102+ use semaphore_rs :: utils :: to_element;
103+ let member = to_element (* identity . commitment ())
104+ ```
105+
106+ - Generate a semaphore group from members
107+ ```rust
108+ use semaphore_rs :: group :: {Element , Group };
109+ const MEMBER1 : Element = [1 ; 32 ];
110+ const MEMBER2 : Element = [2 ; 32 ];
111+ let group = Group :: new (& [
112+ MEMBER1 ,
113+ MEMBER2 ,
114+ to_element (* identity . commitment ())
115+ ]). unwrap ();
116+ ```
117+ - Get the group root
118+ ```rust
119+ let root = group . root ();
120+ ```
121+
122+ ### Semaphore Proof
123+
124+ - Generate a semaphore proof
125+
126+ ```rust
127+ use semaphore_rs :: proof :: GroupOrMerkleProof ;
128+ use semaphore_rs :: proof :: Proof ;
129+
130+ let message = " message" ;
131+ let scope = " scope" ;
132+ let tree_depth = 20 ;
133+ let proof = Proof :: generate_proof (
134+ identity ,
135+ GroupOrMerkleProof :: Group (group ),
136+ message . to_string (),
137+ scope . to_string (),
138+ tree_depth as u16 ,
139+ )
140+ . unwrap ();
141+ ```
142+
143+ - Verify a semaphore proof
144+ ```rust
145+ let valid = Proof :: verify_proof (proof );
146+ ```
147+
148+ ### Serde
149+
150+ - Please enable the feature in the `Cargo . toml`
151+
152+ ```toml
153+ semaphore - rs = { version = " 0.1" , features = [" serde" ] }
154+ ```
155+
156+ - Serialize a semaphore proof
157+ ```rust
158+ let proof_json = proof . export (). unwrap ();
159+ ```
160+ - Deserialize a semaphore proof
161+ ```rust
162+ use semaphore_rs :: proof :: SemaphoreProof ;
163+ let proof_imported = SemaphoreProof :: import (& proof_json ). unwrap ();
164+ ```
165+
166+ ## Development
167+
168+ ### 🛠 Install
71169
72170Clone this repository :
73171
74172```sh
75173git clone https : // github.com/semaphore-protocol/semaphore-rs
76174```
77175
78- ## 📜 Usage
176+ ### 📜 Usage
79177
80- ### Code quality and formatting
178+ #### Code quality and formatting
81179
82180Run [ Rustfmt] ( https://github.com/rust-lang/rustfmt ) to automatically format the code
83181
@@ -91,13 +189,13 @@ Run [rust-clippy](https://github.com/rust-lang/rust-clippy) to catch common mist
91189cargo clippy
92190```
93191
94- ### Testing
192+ #### Testing
95193
96194``` bash
97195cargo test
98196```
99197
100- ### Update ` witness_graph ` with [ ` circom-witnesscalc ` ] ( https://github.com/iden3/circom-witnesscalc )
198+ #### Update ` witness_graph ` with [ ` circom-witnesscalc ` ] ( https://github.com/iden3/circom-witnesscalc )
101199
102200``` bash
103201./script build_witness_graph.sh
0 commit comments