@semaphore-protocol/proof 4.0.0-beta.1 → 4.0.0-beta.11
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 +6 -4
- package/dist/index.browser.js +1103 -382
- package/dist/index.node.cjs +1108 -437
- package/dist/index.node.js +1103 -432
- package/dist/types/generate-proof.d.ts +5 -3
- package/dist/types/hash.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/to-bigint.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -16
- package/package.json +11 -12
- package/src/generate-proof.ts +18 -17
- package/src/hash.ts +1 -1
- package/src/index.ts +1 -1
- package/src/to-bigint.ts +2 -2
- package/src/types/index.ts +2 -19
- package/src/verification-keys.json +928 -168
- package/src/verify-proof.ts +5 -11
- package/dist/types/get-snark-artifacts.browser.d.ts +0 -8
- package/dist/types/get-snark-artifacts.node.d.ts +0 -9
- package/src/get-snark-artifacts.browser.ts +0 -18
- package/src/get-snark-artifacts.node.ts +0 -59
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Group, MerkleProof } from "@semaphore-protocol/group";
|
|
2
2
|
import type { Identity } from "@semaphore-protocol/identity";
|
|
3
|
-
import {
|
|
3
|
+
import { type SnarkArtifacts } from "@zk-kit/artifacts";
|
|
4
|
+
import type { BigNumberish } from "ethers";
|
|
5
|
+
import type { SemaphoreProof } from "./types";
|
|
4
6
|
/**
|
|
5
7
|
* It generates a Semaphore proof, i.e. a zero-knowledge proof that an identity that
|
|
6
8
|
* is part of a group has shared an anonymous message.
|
|
@@ -15,10 +17,10 @@ import { BigNumberish, SemaphoreProof, SnarkArtifacts } from "./types";
|
|
|
15
17
|
* or they will be automatically fetched.
|
|
16
18
|
* @param identity The Semaphore identity.
|
|
17
19
|
* @param groupOrMerkleProof The Semaphore group or its Merkle proof.
|
|
18
|
-
* @param scope The Semaphore scope.
|
|
19
20
|
* @param message The Semaphore message.
|
|
21
|
+
* @param scope The Semaphore scope.
|
|
20
22
|
* @param merkleTreeDepth The depth of the tree with which the circuit was compiled.
|
|
21
|
-
* @param snarkArtifacts
|
|
23
|
+
* @param snarkArtifacts See {@link https://zkkit.pse.dev/interfaces/_zk_kit_utils.SnarkArtifacts.html | SnarkArtifacts}.
|
|
22
24
|
* @returns The Semaphore proof ready to be verified.
|
|
23
25
|
*/
|
|
24
26
|
export default function generateProof(identity: Identity, groupOrMerkleProof: Group | MerkleProof, message: BigNumberish | Uint8Array | string, scope: BigNumberish | Uint8Array | string, merkleTreeDepth?: number, snarkArtifacts?: SnarkArtifacts): Promise<SemaphoreProof>;
|
package/dist/types/hash.d.ts
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { packGroth16Proof, unpackGroth16Proof } from "@zk-kit/utils";
|
|
1
|
+
import { packGroth16Proof, unpackGroth16Proof } from "@zk-kit/utils/proof-packing";
|
|
2
2
|
import generateProof from "./generate-proof";
|
|
3
3
|
import verifyProof from "./verify-proof";
|
|
4
4
|
export * from "./types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BigNumberish } from "
|
|
1
|
+
import type { BigNumberish } from "ethers";
|
|
2
2
|
/**
|
|
3
|
-
* Converts a bignumberish to a bigint.
|
|
3
|
+
* Converts a bignumberish or a text to a bigint.
|
|
4
4
|
* @param value The value to be converted to bigint.
|
|
5
5
|
* @return The value converted to bigint.
|
|
6
6
|
*/
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import type { NumericString } from "snarkjs";
|
|
2
|
-
|
|
3
|
-
export type SnarkArtifacts = {
|
|
4
|
-
wasmFilePath: string;
|
|
5
|
-
zkeyFilePath: string;
|
|
6
|
-
};
|
|
2
|
+
import type { PackedGroth16Proof } from "@zk-kit/utils";
|
|
7
3
|
export type SemaphoreProof = {
|
|
8
4
|
merkleTreeDepth: number;
|
|
9
5
|
merkleTreeRoot: NumericString;
|
|
10
6
|
message: NumericString;
|
|
11
7
|
nullifier: NumericString;
|
|
12
8
|
scope: NumericString;
|
|
13
|
-
points:
|
|
9
|
+
points: PackedGroth16Proof;
|
|
14
10
|
};
|
|
15
|
-
export type PackedPoints = [
|
|
16
|
-
NumericString,
|
|
17
|
-
NumericString,
|
|
18
|
-
NumericString,
|
|
19
|
-
NumericString,
|
|
20
|
-
NumericString,
|
|
21
|
-
NumericString,
|
|
22
|
-
NumericString,
|
|
23
|
-
NumericString
|
|
24
|
-
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/proof",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.11",
|
|
4
4
|
"description": "A library to generate and verify Semaphore proofs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,23 +40,22 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@rollup/plugin-alias": "^5.1.0",
|
|
42
42
|
"@rollup/plugin-json": "^6.1.0",
|
|
43
|
-
"@
|
|
44
|
-
"@types/snarkjs": "0
|
|
45
|
-
"@types/tmp": "^0.2.6",
|
|
43
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
44
|
+
"@types/snarkjs": "^0",
|
|
46
45
|
"poseidon-lite": "^0.2.0",
|
|
47
46
|
"rimraf": "^5.0.5",
|
|
48
|
-
"rollup": "^4.
|
|
49
|
-
"rollup-plugin-cleanup": "^3.2.1"
|
|
50
|
-
"rollup-plugin-typescript2": "^0.36.0"
|
|
47
|
+
"rollup": "^4.12.0",
|
|
48
|
+
"rollup-plugin-cleanup": "^3.2.1"
|
|
51
49
|
},
|
|
52
50
|
"peerDependencies": {
|
|
53
|
-
"@semaphore-protocol/group": "4.0.0-beta.
|
|
54
|
-
"@semaphore-protocol/identity": "4.0.0-beta.
|
|
51
|
+
"@semaphore-protocol/group": "4.0.0-beta.11",
|
|
52
|
+
"@semaphore-protocol/identity": "4.0.0-beta.11"
|
|
55
53
|
},
|
|
56
54
|
"dependencies": {
|
|
57
|
-
"@semaphore-protocol/utils": "4.0.0-beta.
|
|
58
|
-
"@zk-kit/
|
|
55
|
+
"@semaphore-protocol/utils": "4.0.0-beta.11",
|
|
56
|
+
"@zk-kit/artifacts": "^1.3.2",
|
|
57
|
+
"@zk-kit/utils": "1.0.0",
|
|
59
58
|
"ethers": "6.10.0",
|
|
60
|
-
"snarkjs": "0.7.
|
|
59
|
+
"snarkjs": "0.7.4"
|
|
61
60
|
}
|
|
62
61
|
}
|
package/src/generate-proof.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { Group, MerkleProof } from "@semaphore-protocol/group"
|
|
2
2
|
import type { Identity } from "@semaphore-protocol/identity"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { packGroth16Proof } from "@zk-kit/utils"
|
|
6
|
-
import
|
|
3
|
+
import { MAX_DEPTH, MIN_DEPTH } from "@semaphore-protocol/utils/constants"
|
|
4
|
+
import { requireDefined, requireNumber, requireObject, requireTypes } from "@zk-kit/utils/error-handlers"
|
|
5
|
+
import { packGroth16Proof } from "@zk-kit/utils/proof-packing"
|
|
6
|
+
import { maybeGetSnarkArtifacts, Project, type SnarkArtifacts } from "@zk-kit/artifacts"
|
|
7
|
+
import type { BigNumberish } from "ethers"
|
|
8
|
+
import { type NumericString, groth16 } from "snarkjs"
|
|
7
9
|
import hash from "./hash"
|
|
8
10
|
import toBigInt from "./to-bigint"
|
|
9
|
-
import {
|
|
11
|
+
import type { SemaphoreProof } from "./types"
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* It generates a Semaphore proof, i.e. a zero-knowledge proof that an identity that
|
|
@@ -22,10 +24,10 @@ import { BigNumberish, SemaphoreProof, SnarkArtifacts } from "./types"
|
|
|
22
24
|
* or they will be automatically fetched.
|
|
23
25
|
* @param identity The Semaphore identity.
|
|
24
26
|
* @param groupOrMerkleProof The Semaphore group or its Merkle proof.
|
|
25
|
-
* @param scope The Semaphore scope.
|
|
26
27
|
* @param message The Semaphore message.
|
|
28
|
+
* @param scope The Semaphore scope.
|
|
27
29
|
* @param merkleTreeDepth The depth of the tree with which the circuit was compiled.
|
|
28
|
-
* @param snarkArtifacts
|
|
30
|
+
* @param snarkArtifacts See {@link https://zkkit.pse.dev/interfaces/_zk_kit_utils.SnarkArtifacts.html | SnarkArtifacts}.
|
|
29
31
|
* @returns The Semaphore proof ready to be verified.
|
|
30
32
|
*/
|
|
31
33
|
export default async function generateProof(
|
|
@@ -43,8 +45,8 @@ export default async function generateProof(
|
|
|
43
45
|
|
|
44
46
|
requireObject(identity, "identity")
|
|
45
47
|
requireObject(groupOrMerkleProof, "groupOrMerkleProof")
|
|
46
|
-
requireTypes(message, "message", ["string", "bigint", "number", "
|
|
47
|
-
requireTypes(scope, "scope", ["string", "bigint", "number", "
|
|
48
|
+
requireTypes(message, "message", ["string", "bigint", "number", "Uint8Array"])
|
|
49
|
+
requireTypes(scope, "scope", ["string", "bigint", "number", "Uint8Array"])
|
|
48
50
|
|
|
49
51
|
if (merkleTreeDepth) {
|
|
50
52
|
requireNumber(merkleTreeDepth, "merkleTreeDepth")
|
|
@@ -73,17 +75,16 @@ export default async function generateProof(
|
|
|
73
75
|
const merkleProofLength = merkleProof.siblings.length
|
|
74
76
|
|
|
75
77
|
if (merkleTreeDepth !== undefined) {
|
|
76
|
-
if (merkleTreeDepth <
|
|
77
|
-
throw new TypeError(
|
|
78
|
+
if (merkleTreeDepth < MIN_DEPTH || merkleTreeDepth > MAX_DEPTH) {
|
|
79
|
+
throw new TypeError(`The tree depth must be a number between ${MIN_DEPTH} and ${MAX_DEPTH}`)
|
|
78
80
|
}
|
|
79
81
|
} else {
|
|
80
82
|
merkleTreeDepth = merkleProofLength
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
// If the Snark artifacts are not defined they will be automatically downloaded.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
86
|
+
snarkArtifacts ??= await maybeGetSnarkArtifacts(Project.SEMAPHORE, { parameters: [merkleTreeDepth] })
|
|
87
|
+
const { wasm, zkey } = snarkArtifacts
|
|
87
88
|
|
|
88
89
|
// The index must be converted to a list of indices, 1 for each tree level.
|
|
89
90
|
// The missing siblings can be set to 0, as they won't be used in the circuit.
|
|
@@ -94,7 +95,7 @@ export default async function generateProof(
|
|
|
94
95
|
merkleProofIndices.push((merkleProof.index >> i) & 1)
|
|
95
96
|
|
|
96
97
|
if (merkleProofSiblings[i] === undefined) {
|
|
97
|
-
merkleProofSiblings[i] =
|
|
98
|
+
merkleProofSiblings[i] = 0n
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -107,8 +108,8 @@ export default async function generateProof(
|
|
|
107
108
|
scope: hash(scope),
|
|
108
109
|
message: hash(message)
|
|
109
110
|
},
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
wasm,
|
|
112
|
+
zkey
|
|
112
113
|
)
|
|
113
114
|
|
|
114
115
|
return {
|
package/src/hash.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { BigNumberish } from "ethers"
|
|
1
2
|
import { keccak256 } from "ethers/crypto"
|
|
2
3
|
import { toBeHex } from "ethers/utils"
|
|
3
4
|
import { NumericString } from "snarkjs"
|
|
4
|
-
import { BigNumberish } from "./types"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates a keccak256 hash of a message compatible with the SNARK scalar modulus.
|
package/src/index.ts
CHANGED
package/src/to-bigint.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { BigNumberish } from "ethers"
|
|
1
2
|
import { encodeBytes32String } from "ethers/abi"
|
|
2
3
|
import { toBigInt as _toBigInt } from "ethers/utils"
|
|
3
|
-
import { BigNumberish } from "./types"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Converts a bignumberish to a bigint.
|
|
6
|
+
* Converts a bignumberish or a text to a bigint.
|
|
7
7
|
* @param value The value to be converted to bigint.
|
|
8
8
|
* @return The value converted to bigint.
|
|
9
9
|
*/
|
package/src/types/index.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { NumericString } from "snarkjs"
|
|
2
|
-
|
|
3
|
-
export type BigNumberish = string | number | bigint
|
|
4
|
-
|
|
5
|
-
export type SnarkArtifacts = {
|
|
6
|
-
wasmFilePath: string
|
|
7
|
-
zkeyFilePath: string
|
|
8
|
-
}
|
|
2
|
+
import type { PackedGroth16Proof } from "@zk-kit/utils"
|
|
9
3
|
|
|
10
4
|
export type SemaphoreProof = {
|
|
11
5
|
merkleTreeDepth: number
|
|
@@ -13,16 +7,5 @@ export type SemaphoreProof = {
|
|
|
13
7
|
message: NumericString
|
|
14
8
|
nullifier: NumericString
|
|
15
9
|
scope: NumericString
|
|
16
|
-
points:
|
|
10
|
+
points: PackedGroth16Proof
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
export type PackedPoints = [
|
|
20
|
-
NumericString,
|
|
21
|
-
NumericString,
|
|
22
|
-
NumericString,
|
|
23
|
-
NumericString,
|
|
24
|
-
NumericString,
|
|
25
|
-
NumericString,
|
|
26
|
-
NumericString,
|
|
27
|
-
NumericString
|
|
28
|
-
]
|