Compare commits

...

9 Commits

Author SHA1 Message Date
cedoor
281f00ebd5 chore: v3.10.0
Former-commit-id: 63e7e7a7937b84be9122d060b7ec3bf73b182703
2023-05-15 16:13:43 +01:00
Cedoor
f2575f2bec Merge pull request #324 from semaphore-protocol/feat/is-member
New function to check if a member exists

Former-commit-id: e783465dc2
2023-05-15 15:50:18 +01:00
cedoor
3bfc7ce2bc style(data): format code with prettier
Former-commit-id: 2b430dace0
2023-05-15 15:43:50 +01:00
cedoor
ef88c9c84c feat(data): create function to check if a member exists
re #321


Former-commit-id: 9d7076acc7
2023-05-15 15:35:53 +01:00
Cedoor
6580b6620f Merge pull request #322 from semaphore-protocol/feat/init-members
New class parameter to add members

Former-commit-id: 5915ea082b
2023-05-15 12:59:46 +01:00
cedoor
42d33e2af7 feat(group): add new class parameter to add members
re #319


Former-commit-id: ed015ccc83
2023-05-15 12:46:44 +01:00
Cedoor
594c612318 Merge pull request #316 from semaphore-protocol/docs/update-readme-data-package
Update readme file in data package

Former-commit-id: 0ee1fa2b72
2023-05-02 09:46:50 +01:00
vplasencia
fbfa92023d docs(data): update readme file
Former-commit-id: 594daba6cc
2023-05-01 20:58:00 +02:00
cedoor
caed0aecc1 test(data): add test for new function
Former-commit-id: 0cb0ef3514
2023-04-28 12:32:30 +01:00
23 changed files with 146 additions and 62 deletions

View File

@@ -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": {

View File

@@ -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": {

View File

@@ -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",

View File

@@ -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": [

View File

@@ -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": {

View File

@@ -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",

View File

@@ -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": [

View File

@@ -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",

View File

@@ -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": [

View File

@@ -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")
```

View File

@@ -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",

View 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")
})
})
})

View File

@@ -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()
})
})
})

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -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"
}
}

View File

@@ -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", () => {

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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"
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -1 +1 @@
41a594b655244878cf24a7d982a9f8c3bc0988c2
456429e12fe3405758ed27df01c0a93393ac3e89