Reference

SDK

Every export of @once/sdk: the API clients, keys, credentials, the OPRF, nullifiers and proofs.

@once/sdk is one TypeScript package for everything a client of Once does: it reads scopes and ledgers through the API, and it holds the cryptography the device runs, from the unlock to the proofs. It runs in the browser and in Node 22.

ts
import { createSdk, scopeNullifier } from '@once/sdk'

Field elements are bigint, BabyJubJub points are [x, y] pairs of bigint, and keys and encodings are Uint8Array. In the browser it uses WebCrypto for SHA-256, HKDF and randomness, and loads snarkjs only when a proof is made. Each signature below is the package's own declaration.

Reading Once

createClient

A typed client with one method per API endpoint, named as in the API reference. Responses are validated against the contract’s schemas, and a failure throws ApiClientError carrying the error envelope.

ts
function createClient(baseUrl: string, options?: Omit<HttpOptions, 'apiError'>): OnceClient

createOprfClient

A client for one OPRF node, from its address or the evaluation URL config lists: info() and evaluate(request).

ts
function createOprfClient(address: string, options?: Omit<HttpOptions, 'apiError'>): OprfClient

createSdk

Reads scopes and ledgers through the API. claims pages through a ledger for you; hasClaimed looks for a nullifier on your side, so the API never learns which one you asked about.

ts
createSdk(baseUrl: string, options?: Omit<HttpOptions, "apiError">): OnceSdk

OnceSdk

What createSdk returns.

ts
interface OnceSdk {
    api: OnceClient;
    scope: OnceClient['getScope'];
    scopes: OnceClient['listScopes'];
    claims(scopeId: string): AsyncGenerator<Claim>;
    hasClaimed(scopeId: string, n: bigint | string): Promise<boolean>;
}

Unlock and keys

The unlock signature and everything derived from it stay on the device.

deriveUnlock

Derives the place secret kPlace, the holder signing seed and the holder public key from the unlock signature and the wallet address, with HKDF-SHA256.

ts
deriveUnlock(signature: Uint8Array, walletAddress: Uint8Array): Promise<{ kPlace: bigint; holderSeed: Uint8Array; holder: Point; }>

publicKey

The BabyJubJub public key of a 32-byte seed: a holder key or an issuer key.

ts
publicKey(seed: Uint8Array): Point

sign

Signs a field element with EdDSA-Poseidon.

ts
sign(seed: Uint8Array, message: bigint): Signature

unlockMessage

The exact bytes the wallet signs to unlock.

ts
unlockMessage(): Uint8Array

verifySignatureField

Checks an EdDSA-Poseidon signature over a field element, with both points in the subgroup.

ts
verifySignatureField(key: Point, message: bigint, signature: Signature): boolean

Credentials

CredentialFields

What an issuer signs, before encoding.

ts
type CredentialFields = { subjectId: string; name: string; dob: bigint; placeOfBirth: string; sex: string; nationality: string; validFrom: bigint; validUntil: bigint; holder: Point; issuerId: string; credentialType: string }

credentialFromWire

Reads a credential from the issuer API into a SignedCredential and checks its root and signature.

ts
credentialFromWire(wire: WireCredential): Promise<SignedCredential>

credentialRoot

The Poseidon root of the 16 values, which the issuer signs.

ts
credentialRoot(values: bigint[]): bigint

CredentialValues

The 16 field elements a credential encodes to.

ts
type CredentialValues = [subjectId: bigint, name: bigint, dob: bigint, placeOfBirth: bigint, sex: bigint, nationality: bigint, validFrom: bigint, validUntil: bigint, holderX: bigint, holderY: bigint, issuerId: bigint, credentialType: bigint, reserved12: bigint, reserved13: bigint, reserved14: bigint, reserved15: bigint]

encodeCredential

Encodes the fields into the 16 values.

ts
encodeCredential(c: CredentialFields): Promise<CredentialValues>

hashId

The private identifier, the Poseidon hash of values 0 to 6.

ts
hashId(values: bigint[]): bigint

issueCredential

Encodes, roots and signs a credential with an issuer seed.

ts
issueCredential(seed: Uint8Array, fields: CredentialFields): Promise<SignedCredential>

Signature

An EdDSA-Poseidon signature.

ts
type Signature = { R8: Point; S: bigint; }

SignedCredential

A credential as the circuits use it: its values, the issuer key and the signature.

ts
type SignedCredential = { values: CredentialValues; issuer: Point; signature: Signature }

verifyCredential

Checks a credential’s signature over its root.

ts
verifyCredential(credential: SignedCredential): boolean

WireCredential

A credential as the issuer API returns it.

ts
type WireCredential = { type: readonly string[]; issuer: { id: string; publicKey: string; }; validFrom: string; validUntil: string; credentialSubject: { subjectId: string; name: string; dateOfBirth: string; placeOfBirth: string; sex: string; nationality: string; holderPublicKey: string; }; proof: { root: string; signature: string; } }

The OPRF

answerFromWire

Reads a node’s answer from the API.

ts
answerFromWire(evaluation: WireEvaluation): NodeAnswer

blind

Hashes HashID to the curve and blinds it with a fresh random scalar.

ts
blind(hashID: bigint): BlindedQuery

BlindedQuery

A blinded query B with its blinding scalar r, which stays on the device.

ts
type BlindedQuery = { r: bigint; B: Point }

combine

Combines two checked answers and unblinds them into Q and the person secret s.

ts
combine(query: BlindedQuery, keys: Registry, answers: [NodeAnswer, NodeAnswer]): { Z: Point<bigint>; Q: Point; s: bigint; commitments: { t1: Point; t2: Point; }[]; }

DleqProof

A node’s Chaum–Pedersen proof.

ts
type DleqProof = { challenge: bigint; response: bigint }

evaluate

A node’s side: multiplies the query by the share and proves it.

ts
evaluate(share: SecretShare, B: Point): NodeAnswer

evaluateRequest

Builds the signed request body for one node from the credential, the query and the authorization proof.

ts
evaluateRequest(vc: SignedCredential, query: BlindedQuery, authorization: ProofResult, holderSeed: Uint8Array, id: NodeIndex, now: Date): { nodeId: NodeIndex; blindedQuery: string; authorizationProof: WireProof; publicSignals: string[]; holderPublicKey: string; holderSignature: string; timestamp: string; }

evaluationMessage

The field element a holder signs to ask one node.

ts
evaluationMessage(index: NodeIndex, B: Point, timestamp: bigint): bigint

hashToCurve

Maps HashID to a BabyJubJub point with Elligator 2.

ts
hashToCurve(hashID: bigint): Point

lagrange

The interpolation coefficients for two node indices.

ts
lagrange(a: NodeIndex, b: NodeIndex): [bigint, bigint]

NodeAnswer

A node’s partial evaluation with its proof.

ts
type NodeAnswer = { index: NodeIndex; Z: Point; proof: DleqProof }

NodeIndex

A node’s index.

ts
type NodeIndex = 2 | 3 | 1

personSecret

The person secret s = Poseidon(Qx, Qy).

ts
personSecret(Q: Point): bigint

Registry

The public points [K₁, K₂, K₃, K].

ts
type Registry = [Point, Point, Point, Point]

registryDigest

The Poseidon digest of the registry’s eight coordinates.

ts
registryDigest(keys: Registry): bigint

registryFromConfig

Reads the registry from GET /v1/config and checks it.

ts
registryFromConfig(config: WireRegistry): Registry

SecretShare

One node’s share of the OPRF key.

ts
type SecretShare = { index: NodeIndex; scalar: bigint }

splitKey

Splits an OPRF key into three shares and returns the public registry. Run once, where the key is made.

ts
splitKey(secret?: bigint): { registry: Registry; shares: SecretShare[]; }

unblind

Removes the blinding scalar from a combined answer.

ts
unblind(Z: Point, r: bigint): Point

validateRegistry

Checks the four registry points lie on one degree-one polynomial.

ts
validateRegistry(keys: Registry): boolean

verifyAnswer

Checks a node’s answer against its public share.

ts
verifyAnswer(key: Point, B: Point, answer: NodeAnswer): boolean

Nullifiers and the tree

DOMAIN_PERSON

The domain tag of the person nullifier, 2^128 + 0x504552534f4e.

ts
DOMAIN_PERSON: bigint

leafCommitment

The leaf Poseidon(s, kPlace, expiry).

ts
leafCommitment(s: bigint, kPlace: bigint, expiry: bigint): bigint

MerklePath

A leaf’s index, its 20 siblings and the root they lead to.

ts
type MerklePath = { index: number; siblings: bigint[]; root: bigint }

PERSON_TREE_DEPTH

The tree’s depth.

ts
PERSON_TREE_DEPTH: 20

personNullifier

The person nullifier N from s.

ts
personNullifier(s: bigint): bigint

PersonTree

The person tree on the device, built from the full leaf list (zero at revoked indices) and, to accept older roots, the root history read from the tree account. path(index) gives the Merkle path a claim proves with.

ts
class PersonTree {
    constructor(leaves?: readonly bigint[], recentRoots?: readonly bigint[]);
    get nextIndex(): number;
    get root(): bigint;
    get recentRoots(): readonly bigint[];
    accepts(root: bigint): boolean;
    get frontier(): readonly bigint[];
    append(leaf: bigint): number;
    revoke(index: number): void;
    path(index: number): MerklePath;
}

scopeNullifier

The scope nullifier n from s and a scope ID.

ts
scopeNullifier(s: bigint, scopeId: bigint): bigint

TREE_ZEROS

The empty-subtree hash at each height.

ts
TREE_ZEROS: readonly bigint[]

Proofs

authorizeInputs

The authorize circuit’s inputs from a credential and a blinded query.

ts
authorizeInputs(vc: SignedCredential, query: BlindedQuery): { B: Point; holder: Point; validUntil: bigint; issuer: Point; values: CredentialValues; sigR8: Point; sigS: bigint; r: bigint; montY: bigint[]; branch: bigint[]; }

authorizeSignals

The seven public signals an authorize proof must have.

ts
authorizeSignals(B: Point, issuer: Point, holder: Point, validUntil: bigint): bigint[]

CircuitName

authorize, enroll or claim.

ts
type CircuitName = keyof CircuitInputs

claimDigest

The claim circuit’s one public input, as the program rebuilds it.

ts
claimDigest(root: bigint, n: bigint, scopeId: bigint, closesAt: bigint, binding: bigint): bigint

claimInputs

The claim circuit’s inputs. Throws RangeError("CredentialExpiresBeforeClose") when the expiry is not after the closing time.

ts
claimInputs({ s, kPlace, expiry, path, scopeId, closesAt, binding }: ClaimOpening): { s: bigint; kPlace: bigint; expiry: bigint; root: bigint; siblings: bigint[]; index: bigint; scopeId: bigint; closesAt: bigint; binding: bigint; }

ClaimOpening

What claimInputs takes: s, kPlace, the expiry, the Merkle path, the scope ID, its closing time and the binding.

ts
type ClaimOpening = { s: bigint; kPlace: bigint; expiry: bigint; path: MerklePath; scopeId: bigint; closesAt: bigint; binding: bigint }

dropBinding

A drop claim’s binding and payout output, from a fresh claim holder’s address and the scope’s terms.

ts
dropBinding(pda: ClaimHolderPda, scope: { kind: string; amountPerPerson: string | null; relayFee: string; }): { ownerHash: Uint8Array<ArrayBuffer>; value: bigint; recipientOutput: { ownerShieldedAddress: string; amount: string; }; }

enrollInputs

The enroll circuit’s inputs from the credential, the query, the registry, two answers, kPlace and the wallet address.

ts
function enrollInputs(vc: SignedCredential, query: BlindedQuery, keys: Registry, answers: [NodeAnswer, NodeAnswer], kPlace: bigint, walletAddress: Uint8Array): {
    keys: Registry;
    keyPreimages: Point[];
    indices: bigint[];
    answers: Point[];
    answerPreimages: Point[];
    t1: Point[];
    t2: Point[];
    responses: bigint[];
    Q: Point;
    qPreimage: Point;
    kPlace: bigint;
    wallet: [bigint, bigint];
    issuer: Point;
    values: CredentialValues;
    sigR8: Point;
    sigS: bigint;
    r: bigint;
    montY: bigint[];
    branch: bigint[];
};

enrollmentDigest

The enroll circuit’s one public input, as the program rebuilds it.

ts
enrollmentDigest(N: bigint, leaf: bigint, issuer: Point, keyDigest: bigint, validUntil: bigint, walletAddress: Uint8Array): bigint

enrollStatement

The public enrollment terms the API’s buildEnroll takes, with N, the leaf and the expiry.

ts
enrollStatement({ s, kPlace, vc, issuerId }: { s: bigint; kPlace: bigint; vc: SignedCredential; issuerId: string; }): { expiry: bigint; leaf: bigint; personNullifier: bigint; statement: { personNullifier: string; leaf: string; issuerId: string; expiresAt: string; }; }

pollBinding

A poll vote’s binding, from the option index.

ts
pollBinding(optionIndex: number): bigint

proofBytes

The 256 bytes the program takes for a proof.

ts
proofBytes(proof: WireProof): Uint8Array

ProofResult

A proof and its public signals, as snarkjs writes them.

ts
type ProofResult = { proof: WireProof; publicSignals: string[] }

prove

Proves one circuit with snarkjs, loaded on first use.

ts
prove<Name extends CircuitName>(name: Name, inputs: CircuitInputs[Name], artifacts: ProvingArtifacts): Promise<ProofResult>

ProvingArtifacts

A circuit’s WASM and proving key, as URLs in the browser, file paths in Node, or bytes.

ts
type ProvingArtifacts = { wasm: string | Uint8Array; zkey: string | Uint8Array }

verify

Verifies a proof with a trusted verification key and, when given, the full expected public statement.

ts
verify(name: keyof CircuitInputs, result: ProofResult, trustedKey: unknown, expected?: readonly bigint[]): Promise<boolean>

Payouts and withdrawals

These find a person's payout notes and withdraw them. Rings payouts explains the keys and the notes.

AddressLike

An address as a kit Address, a base58 string or anything with toBase58().

ts
type AddressLike = string | Address | { toBase58(): string; }

Assets

What createAssets returns.

ts
type Assets = { readonly registry: AssetRegistry; mint(assetId: bigint, signal?: AbortSignal): Promise<Address>; refresh(signal?: AbortSignal): Promise<void>; }

createAssets

Maps SPP’s asset IDs to mints, read from chain.

ts
createAssets(spr: SprClient): Assets

createOwnerScanner

Reads Once’s payout traffic for the notes the payout keys open. scan() reads what came since the last call, checks each note against its commitment and marks spent ones; notes() returns them all.

ts
createOwnerScanner(options: OwnerScannerOptions): { scan: (signal?: AbortSignal) => Promise<RingsNote[]>; notes: () => RingsNote[]; highest: () => Map<string, number>; }

createRingsClient

A Solana Privacy Rings client for the cluster. On the localnet, pass the indexer’s and the prover’s URLs from config.rings.

ts
createRingsClient(options: RingsClientOptions): Promise<SprClient>

DropAsset

sol or usdc.

ts
type DropAsset = "sol" | "usdc"

encodeWithdrawalRequest

Turns a proven withdrawal into the body of POST /v1/withdrawals/relay.

ts
encodeWithdrawalRequest(spend: { destination: AddressLike; inputNullifier: string; ringsData: Uint8Array; }): { destination: string; inputNullifiers: string[]; withdrawalBase64: string; }

Holder

One payout key: its kind and index, its nullifier key and its viewing key.

ts
type Holder = { readonly kind: string; readonly index: number; readonly nullifierKey: NullifierKey; readonly viewingKey: ViewingKey; readonly viewingPublicKeyHex: string; }

holderOwnerHash

The owner hash of a note the holders authority owns under this key: the binding of a drop claim.

ts
holderOwnerHash(authority: Address, holder: Holder): Bytes32

holderPda

The shielded address a payout under this key is paid to, owned by the holders authority.

ts
holderPda(authority: Address, holder: Holder): ShieldedPda

HolderSet

Every payout key of one wallet, by kind and index.

ts
type HolderSet = { holder(kind: string, index: number): Holder; destroy(): void; }

holdersFromMaster

The same, from a 32-byte master secret already derived.

ts
holdersFromMaster(app: string, master: Uint8Array): Promise<HolderSet>

holdersFromSignature

Derives every payout key from the unlock signature; pass RINGS_APP_LABEL. Call destroy() on the result when the wallet locks or switches.

ts
holdersFromSignature(app: string, wallet: Address, signature: Uint8Array): Promise<HolderSet>

HolderWithdrawal

A proven withdrawal: its SPP data and accounts, the note it spends, the relay fee and what the destination receives.

ts
type HolderWithdrawal = { ringsData: Uint8Array; remaining: AccountMeta<string>[]; provingMs: number; destination: Address; asset: DropAsset; inputNullifier: string; relayFee: bigint; netAmount: bigint }

HolderWithdrawalConfig

What a withdrawal reads from config: the USDC mint, the holders authority and the relay fees.

ts
type HolderWithdrawalConfig = { usdcMint: AddressLike; holdersAuthority: AddressLike; solRelayFee: string | bigint; usdcRelayFee: string | bigint }

OwnerScannerOptions

What createOwnerScanner takes: the Rings client, the holders authority, the payout keys and their kinds.

ts
type OwnerScannerOptions = { spr: SprClient; authority: Address; holders: HolderSet; kinds: readonly string[]; lookahead?: number; assets?: Assets; }

proveHolderWithdrawal

Proves the withdrawal of one whole payout note to a public address, with the relay fee as a second payment. Runs in the browser.

ts
proveHolderWithdrawal(args: { spr: SprClient; config: HolderWithdrawalConfig; relayer: AddressLike; destination: AddressLike; note: RingsNote; }): Promise<HolderWithdrawal>

retryingProverFetch

A fetch for the Rings prover that retries its rate-limit and server-error answers.

ts
function retryingProverFetch(base?: typeof globalThis.fetch, proverUrl?: string): typeof globalThis.fetch;

RINGS_APP_LABEL

The app label Once’s payout keys are derived under: once.

ts
RINGS_APP_LABEL: "once"

RingsClientOptions

What createRingsClient takes.

ts
type RingsClientOptions = { cluster: RingsCluster; solanaRpcUrl: string; indexerUrl?: string; proverUrl?: string; fetch?: { (input: RequestInfo | URL, init?: RequestInit): Promise<Response>; (input: string | Request | URL, init?: RequestInit): Promise<Response>; }; }

RingsCluster

The cluster a Rings client talks to.

ts
type RingsCluster = "mainnet" | "devnet" | "localnet"

RingsNote

One payout note the scanner opened: its key, mint, amount, place in the tree and whether it is spent.

ts
type RingsNote = { readonly holder: Holder; readonly hashHex: string; readonly tree: Address; readonly treeId: number; readonly leafIndex: bigint; readonly slot: bigint; readonly signature: string; readonly proofless: boolean; readonly mint: Address; readonly amount: bigint; readonly utxo: Utxo; readonly nullifierHex: string; walletUtxo: WalletUtxo; spent: boolean; }

SOL_MINT

The address that stands for SOL among assets.

ts
SOL_MINT: Address<"11111111111111111111111111111111">

Encoding

addPoint

Adds two BabyJubJub points.

ts
addPoint(p1: Point<bigint>, p2: Point<bigint>): Point<bigint>

field

Checks a value is a canonical field element.

ts
field(value: bigint): bigint

FIELD

The BN254 scalar field’s modulus.

ts
FIELD: bigint

fieldBytes

A field element as 32 big-endian bytes.

ts
fieldBytes(value: bigint): Uint8Array

fromBytes

Reads big-endian bytes as an integer.

ts
fromBytes(bytes: Uint8Array): bigint

GENERATOR

The BabyJubJub base point the keys use.

ts
GENERATOR: Point<bigint>

multiply

Multiplies a BabyJubJub point by a scalar.

ts
multiply(point: Point, scalar: bigint): Point

Point

A BabyJubJub point in affine coordinates.

ts
type Point = [bigint, bigint]

pointFromHex

Unpacks a point from the API’s hex.

ts
pointFromHex(hex: string): Point

pointHex

Packs a point into 32 bytes of hex, as the API sends points.

ts
pointHex(point: Point): string

randomScalar

A uniform nonzero subgroup scalar.

ts
randomScalar(): bigint

SCALAR_ORDER

The order of BabyJubJub’s prime subgroup.

ts
SCALAR_ORDER: bigint

signatureFromHex

Unpacks a signature from the API’s hex.

ts
signatureFromHex(hex: string): Signature

signatureHex

Packs a signature into 64 bytes of hex.

ts
signatureHex(signature: Signature): string

stringField

A string as a field element: SHA-256 of its UTF-8, first 31 bytes big-endian.

ts
stringField(text: string): Promise<bigint>

subgroupPoint

Whether a point is in BabyJubJub’s prime subgroup.

ts
subgroupPoint(point: Point): boolean

walletLimbs

A wallet address as two 16-byte big-endian limbs.

ts
walletLimbs(address: Uint8Array): [bigint, bigint]