Docs/Reference
SDK
Every call of the Liora SDK, the states it reports and the types it returns.
@liora/sdk does everything the app does: it derives keys, registers, deposits, proves and sends payments, scans, audits and runs the whitelist. It runs in a browser and in Node 22. @liora/contract holds the types and the protocol functions the SDK is built on. Contract 0.2.1.
#Install
The two packages come as tarballs named for the contract version. Install both in one command:
npm install --install-links ./liora-contract-0.2.1.tgz ./liora-sdk-0.2.2.tgz#Create an instance
import { createLioraSdk } from "@liora/sdk";
const liora = await createLioraSdk({ mode: "real", baseUrl: apiOrigin });Keep one instance for the life of a session. It holds the keys in memory after unlock and drops them on lock.
mode"real" | "fixture"requiredrealworks against the chain through the API.fixtureworks against a fixture server, with made-up chain state and no proofs, for building screens and tests.baseUrlstringrequiredThe API's origin. Optional in fixture mode.
deviceProverUrlstringReal mode. A Rings prover running on the same machine as the SDK. Without it, the Rings proof goes to the attested prover through the API, encrypted to it.
artifacts{ pay: { wasm, zkey }, withdraw: { wasm, zkey } }Real mode. Where to load the Liora proving files from. By default the API's versioned files.
programIdstringReal mode. The program to use, when it is not the one the SDK was built for.
sessionIdstringFixture mode. Instances with the same id share one fixture chain.
scenarioFixtureScenarioFixture mode.
default,empty, or a failure to rehearse:proof-failed,simulate-failed,sign-failed,send-failed,confirm-failed.
#The wallet
Calls that need a signature take a wallet in this shape:
type MessageWallet = {
address: string;
signMessage(message: Uint8Array): Promise<Uint8Array>;
signTransaction?(unsignedWire: Uint8Array): Promise<Uint8Array>;
};| The wallet signs | For | With |
|---|---|---|
| The unlock message | unlock | signMessage |
| A registration message | register | signMessage |
| An issuer sign-in message | signInIssuer | signMessage |
| A refusal message | refuse | signMessage |
| A deposit transaction | deposit | signTransaction |
| An admission or removal transaction | admit, remove | signTransaction |
The wallet signs nothing for pay and withdraw. The proof authorizes them and the relayer signs the transaction.
#Holder
unlockState- Whether the holder's keys are on this device.
unlockState(): UnlockState unlock- Asks the wallet for the unlock signature and derives the holder's keys.
unlock(wallet: MessageWallet, onState?: OnState<UnlockState>): Promise<UnlockState> lock- Drops the holder's keys.
lock(): void registration- The holder's own registration and its status.
registration(): Promise<RegistrationState> register- Signs and files a registration under a handle.
register(handle: string): Promise<DirectoryEntry> lookup- Finds a whitelisted recipient by handle or meta-address, on the device.
lookup(handleOrMetaAddress: string): Promise<RecipientLookup> balances- Scans and totals the holder's spendable notes, per asset.
balances(): Promise<Balance[]> scan- Reads the announcements and returns the payments the holder's keys open.
scan(onState?: OnState<InboxState>): Promise<InboxState> activity- The holder's own sent and received transfers, as this instance knows them.
activity(): Promise<ActivityState>
const state = await liora.unlock(wallet);{
"state": "unlocked",
"wallet": "EViimyfpZdQJtspZ3ZGKjja7ms1qJymVh5dsT6JrYSF4",
"metaAddress": "liora:1:818c38b64a0b498c277d851d1ec9a29361e7f01094681ec65a40ce3192a99f90b4a34070fd972d0c51615458d787457ef3a8ae50cbaacb8f02949ba99830a825"
}lookup takes a handle, with or without a leading @, or a full meta-address. It resolves on the device from one directory snapshot and answers found only for an entry that is whitelisted now.
scan reports scanning, then empty or a list. A payment already spent stays in the list with spendable false.
#Transfers
buildDeposit- Builds a deposit without sending it.
buildDeposit(amount: SolAmount): Promise<BuiltDeposit> deposit- Deposits public SOL into the private balance.
deposit(amount: SolAmount, onState?: OnState<TransferState>): Promise<TransferState> pay- Pays a whitelisted recipient: looks them up, proves and sends through the relayer.
pay(input: PayInput, onState?: OnState<TransferState>): Promise<TransferState> withdraw- Pays private balance out to a public wallet, through the relayer.
withdraw(input: WithdrawInput, onState?: OnState<TransferState>): Promise<TransferState> follow- Reads the status of a transfer by signature.
follow(signature: string): Promise<RelayStatus>
Amounts are whole lamports in a decimal string, with the asset id beside them. SOL is asset "1".
const result = await liora.pay(
{ recipient: "mira", assetId: "1", amountLamports: "250000000" },
(state) => render(state),
);The three transfer calls resolve to their final state and report every state on the way to the optional callback. They do not throw when a transfer fails: the final state is failed and carries the reason.
| State | Means | Carries |
|---|---|---|
pending | The transfer is being built | |
proving | Payments only. A proof step finished | progress: phase, completed, total |
sent | The transaction has a signature | signature |
confirmed | It is confirmed on chain | signature, and for a payment its receipt |
failed | It stopped | error: code, stage, message |
A real payment reports four proof steps, in the order they happen: the whitelist path, the Rings proof, the Liora proof, and a local check of the result. Fixture mode stands in for the proofs with three steps of its own, and the states of one payment came like this:
["pending", "proving membership 0/3", "proving liora 1/3", "proving rings 2/3", "proving rings 3/3", "sent", "confirmed"]A pending or sent state can carry a followError when the device lost contact after submitting. The transfer may have landed. Call follow(signature) to learn its status before doing anything else, and never send it again on a guess.
A confirmed payment's receipt is its announcement. When the ledger has not caught up yet the receipt is absent, and payment(signature) returns it a moment later.
#Ledger
ledger- Every payment's announcement.
ledger(): Promise<LedgerResponse> payment- One payment's announcement.
payment(signature: string, eventIndex?: number): Promise<PublicPayment> openPayment- One payment as the public, the recipient or the auditor sees it.
openPayment(signature: string, role: 'public' | 'recipient' | 'auditor', eventIndex?: number): Promise<OpenedPayment>
openPayment returns the same payment in the role asked for, as far as the keys on this device allow:
| Role | Needs | Returns |
|---|---|---|
public | Nothing | The announcement |
recipient | The holder unlocked | The announcement with asset, amount and whether it is still spendable. For a payment that is not theirs, the public view |
auditor | The audit key loaded | The announcement with the recipient's directory entry. The amount reads encrypted |
#Audit
auditState- Whether the audit key is on this device.
auditState(): AuditState unlockAudit- Loads the audit key after checking it against the configuration.
unlockAudit(secret: bigint): Promise<AuditState> lockAudit- Drops the audit key.
lockAudit(): void audit- Each payment with the directory entry of its recipient.
audit(recipient?: string): Promise<AuditRow[]> auditCsv- The same rows as CSV.
auditCsv(recipient?: string): Promise<string> auditIdentities- Each payment with its decrypted spend key, and the directory entry when one exists.
auditIdentities(recipient?: string): Promise<AuditIdentityRow[]> auditIdentitiesCsv- The same rows as CSV, with a
spendPubliccolumn.auditIdentitiesCsv(recipient?: string): Promise<string>
unlockAudit takes the audit secret as a bigint and checks it against the auditor's public key in the configuration. The key stays in memory on this device.
audit and auditCsv return payments whose recipient has a registration in the directory. auditIdentities returns every payment, with the decrypted spend key and recipient: null where the directory holds no registration for it. All four take an optional filter: a handle, an entry id or a meta-address, and for the identity calls a packed spend key.
The CSV has the columns signature, eventIndex, blockTime, handle, wallet, metaAddress, amount. Every field is quoted, records end in CRLF, and amount holds the word encrypted.
#Issuer
issuerState- Whether the issuer is signed in on this device.
issuerState(): IssuerState signInIssuer- Signs in with a wallet. Any wallet but the configured issuer is refused.
signInIssuer(wallet: MessageWallet): Promise<IssuerState> signOutIssuer- Ends the issuer session.
signOutIssuer(): void requests- Registrations waiting for a decision.
requests(): Promise<RequestsResponse> admit- Admits a registration to the whitelist.
admit(id: string, revision: number): Promise<IssuerDecisionResponse> refuse- Refuses a registration.
refuse(id: string, revision: number): Promise<IssuerDecisionResponse> remove- Removes an entry from the whitelist.
remove(id: string, revision: number): Promise<IssuerDecisionResponse>
admit, refuse and remove take the registration's id and the whitelist revision the issuer read. A decision against an older revision fails, so two decisions prepared from the same state cannot both land.
An admission or a removal is a transaction the issuer's wallet signs. The call resolves once the directory shows the change. If that takes more than two minutes it rejects with INDEXER_PENDING: the transaction is confirmed and the directory will follow.
{ "status": "whitelisted", "leafIndex": 1, "revision": 2, "size": 2, "acceptedRoots": 2 }{ "status": "removed", "revision": 3, "size": 1, "acceptedRoots": 1 }These are the entry and the whitelist after admitting one request and then removing it, reduced to the fields that changed.
#Service
sessionId- The fixture session this instance uses. Two instances with the same id see the same fixture chain.
readonly sessionId: string directory- Every registration, the whitelist state and the active leaves.
directory(): Promise<DirectoryResponse> whitelist- The current root, revision, size and accepted roots.
whitelist(): Promise<WhitelistState> config- The program address, the roles, the auditor's public key and both fees.
config(): Promise<ProgramConfig> health- Whether the API is ready, and its mode.
health(): Promise<HealthResponse> figures- The measured figures.
figures(): Promise<FiguresResponse>
#Errors
Every call except the three transfers rejects with a LioraFailure, an Error with code, stage and message. The codes are on Errors.
import { LioraFailure } from "@liora/sdk";
try {
await liora.register("dana");
} catch (error) {
if (error instanceof LioraFailure && error.code === "CONFLICT") {
// the handle is taken
}
}#Protocol functions
@liora/contract exports the functions the SDK uses, for code that works with the protocol directly.
| Function | Returns |
|---|---|
unlockMessage() | The bytes a wallet signs to unlock |
deriveDeviceSecrets(wallet, signature) | The master secret, the spend and view keys and the meta-address |
balanceKey(keys, index) | One balance key with its nullifier secret and viewing key |
publicPoint(secret) | The packed public key of a secret |
isProtocolPoint(wire) | Whether a string is a valid packed point |
encodeMetaAddress(spendPublic, viewPublic) | A meta-address |
decodeMetaAddress(text) | Its two public keys |
ownerAddress(point, programId) | The owner address of a public key |
whitelistLeaf(metaAddress) | The leaf of a meta-address |
whitelistRoot(entries) | The root over a set of active leaves |
whitelistPath(entries, index) | The root and the siblings of an occupied index |
whitelistInsertionPath(entries, index) | The same for an empty index, as an admission needs it |
buildStealthOutput(metaAddress, auditorPublicKey, root) | A payment's announcement, with the private values its proof and note need |
recognizeStealthOutput(keys, announcement) | The one-time key material if the payment is the holder's, otherwise null |
decryptAuditIdentity(secret, ciphertext) | The recipient's packed spend key |
registrationMessage(input), issuerDecisionMessage(input) | The bytes to sign for a registration or a refusal |
toBase58, fromBase58, toBase64, fromBase64 | Byte and text conversions |
shortAddress(address, n?) | An address shortened for display |
It also exports a Zod schema and a type for every API request and response, under the names used on API.
#Fixture mode
A fixture server answers the same routes with a made-up chain per session, so a screen or a test can go through every state without funds or proofs. fixtureWallet("payer" | "recipient" | "issuer") and fixtureAuditorSecret are public demo actors, exported by @liora/sdk for that purpose. A new session starts with the payer funded, the recipient mira whitelisted, one request waiting and one payment on the ledger. The scenario empty starts with mira whitelisted and nothing else.