@dvmkit/dvm-cli 0.7.0 → 0.8.1

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.
Files changed (27) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +35 -37
  3. package/dist/{chunk-2I5XAIQ4.js → chunk-4U43FVT4.js} +3 -3
  4. package/dist/{chunk-IERBEO4C.js → chunk-7ICHLPOY.js} +3 -3
  5. package/dist/{chunk-LIITTIEN.js → chunk-AGGWYE3D.js} +288 -71
  6. package/dist/{chunk-7674LYNL.js → chunk-AX6COXU3.js} +6 -6
  7. package/dist/{chunk-ZM5QFHEY.js → chunk-DSNUC4J7.js} +32 -5
  8. package/dist/{chunk-5QO3MGMH.js → chunk-EDK4X4F3.js} +4 -4
  9. package/dist/{chunk-3PV36227.js → chunk-HY65VFLL.js} +2 -2
  10. package/dist/{chunk-5VOAE2CL.js → chunk-JZPSF4C6.js} +2 -2
  11. package/dist/{chunk-C5XIOTRP.js → chunk-MULGWPBV.js} +2 -2
  12. package/dist/{chunk-EQXNDN5I.js → chunk-PKZUEXMJ.js} +2 -2
  13. package/dist/{chunk-6JP6ZBWW.js → chunk-QPT5KD7H.js} +29 -27
  14. package/dist/{chunk-7OA2XUM4.js → chunk-YJQNDNYK.js} +2 -2
  15. package/dist/{client-PGOH2ION.js → client-65B5WQPC.js} +6 -6
  16. package/dist/dvm.js +80 -28
  17. package/dist/{internal-VIAWW5ED.js → internal-BT3U2FFW.js} +5 -5
  18. package/dist/{lifecycle-VHGTNHHE.js → lifecycle-2LISVEWB.js} +6 -6
  19. package/dist/{payout-reporter-3UVWPGMO-WWZWXWCG.js → payout-reporter-HQSIIBFL-XHOVIA5Q.js} +2 -2
  20. package/dist/{pocket-refill-YY55GISB.js → pocket-refill-K24FKUXH.js} +10 -10
  21. package/dist/{revenue-reporter-E56J3NZK-NZ5H27ZI.js → revenue-reporter-X52GPZ5U-JQKBYUBQ.js} +2 -2
  22. package/dist/{tempo-lifecycle-NDBO3V3A.js → tempo-lifecycle-L5C55URR.js} +8 -8
  23. package/dist/{tempo-wallet-BAU7ASWF.js → tempo-wallet-XPXR3T3E.js} +7 -7
  24. package/dist/{wallet-RB2RPWIN.js → wallet-2XALZRFL.js} +7 -7
  25. package/dist/{x402-BN26TQZ6-4MWLNZGT.js → x402-Q4S36NHQ-KWEN7KSE.js} +2 -2
  26. package/package.json +18 -4
  27. package/skills/dvm/credit.md +2 -0
@@ -322,10 +322,10 @@ import {
322
322
  x402ResourceServer,
323
323
  x402SupportedNetworksHint,
324
324
  x402Version
325
- } from "./chunk-6JP6ZBWW.js";
325
+ } from "./chunk-QPT5KD7H.js";
326
326
  import {
327
327
  x402EarnedCeiling
328
- } from "./chunk-C5XIOTRP.js";
328
+ } from "./chunk-MULGWPBV.js";
329
329
  import {
330
330
  withSdkInitLock
331
331
  } from "./chunk-R2DSAZBO.js";
@@ -338,7 +338,7 @@ import {
338
338
  extendDiagnosticIdentityAuthority,
339
339
  projectDiagnosticFields,
340
340
  projectSpanRow
341
- } from "./chunk-ZM5QFHEY.js";
341
+ } from "./chunk-DSNUC4J7.js";
342
342
  import {
343
343
  privateKeyToAccount
344
344
  } from "./chunk-EVQERRCP.js";
@@ -1987,7 +1987,7 @@ var require_proper_lockfile = __commonJS({
1987
1987
  // node_modules/@dvmkit/sdk/dist/chunk-A262WVYX.js
1988
1988
  var CAPABILITY_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
1989
1989
 
1990
- // node_modules/@dvmkit/sdk/dist/chunk-BDHJVTWA.js
1990
+ // node_modules/@dvmkit/sdk/dist/chunk-55NKZQOC.js
1991
1991
  import { createHash } from "crypto";
1992
1992
 
1993
1993
  // node_modules/@noble/ciphers/utils.js
@@ -3930,7 +3930,7 @@ var getPublicKey2 = i2.getPublicKey;
3930
3930
  var finalizeEvent2 = i2.finalizeEvent;
3931
3931
  var verifyEvent2 = i2.verifyEvent;
3932
3932
 
3933
- // node_modules/@dvmkit/sdk/dist/chunk-BDHJVTWA.js
3933
+ // node_modules/@dvmkit/sdk/dist/chunk-55NKZQOC.js
3934
3934
  var X402_SELF_RELAY_KEY = "DVMKIT_X402_SELF_RELAY_KEY";
3935
3935
  var X402_RECEIVER_AUTHORIZER_KEY = "DVMKIT_X402_RECEIVER_AUTHORIZER_KEY";
3936
3936
  var X402_BATCH_SETTLEMENT_KEY = "DVMKIT_X402_BATCH_SETTLEMENT";
@@ -4969,7 +4969,7 @@ function canonicalRequestPath(pathOrUrl) {
4969
4969
  return parsed.pathname.startsWith("/") ? parsed.pathname : `/${parsed.pathname}`;
4970
4970
  }
4971
4971
 
4972
- // node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
4972
+ // node_modules/@dvmkit/sdk/dist/chunk-RTFBVXCN.js
4973
4973
  import { homedir } from "os";
4974
4974
  import { join as join3 } from "path";
4975
4975
  import { chmodSync, mkdirSync, statSync } from "fs";
@@ -10212,7 +10212,7 @@ zero
10212
10212
  zone
10213
10213
  zoo`.split("\n");
10214
10214
 
10215
- // node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
10215
+ // node_modules/@dvmkit/sdk/dist/chunk-RTFBVXCN.js
10216
10216
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
10217
10217
  import { existsSync as existsSync4, readFileSync as readFileSync4, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "fs";
10218
10218
 
@@ -20186,7 +20186,7 @@ function expand(hash4, prk, info, length = 32) {
20186
20186
  }
20187
20187
  var hkdf = (hash4, ikm, salt, info, length) => expand(hash4, extract(hash4, ikm, salt), info, length);
20188
20188
 
20189
- // node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
20189
+ // node_modules/@dvmkit/sdk/dist/chunk-RTFBVXCN.js
20190
20190
  import { randomBytes as randomBytes6 } from "crypto";
20191
20191
  import {
20192
20192
  chmodSync as chmodSync4,
@@ -21915,10 +21915,7 @@ function createMonotonicClock() {
21915
21915
  };
21916
21916
  }
21917
21917
 
21918
- // node_modules/@dvmkit/sdk/dist/chunk-SX4WCPW7.js
21919
- import { AsyncLocalStorage } from "async_hooks";
21920
- import { randomBytes as randomBytes7, randomUUID } from "crypto";
21921
- import { hostname } from "os";
21918
+ // node_modules/@dvmkit/sdk/dist/chunk-IFWUWHTW.js
21922
21919
  function createConsoleLogger(_jobId) {
21923
21920
  return {
21924
21921
  debug(_message, data) {
@@ -21950,10 +21947,15 @@ function createStdoutLogger(context) {
21950
21947
  };
21951
21948
  }
21952
21949
  function createNoopLogger() {
21953
- const noop22 = () => {
21950
+ const noop3 = () => {
21954
21951
  };
21955
- return { debug: noop22, info: noop22, warn: noop22, error: noop22 };
21952
+ return { debug: noop3, info: noop3, warn: noop3, error: noop3 };
21956
21953
  }
21954
+
21955
+ // node_modules/@dvmkit/sdk/dist/chunk-BL6LRWXD.js
21956
+ import { AsyncLocalStorage } from "async_hooks";
21957
+ import { randomBytes as randomBytes7, randomUUID } from "crypto";
21958
+ import { hostname } from "os";
21957
21959
  var storage = new AsyncLocalStorage();
21958
21960
  var defaultService = "unknown";
21959
21961
  function setDefaultService(service) {
@@ -22377,7 +22379,7 @@ var StepCache = class _StepCache {
22377
22379
  }
22378
22380
  };
22379
22381
 
22380
- // node_modules/@dvmkit/sdk/dist/chunk-LQQ6H4UB.js
22382
+ // node_modules/@dvmkit/sdk/dist/chunk-5CQKSLAU.js
22381
22383
  var InvalidCurrencyError = class extends Error {
22382
22384
  code = "invalid_currency";
22383
22385
  raw;
@@ -22829,7 +22831,7 @@ function resolveFxSourceFromEnv(env) {
22829
22831
  return raw2;
22830
22832
  }
22831
22833
 
22832
- // node_modules/@dvmkit/sdk/dist/chunk-6RYCZLCK.js
22834
+ // node_modules/@dvmkit/sdk/dist/chunk-6FEHRZO7.js
22833
22835
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
22834
22836
  var postgresRecovery = new AsyncLocalStorage2();
22835
22837
  function withPostgresRecoveryContext(context, operation) {
@@ -31261,7 +31263,7 @@ function parseStoreValue(value) {
31261
31263
  return parsed;
31262
31264
  }
31263
31265
 
31264
- // node_modules/@dvmkit/sdk/dist/chunk-GDCIHJAR.js
31266
+ // node_modules/@dvmkit/sdk/dist/chunk-P5WEZXJ2.js
31265
31267
  import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
31266
31268
  var PostgresTempoSessionStore = class {
31267
31269
  constructor(pool) {
@@ -31770,7 +31772,7 @@ function acceptanceVoucherAmount(acceptance, key, current, next) {
31770
31772
  return authorized !== void 0 && authorized >= acceptance.cumulativeAmount ? acceptance.cumulativeAmount : void 0;
31771
31773
  }
31772
31774
 
31773
- // node_modules/@dvmkit/sdk/dist/chunk-BQP3LU2O.js
31775
+ // node_modules/@dvmkit/sdk/dist/chunk-TFYY5APM.js
31774
31776
  import { createHash as createHash5 } from "crypto";
31775
31777
  var DEFAULT_TABLE_NAME = "mpp_tempo_charge_replays";
31776
31778
  var DEFAULT_RETENTION_MS = 60 * 60 * 1e3;
@@ -31999,7 +32001,7 @@ var PostgresTempoChargeStore = class {
31999
32001
  }
32000
32002
  };
32001
32003
 
32002
- // node_modules/@dvmkit/sdk/dist/chunk-KYCLHWKO.js
32004
+ // node_modules/@dvmkit/sdk/dist/chunk-GB5XPAA5.js
32003
32005
  import { createHash as createHash6, randomUUID as randomUUID3 } from "crypto";
32004
32006
  var TEMPO_SETTLEMENT_BALANCE_INTERVAL_MS = 5 * 60 * 1e3;
32005
32007
  function isTempoInsufficientFundsError(error) {
@@ -32111,6 +32113,9 @@ function wrapMppx(mppx) {
32111
32113
  };
32112
32114
  return Object.assign(server, { issueChallenge });
32113
32115
  }
32116
+ var TEMPO_CLOSE_LOG_WINDOW = 5000n;
32117
+ var TEMPO_CLOSE_LOG_SLACK_MS = 10 * 60 * 1e3;
32118
+ var TEMPO_CLOSE_LOG_MAX_WINDOWS = 500;
32114
32119
  var DEFAULT_TEMPO_SESSION_CHAIN_OPS = {
32115
32120
  getChannelStatesBatch: session_exports.Precompile.Chain.getChannelStatesBatch,
32116
32121
  settle: session_exports.Server.settle,
@@ -32120,7 +32125,32 @@ var DEFAULT_TEMPO_SESSION_CHAIN_OPS = {
32120
32125
  "ChannelClosed",
32121
32126
  channelId
32122
32127
  )
32123
- )
32128
+ ),
32129
+ findChannelClose: async (client, channelId, escrowContract, notBeforeMs) => {
32130
+ const { getBlock, getBlockNumber, getLogs } = await import("./actions-J7VGYDBF.js");
32131
+ const event = session_exports.Precompile.escrowAbi.find(
32132
+ (item) => item.type === "event" && item.name === "ChannelClosed"
32133
+ );
32134
+ if (!event || event.type !== "event") throw new Error("Tempo escrow ABI has no ChannelClosed event");
32135
+ let toBlock = await getBlockNumber(client);
32136
+ for (let window = 0; window < TEMPO_CLOSE_LOG_MAX_WINDOWS; window += 1) {
32137
+ const fromBlock = toBlock >= TEMPO_CLOSE_LOG_WINDOW ? toBlock - TEMPO_CLOSE_LOG_WINDOW + 1n : 0n;
32138
+ const logs = await getLogs(client, {
32139
+ address: escrowContract,
32140
+ event,
32141
+ args: { channelId },
32142
+ fromBlock,
32143
+ toBlock
32144
+ });
32145
+ const closed = logs.find((log) => log.transactionHash);
32146
+ if (closed?.transactionHash) return closed.transactionHash;
32147
+ if (fromBlock === 0n) return null;
32148
+ const start = await getBlock(client, { blockNumber: fromBlock });
32149
+ if (Number(start.timestamp) * 1e3 < notBeforeMs - TEMPO_CLOSE_LOG_SLACK_MS) return null;
32150
+ toBlock = fromBlock - 1n;
32151
+ }
32152
+ throw new Error(`Tempo close search for channel ${channelId} exceeded its block budget`);
32153
+ }
32124
32154
  };
32125
32155
  function attachTempoSessionRuntime(mppx, config2, chainOpOverrides = {}) {
32126
32156
  let creditLedger;
@@ -32141,6 +32171,102 @@ function attachTempoSessionRuntime(mppx, config2, chainOpOverrides = {}) {
32141
32171
  }
32142
32172
  if (store) {
32143
32173
  Object.assign(mppx, {
32174
+ assertTempoSessionCloseVoucher: async (voucher) => {
32175
+ const descriptor = readChannelDescriptor(voucher.descriptor);
32176
+ if (!descriptor) {
32177
+ throw new Errors_exports.VerificationFailedError({
32178
+ reason: "descriptor required for TIP-1034 session action"
32179
+ });
32180
+ }
32181
+ const details = isStateRecord(voucher.request.methodDetails) ? voucher.request.methodDetails : {};
32182
+ const stored = await store.get(voucher.channelId.toLowerCase());
32183
+ const state = readTempoSessionState(stored);
32184
+ const chainId = typeof details.chainId === "number" ? details.chainId : state?.chainId;
32185
+ const escrow = typeof details.escrowContract === "string" ? details.escrowContract : state?.escrowContract;
32186
+ if (chainId === void 0 || escrow === void 0) {
32187
+ throw new Errors_exports.VerificationFailedError({ reason: "invalid session request" });
32188
+ }
32189
+ const computed = session_exports.Precompile.Channel.computeId({
32190
+ ...descriptor,
32191
+ chainId,
32192
+ escrow
32193
+ });
32194
+ if (computed.toLowerCase() !== voucher.channelId.toLowerCase()) {
32195
+ throw new Errors_exports.VerificationFailedError({
32196
+ reason: "channel descriptor does not match channelId"
32197
+ });
32198
+ }
32199
+ if (!sameHex(descriptor.payee, voucher.request.recipient)) {
32200
+ throw new Errors_exports.VerificationFailedError({
32201
+ reason: "channel descriptor payee does not match server destination"
32202
+ });
32203
+ }
32204
+ if (!sameHex(descriptor.token, voucher.request.currency)) {
32205
+ throw new Errors_exports.VerificationFailedError({
32206
+ reason: "channel descriptor token does not match server token"
32207
+ });
32208
+ }
32209
+ if (!sameHex(descriptor.operator, details.operator ?? ZERO_ADDRESS)) {
32210
+ throw new Errors_exports.VerificationFailedError({
32211
+ reason: "channel descriptor operator does not match server operator"
32212
+ });
32213
+ }
32214
+ if (!state || !isStateRecord(stored)) {
32215
+ throw new Errors_exports.ChannelNotFoundError({ reason: "channel not found" });
32216
+ }
32217
+ if (stored.backend !== "precompile") {
32218
+ throw new Errors_exports.VerificationFailedError({
32219
+ reason: "channel is not precompile-backed"
32220
+ });
32221
+ }
32222
+ const storedDescriptor = readChannelDescriptor(stored.descriptor);
32223
+ if (!storedDescriptor || !sameDescriptor(descriptor, storedDescriptor)) {
32224
+ throw new Errors_exports.VerificationFailedError({
32225
+ reason: "credential descriptor does not match stored channel"
32226
+ });
32227
+ }
32228
+ const signer = stored.authorizedSigner;
32229
+ if (typeof signer !== "string" || !HEX_ADDRESS_RE2.test(signer)) {
32230
+ throw new Errors_exports.ChannelNotFoundError({ reason: "channel not found" });
32231
+ }
32232
+ if (state.finalized) {
32233
+ throw new Errors_exports.ChannelClosedError({ reason: "channel is already finalized" });
32234
+ }
32235
+ if (state.closeRequestedAt !== 0n) {
32236
+ throw new Errors_exports.ChannelClosedError({ reason: "channel has a pending close request" });
32237
+ }
32238
+ if (state.deposit === 0n && (voucher.cumulativeAmount !== 0n || state.spent !== 0n)) {
32239
+ throw new Errors_exports.ChannelClosedError({ reason: "channel deposit is zero (settled)" });
32240
+ }
32241
+ if (voucher.cumulativeAmount < state.spent) {
32242
+ throw new Errors_exports.VerificationFailedError({
32243
+ reason: `close voucher amount must be >= ${state.spent} (spent)`
32244
+ });
32245
+ }
32246
+ if (voucher.cumulativeAmount < state.settledOnChain) {
32247
+ throw new Errors_exports.VerificationFailedError({
32248
+ reason: `close voucher amount must be >= ${state.settledOnChain} (on-chain settled)`
32249
+ });
32250
+ }
32251
+ const valid = session_exports.Precompile.Voucher.verifyVoucher(
32252
+ escrow,
32253
+ chainId,
32254
+ {
32255
+ channelId: voucher.channelId,
32256
+ cumulativeAmount: voucher.cumulativeAmount,
32257
+ signature: voucher.signature
32258
+ },
32259
+ signer
32260
+ );
32261
+ if (!valid) {
32262
+ throw new Errors_exports.InvalidSignatureError({ reason: "invalid voucher signature" });
32263
+ }
32264
+ if (maxBigInt(state.spent, state.settledOnChain) > state.deposit) {
32265
+ throw new Errors_exports.AmountExceedsDepositError({
32266
+ reason: "close capture amount exceeds on-chain deposit"
32267
+ });
32268
+ }
32269
+ },
32144
32270
  getTempoSessionSpent: async (channelId) => {
32145
32271
  const state = readTempoSessionState(await store.get(channelId.toLowerCase()));
32146
32272
  if (!state) throw new Error(`Tempo session channel ${channelId} not found`);
@@ -32483,7 +32609,32 @@ function attachTempoSessionRuntime(mppx, config2, chainOpOverrides = {}) {
32483
32609
  finalized2 = chainState.deposit === 0n;
32484
32610
  }
32485
32611
  if (!finalized2) return null;
32486
- const recovered = await store.confirmClose(channelId, drainId, `channel:${channelId}`);
32612
+ const pending = await config2.hostedObligations?.pendingTempoClose(channelId, drainId);
32613
+ let reference = pending?.txHash ?? void 0;
32614
+ if (pending && !reference) {
32615
+ const client = await getClient({ chainId: current.chainId });
32616
+ const txHash = await chainOps.findChannelClose(
32617
+ client,
32618
+ current.channelId,
32619
+ current.escrowContract,
32620
+ pending.reservedAtMs
32621
+ );
32622
+ if (txHash) {
32623
+ await config2.hostedObligations.recordSubmitted(pending.id, txHash);
32624
+ reference = txHash;
32625
+ } else {
32626
+ loggers.tempo.warn("tempo_session_close_recovery_unmatched", {
32627
+ channel_id: current.channelId,
32628
+ drain_id: drainId,
32629
+ obligation_id: pending.id
32630
+ });
32631
+ }
32632
+ }
32633
+ const recovered = await store.confirmClose(
32634
+ channelId,
32635
+ drainId,
32636
+ reference ?? `channel:${channelId}`
32637
+ );
32487
32638
  return recovered.reference;
32488
32639
  };
32489
32640
  const getClose = store.getClose?.bind(store) ?? (() => Promise.resolve(null));
@@ -32527,6 +32678,27 @@ function maxBigInt(left, right) {
32527
32678
  function isStateRecord(value) {
32528
32679
  return !!value && typeof value === "object" && !Array.isArray(value);
32529
32680
  }
32681
+ var ZERO_ADDRESS = `0x${"00".repeat(20)}`;
32682
+ var DESCRIPTOR_ADDRESSES = ["payer", "payee", "operator", "token", "authorizedSigner"];
32683
+ var DESCRIPTOR_WORDS = ["salt", "expiringNonceHash"];
32684
+ function readChannelDescriptor(value) {
32685
+ if (!isStateRecord(value)) return void 0;
32686
+ for (const field of DESCRIPTOR_ADDRESSES) {
32687
+ if (typeof value[field] !== "string" || !HEX_ADDRESS_RE2.test(value[field])) return void 0;
32688
+ }
32689
+ for (const field of DESCRIPTOR_WORDS) {
32690
+ if (typeof value[field] !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value[field])) {
32691
+ return void 0;
32692
+ }
32693
+ }
32694
+ return value;
32695
+ }
32696
+ function sameHex(left, right) {
32697
+ return typeof left === "string" && typeof right === "string" && left.toLowerCase() === right.toLowerCase();
32698
+ }
32699
+ function sameDescriptor(left, right) {
32700
+ return DESCRIPTOR_ADDRESSES.every((field) => sameHex(left[field], right[field])) && DESCRIPTOR_WORDS.every((field) => sameHex(left[field], right[field]));
32701
+ }
32530
32702
  function tempoSettlementDue(args) {
32531
32703
  const { channel, chainSettled, forcedClose, intervalMs } = args;
32532
32704
  const settlementBoundary = Date.parse(channel.lastSettlementAt ?? channel.createdAt ?? "");
@@ -32546,7 +32718,7 @@ var _testing = {
32546
32718
  attachTempoSessionRuntime
32547
32719
  };
32548
32720
 
32549
- // node_modules/@dvmkit/sdk/dist/chunk-WP7UX6RF.js
32721
+ // node_modules/@dvmkit/sdk/dist/chunk-VYP6ADCS.js
32550
32722
  import { randomUUID as randomUUID4 } from "crypto";
32551
32723
  import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
32552
32724
  import { isDeepStrictEqual } from "util";
@@ -36485,7 +36657,7 @@ function expiryReleaseReport(dvmId, row) {
36485
36657
  };
36486
36658
  }
36487
36659
 
36488
- // node_modules/@dvmkit/sdk/dist/chunk-FOJKZ4E7.js
36660
+ // node_modules/@dvmkit/sdk/dist/chunk-EBCLWOKF.js
36489
36661
  import { randomUUID as randomUUID5 } from "crypto";
36490
36662
  var MemoryCreditLedger = class _MemoryCreditLedger {
36491
36663
  /**
@@ -37999,7 +38171,7 @@ function applyContentHoldMutation(job, history, mutation) {
37999
38171
  return result;
38000
38172
  }
38001
38173
 
38002
- // node_modules/@dvmkit/sdk/dist/chunk-KB7MEWBE.js
38174
+ // node_modules/@dvmkit/sdk/dist/chunk-QPXI7YPH.js
38003
38175
  import { createHash as createHash7 } from "crypto";
38004
38176
  var DEFAULT_BACKOFF_MS = [1e3, 4e3, 15e3, 3e4];
38005
38177
  var ListenChannel = class {
@@ -39483,7 +39655,7 @@ function isTerminalStatus(status) {
39483
39655
  return status === "completed" || status === "failed" || status === "cancelled";
39484
39656
  }
39485
39657
 
39486
- // node_modules/@dvmkit/sdk/dist/chunk-X5RY2G3C.js
39658
+ // node_modules/@dvmkit/sdk/dist/chunk-5K5E6ME6.js
39487
39659
  function humanizeZodError(err, opts) {
39488
39660
  return humanizeZodIssues(err.issues, opts);
39489
39661
  }
@@ -39636,7 +39808,7 @@ function createDefaultReplayStore() {
39636
39808
  }
39637
39809
  var SATURATION_WARN_INTERVAL_SECONDS = 60;
39638
39810
 
39639
- // node_modules/@dvmkit/sdk/dist/chunk-MYJOV4R4.js
39811
+ // node_modules/@dvmkit/sdk/dist/chunk-I6PHA54S.js
39640
39812
  function accumulateAskedTopUp(prior, ask) {
39641
39813
  const poisoned = (reason) => ({
39642
39814
  micro: UNCAPPABLE_ASK_TOTAL,
@@ -40289,7 +40461,7 @@ function isUniqueViolation2(err) {
40289
40461
  return typeof err === "object" && err !== null && err.code === "23505";
40290
40462
  }
40291
40463
 
40292
- // node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
40464
+ // node_modules/@dvmkit/sdk/dist/chunk-GSPV3UIM.js
40293
40465
  import { createHash as createHash8, randomUUID as randomUUID7 } from "crypto";
40294
40466
  import { createHash as createHash23 } from "crypto";
40295
40467
  import { createHash as createHash33 } from "crypto";
@@ -42422,7 +42594,7 @@ var x402Facilitator = class {
42422
42594
  };
42423
42595
 
42424
42596
  // node_modules/@x402/evm/dist/esm/batch-settlement/facilitator/index.mjs
42425
- var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
42597
+ var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
42426
42598
  function getEip3009DepositCollectorAddress() {
42427
42599
  return getAddress(ERC3009_DEPOSIT_COLLECTOR_ADDRESS);
42428
42600
  }
@@ -42460,7 +42632,7 @@ async function verifyEip3009DepositAuthorization(signer, payload, requirements,
42460
42632
  data: factoryCalldata,
42461
42633
  signature: innerSig
42462
42634
  } = parseErc6492Signature(auth.signature);
42463
- const hasDeploymentInfo = !!(factory && factoryCalldata && !isAddressEqual(factory, ZERO_ADDRESS));
42635
+ const hasDeploymentInfo = !!(factory && factoryCalldata && !isAddressEqual(factory, ZERO_ADDRESS2));
42464
42636
  if (hasDeploymentInfo) {
42465
42637
  let code;
42466
42638
  try {
@@ -42715,7 +42887,7 @@ function validateBatchEip2612Permit(info, payer, tokenAddress, depositAmount) {
42715
42887
  }
42716
42888
  return { isValid: true };
42717
42889
  }
42718
- var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
42890
+ var ZERO_ADDRESS22 = "0x0000000000000000000000000000000000000000";
42719
42891
  async function verifyDeposit(signer, payment, payload, requirements, context, allowedFactories = []) {
42720
42892
  const payer = payload.channelConfig.payer;
42721
42893
  const chainId = getEvmChainId(requirements.network);
@@ -43088,7 +43260,7 @@ async function deployErc3009CounterfactualIfNeeded(signer, payload, requirements
43088
43260
  return null;
43089
43261
  }
43090
43262
  const { address: factory, data: factoryCalldata } = parseErc6492Signature(auth.signature);
43091
- const hasDeploymentInfo = !!(factory && factoryCalldata && !isAddressEqual(factory, ZERO_ADDRESS2));
43263
+ const hasDeploymentInfo = !!(factory && factoryCalldata && !isAddressEqual(factory, ZERO_ADDRESS22));
43092
43264
  if (!hasDeploymentInfo) {
43093
43265
  return null;
43094
43266
  }
@@ -43747,7 +43919,7 @@ var BatchSettlementEvmScheme3 = class {
43747
43919
  }
43748
43920
  };
43749
43921
 
43750
- // node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
43922
+ // node_modules/@dvmkit/sdk/dist/chunk-GSPV3UIM.js
43751
43923
  import { createHash as createHash42, randomBytes as randomBytes8, randomUUID as randomUUID22 } from "crypto";
43752
43924
  import { randomBytes as randomBytes22 } from "crypto";
43753
43925
 
@@ -46118,7 +46290,7 @@ function date3(params) {
46118
46290
  // node_modules/zod/v4/classic/external.js
46119
46291
  config(en_default());
46120
46292
 
46121
- // node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
46293
+ // node_modules/@dvmkit/sdk/dist/chunk-GSPV3UIM.js
46122
46294
  import { createHash as createHash52 } from "crypto";
46123
46295
  import { createHmac as createHmac2, randomUUID as randomUUID42, timingSafeEqual as timingSafeEqual2 } from "crypto";
46124
46296
  import { createHash as createHash62, randomUUID as randomUUID32 } from "crypto";
@@ -48510,7 +48682,7 @@ var streamSSE = (c, cb, onError) => {
48510
48682
  return c.newResponse(stream2.responseReadable);
48511
48683
  };
48512
48684
 
48513
- // node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
48685
+ // node_modules/@dvmkit/sdk/dist/chunk-GSPV3UIM.js
48514
48686
  import { createHash as createHash9 } from "crypto";
48515
48687
  async function initLockPubkeyTable(db) {
48516
48688
  await withSdkInitLock(db, () => createLockPubkeyTable(db));
@@ -51322,6 +51494,10 @@ function decodeBatchPayment(header) {
51322
51494
  if (!isBatchSettlementDepositPayload(parsed.payload) && !isBatchSettlementVoucherPayload(parsed.payload) && !isBatchSettlementRefundPayload(parsed.payload)) {
51323
51495
  throw new Error("invalid batch-settlement payload");
51324
51496
  }
51497
+ const voucher = parsed.payload.voucher;
51498
+ if (typeof voucher.channelId !== "string" || typeof voucher.maxClaimableAmount !== "string" || typeof voucher.signature !== "string") {
51499
+ throw new Error("invalid batch-settlement voucher");
51500
+ }
51325
51501
  return parsed;
51326
51502
  }
51327
51503
  function batchVoucher(payload) {
@@ -52056,7 +52232,7 @@ async function verifyUpfrontPaymentInScope(opts) {
52056
52232
  x402Requirements
52057
52233
  });
52058
52234
  }
52059
- const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
52235
+ const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-Q4S36NHQ-KWEN7KSE.js");
52060
52236
  const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
52061
52237
  x402Payment,
52062
52238
  x402Config,
@@ -52219,6 +52395,30 @@ async function verifyUpfrontPaymentInScope(opts) {
52219
52395
  }
52220
52396
  const expectedAmount = opts.priceFiat?.currency === "usd" ? fiatMicroToMethodAmount(opts.priceFiat.amountMicro, cred.challenge.method) : msatsToMethodAmount(requiredMsats, cred.challenge.method, rate);
52221
52397
  const sessionBasis = mppSessionBasis(cred);
52398
+ const replayRealm = mpp.realm ?? cred.challenge.realm;
52399
+ if (consumedCredentialStore && await withPaymentStage("replay_store", () => consumedCredentialStore.has(replayRealm, cred.challenge.id))) {
52400
+ const mppChallenges = await issueUpfrontChallenges(
52401
+ mpp,
52402
+ requiredMsats,
52403
+ resourcePath ?? "/v1/job",
52404
+ rate,
52405
+ sessionIssuable,
52406
+ opts.fundOnly?.allowOneShotStablecoin,
52407
+ opts.priceFiat
52408
+ );
52409
+ return {
52410
+ paidMsats: 0,
52411
+ receivedProofs: [],
52412
+ error: {
52413
+ body: paymentErrorBody("payment_invalid", {
52414
+ message: "MPP credential already used"
52415
+ }),
52416
+ status: 402,
52417
+ mppChallenges,
52418
+ ...x402Requirements && { x402Requirements }
52419
+ }
52420
+ };
52421
+ }
52222
52422
  let tempoReceipt;
52223
52423
  const broadcast = async () => {
52224
52424
  const receipt = await loggers.tempo.span(
@@ -52336,35 +52536,12 @@ async function verifyUpfrontPaymentInScope(opts) {
52336
52536
  }
52337
52537
  };
52338
52538
  }
52339
- if (consumedCredentialStore) {
52340
- const realm = mpp.realm;
52341
- const id = cred.challenge.id;
52342
- if (await withPaymentStage("replay_store", () => consumedCredentialStore.has(realm, id))) {
52343
- const mppChallenges = await issueUpfrontChallenges(
52344
- mpp,
52345
- requiredMsats,
52346
- resourcePath ?? "/v1/job",
52347
- rate,
52348
- sessionIssuable,
52349
- opts.fundOnly?.allowOneShotStablecoin,
52350
- opts.priceFiat
52351
- );
52352
- return {
52353
- paidMsats: 0,
52354
- receivedProofs: [],
52355
- error: {
52356
- body: paymentErrorBody("payment_invalid", {
52357
- message: "MPP credential already used"
52358
- }),
52359
- status: 402,
52360
- mppChallenges,
52361
- ...x402Requirements && { x402Requirements }
52362
- }
52363
- };
52364
- }
52365
- if (!sessionBasis) {
52366
- await withPaymentStage("replay_store", () => consumedCredentialStore.mark(realm, id, CONSUMED_CREDENTIAL_TTL_MS / 1e3));
52367
- }
52539
+ if (consumedCredentialStore && !sessionBasis) {
52540
+ await withPaymentStage("replay_store", () => consumedCredentialStore.mark(
52541
+ replayRealm,
52542
+ cred.challenge.id,
52543
+ CONSUMED_CREDENTIAL_TTL_MS / 1e3
52544
+ ));
52368
52545
  }
52369
52546
  if (ledgerCtx) {
52370
52547
  try {
@@ -52387,10 +52564,18 @@ async function verifyUpfrontPaymentInScope(opts) {
52387
52564
  }
52388
52565
  if (sessionBasis && consumedCredentialStore) {
52389
52566
  await withPaymentStage("replay_store", () => consumedCredentialStore.mark(
52390
- mpp.realm,
52567
+ replayRealm,
52391
52568
  cred.challenge.id,
52392
52569
  CONSUMED_CREDENTIAL_TTL_MS / 1e3
52393
- ));
52570
+ )).catch((error) => {
52571
+ diagnosticConsole.warn({
52572
+ level: "warn",
52573
+ event: "tempo_replay_mark_failed",
52574
+ phase: "upfront",
52575
+ rail: "tempo",
52576
+ ...paymentFailureFields(error)
52577
+ });
52578
+ });
52394
52579
  }
52395
52580
  if (credited) {
52396
52581
  await mpp.completeHostedTempoCharge?.(cred.challenge.id).catch((error) => {
@@ -52599,6 +52784,22 @@ async function verifyTempoSessionManagementCredential(args) {
52599
52784
  throw new Error("Hosted Tempo close requires non-mutating credential validation");
52600
52785
  }
52601
52786
  await args.mpp.validateCredential(credential, verifyOptions);
52787
+ if (args.action === "close") {
52788
+ if (!args.mpp.assertTempoSessionCloseVoucher) {
52789
+ throw new Error("Hosted Tempo close requires stored-channel voucher validation");
52790
+ }
52791
+ const { cumulativeAmount, signature } = credential.payload;
52792
+ if (typeof cumulativeAmount !== "string" || typeof signature !== "string") {
52793
+ throw new Error("Expected a Tempo session close voucher");
52794
+ }
52795
+ await args.mpp.assertTempoSessionCloseVoucher({
52796
+ channelId: payload.channelId,
52797
+ cumulativeAmount: BigInt(cumulativeAmount),
52798
+ signature,
52799
+ descriptor: credential.payload.descriptor,
52800
+ request: credential.challenge.request
52801
+ });
52802
+ }
52602
52803
  }
52603
52804
  await args.onBound?.();
52604
52805
  const receipt = await args.mpp.broadcastCredential(credential, verifyOptions);
@@ -53044,7 +53245,7 @@ async function verifyIncomingPaymentInScope(body, opts, snapshot) {
53044
53245
  snapshot
53045
53246
  });
53046
53247
  }
53047
- const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
53248
+ const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-Q4S36NHQ-KWEN7KSE.js");
53048
53249
  const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
53049
53250
  body.content.x402_payment,
53050
53251
  opts.x402Config,
@@ -53475,7 +53676,7 @@ async function processIncomingPaymentInScope(job, body, opts) {
53475
53676
  try {
53476
53677
  const requiredMsats = job.pendingPaymentMsats ?? 0;
53477
53678
  const requiredUsdcMicro = job.pendingX402AmountUsdcMicro !== void 0 ? BigInt(job.pendingX402AmountUsdcMicro) : BigInt(msatsToUsdc(requiredMsats, rate));
53478
- const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
53679
+ const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-Q4S36NHQ-KWEN7KSE.js");
53479
53680
  const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
53480
53681
  body.content.x402_payment,
53481
53682
  opts.x402Config,
@@ -58197,6 +58398,18 @@ var HostedSettlementReportObligations = class {
58197
58398
  );
58198
58399
  return result.rows[0];
58199
58400
  }
58401
+ /** The original close obligation reserved for this drain, while its report is outstanding. */
58402
+ async pendingTempoClose(channelId, drainId) {
58403
+ const result = await this.pool.query(
58404
+ `SELECT id,tx_hash,created_at_ms FROM sdk_hosted_settlement_report_obligations
58405
+ WHERE dvm_id=$1 AND scope=$2 AND rail='tempo' AND operation='close' AND channel_id=$3
58406
+ AND original->>'drainId'=$4 AND state NOT IN ('delivered','no_report')
58407
+ ORDER BY created_at_ms DESC LIMIT 1`,
58408
+ [this.dvmId, this.scope, channelId.toLowerCase(), drainId]
58409
+ );
58410
+ const row = result.rows[0];
58411
+ return row && { id: row.id, txHash: row.tx_hash, reservedAtMs: Number(row.created_at_ms) };
58412
+ }
58200
58413
  async submittedIds(rail, operation, txHash, batchId) {
58201
58414
  if (!hex2(txHash, 32)) throw new Error("Hosted effect has no exact transaction hash");
58202
58415
  const result = await this.pool.query(
@@ -58336,6 +58549,10 @@ var HostedSettlementReportObligations = class {
58336
58549
  }));
58337
58550
  }
58338
58551
  async recoverOriginalX402Refunds() {
58552
+ const table = await this.pool.query(
58553
+ "SELECT to_regclass('x402_batch_settlements') IS NOT NULL AS present"
58554
+ );
58555
+ if (!table.rows[0]?.present) return [];
58339
58556
  const rows2 = await this.pool.query(
58340
58557
  `SELECT obligation.id,settlement.settle_response AS response
58341
58558
  FROM sdk_hosted_settlement_report_obligations obligation
@@ -67446,7 +67663,7 @@ async function createDVMServer(descriptor, opts) {
67446
67663
  }
67447
67664
  }
67448
67665
  if (!opts.onJobCompleted && platformToken && platformUrl && dvmId && opts.db) {
67449
- const { RevenueReporter: RevenueReporter2 } = await import("./revenue-reporter-E56J3NZK-NZ5H27ZI.js");
67666
+ const { RevenueReporter: RevenueReporter2 } = await import("./revenue-reporter-X52GPZ5U-JQKBYUBQ.js");
67450
67667
  const reporter = new RevenueReporter2(
67451
67668
  opts.db,
67452
67669
  platformUrl,
@@ -67456,7 +67673,7 @@ async function createDVMServer(descriptor, opts) {
67456
67673
  revenueReporter = reporter;
67457
67674
  await reporter.init();
67458
67675
  reporter.startRetryLoop();
67459
- const { MemoryX402BatchStore, PayoutReporter: PayoutReporter2 } = await import("./payout-reporter-3UVWPGMO-WWZWXWCG.js");
67676
+ const { MemoryX402BatchStore, PayoutReporter: PayoutReporter2 } = await import("./payout-reporter-HQSIIBFL-XHOVIA5Q.js");
67460
67677
  payoutReporter = new PayoutReporter2({
67461
67678
  dvmId,
67462
67679
  db: opts.db,
@@ -68814,7 +69031,7 @@ var DVMServer = class {
68814
69031
  // sees only the shortened list cannot tell a DVM that never did
68815
69032
  // sessions from one whose observer is down for a minute.
68816
69033
  ...withheld.length && { withheld },
68817
- realm: this.opts.mpp.realm,
69034
+ ...this.opts.mpp.realm && { realm: this.opts.mpp.realm },
68818
69035
  ...this.opts.mpp.tempoConfiguration && {
68819
69036
  recipient: this.opts.mpp.tempoConfiguration.recipient,
68820
69037
  payment_token: this.opts.mpp.tempoConfiguration.paymentToken,