@semaphore-protocol/cli-template-contracts-hardhat 4.0.0-alpha.8 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ #root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ end_of_line = lf
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ max_line_length = 120
10
+ indent_size = 4
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
package/.eslintignore ADDED
@@ -0,0 +1,23 @@
1
+ # dependencies
2
+ node_modules
3
+ package-lock.json
4
+ yarn.lock
5
+ .yarn
6
+
7
+ # testing
8
+ coverage
9
+ coverage.json
10
+
11
+ # hardhat
12
+ artifacts
13
+ cache
14
+ typechain-types
15
+
16
+ # misc
17
+ .DS_Store
18
+ *.pem
19
+
20
+ # debug
21
+ npm-debug.log*
22
+ yarn-debug.log*
23
+ yarn-error.log*
package/.eslintrc.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "root": true,
3
+ "env": {
4
+ "es6": true
5
+ },
6
+ "extends": ["airbnb-base", "airbnb-typescript/base", "prettier"],
7
+ "parser": "@typescript-eslint/parser",
8
+ "parserOptions": {
9
+ "ecmaVersion": 6,
10
+ "sourceType": "module",
11
+ "project": ["./tsconfig.json"]
12
+ },
13
+ "plugins": ["@typescript-eslint"],
14
+ "rules": {
15
+ "no-underscore-dangle": "off",
16
+ "import/no-extraneous-dependencies": "off",
17
+ "no-bitwise": "off",
18
+ "no-await-in-loop": "off",
19
+ "no-restricted-syntax": "off",
20
+ "no-console": ["warn", { "allow": ["info", "warn", "error", "log"] }],
21
+ "@typescript-eslint/lines-between-class-members": "off",
22
+ "no-param-reassign": "off"
23
+ }
24
+ }
@@ -0,0 +1,29 @@
1
+ # dependencies
2
+ node_modules
3
+ package-lock.json
4
+ yarn.lock
5
+ .yarn
6
+
7
+ # debug
8
+ npm-debug.log*
9
+ yarn-debug.log*
10
+ yarn-error.log*
11
+
12
+ # testing
13
+ coverage
14
+ coverage.json
15
+
16
+ # hardhat
17
+ artifacts
18
+ cache
19
+ typechain-types
20
+
21
+ # misc
22
+ .DS_Store
23
+ *.pem
24
+
25
+ # debug
26
+ npm-debug.log*
27
+ yarn-debug.log*
28
+ yarn-error.log*
29
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "semi": false,
3
+ "arrowParens": "always",
4
+ "trailingComma": "none"
5
+ }
package/README.md CHANGED
@@ -2,15 +2,23 @@
2
2
 
3
3
  This project demonstrates a basic Semaphore use case. It comes with a sample contract, a test for that contract and a sample task that deploys that contract.
4
4
 
5
+ ## Install
6
+
7
+ ### Install dependencies
8
+
9
+ ```bash
10
+ yarn
11
+ ```
12
+
5
13
  ## Usage
6
14
 
7
- ### Compile
15
+ ### Compile contracts
8
16
 
9
17
  ```bash
10
18
  yarn compile
11
19
  ```
12
20
 
13
- ### Testing
21
+ ### Test contracts
14
22
 
15
23
  ```bash
16
24
  yarn test
@@ -28,7 +36,7 @@ Or a test gas report:
28
36
  yarn test:report-gas
29
37
  ```
30
38
 
31
- ### Deploy
39
+ ### Deploy contracts
32
40
 
33
41
  1. Copy the `.env.example` file as `.env`.
34
42
 
@@ -52,3 +60,23 @@ yarn deploy --semaphore <semaphore-address> --group <group-id> --network sepolia
52
60
 
53
61
  > **Warning**
54
62
  > The group id is a number!
63
+
64
+ ### Code quality and formatting
65
+
66
+ Run [ESLint](https://eslint.org/) and [solhint](https://github.com/protofire/solhint) to analyze the code and catch bugs:
67
+
68
+ ```bash
69
+ yarn lint
70
+ ```
71
+
72
+ Run [Prettier](https://prettier.io/) to check formatting rules:
73
+
74
+ ```bash
75
+ yarn prettier
76
+ ```
77
+
78
+ Or to automatically format the code:
79
+
80
+ ```bash
81
+ yarn prettier:write
82
+ ```
@@ -8,8 +8,8 @@ contract Feedback {
8
8
 
9
9
  uint256 public groupId;
10
10
 
11
- constructor(ISemaphore _semaphore, uint256 _groupId) {
12
- semaphore = _semaphore;
11
+ constructor(address semaphoreAddress, uint256 _groupId) {
12
+ semaphore = ISemaphore(semaphoreAddress);
13
13
  groupId = _groupId;
14
14
 
15
15
  semaphore.createGroup(groupId, address(this));
package/files.tgz CHANGED
Binary file
package/hardhat.config.ts CHANGED
@@ -1,17 +1,10 @@
1
- import "@nomicfoundation/hardhat-chai-matchers"
2
- import "@nomicfoundation/hardhat-ethers"
3
- import "@nomicfoundation/hardhat-verify"
4
- import "@semaphore-protocol/hardhat"
5
- import "@typechain/hardhat"
6
- import { config as dotenvConfig } from "dotenv"
7
- import "hardhat-gas-reporter"
8
1
  import { HardhatUserConfig } from "hardhat/config"
9
2
  import { NetworksUserConfig } from "hardhat/types"
10
- import "solidity-coverage"
3
+ import "@nomicfoundation/hardhat-toolbox"
4
+ import "dotenv/config"
5
+ import "@semaphore-protocol/hardhat"
11
6
  import "./tasks/deploy"
12
7
 
13
- dotenvConfig()
14
-
15
8
  function getNetworks(): NetworksUserConfig {
16
9
  if (!process.env.INFURA_API_KEY || !process.env.ETHEREUM_PRIVATE_KEY) {
17
10
  return {}
@@ -49,7 +42,7 @@ function getNetworks(): NetworksUserConfig {
49
42
  }
50
43
  }
51
44
 
52
- const hardhatConfig: HardhatUserConfig = {
45
+ const config: HardhatUserConfig = {
53
46
  solidity: "0.8.23",
54
47
  networks: {
55
48
  hardhat: {
@@ -73,4 +66,4 @@ const hardhatConfig: HardhatUserConfig = {
73
66
  }
74
67
  }
75
68
 
76
- export default hardhatConfig
69
+ export default config
package/package.json CHANGED
@@ -1,65 +1,78 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/cli-template-contracts-hardhat",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Semaphore Hardhat template.",
5
5
  "license": "Unlicense",
6
6
  "files": [
7
7
  "files.tgz",
8
8
  "contracts/",
9
- "scripts/",
10
9
  "tasks/",
11
10
  "test/",
11
+ ".editorconfig",
12
12
  ".env.example",
13
+ ".eslintignore",
14
+ ".eslintrc.json",
15
+ ".prettierignore",
16
+ ".prettierrc.json",
13
17
  "hardhat.config.ts",
14
18
  "tsconfig.json",
15
- "README.md"
19
+ "README.md",
20
+ ".yarn/",
21
+ ".yarnrc.yml"
16
22
  ],
17
23
  "publishConfig": {
18
24
  "access": "public"
19
25
  },
20
26
  "scripts": {
21
- "dev": "hardhat node & yarn compile && yarn deploy --network localhost",
27
+ "dev": "hardhat node & yarn deploy --network localhost",
22
28
  "compile": "hardhat compile",
23
- "deploy": "yarn compile && hardhat deploy",
29
+ "deploy": "hardhat compile && hardhat deploy",
30
+ "verify": "hardhat verify",
24
31
  "test": "hardhat test",
25
32
  "test:report-gas": "REPORT_GAS=true hardhat test",
26
33
  "test:coverage": "hardhat coverage",
27
34
  "typechain": "hardhat typechain",
28
- "prepublish": "tar -czf files.tgz .gitignore"
35
+ "prepublish": "tar -czf files.tgz .gitignore",
36
+ "lint": "eslint . --ext .js,.ts && solhint 'contracts/**/*.sol'",
37
+ "prettier": "prettier -c --plugin=prettier-plugin-solidity .",
38
+ "prettier:write": "prettier -w --plugin=prettier-plugin-solidity ."
29
39
  },
30
40
  "devDependencies": {
31
- "@ethersproject/abi": "^5.4.7",
32
- "@ethersproject/providers": "^5.4.7",
33
- "@nomicfoundation/hardhat-chai-matchers": "^2.0.3",
41
+ "@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
34
42
  "@nomicfoundation/hardhat-ethers": "^3.0.0",
35
43
  "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
36
44
  "@nomicfoundation/hardhat-toolbox": "^4.0.0",
37
45
  "@nomicfoundation/hardhat-verify": "^2.0.0",
38
- "@semaphore-protocol/group": "4.0.0-alpha.8",
39
- "@semaphore-protocol/hardhat": "4.0.0-alpha.8",
40
- "@semaphore-protocol/identity": "4.0.0-alpha.8",
41
- "@semaphore-protocol/proof": "4.0.0-alpha.8",
46
+ "@semaphore-protocol/core": "4.0.0-beta.1",
47
+ "@semaphore-protocol/hardhat": "4.0.0-beta.1",
42
48
  "@typechain/ethers-v6": "^0.5.0",
43
49
  "@typechain/hardhat": "^9.0.0",
44
50
  "@types/chai": "^4.2.0",
45
- "@types/mocha": "^9.1.0",
46
- "@types/node": "^20",
51
+ "@types/eslint": "^8",
52
+ "@types/mocha": ">=9.1.0",
53
+ "@types/node": "^20.11.20",
54
+ "@typescript-eslint/eslint-plugin": "^7.0.2",
55
+ "@typescript-eslint/parser": "^7.0.2",
47
56
  "chai": "^4.2.0",
48
- "dotenv": "^16.0.3",
57
+ "dotenv": "^16.4.5",
58
+ "eslint": "^8.57.0",
59
+ "eslint-config-airbnb-base": "^15.0.0",
60
+ "eslint-config-airbnb-typescript": "^17.1.0",
61
+ "eslint-config-prettier": "^9.1.0",
62
+ "eslint-plugin-import": "^2.29.1",
49
63
  "ethers": "^6.4.0",
50
- "hardhat": "^2.19.4",
64
+ "hardhat": "^2.20.1",
51
65
  "hardhat-gas-reporter": "^1.0.8",
66
+ "prettier": "^3.2.5",
67
+ "prettier-plugin-solidity": "^1.3.1",
68
+ "solhint": "^4.1.1",
52
69
  "solidity-coverage": "^0.8.1",
53
70
  "ts-node": "^10.9.2",
54
71
  "typechain": "^8.3.0",
55
72
  "typescript": "^5.3.3"
56
73
  },
57
74
  "dependencies": {
58
- "@semaphore-protocol/contracts": "4.0.0-alpha.8"
75
+ "@semaphore-protocol/contracts": "4.0.0-beta.1"
59
76
  },
60
- "config": {
61
- "solidity": {
62
- "version": "0.8.4"
63
- }
64
- }
77
+ "packageManager": "yarn@4.1.0"
65
78
  }
package/test/Feedback.ts CHANGED
@@ -1,37 +1,41 @@
1
- import { Group } from "@semaphore-protocol/group"
2
- import { Identity } from "@semaphore-protocol/identity"
3
- import { generateProof } from "@semaphore-protocol/proof"
1
+ import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"
2
+ import { Group, Identity, generateProof } from "@semaphore-protocol/core"
4
3
  import { expect } from "chai"
5
4
  import { encodeBytes32String } from "ethers"
6
5
  import { run } from "hardhat"
7
6
  // @ts-ignore: typechain folder will be generated after contracts compilation
8
- import { Feedback } from "../typechain-types"
7
+ // eslint-disable-next-line
8
+ import { Feedback, ISemaphore } from "../typechain-types"
9
9
 
10
10
  describe("Feedback", () => {
11
- let feedbackContract: Feedback
12
- let semaphoreContract: string
11
+ async function deployFeedbackFixture() {
12
+ const groupId = "42"
13
13
 
14
- const groupId = "42"
15
- const group = new Group()
16
- const users: Identity[] = []
17
-
18
- before(async () => {
19
14
  const { semaphore } = await run("deploy:semaphore", {
20
15
  logs: false
21
16
  })
22
17
 
23
- feedbackContract = await run("deploy", { logs: false, group: groupId, semaphore: await semaphore.getAddress() })
24
- semaphoreContract = semaphore
18
+ const semaphoreContract: ISemaphore = semaphore
25
19
 
26
- users.push(new Identity())
27
- users.push(new Identity())
28
- })
20
+ const feedbackContract: Feedback = await run("deploy", {
21
+ logs: false,
22
+ group: groupId,
23
+ semaphore: await semaphoreContract.getAddress()
24
+ })
25
+
26
+ return { semaphoreContract, feedbackContract, groupId }
27
+ }
29
28
 
30
29
  describe("# joinGroup", () => {
31
30
  it("Should allow users to join the group", async () => {
32
- for await (const [i, user] of users.entries()) {
33
- const transaction = feedbackContract.joinGroup(user.commitment)
31
+ const { semaphoreContract, feedbackContract, groupId } = await loadFixture(deployFeedbackFixture)
32
+
33
+ const users = [new Identity(), new Identity()]
34
+
35
+ const group = new Group()
34
36
 
37
+ for (const [i, user] of users.entries()) {
38
+ const transaction = await feedbackContract.joinGroup(user.commitment)
35
39
  group.addMember(user.commitment)
36
40
 
37
41
  await expect(transaction)
@@ -43,6 +47,16 @@ describe("Feedback", () => {
43
47
 
44
48
  describe("# sendFeedback", () => {
45
49
  it("Should allow users to send feedback anonymously", async () => {
50
+ const { semaphoreContract, feedbackContract, groupId } = await loadFixture(deployFeedbackFixture)
51
+
52
+ const users = [new Identity(), new Identity()]
53
+ const group = new Group()
54
+
55
+ for (const user of users) {
56
+ await feedbackContract.joinGroup(user.commitment)
57
+ group.addMember(user.commitment)
58
+ }
59
+
46
60
  const feedback = encodeBytes32String("Hello World")
47
61
 
48
62
  const proof = await generateProof(users[1], group, feedback, groupId)
package/tsconfig.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "moduleResolution": "Node",
4
- "noImplicitAny": true,
5
- "resolveJsonModule": true,
6
- "target": "ES2018",
7
- "module": "CommonJS",
8
- "strict": true,
3
+ "target": "es2020",
4
+ "module": "commonjs",
9
5
  "esModuleInterop": true,
10
- "outDir": "dist",
11
- "typeRoots": ["node_modules/@types", "types"]
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "resolveJsonModule": true
12
10
  },
13
- "include": ["scripts/**/*", "tasks/**/*", "test/**/*", "build/typechain/**/*", "types/**/*"],
11
+ "include": ["scripts/**/*", "tasks/**/*", "test/**/*", "typechain-types/**/*"],
14
12
  "files": ["./hardhat.config.ts"]
15
13
  }