@dvmkit/sdk 0.7.0-rc.1 → 0.7.0-rc.2

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 (70) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-S3OY533W.js → chunk-26W6GPCD.js} +48 -6
  3. package/dist/{chunk-FWGWLPXF.js → chunk-2OM2QPBE.js} +2 -2
  4. package/dist/{chunk-CXCQLOOK.js → chunk-62FI3NJF.js} +42 -107
  5. package/dist/{chunk-VHNPVGSA.js → chunk-6STC5TCP.js} +3 -3
  6. package/dist/{chunk-N5RZ5HVB.js → chunk-72V5DTEC.js} +2 -2
  7. package/dist/chunk-A262WVYX.js +6 -0
  8. package/dist/{chunk-GY66THYI.js → chunk-A6CXKAQV.js} +183 -88
  9. package/dist/{chunk-QR2EF2NI.js → chunk-AQ7OX5NX.js} +2 -2
  10. package/dist/{chunk-BYCEKO65.js → chunk-CLIAFTUR.js} +102 -13
  11. package/dist/{chunk-GAOAYHZA.js → chunk-DNG4KGSC.js} +3 -3
  12. package/dist/{chunk-Z4ZT5LNT.js → chunk-GSLS4464.js} +3 -3
  13. package/dist/{chunk-RA2WIX7G.js → chunk-H5FVVEEN.js} +18 -7
  14. package/dist/{chunk-IXR5RFK7.js → chunk-HCE4MPZ5.js} +1 -1
  15. package/dist/{chunk-OML32F6I.js → chunk-I555L2WK.js} +1 -1
  16. package/dist/{chunk-EQLA4FFY.js → chunk-IIZQNDQU.js} +3 -3
  17. package/dist/{chunk-FUJ36YDV.js → chunk-KXWROQGK.js} +24 -1
  18. package/dist/{chunk-ETXDTUJO.js → chunk-LAKP6FUI.js} +55 -0
  19. package/dist/{chunk-X7EZ5CLI.js → chunk-MON76YBJ.js} +3 -3
  20. package/dist/chunk-OFSOLHRX.js +120 -0
  21. package/dist/{chunk-IV6Q7NRW.js → chunk-RAGX6VG7.js} +2 -2
  22. package/dist/{chunk-KA6VN5FK.js → chunk-RXPHMS4C.js} +3 -3
  23. package/dist/{chunk-6XF3RVVX.js → chunk-SPYEJXI7.js} +5 -5
  24. package/dist/{chunk-P6QON7ER.js → chunk-TRNMTTPX.js} +1 -1
  25. package/dist/{chunk-RCM3P2HE.js → chunk-UKD3R2KU.js} +55 -4
  26. package/dist/chunk-USL7ZEXN.js +17 -0
  27. package/dist/{chunk-KMED3H3A.js → chunk-VB5OLOZH.js} +395 -231
  28. package/dist/{content-retention-DHyLdA6b.d.ts → content-retention-CbnouEnh.d.ts} +1 -1
  29. package/dist/{credit-ledger-MCUXYKSJ.js → credit-ledger-7Z7LOCTN.js} +4 -4
  30. package/dist/{credit-menu-DjnkeEUU.d.ts → credit-menu-BO8yJppy.d.ts} +4 -4
  31. package/dist/{fx-zMWFzfrU.d.ts → fx-DSOZQ2z7.d.ts} +1 -1
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +236 -16
  34. package/dist/internal/caller.d.ts +4968 -8286
  35. package/dist/internal/caller.js +4291 -8084
  36. package/dist/internal/index.js +1 -1
  37. package/dist/internal/server.d.ts +7 -7
  38. package/dist/internal/server.js +27 -30
  39. package/dist/{job-store-DdLXBpol.d.ts → job-store-BJRlmq2Q.d.ts} +1 -1
  40. package/dist/{lightning-backend-Bw-qtAbt.d.ts → lightning-backend-f16-fsYK.d.ts} +2 -2
  41. package/dist/{memory-credit-ledger-SBSMGMDX.js → memory-credit-ledger-3WOS74UH.js} +5 -5
  42. package/dist/{mpp-setup-RF5FXGGV.js → mpp-setup-XB4KATMU.js} +2 -2
  43. package/dist/{payout-reporter-3Y2U55ZX.js → payout-reporter-WT7XYW42.js} +2 -2
  44. package/dist/{postgres-consumed-credential-store-BUVCAPLS.js → postgres-consumed-credential-store-W7UP33AH.js} +3 -3
  45. package/dist/{postgres-job-store-VHLQBJZC.js → postgres-job-store-3KGUGFRD.js} +2 -2
  46. package/dist/{postgres-replay-store-ARZSQ45X.js → postgres-replay-store-CVNJJOQG.js} +2 -2
  47. package/dist/{pricing-XT2IAPNE.js → pricing-QAVZUTZR.js} +12 -12
  48. package/dist/{revenue-reporter-MAERPYGK.js → revenue-reporter-7UR3W2SD.js} +2 -2
  49. package/dist/server/index.d.ts +10 -10
  50. package/dist/server/index.js +44 -48
  51. package/dist/{step-cache-2MkvenJn.d.ts → step-cache-CJFiZU3n.d.ts} +1 -1
  52. package/dist/{tempo-charge-store-Q3D7KYMH.js → tempo-charge-store-GA6CED6O.js} +2 -2
  53. package/dist/{tempo-session-store-ZRNCOX7P.js → tempo-session-store-WZWQRITB.js} +3 -3
  54. package/dist/testing/index.d.ts +3 -3
  55. package/dist/testing/index.js +6 -7
  56. package/dist/{usd-DI3d3gTK.d.ts → usd-DmHHg0_4.d.ts} +1 -1
  57. package/dist/{x402-FT4S4JS4.js → x402-ZU4GML7Z.js} +8 -27
  58. package/package.json +1 -1
  59. package/dist/chunk-66HGCPBU.js +0 -25
  60. package/dist/chunk-AT6V3SY7.js +0 -102
  61. package/dist/chunk-EZXAJ6EI.js +0 -1082
  62. package/dist/chunk-HCLVYZUZ.js +0 -244
  63. package/dist/chunk-JEVLNAO3.js +0 -1668
  64. package/dist/chunk-NFMOPYBA.js +0 -357
  65. package/dist/chunk-O2OTZ5GP.js +0 -1869
  66. package/dist/chunk-OFVV37XC.js +0 -57
  67. package/dist/chunk-SZVXOQ75.js +0 -211
  68. package/dist/chunk-WBOKPC37.js +0 -795
  69. package/dist/tempo-lifecycle-GJ77YKVY.js +0 -15
  70. package/dist/tempo-wallet-X2GGAZ6X.js +0 -40
@@ -1,20 +1,28 @@
1
1
  import {
2
- MemoryProcessedPaymentStore,
3
- PostgresProcessedPaymentStore,
4
- ProcessedPaymentReplayError
5
- } from "./chunk-XRLKGCAW.js";
2
+ TEMPO_MODERATO_CHAIN_ID,
3
+ TEMPO_MODERATO_RPC,
4
+ advertisedMethods,
5
+ challengeMeta,
6
+ installHostedTempoChargeGuard,
7
+ installHostedTempoCloseGuard,
8
+ isTempoInsufficientFundsError,
9
+ resolveTempoNetwork
10
+ } from "./chunk-HCE4MPZ5.js";
6
11
  import {
7
12
  createX402FacilitatorAuthHeaders,
8
13
  createX402FacilitatorClient,
14
+ paymentFailureStage,
9
15
  settleWithFacilitator,
10
- verifyWithFacilitator
11
- } from "./chunk-S3OY533W.js";
16
+ verifyWithFacilitator,
17
+ withPaymentDiagnostics,
18
+ withPaymentStage
19
+ } from "./chunk-26W6GPCD.js";
12
20
  import {
13
21
  MemoryCreditLedger
14
- } from "./chunk-OML32F6I.js";
22
+ } from "./chunk-I555L2WK.js";
15
23
  import {
16
24
  PostgresJobStore
17
- } from "./chunk-EQLA4FFY.js";
25
+ } from "./chunk-IIZQNDQU.js";
18
26
  import {
19
27
  parseStoreValue
20
28
  } from "./chunk-YG7G4DPZ.js";
@@ -25,7 +33,7 @@ import {
25
33
  humanizeZodIssues,
26
34
  signedRequestInput,
27
35
  zodIssuesOf
28
- } from "./chunk-N5RZ5HVB.js";
36
+ } from "./chunk-72V5DTEC.js";
29
37
  import {
30
38
  MemoryJobStore,
31
39
  UNCAPPABLE_ASK_TOTAL,
@@ -34,7 +42,7 @@ import {
34
42
  isJobRetentionStore,
35
43
  isReceiptIssuingStore,
36
44
  isStreamableJobStore
37
- } from "./chunk-IV6Q7NRW.js";
45
+ } from "./chunk-RAGX6VG7.js";
38
46
  import {
39
47
  ContentHoldError,
40
48
  JobCancelledError,
@@ -53,34 +61,26 @@ import {
53
61
  ADMIN_AUTH_CLOCK_SKEW_SECONDS,
54
62
  ADMIN_AUTH_NONCE_TTL_SECONDS,
55
63
  ADMIN_STATE_UNAVAILABLE,
64
+ IMPLICIT_CREDIT_TTL_MS,
56
65
  TEMPO_SESSION_UPDATED_REASON,
57
66
  X402_BATCH_CHANNEL_ABI,
58
67
  attestedDvmIdentity,
59
68
  buildAdminChallenge,
60
69
  checkMintHealth,
70
+ computeResultHash,
61
71
  createMonotonicClock,
72
+ formatStaleness,
62
73
  getWallet,
63
74
  isPublicRequestId,
64
- isTestMintUrl,
65
75
  isX402SettlementReconciliationReason,
66
- normaliseMintUrl,
67
76
  parseTraceparent,
68
77
  receiptPubkeyFromSecret,
69
- toLockPubkey,
70
- verifyCashuToken,
71
- verifyChallenge
72
- } from "./chunk-KMED3H3A.js";
73
- import {
74
- IMPLICIT_CREDIT_TTL_MS,
75
- computeResultHash,
76
- formatStaleness,
77
- msatsToUsd,
78
- msatsToUsdc,
79
78
  signDrainReceipt,
80
79
  signFundingReceipt,
81
80
  signReceipt,
82
- usdcToMsats
83
- } from "./chunk-NFMOPYBA.js";
81
+ toLockPubkey,
82
+ verifyChallenge
83
+ } from "./chunk-VB5OLOZH.js";
84
84
  import {
85
85
  X402_BATCH_SETTLEMENT_SCHEME,
86
86
  X402_DEFAULT_FACILITATOR,
@@ -93,25 +93,26 @@ import {
93
93
  encodePaymentRequiredHeader,
94
94
  encodeSettleResponseHeader,
95
95
  exactEvmAuthorization,
96
+ msatsToUsd,
97
+ msatsToUsdc,
96
98
  paymentRequiredV2FromV1,
97
99
  resolveRpcOverride,
100
+ usdcToMsats,
98
101
  x402NetworkToCaip2
99
- } from "./chunk-CXCQLOOK.js";
102
+ } from "./chunk-62FI3NJF.js";
100
103
  import {
101
104
  RAIL_REFUNDABLE,
102
105
  canonicalRequestPath,
106
+ canonicalize,
103
107
  isZodSchema
104
- } from "./chunk-RCM3P2HE.js";
105
- import {
106
- canonicalize
107
- } from "./chunk-OFVV37XC.js";
108
+ } from "./chunk-UKD3R2KU.js";
108
109
  import {
109
110
  createConsoleLogger,
110
111
  loggers,
111
112
  pinDimension,
112
113
  withSpan,
113
114
  withTraceContext
114
- } from "./chunk-QR2EF2NI.js";
115
+ } from "./chunk-AQ7OX5NX.js";
115
116
  import {
116
117
  StepCache
117
118
  } from "./chunk-BQJIFRAZ.js";
@@ -120,16 +121,14 @@ import {
120
121
  InvalidCurrencyError,
121
122
  UnsupportedCurrencyError,
122
123
  createFxFetcher,
123
- fxRateFor,
124
- resolveFxSourceFromEnv,
125
- validateCurrency
126
- } from "./chunk-BYCEKO65.js";
127
- import {
128
124
  fiatToSatsCeil,
125
+ fxRateFor,
129
126
  parseUsdPrice,
127
+ resolveFxSourceFromEnv,
130
128
  roundUsd,
131
- satsToFiat
132
- } from "./chunk-AT6V3SY7.js";
129
+ satsToFiat,
130
+ validateCurrency
131
+ } from "./chunk-CLIAFTUR.js";
133
132
  import {
134
133
  CreditLedger,
135
134
  CreditLedgerError,
@@ -145,30 +144,26 @@ import {
145
144
  isNonChannelBitcoinRail,
146
145
  netOwedSats,
147
146
  x402SettlementPending
148
- } from "./chunk-6XF3RVVX.js";
149
- import {
150
- withSdkInitLock
151
- } from "./chunk-COYKJRMM.js";
147
+ } from "./chunk-SPYEJXI7.js";
152
148
  import {
153
149
  withPostgresRecoveryContext
154
- } from "./chunk-P6QON7ER.js";
150
+ } from "./chunk-TRNMTTPX.js";
155
151
  import {
152
+ DvmError,
156
153
  x402NetworkByCaip2
157
154
  } from "./chunk-BPYMEMQX.js";
158
- import {
159
- TEMPO_MODERATO_CHAIN_ID,
160
- TEMPO_MODERATO_RPC,
161
- advertisedMethods,
162
- challengeMeta,
163
- installHostedTempoChargeGuard,
164
- installHostedTempoCloseGuard,
165
- isTempoInsufficientFundsError,
166
- resolveTempoNetwork
167
- } from "./chunk-IXR5RFK7.js";
168
155
  import {
169
156
  createDiagnosticCapabilityAuthority,
170
157
  diagnosticConsole
171
- } from "./chunk-ETXDTUJO.js";
158
+ } from "./chunk-LAKP6FUI.js";
159
+ import {
160
+ MemoryProcessedPaymentStore,
161
+ PostgresProcessedPaymentStore,
162
+ ProcessedPaymentReplayError
163
+ } from "./chunk-XRLKGCAW.js";
164
+ import {
165
+ withSdkInitLock
166
+ } from "./chunk-COYKJRMM.js";
172
167
 
173
168
  // src/sdk/server/lock-pubkey-store.ts
174
169
  async function initLockPubkeyTable(db) {
@@ -3161,10 +3156,66 @@ function isRecord(value) {
3161
3156
  return !!value && typeof value === "object" && !Array.isArray(value);
3162
3157
  }
3163
3158
 
3159
+ // src/sdk/server/payment-diagnostics.ts
3160
+ import { Errors } from "mppx";
3161
+ function paymentFailureFields(error) {
3162
+ let category = "unknown";
3163
+ try {
3164
+ if (error instanceof ProcessedPaymentReplayError) category = "replay_detected";
3165
+ else if (error instanceof CreditLedgerError) category = "ledger_refused";
3166
+ else if (error instanceof Errors.InvalidChallengeError) category = "invalid_challenge";
3167
+ else if (error instanceof Errors.MalformedCredentialError || error instanceof Errors.InvalidPayloadError) category = "malformed_credential";
3168
+ else if (error instanceof Errors.PaymentExpiredError) category = "payment_expired";
3169
+ else if (error instanceof Errors.VerificationFailedError) category = "verification_failed";
3170
+ else if (error instanceof Errors.PaymentInsufficientError || error instanceof Errors.InsufficientBalanceError) category = "insufficient_funds";
3171
+ else if (error instanceof Errors.InvalidSignatureError) category = "invalid_signature";
3172
+ else if (error instanceof Errors.PaymentMethodUnsupportedError) category = "unsupported_method";
3173
+ } catch {
3174
+ }
3175
+ return { failure_category: category, failure_stage: paymentFailureStage(error) };
3176
+ }
3177
+
3164
3178
  // src/sdk/server/payment.ts
3165
3179
  import { randomBytes, randomUUID as randomUUID2 } from "crypto";
3166
3180
  import { Challenge } from "mppx";
3167
3181
 
3182
+ // src/lib/cashu/verify.ts
3183
+ import { getTokenMetadata } from "@cashu/cashu-ts";
3184
+ function verifyCashuToken(token, acceptedMints) {
3185
+ let mint, unit, totalMsats;
3186
+ try {
3187
+ const meta = getTokenMetadata(token);
3188
+ mint = meta.mint;
3189
+ unit = meta.unit;
3190
+ totalMsats = meta.amount.toNumber() * 1e3;
3191
+ } catch {
3192
+ throw new DvmError(
3193
+ "cashu_invalid_token",
3194
+ "The Cashu token could not be decoded.",
3195
+ "Ensure the token is a valid cashuA... or cashuB... string."
3196
+ );
3197
+ }
3198
+ const normalised = acceptedMints.map(normaliseMintUrl);
3199
+ if (!normalised.includes(normaliseMintUrl(mint))) {
3200
+ throw new DvmError(
3201
+ "cashu_mint_not_accepted",
3202
+ `Mint ${mint} is not accepted by this provider.`,
3203
+ `Accepted mints: ${acceptedMints.join(", ")}`
3204
+ );
3205
+ }
3206
+ return { mint, totalMsats, unit };
3207
+ }
3208
+ function normaliseMintUrl(url) {
3209
+ try {
3210
+ const u = new URL(url);
3211
+ u.hostname = u.hostname.toLowerCase();
3212
+ u.pathname = u.pathname.replace(/\/+/g, "/").replace(/\/+$/, "") || "/";
3213
+ return u.toString().replace(/\/$/, "");
3214
+ } catch {
3215
+ return url.toLowerCase().replace(/\/+$/, "");
3216
+ }
3217
+ }
3218
+
3168
3219
  // src/sdk/server/mpp-units.ts
3169
3220
  function decimalsFor(methodName) {
3170
3221
  switch (methodName) {
@@ -3219,6 +3270,22 @@ function methodNativeAmountToDecimal(amount, methodName) {
3219
3270
  return `${nativeAmount2 / scale}.${(nativeAmount2 % scale).toString().padStart(decimals, "0")}`;
3220
3271
  }
3221
3272
 
3273
+ // src/lib/mints.ts
3274
+ function isTestMintUrl(url) {
3275
+ let host;
3276
+ try {
3277
+ host = new URL(url).hostname.toLowerCase();
3278
+ } catch {
3279
+ return false;
3280
+ }
3281
+ if (host.startsWith("[") && host.endsWith("]")) host = host.slice(1, -1);
3282
+ if (LOOPBACK_HOSTS.has(host)) return true;
3283
+ if (host.endsWith(".localhost")) return true;
3284
+ return TEST_MINT_HOSTS.has(host);
3285
+ }
3286
+ var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1"]);
3287
+ var TEST_MINT_HOSTS = /* @__PURE__ */ new Set(["testnut.cashu.space", "dvmkit-testmint.fly.dev"]);
3288
+
3222
3289
  // src/sdk/server/wallet-accumulator-receive.ts
3223
3290
  import {
3224
3291
  Amount as Amount2,
@@ -3468,6 +3535,9 @@ async function issueUpfrontChallenges(mpp, requiredMsats, resourcePath, btcUsdRa
3468
3535
  );
3469
3536
  }
3470
3537
  async function verifyUpfrontPayment(opts) {
3538
+ return withPaymentDiagnostics(() => verifyUpfrontPaymentInScope(opts));
3539
+ }
3540
+ async function verifyUpfrontPaymentInScope(opts) {
3471
3541
  const {
3472
3542
  cashuToken,
3473
3543
  requiredMsats,
@@ -3733,7 +3803,10 @@ async function verifyUpfrontPayment(opts) {
3733
3803
  );
3734
3804
  } catch (err) {
3735
3805
  const mapped = mapLedgerCommitError(err, x402Requirements);
3736
- if (mapped) return mapped;
3806
+ if (mapped) {
3807
+ logCredentialRejected("x402", "upfront", err);
3808
+ return mapped;
3809
+ }
3737
3810
  logCredentialRejected("x402", "upfront", err);
3738
3811
  return {
3739
3812
  paidMsats: 0,
@@ -3794,15 +3867,15 @@ async function verifyUpfrontPayment(opts) {
3794
3867
  x402Requirements
3795
3868
  });
3796
3869
  }
3797
- const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
3798
- const receipt = await verifyX402Payment(
3870
+ const { verifyX402Payment } = await import("./x402-ZU4GML7Z.js");
3871
+ const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment(
3799
3872
  x402Payment,
3800
3873
  x402Config,
3801
3874
  requiredUsdcMicro,
3802
3875
  x402Resource ?? "/v1/job",
3803
3876
  rate ?? 0,
3804
3877
  x402ExactVersions
3805
- );
3878
+ ));
3806
3879
  if (receipt.verified) {
3807
3880
  const settledUsdcMicro = receipt.amountUsdcMicro;
3808
3881
  const paidMsats = settledUsdcMicro === void 0 ? receipt.amountMsats : x402SettledShare(requiredMsats, Number(requiredUsdcMicro), settledUsdcMicro);
@@ -3846,7 +3919,10 @@ async function verifyUpfrontPayment(opts) {
3846
3919
  });
3847
3920
  } catch (err) {
3848
3921
  const mapped = mapLedgerCommitError(err, x402Requirements, true);
3849
- if (mapped) return mapped;
3922
+ if (mapped) {
3923
+ logCredentialRejected("x402", "upfront", err);
3924
+ return mapped;
3925
+ }
3850
3926
  throw err;
3851
3927
  }
3852
3928
  }
@@ -3963,7 +4039,7 @@ async function verifyUpfrontPayment(opts) {
3963
4039
  challenge_id: cred.challenge.id,
3964
4040
  amount: expectedAmount
3965
4041
  },
3966
- () => mpp.broadcastCredential(mppCredential, {
4042
+ () => withPaymentStage("verifier_broadcast", () => mpp.broadcastCredential(mppCredential, {
3967
4043
  request: { amount: expectedAmount },
3968
4044
  ...opts.hostingAdmissionId && {
3969
4045
  hostedPaymentIntent: {
@@ -3982,7 +4058,8 @@ async function verifyUpfrontPayment(opts) {
3982
4058
  path: resourcePath ?? "/v1/job",
3983
4059
  nonce: challengeMeta(cred.challenge)?.nonce ?? ""
3984
4060
  }
3985
- })
4061
+ })),
4062
+ { onError: paymentFailureFields }
3986
4063
  );
3987
4064
  tempoReceipt = receipt;
3988
4065
  return receipt;
@@ -4039,7 +4116,10 @@ async function verifyUpfrontPayment(opts) {
4039
4116
  credited = accepted.result;
4040
4117
  } catch (err) {
4041
4118
  const mapped = mapLedgerCommitError(err, x402Requirements, true);
4042
- if (mapped) return mapped;
4119
+ if (mapped) {
4120
+ logCredentialRejected("tempo", "upfront", err);
4121
+ return mapped;
4122
+ }
4043
4123
  throw err;
4044
4124
  }
4045
4125
  } else {
@@ -4070,7 +4150,7 @@ async function verifyUpfrontPayment(opts) {
4070
4150
  if (consumedCredentialStore) {
4071
4151
  const realm = mpp.realm;
4072
4152
  const id = cred.challenge.id;
4073
- if (await consumedCredentialStore.has(realm, id)) {
4153
+ if (await withPaymentStage("replay_store", () => consumedCredentialStore.has(realm, id))) {
4074
4154
  const mppChallenges = await issueUpfrontChallenges(
4075
4155
  mpp,
4076
4156
  requiredMsats,
@@ -4094,7 +4174,7 @@ async function verifyUpfrontPayment(opts) {
4094
4174
  };
4095
4175
  }
4096
4176
  if (!sessionBasis) {
4097
- await consumedCredentialStore.mark(realm, id, CONSUMED_CREDENTIAL_TTL_MS / 1e3);
4177
+ await withPaymentStage("replay_store", () => consumedCredentialStore.mark(realm, id, CONSUMED_CREDENTIAL_TTL_MS / 1e3));
4098
4178
  }
4099
4179
  }
4100
4180
  if (ledgerCtx) {
@@ -4109,16 +4189,19 @@ async function verifyUpfrontPayment(opts) {
4109
4189
  });
4110
4190
  } catch (err) {
4111
4191
  const mapped = mapLedgerCommitError(err, x402Requirements, true);
4112
- if (mapped) return mapped;
4192
+ if (mapped) {
4193
+ logCredentialRejected("tempo", "upfront", err);
4194
+ return mapped;
4195
+ }
4113
4196
  throw err;
4114
4197
  }
4115
4198
  }
4116
4199
  if (sessionBasis && consumedCredentialStore) {
4117
- await consumedCredentialStore.mark(
4200
+ await withPaymentStage("replay_store", () => consumedCredentialStore.mark(
4118
4201
  mpp.realm,
4119
4202
  cred.challenge.id,
4120
4203
  CONSUMED_CREDENTIAL_TTL_MS / 1e3
4121
- );
4204
+ ));
4122
4205
  }
4123
4206
  if (credited) {
4124
4207
  await mpp.completeHostedTempoCharge?.(cred.challenge.id).catch((error) => {
@@ -4687,6 +4770,9 @@ function buildPaymentErrorResponse(body, challenges, x402Requirements, status, x
4687
4770
  return new Response(JSON.stringify(mergedBody), { status: status ?? 402, headers });
4688
4771
  }
4689
4772
  async function verifyIncomingPayment(body, opts, snapshot) {
4773
+ return withPaymentDiagnostics(() => verifyIncomingPaymentInScope(body, opts, snapshot));
4774
+ }
4775
+ async function verifyIncomingPaymentInScope(body, opts, snapshot) {
4690
4776
  if (body.type !== "payment") return {};
4691
4777
  if (body.content.cashu_token) {
4692
4778
  if (opts.cashuMode === "p2pk-accumulator" && (opts.accumulatorDb || opts.disposableCashu) && opts.dvmId && opts.lockPubkeys && opts.lockPubkeys.length > 0) {
@@ -4769,15 +4855,15 @@ async function verifyIncomingPayment(body, opts, snapshot) {
4769
4855
  snapshot
4770
4856
  });
4771
4857
  }
4772
- const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
4773
- const receipt = await verifyX402Payment(
4858
+ const { verifyX402Payment } = await import("./x402-ZU4GML7Z.js");
4859
+ const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment(
4774
4860
  body.content.x402_payment,
4775
4861
  opts.x402Config,
4776
4862
  requiredUsdcMicro,
4777
4863
  opts.resourcePath ?? "/v1/job",
4778
4864
  rate,
4779
4865
  opts.x402ExactVersions
4780
- );
4866
+ ));
4781
4867
  if (!receipt.verified) {
4782
4868
  return {
4783
4869
  error: {
@@ -4826,6 +4912,7 @@ async function verifyIncomingPayment(body, opts, snapshot) {
4826
4912
  } catch (err) {
4827
4913
  const mapped = mapLedgerCommitError(err, void 0, true);
4828
4914
  if (mapped?.error) {
4915
+ logCredentialRejected("x402", "mid-job", err);
4829
4916
  return { error: { body: mapped.error.body, status: mapped.error.status } };
4830
4917
  }
4831
4918
  throw err;
@@ -4933,13 +5020,14 @@ async function verifyIncomingPayment(body, opts, snapshot) {
4933
5020
  challenge_id: credential.challenge.id,
4934
5021
  amount: expectedAmount
4935
5022
  },
4936
- () => mppServer.broadcastCredential(credential, {
5023
+ () => withPaymentStage("verifier_broadcast", () => mppServer.broadcastCredential(credential, {
4937
5024
  request: { amount: expectedAmount },
4938
5025
  ...opts.hostingPaymentSeq !== void 0 && {
4939
5026
  hostedPaymentIntent: { jobId: opts.jobId, paymentSeq: opts.hostingPaymentSeq }
4940
5027
  },
4941
5028
  ...expectedMeta && { meta: expectedMeta }
4942
- })
5029
+ })),
5030
+ { onError: paymentFailureFields }
4943
5031
  );
4944
5032
  let credited;
4945
5033
  if (ledgerCtx) {
@@ -4948,6 +5036,7 @@ async function verifyIncomingPayment(body, opts, snapshot) {
4948
5036
  } catch (err) {
4949
5037
  const mapped = mapLedgerCommitError(err, void 0, true);
4950
5038
  if (mapped?.error) {
5039
+ logCredentialRejected("tempo", "mid-job", err);
4951
5040
  return { error: { body: mapped.error.body, status: mapped.error.status } };
4952
5041
  }
4953
5042
  throw err;
@@ -5142,6 +5231,9 @@ function applyPaymentInfoToJob(job, info) {
5142
5231
  creditPendingPayment(job);
5143
5232
  }
5144
5233
  async function processIncomingPayment(job, body, opts) {
5234
+ return withPaymentDiagnostics(() => processIncomingPaymentInScope(job, body, opts));
5235
+ }
5236
+ async function processIncomingPaymentInScope(job, body, opts) {
5145
5237
  if (body.type !== "payment") return null;
5146
5238
  if (body.content.cashu_token) {
5147
5239
  if (opts.cashuMode === "p2pk-accumulator" && (opts.accumulatorDb || opts.disposableCashu) && opts.dvmId && opts.lockPubkeys && opts.lockPubkeys.length > 0) {
@@ -5194,15 +5286,15 @@ async function processIncomingPayment(job, body, opts) {
5194
5286
  try {
5195
5287
  const requiredMsats = job.pendingPaymentMsats ?? 0;
5196
5288
  const requiredUsdcMicro = job.pendingX402AmountUsdcMicro !== void 0 ? BigInt(job.pendingX402AmountUsdcMicro) : BigInt(msatsToUsdc(requiredMsats, rate));
5197
- const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
5198
- const receipt = await verifyX402Payment(
5289
+ const { verifyX402Payment } = await import("./x402-ZU4GML7Z.js");
5290
+ const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment(
5199
5291
  body.content.x402_payment,
5200
5292
  opts.x402Config,
5201
5293
  requiredUsdcMicro,
5202
5294
  opts.resourcePath ?? "/v1/job",
5203
5295
  rate,
5204
5296
  opts.x402ExactVersions
5205
- );
5297
+ ));
5206
5298
  if (receipt.verified) {
5207
5299
  if (job.pendingX402Nonce !== void 0) {
5208
5300
  const incomingNonce = decodePayment(body.content.x402_payment).payload.authorization.nonce;
@@ -5269,13 +5361,14 @@ async function processIncomingPayment(job, body, opts) {
5269
5361
  challenge_id: credential.challenge.id,
5270
5362
  amount: expectedAmount
5271
5363
  },
5272
- () => mppHandle.broadcastCredential(credential, {
5364
+ () => withPaymentStage("verifier_broadcast", () => mppHandle.broadcastCredential(credential, {
5273
5365
  request: { amount: expectedAmount },
5274
5366
  ...opts.hostingPaymentSeq !== void 0 && {
5275
5367
  hostedPaymentIntent: { jobId: opts.jobId, paymentSeq: opts.hostingPaymentSeq }
5276
5368
  },
5277
5369
  ...expectedMeta && { meta: expectedMeta }
5278
- })
5370
+ })),
5371
+ { onError: paymentFailureFields }
5279
5372
  );
5280
5373
  if (!job.pendingMppChallengeIds?.includes(credential.challenge.id)) {
5281
5374
  return {
@@ -5643,8 +5736,7 @@ async function resolveTopUpLedgerContext(opts, snapshot, binding) {
5643
5736
  if (!denomination.ok) {
5644
5737
  logSkip("denomination_unavailable", {
5645
5738
  currency,
5646
- cause: denomination.reason,
5647
- ...denomination.detail !== void 0 && { detail: denomination.detail }
5739
+ cause: denomination.reason
5648
5740
  });
5649
5741
  return void 0;
5650
5742
  }
@@ -5793,6 +5885,9 @@ function withDrawBasis(info, ctx, committed) {
5793
5885
  };
5794
5886
  }
5795
5887
  async function fundAndDraw(ctx, funding, tx) {
5888
+ return withPaymentStage("funding_ledger", () => fundAndDrawInScope(ctx, funding, tx));
5889
+ }
5890
+ async function fundAndDrawInScope(ctx, funding, tx) {
5796
5891
  const env = ctx.creditEnvelope;
5797
5892
  const fundedMicro = funding.fundedMicro ?? fundedMicroFor(ctx.priceFiat, funding.paidMsats, ctx.requiredMsats);
5798
5893
  const shortMidJob = ctx.midJob === true && funding.paidMsats < ctx.requiredMsats;
@@ -6219,7 +6314,7 @@ async function commitMarkedFunding(ctx, funding, outerTx) {
6219
6314
  const env = ctx.creditEnvelope;
6220
6315
  const creditId = ctx.fundOnly?.creditId ?? ctx.topUp?.creditId ?? env?.creditId ?? implicitCreditId(funding.rail, funding.paymentId);
6221
6316
  const drawId = ctx.fundOnly?.fundId ?? ctx.topUp?.drawId ?? env?.drawId ?? funding.paymentId;
6222
- await store.record({
6317
+ await withPaymentStage("replay_store", () => store.record({
6223
6318
  dvmId: ctx.dvmId,
6224
6319
  rail: funding.rail,
6225
6320
  paymentId: funding.paymentId,
@@ -6227,10 +6322,10 @@ async function commitMarkedFunding(ctx, funding, outerTx) {
6227
6322
  drawId,
6228
6323
  jobId: ctx.jobId,
6229
6324
  tx
6230
- });
6325
+ }));
6231
6326
  return fundAndDraw(ctx, funding, tx);
6232
6327
  };
6233
- return outerTx ? commit(outerTx) : store.withTx(commit);
6328
+ return outerTx ? commit(outerTx) : withPaymentStage("replay_store", () => store.withTx(commit));
6234
6329
  }
6235
6330
  async function commitMppFunding(ctx, credential, funding) {
6236
6331
  const session = mppSessionBasis(credential);
@@ -6592,15 +6687,14 @@ function x402NotOfferedResult(currency) {
6592
6687
  error: x402NotOfferedPaymentError(currency)
6593
6688
  };
6594
6689
  }
6595
- function logCredentialRejected(rail, phase, _err) {
6690
+ function logCredentialRejected(rail, phase, err) {
6596
6691
  diagnosticConsole.warn(
6597
6692
  {
6598
6693
  level: "warn",
6599
6694
  event: `${rail}_credential_rejected`,
6600
6695
  phase,
6601
6696
  rail,
6602
- error_name: void 0,
6603
- error_message: void 0
6697
+ ...paymentFailureFields(err)
6604
6698
  }
6605
6699
  );
6606
6700
  }
@@ -16524,7 +16618,7 @@ import {
16524
16618
  Amount as Amount3,
16525
16619
  CheckStateEnum as CheckStateEnum3,
16526
16620
  getP2PKExpectedWitnessPubkeys as getP2PKExpectedWitnessPubkeys2,
16527
- getTokenMetadata
16621
+ getTokenMetadata as getTokenMetadata2
16528
16622
  } from "@cashu/cashu-ts";
16529
16623
  function installAdminCreditRoutes(app, opts) {
16530
16624
  app.get("/admin/credit/pending-drains", (c) => handlePendingDrains(c, opts));
@@ -16885,7 +16979,7 @@ async function handleParkDrain(c, opts) {
16885
16979
  }
16886
16980
  let parsed;
16887
16981
  try {
16888
- const meta = getTokenMetadata(token);
16982
+ const meta = getTokenMetadata2(token);
16889
16983
  parsed = {
16890
16984
  mint: meta.mint,
16891
16985
  faceSats: Amount3.from(meta.amount).toNumber(),
@@ -19422,7 +19516,7 @@ async function createDVMServer(descriptor, opts) {
19422
19516
  }
19423
19517
  }
19424
19518
  if (!opts.onJobCompleted && platformToken && platformUrl && dvmId && opts.db) {
19425
- const { RevenueReporter } = await import("./revenue-reporter-MAERPYGK.js");
19519
+ const { RevenueReporter } = await import("./revenue-reporter-7UR3W2SD.js");
19426
19520
  const reporter = new RevenueReporter(
19427
19521
  opts.db,
19428
19522
  platformUrl,
@@ -19432,7 +19526,7 @@ async function createDVMServer(descriptor, opts) {
19432
19526
  revenueReporter = reporter;
19433
19527
  await reporter.init();
19434
19528
  reporter.startRetryLoop();
19435
- const { MemoryX402BatchStore, PayoutReporter } = await import("./payout-reporter-3Y2U55ZX.js");
19529
+ const { MemoryX402BatchStore, PayoutReporter } = await import("./payout-reporter-WT7XYW42.js");
19436
19530
  payoutReporter = new PayoutReporter({
19437
19531
  dvmId,
19438
19532
  db: opts.db,
@@ -22848,6 +22942,7 @@ export {
22848
22942
  derivedFundCreditId,
22849
22943
  drawSettlementRef,
22850
22944
  rateUnavailablePaymentError,
22945
+ isTestMintUrl,
22851
22946
  X402_BATCH_SETTLEMENT_NETWORK,
22852
22947
  X402_BATCH_SETTLEMENT_MAINNET_NETWORK,
22853
22948
  X402_BATCH_MIN_WITHDRAW_DELAY_SECONDS,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  initCallerLoggers
3
- } from "./chunk-66HGCPBU.js";
3
+ } from "./chunk-KXWROQGK.js";
4
4
  import {
5
5
  bindDiagnosticCapabilityAuthority,
6
6
  bindDiagnosticIdentityAuthority,
@@ -8,7 +8,7 @@ import {
8
8
  extendDiagnosticIdentityAuthority,
9
9
  projectDiagnosticFields,
10
10
  projectSpanRow
11
- } from "./chunk-ETXDTUJO.js";
11
+ } from "./chunk-LAKP6FUI.js";
12
12
 
13
13
  // src/sdk/logger.ts
14
14
  function createConsoleLogger(_jobId) {