Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions packages/data/src/subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
26 changes: 26 additions & 0 deletions packages/data/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}