Merge pull request #636 from semaphore-protocol/refactor/download-artifacts

0-dependency script to download SNARK artifacts

Former-commit-id: a8322fd95c
This commit is contained in:
Cedoor
2024-02-15 19:29:28 +00:00
committed by GitHub
7 changed files with 59 additions and 15 deletions

View File

@@ -30,7 +30,7 @@
"devDependencies": {
"@types/mocha": "^10.0.6",
"@zk-kit/eddsa-poseidon": "0.3.1",
"@zk-kit/imt": "^2.0.0-beta",
"@zk-kit/imt": "^2.0.0-beta.1",
"circomkit": "^0.0.19",
"mocha": "^10.2.0",
"poseidon-lite": "^0.2.0"

View File

@@ -19,7 +19,7 @@ export default {
{ file: pkg.exports.require, format: "cjs", banner, exports: "auto" },
{ file: pkg.exports.default, format: "es", banner }
],
external: Object.keys(pkg.dependencies),
external: [...Object.keys(pkg.dependencies), "ethers/contract", "ethers/constants", "ethers/providers"],
plugins: [
json(),
typescript({ tsconfig: "./build.tsconfig.json", useTsconfigDeclarationDir: true }),

View File

@@ -54,9 +54,7 @@
},
"dependencies": {
"@types/snarkjs": "0.7.8",
"download": "8.0.0",
"ethers": "6.10.0",
"snarkjs": "0.7.3",
"tmp": "0.2.1"
"snarkjs": "0.7.3"
}
}

View File

@@ -23,7 +23,18 @@ export default {
banner
}
],
external: Object.keys(pkg.dependencies),
external: [
...Object.keys(pkg.dependencies),
"node:fs",
"node:fs/promises",
"node:os",
"node:path",
"node:stream",
"node:stream/promises",
"ethers/crypto",
"ethers/utils",
"ethers/abi"
],
plugins: [
alias({
entries: [{ find: "./get-snark-artifacts.node", replacement: "./get-snark-artifacts.browser" }]

View File

@@ -28,7 +28,18 @@ export default {
banner
}
],
external: [...Object.keys(pkg.dependencies), "fs"],
external: [
...Object.keys(pkg.dependencies),
"node:fs",
"node:fs/promises",
"node:os",
"node:path",
"node:stream",
"node:stream/promises",
"ethers/crypto",
"ethers/utils",
"ethers/abi"
],
plugins: [
typescript({
tsconfig: "./build.tsconfig.json",

View File

@@ -1,16 +1,40 @@
/* istanbul ignore file */
import download from "download"
import fs from "fs"
import tmp from "tmp"
import { createWriteStream, existsSync, readdirSync } from "node:fs"
import { mkdir } from "node:fs/promises"
import os from "node:os"
import { dirname } from "node:path"
import { Readable } from "node:stream"
import { finished } from "node:stream/promises"
import { SnarkArtifacts } from "./types"
async function download(url: string, outputPath: string) {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Failed to fetch ${url}: ${response.statusText}`)
}
// Ensure the directory exists.
const dir = dirname(outputPath)
await mkdir(dir, { recursive: true })
const fileStream = createWriteStream(outputPath)
await finished(Readable.fromWeb(response.body as any).pipe(fileStream))
}
export default async function getSnarkArtifacts(treeDepth: number): Promise<SnarkArtifacts> {
const tmpDir = "semaphore-proof"
const tmpPath = `${tmp.tmpdir}/${tmpDir}-${treeDepth}`
const tmpPath = `${os.tmpdir()}/${tmpDir}-${treeDepth}`
if (!fs.existsSync(tmpPath) || fs.readdirSync(tmpPath).length !== 2) {
await download(`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.wasm`, tmpPath)
await download(`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.zkey`, tmpPath)
if (!existsSync(tmpPath) || readdirSync(tmpPath).length !== 2) {
await download(
`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.wasm`,
`${tmpPath}/semaphore.wasm`
)
await download(
`https://semaphore.cedoor.dev/artifacts/${treeDepth}/semaphore.zkey`,
`${tmpPath}/semaphore.zkey`
)
}
return {

View File

@@ -1 +1 @@
0764f553045d18f101b23f70b982ee1b83db9004
c846531c38bcc21c8c7ebc08e5d175f80dc77ac6