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:
Provider Detection¶
getDilithiaProvider()¶
Returns the raw DilithiaProvider object for advanced use cases.
Returns: The provider object attached to window.dilithia.
Throws: Error if the wallet extension is not installed.
hasDilithiaProvider()¶
Check whether the wallet extension is installed and injected.
Returns: true if window.dilithia exists and has isDilithia === true.
Connection¶
connect(permissions?)¶
Connect to the wallet. Prompts the user for approval.
| 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.
| Parameter | Type | Description |
|---|---|---|
permissions |
string[] |
Permissions to request |
Returns: Array of granted permission strings.
permissions()¶
Get the current set of granted permissions.
Returns: Array of permission strings.
disconnect()¶
Disconnect from the wallet and clear the active session.
switchChain(chainId)¶
Switch the wallet to a different chain.
| Parameter | Type | Description |
|---|---|---|
chainId |
string |
The chain ID to switch to |
Returns: Updated DilithiaConnectResult reflecting the new chain.
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).
Returns: Hex-encoded public key string.
accounts()¶
List all connected accounts.
Returns: Array of account address strings.
Signing¶
signMessage(message)¶
Sign a text message with the active account's private key (ML-DSA-65).
| Parameter | Type | Description |
|---|---|---|
message |
string |
The message to sign |
Returns: DilithiaSignedMessage with algorithm, address, public key, original message, and signature.
buildOwnershipProof(challenge)¶
Build a proof of wallet ownership for authentication flows.
| 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.
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", ...).
| 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.
With gas sponsorship:
Events¶
on(eventName, handler)¶
Subscribe to wallet events. Returns an unsubscribe function.
| 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.
| Parameter | Type | Description |
|---|---|---|
amount |
number |
Amount to deposit |
options |
TxOptions (optional) |
Transaction options |
Returns: ShieldedDepositResult with commitment and txHash.
With gas sponsorship:
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:
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.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to register |
options |
TxOptions (optional) |
Transaction options |
Returns: TransactionResult with accepted and txHash.
renewName(name, options?)¶
Renew an existing name registration.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to renew |
options |
TxOptions (optional) |
Transaction options |
Returns: TransactionResult with accepted and txHash.
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.
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.
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.
releaseName(name, options?)¶
Release a name, giving up ownership.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to release |
options |
TxOptions (optional) |
Transaction options |
Returns: TransactionResult with accepted and txHash.
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.
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.
revokeCredential(commitment, options?)¶
Revoke a previously issued credential.
| Parameter | Type | Description |
|---|---|---|
commitment |
string |
Credential commitment to revoke |
options |
TxOptions (optional) |
Transaction options |
Returns: TransactionResult with accepted and txHash.
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.
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.
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.
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.
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.
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.
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.
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.