mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-09 14:48:12 -05:00
chore: update scripts to download snark artifacts
Former-commit-id: d9c069784f
This commit is contained in:
24
scripts/download-snark-artifacts.ts
Normal file
24
scripts/download-snark-artifacts.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import download from "download"
|
||||
import fs from "fs"
|
||||
import { config } from "../package.json"
|
||||
|
||||
async function main() {
|
||||
const snarkArtifactsPath = config.paths.build["snark-artifacts"]
|
||||
const url = `http://www.trusted-setup-pse.org/semaphore/${process.env.TREE_DEPTH}`
|
||||
|
||||
if (!fs.existsSync(snarkArtifactsPath)) {
|
||||
fs.mkdirSync(snarkArtifactsPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
|
||||
await download(`${url}/semaphore.wasm`, snarkArtifactsPath)
|
||||
await download(`${url}/semaphore.zkey`, snarkArtifactsPath)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -1,25 +0,0 @@
|
||||
import download from "download"
|
||||
import fs from "fs"
|
||||
import { config } from "../package.json"
|
||||
|
||||
async function main() {
|
||||
const buildPath = config.paths.build["zk-files"]
|
||||
const url = "http://www.trusted-setup-pse.org/semaphore/semaphore.zip"
|
||||
|
||||
if (!fs.existsSync(buildPath)) {
|
||||
fs.mkdirSync(buildPath, { recursive: true })
|
||||
}
|
||||
|
||||
if (!fs.existsSync(`${buildPath}/16/semaphore.zkey`)) {
|
||||
await download(url, buildPath, {
|
||||
extract: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -1,37 +0,0 @@
|
||||
import fs from "fs"
|
||||
import logger from "js-logger"
|
||||
import { zKey } from "snarkjs"
|
||||
import { config } from "../package.json"
|
||||
|
||||
logger.useDefaults()
|
||||
|
||||
async function main() {
|
||||
const buildPath = config.paths.build["zk-files"]
|
||||
const contractsPath = config.paths.contracts
|
||||
const templatesPath = config.paths["snarkjs-templates"]
|
||||
const solidityVersion = config.solidity.version
|
||||
|
||||
if (fs.existsSync(`${buildPath}/16/semaphore.zkey`)) {
|
||||
for (let treeDepth = 16; treeDepth <= 32; treeDepth++) {
|
||||
let verifierCode = await zKey.exportSolidityVerifier(
|
||||
`${buildPath}/${treeDepth}/semaphore.zkey`,
|
||||
{ groth16: fs.readFileSync(`${templatesPath}/verifier_groth16.sol.ejs`, "utf8") },
|
||||
logger
|
||||
)
|
||||
verifierCode = verifierCode.replace(
|
||||
/pragma solidity \^\d+\.\d+\.\d+/,
|
||||
`pragma solidity ^${solidityVersion}`
|
||||
)
|
||||
verifierCode = verifierCode.replace(/Verifier/, `Verifier${treeDepth}`)
|
||||
|
||||
fs.writeFileSync(`${contractsPath}/verifiers/Verifier${treeDepth}.sol`, verifierCode, "utf-8")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user