@cloak.dev/sdk 0.2.13 → 0.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,48 @@ the README's "Version and compatibility" section and in the git history.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.14]
11
+
12
+ ### Fixed
13
+
14
+ * A Ledger driven through Phantom, Solflare or Backpack can authenticate to the relay again. With
15
+ the hardware-wallet envelope on, these wallets change the 0 SOL auth transaction before the device
16
+ signs it (Phantom adds compute-budget instructions to a transaction that has none, Solflare adds
17
+ its guard instructions), so the signature covered the wallet's message while the relay rebuilt
18
+ the SDK's and refused it. In production this stopped every such user at viewing-key registration
19
+ with "Signature verification failed". `signRelayAuthPayload` now returns the message the wallet
20
+ signed as `txMessage` when it differs from ours and still binds the payload (the wallet as fee
21
+ payer and only signer, `sha256(payload)` as the blockhash, our 0-lamport self-transfer still in
22
+ it), and every relay request carries it as `auth_tx_message` (`tx_message` on
23
+ `/viewing-key/register`). The wallet may add only what wallets add on their own: instructions of
24
+ ComputeBudget (Phantom, Solflare) and Lighthouse (Solflare), the programs seen in real Phantom and
25
+ Solflare messages. Anything else next to the transfer is how a phishing page would disguise the
26
+ envelope, so it is refused, as is a message that fails the relay's `sanitize()` rules or whose
27
+ signature does not cover it. All of these are refused before anything is sent. A wallet that signs the
28
+ envelope unchanged sends exactly what it sent before. Needs the matching relay release; an older
29
+ relay ignores the field.
30
+
31
+ ### Added
32
+
33
+ * `walletAuthTransactionMessageBinds(sender, payload, bytes)`, the client copy of the relay's
34
+ `wallet_tx_message_binds` (pinned to it by a shared corpus,
35
+ `src/__tests__/fixtures/wallet-tx-message-corpus.json`), `WALLET_ADDED_PROGRAMS`, and the
36
+ `SignedRelayAuthPayload` type. `WALLET_ADDED_PROGRAMS` mirrors the relay and grows when a new
37
+ wallet is seen adding another program; read it from the SDK version you run, do not copy it.
38
+
39
+ ### Changed
40
+
41
+ * `signRelayAuthPayload` verifies the signature a transaction-only wallet returns over the message
42
+ it returned, before anything is sent: a wallet that signed other bytes is refused with a sentence
43
+ instead of a 401 after the proof. Message-mode signatures are returned unchecked, as before, so
44
+ callers that verify them and fall back to the envelope (web's affiliate signer) keep working.
45
+ * `TransactOptions.affiliateCode`, `TransactOptions.onWarning` and `normalizeAffiliateCode` are now
46
+ public API. Any approved Cloak partner can pass their code from their own app and earn commission
47
+ on the withdrawals, sends to an address and swaps it makes; before, only Cloak's own web and
48
+ mobile apps were counted. Behaviour and wire format are unchanged: the code is still sent only
49
+ on fee-bearing requests, normalised, signed inside the request, and left out (reported through
50
+ `onWarning`) when invalid. Counting codes from other apps needs the matching relay release.
51
+
10
52
  ## [0.2.13]
11
53
 
12
54
  ### Fixed
package/README.md CHANGED
@@ -5,13 +5,13 @@ per-mint pool, send privately inside the pool, withdraw to any address, or swap
5
5
  USDC/USDT with the output landing in a public token account. Groth16 proofs are generated
6
6
  client-side (snarkjs) and verified on-chain by the Cloak program.
7
7
 
8
- Version 0.2.13 targets the mainnet program deployed on 2026-08-24 and the ceremony-frozen
8
+ Version 0.2.14 targets the mainnet program deployed on 2026-08-24 and the ceremony-frozen
9
9
  `cloak-transaction-0.2.0` circuit bundle. See [Version and compatibility](#version-and-compatibility).
10
10
 
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- npm install @cloak.dev/sdk@^0.2.13
14
+ npm install @cloak.dev/sdk@^0.2.14
15
15
  ```
16
16
 
17
17
  The SDK is built on [`@solana/kit`](https://github.com/anza-xyz/kit) and re-exports the pieces an
@@ -267,7 +267,11 @@ await transact(
267
267
  A wallet that cannot sign messages (Ledger, Trezor) passes `signer` instead of `signMessage`: the
268
268
  sender then authenticates by signing a 0-lamport no-op self-transfer that carries the request
269
269
  digest (`auth_mode: "transaction"`). Give a wallet one of the two; when both are present
270
- `signMessage` is used.
270
+ `signMessage` is used. If the wallet changes that transaction before its device signs it (Phantom
271
+ adds compute-budget instructions, Solflare its guards), the SDK sends the message the wallet
272
+ actually signed as `auth_tx_message`. Only ComputeBudget and Lighthouse instructions may be added
273
+ (`WALLET_ADDED_PROGRAMS`); any other change is refused before anything is sent
274
+ (`walletAuthTransactionMessageBinds`).
271
275
 
272
276
  `signMessage` must return the raw 64-byte ed25519 detached signature over the bytes it is given;
273
277
  adapters that re-encode or wrap the result are rejected by name. `walletPublicKey` must be the end
@@ -506,6 +510,32 @@ keypair, then look up the leaf index as in
506
510
  [Recovery and discovery](#recovery-and-discovery-viewing-key). `swap.refund` no longer carries a
507
511
  private key: the refund is spent with the wallet's own `ownerUtxoKeypair`.
508
512
 
513
+ ### Partner code (rev share)
514
+
515
+ An approved [Cloak partner](https://cloak.ag/affiliates) earns 20% of Cloak's percentage fee on the
516
+ fee-bearing transactions their app makes, by passing their code:
517
+
518
+ ```ts
519
+ import { fullWithdraw, normalizeAffiliateCode } from "@cloak.dev/sdk";
520
+
521
+ const affiliateCode = normalizeAffiliateCode(process.env.CLOAK_PARTNER_CODE); // null if malformed
522
+
523
+ await fullWithdraw(notes, recipient, {
524
+ ...spendOptions,
525
+ ...(affiliateCode ? { affiliateCode } : {}),
526
+ onWarning: (message) => console.warn(message),
527
+ });
528
+ ```
529
+
530
+ The code rides only on withdrawals and sends to a public address, and on swaps. Deposits,
531
+ shield-to-shield sends and the merge steps of `partialWithdraw` never carry it. It is trimmed and
532
+ lower-cased, must match `^[a-z0-9_]{3,24}$`, is signed inside the request and never written
533
+ on-chain; an invalid code is left out and reported through `onWarning`, never failing the
534
+ transaction. Cloak decides after confirmation whether it earns: approved code, not the partner's own
535
+ payout wallet, a fee verified on-chain, and the first approved code per wallet for two calendar
536
+ months. Users pay the same fees either way. Full rules:
537
+ [docs.cloak.ag/affiliates/sdk-integration](https://docs.cloak.ag/affiliates/sdk-integration).
538
+
509
539
  ## Recovery and discovery (viewing key)
510
540
 
511
541
  The viewing base `nk` is derived from the wallet's long-lived UTXO private key
@@ -799,7 +829,7 @@ relay endpoint and the localhost-RPC check.
799
829
 
800
830
  ## Version and compatibility
801
831
 
802
- - SDK 0.2.13 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
832
+ - SDK 0.2.14 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
803
833
  (deployed 2026-08-24) and the 0.2.0 circuit bundle — the program and circuit bundle are unchanged
804
834
  since 0.2.0; only the SDK package version has moved. The 0.2.5 flows were exercised on mainnet on
805
835
  2026-08-25: deposit, private send and withdraw on SOL, USDC and USDT; swaps SOL to USDC and USDT;
@@ -836,6 +866,12 @@ relay endpoint and the localhost-RPC check.
836
866
  - 0.2.13 caps the prover at 8 workers (2 in a 32-bit browser), bounds the circuit download and
837
867
  retries a stalled proof single-threaded; it changes no wire format, hash or signature (see
838
868
  [CHANGELOG.md](CHANGELOG.md)).
869
+ - 0.2.14 lets a hardware wallet authenticate through a software wallet that changes the 0 SOL
870
+ auth transaction before the device signs it (Phantom adds compute budget, Solflare its guards):
871
+ the message the wallet signed is sent as `auth_tx_message` (`tx_message` on
872
+ `/viewing-key/register`). The field appears only for such a wallet, so every other request is
873
+ byte-identical to 0.2.13; it needs the matching relay release, and an older relay ignores it and
874
+ refuses those signatures as before (see [CHANGELOG.md](CHANGELOG.md)).
839
875
  - Proofs generated with the 0.1.x circuits are rejected by the mainnet program. SDK 0.1.x builds
840
876
  (which ship the 0.1.0 bundle) are not usable against it; upgrade to 0.2.x.
841
877
  - The note-based `CloakSDK` class is removed in 0.2.0. It targeted the pre-0.2.0 instruction layout
package/dist/index.cjs CHANGED
@@ -648,6 +648,7 @@ __export(index_exports, {
648
648
  VARIABLE_FEE_NUMERATOR: () => VARIABLE_FEE_NUMERATOR,
649
649
  VARIABLE_FEE_RATE: () => VARIABLE_FEE_RATE,
650
650
  VERSION: () => VERSION,
651
+ WALLET_ADDED_PROGRAMS: () => WALLET_ADDED_PROGRAMS,
651
652
  WITHDRAW_FEE_BPS: () => WITHDRAW_FEE_BPS,
652
653
  WITHDRAW_FIXED_FEE: () => WITHDRAW_FIXED_FEE,
653
654
  accountMeta: () => accountMeta,
@@ -924,6 +925,7 @@ __export(index_exports, {
924
925
  verifyQuoteSignature: () => verifyQuoteSignature,
925
926
  verifyUtxos: () => verifyUtxos,
926
927
  waitForRoot: () => waitForRoot,
928
+ walletAuthTransactionMessageBinds: () => walletAuthTransactionMessageBinds,
927
929
  withShieldRetries: () => withShieldRetries,
928
930
  withTiming: () => withTiming,
929
931
  withdrawFeeFor: () => withdrawFeeFor
@@ -1522,7 +1524,7 @@ function messageSignerFromCallback(address2, signMessage) {
1522
1524
  }
1523
1525
 
1524
1526
  // src/scanning/compliance-keys.ts
1525
- var import_tweetnacl2 = __toESM(require("tweetnacl"), 1);
1527
+ var import_tweetnacl3 = __toESM(require("tweetnacl"), 1);
1526
1528
  var import_blake32 = require("@noble/hashes/blake3");
1527
1529
  var import_sha22 = require("@noble/hashes/sha2");
1528
1530
  init_inputs();
@@ -1795,6 +1797,8 @@ var import_sha2 = require("@noble/hashes/sha2");
1795
1797
  var import_utils = require("@noble/hashes/utils");
1796
1798
  var import_kit5 = require("@solana/kit");
1797
1799
  var import_system2 = require("@solana-program/system");
1800
+ var import_tweetnacl2 = __toESM(require("tweetnacl"), 1);
1801
+ init_address();
1798
1802
 
1799
1803
  // src/solana/transaction.ts
1800
1804
  var import_kit4 = require("@solana/kit");
@@ -2242,6 +2246,61 @@ function buildAuthTransactionMessage(sender, digest) {
2242
2246
  function serializeAuthTransactionMessage(sender, digest) {
2243
2247
  return new Uint8Array(compileUnsigned(buildAuthTransactionMessage(sender, digest)).messageBytes);
2244
2248
  }
2249
+ var MAX_AUTH_TX_MESSAGE_BYTES = 1232;
2250
+ var TRANSFER_ZERO_LAMPORTS = Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
2251
+ var SYSTEM_PROGRAM_ADDRESS2 = "11111111111111111111111111111111";
2252
+ function sameBytes(a, b) {
2253
+ return a.length === b.length && a.every((byte, i) => byte === b[i]);
2254
+ }
2255
+ function walletAuthTransactionMessageBinds(sender, payload, bytes) {
2256
+ if (bytes.length > MAX_AUTH_TX_MESSAGE_BYTES) return false;
2257
+ let compiled;
2258
+ try {
2259
+ compiled = (0, import_kit5.getCompiledTransactionMessageDecoder)().decode(bytes);
2260
+ if (compiled.version !== "legacy" && compiled.version !== 0) return false;
2261
+ if (!sameBytes(new Uint8Array((0, import_kit5.getCompiledTransactionMessageEncoder)().encode(compiled)), bytes)) return false;
2262
+ } catch {
2263
+ return false;
2264
+ }
2265
+ if (!sanitizes(compiled)) return false;
2266
+ const accounts = compiled.staticAccounts;
2267
+ if (compiled.header.numSignerAccounts !== 1 || accounts[0] !== sender) return false;
2268
+ const lifetimeToken = compiled.lifetimeToken;
2269
+ if (lifetimeToken !== (0, import_kit5.getBase58Decoder)().decode((0, import_sha2.sha256)(payload))) return false;
2270
+ let ours = false;
2271
+ for (const instruction of compiled.instructions) {
2272
+ const program = accounts[instruction.programAddressIndex];
2273
+ if (program === SYSTEM_PROGRAM_ADDRESS2 && instruction.accountIndices?.length === 2 && instruction.accountIndices[0] === 0 && instruction.accountIndices[1] === 0 && sameBytes(new Uint8Array(instruction.data ?? []), TRANSFER_ZERO_LAMPORTS)) {
2274
+ ours = true;
2275
+ } else if (!WALLET_ADDED_PROGRAMS.includes(program)) {
2276
+ return false;
2277
+ }
2278
+ }
2279
+ return ours;
2280
+ }
2281
+ var WALLET_ADDED_PROGRAMS = [
2282
+ "ComputeBudget111111111111111111111111111111",
2283
+ "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95"
2284
+ ];
2285
+ function sanitizes(compiled) {
2286
+ const { header, staticAccounts, instructions } = compiled;
2287
+ const lookups = compiled.addressTableLookups ?? [];
2288
+ if (header.numReadonlySignerAccounts >= header.numSignerAccounts) return false;
2289
+ if (header.numSignerAccounts + header.numReadonlyNonSignerAccounts > staticAccounts.length) return false;
2290
+ let total = staticAccounts.length;
2291
+ for (const lookup of lookups) {
2292
+ const loaded = lookup.writableIndexes.length + lookup.readonlyIndexes.length;
2293
+ if (loaded === 0) return false;
2294
+ total += loaded;
2295
+ }
2296
+ if (total > 256) return false;
2297
+ return instructions.every(
2298
+ (instruction) => (
2299
+ // Programs come from static keys only and are never the fee payer.
2300
+ instruction.programAddressIndex > 0 && instruction.programAddressIndex < staticAccounts.length && (instruction.accountIndices ?? []).every((index) => index < total)
2301
+ )
2302
+ );
2303
+ }
2245
2304
  async function signRelayAuthPayload(signer, payload) {
2246
2305
  if (isMessageSigner(signer)) {
2247
2306
  const signature = await signMessageBytes(signer, payload);
@@ -2265,7 +2324,21 @@ async function signRelayAuthPayload(signer, payload) {
2265
2324
  }
2266
2325
  const signature = new Uint8Array(own);
2267
2326
  assertDetachedSignature(signature, "signTransaction");
2268
- return { signature, mode: "transaction" };
2327
+ const signedMessage = new Uint8Array(signed.messageBytes);
2328
+ if (!import_tweetnacl2.default.sign.detached.verify(signedMessage, signature, addressBytes(signer.address))) {
2329
+ throw new Error(
2330
+ "The wallet's signature does not match the Cloak auth transaction it returned. Nothing was submitted."
2331
+ );
2332
+ }
2333
+ if (sameBytes(signedMessage, new Uint8Array(compileUnsigned(message).messageBytes))) {
2334
+ return { signature, mode: "transaction" };
2335
+ }
2336
+ if (!walletAuthTransactionMessageBinds(signer.address, payload, signedMessage)) {
2337
+ throw new Error(
2338
+ "The wallet changed the Cloak auth transaction into one that no longer authorizes this request (another fee payer or signer, another blockhash, or no 0 SOL self-transfer). Nothing was submitted."
2339
+ );
2340
+ }
2341
+ return { signature, mode: "transaction", txMessage: signedMessage };
2269
2342
  }
2270
2343
  throw new Error("Relay auth signer can neither sign messages nor transactions.");
2271
2344
  }
@@ -2327,14 +2400,15 @@ async function buildRelayAuthFields(endpoint, programId, body, signers, fields =
2327
2400
  fields
2328
2401
  );
2329
2402
  const approvalStartedMs = Date.now();
2330
- const { signature, mode } = await signRelayAuthPayload(wallet, preimage.message);
2403
+ const { signature, mode, txMessage } = await signRelayAuthPayload(wallet, preimage.message);
2331
2404
  assertApprovalWithinFreshnessWindow(Date.now() - approvalStartedMs);
2332
2405
  return {
2333
2406
  sender: preimage.sender,
2334
2407
  auth_issued_at: preimage.auth_issued_at,
2335
2408
  auth_nonce: preimage.auth_nonce,
2336
2409
  auth_signature: Buffer.from(signature).toString("base64"),
2337
- ...mode === "transaction" ? { auth_mode: mode } : {}
2410
+ ...mode === "transaction" ? { auth_mode: mode } : {},
2411
+ ...txMessage ? { auth_tx_message: Buffer.from(txMessage).toString("base64") } : {}
2338
2412
  };
2339
2413
  }
2340
2414
  var REQUEST_AUTH_BATCH_DOMAIN = "CLOAK_RELAY_BATCH_AUTH_V1";
@@ -2385,7 +2459,7 @@ function deriveViewingKeyFromNk(nk) {
2385
2459
  preimage.set(nk, CHAIN_NOTE_VK_DOMAIN.length);
2386
2460
  const derived = (0, import_blake32.blake3)(preimage);
2387
2461
  const privateKey = clampX25519Secret(derived);
2388
- const publicKey = import_tweetnacl2.default.scalarMult.base(privateKey);
2462
+ const publicKey = import_tweetnacl3.default.scalarMult.base(privateKey);
2389
2463
  return { privateKey, publicKey };
2390
2464
  }
2391
2465
  function deriveDiversifier(nk, commitmentHex, outputIndex) {
@@ -2420,7 +2494,7 @@ function deriveDiversifiedViewingKey(nk, diversifier) {
2420
2494
  preimage.set(diversifier, SK_D_DOMAIN.length + nk.length);
2421
2495
  const derived = (0, import_blake32.blake3)(preimage);
2422
2496
  const privateKey = clampX25519Secret(derived);
2423
- const publicKey = import_tweetnacl2.default.scalarMult.base(privateKey);
2497
+ const publicKey = import_tweetnacl3.default.scalarMult.base(privateKey);
2424
2498
  return { privateKey, publicKey };
2425
2499
  }
2426
2500
  function deriveViewingKeyFromSpendKey(skSpend) {
@@ -2483,7 +2557,7 @@ async function deriveUserCompliancePublicKey(masterCompliancePublicKey, userPubl
2483
2557
  masterCompliancePublicKey,
2484
2558
  userPublicKey
2485
2559
  );
2486
- return import_tweetnacl2.default.scalarMult(factor, masterCompliancePublicKey);
2560
+ return import_tweetnacl3.default.scalarMult(factor, masterCompliancePublicKey);
2487
2561
  }
2488
2562
  function bytesToHex3(bytes) {
2489
2563
  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
@@ -2530,7 +2604,8 @@ async function registerViewingKey(relayUrl, userPubkey, nk, signMessage) {
2530
2604
  nonce: challenge.nonce,
2531
2605
  identifier: keyId,
2532
2606
  signature,
2533
- ...signed.mode === "transaction" ? { auth_mode: signed.mode } : {}
2607
+ ...signed.mode === "transaction" ? { auth_mode: signed.mode } : {},
2608
+ ...signed.txMessage ? { tx_message: Buffer.from(signed.txMessage).toString("base64") } : {}
2534
2609
  })
2535
2610
  });
2536
2611
  if (!response.ok) {
@@ -2539,7 +2614,7 @@ async function registerViewingKey(relayUrl, userPubkey, nk, signMessage) {
2539
2614
  }
2540
2615
 
2541
2616
  // src/scanning/metadata-encryption.ts
2542
- var import_tweetnacl3 = __toESM(require("tweetnacl"), 1);
2617
+ var import_tweetnacl4 = __toESM(require("tweetnacl"), 1);
2543
2618
  init_inputs();
2544
2619
  var AES_GCM_NONCE_LENGTH = 12;
2545
2620
  var AES_GCM_TAG_LENGTH = 16;
@@ -2637,8 +2712,8 @@ async function aesGcmDecrypt(ciphertext, keyBytes, nonce) {
2637
2712
  }
2638
2713
  async function encryptForRecipient(plaintext, recipientPublicKey) {
2639
2714
  assert32Bytes2(recipientPublicKey, "recipientPublicKey");
2640
- const ephemeral = import_tweetnacl3.default.box.keyPair();
2641
- const sharedSecret = import_tweetnacl3.default.scalarMult(ephemeral.secretKey, recipientPublicKey);
2715
+ const ephemeral = import_tweetnacl4.default.box.keyPair();
2716
+ const sharedSecret = import_tweetnacl4.default.scalarMult(ephemeral.secretKey, recipientPublicKey);
2642
2717
  const nonce = randomBytes(AES_GCM_NONCE_LENGTH);
2643
2718
  const ciphertext = await aesGcmEncrypt(plaintext, sharedSecret, nonce);
2644
2719
  return {
@@ -2697,7 +2772,7 @@ async function encryptTransactionMetadataBundle(metadata, viewingKeyPrivate, use
2697
2772
  const plaintext = new TextEncoder().encode(JSON.stringify(metadata));
2698
2773
  const basePoint = new Uint8Array(32);
2699
2774
  basePoint[0] = 9;
2700
- const viewingKeyPublic = import_tweetnacl3.default.scalarMult(viewingKeyPrivate, basePoint);
2775
+ const viewingKeyPublic = import_tweetnacl4.default.scalarMult(viewingKeyPrivate, basePoint);
2701
2776
  const [userPayload, compliancePayload] = await Promise.all([
2702
2777
  encryptForRecipient(plaintext, viewingKeyPublic),
2703
2778
  encryptForRecipient(plaintext, viewingKeyPublic)
@@ -2716,7 +2791,7 @@ async function decryptTransactionMetadata(encrypted, viewKeySecret) {
2716
2791
  const payload = decodePayload(encrypted);
2717
2792
  const ephemeralPk = hexToBytes(payload.ephemeral_pk);
2718
2793
  assert32Bytes2(ephemeralPk, "ephemeral public key");
2719
- const sharedSecret = import_tweetnacl3.default.scalarMult(viewKeySecret, ephemeralPk);
2794
+ const sharedSecret = import_tweetnacl4.default.scalarMult(viewKeySecret, ephemeralPk);
2720
2795
  return decryptWithSharedSecret(payload, sharedSecret);
2721
2796
  }
2722
2797
  async function decryptComplianceMetadataWithMasterKey(encrypted, masterCompliancePrivateKey, masterCompliancePublicKey, userPublicKey) {
@@ -2729,8 +2804,8 @@ async function decryptComplianceMetadataWithMasterKey(encrypted, masterComplianc
2729
2804
  masterCompliancePublicKey,
2730
2805
  userPublicKey
2731
2806
  );
2732
- const scaledEphemeral = import_tweetnacl3.default.scalarMult(userFactor, ephemeralPk);
2733
- const sharedSecret = import_tweetnacl3.default.scalarMult(masterCompliancePrivateKey, scaledEphemeral);
2807
+ const scaledEphemeral = import_tweetnacl4.default.scalarMult(userFactor, ephemeralPk);
2808
+ const sharedSecret = import_tweetnacl4.default.scalarMult(masterCompliancePrivateKey, scaledEphemeral);
2734
2809
  return decryptWithSharedSecret(payload, sharedSecret);
2735
2810
  }
2736
2811
 
@@ -4390,7 +4465,8 @@ var RelayService = class {
4390
4465
  nonce: challenge.nonce,
4391
4466
  identifier,
4392
4467
  signature,
4393
- ...signed.mode === "transaction" ? { auth_mode: signed.mode } : {}
4468
+ ...signed.mode === "transaction" ? { auth_mode: signed.mode } : {},
4469
+ ...signed.txMessage ? { tx_message: this.bytesToBase64(signed.txMessage) } : {}
4394
4470
  })
4395
4471
  });
4396
4472
  if (!response.ok) {
@@ -5807,7 +5883,7 @@ function chainNoteFromBase64(base64) {
5807
5883
  }
5808
5884
 
5809
5885
  // src/notes/delivery-note.ts
5810
- var import_tweetnacl4 = __toESM(require("tweetnacl"), 1);
5886
+ var import_tweetnacl5 = __toESM(require("tweetnacl"), 1);
5811
5887
  var RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN = 32;
5812
5888
  var RECIPIENT_DELIVERY_NONCE_LEN = 24;
5813
5889
  var RECIPIENT_DELIVERY_PLAINTEXT_LEN = 40;
@@ -5858,10 +5934,10 @@ function encodeRecipientDeliveryNote(note, recipientViewingPublicKey) {
5858
5934
  const plaintext = new Uint8Array(RECIPIENT_DELIVERY_PLAINTEXT_LEN);
5859
5935
  writeU64LE2(plaintext, 0, note.amount);
5860
5936
  writeU256BE2(plaintext, 8, note.blinding);
5861
- const ephemeral = import_tweetnacl4.default.box.keyPair();
5862
- const shared = import_tweetnacl4.default.box.before(recipientViewingPublicKey, ephemeral.secretKey);
5863
- const nonce = import_tweetnacl4.default.randomBytes(import_tweetnacl4.default.secretbox.nonceLength);
5864
- const ciphertext = import_tweetnacl4.default.secretbox(plaintext, nonce, shared);
5937
+ const ephemeral = import_tweetnacl5.default.box.keyPair();
5938
+ const shared = import_tweetnacl5.default.box.before(recipientViewingPublicKey, ephemeral.secretKey);
5939
+ const nonce = import_tweetnacl5.default.randomBytes(import_tweetnacl5.default.secretbox.nonceLength);
5940
+ const ciphertext = import_tweetnacl5.default.secretbox(plaintext, nonce, shared);
5865
5941
  if (ciphertext.length !== RECIPIENT_DELIVERY_CIPHERTEXT_LEN) {
5866
5942
  throw new Error(
5867
5943
  `delivery ciphertext must be ${RECIPIENT_DELIVERY_CIPHERTEXT_LEN} bytes, got ${ciphertext.length}`
@@ -5887,8 +5963,8 @@ function openRecipientDeliveryNote(envelope, viewingSecretKey) {
5887
5963
  const ciphertext = envelope.slice(
5888
5964
  RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN + RECIPIENT_DELIVERY_NONCE_LEN
5889
5965
  );
5890
- const shared = import_tweetnacl4.default.box.before(ephemeralPk, viewingSecretKey);
5891
- const plaintext = import_tweetnacl4.default.secretbox.open(ciphertext, nonce, shared);
5966
+ const shared = import_tweetnacl5.default.box.before(ephemeralPk, viewingSecretKey);
5967
+ const plaintext = import_tweetnacl5.default.secretbox.open(ciphertext, nonce, shared);
5892
5968
  if (!plaintext || plaintext.length !== RECIPIENT_DELIVERY_PLAINTEXT_LEN) return null;
5893
5969
  return { amount: readU64LE2(plaintext, 0), blinding: readU256BE2(plaintext, 8) };
5894
5970
  } catch {
@@ -5924,7 +6000,7 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
5924
6000
  }
5925
6001
  const slow = async (envelope) => openRecipientDeliveryNote(envelope, viewingSecretKey);
5926
6002
  const subtle = globalThis.crypto?.subtle;
5927
- const hsalsa = import_tweetnacl4.default.lowlevel?.crypto_core_hsalsa20;
6003
+ const hsalsa = import_tweetnacl5.default.lowlevel?.crypto_core_hsalsa20;
5928
6004
  if (!subtle || typeof hsalsa !== "function") return slow;
5929
6005
  let privateKey;
5930
6006
  const sharedKey = async (ephemeralPk) => {
@@ -5941,9 +6017,9 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
5941
6017
  pkcs8.set(X25519_PKCS8_PREFIX);
5942
6018
  pkcs8.set(viewingSecretKey, X25519_PKCS8_PREFIX.length);
5943
6019
  privateKey = await subtle.importKey("pkcs8", pkcs8, { name: "X25519" }, false, ["deriveBits"]);
5944
- const probe = import_tweetnacl4.default.box.keyPair().publicKey;
6020
+ const probe = import_tweetnacl5.default.box.keyPair().publicKey;
5945
6021
  const fast = await sharedKey(probe);
5946
- const reference = import_tweetnacl4.default.box.before(probe, viewingSecretKey);
6022
+ const reference = import_tweetnacl5.default.box.before(probe, viewingSecretKey);
5947
6023
  if (fast.length !== reference.length || fast.some((b, i) => b !== reference[i])) return slow;
5948
6024
  } catch {
5949
6025
  return slow;
@@ -5963,7 +6039,7 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
5963
6039
  return openRecipientDeliveryNote(envelope, viewingSecretKey);
5964
6040
  }
5965
6041
  try {
5966
- return decodeOpened(import_tweetnacl4.default.secretbox.open(ciphertext, nonce, key));
6042
+ return decodeOpened(import_tweetnacl5.default.secretbox.open(ciphertext, nonce, key));
5967
6043
  } catch {
5968
6044
  return null;
5969
6045
  }
@@ -6565,7 +6641,7 @@ async function matchChangeNote(params) {
6565
6641
 
6566
6642
  // src/flows/transact.ts
6567
6643
  var import_circomlibjs4 = require("circomlibjs");
6568
- var import_tweetnacl5 = __toESM(require("tweetnacl"), 1);
6644
+ var import_tweetnacl6 = __toESM(require("tweetnacl"), 1);
6569
6645
 
6570
6646
  // src/relay/chain-note-time.ts
6571
6647
  async function relayChainNoteTimestampMs(relayUrl) {
@@ -7438,6 +7514,7 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
7438
7514
  );
7439
7515
  let signatureBase64;
7440
7516
  let authMode = "message";
7517
+ let txMessageBase64;
7441
7518
  const messageBytes = new TextEncoder().encode(challenge.message);
7442
7519
  if (options.signMessage) {
7443
7520
  const sig = await options.signMessage(messageBytes);
@@ -7455,6 +7532,7 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
7455
7532
  const signed = await signRelayAuthPayload(options.signer, messageBytes);
7456
7533
  signatureBase64 = Buffer.from(signed.signature).toString("base64");
7457
7534
  authMode = signed.mode;
7535
+ if (signed.txMessage) txMessageBase64 = Buffer.from(signed.txMessage).toString("base64");
7458
7536
  } else {
7459
7537
  throw new Error(
7460
7538
  "Viewing key registration is mandatory: signMessage or signer (wallet) or depositorKeypair is required."
@@ -7469,7 +7547,8 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
7469
7547
  viewing_key: viewingKeyHex,
7470
7548
  nonce: challenge.nonce,
7471
7549
  signature: signatureBase64,
7472
- ...authMode === "transaction" ? { auth_mode: authMode } : {}
7550
+ ...authMode === "transaction" ? { auth_mode: authMode } : {},
7551
+ ...txMessageBase64 ? { tx_message: txMessageBase64 } : {}
7473
7552
  })
7474
7553
  });
7475
7554
  if (!response.ok) {
@@ -8734,7 +8813,7 @@ async function fetchRiskQuote(riskQuoteUrl, wallet, options) {
8734
8813
  `Invalid risk quote response: invalid lengths (sig=${signatureBuf.length}, msg=${messageArr.length}, pk=${publicKeyBytes.length}; expected msg 33/41/50/82/146)`
8735
8814
  );
8736
8815
  }
8737
- if (!import_tweetnacl5.default.sign.detached.verify(messageArr, new Uint8Array(signatureBuf), publicKeyBytes)) {
8816
+ if (!import_tweetnacl6.default.sign.detached.verify(messageArr, new Uint8Array(signatureBuf), publicKeyBytes)) {
8738
8817
  throw new Error(
8739
8818
  "Invalid risk quote response: signature does not verify under signer_pubkey"
8740
8819
  );
@@ -11664,7 +11743,7 @@ var RelayBatchAuthCoordinator = class {
11664
11743
  );
11665
11744
  }
11666
11745
  const approvalStartedMs = Date.now();
11667
- const { signature, mode } = await signRelayAuthPayload(this.signer, message);
11746
+ const { signature, mode, txMessage } = await signRelayAuthPayload(this.signer, message);
11668
11747
  if (!(0, import_kit9.isKeyPairSigner)(this.signer)) {
11669
11748
  assertApprovalWithinFreshnessWindow(
11670
11749
  Date.now() - approvalStartedMs,
@@ -11682,6 +11761,9 @@ var RelayBatchAuthCoordinator = class {
11682
11761
  auth_nonce: preimage.auth_nonce,
11683
11762
  auth_signature: signatureB64,
11684
11763
  ...mode === "transaction" ? { auth_mode: mode } : {},
11764
+ // The wallet's own message when it changed the envelope; one approval, so the same
11765
+ // message for every item, exactly like the signature.
11766
+ ...txMessage ? { auth_tx_message: Buffer.from(txMessage).toString("base64") } : {},
11685
11767
  // A fresh array per item: `Object.assign` puts this on the wire body, and the body is
11686
11768
  // serialized again on every network retry.
11687
11769
  auth_batch: { digests: [...digests] }
@@ -13525,7 +13607,7 @@ async function fetchNoteIndexPage(relayUrl, epoch, page, options = {}) {
13525
13607
 
13526
13608
  // src/notes/request-keys.ts
13527
13609
  var import_blake37 = require("@noble/hashes/blake3");
13528
- var import_tweetnacl6 = __toESM(require("tweetnacl"), 1);
13610
+ var import_tweetnacl7 = __toESM(require("tweetnacl"), 1);
13529
13611
  init_utxo();
13530
13612
  var BN254_ORDER = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
13531
13613
  var ROOT_SEED_DOMAIN = new TextEncoder().encode("cloak_request_root_v1");
@@ -13576,7 +13658,7 @@ async function deriveRequestKeys(root, counter) {
13576
13658
  return {
13577
13659
  counter,
13578
13660
  utxoKeypair: { privateKey, publicKey },
13579
- viewingKeypair: { privateKey: vk, publicKey: import_tweetnacl6.default.scalarMult.base(vk) }
13661
+ viewingKeypair: { privateKey: vk, publicKey: import_tweetnacl7.default.scalarMult.base(vk) }
13580
13662
  };
13581
13663
  }
13582
13664
  async function deriveRequestKeyRange(root, from, count) {
@@ -15082,7 +15164,7 @@ async function loadWeb3() {
15082
15164
  }
15083
15165
 
15084
15166
  // src/bridge/rail-verify.ts
15085
- var import_tweetnacl7 = __toESM(require("tweetnacl"), 1);
15167
+ var import_tweetnacl8 = __toESM(require("tweetnacl"), 1);
15086
15168
  var import_sha256 = require("@noble/hashes/sha256");
15087
15169
  var ONECLICK_PUBKEY_B58 = "reYaWhvwu8Jzo3WUM3zhn6VrhuMEF4eADL17qtRVifc";
15088
15170
  var b58 = /* @__PURE__ */ (() => {
@@ -15193,7 +15275,7 @@ function verifyQuoteSignature(resp) {
15193
15275
  const message = new TextEncoder().encode(b58.encode(new Uint8Array(digest)));
15194
15276
  const sig = resp.signature.replace(/^ed25519:/, "");
15195
15277
  try {
15196
- return { valid: import_tweetnacl7.default.sign.detached.verify(message, b58.decode(sig), b58.decode(ONECLICK_PUBKEY_B58)) };
15278
+ return { valid: import_tweetnacl8.default.sign.detached.verify(message, b58.decode(sig), b58.decode(ONECLICK_PUBKEY_B58)) };
15197
15279
  } catch (e) {
15198
15280
  return { valid: false, reason: e instanceof Error ? e.message : String(e) };
15199
15281
  }
@@ -15954,7 +16036,7 @@ async function withShieldRetries(attempt, hooks = {}) {
15954
16036
  }
15955
16037
 
15956
16038
  // src/index.ts
15957
- var VERSION = "0.2.13";
16039
+ var VERSION = "0.2.14";
15958
16040
  var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
15959
16041
  // Annotate the CommonJS export names for ESM import in node:
15960
16042
  0 && (module.exports = {
@@ -16031,6 +16113,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
16031
16113
  VARIABLE_FEE_NUMERATOR,
16032
16114
  VARIABLE_FEE_RATE,
16033
16115
  VERSION,
16116
+ WALLET_ADDED_PROGRAMS,
16034
16117
  WITHDRAW_FEE_BPS,
16035
16118
  WITHDRAW_FIXED_FEE,
16036
16119
  accountMeta,
@@ -16307,6 +16390,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
16307
16390
  verifyQuoteSignature,
16308
16391
  verifyUtxos,
16309
16392
  waitForRoot,
16393
+ walletAuthTransactionMessageBinds,
16310
16394
  withShieldRetries,
16311
16395
  withTiming,
16312
16396
  withdrawFeeFor