> ## 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.

# Configuration options

> Every option of createCloak, the transaction options of the low-level API, and the runtime values behind them

## `createCloak(options)`

```ts theme={null}
import { createCloak, type CreateCloakOptions } from "@cloak.dev/sdk";

declare const wallet: unknown; // what your wallet library hands you

const options: CreateCloakOptions = { wallet, rpc: process.env.SOLANA_RPC_URL };
const cloak = await createCloak(options);
```

Pass exactly one way to open the account: `wallet`, `wallets`, `cloakKey` or `account`.

| Option | Type | Default | Description |
| - | - | - | - |
| `wallet` | `unknown` | | The user's wallet, as any supported wallet library hands it out. See [Wallet integrations](https://docs.cloak.ag/wallets/overview.md) |
| `wallets` | `readonly unknown[]` | | Several wallets. The first that can sign opens the account; the others are linked to it |
| `cloakKey` | `string` | | A cloak.ag account's 24-word Cloak Key, or a 12 to 24 word Cloak mobile wallet phrase |
| `account` | `Uint8Array \| string` | | Business mode: an account key you hold, 32 bytes or 64 hex characters |
| `rpc` | `string \| CloakRpc` | public mainnet endpoint (rate-limited) | Your Solana RPC URL, or a `CloakRpc` from `createCloakRpc` |
| `storage` | `CloakStorage` | `localStorage` in a browser, else memory | Where links, open orders, payouts and `ref` receipts are kept. See below |
| `allowStoredAccount` | `boolean` | `false` | For a wallet that cannot sign repeatably: create a stored account key and return its backup words once |
| `resume` | `boolean` | `true` | Finish open cross-chain deposits and sends at start and while one is open |
| `secureExposedNotes` | `boolean` | `true` | Move notes an older client left readable by others into the account before they are spent |
| `affiliateCode` | `string` | | An approved partner code, attached to fee-bearing requests. See [Earn with the SDK](https://docs.cloak.ag/affiliates/sdk-integration.md) |
| `onWarning` | `(message: string) => void` | | Non-fatal events: a wallet that could not be linked, a dropped partner code |
| `web3` | `{ VersionedTransaction }` | | web3.js's class, for a legacy Solana adapter (Ledger) in a bundled app |

There is no endpoint option: the package talks to the one Cloak endpoint it was built with.

### Storage

| Export | Persists | Protects secrets | Use for |
| - | - | - | - |
| `webStorage(store?, prefix?)` | Browser `localStorage` | No | The browser default |
| `memoryStorage()` | Nothing; lost on exit | Yes | Tests, scripts |
| `encryptedStorage(store, secret)` | Your store, AES-256-GCM encrypted | Yes | Servers, and any stored account key |

A `CloakStorage` is any object with `get`, `set` and `delete` returning promises. A stored account key
(`allowStoredAccount`) is only written to a storage that protects secrets.

## Request options on every money call

`shield`, `send` and `withdraw` take, besides `to`/`from`, `token` and `amount`:

| Option | Type | Description |
| - | - | - |
| `ref` | `string` | 1 to 128 printable characters. The call happens once; a repeat returns the first receipt with `repeated: true` |
| `onProgress` | `(step: string) => void` | Human-readable status text. See [Events and callbacks](https://docs.cloak.ag/reference/events-and-callbacks.md) |
| `signal` | `AbortSignal` | Cancels the call. `shield`, `send` and `withdraw` take it |
| `chain` | `string` | `"base"` or `"polygon"` for an EVM address or wallet |
| `wait` | `boolean` | Sends to other chains: resolve on delivery (default) or as soon as sent |

Amounts are decimal strings in token units (`"1.5"`). Zero, negatives and more decimals than the
token has are refused before anything moves.

## Low-level `TransactOptions`

The low-level functions take one options object. The fields most integrations set:

| Option | Type | Required | Description |
| - | - | - | - |
| `connection` | `CloakRpc` | yes | From `createCloakRpc(rpcUrl)` |
| `programId` | `Address` | yes | `CLOAK_PROGRAM_ID` |
| `relayUrl` | `string` | yes in practice | `CLOAK_PRODUCTION_RELAY_URL`. No default; other values throw |
| `ownerUtxoKeypair` | `UtxoKeypair` | yes for spends | The seed-derived keypair that owns the notes |
| `chainNoteViewingKeyNk` | `Uint8Array \| string` | recommended | The viewing key `nk`; makes notes recoverable and history scannable |
| `depositorKeypair` | `KeyPairSigner` | server | Signs deposits and request authentication silently |
| `signer` | `TransactionSigner` | browser deposits | A wallet signer, for example from `signerFromWalletAdapter` |
| `signMessage` | `(m: Uint8Array) => Promise<Uint8Array>` | browser spends | Signs request authentication |
| `walletPublicKey` | `Address` | browser spends | The end user's wallet, the authenticated sender |
| `depositorPublicKey` | `Address` | browser deposits | Same key as `signer.address` |
| `chainNoteSalt` | `bigint` | recoverable deposits | From `createRecoverableDepositUtxo` |
| `recipientViewingPublicKey` | `Uint8Array \| string` | private sends | Seals the recipient's note to them so they can find it |
| `expectedMint` | `Address` | recommended | Refuses input notes from a different pool |
| `onProgress` | `(status: string) => void` | | Status text |
| `onProofProgress` | `(percent: number) => void` | | Emits 10, 30 and 100 |
| `affiliateCode` | `string` | | Partner code, `^[a-z0-9_]{3,24}$` |

Advanced fields:

| Option | Default | Description |
| - | - | - |
| `cachedMerkleTree` | | The `merkleTree` from a previous result, to skip a rebuild |
| `returnMerkleTree` | `true` | Set `false` on deposits that need no tree afterwards |
| `maxRootRetries` | `40` | Stale-root regenerations before giving up |
| `retryDelayMs` | `500` | Base delay between retries, backing off to 5 s |
| `maxWalletApprovals` | `5` | Swaps only: wallet prompts one swap may raise |
| `relaySupplementalAlt` | `false` | SPL deposits: avoid the second signature for a throwaway lookup table |
| `transactionVersion` | `0` | `1` builds a Transaction V1 (4,096 bytes, no lookup tables) for deposits |
| `externalFeePayer` | | Sponsors deposit fees. See [Custom signers](https://docs.cloak.ag/wallets/custom-signers.md#sponsored-deposits) |
| `altAddresses`, `addressLookupTableAccounts` | | Extra or replacement lookup tables for deposits |
| `enforceViewingKeyRegistration` | `true` | Leave on. Turning it off with an empty `relayUrl` submits under the user's own wallet, publicly linking it |
| `swapSlippageBps` | `500` | Swaps: route slippage |
| `swapStatusMaxAttempts`, `swapStatusDelayMs` | `60`, `2000` | Swaps: how long to wait for execution |

`TransactOptions` has no `rpc`, `wallet`, `signTransaction` or `feePayer` field. A wallet adapter's
`signTransaction` reaches the SDK through `signerFromWalletAdapter`.

## Runtime values

| Value | Setting |
| - | - |
| Network | Solana mainnet only |
| Program ID | `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW` (`CLOAK_PROGRAM_ID`) |
| Cloak endpoint | `https://api.cloak.ag` (`CLOAK_PRODUCTION_RELAY_URL`), fixed at build time |
| Circuits | `https://storage.googleapis.com/cloak-circuits/circuits/0.2.0`, hash-pinned |
| Merkle tree height | 32, with 100 recent roots accepted |
| Circuit arity | 2 inputs, 2 outputs |
| Proof | 256-byte Groth16, with 264 bytes of public inputs |
| Request authentication window | 300 s (`REQUEST_AUTH_MAX_AGE_SECONDS`), 30 s future clock skew |
| Node | 22 or later |

### Environment variables the SDK reads

The SDK reads no environment variable for the endpoint, the RPC or signing. A few operational knobs
exist: `CLOAK_RELAY_REQUEST_TIMEOUT_MS` (default 45 000), `CLOAK_RELAY_NETWORK_RETRIES` (default 6),
`CLOAK_SETTLEMENT_CONFIRM_TIMEOUT_MS` (default 30 000), and `CLOAK_DEBUG` for verbose logs. Your
own variables (`SOLANA_RPC_URL` and so on) are read by your code and passed in.

## Related

* [API reference](https://docs.cloak.ag/reference/api.md)
* [Network and RPC](https://docs.cloak.ag/resources/network-and-rpc.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.