@dvmkit/sdk 0.6.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 (74) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-PLG4XER6.js → chunk-26W6GPCD.js} +48 -6
  3. package/dist/{chunk-FI4CST2D.js → chunk-2OM2QPBE.js} +6 -8
  4. package/dist/{chunk-IWQHUSMO.js → chunk-62FI3NJF.js} +78 -2
  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-HHBDBMEO.js → chunk-A6CXKAQV.js} +186 -93
  9. package/dist/{chunk-QR2EF2NI.js → chunk-AQ7OX5NX.js} +2 -2
  10. package/dist/{chunk-RLTSCKRI.js → chunk-BPYMEMQX.js} +50 -3
  11. package/dist/{chunk-BYCEKO65.js → chunk-CLIAFTUR.js} +102 -13
  12. package/dist/{chunk-GAOAYHZA.js → chunk-DNG4KGSC.js} +3 -3
  13. package/dist/{chunk-Z4ZT5LNT.js → chunk-GSLS4464.js} +3 -3
  14. package/dist/{chunk-7ZUKL4IV.js → chunk-H5FVVEEN.js} +17 -6
  15. package/dist/{chunk-IXR5RFK7.js → chunk-HCE4MPZ5.js} +1 -1
  16. package/dist/{chunk-FYRR2UEZ.js → chunk-I555L2WK.js} +1 -1
  17. package/dist/{chunk-EQLA4FFY.js → chunk-IIZQNDQU.js} +3 -3
  18. package/dist/{chunk-FUJ36YDV.js → chunk-KXWROQGK.js} +24 -1
  19. package/dist/{chunk-ETXDTUJO.js → chunk-LAKP6FUI.js} +55 -0
  20. package/dist/{chunk-X7EZ5CLI.js → chunk-MON76YBJ.js} +3 -3
  21. package/dist/chunk-OFSOLHRX.js +120 -0
  22. package/dist/{chunk-IV6Q7NRW.js → chunk-RAGX6VG7.js} +2 -2
  23. package/dist/{chunk-KA6VN5FK.js → chunk-RXPHMS4C.js} +3 -3
  24. package/dist/{chunk-JH3SX3LY.js → chunk-SPYEJXI7.js} +6 -6
  25. package/dist/{chunk-P6QON7ER.js → chunk-TRNMTTPX.js} +1 -1
  26. package/dist/{chunk-RCM3P2HE.js → chunk-UKD3R2KU.js} +55 -4
  27. package/dist/chunk-USL7ZEXN.js +17 -0
  28. package/dist/{chunk-OQA7IHI4.js → chunk-VB5OLOZH.js} +403 -235
  29. package/dist/{content-retention-BTGSQRfP.d.ts → content-retention-CbnouEnh.d.ts} +1 -1
  30. package/dist/{credit-ledger-MI2H7NEC.js → credit-ledger-7Z7LOCTN.js} +4 -5
  31. package/dist/{credit-menu-BAsrRu3z.d.ts → credit-menu-BO8yJppy.d.ts} +4 -4
  32. package/dist/{fx-BgDmyTdd.d.ts → fx-DSOZQ2z7.d.ts} +1 -1
  33. package/dist/index.d.ts +5 -5
  34. package/dist/index.js +236 -16
  35. package/dist/internal/caller.d.ts +4495 -7305
  36. package/dist/internal/caller.js +4415 -8122
  37. package/dist/internal/index.js +1 -1
  38. package/dist/internal/server.d.ts +7 -7
  39. package/dist/internal/server.js +27 -32
  40. package/dist/{job-store-BVeF5_Jq.d.ts → job-store-BJRlmq2Q.d.ts} +1 -1
  41. package/dist/{lightning-backend-40fIzz1W.d.ts → lightning-backend-f16-fsYK.d.ts} +4 -2
  42. package/dist/memory-credit-ledger-3WOS74UH.js +11 -0
  43. package/dist/{mpp-setup-RF5FXGGV.js → mpp-setup-XB4KATMU.js} +2 -2
  44. package/dist/{payout-reporter-3Y2U55ZX.js → payout-reporter-WT7XYW42.js} +2 -2
  45. package/dist/{postgres-consumed-credential-store-BUVCAPLS.js → postgres-consumed-credential-store-W7UP33AH.js} +3 -3
  46. package/dist/{postgres-job-store-VHLQBJZC.js → postgres-job-store-3KGUGFRD.js} +2 -2
  47. package/dist/{postgres-replay-store-ARZSQ45X.js → postgres-replay-store-CVNJJOQG.js} +2 -2
  48. package/dist/{pricing-XT2IAPNE.js → pricing-QAVZUTZR.js} +12 -12
  49. package/dist/{revenue-reporter-MAERPYGK.js → revenue-reporter-7UR3W2SD.js} +2 -2
  50. package/dist/server/index.d.ts +10 -10
  51. package/dist/server/index.js +46 -53
  52. package/dist/{step-cache-CPdH1hei.d.ts → step-cache-CJFiZU3n.d.ts} +1 -1
  53. package/dist/{tempo-charge-store-Q3D7KYMH.js → tempo-charge-store-GA6CED6O.js} +2 -2
  54. package/dist/{tempo-session-store-ZRNCOX7P.js → tempo-session-store-WZWQRITB.js} +3 -3
  55. package/dist/testing/index.d.ts +3 -3
  56. package/dist/testing/index.js +6 -7
  57. package/dist/{usd-AWlrwlM5.d.ts → usd-DmHHg0_4.d.ts} +1 -1
  58. package/dist/{x402-R6HPBY5D.js → x402-ZU4GML7Z.js} +9 -30
  59. package/package.json +3 -2
  60. package/dist/chunk-66HGCPBU.js +0 -25
  61. package/dist/chunk-AT6V3SY7.js +0 -102
  62. package/dist/chunk-B2IROPQF.js +0 -1844
  63. package/dist/chunk-CZULM42S.js +0 -143
  64. package/dist/chunk-GFY5FRX3.js +0 -218
  65. package/dist/chunk-HCLVYZUZ.js +0 -244
  66. package/dist/chunk-LE74UEV7.js +0 -1071
  67. package/dist/chunk-LIRAHP7B.js +0 -53
  68. package/dist/chunk-MZRJR2CW.js +0 -776
  69. package/dist/chunk-OFVV37XC.js +0 -57
  70. package/dist/chunk-PAIM66YA.js +0 -347
  71. package/dist/chunk-UOCZXO2Z.js +0 -1663
  72. package/dist/memory-credit-ledger-W2BAUYJP.js +0 -12
  73. package/dist/tempo-lifecycle-ZBBLFBMH.js +0 -15
  74. package/dist/tempo-wallet-B5XXV3YH.js +0 -40
package/README.md CHANGED
@@ -98,6 +98,8 @@ The public [SDK guide](https://dvmkit.com/docs/sdk) covers signed requests, cust
98
98
 
99
99
  ## Diagnostic retention
100
100
 
101
+ [Payment diagnostics](./docs/DIAGNOSTICS.md) documents the closed failure categories, stages, and top-up causes retained by safe logging sinks.
102
+
101
103
  The SDK advertises 730 days of retention for sanitized diagnostics in every existing span dataset: `platform`, `cashu`, `lightning`, `stripe`, `x402`, `tempo`, `isolate`, `audit`, and `cron`. Dataset names, producer permissions, and query semantics remain unchanged; only operator services may write to `audit`.
102
104
 
103
105
  This metadata describes the retention schedule. The SDK does not automatically delete diagnostics or override platform destruction or case controls. The platform must enforce the schedule and those controls.
@@ -1,9 +1,34 @@
1
1
  import {
2
2
  X402_DEFAULT_FACILITATOR
3
- } from "./chunk-IWQHUSMO.js";
3
+ } from "./chunk-62FI3NJF.js";
4
4
  import {
5
5
  callerLoggers
6
- } from "./chunk-66HGCPBU.js";
6
+ } from "./chunk-KXWROQGK.js";
7
+ import {
8
+ diagnosticConsole
9
+ } from "./chunk-LAKP6FUI.js";
10
+
11
+ // src/observability/payment-diagnostics.ts
12
+ import { AsyncLocalStorage } from "async_hooks";
13
+ var scopes = new AsyncLocalStorage();
14
+ function withPaymentDiagnostics(fn) {
15
+ return scopes.run({}, fn);
16
+ }
17
+ async function withPaymentStage(stage, fn) {
18
+ try {
19
+ return await fn();
20
+ } catch (error) {
21
+ const scope = scopes.getStore();
22
+ if (scope && (!scope.failure || !Object.is(scope.failure.error, error))) {
23
+ scope.failure = { error, stage };
24
+ }
25
+ throw error;
26
+ }
27
+ }
28
+ function paymentFailureStage(error) {
29
+ const failure = scopes.getStore()?.failure;
30
+ return failure && Object.is(failure.error, error) ? failure.stage : "unknown";
31
+ }
7
32
 
8
33
  // src/lib/x402/facilitator.ts
9
34
  import { createPrivateKey, randomBytes } from "crypto";
@@ -82,7 +107,7 @@ async function verifyWithFacilitator(payload, requirements, config = {}, createA
82
107
  return callerLoggers.x402.span(
83
108
  "x402.verify_with_facilitator",
84
109
  { facilitator_url: url },
85
- async () => {
110
+ () => withPaymentStage("verifier", async () => {
86
111
  const authHeaders = (await createAuthHeaders?.())?.verify ?? {};
87
112
  const res = await fetch(url, {
88
113
  method: "POST",
@@ -96,14 +121,17 @@ async function verifyWithFacilitator(payload, requirements, config = {}, createA
96
121
  if (!res.ok) {
97
122
  const rejection = await readFacilitatorRejection(res);
98
123
  if (rejection?.isValid === false && typeof rejection.invalidReason === "string" && rejection.invalidReason.length > 0) {
124
+ logRejected("verifier");
99
125
  return rejection;
100
126
  }
127
+ logRejected("verifier");
101
128
  return { isValid: false, invalidReason: `facilitator_status_${res.status}` };
102
129
  }
103
130
  const data = await res.json();
131
+ if (!data.isValid) logRejected("verifier");
104
132
  callerLoggers.x402.info("x402.verify_with_facilitator.result", { is_valid: data.isValid });
105
133
  return data;
106
- }
134
+ })
107
135
  );
108
136
  }
109
137
  async function settleWithFacilitator(payload, requirements, config = {}, createAuthHeaders = createX402FacilitatorAuthHeaders(config)) {
@@ -112,7 +140,7 @@ async function settleWithFacilitator(payload, requirements, config = {}, createA
112
140
  return callerLoggers.x402.span(
113
141
  "x402.settle_with_facilitator",
114
142
  { facilitator_url: url },
115
- async () => {
143
+ () => withPaymentStage("broadcast", async () => {
116
144
  const authHeaders = (await createAuthHeaders?.())?.settle ?? {};
117
145
  const res = await fetch(url, {
118
146
  method: "POST",
@@ -126,17 +154,20 @@ async function settleWithFacilitator(payload, requirements, config = {}, createA
126
154
  if (!res.ok) {
127
155
  const rejection = await readFacilitatorRejection(res);
128
156
  if (rejection?.success === false && typeof rejection.errorReason === "string" && rejection.errorReason.length > 0) {
157
+ logRejected("broadcast");
129
158
  return rejection;
130
159
  }
160
+ logRejected("broadcast");
131
161
  return { success: false, errorReason: `facilitator_status_${res.status}` };
132
162
  }
133
163
  const data = await res.json();
164
+ if (!data.success) logRejected("broadcast");
134
165
  callerLoggers.x402.info("x402.settle_with_facilitator.result", {
135
166
  success: data.success,
136
167
  tx_hash: data.transaction
137
168
  });
138
169
  return data;
139
- }
170
+ })
140
171
  );
141
172
  }
142
173
  async function readFacilitatorRejection(res) {
@@ -151,8 +182,19 @@ async function readFacilitatorRejection(res) {
151
182
  function isRecord(value) {
152
183
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
153
184
  }
185
+ function logRejected(stage) {
186
+ diagnosticConsole.warn({
187
+ event: "x402_credential_rejected",
188
+ rail: "x402",
189
+ failure_category: stage === "verifier" ? "verification_failed" : "settlement_failed",
190
+ failure_stage: stage
191
+ });
192
+ }
154
193
 
155
194
  export {
195
+ withPaymentDiagnostics,
196
+ withPaymentStage,
197
+ paymentFailureStage,
156
198
  createX402FacilitatorAuthHeaders,
157
199
  createX402FacilitatorClient,
158
200
  verifyWithFacilitator,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  callerLoggers
3
- } from "./chunk-66HGCPBU.js";
3
+ } from "./chunk-KXWROQGK.js";
4
4
  import {
5
5
  diagnosticConsole,
6
6
  projectSpanRow
7
- } from "./chunk-ETXDTUJO.js";
7
+ } from "./chunk-LAKP6FUI.js";
8
8
 
9
9
  // src/lib/x402/env.ts
10
10
  import { isAddress } from "viem";
@@ -388,12 +388,6 @@ var HttpTransport = class {
388
388
  }
389
389
  };
390
390
 
391
- // src/lib/nwc.ts
392
- import { decrypt, encrypt } from "nostr-tools/nip04";
393
- import { SimplePool, useWebSocketImplementation } from "nostr-tools/pool";
394
- import { finalizeEvent, getPublicKey } from "nostr-tools/pure";
395
- import WebSocket from "ws";
396
-
397
391
  // src/lib/hash.ts
398
392
  import { createHash } from "crypto";
399
393
  function sha256hex(input) {
@@ -401,6 +395,10 @@ function sha256hex(input) {
401
395
  }
402
396
 
403
397
  // src/lib/nwc.ts
398
+ import { decrypt, encrypt } from "nostr-tools/nip04";
399
+ import { SimplePool, useWebSocketImplementation } from "nostr-tools/pool";
400
+ import { finalizeEvent, getPublicKey } from "nostr-tools/pure";
401
+ import WebSocket from "ws";
404
402
  var webSocketImplementationConfigured = false;
405
403
  function ensureWebSocketImplementation() {
406
404
  if (webSocketImplementationConfigured) return;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  x402NetworkByCaip2,
3
3
  x402NetworkBySlug
4
- } from "./chunk-RLTSCKRI.js";
4
+ } from "./chunk-BPYMEMQX.js";
5
5
 
6
6
  // src/lib/x402/constants.ts
7
7
  var X402_DEFAULT_FACILITATOR = "https://x402.org/facilitator";
@@ -204,6 +204,73 @@ function isOptionalRecord(value) {
204
204
  return value === void 0 || value === null || isRecord(value);
205
205
  }
206
206
 
207
+ // src/lib/payment-amounts.ts
208
+ function msatsToUsd(msats, rate) {
209
+ return msats / 1e11 * rate;
210
+ }
211
+ function usdToMsats(usd, rate) {
212
+ return Math.round(usd / rate * 1e11);
213
+ }
214
+ function msatsToUsdCents(msats, btcPriceUsd) {
215
+ const usd = msatsToUsd(msats, btcPriceUsd);
216
+ return Math.round(usd * 100);
217
+ }
218
+ function msatsToUsdc(msats, btcUsdRate) {
219
+ if (!Number.isSafeInteger(msats) || msats < 0) {
220
+ throw new RangeError("msats must be a non-negative safe integer");
221
+ }
222
+ if (!Number.isFinite(btcUsdRate) || btcUsdRate <= 0) {
223
+ throw new RangeError("BTC/USD rate must be finite and positive");
224
+ }
225
+ const [mantissa, exponent = "0"] = btcUsdRate.toString().split("e");
226
+ const decimalPlaces = mantissa.split(".")[1]?.length ?? 0;
227
+ const shift = Number(exponent) - decimalPlaces;
228
+ let numerator = BigInt(msats) * BigInt(mantissa.replace(".", ""));
229
+ let denominator = 100000n;
230
+ if (shift > 0) numerator *= 10n ** BigInt(shift);
231
+ else if (shift < 0) denominator *= 10n ** BigInt(-shift);
232
+ const micro = (numerator + denominator - 1n) / denominator;
233
+ if (micro > BigInt(Number.MAX_SAFE_INTEGER)) {
234
+ throw new RangeError("USDC micro-unit amount exceeds the safe integer range");
235
+ }
236
+ return Number(micro);
237
+ }
238
+ function usdcToMsats(usdc, btcUsdRate) {
239
+ return usdToMsats(usdc, btcUsdRate);
240
+ }
241
+ function msatsToMicro(msats, btcRate) {
242
+ return Math.round(msatsToUsd(msats, btcRate) * 1e6);
243
+ }
244
+ function microToSats(micro, btcRate) {
245
+ return Math.ceil(usdToMsats(micro / 1e6, btcRate) / 1e3);
246
+ }
247
+
248
+ // src/lib/payment-rails/rpc.ts
249
+ function resolveRpcOverride(envValue, bundled) {
250
+ const override = envValue?.trim() ?? "";
251
+ return override.length > 0 ? { url: override, source: "override" } : { url: bundled, source: "bundled" };
252
+ }
253
+ function resolveRpcHttpTransportOptions(source, envValue) {
254
+ if (source !== "override" || !envValue?.trim()) return void 0;
255
+ let parsed;
256
+ try {
257
+ parsed = JSON.parse(envValue);
258
+ } catch {
259
+ throw new Error("RPC headers must be a JSON object of non-empty string values.");
260
+ }
261
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
262
+ throw new Error("RPC headers must be a JSON object of non-empty string values.");
263
+ const headers = {};
264
+ for (const [name, value] of Object.entries(parsed)) {
265
+ if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name) || typeof value !== "string" || value.length === 0 || /[\r\n]/.test(value))
266
+ throw new Error("RPC headers must be a JSON object of non-empty string values.");
267
+ headers[name] = value;
268
+ }
269
+ if (Object.keys(headers).length === 0)
270
+ throw new Error("RPC headers must be a JSON object of non-empty string values.");
271
+ return { fetchOptions: { headers } };
272
+ }
273
+
207
274
  export {
208
275
  X402_DEFAULT_FACILITATOR,
209
276
  X402_VERSION,
@@ -226,5 +293,14 @@ export {
226
293
  encodePaymentRequiredHeader,
227
294
  decodePaymentRequiredHeader,
228
295
  exactEvmAuthorization,
229
- encodeSettleResponseHeader
296
+ encodeSettleResponseHeader,
297
+ msatsToUsd,
298
+ usdToMsats,
299
+ msatsToUsdCents,
300
+ msatsToUsdc,
301
+ usdcToMsats,
302
+ msatsToMicro,
303
+ microToSats,
304
+ resolveRpcOverride,
305
+ resolveRpcHttpTransportOptions
230
306
  };
@@ -1,9 +1,9 @@
1
+ import {
2
+ diagnosticConsole
3
+ } from "./chunk-LAKP6FUI.js";
1
4
  import {
2
5
  withSdkInitLock
3
6
  } from "./chunk-COYKJRMM.js";
4
- import {
5
- diagnosticConsole
6
- } from "./chunk-ETXDTUJO.js";
7
7
 
8
8
  // src/sdk/server/postgres-replay-store.ts
9
9
  var DEFAULT_TABLE_NAME = "signed_request_replays";
@@ -4,10 +4,10 @@ import {
4
4
  signedRequestHeaderMatchesDomain,
5
5
  signedRequestStatementHeader,
6
6
  testOnlySignedRequestDomain
7
- } from "./chunk-RCM3P2HE.js";
7
+ } from "./chunk-UKD3R2KU.js";
8
8
  import {
9
9
  diagnosticConsole
10
- } from "./chunk-ETXDTUJO.js";
10
+ } from "./chunk-LAKP6FUI.js";
11
11
 
12
12
  // src/sdk/server/zod-error.ts
13
13
  function humanizeZodError(err, opts) {
@@ -0,0 +1,6 @@
1
+ // src/lib/wire-schema.ts
2
+ var CAPABILITY_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
3
+
4
+ export {
5
+ CAPABILITY_NAME_RE
6
+ };