Skip to content

Commit 29e8f58

Browse files
authored
Merge pull request #312 from semaphore-protocol/feat/nullifier-hash
New function to calculate nullifier hash Former-commit-id: 946ac83
2 parents 26c76f4 + 9a1a1e7 commit 29e8f58

File tree

13 files changed

+78
-8
lines changed

13 files changed

+78
-8
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ jobs:
4141
with:
4242
build_dir: docs
4343
jekyll: false
44+
fqdn: js.semaphore.appliedzkp.org
4445
env:
4546
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
9494
<a href="/packages/identity">
9595
@semaphore-protocol/identity
9696
</a>
97-
<a href="https://semaphore-protocol.github.io/semaphore/identity">
97+
<a href="https://js.semaphore.appliedzkp.org/identity">
9898
(docs)
9999
</a>
100100
</td>
@@ -116,7 +116,7 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
116116
<a href="/packages/group">
117117
@semaphore-protocol/group
118118
</a>
119-
<a href="https://semaphore-protocol.github.io/semaphore/group">
119+
<a href="https://js.semaphore.appliedzkp.org/group">
120120
(docs)
121121
</a>
122122
</td>
@@ -138,7 +138,7 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
138138
<a href="/packages/proof">
139139
@semaphore-protocol/proof
140140
</a>
141-
<a href="https://semaphore-protocol.github.io/semaphore/proof">
141+
<a href="https://js.semaphore.appliedzkp.org/proof">
142142
(docs)
143143
</a>
144144
</td>
@@ -160,7 +160,7 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
160160
<a href="/packages/data">
161161
@semaphore-protocol/data
162162
</a>
163-
<a href="https://semaphore-protocol.github.io/semaphore/data">
163+
<a href="https://js.semaphore.appliedzkp.org/data">
164164
(docs)
165165
</a>
166166
</td>
@@ -220,7 +220,7 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
220220
<a href="/packages/heyauthn">
221221
@semaphore-protocol/heyauthn
222222
</a>
223-
<a href="https://semaphore-protocol.github.io/semaphore/heyauthn">
223+
<a href="https://js.semaphore.appliedzkp.org/heyauthn">
224224
(docs)
225225
</a>
226226
</td>

packages/data/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<a href="https://npmjs.org/package/@semaphore-protocol/data">
1919
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/data.svg?style=flat-square" />
2020
</a>
21+
<a href="https://js.semaphore.appliedzkp.org/data">
22+
<img alt="Documentation typedoc" src="https://img.shields.io/badge/docs-typedoc-744C7C?style=flat-square">
23+
</a>
2124
<a href="https://eslint.org/">
2225
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
2326
</a>

packages/group/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<a href="https://npmjs.org/package/@semaphore-protocol/group">
1919
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/group.svg?style=flat-square" />
2020
</a>
21+
<a href="https://js.semaphore.appliedzkp.org/group">
22+
<img alt="Documentation typedoc" src="https://img.shields.io/badge/docs-typedoc-744C7C?style=flat-square">
23+
</a>
2124
<a href="https://eslint.org/">
2225
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
2326
</a>

packages/heyauthn/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<a href="https://npmjs.org/package/@semaphore-protocol/heyauthn">
1919
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/heyauthn.svg?style=flat-square" />
2020
</a>
21+
<a href="https://js.semaphore.appliedzkp.org/heyauthn">
22+
<img alt="Documentation typedoc" src="https://img.shields.io/badge/docs-typedoc-744C7C?style=flat-square">
23+
</a>
2124
<a href="https://eslint.org/">
2225
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
2326
</a>

packages/identity/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<a href="https://npmjs.org/package/@semaphore-protocol/identity">
1919
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/identity.svg?style=flat-square" />
2020
</a>
21+
<a href="https://js.semaphore.appliedzkp.org/identity">
22+
<img alt="Documentation typedoc" src="https://img.shields.io/badge/docs-typedoc-744C7C?style=flat-square">
23+
</a>
2124
<a href="https://eslint.org/">
2225
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
2326
</a>

packages/proof/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<a href="https://npmjs.org/package/@semaphore-protocol/proof">
1919
<img alt="Downloads" src="https://img.shields.io/npm/dm/@semaphore-protocol/proof.svg?style=flat-square" />
2020
</a>
21+
<a href="https://js.semaphore.appliedzkp.org/proof">
22+
<img alt="Documentation typedoc" src="https://img.shields.io/badge/docs-typedoc-744C7C?style=flat-square">
23+
</a>
2124
<a href="https://eslint.org/">
2225
<img alt="Linter eslint" src="https://img.shields.io/badge/linter-eslint-8080f2?style=flat-square&logo=eslint" />
2326
</a>
@@ -67,7 +70,13 @@ yarn add @semaphore-protocol/identity @semaphore-protocol/group @semaphore-proto
6770

6871
## 📜 Usage
6972

70-
\# **generateProof**(identity: _Identity_, group: _Group_ | _MerkleProof_, externalNullifier: _BigNumberish_, signal: _string_, snarkArtifacts?: _SnarkArtifacts_): Promise\<_SemaphoreFullProof_>
73+
\# **generateProof**(
74+
identity: _Identity_,
75+
group: _Group_ | _MerkleProof_,
76+
externalNullifier: _BytesLike | Hexable | number | bigint_,
77+
signal: _BytesLike | Hexable | number | bigint_,
78+
snarkArtifacts?: _SnarkArtifacts_
79+
): Promise\<_SemaphoreFullProof_>
7180

7281
```typescript
7382
import { Identity } from "@semaphore-protocol/identity"
@@ -98,3 +107,18 @@ import { verifyProof } from "@semaphore-protocol/proof"
98107

99108
await verifyProof(fullProof, 20)
100109
```
110+
111+
\# **calculateNullifierHash**(
112+
identityNullifier: _bigint | number | string_,
113+
externalNullifier: \__BytesLike | Hexable | number | bigint_
114+
): bigint
115+
116+
```typescript
117+
import { Identity } from "@semaphore-protocol/identity"
118+
import { calculateNullifierHash } from "@semaphore-protocol/proof"
119+
120+
const identity = new Identity()
121+
const externalNullifier = utils.formatBytes32String("Topic")
122+
123+
const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier)
124+
```

packages/proof/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
"access": "public"
3131
},
3232
"devDependencies": {
33+
"@rollup/plugin-commonjs": "^24.1.0",
3334
"@rollup/plugin-json": "^5.0.1",
35+
"@rollup/plugin-node-resolve": "^15.0.2",
3436
"ffjavascript": "^0.2.54",
37+
"poseidon-lite": "^0.2.0",
3538
"rollup-plugin-cleanup": "^3.2.1",
3639
"rollup-plugin-typescript2": "^0.31.2",
3740
"typedoc": "^0.22.11"

packages/proof/rollup.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import typescript from "rollup-plugin-typescript2"
2+
import commonjs from "@rollup/plugin-commonjs"
23
import * as fs from "fs"
34
import cleanup from "rollup-plugin-cleanup"
45
import json from "@rollup/plugin-json"
6+
import { nodeResolve } from "@rollup/plugin-node-resolve"
57

68
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"))
79
const banner = `/**
@@ -25,6 +27,8 @@ export default {
2527
tsconfig: "./build.tsconfig.json",
2628
useTsconfigDeclarationDir: true
2729
}),
30+
commonjs(),
31+
nodeResolve(),
2832
cleanup({ comments: "jsdoc" }),
2933
json()
3034
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { BytesLike, Hexable } from "@ethersproject/bytes"
2+
import { poseidon2 } from "poseidon-lite/poseidon2"
3+
import hash from "./hash"
4+
5+
/**
6+
* Given the identity nullifier and the external nullifier, it calculates nullifier hash.
7+
* @param identityNullifier The identity nullifier.
8+
* @param externalNullifier The external nullifier.
9+
* @returns The nullifier hash.
10+
*/
11+
export default function calculateNullifierHash(
12+
identityNullifier: number | bigint | string,
13+
externalNullifier: BytesLike | Hexable | number | bigint
14+
): bigint {
15+
return poseidon2([hash(externalNullifier), identityNullifier])
16+
}

0 commit comments

Comments
 (0)