shinjuku-shielded 0.3.55 → 0.3.56

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/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": "70ff655b113c19d39c8594566c77d38fe7d459ea415f66cda1c09919841ad1a9",
5
- "bytes": 12128720,
6
- "sourceCommit": "d13f57d40a91eecbd9b06acd4f8c587d34bc256a",
4
+ "sha256": "e18d1d9537ea063f2a28f88b4db41a1b93067c5d5aa4f300daaddf80d8544074",
5
+ "bytes": 12133623,
6
+ "sourceCommit": "15d669c631b6ceb1237b994a9ce152d257c85a0c",
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",
@@ -1282,5 +1282,5 @@
1282
1282
  "version": "1.8.0"
1283
1283
  }
1284
1284
  ],
1285
- "publishedAt": "2026-10-21T23:25:11.303Z"
1285
+ "publishedAt": "2026-10-21T23:43:38.976Z"
1286
1286
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shielded",
3
- "version": "0.3.55",
3
+ "version": "0.3.56",
4
4
  "mcpName": "io.github.ShinjukuStaition/shinjuku-mcp",
5
5
  "description": "Shinjuku Shielded, the private x402 facilitator 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": "70ff655b",
7
- "shinjukuSha256": "70ff655b113c19d39c8594566c77d38fe7d459ea415f66cda1c09919841ad1a9",
6
+ "shinjukuRelease": "e18d1d95",
7
+ "shinjukuSha256": "e18d1d9537ea063f2a28f88b4db41a1b93067c5d5aa4f300daaddf80d8544074",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-mcp#readme",
@@ -56468,21 +56468,38 @@ function zeroRoots() {
56468
56468
  zeroRootsMemo = Object.freeze(roots);
56469
56469
  return zeroRootsMemo;
56470
56470
  }
56471
- function foldCompactLeaves(leaves, counts, frontier) {
56471
+ function foldCompactLeavesFrom(leaves, counts, frontier, resume) {
56472
56472
  const zero = zeroRoots();
56473
- const filled = new Array(OUTER_DEPTH2);
56473
+ let filled = new Array(OUTER_DEPTH2);
56474
56474
  const roots = /* @__PURE__ */ new Map();
56475
56475
  if (counts.has(0)) roots.set(0, zero[OUTER_DEPTH2]);
56476
- leaves.forEach((leaf, position3) => {
56477
- appendCompactLeaf(filled, leaf, position3);
56478
- if (counts.has(position3 + 1)) roots.set(position3 + 1, compactRootAt(filled, position3 + 1));
56479
- });
56476
+ let position3 = 0;
56477
+ let appended = 0;
56478
+ const step = () => {
56479
+ appendCompactLeaf(filled, leaves[position3], position3);
56480
+ appended += 1;
56481
+ position3 += 1;
56482
+ if (counts.has(position3)) roots.set(position3, compactRootAt(filled, position3));
56483
+ };
56484
+ if (resume !== void 0) {
56485
+ let below = 0;
56486
+ for (const at of counts) {
56487
+ if (at <= 0 || at > resume.at) continue;
56488
+ const checkpoint = at === resume.at ? resume.filled : resume.checkpoints?.[at];
56489
+ if (checkpoint !== void 0) roots.set(at, compactRootAt(checkpoint, at));
56490
+ else if (at > below) below = at;
56491
+ }
56492
+ while (position3 < below) step();
56493
+ filled = resume.filled.slice();
56494
+ position3 = resume.at;
56495
+ }
56496
+ while (position3 < leaves.length) step();
56480
56497
  if (Array.isArray(frontier)) {
56481
56498
  for (let level = 0; level < OUTER_DEPTH2; level += 1) {
56482
56499
  frontier[level] = bitAt(leaves.length, level) === 1 ? filled[level] : zero[level];
56483
56500
  }
56484
56501
  }
56485
- return roots;
56502
+ return { roots, filled, appended };
56486
56503
  }
56487
56504
  function appendCompactLeaf(filled, leaf, position3) {
56488
56505
  let node3 = leaf;
@@ -56509,7 +56526,9 @@ function foldCompactLeavesReusing(pool2, leaves, counts, { frontier, fresh = /*
56509
56526
  while (common < most && prior.leaves[common] === leaves[common]) common += 1;
56510
56527
  }
56511
56528
  const known = (at) => prior !== void 0 && at <= common && prior.roots.has(at) && !fresh.has(at);
56512
- const roots = foldCompactLeaves(leaves, new Set([...counts].filter((at) => !known(at))), frontier);
56529
+ const resume = prior !== void 0 && Array.isArray(prior.filled) && prior.filled.length === OUTER_DEPTH2 && common > 0 && common === prior.leaves.length ? { at: common, filled: prior.filled, checkpoints: prior.checkpoints } : void 0;
56530
+ const folded = foldCompactLeavesFrom(leaves, new Set([...counts].filter((at) => !known(at))), frontier, resume);
56531
+ const { roots } = folded;
56513
56532
  if (prior !== void 0 && [...fresh].some((at) => at <= common && prior.roots.has(at) && roots.has(at) && prior.roots.get(at) !== roots.get(at))) {
56514
56533
  lastFolds.delete(pool2);
56515
56534
  if (stats) stats.refolded = true;
@@ -56524,7 +56543,7 @@ function foldCompactLeavesReusing(pool2, leaves, counts, { frontier, fresh = /*
56524
56543
  if (prior.tainted?.has(at)) cachedRoots.set(at, prior.roots.get(at));
56525
56544
  }
56526
56545
  }
56527
- if (stats) Object.assign(stats, { reused, cachedRoots });
56546
+ if (stats) Object.assign(stats, { reused, cachedRoots, resumedFrom: resume?.at, appended: folded.appended });
56528
56547
  const kept = new Map(roots);
56529
56548
  const tainted = new Set(cachedRoots.keys());
56530
56549
  if (prior !== void 0) {
@@ -56534,9 +56553,75 @@ function foldCompactLeavesReusing(pool2, leaves, counts, { frontier, fresh = /*
56534
56553
  if (prior.tainted?.has(at)) tainted.add(at);
56535
56554
  }
56536
56555
  }
56537
- lastFolds.set(pool2, { leaves: leaves.slice(), roots: kept, ...tainted.size > 0 ? { tainted } : {} });
56556
+ lastFolds.set(pool2, {
56557
+ leaves: leaves.slice(),
56558
+ roots: kept,
56559
+ filled: folded.filled,
56560
+ ...resume?.checkpoints !== void 0 ? { checkpoints: resume.checkpoints } : {},
56561
+ ...tainted.size > 0 ? { tainted } : {}
56562
+ });
56538
56563
  return roots;
56539
56564
  }
56565
+ function startCompactPreFold(pool2, cached) {
56566
+ const running = preFolds.get(pool2);
56567
+ if (running !== void 0) return running;
56568
+ const records = cached?.served?.records;
56569
+ if (lastFolds.has(pool2) || droppedPools.has(pool2) || !Array.isArray(records) || records.length === 0) return void 0;
56570
+ let hurry = false;
56571
+ const stats = { longestSliceMs: 0 };
56572
+ const done = (async () => {
56573
+ await new Promise((resolve38) => setImmediate(resolve38));
56574
+ markPhase("compact-prefold-start");
56575
+ const count2 = records.length;
56576
+ let cachedCount;
56577
+ let cachedRoot;
56578
+ try {
56579
+ cachedCount = BigInt(cached.snapshot.currentIndex) / SUBTREE_LEAVES3;
56580
+ cachedRoot = BigInt(cached.snapshot.currentRoot);
56581
+ } catch {
56582
+ cachedCount = void 0;
56583
+ }
56584
+ if (cachedCount !== BigInt(count2)) return markPhase("compact-prefold-skipped-count");
56585
+ const counts = /* @__PURE__ */ new Set([count2]);
56586
+ const anchorCounts = cached.snapshot.anchorCounts;
56587
+ if (Array.isArray(anchorCounts)) {
56588
+ for (const at of anchorCounts) if (Number.isSafeInteger(at) && at > 0 && at <= count2) counts.add(at);
56589
+ }
56590
+ const leaves = [];
56591
+ const filled = new Array(OUTER_DEPTH2);
56592
+ const checkpoints = new Array(count2 + 1);
56593
+ const roots = /* @__PURE__ */ new Map();
56594
+ let sliceStart = performance.now();
56595
+ for (let position3 = 0; position3 < count2; position3 += 1) {
56596
+ const hex4 = records[position3]?.outCommitment;
56597
+ if (typeof hex4 !== "string" || !HEX64.test(hex4)) return markPhase("compact-prefold-skipped-leaf");
56598
+ const leaf = BigInt(`0x${hex4}`);
56599
+ if (leaf >= FIELD_MODULUS5) return markPhase("compact-prefold-skipped-leaf");
56600
+ leaves.push(leaf);
56601
+ appendCompactLeaf(filled, leaf, position3);
56602
+ checkpoints[position3 + 1] = filled.slice();
56603
+ if (counts.has(position3 + 1)) roots.set(position3 + 1, compactRootAt(filled, position3 + 1));
56604
+ const sliceMs = performance.now() - sliceStart;
56605
+ if (!hurry && sliceMs >= PRE_FOLD_SLICE_MS) {
56606
+ if (sliceMs > stats.longestSliceMs) stats.longestSliceMs = sliceMs;
56607
+ await new Promise((resolve38) => setImmediate(resolve38));
56608
+ if (lastFolds.has(pool2)) return markPhase("compact-prefold-skipped-folded");
56609
+ sliceStart = performance.now();
56610
+ }
56611
+ }
56612
+ if (!hurry) stats.longestSliceMs = Math.max(stats.longestSliceMs, performance.now() - sliceStart);
56613
+ if (roots.get(count2) !== cachedRoot) return markPhase("compact-prefold-skipped-root");
56614
+ if (lastFolds.has(pool2) || droppedPools.has(pool2)) return markPhase("compact-prefold-skipped-folded");
56615
+ lastFolds.set(pool2, { leaves, roots, filled, checkpoints });
56616
+ return markPhase("compact-prefold-done");
56617
+ })().catch(() => {
56618
+ }).finally(() => preFolds.delete(pool2));
56619
+ const preFold = { done, hurry: () => {
56620
+ hurry = true;
56621
+ }, stats };
56622
+ preFolds.set(pool2, preFold);
56623
+ return preFold;
56624
+ }
56540
56625
  function sparseRoots(roots, count2) {
56541
56626
  const array = new Array(count2 + 1);
56542
56627
  array[0] = zeroRoots()[OUTER_DEPTH2];
@@ -57196,6 +57281,9 @@ async function readCompactP03HistoryNow({
57196
57281
  // compactP03HistoryReport: the compact cache's records and append roots ({ records, foldRoots }),
57197
57282
  // a hint for the fold when this process has not folded the pool yet (hintCompactFold).
57198
57283
  foldHint,
57284
+ // compactP03HistoryReport: the pre-fold of the cached leaves started while this read waits for
57285
+ // the pool account (startCompactPreFold, 2026-10-21). The fold below waits for its end first.
57286
+ preFold,
57199
57287
  // Called once with the served contexts in chain order, before the fold and every own-RPC
57200
57288
  // check: they are NOT verified yet. A payment asks the memo service for their memos here
57201
57289
  // (payAndFetch.mjs), and uses an answer only for a context the verified report names. Its
@@ -57315,6 +57403,10 @@ async function readCompactP03HistoryNow({
57315
57403
  reads.catch(() => {
57316
57404
  });
57317
57405
  await new Promise((resolve38) => setImmediate(resolve38));
57406
+ if (preFold !== void 0) {
57407
+ preFold.hurry();
57408
+ await preFold.done;
57409
+ }
57318
57410
  let frontier;
57319
57411
  let stats;
57320
57412
  try {
@@ -57332,7 +57424,9 @@ async function readCompactP03HistoryNow({
57332
57424
  }
57333
57425
  stats = {};
57334
57426
  roots = foldCompactLeavesReusing(poolString, leaves, counts, { frontier, fresh, stats });
57335
- if (stats.reused > 0 && anchors.some((anchor) => roots.get(Number(anchor.index / SUBTREE_LEAVES3)) !== anchor.root)) {
57427
+ const resumed = stats.resumedFrom !== void 0;
57428
+ if (resumed) markPhase("compact-fold-resumed");
57429
+ if ((stats.reused > 0 || resumed) && (roots.get(count2) !== snapshot.currentRoot || anchors.some((anchor) => roots.get(Number(anchor.index / SUBTREE_LEAVES3)) !== anchor.root))) {
57336
57430
  lastFolds.delete(poolString);
57337
57431
  stats.refolded = true;
57338
57432
  roots = foldCompactLeavesReusing(poolString, leaves, counts, { frontier, fresh });
@@ -57497,12 +57591,14 @@ async function compactP03HistoryReportRun({
57497
57591
  throw Object.assign(refuse3("p03_compact_history_deployment_unattested"), { cause: error, detail: own ?? failureCause(error) });
57498
57592
  }
57499
57593
  };
57594
+ const preFold = cached ? startCompactPreFold(poolKey.toBase58(), cached) : void 0;
57500
57595
  const compact = await readCompactP03History({
57501
57596
  history,
57502
57597
  own: connection,
57503
57598
  programId,
57504
57599
  pool: pool2,
57505
57600
  alongside: attest,
57601
+ ...preFold !== void 0 ? { preFold } : {},
57506
57602
  ...knownIndex !== void 0 ? { knownIndex } : {},
57507
57603
  ...knownSnapshot !== void 0 ? { knownSnapshot } : {},
57508
57604
  ...knownFirst !== void 0 ? { knownFirst } : {},
@@ -57578,7 +57674,10 @@ async function compactP03HistoryReportRun({
57578
57674
  slot: Number(snapshot.slot),
57579
57675
  terminal: snapshot.terminal,
57580
57676
  currentIndex: snapshot.currentIndex.toString(),
57581
- currentRoot: snapshot.currentRoot.toString()
57677
+ currentRoot: snapshot.currentRoot.toString(),
57678
+ // The anchor counts of this pool account (public; 2026-10-21, B): the next process's
57679
+ // pre-fold hashes their roots ahead. Counts only: every root is checked live again.
57680
+ anchorCounts: [...new Set(compact.finalizedPoolSnapshot.anchors.map((anchor) => Number(anchor.index / SUBTREE_LEAVES3)))]
57582
57681
  },
57583
57682
  served: compact.served,
57584
57683
  initialization,
@@ -57604,7 +57703,7 @@ async function tryCompactP03HistoryReport(options) {
57604
57703
  return { ok: false, reason, ...detail ? { detail } : {}, error };
57605
57704
  }
57606
57705
  }
57607
- var import_web397, 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_PREFIX2, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, hex64, droppedPools, verifyQuietMs, VERIFY_SLICE_MS, VERIFY_POLL_MS, verifying, unrefTurn, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, compactReportsRunning, compactHistoryReadsRunning;
57706
+ var import_web397, 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_PREFIX2, VERSION_1_PREFIX2, HEX64, BASE58, REPLAY_STORE_INDEXED2, PROFILES2, MOVE_HEAD_BYTES2, MOVE_INSERTED_VALUES2, refuse3, hash4, bitAt, zeroRootsMemo, lastFolds, PRE_FOLD_SLICE_MS, preFolds, hex64, droppedPools, verifyQuietMs, VERIFY_SLICE_MS, VERIFY_POLL_MS, verifying, unrefTurn, isSignature, isIndex, IMPORT_KEYS, IMPORT_MAX_VALUES, LIST_ATTEMPTS, OWN_READ_TIMEOUT_MS, BOUNDED_OWN_METHODS, compactReportsRunning, compactHistoryReadsRunning;
57608
57707
  var init_compact = __esm({
57609
57708
  "wallet/src/history/compact.mjs"() {
57610
57709
  "use strict";
@@ -57717,6 +57816,8 @@ var init_compact = __esm({
57717
57816
  hash4 = (left, right) => poseidon2([left, right], 3);
57718
57817
  bitAt = (value, level) => Math.floor(value / 2 ** level) % 2;
57719
57818
  lastFolds = /* @__PURE__ */ new Map();
57819
+ PRE_FOLD_SLICE_MS = 8;
57820
+ preFolds = /* @__PURE__ */ new Map();
57720
57821
  hex64 = (value) => value.toString(16).padStart(64, "0");
57721
57822
  droppedPools = /* @__PURE__ */ new Set();
57722
57823
  verifyQuietMs = 3e3;