shinjuku-shield 0.3.191 → 0.3.192

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/README.md CHANGED
@@ -6,8 +6,8 @@ answers privately, in a terminal chat or for your agent app. Its `mcp`
6
6
  command runs a local MCP server (stdio) for your agent. Your keys never
7
7
  leave your machine.
8
8
 
9
- This is version 0.3.191. The command is `shinjuku`. `shinjuku-shield`
10
- is the one package that holds the wallet. `shinjuku-shielded` 0.3.191,
9
+ This is version 0.3.192. The command is `shinjuku`. `shinjuku-shield`
10
+ is the one package that holds the wallet. `shinjuku-shielded` 0.3.192,
11
11
  its older npm name, is a small package that runs this package at the same
12
12
  version, so wallets installed under it keep updating (0.3.186 and earlier
13
13
  versions of `shinjuku-shielded` hold the same files as this package). New
@@ -16,7 +16,7 @@ installs use `shinjuku`.
16
16
  ## Set up
17
17
 
18
18
  ```sh
19
- npx -y shinjuku@0.3.191 setup
19
+ npx -y shinjuku@0.3.192 setup
20
20
  ```
21
21
 
22
22
  Setup offers to install the `shinjuku` command and, on Windows, adds npm's
@@ -39,13 +39,13 @@ Every wallet command works after `shinjuku`, for example `shinjuku balance`,
39
39
  Claude Code:
40
40
 
41
41
  ```sh
42
- claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.191 mcp
42
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.192 mcp
43
43
  ```
44
44
 
45
45
  Claude Desktop (`claude_desktop_config.json`) or Cursor (`~/.cursor/mcp.json`):
46
46
 
47
47
  ```json
48
- { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.191", "mcp"] } } }
48
+ { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.192", "mcp"] } } }
49
49
  ```
50
50
 
51
51
  On native Windows, if the host cannot find `npx`, use `"command": "cmd"` and
@@ -58,7 +58,7 @@ Codex (the Codex app and Codex CLI read the same file, `~/.codex/config.toml`):
58
58
  ```toml
59
59
  [mcp_servers.shinjuku]
60
60
  command = "npx"
61
- args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.191", "mcp"]
61
+ args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.192", "mcp"]
62
62
  startup_timeout_sec = 120
63
63
  tool_timeout_sec = 300
64
64
  ```
package/manifest.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schema": "carbon-shielded-wallet/bundle-manifest/v1",
3
3
  "file": "shinjuku-wallet.mjs",
4
- "sha256": "9491b5e02a253f9ee9f72f83f676c678b2330dc8f7655eeeb6f1fcc4fd324a47",
5
- "bytes": 9347298,
6
- "sourceCommit": "6cbd06bec149f61cc70cb3a3811e99e07da6b153",
4
+ "sha256": "bceca3110047bb17e9d30e8a10e2066f2d180f4d5b111bac1c6a5a2b1d88e625",
5
+ "bytes": 9362565,
6
+ "sourceCommit": "dfae92ecabe3f96ff2d001413a6fea7b8706263b",
7
7
  "sourceDirty": false,
8
8
  "installRecordMatchesLockfile": true,
9
9
  "releaseRule": "valid only when two fresh npm ci --ignore-scripts builds on different OSes give the same sha256; installRecordMatchesLockfile true means every entry npm installed equals its package-lock.json entry and every entry not marked optional, devOptional included, is installed: an optional entry (a package for another platform) may be absent",
@@ -1040,8 +1040,8 @@
1040
1040
  ],
1041
1041
  "seller": {
1042
1042
  "file": "shinjuku-seller.mjs",
1043
- "sha256": "b960e547761733a8fd473ac3189d7b8dd3941c729b64a69c37c8d98bc0f503c0",
1044
- "bytes": 3683810,
1043
+ "sha256": "c43e1b6f5709414a94e7e6b4d03be4f1147a218bb75b59c7f5c5399c611f7647",
1044
+ "bytes": 3692232,
1045
1045
  "entry": "wallet/src/seller/exact/index.mjs",
1046
1046
  "external": [
1047
1047
  "@x402/core/http",
@@ -1932,5 +1932,5 @@
1932
1932
  }
1933
1933
  ]
1934
1934
  },
1935
- "publishedAt": "2026-11-07T22:03:35.105Z"
1935
+ "publishedAt": "2026-11-08T10:46:16.060Z"
1936
1936
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.191",
3
+ "version": "0.3.192",
4
4
  "mcpName": "io.github.ShinjukuStaition/shinjuku-shield",
5
5
  "description": "Shinjuku Shield, private x402 payments on Solana: the self-custody wallet CLI and its MCP server. Shield, pay, and unshield USDC from any MCP agent, under caps you set.",
6
- "shinjukuRelease": "9491b5e0",
7
- "shinjukuSha256": "9491b5e02a253f9ee9f72f83f676c678b2330dc8f7655eeeb6f1fcc4fd324a47",
6
+ "shinjukuRelease": "bceca311",
7
+ "shinjukuSha256": "bceca3110047bb17e9d30e8a10e2066f2d180f4d5b111bac1c6a5a2b1d88e625",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shield",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -39901,6 +39901,7 @@ var init_errorCodes = __esm({
39901
39901
  "inbound_sweep_reclaimed",
39902
39902
  "relay_inbound_above_pool_limit",
39903
39903
  "relay_memo_not_stored_yet",
39904
+ "relay_memo_refused_422",
39904
39905
  "tor_history_unrouted",
39905
39906
  "seller_tor_history_unrouted",
39906
39907
  "x_payment_network_not_offered",
@@ -49245,7 +49246,9 @@ function createCompactHistoryCacheStore({ path, hmacKey, now }) {
49245
49246
  accounts: [...state2.initialization.accounts],
49246
49247
  data: Buffer.from(state2.initialization.data).toString("hex")
49247
49248
  },
49248
- ...state2.attestation ? { attestation: serializeAttestation(state2.attestation) } : {}
49249
+ ...state2.attestation ? { attestation: serializeAttestation(state2.attestation) } : {},
49250
+ // PLAN AB263: the fold of the records (compact.mjs compactFoldForCache), inside the same tag.
49251
+ ...compactFoldShape(state2.fold) ? { fold: state2.fold } : {}
49249
49252
  }),
49250
49253
  deserialize: (value) => {
49251
49254
  const init = value?.initialization;
@@ -49266,12 +49269,17 @@ function createCompactHistoryCacheStore({ path, hmacKey, now }) {
49266
49269
  accounts: Object.freeze([...init.accounts]),
49267
49270
  data: Buffer.from(init.data, "hex")
49268
49271
  }),
49269
- ...value.attestation === void 0 ? {} : { attestation: deserializeAttestation(value.attestation) }
49272
+ ...value.attestation === void 0 ? {} : { attestation: deserializeAttestation(value.attestation) },
49273
+ // A fold of another shape is left out (the next start pre-folds); it never refuses the records.
49274
+ ...compactFoldShape(value.fold) ? { fold: value.fold } : {}
49270
49275
  };
49271
49276
  }
49272
49277
  });
49273
49278
  }
49274
- var P03_HISTORY_CACHE_SCHEMA, positionOrNull, encodeTagged, decodeTagged, deserializeAttestation, serializeAttestation, FOLD_DECIMAL, serializeFold, deserializeFold, serializeState, deserializeState, foldOf, P03_COMPACT_HISTORY_CACHE_SCHEMA;
49279
+ function compactFoldShape(fold) {
49280
+ return fold !== null && typeof fold === "object" && Number.isSafeInteger(fold.count) && fold.count > 0 && foldNodes(fold.filled) && Array.isArray(fold.checkpoints) && fold.checkpoints.every((entry) => Array.isArray(entry) && entry.length === 2 && Number.isSafeInteger(entry[0]) && foldNodes(entry[1])) && Array.isArray(fold.roots) && fold.roots.every((entry) => Array.isArray(entry) && entry.length === 2 && Number.isSafeInteger(entry[0]) && typeof entry[1] === "string" && FOLD_NODE.test(entry[1]));
49281
+ }
49282
+ var P03_HISTORY_CACHE_SCHEMA, positionOrNull, encodeTagged, decodeTagged, deserializeAttestation, serializeAttestation, FOLD_DECIMAL, serializeFold, deserializeFold, serializeState, deserializeState, foldOf, P03_COMPACT_HISTORY_CACHE_SCHEMA, FOLD_NODE, foldNodes;
49275
49283
  var init_cacheStore = __esm({
49276
49284
  "wallet/src/history/cacheStore.mjs"() {
49277
49285
  "use strict";
@@ -49376,6 +49384,8 @@ var init_cacheStore = __esm({
49376
49384
  return fold === void 0 ? {} : { fold };
49377
49385
  };
49378
49386
  P03_COMPACT_HISTORY_CACHE_SCHEMA = "carbon-shielded-x402/compact-history-cache/v1";
49387
+ FOLD_NODE = /^[0-9a-f]{64}$/;
49388
+ foldNodes = (nodes) => Array.isArray(nodes) && nodes.every((node2) => node2 === null || typeof node2 === "string" && FOLD_NODE.test(node2));
49379
49389
  }
49380
49390
  });
49381
49391
 
@@ -52678,19 +52688,29 @@ function foldCompactLeavesFrom(leaves, counts, frontier, resume) {
52678
52688
  if (counts.has(0)) roots.set(0, zero[OUTER_DEPTH2]);
52679
52689
  let position3 = 0;
52680
52690
  let appended = 0;
52691
+ const checkpoints = [];
52681
52692
  const step = () => {
52682
52693
  appendCompactLeaf(filled, leaves[position3], position3);
52683
52694
  appended += 1;
52684
52695
  position3 += 1;
52685
52696
  if (counts.has(position3)) roots.set(position3, compactRootAt(filled, position3));
52697
+ if (position3 % FOLD_CHECKPOINT_EVERY === 0) checkpoints[position3] = filled.slice();
52686
52698
  };
52687
52699
  if (resume !== void 0) {
52688
52700
  let below = 0;
52689
52701
  for (const at of counts) {
52690
52702
  if (at <= 0 || at > resume.at) continue;
52691
52703
  const checkpoint = at === resume.at ? resume.filled : resume.checkpoints?.[at];
52692
- if (checkpoint !== void 0) roots.set(at, compactRootAt(checkpoint, at));
52693
- else if (at > below) below = at;
52704
+ if (checkpoint !== void 0) {
52705
+ roots.set(at, compactRootAt(checkpoint, at));
52706
+ continue;
52707
+ }
52708
+ const near = nearestCheckpointBelow(resume.checkpoints, at);
52709
+ if (near !== void 0) {
52710
+ const stepped = near.filled.slice();
52711
+ for (let p = near.at; p < at; p += 1) appendCompactLeaf(stepped, leaves[p], p);
52712
+ roots.set(at, compactRootAt(stepped, at));
52713
+ } else if (at > below) below = at;
52694
52714
  }
52695
52715
  while (position3 < below) step();
52696
52716
  filled = resume.filled.slice();
@@ -52702,7 +52722,27 @@ function foldCompactLeavesFrom(leaves, counts, frontier, resume) {
52702
52722
  frontier[level] = bitAt(leaves.length, level) === 1 ? filled[level] : zero[level];
52703
52723
  }
52704
52724
  }
52705
- return { roots, filled, appended };
52725
+ return { roots, filled, appended, checkpoints };
52726
+ }
52727
+ function nearestCheckpointBelow(checkpoints, count2) {
52728
+ if (!Array.isArray(checkpoints)) return void 0;
52729
+ const stop = Math.max(0, count2 - 2 * FOLD_CHECKPOINT_EVERY);
52730
+ for (let at = Math.min(count2 - 1, checkpoints.length - 1); at >= stop; at -= 1) {
52731
+ if (at === 0) return { at: 0, filled: new Array(OUTER_DEPTH2) };
52732
+ const filled = checkpoints[at];
52733
+ if (Array.isArray(filled) && filled.length === OUTER_DEPTH2) return { at, filled };
52734
+ }
52735
+ return void 0;
52736
+ }
52737
+ function checkpointsCover(checkpoints, count2) {
52738
+ if (!Array.isArray(checkpoints)) return false;
52739
+ let last = 0;
52740
+ for (let at = 1; at <= count2; at += 1) {
52741
+ const filled = checkpoints[at];
52742
+ if (Array.isArray(filled) && filled.length === OUTER_DEPTH2) last = at;
52743
+ else if (at - last > 2 * FOLD_CHECKPOINT_EVERY) return false;
52744
+ }
52745
+ return true;
52706
52746
  }
52707
52747
  function appendCompactLeaf(filled, leaf, position3) {
52708
52748
  let node2 = leaf;
@@ -52752,12 +52792,17 @@ function foldCompactLeavesReusing(pool2, leaves, counts, { frontier, fresh = /*
52752
52792
  kept2.set(at, root);
52753
52793
  }
52754
52794
  }
52755
- lastFolds.set(pool2, {
52756
- leaves: leaves.slice(),
52757
- roots: kept2,
52758
- filled: folded.filled,
52759
- ...resume?.checkpoints !== void 0 ? { checkpoints: resume.checkpoints } : {}
52795
+ const checkpoints = new Array(leaves.length + 1);
52796
+ if (prior !== void 0 && Array.isArray(prior.checkpoints)) {
52797
+ for (let at = 1; at <= Math.min(common, prior.checkpoints.length - 1); at += 1) {
52798
+ if (prior.checkpoints[at] !== void 0) checkpoints[at] = prior.checkpoints[at];
52799
+ }
52800
+ }
52801
+ folded.checkpoints.forEach((filled, at) => {
52802
+ if (filled !== void 0) checkpoints[at] = filled;
52760
52803
  });
52804
+ checkpoints[leaves.length] = folded.filled;
52805
+ lastFolds.set(pool2, { leaves: leaves.slice(), roots: kept2, filled: folded.filled, checkpoints });
52761
52806
  return roots;
52762
52807
  }
52763
52808
  function startCompactPreFold(pool2, cached) {
@@ -52785,6 +52830,11 @@ function startCompactPreFold(pool2, cached) {
52785
52830
  if (Array.isArray(anchorCounts)) {
52786
52831
  for (const at of anchorCounts) if (Number.isSafeInteger(at) && at > 0 && at <= count2) counts.add(at);
52787
52832
  }
52833
+ if (seedCompactFoldFromCache(pool2, cached, count2, cachedRoot, counts)) {
52834
+ markPhase("compact-prefold-seeded");
52835
+ prewarmP03OuterTreeLeavesOnWorker(lastFolds.get(pool2).leaves);
52836
+ return void 0;
52837
+ }
52788
52838
  const leaves = [];
52789
52839
  const filled = new Array(OUTER_DEPTH2);
52790
52840
  const checkpoints = new Array(count2 + 1);
@@ -52822,6 +52872,70 @@ function startCompactPreFold(pool2, cached) {
52822
52872
  preFolds.set(pool2, preFold);
52823
52873
  return preFold;
52824
52874
  }
52875
+ function seedCompactFoldFromCache(pool2, cached, count2, cachedRoot, counts) {
52876
+ try {
52877
+ const fold = cached.fold;
52878
+ if (fold === void 0 || fold === null || fold.count !== count2 || lastFolds.has(pool2)) return false;
52879
+ const filled = foldFrontier(fold.filled);
52880
+ if (compactRootAt(filled, count2) !== cachedRoot) return false;
52881
+ const records = cached.served.records;
52882
+ const leaves = new Array(count2);
52883
+ for (let position3 = 0; position3 < count2; position3 += 1) leaves[position3] = foldNode(records[position3]?.outCommitment ?? "");
52884
+ if (leaves.some((leaf) => leaf === void 0)) return false;
52885
+ const checkpoints = new Array(count2 + 1);
52886
+ for (const [at, nodes] of Array.isArray(fold.checkpoints) ? fold.checkpoints : []) {
52887
+ if (Number.isSafeInteger(at) && at > 0 && at < count2) checkpoints[at] = foldFrontier(nodes);
52888
+ }
52889
+ checkpoints[count2] = filled;
52890
+ if (!checkpointsCover(checkpoints, count2)) return false;
52891
+ const roots = /* @__PURE__ */ new Map([[count2, cachedRoot]]);
52892
+ for (const [at, hex3] of Array.isArray(fold.roots) ? fold.roots : []) {
52893
+ if (Number.isSafeInteger(at) && at > 0 && at < count2 && counts.has(at)) roots.set(at, foldNode(hex3));
52894
+ }
52895
+ for (const at of counts) {
52896
+ if (roots.has(at)) continue;
52897
+ const near = nearestCheckpointBelow(checkpoints, at);
52898
+ if (near === void 0) continue;
52899
+ const stepped = near.filled.slice();
52900
+ for (let p = near.at; p < at; p += 1) appendCompactLeaf(stepped, leaves[p], p);
52901
+ roots.set(at, compactRootAt(stepped, at));
52902
+ }
52903
+ if (lastFolds.has(pool2)) return false;
52904
+ lastFolds.set(pool2, { leaves, roots, filled, checkpoints });
52905
+ return true;
52906
+ } catch {
52907
+ return false;
52908
+ }
52909
+ }
52910
+ function compactFoldForCache(pool2, count2, currentRoot, anchorCounts) {
52911
+ try {
52912
+ const last = lastFolds.get(pool2);
52913
+ if (last === void 0 || !Array.isArray(last.filled) || last.filled.length !== OUTER_DEPTH2 || last.leaves.length !== count2) return void 0;
52914
+ if (compactRootAt(last.filled, count2) !== currentRoot) return void 0;
52915
+ const nodes = (filled) => Array.from({ length: OUTER_DEPTH2 }, (_, level) => filled[level] === void 0 ? null : foldHex(filled[level]));
52916
+ const checkpoints = [];
52917
+ const kept2 = new Array(count2 + 1);
52918
+ kept2[count2] = last.filled;
52919
+ if (Array.isArray(last.checkpoints)) {
52920
+ let block = -1;
52921
+ for (let at = 1; at < Math.min(count2, last.checkpoints.length); at += 1) {
52922
+ const filled = last.checkpoints[at];
52923
+ if (!Array.isArray(filled) || filled.length !== OUTER_DEPTH2 || Math.floor(at / FOLD_CHECKPOINT_EVERY) === block) continue;
52924
+ block = Math.floor(at / FOLD_CHECKPOINT_EVERY);
52925
+ kept2[at] = filled;
52926
+ checkpoints.push([at, nodes(filled)]);
52927
+ }
52928
+ }
52929
+ if (!checkpointsCover(kept2, count2)) return void 0;
52930
+ const roots = [];
52931
+ for (const at of new Set(anchorCounts)) {
52932
+ if (Number.isSafeInteger(at) && at > 0 && at < count2 && last.roots.has(at)) roots.push([at, foldHex(last.roots.get(at))]);
52933
+ }
52934
+ return { count: count2, filled: nodes(last.filled), checkpoints, roots };
52935
+ } catch {
52936
+ return void 0;
52937
+ }
52938
+ }
52825
52939
  function startCompactE1Candidate(programId, pool2, cached, preFold) {
52826
52940
  const records = cached?.served?.records;
52827
52941
  if (!Array.isArray(records) || records.length === 0) return void 0;
@@ -52858,7 +52972,7 @@ function dropCompactCacheRecords(pool2, cache) {
52858
52972
  return (async () => {
52859
52973
  const current = await cache.load();
52860
52974
  if (!current || current.pool !== pool2) return;
52861
- const { savedAt, served, ...rest } = current;
52975
+ const { savedAt, served, fold: _fold, ...rest } = current;
52862
52976
  await cache.save({ ...rest, served: servedWithoutRecords(served) }, { savedAt });
52863
52977
  })().catch(() => {
52864
52978
  });
@@ -54333,6 +54447,9 @@ async function compactP03HistoryReportRun({
54333
54447
  if (cache) {
54334
54448
  if (dropping !== void 0) await dropping;
54335
54449
  try {
54450
+ const anchorCounts = [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))];
54451
+ const withRecords = !(prefixMismatch && !readAgain);
54452
+ const fold = withRecords && Array.isArray(compact.served?.records) ? compactFoldForCache(poolKey.toBase58(), compact.served.records.length, snapshot.currentRoot, anchorCounts) : void 0;
54336
54453
  await (saving = Promise.resolve().then(() => cache.save({
54337
54454
  programId: program.toBase58(),
54338
54455
  pool: poolKey.toBase58(),
@@ -54343,11 +54460,12 @@ async function compactP03HistoryReportRun({
54343
54460
  currentRoot: snapshot.currentRoot.toString(),
54344
54461
  // The anchor counts of this pool account (public; 2026-10-21, B): the next process's
54345
54462
  // pre-fold hashes their roots ahead. Counts only: every root is checked live again.
54346
- anchorCounts: [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))]
54463
+ anchorCounts
54347
54464
  },
54348
- served: prefixMismatch && !readAgain ? servedWithoutRecords(compact.served) : compact.served,
54465
+ served: withRecords ? compact.served : servedWithoutRecords(compact.served),
54349
54466
  initialization,
54350
- attestation: attested.attestation
54467
+ attestation: attested.attestation,
54468
+ ...fold !== void 0 && compact.served.records.length === Number(snapshot.currentIndex / SUBTREE_LEAVES3) ? { fold } : {}
54351
54469
  })).then(() => {
54352
54470
  if (readAgain) replaced = true;
54353
54471
  }));
@@ -54371,7 +54489,7 @@ async function tryCompactP03HistoryReport(options) {
54371
54489
  return { ok: false, reason, ...detail ? { detail } : {}, error };
54372
54490
  }
54373
54491
  }
54374
- var import_web398, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX3, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse2, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, servedWithoutRecords, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, listInFlight, LIST_HEAD_TIMEOUT_MS, LIST_HEAD_STALLED, LIST_BODY_STALL_MS, LIST_TOTAL_CAP_MS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, P03_COMPACT_TAIL_GRID, TAIL_RETRY_REFUSALS, tailFrom, sameJson, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, compactReportsRunning;
54492
+ var import_web398, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX3, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse2, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, FOLD_CHECKPOINT_EVERY, foldNode, foldFrontier, foldHex, servedWithoutRecords, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, listInFlight, LIST_HEAD_TIMEOUT_MS, LIST_HEAD_STALLED, LIST_BODY_STALL_MS, LIST_TOTAL_CAP_MS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, P03_COMPACT_TAIL_GRID, TAIL_RETRY_REFUSALS, tailFrom, sameJson, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, compactReportsRunning;
54375
54493
  var init_compact = __esm({
54376
54494
  "wallet/src/history/compact.mjs"() {
54377
54495
  "use strict";
@@ -54487,6 +54605,24 @@ var init_compact = __esm({
54487
54605
  lastFolds = /* @__PURE__ */ new Map();
54488
54606
  PRE_FOLD_SLICE_MS = 8;
54489
54607
  preFolds = /* @__PURE__ */ new Map();
54608
+ FOLD_CHECKPOINT_EVERY = 64;
54609
+ foldNode = (hex3) => {
54610
+ if (hex3 === null) return void 0;
54611
+ if (typeof hex3 !== "string" || !HEX64.test(hex3)) throw new Error("fold");
54612
+ const value = BigInt(`0x${hex3}`);
54613
+ if (value >= FIELD_MODULUS5) throw new Error("fold");
54614
+ return value;
54615
+ };
54616
+ foldFrontier = (nodes) => {
54617
+ if (!Array.isArray(nodes) || nodes.length !== OUTER_DEPTH2) throw new Error("fold");
54618
+ const filled = new Array(OUTER_DEPTH2);
54619
+ for (let level = 0; level < OUTER_DEPTH2; level += 1) {
54620
+ const node2 = foldNode(nodes[level]);
54621
+ if (node2 !== void 0) filled[level] = node2;
54622
+ }
54623
+ return filled;
54624
+ };
54625
+ foldHex = (value) => value.toString(16).padStart(64, "0");
54490
54626
  servedWithoutRecords = (served) => ({
54491
54627
  records: [],
54492
54628
  initialization: served.initialization,
@@ -58048,7 +58184,14 @@ async function publishInboundMemoFirst({ serviceUrl: serviceUrl2, record, deps,
58048
58184
  });
58049
58185
  } catch (error) {
58050
58186
  const code = String(error?.message ?? "").replace(/^p03_deposit_/, "");
58051
- if (EARLY_MEMO_WAITS.has(code)) fail13("relay_memo_not_stored_yet");
58187
+ if (code === "memo_publish_refused_422") {
58188
+ throw new Error("p03_deposit_relay_memo_refused_422: Shinjuku's server refused to store this deposit's private record (HTTP 422), so no USDC moved");
58189
+ }
58190
+ if (EARLY_MEMO_WAITS.has(code)) {
58191
+ const answer = EARLY_MEMO_WAITS.get(code);
58192
+ const words = `Shinjuku's server ${answer.words} when the wallet stored this deposit's private record, so no USDC moved`;
58193
+ throw new Error(answer.status ? `p03_deposit_relay_memo_not_stored_yet${answer.status} (${words})` : `p03_deposit_relay_memo_not_stored_yet: ${words}`);
58194
+ }
58052
58195
  throw error;
58053
58196
  }
58054
58197
  }
@@ -58977,7 +59120,11 @@ var init_deposit = __esm({
58977
59120
  MEMO_FIRST_FALLBACKS = /* @__PURE__ */ new Set(["deposit_memo_first_unavailable", "deposit_memo_first_record_started_without"]);
58978
59121
  EARLY_MEMO_ATTEMPTS = 3;
58979
59122
  HELD_MEMO_READBACK_MS = 45e3;
58980
- EARLY_MEMO_WAITS = /* @__PURE__ */ new Set(["memo_publish_no_answer", "memo_publish_refused_422", "memo_publish_refused_429", "memo_publish_refused_503"]);
59123
+ EARLY_MEMO_WAITS = /* @__PURE__ */ new Map([
59124
+ ["memo_publish_no_answer", { status: "", words: "did not answer" }],
59125
+ ["memo_publish_refused_429", { status: ":429", words: "asked the wallet to slow down (HTTP 429)" }],
59126
+ ["memo_publish_refused_503", { status: ":503", words: "was not ready (HTTP 503)" }]
59127
+ ]);
58981
59128
  BUFFER_SIGN_REASONS = /* @__PURE__ */ new Set([
58982
59129
  "deposit_buffer_sign_with_owner_then_same_request",
58983
59130
  "deposit_buffer_resign_with_owner_then_same_request"
@@ -69023,7 +69170,7 @@ function createInboundSweeper({ store, book, connection, programId, proofTools,
69023
69170
  kick();
69024
69171
  return Object.freeze({ enqueue, drain, close });
69025
69172
  }
69026
- var INBOUND_SWEEP_LOCK_WAIT_MS, TRANSIENT_TRIES, TRANSIENT_WAIT_MS, SWEEP_STATES, RECLAIMED, inboundDepositId, TRANSIENT_CODES, PROVE_AGAIN, nowSeconds3, delay2;
69173
+ var INBOUND_SWEEP_LOCK_WAIT_MS, TRANSIENT_TRIES, TRANSIENT_WAIT_MS, SWEEP_STATES, RECLAIMED, inboundDepositId, MEMO_REFUSED, TRANSIENT_CODES, PROVE_AGAIN, nowSeconds3, delay2;
69027
69174
  var init_sweep = __esm({
69028
69175
  "wallet/src/inbound/sweep.mjs"() {
69029
69176
  "use strict";
@@ -69034,6 +69181,7 @@ var init_sweep = __esm({
69034
69181
  SWEEP_STATES = Object.freeze(["paid", "sweeping"]);
69035
69182
  RECLAIMED = "inbound_sweep_reclaimed";
69036
69183
  inboundDepositId = (index) => `inbound-${index}`;
69184
+ MEMO_REFUSED = "p03_deposit_relay_memo_refused_422";
69037
69185
  TRANSIENT_CODES = /* @__PURE__ */ new Set([
69038
69186
  "p03_deposit_relay_inbound_not_funded_yet",
69039
69187
  "p03_deposit_relay_not_settled_rerun_same_id",
@@ -69043,7 +69191,10 @@ var init_sweep = __esm({
69043
69191
  // The facilitator still holds an earlier attempt of this address: the next try resends the same proof body.
69044
69192
  "p03_deposit_relay_refused_deposit_inbound_attempt_in_progress",
69045
69193
  // The memo service did not store the memo yet (no answer, or the deposit's proof not journaled yet): nothing moved.
69046
- "p03_deposit_relay_memo_not_stored_yet"
69194
+ "p03_deposit_relay_memo_not_stored_yet",
69195
+ // The memo service refused the record (422): a fault on Shinjuku's side (AB260, 2026-11-08), not the seller's. Nothing
69196
+ // moved, so the sale keeps trying (inboundSweepFailure names it) instead of sending the seller to a public take-back.
69197
+ MEMO_REFUSED
69047
69198
  ]);
69048
69199
  PROVE_AGAIN = "p03_deposit_relay_refused_deposit_inbound_balance_changed_prove_again";
69049
69200
  nowSeconds3 = () => Math.floor(Date.now() / 1e3);
@@ -70560,7 +70711,12 @@ async function sellerTor(recorded, home) {
70560
70711
  if (home) {
70561
70712
  const current = readSetupConfig(home)?.torTunnel ?? recorded;
70562
70713
  try {
70563
- tunnel = await ensureWalletTor(current, { env: { ...process.env, SHIELDED_WALLET_HOME: home }, explicit: true });
70714
+ tunnel = await ensureWalletTor(current, {
70715
+ env: { ...process.env, SHIELDED_WALLET_HOME: home },
70716
+ explicit: true,
70717
+ say: (line) => process.stderr.write(`${line}
70718
+ `)
70719
+ });
70564
70720
  } catch (error) {
70565
70721
  if (!error?.managedTor) throw error;
70566
70722
  throw new SellerRefusal("seller_tor_not_running", `${String(error.message).replace(/^managed_tor_failed:\s*/, "")}
@@ -57664,7 +57664,9 @@ function createCompactHistoryCacheStore({ path, hmacKey, now }) {
57664
57664
  accounts: [...state2.initialization.accounts],
57665
57665
  data: Buffer.from(state2.initialization.data).toString("hex")
57666
57666
  },
57667
- ...state2.attestation ? { attestation: serializeAttestation(state2.attestation) } : {}
57667
+ ...state2.attestation ? { attestation: serializeAttestation(state2.attestation) } : {},
57668
+ // PLAN AB263: the fold of the records (compact.mjs compactFoldForCache), inside the same tag.
57669
+ ...compactFoldShape(state2.fold) ? { fold: state2.fold } : {}
57668
57670
  }),
57669
57671
  deserialize: (value2) => {
57670
57672
  const init = value2?.initialization;
@@ -57685,12 +57687,17 @@ function createCompactHistoryCacheStore({ path, hmacKey, now }) {
57685
57687
  accounts: Object.freeze([...init.accounts]),
57686
57688
  data: Buffer.from(init.data, "hex")
57687
57689
  }),
57688
- ...value2.attestation === void 0 ? {} : { attestation: deserializeAttestation(value2.attestation) }
57690
+ ...value2.attestation === void 0 ? {} : { attestation: deserializeAttestation(value2.attestation) },
57691
+ // A fold of another shape is left out (the next start pre-folds); it never refuses the records.
57692
+ ...compactFoldShape(value2.fold) ? { fold: value2.fold } : {}
57689
57693
  };
57690
57694
  }
57691
57695
  });
57692
57696
  }
57693
- var P03_HISTORY_CACHE_SCHEMA, positionOrNull, encodeTagged, decodeTagged, deserializeAttestation, serializeAttestation, FOLD_DECIMAL, serializeFold, deserializeFold, serializeState, deserializeState, foldOf, P03_COMPACT_HISTORY_CACHE_SCHEMA;
57697
+ function compactFoldShape(fold) {
57698
+ return fold !== null && typeof fold === "object" && Number.isSafeInteger(fold.count) && fold.count > 0 && foldNodes(fold.filled) && Array.isArray(fold.checkpoints) && fold.checkpoints.every((entry) => Array.isArray(entry) && entry.length === 2 && Number.isSafeInteger(entry[0]) && foldNodes(entry[1])) && Array.isArray(fold.roots) && fold.roots.every((entry) => Array.isArray(entry) && entry.length === 2 && Number.isSafeInteger(entry[0]) && typeof entry[1] === "string" && FOLD_NODE.test(entry[1]));
57699
+ }
57700
+ var P03_HISTORY_CACHE_SCHEMA, positionOrNull, encodeTagged, decodeTagged, deserializeAttestation, serializeAttestation, FOLD_DECIMAL, serializeFold, deserializeFold, serializeState, deserializeState, foldOf, P03_COMPACT_HISTORY_CACHE_SCHEMA, FOLD_NODE, foldNodes;
57694
57701
  var init_cacheStore = __esm({
57695
57702
  "wallet/src/history/cacheStore.mjs"() {
57696
57703
  "use strict";
@@ -57795,6 +57802,8 @@ var init_cacheStore = __esm({
57795
57802
  return fold === void 0 ? {} : { fold };
57796
57803
  };
57797
57804
  P03_COMPACT_HISTORY_CACHE_SCHEMA = "carbon-shielded-x402/compact-history-cache/v1";
57805
+ FOLD_NODE = /^[0-9a-f]{64}$/;
57806
+ foldNodes = (nodes) => Array.isArray(nodes) && nodes.every((node3) => node3 === null || typeof node3 === "string" && FOLD_NODE.test(node3));
57798
57807
  }
57799
57808
  });
57800
57809
 
@@ -61368,19 +61377,29 @@ function foldCompactLeavesFrom(leaves, counts, frontier, resume) {
61368
61377
  if (counts.has(0)) roots.set(0, zero[OUTER_DEPTH2]);
61369
61378
  let position3 = 0;
61370
61379
  let appended = 0;
61380
+ const checkpoints = [];
61371
61381
  const step = () => {
61372
61382
  appendCompactLeaf(filled, leaves[position3], position3);
61373
61383
  appended += 1;
61374
61384
  position3 += 1;
61375
61385
  if (counts.has(position3)) roots.set(position3, compactRootAt(filled, position3));
61386
+ if (position3 % FOLD_CHECKPOINT_EVERY === 0) checkpoints[position3] = filled.slice();
61376
61387
  };
61377
61388
  if (resume !== void 0) {
61378
61389
  let below2 = 0;
61379
61390
  for (const at of counts) {
61380
61391
  if (at <= 0 || at > resume.at) continue;
61381
61392
  const checkpoint = at === resume.at ? resume.filled : resume.checkpoints?.[at];
61382
- if (checkpoint !== void 0) roots.set(at, compactRootAt(checkpoint, at));
61383
- else if (at > below2) below2 = at;
61393
+ if (checkpoint !== void 0) {
61394
+ roots.set(at, compactRootAt(checkpoint, at));
61395
+ continue;
61396
+ }
61397
+ const near = nearestCheckpointBelow(resume.checkpoints, at);
61398
+ if (near !== void 0) {
61399
+ const stepped = near.filled.slice();
61400
+ for (let p = near.at; p < at; p += 1) appendCompactLeaf(stepped, leaves[p], p);
61401
+ roots.set(at, compactRootAt(stepped, at));
61402
+ } else if (at > below2) below2 = at;
61384
61403
  }
61385
61404
  while (position3 < below2) step();
61386
61405
  filled = resume.filled.slice();
@@ -61392,7 +61411,27 @@ function foldCompactLeavesFrom(leaves, counts, frontier, resume) {
61392
61411
  frontier[level] = bitAt(leaves.length, level) === 1 ? filled[level] : zero[level];
61393
61412
  }
61394
61413
  }
61395
- return { roots, filled, appended };
61414
+ return { roots, filled, appended, checkpoints };
61415
+ }
61416
+ function nearestCheckpointBelow(checkpoints, count3) {
61417
+ if (!Array.isArray(checkpoints)) return void 0;
61418
+ const stop2 = Math.max(0, count3 - 2 * FOLD_CHECKPOINT_EVERY);
61419
+ for (let at = Math.min(count3 - 1, checkpoints.length - 1); at >= stop2; at -= 1) {
61420
+ if (at === 0) return { at: 0, filled: new Array(OUTER_DEPTH2) };
61421
+ const filled = checkpoints[at];
61422
+ if (Array.isArray(filled) && filled.length === OUTER_DEPTH2) return { at, filled };
61423
+ }
61424
+ return void 0;
61425
+ }
61426
+ function checkpointsCover(checkpoints, count3) {
61427
+ if (!Array.isArray(checkpoints)) return false;
61428
+ let last = 0;
61429
+ for (let at = 1; at <= count3; at += 1) {
61430
+ const filled = checkpoints[at];
61431
+ if (Array.isArray(filled) && filled.length === OUTER_DEPTH2) last = at;
61432
+ else if (at - last > 2 * FOLD_CHECKPOINT_EVERY) return false;
61433
+ }
61434
+ return true;
61396
61435
  }
61397
61436
  function appendCompactLeaf(filled, leaf2, position3) {
61398
61437
  let node3 = leaf2;
@@ -61442,12 +61481,17 @@ function foldCompactLeavesReusing(pool2, leaves, counts, { frontier, fresh = /*
61442
61481
  kept3.set(at, root);
61443
61482
  }
61444
61483
  }
61445
- lastFolds.set(pool2, {
61446
- leaves: leaves.slice(),
61447
- roots: kept3,
61448
- filled: folded.filled,
61449
- ...resume?.checkpoints !== void 0 ? { checkpoints: resume.checkpoints } : {}
61484
+ const checkpoints = new Array(leaves.length + 1);
61485
+ if (prior !== void 0 && Array.isArray(prior.checkpoints)) {
61486
+ for (let at = 1; at <= Math.min(common, prior.checkpoints.length - 1); at += 1) {
61487
+ if (prior.checkpoints[at] !== void 0) checkpoints[at] = prior.checkpoints[at];
61488
+ }
61489
+ }
61490
+ folded.checkpoints.forEach((filled, at) => {
61491
+ if (filled !== void 0) checkpoints[at] = filled;
61450
61492
  });
61493
+ checkpoints[leaves.length] = folded.filled;
61494
+ lastFolds.set(pool2, { leaves: leaves.slice(), roots: kept3, filled: folded.filled, checkpoints });
61451
61495
  return roots;
61452
61496
  }
61453
61497
  function startCompactPreFold(pool2, cached) {
@@ -61475,6 +61519,11 @@ function startCompactPreFold(pool2, cached) {
61475
61519
  if (Array.isArray(anchorCounts)) {
61476
61520
  for (const at of anchorCounts) if (Number.isSafeInteger(at) && at > 0 && at <= count3) counts.add(at);
61477
61521
  }
61522
+ if (seedCompactFoldFromCache(pool2, cached, count3, cachedRoot, counts)) {
61523
+ markPhase("compact-prefold-seeded");
61524
+ prewarmP03OuterTreeLeavesOnWorker(lastFolds.get(pool2).leaves);
61525
+ return void 0;
61526
+ }
61478
61527
  const leaves = [];
61479
61528
  const filled = new Array(OUTER_DEPTH2);
61480
61529
  const checkpoints = new Array(count3 + 1);
@@ -61512,6 +61561,70 @@ function startCompactPreFold(pool2, cached) {
61512
61561
  preFolds.set(pool2, preFold);
61513
61562
  return preFold;
61514
61563
  }
61564
+ function seedCompactFoldFromCache(pool2, cached, count3, cachedRoot, counts) {
61565
+ try {
61566
+ const fold = cached.fold;
61567
+ if (fold === void 0 || fold === null || fold.count !== count3 || lastFolds.has(pool2)) return false;
61568
+ const filled = foldFrontier(fold.filled);
61569
+ if (compactRootAt(filled, count3) !== cachedRoot) return false;
61570
+ const records = cached.served.records;
61571
+ const leaves = new Array(count3);
61572
+ for (let position3 = 0; position3 < count3; position3 += 1) leaves[position3] = foldNode(records[position3]?.outCommitment ?? "");
61573
+ if (leaves.some((leaf2) => leaf2 === void 0)) return false;
61574
+ const checkpoints = new Array(count3 + 1);
61575
+ for (const [at, nodes] of Array.isArray(fold.checkpoints) ? fold.checkpoints : []) {
61576
+ if (Number.isSafeInteger(at) && at > 0 && at < count3) checkpoints[at] = foldFrontier(nodes);
61577
+ }
61578
+ checkpoints[count3] = filled;
61579
+ if (!checkpointsCover(checkpoints, count3)) return false;
61580
+ const roots = /* @__PURE__ */ new Map([[count3, cachedRoot]]);
61581
+ for (const [at, hex4] of Array.isArray(fold.roots) ? fold.roots : []) {
61582
+ if (Number.isSafeInteger(at) && at > 0 && at < count3 && counts.has(at)) roots.set(at, foldNode(hex4));
61583
+ }
61584
+ for (const at of counts) {
61585
+ if (roots.has(at)) continue;
61586
+ const near = nearestCheckpointBelow(checkpoints, at);
61587
+ if (near === void 0) continue;
61588
+ const stepped = near.filled.slice();
61589
+ for (let p = near.at; p < at; p += 1) appendCompactLeaf(stepped, leaves[p], p);
61590
+ roots.set(at, compactRootAt(stepped, at));
61591
+ }
61592
+ if (lastFolds.has(pool2)) return false;
61593
+ lastFolds.set(pool2, { leaves, roots, filled, checkpoints });
61594
+ return true;
61595
+ } catch {
61596
+ return false;
61597
+ }
61598
+ }
61599
+ function compactFoldForCache(pool2, count3, currentRoot, anchorCounts) {
61600
+ try {
61601
+ const last = lastFolds.get(pool2);
61602
+ if (last === void 0 || !Array.isArray(last.filled) || last.filled.length !== OUTER_DEPTH2 || last.leaves.length !== count3) return void 0;
61603
+ if (compactRootAt(last.filled, count3) !== currentRoot) return void 0;
61604
+ const nodes = (filled) => Array.from({ length: OUTER_DEPTH2 }, (_, level) => filled[level] === void 0 ? null : foldHex(filled[level]));
61605
+ const checkpoints = [];
61606
+ const kept3 = new Array(count3 + 1);
61607
+ kept3[count3] = last.filled;
61608
+ if (Array.isArray(last.checkpoints)) {
61609
+ let block = -1;
61610
+ for (let at = 1; at < Math.min(count3, last.checkpoints.length); at += 1) {
61611
+ const filled = last.checkpoints[at];
61612
+ if (!Array.isArray(filled) || filled.length !== OUTER_DEPTH2 || Math.floor(at / FOLD_CHECKPOINT_EVERY) === block) continue;
61613
+ block = Math.floor(at / FOLD_CHECKPOINT_EVERY);
61614
+ kept3[at] = filled;
61615
+ checkpoints.push([at, nodes(filled)]);
61616
+ }
61617
+ }
61618
+ if (!checkpointsCover(kept3, count3)) return void 0;
61619
+ const roots = [];
61620
+ for (const at of new Set(anchorCounts)) {
61621
+ if (Number.isSafeInteger(at) && at > 0 && at < count3 && last.roots.has(at)) roots.push([at, foldHex(last.roots.get(at))]);
61622
+ }
61623
+ return { count: count3, filled: nodes(last.filled), checkpoints, roots };
61624
+ } catch {
61625
+ return void 0;
61626
+ }
61627
+ }
61515
61628
  function startCompactE1Candidate(programId, pool2, cached, preFold) {
61516
61629
  const records = cached?.served?.records;
61517
61630
  if (!Array.isArray(records) || records.length === 0) return void 0;
@@ -61548,7 +61661,7 @@ function dropCompactCacheRecords(pool2, cache) {
61548
61661
  return (async () => {
61549
61662
  const current = await cache.load();
61550
61663
  if (!current || current.pool !== pool2) return;
61551
- const { savedAt, served, ...rest } = current;
61664
+ const { savedAt, served, fold: _fold, ...rest } = current;
61552
61665
  await cache.save({ ...rest, served: servedWithoutRecords(served) }, { savedAt });
61553
61666
  })().catch(() => {
61554
61667
  });
@@ -63023,6 +63136,9 @@ async function compactP03HistoryReportRun({
63023
63136
  if (cache) {
63024
63137
  if (dropping !== void 0) await dropping;
63025
63138
  try {
63139
+ const anchorCounts = [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))];
63140
+ const withRecords = !(prefixMismatch && !readAgain);
63141
+ const fold = withRecords && Array.isArray(compact.served?.records) ? compactFoldForCache(poolKey.toBase58(), compact.served.records.length, snapshot.currentRoot, anchorCounts) : void 0;
63026
63142
  await (saving = Promise.resolve().then(() => cache.save({
63027
63143
  programId: program.toBase58(),
63028
63144
  pool: poolKey.toBase58(),
@@ -63033,11 +63149,12 @@ async function compactP03HistoryReportRun({
63033
63149
  currentRoot: snapshot.currentRoot.toString(),
63034
63150
  // The anchor counts of this pool account (public; 2026-10-21, B): the next process's
63035
63151
  // pre-fold hashes their roots ahead. Counts only: every root is checked live again.
63036
- anchorCounts: [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))]
63152
+ anchorCounts
63037
63153
  },
63038
- served: prefixMismatch && !readAgain ? servedWithoutRecords(compact.served) : compact.served,
63154
+ served: withRecords ? compact.served : servedWithoutRecords(compact.served),
63039
63155
  initialization,
63040
- attestation: attested.attestation
63156
+ attestation: attested.attestation,
63157
+ ...fold !== void 0 && compact.served.records.length === Number(snapshot.currentIndex / SUBTREE_LEAVES3) ? { fold } : {}
63041
63158
  })).then(() => {
63042
63159
  if (readAgain) replaced = true;
63043
63160
  }));
@@ -63061,7 +63178,7 @@ async function tryCompactP03HistoryReport(options) {
63061
63178
  return { ok: false, reason, ...detail ? { detail } : {}, error };
63062
63179
  }
63063
63180
  }
63064
- var import_web398, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX3, VERSION_1_PREFIX2, HEX642, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, servedWithoutRecords, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, listInFlight, LIST_HEAD_TIMEOUT_MS, LIST_HEAD_STALLED, LIST_BODY_STALL_MS, LIST_TOTAL_CAP_MS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, P03_COMPACT_TAIL_GRID, TAIL_RETRY_REFUSALS, tailFrom, sameJson2, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, compactReportsRunning, compactHistoryReadsRunning;
63181
+ var import_web398, P03_COMPACT_HISTORY_SOURCE_MODEL, P03_COMPACT_PAGE, P03_COMPACT_SPOT_CHECKS, FIELD_MODULUS5, SUBTREE_LEAVES3, LOCAL_DEPTH2, OUTER_DEPTH2, PRIMARY_PROOF_BYTES2, FIELD_BYTES3, ED25519_SPKI_PREFIX3, VERSION_1_PREFIX2, HEX642, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, FOLD_CHECKPOINT_EVERY, foldNode, foldFrontier, foldHex, servedWithoutRecords, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, listInFlight, LIST_HEAD_TIMEOUT_MS, LIST_HEAD_STALLED, LIST_BODY_STALL_MS, LIST_TOTAL_CAP_MS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, P03_COMPACT_TAIL_GRID, TAIL_RETRY_REFUSALS, tailFrom, sameJson2, SPOT_HEDGE_AFTER_MS, SPOT_HEDGE_LANE, POOL_HEDGE_AFTER_MS, POOL_HEDGE_LANE, compactReportsRunning, compactHistoryReadsRunning;
63065
63182
  var init_compact = __esm({
63066
63183
  "wallet/src/history/compact.mjs"() {
63067
63184
  "use strict";
@@ -63177,6 +63294,24 @@ var init_compact = __esm({
63177
63294
  lastFolds = /* @__PURE__ */ new Map();
63178
63295
  PRE_FOLD_SLICE_MS = 8;
63179
63296
  preFolds = /* @__PURE__ */ new Map();
63297
+ FOLD_CHECKPOINT_EVERY = 64;
63298
+ foldNode = (hex4) => {
63299
+ if (hex4 === null) return void 0;
63300
+ if (typeof hex4 !== "string" || !HEX642.test(hex4)) throw new Error("fold");
63301
+ const value2 = BigInt(`0x${hex4}`);
63302
+ if (value2 >= FIELD_MODULUS5) throw new Error("fold");
63303
+ return value2;
63304
+ };
63305
+ foldFrontier = (nodes) => {
63306
+ if (!Array.isArray(nodes) || nodes.length !== OUTER_DEPTH2) throw new Error("fold");
63307
+ const filled = new Array(OUTER_DEPTH2);
63308
+ for (let level = 0; level < OUTER_DEPTH2; level += 1) {
63309
+ const node3 = foldNode(nodes[level]);
63310
+ if (node3 !== void 0) filled[level] = node3;
63311
+ }
63312
+ return filled;
63313
+ };
63314
+ foldHex = (value2) => value2.toString(16).padStart(64, "0");
63180
63315
  servedWithoutRecords = (served) => ({
63181
63316
  records: [],
63182
63317
  initialization: served.initialization,
@@ -67661,7 +67796,14 @@ async function publishInboundMemoFirst({ serviceUrl: serviceUrl2, record, deps,
67661
67796
  });
67662
67797
  } catch (error) {
67663
67798
  const code2 = String(error?.message ?? "").replace(/^p03_deposit_/, "");
67664
- if (EARLY_MEMO_WAITS.has(code2)) fail15("relay_memo_not_stored_yet");
67799
+ if (code2 === "memo_publish_refused_422") {
67800
+ throw new Error("p03_deposit_relay_memo_refused_422: Shinjuku's server refused to store this deposit's private record (HTTP 422), so no USDC moved");
67801
+ }
67802
+ if (EARLY_MEMO_WAITS.has(code2)) {
67803
+ const answer = EARLY_MEMO_WAITS.get(code2);
67804
+ const words2 = `Shinjuku's server ${answer.words} when the wallet stored this deposit's private record, so no USDC moved`;
67805
+ throw new Error(answer.status ? `p03_deposit_relay_memo_not_stored_yet${answer.status} (${words2})` : `p03_deposit_relay_memo_not_stored_yet: ${words2}`);
67806
+ }
67665
67807
  throw error;
67666
67808
  }
67667
67809
  }
@@ -68592,7 +68734,11 @@ var init_deposit = __esm({
68592
68734
  MEMO_FIRST_FALLBACKS = /* @__PURE__ */ new Set(["deposit_memo_first_unavailable", "deposit_memo_first_record_started_without"]);
68593
68735
  EARLY_MEMO_ATTEMPTS = 3;
68594
68736
  HELD_MEMO_READBACK_MS = 45e3;
68595
- EARLY_MEMO_WAITS = /* @__PURE__ */ new Set(["memo_publish_no_answer", "memo_publish_refused_422", "memo_publish_refused_429", "memo_publish_refused_503"]);
68737
+ EARLY_MEMO_WAITS = /* @__PURE__ */ new Map([
68738
+ ["memo_publish_no_answer", { status: "", words: "did not answer" }],
68739
+ ["memo_publish_refused_429", { status: ":429", words: "asked the wallet to slow down (HTTP 429)" }],
68740
+ ["memo_publish_refused_503", { status: ":503", words: "was not ready (HTTP 503)" }]
68741
+ ]);
68596
68742
  BUFFER_SIGN_REASONS = /* @__PURE__ */ new Set([
68597
68743
  "deposit_buffer_sign_with_owner_then_same_request",
68598
68744
  "deposit_buffer_resign_with_owner_then_same_request"
@@ -72592,6 +72738,7 @@ var init_errorCodes = __esm({
72592
72738
  "inbound_sweep_reclaimed",
72593
72739
  "relay_inbound_above_pool_limit",
72594
72740
  "relay_memo_not_stored_yet",
72741
+ "relay_memo_refused_422",
72595
72742
  "tor_history_unrouted",
72596
72743
  "seller_tor_history_unrouted",
72597
72744
  "x_payment_network_not_offered",
@@ -106761,13 +106908,14 @@ function floatOutcomeWords(code2, error, t) {
106761
106908
  switch (code2) {
106762
106909
  case PAID_SELLER_FAILED_CODE: {
106763
106910
  const status = Number.isInteger(error?.httpStatus) ? ` (it answered HTTP ${error.httpStatus}${typeof error?.sellerCode === "string" ? `, ${error.sellerCode}` : ""})` : "";
106911
+ const failed = error?.sellerUnanswered === true ? `${p.the} sent no data before the wallet's time limit after it took the payment` : `${p.the}'s own service failed after it took the payment${status}, so no data came back`;
106764
106912
  const paid = ATOMIC4.test(String(error?.paidAtomic ?? "")) ? totalText(error) : ATOMIC4.test(String(error?.priceAtomic ?? "")) ? usdcWords(error.priceAtomic) : "the price";
106765
106913
  const kept3 = error?.replayed === true ? " This is the answer the wallet kept for this request; nothing was sent or paid again." : "";
106766
106914
  const support = typeof error?.transaction === "string" ? ` (give them the transaction ${error.transaction})` : "";
106767
106915
  const later = t.ai ? t.ai.other : `If ${stillWants(t)} the data, try ${p.this} later with ${t.newId} (that is a new payment), once its service works, or ask ${p.the}'s support about this payment${support}`;
106768
106916
  return [
106769
106917
  code2,
106770
- `PAID ${paid}: the payment went through${withTransaction(error)}, and ${p.the} has it, but ${p.the}'s own service failed after it took the payment${status}, so no data came back.${kept3}`,
106918
+ `PAID ${paid}: the payment went through${withTransaction(error)}, and ${p.the} has it, but ${failed}.${kept3}`,
106771
106919
  `Do not ${t.noRepeat}: the same request gets the same error and never pays twice, and no refund comes from Shinjuku. ${later}`
106772
106920
  ];
106773
106921
  }
@@ -106836,7 +106984,7 @@ function floatOutcomeWords(code2, error, t) {
106836
106984
  // dropped request or a stopped self-broadcast (broadcastRefusal): the seller may hold it, so neither a refund nor a kept
106837
106985
  // payment is said, and no retry: a rerun only reads Shinjuku's state again, which wallet_receipts does by itself.
106838
106986
  case "p03_float_outcome_not_certain":
106839
- return floatUnsureWords(code2, error, t, typeof error?.broadcastRefusal === "string" ? `an earlier send of Shinjuku's transfer to ${p.the} got no clear answer from Shinjuku` : `an earlier send of this payment to ${p.the} got no answer`);
106987
+ return floatUnsureWords(code2, error, t, typeof error?.broadcastRefusal === "string" ? `an earlier send of Shinjuku's transfer to ${p.the} got no clear answer from Shinjuku` : error?.transferLanded === true && typeof error?.httpStatus === "number" ? `${answeredInstead(p, error.httpStatus, t.ai ? "an answer" : "the data")}, and Shinjuku's transfer to ${p.the} landed but is not final yet` : error?.transferLanded === true ? `${p.the} sent no ${t.ai ? "answer" : "data"} before the wallet's time limit, and Shinjuku's transfer to ${p.the} landed but is not final yet` : `an earlier send of this payment to ${p.the} got no answer`);
106840
106988
  // A transfer sent to the seller before, near or past its last valid block while Shinjuku's transfer is still open
106841
106989
  // (floatPay.mjs transferWindow, retry-stale-transfer 2026-10-29): a resend can no longer pay the seller, so no retry.
106842
106990
  // The refund time: F proves the transfer dead from 60 s after its sign and refunds 30 s after that proof (float.mjs
@@ -110010,14 +110158,15 @@ async function payViaFloat({
110010
110158
  }
110011
110159
  const lostAnswer = record.state === "submitted";
110012
110160
  const wasKept = record.state === "seller_kept";
110013
- const sellerFailedKept = (status, transaction, sellerReason, { replayed = false, resent = false } = {}) => {
110161
+ const sellerFailedKept = (status, transaction, sellerReason, { replayed = false, resent = false, unanswered: unanswered3 = false } = {}) => {
110014
110162
  const landedTransaction = isSolanaSignature(transaction) ? transaction : record.landedTransaction;
110015
- if (record.state !== "seller_kept" || record.sellerFailed !== true || record.sellerStatus !== status || record.landedTransaction !== landedTransaction) {
110163
+ if (record.state !== "seller_kept" || record.sellerFailed !== true || record.sellerStatus !== status || record.landedTransaction !== landedTransaction || unanswered3 && record.sellerUnanswered !== true) {
110016
110164
  record = {
110017
110165
  ...record,
110018
110166
  state: "seller_kept",
110019
110167
  sellerFailed: true,
110020
110168
  sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(),
110169
+ ...unanswered3 ? { sellerUnanswered: true } : {},
110021
110170
  ...Number.isInteger(status) ? { sellerStatus: status } : {},
110022
110171
  ...isSolanaSignature(landedTransaction) ? { landedTransaction } : {}
110023
110172
  };
@@ -110031,11 +110180,12 @@ async function payViaFloat({
110031
110180
  feeAtomic: record.feeAtomic,
110032
110181
  floatId: record.floatId,
110033
110182
  replayed,
110034
- resent
110183
+ resent,
110184
+ unanswered: record.sellerUnanswered === true
110035
110185
  }), sellerReason ? { sellerReason } : {});
110036
110186
  };
110037
110187
  const keptAgain = (status, sellerReason) => {
110038
- if (record.sellerFailed === true) {
110188
+ if (record.sellerFailed === true || record.sellerFailedLanded === true) {
110039
110189
  sellerFailedKept(record.sellerStatus, record.landedTransaction, sellerReason, { replayed: true, resent: record.keptResent === true });
110040
110190
  }
110041
110191
  if (Number.isInteger(status) && record.sellerStatus !== status) {
@@ -110053,7 +110203,7 @@ async function payViaFloat({
110053
110203
  resent: true
110054
110204
  });
110055
110205
  };
110056
- if (wasKept && (record.keptResent === true || record.sellerFailed === true)) keptAgain();
110206
+ if (wasKept && (record.keptResent === true || record.sellerFailed === true || record.sellerFailedLanded === true)) keptAgain();
110057
110207
  if (record.requestPruned === true) {
110058
110208
  if (wasKept) finishedPruned(record);
110059
110209
  if (lostAnswer) byVerdict(await floatVerdict(record, fetchImpl, statusSleep, verdictUntil(Date.now())), {}, {});
@@ -110061,6 +110211,18 @@ async function payViaFloat({
110061
110211
  store.writeWal(walName2, record);
110062
110212
  refundPendingAnswer(record);
110063
110213
  }
110214
+ if (!answeredThisRun && record.state === "submitted" && record.sellerFailedLanded === true) {
110215
+ const read = await readFloatTransferState(record, fetchImpl);
110216
+ if (read?.state === "final") {
110217
+ const { ambiguous: _settled, ...rest } = record;
110218
+ record = rest;
110219
+ sellerFailedKept(record.sellerStatus, read.transaction);
110220
+ }
110221
+ byVerdict(read, { sellerFailedLanded: true }, {
110222
+ ...Number.isInteger(record.sellerStatus) ? { httpStatus: record.sellerStatus } : {},
110223
+ ...read?.state === "landed" ? { transferLanded: true } : {}
110224
+ });
110225
+ }
110064
110226
  if (!answeredThisRun && !wasKept) {
110065
110227
  const window2 = await transferWindow(record, connection, deps);
110066
110228
  if (!window2.open) {
@@ -110101,9 +110263,10 @@ async function payViaFloat({
110101
110263
  record = { ...record, sellerStallResent: true };
110102
110264
  store.writeWal(walName2, record);
110103
110265
  }
110104
- function unanswered2(error) {
110266
+ async function unanswered2(error) {
110105
110267
  if (wasKept) keptAgain();
110106
- const verdict = watch.verdict();
110268
+ let verdict = watch.verdict();
110269
+ if (verdict?.state === "landed") verdict = await finalAfterLanded();
110107
110270
  if (verdict?.state === "dead") {
110108
110271
  const sellerUnansweredSeconds = Math.round((Date.now() - sentAtMs2) / 1e3);
110109
110272
  const { ambiguous: _settled, ...rest } = record;
@@ -110119,16 +110282,9 @@ async function payViaFloat({
110119
110282
  }
110120
110283
  if (verdict?.state === "cancelled") byVerdict(verdict, {}, { cause: error });
110121
110284
  const resentNow = record.sellerStallResent === true ? { stallResent: true } : {};
110122
- if (verdict?.state === "final") {
110123
- fail25("p03_float_seller_unanswered_paid_retry_same_request", {
110124
- cause: error,
110125
- floatId: record.floatId,
110126
- ...verdict.transaction ? { transaction: verdict.transaction } : {},
110127
- paidAtomic: record.paidAtomic,
110128
- priceAtomic: record.priceAtomic,
110129
- feeAtomic: record.feeAtomic,
110130
- ...resentNow
110131
- });
110285
+ if (verdict?.state === "final") sellerFailedKept(void 0, verdict.transaction, void 0, { unanswered: true });
110286
+ if (verdict?.state === "landed") {
110287
+ byVerdict(verdict, { sellerFailedLanded: true, sellerUnanswered: true }, { cause: error, transferLanded: true, ...resentNow });
110132
110288
  }
110133
110289
  fail25("p03_float_seller_unanswered_retry_same_request", {
110134
110290
  cause: error,
@@ -110136,14 +110292,14 @@ async function payViaFloat({
110136
110292
  paidAtomic: record.paidAtomic,
110137
110293
  priceAtomic: record.priceAtomic,
110138
110294
  feeAtomic: record.feeAtomic,
110139
- ...verdict?.state === "landed" ? { transferLanded: true } : {},
110140
110295
  ...resentNow
110141
110296
  });
110142
110297
  }
110143
110298
  async function finalAfterLanded() {
110144
- const deadline = Date.now() + FINAL_AFTER_202_MS;
110299
+ const deadline = Math.min(Date.now() + FINAL_AFTER_202_MS, Number.isSafeInteger(deps.answerByMs) ? deps.answerByMs : Infinity);
110145
110300
  const watched = watch.verdict();
110146
- let state2 = ["final", "dead", "cancelled", "landed"].includes(watched?.state) ? watched : await readFloatTransferState(record, fetchImpl, Math.min(FLOAT_STATUS_TIMEOUT_MS, FINAL_AFTER_202_MS));
110301
+ const firstLeft = deadline - Date.now();
110302
+ let state2 = ["final", "dead", "cancelled", "landed"].includes(watched?.state) ? watched : firstLeft > 0 ? await readFloatTransferState(record, fetchImpl, Math.min(FLOAT_STATUS_TIMEOUT_MS, firstLeft)) : void 0;
110147
110303
  while (state2?.state === "landed" && Date.now() < deadline) {
110148
110304
  await sleep5(Math.min(1e3, Math.max(0, deadline - Date.now())));
110149
110305
  const left = deadline - Date.now();
@@ -110193,7 +110349,7 @@ async function payViaFloat({
110193
110349
  } }
110194
110350
  ));
110195
110351
  } catch (error) {
110196
- unanswered2(error);
110352
+ await unanswered2(error);
110197
110353
  } finally {
110198
110354
  if (socketWatch !== void 0) {
110199
110355
  const { outcome, sentAtMs: sentAtMs3 } = socketWatch.stop();
@@ -110238,7 +110394,7 @@ async function payViaFloat({
110238
110394
  resultBase64 = "";
110239
110395
  } else {
110240
110396
  if (error?.message === "result_too_large_retry_same_request") throw error;
110241
- unanswered2(error);
110397
+ await unanswered2(error);
110242
110398
  }
110243
110399
  }
110244
110400
  let chain = paidKnown ? { state: "landed", transaction: knownTransaction } : watch.verdict();
@@ -110282,7 +110438,7 @@ async function payViaFloat({
110282
110438
  store.writeWal(walName2, record);
110283
110439
  }
110284
110440
  const watchedNow = watch.verdict();
110285
- const state2 = response.status === 202 ? state202 : ["final", "dead", "cancelled"].includes(watchedNow?.state) ? watchedNow : await readFloatTransferState(record, fetchImpl);
110441
+ const state2 = response.status === 202 ? state202 : ["final", "dead", "cancelled"].includes(watchedNow?.state) ? watchedNow : await finalAfterLanded();
110286
110442
  if (state2?.state === "cancelled") {
110287
110443
  byVerdict(state2, {}, { httpStatus: response.status, ...sellerReason ? { sellerReason } : {} });
110288
110444
  }
@@ -110300,28 +110456,17 @@ async function payViaFloat({
110300
110456
  if (state2?.state === "final" && response.status >= 500) {
110301
110457
  sellerFailedKept(response.status, state2.transaction, sellerReason);
110302
110458
  }
110303
- if (state2?.state === "final") {
110304
- fail25("p03_float_seller_unanswered_paid_retry_same_request", {
110305
- httpStatus: response.status,
110306
- ...sellerReason ? { sellerReason } : {},
110307
- floatId: record.floatId,
110308
- ...state2.transaction ? { transaction: state2.transaction } : {},
110309
- paidAtomic: record.paidAtomic,
110310
- priceAtomic: record.priceAtomic,
110311
- feeAtomic: record.feeAtomic
110312
- });
110313
- }
110314
- if (state2?.state !== "landed") {
110315
- const window2 = await transferWindow(record, connection, deps);
110316
- if (!window2.open) transferExpiredAnswer(store, walName2, record, window2, sellerReason ? { sellerReason } : {});
110459
+ if (state2?.state === "landed" && response.status >= 500) {
110460
+ byVerdict(state2, { sellerFailedLanded: true }, { httpStatus: response.status, transferLanded: true, ...sellerReason ? { sellerReason } : {} });
110317
110461
  }
110462
+ const window2 = await transferWindow(record, connection, deps);
110463
+ if (!window2.open) transferExpiredAnswer(store, walName2, record, window2, sellerReason ? { sellerReason } : {});
110318
110464
  fail25("p03_float_seller_unanswered_retry_same_request", {
110319
110465
  httpStatus: response.status,
110320
110466
  floatId: record.floatId,
110321
110467
  paidAtomic: record.paidAtomic,
110322
110468
  priceAtomic: record.priceAtomic,
110323
- feeAtomic: record.feeAtomic,
110324
- ...state2?.state === "landed" ? { transferLanded: true } : {}
110469
+ feeAtomic: record.feeAtomic
110325
110470
  });
110326
110471
  }
110327
110472
  const settled = sellerSettleAnswer(response);
@@ -110351,7 +110496,8 @@ function recordVerdict(store, walName2, record, verdict, fields, errorFields) {
110351
110496
  ...fields,
110352
110497
  state: "seller_kept",
110353
110498
  sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(),
110354
- ...verdict.transaction ? { landedTransaction: verdict.transaction } : {}
110499
+ ...verdict.transaction ? { landedTransaction: verdict.transaction } : {},
110500
+ ...record.sellerFailedLanded === true || fields?.sellerFailedLanded === true ? { sellerFailed: true } : {}
110355
110501
  });
110356
110502
  fail25("p03_float_seller_kept_payment", { ...errorFields, ...amounts, ...verdict.transaction ? { transaction: verdict.transaction } : {} });
110357
110503
  }
@@ -112768,7 +112914,8 @@ function paidSellerFailedError({
112768
112914
  feeAtomic,
112769
112915
  floatId,
112770
112916
  replayed = false,
112771
- resent
112917
+ resent,
112918
+ unanswered: unanswered2
112772
112919
  } = {}) {
112773
112920
  const atomic5 = (value2) => /^[0-9]+$/.test(String(value2 ?? "")) ? String(value2) : void 0;
112774
112921
  return Object.assign(new Error("p03_resource_paid_seller_failed"), {
@@ -112781,7 +112928,9 @@ function paidSellerFailedError({
112781
112928
  ...atomic5(priceAtomic) ? { priceAtomic: atomic5(priceAtomic) } : {},
112782
112929
  ...atomic5(feeAtomic) ? { feeAtomic: atomic5(feeAtomic) } : {},
112783
112930
  ...typeof floatId === "string" && floatId ? { floatId } : {},
112784
- ...resent === true ? { resent: true } : {}
112931
+ ...resent === true ? { resent: true } : {},
112932
+ // AB264: the seller sent no answer before the wallet's time limit (no HTTP status), after it took the payment.
112933
+ ...unanswered2 === true ? { sellerUnanswered: true } : {}
112785
112934
  });
112786
112935
  }
112787
112936
  async function readBounded(response, limit) {
@@ -115054,7 +115203,7 @@ function refusalSay(a, tool, again, npmVersion) {
115054
115203
  }
115055
115204
  if (code2 === "p03_resource_paid_seller_failed") {
115056
115205
  const tx = typeof a.transaction === "string" && /^[1-9A-HJ-NP-Za-km-z]{43,90}$/.test(a.transaction) ? a.transaction : void 0;
115057
- const head = (status) => `${total ? `Paid ${total} USDC` : "Paid"}; ${seller} got paid, but its service failed${status}.`;
115206
+ const head = (status) => `${total ? `Paid ${total} USDC` : "Paid"}; ${seller} got paid, but ${a.sellerUnanswered === true ? "sent nothing in time" : `its service failed${status}`}.`;
115058
115207
  const statuses = [...Number.isInteger(a.httpStatus) ? [` (HTTP ${a.httpStatus})`] : [], ""];
115059
115208
  return firstFit(
115060
115209
  ...tx ? statuses.map((s3) => `${head(s3)} Shinjuku refunds nothing. Do not pay again; ask its support, giving transaction ${tx}.`) : [],
@@ -117661,12 +117810,73 @@ function launchOnce(file, spawnImpl) {
117661
117810
  });
117662
117811
  });
117663
117812
  }
117664
- async function checkProgramsLaunch(files, { spawnImpl = spawn5, platform = process.platform } = {}) {
117813
+ function smartAppControlOn({ platform = process.platform, spawnImpl = spawn5, limitMs = 5e3 } = {}) {
117814
+ if (platform !== "win32") return Promise.resolve(false);
117815
+ return new Promise((resolveRead) => {
117816
+ let out = "";
117817
+ let child;
117818
+ let ended2 = false;
117819
+ const end2 = (value2) => {
117820
+ if (!ended2) {
117821
+ ended2 = true;
117822
+ clearTimeout(timer);
117823
+ resolveRead(value2);
117824
+ }
117825
+ };
117826
+ const timer = setTimeout(() => {
117827
+ end2(false);
117828
+ if (!child || child.exitCode !== null) return;
117829
+ let killed = false;
117830
+ try {
117831
+ killed = child.kill();
117832
+ } catch {
117833
+ killed = false;
117834
+ }
117835
+ if (!killed && child.pid) {
117836
+ try {
117837
+ spawnImpl("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true }).unref?.();
117838
+ } catch {
117839
+ }
117840
+ }
117841
+ }, limitMs);
117842
+ try {
117843
+ child = spawnImpl(
117844
+ "reg.exe",
117845
+ ["query", "HKLM\\SYSTEM\\CurrentControlSet\\Control\\CI\\Policy", "/v", "VerifiedAndReputablePolicyState"],
117846
+ { stdio: ["ignore", "pipe", "ignore"], windowsHide: true }
117847
+ );
117848
+ } catch {
117849
+ end2(false);
117850
+ return;
117851
+ }
117852
+ child.unref?.();
117853
+ child.stdout?.on("data", (chunk) => {
117854
+ if (out.length < 4096) out += String(chunk);
117855
+ });
117856
+ child.on("error", () => end2(false));
117857
+ child.on("close", (status) => end2(status === 0 && /VerifiedAndReputablePolicyState\s+REG_DWORD\s+0x1\b/i.test(out)));
117858
+ });
117859
+ }
117860
+ function blockedProgramWords({ name = "the wallet's programs", what = "it", smartAppControl, again }) {
117861
+ return smartAppControl ? {
117862
+ cause: `Windows Smart App Control is on, and it may have blocked ${what}: Smart App Control can stop a program that is not code-signed when Windows does not know it yet, and the wallet's proof programs are not signed yet`,
117863
+ next: `Windows has no way to allow one program while Smart App Control is on. You can wait for a wallet version with signed programs, or turn Smart App Control off (Windows Security > App & browser control > Smart App Control settings > Off) and ${again}. With it off, Windows no longer checks new programs this way (its other protections stay on), so an unknown program that is harmful is easier to start on this computer`
117864
+ } : {
117865
+ cause: `the wallet cannot tell the exact cause. An antivirus or an app control rule may have blocked or removed ${what} (the wallet's proof programs are not code-signed yet), or a file it needs may be missing on this computer`,
117866
+ next: `If your antivirus blocked or removed ${name}, allow ${name === "the wallet's programs" ? "them" : "it"} there (or ask the person who manages this computer) and ${again}. Otherwise ${again} once; if it stops the same way, wait for a wallet version with signed programs`
117867
+ };
117868
+ }
117869
+ async function checkProgramsLaunch(files, { spawnImpl = spawn5, platform = process.platform, smartAppControl } = {}) {
117665
117870
  const results = await Promise.all(files.map((file) => launchOnce(file, spawnImpl)));
117666
117871
  const blocked = results.find((result) => !result.ok);
117667
117872
  if (!blocked) return;
117668
117873
  const name = basename7(blocked.file);
117669
- throw fail31("setup_program_blocked", platform === "win32" ? `the wallet's proof program ${name} could not start on this computer (${blocked.why}). Windows Smart App Control, another app control rule or an antivirus blocked it or removed it. Setup stopped before it made or changed any wallet. Allow ${name} in Windows Security (or in your antivirus), or ask the person who manages this computer, then run setup again` : `the wallet's proof program ${name} could not start on this computer (${blocked.why}). The disk of the wallet folder may not allow programs to run (mounted noexec), the program may not match this computer's processor, or an antivirus blocked it. Setup stopped before it made or changed any wallet. Use a wallet folder on a disk that allows programs to run, then run setup again`);
117874
+ const words2 = platform === "win32" ? blockedProgramWords({
117875
+ name,
117876
+ again: "run setup again",
117877
+ smartAppControl: startRefused(blocked.why) && (smartAppControl ?? await smartAppControlOn({ platform }))
117878
+ }) : void 0;
117879
+ throw fail31("setup_program_blocked", platform === "win32" ? `the wallet's proof program ${name} could not start on this computer (${blocked.why}). ${words2.cause[0].toUpperCase()}${words2.cause.slice(1)}. Setup stopped before it made or changed any wallet. ${words2.next}` : `the wallet's proof program ${name} could not start on this computer (${blocked.why}). The disk of the wallet folder may not allow programs to run (mounted noexec), the program may not match this computer's processor, or an antivirus blocked it. Setup stopped before it made or changed any wallet. Use a wallet folder on a disk that allows programs to run, then run setup again`);
117670
117880
  }
117671
117881
  function verifyToolsFolder(folder, sumsSha256) {
117672
117882
  try {
@@ -118259,7 +118469,7 @@ async function refreshChannelAfterProgramUpgrade({ home, facilitator, fetchImpl
118259
118469
  }
118260
118470
  return moved;
118261
118471
  }
118262
- var PINNED_PROOF_TOOLS, PROOF_TOOLS_PLATFORMS, DEFAULT_PROOF_TOOLS_PLATFORM, UPDATE_NEXT, HEX643, DIR2, SUMS_LINE, MAX_FILES, LIMITS, RELEASE_TIMEOUT_MS, DOWNLOAD_LANES, RANGE_BYTES, RANGE_TIMEOUT_MS, RANGE_STALL_MS, RANGE_FLOOR_BYTES, SPEED_WINDOWS, rangeFloor, RANGE_ATTEMPTS, HEDGE_AFTER_MS, CONTENT_RANGE, PROGRESS_EVERY_MS, releasedBytes, megabytes, REQUIRED_FILES, sha2569, fail31, SMALL_HEDGE_MS, SMALL_LANES, LOST, SETUP_RELEASE_PATIENCE_MS, passing, localPath, executable, LAUNCH_CHECK_ARG, LAUNCH_CHECK_TIMEOUT_MS, LAUNCH_CHECK_EXITS, toolPaths, SPACE_MARGIN_BYTES, DISK_FULL, diskFull, RESUME_DIR, resumeName, trustedRefreshes;
118472
+ var PINNED_PROOF_TOOLS, PROOF_TOOLS_PLATFORMS, DEFAULT_PROOF_TOOLS_PLATFORM, UPDATE_NEXT, HEX643, DIR2, SUMS_LINE, MAX_FILES, LIMITS, RELEASE_TIMEOUT_MS, DOWNLOAD_LANES, RANGE_BYTES, RANGE_TIMEOUT_MS, RANGE_STALL_MS, RANGE_FLOOR_BYTES, SPEED_WINDOWS, rangeFloor, RANGE_ATTEMPTS, HEDGE_AFTER_MS, CONTENT_RANGE, PROGRESS_EVERY_MS, releasedBytes, megabytes, REQUIRED_FILES, sha2569, fail31, SMALL_HEDGE_MS, SMALL_LANES, LOST, SETUP_RELEASE_PATIENCE_MS, passing, localPath, executable, LAUNCH_CHECK_ARG, LAUNCH_CHECK_TIMEOUT_MS, LAUNCH_CHECK_EXITS, startRefused, toolPaths, SPACE_MARGIN_BYTES, DISK_FULL, diskFull, RESUME_DIR, resumeName, trustedRefreshes;
118263
118473
  var init_proofTools = __esm({
118264
118474
  "wallet/src/setup/proofTools.mjs"() {
118265
118475
  "use strict";
@@ -118324,6 +118534,7 @@ var init_proofTools = __esm({
118324
118534
  LAUNCH_CHECK_ARG = "--launch-check";
118325
118535
  LAUNCH_CHECK_TIMEOUT_MS = 6e4;
118326
118536
  LAUNCH_CHECK_EXITS = /* @__PURE__ */ new Set([1, 101]);
118537
+ startRefused = (why) => /this computer refused to start it|this computer does not allow it to start/.test(String(why ?? ""));
118327
118538
  toolPaths = (folder) => Object.freeze({
118328
118539
  proofTools: join29(folder, "proof-tools.json"),
118329
118540
  exitProofTools: join29(folder, "exit-proof-tools.json"),
@@ -119611,6 +119822,14 @@ function inboundSweepFailure(code2, { reclaim, inBalance = false } = {}) {
119611
119822
  next: `take the USDC back out: ${service} (if it answers that Shinjuku does not know the deposit: ${keyFile2}). ${linked}`
119612
119823
  };
119613
119824
  }
119825
+ if (code2 === MEMO_REFUSED) {
119826
+ return {
119827
+ stopped: false,
119828
+ retriesByItself: true,
119829
+ what: "Shinjuku's server refused this sale's private record (a fault on Shinjuku's side), so nothing moved",
119830
+ next: "nothing to do: it tries again by itself when your server starts again, and it moves in once Shinjuku fixes it"
119831
+ };
119832
+ }
119614
119833
  if (isTransient(code2) || code2 === PROVE_AGAIN) {
119615
119834
  return {
119616
119835
  stopped: false,
@@ -119763,7 +119982,7 @@ function createInboundSweeper({ store, book, connection, programId, proofTools,
119763
119982
  kick();
119764
119983
  return Object.freeze({ enqueue, drain, close });
119765
119984
  }
119766
- var INBOUND_SWEEP_LOCK_WAIT_MS, TRANSIENT_TRIES, TRANSIENT_WAIT_MS, SWEEP_STATES, RECLAIMED, ABOVE_LIMIT, ATTEMPTS_EXHAUSTED, BUFFERS_EXHAUSTED, inboundDepositId, TRANSIENT_CODES, PROVE_AGAIN, nowSeconds4, delay2;
119985
+ var INBOUND_SWEEP_LOCK_WAIT_MS, TRANSIENT_TRIES, TRANSIENT_WAIT_MS, SWEEP_STATES, RECLAIMED, ABOVE_LIMIT, ATTEMPTS_EXHAUSTED, BUFFERS_EXHAUSTED, inboundDepositId, MEMO_REFUSED, TRANSIENT_CODES, PROVE_AGAIN, nowSeconds4, delay2;
119767
119986
  var init_sweep = __esm({
119768
119987
  "wallet/src/inbound/sweep.mjs"() {
119769
119988
  "use strict";
@@ -119777,6 +119996,7 @@ var init_sweep = __esm({
119777
119996
  ATTEMPTS_EXHAUSTED = "p03_deposit_relay_refused_deposit_inbound_attempts_exhausted";
119778
119997
  BUFFERS_EXHAUSTED = "p03_deposit_relay_refused_deposit_inbound_buffer_sponsorship_exhausted";
119779
119998
  inboundDepositId = (index) => `inbound-${index}`;
119999
+ MEMO_REFUSED = "p03_deposit_relay_memo_refused_422";
119780
120000
  TRANSIENT_CODES = /* @__PURE__ */ new Set([
119781
120001
  "p03_deposit_relay_inbound_not_funded_yet",
119782
120002
  "p03_deposit_relay_not_settled_rerun_same_id",
@@ -119786,7 +120006,10 @@ var init_sweep = __esm({
119786
120006
  // The facilitator still holds an earlier attempt of this address: the next try resends the same proof body.
119787
120007
  "p03_deposit_relay_refused_deposit_inbound_attempt_in_progress",
119788
120008
  // The memo service did not store the memo yet (no answer, or the deposit's proof not journaled yet): nothing moved.
119789
- "p03_deposit_relay_memo_not_stored_yet"
120009
+ "p03_deposit_relay_memo_not_stored_yet",
120010
+ // The memo service refused the record (422): a fault on Shinjuku's side (AB260, 2026-11-08), not the seller's. Nothing
120011
+ // moved, so the sale keeps trying (inboundSweepFailure names it) instead of sending the seller to a public take-back.
120012
+ MEMO_REFUSED
119790
120013
  ]);
119791
120014
  PROVE_AGAIN = "p03_deposit_relay_refused_deposit_inbound_balance_changed_prove_again";
119792
120015
  nowSeconds4 = () => Math.floor(Date.now() / 1e3);
@@ -120310,7 +120533,13 @@ function writeProvenFloatStates(store, proven) {
120310
120533
  ...Number.isSafeInteger(refundDueAtMs) ? { refundDueAtMs } : {}
120311
120534
  });
120312
120535
  } else if (verdict === "final") {
120313
- store.writeWal(name, { ...rest, state: "seller_kept", sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(), ...landed });
120536
+ store.writeWal(name, {
120537
+ ...rest,
120538
+ state: "seller_kept",
120539
+ sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(),
120540
+ ...landed,
120541
+ ...record.sellerFailedLanded === true ? { sellerFailed: true } : {}
120542
+ });
120314
120543
  } else if (verdict === "cancelled") {
120315
120544
  store.writeWal(name, { ...rest, state: "cancelled", cancelledAtMs: record.cancelledAtMs ?? Date.now() });
120316
120545
  } else continue;
@@ -137457,6 +137686,8 @@ ${canonical5}`;
137457
137686
  ...typeof error?.floatCode === "string" ? { floatCode: error.floatCode } : {},
137458
137687
  // AB164: the seller's own code beside its error after it took the payment (floatWords.mjs PAID_SELLER_FAILED_CODE).
137459
137688
  ...code2 === PAID_SELLER_FAILED_CODE && typeof error?.sellerCode === "string" ? { sellerCode: error.sellerCode } : {},
137689
+ // AB264: the seller sent nothing in time after it took the payment (say.mjs, floatWords.mjs).
137690
+ ...code2 === PAID_SELLER_FAILED_CODE && error?.sellerUnanswered === true ? { sellerUnanswered: true } : {},
137460
137691
  ...code2 === PAID_SELLER_FAILED_CODE && error?.replayed === true ? { replayed: true } : {},
137461
137692
  ...typeof error?.priceAtomic === "string" ? { priceAtomic: error.priceAtomic } : {},
137462
137693
  ...typeof error?.feeAtomic === "string" ? { feeAtomic: error.feeAtomic } : {},
@@ -145913,7 +146144,9 @@ var init_tools = __esm({
145913
146144
  PLAIN_REASONS = [
145914
146145
  [/underfunded/, "Shinjuku could not pay the network fee"],
145915
146146
  // Memo first: Shinjuku holds a deposit until its private record is stored, and that store did not answer yet.
145916
- [/relay_memo_not_stored_yet$/, "Shinjuku did not store this deposit's private record yet, so no USDC moved; asking again finishes it"],
146147
+ [/relay_memo_not_stored_yet(:\d{3})?$/, "Shinjuku did not store this deposit's private record yet, so no USDC moved; asking again a little later can finish it"],
146148
+ // AB260 (2026-11-08): the server refused the record; asking again does not help until Shinjuku fixes it.
146149
+ [/relay_memo_refused_422$/, "Shinjuku's server refused this deposit's private record (a fault on Shinjuku's side), so no USDC moved and it stays where it was; asking again does not help until Shinjuku fixes it"],
145917
146150
  // Codes our own code throws with no words an answer may show (AB253): fixed words here, never the exception's text.
145918
146151
  [/^process_lock_lost$/, "another Shinjuku program took over this wallet while this step ran, so the step stopped"],
145919
146152
  [/^process_lock_stopped$/, "the wait for this wallet was stopped before the step could run"],
@@ -153166,7 +153399,12 @@ async function sellerTor(recorded, home) {
153166
153399
  if (home) {
153167
153400
  const current = readSetupConfig(home)?.torTunnel ?? recorded;
153168
153401
  try {
153169
- tunnel = await ensureWalletTor(current, { env: { ...process.env, SHIELDED_WALLET_HOME: home }, explicit: true });
153402
+ tunnel = await ensureWalletTor(current, {
153403
+ env: { ...process.env, SHIELDED_WALLET_HOME: home },
153404
+ explicit: true,
153405
+ say: (line) => process.stderr.write(`${line}
153406
+ `)
153407
+ });
153170
153408
  } catch (error) {
153171
153409
  if (!error?.managedTor) throw error;
153172
153410
  throw new SellerRefusal("seller_tor_not_running", `${String(error.message).replace(/^managed_tor_failed:\s*/, "")}
@@ -155125,7 +155363,7 @@ async function keepWarmMain(args, values, { io, env = process.env, entry } = {})
155125
155363
  }
155126
155364
  const waitGap = async () => {
155127
155365
  const gap = randomInt7(KEEP_WARM_MIN_MS, KEEP_WARM_MAX_MS + 1);
155128
- io.err(`keep-warm: next refresh in ${Math.round(gap / 1e3)} s (stop with Ctrl-C)
155366
+ io.err(`keep-warm: next refresh in ${Math.round(gap / 1e3)} s (${parent ? "it stops when the wallet's MCP ends" : "stop with Ctrl-C"})
155129
155367
  `);
155130
155368
  await new Promise((done) => {
155131
155369
  const timer = setTimeout(done, gap);
@@ -155421,8 +155659,13 @@ async function moveToNativeSet(home, { say: say2 = () => {
155421
155659
  return { moved: true, config: after };
155422
155660
  }
155423
155661
  const code2 = /^([a-z][a-z0-9_]*): /.exec(String(failure3?.message ?? ""))?.[1];
155424
- const cause = timedOut ? "the download took too long, so the wallet stopped it (a slow connection or a slow Tor circuit)" : code2 === "setup_program_blocked" ? "this computer blocked one of the wallet's programs (an app control rule or an antivirus)" : code2 === "setup_file_hash_mismatch" ? "a downloaded file did not check out, so it was not used" : failure3 ? "the download did not finish (Shinjuku's server did not answer, or the connection stopped)" : "the downloaded files did not replace the old ones";
155425
- const next = code2 === "setup_program_blocked" ? "Allow the wallet's programs in your antivirus or app control settings, then ask again: the wallet tries again by itself" : "Check that this computer is online, then ask again: the wallet tries the download again by itself (no setup is needed)";
155662
+ const blockedWords = code2 === "setup_program_blocked" && platform === "win32" ? blockedProgramWords({
155663
+ what: "one of the wallet's programs",
155664
+ again: "ask again",
155665
+ smartAppControl: startRefused(failure3?.message) && await smartAppControlOn({ platform })
155666
+ }) : void 0;
155667
+ const cause = timedOut ? "the download took too long, so the wallet stopped it (a slow connection or a slow Tor circuit)" : blockedWords ? blockedWords.cause : code2 === "setup_program_blocked" ? "this computer blocked one of the wallet's programs (an app control rule or an antivirus)" : code2 === "setup_file_hash_mismatch" ? "a downloaded file did not check out, so it was not used" : failure3 ? "the download did not finish (Shinjuku's server did not answer, or the connection stopped)" : "the downloaded files did not replace the old ones";
155668
+ const next = blockedWords ? blockedWords.next : code2 === "setup_program_blocked" ? "Allow the wallet's programs in your antivirus or app control settings, then ask again: the wallet tries again by itself" : "Check that this computer is online, then ask again: the wallet tries the download again by itself (no setup is needed)";
155426
155669
  const error = new Error(`setup_files_other_computer: this wallet's setup files are from an older setup and do not run on this computer, and ${cause}. Nothing was paid or sent, and your money is safe. ${next}`);
155427
155670
  error.detail = failure3 ? String(failure3.message ?? failure3).replace(/^[a-z][a-z0-9_]*: /, "") : void 0;
155428
155671
  throw error;
@@ -156719,6 +156962,7 @@ var FACILITATOR_LATER = /_(intake_paused|relayer_underfunded|paused)_retry_later
156719
156962
  var TRANSIENT = [
156720
156963
  /_(retry_later|rerun_later|rerun_same_id|not_final_rerun|notes_changed_rerun)$/,
156721
156964
  /_retry_same_(request|unshield|payment)$/,
156965
+ /relay_memo_not_stored_yet(:\d{3})?$/,
156722
156966
  /^(rpc_rate_limited|rpc_unreachable|memo_publish_no_answer|memo_service_rate_limited|memo_service_unavailable|wallet_process_locked|p03_pocket_cli_wallet_locked)$/,
156723
156967
  /_(wait_next_epoch|anchor_refused_503|anchor_not_finalized)$/,
156724
156968
  /_(balance_unreadable|token_balance_unreadable|chain_time_unavailable)$/,
@@ -156739,6 +156983,10 @@ var RETRY_WORDS = [
156739
156983
  now: "the server has not moved the deposit into the pool yet, so the wallet asks again",
156740
156984
  waitsFor: "the server to move the deposit into the pool"
156741
156985
  }],
156986
+ [/relay_memo_not_stored_yet(:\d{3})?$/, {
156987
+ now: "Shinjuku's server did not store this deposit's private record yet (no USDC moved; it is safe at the one-time address), so the wallet asks again",
156988
+ waitsFor: "Shinjuku's server to store this deposit's private record (no USDC moved; it is safe at the one-time address)"
156989
+ }],
156742
156990
  [/^rpc_unreachable$/, { now: "the RPC did not answer, so the wallet asks again", waitsFor: "an answer from the RPC (it did not answer)" }],
156743
156991
  [/^rpc_rate_limited$/, { now: "the RPC asked the wallet to slow down, so it asks again", waitsFor: "the RPC to take requests again (it asked the wallet to slow down)" }],
156744
156992
  [/^(wallet_process_locked|p03_pocket_cli_wallet_locked)$/, {
@@ -156770,6 +157018,9 @@ function otherwise(ctx, run2) {
156770
157018
  const codes = [run2.code, ...run2.codes].filter(Boolean);
156771
157019
  return transient(ctx, run2, RETRY_WORDS.find(([pattern]) => codes.some((code2) => pattern.test(code2)))?.[1] ?? RETRY_ANY);
156772
157020
  }
157021
+ if (has(run2, /relay_memo_refused_422$/)) {
157022
+ return { ...stop(run2, "Shinjuku's server to accept this deposit's private record (it refused it: a fault on Shinjuku's side)"), serverFault: true };
157023
+ }
156773
157024
  return stop(run2, `the step refused (${run2.code ?? run2.codes[0]})`);
156774
157025
  }
156775
157026
  function depositArgs(ctx, submit, part) {
@@ -157364,6 +157615,9 @@ async function addFunds(values, deps) {
157364
157615
  plan.status = { stage: label, at: iso(deps.now()), stopped: outcome.run?.code ?? outcome.run?.codes?.[0] ?? "refused", waitsFor: outcome.waitsFor, ...said.length ? { said } : {} };
157365
157616
  save2();
157366
157617
  if (outcome.closed) throw failure("stopped", `${outcome.waitsFor}, and this add-funds run cannot continue. ${stepWords("To add money", "add-funds", `${cli()} add-funds`)}`);
157618
+ if (outcome.serverFault) {
157619
+ throw failure("stopped", `the ${label} step stopped on a fault at Shinjuku's server: it refused this deposit's private record. There is nothing for you to fix, and no USDC moved: it is safe at the one-time address. Run this same add-funds command after Shinjuku fixes it: it continues at ${label}`);
157620
+ }
157367
157621
  throw failure("stopped", outcome.tries ? `add-funds stopped after ${MAX_TRANSIENT} tries of the ${label} step: it still waits for ${outcome.waitsFor}. Nothing was lost. Run this same add-funds command again later: it continues at ${label}` : `the ${label} step needs you: ${outcome.waitsFor}${said.length ? " (its own line and hint are above)" : ""}. Fix that, then rerun this same add-funds command: it continues at ${label}`);
157368
157622
  }
157369
157623
  const until = iso(deps.now() + outcome.ms);