@semaphore-protocol/proof 2.6.0 → 3.0.0-beta.5
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 +9 -10
- package/dist/index.mjs +813 -31
- package/dist/index.node.js +811 -31
- package/dist/types/generateProof.d.ts +3 -2
- package/dist/types/hash.d.ts +7 -0
- package/dist/types/index.d.ts +1 -3
- package/dist/types/types/index.d.ts +7 -7
- package/dist/types/verifyProof.d.ts +2 -2
- package/package.json +6 -5
- package/src/generateProof.ts +9 -8
- package/src/hash.ts +15 -0
- package/src/index.test.ts +56 -36
- package/src/index.ts +1 -3
- package/src/types/index.ts +1 -1
- package/src/verificationKeys.json +712 -0
- package/src/verifyProof.ts +14 -3
- package/dist/types/generateNullifierHash.d.ts +0 -8
- package/dist/types/generateSignalHash.d.ts +0 -6
- package/src/generateNullifierHash.ts +0 -15
- package/src/generateSignalHash.ts +0 -16
package/src/verifyProof.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import { groth16 } from "snarkjs"
|
|
2
2
|
import { FullProof } from "./types"
|
|
3
|
+
import verificationKeys from "./verificationKeys.json"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Verifies a SnarkJS proof.
|
|
6
|
-
* @param verificationKey The zero-knowledge verification key.
|
|
7
7
|
* @param fullProof The SnarkJS full proof.
|
|
8
|
+
* @param treeDepth The Merkle tree depth.
|
|
8
9
|
* @returns True if the proof is valid, false otherwise.
|
|
9
10
|
*/
|
|
10
|
-
export default function verifyProof(
|
|
11
|
+
export default function verifyProof({ proof, publicSignals }: FullProof, treeDepth: number): Promise<boolean> {
|
|
12
|
+
if (treeDepth < 16 || treeDepth > 32) {
|
|
13
|
+
throw new TypeError("The tree depth must be a number between 16 and 32")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const verificationKey = {
|
|
17
|
+
...verificationKeys,
|
|
18
|
+
vk_delta_2: verificationKeys.vk_delta_2[treeDepth - 16],
|
|
19
|
+
IC: verificationKeys.IC[treeDepth - 16]
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
return groth16.verify(
|
|
12
23
|
verificationKey,
|
|
13
24
|
[
|
|
14
|
-
publicSignals.
|
|
25
|
+
publicSignals.merkleTreeRoot,
|
|
15
26
|
publicSignals.nullifierHash,
|
|
16
27
|
publicSignals.signalHash,
|
|
17
28
|
publicSignals.externalNullifier
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BigNumberish } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Generates a nullifier by hashing the external and the identity nullifiers.
|
|
4
|
-
* @param externalNullifier The external nullifier.
|
|
5
|
-
* @param identityNullifier The identity nullifier.
|
|
6
|
-
* @returns The nullifier hash.
|
|
7
|
-
*/
|
|
8
|
-
export default function generateNullifierHash(externalNullifier: BigNumberish, identityNullifier: BigNumberish): bigint;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { poseidon } from "circomlibjs"
|
|
2
|
-
import { BigNumberish } from "./types"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generates a nullifier by hashing the external and the identity nullifiers.
|
|
6
|
-
* @param externalNullifier The external nullifier.
|
|
7
|
-
* @param identityNullifier The identity nullifier.
|
|
8
|
-
* @returns The nullifier hash.
|
|
9
|
-
*/
|
|
10
|
-
export default function generateNullifierHash(
|
|
11
|
-
externalNullifier: BigNumberish,
|
|
12
|
-
identityNullifier: BigNumberish
|
|
13
|
-
): bigint {
|
|
14
|
-
return poseidon([BigInt(externalNullifier), BigInt(identityNullifier)])
|
|
15
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isHexString } from "@ethersproject/bytes"
|
|
2
|
-
import { keccak256 } from "@ethersproject/solidity"
|
|
3
|
-
import { formatBytes32String } from "@ethersproject/strings"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Hashes a signal string with Keccak256.
|
|
7
|
-
* @param signal The Semaphore signal.
|
|
8
|
-
* @returns The signal hash.
|
|
9
|
-
*/
|
|
10
|
-
export default function genSignalHash(signal: string): bigint {
|
|
11
|
-
if (!isHexString(signal, 32)) {
|
|
12
|
-
signal = formatBytes32String(signal)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return BigInt(keccak256(["bytes32"], [signal])) >> BigInt(8)
|
|
16
|
-
}
|