Skip to content

Wallet (Layer 1)

Layer 1 of the SDK communicates with the Dilithia Wallet browser extension. Every function in this layer requires the extension to be installed and injected into window.dilithia.

All wallet functions are top-level named exports:

import { connect, transfer, signMessage, ... } from "@dilithia/browser-sdk";

Provider Detection

getDilithiaProvider()

Returns the raw DilithiaProvider object for advanced use cases.

function getDilithiaProvider(): DilithiaProvider

Returns: The provider object attached to window.dilithia.

Throws: Error if the wallet extension is not installed.

const provider = getDilithiaProvider();
console.log("Version:", provider.providerVersion);

hasDilithiaProvider()

Check whether the wallet extension is installed and injected.

function hasDilithiaProvider(): boolean

Returns: true if window.dilithia exists and has isDilithia === true.

if (!hasDilithiaProvider()) {
  alert("Please install the Dilithia Wallet extension.");
}

Connection

connect(permissions?)

Connect to the wallet. Prompts the user for approval.

function connect(permissions?: string[]): Promise<DilithiaConnectResult>
Parameter Type Description
permissions string[] (optional) Permissions to request on connect

Returns: DilithiaConnectResult with account details, chain info, and the RPC URL.

const session = await connect(["dilithia_signPayload", "dilithia_getBalance"]);
console.log(session.address, session.chainId, session.rpcUrl);

requestPermissions(permissions)

Request additional permissions after connecting.

function requestPermissions(permissions: string[]): Promise<string[]>
Parameter Type Description
permissions string[] Permissions to request

Returns: Array of granted permission strings.

const granted = await requestPermissions(["dilithia_signPayload"]);

permissions()

Get the current set of granted permissions.

function permissions(): Promise<string[]>

Returns: Array of permission strings.

const perms = await permissions();
console.log("Granted:", perms);

disconnect()

Disconnect from the wallet and clear the active session.

function disconnect(): Promise<void>
await disconnect();

switchChain(chainId)

Switch the wallet to a different chain.

function switchChain(chainId: string): Promise<DilithiaConnectResult>
Parameter Type Description
chainId string The chain ID to switch to

Returns: Updated DilithiaConnectResult reflecting the new chain.

const session = await switchChain("dilithia-testnet-2");
console.log("Now on:", session.chainId);

addChain(config)

Register a new chain with the wallet.

function addChain(config: {
  chainId: string;
  rpcUrl: string;
  networkLabel?: string;
}): Promise<void>
Parameter Type Description
config.chainId string Chain identifier
config.rpcUrl string RPC endpoint URL
config.networkLabel string (optional) Human-readable name
await addChain({
  chainId: "dilithia-local",
  rpcUrl: "http://localhost:9070/rpc",
  networkLabel: "Local Dev",
});

Account

getPublicKey()

Get the active account's post-quantum public key (ML-DSA-65).

function getPublicKey(): Promise<string>

Returns: Hex-encoded public key string.

const pubKey = await getPublicKey();
console.log("Public key:", pubKey);

accounts()

List all connected accounts.

function accounts(): Promise<string[]>

Returns: Array of account address strings.

const addrs = await accounts();
console.log("Connected accounts:", addrs);

Signing

signMessage(message)

Sign a text message with the active account's private key (ML-DSA-65).

function signMessage(message: string): Promise<DilithiaSignedMessage>
Parameter Type Description
message string The message to sign

Returns: DilithiaSignedMessage with algorithm, address, public key, original message, and signature.

const signed = await signMessage("Hello, Dilithia!");
console.log("Signature:", signed.signature);

buildOwnershipProof(challenge)

Build a proof of wallet ownership for authentication flows.

function buildOwnershipProof(challenge: string): Promise<Record<string, unknown>>
Parameter Type Description
challenge string Server-issued challenge string

Returns: Proof object suitable for server-side verification.

const proof = await buildOwnershipProof("random-server-challenge-xyz");
// Send proof to your backend for verification
await fetch("/api/verify", { method: "POST", body: JSON.stringify(proof) });

signPayload(payload, options?)

Sign a structured payload. Supports gas sponsorship via the paymaster option.

function signPayload(
  payload: Record<string, unknown>,
  options?: TxOptions,
): Promise<DilithiaSignedPayload>
Parameter Type Description
payload Record<string, unknown> Structured data to sign
options TxOptions (optional) Transaction options

Returns: DilithiaSignedPayload with algorithm, address, public key, signature, payload, and JSON-serialized payload.

const signed = await signPayload({
  contract: "token",
  method: "transfer",
  args: { to: "dili1bob", amount: 50 },
});

With gas sponsorship:

const signed = await signPayload(
  { contract: "token", method: "transfer", args: { to: "dili1bob", amount: 50 } },
  { paymaster: "dili1sponsor" },
);

Transactions

sendTransaction(transaction, options?)

Submit a pre-built transaction to the network. The wallet signs and submits it.

function sendTransaction(
  transaction: Record<string, unknown>,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
transaction Record<string, unknown> The transaction object
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const result = await sendTransaction(
  { to: "dili1contract", data: "0x..." },
  { paymaster: "dili1sponsor" },
);
console.log("Accepted:", result.accepted, "Hash:", result.txHash);

callContract(contract, method, args?, options?)

Build, sign, and submit a contract call in one step. The wallet handles nonce, signing, and submission.

function callContract(
  contract: string,
  method: string,
  args?: Record<string, unknown>,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
contract string Contract address or name
method string Method to invoke
args Record<string, unknown> (optional) Method arguments
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await callContract("token", "approve", {
  spender: "dili1dex",
  amount: 1000,
});

With gas sponsorship:

const tx = await callContract(
  "token", "approve",
  { spender: "dili1dex", amount: 1000 },
  { paymaster: "dili1sponsor" },
);

transfer(to, amount, options?)

Transfer native DILI tokens. Convenience wrapper around callContract("token", "transfer", ...).

function transfer(
  to: string,
  amount: number,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
to string Recipient address
amount number Amount of DILI to send
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await transfer("dili1bob", 100);

With gas sponsorship:

const tx = await transfer("dili1bob", 100, { paymaster: "dili1sponsor" });

Events

on(eventName, handler)

Subscribe to wallet events. Returns an unsubscribe function.

function on(
  eventName: DilithiaEventName,
  handler: (detail: unknown) => void,
): () => void
Parameter Type Description
eventName DilithiaEventName One of "accountsChanged", "chainChanged", "permissionsChanged", "disconnect"
handler (detail: unknown) => void Callback invoked when the event fires

Returns: A function that removes the listener when called.

const unsubscribe = on("accountsChanged", (accounts) => {
  console.log("Active accounts:", accounts);
});

// Later, to stop listening:
unsubscribe();
on("chainChanged", (chainId) => {
  console.log("Switched to chain:", chainId);
  // Re-create your ChainClient with the new rpcUrl
});

Shielded Pool

shieldedDeposit(amount, options?)

Deposit tokens into the shielded pool. The wallet generates the Poseidon hash commitment internally and stores the secret/nonce locally for later withdrawal.

function shieldedDeposit(
  amount: number,
  options?: TxOptions,
): Promise<ShieldedDepositResult>
Parameter Type Description
amount number Amount to deposit
options TxOptions (optional) Transaction options

Returns: ShieldedDepositResult with commitment and txHash.

const deposit = await shieldedDeposit(500);
console.log("Commitment:", deposit.commitment);

With gas sponsorship:

const deposit = await shieldedDeposit(500, { paymaster: "dili1sponsor" });

shieldedWithdraw(commitmentIndex, amount, recipient, options?)

Withdraw from the shielded pool. The wallet generates the STARK proof internally (WASM prover, ~200 ms), computes the nullifier, signs the transaction, and submits.

function shieldedWithdraw(
  commitmentIndex: number,
  amount: number,
  recipient: string,
  options?: TxOptions,
): Promise<ShieldedWithdrawResult>
Parameter Type Description
commitmentIndex number Index of the commitment to spend
amount number Amount to withdraw
recipient string Recipient address
options TxOptions (optional) Transaction options

Returns: ShieldedWithdrawResult with nullifier, proof, and txHash.

const withdrawal = await shieldedWithdraw(0, 500, "dili1alice");
console.log("Nullifier:", withdrawal.nullifier);

With gas sponsorship:

const withdrawal = await shieldedWithdraw(0, 500, "dili1alice", {
  paymaster: "dili1sponsor",
});

shieldedComplianceProof(proofType, params)

Generate a ZK compliance proof. Proves a statement about shielded history without revealing details.

function shieldedComplianceProof(
  proofType: ComplianceProofType,
  params: Record<string, unknown>,
): Promise<{ proof: string; publicInputs: string }>
Parameter Type Description
proofType ComplianceProofType One of "not_on_sanctions", "tax_paid", "balance_range"
params Record<string, unknown> Proof-specific parameters

Returns: Object with proof and publicInputs strings.

const { proof, publicInputs } = await shieldedComplianceProof("balance_range", {
  min: 0,
  max: 10000,
});
const { proof, publicInputs } = await shieldedComplianceProof("not_on_sanctions", {
  sanctionsList: "ofac_sdn_2024",
});

Name Service

registerName(name, options?)

Register a name on the Dilithia Name Service.

function registerName(
  name: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to register
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await registerName("alice");
console.log("Registered:", tx.txHash);

renewName(name, options?)

Renew an existing name registration.

function renewName(
  name: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to renew
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await renewName("alice");

transferName(name, newOwner, options?)

Transfer ownership of a name to another address.

function transferName(
  name: string,
  newOwner: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to transfer
newOwner string The recipient address
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await transferName("alice", "dili1newowner");

setNameTarget(name, target, options?)

Set the resolution target address for a name.

function setNameTarget(
  name: string,
  target: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to update
target string The target address
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await setNameTarget("alice", "dili1target");

setNameRecord(name, key, value, options?)

Set a key-value record on a name.

function setNameRecord(
  name: string,
  key: string,
  value: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to update
key string Record key (e.g., "display_name")
value string Record value
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await setNameRecord("alice", "display_name", "Alice");

releaseName(name, options?)

Release a name, giving up ownership.

function releaseName(
  name: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string The name to release
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await releaseName("alice");

Credentials

registerSchema(name, version, attributes, options?)

Register a credential schema on-chain.

function registerSchema(
  name: string,
  version: string,
  attributes: SchemaAttribute[],
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
name string Schema name
version string Schema version
attributes SchemaAttribute[] Array of attribute definitions
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await registerSchema("KYC", "1.0", [{ name: "age", type: "u64" }]);

issueCredential(holder, schemaHash, commitment, options?)

Issue a credential to a holder.

function issueCredential(
  holder: string,
  schemaHash: string,
  commitment: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
holder string Holder address
schemaHash string Schema hash
commitment string Credential commitment
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await issueCredential("dili1holder", "0xschema", "0xabc");

revokeCredential(commitment, options?)

Revoke a previously issued credential.

function revokeCredential(
  commitment: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
commitment string Credential commitment to revoke
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await revokeCredential("0xabc");

verifyCredentialProof(commitment, disclosedFields, proof, options?)

Verify a selective-disclosure credential proof on-chain.

function verifyCredentialProof(
  commitment: string,
  disclosedFields: string[],
  proof: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
commitment string Credential commitment
disclosedFields string[] Fields to disclose
proof string The ZK proof
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await verifyCredentialProof("0xcred", ["age"], "0xproof");

Multisig

createMultisig(signers, threshold, options?)

Create a new multisig wallet.

function createMultisig(
  signers: string[],
  threshold: number,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
signers string[] Array of signer addresses
threshold number Number of required approvals
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await createMultisig(["dili1a", "dili1b", "dili1c"], 2);

proposeTx(wallet, transaction, options?)

Propose a new transaction on a multisig wallet.

function proposeTx(
  wallet: string,
  transaction: Record<string, unknown>,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
transaction Record<string, unknown> The transaction to propose
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await proposeTx("dili1multisig", { to: "dili1dest", value: 100 });

approveMultisigTx(wallet, txId, options?)

Approve a pending multisig transaction.

function approveMultisigTx(
  wallet: string,
  txId: number,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
txId number Transaction ID to approve
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await approveMultisigTx("dili1multisig", 0);

executeMultisigTx(wallet, txId, options?)

Execute a multisig transaction that has met the approval threshold.

function executeMultisigTx(
  wallet: string,
  txId: number,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
txId number Transaction ID to execute
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await executeMultisigTx("dili1multisig", 0);

revokeMultisigApproval(wallet, txId, options?)

Revoke a previously given approval on a multisig transaction.

function revokeMultisigApproval(
  wallet: string,
  txId: number,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
txId number Transaction ID
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await revokeMultisigApproval("dili1multisig", 0);

addMultisigSigner(wallet, signer, options?)

Add a new signer to a multisig wallet.

function addMultisigSigner(
  wallet: string,
  signer: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
signer string Address of the new signer
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await addMultisigSigner("dili1multisig", "dili1newsigner");

removeMultisigSigner(wallet, signer, options?)

Remove a signer from a multisig wallet.

function removeMultisigSigner(
  wallet: string,
  signer: string,
  options?: TxOptions,
): Promise<TransactionResult>
Parameter Type Description
wallet string Multisig wallet address
signer string Address of the signer to remove
options TxOptions (optional) Transaction options

Returns: TransactionResult with accepted and txHash.

const tx = await removeMultisigSigner("dili1multisig", "dili1oldsigner");