A library to query Semaphore contracts.
This library allows you to query the Semaphore.sol contract data (i.e. groups) using the Semaphore subgraph or Ethers. It can be used on Node.js and browsers. |
---|
Install the @semaphore-protocol/data
package with npm:
npm i @semaphore-protocol/data
or yarn:
yarn add @semaphore-protocol/data
# getSupportedNetworks(): string[]
const supportedNetworks = getSupportedNetworks()
# new SemaphoreSubgraph(networkOrSubgraphURL: SupportedNetwork | ValueOf<SupportedNetwork> | string = "sepolia"): SemaphoreSubgraph
import { SemaphoreSubgraph } from "@semaphore-protocol/data"
const semaphoreSubgraph = new SemaphoreSubgraph()
// or:
const semaphoreSubgraph = new SemaphoreSubgraph("arbitrum")
// or:
const semaphoreSubgraph = new SemaphoreSubgraph(
"https://api.studio.thegraph.com/query/14377/<your-subgraph>/<your-version>"
)
# getGroupIds(): Promise<string[]>
const groupIds = await semaphoreSubgraph.getGroupIds()
# getGroups(options?: GroupOptions): Promise<GroupResponse[]>
const groups = await semaphoreSubgraph.getGroups()
// or
const groups = await semaphoreSubgraph.getGroups({ members: true, verifiedProofs: true })
# getGroup(groupId: string, options?: GroupOptions): Promise<GroupResponse>
const group = await semaphoreSubgraph.getGroup("42")
// or
const { members, verifiedProofs } = semaphoreSubgraph.getGroup("42", { members: true, verifiedProofs: true })
# isGroupMember(groupId: string, member: string): Promise<boolean>
await semaphoreSubgraph.isGroupMember(
"42",
"16948514235341957898454876473214737047419402240398321289450170535251226167324"
)
# new Ethers(networkOrEthereumURL: Network | string = "goerli", options: EthersOptions = {}): SemaphoreEthers
import { SemaphoreEthers } from "@semaphore-protocol/data"
const semaphoreEthers = new SemaphoreEthers()
// or:
const semaphoreEthers = new SemaphoreEthers("homestead", {
address: "semaphore-address",
startBlock: 0
})
// or:
const semaphoreEthers = new SemaphoreEthers("http://localhost:8545", {
address: "semaphore-address"
})
# getGroupIds(): Promise<string[]>
const groupIds = await semaphoreEthers.getGroupIds()
# getGroup(groupId: string): Promise<GroupResponse>
const group = await semaphoreEthers.getGroup("42")
# getGroupAdmin(groupId: string): Promise<string>
const admin = await semaphoreEthers.getGroupAdmin("42")
# getGroupMembers(groupId: string): Promise<string[]>
const members = await semaphoreEthers.getGroupMembers("42")
# getGroupVerifiedProofs(groupId: string): Promise<any[]>
const verifiedProofs = await semaphoreEthers.getGroupVerifiedProofs("42")