@semaphore-protocol/proof 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -11
- package/dist/index.mjs +2 -2
- package/dist/index.node.js +2 -2
- package/package.json +10 -6
- package/src/index.test.ts +12 -22
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<a href="https://github.com/semaphore-protocol
|
|
10
|
-
<img src="https://img.shields.io/badge/project-
|
|
9
|
+
<a href="https://github.com/semaphore-protocol">
|
|
10
|
+
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
|
11
11
|
</a>
|
|
12
|
-
<a href="https://github.com/semaphore-protocol/semaphore
|
|
13
|
-
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.
|
|
12
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
|
13
|
+
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
|
14
14
|
</a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/@semaphore-protocol/proof">
|
|
16
16
|
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/proof?style=flat-square" />
|
|
@@ -28,12 +28,20 @@
|
|
|
28
28
|
|
|
29
29
|
<div align="center">
|
|
30
30
|
<h4>
|
|
31
|
-
<a href="https://
|
|
32
|
-
|
|
31
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CONTRIBUTING.md">
|
|
32
|
+
👥 Contributing
|
|
33
|
+
</a>
|
|
34
|
+
<span> | </span>
|
|
35
|
+
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/CODE_OF_CONDUCT.md">
|
|
36
|
+
🤝 Code of conduct
|
|
33
37
|
</a>
|
|
34
38
|
<span> | </span>
|
|
35
|
-
<a href="https://semaphore-protocol
|
|
36
|
-
|
|
39
|
+
<a href="https://github.com/semaphore-protocol/semaphore/contribute">
|
|
40
|
+
🔎 Issues
|
|
41
|
+
</a>
|
|
42
|
+
<span> | </span>
|
|
43
|
+
<a href="https://discord.gg/6mSdGHnstH">
|
|
44
|
+
🗣️ Chat & Support
|
|
37
45
|
</a>
|
|
38
46
|
</h4>
|
|
39
47
|
</div>
|
|
@@ -45,16 +53,16 @@
|
|
|
45
53
|
|
|
46
54
|
### npm or yarn
|
|
47
55
|
|
|
48
|
-
Install the `@semaphore-protocol/proof` package with npm:
|
|
56
|
+
Install the `@semaphore-protocol/proof` package and its peer dependencies with npm:
|
|
49
57
|
|
|
50
58
|
```bash
|
|
51
|
-
npm i @semaphore-protocol/proof
|
|
59
|
+
npm i @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof
|
|
52
60
|
```
|
|
53
61
|
|
|
54
62
|
or yarn:
|
|
55
63
|
|
|
56
64
|
```bash
|
|
57
|
-
yarn add @semaphore-protocol/proof
|
|
65
|
+
yarn add @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof
|
|
58
66
|
```
|
|
59
67
|
|
|
60
68
|
## 📜 Usage
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 2.
|
|
3
|
+
* @version 2.4.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
7
|
-
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/proof}
|
|
8
8
|
*/
|
|
9
9
|
import { poseidon } from 'circomlibjs';
|
|
10
10
|
import { groth16 } from 'snarkjs';
|
package/dist/index.node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/proof
|
|
3
|
-
* @version 2.
|
|
3
|
+
* @version 2.4.0
|
|
4
4
|
* @file A library to generate and verify Semaphore proofs.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
7
|
-
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore
|
|
7
|
+
* @see [Github]{@link https://github.com/semaphore-protocol/semaphore/tree/main/packages/proof}
|
|
8
8
|
*/
|
|
9
9
|
'use strict';
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/proof",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A library to generate and verify Semaphore proofs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
|
-
"repository": "https://github.com/semaphore-protocol/semaphore
|
|
19
|
-
"homepage": "https://github.com/semaphore-protocol/semaphore
|
|
18
|
+
"repository": "https://github.com/semaphore-protocol/semaphore",
|
|
19
|
+
"homepage": "https://github.com/semaphore-protocol/semaphore/tree/main/packages/proof",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
|
22
|
+
},
|
|
20
23
|
"scripts": {
|
|
21
24
|
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
|
22
25
|
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
|
@@ -27,18 +30,19 @@
|
|
|
27
30
|
"access": "public"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"download": "^8.0.0",
|
|
31
33
|
"ffjavascript": "^0.2.54",
|
|
32
34
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
33
35
|
"rollup-plugin-typescript2": "^0.31.2",
|
|
34
36
|
"typedoc": "^0.22.11"
|
|
35
37
|
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@semaphore-protocol/group": "2.4.0",
|
|
40
|
+
"@semaphore-protocol/identity": "2.4.0"
|
|
41
|
+
},
|
|
36
42
|
"dependencies": {
|
|
37
43
|
"@ethersproject/bytes": "^5.7.0",
|
|
38
44
|
"@ethersproject/solidity": "^5.5.0",
|
|
39
45
|
"@ethersproject/strings": "^5.5.0",
|
|
40
|
-
"@semaphore-protocol/group": "2.2.0",
|
|
41
|
-
"@semaphore-protocol/identity": "2.0.0",
|
|
42
46
|
"@zk-kit/incremental-merkle-tree": "0.4.3",
|
|
43
47
|
"circomlibjs": "0.0.8",
|
|
44
48
|
"snarkjs": "^0.4.13"
|
package/src/index.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { formatBytes32String } from "@ethersproject/strings"
|
|
2
2
|
import { Group } from "@semaphore-protocol/group"
|
|
3
3
|
import { Identity } from "@semaphore-protocol/identity"
|
|
4
|
-
import download from "download"
|
|
5
4
|
import { getCurveFromName } from "ffjavascript"
|
|
6
5
|
import fs from "fs"
|
|
7
6
|
import generateNullifierHash from "./generateNullifierHash"
|
|
@@ -12,13 +11,14 @@ import { FullProof } from "./types"
|
|
|
12
11
|
import verifyProof from "./verifyProof"
|
|
13
12
|
|
|
14
13
|
describe("Proof", () => {
|
|
15
|
-
const treeDepth = 20
|
|
14
|
+
const treeDepth = Number(process.env.TREE_DEPTH) || 20
|
|
16
15
|
|
|
17
16
|
const externalNullifier = "1"
|
|
18
17
|
const signal = "0x111"
|
|
19
18
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const wasmFilePath = `./snark-artifacts/semaphore.wasm`
|
|
20
|
+
const zkeyFilePath = `./snark-artifacts/semaphore.zkey`
|
|
21
|
+
const verificationKeyPath = `./snark-artifacts/semaphore.json`
|
|
22
22
|
|
|
23
23
|
const identity = new Identity()
|
|
24
24
|
const identityCommitment = identity.generateCommitment()
|
|
@@ -28,17 +28,7 @@ describe("Proof", () => {
|
|
|
28
28
|
|
|
29
29
|
beforeAll(async () => {
|
|
30
30
|
curve = await getCurveFromName("bn128")
|
|
31
|
-
|
|
32
|
-
if (!fs.existsSync(snarkArtifactsPath)) {
|
|
33
|
-
fs.mkdirSync(snarkArtifactsPath)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
|
|
37
|
-
await download(`${snarkArtifactsUrl}/semaphore.wasm`, snarkArtifactsPath)
|
|
38
|
-
await download(`${snarkArtifactsUrl}/semaphore.zkey`, snarkArtifactsPath)
|
|
39
|
-
await download(`${snarkArtifactsUrl}/semaphore.json`, snarkArtifactsPath)
|
|
40
|
-
}
|
|
41
|
-
}, 10000)
|
|
31
|
+
})
|
|
42
32
|
|
|
43
33
|
afterAll(async () => {
|
|
44
34
|
await curve.terminate()
|
|
@@ -52,8 +42,8 @@ describe("Proof", () => {
|
|
|
52
42
|
|
|
53
43
|
const fun = () =>
|
|
54
44
|
generateProof(identity, group, externalNullifier, signal, {
|
|
55
|
-
wasmFilePath
|
|
56
|
-
zkeyFilePath
|
|
45
|
+
wasmFilePath,
|
|
46
|
+
zkeyFilePath
|
|
57
47
|
})
|
|
58
48
|
|
|
59
49
|
await expect(fun).rejects.toThrow("The identity is not part of the group")
|
|
@@ -75,8 +65,8 @@ describe("Proof", () => {
|
|
|
75
65
|
group.addMembers([BigInt(1), BigInt(2), identityCommitment])
|
|
76
66
|
|
|
77
67
|
fullProof = await generateProof(identity, group, externalNullifier, signal, {
|
|
78
|
-
wasmFilePath
|
|
79
|
-
zkeyFilePath
|
|
68
|
+
wasmFilePath,
|
|
69
|
+
zkeyFilePath
|
|
80
70
|
})
|
|
81
71
|
|
|
82
72
|
expect(typeof fullProof).toBe("object")
|
|
@@ -90,8 +80,8 @@ describe("Proof", () => {
|
|
|
90
80
|
group.addMembers([BigInt(1), BigInt(2), identityCommitment])
|
|
91
81
|
|
|
92
82
|
fullProof = await generateProof(identity, group.generateProofOfMembership(2), externalNullifier, signal, {
|
|
93
|
-
wasmFilePath
|
|
94
|
-
zkeyFilePath
|
|
83
|
+
wasmFilePath,
|
|
84
|
+
zkeyFilePath
|
|
95
85
|
})
|
|
96
86
|
|
|
97
87
|
expect(typeof fullProof).toBe("object")
|
|
@@ -132,7 +122,7 @@ describe("Proof", () => {
|
|
|
132
122
|
|
|
133
123
|
describe("# verifyProof", () => {
|
|
134
124
|
it("Should generate and verify a Semaphore proof", async () => {
|
|
135
|
-
const verificationKey = JSON.parse(fs.readFileSync(
|
|
125
|
+
const verificationKey = JSON.parse(fs.readFileSync(verificationKeyPath, "utf-8"))
|
|
136
126
|
|
|
137
127
|
const response = await verifyProof(verificationKey, fullProof)
|
|
138
128
|
|