Skip to content

Commit e619f61

Browse files
authored
Merge pull request #18 from semaphore-protocol/doc-publish
docs: enhance README with detailed installation and usage instruction…
2 parents 642e1df + f91ff0e commit e619f61

File tree

1 file changed

+105
-5
lines changed

1 file changed

+105
-5
lines changed

README.md

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,117 @@
6767

6868
All 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+
### 📜 Usage
82+
83+
#### Semaphore Identity
84+
85+
- Generate a semaphore identity from a string
86+
```rust
87+
use semaphore_rs::identity::Identity;
88+
let identity = Identity::new("secret".as_bytes());
89+
```
90+
- Get the identity commitment
91+
```rust
92+
identity.commitment()
93+
```
94+
- Get the identity private key
95+
```rust
96+
identity.private_key()
97+
```
98+
99+
#### Semaphore Group
100+
101+
- Generate a group member from an identity
102+
103+
```rust
104+
use semaphore_rs::utils::to_element;
105+
let member = to_element(*identity.commitment())
106+
```
107+
108+
- Generate a semaphore group from members
109+
```rust
110+
use semaphore_rs::group::{Element, Group};
111+
const MEMBER1: Element = [1; 32];
112+
const MEMBER2: Element = [2; 32];
113+
let group = Group::new(&[
114+
MEMBER1,
115+
MEMBER2,
116+
to_element(*identity.commitment())
117+
]).unwrap();
118+
```
119+
- Get the group root
120+
```rust
121+
let root = group.root();
122+
```
123+
124+
#### Semaphore Proof
125+
126+
- Generate a semaphore proof
127+
128+
```rust
129+
use semaphore_rs::proof::GroupOrMerkleProof;
130+
use semaphore_rs::proof::Proof;
131+
132+
let message = "message";
133+
let scope = "scope";
134+
let tree_depth = 20;
135+
let proof = Proof::generate_proof(
136+
identity,
137+
GroupOrMerkleProof::Group(group),
138+
message.to_string(),
139+
scope.to_string(),
140+
tree_depth as u16,
141+
)
142+
.unwrap();
143+
```
144+
145+
- Verify a semaphore proof
146+
```rust
147+
let valid = Proof::verify_proof(proof);
148+
```
149+
150+
#### Serde
151+
152+
- Please enable the feature in the `Cargo.toml`
153+
154+
```toml
155+
semaphore-rs = { version = "0.1", features = ["serde"] }
156+
```
157+
158+
- Serialize a semaphore proof
159+
```rust
160+
let proof_json = proof.export().unwrap();
161+
```
162+
- Deserialize a semaphore proof
163+
```rust
164+
use semaphore_rs::proof::SemaphoreProof;
165+
let proof_imported = SemaphoreProof::import(&proof_json).unwrap();
166+
```
167+
168+
## Development
169+
170+
### 🛠 Install
71171

72172
Clone this repository:
73173

74174
```sh
75175
git clone https://github.com/semaphore-protocol/semaphore-rs
76176
```
77177

78-
## 📜 Usage
178+
### 📜 Usage
79179

80-
### Code quality and formatting
180+
#### Code quality and formatting
81181

82182
Run [Rustfmt](https://github.com/rust-lang/rustfmt) to automatically format the code
83183

@@ -91,13 +191,13 @@ Run [rust-clippy](https://github.com/rust-lang/rust-clippy) to catch common mist
91191
cargo clippy
92192
```
93193

94-
### Testing
194+
#### Testing
95195

96196
```bash
97197
cargo test
98198
```
99199

100-
### Update `witness_graph` with [`circom-witnesscalc`](https://github.com/iden3/circom-witnesscalc)
200+
#### Update `witness_graph` with [`circom-witnesscalc`](https://github.com/iden3/circom-witnesscalc)
101201

102202
```bash
103203
./script build_witness_graph.sh

0 commit comments

Comments
 (0)