shinjuku-shield 0.3.135 → 0.3.136
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 +5 -5
- package/manifest.json +4 -4
- package/package.json +3 -3
- package/shinjuku-wallet.mjs +177 -82
package/README.md
CHANGED
|
@@ -6,19 +6,19 @@ answers privately, in a terminal chat or for your agent app. Its `mcp`
|
|
|
6
6
|
command runs a local MCP server (stdio) for your agent. Your keys never
|
|
7
7
|
leave your machine.
|
|
8
8
|
|
|
9
|
-
This is version 0.3.
|
|
9
|
+
This is version 0.3.136. The npm packages `shinjuku-shield` and
|
|
10
10
|
`shinjuku-shielded` hold the same files. The command is `shinjuku`.
|
|
11
11
|
|
|
12
12
|
## Set up
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
|
-
npm install -g shinjuku@0.3.
|
|
15
|
+
npm install -g shinjuku@0.3.136
|
|
16
16
|
shinjuku setup
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Type the two lines as they are. `npx install shinjuku` does not work: npx
|
|
20
20
|
reads `install` as the name of another npm package. To set up without
|
|
21
|
-
installing, type `npx shinjuku@0.3.
|
|
21
|
+
installing, type `npx shinjuku@0.3.136 setup`.
|
|
22
22
|
|
|
23
23
|
Setup makes the wallet on this machine, a private passphrase file, and the
|
|
24
24
|
checked proof tools (about 191 MB), and writes `config.json`. It also writes
|
|
@@ -36,13 +36,13 @@ Every wallet command works after `shinjuku`, for example `shinjuku balance`,
|
|
|
36
36
|
Claude Code:
|
|
37
37
|
|
|
38
38
|
```sh
|
|
39
|
-
claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.
|
|
39
|
+
claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.136 mcp
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Claude Desktop (`claude_desktop_config.json`) or Cursor (`~/.cursor/mcp.json`):
|
|
43
43
|
|
|
44
44
|
```json
|
|
45
|
-
{ "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.
|
|
45
|
+
{ "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.136", "mcp"] } } }
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
On native Windows, if the host cannot find `npx`, use `"command": "cmd"` and
|
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": "24c033c4a5ba30b63911674d18a731e7ad32c2bb22f660dc451dd2af6258a275",
|
|
5
|
+
"bytes": 8900675,
|
|
6
|
+
"sourceCommit": "edde08b7e130bd8905165c8868af9f52ec7817b5",
|
|
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",
|
|
@@ -1037,5 +1037,5 @@
|
|
|
1037
1037
|
"version": "1.8.0"
|
|
1038
1038
|
}
|
|
1039
1039
|
],
|
|
1040
|
-
"publishedAt": "2026-10-
|
|
1040
|
+
"publishedAt": "2026-10-31T17:35:38.949Z"
|
|
1041
1041
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shinjuku-shield",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.136",
|
|
4
4
|
"mcpName": "io.github.ShinjukuStaition/shinjuku-mcp",
|
|
5
5
|
"description": "Shinjuku Shielded, the private x402 facilitator on Solana: the self-custody wallet CLI and its MCP server. Shield, pay, and unshield USDC from any MCP agent, under caps you set.",
|
|
6
|
-
"shinjukuRelease": "
|
|
7
|
-
"shinjukuSha256": "
|
|
6
|
+
"shinjukuRelease": "24c033c4",
|
|
7
|
+
"shinjukuSha256": "24c033c4a5ba30b63911674d18a731e7ad32c2bb22f660dc451dd2af6258a275",
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
9
9
|
"author": "Shinjuku Shielded",
|
|
10
10
|
"homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
|
package/shinjuku-wallet.mjs
CHANGED
|
@@ -112486,6 +112486,142 @@ var init_publicRead = __esm({
|
|
|
112486
112486
|
}
|
|
112487
112487
|
});
|
|
112488
112488
|
|
|
112489
|
+
// wallet/src/pay/floatRefundCheck.mjs
|
|
112490
|
+
function floatNeverLanded(store, float, requestId) {
|
|
112491
|
+
try {
|
|
112492
|
+
if (!float || float.state === "cancelled") return false;
|
|
112493
|
+
const inner = typeof float.innerRequestId === "string" && float.innerRequestId ? float.innerRequestId : typeof requestId === "string" ? floatInnerRequestId(requestId) : void 0;
|
|
112494
|
+
return floatLegNeverLanded(store, inner);
|
|
112495
|
+
} catch {
|
|
112496
|
+
return false;
|
|
112497
|
+
}
|
|
112498
|
+
}
|
|
112499
|
+
function staleFloatRefundNames(store, now = Date.now()) {
|
|
112500
|
+
const names = [];
|
|
112501
|
+
for (const name of store.listWal()) {
|
|
112502
|
+
if (!name.startsWith(FLOAT_PAYMENT_WAL_PREFIX2)) continue;
|
|
112503
|
+
let record;
|
|
112504
|
+
try {
|
|
112505
|
+
record = store.readWal(name);
|
|
112506
|
+
} catch {
|
|
112507
|
+
continue;
|
|
112508
|
+
}
|
|
112509
|
+
if (floatRecordState(record) === "submitted") {
|
|
112510
|
+
const age = Number.isSafeInteger(floatEndedAtMs(record)) ? now - floatEndedAtMs(record) : NaN;
|
|
112511
|
+
if (age > SUBMITTED_READ_AFTER_MS && (age < 2 * STALE_FLOAT_REFUND_MS || record.ambiguous === true)) names.push(name);
|
|
112512
|
+
continue;
|
|
112513
|
+
}
|
|
112514
|
+
if (floatRecordState(record) !== "refund_pending" || record.refundOutcome === "refund_arrived" || !Number.isSafeInteger(record.refundPendingAtMs)) continue;
|
|
112515
|
+
if (now - record.refundPendingAtMs > STALE_FLOAT_REFUND_MS || floatRefundReadDue(record, now)) names.push(name);
|
|
112516
|
+
}
|
|
112517
|
+
return names;
|
|
112518
|
+
}
|
|
112519
|
+
async function readFloatRefunds(store, names, { fetchImpl = fetch, untilMs = Date.now() + 3e3, now = Date.now() } = {}) {
|
|
112520
|
+
const due = [];
|
|
112521
|
+
for (const name of names) {
|
|
112522
|
+
if (!name.startsWith(FLOAT_PAYMENT_WAL_PREFIX2)) continue;
|
|
112523
|
+
let record;
|
|
112524
|
+
try {
|
|
112525
|
+
record = store.readWal(name);
|
|
112526
|
+
} catch {
|
|
112527
|
+
continue;
|
|
112528
|
+
}
|
|
112529
|
+
if (!FLOAT_ID.test(String(record?.floatId)) || floatNeverLanded(store, record)) continue;
|
|
112530
|
+
const state = floatRecordState(record);
|
|
112531
|
+
if (state !== "refund_pending" && state !== "submitted") continue;
|
|
112532
|
+
if (state === "submitted" && record.memoryOnly === true && !memoryRequestHeld(record)) continue;
|
|
112533
|
+
if (!(now - floatEndedAtMs(record) < FLOAT_REFUND_READ_AGE_MS)) continue;
|
|
112534
|
+
due.push({ name, record, state });
|
|
112535
|
+
}
|
|
112536
|
+
due.sort((left, right) => floatEndedAtMs(right.record) - floatEndedAtMs(left.record));
|
|
112537
|
+
const proven = [];
|
|
112538
|
+
let refunded = 0;
|
|
112539
|
+
const reads = due.slice(0, FLOAT_REFUND_READS).map(({ name, record, state }) => readFloatTransferState(record, fetchImpl).then((read) => {
|
|
112540
|
+
if (read?.state === "final") proven.push({ name, from: record.state, verdict: "final", transaction: read.transaction });
|
|
112541
|
+
else if (read?.state === "cancelled") proven.push({ name, from: record.state, verdict: "cancelled" });
|
|
112542
|
+
else if (read?.state === "dead" && typeof read.floatState === "string") {
|
|
112543
|
+
if (read.floatState === "refunded" && read.refundTransaction) refunded += 1;
|
|
112544
|
+
if (state === "submitted") proven.push({ name, from: record.state, verdict: "dead", refundDueAtMs: read.refundDueAtMs });
|
|
112545
|
+
}
|
|
112546
|
+
}, () => void 0));
|
|
112547
|
+
const wait2 = new Promise((resolve35) => {
|
|
112548
|
+
const timer = setTimeout(resolve35, Math.max(0, untilMs - Date.now()));
|
|
112549
|
+
timer.unref?.();
|
|
112550
|
+
});
|
|
112551
|
+
await Promise.race([Promise.all(reads), wait2]);
|
|
112552
|
+
return { proven: [...proven], refunded };
|
|
112553
|
+
}
|
|
112554
|
+
async function checkFloatRefundsNow({ store, reopen, lockPath: lockPath2, fetchImpl = fetch, now = Date.now(), acquireLease = acquireWalletProcessLease }) {
|
|
112555
|
+
let names;
|
|
112556
|
+
try {
|
|
112557
|
+
names = staleFloatRefundNames(store, now);
|
|
112558
|
+
} catch {
|
|
112559
|
+
return { written: 0, refunded: 0 };
|
|
112560
|
+
}
|
|
112561
|
+
if (!names.length) return { written: 0, refunded: 0 };
|
|
112562
|
+
const { proven, refunded } = await readFloatRefunds(store, names, { fetchImpl, untilMs: Date.now() + 3e3, now });
|
|
112563
|
+
if (!proven.length) return { written: 0, refunded };
|
|
112564
|
+
let release;
|
|
112565
|
+
try {
|
|
112566
|
+
release = await acquireLease(lockPath2);
|
|
112567
|
+
} catch {
|
|
112568
|
+
return { written: 0, refunded };
|
|
112569
|
+
}
|
|
112570
|
+
try {
|
|
112571
|
+
return { written: writeProvenFloatStates(reopen(), proven), refunded };
|
|
112572
|
+
} catch {
|
|
112573
|
+
return { written: 0, refunded };
|
|
112574
|
+
} finally {
|
|
112575
|
+
try {
|
|
112576
|
+
await release();
|
|
112577
|
+
} catch {
|
|
112578
|
+
}
|
|
112579
|
+
}
|
|
112580
|
+
}
|
|
112581
|
+
function writeProvenFloatStates(store, proven) {
|
|
112582
|
+
let written = 0;
|
|
112583
|
+
for (const { name, from, verdict, transaction, refundDueAtMs, fill } of proven) {
|
|
112584
|
+
const record = store.readWal(name);
|
|
112585
|
+
if (record?.state !== from) continue;
|
|
112586
|
+
const { ambiguous: _settled, refundDueAtMs: _due, ...rest } = record;
|
|
112587
|
+
const landed = SIGNATURE_TEXT.test(String(transaction ?? "")) ? { landedTransaction: transaction } : {};
|
|
112588
|
+
if (fill) {
|
|
112589
|
+
if (knownSellerTransfer(record) !== null || !landed.landedTransaction) continue;
|
|
112590
|
+
store.writeWal(name, { ...record, ...landed });
|
|
112591
|
+
} else if (verdict === "dead" && floatRecordState(record) === "submitted") {
|
|
112592
|
+
store.writeWal(name, {
|
|
112593
|
+
...rest,
|
|
112594
|
+
state: "refund_pending",
|
|
112595
|
+
refundPendingAtMs: record.refundPendingAtMs ?? Date.now(),
|
|
112596
|
+
...Number.isSafeInteger(refundDueAtMs) ? { refundDueAtMs } : {}
|
|
112597
|
+
});
|
|
112598
|
+
} else if (verdict === "final") {
|
|
112599
|
+
store.writeWal(name, { ...rest, state: "seller_kept", sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(), ...landed });
|
|
112600
|
+
} else if (verdict === "cancelled") {
|
|
112601
|
+
store.writeWal(name, { ...rest, state: "cancelled", cancelledAtMs: record.cancelledAtMs ?? Date.now() });
|
|
112602
|
+
} else continue;
|
|
112603
|
+
written += 1;
|
|
112604
|
+
}
|
|
112605
|
+
return written;
|
|
112606
|
+
}
|
|
112607
|
+
var FLOAT_REFUND_READS, FLOAT_REFUND_READ_AGE_MS, STALE_FLOAT_REFUND_MS, SUBMITTED_READ_AFTER_MS, FLOAT_ID, SIGNATURE_TEXT, floatEndedAtMs, knownSellerTransfer;
|
|
112608
|
+
var init_floatRefundCheck = __esm({
|
|
112609
|
+
"wallet/src/pay/floatRefundCheck.mjs"() {
|
|
112610
|
+
"use strict";
|
|
112611
|
+
init_floatPay();
|
|
112612
|
+
init_memoryOnly();
|
|
112613
|
+
init_processLease();
|
|
112614
|
+
FLOAT_REFUND_READS = 5;
|
|
112615
|
+
FLOAT_REFUND_READ_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
112616
|
+
STALE_FLOAT_REFUND_MS = 2 * FLOAT_REFUND_ETA_SECONDS * 1e3;
|
|
112617
|
+
SUBMITTED_READ_AFTER_MS = 6e4;
|
|
112618
|
+
FLOAT_ID = /^[0-9a-f]{64}$/;
|
|
112619
|
+
SIGNATURE_TEXT = /^[1-9A-HJ-NP-Za-km-z]{64,90}$/;
|
|
112620
|
+
floatEndedAtMs = (record) => Number.isSafeInteger(record.refundPendingAtMs) ? record.refundPendingAtMs : record.submittedAtMs;
|
|
112621
|
+
knownSellerTransfer = (record) => [record?.receipt?.transaction, record?.landedTransaction].find((one) => SIGNATURE_TEXT.test(String(one ?? ""))) ?? null;
|
|
112622
|
+
}
|
|
112623
|
+
});
|
|
112624
|
+
|
|
112489
112625
|
// wallet/src/unshield/cli.mjs
|
|
112490
112626
|
import { randomBytes as randomBytes20 } from "node:crypto";
|
|
112491
112627
|
import { resolve as resolve18 } from "node:path";
|
|
@@ -128270,15 +128406,6 @@ function leg1Transaction(store, float, requestId) {
|
|
|
128270
128406
|
return null;
|
|
128271
128407
|
}
|
|
128272
128408
|
}
|
|
128273
|
-
function floatNeverLanded(store, float, requestId) {
|
|
128274
|
-
try {
|
|
128275
|
-
if (!float || float.state === "cancelled") return false;
|
|
128276
|
-
const inner = typeof float.innerRequestId === "string" && float.innerRequestId ? float.innerRequestId : typeof requestId === "string" ? floatInnerRequestId(requestId) : void 0;
|
|
128277
|
-
return floatLegNeverLanded(store, inner);
|
|
128278
|
-
} catch {
|
|
128279
|
-
return false;
|
|
128280
|
-
}
|
|
128281
|
-
}
|
|
128282
128409
|
function bindUnshieldRecipient(store, unshieldId, amountAtomic, to, requestId) {
|
|
128283
128410
|
const name = `self-pay-${unshieldId}`;
|
|
128284
128411
|
const record = store.readWal(name);
|
|
@@ -131029,10 +131156,10 @@ ${canonical5}`;
|
|
|
131029
131156
|
// force-live 5r, 2026-10-22: the answer gave no id, so nobody could look the refund up).
|
|
131030
131157
|
// refundAtomic and refundEtaSeconds (Shinjuku's time) for a proven refund; an unproven send carries ambiguous: true.
|
|
131031
131158
|
...paidBack ? {
|
|
131032
|
-
...
|
|
131159
|
+
...FLOAT_ID2.test(String(error?.floatId)) ? { floatId: error.floatId } : {},
|
|
131033
131160
|
refundAtomic: error?.paidAtomic ?? null,
|
|
131034
131161
|
...arrived ? { refundArrived: true } : Number.isSafeInteger(error?.refundEtaSeconds) && error.refundEtaSeconds > 0 ? { refundEtaSeconds: error.refundEtaSeconds } : {}
|
|
131035
|
-
} : ambiguous ? { ambiguous: true, ...
|
|
131162
|
+
} : ambiguous ? { ambiguous: true, ...FLOAT_ID2.test(String(error?.floatId)) ? { floatId: error.floatId } : {} } : {},
|
|
131036
131163
|
...balanceAnswer(one)
|
|
131037
131164
|
});
|
|
131038
131165
|
}
|
|
@@ -132168,37 +132295,12 @@ ${canonical5}`;
|
|
|
132168
132295
|
return REQUEST_ID4.test(id) && sha256Hex2(Buffer.from(id, "utf8")) === key ? id : void 0;
|
|
132169
132296
|
};
|
|
132170
132297
|
const finalRefundStates = /* @__PURE__ */ new Map();
|
|
132171
|
-
const
|
|
132172
|
-
const REFUND_STATUS_READ_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
132173
|
-
const floatEndedAtMs = (record) => Number.isSafeInteger(record.refundPendingAtMs) ? record.refundPendingAtMs : record.submittedAtMs;
|
|
132174
|
-
const SIGNATURE_TEXT = /^[1-9A-HJ-NP-Za-km-z]{64,90}$/;
|
|
132175
|
-
const knownSellerTransfer = (record) => [record?.receipt?.transaction, record?.landedTransaction].find((one) => SIGNATURE_TEXT.test(String(one ?? ""))) ?? null;
|
|
132298
|
+
const SIGNATURE_TEXT2 = /^[1-9A-HJ-NP-Za-km-z]{64,90}$/;
|
|
132176
132299
|
const finalTransfers = /* @__PURE__ */ new Map();
|
|
132177
132300
|
const transferMisses = /* @__PURE__ */ new Set();
|
|
132178
132301
|
const sellerTransferUnknown = (record) => ["receipt", "seller_kept"].includes(floatRecordState(record)) && knownSellerTransfer(record) === null;
|
|
132179
132302
|
const floatAnsweredAtMs = (record) => [record.answeredAtMs, record.sellerKeptAtMs, record.submittedAtMs].find(Number.isSafeInteger);
|
|
132180
|
-
const
|
|
132181
|
-
const SUBMITTED_READ_AFTER_MS = 6e4;
|
|
132182
|
-
function staleRefundNames(store) {
|
|
132183
|
-
const names = [];
|
|
132184
|
-
for (const name of store.listWal()) {
|
|
132185
|
-
if (!name.startsWith(FLOAT_PAYMENT_WAL_PREFIX2)) continue;
|
|
132186
|
-
let record;
|
|
132187
|
-
try {
|
|
132188
|
-
record = store.readWal(name);
|
|
132189
|
-
} catch {
|
|
132190
|
-
continue;
|
|
132191
|
-
}
|
|
132192
|
-
if (floatRecordState(record) === "submitted") {
|
|
132193
|
-
const age = Number.isSafeInteger(floatEndedAtMs(record)) ? Date.now() - floatEndedAtMs(record) : NaN;
|
|
132194
|
-
if (age > SUBMITTED_READ_AFTER_MS && (age < 2 * STALE_REFUND_MS || record.ambiguous === true)) names.push(name);
|
|
132195
|
-
continue;
|
|
132196
|
-
}
|
|
132197
|
-
if (floatRecordState(record) !== "refund_pending" || record.refundOutcome === "refund_arrived" || !Number.isSafeInteger(record.refundPendingAtMs)) continue;
|
|
132198
|
-
if (Date.now() - record.refundPendingAtMs > STALE_REFUND_MS || floatRefundReadDue(record)) names.push(name);
|
|
132199
|
-
}
|
|
132200
|
-
return names;
|
|
132201
|
-
}
|
|
132303
|
+
const staleRefundNames = (store) => staleFloatRefundNames(store);
|
|
132202
132304
|
async function correctFloatRecords(store, names, untilMs, started = floatCorrectionReads(store, names)) {
|
|
132203
132305
|
const { states, proven, settled } = started;
|
|
132204
132306
|
if (settled === void 0) return { states, written: 0 };
|
|
@@ -132208,7 +132310,7 @@ ${canonical5}`;
|
|
|
132208
132310
|
});
|
|
132209
132311
|
await Promise.race([settled, until(untilMs)]);
|
|
132210
132312
|
if (!proven.length) return { states, written: 0 };
|
|
132211
|
-
const writing = underLease((leased) => Date.now() >= untilMs ? 0 :
|
|
132313
|
+
const writing = underLease((leased) => Date.now() >= untilMs ? 0 : writeProvenFloatStates(leased, proven));
|
|
132212
132314
|
const written = await Promise.race([writing.catch(() => 0), until(untilMs).then(() => 0)]);
|
|
132213
132315
|
if (written > 0) log(`MCP_FLOAT_RECORDS_CORRECTED records=${written}`);
|
|
132214
132316
|
return { states, written };
|
|
@@ -132225,10 +132327,10 @@ ${canonical5}`;
|
|
|
132225
132327
|
} catch {
|
|
132226
132328
|
continue;
|
|
132227
132329
|
}
|
|
132228
|
-
if (!
|
|
132330
|
+
if (!FLOAT_ID2.test(String(record?.floatId))) continue;
|
|
132229
132331
|
if (floatNeverLanded(store, record)) continue;
|
|
132230
132332
|
if (sellerTransferUnknown(record)) {
|
|
132231
|
-
if (!finalTransfers.has(record.floatId) && !transferMisses.has(record.floatId) && now - floatAnsweredAtMs(record) <
|
|
132333
|
+
if (!finalTransfers.has(record.floatId) && !transferMisses.has(record.floatId) && now - floatAnsweredAtMs(record) < FLOAT_REFUND_READ_AGE_MS) {
|
|
132232
132334
|
transfers.push({ name, record });
|
|
132233
132335
|
}
|
|
132234
132336
|
continue;
|
|
@@ -132236,7 +132338,7 @@ ${canonical5}`;
|
|
|
132236
132338
|
if (!["refund_pending", "submitted"].includes(floatRecordState(record))) continue;
|
|
132237
132339
|
if (floatRecordState(record) === "submitted" && record.memoryOnly === true && !memoryRequestHeld(record)) continue;
|
|
132238
132340
|
if (finalRefundStates.has(record.floatId)) continue;
|
|
132239
|
-
if (!(now - floatEndedAtMs(record) <
|
|
132341
|
+
if (!(now - floatEndedAtMs(record) < FLOAT_REFUND_READ_AGE_MS)) continue;
|
|
132240
132342
|
due.push({ name, record });
|
|
132241
132343
|
}
|
|
132242
132344
|
const states = new Map(finalRefundStates);
|
|
@@ -132246,7 +132348,7 @@ ${canonical5}`;
|
|
|
132246
132348
|
due.sort((left, right) => floatEndedAtMs(right.record) - floatEndedAtMs(left.record));
|
|
132247
132349
|
transfers.sort((left, right) => floatAnsweredAtMs(right.record) - floatAnsweredAtMs(left.record));
|
|
132248
132350
|
const fetchImpl = ops.fetch ?? fetch;
|
|
132249
|
-
const reads = due.slice(0,
|
|
132351
|
+
const reads = due.slice(0, FLOAT_REFUND_READS).map(({ name, record }) => readFloatTransferState(record, fetchImpl).then((read) => {
|
|
132250
132352
|
const state = floatRecordState(record);
|
|
132251
132353
|
if (state === "submitted" && read?.state === "landed" || read?.state === "final") {
|
|
132252
132354
|
states.set(record.floatId, { floatState: read.state, ...read.transaction ? { transaction: read.transaction } : {} });
|
|
@@ -132263,10 +132365,10 @@ ${canonical5}`;
|
|
|
132263
132365
|
if (refund.floatState === "refunded" && refund.refundTransaction) finalRefundStates.set(record.floatId, refund);
|
|
132264
132366
|
if (state === "submitted") proven.push({ name, from: record.state, verdict: "dead", refundDueAtMs: read.refundDueAtMs });
|
|
132265
132367
|
}));
|
|
132266
|
-
for (const { name, record } of transfers.slice(0,
|
|
132368
|
+
for (const { name, record } of transfers.slice(0, FLOAT_REFUND_READS)) {
|
|
132267
132369
|
reads.push(readFloatTransferState(record, fetchImpl).then((read) => {
|
|
132268
|
-
if (read?.unserved || read?.state === "dead" || read?.state === "final" && !
|
|
132269
|
-
if (read?.state !== "final" && read?.state !== "landed" || !
|
|
132370
|
+
if (read?.unserved || read?.state === "dead" || read?.state === "final" && !SIGNATURE_TEXT2.test(String(read.transaction ?? ""))) transferMisses.add(record.floatId);
|
|
132371
|
+
if (read?.state !== "final" && read?.state !== "landed" || !SIGNATURE_TEXT2.test(String(read.transaction ?? ""))) return;
|
|
132270
132372
|
states.set(record.floatId, { floatState: read.state, transaction: read.transaction });
|
|
132271
132373
|
if (read.state !== "final") return;
|
|
132272
132374
|
finalTransfers.set(record.floatId, read.transaction);
|
|
@@ -132291,32 +132393,6 @@ ${canonical5}`;
|
|
|
132291
132393
|
return void 0;
|
|
132292
132394
|
}
|
|
132293
132395
|
}
|
|
132294
|
-
function writeProven(store, proven) {
|
|
132295
|
-
let written = 0;
|
|
132296
|
-
for (const { name, from, verdict, transaction, refundDueAtMs, fill } of proven) {
|
|
132297
|
-
const record = store.readWal(name);
|
|
132298
|
-
if (record?.state !== from) continue;
|
|
132299
|
-
const { ambiguous: _settled, refundDueAtMs: _due, ...rest } = record;
|
|
132300
|
-
const landed = SIGNATURE_TEXT.test(String(transaction ?? "")) ? { landedTransaction: transaction } : {};
|
|
132301
|
-
if (fill) {
|
|
132302
|
-
if (knownSellerTransfer(record) !== null || !landed.landedTransaction) continue;
|
|
132303
|
-
store.writeWal(name, { ...record, ...landed });
|
|
132304
|
-
} else if (verdict === "dead" && floatRecordState(record) === "submitted") {
|
|
132305
|
-
store.writeWal(name, {
|
|
132306
|
-
...rest,
|
|
132307
|
-
state: "refund_pending",
|
|
132308
|
-
refundPendingAtMs: record.refundPendingAtMs ?? Date.now(),
|
|
132309
|
-
...Number.isSafeInteger(refundDueAtMs) ? { refundDueAtMs } : {}
|
|
132310
|
-
});
|
|
132311
|
-
} else if (verdict === "final") {
|
|
132312
|
-
store.writeWal(name, { ...rest, state: "seller_kept", sellerKeptAtMs: record.sellerKeptAtMs ?? Date.now(), ...landed });
|
|
132313
|
-
} else if (verdict === "cancelled") {
|
|
132314
|
-
store.writeWal(name, { ...rest, state: "cancelled", cancelledAtMs: record.cancelledAtMs ?? Date.now() });
|
|
132315
|
-
} else continue;
|
|
132316
|
-
written += 1;
|
|
132317
|
-
}
|
|
132318
|
-
return written;
|
|
132319
|
-
}
|
|
132320
132396
|
const refundStateWords = (floatState) => ({
|
|
132321
132397
|
dead: "sure: the transfer to the seller expired, so Shinjuku sends the refund",
|
|
132322
132398
|
refund_queued: "sure: Shinjuku is sending the refund",
|
|
@@ -132468,13 +132544,13 @@ ${canonical5}`;
|
|
|
132468
132544
|
const refund = !refunded ? {} : {
|
|
132469
132545
|
refundAtomic: paid,
|
|
132470
132546
|
refund: told.refund,
|
|
132471
|
-
...
|
|
132547
|
+
...FLOAT_ID2.test(String(record.floatId)) ? { floatId: record.floatId } : {},
|
|
132472
132548
|
...shinjuku?.floatState ? { refundState: refundStateWords(shinjuku.floatState) } : {},
|
|
132473
132549
|
...shinjuku?.refundTransaction ? { refundTransaction: shinjuku.refundTransaction } : {},
|
|
132474
132550
|
note: told.note
|
|
132475
132551
|
};
|
|
132476
132552
|
const landedTransaction = knownSellerTransfer(record) ?? (!refunded ? refundReads.get(record.floatId)?.transaction : void 0);
|
|
132477
|
-
const keptTransaction = !refunded &&
|
|
132553
|
+
const keptTransaction = !refunded && SIGNATURE_TEXT2.test(String(landedTransaction ?? "")) ? landedTransaction : null;
|
|
132478
132554
|
row(
|
|
132479
132555
|
name.slice(FLOAT_PAYMENT_WAL_PREFIX2.length),
|
|
132480
132556
|
{ ...record, answeredAtMs: at },
|
|
@@ -132500,7 +132576,7 @@ ${canonical5}`;
|
|
|
132500
132576
|
if (state !== "receipt") continue;
|
|
132501
132577
|
const view2 = viewOf(record);
|
|
132502
132578
|
const read = refundReads.get(record.floatId)?.transaction;
|
|
132503
|
-
const sellerTransaction = view2.sellerTransaction ?? knownSellerTransfer(record) ?? (
|
|
132579
|
+
const sellerTransaction = view2.sellerTransaction ?? knownSellerTransfer(record) ?? (SIGNATURE_TEXT2.test(String(read ?? "")) ? read : null);
|
|
132504
132580
|
row(name.slice(FLOAT_PAYMENT_WAL_PREFIX2.length), record, { ...view2, sellerTransaction }, {
|
|
132505
132581
|
scheme: "exact",
|
|
132506
132582
|
// RC1 (mcp56 pass of 0.3.102, hypernatt): this said "a later wallet_receipts shows it", but Shinjuku drops a final
|
|
@@ -133039,7 +133115,7 @@ ${canonical5}`;
|
|
|
133039
133115
|
refund,
|
|
133040
133116
|
refundAtomic: float.paidAtomic ?? null,
|
|
133041
133117
|
...read?.refundTransaction ? { refundTransaction: read.refundTransaction } : {},
|
|
133042
|
-
...
|
|
133118
|
+
...FLOAT_ID2.test(String(float.floatId)) ? { floatId: float.floatId } : {},
|
|
133043
133119
|
detail: `${words2}; there is nothing to cancel`,
|
|
133044
133120
|
next: `Tell the user: ${words2}. Nothing was changed; wallet_receipts lists it`
|
|
133045
133121
|
});
|
|
@@ -133069,7 +133145,7 @@ ${canonical5}`;
|
|
|
133069
133145
|
finished: false,
|
|
133070
133146
|
state: floatState,
|
|
133071
133147
|
ambiguous: true,
|
|
133072
|
-
...
|
|
133148
|
+
...FLOAT_ID2.test(String(float.floatId)) ? { floatId: float.floatId } : {},
|
|
133073
133149
|
detail: "this payment through Shinjuku is paid, and it is not certain yet whether the seller kept it; a payment sent to Shinjuku cannot be cancelled; nothing was changed",
|
|
133074
133150
|
next: "Tell the user it is not certain yet whether the seller kept the payment, and nothing was changed. wallet_receipts shows the result (a refund, or that the seller kept it) when Shinjuku's transfer to the seller is final or can no longer land. Do not pay again with a NEW request_id until then"
|
|
133075
133151
|
});
|
|
@@ -138785,7 +138861,7 @@ function createSetupTools({
|
|
|
138785
138861
|
doneTool: sayOnRefusal(doneTool)
|
|
138786
138862
|
};
|
|
138787
138863
|
}
|
|
138788
|
-
var import_web3133, shownCaps, RELEASE_RETRY_MS, STAGE_WORDS, stageWords, INTERNAL_BALANCE_DETAIL, shownBreakdown, sessionLeftShown, TOKEN_UNIT_TOOLS, RESOURCE_PAYMENT_WAL_PREFIX2, POOL_LAYOUT_CODE, POOL_LAYOUT_UPDATE, USEPOD_VIA_INFERENCE_CHAT, SEND_RUNS_ON, DEPOSIT_RUNS_ON, CLI_FUNDS_PLAN_PREFIX, CLI_FUNDS_SCHEMA, SELF_PAY_ORIGIN3, REQUEST_ID4, POSITIVE_ATOMIC6, PRIVATE_HOST3, FORBIDDEN_HEADERS3, MAX_BODY_BYTES2, PREVIEW_TIMEOUT_MS, PREVIEW_SELLER_READ_MS, CALL_BUDGET_MS, budgetLeft, PAY_ANSWER_MARGIN_MS, MONEY_FIRST_ANSWER_MS, BALANCE_AFTER_LANDING_MS, JOIN_CALL_MAX_MS, JOIN_CALL_ANSWER_MARGIN_S, PAY_AFTER_JOIN_MS, joinAnswerSeconds, JOIN_TIME_MS, JOIN_NUDGE_QUIET_MS, JOIN_STEP_MS, sleep2, PROGRESS_EVERY_MS2, READ_BUDGET_MS, UNPAID_TOR_TRY_MS, UNPAID_CLEAR_MS, READ_BUDGET_TOOLS, FLOAT_BUSY_CODES, RETRY_MARGIN_MS, ASK_PAY_CODES, runningNpmVersion, terminalCommand2, capPlaceWords, noLimitSetLine, CAP_NAMES, capName, entryPlaces, capRaiseText, runningLimits, payCapFlag, noPriceFits, cheaperText, limitNext, overLimitStep, SAFE_TEXT, causesLog, MCP_TOOL_ALIASES, POOL_SWITCH_WHY, POOL_SWITCH_NEXT, SWITCH_STATES, quietSwitch, switchKey, ATOMIC_TEXT, MAX_PAYMENT_ATOMIC_LEAST, movedTo,
|
|
138864
|
+
var import_web3133, shownCaps, RELEASE_RETRY_MS, STAGE_WORDS, stageWords, INTERNAL_BALANCE_DETAIL, shownBreakdown, sessionLeftShown, TOKEN_UNIT_TOOLS, RESOURCE_PAYMENT_WAL_PREFIX2, POOL_LAYOUT_CODE, POOL_LAYOUT_UPDATE, USEPOD_VIA_INFERENCE_CHAT, SEND_RUNS_ON, DEPOSIT_RUNS_ON, CLI_FUNDS_PLAN_PREFIX, CLI_FUNDS_SCHEMA, SELF_PAY_ORIGIN3, REQUEST_ID4, POSITIVE_ATOMIC6, PRIVATE_HOST3, FORBIDDEN_HEADERS3, MAX_BODY_BYTES2, PREVIEW_TIMEOUT_MS, PREVIEW_SELLER_READ_MS, CALL_BUDGET_MS, budgetLeft, PAY_ANSWER_MARGIN_MS, MONEY_FIRST_ANSWER_MS, BALANCE_AFTER_LANDING_MS, JOIN_CALL_MAX_MS, JOIN_CALL_ANSWER_MARGIN_S, PAY_AFTER_JOIN_MS, joinAnswerSeconds, JOIN_TIME_MS, JOIN_NUDGE_QUIET_MS, JOIN_STEP_MS, sleep2, PROGRESS_EVERY_MS2, READ_BUDGET_MS, UNPAID_TOR_TRY_MS, UNPAID_CLEAR_MS, READ_BUDGET_TOOLS, FLOAT_BUSY_CODES, RETRY_MARGIN_MS, ASK_PAY_CODES, runningNpmVersion, terminalCommand2, capPlaceWords, noLimitSetLine, CAP_NAMES, capName, entryPlaces, capRaiseText, runningLimits, payCapFlag, noPriceFits, cheaperText, limitNext, overLimitStep, SAFE_TEXT, causesLog, MCP_TOOL_ALIASES, POOL_SWITCH_WHY, POOL_SWITCH_NEXT, SWITCH_STATES, quietSwitch, switchKey, ATOMIC_TEXT, MAX_PAYMENT_ATOMIC_LEAST, movedTo, FLOAT_ID2, ANSWERED_EXIT_RETRY_MS, ANSWERED_EXIT_UNCONFIRMED_MS, ANSWERED_EXIT_RETRY_WINDOW_MS, ANSWERED_EXIT_CLOSED, switchAmount, switchEta, switchRows, OWNER_CAP_CODES, JOIN_END_MCP, JOIN_END_TERMINAL_LIBRARY, JOIN_RETRY_BACKOFF_MS, WALLET_CAP_FIX, ENTRY_CAP_CODES, MCP_CAP_FIX, capFix, ownerOnlyNext, mcpNext, CONFIDENTIAL_RETIRED, json3, answerResult, discoverTool, LAUNCH_CAP_CODES, dayCapKind, refuse12, newRequestIdFor, payCapName, publicOffer, FLOAT_PAID_CODES, FLOAT_NOT_CERTAIN_CODES, FLOAT_PRIVATE_LEG, SELLER_ONLY_HERE, outsideWalletRule, proxyStartStep, MONEY_ID2, toRecordId, linkKindOf, moneyId, REFUSED_CODES, refusedCodeOf, PLAIN_REASONS, insufficientCause, INSUFFICIENT_REASONS, reasonOf, plainReason, KEPT_SEND_TRIES, shownId, isSplitSend, PROMISED_NEXT, partFailReason, sendAnswerOf, PUBLIC_READ_TIMEOUT_MS, RECIPIENT_CHECK_TIMEOUT_MS, withTimeout, ownKey, readFailure, OWN_KEY_TOKENS_MAX, tokenAmountText, elsewhereId, AGENT_ID_SCHEMA, agentIdName, minutesText2, ageWords2, DEPOSIT_SENT_STATES, depositLanded, usdcText3, walkWalletHistory, REFRESH_LEASE_WALK_MS, HOME_MARKS_SETTLED_MS2, AUTO_BACKUPS_KEPT, AUTO_BACKUP_NAME, AUTO_BACKUP_VERIFIED, FRONTED_SETTLE_MARGIN_SLOTS, UNSHIELD_WINDOW_YIELD_MS, NOT_FINAL_YET, FINISH_FINALITY_WAIT_MS, FINISH_FINALITY_WAITS, FINISH_FINALITY_RECENT_MS, walkStillCurrent, DIRECT_EXIT_GONE, BALANCE_REFRESH_WAIT_MS, BALANCE_REFRESH_GRACE_MS, BALANCE_REFRESH_LONG_MS, INBOUND_REFRESH_AGE_MS, changeFields, balanceAnswer, CAP_BALANCE_WAIT_MS, CAP_BALANCE_RETRY_MS, REFRESH_RETRY_MS, FINALITY_POLL_MS, FINALITY_WAIT_MS, FINALITY_REFRESH_LIMIT_MS, POOL_WATCH_MS, POOL_WATCH_POLL_MS, EARLY_BALANCE_DELAY_MS, FINALITY_SETTLE_WINDOW_SLOTS, PUBLIC_READ_ANSWER_MS, LINK_READ_ANSWER_MS, OWN_READS_AHEAD_MS, OWN_PUBLIC_KNOWN_MS, FLOAT_CORRECT_WAIT_MS, SWITCH_WAIT_MS, UNSHIELD_TO_NO_USDC_DETAIL, UNSHIELD_TO_INVALID_NEXT, INFERENCE_MIN_MAX_TOKENS, ELICIT_TIMEOUT_MS, ELICIT_UNSHOWN_MS, elicitUnshown, POLL_SECONDS2, TRANSFER_CHANGE_READ_MS, TEMP_CLEAN_DELAY_MS, KEPT_ON_DISK, MAX_SHIELDED_BALANCE_ATOMIC, receiveGenerator, MCP_TOOL_NAMES, MCP_HIDDEN_TOOL_NAMES, setupTerminalNext, SETUP_RUNNING_SAY, ACCEPTED_NEXT, SETUP_RUNNING_NEXT, SETUP_ANSWER_WAIT_MS, SETUP_CONFIRMING_SAY, SETUP_CONFIRMING_NEXT, OWN_ADDRESS_QUESTION, OWN_ADDRESS_WHERE, OWN_ADDRESS_INVALID, PRIVATE_INFERENCE_WHY, RESTART_STEPS, HOST_BLOCKED_LINE, TOR_BROWSER_PORT, SETUP_TOR_TITLE, SETUP_TOR_WHY;
|
|
138789
138865
|
var init_tools = __esm({
|
|
138790
138866
|
"wallet/src/mcp/tools.mjs"() {
|
|
138791
138867
|
"use strict";
|
|
@@ -138810,6 +138886,7 @@ var init_tools = __esm({
|
|
|
138810
138886
|
init_publicRead();
|
|
138811
138887
|
init_floatPay();
|
|
138812
138888
|
init_floatWords();
|
|
138889
|
+
init_floatRefundCheck();
|
|
138813
138890
|
init_sellerInput();
|
|
138814
138891
|
init_prepareRecoveredPayment();
|
|
138815
138892
|
init_walletHistory();
|
|
@@ -138991,7 +139068,7 @@ var init_tools = __esm({
|
|
|
138991
139068
|
return void 0;
|
|
138992
139069
|
}
|
|
138993
139070
|
};
|
|
138994
|
-
|
|
139071
|
+
FLOAT_ID2 = /^[0-9a-f]{64}$/;
|
|
138995
139072
|
ANSWERED_EXIT_RETRY_MS = 3e4;
|
|
138996
139073
|
ANSWERED_EXIT_UNCONFIRMED_MS = 10 * 6e4;
|
|
138997
139074
|
ANSWERED_EXIT_RETRY_WINDOW_MS = 30 * 6e4;
|
|
@@ -142809,7 +142886,7 @@ async function runChat({ io, values, deps = {} }) {
|
|
|
142809
142886
|
}
|
|
142810
142887
|
};
|
|
142811
142888
|
let parts = readParts();
|
|
142812
|
-
if (parts?.spendableAtomic == null) {
|
|
142889
|
+
if (parts?.spendableAtomic == null || /^[1-9][0-9]*$/.test(String(parts?.refundsNotCertainAtomic ?? ""))) {
|
|
142813
142890
|
let read;
|
|
142814
142891
|
if (typeof deps.readChainBalance === "function") {
|
|
142815
142892
|
say3("Reading your private balance from the chain (the same read as shinjuku balance) ...");
|
|
@@ -147176,6 +147253,7 @@ init_qr();
|
|
|
147176
147253
|
init_rpcDefault();
|
|
147177
147254
|
init_usdcWords();
|
|
147178
147255
|
init_processLease();
|
|
147256
|
+
init_floatRefundCheck();
|
|
147179
147257
|
init_secretFile();
|
|
147180
147258
|
var FUNDS_SCHEMA = "carbon-shielded-wallet/add-funds/v1";
|
|
147181
147259
|
var FUNDS_ROUTES = Object.freeze(["exchange", "changenow", "privacy-cash"]);
|
|
@@ -148281,8 +148359,10 @@ async function fundsStatus(values, deps) {
|
|
|
148281
148359
|
const pool2 = values.get("--pool");
|
|
148282
148360
|
const passphrase2 = values.has("--passphrase-file") ? readPrivateLine(resolve31(values.get("--passphrase-file")), "--passphrase-file") : deps.env[PASSPHRASE_ENV];
|
|
148283
148361
|
const walletFile = resolve31(deps.walletPath(pool2));
|
|
148284
|
-
|
|
148362
|
+
let store = deps.openWalletStore(walletFile, passphrase2);
|
|
148285
148363
|
if (store.state.pool !== pool2) throw failure("wallet_pool_mismatch", "the wallet file for this --pool belongs to another pool; check --pool and SHIELDED_WALLET_HOME");
|
|
148364
|
+
const reopen = () => deps.openWalletStore(walletFile, passphrase2);
|
|
148365
|
+
if ((await checkFloatRefundsNow({ store, reopen, lockPath: walletLockPath(walletFile), fetchImpl: deps.fetch ?? fetch, now: deps.now() })).written > 0) store = reopen();
|
|
148286
148366
|
const plans = fundsPlans(store);
|
|
148287
148367
|
const wanted = values.get("--funds-id");
|
|
148288
148368
|
const plan = wanted === void 0 ? plans.at(-1) : plans.find((entry) => entry.fundsId === wanted);
|
|
@@ -148314,6 +148394,7 @@ async function fundsMain(command, values, deps) {
|
|
|
148314
148394
|
// wallet/src/cli/shinjukuWallet.mjs
|
|
148315
148395
|
init_store();
|
|
148316
148396
|
init_processLease();
|
|
148397
|
+
init_floatRefundCheck();
|
|
148317
148398
|
init_notes2();
|
|
148318
148399
|
init_proxy();
|
|
148319
148400
|
init_autoJoin();
|
|
@@ -150247,6 +150328,7 @@ async function stopWhenShort(values, deps, { needAtomic = 1n, costAtomic, paymen
|
|
|
150247
150328
|
noWalk = false;
|
|
150248
150329
|
}
|
|
150249
150330
|
if (!knownShortBalance(store, { needAtomic, payment }) && !noWalk && !(noAccount && !savedWalkHoldsAccount(store))) return false;
|
|
150331
|
+
await checkFloatRefunds(store, values, deps, () => commandStore(values, deps));
|
|
150250
150332
|
const read = await readBalanceFromChain(store, values, deps);
|
|
150251
150333
|
if (read === "failed") deps.io.err(`Your private balance could not be read from the chain now; the ${payment ? "payment" : "send"} reads it again before it signs anything.
|
|
150252
150334
|
`);
|
|
@@ -156102,9 +156184,12 @@ async function runBalance(args, values, deps, io) {
|
|
|
156102
156184
|
} else {
|
|
156103
156185
|
store = openPoolWallet(values, deps);
|
|
156104
156186
|
}
|
|
156187
|
+
const refunds = await checkFloatRefunds(store, values, deps);
|
|
156188
|
+
if (refunds.written > 0) store = openPoolWallet(values, deps);
|
|
156105
156189
|
const parts = balanceNow(store, { source: values.has("--refresh") ? "refresh" : "local", now: deps.now() });
|
|
156106
156190
|
const report = parts?.report;
|
|
156107
|
-
const
|
|
156191
|
+
const current = (report?.status === "current" || report?.status === "empty") && !(refunds.refunded > 0 && refunds.written > 0);
|
|
156192
|
+
const refreshArgs = values.has("--refresh") || current ? void 0 : homeRefreshArgs(store, deps);
|
|
156108
156193
|
if (refreshArgs) {
|
|
156109
156194
|
io.err("reading your private balance from the chain\n");
|
|
156110
156195
|
const shownFlags = ["--json", "--verbose"].filter((name) => values.has(name));
|
|
@@ -156173,6 +156258,16 @@ async function runBalance(args, values, deps, io) {
|
|
|
156173
156258
|
`);
|
|
156174
156259
|
mark("balance-printed");
|
|
156175
156260
|
}
|
|
156261
|
+
function checkFloatRefunds(store, values, deps, open4 = () => openPoolWallet(values, deps)) {
|
|
156262
|
+
return checkFloatRefundsNow({
|
|
156263
|
+
store,
|
|
156264
|
+
reopen: open4,
|
|
156265
|
+
lockPath: walletLockPath(commandWalletPath(values, deps)),
|
|
156266
|
+
fetchImpl: deps.fetch,
|
|
156267
|
+
now: deps.now(),
|
|
156268
|
+
...deps.acquireLease ? { acquireLease: deps.acquireLease } : {}
|
|
156269
|
+
});
|
|
156270
|
+
}
|
|
156176
156271
|
function homeRefreshArgs(store, deps) {
|
|
156177
156272
|
let config;
|
|
156178
156273
|
try {
|