shinjuku-shield 0.3.221 → 0.3.222

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
@@ -5,12 +5,12 @@ web services and AI answers from your private balance, so the payment does
5
5
  not show who paid. It works inside your AI app (Claude, Cursor, Codex) and in
6
6
  a terminal. Only you hold the keys: they never leave your computer.
7
7
 
8
- This is version 0.3.221. The command is `shinjuku`.
8
+ This is version 0.3.222. The command is `shinjuku`.
9
9
 
10
10
  ## Set up
11
11
 
12
12
  ```sh
13
- npx -y shinjuku@0.3.221 setup
13
+ npx -y shinjuku@0.3.222 setup
14
14
  ```
15
15
 
16
16
  Setup does every step for you:
@@ -100,7 +100,7 @@ Add it yourself. The name of the wallet in your app is `shinjuku`.
100
100
  Claude Code:
101
101
 
102
102
  ```sh
103
- claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.221 mcp
103
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.222 mcp
104
104
  ```
105
105
 
106
106
  ## For builders: check what you install
@@ -116,7 +116,7 @@ with the Releases table in
116
116
  Versions are published from GitHub Actions with npm provenance.
117
117
 
118
118
  `shinjuku-shield` is the package that holds the wallet. `shinjuku-shielded`
119
- 0.3.221, its older name, runs this package at the same version, so wallets
119
+ 0.3.222, its older name, runs this package at the same version, so wallets
120
120
  installed under that name keep updating. New installs use `shinjuku`.
121
121
 
122
122
  The full guide is
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": "52c863352dfca86ebd1266a905c55445c48cadc8b53b77d349725fd5062a2a62",
5
- "bytes": 10298934,
6
- "sourceCommit": "7411e830aea9ee9b7143b5c895a054606cfecaf8",
4
+ "sha256": "a2402ed74f220f3e905e948b89b40c954b82b7dfe205a190256513a3b530976a",
5
+ "bytes": 10301256,
6
+ "sourceCommit": "af208b57f4e1150cd0770d9cbfdc232c90bf7372",
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",
@@ -1075,8 +1075,8 @@
1075
1075
  ],
1076
1076
  "seller": {
1077
1077
  "file": "shinjuku-seller.mjs",
1078
- "sha256": "3fbd12397c06f6b157b183fafd86d9f0d72e708c0c97887833ead480da1aabe6",
1079
- "bytes": 4182433,
1078
+ "sha256": "0278f5d89c7b8a73482c5e156f7c28a96ece6b4746aca02626447e79cd55d815",
1079
+ "bytes": 4184815,
1080
1080
  "entry": "wallet/src/seller/exact/index.mjs",
1081
1081
  "external": [
1082
1082
  "@x402/core/http",
@@ -1968,5 +1968,5 @@
1968
1968
  }
1969
1969
  ]
1970
1970
  },
1971
- "publishedAt": "2026-11-12T16:14:06.249Z"
1971
+ "publishedAt": "2026-11-12T16:40:00.515Z"
1972
1972
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.221",
3
+ "version": "0.3.222",
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": "52c86335",
7
- "shinjukuSha256": "52c863352dfca86ebd1266a905c55445c48cadc8b53b77d349725fd5062a2a62",
6
+ "shinjukuRelease": "a2402ed7",
7
+ "shinjukuSha256": "a2402ed74f220f3e905e948b89b40c954b82b7dfe205a190256513a3b530976a",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shield",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -79437,7 +79437,7 @@ init_timing();
79437
79437
  import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
79438
79438
  import { createHash as createHash27, createHmac as createHmac12, randomBytes as randomBytes17, timingSafeEqual as timingSafeEqual4 } from "node:crypto";
79439
79439
  import net3 from "node:net";
79440
- import { basename as basename6, dirname as dirname20, join as join24 } from "node:path";
79440
+ import { basename as basename6, dirname as dirname20, join as join24, sep as sep3 } from "node:path";
79441
79441
  import { Readable } from "node:stream";
79442
79442
  import { pipeline } from "node:stream/promises";
79443
79443
  var ownTorPlatform = (platform = process.platform, arch = process.arch) => platform === "win32" || platform === "darwin" || platform === "linux" && arch === "x64";
@@ -80355,15 +80355,76 @@ async function ownTorReady(home, state2, { wait = true, deadline } = {}) {
80355
80355
  }
80356
80356
  return tunnelOf(state2.port);
80357
80357
  }
80358
- function ownPortOf(home) {
80359
- const state2 = managedTorState(home);
80360
- if (state2) return state2.port;
80361
- if (!bundleComplete(home) && !existsSync(join24(managedTorDir(home), "torrc"))) return void 0;
80358
+ var NOTICE_READ_MAX = 2 * 1024 * 1024;
80359
+ var TUNNEL_LISTENER_LINE = /^[A-Z][a-z]{2} [ 0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} \[notice\] Opened HTTP tunnel listener (?:connection \(ready\) )?on 127\.0\.0\.1:([0-9]{1,5})\r?$/gm;
80360
+ function readHomeFileTail(home, path, max) {
80361
+ try {
80362
+ const kind = lstatSync(path);
80363
+ if (!kind.isFile()) return void 0;
80364
+ if (!realpathSync(path).startsWith(`${realpathSync(home)}${sep3}`)) return void 0;
80365
+ const length = Math.min(kind.size, max);
80366
+ const bytes2 = Buffer.alloc(length);
80367
+ const fd = openSync(path, "r");
80368
+ try {
80369
+ readSync(fd, bytes2, 0, length, kind.size - length);
80370
+ } finally {
80371
+ closeSync(fd);
80372
+ }
80373
+ return bytes2.toString("utf8");
80374
+ } catch {
80375
+ return void 0;
80376
+ }
80377
+ }
80378
+ function loggedTunnelPorts(home) {
80379
+ const ports = /* @__PURE__ */ new Set();
80380
+ const text2 = readHomeFileTail(home, logFile(home), NOTICE_READ_MAX);
80381
+ if (text2 === void 0) return ports;
80382
+ for (const match of text2.matchAll(TUNNEL_LISTENER_LINE)) {
80383
+ const port = Number(match[1]);
80384
+ if (port > 0 && port < 65536) ports.add(port);
80385
+ }
80386
+ return ports;
80387
+ }
80388
+ var ownPortsFile = (home) => join24(managedTorDir(home), "own-ports.json");
80389
+ var OWN_PORTS_MAX = 256;
80390
+ var OWN_PORTS_READ_MAX = 16 * 1024;
80391
+ function recordedOwnPorts(home) {
80392
+ const text2 = readHomeFileTail(home, ownPortsFile(home), OWN_PORTS_READ_MAX + 1);
80393
+ if (text2 === void 0 || text2.length > OWN_PORTS_READ_MAX) return void 0;
80394
+ let parsed;
80362
80395
  try {
80363
- return Number(new URL(readSetupConfig(home)?.torTunnel ?? "").port) || void 0;
80396
+ parsed = JSON.parse(text2);
80364
80397
  } catch {
80365
80398
  return void 0;
80366
80399
  }
80400
+ if (!Array.isArray(parsed?.ports) || !parsed.ports.every((port) => Number.isInteger(port) && port > 0 && port < 65536)) return void 0;
80401
+ return parsed.ports;
80402
+ }
80403
+ function recordOwnPort(home, port) {
80404
+ try {
80405
+ const path = ownPortsFile(home);
80406
+ const known = recordedOwnPorts(home);
80407
+ if (known === void 0 && existsSync(path) && !lstatSync(path).isFile()) return;
80408
+ if (known?.includes(port)) return;
80409
+ writeAtomic(path, `${JSON.stringify({ ports: [...known ?? [], port].slice(-OWN_PORTS_MAX) })}
80410
+ `);
80411
+ } catch {
80412
+ }
80413
+ }
80414
+ function ownTunnelPort(home, tunnel) {
80415
+ let url;
80416
+ try {
80417
+ url = new URL(tunnel);
80418
+ } catch {
80419
+ return void 0;
80420
+ }
80421
+ if (url.protocol !== "http:" || url.hostname !== "127.0.0.1") return void 0;
80422
+ const port = Number(url.port);
80423
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) return void 0;
80424
+ const state2 = managedTorState(home);
80425
+ if (state2) return state2.port === port ? port : void 0;
80426
+ if (recordedOwnPorts(home)?.includes(port)) return port;
80427
+ return loggedTunnelPorts(home).has(port) ? port : void 0;
80367
80428
  }
80368
80429
  async function ensureWalletTor(proxy, { env = process.env, platform = process.platform, explicit = false, say = () => {
80369
80430
  } } = {}) {
@@ -80375,14 +80436,15 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
80375
80436
  return proxy;
80376
80437
  }
80377
80438
  const home = setupHome(env);
80378
- const ownPort = ownPortOf(home);
80379
- if (explicit && Number(url.port) !== ownPort) return proxy;
80439
+ const ownPort = explicit ? ownTunnelPort(home, proxy) : void 0;
80440
+ if (explicit && ownPort === void 0) return proxy;
80380
80441
  let deadline = Date.now() + BOOTSTRAP_MAX_MS;
80381
80442
  const timeLeft = () => deadline - Date.now();
80382
80443
  try {
80383
80444
  const known = managedTorState(home);
80384
80445
  const ready = await ownTorReady(home, known, { wait: false });
80385
80446
  if (ready && await processLockFree(lockName(home)) && pidAlive3(known.pid)) {
80447
+ recordOwnPort(home, known.port);
80386
80448
  await recordTunnel(home, ready, deadline);
80387
80449
  return ready;
80388
80450
  }
@@ -80397,6 +80459,7 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
80397
80459
  if (!(error?.stalled === true && timeLeft() >= RESTART_MIN_MS)) throw error;
80398
80460
  }
80399
80461
  if (again) {
80462
+ recordOwnPort(home, state2.port);
80400
80463
  await recordTunnel(home, again, deadline);
80401
80464
  return again;
80402
80465
  }
@@ -80427,6 +80490,7 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
80427
80490
  if (timeLeft() < RESTART_MIN_MS) throw noTimeLeft();
80428
80491
  try {
80429
80492
  await startTor(home, port, say, assertHeld, deadline);
80493
+ recordOwnPort(home, port);
80430
80494
  await recordTunnel(home, tunnelOf(port), deadline);
80431
80495
  return tunnelOf(port);
80432
80496
  } catch (error) {
@@ -80452,10 +80516,8 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
80452
80516
  setTunnelCircuitProbe(async ({ proxyHost, proxyPort } = {}) => {
80453
80517
  if (String(proxyHost) !== "127.0.0.1") return void 0;
80454
80518
  const home = setupHome(process.env);
80455
- const port = ownPortOf(home);
80456
- if (!Number.isInteger(port) || Number(proxyPort) !== port) return void 0;
80457
80519
  const state2 = managedTorState(home);
80458
- if (!state2 || state2.port !== port) return void 0;
80520
+ if (!state2 || Number(proxyPort) !== state2.port) return void 0;
80459
80521
  const answer = await controlCheck(home, state2, { circuits: true, unref: true });
80460
80522
  return answer && answer.tunnelPort === Number(proxyPort) ? answer.circuits : void 0;
80461
80523
  });
@@ -80648,11 +80710,12 @@ function proxyDispatcherClass() {
80648
80710
  async function sellerTor(recorded, home) {
80649
80711
  let tunnel = recorded;
80650
80712
  if (home) {
80651
- const current = readSetupConfig(home)?.torTunnel ?? recorded;
80713
+ const walletRecorded = readSetupConfig(home)?.torTunnel;
80714
+ const current = walletRecorded ?? recorded;
80652
80715
  try {
80653
80716
  tunnel = await ensureWalletTor(current, {
80654
80717
  env: { ...process.env, SHIELDED_WALLET_HOME: home },
80655
- explicit: true,
80718
+ explicit: walletRecorded !== void 0,
80656
80719
  say: (line) => process.stderr.write(`${line}
80657
80720
  `)
80658
80721
  });
@@ -139030,7 +139030,7 @@ function cloudPlace(place, { platform = process.platform, env = process.env, hom
139030
139030
  const text3 = String(place ?? "").trim();
139031
139031
  if (!text3) return void 0;
139032
139032
  const fold = platform === "win32" || platform === "darwin";
139033
- const sep6 = platform === "win32" ? "\\" : "/";
139033
+ const sep7 = platform === "win32" ? "\\" : "/";
139034
139034
  const norm = (path) => {
139035
139035
  const full = (platform === "win32" ? resolve26(localForm(path, platform)) : posix.resolve(path)).replace(/[\\/]+$/, "");
139036
139036
  return fold ? full.toLowerCase() : full;
@@ -139038,7 +139038,7 @@ function cloudPlace(place, { platform = process.platform, env = process.env, hom
139038
139038
  const at = norm(text3);
139039
139039
  for (const root of (roots ?? (() => cloudRoots({ platform, env, home })))()) {
139040
139040
  const base = norm(root.path);
139041
- if (base && (at === base || at.startsWith(`${base}${sep6}`))) return root.service;
139041
+ if (base && (at === base || at.startsWith(`${base}${sep7}`))) return root.service;
139042
139042
  }
139043
139043
  for (const part of text3.split(/[\\/]+/).map((name) => name.trim().toLowerCase())) {
139044
139044
  if (part === "onedrive" || part.startsWith("onedrive - ") || part.startsWith("onedrive-")) return "OneDrive";
@@ -161740,7 +161740,7 @@ ${words2}`;
161740
161740
  import { spawn as spawn11, spawnSync as spawnSync9 } from "node:child_process";
161741
161741
  import { createHash as createHash43, createHmac as createHmac15, randomBytes as randomBytes44, timingSafeEqual as timingSafeEqual6 } from "node:crypto";
161742
161742
  import net3 from "node:net";
161743
- import { basename as basename12, dirname as dirname42, join as join51 } from "node:path";
161743
+ import { basename as basename12, dirname as dirname42, join as join51, sep as sep6 } from "node:path";
161744
161744
  import { Readable } from "node:stream";
161745
161745
  import { pipeline } from "node:stream/promises";
161746
161746
  function bootstrapProgress(text3) {
@@ -162540,25 +162540,75 @@ async function ownTorReady(home, state2, { wait: wait2 = true, deadline } = {})
162540
162540
  }
162541
162541
  return tunnelOf(state2.port);
162542
162542
  }
162543
- function ownPortOf(home) {
162544
- const state2 = managedTorState(home);
162545
- if (state2) return state2.port;
162546
- if (!bundleComplete(home) && !existsSync(join51(managedTorDir(home), "torrc"))) return void 0;
162543
+ function readHomeFileTail(home, path, max) {
162547
162544
  try {
162548
- return Number(new URL(readSetupConfig(home)?.torTunnel ?? "").port) || void 0;
162545
+ const kind = lstatSync(path);
162546
+ if (!kind.isFile()) return void 0;
162547
+ if (!realpathSync(path).startsWith(`${realpathSync(home)}${sep6}`)) return void 0;
162548
+ const length = Math.min(kind.size, max);
162549
+ const bytes2 = Buffer.alloc(length);
162550
+ const fd = openSync(path, "r");
162551
+ try {
162552
+ readSync(fd, bytes2, 0, length, kind.size - length);
162553
+ } finally {
162554
+ closeSync(fd);
162555
+ }
162556
+ return bytes2.toString("utf8");
162549
162557
  } catch {
162550
162558
  return void 0;
162551
162559
  }
162552
162560
  }
162553
- function isWalletOwnTunnel(home, tunnel) {
162554
- const state2 = managedTorState(home);
162555
- if (!state2) return false;
162561
+ function loggedTunnelPorts(home) {
162562
+ const ports = /* @__PURE__ */ new Set();
162563
+ const text3 = readHomeFileTail(home, logFile(home), NOTICE_READ_MAX);
162564
+ if (text3 === void 0) return ports;
162565
+ for (const match of text3.matchAll(TUNNEL_LISTENER_LINE)) {
162566
+ const port = Number(match[1]);
162567
+ if (port > 0 && port < 65536) ports.add(port);
162568
+ }
162569
+ return ports;
162570
+ }
162571
+ function recordedOwnPorts(home) {
162572
+ const text3 = readHomeFileTail(home, ownPortsFile(home), OWN_PORTS_READ_MAX + 1);
162573
+ if (text3 === void 0 || text3.length > OWN_PORTS_READ_MAX) return void 0;
162574
+ let parsed2;
162556
162575
  try {
162557
- return new URL(tunnel).origin === new URL(tunnelOf(state2.port)).origin;
162576
+ parsed2 = JSON.parse(text3);
162577
+ } catch {
162578
+ return void 0;
162579
+ }
162580
+ if (!Array.isArray(parsed2?.ports) || !parsed2.ports.every((port) => Number.isInteger(port) && port > 0 && port < 65536)) return void 0;
162581
+ return parsed2.ports;
162582
+ }
162583
+ function recordOwnPort(home, port) {
162584
+ try {
162585
+ const path = ownPortsFile(home);
162586
+ const known = recordedOwnPorts(home);
162587
+ if (known === void 0 && existsSync(path) && !lstatSync(path).isFile()) return;
162588
+ if (known?.includes(port)) return;
162589
+ writeAtomic5(path, `${JSON.stringify({ ports: [...known ?? [], port].slice(-OWN_PORTS_MAX) })}
162590
+ `);
162558
162591
  } catch {
162559
- return false;
162560
162592
  }
162561
162593
  }
162594
+ function ownTunnelPort(home, tunnel) {
162595
+ let url;
162596
+ try {
162597
+ url = new URL(tunnel);
162598
+ } catch {
162599
+ return void 0;
162600
+ }
162601
+ if (url.protocol !== "http:" || url.hostname !== "127.0.0.1") return void 0;
162602
+ const port = Number(url.port);
162603
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) return void 0;
162604
+ const state2 = managedTorState(home);
162605
+ if (state2) return state2.port === port ? port : void 0;
162606
+ if (recordedOwnPorts(home)?.includes(port)) return port;
162607
+ return loggedTunnelPorts(home).has(port) ? port : void 0;
162608
+ }
162609
+ function isWalletOwnTunnel(home, tunnel) {
162610
+ return ownTunnelPort(home, tunnel) !== void 0;
162611
+ }
162562
162612
  async function setWalletTor(home, on, { say: say2 = () => {
162563
162613
  }, platform = process.platform } = {}) {
162564
162614
  let config;
@@ -162573,13 +162623,7 @@ async function setWalletTor(home, on, { say: say2 = () => {
162573
162623
  return { tor: false, agentAppRestart: true };
162574
162624
  }
162575
162625
  const recorded = config.torTunnel;
162576
- let recordedPort;
162577
- try {
162578
- recordedPort = recorded ? Number(new URL(recorded).port) : void 0;
162579
- } catch {
162580
- recordedPort = void 0;
162581
- }
162582
- const explicit = recorded !== void 0 && recordedPort !== ownPortOf(home);
162626
+ const explicit = recorded !== void 0 && ownTunnelPort(home, recorded) === void 0;
162583
162627
  const tunnel = await ensureWalletTor(recorded ?? TOR_HTTP_TUNNEL, { env: { ...process.env, SHIELDED_WALLET_HOME: home }, platform, explicit, say: say2 });
162584
162628
  if (!ownTorPlatform(platform) || explicit) {
162585
162629
  let now;
@@ -162603,14 +162647,15 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
162603
162647
  return proxy;
162604
162648
  }
162605
162649
  const home = setupHome(env);
162606
- const ownPort = ownPortOf(home);
162607
- if (explicit && Number(url.port) !== ownPort) return proxy;
162650
+ const ownPort = explicit ? ownTunnelPort(home, proxy) : void 0;
162651
+ if (explicit && ownPort === void 0) return proxy;
162608
162652
  let deadline = Date.now() + BOOTSTRAP_MAX_MS;
162609
162653
  const timeLeft = () => deadline - Date.now();
162610
162654
  try {
162611
162655
  const known = managedTorState(home);
162612
162656
  const ready = await ownTorReady(home, known, { wait: false });
162613
162657
  if (ready && await processLockFree(lockName(home)) && pidAlive5(known.pid)) {
162658
+ recordOwnPort(home, known.port);
162614
162659
  await recordTunnel(home, ready, deadline);
162615
162660
  return ready;
162616
162661
  }
@@ -162625,6 +162670,7 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
162625
162670
  if (!(error?.stalled === true && timeLeft() >= RESTART_MIN_MS)) throw error;
162626
162671
  }
162627
162672
  if (again) {
162673
+ recordOwnPort(home, state2.port);
162628
162674
  await recordTunnel(home, again, deadline);
162629
162675
  return again;
162630
162676
  }
@@ -162655,6 +162701,7 @@ async function ensureWalletTor(proxy, { env = process.env, platform = process.pl
162655
162701
  if (timeLeft() < RESTART_MIN_MS) throw noTimeLeft();
162656
162702
  try {
162657
162703
  await startTor(home, port, say2, assertHeld, deadline);
162704
+ recordOwnPort(home, port);
162658
162705
  await recordTunnel(home, tunnelOf(port), deadline);
162659
162706
  return tunnelOf(port);
162660
162707
  } catch (error) {
@@ -162744,7 +162791,7 @@ function startTorTimingMarks() {
162744
162791
  }
162745
162792
  });
162746
162793
  }
162747
- var ownTorPlatform, MAC, LINUX, SYSTEM2, bundle, managedTorDir, stateFile, bundleDir, torExe, MAC_SIGNED, COMPLETE, LINUX_TOR, BUNDLE_FILES, logFile, BOOTSTRAP_STALL_MS, BOOTSTRAP_MAX_MS, STALL_RESTART_PERCENT, RESTART_MIN_MS, REACHED_RELAY_PERCENT, phaseWords, DOWNLOAD_TIMEOUT_MS, BIND_TRIES, POLL_MS2, pidAlive5, WIN_OWN_TOR, STOP_WAIT_MS, cookieFile, CONTROL_TIMEOUT_MS, SERVER_KEY, CLIENT_KEY, failure2, sleep4, tunnelOf, bundleComplete, LINUX_HASHES, fileSha256, startErrorsFile, EVENT_LINE_MAX, TOR_TIMING_MAX, HS_DESC_ACTIONS, HS_DESC_REASONS, CIRC_STATUSES, CIRC_PURPOSES, CIRC_HS_STATES, CIRC_REASONS;
162794
+ var ownTorPlatform, MAC, LINUX, SYSTEM2, bundle, managedTorDir, stateFile, bundleDir, torExe, MAC_SIGNED, COMPLETE, LINUX_TOR, BUNDLE_FILES, logFile, BOOTSTRAP_STALL_MS, BOOTSTRAP_MAX_MS, STALL_RESTART_PERCENT, RESTART_MIN_MS, REACHED_RELAY_PERCENT, phaseWords, DOWNLOAD_TIMEOUT_MS, BIND_TRIES, POLL_MS2, pidAlive5, WIN_OWN_TOR, STOP_WAIT_MS, cookieFile, CONTROL_TIMEOUT_MS, SERVER_KEY, CLIENT_KEY, failure2, sleep4, tunnelOf, bundleComplete, LINUX_HASHES, fileSha256, startErrorsFile, NOTICE_READ_MAX, TUNNEL_LISTENER_LINE, ownPortsFile, OWN_PORTS_MAX, OWN_PORTS_READ_MAX, EVENT_LINE_MAX, TOR_TIMING_MAX, HS_DESC_ACTIONS, HS_DESC_REASONS, CIRC_STATUSES, CIRC_PURPOSES, CIRC_HS_STATES, CIRC_REASONS;
162748
162795
  var init_managedTor = __esm({
162749
162796
  "wallet/src/net/managedTor.mjs"() {
162750
162797
  "use strict";
@@ -162875,13 +162922,16 @@ public static class ShinjukuOwnTor {
162875
162922
  LINUX_HASHES = ".hashes.json";
162876
162923
  fileSha256 = (path) => createHash43("sha256").update(readFileSync(path)).digest("hex");
162877
162924
  startErrorsFile = (home) => join51(managedTorDir(home), "start-errors.log");
162925
+ NOTICE_READ_MAX = 2 * 1024 * 1024;
162926
+ TUNNEL_LISTENER_LINE = /^[A-Z][a-z]{2} [ 0-9]?[0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3} \[notice\] Opened HTTP tunnel listener (?:connection \(ready\) )?on 127\.0\.0\.1:([0-9]{1,5})\r?$/gm;
162927
+ ownPortsFile = (home) => join51(managedTorDir(home), "own-ports.json");
162928
+ OWN_PORTS_MAX = 256;
162929
+ OWN_PORTS_READ_MAX = 16 * 1024;
162878
162930
  setTunnelCircuitProbe(async ({ proxyHost, proxyPort } = {}) => {
162879
162931
  if (String(proxyHost) !== "127.0.0.1") return void 0;
162880
162932
  const home = setupHome(process.env);
162881
- const port = ownPortOf(home);
162882
- if (!Number.isInteger(port) || Number(proxyPort) !== port) return void 0;
162883
162933
  const state2 = managedTorState(home);
162884
- if (!state2 || state2.port !== port) return void 0;
162934
+ if (!state2 || Number(proxyPort) !== state2.port) return void 0;
162885
162935
  const answer = await controlCheck(home, state2, { circuits: true, unref: true });
162886
162936
  return answer && answer.tunnelPort === Number(proxyPort) ? answer.circuits : void 0;
162887
162937
  });
@@ -163127,11 +163177,12 @@ function proxyDispatcherClass() {
163127
163177
  async function sellerTor(recorded, home) {
163128
163178
  let tunnel = recorded;
163129
163179
  if (home) {
163130
- const current = readSetupConfig(home)?.torTunnel ?? recorded;
163180
+ const walletRecorded = readSetupConfig(home)?.torTunnel;
163181
+ const current = walletRecorded ?? recorded;
163131
163182
  try {
163132
163183
  tunnel = await ensureWalletTor(current, {
163133
163184
  env: { ...process.env, SHIELDED_WALLET_HOME: home },
163134
- explicit: true,
163185
+ explicit: walletRecorded !== void 0,
163135
163186
  say: (line) => process.stderr.write(`${line}
163136
163187
  `)
163137
163188
  });
@@ -172517,8 +172568,9 @@ function mcpSetupAdapter(values, home, deps) {
172517
172568
  // A "Use Tor?" yes: run() starts the wallet's own Tor first (mcpSetupBehindTor -> torTunnelReady -> ensureWalletTor)
172518
172569
  // when it applies, so the setup box probes no tunnel then (a live check on npm 0.3.219, a fresh computer, 2026-11-12 15:23:32 UTC: a
172519
172570
  // fresh home with nothing at 127.0.0.1:9080 stopped at tor_not_running with a terminal step before that start). The
172520
- // rule: an own-Tor platform, and no recorded torTunnel, or the recorded one is the tunnel managed.json names (the Tor
172521
- // this wallet started here; isWalletOwnTunnel). Any other recorded tunnel is the user's, and the box probes it.
172571
+ // rule: an own-Tor platform, and no recorded torTunnel, or the recorded one is this home's own Tor tunnel by the rule
172572
+ // every Tor run uses (isWalletOwnTunnel: managed.json, else tor\own-ports.json, else tor\notice.log; never config.json).
172573
+ // Any other recorded tunnel is the user's, and the box probes it.
172522
172574
  // torTunnel: the tunnel the probe checks otherwise (a Tor the user set, recorded in config.json; else the default).
172523
172575
  ownTor: () => {
172524
172576
  const recorded = configOrNull(home)?.torTunnel;
@@ -173403,7 +173455,7 @@ async function hostCheckProxy(home, deps, noTor) {
173403
173455
  if (proxy.tor) {
173404
173456
  if (!inProxiedRun(deps.env)) {
173405
173457
  try {
173406
- proxy = { ...proxy, url: await torTunnelReady(proxy.url, { explicit: proxy.url !== TOR_HTTP_TUNNEL }) };
173458
+ proxy = { ...proxy, url: await torTunnelReady(proxy.url, { explicit: proxy.explicit === true }) };
173407
173459
  } catch {
173408
173460
  return { down: true };
173409
173461
  }
@@ -173596,8 +173648,8 @@ Setup stopped. Run the same setup line again to finish it; files already downloa
173596
173648
  }
173597
173649
  function installProxy(deps, behindTor, tunnel) {
173598
173650
  const run2 = childRunProxy(deps.env).args;
173599
- if (run2[0] === "--tor") return { url: run2[2] ?? TOR_HTTP_TUNNEL, tor: true };
173600
- return behindTor ? { url: tunnel ?? TOR_HTTP_TUNNEL, tor: true } : void 0;
173651
+ if (run2[0] === "--tor") return { url: run2[2] ?? TOR_HTTP_TUNNEL, tor: true, explicit: run2[2] !== void 0 };
173652
+ return behindTor ? { url: tunnel ?? TOR_HTTP_TUNNEL, tor: true, explicit: tunnel !== void 0 } : void 0;
173601
173653
  }
173602
173654
  var COMMAND_NOT_INSTALLED = "The shinjuku command could not be installed on this computer; the longer command below works the same.";
173603
173655
  async function installCommand(deps, {
@@ -173621,7 +173673,7 @@ async function installCommand(deps, {
173621
173673
  tunnelOf2(proxy.url);
173622
173674
  if (!inProxiedRun(deps.env)) {
173623
173675
  try {
173624
- proxy = { ...proxy, url: await torTunnelReady(proxy.url, { explicit: proxy.url !== TOR_HTTP_TUNNEL }) };
173676
+ proxy = { ...proxy, url: await torTunnelReady(proxy.url, { explicit: proxy.explicit === true }) };
173625
173677
  } catch {
173626
173678
  return "tor-down";
173627
173679
  }