API reference · Browser and Node

# @toip-tools/anon-membership

93 public exports.

Module import:

```ts
import { type Acceptance, acceptMembership, type AcceptPolicy } from "@toip-tools/anon-membership";
```

## Functions

- [`acceptMembership`](https://toip.tools/toolkit/anon-membership/api/acceptMembership/)

  Decides whether a membership proof is acceptable: the circuit is pinned, the groups are the

- [`bundledCrs`](https://toip.tools/toolkit/anon-membership/api/bundledCrs/)

  The CRS bundled in artifacts/crs.json, enough points for every compiled circuit.

- [`checkRootLog`](https://toip.tools/toolkit/anon-membership/api/checkRootLog/)

  Checks a group's root log, oldest first: each document signed by \`expectedIssuer\`, one group,

- [`checkStatement`](https://toip.tools/toolkit/anon-membership/api/checkStatement/)

  Throws if the statement can't be a public input of the circuit.

- [`commitmentOf`](https://toip.tools/toolkit/anon-membership/api/commitmentOf/)

  H(1, secret, groupId).

- [`dayFromIso`](https://toip.tools/toolkit/anon-membership/api/dayFromIso/)

- [`dayOf`](https://toip.tools/toolkit/anon-membership/api/dayOf/)

  Days since 1970-01-01 UTC.

- [`decodeLeaf`](https://toip.tools/toolkit/anon-membership/api/decodeLeaf/)

- [`decodeMembershipCode`](https://toip.tools/toolkit/anon-membership/api/decodeMembershipCode/)

  The secret, or null for a typo or a code made for another group.

- [`decodeStatement`](https://toip.tools/toolkit/anon-membership/api/decodeStatement/)

- [`deriveSecret`](https://toip.tools/toolkit/anon-membership/api/deriveSecret/)

  toField(HMAC-SHA256(seed, utf8(info))).

- [`encodeLeaf`](https://toip.tools/toolkit/anon-membership/api/encodeLeaf/)

- [`encodeMembershipCode`](https://toip.tools/toolkit/anon-membership/api/encodeMembershipCode/)

  Crockford base32 of the 31-byte secret and a 2-byte checksum over (groupId, secret), in groups of 4.

- [`encodeStatement`](https://toip.tools/toolkit/anon-membership/api/encodeStatement/)

- [`enroll`](https://toip.tools/toolkit/anon-membership/api/enroll/)

  Member side: sends the commitment for \`groupId\` and checks the leaf the issuer recorded.

- [`epochIndex`](https://toip.tools/toolkit/anon-membership/api/epochIndex/)

  The epoch's index: periods since 1970.

- [`epochOf`](https://toip.tools/toolkit/anon-membership/api/epochOf/)

- [`fieldFromBytes`](https://toip.tools/toolkit/anon-membership/api/fieldFromBytes/)

  \`toField(SHA-256(bytes))\`: agora's f(bytes).

- [`fieldFromBytes32`](https://toip.tools/toolkit/anon-membership/api/fieldFromBytes32/)

  Reads 32 bytes, big-endian.

- [`fieldFromHex`](https://toip.tools/toolkit/anon-membership/api/fieldFromHex/)

  Reads \`fieldToHex\`'s form.

- [`fieldToBytes`](https://toip.tools/toolkit/anon-membership/api/fieldToBytes/)

  32 bytes, big-endian.

- [`fieldToHex`](https://toip.tools/toolkit/anon-membership/api/fieldToHex/)

  "0x" and 64 lowercase hex digits, big-endian.

- [`findEquivocation`](https://toip.tools/toolkit/anon-membership/api/findEquivocation/)

  Two validly signed, different roots of one group with the same seq or epoch, if \`docs\` holds any.

- [`groupFieldOf`](https://toip.tools/toolkit/anon-membership/api/groupFieldOf/)

  The group id as the circuit sees it: f(utf8(groupId)), as agora's design writes it.

- [`groupIdOf`](https://toip.tools/toolkit/anon-membership/api/groupIdOf/)

  "\<issuer DID>#\<name>".

- [`hash`](https://toip.tools/toolkit/anon-membership/api/hash/)

  Agora's name for the same hash.

- [`initHashing`](https://toip.tools/toolkit/anon-membership/api/initHashing/)

  Loads Barretenberg's WebAssembly once, for hashing.

- [`isoFromDay`](https://toip.tools/toolkit/anon-membership/api/isoFromDay/)

- [`leafHash`](https://toip.tools/toolkit/anon-membership/api/leafHash/)

  H(4, commitment, schemaId, validUntilDay, registeredDay, attrs\[0\], attrs\[1\], attrs\[2\], attrs\[3\]).

- [`loadArtifacts`](https://toip.tools/toolkit/anon-membership/api/loadArtifacts/)

  The committed artifacts for a depth.

- [`memberSecret`](https://toip.tools/toolkit/anon-membership/api/memberSecret/)

  One secret per group, so the same person's commitments in two groups differ.

- [`membershipInputs`](https://toip.tools/toolkit/anon-membership/api/membershipInputs/)

  Finds the member's leaf in one of the groups and builds the statement and witness to prove.

- [`messageOf`](https://toip.tools/toolkit/anon-membership/api/messageOf/)

  toField(SHA-256(JCS(\["anon-membership/v1/message", app, value\]))).

- [`nodeHash`](https://toip.tools/toolkit/anon-membership/api/nodeHash/)

- [`nullifierOf`](https://toip.tools/toolkit/anon-membership/api/nullifierOf/)

  H(2, secret, scope, k).

- [`parseMembershipProof`](https://toip.tools/toolkit/anon-membership/api/parseMembershipProof/)

  Checks the shape of a proof that arrived from elsewhere.

- [`plainLeaf`](https://toip.tools/toolkit/anon-membership/api/plainLeaf/)

  A leaf with no attributes that never expires: tipline's case, where the root itself is the revocation.

- [`poseidon2`](https://toip.tools/toolkit/anon-membership/api/poseidon2/)

  Poseidon2 over BN254 as Noir's \`Poseidon2::hash(inputs, inputs.length)\` (noir-lang/poseidon v0.4.0).

- [`rootDocHash`](https://toip.tools/toolkit/anon-membership/api/rootDocHash/)

  Hex SHA-256 of the JCS of the signed root document.

- [`sameStatement`](https://toip.tools/toolkit/anon-membership/api/sameStatement/)

  Equal as public inputs: trailing "any" predicates are the same as missing ones.

- [`scopeOf`](https://toip.tools/toolkit/anon-membership/api/scopeOf/)

  toField(SHA-256(JCS(\["anon-membership/v1/scope", app, ...parts\]))).

- [`simpleStatement`](https://toip.tools/toolkit/anon-membership/api/simpleStatement/)

  Defaults that make a statement mean "a current member of this group": tipline's case.

- [`snapshotMatches`](https://toip.tools/toolkit/anon-membership/api/snapshotMatches/)

- [`toField`](https://toip.tools/toolkit/anon-membership/api/toField/)

  The first 31 bytes of a 32-byte digest, big-endian.

- [`treeFromRoot`](https://toip.tools/toolkit/anon-membership/api/treeFromRoot/)

  Rebuilds the tree from a snapshot and checks it against the signed root: hash, root, length and size.

- [`verifyPath`](https://toip.tools/toolkit/anon-membership/api/verifyPath/)

  True if \`leaf\` at \`path.index\` with \`path.siblings\` gives \`root\`.

- [`vkHashOf`](https://toip.tools/toolkit/anon-membership/api/vkHashOf/)

- [`whyUnsatisfied`](https://toip.tools/toolkit/anon-membership/api/whyUnsatisfied/)

  Why a witness can't satisfy a statement, or null.

- [`zeroHashes`](https://toip.tools/toolkit/anon-membership/api/zeroHashes/)

  Z\[0\] = 0, Z\[i+1\] = H(3, Z\[i\], Z\[i\]), for i up to \`depth\`.

## Classes

- [`GroupIssuer`](https://toip.tools/toolkit/anon-membership/api/GroupIssuer/)

  Runs one group: enrolls members, removes leavers, and signs one root per epoch in a hash chain.

- [`GroupTree`](https://toip.tools/toolkit/anon-membership/api/GroupTree/)

  A fixed-depth, sparse Poseidon2 Merkle tree of leaves.

- [`MembershipError`](https://toip.tools/toolkit/anon-membership/api/MembershipError/)

  Thrown when the witness can't satisfy the statement: not a member, expired, an unmet predicate, and so on.

- [`MembershipProver`](https://toip.tools/toolkit/anon-membership/api/MembershipProver/)

- [`MembershipVerifier`](https://toip.tools/toolkit/anon-membership/api/MembershipVerifier/)

- [`NullifierBook`](https://toip.tools/toolkit/anon-membership/api/NullifierBook/)

  Turns nullifiers into stable labels, "Source A", "Source B", …, per (group, scope), in order of first sight.

## Interfaces

- [`AcceptPolicy`](https://toip.tools/toolkit/anon-membership/api/AcceptPolicy/)

  What a verifier accepts.

- [`BackendOptions`](https://toip.tools/toolkit/anon-membership/api/BackendOptions/)

- [`CircuitArtifacts`](https://toip.tools/toolkit/anon-membership/api/CircuitArtifacts/)

- [`Crs`](https://toip.tools/toolkit/anon-membership/api/Crs/)

  Setup data for proving and verifying: uncompressed BN254 G1 points (64 bytes each) and the G2 point.

- [`Enrollment`](https://toip.tools/toolkit/anon-membership/api/Enrollment/)

  What the member's side gets back, decoded.

- [`EnrollRequest`](https://toip.tools/toolkit/anon-membership/api/EnrollRequest/)

- [`EnrollResponse`](https://toip.tools/toolkit/anon-membership/api/EnrollResponse/)

- [`GroupIssuerState`](https://toip.tools/toolkit/anon-membership/api/GroupIssuerState/)

- [`GroupRoot`](https://toip.tools/toolkit/anon-membership/api/GroupRoot/)

  A signed group root.

- [`Leaf`](https://toip.tools/toolkit/anon-membership/api/Leaf/)

  What the issuer puts in the tree for one member.

- [`LeafJson`](https://toip.tools/toolkit/anon-membership/api/LeafJson/)

- [`MembershipInputsOptions`](https://toip.tools/toolkit/anon-membership/api/MembershipInputsOptions/)

- [`MembershipProof`](https://toip.tools/toolkit/anon-membership/api/MembershipProof/)

  A proof in a JSON-safe form, as it travels.

- [`MerklePath`](https://toip.tools/toolkit/anon-membership/api/MerklePath/)

  A leaf's index and its siblings, leaf level first.

- [`NullifierBookState`](https://toip.tools/toolkit/anon-membership/api/NullifierBookState/)

- [`ProveProgress`](https://toip.tools/toolkit/anon-membership/api/ProveProgress/)

- [`Statement`](https://toip.tools/toolkit/anon-membership/api/Statement/)

  The public half of a proof.

- [`StatementJson`](https://toip.tools/toolkit/anon-membership/api/StatementJson/)

- [`Witness`](https://toip.tools/toolkit/anon-membership/api/Witness/)

  The private half.

## Types

- [`Acceptance`](https://toip.tools/toolkit/anon-membership/api/Acceptance/)

- [`AcceptReason`](https://toip.tools/toolkit/anon-membership/api/AcceptReason/)

- [`CrsSource`](https://toip.tools/toolkit/anon-membership/api/CrsSource/)

  Where the prover gets its CRS.

- [`Depth`](https://toip.tools/toolkit/anon-membership/api/Depth/)

- [`Field`](https://toip.tools/toolkit/anon-membership/api/Field/)

  An element of BN254's scalar field Fr, the native field of Noir on Barretenberg.

- [`LeafFields`](https://toip.tools/toolkit/anon-membership/api/LeafFields/)

- [`Predicate`](https://toip.tools/toolkit/anon-membership/api/Predicate/)

- [`RootLogCheck`](https://toip.tools/toolkit/anon-membership/api/RootLogCheck/)

- [`ScopePart`](https://toip.tools/toolkit/anon-membership/api/ScopePart/)

  One part of a scope: a string, an integer, or a field (written as hex).

- [`VerifyResult`](https://toip.tools/toolkit/anon-membership/api/VerifyResult/)

## Constants

- [`CIRCUIT_ID`](https://toip.tools/toolkit/anon-membership/api/CIRCUIT_ID/)

  The circuit the library proves with.

- [`DAY_SECONDS`](https://toip.tools/toolkit/anon-membership/api/DAY_SECONDS/)

- [`DEPTH`](https://toip.tools/toolkit/anon-membership/api/DEPTH/)

  The compiled circuit's depth.

- [`ENROLL`](https://toip.tools/toolkit/anon-membership/api/ENROLL/)

  ourSpec("anon-membership/enroll"): member DID → issuer, request and response.

- [`FIELD_MODULUS`](https://toip.tools/toolkit/anon-membership/api/FIELD_MODULUS/)

- [`MAX_LIMIT`](https://toip.tools/toolkit/anon-membership/api/MAX_LIMIT/)

  Rate-limit indexes are below this.

- [`NEVER_EXPIRES`](https://toip.tools/toolkit/anon-membership/api/NEVER_EXPIRES/)

  The largest day number, for leaves that never expire.

- [`PROOF_SYSTEM`](https://toip.tools/toolkit/anon-membership/api/PROOF_SYSTEM/)

  UltraHonk in its zero-knowledge mode, with a Poseidon2 transcript.

- [`TAG`](https://toip.tools/toolkit/anon-membership/api/TAG/)

  Domain tags, the first input of each hash.

Signatures and source documentation are generated from [`packages/anon-membership/src/index.ts`](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/anon-membership/src/index.ts).

---

This is the Markdown version of https://toip.tools/toolkit/anon-membership/api/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
