mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-11 07:38:14 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
281f00ebd5 | ||
|
|
f2575f2bec | ||
|
|
3bfc7ce2bc | ||
|
|
ef88c9c84c | ||
|
|
6580b6620f | ||
|
|
42d33e2af7 | ||
|
|
594c612318 | ||
|
|
fbfa92023d | ||
|
|
caed0aecc1 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-contracts-hardhat",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "Semaphore Hardhat template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
@@ -36,10 +36,10 @@
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.0",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.0.0",
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/hardhat": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/proof": "3.9.0",
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/hardhat": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@semaphore-protocol/proof": "3.10.0",
|
||||
"@typechain/ethers-v5": "^10.1.0",
|
||||
"@typechain/hardhat": "^6.1.2",
|
||||
"@types/chai": "^4.2.0",
|
||||
@@ -58,7 +58,7 @@
|
||||
"typescript": ">=4.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "3.9.0"
|
||||
"@semaphore-protocol/contracts": "3.10.0"
|
||||
},
|
||||
"config": {
|
||||
"solidity": {
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.0",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.1.7",
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/hardhat": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/proof": "3.9.0",
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/hardhat": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@semaphore-protocol/proof": "3.10.0",
|
||||
"@typechain/ethers-v5": "^10.0.0",
|
||||
"@typechain/hardhat": "^6.0.0",
|
||||
"@types/chai": "^4.3.1",
|
||||
@@ -40,7 +40,7 @@
|
||||
"typechain": "^8.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "3.9.0"
|
||||
"@semaphore-protocol/contracts": "3.10.0"
|
||||
},
|
||||
"config": {
|
||||
"solidity": {
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@next/font": "13.0.3",
|
||||
"@semaphore-protocol/data": "3.9.0",
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/proof": "3.9.0",
|
||||
"@semaphore-protocol/data": "3.10.0",
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@semaphore-protocol/proof": "3.10.0",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"dotenv": "^16.0.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-monorepo-ethers",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "Semaphore Hardhat + Next.js + SemaphoreEthers template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.0",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.1.7",
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/hardhat": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/proof": "3.9.0",
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/hardhat": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@semaphore-protocol/proof": "3.10.0",
|
||||
"@typechain/ethers-v5": "^10.0.0",
|
||||
"@typechain/hardhat": "^6.0.0",
|
||||
"@types/chai": "^4.3.1",
|
||||
@@ -40,7 +40,7 @@
|
||||
"typechain": "^8.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "3.9.0"
|
||||
"@semaphore-protocol/contracts": "3.10.0"
|
||||
},
|
||||
"config": {
|
||||
"solidity": {
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@next/font": "13.0.3",
|
||||
"@semaphore-protocol/data": "3.9.0",
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/proof": "3.9.0",
|
||||
"@semaphore-protocol/data": "3.10.0",
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@semaphore-protocol/proof": "3.10.0",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"dotenv": "^16.0.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-monorepo-subgraph",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "Semaphore Hardhat + Next.js + SemaphoreSubgraph template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli",
|
||||
"type": "module",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A command line tool to set up your Semaphore project and get group data.",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
@@ -43,7 +43,7 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/data": "3.9.0",
|
||||
"@semaphore-protocol/data": "3.10.0",
|
||||
"axios": "^1.3.2",
|
||||
"boxen": "^7.0.1",
|
||||
"chalk": "^5.1.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/contracts",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
| This library allows you to query the [`Semaphore.sol`](https://github.com/semaphore-protocol/semaphore/blob/main/contracts/Semaphore.sol) contract data (i.e. groups) using the [Semaphore subgraph](https://github.com/semaphore-protocol/subgraph) or Ethers. It can be used on Node.js and browsers. |
|
||||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| This library allows you to query the [`Semaphore.sol`](https://github.com/semaphore-protocol/semaphore/blob/main/packages/contracts/contracts/Semaphore.sol) contract data (i.e. groups) using the [Semaphore subgraph](https://github.com/semaphore-protocol/subgraph) or Ethers. It can be used on Node.js and browsers. |
|
||||
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
|
||||
## 🛠 Install
|
||||
|
||||
@@ -118,6 +118,15 @@ const group = await semaphoreSubgraph.getGroup("42")
|
||||
const { members, verifiedProofs } = semaphoreSubgraph.getGroup("42", { members: true, verifiedProofs: true })
|
||||
```
|
||||
|
||||
\# **isGroupMember**(groupId: _string_, member: _string_): _Promise\<boolean>_
|
||||
|
||||
```typescript
|
||||
await semaphoreSubgraph.isGroupMember(
|
||||
"42",
|
||||
"16948514235341957898454876473214737047419402240398321289450170535251226167324"
|
||||
)
|
||||
```
|
||||
|
||||
\# **new Ethers**(networkOrEthereumURL: Network | string = "goerli", options: EthersOptions = {}): _SemaphoreEthers_
|
||||
|
||||
```typescript
|
||||
@@ -164,5 +173,5 @@ const members = await semaphoreEthers.getGroupMembers("42")
|
||||
\# **getGroupVerifiedProofs**(groupId: _string_): _Promise\<any[]>_
|
||||
|
||||
```typescript
|
||||
const verifiedProofs = await semaphoreEthers.getGroupVerifiedProofs()
|
||||
const verifiedProofs = await semaphoreEthers.getGroupVerifiedProofs("42")
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/data",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A library to query Semaphore contracts.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
|
||||
12
packages/data/src/index.test.ts
Normal file
12
packages/data/src/index.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import getSupportedNetworks from "./getSupportedNetworks"
|
||||
|
||||
describe("Data", () => {
|
||||
describe("# getSupportedNetworks", () => {
|
||||
it("Should return a list of supported networks", () => {
|
||||
const supportedNetworks = getSupportedNetworks()
|
||||
|
||||
expect(supportedNetworks).toHaveLength(6)
|
||||
expect(supportedNetworks).toContain("sepolia")
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -338,4 +338,31 @@ describe("SemaphoreSubgraph", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("# isGroupMember", () => {
|
||||
it("Should throw an error if the member parameter type is wrong", async () => {
|
||||
const fun = () => semaphore.isGroupMember("1", 1 as any)
|
||||
|
||||
await expect(fun).rejects.toThrow("Parameter 'member' is not a string")
|
||||
})
|
||||
|
||||
it("Should return true if a group member exist", async () => {
|
||||
requestMocked.mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
groups: [
|
||||
{
|
||||
id: "1"
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
const expectedValue = await semaphore.isGroupMember(
|
||||
"1",
|
||||
"19759682999141591121829027463339362582441675980174830329241909768001406603165"
|
||||
)
|
||||
|
||||
expect(expectedValue).toBeTruthy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -195,4 +195,30 @@ export default class SemaphoreSubgraph {
|
||||
|
||||
return groups[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a member is part of group, and false otherwise.
|
||||
* @param groupId Group id
|
||||
* @param member Group member.
|
||||
* @returns True if the member is part of the group, false otherwise.
|
||||
*/
|
||||
async isGroupMember(groupId: string, member: string): Promise<boolean> {
|
||||
checkParameter(groupId, "groupId", "string")
|
||||
checkParameter(member, "member", "string")
|
||||
|
||||
const config: AxiosRequestConfig = {
|
||||
method: "post",
|
||||
data: JSON.stringify({
|
||||
query: `{
|
||||
groups(where: { id: "${groupId}", members_: { identityCommitment: "${member}" } }) {
|
||||
id
|
||||
}
|
||||
}`
|
||||
})
|
||||
}
|
||||
|
||||
const { groups } = await request(this._url, config)
|
||||
|
||||
return groups.length !== 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ yarn add @semaphore-protocol/group
|
||||
|
||||
```typescript
|
||||
import { Group } from "@semaphore-protocol/group"
|
||||
import { Identity } from "@semaphore-protocol/identity"
|
||||
|
||||
// Group with max 1048576 members (20^²).
|
||||
const group1 = new Group(1)
|
||||
@@ -83,6 +84,13 @@ const group2 = new Group(1, 16)
|
||||
|
||||
// Group with max 16777216 members (24^²).
|
||||
const group3 = new Group(1, 24)
|
||||
|
||||
// Group with a list of predefined members.
|
||||
const identity1 = new Identity()
|
||||
const identity2 = new Identity()
|
||||
const identity3 = new Identity()
|
||||
|
||||
const group3 = new Group(1, 16, [identity1.commitment, identity2.commitment, identity3.commitment])
|
||||
```
|
||||
|
||||
\# **addMember**(identityCommitment: _Member_)
|
||||
@@ -96,21 +104,6 @@ const commitment = identity.generateCommitment()
|
||||
group.addMember(commitment)
|
||||
```
|
||||
|
||||
\# **addMembers**(identityCommitments: _Member\[]_)
|
||||
|
||||
```typescript
|
||||
let identityCommitments: bigint[]
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const identity = new Identity()
|
||||
const commitment = identity.generateCommitment()
|
||||
|
||||
identityCommitments.push(commitment)
|
||||
}
|
||||
|
||||
group.addMember(identityCommitments)
|
||||
```
|
||||
|
||||
\# **removeMember**(index: _number_)
|
||||
|
||||
```typescript
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/group",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A library to create and manage Semaphore groups.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -41,6 +41,6 @@
|
||||
"@ethersproject/bignumber": "^5.7.0",
|
||||
"@ethersproject/bytes": "^5.7.0",
|
||||
"@ethersproject/keccak256": "^5.7.0",
|
||||
"@zk-kit/incremental-merkle-tree": "1.0.0"
|
||||
"@zk-kit/incremental-merkle-tree": "1.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("Group", () => {
|
||||
expect(fun).toThrow("The tree depth must be between 16 and 32")
|
||||
})
|
||||
|
||||
it("Should create a group with different parameters", () => {
|
||||
it("Should create a group with a different tree depth", () => {
|
||||
const group = new Group(1, 32)
|
||||
|
||||
expect(group.root.toString()).toContain("460373")
|
||||
@@ -27,6 +27,21 @@ describe("Group", () => {
|
||||
expect(group.zeroValue).toBe(hash(1))
|
||||
expect(group.members).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("Should create a group with a list of members", () => {
|
||||
const group = new Group(2, 20, [1, 2, 3])
|
||||
|
||||
const group2 = new Group(2, 20)
|
||||
|
||||
group2.addMember(1)
|
||||
group2.addMember(2)
|
||||
group2.addMember(3)
|
||||
|
||||
expect(group.root.toString()).toContain(group2.root.toString())
|
||||
expect(group.depth).toBe(20)
|
||||
expect(group.zeroValue).toBe(hash(2))
|
||||
expect(group.members).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe("# addMember", () => {
|
||||
|
||||
@@ -12,14 +12,15 @@ export default class Group {
|
||||
* Initializes the group with the group id and the tree depth.
|
||||
* @param id Group identifier.
|
||||
* @param treeDepth Tree depth.
|
||||
* @param members List of group members.
|
||||
*/
|
||||
constructor(id: BigNumberish, treeDepth = 20) {
|
||||
constructor(id: BigNumberish, treeDepth = 20, members: BigNumberish[] = []) {
|
||||
if (treeDepth < 16 || treeDepth > 32) {
|
||||
throw new Error("The tree depth must be between 16 and 32")
|
||||
}
|
||||
|
||||
this._id = id
|
||||
this.merkleTree = new IncrementalMerkleTree(poseidon2, treeDepth, hash(id), 2)
|
||||
this.merkleTree = new IncrementalMerkleTree(poseidon2, treeDepth, hash(id), 2, members)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,6 +83,7 @@ export default class Group {
|
||||
/**
|
||||
* Adds new members to the group.
|
||||
* @param members New members.
|
||||
* @deprecated Use the new class parameter to add a list of members.
|
||||
*/
|
||||
addMembers(members: BigNumberish[]) {
|
||||
for (const member of members) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/hardhat",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.1.1",
|
||||
"@semaphore-protocol/contracts": "3.9.0",
|
||||
"@semaphore-protocol/contracts": "3.10.0",
|
||||
"circomlibjs": "^0.0.8",
|
||||
"ethers": "^5.7.1",
|
||||
"hardhat-dependency-compiler": "^1.1.3"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/heyauthn",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A library to allow developers to create and manage Semaphore identities using WebAuthn",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -35,7 +35,7 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/identity": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.10.0",
|
||||
"@simplewebauthn/browser": "7.2.0",
|
||||
"@simplewebauthn/server": "7.2.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/identity",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A library to create Semaphore identities.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/proof",
|
||||
"version": "3.9.0",
|
||||
"version": "3.10.0",
|
||||
"description": "A library to generate and verify Semaphore proofs.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -40,8 +40,8 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@semaphore-protocol/group": "3.9.0",
|
||||
"@semaphore-protocol/identity": "3.9.0"
|
||||
"@semaphore-protocol/group": "3.10.0",
|
||||
"@semaphore-protocol/identity": "3.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/bignumber": "^5.5.0",
|
||||
|
||||
@@ -1 +1 @@
|
||||
41a594b655244878cf24a7d982a9f8c3bc0988c2
|
||||
456429e12fe3405758ed27df01c0a93393ac3e89
|
||||
Reference in New Issue
Block a user