shinjuku-shield 0.3.142 → 0.3.144

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.142. The npm packages `shinjuku-shield` and
9
+ This is version 0.3.144. 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.142
15
+ npm install -g shinjuku@0.3.144
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.142 setup`.
21
+ installing, type `npx shinjuku@0.3.144 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.142 mcp
39
+ claude mcp add --scope user shinjuku -- npx -y --no-audit --no-fund shinjuku-shield@0.3.144 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.142", "mcp"] } } }
45
+ { "mcpServers": { "shinjuku": { "command": "npx", "args": ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.144", "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.142", "mcp"]
58
+ args = ["-y", "--no-audit", "--no-fund", "shinjuku-shield@0.3.144", "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": "88aadc6644df79f42aba537416608eea0462184073f62a0053c9d6f83f3cb46d",
5
- "bytes": 8972142,
6
- "sourceCommit": "9787e6457056edc02c707b855c12db300b81beac",
4
+ "sha256": "325c7ac76ca281c68aaeb201b8601305495083f9bfb211578189e55f2f9f298c",
5
+ "bytes": 8975329,
6
+ "sourceCommit": "4c820285fc768c8cdfbc6496a62d691a71962a14",
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",
@@ -38,6 +38,7 @@
38
38
  "src/server/payments/shielded/p03LoopLag.ts",
39
39
  "src/server/payments/shielded/p03MinContextSlotRetry.ts",
40
40
  "src/server/payments/shielded/p03PhotonHost.ts",
41
+ "src/server/payments/shielded/p03QuoteRingAnchor.ts",
41
42
  "src/server/payments/shielded/poseidon/poseidon_params_t_2.json",
42
43
  "src/server/payments/shielded/poseidon/poseidon_params_t_3.json",
43
44
  "src/server/payments/shielded/poseidon/poseidon_params_t_6.json",
@@ -1037,5 +1038,5 @@
1037
1038
  "version": "1.8.0"
1038
1039
  }
1039
1040
  ],
1040
- "publishedAt": "2026-11-01T08:46:43.152Z"
1041
+ "publishedAt": "2026-11-01T09:50:32.342Z"
1041
1042
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shield",
3
- "version": "0.3.142",
3
+ "version": "0.3.144",
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": "88aadc66",
7
- "shinjukuSha256": "88aadc6644df79f42aba537416608eea0462184073f62a0053c9d6f83f3cb46d",
6
+ "shinjukuRelease": "325c7ac7",
7
+ "shinjukuSha256": "325c7ac76ca281c68aaeb201b8601305495083f9bfb211578189e55f2f9f298c",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-shield#readme",
@@ -80044,6 +80044,35 @@ var init_ShieldedSolanaP03Types = __esm({
80044
80044
  }
80045
80045
  });
80046
80046
 
80047
+ // src/server/payments/shielded/p03QuoteRingAnchor.ts
80048
+ function p03QuoteValidBefore(epoch) {
80049
+ return (epoch + 2n) * EPOCH_SECONDS;
80050
+ }
80051
+ function p03RingAnchorHasQuoteMargin(epoch, chainTimestamp) {
80052
+ return p03QuoteValidBefore(epoch) - chainTimestamp >= P03_QUOTE_RING_ANCHOR_MIN_SECONDS_LEFT;
80053
+ }
80054
+ function p03StaleQuoteAnchorRing(error) {
80055
+ return error instanceof P03QuoteAnchorStaleError ? error.ring : void 0;
80056
+ }
80057
+ function p03RingAnchorServesQuote(anchor, ring) {
80058
+ return p03RingAnchorHasQuoteMargin(anchor.epoch, ring.chainTimestamp) && ring.anchors.some((slot3) => slot3.epoch === anchor.epoch && slot3.anchorIndex === anchor.anchorIndex && slot3.anchorRoot === anchor.anchorRoot);
80059
+ }
80060
+ var P03_QUOTE_RING_ANCHOR_MIN_SECONDS_LEFT, EPOCH_SECONDS, P03QuoteAnchorStaleError;
80061
+ var init_p03QuoteRingAnchor = __esm({
80062
+ "src/server/payments/shielded/p03QuoteRingAnchor.ts"() {
80063
+ "use strict";
80064
+ P03_QUOTE_RING_ANCHOR_MIN_SECONDS_LEFT = 120n;
80065
+ EPOCH_SECONDS = 300n;
80066
+ P03QuoteAnchorStaleError = class extends Error {
80067
+ ring;
80068
+ constructor(ring) {
80069
+ super("p03_quote_anchor_stale");
80070
+ this.ring = Object.freeze({ ...ring, anchors: Object.freeze(ring.anchors.map((anchor) => Object.freeze({ ...anchor }))) });
80071
+ }
80072
+ };
80073
+ }
80074
+ });
80075
+
80047
80076
  // src/server/payments/shielded/ShieldedSolanaP03Quote.ts
80048
80077
  function deriveShieldedSolanaP03SvmMappings(input) {
80049
80078
  const network = canonicalNetwork(input.network);
@@ -80100,8 +80129,8 @@ function parseAnchor(raw, label) {
80100
80129
  });
80101
80130
  }
80102
80131
  function checkedValidBefore(epoch) {
80103
- if (epoch > U64_LIMIT / EPOCH_SECONDS - 2n) throw new Error("p03_quote_expiry_overflow");
80104
- return (epoch + 2n) * EPOCH_SECONDS;
80132
+ if (epoch > U64_LIMIT / EPOCH_SECONDS2 - 2n) throw new Error("p03_quote_expiry_overflow");
80133
+ return (epoch + 2n) * EPOCH_SECONDS2;
80105
80134
  }
80106
80135
  function canonicalPublicInput(value2) {
80107
80136
  if (value2 instanceof Uint8Array) {
@@ -80228,7 +80257,7 @@ function assertExactKeys(value2, expectedKeys, label) {
80228
80257
  throw new Error(`p03_quote_${label}_shape_invalid`);
80229
80258
  }
80230
80259
  }
80231
- var import_web3108, U48_LIMIT, U64_LIMIT, EPOCH_SECONDS, QUOTE_DOMAIN_LABEL, POOL_DOMAIN_LABEL, SHIELDED_SOLANA_P03_QUOTE_DOMAIN, REQUIREMENT_KEYS, EXTRA_KEYS, ShieldedSolanaP03QuoteIssuer;
80260
+ var import_web3108, U48_LIMIT, U64_LIMIT, EPOCH_SECONDS2, QUOTE_DOMAIN_LABEL, POOL_DOMAIN_LABEL, SHIELDED_SOLANA_P03_QUOTE_DOMAIN, REQUIREMENT_KEYS, EXTRA_KEYS, ShieldedSolanaP03QuoteIssuer;
80232
80261
  var init_ShieldedSolanaP03Quote = __esm({
80233
80262
  "src/server/payments/shielded/ShieldedSolanaP03Quote.ts"() {
80234
80263
  "use strict";
@@ -80236,10 +80265,11 @@ var init_ShieldedSolanaP03Quote = __esm({
80236
80265
  init_sha3();
80237
80266
  init_utils();
80238
80267
  init_ShieldedSolanaP03Types();
80268
+ init_p03QuoteRingAnchor();
80239
80269
  init_ShieldedSolanaP03QuoteCrypto();
80240
80270
  U48_LIMIT = 1n << 48n;
80241
80271
  U64_LIMIT = 1n << 64n;
80242
- EPOCH_SECONDS = 300n;
80272
+ EPOCH_SECONDS2 = 300n;
80243
80273
  QUOTE_DOMAIN_LABEL = utf8ToBytes("carbon-shielded-exact/quote/v1");
80244
80274
  POOL_DOMAIN_LABEL = utf8ToBytes("carbon-shielded-exact/pool/v1");
80245
80275
  SHIELDED_SOLANA_P03_QUOTE_DOMAIN = bytesToBigInt2(keccak_256(QUOTE_DOMAIN_LABEL)) % SHIELDED_SOLANA_P03_QUOTE_FIELD_MODULUS;
@@ -80307,7 +80337,7 @@ var init_ShieldedSolanaP03Quote = __esm({
80307
80337
  }
80308
80338
  async issue(recipientAddress) {
80309
80339
  const evidence = parseAnchorEvidence(await this.readCurrentQuoteAnchor());
80310
- const chainEpoch = evidence.chainTimestamp / EPOCH_SECONDS;
80340
+ const chainEpoch = evidence.chainTimestamp / EPOCH_SECONDS2;
80311
80341
  if (evidence.current.epoch !== chainEpoch) throw new Error("p03_quote_anchor_not_current");
80312
80342
  const nonceResult = this.randomBytes(32);
80313
80343
  if (!(nonceResult instanceof Uint8Array) || nonceResult.length !== 32) {
@@ -80337,7 +80367,17 @@ var init_ShieldedSolanaP03Quote = __esm({
80337
80367
  }
80338
80368
  async authenticate(input) {
80339
80369
  const parsed2 = this.parseAuthentication(input);
80340
- const evidence = parseAnchorEvidence(await this.readCurrentQuoteAnchor());
80370
+ let raw;
80371
+ try {
80372
+ raw = await this.readCurrentQuoteAnchor();
80373
+ } catch (error) {
80374
+ const ring = p03StaleQuoteAnchorRing(error);
80375
+ if (ring === void 0) throw error;
80376
+ if (ring.chainTimestamp >= parsed2.validBefore) throw new Error("p03_quote_expired");
80377
+ if (!p03RingAnchorServesQuote(parsed2.anchor, ring)) throw error;
80378
+ return this.authenticateParsed(input, parsed2);
80379
+ }
80380
+ const evidence = parseAnchorEvidence(raw);
80341
80381
  if (evidence.chainTimestamp >= parsed2.validBefore) throw new Error("p03_quote_expired");
80342
80382
  if (parsed2.anchor.epoch > evidence.current.epoch || parsed2.anchor.epoch === evidence.current.epoch && parsed2.anchor.anchorIndex > evidence.current.anchorIndex) {
80343
80383
  throw new Error("p03_quote_anchor_stale");
@@ -82217,16 +82257,37 @@ function createAnchorReader({ connection, profile }) {
82217
82257
  if (chainTimestamp < 0n) fail17("chain_clock_invalid");
82218
82258
  const anchors = state.validAnchors.map((a) => ({ epoch: a.epoch, anchorIndex: a.index, anchorRoot: bigint(a.root) }));
82219
82259
  const current = anchors.find((a) => a.epoch === chainTimestamp / 300n);
82220
- if (requireCapacity && !current) fail17("anchor_not_ready");
82221
- const selected = current ?? anchors[0];
82222
- return {
82260
+ const newest = anchors[0];
82261
+ const ringSlotServes = !current && requireCapacity && state.anchorMode === 2 && state.anchorRing !== null && newest !== void 0 && newest.anchorIndex === BigInt(state.currentIndex) && p03RingAnchorHasQuoteMargin(BigInt(newest.epoch), chainTimestamp);
82262
+ if (requireCapacity && !current && !ringSlotServes) fail17("anchor_not_ready");
82263
+ const selected = current ?? newest;
82264
+ const read = {
82223
82265
  ...selected,
82224
82266
  chainTimestamp,
82225
82267
  finalizedSlot: slot3,
82226
82268
  retainedAnchors: anchors.filter((a) => a !== selected)
82227
82269
  };
82270
+ if (state.anchorMode === 2 && state.anchorRing !== null) ringModeReads.add(read);
82271
+ return read;
82228
82272
  };
82229
82273
  }
82274
+ function ringSlotServesPayment(read, quoteAnchor) {
82275
+ return quoteAnchor !== void 0 && ringModeReads.has(read) && p03RingAnchorServesQuote(quoteAnchor, {
82276
+ chainTimestamp: read.chainTimestamp,
82277
+ finalizedSlot: read.finalizedSlot,
82278
+ anchors: [read, ...read.retainedAnchors].map((a) => ({ epoch: BigInt(a.epoch), anchorIndex: BigInt(a.anchorIndex), anchorRoot: BigInt(a.anchorRoot) }))
82279
+ });
82280
+ }
82281
+ function quoteAnchorOfOffer(offer) {
82282
+ try {
82283
+ const extra = JSON.parse(offer.outboundJson).paymentRequirements.extra;
82284
+ const field4 = (value2) => typeof value2 === "string" && /^(0|[1-9][0-9]*)$/.test(value2) ? BigInt(value2) : void 0;
82285
+ const anchor = { epoch: field4(extra.epoch), anchorIndex: field4(extra.anchorIndex), anchorRoot: field4(extra.anchorRoot) };
82286
+ return Object.values(anchor).includes(void 0) ? void 0 : anchor;
82287
+ } catch {
82288
+ return void 0;
82289
+ }
82290
+ }
82230
82291
  function reusableBeforeSettle(offer, chain, elapsedMs) {
82231
82292
  if (!chain || !Number.isFinite(elapsedMs) || elapsedMs < 0 || elapsedMs > PRE_SETTLE_REUSE_MAX_AGE_MS) return false;
82232
82293
  const expiresAt = JSON.parse(offer.outboundJson).sellerAcceptance?.expiresAt;
@@ -82371,14 +82432,14 @@ async function createSellerAdapter({
82371
82432
  anchorPoll = void 0;
82372
82433
  });
82373
82434
  };
82374
- const readCurrentAnchor = async (first) => {
82375
- const isCurrent = (chain2) => chain2.epoch === chain2.chainTimestamp / 300n;
82435
+ const readCurrentAnchor = async (first, quoteAnchor) => {
82436
+ const usable = (chain2) => chain2.epoch === chain2.chainTimestamp / 300n || ringSlotServesPayment(chain2, quoteAnchor);
82376
82437
  const chain = first ?? await readAnchor();
82377
- if (isCurrent(chain)) return chain;
82438
+ if (usable(chain)) return chain;
82378
82439
  await requestFacilitatorAnchor();
82379
82440
  for (let attempt = 1; ; attempt += 1) {
82380
82441
  const next = await readAnchor();
82381
- if (isCurrent(next)) return next;
82442
+ if (usable(next)) return next;
82382
82443
  if (attempt >= ANCHOR_POLL_ATTEMPTS) fail17("anchor_not_ready");
82383
82444
  await sleep4(ANCHOR_POLL_MS);
82384
82445
  }
@@ -82924,7 +82985,7 @@ async function createSellerAdapter({
82924
82985
  }
82925
82986
  const firstIntake = intakeChain !== void 0 && !offer.settleAttempted;
82926
82987
  if (firstIntake) {
82927
- await readCurrentAnchor(intakeChain);
82988
+ await readCurrentAnchor(intakeChain, quoteAnchorOfOffer(offer));
82928
82989
  offer = { ...offer, phase: "settlement_pending", settleAttempted: true };
82929
82990
  await put(nonce, offer);
82930
82991
  mark("first-intake-settle");
@@ -82943,7 +83004,7 @@ async function createSellerAdapter({
82943
83004
  const renewed = await renewPreSettlementAcceptance(nonce, offer, chain);
82944
83005
  if (!renewed) return { status: 202, code: PAYMENT_REFUSED };
82945
83006
  offer = renewed;
82946
- await readCurrentAnchor(chain);
83007
+ await readCurrentAnchor(chain, quoteAnchorOfOffer(offer));
82947
83008
  const verified = await facilitator("verify", offer.outboundJson);
82948
83009
  mark("verify");
82949
83010
  if (verified?.isValid !== true) {
@@ -83132,7 +83193,7 @@ async function createSellerAdapter({
83132
83193
  };
83133
83194
  return { server, handle, close, signerPublicKey, settledTransactions, offerSummaries, discardUnsentOffer };
83134
83195
  }
83135
- var import_web3113, LOOPBACK_ORIGIN, BINDING, SCHEMA2, OFFERS_LAYOUT, SNAPSHOT_EVERY_MS, LOADER2, canonical4, storeProfileIdentity, jsonSafe, bigint, encodeHeader, PROGRAM_DATA_HEADER_BYTES, hashedProgramDataHeaders, PAYMENT_REFUSED, FACILITATOR_UNDERFUNDED, DEFINITE_VERIFY_REFUSALS, definiteVerifyRefusal, refusedBeforeSettlement, ANCHOR_REQUEST_TIMEOUT_MS2, ANCHOR_POLL_ATTEMPTS, ANCHOR_POLL_MS, ANCHOR_BUSY_DEFAULT_SECONDS, ANCHOR_BUSY_MAX_SECONDS, MEMO_PRECOMPUTES_MAX, MEMO_PRECOMPUTE_WAIT_MS, WALLET_MERCHANT_SLOT, PRE_SETTLE_REUSE_MARGIN_S, PRE_SETTLE_REUSE_MAX_AGE_MS, FINALIZED_MEMO_MAX_AGE_MS, INTAKE_REUSE_MAX_AGE_MS, pause, FOLLOW_UP_DELAYS_MS, FOLLOW_UP_RESETTLE_FROM, UPSTREAM_FAILED, UPSTREAM_BODY_MAX, upstreamFailure, forwardedContentType, CONFIRMED_TRANSACTION_READ;
83196
+ var import_web3113, LOOPBACK_ORIGIN, BINDING, SCHEMA2, OFFERS_LAYOUT, SNAPSHOT_EVERY_MS, LOADER2, canonical4, storeProfileIdentity, jsonSafe, bigint, encodeHeader, PROGRAM_DATA_HEADER_BYTES, hashedProgramDataHeaders, ringModeReads, PAYMENT_REFUSED, FACILITATOR_UNDERFUNDED, DEFINITE_VERIFY_REFUSALS, definiteVerifyRefusal, refusedBeforeSettlement, ANCHOR_REQUEST_TIMEOUT_MS2, ANCHOR_POLL_ATTEMPTS, ANCHOR_POLL_MS, ANCHOR_BUSY_DEFAULT_SECONDS, ANCHOR_BUSY_MAX_SECONDS, MEMO_PRECOMPUTES_MAX, MEMO_PRECOMPUTE_WAIT_MS, WALLET_MERCHANT_SLOT, PRE_SETTLE_REUSE_MARGIN_S, PRE_SETTLE_REUSE_MAX_AGE_MS, FINALIZED_MEMO_MAX_AGE_MS, INTAKE_REUSE_MAX_AGE_MS, pause, FOLLOW_UP_DELAYS_MS, FOLLOW_UP_RESETTLE_FROM, UPSTREAM_FAILED, UPSTREAM_BODY_MAX, upstreamFailure, forwardedContentType, CONFIRMED_TRANSACTION_READ;
83136
83197
  var init_service = __esm({
83137
83198
  "wallet/src/seller/service.mjs"() {
83138
83199
  "use strict";
@@ -83142,6 +83203,7 @@ var init_service = __esm({
83142
83203
  init_EncryptedJsonFile();
83143
83204
  init_finalizedReadMemo();
83144
83205
  init_ShieldedSolanaP03Quote();
83206
+ init_p03QuoteRingAnchor();
83145
83207
  init_ShieldedSolanaP03MemoScanner();
83146
83208
  init_SolanaP03Wire();
83147
83209
  init_ShieldedSolanaP03QuoteCrypto();
@@ -83168,6 +83230,7 @@ var init_service = __esm({
83168
83230
  encodeHeader = (v) => Buffer.from(JSON.stringify(v)).toString("base64");
83169
83231
  PROGRAM_DATA_HEADER_BYTES = 45;
83170
83232
  hashedProgramDataHeaders = /* @__PURE__ */ new Map();
83233
+ ringModeReads = /* @__PURE__ */ new WeakSet();
83171
83234
  PAYMENT_REFUSED = "payment_refused_pay_again";
83172
83235
  FACILITATOR_UNDERFUNDED = "facilitator_underfunded";
83173
83236
  DEFINITE_VERIFY_REFUSALS = /* @__PURE__ */ new Set([