Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt

Use this file to discover all available pages before exploring further.

This page tracks the current public exports of @cloak.dev/sdk.

Main client: CloakSDK

Constructor

new CloakSDK({
  keypairBytes?: Uint8Array;
  wallet?: WalletAdapter;
  network?: "mainnet";
  cloakKeys?: CloakKeyPair;
  storage?: StorageAdapter;
  programId?: PublicKey;
  relayUrl?: string;
  debug?: boolean;
})
At least one signer path is required: keypairBytes or wallet.

Core methods

sdk.deposit(connection, amountOrNote, options?) => Promise<DepositResult>
sdk.withdraw(connection, note, recipient, options?) => Promise<TransferResult>
sdk.send(connection, note, recipients, options?) => Promise<TransferResult>
sdk.swap(connection, note, recipient, options) => Promise<SwapResult>
Also available:
sdk.privateTransfer(connection, note, recipients, options?)
sdk.generateNote(amountLamports, useWalletKeys?)
sdk.getMerkleProof(connection, leafIndex)
sdk.getCurrentRoot(connection)
sdk.getTransactionStatus(requestId)
Storage/key helpers on the class:
sdk.loadNotes();
sdk.saveNote(note);
sdk.findNote(commitment);
sdk.importWalletKeys(keysJson);
sdk.exportWalletKeys();
sdk.getConfig();

Note API types

type DepositResult = {
  note: CloakNote;
  signature: string;
  leafIndex: number;
  root: string;
};

type TransferResult = {
  signature: string;
  outputs: Array<{ recipient: string; amount: number }>;
  nullifier: string;
  root: string;
};

UTXO API

Common UTXO transaction exports:
transact(params, options)
transfer(inputUtxos, recipientPubkey, amount, options)
partialWithdraw(inputUtxos, recipient, withdrawAmount, options)
fullWithdraw(inputUtxos, recipient, options)
swapUtxo(params, options)
swapWithChange(inputUtxos, swapAmount, outputMint, recipientAta, minOutputAmount, options, recipientWallet?)
UTXO primitives:
generateUtxoKeypair()
createUtxo(amount, keypair, mint?)
createZeroUtxo(mint?)
computeUtxoCommitment(utxo)
computeUtxoNullifier(utxo)
Full flow guide: UTXO Transactions

Relay and proof utilities

new RelayService(baseUrl)
relay.submitWithdraw(...)
relay.submitSwap(...)
relay.getStatus(requestId)
relay.resumeWithdraw(requestId)

computeProofFromChain(connection, merkleTreePDA, leafIndex)
readMerkleTreeState(connection, merkleTreePDA)
buildMerkleTreeFromRelay(relayUrl)
Notes:
  • UTXO transact/swap flows submit 256-byte proofs and 264-byte public inputs.
  • RelayService is the low-level submission client; the high-level CloakSDK class wraps it for you.

Fee constants

FIXED_FEE_LAMPORTS      // 5_000_000
VARIABLE_FEE_NUMERATOR  // 3
VARIABLE_FEE_DENOMINATOR// 1000
MIN_DEPOSIT_LAMPORTS    // 10_000_000
VARIABLE_FEE_RATE       // 0.003
Q64_64_ONE              // 2^64

calculateFee(amount: number)
calculateFeeBigint(amount: bigint)
calculateSolFeeLamports(gross: bigint)
calculateSolNetAmountLamports(gross: bigint)

tokenPerSolBaseUnitsToQ64(price: bigint)
q64ToTokenPerSolBaseUnits(priceQ64: bigint)
calculateSplFixedFeeTokenAmount(priceQ64: bigint)
calculateSplFeeTokenAmount(grossTokenBaseUnits: bigint, priceQ64: bigint)
calculateSplNetAmountToken(grossTokenBaseUnits: bigint, priceQ64: bigint)

isWithdrawAmountSufficient(amount: bigint)
isSplWithdrawAmountSufficient(grossTokenBaseUnits: bigint, priceQ64: bigint)
getDistributableAmount(amount: number)

Error utilities

CloakError;
ShieldPoolErrors;
RootNotFoundError;
isRootNotFoundError(error);
parseError(error);
parseTransactionError(error);
Detailed usage: Error Handling

Versioned exports

VERSION; // "1.0.0"
CLOAK_PROGRAM_ID; // mainnet program constant

Protocol and service docs