mirror of
https://github.com/CryptKeeperZK/semaphore.git
synced 2026-01-08 23:17:58 -05:00
chore: move env variables to the root folder
This commit is contained in:
16
README.md
16
README.md
@@ -200,6 +200,14 @@ cd semaphore && yarn
|
||||
|
||||
## 📜 Usage
|
||||
|
||||
Copy the `.env.example` file as `.env`:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
And add your environment variables.
|
||||
|
||||
### Code quality and formatting
|
||||
|
||||
Run [ESLint](https://eslint.org/) to analyze the code and catch bugs:
|
||||
@@ -230,6 +238,14 @@ yarn commit
|
||||
|
||||
It will also automatically check that the modified files comply with ESLint and Prettier rules.
|
||||
|
||||
### Snark artifacts
|
||||
|
||||
Download the Semaphore snark artifacts needed to generate and verify proofs:
|
||||
|
||||
```bash
|
||||
yarn download:snark-artifacts
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
Run [Jest](https://jestjs.io/) to test the JS libraries:
|
||||
|
||||
@@ -7,6 +7,7 @@ const projects: any = fs
|
||||
.map(({ name }) => ({
|
||||
rootDir: `packages/${name}`,
|
||||
displayName: name,
|
||||
setupFiles: ["dotenv/config"],
|
||||
moduleNameMapper: {
|
||||
"@semaphore-protocol/(.*)": "<rootDir>/../$1/src/index.ts" // Interdependency packages.
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"scripts": {
|
||||
"build:libraries": "yarn workspaces foreach run build",
|
||||
"compile:contracts": "yarn workspace contracts compile",
|
||||
"download:snark-artifacts": "ts-node scripts/download-snark-artifacts.ts",
|
||||
"test": "yarn test:libraries && yarn test:contracts",
|
||||
"test:libraries": "jest --coverage",
|
||||
"test:contracts": "yarn workspace contracts test:coverage",
|
||||
@@ -17,7 +18,8 @@
|
||||
"prettier:write": "prettier -w .",
|
||||
"docs": "yarn workspaces foreach run docs",
|
||||
"commit": "cz",
|
||||
"precommit": "lint-staged"
|
||||
"precommit": "lint-staged",
|
||||
"postinstall": "yarn download:snark-artifacts"
|
||||
},
|
||||
"keywords": [
|
||||
"ethereum",
|
||||
@@ -54,6 +56,7 @@
|
||||
"circomlibjs": "^0.0.8",
|
||||
"commitizen": "^4.2.4",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"dotenv": "^16.0.2",
|
||||
"eslint": "^8.2.0",
|
||||
"eslint-config-airbnb-base": "15.0.0",
|
||||
"eslint-config-airbnb-typescript": "^16.1.0",
|
||||
|
||||
@@ -62,22 +62,6 @@ yarn add @semaphore-protocol/contracts
|
||||
|
||||
## 📜 Usage
|
||||
|
||||
Copy the `.env.example` file as `.env`:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
And add your environment variables.
|
||||
|
||||
### Snark artifacts
|
||||
|
||||
Download the Semaphore snark artifacts needed to generate and verify proofs:
|
||||
|
||||
```bash
|
||||
yarn download:snark-artifacts
|
||||
```
|
||||
|
||||
### Compile contracts
|
||||
|
||||
Compile the smart contracts with [Hardhat](https://hardhat.org/):
|
||||
|
||||
@@ -15,7 +15,7 @@ import "./tasks/deploy-semaphore-voting"
|
||||
import "./tasks/deploy-semaphore-whistleblowing"
|
||||
import "./tasks/deploy-verifier"
|
||||
|
||||
dotenvConfig({ path: resolve(__dirname, "./.env") })
|
||||
dotenvConfig({ path: resolve(__dirname, "../../.env") })
|
||||
|
||||
function getNetworks(): NetworksUserConfig {
|
||||
if (!process.env.INFURA_API_KEY || !process.env.BACKEND_PRIVATE_KEY) {
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
"scripts": {
|
||||
"start": "hardhat node",
|
||||
"compile": "hardhat compile",
|
||||
"download:snark-artifacts": "hardhat run scripts/download-snark-artifacts.ts",
|
||||
"deploy:all": "hardhat run scripts/deploy-all.ts",
|
||||
"deploy:verifier": "hardhat deploy:verifier",
|
||||
"deploy:semaphore": "hardhat deploy:semaphore",
|
||||
"deploy:semaphore-voting": "hardhat deploy:semaphore-voting",
|
||||
"deploy:semaphore-whistleblowing": "hardhat deploy:semaphore-whistleblowing",
|
||||
"test": "yarn download:snark-artifacts && hardhat test",
|
||||
"test:report-gas": "yarn download:snark-artifacts && REPORT_GAS=true hardhat test",
|
||||
"test:coverage": "yarn download:snark-artifacts && hardhat coverage",
|
||||
"test": "hardhat test",
|
||||
"test:report-gas": "REPORT_GAS=true hardhat test",
|
||||
"test:coverage": "hardhat coverage",
|
||||
"typechain": "hardhat typechain",
|
||||
"lint": "solhint 'contracts/**/*.sol'"
|
||||
},
|
||||
@@ -33,7 +32,6 @@
|
||||
"chai": "^4.3.5",
|
||||
"circomlib": "^2.0.2",
|
||||
"circomlibjs": "^0.0.8",
|
||||
"dotenv": "^14.3.2",
|
||||
"download": "^8.0.0",
|
||||
"ethereum-waffle": "^3.4.4",
|
||||
"ethers": "^5.6.8",
|
||||
@@ -60,7 +58,6 @@
|
||||
"cache": "./cache",
|
||||
"snarkjs-templates": "./snarkjs-templates",
|
||||
"build": {
|
||||
"snark-artifacts": "./build/snark-artifacts",
|
||||
"contracts": "./build/contracts",
|
||||
"typechain": "./build/typechain"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import { expect } from "chai"
|
||||
import { constants, Signer, utils } from "ethers"
|
||||
import { run } from "hardhat"
|
||||
import { Semaphore } from "../build/typechain"
|
||||
import { config } from "../package.json"
|
||||
import { createIdentityCommitments } from "./utils"
|
||||
|
||||
describe("Semaphore", () => {
|
||||
@@ -19,8 +18,8 @@ describe("Semaphore", () => {
|
||||
const groupId = 1
|
||||
const members = createIdentityCommitments(3)
|
||||
|
||||
const wasmFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.wasm`
|
||||
const zkeyFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.zkey`
|
||||
const wasmFilePath = `../../snark-artifacts/semaphore.wasm`
|
||||
const zkeyFilePath = `../../snark-artifacts/semaphore.zkey`
|
||||
|
||||
before(async () => {
|
||||
const { address: verifierAddress } = await run("deploy:verifier", { logs: false, depth: treeDepth })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable jest/valid-expect */
|
||||
import { Identity } from "@semaphore-protocol/identity"
|
||||
import { Group } from "@semaphore-protocol/group"
|
||||
import { Identity } from "@semaphore-protocol/identity"
|
||||
import {
|
||||
generateNullifierHash,
|
||||
generateProof,
|
||||
@@ -12,7 +12,6 @@ import { expect } from "chai"
|
||||
import { Signer, utils } from "ethers"
|
||||
import { ethers, run } from "hardhat"
|
||||
import { SemaphoreVoting } from "../build/typechain"
|
||||
import { config } from "../package.json"
|
||||
|
||||
describe("SemaphoreVoting", () => {
|
||||
let contract: SemaphoreVoting
|
||||
@@ -24,8 +23,8 @@ describe("SemaphoreVoting", () => {
|
||||
const encryptionKey = BigInt(0)
|
||||
const decryptionKey = BigInt(0)
|
||||
|
||||
const wasmFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.wasm`
|
||||
const zkeyFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.zkey`
|
||||
const wasmFilePath = `../../snark-artifacts/semaphore.wasm`
|
||||
const zkeyFilePath = `../../snark-artifacts/semaphore.zkey`
|
||||
|
||||
before(async () => {
|
||||
const { address: verifierAddress } = await run("deploy:verifier", { logs: false, depth: treeDepth })
|
||||
|
||||
@@ -12,7 +12,6 @@ import { expect } from "chai"
|
||||
import { Signer, utils } from "ethers"
|
||||
import { ethers, run } from "hardhat"
|
||||
import { SemaphoreWhistleblowing } from "../build/typechain"
|
||||
import { config } from "../package.json"
|
||||
|
||||
describe("SemaphoreWhistleblowing", () => {
|
||||
let contract: SemaphoreWhistleblowing
|
||||
@@ -22,8 +21,8 @@ describe("SemaphoreWhistleblowing", () => {
|
||||
const treeDepth = Number(process.env.TREE_DEPTH) || 20
|
||||
const entityIds = [BigInt(1), BigInt(2)]
|
||||
|
||||
const wasmFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.wasm`
|
||||
const zkeyFilePath = `${config.paths.build["snark-artifacts"]}/semaphore.zkey`
|
||||
const wasmFilePath = `../../snark-artifacts/semaphore.wasm`
|
||||
const zkeyFilePath = `../../snark-artifacts/semaphore.zkey`
|
||||
|
||||
before(async () => {
|
||||
const { address: verifierAddress } = await run("deploy:verifier", { logs: false, depth: treeDepth })
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"download": "^8.0.0",
|
||||
"ffjavascript": "^0.2.54",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
"rollup-plugin-typescript2": "^0.31.2",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { formatBytes32String } from "@ethersproject/strings"
|
||||
import { Group } from "@semaphore-protocol/group"
|
||||
import { Identity } from "@semaphore-protocol/identity"
|
||||
import download from "download"
|
||||
import { getCurveFromName } from "ffjavascript"
|
||||
import fs from "fs"
|
||||
import generateNullifierHash from "./generateNullifierHash"
|
||||
@@ -12,13 +11,14 @@ import { FullProof } from "./types"
|
||||
import verifyProof from "./verifyProof"
|
||||
|
||||
describe("Proof", () => {
|
||||
const treeDepth = 20
|
||||
const treeDepth = Number(process.env.TREE_DEPTH) || 20
|
||||
|
||||
const externalNullifier = "1"
|
||||
const signal = "0x111"
|
||||
|
||||
const snarkArtifactsPath = "./packages/proof/snark-artifacts"
|
||||
const snarkArtifactsUrl = `http://www.trusted-setup-pse.org/semaphore/${treeDepth}`
|
||||
const wasmFilePath = `./snark-artifacts/semaphore.wasm`
|
||||
const zkeyFilePath = `./snark-artifacts/semaphore.zkey`
|
||||
const verificationKeyPath = `./snark-artifacts/semaphore.json`
|
||||
|
||||
const identity = new Identity()
|
||||
const identityCommitment = identity.generateCommitment()
|
||||
@@ -28,17 +28,7 @@ describe("Proof", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
curve = await getCurveFromName("bn128")
|
||||
|
||||
if (!fs.existsSync(snarkArtifactsPath)) {
|
||||
fs.mkdirSync(snarkArtifactsPath)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
|
||||
await download(`${snarkArtifactsUrl}/semaphore.wasm`, snarkArtifactsPath)
|
||||
await download(`${snarkArtifactsUrl}/semaphore.zkey`, snarkArtifactsPath)
|
||||
await download(`${snarkArtifactsUrl}/semaphore.json`, snarkArtifactsPath)
|
||||
}
|
||||
}, 10000)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await curve.terminate()
|
||||
@@ -52,8 +42,8 @@ describe("Proof", () => {
|
||||
|
||||
const fun = () =>
|
||||
generateProof(identity, group, externalNullifier, signal, {
|
||||
wasmFilePath: `${snarkArtifactsPath}/semaphore.wasm`,
|
||||
zkeyFilePath: `${snarkArtifactsPath}/semaphore.zkey`
|
||||
wasmFilePath,
|
||||
zkeyFilePath
|
||||
})
|
||||
|
||||
await expect(fun).rejects.toThrow("The identity is not part of the group")
|
||||
@@ -75,8 +65,8 @@ describe("Proof", () => {
|
||||
group.addMembers([BigInt(1), BigInt(2), identityCommitment])
|
||||
|
||||
fullProof = await generateProof(identity, group, externalNullifier, signal, {
|
||||
wasmFilePath: `${snarkArtifactsPath}/semaphore.wasm`,
|
||||
zkeyFilePath: `${snarkArtifactsPath}/semaphore.zkey`
|
||||
wasmFilePath,
|
||||
zkeyFilePath
|
||||
})
|
||||
|
||||
expect(typeof fullProof).toBe("object")
|
||||
@@ -90,8 +80,8 @@ describe("Proof", () => {
|
||||
group.addMembers([BigInt(1), BigInt(2), identityCommitment])
|
||||
|
||||
fullProof = await generateProof(identity, group.generateProofOfMembership(2), externalNullifier, signal, {
|
||||
wasmFilePath: `${snarkArtifactsPath}/semaphore.wasm`,
|
||||
zkeyFilePath: `${snarkArtifactsPath}/semaphore.zkey`
|
||||
wasmFilePath,
|
||||
zkeyFilePath
|
||||
})
|
||||
|
||||
expect(typeof fullProof).toBe("object")
|
||||
@@ -132,7 +122,7 @@ describe("Proof", () => {
|
||||
|
||||
describe("# verifyProof", () => {
|
||||
it("Should generate and verify a Semaphore proof", async () => {
|
||||
const verificationKey = JSON.parse(fs.readFileSync(`${snarkArtifactsPath}/semaphore.json`, "utf-8"))
|
||||
const verificationKey = JSON.parse(fs.readFileSync(verificationKeyPath, "utf-8"))
|
||||
|
||||
const response = await verifyProof(verificationKey, fullProof)
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import download from "download"
|
||||
import fs from "fs"
|
||||
import { config } from "../package.json"
|
||||
|
||||
async function main() {
|
||||
const snarkArtifactsPath = config.paths.build["snark-artifacts"]
|
||||
const snarkArtifactsPath = "./snark-artifacts"
|
||||
const url = `https://www.trusted-setup-pse.org/semaphore/${process.env.TREE_DEPTH || 20}`
|
||||
|
||||
if (!fs.existsSync(snarkArtifactsPath)) {
|
||||
@@ -13,6 +12,7 @@ async function main() {
|
||||
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
|
||||
await download(`${url}/semaphore.wasm`, snarkArtifactsPath)
|
||||
await download(`${url}/semaphore.zkey`, snarkArtifactsPath)
|
||||
await download(`${url}/semaphore.json`, snarkArtifactsPath)
|
||||
}
|
||||
}
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@@ -3007,7 +3007,6 @@ __metadata:
|
||||
"@semaphore-protocol/identity": 2.0.0
|
||||
"@zk-kit/incremental-merkle-tree": 0.4.3
|
||||
circomlibjs: 0.0.8
|
||||
download: ^8.0.0
|
||||
ffjavascript: ^0.2.54
|
||||
rollup-plugin-cleanup: ^3.2.1
|
||||
rollup-plugin-typescript2: ^0.31.2
|
||||
@@ -6924,7 +6923,6 @@ __metadata:
|
||||
chai: ^4.3.5
|
||||
circomlib: ^2.0.2
|
||||
circomlibjs: ^0.0.8
|
||||
dotenv: ^14.3.2
|
||||
download: ^8.0.0
|
||||
ethereum-waffle: ^3.4.4
|
||||
ethers: ^5.6.8
|
||||
@@ -7810,10 +7808,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"dotenv@npm:^14.3.2":
|
||||
version: 14.3.2
|
||||
resolution: "dotenv@npm:14.3.2"
|
||||
checksum: 86c06758915d6facc35275f4a7fafc16705b6f3b44befaa8abca91367991efc8ff8db5437d3cc14778231d19fb97610fe82d60f8a53ba723cdb69fe4171439aa
|
||||
"dotenv@npm:^16.0.2":
|
||||
version: 16.0.2
|
||||
resolution: "dotenv@npm:16.0.2"
|
||||
checksum: ca8f9ca2d67929c7771069f4c31b4e46b9932621009e658e5afd655dde2d69b77642bf36dbc9e72bc170523dfd908a9ee41c26f034c1fdc605ace3b1b4b10faf
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -16872,6 +16870,7 @@ __metadata:
|
||||
circomlibjs: ^0.0.8
|
||||
commitizen: ^4.2.4
|
||||
cz-conventional-changelog: ^3.3.0
|
||||
dotenv: ^16.0.2
|
||||
eslint: ^8.2.0
|
||||
eslint-config-airbnb-base: 15.0.0
|
||||
eslint-config-airbnb-typescript: ^16.1.0
|
||||
|
||||
Reference in New Issue
Block a user