shinjuku-shielded 0.3.29 → 0.3.31

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/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": "902397c7c00f815b7f80b1275a1a987ca78871df5fdf370e7c80a282ecfb15a4",
5
- "bytes": 11176401,
6
- "sourceCommit": "7c322196100fd59b6193ea99e999fd61f0ef6ed5",
4
+ "sha256": "c8c82dc4ce0277f8c560adec5cb16119709d00240a8efa4ebbb2a426e5161b6a",
5
+ "bytes": 11178235,
6
+ "sourceCommit": "206a11827c4c668d65b7e8e2040a344f17aad1d0",
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",
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "shinjuku-shielded",
3
- "version": "0.3.29",
3
+ "version": "0.3.31",
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": "902397c7",
7
- "shinjukuSha256": "902397c7c00f815b7f80b1275a1a987ca78871df5fdf370e7c80a282ecfb15a4",
6
+ "shinjukuRelease": "c8c82dc4",
7
+ "shinjukuSha256": "c8c82dc4ce0277f8c560adec5cb16119709d00240a8efa4ebbb2a426e5161b6a",
8
8
  "license": "SEE LICENSE IN LICENSE.txt",
9
9
  "author": "Shinjuku Shielded",
10
10
  "homepage": "https://github.com/ShinjukuStaition/shinjuku-mcp#readme",
@@ -70299,11 +70299,14 @@ async function runRecoveredP03NoteExit({
70299
70299
  }
70300
70300
  wal = { ...wal, state: "confirmed", signature };
70301
70301
  store.writeWal(walName2, wal);
70302
- poolState2 = await readPool2(connection, pool2, "finalized");
70303
- if (!poolState2 || !poolState2.owner.equals(chainProgramId) || poolState2.version !== 3) {
70304
- throw new Error("finalized note-exit pool postcondition invalid");
70302
+ for (let attempt = 1; ; attempt += 1) {
70303
+ history = await walkHistory();
70304
+ poolState2 = await readPool2(connection, pool2, "finalized");
70305
+ if (!poolState2 || !poolState2.owner.equals(chainProgramId) || poolState2.version !== 3) {
70306
+ throw new Error("finalized note-exit pool postcondition invalid");
70307
+ }
70308
+ if (attempt >= 4 || history.finalizedPoolSnapshot.currentIndex === poolState2.currentIndex && history.finalizedPoolSnapshot.currentRoot === poolState2.currentRoot) break;
70305
70309
  }
70306
- history = await walkHistory();
70307
70310
  await prepareFold(history);
70308
70311
  const spentPath = buildRecoveryPath({
70309
70312
  history,
@@ -72326,7 +72329,7 @@ async function validateReceiptTransaction(connection, receipt, record, state, pr
72326
72329
  [{ signature: receipt.transaction, slot: status.slot, failed: false }],
72327
72330
  blockCache,
72328
72331
  transactions,
72329
- { commitment }
72332
+ { commitment, positionWhen: () => false }
72330
72333
  );
72331
72334
  const settlements = targetInstructions([...transactions.values()], program).filter((instruction) => (instruction.data[0] === 4 || instruction.data[0] === COMPRESSED_SETTLE_TAG.payment || instruction.data[0] === E1_SETTLE_TAG.payment) && instruction.accounts[0] === pool2.toBase58());
72332
72335
  if (settlements.length !== 1) fail16("receipt_payment_instruction_missing");
@@ -91047,6 +91050,36 @@ var init_pay = __esm({
91047
91050
  }
91048
91051
  });
91049
91052
 
91053
+ // wallet/src/fetch/keepAlive.mjs
91054
+ function proxiedRun() {
91055
+ const env = process.env;
91056
+ return Boolean(env.SHINJUKU_WALLET_PROXIED || env.NODE_USE_ENV_PROXY || env.HTTPS_PROXY || env.HTTP_PROXY || env.https_proxy || env.http_proxy);
91057
+ }
91058
+ function keepAliveDispatcher() {
91059
+ if (shared !== void 0) return shared;
91060
+ try {
91061
+ if (proxiedRun()) return void 0;
91062
+ const global2 = globalThis[GLOBAL_DISPATCHER];
91063
+ if (global2?.constructor?.name !== "Agent") return void 0;
91064
+ shared = new global2.constructor({ keepAliveTimeout: KEEP_ALIVE_MS, keepAliveMaxTimeout: KEEP_ALIVE_MS });
91065
+ return shared;
91066
+ } catch {
91067
+ return void 0;
91068
+ }
91069
+ }
91070
+ function keepAliveInit(init = {}) {
91071
+ const dispatcher = keepAliveDispatcher();
91072
+ return dispatcher === void 0 ? init : { ...init, dispatcher };
91073
+ }
91074
+ var GLOBAL_DISPATCHER, KEEP_ALIVE_MS, shared;
91075
+ var init_keepAlive = __esm({
91076
+ "wallet/src/fetch/keepAlive.mjs"() {
91077
+ "use strict";
91078
+ GLOBAL_DISPATCHER = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
91079
+ KEEP_ALIVE_MS = 2e4;
91080
+ }
91081
+ });
91082
+
91050
91083
  // wallet/src/pay/floatPay.mjs
91051
91084
  import { createHash as createHash20, randomBytes as randomBytes11 } from "node:crypto";
91052
91085
  import { fileURLToPath as fileURLToPath9 } from "node:url";
@@ -91140,7 +91173,7 @@ async function readFloatConfig({ origin, fetchImpl = fetch }) {
91140
91173
  try {
91141
91174
  response = await fetchImpl(
91142
91175
  new URL("/api/x402/float/config", origin).href,
91143
- { method: "GET", redirect: "error", signal: AbortSignal.timeout(CONFIG_TIMEOUT_MS) }
91176
+ keepAliveInit({ method: "GET", redirect: "error", signal: AbortSignal.timeout(CONFIG_TIMEOUT_MS) })
91144
91177
  );
91145
91178
  } catch (error) {
91146
91179
  fail18("p03_float_config_unreadable", { cause: error });
@@ -91271,7 +91304,7 @@ function withSellerResource(xPayment, record) {
91271
91304
  }
91272
91305
  function floatFetch(base, seen) {
91273
91306
  return async (target, init = {}) => {
91274
- const response = await base(target, init);
91307
+ const response = await base(target, keepAliveInit(init));
91275
91308
  const paid = Object.keys(init.headers ?? {}).some((name) => name.toLowerCase() === "payment-signature");
91276
91309
  if (paid || response.status === 402 || response.status < 400) return response;
91277
91310
  let answer;
@@ -91469,13 +91502,13 @@ async function payViaFloat({
91469
91502
  mark("seller-sent");
91470
91503
  let response;
91471
91504
  try {
91472
- response = await fetchImpl(record.url, {
91505
+ response = await fetchImpl(record.url, keepAliveInit({
91473
91506
  method: record.request.method,
91474
91507
  headers: { ...Object.fromEntries(record.request.headers), "PAYMENT-SIGNATURE": record.xPayment },
91475
91508
  ...record.request.method === "POST" ? { body: Buffer.from(record.request.bodyBase64, "base64") } : {},
91476
91509
  redirect: "error",
91477
91510
  signal: AbortSignal.timeout(SELLER_TIMEOUT_MS)
91478
- });
91511
+ }));
91479
91512
  } catch (error) {
91480
91513
  fail18("p03_float_seller_unanswered_retry_same_request", { cause: error, floatId: record.floatId });
91481
91514
  }
@@ -91548,6 +91581,7 @@ var init_floatPay = __esm({
91548
91581
  init_http();
91549
91582
  init_ShieldedSolanaP03QuoteCrypto();
91550
91583
  init_chain2();
91584
+ init_keepAlive();
91551
91585
  init_notes2();
91552
91586
  init_pay();
91553
91587
  init_quote2();
@@ -91934,7 +91968,7 @@ async function assertRefusedPaymentsCannotLand({ store, walName: walName2, payme
91934
91968
  resolve38("proved-dead");
91935
91969
  }
91936
91970
  }
91937
- async function finalizePendingReceipt({ store, connection, programId, name, timeoutMs, pollMs, deps = {} }) {
91971
+ async function finalizePendingReceipt({ store, connection, programId, name, timeoutMs, pollMs, deps = {}, shared: shared2 }) {
91938
91972
  const sleep5 = deps.sleep ?? ((ms) => new Promise((resolve38) => setTimeout(resolve38, ms)));
91939
91973
  const now = deps.now ?? Date.now;
91940
91974
  const deadline = now() + timeoutMs;
@@ -91944,6 +91978,20 @@ async function finalizePendingReceipt({ store, connection, programId, name, time
91944
91978
  const record = store.readWal(name);
91945
91979
  if (!isPending(record)) return record;
91946
91980
  if (!connection || !programId || typeof deps.walkHistory !== "function") fail19("receipt_finality_needs_chain");
91981
+ if (!gated && shared2?.history !== void 0) {
91982
+ gated = true;
91983
+ const { clock: clock3, history: history2 } = shared2;
91984
+ const settlement2 = settlementInHistory(history2, record.paymentHeader, store.state, programId);
91985
+ markPhase("walk-shared");
91986
+ if (settlement2) return writeFinalized(store, name, record, settlement2);
91987
+ if (!paymentBlockerAt(record, clock3, history2)) {
91988
+ const dead = { ...record, receiptFinality: "never-finalized" };
91989
+ store.writeWal(name, dead);
91990
+ return dead;
91991
+ }
91992
+ strict = true;
91993
+ continue;
91994
+ }
91947
91995
  if (!gated) {
91948
91996
  gated = true;
91949
91997
  const answeredLongAgo = Number.isSafeInteger(record.answeredAtMs) && Date.now() - record.answeredAtMs >= FINALITY_GATE_SKIP_AFTER_MS;
@@ -91962,13 +92010,9 @@ async function finalizePendingReceipt({ store, connection, programId, name, time
91962
92010
  await (strict ? withStrictHistorySource(() => deps.walkHistory()) : deps.walkHistory())
91963
92011
  );
91964
92012
  markPhase("walk");
92013
+ if (shared2) Object.assign(shared2, { clock: clock2, history });
91965
92014
  const settlement = settlementInHistory(history, record.paymentHeader, store.state, programId);
91966
- if (settlement) {
91967
- const settledTransaction = settlement.provenance?.signature;
91968
- const finalized = settledTransaction === record.receipt.transaction ? { ...record, receiptFinality: "finalized" } : { ...record, receiptFinality: "finalized", receiptMismatch: "transaction", settledTransaction };
91969
- store.writeWal(name, finalized);
91970
- return finalized;
91971
- }
92015
+ if (settlement) return writeFinalized(store, name, record, settlement);
91972
92016
  if (!paymentBlockerAt(record, clock2, history)) {
91973
92017
  const dead = { ...record, receiptFinality: "never-finalized" };
91974
92018
  store.writeWal(name, dead);
@@ -91978,6 +92022,12 @@ async function finalizePendingReceipt({ store, connection, programId, name, time
91978
92022
  await sleep5(pollMs);
91979
92023
  }
91980
92024
  }
92025
+ function writeFinalized(store, name, record, settlement) {
92026
+ const settledTransaction = settlement.provenance?.signature;
92027
+ const finalized = settledTransaction === record.receipt.transaction ? { ...record, receiptFinality: "finalized" } : { ...record, receiptFinality: "finalized", receiptMismatch: "transaction", settledTransaction };
92028
+ store.writeWal(name, finalized);
92029
+ return finalized;
92030
+ }
91981
92031
  async function awaitResourceReceiptFinality({
91982
92032
  store,
91983
92033
  connection,
@@ -92208,13 +92258,13 @@ async function payResourceOnce({
92208
92258
  rpcUrl: pocket.rpcUrl,
92209
92259
  readResult,
92210
92260
  deps: pocket.deps ?? {},
92211
- send: (paymentHeaders) => (deps.fetchImpl ?? fetch)(url, {
92261
+ send: (paymentHeaders) => (deps.fetchImpl ?? fetch)(url, keepAliveInit({
92212
92262
  method: suppliedRequest.method,
92213
92263
  headers: { ...Object.fromEntries(suppliedRequest.headers), ...paymentHeaders },
92214
92264
  ...suppliedRequest.method === "POST" ? { body: Buffer.from(suppliedRequest.bodyBase64, "base64") } : {},
92215
92265
  redirect: "error",
92216
92266
  signal: AbortSignal.timeout(12e4)
92217
- })
92267
+ }))
92218
92268
  });
92219
92269
  if (!record && store.readWal(pocketPaymentWalName(requestKey))) {
92220
92270
  if (!pocket) fail19("pocket_payment_needs_rpc");
@@ -92272,13 +92322,13 @@ async function payResourceOnce({
92272
92322
  }
92273
92323
  let requestData = record?.request ?? suppliedRequest;
92274
92324
  const fetchImpl = deps.fetchImpl ?? fetch;
92275
- const request = (paymentHeaders = {}) => fetchImpl(url, {
92325
+ const request = (paymentHeaders = {}) => fetchImpl(url, keepAliveInit({
92276
92326
  method: requestData.method,
92277
92327
  headers: { ...Object.fromEntries(requestData.headers), ...paymentHeaders },
92278
92328
  ...requestData.method === "POST" ? { body: Buffer.from(requestData.bodyBase64, "base64") } : {},
92279
92329
  redirect: "error",
92280
92330
  signal: AbortSignal.timeout(12e4)
92281
- });
92331
+ }));
92282
92332
  const challengeSleep = deps.sleep ?? ((ms) => new Promise((resolve38) => setTimeout(resolve38, ms)));
92283
92333
  let prefetched = !record && typeof sellerChallenge === "string" && sellerChallenge.length > 0 && sellerChallenge.length <= 128 * 1024 ? sellerChallenge : void 0;
92284
92334
  const requestChallenge = async () => {
@@ -92314,11 +92364,11 @@ async function payResourceOnce({
92314
92364
  };
92315
92365
  const held = /* @__PURE__ */ new Set();
92316
92366
  const deferred = [];
92317
- const settlePrior = async (name) => {
92367
+ const settlePrior = async (name, shared2) => {
92318
92368
  let other = store.readWal(name);
92319
92369
  if (isPending(other)) {
92320
92370
  mark("prior-finality-wait");
92321
- other = await withPhaseScope(mark, "fin", () => finalizePendingReceipt({ store, connection, programId, name, ...finalityWait, deps: finality }));
92371
+ other = await withPhaseScope(mark, "fin", () => finalizePendingReceipt({ store, connection, programId, name, ...finalityWait, deps: finality, shared: shared2 }));
92322
92372
  if (isPending(other)) failUnresolved(other);
92323
92373
  mark("prior-finality-done");
92324
92374
  }
@@ -92483,7 +92533,9 @@ async function payResourceOnce({
92483
92533
  const noProof = store.readWal(`resource-proof-${requestKey}`)?.proved === void 0;
92484
92534
  if (noProof && deferred.length > 0 && /^p03_merchant_respend_inputs_held_by_pending_payment/.test(message)) {
92485
92535
  mark("prior-finality-fallback");
92486
- for (const name of deferred.splice(0)) await settlePrior(name);
92536
+ const answeredAt = (name) => store.readWal(name)?.answeredAtMs ?? 0;
92537
+ const shared2 = {};
92538
+ for (const name of deferred.splice(0).sort((a, b) => answeredAt(b) - answeredAt(a))) await settlePrior(name, shared2);
92487
92539
  held.clear();
92488
92540
  continue;
92489
92541
  }
@@ -92601,6 +92653,7 @@ var init_payResource = __esm({
92601
92653
  init_anchorWait();
92602
92654
  init_anchorClock();
92603
92655
  init_requestId();
92656
+ init_keepAlive();
92604
92657
  fail19 = (reason) => {
92605
92658
  throw new Error(`p03_resource_payment_${reason}`);
92606
92659
  };
@@ -96173,6 +96226,7 @@ async function createSellerAdapter({
96173
96226
  return { status: original.result.status, result: original.result, receipt: original.receipt };
96174
96227
  }
96175
96228
  let offer = original;
96229
+ let intakeChain;
96176
96230
  try {
96177
96231
  if (!offer.outboundJson) {
96178
96232
  const parsed = parseSolanaP03HttpPaymentPayload(payment.payload);
@@ -96187,6 +96241,7 @@ async function createSellerAdapter({
96187
96241
  const recoveredNote = await scanner.recoverMerchantNoteYielding({ parsed, authenticatedQuote: auth });
96188
96242
  mark("intake-note-recovered");
96189
96243
  const chain = await intakeRead;
96244
+ intakeChain = chain;
96190
96245
  mark("intake-anchor-read");
96191
96246
  const issuedAt = Number(chain.chainTimestamp);
96192
96247
  const expiresAt = Math.min(issuedAt + 300, Number(payment.accepted.extra.validBefore));
@@ -96227,11 +96282,18 @@ async function createSellerAdapter({
96227
96282
  await put(nonce, offer);
96228
96283
  mark("intake-durable");
96229
96284
  }
96285
+ const firstIntake = intakeChain !== void 0 && !offer.settleAttempted;
96286
+ if (firstIntake) {
96287
+ await readCurrentAnchor(intakeChain);
96288
+ offer = { ...offer, phase: "settlement_pending", settleAttempted: true };
96289
+ await put(nonce, offer);
96290
+ mark("first-intake-settle");
96291
+ }
96230
96292
  const preVerifyReadAt = Date.now();
96231
96293
  const preVerifyRead = offer.settleAttempted ? void 0 : readAnchor();
96232
96294
  preVerifyRead?.catch(() => void 0);
96233
- const claimed = await facilitator("claim", offer.outboundJson);
96234
- mark("claim");
96295
+ const claimed = firstIntake ? void 0 : await facilitator("claim", offer.outboundJson);
96296
+ if (!firstIntake) mark("claim");
96235
96297
  if (claimed) {
96236
96298
  offer = await persistReceipt(nonce, offer, claimed, mark);
96237
96299
  return { status: offer.result.status, result: offer.result, receipt: offer.receipt };
@@ -117728,40 +117790,14 @@ init_payResource();
117728
117790
  init_quote2();
117729
117791
  init_floatPay();
117730
117792
  init_walletHistory();
117731
- import { randomBytes as randomBytes12 } from "node:crypto";
117732
-
117733
- // wallet/src/fetch/keepAlive.mjs
117734
- var GLOBAL_DISPATCHER = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
117735
- var KEEP_ALIVE_MS = 2e4;
117736
- var shared;
117737
- function proxiedRun() {
117738
- const env = process.env;
117739
- return Boolean(env.SHINJUKU_WALLET_PROXIED || env.NODE_USE_ENV_PROXY || env.HTTPS_PROXY || env.HTTP_PROXY || env.https_proxy || env.http_proxy);
117740
- }
117741
- function keepAliveDispatcher() {
117742
- if (shared !== void 0) return shared;
117743
- try {
117744
- if (proxiedRun()) return void 0;
117745
- const global2 = globalThis[GLOBAL_DISPATCHER];
117746
- if (global2?.constructor?.name !== "Agent") return void 0;
117747
- shared = new global2.constructor({ keepAliveTimeout: KEEP_ALIVE_MS, keepAliveMaxTimeout: KEEP_ALIVE_MS });
117748
- return shared;
117749
- } catch {
117750
- return void 0;
117751
- }
117752
- }
117753
- function keepAliveInit(init = {}) {
117754
- const dispatcher = keepAliveDispatcher();
117755
- return dispatcher === void 0 ? init : { ...init, dispatcher };
117756
- }
117757
-
117758
- // wallet/src/fetch/payAndFetch.mjs
117793
+ init_keepAlive();
117759
117794
  init_phaseTiming();
117760
117795
  init_chain2();
117761
117796
  init_processLease();
117762
117797
  init_store();
117763
117798
  init_proxy();
117764
117799
  init_book();
117800
+ import { randomBytes as randomBytes12 } from "node:crypto";
117765
117801
 
117766
117802
  // wallet/src/caps/spendPolicy.mjs
117767
117803
  init_book();