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.
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.
function createClient(baseUrl: string, options?: Omit<HttpOptions, 'apiError'>): OnceClientcreateOprfClient
A client for one OPRF node, from its address or the evaluation URL config lists: info() and evaluate(request).
function createOprfClient(address: string, options?: Omit<HttpOptions, 'apiError'>): OprfClientcreateSdk
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.
createSdk(baseUrl: string, options?: Omit<HttpOptions, "apiError">): OnceSdkOnceSdk
What createSdk returns.
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.
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.
publicKey(seed: Uint8Array): PointverifySignatureField
Checks an EdDSA-Poseidon signature over a field element, with both points in the subgroup.
verifySignatureField(key: Point, message: bigint, signature: Signature): booleanCredentials
CredentialFields
What an issuer signs, before encoding.
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.
credentialFromWire(wire: WireCredential): Promise<SignedCredential>credentialRoot
The Poseidon root of the 16 values, which the issuer signs.
credentialRoot(values: bigint[]): bigintCredentialValues
The 16 field elements a credential encodes to.
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.
encodeCredential(c: CredentialFields): Promise<CredentialValues>issueCredential
Encodes, roots and signs a credential with an issuer seed.
issueCredential(seed: Uint8Array, fields: CredentialFields): Promise<SignedCredential>SignedCredential
A credential as the circuits use it: its values, the issuer key and the signature.
type SignedCredential = { values: CredentialValues; issuer: Point; signature: Signature }verifyCredential
Checks a credential’s signature over its root.
verifyCredential(credential: SignedCredential): booleanWireCredential
A credential as the issuer API returns it.
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.
answerFromWire(evaluation: WireEvaluation): NodeAnswerblind
Hashes HashID to the curve and blinds it with a fresh random scalar.
blind(hashID: bigint): BlindedQueryBlindedQuery
A blinded query B with its blinding scalar r, which stays on the device.
type BlindedQuery = { r: bigint; B: Point }combine
Combines two checked answers and unblinds them into Q and the person secret s.
combine(query: BlindedQuery, keys: Registry, answers: [NodeAnswer, NodeAnswer]): { Z: Point<bigint>; Q: Point; s: bigint; commitments: { t1: Point; t2: Point; }[]; }evaluate
A node’s side: multiplies the query by the share and proves it.
evaluate(share: SecretShare, B: Point): NodeAnswerevaluateRequest
Builds the signed request body for one node from the credential, the query and the authorization proof.
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.
evaluationMessage(index: NodeIndex, B: Point, timestamp: bigint): bigintlagrange
The interpolation coefficients for two node indices.
lagrange(a: NodeIndex, b: NodeIndex): [bigint, bigint]NodeAnswer
A node’s partial evaluation with its proof.
type NodeAnswer = { index: NodeIndex; Z: Point; proof: DleqProof }registryDigest
The Poseidon digest of the registry’s eight coordinates.
registryDigest(keys: Registry): bigintregistryFromConfig
Reads the registry from GET /v1/config and checks it.
registryFromConfig(config: WireRegistry): RegistrySecretShare
One node’s share of the OPRF key.
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.
splitKey(secret?: bigint): { registry: Registry; shares: SecretShare[]; }validateRegistry
Checks the four registry points lie on one degree-one polynomial.
validateRegistry(keys: Registry): booleanverifyAnswer
Checks a node’s answer against its public share.
verifyAnswer(key: Point, B: Point, answer: NodeAnswer): booleanNullifiers and the tree
leafCommitment
The leaf Poseidon(s, kPlace, expiry).
leafCommitment(s: bigint, kPlace: bigint, expiry: bigint): bigintMerklePath
A leaf’s index, its 20 siblings and the root they lead to.
type MerklePath = { index: number; siblings: bigint[]; root: 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.
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.
scopeNullifier(s: bigint, scopeId: bigint): bigintProofs
authorizeInputs
The authorize circuit’s inputs from a credential and a blinded query.
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.
authorizeSignals(B: Point, issuer: Point, holder: Point, validUntil: bigint): bigint[]claimDigest
The claim circuit’s one public input, as the program rebuilds it.
claimDigest(root: bigint, n: bigint, scopeId: bigint, closesAt: bigint, binding: bigint): bigintclaimInputs
The claim circuit’s inputs. Throws RangeError("CredentialExpiresBeforeClose") when the expiry is not after the closing time.
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.
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.
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.
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.
enrollmentDigest(N: bigint, leaf: bigint, issuer: Point, keyDigest: bigint, validUntil: bigint, walletAddress: Uint8Array): bigintenrollStatement
The public enrollment terms the API’s buildEnroll takes, with N, the leaf and the expiry.
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; }; }ProofResult
A proof and its public signals, as snarkjs writes them.
type ProofResult = { proof: WireProof; publicSignals: string[] }prove
Proves one circuit with snarkjs, loaded on first use.
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.
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.
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().
type AddressLike = string | Address | { toBase58(): string; }Assets
What createAssets returns.
type Assets = { readonly registry: AssetRegistry; mint(assetId: bigint, signal?: AbortSignal): Promise<Address>; refresh(signal?: AbortSignal): Promise<void>; }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.
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.
createRingsClient(options: RingsClientOptions): Promise<SprClient>encodeWithdrawalRequest
Turns a proven withdrawal into the body of POST /v1/withdrawals/relay.
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.
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.
holderOwnerHash(authority: Address, holder: Holder): Bytes32holderPda
The shielded address a payout under this key is paid to, owned by the holders authority.
holderPda(authority: Address, holder: Holder): ShieldedPdaHolderSet
Every payout key of one wallet, by kind and index.
type HolderSet = { holder(kind: string, index: number): Holder; destroy(): void; }holdersFromMaster
The same, from a 32-byte master secret already derived.
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.
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.
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.
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.
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.
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.
function retryingProverFetch(base?: typeof globalThis.fetch, proverUrl?: string): typeof globalThis.fetch;RingsClientOptions
What createRingsClient takes.
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.
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.
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.
SOL_MINT: Address<"11111111111111111111111111111111">Encoding
pointHex
Packs a point into 32 bytes of hex, as the API sends points.
pointHex(point: Point): stringstringField
A string as a field element: SHA-256 of its UTF-8, first 31 bytes big-endian.
stringField(text: string): Promise<bigint>subgroupPoint
Whether a point is in BabyJubJub’s prime subgroup.
subgroupPoint(point: Point): booleanwalletLimbs
A wallet address as two 16-byte big-endian limbs.
walletLimbs(address: Uint8Array): [bigint, bigint]