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

# Private transfers

> Pay another private balance without the money ever leaving the pool: one call with createCloak, and the mechanism underneath

A **private transfer** moves value from one private balance to another without it ever leaving the
pool. The amount, the sender and the recipient stay hidden. The recipient ends up owning a shielded
note in their own private balance, and there is no protocol fee.

## With `createCloak`: send to a `cloak_` address

The recipient shares their `cloak_` address (`cloak.address`). Send to it:

```ts theme={null}
const receipt = await cloak.send({ to: "cloak_…", token: "USDC", amount: "12.5", ref: "invoice-1042" });
console.log(receipt.status, receipt.fee, receipt.txs.solana); // "sent", "0", "<signature>"
```

The SDK picks up to two notes (merging first if it needs to), creates
the recipient's note and your change, seals the recipient's note secrets to the delivery key inside
their `cloak_` address, and submits. The sender's wallet is not prompted and needs no SOL. The
recipient finds the note with their own keys the next time their client reads its balance
(`cloak.balance()`); nothing has to be handed over off chain.

| Common error | Meaning |
| - | - |
| `balance.insufficient` | The private balance cannot cover the amount |
| `send.failed` | The send did not complete; retryable, and `moneyAt` says where the money is |
| `route.unknown` | `to` is not an address the SDK can send to |

The rest of this page explains the mechanism with the low-level `transfer`, which is what `send` is
built on. Read on if you manage notes yourself.

> [!NOTE]
>
> **Low-level signing.** With `transfer`, the request carries an **authenticated sender** signed by the
> end user's own wallet: `depositorKeypair` on a server, `signMessage` plus `walletPublicKey` in a
> browser, or `signer` for a hardware wallet. See [Request authentication](https://docs.cloak.ag/sdk/request-authentication.md).
> Every spend also needs the user's `ownerUtxoKeypair` and `nk`, derived from one seed: see
> [where the user's keys live](https://docs.cloak.ag/wallets/wallet-adapter.md#where-the-users-keys-live).

## Walkthrough: Alice pays Bob 0.06 SOL, privately

Alice and Bob each have two separate identities, and the rest of this page depends on keeping them apart:

| Identity | Looks like | What it's for |
| - | - | - |
| **Solana wallet** | `3uNc…` (base58) | holds public SOL; signs transactions |
| **Cloak pubkey** | `0x1f03…` | owns shielded **notes**; what a transfer is addressed to |
| **Cloak viewing public key** | 32-byte X25519 | lets a sender address a discovery envelope to you |

The Cloak pubkey (a note's `owner_pubkey`) is derived from a private spending key. That key has nothing to do with your Solana wallet: it is a plain number used inside the pool's cryptographic math.

![Shielded transfer: you deposit into the pool, then send. The lamports stay in the pool and only note ownership moves to the recipient; you then hand the recipient the note's secrets off-chain, and they only touch the chain if they later withdraw](https://mintcdn.com/cloak/-H4qp3ajIx2GThhJ/images/private-send-flow.svg?fit=max\&auto=format\&n=-H4qp3ajIx2GThhJ\&q=85\&s=99d68e58c6c079e6d74b63a1bff84d29)

Say Alice already holds a **0.10 SOL note** in the pool (her private balance). The flow goes like this:

**1 · Bob shares his Cloak pubkey** with Alice, over any off-chain channel (a DM, a QR). The pubkey is safe to share and can't be used to spend or trace him. At the same time he shares his Cloak viewing public key (`deriveViewingKeyFromNk(bobNk).publicKey`), which lets Alice address a discovery envelope to him. That is also a public key, so sharing it grants no ability to spend.

**2 · Alice calls `transfer`.** She spends her 0.10 note and creates two new notes: 0.06 owned by Bob's Cloak pubkey, and 0.04 change owned by herself. Because `externalAmount === 0`, the pool's lamports don't move at all. Only ownership changes:

| | Alice (shielded) | Bob (shielded) | Bob's wallet |
| - | - | - | - |
| Alice holds a note | 0.10 | 0.00 | 0.00 |
| **after `transfer`** | **0.04** | **0.06** | 0.00 |
| after Bob withdraws | 0.04 | 0.00 | **\~0.0548** |

Value moved between two private balances (Alice `0.10 → 0.04`, Bob `0.00 → 0.06`) while the pool total and every public wallet stayed flat. (Bob's `~0.0548` is his 0.06 note minus the [exit fee](https://docs.cloak.ag/guide/fees.md), charged only when value leaves the pool at withdraw.)

**3 · Bob finds it himself, if Alice opted in.** Because Alice passed Bob's viewing public key as `recipientViewingPublicKey`, the send published a sealed envelope on chain carrying the note's amount and blinding, addressed to Bob. Bob calls `scanRecipientDeliveryNotes` holding nothing but his own keys and the note comes back. If Alice had not passed that key, Bob would find nothing, because the blinding would never have reached the chain, and there'd be no trail from the note to him. ([The full reason.](#how-the-recipient-gets-the-secrets))

**4 · Fallback, only when Alice skipped the envelope: Alice hands Bob the note's secrets** off-chain. These are the amount and the blinding (a secret random value Alice picked when building the note), which together amount to the note object. With them, Bob attaches his own key and can spend the note.

**5 · Bob withdraws** to any wallet he likes. His 0.06 private balance becomes \~0.0548 public SOL (minus the exit fee). Only this last step moves SOL out of the pool.

To sum up: ownership moves on-chain in step 2, and delivery travels on chain in the sealed envelope. Skip the envelope and delivery falls back to the off-chain handoff in step 4; a transfer with neither is a note Bob owns but can't use.

## How the recipient gets the secrets

To spend a note you need its full secrets, `(amount, owner_pubkey, blinding, mint)`, because spending means recomputing the commitment and proving ownership in zero knowledge. The recipient supplies `owner_pubkey` (it's their key), but the `blinding` is fresh randomness chosen by the sender. It is not part of the commitment the chain stores, and it reaches the recipient on chain only through the sealed delivery envelope described below.

So receiving takes one up-front exchange. Before the send, the recipient shares two things: their Cloak pubkey (the note's `owner_pubkey`) and their public viewing key, `deriveViewingKeyFromNk(nk).publicKey`. The sender passes the second as `recipientViewingPublicKey` in the `transfer(...)` options. The SDK then seals `{amount, blinding}` of the recipient's note into a 112-byte envelope (X25519 + XSalsa20-Poly1305) and it is published on chain. The recipient finds and opens it with their `nk` alone, via `scanRecipientDeliveryNotes({ connection, programId, viewingKeyNk, ownerUtxoPublicKey })`, which trial-opens every carrier and keeps the ones whose recomputed Poseidon commitment matches. No second hand-off is needed.

When the sender **omits** `recipientViewingPublicKey`, the blinding never reaches the chain and the note secrets have to be handed over out of band instead:

1. **Before, recipient → sender:** the recipient's Cloak pubkey, so the sender can lock the note to it.
2. **After, sender → recipient:** the note secrets, so the recipient can spend it.

> [!WARNING]
>
> **Recipient discovery is opt-in.** Bob derives a viewing public key from his own `nk` (`deriveViewingKeyFromNk(bobNk).publicKey`, a 32-byte X25519 key) and shares that public key along with his Cloak pubkey. Alice passes it as `recipientViewingPublicKey` on the send, and Bob then finds the note himself with `scanRecipientDeliveryNotes({ connection, programId, viewingKeyNk: bobNk, ownerUtxoPublicKey: bob.publicKey })`, holding nothing but his own keys. Omit `recipientViewingPublicKey` and the note stays undiscoverable on chain, so the secrets still have to be handed over out of band.
>
> `nk` itself is derived from the recipient's spending key (`getNkFromUtxoPrivateKey`) and opens every envelope addressed to them, so it must never leave the recipient. The recipient derives; the recipient shares only the public half.

Scope and limits to know before you rely on it:

* The envelope is attached only on a shield-to-shield send (`externalAmount === 0` with no external `recipient`). Deposits and withdrawals carry none.
* It always describes output 0, and it is skipped when output 0 belongs to the spender (change, or a send-to-self). `transfer()` puts the recipient's note at output 0, so the documented API satisfies this for you.
* The carrier's declared commitment is not covered by the envelope's Poly1305 tag. Pass `ownerUtxoPublicKey` to `scanRecipientDeliveryNotes` and trust the `commitmentVerified` flag on the returned note rather than the memo.

### The on-chain "chain note" is not a delivery channel

Every transfer posts a small encrypted chain note. It is easy to mistake for delivery, but it isn't one. It's an AES-256-GCM envelope sealed under a key derived from the sender's own viewing key plus the output commitment, so opening it takes both, and the recipient has neither. Its contents are `{ timestamp, noteSalt, outAmount0, outPubkey0, isSendToSelfKey0 }`, which does include the recipient note's amount and Cloak pubkey, but not the `blinding`. Even if it did, the envelope isn't addressed to the recipient in the first place. It's a self-scan and compliance record for the party who wrote it, not a channel that delivers a spendable note to anyone else. (See [viewing keys & compliance](https://docs.cloak.ag/concepts/viewing-keys-compliance.md).)

The recipient-addressed delivery envelope (CLKD1) described above is the separate artifact that does deliver. Don't confuse the two: the chain note is sender-keyed and compliance-facing; the delivery envelope is recipient-keyed and is the actual delivery channel.

## Who can spend the note, and the limit

Ownership is cryptographic. That keeps the note safe, and it also means a note can get stuck.

**Only the owner's key can spend it, not even the sender's.** Spending requires proving, in zero knowledge, that you hold the private key behind the note's `owner_pubkey`. Alice *built* Bob's note and knows its amount and blinding, yet she still cannot spend it: she doesn't have Bob's private key, and the secrets alone aren't enough. Knowing a note's data is not the same as being able to spend it; the ownership check is a separate cryptographic gate. An attacker who learns everything except the private key gets nowhere.

**No clawback.** The flip side of that safety is that a raw shielded transfer has no refund path. If the sender never hands over the secrets, the note is stranded: the recipient can't spend it (no secrets) and the sender can't either (no key). This is why [payment links](https://docs.cloak.ag/guide/payment-links.md) use an ephemeral key the sender controls: an unclaimed link stays reclaimable, where a raw send-to-a-Cloak-pubkey does not.

## Relationship to payment links

A shielded transfer and a [payment link](https://docs.cloak.ag/guide/payment-links.md) are the same bearer mechanic with different key ownership:

* **Shielded transfer:** the note is locked to the recipient's own Cloak key. The recipient must exist and share their Cloak pubkey and viewing public key up front: one off-chain exchange, after which the sealed envelope carries the secrets on chain.
* **Payment link:** the sender generates a throwaway key, funds a note to it, and packages the whole claim into a single link handed off-chain. The recipient needs no Cloak identity and gives nothing up front. Whoever holds the link claims it, so there is one off-chain handoff.

Payment links stay the productized version of the same primitive, and they still need nothing from the recipient up front: no Cloak identity and no viewing key. That's why the app ships them rather than a raw "send to a shielded address" button.

## Under the hood

**Value lives as notes.** A note is a set of secrets `(amount, owner_pubkey, blinding, mint)`; only its commitment (a Poseidon hash over those fields) goes on-chain, as a leaf in the pool's Merkle tree. The preimage is secret, so the chain sees an opaque hash, not "5 SOL owned by X." Fresh `blinding` per note means equal amounts don't produce equal commitments.

**Ownership is a key, not an account.** The "Cloak pubkey" is `owner_pubkey = Poseidon([spending_privkey], KEYPAIR_DOMAIN_TAG)`. To spend, you prove in zero knowledge that you know the spending key behind the pubkey baked into the commitment.

**Nullifiers stop double-spends.** Spending a note publishes its nullifier (derived from the note + your spending key). The program records every nullifier and rejects repeats. A nullifier is also unlinkable to its commitment, so nobody can tell which leaf it spent.

**One instruction does everything.** Deposit, transfer, and withdraw are all the same `Transact` instruction: a Groth16 proof plus public inputs, 2-in / 2-out (pad an unused input with a zero note; all-zero outputs are dropped before the tree append). The proof establishes that the inputs are in the tree, you own them, the nullifiers are correct, the outputs are well-formed, and conservation holds:

```
sum(inputs) = sum(outputs) + public_amount
```

`public_amount` decides what kind of flow a transaction is. It's the circuit's name for the same knob the SDK exposes as `externalAmount` (the amount crossing the pool's boundary):

| `public_amount` | Flow | Lamports |
| - | - | - |
| `> 0` | deposit / shield | flow **into** the pool |
| `< 0` | withdraw / unshield | flow **out** to a wallet |
| `= 0` | **shielded transfer** | **nothing moves** |

So Alice's 0.06 transfer out of her 0.10 note is:

```
inputs:  [ Alice's 0.10 note ]                 → nullified
outputs: [ Bob's 0.06 note, Alice's 0.04 change ]
public_amount = 0        # 0.10 = 0.06 + 0.04 + 0  ✓  nothing leaves the pool
```

One commitment nullified, two appended, `public_amount = 0`. An observer sees two nullifiers, two opaque commitments, and a zero public amount, so the amount doesn't leak, and sender and recipient aren't linkable.

## Example: end to end

Bob shares two public values once, up front. After that the SDK delivers: the send seals the note's secrets to Bob's viewing key and publishes them on chain, and Bob's scan picks them up.

This version runs server-side, so every call authenticates with a local `depositorKeypair`. From a browser, everything else stays identical and that one option is replaced by `signMessage` + `walletPublicKey`: see [the wallet-adapter version](#browser-the-same-send-from-a-wallet-adapter) right below, or [Request authentication](https://docs.cloak.ag/sdk/request-authentication.md) for the whole contract.

It starts one step earlier than the walkthrough did, with the deposit that creates Alice's note, so `aliceNote` is a note the script actually funds rather than a name you are left to fill in yourself.

```ts theme={null}
import {
  CLOAK_PRODUCTION_RELAY_URL,
  CLOAK_PROGRAM_ID,
  NATIVE_SOL_MINT,
  createRecoverableDepositUtxo,
  createZeroUtxo,
  deriveSpendKey,
  deriveUtxoKeypairFromSpendKey,
  deriveViewingKeyFromNk,
  generateMasterSeed,
  getNkFromUtxoPrivateKey,
  scanRecipientDeliveryNotes,
  serializeUtxo,
  transact,
  transfer,
  fullWithdraw,
  createCloakRpc,
  signerFromSecretKey,
  type Utxo,
} from "@cloak.dev/sdk";
import { writeFileSync } from "node:fs";

const connection = createCloakRpc(process.env.SOLANA_RPC_URL!);
const programId = CLOAK_PROGRAM_ID;
const relayUrl = CLOAK_PRODUCTION_RELAY_URL;

// The SDK persists nothing for you. `serializeUtxo` is the 128-byte encoding of one
// note (amount, private key, blinding, mint, index) that `deserializeUtxo` reads back;
// nothing else can. A file is the simplest durable store there is. Treat these bytes
// as key material: whoever holds them can spend the note.
const keepNote = (name: string, utxo: Utxo) =>
  writeFileSync(`${name}.note`, serializeUtxo(utxo));

// Solana wallets. Each side's own wallet authenticates that side's request.
const aliceWallet = await signerFromSecretKey(
  Uint8Array.from(JSON.parse(process.env.ALICE_SECRET_KEY!)),
);
const bobWallet = await signerFromSecretKey(
  Uint8Array.from(JSON.parse(process.env.BOB_SECRET_KEY!)),
);

// Each person's Cloak keys come from one 32-byte seed. Here the seeds are generated on the
// spot; in a real app generate once and store it like a private key, because a lost seed
// loses the notes.
async function deriveKeys(seed: Uint8Array) {
  const { sk_spend } = deriveSpendKey(seed);
  const ownerUtxoKeypair = await deriveUtxoKeypairFromSpendKey(sk_spend);
  const nk = getNkFromUtxoPrivateKey(ownerUtxoKeypair.privateKey); // view-only: finds notes, never spends
  return { ownerUtxoKeypair, nk };
}

// ── Recipient (Bob), once ────────────────────────────────────────────
// Bob has a Cloak keypair and shares TWO public values with the sender.
const { ownerUtxoKeypair: bob, nk: bobNk } = await deriveKeys(generateMasterSeed().seed); // bobNk stays with Bob, never shared
const bobPubkey = bob.publicKey;                          // ← handoff #1a: Bob → Alice
const bobViewingPublicKey = deriveViewingKeyFromNk(bobNk).publicKey; // ← handoff #1b: Bob → Alice

// ── Sender (Alice): where `aliceNote` comes from ─────────────────────
// A note exists only because someone deposited. `alice` is Alice's Cloak keypair;
// `aliceWallet` is her Solana wallet, and it is the wallet that authenticates
// every request she makes. This deposit shields 0.10 SOL to her Cloak key.
const { ownerUtxoKeypair: alice, nk: aliceNk } = await deriveKeys(generateMasterSeed().seed); // aliceNk is Alice's OWN nk

// A recoverable deposit note: a scan holding aliceNk can rebuild it if the bytes are lost.
const { utxo: aliceDepositNote, noteSalt } = await createRecoverableDepositUtxo({
  amount: 100_000_000n,
  viewingKeyNk: aliceNk,
  ownerUtxoKeypair: alice,
  mintAddress: NATIVE_SOL_MINT,
});

const deposit = await transact(
  {
    inputUtxos: [await createZeroUtxo(NATIVE_SOL_MINT)],   // 2-in circuit: pad with a zero note
    outputUtxos: [aliceDepositNote],
    externalAmount: 100_000_000n,           // 0.10 SOL flowing INTO the pool
    depositor: aliceWallet.address,
  },
  {
    connection, programId, relayUrl,
    depositorKeypair: aliceWallet,
    walletPublicKey: aliceWallet.address,
    ownerUtxoKeypair: alice,
    chainNoteViewingKeyNk: aliceNk,
    chainNoteSalt: noteSalt,
  },
);
const [aliceNote] = deposit.outputUtxos;   // ← the 0.10 note, with its leaf index attached
keepNote(`alice-deposit-${deposit.signature}`, aliceNote);  // crash before this and only a scan finds it

// ── Sender (Alice) sends ─────────────────────────────────────────────
// Alice moves 0.06 SOL of that note to Bob. externalAmount is 0 this time, so
// nothing leaves the pool, only ownership. Her 0.04 change comes back on
// `outputUtxos`, and that is the only complete copy of it: see the note below.
const sent = await transfer(
  [aliceNote],              // input note(s) Alice owns
  bobPubkey,                // recipient's Cloak pubkey, not a Solana wallet
  60_000_000n,             // 0.06 SOL
  {
    connection, programId, relayUrl,
    depositorKeypair: aliceWallet,          // server signer; a browser passes signMessage instead
    walletPublicKey: aliceWallet.address, // the authenticated sender, either way
    ownerUtxoKeypair: alice,                // Alice's own keypair: owns her change note
    chainNoteViewingKeyNk: aliceNk,         // Alice's OWN nk
    recipientViewingPublicKey: bobViewingPublicKey,  // opt in to recipient discovery
    cachedMerkleTree: deposit.merkleTree,   // the deposit already built the tree; reuse it
  },
);

// Bank Alice's 0.04 change BEFORE anything reports success. `transfer` puts Bob's
// note at output 0 and Alice's change at output 1; a zero amount there means the
// input was consumed exactly and there is no change. The change note's blinding is
// derived from aliceNk, but the chain note records only Bob's output, so a later
// scan cannot learn the 0.04 amount by itself. Keep these bytes.
const aliceChange = sent.outputUtxos[1];
if (aliceChange && aliceChange.amount > 0n) {
  keepNote(`alice-change-${sent.signature}`, aliceChange);
}

// ── Recipient (Bob) discovers and claims ─────────────────────────────
// Bob scans with nothing but his own keys and finds the note Alice sent him.
const { notes } = await scanRecipientDeliveryNotes({
  connection,
  programId,
  viewingKeyNk: bobNk,
  ownerUtxoPublicKey: bob.publicKey,   // authenticates the carrier's declared commitment
});
const delivered = notes.find((n) => n.commitmentVerified && n.amount === 60_000_000n);
if (!delivered) throw new Error("no delivered note found");

const claimable = {
  amount: delivered.amount,
  blinding: delivered.blinding,
  keypair: bob,
  mintAddress: NATIVE_SOL_MINT,
};
await fullWithdraw([claimable], bobWallet.address, {   // ← funds land at bobWallet (any address)
  connection, programId, relayUrl,
  depositorKeypair: bobWallet,            // Bob's OWN wallet authenticates his withdrawal
  walletPublicKey: bobWallet.address,   // never a service key: this is the screened sender
  ownerUtxoKeypair: bob,
  chainNoteViewingKeyNk: bobNk,           // Bob's OWN nk
});
```

> [!NOTE]
>
> **Where `aliceNote` comes from in a real app.** The script above funds it in the same run, which is what makes it runnable end to end. A wallet cannot do that: the deposit happened yesterday, and the note has to come back out of storage. The SDK persists nothing for you: `transact` and `transfer` hand you `result.outputUtxos` once and then forget them. Write the outputs down before you report success. The deposit above is built with `createRecoverableDepositUtxo`, so a later cold scan holding `aliceNk` can rebuild it. Alice's change note has a blinding derived from `aliceNk` too, but it sits at output 1 and the chain note describes only output 0, so a scan cannot recover its amount on its own: the note is spendable again only if Alice knows the amount. Persist it. Both are covered in [where your notes live between sessions](https://docs.cloak.ag/wallets/wallet-adapter.md#where-your-notes-live-between-sessions).

> [!NOTE]
>
> Drop `recipientViewingPublicKey` and you are back on the bearer path: Alice must read the recipient note out of `sent.outputUtxos[0]` and hand Bob its amount and blinding off-chain herself, on top of banking her own change from `sent.outputUtxos[1]`. Without either the envelope or that hand-off, the note is orphaned: Bob owns a commitment he has no secrets for, and no scan will surface it.

### Browser: the same send from a wallet adapter

A wallet adapter has no secret key to give you, so there is no `depositorKeypair` to pass. You hand the SDK the wallet's `signMessage` plus the connected `walletPublicKey`, and the SDK builds and signs the request with them. The send itself is unchanged: same recipient Cloak pubkey, same `recipientViewingPublicKey` opt-in.

The input notes are the other difference, and it is a difference of plumbing rather than of protocol. There is no deposit a line above to take them from, so they come back out of [your own storage](https://docs.cloak.ag/wallets/wallet-adapter.md#where-your-notes-live-between-sessions): a `UtxoWallet` you loaded on mount, with `selectUtxos` picking the inputs for this amount.

```ts theme={null}
import {
  CLOAK_PRODUCTION_RELAY_URL,
  CLOAK_PROGRAM_ID,
  NATIVE_SOL_MINT,
  UtxoWallet,
  explainRelayAuthRejection,
  addressFromPublicKey,
  createCloakRpc,
  selectUtxos,
  transfer,
  type UtxoKeypair,
} from "@cloak.dev/sdk";
import { useWallet } from "@solana/wallet-adapter-react";

const connection = createCloakRpc(process.env.NEXT_PUBLIC_SOLANA_RPC_URL!);
const programId = CLOAK_PROGRAM_ID;
const relayUrl = CLOAK_PRODUCTION_RELAY_URL;
const NOTES_KEY = "myapp.cloak.notes";

// Inside a React component: `const { publicKey, signMessage } = useWallet();`
type WalletHandles = Pick<ReturnType<typeof useWallet>, "publicKey" | "signMessage">;

// `wallet` is the note set restored with UtxoWallet.deserialize on mount, and
// `alice` / `aliceNk` are the user's seed-derived keys. Neither comes from the wallet adapter.
async function sendToBob(
  { publicKey, signMessage }: WalletHandles,
  wallet: UtxoWallet,
  alice: UtxoKeypair,
  aliceNk: Uint8Array,
  bobPubkey: bigint,
  bobViewingPublicKey: Uint8Array,
) {
  // Not every adapter implements signMessage. Check before you offer the action.
  // (A hardware wallet without it passes `signer` instead: see Request authentication.)
  if (!publicKey || !signMessage) {
    throw new Error("Connect a wallet that supports message signing.");
  }

  const inputs = selectUtxos(wallet.getUnspentUtxos(NATIVE_SOL_MINT), 60_000_000n);
  if (!inputs) throw new Error("insufficient shielded balance");   // null, not a throw
  if (inputs.length > 2) throw new Error("consolidate first");     // transfer will not

  try {
    const result = await transfer(inputs, bobPubkey, 60_000_000n, {
      connection, programId, relayUrl,

      // ── replaces depositorKeypair: the user's own wallet signs the request ──
      // The adapter gives a web3.js PublicKey; Cloak options take a Kit Address.
      walletPublicKey: addressFromPublicKey(publicKey), // the request's authenticated sender
      signMessage,                  // returns the 64-byte ed25519 detached signature
      // ───────────────────────────────────────────────────────────────────────

      ownerUtxoKeypair: alice,
      chainNoteViewingKeyNk: aliceNk, // Alice's OWN nk
      recipientViewingPublicKey: bobViewingPublicKey, // opt in to recipient discovery
    });

    // Bank the change before you render "sent". This is its only copy: output 0 is
    // Bob's note, output 1 is Alice's change, and its blinding reaches no chain.
    for (const spent of inputs) wallet.markSpent(spent, spent.mintAddress);
    for (const utxo of result.outputUtxos) wallet.addUtxo(utxo, utxo.mintAddress);
    window.localStorage.setItem(NOTES_KEY, wallet.serialize());
  } catch (error) {
    const hint = explainRelayAuthRejection(String(error));
    throw hint ? new Error(hint, { cause: error }) : error;
  }
}
```

> [!NOTE]
>
> **`UtxoWallet.serialize()` drops each note's `commitment`.** It is spend-complete, so nothing here is
> lost, but notes restored with `UtxoWallet.deserialize` come back from `verifyUtxos` as `skipped`
> rather than `unspent`. Read `skipped` as "not checked", never as "gone".

Two things a browser integration should design around, both covered in full on [Request authentication](https://docs.cloak.ag/sdk/request-authentication.md):

* **The user usually sees one prompt.** A shielded transfer signs once per submitted request, and network retries re-send the same signed request. A stale Merkle root forces a new proof and a new prompt. With `createCloak`, `send` raises no prompt at all.
* **The signed timestamp expires.** `REQUEST_AUTH_MAX_AGE_SECONDS` is `300` and the SDK holds a little of that back for serializing and shipping the request, leaving roughly 285 seconds to approve. An approval dialog left sitting on a desk comes back to a dead request: nothing was submitted and nothing is at risk, but the whole send, proof included, has to be started again.

## Where next

> [card] [Where your notes live between sessions](https://docs.cloak.ag/wallets/wallet-adapter.md#where-your-notes-live-between-sessions)
>
> What to persist the moment a send returns, and which losses no scan can undo.

> [card] [UTXO Transactions](https://docs.cloak.ag/sdk/low-level-api.md)
>
> The `transfer` / `transact` API, `externalAmount` semantics, and fees.

> [card] [Request authentication](https://docs.cloak.ag/sdk/request-authentication.md)
>
> Who signs a shielded transfer, the browser wallet-adapter wiring, and the approval window.

> [card] [Payment links](https://docs.cloak.ag/guide/payment-links.md)
>
> The productized version that needs nothing from the recipient up front, with a refund path.

> [card] [Moving value out of your private balance](https://docs.cloak.ag/guide/private-send.md)
>
> The consumer view: the two ways value leaves the pool (send / withdraw), and where this fits.

> [card] [Viewing keys & compliance](https://docs.cloak.ag/concepts/viewing-keys-compliance.md)
>
> What the self-scan is, and how it powers compliance.


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