createCloak is the SDK’s front door. It opens the user’s account from one wallet signature and
returns an object with one call per action. The SDK finds and picks the notes, merges them when it
needs to, adds the fee on a withdrawal, keeps what it must remember in storage, and finishes
anything an earlier run left open. It is built on the free functions,
which stay exported for full control.
Everything on this page is exported by @cloak.dev/sdk 0.2.20.
Opening the account
The account is the one the Cloak mobile app shows for the same wallet: the SDK asks the wallet to sign one fixed message and derives the account’s keys from the signature. The first time a wallet is seen instorage it signs twice, so the SDK can check that it signs the same way each time. The signature rebuilds
everything, so the same wallet opens the same account on any device.
Once open,
cloak.address is the cloak_ address to share to get paid privately,
cloak.accountId a public id that stays the same across devices and wallets, and cloak.wallets
the wallets the object can use ({ name, chain, address, networks }). cloak.connect(wallet) adds
one later; cloak.disconnect(wallet, { unlink: true }) drops one and forgets its link.
The wallets it takes
wallet is whatever your wallet library hands you; the SDK recognizes it (recognizeWallet):
useWallet()from@solana/wallet-adapter-react, or a wallet-adapter adapter;- a Wallet Standard wallet (Phantom, Solflare, Backpack, Slush, Suiet);
window.ethereum, or an EIP-6963 provider fromdiscoverEvmWallets();- a Privy wallet;
- a
@solana/kitsigner or a web3.jsKeypair, a viemWalletClientor an ethersSigner(keys a server holds); - a Sui key pair;
- or
{ chain, address, signMessage, signTransaction, sendTransaction }.
Options
There is no endpoint option: the package talks to the one Cloak endpoint it was built with.
Tokens and destinations
The private balance holds USDC, USDT, SOL and BRS, each in its own pool. Every call names its token, and a call whose route cannot carry that token is refused before anything moves.to takes:
For a shield,
from is "solana", "base", "polygon", "sui", or a connected wallet; with an
EVM wallet, chain picks the network. Which tokens each network takes, the minimums and the route
each one uses are on Other networks.
The calls
The money calls take
onProgress: (step) => … for status text, and shield, send and withdraw
also take signal (an AbortSignal). Payment links use cloak.ag’s format, so the website claims a
link the SDK made and the other way round; the URL’s secret is the part after #, so treat the
whole URL like cash.
Quote before you move
arrives.atLeast is the least that arrives, the route’s signed floor where the route signs one.
fee is everything between what leaves the private balance and what arrives, in the arriving token.
networkFee appears when a fee is paid in another chain’s own coin (BRS through LayerZero).
Receipts
A send to another network resolves once it is delivered. Pass
wait: false to resolve as soon as it
is sent (status: "on its way"), and call receipt.track() later.
Business mode
A server that holds its customers’ keys opens each account withaccount, keeps the records in its
own database, encrypted, and names every money call with a ref, so a retry never pays twice:
encryptedStorage(db, secret) wraps any store that has get and set in AES-256-GCM, bound to the
key and the network. A ref works on shield, send and withdraw; on createPaymentLink it
derives the link’s secret, so the same ref always rebuilds the same link.
To keep a copy of the notes themselves, save them encrypted and import them on any machine that
opens the same account:
restoreNotes(saved, secret) reads the same string without opening an account.
When something goes wrong
Every call throws aCloakCallError (isCloakCallError(e)), which carries:
code: stable and dotted (payout.refused,wallet.rejected). Match on it, never on the message.retryable: whether the same call can succeed if it is made again.moneyAtandnext, when money is in flight: where it is now, and what happens to it.
Every code, with when it is thrown and whether it is retryable, is in Error codes.
Finishing what stopped
A shield from another network, or a send to one, can stop halfway: a closed tab, a dropped connection. On the next start, and again while an order is open, the SDK finishes it, andcloak.resume() runs a pass on demand. Each item it finishes arrives as a finished event:
storage, so a server needs one that outlives the process.
What createCloak does not do
- Private swaps. Use
swapWithChange(Code examples). - Choosing notes, building proofs or submitting yourself. Use the free functions it is built on.