@semaphore-protocol/proof 4.0.0-beta.1 → 4.0.0-beta.10
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 +10 -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
package/src/verify-proof.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
requireNumber,
|
|
5
|
-
requireObject,
|
|
6
|
-
requireString
|
|
7
|
-
} from "@semaphore-protocol/utils/errors"
|
|
1
|
+
import { MAX_DEPTH, MIN_DEPTH } from "@semaphore-protocol/utils/constants"
|
|
2
|
+
import { requireArray, requireDefined, requireNumber, requireObject, requireString } from "@zk-kit/utils/error-handlers"
|
|
3
|
+
import { unpackGroth16Proof } from "@zk-kit/utils/proof-packing"
|
|
8
4
|
import { groth16 } from "snarkjs"
|
|
9
|
-
import { unpackGroth16Proof } from "@zk-kit/utils"
|
|
10
5
|
import hash from "./hash"
|
|
11
6
|
import { SemaphoreProof } from "./types"
|
|
12
7
|
import verificationKeys from "./verification-keys.json"
|
|
@@ -30,9 +25,8 @@ export default async function verifyProof(proof: SemaphoreProof): Promise<boolea
|
|
|
30
25
|
requireString(scope, "proof.scope")
|
|
31
26
|
requireArray(points, "proof.points")
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
throw new TypeError("The tree depth must be a number between 1 and 12")
|
|
28
|
+
if (merkleTreeDepth < MIN_DEPTH || merkleTreeDepth > MAX_DEPTH) {
|
|
29
|
+
throw new TypeError(`The tree depth must be a number between ${MIN_DEPTH} and ${MAX_DEPTH}`)
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
const verificationKey = {
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SnarkArtifacts } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Returns the zero-knowledge artifact paths. Artifacts exist for each tree
|
|
4
|
-
* depth supported by Semaphore, and they were generated in a trusted-setup.
|
|
5
|
-
* @param treeDepth The depth of the tree.
|
|
6
|
-
* @returns The zero-knowledge artifacts paths.
|
|
7
|
-
*/
|
|
8
|
-
export default function getSnarkArtifacts(treeDepth: number): Promise<SnarkArtifacts>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SnarkArtifacts } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Downloads the zero-knowledge artifacts and returns their paths.
|
|
4
|
-
* Artifacts exist for each tree depth supported by Semaphore, and
|
|
5
|
-
* they were generated in a trusted-setup.
|
|
6
|
-
* @param treeDepth The depth of the tree.
|
|
7
|
-
* @returns The zero-knowledge artifacts paths.
|
|
8
|
-
*/
|
|
9
|
-
export default function getSnarkArtifacts(treeDepth: number): Promise<SnarkArtifacts>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { requireNumber } from "@semaphore-protocol/utils/errors"
|
|
3
|
-
import { SnarkArtifacts } from "./types"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns the zero-knowledge artifact paths. Artifacts exist for each tree
|
|
7
|
-
* depth supported by Semaphore, and they were generated in a trusted-setup.
|
|
8
|
-
* @param treeDepth The depth of the tree.
|
|
9
|
-
* @returns The zero-knowledge artifacts paths.
|
|
10
|
-
*/
|
|
11
|
-
export default async function getSnarkArtifacts(treeDepth: number): Promise<SnarkArtifacts> {
|
|
12
|
-
requireNumber(treeDepth, "treeDepth")
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
wasmFilePath: `https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.wasm`,
|
|
16
|
-
zkeyFilePath: `https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.zkey`
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { requireNumber } from "@semaphore-protocol/utils/errors"
|
|
3
|
-
import { createWriteStream, existsSync, readdirSync } from "node:fs"
|
|
4
|
-
import { mkdir } from "node:fs/promises"
|
|
5
|
-
import os from "node:os"
|
|
6
|
-
import { dirname } from "node:path"
|
|
7
|
-
import { Readable } from "node:stream"
|
|
8
|
-
import { finished } from "node:stream/promises"
|
|
9
|
-
import { SnarkArtifacts } from "./types"
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A utility function to download the zero-knowledge artifacts from an external server.
|
|
13
|
-
* @param url The URL from which to download the artifacts.
|
|
14
|
-
* @param outputPath The path in which to save the artifacts.
|
|
15
|
-
*/
|
|
16
|
-
async function download(url: string, outputPath: string) {
|
|
17
|
-
const response = await fetch(url)
|
|
18
|
-
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Ensure the directory exists.
|
|
24
|
-
const dir = dirname(outputPath)
|
|
25
|
-
await mkdir(dir, { recursive: true })
|
|
26
|
-
|
|
27
|
-
const fileStream = createWriteStream(outputPath)
|
|
28
|
-
await finished(Readable.fromWeb(response.body as any).pipe(fileStream))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Downloads the zero-knowledge artifacts and returns their paths.
|
|
33
|
-
* Artifacts exist for each tree depth supported by Semaphore, and
|
|
34
|
-
* they were generated in a trusted-setup.
|
|
35
|
-
* @param treeDepth The depth of the tree.
|
|
36
|
-
* @returns The zero-knowledge artifacts paths.
|
|
37
|
-
*/
|
|
38
|
-
export default async function getSnarkArtifacts(treeDepth: number): Promise<SnarkArtifacts> {
|
|
39
|
-
requireNumber(treeDepth, "treeDepth")
|
|
40
|
-
|
|
41
|
-
const tmpDir = "semaphore-proof"
|
|
42
|
-
const tmpPath = `${os.tmpdir()}/${tmpDir}-${treeDepth}`
|
|
43
|
-
|
|
44
|
-
if (!existsSync(tmpPath) || readdirSync(tmpPath).length !== 2) {
|
|
45
|
-
await download(
|
|
46
|
-
`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.wasm`,
|
|
47
|
-
`${tmpPath}/semaphore.wasm`
|
|
48
|
-
)
|
|
49
|
-
await download(
|
|
50
|
-
`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.zkey`,
|
|
51
|
-
`${tmpPath}/semaphore.zkey`
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
wasmFilePath: `${tmpPath}/semaphore.wasm`,
|
|
57
|
-
zkeyFilePath: `${tmpPath}/semaphore.zkey`
|
|
58
|
-
}
|
|
59
|
-
}
|