Prerequisites
- Node 22 or later.
@cloak.dev/sdk0.2.20 and@solana/kit.- A mainnet RPC with generous limits.
- A database for SDK state, and a secret store for keys.
Choose the account model
Business mode is the usual choice for payouts and treasury. Generate a key per account once, keep it
in your secret store, and never log it.
Keep state in your database, encrypted
createCloak keeps payment links, open cross-chain orders, payout records and ref receipts in
storage. The default on a server is memory, which is lost on exit. Wrap your own key-value store
with encryptedStorage, which encrypts every value with AES-256-GCM, bound to the key and the
network:
cloak.ts
Cloak object per account per process. Its money-moving calls are serialized, so two calls
never pick the same notes.
Make every payment idempotent with ref
Pass a ref on every shield, send and withdraw. A second call with the same ref returns the
first receipt with repeated: true and moves nothing:
ref is 1 to 128 printable characters. Use your own stable identifier (invoice, payout row,
withdrawal request).
Resume what a crash left open
A shield from another chain or a send to one can stop halfway if the process exits.createCloak
resumes open work shortly after start, and every minute while something is open. Subscribe to see it:
storage outlived the crash, which is why the store above is your database.
Proving on a server
- Each spend generates a Groth16 proof in-process, in worker threads. No prover service is needed.
- The first proof in a process downloads about 23 MB of circuit files and checks their hashes. Warm
them at boot with
verifyAllCircuits(getCircuitsPath()). - Proving is CPU and memory heavy. Size workers for concurrent proofs, or queue spends per process. For many payouts in one go, see Batch signing.
Exposing Cloak to other languages
There is no Rust or Python SDK. A backend in another language runs a small Node service that holds the account keys and exposes your own API (pay, balance, quote) to the rest of your system. Keep that service on a private network: whoever can call it can spend.Security checklist
- Account keys and
CLOAK_STORAGE_SECRETin a secret manager, never in source or logs. - One
refper business operation, persisted before the call. - Alert on
ref.unsettled,payout.screening_refusedand any*.failedthat is not retryable. - Rate-limit and authenticate the endpoints that trigger spends.
- Back up the storage table: it holds receipts and open orders.
Related
- Backend orchestration example: a complete payout worker.
- Payroll: many recipients, one run.
- createCloak