Files
Vivian Plasencia 25847c4422 refactor(contracts): remove existence check for group id
since the group ids are created incrementally internally in the contracts, there's no need to check
whether the group id has already been taken.

re #708


Former-commit-id: e205bf6ad7
2024-03-14 23:40:41 +01:00
..
2024-03-13 16:40:56 +00:00
2024-02-10 15:26:06 +00:00

Semaphore data

A library to query Semaphore contracts.

NPM license NPM version Downloads Documentation typedoc Linter eslint Code style prettier

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

npm or yarn

Install the @semaphore-protocol/data package with npm:

npm i @semaphore-protocol/data

or yarn:

yarn add @semaphore-protocol/data

📜 Usage

For more information on the functions provided by @semaphore-protocol/data, please refer to the TypeDoc documentation.

# 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 })

# getGroupMembers(groupId: string): Promise<string[]>

const members = await semaphoreSubgraph.getGroupMembers("42")

# getGroupVerifiedProofs(groupId: string): Promise<any[]>

const verifiedProofs = await semaphoreSubgraph.getGroupVerifiedProofs("42")

# isGroupMember(groupId: string, member: string): Promise<boolean>

await semaphoreSubgraph.isGroupMember(
    "42",
    "16948514235341957898454876473214737047419402240398321289450170535251226167324"
)

# new Ethers(networkOrEthereumURL: Network | string = "sepolia", 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")

# isGroupMember(groupId: string, member: string): Promise<boolean>

await semaphoreEthers.isGroupMember(
    "42",
    "16948514235341957898454876473214737047419402240398321289450170535251226167324"
)