Skip to content

Latest commit

 

History

History
189 lines (142 loc) · 5.77 KB

README.md

File metadata and controls

189 lines (142 loc) · 5.77 KB

Semaphore data

A library for querying Semaphore smart contract.

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

This library provides tools for querying and interacting with the Semaphore.sol smart contract. It supports both the Semaphore subgraph and direct Ethereum network connections via Ethers. Designed for use in both Node.js and browser environments, it facilitates the management of group data and verification processes within the Semaphore protocol.

🛠 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 detailed information on the functions provided by @semaphore-protocol/data, please refer to the TypeDoc documentation.

Creating and Managing Subgraphs

Initialize a Semaphore Subgraph instance

import { SemaphoreSubgraph } from "@semaphore-protocol/data"

const semaphoreSubgraph = new SemaphoreSubgraph()

// or:
const semaphoreSubgraphOnArbitrum = new SemaphoreSubgraph("arbitrum")

// or:
const customSubgraph = new SemaphoreSubgraph(
    "https://api.studio.thegraph.com/query/14377/<your-subgraph>/<your-version>"
)

With your SemaphoreSubgraph, you can:

Query Group IDs

const groupIds = await semaphoreSubgraph.getGroupIds()

Query Group Details

const group = await semaphoreSubgraph.getGroup("42")
const { members, verifiedProofs } = await semaphoreSubgraph.getGroup("42", { members: true, verifiedProofs: true })

Query Group Members

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

Query Verified Proofs

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

Check Group Membership

const isMember = await semaphoreSubgraph.isGroupMember(
    "42",
    "16948514235341957898454876473214737047419402240398321289450170535251226167324"
)

Using Ethers for Direct Blockchain Interaction

Initialize a Semaphore Ethers instance

import { SemaphoreEthers } from "@semaphore-protocol/data"

const semaphoreEthers = new SemaphoreEthers()

// or:
const semaphoreEthersOnHomestead = new SemaphoreEthers("homestead", {
    address: "semaphore-address",
    startBlock: 0
})

// or:
const localEthersInstance = new SemaphoreEthers("http://localhost:8545", {
    address: "semaphore-address"
})

With your SemaphoreEthers instance, you can:

Fetch Group IDs

const groupIds = await semaphoreEthers.getGroupIds()

Fetch Group Details

const group = await semaphoreEthers.getGroup("42")

Fetch Group Admin

const admin = await semaphoreEthers.getGroupAdmin("42")

Fetch Group Members

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

Fetch Verified Proofs

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

Check Group Membership

const isMember = await semaphoreEthers.isGroupMember(
    "42",
    "16948514235341957898454876473214737047419402240398321289450170535251226167324"
)