1
1
import { BigNumber } from "@ethersproject/bignumber"
2
2
import { BytesLike , Hexable } from "@ethersproject/bytes"
3
- import { Group } from "@semaphore-protocol/group"
3
+ import type { Group , MerkleProof } from "@semaphore-protocol/group"
4
4
import type { Identity } from "@semaphore-protocol/identity"
5
5
import { NumericString , groth16 } from "snarkjs"
6
6
import getSnarkArtifacts from "./get-snark-artifacts.node"
@@ -11,7 +11,7 @@ import { SemaphoreProof, SnarkArtifacts } from "./types"
11
11
/**
12
12
* Generates a Semaphore proof.
13
13
* @param identity The Semaphore identity.
14
- * @param group The Semaphore group or its Merkle proof.
14
+ * @param groupOrMerkleProof The Semaphore group or its Merkle proof.
15
15
* @param scope The external nullifier.
16
16
* @param message The Semaphore signal.
17
17
* @param merkleTreeDepth The depth of the tree with which the circuit was compiled.
@@ -20,14 +20,21 @@ import { SemaphoreProof, SnarkArtifacts } from "./types"
20
20
*/
21
21
export default async function generateProof (
22
22
identity : Identity ,
23
- group : Group ,
23
+ groupOrMerkleProof : Group | MerkleProof ,
24
24
message : BytesLike | Hexable | number | bigint ,
25
25
scope : BytesLike | Hexable | number | bigint ,
26
26
merkleTreeDepth ?: number ,
27
27
snarkArtifacts ?: SnarkArtifacts
28
28
) : Promise < SemaphoreProof > {
29
- const leafIndex = group . indexOf ( identity . commitment )
30
- const merkleProof = group . generateMerkleProof ( leafIndex )
29
+ let merkleProof
30
+
31
+ if ( "siblings" in groupOrMerkleProof ) {
32
+ merkleProof = groupOrMerkleProof
33
+ } else {
34
+ const leafIndex = groupOrMerkleProof . indexOf ( identity . commitment )
35
+ merkleProof = groupOrMerkleProof . generateMerkleProof ( leafIndex )
36
+ }
37
+
31
38
const merkleProofLength = merkleProof . siblings . length
32
39
33
40
if ( merkleTreeDepth !== undefined ) {
0 commit comments