shinjuku-shield 0.3.148 → 0.3.150

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,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.148. The npm packages `shinjuku-shield` and
9
+ This is version 0.3.150. 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.148
15
+ npm install -g shinjuku@0.3.150
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.148 setup`.
21
+ installing, type `npx shinjuku@0.3.150 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.148 mcp
39
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.150 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.148", "mcp"] } } }
45
+ { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.150", "mcp"] } } }
46
46
  ```
47
47
 
48
48
  On native Windows, if the host cannot find `npx`, use `"command": "cmd"` and
@@ -55,7 +55,7 @@ Codex (the Codex app and Codex CLI read the same file, `~/.codex/config.toml`):
55
55
  ```toml
56
56
  [mcp_servers.shinjuku]
57
57
  command = "npx"
58
- args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.148", "mcp"]
58
+ args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.150", "mcp"]
59
59
  startup_timeout_sec = 120
60
60
  tool_timeout_sec = 300
61
61
  ```
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": "c6990ffc94f21e46128aa3386b0ca78934100ab75aea6687ed1ea7d01386c689",
5
- "bytes": 8986535,
6
- "sourceCommit": "4885d6bbb6136da01ebb3aa9ed57e471abea6294",
4
+ "sha256": "35457f8ab4f209c7518da98152cb6ee55157a1df110729c1c3998962cfb15dce",
5
+ "bytes": 8997333,
6
+ "sourceCommit": "9319b1ca86d33ad0730f0ed9553d382c060b3343",
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",
@@ -1038,5 +1038,5 @@
1038
1038
  "version": "1.8.0"
1039
1039
  }
1040
1040
  ],
1041
- "publishedAt": "2026-11-01T14:33:44.965Z"
1041
+ "publishedAt": "2026-11-01T18:50:14.510Z"
1042
1042
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.148",
3
+ "version": "0.3.150",
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": "c6990ffc",
7
- "shinjukuSha256": "c6990ffc94f21e46128aa3386b0ca78934100ab75aea6687ed1ea7d01386c689",
6
+ "shinjukuRelease": "35457f8a",
7
+ "shinjukuSha256": "35457f8ab4f209c7518da98152cb6ee55157a1df110729c1c3998962cfb15dce",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -61891,18 +61891,15 @@ function usdcWords(atomic4) {
61891
61891
  const fraction = padded.slice(-6).replace(/0+$/, "");
61892
61892
  return `${fraction ? `${whole}.${fraction}` : whole} USDC`;
61893
61893
  }
61894
- function spendNowForms(spendableAtomic, largestAtomic, { surface, prepareCommand } = {}) {
61894
+ function spendNowForms(spendableAtomic, largestAtomic, { surface } = {}) {
61895
61895
  const spendable = String(spendableAtomic ?? "");
61896
61896
  if (!ATOMIC.test(spendable)) return [];
61897
61897
  const largest = String(largestAtomic ?? "");
61898
61898
  const total = usdcWords(spendable);
61899
61899
  if (BigInt(spendable) === 0n || ATOMIC.test(largest) && BigInt(largest) >= BigInt(spendable)) return [`${total} now`];
61900
61900
  if (!ATOMIC.test(largest)) return [`${total} in total now`];
61901
- const step = surface === "cli" ? `needs ${prepareCommand ?? "the prepare command"} first` : "first gets the balance ready";
61902
- return [
61903
- `${total} (a payment above ${usdcWords(largest)} ${step})`,
61904
- `${total}, up to ${usdcWords(largest)} in one payment now`
61905
- ];
61901
+ const limit = `${total}, up to ${usdcWords(largest)} in one payment now`;
61902
+ return surface === "cli" ? [limit] : [`${total} (a payment above ${usdcWords(largest)} first gets the balance ready)`, limit];
61906
61903
  }
61907
61904
  function spendHeads(spendableAtomic, largestAtomic, change = {}, options = {}) {
61908
61905
  const spendable = String(spendableAtomic ?? "");
@@ -66862,6 +66859,8 @@ var init_errorCodes = __esm({
66862
66859
  "inference_out_of_tokens",
66863
66860
  // wallet_unshield of a balance in several accounts: the stage code while the automatic join runs (mcp/tools.mjs joiningStage).
66864
66861
  "unshield_joining_accounts",
66862
+ // unshield of a fixed amount in a terminal: its own join (joinForFixedSend, AB186) did not get the balance ready.
66863
+ "unshield_balance_not_ready",
66865
66864
  "inference_response_invalid",
66866
66865
  "inference_route_unknown",
66867
66866
  "inference_serve_unauthorized",
@@ -69226,6 +69225,8 @@ var init_errorCodes = __esm({
69226
69225
  // The no-flag terminal (0.3.97, shinjukuWallet.mjs): a terminal question that ended with no change, or a no to a money move.
69227
69226
  "add_funds_no_amount",
69228
69227
  "curl_payment_declined",
69228
+ // curl in a terminal: its own join (joinForCurlPayment, AB185) did not get the balance ready.
69229
+ "curl_balance_not_ready",
69229
69230
  // curl in a terminal: a price the user's own limits cannot let pass, refused before the question (runCurl).
69230
69231
  "curl_over_your_limits",
69231
69232
  "limits_not_changed",
@@ -112503,6 +112504,7 @@ __export(inference_exports, {
112503
112504
  InferenceError: () => InferenceError,
112504
112505
  MIN_MAX_TOKENS: () => MIN_MAX_TOKENS,
112505
112506
  USEPOD_MIN_PAYMENT_ATOMIC: () => USEPOD_MIN_PAYMENT_ATOMIC,
112507
+ USEPOD_QUOTE_FEE_PERMILLE: () => USEPOD_QUOTE_FEE_PERMILLE,
112506
112508
  USEPOD_X402_CHAT_URL: () => USEPOD_X402_CHAT_URL,
112507
112509
  buildChatRequest: () => buildChatRequest,
112508
112510
  ceilingAtomic: () => ceilingAtomic,
@@ -112613,7 +112615,8 @@ function inputTokensBound(messages, tools) {
112613
112615
  return tokens;
112614
112616
  }
112615
112617
  function ceilingOf(entry, messages, maxTokens, tools) {
112616
- const estimate = ceilDiv(entry.priceInPerMAtomic * inputTokensBound(messages, tools) + entry.priceOutPerMAtomic * maxTokens, PER_M);
112618
+ const listed = entry.priceInPerMAtomic * inputTokensBound(messages, tools) + entry.priceOutPerMAtomic * maxTokens;
112619
+ const estimate = ceilDiv(listed * (1000n + USEPOD_QUOTE_FEE_PERMILLE), 1000n * PER_M);
112617
112620
  return estimate > USEPOD_MIN_PAYMENT_ATOMIC ? estimate : USEPOD_MIN_PAYMENT_ATOMIC;
112618
112621
  }
112619
112622
  function ceilingAtomic({ model, messages, maxTokens, tools }) {
@@ -112747,7 +112750,7 @@ function overCapNext(entry, messages, cap, ceiling) {
112747
112750
  if (cap < USEPOD_MIN_PAYMENT_ATOMIC) {
112748
112751
  return "allow more than 0.01 USDC (the AI provider's minimum per call) plus the Shinjuku fee for this call";
112749
112752
  }
112750
- const room = cap * PER_M - entry.priceInPerMAtomic * inputTokensBound(messages, void 0);
112753
+ const room = cap * PER_M * 1000n / (1000n + USEPOD_QUOTE_FEE_PERMILLE) - entry.priceInPerMAtomic * inputTokensBound(messages, void 0);
112751
112754
  const fits = room > 0n ? room / entry.priceOutPerMAtomic : 0n;
112752
112755
  return fits >= 1n ? `lower max_tokens to ${fits}, or allow up to ${usdcWords(ceiling)} for this call` : `shorten the messages, or allow up to ${usdcWords(ceiling)} for this call`;
112753
112756
  }
@@ -112820,7 +112823,7 @@ async function inferenceChat({
112820
112823
  maxTokensDefault: maxTokens === void 0 || maxTokens === null
112821
112824
  };
112822
112825
  }
112823
- var USEPOD_X402_CHAT_URL, USEPOD_MIN_PAYMENT_ATOMIC, INFERENCE_NOTICE, ROLES, MAX_TOOLS, TOOL_NAME, MESSAGE_OVERHEAD_TOKENS, PER_M, InferenceError, fail30, modelIds, ceilDiv, spelling;
112826
+ var USEPOD_X402_CHAT_URL, USEPOD_MIN_PAYMENT_ATOMIC, INFERENCE_NOTICE, ROLES, MAX_TOOLS, TOOL_NAME, MESSAGE_OVERHEAD_TOKENS, PER_M, InferenceError, fail30, modelIds, ceilDiv, USEPOD_QUOTE_FEE_PERMILLE, spelling;
112824
112827
  var init_inference = __esm({
112825
112828
  "wallet/src/inference/index.mjs"() {
112826
112829
  "use strict";
@@ -112849,6 +112852,7 @@ var init_inference = __esm({
112849
112852
  };
112850
112853
  modelIds = () => MODELS.map((model) => model.id).join(", ");
112851
112854
  ceilDiv = (a, b) => (a + b - 1n) / b;
112855
+ USEPOD_QUOTE_FEE_PERMILLE = 100n;
112852
112856
  spelling = (name) => String(name ?? "").toLowerCase().replace(/[^a-z0-9]/g, "");
112853
112857
  }
112854
112858
  });
@@ -113023,10 +113027,9 @@ function openPaymentWords(parts) {
113023
113027
  const rerun = one?.requestId ? `run the same command again with --request-id ${one.requestId}` : "run the same command again with its --request-id";
113024
113028
  return `To finish ${which}, ${rerun} (it never pays twice); if the seller never takes it, Shinjuku sends it back to your private balance by itself within about ${Math.round(FLOAT_REFUND_ETA_SECONDS / 60)} minutes.`;
113025
113029
  }
113026
- function balanceWords(parts, { afterSend = false } = {}) {
113027
- const prepareCommand = commandLine("prepare");
113028
- const heads = parts && parts.spendableAtomic !== null ? spendHeads(parts.spendableAtomic, parts.largestPaymentAtomic, parts, { surface: "cli", prepareCommand }) : [];
113029
- const spend = afterSend ? heads.find((head) => !head.includes(prepareCommand)) ?? heads[0] : heads[0];
113030
+ function balanceWords(parts) {
113031
+ const heads = parts && parts.spendableAtomic !== null ? spendHeads(parts.spendableAtomic, parts.largestPaymentAtomic, parts, { surface: "cli" }) : [];
113032
+ const spend = heads[0];
113030
113033
  if (spend === void 0) return void 0;
113031
113034
  const positive2 = (atomic4) => POSITIVE2.test(String(atomic4 ?? ""));
113032
113035
  const notes = [
@@ -113043,7 +113046,6 @@ var init_balanceNow = __esm({
113043
113046
  init_book();
113044
113047
  init_store();
113045
113048
  init_usdcWords();
113046
- init_commandName();
113047
113049
  init_floatPay();
113048
113050
  init_prepareRecoveredPayment();
113049
113051
  init_balance();
@@ -144073,6 +144075,10 @@ When it says ready, type /retry: it asks the same question again.` : receivedOnl
144073
144075
  const { maxPaymentAtomic: payLimit, maxSessionAtomic: dayLimit } = caps.limits;
144074
144076
  const atLimit = payLimit !== void 0 && caps.answer >= BigInt(payLimit) || dayLimit !== void 0 && caps.chat >= BigInt(dayLimit);
144075
144077
  say3(`This answer costs more than the chat's caps allow. ${paidWords} ${capsLine2()} ${atLimit ? `To pay more, end the chat (/exit), raise your limits with ${commandLine("limits")}, then start it again: ${commandLine("chat")}` : `End the chat (/exit) and start it again with higher caps when you want more: ${commandLine(`chat --max-payment ${higherCap(caps.answer, payLimit, dayLimit)} --max-session ${higherCap(caps.chat, dayLimit)}`)}`}${closeOtherwise}`);
144078
+ } else if (code2 === "fetch_price_over_ceiling") {
144079
+ const fact = [error, error?.cause, error?.cause?.cause].find((one) => /^[0-9]{1,30}$/.test(String(one?.askedAtomic ?? "")));
144080
+ const asks = fact ? ` (${usdcWords(BigInt(fact.askedAtomic))}${/^[0-9]{1,30}$/.test(String(fact.ceilingAtomic ?? "")) ? `, the wallet expected at most ${usdcWords(BigInt(fact.ceilingAtomic))}` : ""})` : "";
144081
+ say3(`The AI provider asks more for this answer than the wallet expected${asks}, so it was not paid. ${paidWords} Try another model (/model ${models.find((entry) => entry.id !== turn.model)?.id ?? DEFAULT_MODEL2}), or ${again} later.${closeOtherwise}`);
144076
144082
  } else if (code2 === "inference_no_provider") {
144077
144083
  say3(`No AI provider can take this wallet's payment for ${turn.model} right now. ${paidWords} Try another model (/model ${models.find((entry) => entry.id !== turn.model)?.id ?? DEFAULT_MODEL2}), or ${again} later.${closeOtherwise}`);
144078
144084
  } else if (NO_ANSWER_CODES.test(code2 ?? "")) {
@@ -151807,6 +151813,10 @@ var NOT_SET_UP_CODE = "wallet_not_set_up";
151807
151813
  var EMPTY_BALANCE_CODE = "no_spendable_account";
151808
151814
  var OVER_LIMITS_CODE = "curl_over_your_limits";
151809
151815
  var CEILING_OVER_CAP_CODE = "inference_ceiling_over_cap";
151816
+ var BALANCE_NOT_READY_CODE = "curl_balance_not_ready";
151817
+ var SEND_NOT_READY_CODE = "unshield_balance_not_ready";
151818
+ var SPLIT_CODE = "p03_merchant_respend_accounts_split_merge_first";
151819
+ var JOIN_SKIPPED = /* @__PURE__ */ Symbol("join skipped");
151810
151820
  var flag2 = (name, value2, about, options = {}) => ({ name, value: value2, about, ...options });
151811
151821
  var bool2 = (name, about, options = {}) => ({ name, boolean: true, about, ...options });
151812
151822
  var RPC_DEFAULT_TEXT = `default: Shinjuku's relay <server>${FACILITATOR_RPC_PATH} (the server this command names, else ${GUIDE.facilitator}), which sees which addresses this wallet reads; your own RPC wins and keeps those reads away from Shinjuku`;
@@ -152282,14 +152292,26 @@ async function runCurlPaid(values, deps, { requestId: probeId } = {}) {
152282
152292
  io.err(`request-id ${requestId}${given ? "" : ` (if this run stops, rerun with --request-id ${requestId}: it never pays twice)`}
152283
152293
  `);
152284
152294
  await poolSwitchGate({ session, amountAtomic: values.get("--max-payment"), again: ` with --request-id ${requestId}`, deps, io });
152285
- try {
152286
- response = await (deps.payAndFetch ?? payAndFetch)(session, values.get("--url"), { method, headers, ...body === void 0 ? {} : { body } }, { requestId });
152287
- } catch (error) {
152288
- if (/^inference_tor_required: /.test(error instanceof Error ? error.message : "")) {
152289
- throw new PublicFailure(`${error.message}
152295
+ for (let joined = false; ; ) {
152296
+ try {
152297
+ response = await (deps.payAndFetch ?? payAndFetch)(session, values.get("--url"), { method, headers, ...body === void 0 ? {} : { body } }, { requestId });
152298
+ break;
152299
+ } catch (error) {
152300
+ if (/^inference_tor_required: /.test(error instanceof Error ? error.message : "")) {
152301
+ throw new PublicFailure(`${error.message}
152290
152302
  ${CURL_USEPOD_NEXT}`, { cause: error });
152303
+ }
152304
+ if (!joined && localErrorCodes(error).includes(SPLIT_CODE)) {
152305
+ joined = true;
152306
+ const outcome = await joinForCurlPayment(session, values, deps, io, requestId);
152307
+ if (outcome === true) continue;
152308
+ if (outcome === "stale") {
152309
+ throw new PublicFailure(`${BALANCE_NOT_READY_CODE}: your private balance covers this payment in total, but the wallet's saved balance is not up to date, so it could not get the balance ready for one payment. Nothing was signed or paid. Run ${cli4()} balance --refresh, then the same command again: it never pays twice`);
152310
+ }
152311
+ if (outcome === "files") values.set(JOIN_SKIPPED, true);
152312
+ }
152313
+ throw curlFailure(error);
152291
152314
  }
152292
- throw curlFailure(error);
152293
152315
  }
152294
152316
  sessionMark(session)("curl-paid-returned");
152295
152317
  return await curlOutput(response, values, deps, requestId);
@@ -155155,7 +155177,7 @@ var COMMANDS = [
155155
155177
  "Without --refresh, balance reads only local files: the last walk (recover or balance --refresh) and the wallet log. Outside a set-up home it makes no network call; in a set-up home it reads the chain once when the last walk is not current, and reads the public USDC on the wallet's own address (one RPC read, at most 3 s).",
155156
155178
  "USDC on the wallet's own public address is not private: the line after the balance names it and how to make it private (publicOnOwnAddressAtomic in the JSON; null when not read).",
155157
155179
  "shinjukuShielded is null when the last walk is missing, stale, or incomplete. reasons says why; next shows the command to run.",
155158
- `In a terminal it prints one plain line: the private balance in USDC, and a short reason when it is not current (then the command to run). The wallet's own progress lines (Tor, the RPC relay, the pool history walk, the memo reads) show only with --verbose; warnings and failures always show. A program, or --json, gets the whole report as JSON (total, shinjukuShielded, status, reasons, next, detail). Its spend is the terminal's spend sentence ("You can spend X USDC (a payment above S USDC needs ${CLI_WORD} prepare first)"; the MCP says "first gets the balance ready" there), and largestPaymentAtomic is the most one payment can spend now (changeSettling: 0 only while the last payment's change settles, about changeReadyInSeconds; then one payment can use all of it, or changeUpToAtomic when a private send holds the rest).`,
155180
+ `In a terminal it prints one plain line: the private balance in USDC, and a short reason when it is not current (then the command to run). The wallet's own progress lines (Tor, the RPC relay, the pool history walk, the memo reads) show only with --verbose; warnings and failures always show. A program, or --json, gets the whole report as JSON (total, shinjukuShielded, status, reasons, next, detail). Its spend is the terminal's spend sentence ("You can spend X USDC, up to S USDC in one payment now"; the MCP says "X USDC (a payment above S USDC first gets the balance ready)"), and largestPaymentAtomic is the most one payment can spend now (changeSettling: 0 only while the last payment's change settles, about changeReadyInSeconds; then one payment can use all of it, or changeUpToAtomic when a private send holds the rest).`,
155159
155181
  "Payments that others send to this wallet appear only after a refresh.",
155160
155182
  "With --refresh it also reads the one-time deposit addresses of this home's earlier pools (one address per request). USDC found there goes into this pool by itself (Shinjuku pays the fee), and earlierDeposits lists each one with a notice.",
155161
155183
  "paymentsWithoutWaiting (and detail.fundedAccounts): your funded deposits that no in-flight work holds. A payment spends one funded deposit, and its change pays only after the next pool anchor, so this many payments can run before the next anchor without waiting (a funded deposit made since the last anchor, such as a change, waits for the next one). add-funds --split makes more of them."
@@ -156818,10 +156840,30 @@ async function runUnshieldRequest(args, values, deps, io) {
156818
156840
  io.out(terminal ? unshieldDoneText(result, owner.toBase58()) : `${JSON.stringify(result)}
156819
156841
  `);
156820
156842
  };
156821
- const returned = await deps.unshieldMain(gated, { output: (result) => {
156822
- answer = result;
156823
- show(result);
156824
- }, directExit });
156843
+ let returned;
156844
+ for (let joined = false; ; ) {
156845
+ try {
156846
+ returned = await deps.unshieldMain(gated, { output: (result) => {
156847
+ answer = result;
156848
+ show(result);
156849
+ }, directExit });
156850
+ break;
156851
+ } catch (error) {
156852
+ if (joined || shown || recorded?.inParts === true || !(localErrorCodes(error).includes(SPLIT_CODE) || String(error?.message ?? "").includes(SPLIT_CODE))) {
156853
+ if (recorded?.inParts === true) values.set(JOIN_SKIPPED, true);
156854
+ throw error;
156855
+ }
156856
+ joined = true;
156857
+ const sendWallet = gated.includes("--wallet") ? gated[gated.indexOf("--wallet") + 1] : values.get("--wallet");
156858
+ const outcome = await joinForFixedSend(new Map([...values, ["--wallet", sendWallet]]), deps, io);
156859
+ if (outcome === true) continue;
156860
+ if (outcome === "stale") {
156861
+ throw new PublicFailure(`${SEND_NOT_READY_CODE}: your private balance covers this send in total, but the wallet's saved balance is not up to date, so it could not get the balance ready for one send. Nothing was signed or sent. Run ${cli4()} balance --refresh, then the same command again with --unshield-id ${id}: it never sends twice`);
156862
+ }
156863
+ if (outcome === "files") values.set(JOIN_SKIPPED, true);
156864
+ throw error;
156865
+ }
156866
+ }
156825
156867
  answer ??= returned;
156826
156868
  if (!answer || typeof answer !== "object") return;
156827
156869
  show(answer);
@@ -156842,7 +156884,7 @@ async function runUnshieldRequest(args, values, deps, io) {
156842
156884
  } catch {
156843
156885
  parts = void 0;
156844
156886
  }
156845
- io.out(`${[privateBalanceLine(parts, { afterSend: true }), ...unfinished.map(unfinishedUnshieldLine)].join("\n")}
156887
+ io.out(`${[privateBalanceLine(parts), ...unfinished.map(unfinishedUnshieldLine)].join("\n")}
156846
156888
  `);
156847
156889
  } finally {
156848
156890
  stopWatch();
@@ -156986,8 +157028,8 @@ var STALE_WORDS = Object.freeze({
156986
157028
  pool_move: "money is moving to Shinjuku's new pool"
156987
157029
  });
156988
157030
  var balanceNotCurrentWhy = (report) => STALE_WORDS[staleCauseOf(report)] ?? (report?.status === "unknown" ? "this wallet has no balance walk yet" : "a payment, deposit, or send finished after the last balance walk");
156989
- function privateBalanceLine(parts, { afterSend = false } = {}) {
156990
- const words2 = balanceWords(parts, { afterSend });
157031
+ function privateBalanceLine(parts) {
157032
+ const words2 = balanceWords(parts);
156991
157033
  const report = parts?.report;
156992
157034
  if (words2 === void 0) {
156993
157035
  const why = report && report.status !== "current" && report.status !== "empty" ? ` (${balanceNotCurrentWhy(report)})` : "";
@@ -157081,14 +157123,6 @@ async function joinForSendAll(report, parts, store, values, deps, io, ensureId)
157081
157123
  io.err(`The wallet first gets your private balance${known ? `, ${usdcOr(report.atomic)},` : ""} ready to send (a private step inside this wallet: no fee, nothing leaves it), then sends all of it. It does this here, in rounds, each one final before the next; Ctrl+C stops it, and the same command again goes on where it stopped and never pays or sends twice
157082
157124
  `);
157083
157125
  ensureId();
157084
- if (parts.joining === 0) {
157085
- const waitMs = Math.floor((deps.random ?? Math.random)() * (JOIN_SOON_MAX_MS + 1));
157086
- io.err(`getting your balance ready starts in ${Math.round(waitMs / 1e3)} s (a random wait, so the chain does not link this step to your request)
157087
- `);
157088
- await (deps.sleep ?? ((ms) => new Promise((done) => {
157089
- setTimeout(done, ms);
157090
- })))(waitMs);
157091
- }
157092
157126
  const history = values.get("--history-rpc");
157093
157127
  const mergeArgs = [
157094
157128
  "--wallet",
@@ -157106,6 +157140,23 @@ async function joinForSendAll(report, parts, store, values, deps, io, ensureId)
157106
157140
  ...values.has("--rpc-file") ? ["--rpc-file", values.get("--rpc-file")] : [],
157107
157141
  ...history ? ["--history-rpc", history] : []
157108
157142
  ];
157143
+ return joinRounds(parts, store, values, deps, io, {
157144
+ mergeArgs,
157145
+ stopped: "note: getting your balance ready stopped, so the send did not start; nothing was sent\n",
157146
+ ready: (read, took) => `your balance is ready to send (it took ${took}); sending all ${usdcOr(read.atomic)} now
157147
+ `,
157148
+ failure: ({ remaining, read, keep }) => new PublicFailure("unshield_joining_accounts: the wallet did not finish getting your private balance ready to send" + (remaining > 1 ? "" : read ? " (the balance read after this step is not current yet)" : " (the balance could not be read after this step)") + `; nothing was sent. Send ${keep ? `up to ${usdcOr(keep)} (the amount ready now)` : "a smaller fixed amount"} now, like ${UNSHIELD_EXAMPLE}, or run ${cli4()} unshield --amount all --to <your wallet address> again after the next pool anchor: it goes on getting the balance ready and never pays or sends twice`)
157149
+ });
157150
+ }
157151
+ async function joinRounds(parts, store, values, deps, io, { mergeArgs, stopped, ready, failure: failure2 }) {
157152
+ if (parts.joining === 0) {
157153
+ const waitMs = Math.floor((deps.random ?? Math.random)() * (JOIN_SOON_MAX_MS + 1));
157154
+ io.err(`getting your balance ready starts in ${Math.round(waitMs / 1e3)} s (a random wait, so the chain does not link this step to your request)
157155
+ `);
157156
+ await (deps.sleep ?? ((ms) => new Promise((done) => {
157157
+ setTimeout(done, ms);
157158
+ })))(waitMs);
157159
+ }
157109
157160
  const startedAt = deps.now();
157110
157161
  let left = parts;
157111
157162
  let keep;
@@ -157117,7 +157168,7 @@ async function joinForSendAll(report, parts, store, values, deps, io, ensureId)
157117
157168
  answer = result;
157118
157169
  } });
157119
157170
  } catch (error) {
157120
- io.err("note: getting your balance ready stopped, so the send did not start; nothing was sent\n");
157171
+ io.err(stopped);
157121
157172
  throw error;
157122
157173
  }
157123
157174
  const merged = (answer?.merged ?? answer?.resumed ?? []).filter((entry) => entry?.state === "merged").length;
@@ -157126,16 +157177,145 @@ async function joinForSendAll(report, parts, store, values, deps, io, ensureId)
157126
157177
  left = joinParts(store);
157127
157178
  if (read?.status === "current" && left?.parts <= 1 && left.joining === 0) {
157128
157179
  const seconds2 = Math.max(0, Math.round((deps.now() - startedAt) / 1e3));
157129
- io.err(`your balance is ready to send (it took ${Math.floor(seconds2 / 60)} min ${seconds2 % 60} s); sending all ${usdcOr(read.atomic)} now
157130
- `);
157180
+ io.err(ready(read, `${Math.floor(seconds2 / 60)} min ${seconds2 % 60} s`));
157131
157181
  return read;
157132
157182
  }
157133
157183
  if (!read || read.status !== "current" || merged === 0) break;
157134
157184
  if (round < SEND_ALL_JOIN_ROUNDS) io.err(`getting your balance ready: round ${round} is final; the next round starts now
157135
157185
  `);
157136
157186
  }
157137
- const remaining = left ? left.parts + left.joining : void 0;
157138
- throw new PublicFailure("unshield_joining_accounts: the wallet did not finish getting your private balance ready to send" + (remaining > 1 ? "" : read ? " (the balance read after this step is not current yet)" : " (the balance could not be read after this step)") + `; nothing was sent. Send ${keep ? `up to ${usdcOr(keep)} (the amount ready now)` : "a smaller fixed amount"} now, like ${UNSHIELD_EXAMPLE}, or run ${cli4()} unshield --amount all --to <your wallet address> again after the next pool anchor: it goes on getting the balance ready and never pays or sends twice`);
157187
+ throw failure2({ remaining: left ? left.parts + left.joining : void 0, read, keep });
157188
+ }
157189
+ async function joinForCurlPayment(session, values, deps, io, requestId) {
157190
+ let config;
157191
+ let home;
157192
+ try {
157193
+ home = setupHome(deps.env);
157194
+ config = setupConfigOf(home);
157195
+ } catch {
157196
+ config = void 0;
157197
+ }
157198
+ const proofTools = values.get("--proof-tools");
157199
+ let walletPath2;
157200
+ try {
157201
+ walletPath2 = typeof config?.pool === "string" ? deps.walletPath(config.pool) : void 0;
157202
+ } catch {
157203
+ walletPath2 = void 0;
157204
+ }
157205
+ const passphraseFile = values.get("--passphrase-file") ?? config?.passphraseFile;
157206
+ const same2 = (one, two) => process.platform === "win32" ? resolve37(one).toLowerCase() === resolve37(two).toLowerCase() : resolve37(one) === resolve37(two);
157207
+ if (!config?.profile || !passphraseFile || !proofTools || !values.get("--memo-service") || typeof deps.mergeMain !== "function" || typeof walletPath2 !== "string" || typeof session.walletPath !== "string" || !same2(session.walletPath, walletPath2) || ![passphraseFile, config.profile, proofTools, walletPath2].every((file) => existsSync(resolve37(file)))) return "files";
157208
+ let store;
157209
+ try {
157210
+ store = session.openStore();
157211
+ } catch {
157212
+ return "files";
157213
+ }
157214
+ const parts = joinParts(store);
157215
+ if (!parts || parts.parts <= 1 && parts.joining === 0) return "busy";
157216
+ let report;
157217
+ try {
157218
+ report = computeBalance({ store, snapshotRead: readBalanceSnapshot(store), source: "local", now: deps.now() });
157219
+ } catch {
157220
+ return "stale";
157221
+ }
157222
+ if ((report.detail?.inFlight ?? []).some((item) => item.kind !== "merge")) return "busy";
157223
+ if (parts.joining === 0 && report.status !== "current") return "stale";
157224
+ const service = new URL(values.get("--memo-service")).origin;
157225
+ const joinValues = new Map([
157226
+ ...values,
157227
+ ["--wallet", walletPath2],
157228
+ ["--facilitator", service],
157229
+ ["--payer-proof-tools", proofTools],
157230
+ ["--passphrase-file", passphraseFile],
157231
+ ["--profile", config.profile]
157232
+ ]);
157233
+ io.err("Your private balance covers this payment, but not yet in one payment. The wallet first gets it ready (a private step inside this wallet: no fee, nothing leaves it), then pays. Ctrl+C stops it; the same command again with this request-id goes on and never pays twice\n");
157234
+ const history = values.get("--history-rpc");
157235
+ const mergeArgs = [
157236
+ "--wallet",
157237
+ walletPath2,
157238
+ "--passphrase-file",
157239
+ passphraseFile,
157240
+ "--program",
157241
+ values.get("--program"),
157242
+ "--proof-tools",
157243
+ proofTools,
157244
+ "--profile",
157245
+ config.profile,
157246
+ "--facilitator",
157247
+ service,
157248
+ ...values.has("--rpc-file") ? ["--rpc-file", values.get("--rpc-file")] : [],
157249
+ ...history ? ["--history-rpc", history] : []
157250
+ ];
157251
+ await joinRounds(parts, store, joinValues, deps, io, {
157252
+ mergeArgs,
157253
+ stopped: "note: getting your balance ready stopped, so nothing was paid\n",
157254
+ ready: (_read, took) => `your balance is ready (it took ${took}); paying now
157255
+ `,
157256
+ failure: () => new PublicFailure(`${BALANCE_NOT_READY_CODE}: the wallet did not finish getting your private balance ready for this payment, so nothing was paid. Run the same command again in a minute with --request-id ${requestId}: it goes on where it stopped and never pays twice`)
157257
+ });
157258
+ return true;
157259
+ }
157260
+ async function joinForFixedSend(values, deps, io) {
157261
+ const walletFile = values.get("--wallet");
157262
+ const pool2 = typeof walletFile === "string" ? /([1-9A-HJ-NP-Za-km-z]{32,44})[\\/]wallet\.json$/.exec(resolve37(walletFile))?.[1] : void 0;
157263
+ let homeWallet;
157264
+ try {
157265
+ homeWallet = pool2 ? deps.walletPath(pool2) : void 0;
157266
+ } catch {
157267
+ homeWallet = void 0;
157268
+ }
157269
+ if (typeof homeWallet !== "string" || resolve37(homeWallet) !== resolve37(walletFile) || typeof deps.mergeMain !== "function") return "files";
157270
+ const files = ["--passphrase-file", "--profile", "--payer-proof-tools"].map((name) => values.get(name));
157271
+ if (!values.get("--facilitator") || !values.get("--program") || ![...files, walletFile].every((file) => typeof file === "string" && existsSync(resolve37(file)))) return "files";
157272
+ let store;
157273
+ try {
157274
+ store = (deps.openWalletStore ?? openWalletStore)(resolve37(walletFile), payerPassphrase(values, deps));
157275
+ } catch {
157276
+ return "files";
157277
+ }
157278
+ let parts = joinParts(store);
157279
+ let report;
157280
+ try {
157281
+ report = computeBalance({ store, snapshotRead: readBalanceSnapshot(store), source: "local", now: deps.now() });
157282
+ } catch {
157283
+ return "stale";
157284
+ }
157285
+ if (parts && parts.joining === 0 && report.status !== "current") {
157286
+ report = await refreshAfterUnshield(walletFile, values, deps, io) ?? report;
157287
+ if (report.status !== "current") return "stale";
157288
+ parts = joinParts(store);
157289
+ if (parts && parts.parts <= 1 && parts.joining === 0) return true;
157290
+ }
157291
+ if (!parts || parts.parts <= 1 && parts.joining === 0) return "busy";
157292
+ if ((report.detail?.inFlight ?? []).some((item) => item.kind !== "merge")) return "busy";
157293
+ io.err("Your private balance covers this send, but not yet in one payment. The wallet first gets it ready (a private step inside this wallet: no fee, nothing leaves it), then sends. Ctrl+C stops it; nothing is sent before it is ready\n");
157294
+ const history = values.get("--history-rpc");
157295
+ const mergeArgs = [
157296
+ "--wallet",
157297
+ walletFile,
157298
+ "--passphrase-file",
157299
+ values.get("--passphrase-file"),
157300
+ "--program",
157301
+ values.get("--program"),
157302
+ "--proof-tools",
157303
+ values.get("--payer-proof-tools"),
157304
+ "--profile",
157305
+ values.get("--profile"),
157306
+ "--facilitator",
157307
+ new URL(values.get("--facilitator")).origin,
157308
+ ...values.has("--rpc-file") ? ["--rpc-file", values.get("--rpc-file")] : [],
157309
+ ...history ? ["--history-rpc", history] : []
157310
+ ];
157311
+ await joinRounds(parts, store, values, deps, io, {
157312
+ mergeArgs,
157313
+ stopped: "note: getting your balance ready stopped, so nothing was sent\n",
157314
+ ready: (_read, took) => `your balance is ready (it took ${took}); sending now
157315
+ `,
157316
+ failure: () => new PublicFailure(`${SEND_NOT_READY_CODE}: the wallet did not finish getting your private balance ready for this send, so nothing was sent. Run the same command again in a minute with --unshield-id ${values.get("--unshield-id")}: it goes on where it stopped and never sends twice`)
157317
+ });
157318
+ return true;
157139
157319
  }
157140
157320
  async function runUnshieldCancel(values, deps, io) {
157141
157321
  const walletFile = resolve37(values.get("--wallet"));
@@ -157971,7 +158151,7 @@ async function runBalance(args, values, deps, io) {
157971
158151
  ...Number.isSafeInteger(parts.changeReadyInSeconds) ? { changeReadyInSeconds: parts.changeReadyInSeconds } : {},
157972
158152
  .../^[0-9]+$/.test(String(parts.changeUpToAtomic ?? "")) && BigInt(parts.changeUpToAtomic) < BigInt(parts.spendableAtomic) ? { changeUpToAtomic: parts.changeUpToAtomic } : {}
157973
158153
  } : {},
157974
- spend: spendHeads(parts.spendableAtomic, parts.largestPaymentAtomic, parts, { surface: "cli", prepareCommand: `${cli4()} prepare` })[0] ?? null,
158154
+ spend: spendHeads(parts.spendableAtomic, parts.largestPaymentAtomic, parts, { surface: "cli" })[0] ?? null,
157975
158155
  refundsInFlightAtomic: parts.refundsInFlightAtomic,
157976
158156
  refundsNotCertainAtomic: parts.refundsNotCertainAtomic,
157977
158157
  openPaymentsAtomic: parts.openPaymentsAtomic,
@@ -158122,11 +158302,14 @@ function insufficientCause2(reason, parts) {
158122
158302
  if (/p03_merchant_respend_accounts_split_merge_first/.test(reason)) return "split";
158123
158303
  return parts?.spendableAtomic === "0" && /^[1-9][0-9]*$/.test(String(parts.report?.detail?.reservedAtomic ?? "")) ? "held" : "short";
158124
158304
  }
158125
- function insufficientWords(cause, parts) {
158305
+ function insufficientWords(cause, parts, { selfJoin = false, send: send3 = false } = {}) {
158126
158306
  const anchor = "after the next pool anchor";
158127
158307
  switch (cause) {
158128
158308
  case "split":
158129
- return "your private balance covers this amount in total, but it is not ready to pay in one payment yet. Nothing was signed, and the quote was dropped. " + (balanceWords(parts) ? `${balanceWords(parts)}. ` : "") + `Get it ready first: run ${cli4()} prepare (after setup it needs no flags; ${cli4()} help prepare shows them otherwise; --dry-run shows the plan). It runs one round in this terminal and never pays twice; its answer says whether another round is due. Then rerun this payment ${anchor}`;
158309
+ if (selfJoin) {
158310
+ return `your private balance covers this amount in total, but part of it is not ready to spend yet (another payment or send of this wallet, or its change, is not final yet), so it cannot ${send3 ? "send" : "pay"} this in one payment now. Nothing was signed or ${send3 ? "sent" : "paid"}. ${/^[0-9]+$/.test(String(parts?.spendableAtomic ?? "")) ? `You can spend ${usdcOr(parts.spendableAtomic)} in total. ` : ""}Run the same command again in a minute: it gets your balance ready by itself when it needs to, and never ${send3 ? "sends" : "pays"} twice`;
158311
+ }
158312
+ return "your private balance covers this amount in total, but it is not ready to pay in one payment yet. Nothing was signed, and the quote was dropped. " + (balanceWords(parts) ? `${balanceWords(parts)}. ` : "") + `Get it ready first: run ${cli4()} prepare (after setup it needs no flags; ${cli4()} help prepare shows them otherwise; --dry-run shows the plan). It runs one round in this terminal and never pays twice; its answer says whether another round is due. Then rerun this ${send3 ? "send" : "payment"} ${anchor}`;
158130
158313
  case "held":
158131
158314
  return `open work of this wallet (a payment, a send, or a fill) holds your whole private balance now, so none of it is free for this payment. Nothing was signed, and the quote was dropped. ${cli4()} balance --json lists that work (detail.inFlight); rerun this command once it finished`;
158132
158315
  default: {
@@ -158471,7 +158654,10 @@ function failureHint(command, reason, deps, values, floatError) {
158471
158654
  }
158472
158655
  if (/p03_merchant_respend_(insufficient_recovered_value|accounts_split_merge_first)/.test(reason)) {
158473
158656
  const parts = runBalanceParts(values, deps);
158474
- return insufficientWords(insufficientCause2(reason, parts), parts);
158657
+ return insufficientWords(insufficientCause2(reason, parts), parts, {
158658
+ selfJoin: ["curl", "unshield"].includes(command?.name) && values?.get?.(JOIN_SKIPPED) !== true,
158659
+ send: command?.name === "unshield"
158660
+ });
158475
158661
  }
158476
158662
  if (/p03_unshield_anchor_settler_underfunded/.test(reason)) {
158477
158663
  return "Shinjuku cannot take this step now (its own account for it is low on funds), so nothing was sent. Run the same command again later; it goes on where it stopped";
@@ -159424,7 +159610,7 @@ This copy: ${walletVersionLine(deps.walletVersion())}
159424
159610
  const reason = failureReason(command, error, values);
159425
159611
  const codes = failureCodes(error, reason);
159426
159612
  writeRunResult(deps, command, 1, error, codes);
159427
- const plainCode = [NOT_SET_UP_CODE, EMPTY_BALANCE_CODE, OVER_LIMITS_CODE, CEILING_OVER_CAP_CODE, CAP_ABOVE_LIMIT_CODE].find((code2) => reason.startsWith(`${code2}: `));
159613
+ const plainCode = [NOT_SET_UP_CODE, EMPTY_BALANCE_CODE, OVER_LIMITS_CODE, CEILING_OVER_CAP_CODE, CAP_ABOVE_LIMIT_CODE, BALANCE_NOT_READY_CODE, SEND_NOT_READY_CODE].find((code2) => reason.startsWith(`${code2}: `));
159428
159614
  if (plainCode) {
159429
159615
  const plain = reason.slice(plainCode.length + 2);
159430
159616
  io.err(`${plain[0].toUpperCase()}${plain.slice(1)}
@@ -159494,6 +159680,13 @@ Next: fund that address, then rerun the same command; it continues where it stop
159494
159680
  `);
159495
159681
  return 1;
159496
159682
  }
159683
+ if (hint && ["curl", "pay", "unshield"].includes(command?.name) && codes.some((code2) => /^p03_merchant_respend_(insufficient_recovered_value|accounts_split_merge_first)$/.test(code2))) {
159684
+ const made = command.name === "unshield" ? values?.get?.(UNSHIELD_MADE_ID) : void 0;
159685
+ io.err(`${hint[0].toUpperCase()}${hint.slice(1).replace(/[\s.;]+$/, "")}.
159686
+ ` + (made ? `this unshield's id is ${made}: to rerun or finish it, run the same command with --unshield-id ${made} added (it never sends twice)
159687
+ ` : ""));
159688
+ return 1;
159689
+ }
159497
159690
  if (hint && ANCHOR_REFUSAL.test([...codes, reason].join(" "))) {
159498
159691
  io.err(`${hint[0].toUpperCase()}${hint.slice(1).replace(/[\s.;]+$/, "")}.
159499
159692
  `);