From 4fcdab95bee08934bf669862be9c8887d6547c31 Mon Sep 17 00:00:00 2001 From: cedoor Date: Wed, 22 Nov 2023 19:23:39 +0000 Subject: [PATCH 01/27] feat(poseidon-proof): create package --- .gitignore | 1 + packages/poseidon-proof/LICENSE | 21 +++ packages/poseidon-proof/README.md | 124 ++++++++++++++++++ packages/poseidon-proof/build.tsconfig.json | 8 ++ packages/poseidon-proof/package.json | 42 ++++++ packages/poseidon-proof/rollup.config.ts | 40 ++++++ packages/poseidon-proof/src/generate.ts | 35 +++++ packages/poseidon-proof/src/index.test.ts | 52 ++++++++ packages/poseidon-proof/src/index.ts | 7 + packages/poseidon-proof/src/packProof.ts | 20 +++ packages/poseidon-proof/src/types/index.ts | 24 ++++ packages/poseidon-proof/src/unpackProof.ts | 20 +++ .../poseidon-proof/src/verification-key.json | 95 ++++++++++++++ packages/poseidon-proof/src/verify.ts | 13 ++ packages/poseidon-proof/tsconfig.json | 4 + packages/poseidon-proof/typedoc.json | 3 + tsconfig.json | 1 + yarn.lock | 44 +++++++ 18 files changed, 554 insertions(+) create mode 100644 packages/poseidon-proof/LICENSE create mode 100644 packages/poseidon-proof/README.md create mode 100644 packages/poseidon-proof/build.tsconfig.json create mode 100644 packages/poseidon-proof/package.json create mode 100644 packages/poseidon-proof/rollup.config.ts create mode 100644 packages/poseidon-proof/src/generate.ts create mode 100644 packages/poseidon-proof/src/index.test.ts create mode 100644 packages/poseidon-proof/src/index.ts create mode 100644 packages/poseidon-proof/src/packProof.ts create mode 100644 packages/poseidon-proof/src/types/index.ts create mode 100644 packages/poseidon-proof/src/unpackProof.ts create mode 100644 packages/poseidon-proof/src/verification-key.json create mode 100644 packages/poseidon-proof/src/verify.ts create mode 100644 packages/poseidon-proof/tsconfig.json create mode 100644 packages/poseidon-proof/typedoc.json diff --git a/.gitignore b/.gitignore index 50d2ab8ab..53d6e5ac9 100644 --- a/.gitignore +++ b/.gitignore @@ -83,3 +83,4 @@ typechain-types # Other benchmarks/results +snark-artifacts diff --git a/packages/poseidon-proof/LICENSE b/packages/poseidon-proof/LICENSE new file mode 100644 index 000000000..4377091ec --- /dev/null +++ b/packages/poseidon-proof/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Ethereum Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md new file mode 100644 index 000000000..691bb41f1 --- /dev/null +++ b/packages/poseidon-proof/README.md @@ -0,0 +1,124 @@ +

+

+ Semaphore proof +

+

A library to generate and verify Semaphore proofs.

+

+ +

+ + + + + Github license + + + NPM version + + + Downloads + + + Documentation typedoc + + + Linter eslint + + + Code style prettier + +

+ +
+

+ + 👥 Contributing + +   |   + + 🤝 Code of conduct + +   |   + + 🔎 Issues + +   |   + + 🗣️ Chat & Support + +

+
+ +| This library provides utility functions to generate and verify Semaphore proofs compatible with the Semaphore [circuits](https://github.com/semaphore-protocol/semaphore/tree/main/circuits). Generating valid zero-knowledge proofs requires files that can only be obtained in an attested [trusted-setup ceremony](https://storage.googleapis.com/trustedsetup-a86f4.appspot.com/semaphore/semaphore_top_index.html). For a complete list of ready-to-use files visit [trusted-setup-pse.org](http://www.trusted-setup-pse.org/). | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | + +## 🛠 Install + +### npm or yarn + +Install the `@semaphore-protocol/proof` package and its peer dependencies with npm: + +```bash +npm i @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof +``` + +or yarn: + +```bash +yarn add @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof +``` + +## 📜 Usage + +\# **generateProof**( +identity: _Identity_, +group: _Group_ | _MerkleProof_, +externalNullifier: _BytesLike | Hexable | number | bigint_, +signal: _BytesLike | Hexable | number | bigint_, +snarkArtifacts?: _SnarkArtifacts_ +): Promise\<_SemaphoreProof_> + +```typescript +import { Identity } from "@semaphore-protocol/identity" +import { Group } from "@semaphore-protocol/group" +import { generateProof } from "@semaphore-protocol/proof" +import { utils } from "ethers" + +const identity = new Identity() +const group = new Group() +const externalNullifier = utils.formatBytes32String("Topic") +const signal = utils.formatBytes32String("Hello world") + +group.addMembers([...identityCommitments, identity.generateCommitment()]) + +const fullProof = await generateProof(identity, group, externalNullifier, signal, { + zkeyFilePath: "./semaphore.zkey", + wasmFilePath: "./semaphore.wasm" +}) + +// You can also use the default zkey/wasm files (it only works from browsers!). +// const fullProof = await generateProof(identity, group, externalNullifier, signal) +``` + +\# **verifyProof**(semaphoreProof: _SemaphoreProof_, treeDepth: _number_): Promise\<_boolean_> + +```typescript +import { verifyProof } from "@semaphore-protocol/proof" + +await verifyProof(fullProof, 20) +``` + +\# **calculateNullifierHash**( +identityNullifier: _bigint | number | string_, +externalNullifier: \__BytesLike | Hexable | number | bigint_ +): bigint + +```typescript +import { Identity } from "@semaphore-protocol/identity" +import { calculateNullifierHash } from "@semaphore-protocol/proof" + +const identity = new Identity() +const externalNullifier = utils.formatBytes32String("Topic") + +const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier) +``` diff --git a/packages/poseidon-proof/build.tsconfig.json b/packages/poseidon-proof/build.tsconfig.json new file mode 100644 index 000000000..2d4a1d6da --- /dev/null +++ b/packages/poseidon-proof/build.tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json new file mode 100644 index 000000000..675a2ce6b --- /dev/null +++ b/packages/poseidon-proof/package.json @@ -0,0 +1,42 @@ +{ + "name": "@zk-kit/poseidon-proof", + "version": "0.1.0", + "description": "A library to generate and verify Poseidon proofs.", + "license": "MIT", + "main": "dist/index.node.js", + "exports": { + "import": "./dist/index.node.mjs", + "require": "./dist/index.node.js", + "types": "./dist/types/index.d.ts" + }, + "types": "dist/types/index.d.ts", + "files": [ + "dist/", + "src/", + "LICENSE", + "README.md" + ], + "repository": "git@github.com:privacy-scaling-explorations/zk-kit.git", + "homepage": "https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/poseidon-proof", + "bugs": { + "url": "https://github.com/privacy-scaling-explorations/zk-kit.git/issues" + }, + "scripts": { + "build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript", + "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript", + "prepublishOnly": "yarn build" + }, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@rollup/plugin-json": "^5.0.1", + "@types/snarkjs": "^0.7.7", + "rollup-plugin-cleanup": "^3.2.1", + "rollup-plugin-terser": "^7.0.2", + "rollup-plugin-typescript2": "^0.32.1" + }, + "dependencies": { + "@zk-kit/groth16": "0.3.0" + } +} diff --git a/packages/poseidon-proof/rollup.config.ts b/packages/poseidon-proof/rollup.config.ts new file mode 100644 index 000000000..7cc6448f1 --- /dev/null +++ b/packages/poseidon-proof/rollup.config.ts @@ -0,0 +1,40 @@ +import json from "@rollup/plugin-json" +import * as fs from "fs" +import cleanup from "rollup-plugin-cleanup" +import typescript from "rollup-plugin-typescript2" + +const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8")) +const banner = `/** + * @module ${pkg.name} + * @version ${pkg.version} + * @file ${pkg.description} + * @copyright Ethereum Foundation 2023 + * @license ${pkg.license} + * @see [Github]{@link ${pkg.homepage}} +*/` + +export default { + input: "src/index.ts", + output: [ + { + file: pkg.exports.require, + format: "cjs", + banner, + exports: "auto" + }, + { + file: pkg.exports.import, + format: "es", + banner + } + ], + external: Object.keys(pkg.dependencies), + plugins: [ + typescript({ + tsconfig: "./build.tsconfig.json", + useTsconfigDeclarationDir: true + }), + cleanup({ comments: "jsdoc" }), + json() + ] +} diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts new file mode 100644 index 000000000..50a124171 --- /dev/null +++ b/packages/poseidon-proof/src/generate.ts @@ -0,0 +1,35 @@ +import { prove } from "@zk-kit/groth16" +import type { NumericString } from "snarkjs" +import packProof from "./packProof" +import { PoseidonProof, SnarkArtifacts } from "./types" + +/** + */ +export default async function generate( + message: NumericString, + scope: NumericString, + snarkArtifacts?: SnarkArtifacts +): Promise { + if (!snarkArtifacts) { + snarkArtifacts = { + wasmFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey", + zkeyFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey" + } + } + + const { proof, publicSignals } = await prove( + { + in: message, + scope + }, + snarkArtifacts.wasmFilePath, + snarkArtifacts.zkeyFilePath + ) + + return { + scope: publicSignals[0], + hash: publicSignals[1], + nullifier: publicSignals[2], + proof: packProof(proof) + } +} diff --git a/packages/poseidon-proof/src/index.test.ts b/packages/poseidon-proof/src/index.test.ts new file mode 100644 index 000000000..5144296e3 --- /dev/null +++ b/packages/poseidon-proof/src/index.test.ts @@ -0,0 +1,52 @@ +import { buildBn128 } from "@zk-kit/groth16" +import generate from "./generate" +import verify from "./verify" +import packProof from "./packProof" +import { PoseidonProof } from "./types" +import unpackProof from "./unpackProof" + +describe("PoseidonProof", () => { + const scope = "1" + + const wasmFilePath = `./snark-artifacts/poseidon-proof.wasm` + const zkeyFilePath = `./snark-artifacts/poseidon-proof.zkey` + + let fullProof: PoseidonProof + let curve: any + + beforeAll(async () => { + curve = await buildBn128() + }) + + afterAll(async () => { + await curve.terminate() + }) + + describe("# generate", () => { + it("Should generate a Poseidon proof", async () => { + fullProof = await generate("3", scope, { + wasmFilePath, + zkeyFilePath + }) + + expect(typeof fullProof).toBe("object") + }) + }) + + describe("# verify", () => { + it("Should verify a Semaphore proof", async () => { + const response = await verify(fullProof) + + expect(response).toBe(true) + }) + }) + + describe("# packProof/unpackProof", () => { + it("Should return a packed proof", async () => { + const originalProof = unpackProof(fullProof.proof) + const proof = packProof(originalProof) + + expect(proof).toStrictEqual(fullProof.proof) + }) + }) +}) diff --git a/packages/poseidon-proof/src/index.ts b/packages/poseidon-proof/src/index.ts new file mode 100644 index 000000000..72d4e1389 --- /dev/null +++ b/packages/poseidon-proof/src/index.ts @@ -0,0 +1,7 @@ +import calculateNullifierHash from "./calculateNullifierHash" +import generateProof from "./generateProof" +import verifyProof from "./verifyProof" + +export { MerkleProof } from "@zk-kit/incremental-merkle-tree" +export * from "./types" +export { generateProof, verifyProof, calculateNullifierHash } diff --git a/packages/poseidon-proof/src/packProof.ts b/packages/poseidon-proof/src/packProof.ts new file mode 100644 index 000000000..6677eaeab --- /dev/null +++ b/packages/poseidon-proof/src/packProof.ts @@ -0,0 +1,20 @@ +import { Groth16Proof } from "snarkjs" +import { PackedProof } from "./types" + +/** + * Packs a proof into a format compatible with Semaphore. + * @param proof The Groth16 proof generated with SnarkJS. + * @returns The proof compatible with Semaphore. + */ +export default function packProof(proof: Groth16Proof): PackedProof { + return [ + proof.pi_a[0], + proof.pi_a[1], + proof.pi_b[0][1], + proof.pi_b[0][0], + proof.pi_b[1][1], + proof.pi_b[1][0], + proof.pi_c[0], + proof.pi_c[1] + ] +} diff --git a/packages/poseidon-proof/src/types/index.ts b/packages/poseidon-proof/src/types/index.ts new file mode 100644 index 000000000..736ad1378 --- /dev/null +++ b/packages/poseidon-proof/src/types/index.ts @@ -0,0 +1,24 @@ +import type { NumericString } from "snarkjs" + +export type SnarkArtifacts = { + wasmFilePath: string + zkeyFilePath: string +} + +export type PoseidonProof = { + scope: NumericString + hash: NumericString + nullifier: NumericString + proof: PackedProof +} + +export type PackedProof = [ + NumericString, + NumericString, + NumericString, + NumericString, + NumericString, + NumericString, + NumericString, + NumericString +] diff --git a/packages/poseidon-proof/src/unpackProof.ts b/packages/poseidon-proof/src/unpackProof.ts new file mode 100644 index 000000000..68ba66599 --- /dev/null +++ b/packages/poseidon-proof/src/unpackProof.ts @@ -0,0 +1,20 @@ +import { Groth16Proof } from "snarkjs" +import { PackedProof } from "./types" + +/** + * Unpacks a proof into its original form. + * @param proof The proof compatible with Semaphore. + * @returns The proof compatible with SnarkJS. + */ +export default function unpackProof(proof: PackedProof): Groth16Proof { + return { + pi_a: [proof[0], proof[1]], + pi_b: [ + [proof[3], proof[2]], + [proof[5], proof[4]] + ], + pi_c: [proof[6], proof[7]], + protocol: "groth16", + curve: "bn128" + } +} diff --git a/packages/poseidon-proof/src/verification-key.json b/packages/poseidon-proof/src/verification-key.json new file mode 100644 index 000000000..1efc16b78 --- /dev/null +++ b/packages/poseidon-proof/src/verification-key.json @@ -0,0 +1,95 @@ +{ + "protocol": "groth16", + "curve": "bn128", + "nPublic": 3, + "vk_alpha_1": [ + "20491192805390485299153009773594534940189261866228447918068658471970481763042", + "9383485363053290200918347156157836566562967994039712273449902621266178545958", + "1" + ], + "vk_beta_2": [ + [ + "6375614351688725206403948262868962793625744043794305715222011528459656738731", + "4252822878758300859123897981450591353533073413197771768651442665752259397132" + ], + [ + "10505242626370262277552901082094356697409835680220590971873171140371331206856", + "21847035105528745403288232691147584728191162732299865338377159692350059136679" + ], + ["1", "0"] + ], + "vk_gamma_2": [ + [ + "10857046999023057135944570762232829481370756359578518086990519993285655852781", + "11559732032986387107991004021392285783925812861821192530917403151452391805634" + ], + [ + "8495653923123431417604973247489272438418190587263600148770280649306958101930", + "4082367875863433681332203403145435568316851327593401208105741076214120093531" + ], + ["1", "0"] + ], + "vk_delta_2": [ + [ + "2835903340493476135669393995212430686644232844074748296301661059863628867659", + "21200517440412175813023865627601707544755149396955380927016469073800677870531" + ], + [ + "2023534037270876846108571120843095937025463982029470775515903125985541660504", + "4638506558619308316357865353088633912755780966328746320262350429585529218255" + ], + ["1", "0"] + ], + "vk_alphabeta_12": [ + [ + [ + "2029413683389138792403550203267699914886160938906632433982220835551125967885", + "21072700047562757817161031222997517981543347628379360635925549008442030252106" + ], + [ + "5940354580057074848093997050200682056184807770593307860589430076672439820312", + "12156638873931618554171829126792193045421052652279363021382169897324752428276" + ], + [ + "7898200236362823042373859371574133993780991612861777490112507062703164551277", + "7074218545237549455313236346927434013100842096812539264420499035217050630853" + ] + ], + [ + [ + "7077479683546002997211712695946002074877511277312570035766170199895071832130", + "10093483419865920389913245021038182291233451549023025229112148274109565435465" + ], + [ + "4595479056700221319381530156280926371456704509942304414423590385166031118820", + "19831328484489333784475432780421641293929726139240675179672856274388269393268" + ], + [ + "11934129596455521040620786944827826205713621633706285934057045369193958244500", + "8037395052364110730298837004334506829870972346962140206007064471173334027475" + ] + ] + ], + "IC": [ + [ + "10540353245037691655240058832465935071147222378795512774896416883563614389198", + "20042286059857913285646233979306226083538103143380748863555356103197961213823", + "1" + ], + [ + "12178048393484805922448151297512780036777540315506565788645040495931277621130", + "9697539656531822741576184528195082340044862873578980581504958946888585254425", + "1" + ], + [ + "20991907493060125430185038723439696392069163847357524165903787100018954817952", + "12348708907766483529401318577288191297476103087328423321867414316726183562292", + "1" + ], + [ + "6823739927950557742246913693052072220213742766782370219666937126411380340633", + "19878777316727584245579797737044924949420447706770682437221414501064053790692", + "1" + ] + ] +} diff --git a/packages/poseidon-proof/src/verify.ts b/packages/poseidon-proof/src/verify.ts new file mode 100644 index 000000000..eee2fd88a --- /dev/null +++ b/packages/poseidon-proof/src/verify.ts @@ -0,0 +1,13 @@ +import { verify as _verify } from "@zk-kit/groth16" +import unpackProof from "./unpackProof" +import verificationKey from "./verification-key.json" +import { PoseidonProof } from "./types" + +/** + */ +export default function verify({ scope, hash, nullifier, proof }: PoseidonProof): Promise { + return _verify(verificationKey, { + publicSignals: [scope, hash, nullifier], + proof: unpackProof(proof) + }) +} diff --git a/packages/poseidon-proof/tsconfig.json b/packages/poseidon-proof/tsconfig.json new file mode 100644 index 000000000..dfaf0c1ad --- /dev/null +++ b/packages/poseidon-proof/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src", "rollup.config.ts"] +} diff --git a/packages/poseidon-proof/typedoc.json b/packages/poseidon-proof/typedoc.json new file mode 100644 index 000000000..77a471c91 --- /dev/null +++ b/packages/poseidon-proof/typedoc.json @@ -0,0 +1,3 @@ +{ + "entryPoints": ["src/index.ts"] +} diff --git a/tsconfig.json b/tsconfig.json index 8d72d0ebf..ceead27bd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "ES5", "module": "ES6", "moduleResolution": "node", + "resolveJsonModule": true, "esModuleInterop": true, "preserveConstEnums": true, "skipLibCheck": true, diff --git a/yarn.lock b/yarn.lock index 07320c753..7a3b73054 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3291,6 +3291,20 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-json@npm:^5.0.1": + version: 5.0.2 + resolution: "@rollup/plugin-json@npm:5.0.2" + dependencies: + "@rollup/pluginutils": ^5.0.1 + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: 9b5f90ea311dfcfacf0f38af39bbb1954ea56d6faecdee3d528f73d0e02da96a0706ab21fae0c8eef9bb5d756f6f50b40b5a252ffd9800397012b5bac6764b6f + languageName: node + linkType: hard + "@rollup/plugin-node-resolve@npm:^15.0.2": version: 15.2.3 resolution: "@rollup/plugin-node-resolve@npm:15.2.3" @@ -4130,6 +4144,13 @@ __metadata: languageName: node linkType: hard +"@types/snarkjs@npm:^0.7.7": + version: 0.7.7 + resolution: "@types/snarkjs@npm:0.7.7" + checksum: 24e655c4828c13f4fb486b00c4051aac6df0c43c27a65c0311fc85f9dcba9da2dbea567e6d87ccfd6971cd550b36bca539de3ac53a91db2b67e1c777530def1f + languageName: node + linkType: hard + "@types/stack-utils@npm:^2.0.0": version: 2.0.3 resolution: "@types/stack-utils@npm:2.0.3" @@ -4319,6 +4340,16 @@ __metadata: languageName: node linkType: hard +"@zk-kit/groth16@npm:0.3.0": + version: 0.3.0 + resolution: "@zk-kit/groth16@npm:0.3.0" + dependencies: + circom_runtime: 0.1.24 + ffjavascript: 0.2.60 + checksum: f177fffd7e28c1f6617a67758c017bb962bde8829a6b90bea8053c0c164386b73b58cfe26c2481435bbc0de0c14d8301c23818e4a0450979bceb525f64e9db51 + languageName: node + linkType: hard + "@zk-kit/groth16@workspace:packages/groth16": version: 0.0.0-use.local resolution: "@zk-kit/groth16@workspace:packages/groth16" @@ -4371,6 +4402,19 @@ __metadata: languageName: unknown linkType: soft +"@zk-kit/poseidon-proof@workspace:packages/poseidon-proof": + version: 0.0.0-use.local + resolution: "@zk-kit/poseidon-proof@workspace:packages/poseidon-proof" + dependencies: + "@rollup/plugin-json": ^5.0.1 + "@types/snarkjs": ^0.7.7 + "@zk-kit/groth16": 0.3.0 + rollup-plugin-cleanup: ^3.2.1 + rollup-plugin-terser: ^7.0.2 + rollup-plugin-typescript2: ^0.32.1 + languageName: unknown + linkType: soft + "@zk-kit/rollup-plugin-rust@workspace:packages/rollup-plugin-rust": version: 0.0.0-use.local resolution: "@zk-kit/rollup-plugin-rust@workspace:packages/rollup-plugin-rust" From d33da793b877339033be4bc3d114230d32ecd420 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 11:08:27 +0000 Subject: [PATCH 02/27] docs(poseidon-proof): update readme file --- packages/poseidon-proof/README.md | 101 ++++++++++-------------------- 1 file changed, 33 insertions(+), 68 deletions(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index 691bb41f1..f2688e9ec 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -1,25 +1,25 @@

- Semaphore proof + Poseidon proof

-

A library to generate and verify Semaphore proofs.

+

A library to generate and verify Poseidon proofs.

- - + + - - Github license + + NPM license - - NPM version + + NPM version - - Downloads + + Downloads - - Documentation typedoc + + npm bundle size (scoped) Linter eslint @@ -31,94 +31,59 @@

- - 👥 Contributing - -   |   - - 🤝 Code of conduct - -   |   - - 🔎 Issues + + 🗣️ Chat & Support   |   - - 🗣️ Chat & Support + + 📘 Docs

-| This library provides utility functions to generate and verify Semaphore proofs compatible with the Semaphore [circuits](https://github.com/semaphore-protocol/semaphore/tree/main/circuits). Generating valid zero-knowledge proofs requires files that can only be obtained in an attested [trusted-setup ceremony](https://storage.googleapis.com/trustedsetup-a86f4.appspot.com/semaphore/semaphore_top_index.html). For a complete list of ready-to-use files visit [trusted-setup-pse.org](http://www.trusted-setup-pse.org/). | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | - ## 🛠 Install ### npm or yarn -Install the `@semaphore-protocol/proof` package and its peer dependencies with npm: +Install the `@zk-kit/poseidon-proof` package: ```bash -npm i @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof +npm i @zk-kit/poseidon-proof ``` or yarn: ```bash -yarn add @semaphore-protocol/identity @semaphore-protocol/group @semaphore-protocol/proof +yarn add @zk-kit/poseidon-proof ``` ## 📜 Usage -\# **generateProof**( -identity: _Identity_, -group: _Group_ | _MerkleProof_, -externalNullifier: _BytesLike | Hexable | number | bigint_, -signal: _BytesLike | Hexable | number | bigint_, +\# **generate**( +message: _NumericString_, +scope: _NumericString_, snarkArtifacts?: _SnarkArtifacts_ -): Promise\<_SemaphoreProof_> +): Promise\<_PoseidonProof_> ```typescript -import { Identity } from "@semaphore-protocol/identity" -import { Group } from "@semaphore-protocol/group" -import { generateProof } from "@semaphore-protocol/proof" -import { utils } from "ethers" +import { generate } from "@zk-kit/poseidon-proof" -const identity = new Identity() -const group = new Group() -const externalNullifier = utils.formatBytes32String("Topic") -const signal = utils.formatBytes32String("Hello world") +const scope = "1" +const message = "2" -group.addMembers([...identityCommitments, identity.generateCommitment()]) - -const fullProof = await generateProof(identity, group, externalNullifier, signal, { - zkeyFilePath: "./semaphore.zkey", - wasmFilePath: "./semaphore.wasm" +const fullProof = await generate(message, scope, { + zkeyFilePath: "./poseidon-proof.zkey", + wasmFilePath: "./poseidon-proof.wasm" }) // You can also use the default zkey/wasm files (it only works from browsers!). -// const fullProof = await generateProof(identity, group, externalNullifier, signal) +// const fullProof = await generate(message, scope) ``` -\# **verifyProof**(semaphoreProof: _SemaphoreProof_, treeDepth: _number_): Promise\<_boolean_> +\# **verify**(poseidonProof: _PoseidonProof_): Promise\<_boolean_> ```typescript -import { verifyProof } from "@semaphore-protocol/proof" - -await verifyProof(fullProof, 20) -``` - -\# **calculateNullifierHash**( -identityNullifier: _bigint | number | string_, -externalNullifier: \__BytesLike | Hexable | number | bigint_ -): bigint - -```typescript -import { Identity } from "@semaphore-protocol/identity" -import { calculateNullifierHash } from "@semaphore-protocol/proof" - -const identity = new Identity() -const externalNullifier = utils.formatBytes32String("Topic") +import { verify } from "@zk-key/poseidon-proof" -const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier) +await verifyProof(fullProof) ``` From 60b42a04ee9973fc3831b2230c7d1fe7cf2081e4 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 11:13:55 +0000 Subject: [PATCH 03/27] fix(poseidon-proof): set correct index.js --- packages/poseidon-proof/src/index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/poseidon-proof/src/index.ts b/packages/poseidon-proof/src/index.ts index 72d4e1389..78f8eb6dc 100644 --- a/packages/poseidon-proof/src/index.ts +++ b/packages/poseidon-proof/src/index.ts @@ -1,7 +1,5 @@ -import calculateNullifierHash from "./calculateNullifierHash" -import generateProof from "./generateProof" -import verifyProof from "./verifyProof" +import generate from "./generate" +import verify from "./verify" -export { MerkleProof } from "@zk-kit/incremental-merkle-tree" export * from "./types" -export { generateProof, verifyProof, calculateNullifierHash } +export { generate, verify } From ebd692d13082b366f494aeccba6795890966f537 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 12:46:21 +0000 Subject: [PATCH 04/27] feat(poseidon-proof): download snark artifacts on node --- .eslintrc.json | 1 + .gitignore | 1 - packages/poseidon-proof/.npmrc | 1 + packages/poseidon-proof/package.json | 9 +- packages/poseidon-proof/src/config.ts | 8 + packages/poseidon-proof/src/generate.ts | 39 +- packages/poseidon-proof/src/index.test.ts | 10 +- packages/poseidon-proof/src/packProof.ts | 4 +- packages/poseidon-proof/src/types/index.ts | 4 +- packages/poseidon-proof/src/unpackProof.ts | 2 +- packages/poseidon-proof/src/utils.ts | 20 + tsconfig.json | 2 +- yarn.lock | 739 ++++++++++++++++++++- 13 files changed, 799 insertions(+), 41 deletions(-) create mode 100644 packages/poseidon-proof/.npmrc create mode 100644 packages/poseidon-proof/src/config.ts create mode 100644 packages/poseidon-proof/src/utils.ts diff --git a/.eslintrc.json b/.eslintrc.json index 21e030869..5ed9f5a9e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,7 @@ "class-methods-use-this": "warn", "import/no-extraneous-dependencies": "off", "import/no-relative-packages": "off", + "@typescript-eslint/no-implied-eval": "off", "@typescript-eslint/no-loop-func": "off", "@typescript-eslint/no-shadow": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/.gitignore b/.gitignore index 53d6e5ac9..50d2ab8ab 100644 --- a/.gitignore +++ b/.gitignore @@ -83,4 +83,3 @@ typechain-types # Other benchmarks/results -snark-artifacts diff --git a/packages/poseidon-proof/.npmrc b/packages/poseidon-proof/.npmrc new file mode 100644 index 000000000..b6f27f135 --- /dev/null +++ b/packages/poseidon-proof/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 675a2ce6b..f3ee44cb2 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -16,6 +16,9 @@ "LICENSE", "README.md" ], + "engines": { + "node": ">=18.0.0" + }, "repository": "git@github.com:privacy-scaling-explorations/zk-kit.git", "homepage": "https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/poseidon-proof", "bugs": { @@ -31,12 +34,16 @@ }, "devDependencies": { "@rollup/plugin-json": "^5.0.1", + "@types/download": "^8.0.5", "@types/snarkjs": "^0.7.7", + "@types/tmp": "^0.2.6", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.32.1" }, "dependencies": { - "@zk-kit/groth16": "0.3.0" + "@zk-kit/groth16": "0.3.0", + "download": "^8.0.0", + "tmp": "^0.2.1" } } diff --git a/packages/poseidon-proof/src/config.ts b/packages/poseidon-proof/src/config.ts new file mode 100644 index 000000000..65d282708 --- /dev/null +++ b/packages/poseidon-proof/src/config.ts @@ -0,0 +1,8 @@ +import pkg from "../package.json" + +export const libraryName = pkg.name.split("/")[1] + +export const defaultSnarkArtifacts = { + wasmFilePath: "https://zkkit.cedoor.dev/poseidon-proof.wasm", + zkeyFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey" +} diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index 50a124171..4cb4807dc 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -1,20 +1,45 @@ import { prove } from "@zk-kit/groth16" -import type { NumericString } from "snarkjs" +import { defaultSnarkArtifacts, libraryName } from "./config" import packProof from "./packProof" -import { PoseidonProof, SnarkArtifacts } from "./types" +import { BigNumberish, PoseidonProof, SnarkArtifacts } from "./types" +import { isBrowser, isNode } from "./utils" /** */ export default async function generate( - message: NumericString, - scope: NumericString, + message: BigNumberish, + scope: BigNumberish, snarkArtifacts?: SnarkArtifacts ): Promise { if (!snarkArtifacts) { - snarkArtifacts = { - wasmFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey", - zkeyFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey" + if (isNode()) { + const download = await import("download") + const tmp = await import("tmp") + const fs = await import("fs") + + const tmpDir = libraryName + const tmpPath = `${tmp.tmpdir}/${tmpDir}` + + if (!fs.existsSync(tmpPath)) { + tmp.dirSync({ name: tmpDir }) + } + + await download.default(defaultSnarkArtifacts.wasmFilePath, tmpPath) + await download.default(defaultSnarkArtifacts.zkeyFilePath, tmpPath) + + snarkArtifacts = { + wasmFilePath: `${tmpPath}/poseidon-proof.wasm`, + zkeyFilePath: `${tmpPath}/poseidon-proof.zkey` + } } + + if (isBrowser()) { + snarkArtifacts = defaultSnarkArtifacts + } + } + + if (!snarkArtifacts) { + throw new Error("Error: Missing Snark artifacts. Please ensure all necessary Snark artifacts are included.") } const { proof, publicSignals } = await prove( diff --git a/packages/poseidon-proof/src/index.test.ts b/packages/poseidon-proof/src/index.test.ts index 5144296e3..560ad7eb2 100644 --- a/packages/poseidon-proof/src/index.test.ts +++ b/packages/poseidon-proof/src/index.test.ts @@ -6,10 +6,7 @@ import { PoseidonProof } from "./types" import unpackProof from "./unpackProof" describe("PoseidonProof", () => { - const scope = "1" - - const wasmFilePath = `./snark-artifacts/poseidon-proof.wasm` - const zkeyFilePath = `./snark-artifacts/poseidon-proof.zkey` + const scope = 1 let fullProof: PoseidonProof let curve: any @@ -24,10 +21,7 @@ describe("PoseidonProof", () => { describe("# generate", () => { it("Should generate a Poseidon proof", async () => { - fullProof = await generate("3", scope, { - wasmFilePath, - zkeyFilePath - }) + fullProof = await generate(3, scope) expect(typeof fullProof).toBe("object") }) diff --git a/packages/poseidon-proof/src/packProof.ts b/packages/poseidon-proof/src/packProof.ts index 6677eaeab..d70cc1c73 100644 --- a/packages/poseidon-proof/src/packProof.ts +++ b/packages/poseidon-proof/src/packProof.ts @@ -2,9 +2,9 @@ import { Groth16Proof } from "snarkjs" import { PackedProof } from "./types" /** - * Packs a proof into a format compatible with Semaphore. + * Packs a proof into a format compatible with PoseidonProof. * @param proof The Groth16 proof generated with SnarkJS. - * @returns The proof compatible with Semaphore. + * @returns The proof compatible with PoseidonProof. */ export default function packProof(proof: Groth16Proof): PackedProof { return [ diff --git a/packages/poseidon-proof/src/types/index.ts b/packages/poseidon-proof/src/types/index.ts index 736ad1378..efa109742 100644 --- a/packages/poseidon-proof/src/types/index.ts +++ b/packages/poseidon-proof/src/types/index.ts @@ -1,4 +1,6 @@ -import type { NumericString } from "snarkjs" +import type { NumericString, SignalValueType } from "snarkjs" + +export type BigNumberish = NumericString | number | bigint export type SnarkArtifacts = { wasmFilePath: string diff --git a/packages/poseidon-proof/src/unpackProof.ts b/packages/poseidon-proof/src/unpackProof.ts index 68ba66599..0086dc8b4 100644 --- a/packages/poseidon-proof/src/unpackProof.ts +++ b/packages/poseidon-proof/src/unpackProof.ts @@ -3,7 +3,7 @@ import { PackedProof } from "./types" /** * Unpacks a proof into its original form. - * @param proof The proof compatible with Semaphore. + * @param proof The proof compatible with PoseidonProof. * @returns The proof compatible with SnarkJS. */ export default function unpackProof(proof: PackedProof): Groth16Proof { diff --git a/packages/poseidon-proof/src/utils.ts b/packages/poseidon-proof/src/utils.ts new file mode 100644 index 000000000..6fcd51b58 --- /dev/null +++ b/packages/poseidon-proof/src/utils.ts @@ -0,0 +1,20 @@ +/** + * Secure method to check if the environment is Node.js. + * @returns true if the environment is Node.js, false otherwise. + */ +export function isNode(): boolean { + // Checking the existence of 'window' variable, or 'process' is not enough, + // as those variables can be redefined by inner scopes (by any module/library). + // In the 'new Function()' constructor, the execution scope of 'this' is bound + // to the global scope and it can be compared to the expected value (the objects + // will have the same id if the environment is the expected one). + return new Function("try {return this===global}catch(e){ return false}")() +} + +/** + * Secure method to check if the environment is a browser. + * @returns true if the environment is a browser, false otherwise. + */ +export function isBrowser(): boolean { + return new Function("try {return this===window}catch(e){ return false}")() +} diff --git a/tsconfig.json b/tsconfig.json index ceead27bd..9de0656b9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "baseUrl": ".", "strict": true, "target": "ES5", - "module": "ES6", + "module": "ES2020", "moduleResolution": "node", "resolveJsonModule": true, "esModuleInterop": true, diff --git a/yarn.lock b/yarn.lock index 7a3b73054..dfa310563 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3607,6 +3607,13 @@ __metadata: languageName: node linkType: hard +"@sindresorhus/is@npm:^0.7.0": + version: 0.7.0 + resolution: "@sindresorhus/is@npm:0.7.0" + checksum: decc50f6fe80b75c981bcff0a585c05259f5e04424a46a653ac9a7e065194145c463ca81001e3a229bd203f59474afadb5b1fa0af5507723f87f2dd45bd3897c + languageName: node + linkType: hard + "@sindresorhus/is@npm:^4.0.0, @sindresorhus/is@npm:^4.6.0": version: 4.6.0 resolution: "@sindresorhus/is@npm:4.6.0" @@ -3847,6 +3854,26 @@ __metadata: languageName: node linkType: hard +"@types/decompress@npm:*": + version: 4.2.7 + resolution: "@types/decompress@npm:4.2.7" + dependencies: + "@types/node": "*" + checksum: f2fcc588e0bbeed4f3897e25980d3a5cceba334b900f83c9ad91b9885e3b25b50bdc283a6d684b73442368f9f12f34b4eabfc7f422067c6a882591ed844aa65b + languageName: node + linkType: hard + +"@types/download@npm:^8.0.5": + version: 8.0.5 + resolution: "@types/download@npm:8.0.5" + dependencies: + "@types/decompress": "*" + "@types/got": ^9 + "@types/node": "*" + checksum: 10e807e9e4a6dc21918ff3ec302c41db529ba5488c7b296cd6ee7d5cefc872b35f0078d6f47671eb5dd40661d5128eab552c1882982c69fb4825b8a4943f30c9 + languageName: node + linkType: hard + "@types/estree@npm:*, @types/estree@npm:^1.0.0": version: 1.0.5 resolution: "@types/estree@npm:1.0.5" @@ -3890,6 +3917,17 @@ __metadata: languageName: node linkType: hard +"@types/got@npm:^9": + version: 9.6.12 + resolution: "@types/got@npm:9.6.12" + dependencies: + "@types/node": "*" + "@types/tough-cookie": "*" + form-data: ^2.5.0 + checksum: e6c17cf49107064bc0c4371efaef6855d4753b0e17b615da1a9ab7dcd10c6208c48620c7309e96861a4ea1a0d8b9e7cdda67316b4075d4ba2aff4d7400f92f53 + languageName: node + linkType: hard + "@types/graceful-fs@npm:^4.1.2": version: 4.1.9 resolution: "@types/graceful-fs@npm:4.1.9" @@ -3965,7 +4003,7 @@ __metadata: languageName: node linkType: hard -"@types/keyv@npm:^3.1.4": +"@types/keyv@npm:^3.1.1, @types/keyv@npm:^3.1.4": version: 3.1.4 resolution: "@types/keyv@npm:3.1.4" dependencies: @@ -4158,6 +4196,20 @@ __metadata: languageName: node linkType: hard +"@types/tmp@npm:^0.2.6": + version: 0.2.6 + resolution: "@types/tmp@npm:0.2.6" + checksum: 0b24bb6040cc289440a609e10ec99a704978c890a5828ff151576489090b2257ce2e2570b0f320ace9c8099c3642ea6221fbdf6d8f2e22b7cd1f4fbf6e989e3e + languageName: node + linkType: hard + +"@types/tough-cookie@npm:*": + version: 4.0.5 + resolution: "@types/tough-cookie@npm:4.0.5" + checksum: f19409d0190b179331586365912920d192733112a195e870c7f18d20ac8adb7ad0b0ff69dad430dba8bc2be09593453a719cfea92dc3bda19748fd158fe1498d + languageName: node + linkType: hard + "@types/yargs-parser@npm:*": version: 21.0.3 resolution: "@types/yargs-parser@npm:21.0.3" @@ -4407,11 +4459,15 @@ __metadata: resolution: "@zk-kit/poseidon-proof@workspace:packages/poseidon-proof" dependencies: "@rollup/plugin-json": ^5.0.1 + "@types/download": ^8.0.5 "@types/snarkjs": ^0.7.7 + "@types/tmp": ^0.2.6 "@zk-kit/groth16": 0.3.0 + download: ^8.0.0 rollup-plugin-cleanup: ^3.2.1 rollup-plugin-terser: ^7.0.2 rollup-plugin-typescript2: ^0.32.1 + tmp: ^0.2.1 languageName: unknown linkType: soft @@ -4776,6 +4832,15 @@ __metadata: languageName: node linkType: hard +"archive-type@npm:^4.0.0": + version: 4.0.0 + resolution: "archive-type@npm:4.0.0" + dependencies: + file-type: ^4.2.0 + checksum: 271f0d118294dd0305831f0700b635e8a9475f97693212d548eee48017f917e14349a25ad578f8e13486ba4b7cde1972d53e613d980e8738cfccea5fc626c76f + languageName: node + linkType: hard + "arg@npm:^4.1.0": version: 4.1.3 resolution: "arg@npm:4.1.3" @@ -5404,6 +5469,16 @@ __metadata: languageName: node linkType: hard +"bl@npm:^1.0.0": + version: 1.2.3 + resolution: "bl@npm:1.2.3" + dependencies: + readable-stream: ^2.3.5 + safe-buffer: ^5.1.1 + checksum: 123f097989ce2fa9087ce761cd41176aaaec864e28f7dfe5c7dab8ae16d66d9844f849c3ad688eb357e3c5e4f49b573e3c0780bb8bc937206735a3b6f8569a5f + languageName: node + linkType: hard + "bl@npm:^4.1.0": version: 4.1.0 resolution: "bl@npm:4.1.0" @@ -5695,6 +5770,37 @@ __metadata: languageName: node linkType: hard +"buffer-alloc-unsafe@npm:^1.1.0": + version: 1.1.0 + resolution: "buffer-alloc-unsafe@npm:1.1.0" + checksum: c5e18bf51f67754ec843c9af3d4c005051aac5008a3992938dda1344e5cfec77c4b02b4ca303644d1e9a6e281765155ce6356d85c6f5ccc5cd21afc868def396 + languageName: node + linkType: hard + +"buffer-alloc@npm:^1.2.0": + version: 1.2.0 + resolution: "buffer-alloc@npm:1.2.0" + dependencies: + buffer-alloc-unsafe: ^1.1.0 + buffer-fill: ^1.0.0 + checksum: 560cd27f3cbe73c614867da373407d4506309c62fe18de45a1ce191f3785ec6ca2488d802ff82065798542422980ca25f903db078c57822218182c37c3576df5 + languageName: node + linkType: hard + +"buffer-crc32@npm:~0.2.3": + version: 0.2.13 + resolution: "buffer-crc32@npm:0.2.13" + checksum: 06252347ae6daca3453b94e4b2f1d3754a3b146a111d81c68924c22d91889a40623264e95e67955b1cb4a68cbedf317abeabb5140a9766ed248973096db5ce1c + languageName: node + linkType: hard + +"buffer-fill@npm:^1.0.0": + version: 1.0.0 + resolution: "buffer-fill@npm:1.0.0" + checksum: c29b4723ddeab01e74b5d3b982a0c6828f2ded49cef049ddca3dac661c874ecdbcecb5dd8380cf0f4adbeb8cff90a7de724126750a1f1e5ebd4eb6c59a1315b1 + languageName: node + linkType: hard + "buffer-from@npm:1.x, buffer-from@npm:^1.0.0": version: 1.1.2 resolution: "buffer-from@npm:1.1.2" @@ -5716,7 +5822,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:^5.0.5, buffer@npm:^5.5.0, buffer@npm:^5.6.0": +"buffer@npm:^5.0.5, buffer@npm:^5.2.1, buffer@npm:^5.5.0, buffer@npm:^5.6.0": version: 5.7.1 resolution: "buffer@npm:5.7.1" dependencies: @@ -5821,6 +5927,21 @@ __metadata: languageName: node linkType: hard +"cacheable-request@npm:^2.1.1": + version: 2.1.4 + resolution: "cacheable-request@npm:2.1.4" + dependencies: + clone-response: 1.0.2 + get-stream: 3.0.0 + http-cache-semantics: 3.8.1 + keyv: 3.0.0 + lowercase-keys: 1.0.0 + normalize-url: 2.0.1 + responselike: 1.0.2 + checksum: 69c684cb3645f75af094e3ef6e7959ca5edff33d70737498de1a068d2f719a12786efdd82fe1e2254a1f332bb88cce088273bd78fad3e57cdef5034f3ded9432 + languageName: node + linkType: hard + "cacheable-request@npm:^7.0.2": version: 7.0.4 resolution: "cacheable-request@npm:7.0.4" @@ -6482,6 +6603,15 @@ __metadata: languageName: node linkType: hard +"clone-response@npm:1.0.2": + version: 1.0.2 + resolution: "clone-response@npm:1.0.2" + dependencies: + mimic-response: ^1.0.0 + checksum: 2d0e61547fc66276e0903be9654ada422515f5a15741691352000d47e8c00c226061221074ce2c0064d12e975e84a8687cfd35d8b405750cb4e772f87b256eda + languageName: node + linkType: hard + "clone-response@npm:^1.0.2": version: 1.0.3 resolution: "clone-response@npm:1.0.3" @@ -6634,7 +6764,7 @@ __metadata: languageName: node linkType: hard -"commander@npm:^2.20.0": +"commander@npm:^2.20.0, commander@npm:^2.8.1": version: 2.20.3 resolution: "commander@npm:2.20.3" checksum: ab8c07884e42c3a8dbc5dd9592c606176c7eb5c1ca5ff274bcf907039b2c41de3626f684ea75ccf4d361ba004bbaff1f577d5384c155f3871e456bdf27becf9e @@ -6738,7 +6868,7 @@ __metadata: languageName: node linkType: hard -"content-disposition@npm:0.5.4, content-disposition@npm:~0.5.2": +"content-disposition@npm:0.5.4, content-disposition@npm:^0.5.2, content-disposition@npm:~0.5.2": version: 0.5.4 resolution: "content-disposition@npm:0.5.4" dependencies: @@ -7245,6 +7375,69 @@ __metadata: languageName: node linkType: hard +"decompress-tar@npm:^4.0.0, decompress-tar@npm:^4.1.0, decompress-tar@npm:^4.1.1": + version: 4.1.1 + resolution: "decompress-tar@npm:4.1.1" + dependencies: + file-type: ^5.2.0 + is-stream: ^1.1.0 + tar-stream: ^1.5.2 + checksum: 42d5360b558a28dd884e1bf809e3fea92b9910fda5151add004d4a64cc76ac124e8b3e9117e805f2349af9e49c331d873e6fc5ad86a00e575703fee632b0a225 + languageName: node + linkType: hard + +"decompress-tarbz2@npm:^4.0.0": + version: 4.1.1 + resolution: "decompress-tarbz2@npm:4.1.1" + dependencies: + decompress-tar: ^4.1.0 + file-type: ^6.1.0 + is-stream: ^1.1.0 + seek-bzip: ^1.0.5 + unbzip2-stream: ^1.0.9 + checksum: 519c81337730159a1f2d7072a6ee8523ffd76df48d34f14c27cb0a27f89b4e2acf75dad2f761838e5bc63230cea1ac154b092ecb7504be4e93f7d0e32ddd6aff + languageName: node + linkType: hard + +"decompress-targz@npm:^4.0.0": + version: 4.1.1 + resolution: "decompress-targz@npm:4.1.1" + dependencies: + decompress-tar: ^4.1.1 + file-type: ^5.2.0 + is-stream: ^1.1.0 + checksum: 22738f58eb034568dc50d370c03b346c428bfe8292fe56165847376b5af17d3c028fefca82db642d79cb094df4c0a599d40a8f294b02aad1d3ddec82f3fd45d4 + languageName: node + linkType: hard + +"decompress-unzip@npm:^4.0.1": + version: 4.0.1 + resolution: "decompress-unzip@npm:4.0.1" + dependencies: + file-type: ^3.8.0 + get-stream: ^2.2.0 + pify: ^2.3.0 + yauzl: ^2.4.2 + checksum: ba9f3204ab2415bedb18d796244928a18148ef40dbb15174d0d01e5991b39536b03d02800a8a389515a1523f8fb13efc7cd44697df758cd06c674879caefd62b + languageName: node + linkType: hard + +"decompress@npm:^4.2.1": + version: 4.2.1 + resolution: "decompress@npm:4.2.1" + dependencies: + decompress-tar: ^4.0.0 + decompress-tarbz2: ^4.0.0 + decompress-targz: ^4.0.0 + decompress-unzip: ^4.0.1 + graceful-fs: ^4.1.10 + make-dir: ^1.0.0 + pify: ^2.3.0 + strip-dirs: ^2.0.0 + checksum: 8247a31c6db7178413715fdfb35a482f019c81dfcd6e8e623d9f0382c9889ce797ce0144de016b256ed03298907a620ce81387cca0e69067a933470081436cb8 + languageName: node + linkType: hard + "dedent@npm:0.7.0, dedent@npm:^0.7.0": version: 0.7.0 resolution: "dedent@npm:0.7.0" @@ -7527,6 +7720,32 @@ __metadata: languageName: node linkType: hard +"download@npm:^8.0.0": + version: 8.0.0 + resolution: "download@npm:8.0.0" + dependencies: + archive-type: ^4.0.0 + content-disposition: ^0.5.2 + decompress: ^4.2.1 + ext-name: ^5.0.0 + file-type: ^11.1.0 + filenamify: ^3.0.0 + get-stream: ^4.1.0 + got: ^8.3.1 + make-dir: ^2.1.0 + p-event: ^2.1.0 + pify: ^4.0.1 + checksum: 8a26b21eee8d23352265729dba8eea9f18cba0ebfa3e064041afffeefdfe508fc31e54a08bd0606ff8b0d548466bdb2e2e32b571a8f95227efa5b7c09c261a2f + languageName: node + linkType: hard + +"duplexer3@npm:^0.1.4": + version: 0.1.4 + resolution: "duplexer3@npm:0.1.4" + checksum: c2fd6969314607d23439c583699aaa43c4100d66b3e161df55dccd731acc57d5c81a64bb4f250805fbe434ddb1d2623fee2386fb890f5886ca1298690ec53415 + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" @@ -7628,7 +7847,7 @@ __metadata: languageName: node linkType: hard -"end-of-stream@npm:^1.1.0": +"end-of-stream@npm:^1.0.0, end-of-stream@npm:^1.1.0": version: 1.4.4 resolution: "end-of-stream@npm:1.4.4" dependencies: @@ -7808,7 +8027,7 @@ __metadata: languageName: node linkType: hard -"escape-string-regexp@npm:^1.0.5": +"escape-string-regexp@npm:^1.0.2, escape-string-regexp@npm:^1.0.5": version: 1.0.5 resolution: "escape-string-regexp@npm:1.0.5" checksum: 6092fda75c63b110c706b6a9bfde8a612ad595b628f0bd2147eea1d3406723020810e591effc7db1da91d80a71a737a313567c5abb3813e8d9c71f4aa595b410 @@ -8565,6 +8784,25 @@ __metadata: languageName: node linkType: hard +"ext-list@npm:^2.0.0": + version: 2.2.2 + resolution: "ext-list@npm:2.2.2" + dependencies: + mime-db: ^1.28.0 + checksum: 9b2426bea312e674eeced62c5f18407ab9a8653bbdfbde36492331c7973dab7fbf9e11d6c38605786168b42da333910314988097ca06eee61f1b9b57efae3f18 + languageName: node + linkType: hard + +"ext-name@npm:^5.0.0": + version: 5.0.0 + resolution: "ext-name@npm:5.0.0" + dependencies: + ext-list: ^2.0.0 + sort-keys-length: ^1.0.0 + checksum: f598269bd5de4295540ea7d6f8f6a01d82a7508f148b7700a05628ef6121648d26e6e5e942049e953b3051863df6b54bd8fe951e7877f185e34ace5d44370b33 + languageName: node + linkType: hard + "ext@npm:^1.1.2": version: 1.7.0 resolution: "ext@npm:1.7.0" @@ -8728,6 +8966,15 @@ __metadata: languageName: node linkType: hard +"fd-slicer@npm:~1.1.0": + version: 1.1.0 + resolution: "fd-slicer@npm:1.1.0" + dependencies: + pend: ~1.2.0 + checksum: c8585fd5713f4476eb8261150900d2cb7f6ff2d87f8feb306ccc8a1122efd152f1783bdb2b8dc891395744583436bfd8081d8e63ece0ec8687eeefea394d4ff2 + languageName: node + linkType: hard + "feature-policy@npm:0.3.0": version: 0.3.0 resolution: "feature-policy@npm:0.3.0" @@ -8911,6 +9158,41 @@ __metadata: languageName: node linkType: hard +"file-type@npm:^11.1.0": + version: 11.1.0 + resolution: "file-type@npm:11.1.0" + checksum: 66c2086867291fda760a245534bec1fbf12817dc6fd3426c2b41f29a37c71bb61f1091505c98f03a446703321cc1d4a8e873ce631f5763fc53178645d9eb3f85 + languageName: node + linkType: hard + +"file-type@npm:^3.8.0": + version: 3.9.0 + resolution: "file-type@npm:3.9.0" + checksum: 1db70b2485ac77c4edb4b8753c1874ee6194123533f43c2651820f96b518f505fa570b093fedd6672eb105ba9fb89c62f84b6492e46788e39c3447aed37afa2d + languageName: node + linkType: hard + +"file-type@npm:^4.2.0": + version: 4.4.0 + resolution: "file-type@npm:4.4.0" + checksum: f3e0b38bef643a330b3d98e3aa9d6f0f32d2d80cb9341f5612187bd53ac84489a4dc66b354bd0cff6b60bff053c7ef21eb8923d62e9f1196ac627b63bd7875ef + languageName: node + linkType: hard + +"file-type@npm:^5.2.0": + version: 5.2.0 + resolution: "file-type@npm:5.2.0" + checksum: b2b21c7fc3cfb3c6a3a18b0d5d7233b74d8c17d82757655766573951daf42962a5c809e5fc3637675b237c558ebc67e4958fb2cc5a4ad407bc545aaa40001c74 + languageName: node + linkType: hard + +"file-type@npm:^6.1.0": + version: 6.2.0 + resolution: "file-type@npm:6.2.0" + checksum: 749540cefcd4959121eb83e373ed84e49b2e5a510aa5d598b725bd772dd306ae41fd00d3162ae3f6563b4db5cfafbbd0df321de3f20c17e20a8c56431ae55e58 + languageName: node + linkType: hard + "file-uri-to-path@npm:1.0.0": version: 1.0.0 resolution: "file-uri-to-path@npm:1.0.0" @@ -8927,6 +9209,24 @@ __metadata: languageName: node linkType: hard +"filename-reserved-regex@npm:^2.0.0": + version: 2.0.0 + resolution: "filename-reserved-regex@npm:2.0.0" + checksum: 323a0020fd7f243238ffccab9d728cbc5f3a13c84b2c10e01efb09b8324561d7a51776be76f36603c734d4f69145c39a5d12492bf6142a28b50d7f90bd6190bc + languageName: node + linkType: hard + +"filenamify@npm:^3.0.0": + version: 3.0.0 + resolution: "filenamify@npm:3.0.0" + dependencies: + filename-reserved-regex: ^2.0.0 + strip-outer: ^1.0.0 + trim-repeated: ^1.0.0 + checksum: d419eaa1b8c331ab8616e1fffe33e4af135c60b5364320bbe015bc93ded89c6c301363f69593991de18a8f9dd278324c0a0d89fd554c30250306f4c16c956673 + languageName: node + linkType: hard + "fill-range@npm:^4.0.0": version: 4.0.0 resolution: "fill-range@npm:4.0.0" @@ -9125,7 +9425,7 @@ __metadata: languageName: node linkType: hard -"form-data@npm:^2.2.0": +"form-data@npm:^2.2.0, form-data@npm:^2.5.0": version: 2.5.1 resolution: "form-data@npm:2.5.1" dependencies: @@ -9206,6 +9506,23 @@ __metadata: languageName: node linkType: hard +"from2@npm:^2.1.1": + version: 2.3.0 + resolution: "from2@npm:2.3.0" + dependencies: + inherits: ^2.0.1 + readable-stream: ^2.0.0 + checksum: 6080eba0793dce32f475141fb3d54cc15f84ee52e420ee22ac3ab0ad639dc95a1875bc6eb9c0e1140e94972a36a89dc5542491b85f1ab8df0c126241e0f1a61b + languageName: node + linkType: hard + +"fs-constants@npm:^1.0.0": + version: 1.0.0 + resolution: "fs-constants@npm:1.0.0" + checksum: 18f5b718371816155849475ac36c7d0b24d39a11d91348cfcb308b4494824413e03572c403c86d3a260e049465518c4f0d5bd00f0371cdfcad6d4f30a85b350d + languageName: node + linkType: hard + "fs-extra@npm:9.1.0, fs-extra@npm:^9.1.0": version: 9.1.0 resolution: "fs-extra@npm:9.1.0" @@ -9382,7 +9699,7 @@ __metadata: languageName: node linkType: hard -"get-func-name@npm:^2.0.1, get-func-name@npm:^2.0.2": +"get-func-name@npm:^2.0.0, get-func-name@npm:^2.0.2": version: 2.0.2 resolution: "get-func-name@npm:2.0.2" checksum: 3f62f4c23647de9d46e6f76d2b3eafe58933a9b3830c60669e4180d6c601ce1b4aa310ba8366143f55e52b139f992087a9f0647274e8745621fa2af7e0acf13b @@ -9415,7 +9732,24 @@ __metadata: languageName: node linkType: hard -"get-stream@npm:^4.0.0": +"get-stream@npm:3.0.0, get-stream@npm:^3.0.0": + version: 3.0.0 + resolution: "get-stream@npm:3.0.0" + checksum: 36142f46005ed74ce3a45c55545ec4e7da8e243554179e345a786baf144e5c4a35fb7bdc49fadfa9f18bd08000589b6fe364abdadfc4e1eb0e1b9914a6bb9c56 + languageName: node + linkType: hard + +"get-stream@npm:^2.2.0": + version: 2.3.1 + resolution: "get-stream@npm:2.3.1" + dependencies: + object-assign: ^4.0.1 + pinkie-promise: ^2.0.0 + checksum: d82c86556e131ba7bef00233aa0aa7a51230e6deac11a971ce0f47cd43e2a5e968a3e3914cd082f07cd0d69425653b2f96735b0a7d5c5c03fef3ab857a531367 + languageName: node + linkType: hard + +"get-stream@npm:^4.0.0, get-stream@npm:^4.1.0": version: 4.1.0 resolution: "get-stream@npm:4.1.0" dependencies: @@ -9775,7 +10109,32 @@ __metadata: languageName: node linkType: hard -"graceful-fs@npm:^4.1.2, graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.1.9, graceful-fs@npm:^4.2.0, graceful-fs@npm:^4.2.4, graceful-fs@npm:^4.2.6, graceful-fs@npm:^4.2.9": +"got@npm:^8.3.1": + version: 8.3.2 + resolution: "got@npm:8.3.2" + dependencies: + "@sindresorhus/is": ^0.7.0 + cacheable-request: ^2.1.1 + decompress-response: ^3.3.0 + duplexer3: ^0.1.4 + get-stream: ^3.0.0 + into-stream: ^3.1.0 + is-retry-allowed: ^1.1.0 + isurl: ^1.0.0-alpha5 + lowercase-keys: ^1.0.0 + mimic-response: ^1.0.0 + p-cancelable: ^0.4.0 + p-timeout: ^2.0.1 + pify: ^3.0.0 + safe-buffer: ^5.1.1 + timed-out: ^4.0.1 + url-parse-lax: ^3.0.0 + url-to-options: ^1.0.1 + checksum: ab05bfcb6de86dc0c3fba8d25cc51cb2b09851ff3f6f899c86cde8c63b30269f8823d69dbbc6d03f7c58bb069f55a3c5f60aba74aad6721938652d8f35fd3165 + languageName: node + linkType: hard + +"graceful-fs@npm:^4.1.10, graceful-fs@npm:^4.1.2, graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.1.9, graceful-fs@npm:^4.2.0, graceful-fs@npm:^4.2.4, graceful-fs@npm:^4.2.6, graceful-fs@npm:^4.2.9": version: 4.2.11 resolution: "graceful-fs@npm:4.2.11" checksum: ac85f94da92d8eb6b7f5a8b20ce65e43d66761c55ce85ac96df6865308390da45a8d3f0296dd3a663de65d30ba497bd46c696cc1e248c72b13d6d567138a4fc7 @@ -9990,6 +10349,13 @@ __metadata: languageName: node linkType: hard +"has-symbol-support-x@npm:^1.4.1": + version: 1.4.2 + resolution: "has-symbol-support-x@npm:1.4.2" + checksum: ff06631d556d897424c00e8e79c10093ad34c93e88bb0563932d7837f148a4c90a4377abc5d8da000cb6637c0ecdb4acc9ae836c7cfd0ffc919986db32097609 + languageName: node + linkType: hard + "has-symbols@npm:^1.0.2, has-symbols@npm:^1.0.3": version: 1.0.3 resolution: "has-symbols@npm:1.0.3" @@ -9997,6 +10363,15 @@ __metadata: languageName: node linkType: hard +"has-to-string-tag-x@npm:^1.2.0": + version: 1.4.1 + resolution: "has-to-string-tag-x@npm:1.4.1" + dependencies: + has-symbol-support-x: ^1.4.1 + checksum: 804c4505727be7770f8b2f5e727ce31c9affc5b83df4ce12344f44b68d557fefb31f77751dbd739de900653126bcd71f8842fac06f97a3fae5422685ab0ce6f0 + languageName: node + linkType: hard + "has-tostringtag@npm:^1.0.0": version: 1.0.0 resolution: "has-tostringtag@npm:1.0.0" @@ -10240,6 +10615,13 @@ __metadata: languageName: node linkType: hard +"http-cache-semantics@npm:3.8.1": + version: 3.8.1 + resolution: "http-cache-semantics@npm:3.8.1" + checksum: b1108d37be478fa9b03890d4185217aac2256e9d2247ce6c6bd90bc5432687d68dc7710ba908cea6166fb983a849d902195241626cf175a3c62817a494c0f7f6 + languageName: node + linkType: hard + "http-cache-semantics@npm:^4.0.0, http-cache-semantics@npm:^4.1.1": version: 4.1.1 resolution: "http-cache-semantics@npm:4.1.1" @@ -10594,6 +10976,16 @@ __metadata: languageName: node linkType: hard +"into-stream@npm:^3.1.0": + version: 3.1.0 + resolution: "into-stream@npm:3.1.0" + dependencies: + from2: ^2.1.1 + p-is-promise: ^1.1.0 + checksum: e6e1a202227b20c446c251ef95348b3e8503cdc75aa2a09076f8821fc42c1b7fd43fabaeb8ed3cf9eb875942cfa4510b66949c5317997aa640921cc9bbadcd17 + languageName: node + linkType: hard + "io-ts@npm:1.10.4": version: 1.10.4 resolution: "io-ts@npm:1.10.4" @@ -10902,6 +11294,13 @@ __metadata: languageName: node linkType: hard +"is-natural-number@npm:^4.0.1": + version: 4.0.1 + resolution: "is-natural-number@npm:4.0.1" + checksum: 3e5e3d52e0dfa4fea923b5d2b8a5cdbd9bf110c4598d30304b98528b02f40c9058a2abf1bae10bcbaf2bac18ace41cff7bc9673aff339f8c8297fae74ae0e75d + languageName: node + linkType: hard + "is-negative-zero@npm:^2.0.2": version: 2.0.2 resolution: "is-negative-zero@npm:2.0.2" @@ -10941,6 +11340,13 @@ __metadata: languageName: node linkType: hard +"is-object@npm:^1.0.1": + version: 1.0.2 + resolution: "is-object@npm:1.0.2" + checksum: 971219c4b1985b9751f65e4c8296d3104f0457b0e8a70849e848a4a2208bc47317d73b3b85d4a369619cb2df8284dc22584cb2695a7d99aca5e8d0aa64fc075a + languageName: node + linkType: hard + "is-path-inside@npm:^3.0.3": version: 3.0.3 resolution: "is-path-inside@npm:3.0.3" @@ -10948,7 +11354,7 @@ __metadata: languageName: node linkType: hard -"is-plain-obj@npm:^1.1.0": +"is-plain-obj@npm:^1.0.0, is-plain-obj@npm:^1.1.0": version: 1.1.0 resolution: "is-plain-obj@npm:1.1.0" checksum: 0ee04807797aad50859652a7467481816cbb57e5cc97d813a7dcd8915da8195dc68c436010bf39d195226cde6a2d352f4b815f16f26b7bf486a5754290629931 @@ -10997,6 +11403,13 @@ __metadata: languageName: node linkType: hard +"is-retry-allowed@npm:^1.1.0": + version: 1.2.0 + resolution: "is-retry-allowed@npm:1.2.0" + checksum: 50d700a89ae31926b1c91b3eb0104dbceeac8790d8b80d02f5c76d9a75c2056f1bb24b5268a8a018dead606bddf116b2262e5ac07401eb8b8783b266ed22558d + languageName: node + linkType: hard + "is-shared-array-buffer@npm:^1.0.2": version: 1.0.2 resolution: "is-shared-array-buffer@npm:1.0.2" @@ -11217,6 +11630,16 @@ __metadata: languageName: node linkType: hard +"isurl@npm:^1.0.0-alpha5": + version: 1.0.0 + resolution: "isurl@npm:1.0.0" + dependencies: + has-to-string-tag-x: ^1.2.0 + is-object: ^1.0.1 + checksum: 28a96e019269d57015fa5869f19dda5a3ed1f7b21e3e0c4ff695419bd0541547db352aa32ee4a3659e811a177b0e37a5bc1a036731e71939dd16b59808ab92bd + languageName: node + linkType: hard + "jackspeak@npm:^2.3.5": version: 2.3.6 resolution: "jackspeak@npm:2.3.6" @@ -12315,6 +12738,13 @@ __metadata: languageName: node linkType: hard +"json-buffer@npm:3.0.0": + version: 3.0.0 + resolution: "json-buffer@npm:3.0.0" + checksum: 0cecacb8025370686a916069a2ff81f7d55167421b6aa7270ee74e244012650dd6bce22b0852202ea7ff8624fce50ff0ec1bdf95914ccb4553426e290d5a63fa + languageName: node + linkType: hard + "json-buffer@npm:3.0.1": version: 3.0.1 resolution: "json-buffer@npm:3.0.1" @@ -12499,6 +12929,15 @@ __metadata: languageName: node linkType: hard +"keyv@npm:3.0.0": + version: 3.0.0 + resolution: "keyv@npm:3.0.0" + dependencies: + json-buffer: 3.0.0 + checksum: 5182775e546cdbb88dc583825bc0e990164709f31904a219e3321b3bf564a301ac4e5255ba95f7fba466548eba793b356a04a0242110173b199a37192b3b565f + languageName: node + linkType: hard + "keyv@npm:^4.0.0, keyv@npm:^4.5.3": version: 4.5.4 resolution: "keyv@npm:4.5.4" @@ -12915,11 +13354,25 @@ __metadata: version: 2.3.7 resolution: "loupe@npm:2.3.7" dependencies: - get-func-name: ^2.0.1 + get-func-name: ^2.0.0 checksum: 96c058ec7167598e238bb7fb9def2f9339215e97d6685d9c1e3e4bdb33d14600e11fe7a812cf0c003dfb73ca2df374f146280b2287cae9e8d989e9d7a69a203b languageName: node linkType: hard +"lowercase-keys@npm:1.0.0": + version: 1.0.0 + resolution: "lowercase-keys@npm:1.0.0" + checksum: 2370110c149967038fd5eb278f9b2d889eb427487c0e7fb417ab2ef4d93bacba1c8f226cf2ef1c2848b3191f37d84167d4342fbee72a1a122086680adecf362b + languageName: node + linkType: hard + +"lowercase-keys@npm:^1.0.0": + version: 1.0.1 + resolution: "lowercase-keys@npm:1.0.1" + checksum: 4d045026595936e09953e3867722e309415ff2c80d7701d067546d75ef698dac218a4f53c6d1d0e7368b47e45fd7529df47e6cb56fbb90523ba599f898b3d147 + languageName: node + linkType: hard + "lowercase-keys@npm:^2.0.0": version: 2.0.0 resolution: "lowercase-keys@npm:2.0.0" @@ -12998,6 +13451,25 @@ __metadata: languageName: node linkType: hard +"make-dir@npm:^1.0.0": + version: 1.3.0 + resolution: "make-dir@npm:1.3.0" + dependencies: + pify: ^3.0.0 + checksum: c564f6e7bb5ace1c02ad56b3a5f5e07d074af0c0b693c55c7b2c2b148882827c8c2afc7b57e43338a9f90c125b58d604e8cf3e6990a48bf949dfea8c79668c0b + languageName: node + linkType: hard + +"make-dir@npm:^2.1.0": + version: 2.1.0 + resolution: "make-dir@npm:2.1.0" + dependencies: + pify: ^4.0.1 + semver: ^5.6.0 + checksum: 043548886bfaf1820323c6a2997e6d2fa51ccc2586ac14e6f14634f7458b4db2daf15f8c310e2a0abd3e0cddc64df1890d8fc7263033602c47bb12cbfcf86aab + languageName: node + linkType: hard + "make-dir@npm:^3.0.2": version: 3.1.0 resolution: "make-dir@npm:3.1.0" @@ -13232,7 +13704,7 @@ __metadata: languageName: node linkType: hard -"mime-db@npm:1.52.0": +"mime-db@npm:1.52.0, mime-db@npm:^1.28.0": version: 1.52.0 resolution: "mime-db@npm:1.52.0" checksum: 0d99a03585f8b39d68182803b12ac601d9c01abfa28ec56204fa330bc9f3d1c5e14beb049bafadb3dbdf646dfb94b87e24d4ec7b31b7279ef906a8ea9b6a513f @@ -14004,6 +14476,17 @@ __metadata: languageName: node linkType: hard +"normalize-url@npm:2.0.1": + version: 2.0.1 + resolution: "normalize-url@npm:2.0.1" + dependencies: + prepend-http: ^2.0.0 + query-string: ^5.0.1 + sort-keys: ^2.0.0 + checksum: 30e337ee03fc7f360c7d2b966438657fabd2628925cc58bffc893982fe4d2c59b397ae664fa2c319cd83565af73eee88906e80bc5eec91bc32b601920e770d75 + languageName: node + linkType: hard + "normalize-url@npm:^6.0.1": version: 6.1.0 resolution: "normalize-url@npm:6.1.0" @@ -14053,7 +14536,7 @@ __metadata: languageName: node linkType: hard -"object-assign@npm:^4, object-assign@npm:^4.1.0, object-assign@npm:^4.1.1": +"object-assign@npm:^4, object-assign@npm:^4.0.1, object-assign@npm:^4.1.0, object-assign@npm:^4.1.1": version: 4.1.1 resolution: "object-assign@npm:4.1.1" checksum: fcc6e4ea8c7fe48abfbb552578b1c53e0d194086e2e6bbbf59e0a536381a292f39943c6e9628af05b5528aa5e3318bb30d6b2e53cadaf5b8fe9e12c4b69af23f @@ -14279,6 +14762,13 @@ __metadata: languageName: node linkType: hard +"p-cancelable@npm:^0.4.0": + version: 0.4.1 + resolution: "p-cancelable@npm:0.4.1" + checksum: d11144d72ee3a99f62fe595cb0e13b8585ea73c3807b4a9671744f1bf5d3ccddb049247a4ec3ceff05ca4adba9d0bb0f1862829daf20795bf528c86fa088509c + languageName: node + linkType: hard + "p-cancelable@npm:^2.0.0": version: 2.1.1 resolution: "p-cancelable@npm:2.1.1" @@ -14300,6 +14790,15 @@ __metadata: languageName: node linkType: hard +"p-event@npm:^2.1.0": + version: 2.3.1 + resolution: "p-event@npm:2.3.1" + dependencies: + p-timeout: ^2.0.1 + checksum: 7f973c4c001045bcd561202fc1b2bdf9e148182bb28a7bafa8e7b2ebfaf71a4f9ba91554222040d364290e707e3ebbb049122b8eda9d2aac413b4cf8de0b79ff + languageName: node + linkType: hard + "p-finally@npm:^1.0.0": version: 1.0.0 resolution: "p-finally@npm:1.0.0" @@ -14307,6 +14806,13 @@ __metadata: languageName: node linkType: hard +"p-is-promise@npm:^1.1.0": + version: 1.1.0 + resolution: "p-is-promise@npm:1.1.0" + checksum: 64d7c6cda18af2c91c04209e5856c54d1a9818662d2320b34153d446645f431307e04406969a1be00cad680288e86dcf97b9eb39edd5dc4d0b1bd714ee85e13b + languageName: node + linkType: hard + "p-limit@npm:^1.1.0": version: 1.3.0 resolution: "p-limit@npm:1.3.0" @@ -14370,6 +14876,15 @@ __metadata: languageName: node linkType: hard +"p-timeout@npm:^2.0.1": + version: 2.0.1 + resolution: "p-timeout@npm:2.0.1" + dependencies: + p-finally: ^1.0.0 + checksum: 9205a661173f03adbeabda8e02826de876376b09c99768bdc33e5b25ae73230e3ac00e520acedbe3cf05fbd3352fb02efbd3811a9a021b148fb15eb07e7accac + languageName: node + linkType: hard + "p-try@npm:^1.0.0": version: 1.0.0 resolution: "p-try@npm:1.0.0" @@ -14551,6 +15066,13 @@ __metadata: languageName: node linkType: hard +"pend@npm:~1.2.0": + version: 1.2.0 + resolution: "pend@npm:1.2.0" + checksum: 6c72f5243303d9c60bd98e6446ba7d30ae29e3d56fdb6fae8767e8ba6386f33ee284c97efe3230a0d0217e2b1723b8ab490b1bbf34fcbb2180dbc8a9de47850d + languageName: node + linkType: hard + "perf-regexes@npm:^1.0.1": version: 1.0.1 resolution: "perf-regexes@npm:1.0.1" @@ -14588,6 +15110,20 @@ __metadata: languageName: node linkType: hard +"pify@npm:^2.3.0": + version: 2.3.0 + resolution: "pify@npm:2.3.0" + checksum: 9503aaeaf4577acc58642ad1d25c45c6d90288596238fb68f82811c08104c800e5a7870398e9f015d82b44ecbcbef3dc3d4251a1cbb582f6e5959fe09884b2ba + languageName: node + linkType: hard + +"pify@npm:^3.0.0": + version: 3.0.0 + resolution: "pify@npm:3.0.0" + checksum: 6cdcbc3567d5c412450c53261a3f10991665d660961e06605decf4544a61a97a54fefe70a68d5c37080ff9d6f4cf51444c90198d1ba9f9309a6c0d6e9f5c4fde + languageName: node + linkType: hard + "pify@npm:^4.0.1": version: 4.0.1 resolution: "pify@npm:4.0.1" @@ -14595,6 +15131,22 @@ __metadata: languageName: node linkType: hard +"pinkie-promise@npm:^2.0.0": + version: 2.0.1 + resolution: "pinkie-promise@npm:2.0.1" + dependencies: + pinkie: ^2.0.0 + checksum: b53a4a2e73bf56b6f421eef711e7bdcb693d6abb474d57c5c413b809f654ba5ee750c6a96dd7225052d4b96c4d053cdcb34b708a86fceed4663303abee52fcca + languageName: node + linkType: hard + +"pinkie@npm:^2.0.0": + version: 2.0.4 + resolution: "pinkie@npm:2.0.4" + checksum: b12b10afea1177595aab036fc220785488f67b4b0fc49e7a27979472592e971614fa1c728e63ad3e7eb748b4ec3c3dbd780819331dad6f7d635c77c10537b9db + languageName: node + linkType: hard + "pirates@npm:^4.0.1, pirates@npm:^4.0.4": version: 4.0.6 resolution: "pirates@npm:4.0.6" @@ -14669,6 +15221,13 @@ __metadata: languageName: node linkType: hard +"prepend-http@npm:^2.0.0": + version: 2.0.0 + resolution: "prepend-http@npm:2.0.0" + checksum: 7694a9525405447662c1ffd352fcb41b6410c705b739b6f4e3a3e21cf5fdede8377890088e8934436b8b17ba55365a615f153960f30877bf0d0392f9e93503ea + languageName: node + linkType: hard + "prettier-linter-helpers@npm:^1.0.0": version: 1.0.0 resolution: "prettier-linter-helpers@npm:1.0.0" @@ -15008,7 +15567,7 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:^2.2.2": +"readable-stream@npm:^2.0.0, readable-stream@npm:^2.2.2, readable-stream@npm:^2.3.0, readable-stream@npm:^2.3.5": version: 2.3.8 resolution: "readable-stream@npm:2.3.8" dependencies: @@ -15391,6 +15950,15 @@ __metadata: languageName: node linkType: hard +"responselike@npm:1.0.2": + version: 1.0.2 + resolution: "responselike@npm:1.0.2" + dependencies: + lowercase-keys: ^2.0.0 + checksum: 2e9e70f1dcca3da621a80ce71f2f9a9cad12c047145c6ece20df22f0743f051cf7c73505e109814915f23f9e34fb0d358e22827723ee3d56b623533cab8eafcd + languageName: node + linkType: hard + "responselike@npm:^2.0.0": version: 2.0.1 resolution: "responselike@npm:2.0.1" @@ -15796,12 +16364,24 @@ __metadata: languageName: node linkType: hard +"seek-bzip@npm:^1.0.5": + version: 1.0.6 + resolution: "seek-bzip@npm:1.0.6" + dependencies: + commander: ^2.8.1 + bin: + seek-bunzip: bin/seek-bunzip + seek-table: bin/seek-bzip-table + checksum: c2ab3291e7085558499efd4e99d1466ee6782f6c4a4e4c417aa859e1cd2f5117fb3b5444f3d27c38ec5908c0f0312e2a0bc69dff087751f97b3921b5bde4f9ed + languageName: node + linkType: hard + "semver@npm:2 || 3 || 4 || 5, semver@npm:^5.5.0": - version: 5.7.2 - resolution: "semver@npm:5.7.2" + version: 5.7.1 + resolution: "semver@npm:5.7.1" bin: semver: bin/semver - checksum: fb4ab5e0dd1c22ce0c937ea390b4a822147a9c53dbd2a9a0132f12fe382902beef4fbf12cf51bb955248d8d15874ce8cd89532569756384f994309825f10b686 + checksum: 57fd0acfd0bac382ee87cd52cd0aaa5af086a7dc8d60379dfe65fea491fb2489b6016400813930ecd61fd0952dae75c115287a1b16c234b1550887117744dfaf languageName: node linkType: hard @@ -15827,6 +16407,15 @@ __metadata: languageName: node linkType: hard +"semver@npm:^5.6.0": + version: 5.7.2 + resolution: "semver@npm:5.7.2" + bin: + semver: bin/semver + checksum: fb4ab5e0dd1c22ce0c937ea390b4a822147a9c53dbd2a9a0132f12fe382902beef4fbf12cf51bb955248d8d15874ce8cd89532569756384f994309825f10b686 + languageName: node + linkType: hard + "semver@npm:^6.0.0, semver@npm:^6.3.0, semver@npm:^6.3.1": version: 6.3.1 resolution: "semver@npm:6.3.1" @@ -16350,6 +16939,33 @@ __metadata: languageName: node linkType: hard +"sort-keys-length@npm:^1.0.0": + version: 1.0.1 + resolution: "sort-keys-length@npm:1.0.1" + dependencies: + sort-keys: ^1.0.0 + checksum: f9acac5fb31580a9e3d43b419dc86a1b75e85b79036a084d95dd4d1062b621c9589906588ac31e370a0dd381be46d8dbe900efa306d087ca9c912d7a59b5a590 + languageName: node + linkType: hard + +"sort-keys@npm:^1.0.0": + version: 1.1.2 + resolution: "sort-keys@npm:1.1.2" + dependencies: + is-plain-obj: ^1.0.0 + checksum: 5963fd191a2a185a5ec86f06e47721e8e04713eda43bb04ae60d2a8afb21241553dd5bc9d863ed2bd7c3d541b609b0c8d0e58836b1a3eb6764c09c094bcc8b00 + languageName: node + linkType: hard + +"sort-keys@npm:^2.0.0": + version: 2.0.0 + resolution: "sort-keys@npm:2.0.0" + dependencies: + is-plain-obj: ^1.0.0 + checksum: f0fd827fa9f8f866e98588d2a38c35209afbf1e9a05bb0e4ceeeb8bbf31d923c8902b0a7e0f561590ddb65e58eba6a74f74b991c85360bcc52e83a3f0d1cffd7 + languageName: node + linkType: hard + "source-map-resolve@npm:^0.5.0": version: 0.5.3 resolution: "source-map-resolve@npm:0.5.3" @@ -16712,6 +17328,15 @@ __metadata: languageName: node linkType: hard +"strip-dirs@npm:^2.0.0": + version: 2.1.0 + resolution: "strip-dirs@npm:2.1.0" + dependencies: + is-natural-number: ^4.0.1 + checksum: 9465547d71d8819daa7a5c9d4d783289ed8eac72eb06bd687bed382ce62af8ab8e6ffbda229805f5d2e71acce2ca4915e781c94190d284994cbc0b7cdc8303cc + languageName: node + linkType: hard + "strip-eof@npm:^1.0.0": version: 1.0.0 resolution: "strip-eof@npm:1.0.0" @@ -16751,6 +17376,15 @@ __metadata: languageName: node linkType: hard +"strip-outer@npm:^1.0.0": + version: 1.0.1 + resolution: "strip-outer@npm:1.0.1" + dependencies: + escape-string-regexp: ^1.0.2 + checksum: f8d65d33ca2b49aabc66bb41d689dda7b8b9959d320e3a40a2ef4d7079ff2f67ffb72db43f179f48dbf9495c2e33742863feab7a584d180fa62505439162c191 + languageName: node + linkType: hard + "supports-color@npm:8.1.1, supports-color@npm:^8.0.0": version: 8.1.1 resolution: "supports-color@npm:8.1.1" @@ -16882,6 +17516,21 @@ __metadata: languageName: node linkType: hard +"tar-stream@npm:^1.5.2": + version: 1.6.2 + resolution: "tar-stream@npm:1.6.2" + dependencies: + bl: ^1.0.0 + buffer-alloc: ^1.2.0 + end-of-stream: ^1.0.0 + fs-constants: ^1.0.0 + readable-stream: ^2.3.0 + to-buffer: ^1.1.1 + xtend: ^4.0.0 + checksum: a5d49e232d3e33321bbd150381b6a4e5046bf12b1c2618acb95435b7871efde4d98bd1891eb2200478a7142ef7e304e033eb29bbcbc90451a2cdfa1890e05245 + languageName: node + linkType: hard + "tar@npm:^4.0.2": version: 4.4.19 resolution: "tar@npm:4.4.19" @@ -17052,7 +17701,7 @@ __metadata: languageName: node linkType: hard -"tmp@npm:^0.2.0": +"tmp@npm:^0.2.0, tmp@npm:^0.2.1": version: 0.2.1 resolution: "tmp@npm:0.2.1" dependencies: @@ -17068,6 +17717,13 @@ __metadata: languageName: node linkType: hard +"to-buffer@npm:^1.1.1": + version: 1.1.1 + resolution: "to-buffer@npm:1.1.1" + checksum: 6c897f58c2bdd8b8b1645ea515297732fec6dafb089bf36d12370c102ff5d64abf2be9410e0b1b7cfc707bada22d9a4084558010bfc78dd7023748dc5dd9a1ce + languageName: node + linkType: hard + "to-fast-properties@npm:^2.0.0": version: 2.0.0 resolution: "to-fast-properties@npm:2.0.0" @@ -17174,6 +17830,15 @@ __metadata: languageName: node linkType: hard +"trim-repeated@npm:^1.0.0": + version: 1.0.0 + resolution: "trim-repeated@npm:1.0.0" + dependencies: + escape-string-regexp: ^1.0.2 + checksum: e25c235305b82c43f1d64a67a71226c406b00281755e4c2c4f3b1d0b09c687a535dd3c4483327f949f28bb89dc400a0bc5e5b749054f4b99f49ebfe48ba36496 + languageName: node + linkType: hard + "tryer@npm:^1.0.1": version: 1.0.1 resolution: "tryer@npm:1.0.1" @@ -17600,6 +18265,16 @@ __metadata: languageName: node linkType: hard +"unbzip2-stream@npm:^1.0.9": + version: 1.4.3 + resolution: "unbzip2-stream@npm:1.4.3" + dependencies: + buffer: ^5.2.1 + through: ^2.3.8 + checksum: 0e67c4a91f4fa0fc7b4045f8b914d3498c2fc2e8c39c359977708ec85ac6d6029840e97f508675fdbdf21fcb8d276ca502043406f3682b70f075e69aae626d1d + languageName: node + linkType: hard + "underscore@npm:1.12.1": version: 1.12.1 resolution: "underscore@npm:1.12.1" @@ -17764,6 +18439,15 @@ __metadata: languageName: node linkType: hard +"url-parse-lax@npm:^3.0.0": + version: 3.0.0 + resolution: "url-parse-lax@npm:3.0.0" + dependencies: + prepend-http: ^2.0.0 + checksum: 1040e357750451173132228036aff1fd04abbd43eac1fb3e4fca7495a078bcb8d33cb765fe71ad7e473d9c94d98fd67adca63bd2716c815a2da066198dd37217 + languageName: node + linkType: hard + "url-parse@npm:^1.5.3": version: 1.5.10 resolution: "url-parse@npm:1.5.10" @@ -17781,6 +18465,13 @@ __metadata: languageName: node linkType: hard +"url-to-options@npm:^1.0.1": + version: 1.0.1 + resolution: "url-to-options@npm:1.0.1" + checksum: 20e59f4578525fb0d30ffc22b13b5aa60bc9e57cefd4f5842720f5b57211b6dec54abeae2d675381ac4486fd1a2e987f1318725dea996e503ff89f8c8ce2c17e + languageName: node + linkType: hard + "use@npm:^3.1.0": version: 3.1.1 resolution: "use@npm:3.1.1" @@ -18821,6 +19512,16 @@ __metadata: languageName: node linkType: hard +"yauzl@npm:^2.4.2": + version: 2.10.0 + resolution: "yauzl@npm:2.10.0" + dependencies: + buffer-crc32: ~0.2.3 + fd-slicer: ~1.1.0 + checksum: 7f21fe0bbad6e2cb130044a5d1d0d5a0e5bf3d8d4f8c4e6ee12163ce798fee3de7388d22a7a0907f563ac5f9d40f8699a223d3d5c1718da90b0156da6904022b + languageName: node + linkType: hard + "ylru@npm:^1.2.0": version: 1.3.2 resolution: "ylru@npm:1.3.2" From 995db1c6878e9c75f681ad114c346523d05b33e6 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 12:47:07 +0000 Subject: [PATCH 05/27] chore(poseidon-proof): v0.2.0 --- packages/poseidon-proof/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index f3ee44cb2..7350083f7 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.1.0", + "version": "0.2.0", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.node.js", From f7f0b1c21eaf8e81b223e1fbbf6f0b9adb61e761 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 12:50:19 +0000 Subject: [PATCH 06/27] docs(poseidon-proof): update readme usage section --- packages/poseidon-proof/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index f2688e9ec..d5ed4c6f8 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -60,24 +60,25 @@ yarn add @zk-kit/poseidon-proof ## 📜 Usage \# **generate**( -message: _NumericString_, -scope: _NumericString_, +message: _BigNumberish_, +scope: _BigNumberish_, snarkArtifacts?: _SnarkArtifacts_ ): Promise\<_PoseidonProof_> ```typescript import { generate } from "@zk-kit/poseidon-proof" -const scope = "1" -const message = "2" +const scope = 1 +const message = 2 +const fullProof = await generate(message, scope) + +// If not specified, the Snark artifacts are download automatically. +// You can also specify them. const fullProof = await generate(message, scope, { zkeyFilePath: "./poseidon-proof.zkey", wasmFilePath: "./poseidon-proof.wasm" }) - -// You can also use the default zkey/wasm files (it only works from browsers!). -// const fullProof = await generate(message, scope) ``` \# **verify**(poseidonProof: _PoseidonProof_): Promise\<_boolean_> From 22cd9d00787e81c342e70732d634bd8313e3de14 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 12:57:59 +0000 Subject: [PATCH 07/27] fix(poseidon-proof): use correct dynamic default props --- packages/poseidon-proof/package.json | 6 +++--- packages/poseidon-proof/src/generate.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 7350083f7..2b435f5e0 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -3,10 +3,10 @@ "version": "0.2.0", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", - "main": "dist/index.node.js", + "main": "dist/index.js", "exports": { - "import": "./dist/index.node.mjs", - "require": "./dist/index.node.js", + "import": "./dist/index.mjs", + "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, "types": "dist/types/index.d.ts", diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index 4cb4807dc..2f381b622 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -13,8 +13,8 @@ export default async function generate( ): Promise { if (!snarkArtifacts) { if (isNode()) { - const download = await import("download") - const tmp = await import("tmp") + const { default: download } = await import("download") + const { default: tmp } = await import("tmp") const fs = await import("fs") const tmpDir = libraryName @@ -24,8 +24,8 @@ export default async function generate( tmp.dirSync({ name: tmpDir }) } - await download.default(defaultSnarkArtifacts.wasmFilePath, tmpPath) - await download.default(defaultSnarkArtifacts.zkeyFilePath, tmpPath) + await download(defaultSnarkArtifacts.wasmFilePath, tmpPath) + await download(defaultSnarkArtifacts.zkeyFilePath, tmpPath) snarkArtifacts = { wasmFilePath: `${tmpPath}/poseidon-proof.wasm`, From 16fb86241c2ff11106ecbcb9025c7f6ec8c43817 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 12:58:37 +0000 Subject: [PATCH 08/27] chore(poseidon-proof): v0.2.1 --- packages/poseidon-proof/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 2b435f5e0..ca6689626 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.2.0", + "version": "0.2.1", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", From cac92bbd41bb4d31c23db7a1729c2e25f815c4cd Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 13:52:03 +0000 Subject: [PATCH 09/27] refactor(poseidon-proof): make imports static --- packages/poseidon-proof/README.md | 2 +- packages/poseidon-proof/src/generate.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index d5ed4c6f8..d5996e066 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -73,7 +73,7 @@ const message = 2 const fullProof = await generate(message, scope) -// If not specified, the Snark artifacts are download automatically. +// If not specified, the Snark artifacts are downloaded automatically. // You can also specify them. const fullProof = await generate(message, scope, { zkeyFilePath: "./poseidon-proof.zkey", diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index 2f381b622..8742e99df 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -1,4 +1,7 @@ import { prove } from "@zk-kit/groth16" +import download from "download" +import fs from "fs" +import tmp from "tmp" import { defaultSnarkArtifacts, libraryName } from "./config" import packProof from "./packProof" import { BigNumberish, PoseidonProof, SnarkArtifacts } from "./types" @@ -13,10 +16,6 @@ export default async function generate( ): Promise { if (!snarkArtifacts) { if (isNode()) { - const { default: download } = await import("download") - const { default: tmp } = await import("tmp") - const fs = await import("fs") - const tmpDir = libraryName const tmpPath = `${tmp.tmpdir}/${tmpDir}` From 21c6b8de79598076becc52308511d20f05280cb1 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 13:52:34 +0000 Subject: [PATCH 10/27] chore(poseidon-proof): v0.2.2 --- packages/poseidon-proof/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index ca6689626..9e00f1488 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.2.1", + "version": "0.2.2", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", From e7b67f9c1af35882260c5ac22be5dba21104e62c Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 13:55:29 +0000 Subject: [PATCH 11/27] fix(poseidon-proof): download snark artifacts when needed --- packages/poseidon-proof/src/generate.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index 8742e99df..af2a8d296 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -21,10 +21,10 @@ export default async function generate( if (!fs.existsSync(tmpPath)) { tmp.dirSync({ name: tmpDir }) - } - await download(defaultSnarkArtifacts.wasmFilePath, tmpPath) - await download(defaultSnarkArtifacts.zkeyFilePath, tmpPath) + await download(defaultSnarkArtifacts.wasmFilePath, tmpPath) + await download(defaultSnarkArtifacts.zkeyFilePath, tmpPath) + } snarkArtifacts = { wasmFilePath: `${tmpPath}/poseidon-proof.wasm`, From c8ec21adb5b42376d648d98e999b09b00cc12f56 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 23 Nov 2023 13:56:04 +0000 Subject: [PATCH 12/27] chore(poseidon-proof): v0.2.3 --- packages/poseidon-proof/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 9e00f1488..86a89cade 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.2.2", + "version": "0.2.3", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", From 625bb4b62934e4f1077f15b7fbc3708e441d5f0d Mon Sep 17 00:00:00 2001 From: Cedoor Date: Fri, 24 Nov 2023 13:01:31 +0000 Subject: [PATCH 13/27] docs(poseidon-proof): update README description --- packages/poseidon-proof/README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index d5996e066..bcd35aa8a 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -41,6 +41,21 @@ +| This zero-knowledge library facilitates the demonstration of having a Poseidon hash pre-image while keeping the pre-image value confidential. Additionally, it offers a mechanism to prevent the same proof from being reused. The circuit that forms the foundation of this library is accessible via this [link](https://github.com/privacy-scaling-explorations/zk-kit/blob/main/packages/circuits/templates/poseidon-proof.circom). | +| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + +Originally developed for integration with [Semaphore V4](https://github.com/semaphore-protocol/semaphore), this library also functions effectively as a standalone tool. Notable use cases in connection with Semaphore can be: + +* allowing a Semaphore user to prove that they possess the secret value associated with the identity commitment of their Semaphore identity, +* unmasking the identity of zero-knowledge proofs earlier created using Semaphore. + +The Snark artifacts (`.wasm` and `.zkey` files) can be specified or not in the `generate` function parameters and can possibly be downloaded using the following URLs: + +https://github.com/privacy-scaling-explorations/zk-kit/blob/ee457299d36d2601e5bf520237977a9f16b1b599/packages/poseidon-proof/src/config.ts#L5-L8 + +> [!WARNING] +> The Snark artifacts currently used to generate zero-knowledge proofs are the result of an unsecure trusted setup, and the library has not yet been audited. Therefore, it is advised not to use it in production. + ## 🛠 Install ### npm or yarn From 7e91fb8f67a5377902804bc6640afefa83a6ad85 Mon Sep 17 00:00:00 2001 From: Cedoor Date: Fri, 24 Nov 2023 16:30:25 +0000 Subject: [PATCH 14/27] docs(poseidon-proof): add benchmarks --- packages/poseidon-proof/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index bcd35aa8a..3d671c645 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -56,6 +56,14 @@ https://github.com/privacy-scaling-explorations/zk-kit/blob/ee457299d36d2601e5bf > [!WARNING] > The Snark artifacts currently used to generate zero-knowledge proofs are the result of an unsecure trusted setup, and the library has not yet been audited. Therefore, it is advised not to use it in production. +## 📈 Benchmarks + +Benchmarks were run on an Intel Core i7-1165G7, 16 GB RAM machine, after initializing the BN128 curve with [`@zk-kit/groth16`](https://github.com/privacy-scaling-explorations/zk-kit/edit/main/packages/groth16)-`buildBn128` (~230ms). + +| Generate proof | Verify proof | Constraints | +| -------------- | ------------ | ----------- | +| `80ms` | `10ms` | `141` | + ## 🛠 Install ### npm or yarn From e9de87af0be6c24f057e3b7116a79603591a924e Mon Sep 17 00:00:00 2001 From: Cedoor Date: Fri, 24 Nov 2023 16:41:53 +0000 Subject: [PATCH 15/27] docs(poseidon-proof): update usage readme section --- packages/poseidon-proof/README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index 3d671c645..bbaaaaf18 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -102,6 +102,25 @@ const fullProof = await generate(message, scope, { zkeyFilePath: "./poseidon-proof.zkey", wasmFilePath: "./poseidon-proof.wasm" }) + +console.log(fullProof) +/* +{ + scope: '1', + hash: '8645981980787649023086883978738420856660271013038108762834452721572614684349', + nullifier: '7853200120776062878684798364095072458815029376092732009249414926327459813530', + proof: [ + '8439157877715136449451128027974582198942685548176158240742469858289217640295', + '7742778415084033741154475792823260193410560424636243716622958831215275441500', + '19005176609208302398813682947612978224483117018101271134113308439452561466691', + '6209272538382784759793219866517186573065390524051102537220446165983489601194', + '12222537243697573476419214640884921904066033266502734603198915705889607365883', + '20066191345466355816238393590466176790809335456890624395337970890893401456064', + '4851746896803117511000878727783002155680855098198108089136166702412365578625', + '18391775232946751568173446051923718267369779168471637305003186214102154164036' + ] +} +*/ ``` \# **verify**(poseidonProof: _PoseidonProof_): Promise\<_boolean_> @@ -109,5 +128,9 @@ const fullProof = await generate(message, scope, { ```typescript import { verify } from "@zk-key/poseidon-proof" -await verifyProof(fullProof) +const response = await verifyProof(fullProof) + +console.log(response) // true or false + +// Eventually you may want to check the nullifier. ``` From 2249d1e9bee8049a287320f11e99efb2c256a3c8 Mon Sep 17 00:00:00 2001 From: Cedoor Date: Fri, 24 Nov 2023 16:45:43 +0000 Subject: [PATCH 16/27] docs(poseidon-proof): update benchmarks section --- packages/poseidon-proof/README.md | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index bbaaaaf18..ba819941e 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -56,14 +56,6 @@ https://github.com/privacy-scaling-explorations/zk-kit/blob/ee457299d36d2601e5bf > [!WARNING] > The Snark artifacts currently used to generate zero-knowledge proofs are the result of an unsecure trusted setup, and the library has not yet been audited. Therefore, it is advised not to use it in production. -## 📈 Benchmarks - -Benchmarks were run on an Intel Core i7-1165G7, 16 GB RAM machine, after initializing the BN128 curve with [`@zk-kit/groth16`](https://github.com/privacy-scaling-explorations/zk-kit/edit/main/packages/groth16)-`buildBn128` (~230ms). - -| Generate proof | Verify proof | Constraints | -| -------------- | ------------ | ----------- | -| `80ms` | `10ms` | `141` | - ## 🛠 Install ### npm or yarn @@ -134,3 +126,30 @@ console.log(response) // true or false // Eventually you may want to check the nullifier. ``` + +## 📈 Benchmarks + +Benchmarks were run on an Intel Core i7-1165G7, 16 GB RAM machine, after initializing the BN128 curve with [`@zk-kit/groth16`](https://github.com/privacy-scaling-explorations/zk-kit/edit/main/packages/groth16)-`buildBn128` (~230ms). + +| Generate proof | Verify proof | Constraints | +| -------------- | ------------ | ----------- | +| `80ms` | `10ms` | `141` | + +```js +import { generate, verify } from "@zk-kit/poseidon-proof" +import { buildBn128 } from "@zk-kit/groth16" + +await buildBn128() + +console.time("generate") + +const proof = await generate(1, 2) + +console.timeEnd("generate") + +console.time("verify") + +console.log(await verify(proof)) + +console.timeEnd("verify") +``` From 0afa086131375ff6e86ba1de1e0457eb1f9bd9ce Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 17:22:58 +0000 Subject: [PATCH 17/27] docs(poseidon-proof): add comments to main functions --- packages/poseidon-proof/src/generate.ts | 20 ++++++++++++++++++-- packages/poseidon-proof/src/verify.ts | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index af2a8d296..edc590d75 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -8,12 +8,27 @@ import { BigNumberish, PoseidonProof, SnarkArtifacts } from "./types" import { isBrowser, isNode } from "./utils" /** + * Creates a zero-knowledge proof to prove that you have the pre-image or + * the original message of a hash, without disclosing the actual message itself. + * The use of a scope parameter along with a nullifier helps ensure the uniqueness + * and non-reusability of the proofs, enhancing security in applications like + * blockchain transactions or private data verification. + * If, for example, this package were used with Semaphore to demonstrate possession + * of a Semaphore identity of a group of voters, the scope could be the poll's ID. + * @param message The message (or pre-image) of the hash. + * @param scope A public value used to contextualize the cryptographic proof + * and calculate the nullifier. + * @param snarkArtifacts The Snark artifacts (wasm and zkey files) generated in + * a trusted setup of the circuit are necessary to generate valid proofs + * @returns The Poseidon zero-knowledge proof. */ export default async function generate( message: BigNumberish, scope: BigNumberish, snarkArtifacts?: SnarkArtifacts ): Promise { + // If the Snark artifacts are not defined they will be automatically downloaded. + /* istanbul ignore next */ if (!snarkArtifacts) { if (isNode()) { const tmpDir = libraryName @@ -37,6 +52,7 @@ export default async function generate( } } + /* istanbul ignore next */ if (!snarkArtifacts) { throw new Error("Error: Missing Snark artifacts. Please ensure all necessary Snark artifacts are included.") } @@ -51,9 +67,9 @@ export default async function generate( ) return { - scope: publicSignals[0], + scope: publicSignals[2], hash: publicSignals[1], - nullifier: publicSignals[2], + nullifier: publicSignals[0], proof: packProof(proof) } } diff --git a/packages/poseidon-proof/src/verify.ts b/packages/poseidon-proof/src/verify.ts index eee2fd88a..dfe4beaa3 100644 --- a/packages/poseidon-proof/src/verify.ts +++ b/packages/poseidon-proof/src/verify.ts @@ -4,10 +4,13 @@ import verificationKey from "./verification-key.json" import { PoseidonProof } from "./types" /** + * Verifies that a Poseidon proof is valid. + * @param poseidonProof The Poseidon zero-knowledge proof. + * @returns True if the proof is valid, false otherwise. */ export default function verify({ scope, hash, nullifier, proof }: PoseidonProof): Promise { return _verify(verificationKey, { - publicSignals: [scope, hash, nullifier], + publicSignals: [nullifier, hash, scope], proof: unpackProof(proof) }) } From 8157f7ca05dcb541c1cdc0e743e98b0b4c2d8794 Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 17:23:33 +0000 Subject: [PATCH 18/27] test(poseidon-proof): add more tests --- packages/poseidon-proof/package.json | 1 + packages/poseidon-proof/src/index.test.ts | 24 +++++++++++++++++++---- yarn.lock | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 86a89cade..427938f24 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -37,6 +37,7 @@ "@types/download": "^8.0.5", "@types/snarkjs": "^0.7.7", "@types/tmp": "^0.2.6", + "poseidon-lite": "^0.2.0", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.32.1" diff --git a/packages/poseidon-proof/src/index.test.ts b/packages/poseidon-proof/src/index.test.ts index 560ad7eb2..7b25ab5c3 100644 --- a/packages/poseidon-proof/src/index.test.ts +++ b/packages/poseidon-proof/src/index.test.ts @@ -1,12 +1,14 @@ import { buildBn128 } from "@zk-kit/groth16" +import { poseidon2, poseidon1 } from "poseidon-lite" import generate from "./generate" -import verify from "./verify" import packProof from "./packProof" import { PoseidonProof } from "./types" import unpackProof from "./unpackProof" +import verify from "./verify" describe("PoseidonProof", () => { const scope = 1 + const message = 2 let fullProof: PoseidonProof let curve: any @@ -21,18 +23,32 @@ describe("PoseidonProof", () => { describe("# generate", () => { it("Should generate a Poseidon proof", async () => { - fullProof = await generate(3, scope) + fullProof = await generate(message, scope) - expect(typeof fullProof).toBe("object") + const hash = poseidon1([message]) + const nullifier = poseidon2([scope, message]) + + expect(fullProof.proof).toHaveLength(8) + expect(fullProof.scope).toBe(scope.toString()) + expect(fullProof.hash).toBe(hash.toString()) + expect(fullProof.nullifier).toBe(nullifier.toString()) }) }) describe("# verify", () => { - it("Should verify a Semaphore proof", async () => { + it("Should verify a valid Poseidon proof", async () => { const response = await verify(fullProof) expect(response).toBe(true) }) + + it("Should verify an invalid Poseidon proof", async () => { + fullProof.hash = "3" + + const response = await verify(fullProof) + + expect(response).toBe(false) + }) }) describe("# packProof/unpackProof", () => { diff --git a/yarn.lock b/yarn.lock index dfa310563..c52ce7f23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4464,6 +4464,7 @@ __metadata: "@types/tmp": ^0.2.6 "@zk-kit/groth16": 0.3.0 download: ^8.0.0 + poseidon-lite: ^0.2.0 rollup-plugin-cleanup: ^3.2.1 rollup-plugin-terser: ^7.0.2 rollup-plugin-typescript2: ^0.32.1 From 339b1a2ce6288b9962608b37eeff192405436f0e Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 17:49:18 +0000 Subject: [PATCH 19/27] feat(poseidon-proof): hash preimage and scope --- packages/poseidon-proof/package.json | 4 +++- packages/poseidon-proof/src/generate.ts | 25 ++++++++++++---------- packages/poseidon-proof/src/hash.ts | 16 ++++++++++++++ packages/poseidon-proof/src/index.test.ts | 15 +++++++------ packages/poseidon-proof/src/index.ts | 2 +- packages/poseidon-proof/src/types/index.ts | 6 ++---- packages/poseidon-proof/src/verify.ts | 7 +++--- yarn.lock | 11 +++------- 8 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 packages/poseidon-proof/src/hash.ts diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 427938f24..9e3f9eed8 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -35,7 +35,6 @@ "devDependencies": { "@rollup/plugin-json": "^5.0.1", "@types/download": "^8.0.5", - "@types/snarkjs": "^0.7.7", "@types/tmp": "^0.2.6", "poseidon-lite": "^0.2.0", "rollup-plugin-cleanup": "^3.2.1", @@ -43,6 +42,9 @@ "rollup-plugin-typescript2": "^0.32.1" }, "dependencies": { + "@ethersproject/bignumber": "^5.7.0", + "@ethersproject/bytes": "^5.7.0", + "@ethersproject/keccak256": "^5.7.0", "@zk-kit/groth16": "0.3.0", "download": "^8.0.0", "tmp": "^0.2.1" diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index edc590d75..e5a0f6797 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -1,21 +1,24 @@ -import { prove } from "@zk-kit/groth16" +import { BigNumber } from "@ethersproject/bignumber" +import { BytesLike, Hexable } from "@ethersproject/bytes" +import { NumericString, prove } from "@zk-kit/groth16" import download from "download" import fs from "fs" import tmp from "tmp" import { defaultSnarkArtifacts, libraryName } from "./config" +import hash from "./hash" import packProof from "./packProof" -import { BigNumberish, PoseidonProof, SnarkArtifacts } from "./types" +import { PoseidonProof, SnarkArtifacts } from "./types" import { isBrowser, isNode } from "./utils" /** - * Creates a zero-knowledge proof to prove that you have the pre-image or - * the original message of a hash, without disclosing the actual message itself. + * Creates a zero-knowledge proof to prove that you have the pre-image of a hash, + * without disclosing the actual preimage itself. * The use of a scope parameter along with a nullifier helps ensure the uniqueness * and non-reusability of the proofs, enhancing security in applications like * blockchain transactions or private data verification. * If, for example, this package were used with Semaphore to demonstrate possession * of a Semaphore identity of a group of voters, the scope could be the poll's ID. - * @param message The message (or pre-image) of the hash. + * @param preimage The preimage of the hash. * @param scope A public value used to contextualize the cryptographic proof * and calculate the nullifier. * @param snarkArtifacts The Snark artifacts (wasm and zkey files) generated in @@ -23,8 +26,8 @@ import { isBrowser, isNode } from "./utils" * @returns The Poseidon zero-knowledge proof. */ export default async function generate( - message: BigNumberish, - scope: BigNumberish, + preimage: BytesLike | Hexable | number | bigint, + scope: BytesLike | Hexable | number | bigint, snarkArtifacts?: SnarkArtifacts ): Promise { // If the Snark artifacts are not defined they will be automatically downloaded. @@ -59,16 +62,16 @@ export default async function generate( const { proof, publicSignals } = await prove( { - in: message, - scope + in: hash(preimage), + scope: hash(scope) }, snarkArtifacts.wasmFilePath, snarkArtifacts.zkeyFilePath ) return { - scope: publicSignals[2], - hash: publicSignals[1], + scope: BigNumber.from(scope).toString() as NumericString, + digest: publicSignals[1], nullifier: publicSignals[0], proof: packProof(proof) } diff --git a/packages/poseidon-proof/src/hash.ts b/packages/poseidon-proof/src/hash.ts new file mode 100644 index 000000000..2b7225342 --- /dev/null +++ b/packages/poseidon-proof/src/hash.ts @@ -0,0 +1,16 @@ +import { BigNumber } from "@ethersproject/bignumber" +import { BytesLike, Hexable, zeroPad } from "@ethersproject/bytes" +import { keccak256 } from "@ethersproject/keccak256" +import { NumericString } from "@zk-kit/groth16" + +/** + * Creates a keccak256 hash of a message compatible with the SNARK scalar modulus. + * @param message The message to be hashed. + * @returns The message digest. + */ +export default function hash(message: BytesLike | Hexable | number | bigint): NumericString { + message = BigNumber.from(message).toTwos(256).toHexString() + message = zeroPad(message, 32) + + return (BigInt(keccak256(message)) >> BigInt(8)).toString() as NumericString +} diff --git a/packages/poseidon-proof/src/index.test.ts b/packages/poseidon-proof/src/index.test.ts index 7b25ab5c3..76ada93d7 100644 --- a/packages/poseidon-proof/src/index.test.ts +++ b/packages/poseidon-proof/src/index.test.ts @@ -1,14 +1,15 @@ import { buildBn128 } from "@zk-kit/groth16" -import { poseidon2, poseidon1 } from "poseidon-lite" +import { poseidon1, poseidon2 } from "poseidon-lite" import generate from "./generate" import packProof from "./packProof" import { PoseidonProof } from "./types" import unpackProof from "./unpackProof" import verify from "./verify" +import hash from "./hash" describe("PoseidonProof", () => { + const preimage = 2 const scope = 1 - const message = 2 let fullProof: PoseidonProof let curve: any @@ -23,14 +24,14 @@ describe("PoseidonProof", () => { describe("# generate", () => { it("Should generate a Poseidon proof", async () => { - fullProof = await generate(message, scope) + fullProof = await generate(preimage, scope) - const hash = poseidon1([message]) - const nullifier = poseidon2([scope, message]) + const digest = poseidon1([hash(preimage)]) + const nullifier = poseidon2([hash(scope), hash(preimage)]) expect(fullProof.proof).toHaveLength(8) expect(fullProof.scope).toBe(scope.toString()) - expect(fullProof.hash).toBe(hash.toString()) + expect(fullProof.digest).toBe(digest.toString()) expect(fullProof.nullifier).toBe(nullifier.toString()) }) }) @@ -43,7 +44,7 @@ describe("PoseidonProof", () => { }) it("Should verify an invalid Poseidon proof", async () => { - fullProof.hash = "3" + fullProof.digest = "3" const response = await verify(fullProof) diff --git a/packages/poseidon-proof/src/index.ts b/packages/poseidon-proof/src/index.ts index 78f8eb6dc..8db0e3ab5 100644 --- a/packages/poseidon-proof/src/index.ts +++ b/packages/poseidon-proof/src/index.ts @@ -1,5 +1,5 @@ import generate from "./generate" -import verify from "./verify" +import verify from "./verify.1" export * from "./types" export { generate, verify } diff --git a/packages/poseidon-proof/src/types/index.ts b/packages/poseidon-proof/src/types/index.ts index efa109742..b4aa7982d 100644 --- a/packages/poseidon-proof/src/types/index.ts +++ b/packages/poseidon-proof/src/types/index.ts @@ -1,6 +1,4 @@ -import type { NumericString, SignalValueType } from "snarkjs" - -export type BigNumberish = NumericString | number | bigint +import { NumericString } from "@zk-kit/groth16" export type SnarkArtifacts = { wasmFilePath: string @@ -9,7 +7,7 @@ export type SnarkArtifacts = { export type PoseidonProof = { scope: NumericString - hash: NumericString + digest: NumericString nullifier: NumericString proof: PackedProof } diff --git a/packages/poseidon-proof/src/verify.ts b/packages/poseidon-proof/src/verify.ts index dfe4beaa3..9ee0eb00e 100644 --- a/packages/poseidon-proof/src/verify.ts +++ b/packages/poseidon-proof/src/verify.ts @@ -1,16 +1,17 @@ import { verify as _verify } from "@zk-kit/groth16" +import hash from "./hash" +import { PoseidonProof } from "./types" import unpackProof from "./unpackProof" import verificationKey from "./verification-key.json" -import { PoseidonProof } from "./types" /** * Verifies that a Poseidon proof is valid. * @param poseidonProof The Poseidon zero-knowledge proof. * @returns True if the proof is valid, false otherwise. */ -export default function verify({ scope, hash, nullifier, proof }: PoseidonProof): Promise { +export default function verify({ scope, digest, nullifier, proof }: PoseidonProof): Promise { return _verify(verificationKey, { - publicSignals: [nullifier, hash, scope], + publicSignals: [nullifier, digest, hash(scope)], proof: unpackProof(proof) }) } diff --git a/yarn.lock b/yarn.lock index c52ce7f23..8dc47852e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4182,13 +4182,6 @@ __metadata: languageName: node linkType: hard -"@types/snarkjs@npm:^0.7.7": - version: 0.7.7 - resolution: "@types/snarkjs@npm:0.7.7" - checksum: 24e655c4828c13f4fb486b00c4051aac6df0c43c27a65c0311fc85f9dcba9da2dbea567e6d87ccfd6971cd550b36bca539de3ac53a91db2b67e1c777530def1f - languageName: node - linkType: hard - "@types/stack-utils@npm:^2.0.0": version: 2.0.3 resolution: "@types/stack-utils@npm:2.0.3" @@ -4458,9 +4451,11 @@ __metadata: version: 0.0.0-use.local resolution: "@zk-kit/poseidon-proof@workspace:packages/poseidon-proof" dependencies: + "@ethersproject/bignumber": ^5.7.0 + "@ethersproject/bytes": ^5.7.0 + "@ethersproject/keccak256": ^5.7.0 "@rollup/plugin-json": ^5.0.1 "@types/download": ^8.0.5 - "@types/snarkjs": ^0.7.7 "@types/tmp": ^0.2.6 "@zk-kit/groth16": 0.3.0 download: ^8.0.0 From 5c1a86fe7e607e5ea02d364c863d0d8c3fa053af Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 17:58:49 +0000 Subject: [PATCH 20/27] fix(poseidon-proof): fix ts errors --- packages/poseidon-proof/src/index.ts | 2 +- packages/poseidon-proof/src/packProof.ts | 2 +- packages/poseidon-proof/src/unpackProof.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/poseidon-proof/src/index.ts b/packages/poseidon-proof/src/index.ts index 8db0e3ab5..78f8eb6dc 100644 --- a/packages/poseidon-proof/src/index.ts +++ b/packages/poseidon-proof/src/index.ts @@ -1,5 +1,5 @@ import generate from "./generate" -import verify from "./verify.1" +import verify from "./verify" export * from "./types" export { generate, verify } diff --git a/packages/poseidon-proof/src/packProof.ts b/packages/poseidon-proof/src/packProof.ts index d70cc1c73..9926de915 100644 --- a/packages/poseidon-proof/src/packProof.ts +++ b/packages/poseidon-proof/src/packProof.ts @@ -1,4 +1,4 @@ -import { Groth16Proof } from "snarkjs" +import { Groth16Proof } from "@zk-kit/groth16" import { PackedProof } from "./types" /** diff --git a/packages/poseidon-proof/src/unpackProof.ts b/packages/poseidon-proof/src/unpackProof.ts index 0086dc8b4..d1fb5bef1 100644 --- a/packages/poseidon-proof/src/unpackProof.ts +++ b/packages/poseidon-proof/src/unpackProof.ts @@ -1,4 +1,4 @@ -import { Groth16Proof } from "snarkjs" +import { Groth16Proof } from "@zk-kit/groth16" import { PackedProof } from "./types" /** From d200e1062b00cf97951f78491d99b03230198d30 Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 17:59:45 +0000 Subject: [PATCH 21/27] style(poseidon-proof): format code with prettier --- packages/poseidon-proof/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index ba819941e..be5504efa 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -42,12 +42,12 @@ | This zero-knowledge library facilitates the demonstration of having a Poseidon hash pre-image while keeping the pre-image value confidential. Additionally, it offers a mechanism to prevent the same proof from being reused. The circuit that forms the foundation of this library is accessible via this [link](https://github.com/privacy-scaling-explorations/zk-kit/blob/main/packages/circuits/templates/poseidon-proof.circom). | -| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | Originally developed for integration with [Semaphore V4](https://github.com/semaphore-protocol/semaphore), this library also functions effectively as a standalone tool. Notable use cases in connection with Semaphore can be: -* allowing a Semaphore user to prove that they possess the secret value associated with the identity commitment of their Semaphore identity, -* unmasking the identity of zero-knowledge proofs earlier created using Semaphore. +- allowing a Semaphore user to prove that they possess the secret value associated with the identity commitment of their Semaphore identity, +- unmasking the identity of zero-knowledge proofs earlier created using Semaphore. The Snark artifacts (`.wasm` and `.zkey` files) can be specified or not in the `generate` function parameters and can possibly be downloaded using the following URLs: From 6a92270817dd7b8dd795a6eacf06bdbc5604270e Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 18:01:53 +0000 Subject: [PATCH 22/27] chore(poseidon-proof): v0.3.0 --- packages/poseidon-proof/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 9e3f9eed8..5557cd5a1 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.2.3", + "version": "0.3.0", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", From 9e2c4eb9fda8fd523973682a9983fa22c999df20 Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 18:42:04 +0000 Subject: [PATCH 23/27] chore(poseidon-proof): move tests outside source folder --- packages/poseidon-proof/build.tsconfig.json | 3 ++- packages/poseidon-proof/package.json | 4 ++-- packages/poseidon-proof/src/config.ts | 5 +---- packages/poseidon-proof/src/generate.ts | 4 ++-- .../poseidon-proof/{src => tests}/index.test.ts | 12 ++++++------ packages/poseidon-proof/tsconfig.json | 5 ++++- tsconfig.json | 1 - yarn.lock | 14 ++------------ 8 files changed, 19 insertions(+), 29 deletions(-) rename packages/poseidon-proof/{src => tests}/index.test.ts (87%) diff --git a/packages/poseidon-proof/build.tsconfig.json b/packages/poseidon-proof/build.tsconfig.json index 2d4a1d6da..09b37d986 100644 --- a/packages/poseidon-proof/build.tsconfig.json +++ b/packages/poseidon-proof/build.tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "baseUrl": ".", - "declarationDir": "dist/types" + "declarationDir": "dist/types", + "resolveJsonModule": true }, "include": ["src"] } diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 5557cd5a1..6da05508f 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.3.0", + "version": "0.4.0", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", @@ -45,7 +45,7 @@ "@ethersproject/bignumber": "^5.7.0", "@ethersproject/bytes": "^5.7.0", "@ethersproject/keccak256": "^5.7.0", - "@zk-kit/groth16": "0.3.0", + "@zk-kit/groth16": "0.4.0", "download": "^8.0.0", "tmp": "^0.2.1" } diff --git a/packages/poseidon-proof/src/config.ts b/packages/poseidon-proof/src/config.ts index 65d282708..402020e70 100644 --- a/packages/poseidon-proof/src/config.ts +++ b/packages/poseidon-proof/src/config.ts @@ -1,7 +1,4 @@ -import pkg from "../package.json" - -export const libraryName = pkg.name.split("/")[1] - +// eslint-disable-next-line import/prefer-default-export export const defaultSnarkArtifacts = { wasmFilePath: "https://zkkit.cedoor.dev/poseidon-proof.wasm", zkeyFilePath: "https://zkkit.cedoor.dev/poseidon-proof.zkey" diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index e5a0f6797..d52754ee6 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -4,7 +4,7 @@ import { NumericString, prove } from "@zk-kit/groth16" import download from "download" import fs from "fs" import tmp from "tmp" -import { defaultSnarkArtifacts, libraryName } from "./config" +import { defaultSnarkArtifacts } from "./config" import hash from "./hash" import packProof from "./packProof" import { PoseidonProof, SnarkArtifacts } from "./types" @@ -34,7 +34,7 @@ export default async function generate( /* istanbul ignore next */ if (!snarkArtifacts) { if (isNode()) { - const tmpDir = libraryName + const tmpDir = "poseidon-proof" const tmpPath = `${tmp.tmpdir}/${tmpDir}` if (!fs.existsSync(tmpPath)) { diff --git a/packages/poseidon-proof/src/index.test.ts b/packages/poseidon-proof/tests/index.test.ts similarity index 87% rename from packages/poseidon-proof/src/index.test.ts rename to packages/poseidon-proof/tests/index.test.ts index 76ada93d7..f3e6d6db1 100644 --- a/packages/poseidon-proof/src/index.test.ts +++ b/packages/poseidon-proof/tests/index.test.ts @@ -1,11 +1,11 @@ import { buildBn128 } from "@zk-kit/groth16" import { poseidon1, poseidon2 } from "poseidon-lite" -import generate from "./generate" -import packProof from "./packProof" -import { PoseidonProof } from "./types" -import unpackProof from "./unpackProof" -import verify from "./verify" -import hash from "./hash" +import generate from "../src/generate" +import packProof from "../src/packProof" +import { PoseidonProof } from "../src/types" +import unpackProof from "../src/unpackProof" +import verify from "../src/verify" +import hash from "../src/hash" describe("PoseidonProof", () => { const preimage = 2 diff --git a/packages/poseidon-proof/tsconfig.json b/packages/poseidon-proof/tsconfig.json index dfaf0c1ad..98496a5a1 100644 --- a/packages/poseidon-proof/tsconfig.json +++ b/packages/poseidon-proof/tsconfig.json @@ -1,4 +1,7 @@ { "extends": "../../tsconfig.json", - "include": ["src", "rollup.config.ts"] + "compilerOptions": { + "resolveJsonModule": true + }, + "include": ["src", "tests", "rollup.config.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 9de0656b9..b27f99d7f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,6 @@ "target": "ES5", "module": "ES2020", "moduleResolution": "node", - "resolveJsonModule": true, "esModuleInterop": true, "preserveConstEnums": true, "skipLibCheck": true, diff --git a/yarn.lock b/yarn.lock index 8dc47852e..60212fe35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4385,17 +4385,7 @@ __metadata: languageName: node linkType: hard -"@zk-kit/groth16@npm:0.3.0": - version: 0.3.0 - resolution: "@zk-kit/groth16@npm:0.3.0" - dependencies: - circom_runtime: 0.1.24 - ffjavascript: 0.2.60 - checksum: f177fffd7e28c1f6617a67758c017bb962bde8829a6b90bea8053c0c164386b73b58cfe26c2481435bbc0de0c14d8301c23818e4a0450979bceb525f64e9db51 - languageName: node - linkType: hard - -"@zk-kit/groth16@workspace:packages/groth16": +"@zk-kit/groth16@0.4.0, @zk-kit/groth16@workspace:packages/groth16": version: 0.0.0-use.local resolution: "@zk-kit/groth16@workspace:packages/groth16" dependencies: @@ -4457,7 +4447,7 @@ __metadata: "@rollup/plugin-json": ^5.0.1 "@types/download": ^8.0.5 "@types/tmp": ^0.2.6 - "@zk-kit/groth16": 0.3.0 + "@zk-kit/groth16": 0.4.0 download: ^8.0.0 poseidon-lite: ^0.2.0 rollup-plugin-cleanup: ^3.2.1 From 0ed3aa62916e08358fe8c4f14057ffd5df04b398 Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 18:45:17 +0000 Subject: [PATCH 24/27] refactor(poseidon-proof): make node imports dynamic --- packages/poseidon-proof/package.json | 2 +- packages/poseidon-proof/src/generate.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 6da05508f..387489572 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,6 +1,6 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.4.0", + "version": "0.4.1", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", "main": "dist/index.js", diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index d52754ee6..e26c6b225 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -1,9 +1,7 @@ import { BigNumber } from "@ethersproject/bignumber" import { BytesLike, Hexable } from "@ethersproject/bytes" import { NumericString, prove } from "@zk-kit/groth16" -import download from "download" -import fs from "fs" -import tmp from "tmp" + import { defaultSnarkArtifacts } from "./config" import hash from "./hash" import packProof from "./packProof" @@ -34,6 +32,10 @@ export default async function generate( /* istanbul ignore next */ if (!snarkArtifacts) { if (isNode()) { + const { default: download } = await import("download") + const { default: fs } = await import("fs") + const { default: tmp } = await import("tmp") + const tmpDir = "poseidon-proof" const tmpPath = `${tmp.tmpdir}/${tmpDir}` From 0ec7106f582656b0121bb6d6c86c73db43ca76b8 Mon Sep 17 00:00:00 2001 From: cedoor Date: Fri, 24 Nov 2023 19:46:39 +0000 Subject: [PATCH 25/27] chore(poseidon-proof): add conditional bundles --- packages/groth16/package.json | 1 - packages/poseidon-proof/package.json | 19 ++++++---- .../poseidon-proof/rollup.browser.config.ts | 38 +++++++++++++++++++ ...rollup.config.ts => rollup.node.config.ts} | 4 +- packages/poseidon-proof/src/generate.ts | 36 ++---------------- .../src/get-snark-artifacts.browser.ts | 6 +++ .../src/get-snark-artifacts.node.ts | 22 +++++++++++ .../src/{packProof.ts => pack-proof.ts} | 0 .../src/{unpackProof.ts => unpack-proof.ts} | 0 packages/poseidon-proof/src/utils.ts | 20 ---------- packages/poseidon-proof/src/verify.ts | 2 +- packages/poseidon-proof/tests/index.test.ts | 4 +- yarn.lock | 22 +++++++++++ 13 files changed, 108 insertions(+), 66 deletions(-) create mode 100644 packages/poseidon-proof/rollup.browser.config.ts rename packages/poseidon-proof/{rollup.config.ts => rollup.node.config.ts} (91%) create mode 100644 packages/poseidon-proof/src/get-snark-artifacts.browser.ts create mode 100644 packages/poseidon-proof/src/get-snark-artifacts.node.ts rename packages/poseidon-proof/src/{packProof.ts => pack-proof.ts} (100%) rename packages/poseidon-proof/src/{unpackProof.ts => unpack-proof.ts} (100%) delete mode 100644 packages/poseidon-proof/src/utils.ts diff --git a/packages/groth16/package.json b/packages/groth16/package.json index f4024d30c..d7b0cc814 100644 --- a/packages/groth16/package.json +++ b/packages/groth16/package.json @@ -25,7 +25,6 @@ "url": "https://github.com/privacy-scaling-explorations/zk-kit.git/issues" }, "scripts": { - "build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript", "build": "rimraf dist && yarn build:browser && yarn build:node", "build:browser": "rollup -c rollup.browser.config.ts --configPlugin typescript", "build:node": "rollup -c rollup.node.config.ts --configPlugin typescript", diff --git a/packages/poseidon-proof/package.json b/packages/poseidon-proof/package.json index 387489572..433e140e6 100644 --- a/packages/poseidon-proof/package.json +++ b/packages/poseidon-proof/package.json @@ -1,13 +1,16 @@ { "name": "@zk-kit/poseidon-proof", - "version": "0.4.1", + "version": "0.5.0", "description": "A library to generate and verify Poseidon proofs.", "license": "MIT", - "main": "dist/index.js", + "main": "dist/index.node.js", "exports": { - "import": "./dist/index.mjs", - "require": "./dist/index.js", - "types": "./dist/types/index.d.ts" + "node": { + "import": "./dist/index.node.mjs", + "require": "./dist/index.node.js" + }, + "browser": "./dist/index.browser.mjs", + "default": "./dist/index.browser.mjs" }, "types": "dist/types/index.d.ts", "files": [ @@ -25,14 +28,16 @@ "url": "https://github.com/privacy-scaling-explorations/zk-kit.git/issues" }, "scripts": { - "build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript", - "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript", + "build": "rimraf dist && yarn build:browser && yarn build:node", + "build:browser": "rollup -c rollup.browser.config.ts --configPlugin typescript", + "build:node": "rollup -c rollup.node.config.ts --configPlugin typescript", "prepublishOnly": "yarn build" }, "publishConfig": { "access": "public" }, "devDependencies": { + "@rollup/plugin-alias": "^5.0.1", "@rollup/plugin-json": "^5.0.1", "@types/download": "^8.0.5", "@types/tmp": "^0.2.6", diff --git a/packages/poseidon-proof/rollup.browser.config.ts b/packages/poseidon-proof/rollup.browser.config.ts new file mode 100644 index 000000000..5d3ab649e --- /dev/null +++ b/packages/poseidon-proof/rollup.browser.config.ts @@ -0,0 +1,38 @@ +import alias from "@rollup/plugin-alias" +import json from "@rollup/plugin-json" +import * as fs from "fs" +import cleanup from "rollup-plugin-cleanup" +import typescript from "rollup-plugin-typescript2" + +const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8")) +const banner = `/** + * @module ${pkg.name} + * @version ${pkg.version} + * @file ${pkg.description} + * @copyright Ethereum Foundation 2023 + * @license ${pkg.license} + * @see [Github]{@link ${pkg.homepage}} +*/` + +export default { + input: "src/index.ts", + output: [ + { + file: pkg.exports.browser, + format: "es", + banner + } + ], + external: Object.keys(pkg.dependencies), + plugins: [ + alias({ + entries: [{ find: "./get-snark-artifacts.node", replacement: "./get-snark-artifacts.browser" }] + }), + typescript({ + tsconfig: "./build.tsconfig.json", + useTsconfigDeclarationDir: true + }), + cleanup({ comments: "jsdoc" }), + json() + ] +} diff --git a/packages/poseidon-proof/rollup.config.ts b/packages/poseidon-proof/rollup.node.config.ts similarity index 91% rename from packages/poseidon-proof/rollup.config.ts rename to packages/poseidon-proof/rollup.node.config.ts index 7cc6448f1..ee88555d2 100644 --- a/packages/poseidon-proof/rollup.config.ts +++ b/packages/poseidon-proof/rollup.node.config.ts @@ -17,13 +17,13 @@ export default { input: "src/index.ts", output: [ { - file: pkg.exports.require, + file: pkg.exports.node.require, format: "cjs", banner, exports: "auto" }, { - file: pkg.exports.import, + file: pkg.exports.node.import, format: "es", banner } diff --git a/packages/poseidon-proof/src/generate.ts b/packages/poseidon-proof/src/generate.ts index e26c6b225..935227611 100644 --- a/packages/poseidon-proof/src/generate.ts +++ b/packages/poseidon-proof/src/generate.ts @@ -1,12 +1,10 @@ import { BigNumber } from "@ethersproject/bignumber" import { BytesLike, Hexable } from "@ethersproject/bytes" import { NumericString, prove } from "@zk-kit/groth16" - -import { defaultSnarkArtifacts } from "./config" +import getSnarkArtifacts from "./get-snark-artifacts.node" import hash from "./hash" -import packProof from "./packProof" +import packProof from "./pack-proof" import { PoseidonProof, SnarkArtifacts } from "./types" -import { isBrowser, isNode } from "./utils" /** * Creates a zero-knowledge proof to prove that you have the pre-image of a hash, @@ -31,35 +29,7 @@ export default async function generate( // If the Snark artifacts are not defined they will be automatically downloaded. /* istanbul ignore next */ if (!snarkArtifacts) { - if (isNode()) { - const { default: download } = await import("download") - const { default: fs } = await import("fs") - const { default: tmp } = await import("tmp") - - const tmpDir = "poseidon-proof" - const tmpPath = `${tmp.tmpdir}/${tmpDir}` - - if (!fs.existsSync(tmpPath)) { - tmp.dirSync({ name: tmpDir }) - - await download(defaultSnarkArtifacts.wasmFilePath, tmpPath) - await download(defaultSnarkArtifacts.zkeyFilePath, tmpPath) - } - - snarkArtifacts = { - wasmFilePath: `${tmpPath}/poseidon-proof.wasm`, - zkeyFilePath: `${tmpPath}/poseidon-proof.zkey` - } - } - - if (isBrowser()) { - snarkArtifacts = defaultSnarkArtifacts - } - } - - /* istanbul ignore next */ - if (!snarkArtifacts) { - throw new Error("Error: Missing Snark artifacts. Please ensure all necessary Snark artifacts are included.") + snarkArtifacts = await getSnarkArtifacts() } const { proof, publicSignals } = await prove( diff --git a/packages/poseidon-proof/src/get-snark-artifacts.browser.ts b/packages/poseidon-proof/src/get-snark-artifacts.browser.ts new file mode 100644 index 000000000..3ecd2679e --- /dev/null +++ b/packages/poseidon-proof/src/get-snark-artifacts.browser.ts @@ -0,0 +1,6 @@ +/* istanbul ignore file */ +import { defaultSnarkArtifacts } from "./config" + +export default async function getSnarkArtifacts() { + return defaultSnarkArtifacts +} diff --git a/packages/poseidon-proof/src/get-snark-artifacts.node.ts b/packages/poseidon-proof/src/get-snark-artifacts.node.ts new file mode 100644 index 000000000..ba8db05ca --- /dev/null +++ b/packages/poseidon-proof/src/get-snark-artifacts.node.ts @@ -0,0 +1,22 @@ +/* istanbul ignore file */ +import download from "download" +import tmp from "tmp" +import fs from "fs" +import { defaultSnarkArtifacts } from "./config" + +export default async function getSnarkArtifacts() { + const tmpDir = "poseidon-proof" + const tmpPath = `${tmp.tmpdir}/${tmpDir}` + + if (!fs.existsSync(tmpPath)) { + tmp.dirSync({ name: tmpDir }) + + await download(defaultSnarkArtifacts.wasmFilePath, tmpPath) + await download(defaultSnarkArtifacts.zkeyFilePath, tmpPath) + } + + return { + wasmFilePath: `${tmpPath}/poseidon-proof.wasm`, + zkeyFilePath: `${tmpPath}/poseidon-proof.zkey` + } +} diff --git a/packages/poseidon-proof/src/packProof.ts b/packages/poseidon-proof/src/pack-proof.ts similarity index 100% rename from packages/poseidon-proof/src/packProof.ts rename to packages/poseidon-proof/src/pack-proof.ts diff --git a/packages/poseidon-proof/src/unpackProof.ts b/packages/poseidon-proof/src/unpack-proof.ts similarity index 100% rename from packages/poseidon-proof/src/unpackProof.ts rename to packages/poseidon-proof/src/unpack-proof.ts diff --git a/packages/poseidon-proof/src/utils.ts b/packages/poseidon-proof/src/utils.ts deleted file mode 100644 index 6fcd51b58..000000000 --- a/packages/poseidon-proof/src/utils.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Secure method to check if the environment is Node.js. - * @returns true if the environment is Node.js, false otherwise. - */ -export function isNode(): boolean { - // Checking the existence of 'window' variable, or 'process' is not enough, - // as those variables can be redefined by inner scopes (by any module/library). - // In the 'new Function()' constructor, the execution scope of 'this' is bound - // to the global scope and it can be compared to the expected value (the objects - // will have the same id if the environment is the expected one). - return new Function("try {return this===global}catch(e){ return false}")() -} - -/** - * Secure method to check if the environment is a browser. - * @returns true if the environment is a browser, false otherwise. - */ -export function isBrowser(): boolean { - return new Function("try {return this===window}catch(e){ return false}")() -} diff --git a/packages/poseidon-proof/src/verify.ts b/packages/poseidon-proof/src/verify.ts index 9ee0eb00e..5a6090e25 100644 --- a/packages/poseidon-proof/src/verify.ts +++ b/packages/poseidon-proof/src/verify.ts @@ -1,7 +1,7 @@ import { verify as _verify } from "@zk-kit/groth16" import hash from "./hash" import { PoseidonProof } from "./types" -import unpackProof from "./unpackProof" +import unpackProof from "./unpack-proof" import verificationKey from "./verification-key.json" /** diff --git a/packages/poseidon-proof/tests/index.test.ts b/packages/poseidon-proof/tests/index.test.ts index f3e6d6db1..949583cfc 100644 --- a/packages/poseidon-proof/tests/index.test.ts +++ b/packages/poseidon-proof/tests/index.test.ts @@ -1,9 +1,9 @@ import { buildBn128 } from "@zk-kit/groth16" import { poseidon1, poseidon2 } from "poseidon-lite" import generate from "../src/generate" -import packProof from "../src/packProof" +import packProof from "../src/pack-proof" import { PoseidonProof } from "../src/types" -import unpackProof from "../src/unpackProof" +import unpackProof from "../src/unpack-proof" import verify from "../src/verify" import hash from "../src/hash" diff --git a/yarn.lock b/yarn.lock index 60212fe35..5888ea146 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3272,6 +3272,20 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-alias@npm:^5.0.1": + version: 5.0.1 + resolution: "@rollup/plugin-alias@npm:5.0.1" + dependencies: + slash: ^4.0.0 + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: dab5bba16a0425c8412ece858df677c9f792bb0c5a7789c1677ee34b03533c1cda407191fcc40f3e93eb5f992cd8ed0e980e49dad3e38346547a2723b0f56fa1 + languageName: node + linkType: hard + "@rollup/plugin-commonjs@npm:^24.1.0": version: 24.1.0 resolution: "@rollup/plugin-commonjs@npm:24.1.0" @@ -4444,6 +4458,7 @@ __metadata: "@ethersproject/bignumber": ^5.7.0 "@ethersproject/bytes": ^5.7.0 "@ethersproject/keccak256": ^5.7.0 + "@rollup/plugin-alias": ^5.0.1 "@rollup/plugin-json": ^5.0.1 "@types/download": ^8.0.5 "@types/tmp": ^0.2.6 @@ -16690,6 +16705,13 @@ __metadata: languageName: node linkType: hard +"slash@npm:^4.0.0": + version: 4.0.0 + resolution: "slash@npm:4.0.0" + checksum: da8e4af73712253acd21b7853b7e0dbba776b786e82b010a5bfc8b5051a1db38ed8aba8e1e8f400dd2c9f373be91eb1c42b66e91abb407ff42b10feece5e1d2d + languageName: node + linkType: hard + "slice-ansi@npm:^3.0.0": version: 3.0.0 resolution: "slice-ansi@npm:3.0.0" From 42a70238a5d23c65192c1d5dc51d058dde7b29d5 Mon Sep 17 00:00:00 2001 From: cedoor Date: Mon, 27 Nov 2023 13:02:54 +0000 Subject: [PATCH 26/27] docs(poseidon-proof): fix typos --- .eslintrc.json | 1 - packages/poseidon-proof/README.md | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 5ed9f5a9e..21e030869 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,7 +23,6 @@ "class-methods-use-this": "warn", "import/no-extraneous-dependencies": "off", "import/no-relative-packages": "off", - "@typescript-eslint/no-implied-eval": "off", "@typescript-eslint/no-loop-func": "off", "@typescript-eslint/no-shadow": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/poseidon-proof/README.md b/packages/poseidon-proof/README.md index be5504efa..86cfda720 100644 --- a/packages/poseidon-proof/README.md +++ b/packages/poseidon-proof/README.md @@ -90,7 +90,7 @@ const fullProof = await generate(message, scope) // If not specified, the Snark artifacts are downloaded automatically. // You can also specify them. -const fullProof = await generate(message, scope, { +const fullProof2 = await generate(message, scope, { zkeyFilePath: "./poseidon-proof.zkey", wasmFilePath: "./poseidon-proof.wasm" }) @@ -118,9 +118,9 @@ console.log(fullProof) \# **verify**(poseidonProof: _PoseidonProof_): Promise\<_boolean_> ```typescript -import { verify } from "@zk-key/poseidon-proof" +import { verify } from "@zk-kit/poseidon-proof" -const response = await verifyProof(fullProof) +const response = await verify(fullProof) console.log(response) // true or false From 3ce32cfe37bbfbdaee0be5e54803eae59d59bc62 Mon Sep 17 00:00:00 2001 From: cedoor Date: Mon, 27 Nov 2023 13:09:22 +0000 Subject: [PATCH 27/27] docs: add poseidon-proof package to readme --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 153232c10..9eaedde15 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,34 @@ + + + + @zk-kit/poseidon-proof + + + (docs) + + + + + + NPM version + + + + + + Downloads + + + + + + npm bundle size (scoped) + + +