shinjuku-shield 0.3.222 → 0.3.224
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 +4 -4
- package/manifest.json +6 -6
- package/package.json +3 -3
- package/shinjuku-seller.mjs +101 -19
- package/shinjuku-wallet.mjs +273 -103
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.
|
|
8
|
+
This is version 0.3.224. The command is `shinjuku`.
|
|
9
9
|
|
|
10
10
|
## Set up
|
|
11
11
|
|
|
12
12
|
```sh
|
|
13
|
-
npx -y shinjuku@0.3.
|
|
13
|
+
npx -y shinjuku@0.3.224 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.
|
|
103
|
+
claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.224 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.
|
|
119
|
+
0.3.224, 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": "
|
|
5
|
-
"bytes":
|
|
6
|
-
"sourceCommit": "
|
|
4
|
+
"sha256": "1d84992b84ede1559b296b31a0d0a67d0551a6dfb14a97830b10f019a71147a4",
|
|
5
|
+
"bytes": 10309158,
|
|
6
|
+
"sourceCommit": "f770bc410e82af84b537f8e55313af223dfe1bfb",
|
|
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": "
|
|
1079
|
-
"bytes":
|
|
1078
|
+
"sha256": "e785def47b04adc745e1539616d38392c7e0ce990399d94cb20d7215122c26d6",
|
|
1079
|
+
"bytes": 4188398,
|
|
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-
|
|
1971
|
+
"publishedAt": "2026-11-12T18:01:50.905Z"
|
|
1972
1972
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shinjuku-shield",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.224",
|
|
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": "
|
|
7
|
-
"shinjukuSha256": "
|
|
6
|
+
"shinjukuRelease": "1d84992b",
|
|
7
|
+
"shinjukuSha256": "1d84992b84ede1559b296b31a0d0a67d0551a6dfb14a97830b10f019a71147a4",
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
9
9
|
"author": "Shinjuku Shield",
|
|
10
10
|
"homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
|
package/shinjuku-seller.mjs
CHANGED
|
@@ -33384,7 +33384,10 @@ function runSleep(ms) {
|
|
|
33384
33384
|
function registerRunDispatchers(list) {
|
|
33385
33385
|
sources.add(list);
|
|
33386
33386
|
}
|
|
33387
|
-
|
|
33387
|
+
function registerRunSockets(list) {
|
|
33388
|
+
socketSources.add(list);
|
|
33389
|
+
}
|
|
33390
|
+
var ended, sources, runEnded, runEndedError, sleeps, socketSources;
|
|
33388
33391
|
var init_runEnd = __esm({
|
|
33389
33392
|
"wallet/src/net/runEnd.mjs"() {
|
|
33390
33393
|
"use strict";
|
|
@@ -33394,6 +33397,7 @@ var init_runEnd = __esm({
|
|
|
33394
33397
|
runEnded = () => ended;
|
|
33395
33398
|
runEndedError = () => Object.assign(new Error("run_ended"), { code: "run_ended" });
|
|
33396
33399
|
sleeps = /* @__PURE__ */ new Set();
|
|
33400
|
+
socketSources = /* @__PURE__ */ new Set();
|
|
33397
33401
|
}
|
|
33398
33402
|
});
|
|
33399
33403
|
|
|
@@ -34877,8 +34881,15 @@ var init_keepAlive = __esm({
|
|
|
34877
34881
|
});
|
|
34878
34882
|
|
|
34879
34883
|
// wallet/src/net/tunnelGuard.mjs
|
|
34884
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
34880
34885
|
import net from "node:net";
|
|
34881
34886
|
import { Duplex } from "node:stream";
|
|
34887
|
+
function claimTunnelSignal() {
|
|
34888
|
+
const claim = tunnelSignal.getStore();
|
|
34889
|
+
if (claim === void 0 || claim.claimed || claim.signal.aborted) return void 0;
|
|
34890
|
+
claim.claimed = true;
|
|
34891
|
+
return claim.signal;
|
|
34892
|
+
}
|
|
34882
34893
|
function setTunnelCircuitProbe(probe) {
|
|
34883
34894
|
circuitProbe = typeof probe === "function" ? probe : void 0;
|
|
34884
34895
|
}
|
|
@@ -34889,9 +34900,14 @@ function tunnelClient(Dispatcher, proxyPort, proxyHost) {
|
|
|
34889
34900
|
async connect(params) {
|
|
34890
34901
|
const target = String(params?.path ?? "");
|
|
34891
34902
|
if (optimisticTarget(target)) return optimisticConnect(params, { proxyHost, proxyPort, closedInRow });
|
|
34903
|
+
if (runEnded()) throw runEndedError();
|
|
34904
|
+
const own = claimTunnelSignal();
|
|
34905
|
+
const signal = own === void 0 ? params?.signal : params?.signal ? AbortSignal.any([params.signal, own]) : own;
|
|
34906
|
+
const startedAt = Date.now();
|
|
34892
34907
|
try {
|
|
34893
|
-
const answer = await direct.connect(params);
|
|
34908
|
+
const answer = await direct.connect(signal === params?.signal ? params : { ...params, signal });
|
|
34894
34909
|
closedInRow.delete(target);
|
|
34910
|
+
if (answer?.socket && typeof answer.socket === "object") tunnelConnectMs.set(answer.socket, Date.now() - startedAt);
|
|
34895
34911
|
return answer;
|
|
34896
34912
|
} catch (error) {
|
|
34897
34913
|
if (error?.code !== "UND_ERR_SOCKET") throw error;
|
|
@@ -35037,8 +35053,17 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
35037
35053
|
});
|
|
35038
35054
|
stream.on("error", () => {
|
|
35039
35055
|
});
|
|
35056
|
+
openTunnelStreams.add(stream);
|
|
35057
|
+
stream.once("close", () => openTunnelStreams.delete(stream));
|
|
35058
|
+
if (runEnded()) {
|
|
35059
|
+
stream.destroy();
|
|
35060
|
+
return Promise.reject(runEndedError());
|
|
35061
|
+
}
|
|
35040
35062
|
const abortReason = () => params.signal?.reason ?? Object.assign(new Error("This operation was aborted"), { name: "AbortError", code: "ABORT_ERR" });
|
|
35041
|
-
if (params.signal?.aborted)
|
|
35063
|
+
if (params.signal?.aborted) {
|
|
35064
|
+
stream.destroy();
|
|
35065
|
+
return Promise.reject(abortReason());
|
|
35066
|
+
}
|
|
35042
35067
|
const onAbort = () => {
|
|
35043
35068
|
const reject = pendingReject;
|
|
35044
35069
|
pendingReject = void 0;
|
|
@@ -35053,6 +35078,10 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
35053
35078
|
};
|
|
35054
35079
|
params.signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
35055
35080
|
const dial = (first) => new Promise((resolve18, reject) => {
|
|
35081
|
+
if (runEnded()) {
|
|
35082
|
+
reject(runEndedError());
|
|
35083
|
+
return;
|
|
35084
|
+
}
|
|
35056
35085
|
pendingReject = reject;
|
|
35057
35086
|
reply = Buffer.alloc(0);
|
|
35058
35087
|
ready = false;
|
|
@@ -35114,6 +35143,10 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
35114
35143
|
stream.push(null);
|
|
35115
35144
|
return;
|
|
35116
35145
|
}
|
|
35146
|
+
if (runEnded()) {
|
|
35147
|
+
stream.destroy(runEndedError());
|
|
35148
|
+
return;
|
|
35149
|
+
}
|
|
35117
35150
|
const closed2 = (closedInRow.get(target) ?? 0) + 1;
|
|
35118
35151
|
mark("tunnel-closed", `n${closed2}`);
|
|
35119
35152
|
if (tooBigToReplay) {
|
|
@@ -35139,23 +35172,30 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
35139
35172
|
stream.once("close", () => params.signal?.removeEventListener?.("abort", onAbort));
|
|
35140
35173
|
return dial(true).then(() => ({ statusCode: 200, socket: stream, headers: {} }), (error) => {
|
|
35141
35174
|
params.signal?.removeEventListener?.("abort", onAbort);
|
|
35175
|
+
if (!stream.destroyed) stream.destroy();
|
|
35142
35176
|
throw error;
|
|
35143
35177
|
});
|
|
35144
35178
|
}
|
|
35145
|
-
var circuitProbe, RUN_MARK, TUNNEL_CLOSED_TRIES, REPLAY_LIMIT;
|
|
35179
|
+
var openTunnelStreams, tunnelSignal, circuitProbe, RUN_MARK, tunnelConnectMs, tunnelConnectMsOf, TUNNEL_CLOSED_TRIES, REPLAY_LIMIT;
|
|
35146
35180
|
var init_tunnelGuard = __esm({
|
|
35147
35181
|
"wallet/src/net/tunnelGuard.mjs"() {
|
|
35148
35182
|
"use strict";
|
|
35149
35183
|
init_keepAlive();
|
|
35150
35184
|
init_phaseTiming();
|
|
35185
|
+
init_runEnd();
|
|
35186
|
+
openTunnelStreams = /* @__PURE__ */ new Set();
|
|
35187
|
+
registerRunSockets(() => openTunnelStreams);
|
|
35188
|
+
tunnelSignal = new AsyncLocalStorage2();
|
|
35151
35189
|
RUN_MARK = "SHINJUKU_WALLET_PROXIED";
|
|
35190
|
+
tunnelConnectMs = /* @__PURE__ */ new WeakMap();
|
|
35191
|
+
tunnelConnectMsOf = (socket) => socket && typeof socket === "object" ? tunnelConnectMs.get(socket) : void 0;
|
|
35152
35192
|
TUNNEL_CLOSED_TRIES = 3;
|
|
35153
35193
|
REPLAY_LIMIT = 8 * 1024;
|
|
35154
35194
|
}
|
|
35155
35195
|
});
|
|
35156
35196
|
|
|
35157
35197
|
// wallet/src/net/facilitatorOnion.mjs
|
|
35158
|
-
import { AsyncLocalStorage as
|
|
35198
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
35159
35199
|
function onionRouteCold(url, sentAtMs = Date.now()) {
|
|
35160
35200
|
let origin;
|
|
35161
35201
|
try {
|
|
@@ -35247,7 +35287,7 @@ function untilAborted(promise, signal) {
|
|
|
35247
35287
|
promise.then(resolve18, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
35248
35288
|
});
|
|
35249
35289
|
}
|
|
35250
|
-
var SITE_ONIONS, SITE_SPARE_ONIONS, PINNED_FACILITATOR_ONIONS, PINNED_SPARE_ONIONS, HISTORY_ONIONS, HISTORY_SPARE_ONIONS, PINNED_HISTORY_ONIONS, PINNED_HISTORY_SPARE_ONIONS, KEPT_ANSWER_BYTES, streamScope, requestStreams, socketRequests, guarded, STREAM_CHANNELS, SPARE_CAUSE, routedOrigins, routedGroupOf, answeredOn, onionDispatchers, ownTag, ownTagDispatchers, onOwnTagNow, ownTagInit;
|
|
35290
|
+
var SITE_ONIONS, SITE_SPARE_ONIONS, PINNED_FACILITATOR_ONIONS, PINNED_SPARE_ONIONS, HISTORY_ONIONS, HISTORY_SPARE_ONIONS, PINNED_HISTORY_ONIONS, PINNED_HISTORY_SPARE_ONIONS, KEPT_ANSWER_BYTES, streamScope, requestStreams, socketRequests, guarded, STREAM_CHANNELS, SPARE_CAUSE, routedOrigins, routedGroupOf, answeredOn, tagRoutes, isKey, noteRoute, TAG_LETTERS, onionDispatchers, ownTag, ownTagDispatchers, onOwnTagNow, ownTagInit;
|
|
35251
35291
|
var init_facilitatorOnion = __esm({
|
|
35252
35292
|
"wallet/src/net/facilitatorOnion.mjs"() {
|
|
35253
35293
|
"use strict";
|
|
@@ -35278,7 +35318,7 @@ var init_facilitatorOnion = __esm({
|
|
|
35278
35318
|
PINNED_HISTORY_ONIONS = Object.freeze({ [HISTORY_ONIONS[0]]: HISTORY_ONIONS });
|
|
35279
35319
|
PINNED_HISTORY_SPARE_ONIONS = Object.freeze({ [HISTORY_ONIONS[0]]: HISTORY_SPARE_ONIONS });
|
|
35280
35320
|
KEPT_ANSWER_BYTES = 16 * 1024;
|
|
35281
|
-
streamScope = new
|
|
35321
|
+
streamScope = new AsyncLocalStorage3();
|
|
35282
35322
|
requestStreams = /* @__PURE__ */ new WeakMap();
|
|
35283
35323
|
socketRequests = /* @__PURE__ */ new WeakMap();
|
|
35284
35324
|
guarded = (fn) => (message) => {
|
|
@@ -35306,14 +35346,29 @@ var init_facilitatorOnion = __esm({
|
|
|
35306
35346
|
if (!stream || stream.request !== request || stream.sentAt !== void 0) return;
|
|
35307
35347
|
stream.sentAt = Date.now();
|
|
35308
35348
|
stream.kind = !known ? "unknown" : sent === 1 ? "new" : "reused";
|
|
35349
|
+
if (stream.kind === "new") stream.connectMs = tunnelConnectMsOf(socket);
|
|
35350
|
+
if (known && Number.isInteger(socket.localPort)) stream.localPort = socket.localPort;
|
|
35351
|
+
if (stream.route) noteRoute(stream.route.dispatcher, stream.route.onion);
|
|
35309
35352
|
})
|
|
35310
35353
|
});
|
|
35311
35354
|
SPARE_CAUSE = Object.freeze({ silent: "no pinned onion answered", failed: "every pinned probe failed", wait: "a request's route wait ended" });
|
|
35312
35355
|
routedOrigins = /* @__PURE__ */ new Map();
|
|
35313
35356
|
routedGroupOf = /* @__PURE__ */ new Map();
|
|
35314
35357
|
answeredOn = /* @__PURE__ */ new WeakMap();
|
|
35358
|
+
tagRoutes = /* @__PURE__ */ new WeakMap();
|
|
35359
|
+
isKey = (value2) => value2 !== null && (typeof value2 === "object" || typeof value2 === "function");
|
|
35360
|
+
noteRoute = (dispatcher, onion) => {
|
|
35361
|
+
try {
|
|
35362
|
+
if (!isKey(dispatcher) || typeof onion !== "string") return;
|
|
35363
|
+
let onions = tagRoutes.get(dispatcher);
|
|
35364
|
+
if (!onions) tagRoutes.set(dispatcher, onions = /* @__PURE__ */ new Set());
|
|
35365
|
+
onions.add(onion);
|
|
35366
|
+
} catch {
|
|
35367
|
+
}
|
|
35368
|
+
};
|
|
35369
|
+
TAG_LETTERS = Object.freeze({ run: "r", own: "o", given: "g", none: "n" });
|
|
35315
35370
|
onionDispatchers = /* @__PURE__ */ new Map();
|
|
35316
|
-
ownTag = new
|
|
35371
|
+
ownTag = new AsyncLocalStorage3();
|
|
35317
35372
|
ownTagDispatchers = /* @__PURE__ */ new Set();
|
|
35318
35373
|
registerRunDispatchers(() => [...onionDispatchers.values(), ...ownTagDispatchers]);
|
|
35319
35374
|
onOwnTagNow = () => ownTag.getStore()?.dispatcher !== void 0;
|
|
@@ -38019,7 +38074,7 @@ async function rpcFetch(input, init) {
|
|
|
38019
38074
|
rpcNotBefore.set(post.key, Math.max(rpcNotBefore.get(post.key) ?? 0, Date.now() + retryAfterMs(response)));
|
|
38020
38075
|
}
|
|
38021
38076
|
}
|
|
38022
|
-
var relayKeyOf, READ_ONLY_METHOD, readOnlyPost, TOR_HTTP_TUNNEL, LOCAL_PROOF_TIMEOUT_MS, LOCAL_PROOF_MAX_BYTES, MARK, ownProxyRefused, ONION_V3, RETRY_AFTER_CAP_MS, RETRY_AFTER_FLOOR_MS, RETRY_AFTER_DEFAULT_MS, RPC_NO_ANSWER_LIMIT_MS, RPC_PACING_CAP_MS, PACING_NOTICE_EVERY_MS, PACING_RATE_WINDOW_MS, TOR_MAX_ROTATIONS, runStartedAt, rpcNotBefore, pacingWaiters, pacingSince, pacedMs, rpcAnswered, lastAnswerAt, readSteps, pacingNoticeAt, pacingSamples, torMoves, torCircuitId, torTagStartedAt, torMovesRefused, pendingMove, inTorRunOf, inTorRun, isOnionOrigin, ownTorControlAllowance, OWN_TOR_CONTROL_ALLOWANCE_MS, TOR_MIN_VERSION, TOR_EXPERT_BUNDLE, TOR_EXPERT_BUNDLE_SHA256, TOR_ARCHIVE, TOR_EXPERT_BUNDLE_URL, TOR_EXPERT_BUNDLES, TUNNEL_LINE, TOR_DEB_KEY, TOR_DEB_KEYRING, TOR_INSTALL, torStart, LOCAL_TUNNEL, torStartText, TOR_WINDOW, torUpdateHow, TOR_STOP_OLD_WINDOWS, torTooOldWhy, TOR_WAIT_WORDS, TOR_WAIT_PLAIN, withRunTag, proxyEnv, pacedSoFar, RESENDABLE_METHOD, torCircuit, laneDispatchers, laneOfDispatcher, ONION_COLD_KEEP_MS, coldStallSaidOn, HOUR_CLOSURES;
|
|
38077
|
+
var relayKeyOf, READ_ONLY_METHOD, readOnlyPost, TOR_HTTP_TUNNEL, LOCAL_PROOF_TIMEOUT_MS, LOCAL_PROOF_MAX_BYTES, MARK, ownProxyRefused, ONION_V3, RETRY_AFTER_CAP_MS, RETRY_AFTER_FLOOR_MS, RETRY_AFTER_DEFAULT_MS, RPC_NO_ANSWER_LIMIT_MS, RPC_PACING_CAP_MS, PACING_NOTICE_EVERY_MS, PACING_RATE_WINDOW_MS, TOR_MAX_ROTATIONS, runStartedAt, rpcNotBefore, pacingWaiters, pacingSince, pacedMs, rpcAnswered, lastAnswerAt, readSteps, pacingNoticeAt, pacingSamples, torMoves, torCircuitId, torTagStartedAt, torMovesRefused, pendingMove, inTorRunOf, inTorRun, isOnionOrigin, ownTorControlAllowance, OWN_TOR_CONTROL_ALLOWANCE_MS, tunnelSockets, TOR_MIN_VERSION, TOR_EXPERT_BUNDLE, TOR_EXPERT_BUNDLE_SHA256, TOR_ARCHIVE, TOR_EXPERT_BUNDLE_URL, TOR_EXPERT_BUNDLES, TUNNEL_LINE, TOR_DEB_KEY, TOR_DEB_KEYRING, TOR_INSTALL, torStart, LOCAL_TUNNEL, torStartText, TOR_WINDOW, torUpdateHow, TOR_STOP_OLD_WINDOWS, torTooOldWhy, TOR_WAIT_WORDS, TOR_WAIT_PLAIN, withRunTag, proxyEnv, pacedSoFar, RESENDABLE_METHOD, torCircuit, laneDispatchers, laneOfDispatcher, ONION_COLD_KEEP_MS, coldStallSaidOn, HOUR_CLOSURES;
|
|
38023
38078
|
var init_proxy = __esm({
|
|
38024
38079
|
"wallet/src/net/proxy.mjs"() {
|
|
38025
38080
|
"use strict";
|
|
@@ -38078,6 +38133,8 @@ var init_proxy = __esm({
|
|
|
38078
38133
|
inTorRun = () => inTorRunOf(process.env);
|
|
38079
38134
|
isOnionOrigin = (url) => inTorRun() && url?.protocol === "http:" && ONION_V3.test(url.hostname);
|
|
38080
38135
|
OWN_TOR_CONTROL_ALLOWANCE_MS = 1e3;
|
|
38136
|
+
tunnelSockets = /* @__PURE__ */ new Set();
|
|
38137
|
+
registerRunSockets(() => tunnelSockets);
|
|
38081
38138
|
TOR_MIN_VERSION = Object.freeze([0, 4, 9, 13]);
|
|
38082
38139
|
TOR_EXPERT_BUNDLE = "15.0.25";
|
|
38083
38140
|
TOR_EXPERT_BUNDLE_SHA256 = "c1988c701de2f24f7d098d1d6d7f507b58f27740d097f29c246e0524d639b252";
|
|
@@ -53498,7 +53555,7 @@ var init_readTokenCrypto = __esm({
|
|
|
53498
53555
|
|
|
53499
53556
|
// wallet/src/net/readTokens.mjs
|
|
53500
53557
|
import { createHash as createHash11, createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey3, randomBytes as randomBytes10, sign } from "node:crypto";
|
|
53501
|
-
import { AsyncLocalStorage as
|
|
53558
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
53502
53559
|
import { dirname as dirname11, join as join11 } from "node:path";
|
|
53503
53560
|
function depositReadTokenProver(seed) {
|
|
53504
53561
|
const key2 = createPrivateKey2({ key: Buffer.concat([ED25519_PKCS8_PREFIX, Buffer.from(seed).subarray(0, 32)]), format: "der", type: "pkcs8" });
|
|
@@ -53942,7 +53999,7 @@ var init_readTokens = __esm({
|
|
|
53942
53999
|
throttledUntil = /* @__PURE__ */ new Map();
|
|
53943
54000
|
RETRY_AFTER_MIN_MS = 3e4;
|
|
53944
54001
|
RETRY_AFTER_DEFAULT_MS2 = 6e4;
|
|
53945
|
-
userAction = new
|
|
54002
|
+
userAction = new AsyncLocalStorage4();
|
|
53946
54003
|
userActionNow = () => {
|
|
53947
54004
|
const scope2 = userAction.getStore();
|
|
53948
54005
|
return scope2?.open === true && typeof scope2.walletPath === "string" ? scope2 : void 0;
|
|
@@ -61981,7 +62038,7 @@ var init_incremental = __esm({
|
|
|
61981
62038
|
});
|
|
61982
62039
|
|
|
61983
62040
|
// wallet/src/history/walletHistory.mjs
|
|
61984
|
-
import { AsyncLocalStorage as
|
|
62041
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
61985
62042
|
import { createHmac as createHmac7 } from "node:crypto";
|
|
61986
62043
|
import { dirname as dirname13, join as join13, resolve as resolve9 } from "node:path";
|
|
61987
62044
|
function sweepFolderOnce(folder) {
|
|
@@ -62790,8 +62847,8 @@ var init_walletHistory = __esm({
|
|
|
62790
62847
|
init_runEnd();
|
|
62791
62848
|
init_rpcRefusal();
|
|
62792
62849
|
init_store();
|
|
62793
|
-
strictScope = new
|
|
62794
|
-
recentScope = new
|
|
62850
|
+
strictScope = new AsyncLocalStorage5();
|
|
62851
|
+
recentScope = new AsyncLocalStorage5();
|
|
62795
62852
|
recentLoads = /* @__PURE__ */ new Map();
|
|
62796
62853
|
recentAgeStart = (recent) => recent.ageFrom ?? poolReadAtOf(recent.report) ?? recent.startedAt;
|
|
62797
62854
|
proofBuiltAt = 0;
|
|
@@ -79827,7 +79884,7 @@ AUTHCHALLENGE SAFECOOKIE ${clientNonce.toString("hex")}\r
|
|
|
79827
79884
|
}
|
|
79828
79885
|
if (step === 2 && typeof events === "function") {
|
|
79829
79886
|
step = 6;
|
|
79830
|
-
socket.write("SETEVENTS HS_DESC CIRC\r\n");
|
|
79887
|
+
socket.write("SETEVENTS HS_DESC CIRC STREAM\r\n");
|
|
79831
79888
|
continue;
|
|
79832
79889
|
}
|
|
79833
79890
|
if (step === 6) {
|
|
@@ -80522,7 +80579,7 @@ setTunnelCircuitProbe(async ({ proxyHost, proxyPort } = {}) => {
|
|
|
80522
80579
|
return answer && answer.tunnelPort === Number(proxyPort) ? answer.circuits : void 0;
|
|
80523
80580
|
});
|
|
80524
80581
|
var EVENT_LINE_MAX = 4096;
|
|
80525
|
-
var TOR_TIMING_MAX =
|
|
80582
|
+
var TOR_TIMING_MAX = 800;
|
|
80526
80583
|
var HS_DESC_ACTIONS = /* @__PURE__ */ new Set(["REQUESTED", "RECEIVED", "FAILED"]);
|
|
80527
80584
|
var HS_DESC_REASONS = /* @__PURE__ */ new Set([
|
|
80528
80585
|
"BAD_DESC",
|
|
@@ -80562,6 +80619,7 @@ var CIRC_REASONS = /* @__PURE__ */ new Set([
|
|
|
80562
80619
|
"MEASUREMENT_EXPIRED",
|
|
80563
80620
|
"IP_NOW_REDUNDANT"
|
|
80564
80621
|
]);
|
|
80622
|
+
var STREAM_STATUSES = /* @__PURE__ */ new Set(["NEW", "SENTCONNECT", "SUCCEEDED", "FAILED", "CLOSED", "DETACHED"]);
|
|
80565
80623
|
function ownOnionPrefixes() {
|
|
80566
80624
|
const all = [
|
|
80567
80625
|
...FACILITATOR_SITE_ONIONS,
|
|
@@ -80585,6 +80643,13 @@ function torTimingMark(line, ours) {
|
|
|
80585
80643
|
if (!prefix2 || !HS_DESC_ACTIONS.has(desc[1]) || reason2 !== void 0 && !HS_DESC_REASONS.has(reason2)) return void 0;
|
|
80586
80644
|
return { phase: `hs-desc-${desc[1].toLowerCase()}`, outcome: `onion_${prefix2}${reason2 ? `_${reason2.toLowerCase()}` : ""}` };
|
|
80587
80645
|
}
|
|
80646
|
+
const stream = /^650 STREAM (\d{1,20}) ([A-Z_]+) (\d{1,10}) ([a-z2-7]{56})\.onion:\d{1,5}(?: |$)/.exec(line);
|
|
80647
|
+
if (stream) {
|
|
80648
|
+
const prefix2 = ours.get(stream[4]);
|
|
80649
|
+
if (!prefix2 || !STREAM_STATUSES.has(stream[2])) return void 0;
|
|
80650
|
+
const port = stream[2] === "NEW" ? /(?:^| )SOURCE_ADDR=127\.0\.0\.1:(\d{1,5})(?: |$)/.exec(line)?.[1] : void 0;
|
|
80651
|
+
return { phase: `stream-${stream[2].toLowerCase()}`, outcome: `onion_${prefix2}_s${stream[1]}_c${stream[3]}${port ? `_lp${port}` : ""}` };
|
|
80652
|
+
}
|
|
80588
80653
|
const circ = /^650 CIRC (\d{1,10}) ([A-Z_]+) /.exec(`${line} `);
|
|
80589
80654
|
if (!circ || !CIRC_STATUSES.has(circ[2])) return void 0;
|
|
80590
80655
|
const rend = /(?:^| )REND_QUERY=([a-z2-7]{56})(?: |$)/.exec(line)?.[1];
|
|
@@ -80597,7 +80662,7 @@ function torTimingMark(line, ours) {
|
|
|
80597
80662
|
}
|
|
80598
80663
|
function startTorTimingMarks() {
|
|
80599
80664
|
const run2 = String(process.env.SHINJUKU_WALLET_PROXIED ?? "");
|
|
80600
|
-
if (!run2.startsWith("tor ") || !process.argv.includes("--verbose")) return;
|
|
80665
|
+
if (!run2.startsWith("tor ") || !(process.argv.includes("--verbose") || process.argv[2] === "mcp")) return;
|
|
80601
80666
|
setImmediate(async () => {
|
|
80602
80667
|
try {
|
|
80603
80668
|
const home = setupHome(process.env);
|
|
@@ -80613,17 +80678,34 @@ function startTorTimingMarks() {
|
|
|
80613
80678
|
const ours = ownOnionPrefixes();
|
|
80614
80679
|
const mark = createTimingLog(join24(home, pool2, "wallet.json.timing.log"), { component: "tor" }).start({ startedAt: Date.now() - performance.now() });
|
|
80615
80680
|
let marks = 0;
|
|
80681
|
+
let session;
|
|
80682
|
+
let spent = false;
|
|
80683
|
+
const closeSession = () => {
|
|
80684
|
+
try {
|
|
80685
|
+
session?.close();
|
|
80686
|
+
} catch {
|
|
80687
|
+
}
|
|
80688
|
+
};
|
|
80616
80689
|
const once2 = (phase, outcome) => {
|
|
80617
80690
|
if (marks >= TOR_TIMING_MAX) return;
|
|
80618
80691
|
marks += 1;
|
|
80619
80692
|
mark(phase, outcome);
|
|
80693
|
+
if (marks >= TOR_TIMING_MAX) {
|
|
80694
|
+
spent = true;
|
|
80695
|
+
closeSession();
|
|
80696
|
+
}
|
|
80620
80697
|
};
|
|
80621
|
-
|
|
80698
|
+
session = await controlCheck(home, state2, { unref: true, events: (line) => {
|
|
80699
|
+
if (spent) return;
|
|
80622
80700
|
const one = torTimingMark(line, ours);
|
|
80623
80701
|
if (one) once2(one.phase, one.outcome);
|
|
80624
80702
|
} });
|
|
80625
80703
|
if (!session) return;
|
|
80626
|
-
|
|
80704
|
+
if (spent) {
|
|
80705
|
+
closeSession();
|
|
80706
|
+
return;
|
|
80707
|
+
}
|
|
80708
|
+
process.once("exit", closeSession);
|
|
80627
80709
|
once2("events-on");
|
|
80628
80710
|
} catch {
|
|
80629
80711
|
}
|
package/shinjuku-wallet.mjs
CHANGED
|
@@ -43784,9 +43784,104 @@ var init_keepAlive = __esm({
|
|
|
43784
43784
|
}
|
|
43785
43785
|
});
|
|
43786
43786
|
|
|
43787
|
+
// wallet/src/net/runEnd.mjs
|
|
43788
|
+
function runSleep(ms) {
|
|
43789
|
+
if (ended) return Promise.resolve();
|
|
43790
|
+
return new Promise((resolve43) => {
|
|
43791
|
+
const entry = { resolve: resolve43, timer: void 0 };
|
|
43792
|
+
entry.timer = setTimeout(() => {
|
|
43793
|
+
sleeps.delete(entry);
|
|
43794
|
+
resolve43();
|
|
43795
|
+
}, ms);
|
|
43796
|
+
sleeps.add(entry);
|
|
43797
|
+
});
|
|
43798
|
+
}
|
|
43799
|
+
function registerRunDispatchers(list) {
|
|
43800
|
+
sources.add(list);
|
|
43801
|
+
}
|
|
43802
|
+
function registerRunSockets(list) {
|
|
43803
|
+
socketSources.add(list);
|
|
43804
|
+
}
|
|
43805
|
+
function holdRunEnd(reason = "held") {
|
|
43806
|
+
held ??= String(reason);
|
|
43807
|
+
}
|
|
43808
|
+
function endRun({ stderr = process.stderr } = {}) {
|
|
43809
|
+
if (held !== void 0) return false;
|
|
43810
|
+
if (ended) return true;
|
|
43811
|
+
ended = true;
|
|
43812
|
+
for (const entry of sleeps) {
|
|
43813
|
+
clearTimeout(entry.timer);
|
|
43814
|
+
entry.resolve();
|
|
43815
|
+
}
|
|
43816
|
+
sleeps.clear();
|
|
43817
|
+
try {
|
|
43818
|
+
stderr.write = (chunk, encoding, callback) => {
|
|
43819
|
+
const done = typeof encoding === "function" ? encoding : callback;
|
|
43820
|
+
if (typeof done === "function") queueMicrotask(() => done());
|
|
43821
|
+
return true;
|
|
43822
|
+
};
|
|
43823
|
+
} catch {
|
|
43824
|
+
}
|
|
43825
|
+
const all = /* @__PURE__ */ new Set([activeGlobalDispatcher()]);
|
|
43826
|
+
for (const list of sources) {
|
|
43827
|
+
try {
|
|
43828
|
+
for (const dispatcher of list()) all.add(dispatcher);
|
|
43829
|
+
} catch {
|
|
43830
|
+
}
|
|
43831
|
+
}
|
|
43832
|
+
for (const dispatcher of all) {
|
|
43833
|
+
try {
|
|
43834
|
+
dispatcher?.destroy?.()?.catch?.(() => {
|
|
43835
|
+
});
|
|
43836
|
+
} catch {
|
|
43837
|
+
}
|
|
43838
|
+
}
|
|
43839
|
+
for (const name of ["node:http", "node:https"]) {
|
|
43840
|
+
try {
|
|
43841
|
+
process.getBuiltinModule(name).globalAgent.destroy();
|
|
43842
|
+
} catch {
|
|
43843
|
+
}
|
|
43844
|
+
}
|
|
43845
|
+
for (const list of socketSources) {
|
|
43846
|
+
try {
|
|
43847
|
+
for (const socket of [...list()]) {
|
|
43848
|
+
try {
|
|
43849
|
+
socket.destroy();
|
|
43850
|
+
} catch {
|
|
43851
|
+
}
|
|
43852
|
+
}
|
|
43853
|
+
} catch {
|
|
43854
|
+
}
|
|
43855
|
+
}
|
|
43856
|
+
return true;
|
|
43857
|
+
}
|
|
43858
|
+
var ended, held, sources, runEnded, runEndedError, sleeps, socketSources;
|
|
43859
|
+
var init_runEnd = __esm({
|
|
43860
|
+
"wallet/src/net/runEnd.mjs"() {
|
|
43861
|
+
"use strict";
|
|
43862
|
+
init_globalDispatcher();
|
|
43863
|
+
ended = false;
|
|
43864
|
+
sources = /* @__PURE__ */ new Set();
|
|
43865
|
+
runEnded = () => ended;
|
|
43866
|
+
runEndedError = () => Object.assign(new Error("run_ended"), { code: "run_ended" });
|
|
43867
|
+
sleeps = /* @__PURE__ */ new Set();
|
|
43868
|
+
socketSources = /* @__PURE__ */ new Set();
|
|
43869
|
+
}
|
|
43870
|
+
});
|
|
43871
|
+
|
|
43787
43872
|
// wallet/src/net/tunnelGuard.mjs
|
|
43873
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
43788
43874
|
import net from "node:net";
|
|
43789
43875
|
import { Duplex } from "node:stream";
|
|
43876
|
+
function withTunnelSignal(signal, task) {
|
|
43877
|
+
return signal === void 0 ? task() : tunnelSignal.run({ signal, claimed: false }, task);
|
|
43878
|
+
}
|
|
43879
|
+
function claimTunnelSignal() {
|
|
43880
|
+
const claim = tunnelSignal.getStore();
|
|
43881
|
+
if (claim === void 0 || claim.claimed || claim.signal.aborted) return void 0;
|
|
43882
|
+
claim.claimed = true;
|
|
43883
|
+
return claim.signal;
|
|
43884
|
+
}
|
|
43790
43885
|
function setTunnelCircuitProbe(probe) {
|
|
43791
43886
|
circuitProbe = typeof probe === "function" ? probe : void 0;
|
|
43792
43887
|
}
|
|
@@ -43797,9 +43892,14 @@ function tunnelClient(Dispatcher, proxyPort, proxyHost) {
|
|
|
43797
43892
|
async connect(params) {
|
|
43798
43893
|
const target = String(params?.path ?? "");
|
|
43799
43894
|
if (optimisticTarget(target)) return optimisticConnect(params, { proxyHost, proxyPort, closedInRow });
|
|
43895
|
+
if (runEnded()) throw runEndedError();
|
|
43896
|
+
const own = claimTunnelSignal();
|
|
43897
|
+
const signal = own === void 0 ? params?.signal : params?.signal ? AbortSignal.any([params.signal, own]) : own;
|
|
43898
|
+
const startedAt = Date.now();
|
|
43800
43899
|
try {
|
|
43801
|
-
const answer = await direct.connect(params);
|
|
43900
|
+
const answer = await direct.connect(signal === params?.signal ? params : { ...params, signal });
|
|
43802
43901
|
closedInRow.delete(target);
|
|
43902
|
+
if (answer?.socket && typeof answer.socket === "object") tunnelConnectMs.set(answer.socket, Date.now() - startedAt);
|
|
43803
43903
|
return answer;
|
|
43804
43904
|
} catch (error) {
|
|
43805
43905
|
if (error?.code !== "UND_ERR_SOCKET") throw error;
|
|
@@ -43945,8 +44045,17 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
43945
44045
|
});
|
|
43946
44046
|
stream.on("error", () => {
|
|
43947
44047
|
});
|
|
44048
|
+
openTunnelStreams.add(stream);
|
|
44049
|
+
stream.once("close", () => openTunnelStreams.delete(stream));
|
|
44050
|
+
if (runEnded()) {
|
|
44051
|
+
stream.destroy();
|
|
44052
|
+
return Promise.reject(runEndedError());
|
|
44053
|
+
}
|
|
43948
44054
|
const abortReason = () => params.signal?.reason ?? Object.assign(new Error("This operation was aborted"), { name: "AbortError", code: "ABORT_ERR" });
|
|
43949
|
-
if (params.signal?.aborted)
|
|
44055
|
+
if (params.signal?.aborted) {
|
|
44056
|
+
stream.destroy();
|
|
44057
|
+
return Promise.reject(abortReason());
|
|
44058
|
+
}
|
|
43950
44059
|
const onAbort = () => {
|
|
43951
44060
|
const reject = pendingReject;
|
|
43952
44061
|
pendingReject = void 0;
|
|
@@ -43961,6 +44070,10 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
43961
44070
|
};
|
|
43962
44071
|
params.signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
43963
44072
|
const dial = (first) => new Promise((resolve43, reject) => {
|
|
44073
|
+
if (runEnded()) {
|
|
44074
|
+
reject(runEndedError());
|
|
44075
|
+
return;
|
|
44076
|
+
}
|
|
43964
44077
|
pendingReject = reject;
|
|
43965
44078
|
reply = Buffer.alloc(0);
|
|
43966
44079
|
ready = false;
|
|
@@ -44022,6 +44135,10 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
44022
44135
|
stream.push(null);
|
|
44023
44136
|
return;
|
|
44024
44137
|
}
|
|
44138
|
+
if (runEnded()) {
|
|
44139
|
+
stream.destroy(runEndedError());
|
|
44140
|
+
return;
|
|
44141
|
+
}
|
|
44025
44142
|
const closed2 = (closedInRow.get(target) ?? 0) + 1;
|
|
44026
44143
|
mark("tunnel-closed", `n${closed2}`);
|
|
44027
44144
|
if (tooBigToReplay) {
|
|
@@ -44047,93 +44164,30 @@ ${Object.entries(params.headers ?? {}).filter(([name, value2]) => value2 !== voi
|
|
|
44047
44164
|
stream.once("close", () => params.signal?.removeEventListener?.("abort", onAbort));
|
|
44048
44165
|
return dial(true).then(() => ({ statusCode: 200, socket: stream, headers: {} }), (error) => {
|
|
44049
44166
|
params.signal?.removeEventListener?.("abort", onAbort);
|
|
44167
|
+
if (!stream.destroyed) stream.destroy();
|
|
44050
44168
|
throw error;
|
|
44051
44169
|
});
|
|
44052
44170
|
}
|
|
44053
|
-
var circuitProbe, RUN_MARK, TUNNEL_CLOSED_TRIES, REPLAY_LIMIT;
|
|
44171
|
+
var openTunnelStreams, tunnelSignal, circuitProbe, RUN_MARK, tunnelConnectMs, tunnelConnectMsOf, TUNNEL_CLOSED_TRIES, REPLAY_LIMIT;
|
|
44054
44172
|
var init_tunnelGuard = __esm({
|
|
44055
44173
|
"wallet/src/net/tunnelGuard.mjs"() {
|
|
44056
44174
|
"use strict";
|
|
44057
44175
|
init_keepAlive();
|
|
44058
44176
|
init_phaseTiming();
|
|
44177
|
+
init_runEnd();
|
|
44178
|
+
openTunnelStreams = /* @__PURE__ */ new Set();
|
|
44179
|
+
registerRunSockets(() => openTunnelStreams);
|
|
44180
|
+
tunnelSignal = new AsyncLocalStorage2();
|
|
44059
44181
|
RUN_MARK = "SHINJUKU_WALLET_PROXIED";
|
|
44182
|
+
tunnelConnectMs = /* @__PURE__ */ new WeakMap();
|
|
44183
|
+
tunnelConnectMsOf = (socket) => socket && typeof socket === "object" ? tunnelConnectMs.get(socket) : void 0;
|
|
44060
44184
|
TUNNEL_CLOSED_TRIES = 3;
|
|
44061
44185
|
REPLAY_LIMIT = 8 * 1024;
|
|
44062
44186
|
}
|
|
44063
44187
|
});
|
|
44064
44188
|
|
|
44065
|
-
// wallet/src/net/runEnd.mjs
|
|
44066
|
-
function runSleep(ms) {
|
|
44067
|
-
if (ended) return Promise.resolve();
|
|
44068
|
-
return new Promise((resolve43) => {
|
|
44069
|
-
const entry = { resolve: resolve43, timer: void 0 };
|
|
44070
|
-
entry.timer = setTimeout(() => {
|
|
44071
|
-
sleeps.delete(entry);
|
|
44072
|
-
resolve43();
|
|
44073
|
-
}, ms);
|
|
44074
|
-
sleeps.add(entry);
|
|
44075
|
-
});
|
|
44076
|
-
}
|
|
44077
|
-
function registerRunDispatchers(list) {
|
|
44078
|
-
sources.add(list);
|
|
44079
|
-
}
|
|
44080
|
-
function holdRunEnd(reason = "held") {
|
|
44081
|
-
held ??= String(reason);
|
|
44082
|
-
}
|
|
44083
|
-
function endRun({ stderr = process.stderr } = {}) {
|
|
44084
|
-
if (held !== void 0) return false;
|
|
44085
|
-
if (ended) return true;
|
|
44086
|
-
ended = true;
|
|
44087
|
-
for (const entry of sleeps) {
|
|
44088
|
-
clearTimeout(entry.timer);
|
|
44089
|
-
entry.resolve();
|
|
44090
|
-
}
|
|
44091
|
-
sleeps.clear();
|
|
44092
|
-
try {
|
|
44093
|
-
stderr.write = (chunk, encoding, callback) => {
|
|
44094
|
-
const done = typeof encoding === "function" ? encoding : callback;
|
|
44095
|
-
if (typeof done === "function") queueMicrotask(() => done());
|
|
44096
|
-
return true;
|
|
44097
|
-
};
|
|
44098
|
-
} catch {
|
|
44099
|
-
}
|
|
44100
|
-
const all = /* @__PURE__ */ new Set([activeGlobalDispatcher()]);
|
|
44101
|
-
for (const list of sources) {
|
|
44102
|
-
try {
|
|
44103
|
-
for (const dispatcher of list()) all.add(dispatcher);
|
|
44104
|
-
} catch {
|
|
44105
|
-
}
|
|
44106
|
-
}
|
|
44107
|
-
for (const dispatcher of all) {
|
|
44108
|
-
try {
|
|
44109
|
-
dispatcher?.destroy?.()?.catch?.(() => {
|
|
44110
|
-
});
|
|
44111
|
-
} catch {
|
|
44112
|
-
}
|
|
44113
|
-
}
|
|
44114
|
-
for (const name of ["node:http", "node:https"]) {
|
|
44115
|
-
try {
|
|
44116
|
-
process.getBuiltinModule(name).globalAgent.destroy();
|
|
44117
|
-
} catch {
|
|
44118
|
-
}
|
|
44119
|
-
}
|
|
44120
|
-
return true;
|
|
44121
|
-
}
|
|
44122
|
-
var ended, held, sources, runEnded, runEndedError, sleeps;
|
|
44123
|
-
var init_runEnd = __esm({
|
|
44124
|
-
"wallet/src/net/runEnd.mjs"() {
|
|
44125
|
-
"use strict";
|
|
44126
|
-
init_globalDispatcher();
|
|
44127
|
-
ended = false;
|
|
44128
|
-
sources = /* @__PURE__ */ new Set();
|
|
44129
|
-
runEnded = () => ended;
|
|
44130
|
-
runEndedError = () => Object.assign(new Error("run_ended"), { code: "run_ended" });
|
|
44131
|
-
sleeps = /* @__PURE__ */ new Set();
|
|
44132
|
-
}
|
|
44133
|
-
});
|
|
44134
|
-
|
|
44135
44189
|
// wallet/src/net/facilitatorOnion.mjs
|
|
44136
|
-
import { AsyncLocalStorage as
|
|
44190
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
44137
44191
|
import diagnosticsChannel2 from "node:diagnostics_channel";
|
|
44138
44192
|
function subscribeStreamChannels() {
|
|
44139
44193
|
streamSubscribers += 1;
|
|
@@ -44156,6 +44210,19 @@ function unsubscribeStreamChannels() {
|
|
|
44156
44210
|
}
|
|
44157
44211
|
}
|
|
44158
44212
|
}
|
|
44213
|
+
function tagOf(init, routedInit) {
|
|
44214
|
+
try {
|
|
44215
|
+
let base = init?.dispatcher;
|
|
44216
|
+
if (base && typeof base.tagDispatcher === "function") base = base.tagDispatcher() ?? base;
|
|
44217
|
+
const dispatcher = base ?? routedInit?.dispatcher;
|
|
44218
|
+
if (!isKey(dispatcher)) return { dispatcher: void 0, tag: "none" };
|
|
44219
|
+
if (ownTagDispatchers.has(dispatcher)) return { dispatcher, tag: "own" };
|
|
44220
|
+
for (const kept3 of onionDispatchers.values()) if (kept3 === dispatcher) return { dispatcher, tag: "run" };
|
|
44221
|
+
return { dispatcher, tag: "given" };
|
|
44222
|
+
} catch {
|
|
44223
|
+
return { dispatcher: void 0, tag: "none" };
|
|
44224
|
+
}
|
|
44225
|
+
}
|
|
44159
44226
|
function onionRouteCold(url, sentAtMs2 = Date.now()) {
|
|
44160
44227
|
let origin;
|
|
44161
44228
|
try {
|
|
@@ -44185,6 +44252,7 @@ function markFirstOnionRaces(timingLog) {
|
|
|
44185
44252
|
firstRacesMarked = true;
|
|
44186
44253
|
moveTimingLog = timingLog;
|
|
44187
44254
|
for (const move of moveRecords.splice(0)) writeMove(move);
|
|
44255
|
+
for (const record of requestRecords.splice(0)) writeRequest(record);
|
|
44188
44256
|
for (const record of firstRaceRecords) {
|
|
44189
44257
|
record.then((race) => {
|
|
44190
44258
|
const mark = timingLog.start({ startedAt: race.startedAt });
|
|
@@ -44264,7 +44332,7 @@ function warmOnions({ onions = routedOnions(), fetchImpl = globalThis.fetch, tim
|
|
|
44264
44332
|
const controller = new AbortController();
|
|
44265
44333
|
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(timeoutMs)]);
|
|
44266
44334
|
for (const onion of new Set(onions)) {
|
|
44267
|
-
Promise.resolve().then(() => fetchImpl(`${onion}/api/health`, onionInit({ redirect: "error", signal, headers: { accept: "application/json" } }))).then((response) => response?.body?.cancel()).catch(() => {
|
|
44335
|
+
Promise.resolve().then(() => withTunnelSignal(signal, () => fetchImpl(`${onion}/api/health`, onionInit({ redirect: "error", signal, headers: { accept: "application/json" } })))).then((response) => response?.body?.cancel()).catch(() => {
|
|
44268
44336
|
});
|
|
44269
44337
|
}
|
|
44270
44338
|
return () => controller.abort();
|
|
@@ -44283,7 +44351,7 @@ function raceOnions(onions, {
|
|
|
44283
44351
|
} = {}) {
|
|
44284
44352
|
const controller = new AbortController();
|
|
44285
44353
|
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(timeoutMs)]);
|
|
44286
|
-
const probe = (onion) => Promise.resolve().then(() => fetchImpl(`${onion}${path}`, onionInit({ redirect: "error", signal, headers: { accept: "application/json" } }))).then(async (response) => {
|
|
44354
|
+
const probe = (onion) => Promise.resolve().then(() => withTunnelSignal(signal, () => fetchImpl(`${onion}${path}`, onionInit({ redirect: "error", signal, headers: { accept: "application/json" } })))).then(async (response) => {
|
|
44287
44355
|
if (keep && response?.status === 200) {
|
|
44288
44356
|
const body = await boundedBody(response, KEPT_ANSWER_BYTES);
|
|
44289
44357
|
return { onion, answer: body === void 0 ? void 0 : { status: 200, contentType: response.headers.get("content-type"), body } };
|
|
@@ -44562,6 +44630,7 @@ async function routeOverOnions(argv2, {
|
|
|
44562
44630
|
});
|
|
44563
44631
|
group.pending = raced.winner.then((onion) => {
|
|
44564
44632
|
if (!unanswered2 && !raced.stopped) noteAnswered(group, raceDispatcher);
|
|
44633
|
+
if (!unanswered2 && !raced.stopped) noteRoute(raceDispatcher, onion);
|
|
44565
44634
|
const answer = raced.answer();
|
|
44566
44635
|
group.answer = answer && !raced.stopped ? { ...answer, path: SITE_PROBE_PATH, atMs: Date.now() } : void 0;
|
|
44567
44636
|
if (first) Object.assign(first, { endedAt: Date.now(), answered: !unanswered2 });
|
|
@@ -44603,7 +44672,7 @@ async function routeOverOnions(argv2, {
|
|
|
44603
44672
|
} } : {}
|
|
44604
44673
|
}).startSpares;
|
|
44605
44674
|
}
|
|
44606
|
-
const moveOn = (group, onion, why, { request, ageMs }) => {
|
|
44675
|
+
const moveOn = (group, onion, why, { request, ageMs, tag: tag2 }) => {
|
|
44607
44676
|
if (stopped || group.winner !== onion || group.pending) return;
|
|
44608
44677
|
endHedge(group, onion);
|
|
44609
44678
|
group.moves = (group.moves ?? 0) + 1;
|
|
@@ -44619,7 +44688,7 @@ async function routeOverOnions(argv2, {
|
|
|
44619
44688
|
group.live = group.onions.length;
|
|
44620
44689
|
group.winner = void 0;
|
|
44621
44690
|
const role = roleOf(group, onion);
|
|
44622
|
-
const move = { at: Date.now(), role, request, cause: why === "the stream failed" ? "stream_failed" : "timeout", ageMs };
|
|
44691
|
+
const move = { at: Date.now(), role, request, cause: why === "the stream failed" ? "stream_failed" : "timeout", ageMs, tag: tag2 };
|
|
44623
44692
|
if (moveTimingLog) writeMove(move);
|
|
44624
44693
|
else moveRecords.push(move);
|
|
44625
44694
|
err(`tor: the onion ${hostOf(onion)} of ${group.label} gave no answer (${why}); its requests move to the first of ${others.map(hostOf).join(", ")} to answer (move ${group.moves} of ${max}; the request was ${request} to ${role}, sent ${(ageMs / 1e3).toFixed(1)} s before)
|
|
@@ -44664,6 +44733,8 @@ async function routeOverOnions(argv2, {
|
|
|
44664
44733
|
hedgeAborts.add(hedge.abort);
|
|
44665
44734
|
const role = roleOf(group, onion);
|
|
44666
44735
|
const streamNow = streamWords(stream);
|
|
44736
|
+
const tagNow = tagWords(stream);
|
|
44737
|
+
const hedgeDispatcher = onionInit({}).dispatcher;
|
|
44667
44738
|
err(`tor: the onion ${hostOf(onion)} of ${group.label} has not started its answer in ${HEDGE_MS / 1e3} s (the request was ${request} to ${role}, on ${streamText(stream)}); the other onions race for the next requests, and that request keeps waiting
|
|
44668
44739
|
`);
|
|
44669
44740
|
raced.winner.then((won) => {
|
|
@@ -44673,6 +44744,7 @@ async function routeOverOnions(argv2, {
|
|
|
44673
44744
|
hedge.waiters = [];
|
|
44674
44745
|
if (hedge.ended || !answered2 || stopped || group.winner !== onion || group.pending) return;
|
|
44675
44746
|
group.winner = won;
|
|
44747
|
+
noteRoute(hedgeDispatcher, won);
|
|
44676
44748
|
(group.hedgedFrom ??= /* @__PURE__ */ new Set()).add(onion);
|
|
44677
44749
|
const move = {
|
|
44678
44750
|
at: Date.now(),
|
|
@@ -44681,7 +44753,8 @@ async function routeOverOnions(argv2, {
|
|
|
44681
44753
|
request,
|
|
44682
44754
|
cause: `to_${roleOf(group, won).replaceAll("-", "_")}`,
|
|
44683
44755
|
ageMs: ageMs + (Date.now() - hedge.startedAt),
|
|
44684
|
-
stream: streamNow
|
|
44756
|
+
stream: streamNow,
|
|
44757
|
+
tag: tagNow
|
|
44685
44758
|
};
|
|
44686
44759
|
if (moveTimingLog) writeMove(move);
|
|
44687
44760
|
else moveRecords.push(move);
|
|
@@ -44737,12 +44810,18 @@ async function routeOverOnions(argv2, {
|
|
|
44737
44810
|
return original(input instanceof Request ? new Request(target, input) : target, routedInit);
|
|
44738
44811
|
};
|
|
44739
44812
|
const sentAt = Date.now();
|
|
44740
|
-
const
|
|
44813
|
+
const tagged = tagOf(init, routedInit);
|
|
44814
|
+
const stream = streamRecord(tagged, onion);
|
|
44741
44815
|
const sent = streamScope.run(stream, () => sendTo(onion));
|
|
44742
44816
|
sent.then(() => noteAnswered(group, routedInit.dispatcher), () => {
|
|
44743
44817
|
});
|
|
44744
|
-
if (group.onions.length < 2) return sent;
|
|
44745
44818
|
const request = requestLabel(group, method, url);
|
|
44819
|
+
const markSend = (promise, to, record, phase) => promise.then(
|
|
44820
|
+
() => noteRequest({ at: Date.now(), role: roleOf(group, to), request, stream: record, phase }),
|
|
44821
|
+
() => noteRequest({ at: Date.now(), role: roleOf(group, to), request, stream: record, phase, failed: true })
|
|
44822
|
+
);
|
|
44823
|
+
markSend(sent, onion, stream, "onion:request");
|
|
44824
|
+
if (group.onions.length < 2) return sent;
|
|
44746
44825
|
const hedgeable = group.kind !== "history" && !init?.ownLane && onion === group.winner && !CHAIN_WAIT_LABELS.has(request);
|
|
44747
44826
|
let headTimer;
|
|
44748
44827
|
const clearHead = () => {
|
|
@@ -44762,7 +44841,7 @@ async function routeOverOnions(argv2, {
|
|
|
44762
44841
|
}, (error) => {
|
|
44763
44842
|
clearHead();
|
|
44764
44843
|
const why = noAnswer(error, signal);
|
|
44765
|
-
if (why && !init?.ownLane) moveOn(group, onion, why, { request, ageMs: Date.now() - sentAt });
|
|
44844
|
+
if (why && !init?.ownLane) moveOn(group, onion, why, { request, ageMs: Date.now() - sentAt, tag: tagWords(stream) });
|
|
44766
44845
|
throw error;
|
|
44767
44846
|
});
|
|
44768
44847
|
if (!hedgeable) return tracked;
|
|
@@ -44789,7 +44868,10 @@ async function routeOverOnions(argv2, {
|
|
|
44789
44868
|
onSwitch = (won) => {
|
|
44790
44869
|
if (done || signal?.aborted || runEnded()) return;
|
|
44791
44870
|
open5 += 1;
|
|
44792
|
-
|
|
44871
|
+
const resendStream = streamRecord(tagged, won);
|
|
44872
|
+
const resent = streamScope.run(resendStream, () => sendTo(won));
|
|
44873
|
+
markSend(resent, won, resendStream, "onion:resend");
|
|
44874
|
+
resent.then(win, lose);
|
|
44793
44875
|
};
|
|
44794
44876
|
});
|
|
44795
44877
|
headTimer = setTimeout(() => {
|
|
@@ -44823,7 +44905,7 @@ async function routeOverOnions(argv2, {
|
|
|
44823
44905
|
}
|
|
44824
44906
|
};
|
|
44825
44907
|
}
|
|
44826
|
-
var SITE_ONIONS, SITE_SPARE_ONIONS, PINNED_FACILITATOR_ONIONS, PINNED_SPARE_ONIONS, HISTORY_ONIONS, HISTORY_SPARE_ONIONS, PINNED_HISTORY_ONIONS, PINNED_HISTORY_SPARE_ONIONS, HISTORY_PROBE_PATH, SITE_PROBE_PATH, SITE_PROBE_ANSWERS, KEPT_ANSWER_MS, KEPT_ANSWER_BYTES, KEPT_BODY_MS, FACILITATOR_FLAGS, V3_ONION, DISCOVERY_TIMEOUT_MS, WARM_TIMEOUT_MS, RACE_TIMEOUT_MS, ROUTE_WAIT_MS, SPARE_AFTER_MS, HISTORY_SPARE_AFTER_MS, HEDGE_MS, streamScope, requestStreams, socketRequests, guarded, STREAM_CHANNELS, streamSubscribers, streamWords, streamText, RESEND_LABELS, CHAIN_WAIT_LABELS, SPARE_CAUSE, routedGroups, liveOnions, hostOf, noAnswer, routedOnions, routedOrigins, onionsOfOrigin, routesOverOnion, routedGroupOf, answeredOn, noteAnswered, firstRaces, firstRaceRecords, firstRacesMarked, roleOf, ROUTE_LABELS, requestLabel, moveRecords, moveTimingLog, writeMove, firstOnionRace, onionDispatchers, ownTag, ownTagDispatchers, onOwnTagNow, ownTagInit;
|
|
44908
|
+
var SITE_ONIONS, SITE_SPARE_ONIONS, PINNED_FACILITATOR_ONIONS, PINNED_SPARE_ONIONS, HISTORY_ONIONS, HISTORY_SPARE_ONIONS, PINNED_HISTORY_ONIONS, PINNED_HISTORY_SPARE_ONIONS, HISTORY_PROBE_PATH, SITE_PROBE_PATH, SITE_PROBE_ANSWERS, KEPT_ANSWER_MS, KEPT_ANSWER_BYTES, KEPT_BODY_MS, FACILITATOR_FLAGS, V3_ONION, DISCOVERY_TIMEOUT_MS, WARM_TIMEOUT_MS, RACE_TIMEOUT_MS, ROUTE_WAIT_MS, SPARE_AFTER_MS, HISTORY_SPARE_AFTER_MS, HEDGE_MS, streamScope, requestStreams, socketRequests, guarded, STREAM_CHANNELS, streamSubscribers, streamWords, streamText, RESEND_LABELS, CHAIN_WAIT_LABELS, SPARE_CAUSE, routedGroups, liveOnions, hostOf, noAnswer, routedOnions, routedOrigins, onionsOfOrigin, routesOverOnion, routedGroupOf, answeredOn, tagRoutes, isKey, tagHasRoute, noteRoute, streamRecord, TAG_LETTERS, tagWords, OUTCOME_MAX, noteAnswered, firstRaces, firstRaceRecords, firstRacesMarked, roleOf, ROUTE_LABELS, requestLabel, moveRecords, moveTimingLog, writeMove, REQUEST_RECORDS_MAX, requestRecords, requestOutcome, writeRequest, REQUEST_MARK_FAST_MS, noteRequest, firstOnionRace, onionDispatchers, ownTag, ownTagDispatchers, onOwnTagNow, ownTagInit;
|
|
44827
44909
|
var init_facilitatorOnion = __esm({
|
|
44828
44910
|
"wallet/src/net/facilitatorOnion.mjs"() {
|
|
44829
44911
|
"use strict";
|
|
@@ -44868,7 +44950,7 @@ var init_facilitatorOnion = __esm({
|
|
|
44868
44950
|
SPARE_AFTER_MS = 4e3;
|
|
44869
44951
|
HISTORY_SPARE_AFTER_MS = 8e3;
|
|
44870
44952
|
HEDGE_MS = 5e3;
|
|
44871
|
-
streamScope = new
|
|
44953
|
+
streamScope = new AsyncLocalStorage3();
|
|
44872
44954
|
requestStreams = /* @__PURE__ */ new WeakMap();
|
|
44873
44955
|
socketRequests = /* @__PURE__ */ new WeakMap();
|
|
44874
44956
|
guarded = (fn) => (message) => {
|
|
@@ -44896,6 +44978,9 @@ var init_facilitatorOnion = __esm({
|
|
|
44896
44978
|
if (!stream || stream.request !== request || stream.sentAt !== void 0) return;
|
|
44897
44979
|
stream.sentAt = Date.now();
|
|
44898
44980
|
stream.kind = !known ? "unknown" : sent === 1 ? "new" : "reused";
|
|
44981
|
+
if (stream.kind === "new") stream.connectMs = tunnelConnectMsOf(socket);
|
|
44982
|
+
if (known && Number.isInteger(socket.localPort)) stream.localPort = socket.localPort;
|
|
44983
|
+
if (stream.route) noteRoute(stream.route.dispatcher, stream.route.onion);
|
|
44899
44984
|
})
|
|
44900
44985
|
});
|
|
44901
44986
|
streamSubscribers = 0;
|
|
@@ -44932,6 +45017,31 @@ var init_facilitatorOnion = __esm({
|
|
|
44932
45017
|
routesOverOnion = (origin) => routedOrigins.has(origin);
|
|
44933
45018
|
routedGroupOf = /* @__PURE__ */ new Map();
|
|
44934
45019
|
answeredOn = /* @__PURE__ */ new WeakMap();
|
|
45020
|
+
tagRoutes = /* @__PURE__ */ new WeakMap();
|
|
45021
|
+
isKey = (value2) => value2 !== null && (typeof value2 === "object" || typeof value2 === "function");
|
|
45022
|
+
tagHasRoute = (dispatcher, onion) => {
|
|
45023
|
+
try {
|
|
45024
|
+
return isKey(dispatcher) && typeof onion === "string" ? tagRoutes.get(dispatcher)?.has(onion) === true : void 0;
|
|
45025
|
+
} catch {
|
|
45026
|
+
return void 0;
|
|
45027
|
+
}
|
|
45028
|
+
};
|
|
45029
|
+
noteRoute = (dispatcher, onion) => {
|
|
45030
|
+
try {
|
|
45031
|
+
if (!isKey(dispatcher) || typeof onion !== "string") return;
|
|
45032
|
+
let onions = tagRoutes.get(dispatcher);
|
|
45033
|
+
if (!onions) tagRoutes.set(dispatcher, onions = /* @__PURE__ */ new Set());
|
|
45034
|
+
onions.add(onion);
|
|
45035
|
+
} catch {
|
|
45036
|
+
}
|
|
45037
|
+
};
|
|
45038
|
+
streamRecord = (tagged, onion) => {
|
|
45039
|
+
const known = tagHasRoute(tagged.dispatcher, onion);
|
|
45040
|
+
return { startedAt: Date.now(), tag: tagged.tag, first: known === void 0 ? void 0 : !known, route: { dispatcher: tagged.dispatcher, onion } };
|
|
45041
|
+
};
|
|
45042
|
+
TAG_LETTERS = Object.freeze({ run: "r", own: "o", given: "g", none: "n" });
|
|
45043
|
+
tagWords = (stream) => `t${TAG_LETTERS[stream?.tag] ?? "x"}${stream?.first === true ? "f" : stream?.first === false ? "l" : "x"}`;
|
|
45044
|
+
OUTCOME_MAX = 96;
|
|
44935
45045
|
noteAnswered = (group, dispatcher) => {
|
|
44936
45046
|
if (!dispatcher) return;
|
|
44937
45047
|
let seen = answeredOn.get(group);
|
|
@@ -44978,17 +45088,36 @@ var init_facilitatorOnion = __esm({
|
|
|
44978
45088
|
moveRecords = [];
|
|
44979
45089
|
writeMove = (move) => {
|
|
44980
45090
|
try {
|
|
44981
|
-
|
|
45091
|
+
let outcome = `${move.role.replaceAll("-", "_")}_${move.request}_${move.cause}_age_${move.ageMs}${move.stream ? `_${move.stream}` : ""}${move.tag ? `_${move.tag}` : ""}`;
|
|
45092
|
+
if (outcome.length > OUTCOME_MAX) outcome = outcome.slice(0, OUTCOME_MAX);
|
|
44982
45093
|
moveTimingLog?.start({ startedAt: move.at - move.ageMs })(move.phase ?? "onion:move", outcome, move.at);
|
|
44983
45094
|
} catch {
|
|
44984
45095
|
}
|
|
44985
45096
|
};
|
|
45097
|
+
REQUEST_RECORDS_MAX = 256;
|
|
45098
|
+
requestRecords = [];
|
|
45099
|
+
requestOutcome = ({ role, request, stream, failed }) => {
|
|
45100
|
+
const ms = (value2) => Number.isFinite(value2) && value2 >= 0 ? String(Math.round(value2)) : "na";
|
|
45101
|
+
return `${role.replaceAll("-", "_")}_${request}_${tagWords(stream)}_${streamWords(stream)}_connect_${ms(stream.connectMs)}_sent_${ms(stream.sentAt - stream.startedAt)}_lp${ms(stream.localPort)}${failed ? "_failed" : ""}`.slice(0, OUTCOME_MAX);
|
|
45102
|
+
};
|
|
45103
|
+
writeRequest = (record) => {
|
|
45104
|
+
try {
|
|
45105
|
+
moveTimingLog?.start({ startedAt: record.stream.startedAt })(record.phase ?? "onion:request", requestOutcome(record), record.at);
|
|
45106
|
+
} catch {
|
|
45107
|
+
}
|
|
45108
|
+
};
|
|
45109
|
+
REQUEST_MARK_FAST_MS = 1e3;
|
|
45110
|
+
noteRequest = (record) => {
|
|
45111
|
+
if (!record.failed && record.stream.kind === "reused" && record.at - record.stream.startedAt < REQUEST_MARK_FAST_MS) return;
|
|
45112
|
+
if (moveTimingLog) writeRequest(record);
|
|
45113
|
+
else if (requestRecords.length < REQUEST_RECORDS_MAX) requestRecords.push(record);
|
|
45114
|
+
};
|
|
44986
45115
|
firstOnionRace = (origin) => {
|
|
44987
45116
|
const race = firstRaces.get(origin);
|
|
44988
45117
|
return race === void 0 ? void 0 : { ...race };
|
|
44989
45118
|
};
|
|
44990
45119
|
onionDispatchers = /* @__PURE__ */ new Map();
|
|
44991
|
-
ownTag = new
|
|
45120
|
+
ownTag = new AsyncLocalStorage3();
|
|
44992
45121
|
ownTagDispatchers = /* @__PURE__ */ new Set();
|
|
44993
45122
|
registerRunDispatchers(() => [...onionDispatchers.values(), ...ownTagDispatchers]);
|
|
44994
45123
|
onOwnTagNow = () => ownTag.getStore()?.dispatcher !== void 0;
|
|
@@ -49413,7 +49542,18 @@ function refuseDirectSockets(proxy) {
|
|
|
49413
49542
|
net2.Socket.prototype.connect = function guardedConnect(...args) {
|
|
49414
49543
|
const [first] = args;
|
|
49415
49544
|
const options = Array.isArray(first) ? first[0] : first;
|
|
49416
|
-
const
|
|
49545
|
+
const byOptions = options !== null && typeof options === "object";
|
|
49546
|
+
const pipe3 = byOptions ? options.path !== void 0 : typeof first === "string" && !/^\d+$/.test(first);
|
|
49547
|
+
const toProxy = !pipe3 && (byOptions ? isProxy(options.host ?? "localhost", options.port) : isProxy(typeof args[1] === "string" ? args[1] : "localhost", first));
|
|
49548
|
+
if (toProxy && runEnded()) {
|
|
49549
|
+
process.nextTick(() => this.destroy(runEndedError()));
|
|
49550
|
+
return this;
|
|
49551
|
+
}
|
|
49552
|
+
const allowed = pipe3 || toProxy || byOptions && isOwnTorControl(options.host, options.port);
|
|
49553
|
+
if (toProxy && !tunnelSockets.has(this)) {
|
|
49554
|
+
tunnelSockets.add(this);
|
|
49555
|
+
this.once("close", () => tunnelSockets.delete(this));
|
|
49556
|
+
}
|
|
49417
49557
|
if (allowed) return connect3.apply(this, args);
|
|
49418
49558
|
process.nextTick(() => this.destroy(new Error("shinjuku_wallet_direct_connection_refused: with --tor, every connection goes through Tor's tunnel")));
|
|
49419
49559
|
return this;
|
|
@@ -49992,7 +50132,7 @@ function torChild(argv2, stdio) {
|
|
|
49992
50132
|
if (!options.mode) throw new ProxyUsageError("torChild needs --tor");
|
|
49993
50133
|
return proxiedChild(options.args, options.proxy, stdio);
|
|
49994
50134
|
}
|
|
49995
|
-
var relayKeyOf, READ_ONLY_METHOD, readOnlyPost, TOR_HTTP_TUNNEL, TOR_CHECK, PROOF_TIMEOUT_MS, LOCAL_PROOF_TIMEOUT_MS, LOCAL_PROOF_MAX_BYTES, torProvenAt, proxyProvenAt, MARK, TOR_RUN_STARTED_ENV, ownProxyRefused, ONION_V3, RETRY_AFTER_CAP_MS, RETRY_AFTER_FLOOR_MS, RETRY_AFTER_DEFAULT_MS, RPC_NO_ANSWER_LIMIT_MS, RPC_PACING_CAP_MS, PACING_NOTICE_EVERY_MS, PACING_RATE_WINDOW_MS, TOR_MAX_ROTATIONS, runStartedAt, rpcNotBefore, pacingWaiters, pacingSince, pacedMs, rpcAnswered, lastAnswerAt, readSteps, pacingNoticeAt, pacingSamples, torMoves, torCircuitId, torTagStartedAt, torMovesRefused, pendingMove, inTorRunOf, inTorRun, runNetworkMode, isOnionOrigin, ProxyUsageError, isOnionHost, PROXY_REMOVED, ENV_PROXY_NAMES, OUTER_PROXY_ENV, DIRECT_RUN_MARK, USE_ENV_PROXY_FLAG, withoutEnvProxyFlag, ownTorControlAllowance, OWN_TOR_CONTROL_ALLOWANCE_MS, TOR_MIN_VERSION, localTorProof, TOR_EXPERT_BUNDLE, TOR_EXPERT_BUNDLE_SHA256, TOR_ARCHIVE, TOR_EXPERT_BUNDLE_URL, TOR_EXPERT_BUNDLES, TUNNEL_LINE, TOR_DEB_KEY, TOR_DEB_KEYRING, TOR_INSTALL, torStart, LOCAL_TUNNEL, torStartText, TOR_WINDOW, torNotRunningMessage, torUpdateHow, TOR_STOP_OLD_WINDOWS, torTooOldWhy, torTooOldMessage, NOTICE, TOR_NOTICE_LINE, ONION_DETAIL_LINE, withoutOnionDetail, QUIET_RUN_MARK, QUIET_RUNS, QUIET_TERMINAL_COMMANDS, INFER_SUBCOMMANDS, quietRun, TOR_TROUBLE_LINE, TOR_WAIT_WORDS, TOR_WAIT_PLAIN, TOR_TROUBLE_PLAIN, promptRedraw, TOR_TROUBLE_SAID, quietTorErr, withRunTag, proxyEnv, pacedSoFar, RESENDABLE_METHOD, torCircuit, laneDispatchers, laneOfDispatcher, ONION_COLD_KEEP_MS, coldStallSaidOn, HOUR_CLOSURES, PROXY_WARNING_FLAG, proxiedExecArgv, proxiedNodeOptions, TOR_FROM_CONFIG_ENV, TOR_FROM_CONFIG_HINT, TOR_FROM_CONFIG_SENTENCE, launcherPid, torStarter;
|
|
50135
|
+
var relayKeyOf, READ_ONLY_METHOD, readOnlyPost, TOR_HTTP_TUNNEL, TOR_CHECK, PROOF_TIMEOUT_MS, LOCAL_PROOF_TIMEOUT_MS, LOCAL_PROOF_MAX_BYTES, torProvenAt, proxyProvenAt, MARK, TOR_RUN_STARTED_ENV, ownProxyRefused, ONION_V3, RETRY_AFTER_CAP_MS, RETRY_AFTER_FLOOR_MS, RETRY_AFTER_DEFAULT_MS, RPC_NO_ANSWER_LIMIT_MS, RPC_PACING_CAP_MS, PACING_NOTICE_EVERY_MS, PACING_RATE_WINDOW_MS, TOR_MAX_ROTATIONS, runStartedAt, rpcNotBefore, pacingWaiters, pacingSince, pacedMs, rpcAnswered, lastAnswerAt, readSteps, pacingNoticeAt, pacingSamples, torMoves, torCircuitId, torTagStartedAt, torMovesRefused, pendingMove, inTorRunOf, inTorRun, runNetworkMode, isOnionOrigin, ProxyUsageError, isOnionHost, PROXY_REMOVED, ENV_PROXY_NAMES, OUTER_PROXY_ENV, DIRECT_RUN_MARK, USE_ENV_PROXY_FLAG, withoutEnvProxyFlag, ownTorControlAllowance, OWN_TOR_CONTROL_ALLOWANCE_MS, tunnelSockets, TOR_MIN_VERSION, localTorProof, TOR_EXPERT_BUNDLE, TOR_EXPERT_BUNDLE_SHA256, TOR_ARCHIVE, TOR_EXPERT_BUNDLE_URL, TOR_EXPERT_BUNDLES, TUNNEL_LINE, TOR_DEB_KEY, TOR_DEB_KEYRING, TOR_INSTALL, torStart, LOCAL_TUNNEL, torStartText, TOR_WINDOW, torNotRunningMessage, torUpdateHow, TOR_STOP_OLD_WINDOWS, torTooOldWhy, torTooOldMessage, NOTICE, TOR_NOTICE_LINE, ONION_DETAIL_LINE, withoutOnionDetail, QUIET_RUN_MARK, QUIET_RUNS, QUIET_TERMINAL_COMMANDS, INFER_SUBCOMMANDS, quietRun, TOR_TROUBLE_LINE, TOR_WAIT_WORDS, TOR_WAIT_PLAIN, TOR_TROUBLE_PLAIN, promptRedraw, TOR_TROUBLE_SAID, quietTorErr, withRunTag, proxyEnv, pacedSoFar, RESENDABLE_METHOD, torCircuit, laneDispatchers, laneOfDispatcher, ONION_COLD_KEEP_MS, coldStallSaidOn, HOUR_CLOSURES, PROXY_WARNING_FLAG, proxiedExecArgv, proxiedNodeOptions, TOR_FROM_CONFIG_ENV, TOR_FROM_CONFIG_HINT, TOR_FROM_CONFIG_SENTENCE, launcherPid, torStarter;
|
|
49996
50136
|
var init_proxy = __esm({
|
|
49997
50137
|
"wallet/src/net/proxy.mjs"() {
|
|
49998
50138
|
"use strict";
|
|
@@ -50068,6 +50208,8 @@ var init_proxy = __esm({
|
|
|
50068
50208
|
};
|
|
50069
50209
|
withoutEnvProxyFlag = (options) => String(options).split(/\s+/).filter((word2) => word2 && !USE_ENV_PROXY_FLAG(word2)).join(" ");
|
|
50070
50210
|
OWN_TOR_CONTROL_ALLOWANCE_MS = 1e3;
|
|
50211
|
+
tunnelSockets = /* @__PURE__ */ new Set();
|
|
50212
|
+
registerRunSockets(() => tunnelSockets);
|
|
50071
50213
|
TOR_MIN_VERSION = Object.freeze([0, 4, 9, 13]);
|
|
50072
50214
|
localTorProof = async (proxy) => (await localTorCheck(proxy)).answer;
|
|
50073
50215
|
TOR_EXPERT_BUNDLE = "15.0.25";
|
|
@@ -53596,7 +53738,7 @@ var init_readTokenCrypto = __esm({
|
|
|
53596
53738
|
|
|
53597
53739
|
// wallet/src/net/readTokens.mjs
|
|
53598
53740
|
import { createHash as createHash10, createPrivateKey, createPublicKey as createPublicKey2, randomBytes as randomBytes10, sign } from "node:crypto";
|
|
53599
|
-
import { AsyncLocalStorage as
|
|
53741
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
53600
53742
|
import { dirname as dirname8, join as join9 } from "node:path";
|
|
53601
53743
|
function depositReadTokenProver(seed) {
|
|
53602
53744
|
const key = createPrivateKey({ key: Buffer.concat([ED25519_PKCS8_PREFIX, Buffer.from(seed).subarray(0, 32)]), format: "der", type: "pkcs8" });
|
|
@@ -54071,7 +54213,7 @@ var init_readTokens = __esm({
|
|
|
54071
54213
|
throttledUntil = /* @__PURE__ */ new Map();
|
|
54072
54214
|
RETRY_AFTER_MIN_MS = 3e4;
|
|
54073
54215
|
RETRY_AFTER_DEFAULT_MS2 = 6e4;
|
|
54074
|
-
userAction = new
|
|
54216
|
+
userAction = new AsyncLocalStorage4();
|
|
54075
54217
|
USER_RUN_TOKEN_MAX = 16;
|
|
54076
54218
|
userActionNow = () => {
|
|
54077
54219
|
const scope2 = userAction.getStore();
|
|
@@ -66619,7 +66761,7 @@ var init_incremental = __esm({
|
|
|
66619
66761
|
});
|
|
66620
66762
|
|
|
66621
66763
|
// wallet/src/history/walletHistory.mjs
|
|
66622
|
-
import { AsyncLocalStorage as
|
|
66764
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
66623
66765
|
import { createHmac as createHmac6 } from "node:crypto";
|
|
66624
66766
|
import { dirname as dirname12, join as join15, resolve as resolve8 } from "node:path";
|
|
66625
66767
|
function sweepFolderOnce(folder) {
|
|
@@ -67541,9 +67683,9 @@ var init_walletHistory = __esm({
|
|
|
67541
67683
|
prewarmFinalizedP03OuterTreeOnWorker(report);
|
|
67542
67684
|
return prepareFinalizedP03RecoveryFold(report);
|
|
67543
67685
|
};
|
|
67544
|
-
strictScope = new
|
|
67686
|
+
strictScope = new AsyncLocalStorage5();
|
|
67545
67687
|
withStrictHistorySource = (fn) => strictScope.run(true, fn);
|
|
67546
|
-
recentScope = new
|
|
67688
|
+
recentScope = new AsyncLocalStorage5();
|
|
67547
67689
|
withRecentWalletHistory = (fn, { accept } = {}) => recentScope.run({ accept }, fn);
|
|
67548
67690
|
recentLoads = /* @__PURE__ */ new Map();
|
|
67549
67691
|
recentAgeStart = (recent) => recent.ageFrom ?? poolReadAtOf(recent.report) ?? recent.startedAt;
|
|
@@ -106614,7 +106756,10 @@ function sellerWaitMs(record) {
|
|
|
106614
106756
|
function sellerAnswerInit(url, init, ms) {
|
|
106615
106757
|
const target = () => init.dispatcher ?? routeDispatcherOf(url) ?? activeGlobalDispatcher();
|
|
106616
106758
|
if (target() === void 0) return init;
|
|
106617
|
-
return { ...init, dispatcher: {
|
|
106759
|
+
return { ...init, dispatcher: {
|
|
106760
|
+
dispatch: (options, handler) => target().dispatch({ ...options, headersTimeout: ms, bodyTimeout: ms }, handler),
|
|
106761
|
+
tagDispatcher: target
|
|
106762
|
+
} };
|
|
106618
106763
|
}
|
|
106619
106764
|
async function sendWatchingStall(fetchImpl, url, init, waitMs, {
|
|
106620
106765
|
mark = () => {
|
|
@@ -138213,7 +138358,7 @@ var init_qr = __esm({
|
|
|
138213
138358
|
});
|
|
138214
138359
|
|
|
138215
138360
|
// wallet/src/mcp/addFunds.mjs
|
|
138216
|
-
import { AsyncLocalStorage as
|
|
138361
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
138217
138362
|
import { randomBytes as randomBytes34 } from "node:crypto";
|
|
138218
138363
|
import diagnosticsChannel3 from "node:diagnostics_channel";
|
|
138219
138364
|
function onRequestCreate(message) {
|
|
@@ -138754,7 +138899,7 @@ var init_addFunds = __esm({
|
|
|
138754
138899
|
};
|
|
138755
138900
|
NO_MARKS = Object.freeze({ mark: () => {
|
|
138756
138901
|
} });
|
|
138757
|
-
stepScope = new
|
|
138902
|
+
stepScope = new AsyncLocalStorage6();
|
|
138758
138903
|
stepRequests = /* @__PURE__ */ new WeakMap();
|
|
138759
138904
|
outcomeOfError = (error) => String(error?.code ?? error?.name ?? "error").toLowerCase().replace(/[^a-z0-9_]/g, "_").slice(0, 64);
|
|
138760
138905
|
onRequestEvent = (event) => (message) => {
|
|
@@ -162019,7 +162164,7 @@ AUTHCHALLENGE SAFECOOKIE ${clientNonce.toString("hex")}\r
|
|
|
162019
162164
|
}
|
|
162020
162165
|
if (step === 2 && typeof events === "function") {
|
|
162021
162166
|
step = 6;
|
|
162022
|
-
socket.write("SETEVENTS HS_DESC CIRC\r\n");
|
|
162167
|
+
socket.write("SETEVENTS HS_DESC CIRC STREAM\r\n");
|
|
162023
162168
|
continue;
|
|
162024
162169
|
}
|
|
162025
162170
|
if (step === 6) {
|
|
@@ -162747,6 +162892,13 @@ function torTimingMark(line, ours) {
|
|
|
162747
162892
|
if (!prefix2 || !HS_DESC_ACTIONS.has(desc[1]) || reason2 !== void 0 && !HS_DESC_REASONS.has(reason2)) return void 0;
|
|
162748
162893
|
return { phase: `hs-desc-${desc[1].toLowerCase()}`, outcome: `onion_${prefix2}${reason2 ? `_${reason2.toLowerCase()}` : ""}` };
|
|
162749
162894
|
}
|
|
162895
|
+
const stream = /^650 STREAM (\d{1,20}) ([A-Z_]+) (\d{1,10}) ([a-z2-7]{56})\.onion:\d{1,5}(?: |$)/.exec(line);
|
|
162896
|
+
if (stream) {
|
|
162897
|
+
const prefix2 = ours.get(stream[4]);
|
|
162898
|
+
if (!prefix2 || !STREAM_STATUSES.has(stream[2])) return void 0;
|
|
162899
|
+
const port = stream[2] === "NEW" ? /(?:^| )SOURCE_ADDR=127\.0\.0\.1:(\d{1,5})(?: |$)/.exec(line)?.[1] : void 0;
|
|
162900
|
+
return { phase: `stream-${stream[2].toLowerCase()}`, outcome: `onion_${prefix2}_s${stream[1]}_c${stream[3]}${port ? `_lp${port}` : ""}` };
|
|
162901
|
+
}
|
|
162750
162902
|
const circ = /^650 CIRC (\d{1,10}) ([A-Z_]+) /.exec(`${line} `);
|
|
162751
162903
|
if (!circ || !CIRC_STATUSES.has(circ[2])) return void 0;
|
|
162752
162904
|
const rend = /(?:^| )REND_QUERY=([a-z2-7]{56})(?: |$)/.exec(line)?.[1];
|
|
@@ -162759,7 +162911,7 @@ function torTimingMark(line, ours) {
|
|
|
162759
162911
|
}
|
|
162760
162912
|
function startTorTimingMarks() {
|
|
162761
162913
|
const run2 = String(process.env.SHINJUKU_WALLET_PROXIED ?? "");
|
|
162762
|
-
if (!run2.startsWith("tor ") || !process.argv.includes("--verbose")) return;
|
|
162914
|
+
if (!run2.startsWith("tor ") || !(process.argv.includes("--verbose") || process.argv[2] === "mcp")) return;
|
|
162763
162915
|
setImmediate(async () => {
|
|
162764
162916
|
try {
|
|
162765
162917
|
const home = setupHome(process.env);
|
|
@@ -162775,23 +162927,40 @@ function startTorTimingMarks() {
|
|
|
162775
162927
|
const ours = ownOnionPrefixes();
|
|
162776
162928
|
const mark = createTimingLog(join51(home, pool2, "wallet.json.timing.log"), { component: "tor" }).start({ startedAt: Date.now() - performance.now() });
|
|
162777
162929
|
let marks = 0;
|
|
162930
|
+
let session;
|
|
162931
|
+
let spent = false;
|
|
162932
|
+
const closeSession = () => {
|
|
162933
|
+
try {
|
|
162934
|
+
session?.close();
|
|
162935
|
+
} catch {
|
|
162936
|
+
}
|
|
162937
|
+
};
|
|
162778
162938
|
const once2 = (phase, outcome) => {
|
|
162779
162939
|
if (marks >= TOR_TIMING_MAX) return;
|
|
162780
162940
|
marks += 1;
|
|
162781
162941
|
mark(phase, outcome);
|
|
162942
|
+
if (marks >= TOR_TIMING_MAX) {
|
|
162943
|
+
spent = true;
|
|
162944
|
+
closeSession();
|
|
162945
|
+
}
|
|
162782
162946
|
};
|
|
162783
|
-
|
|
162947
|
+
session = await controlCheck(home, state2, { unref: true, events: (line) => {
|
|
162948
|
+
if (spent) return;
|
|
162784
162949
|
const one = torTimingMark(line, ours);
|
|
162785
162950
|
if (one) once2(one.phase, one.outcome);
|
|
162786
162951
|
} });
|
|
162787
162952
|
if (!session) return;
|
|
162788
|
-
|
|
162953
|
+
if (spent) {
|
|
162954
|
+
closeSession();
|
|
162955
|
+
return;
|
|
162956
|
+
}
|
|
162957
|
+
process.once("exit", closeSession);
|
|
162789
162958
|
once2("events-on");
|
|
162790
162959
|
} catch {
|
|
162791
162960
|
}
|
|
162792
162961
|
});
|
|
162793
162962
|
}
|
|
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;
|
|
162963
|
+
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, STREAM_STATUSES;
|
|
162795
162964
|
var init_managedTor = __esm({
|
|
162796
162965
|
"wallet/src/net/managedTor.mjs"() {
|
|
162797
162966
|
"use strict";
|
|
@@ -162936,7 +163105,7 @@ public static class ShinjukuOwnTor {
|
|
|
162936
163105
|
return answer && answer.tunnelPort === Number(proxyPort) ? answer.circuits : void 0;
|
|
162937
163106
|
});
|
|
162938
163107
|
EVENT_LINE_MAX = 4096;
|
|
162939
|
-
TOR_TIMING_MAX =
|
|
163108
|
+
TOR_TIMING_MAX = 800;
|
|
162940
163109
|
HS_DESC_ACTIONS = /* @__PURE__ */ new Set(["REQUESTED", "RECEIVED", "FAILED"]);
|
|
162941
163110
|
HS_DESC_REASONS = /* @__PURE__ */ new Set([
|
|
162942
163111
|
"BAD_DESC",
|
|
@@ -162976,6 +163145,7 @@ public static class ShinjukuOwnTor {
|
|
|
162976
163145
|
"MEASUREMENT_EXPIRED",
|
|
162977
163146
|
"IP_NOW_REDUNDANT"
|
|
162978
163147
|
]);
|
|
163148
|
+
STREAM_STATUSES = /* @__PURE__ */ new Set(["NEW", "SENTCONNECT", "SUCCEEDED", "FAILED", "CLOSED", "DETACHED"]);
|
|
162979
163149
|
startTorTimingMarks();
|
|
162980
163150
|
}
|
|
162981
163151
|
});
|