API reference · Browser and Node
@toip-tools/anon-membership
93 public exports.
import { type Acceptance, acceptMembership, type AcceptPolicy } from "@toip-tools/anon-membership";
Functions
-
acceptMembershipDecides whether a membership proof is acceptable: the circuit is pinned, the groups are the
-
bundledCrsThe CRS bundled in artifacts/crs.json, enough points for every compiled circuit.
-
checkRootLogChecks a group's root log, oldest first: each document signed by `expectedIssuer`, one group,
-
checkStatementThrows if the statement can't be a public input of the circuit.
-
commitmentOfH(1, secret, groupId).
-
dayFromIso -
dayOfDays since 1970-01-01 UTC.
-
decodeLeaf -
decodeMembershipCodeThe secret, or null for a typo or a code made for another group.
-
decodeStatement -
deriveSecrettoField(HMAC-SHA256(seed, utf8(info))).
-
encodeLeaf -
encodeMembershipCodeCrockford base32 of the 31-byte secret and a 2-byte checksum over (groupId, secret), in groups of 4.
-
encodeStatement -
enrollMember side: sends the commitment for `groupId` and checks the leaf the issuer recorded.
-
epochIndexThe epoch's index: periods since 1970.
-
epochOf -
fieldFromBytes`toField(SHA-256(bytes))`: agora's f(bytes).
-
fieldFromBytes32Reads 32 bytes, big-endian.
-
fieldFromHexReads `fieldToHex`'s form.
-
fieldToBytes32 bytes, big-endian.
-
fieldToHex"0x" and 64 lowercase hex digits, big-endian.
-
findEquivocationTwo validly signed, different roots of one group with the same seq or epoch, if `docs` holds any.
-
groupFieldOfThe group id as the circuit sees it: f(utf8(groupId)), as agora's design writes it.
-
groupIdOf"<issuer DID>#<name>".
-
hashAgora's name for the same hash.
-
initHashingLoads Barretenberg's WebAssembly once, for hashing.
-
isoFromDay -
leafHashH(4, commitment, schemaId, validUntilDay, registeredDay, attrs[0], attrs[1], attrs[2], attrs[3]).
-
loadArtifactsThe committed artifacts for a depth.
-
memberSecretOne secret per group, so the same person's commitments in two groups differ.
-
membershipInputsFinds the member's leaf in one of the groups and builds the statement and witness to prove.
-
messageOftoField(SHA-256(JCS(["anon-membership/v1/message", app, value]))).
-
nodeHash -
nullifierOfH(2, secret, scope, k).
-
parseMembershipProofChecks the shape of a proof that arrived from elsewhere.
-
plainLeafA leaf with no attributes that never expires: tipline's case, where the root itself is the revocation.
-
poseidon2Poseidon2 over BN254 as Noir's `Poseidon2::hash(inputs, inputs.length)` (noir-lang/poseidon v0.4.0).
-
rootDocHashHex SHA-256 of the JCS of the signed root document.
-
sameStatementEqual as public inputs: trailing "any" predicates are the same as missing ones.
-
scopeOftoField(SHA-256(JCS(["anon-membership/v1/scope", app, ...parts]))).
-
simpleStatementDefaults that make a statement mean "a current member of this group": tipline's case.
-
snapshotMatches -
toFieldThe first 31 bytes of a 32-byte digest, big-endian.
-
treeFromRootRebuilds the tree from a snapshot and checks it against the signed root: hash, root, length and size.
-
verifyPathTrue if `leaf` at `path.index` with `path.siblings` gives `root`.
-
vkHashOf -
whyUnsatisfiedWhy a witness can't satisfy a statement, or null.
-
zeroHashesZ[0] = 0, Z[i+1] = H(3, Z[i], Z[i]), for i up to `depth`.
Classes
-
GroupIssuerRuns one group: enrolls members, removes leavers, and signs one root per epoch in a hash chain.
-
GroupTreeA fixed-depth, sparse Poseidon2 Merkle tree of leaves.
-
MembershipErrorThrown when the witness can't satisfy the statement: not a member, expired, an unmet predicate, and so on.
-
MembershipProver -
MembershipVerifier -
NullifierBookTurns nullifiers into stable labels, "Source A", "Source B", …, per (group, scope), in order of first sight.
Interfaces
-
AcceptPolicyWhat a verifier accepts.
-
BackendOptions -
CircuitArtifacts -
CrsSetup data for proving and verifying: uncompressed BN254 G1 points (64 bytes each) and the G2 point.
-
EnrollmentWhat the member's side gets back, decoded.
-
EnrollRequest -
EnrollResponse -
GroupIssuerState -
GroupRootA signed group root.
-
LeafWhat the issuer puts in the tree for one member.
-
LeafJson -
MembershipInputsOptions -
MembershipProofA proof in a JSON-safe form, as it travels.
-
MerklePathA leaf's index and its siblings, leaf level first.
-
NullifierBookState -
ProveProgress -
StatementThe public half of a proof.
-
StatementJson -
WitnessThe private half.
Types
-
Acceptance -
AcceptReason -
CrsSourceWhere the prover gets its CRS.
-
Depth -
FieldAn element of BN254's scalar field Fr, the native field of Noir on Barretenberg.
-
LeafFields -
Predicate -
RootLogCheck -
ScopePartOne part of a scope: a string, an integer, or a field (written as hex).
-
VerifyResult
Constants
-
CIRCUIT_IDThe circuit the library proves with.
-
DAY_SECONDS -
DEPTHThe compiled circuit's depth.
-
ENROLLourSpec("anon-membership/enroll"): member DID → issuer, request and response.
-
FIELD_MODULUS -
MAX_LIMITRate-limit indexes are below this.
-
NEVER_EXPIRESThe largest day number, for leaves that never expire.
-
PROOF_SYSTEMUltraHonk in its zero-knowledge mode, with a Poseidon2 transcript.
-
TAGDomain tags, the first input of each hash.
Signatures and source documentation are generated from packages/anon-membership/src/index.ts.