@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
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-CXCQLOOK.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";
@@ -204,90 +204,45 @@ function isOptionalRecord(value) {
204
204
  return value === void 0 || value === null || isRecord(value);
205
205
  }
206
206
 
207
- // src/defaults.ts
208
- import { homedir } from "os";
209
- import { join } from "path";
210
- var CONFIG_DIR = process.env.DVM_CONFIG_DIR ?? join(homedir(), ".dvm");
211
- var CONFIG_FILE = join(CONFIG_DIR, "config.json");
212
- var CONFIG_BACKUP_FILE = join(CONFIG_DIR, "config.json.bak");
213
- var CONFIG_AUDIT_FILE = join(CONFIG_DIR, "config-audit.jsonl");
214
- var CONFIG_PINNED_FILE = join(CONFIG_DIR, "config.json.pinned");
215
- var JOBS_FILE = join(CONFIG_DIR, "jobs.json");
216
- var REQUEST_INTENTS_DIR = join(CONFIG_DIR, "request-intents");
217
- var FAVORITES_FILE = join(CONFIG_DIR, "favorites.json");
218
- var MESSAGES_DIR = join(CONFIG_DIR, "messages");
219
- var RECEIPTS_FILE = join(CONFIG_DIR, "receipts.jsonl");
220
- var CREDITS_FILE = join(CONFIG_DIR, "credits.json");
221
- var X402_CHANNELS_FILE = join(CONFIG_DIR, "x402-channels.json");
222
- var TEMPO_CHANNELS_FILE = join(CONFIG_DIR, "tempo-channels.json");
223
- var FEEDBACK_NUDGES_FILE = join(CONFIG_DIR, "feedback-nudges.json");
224
- var RECOVERY_MNEMONIC_FILE = join(CONFIG_DIR, "recovery.mnemonic");
225
- var WALLET_FILE = join(CONFIG_DIR, "wallet.json");
226
- var AGENT_MNEMONIC_FILE = join(CONFIG_DIR, "wallet.mnemonic");
227
- var IDENTITIES_FILE = join(CONFIG_DIR, "identities.json");
228
- var PAIRINGS_DIR = join(CONFIG_DIR, "pairings");
229
- var BUDGET_FILE = join(CONFIG_DIR, "budget.json");
230
- var BTC_RATE_FILE = join(CONFIG_DIR, "btc-rate.json");
231
- var ADMIN_DIR = join(CONFIG_DIR, "admin");
232
- var PROXY_STATE_FILE = join(ADMIN_DIR, "proxy.json");
233
- var BUILDER_CONFIG_DIR = process.env.DVMKIT_CONFIG_DIR ?? join(homedir(), ".dvmkit");
234
- var BUILDER_FILE = join(BUILDER_CONFIG_DIR, "builder.json");
235
- var BUILDER_MNEMONIC_FILE = join(BUILDER_CONFIG_DIR, "recovery.mnemonic");
236
- var BUILDER_KEY_FILE = join(BUILDER_CONFIG_DIR, "builder.key");
237
- var MELT_PENDING_LOG_FILE = join(BUILDER_CONFIG_DIR, "melt-pending.log");
238
- var DRAIN_PARK_LOG_FILE = join(BUILDER_CONFIG_DIR, "drain-park.log");
239
- var DRAIN_HOLD_STATE_FILE = join(BUILDER_CONFIG_DIR, "drain-hold.json");
240
- var MELT_SUCCESS_FILE = join(BUILDER_CONFIG_DIR, "melt-success.json");
241
-
242
- // src/lib/config-dir.ts
243
- import { chmodSync, mkdirSync, statSync } from "fs";
244
- var CONFIG_DIR_MODE = 448;
245
- function ensureConfigDir() {
246
- ensureConfigSubdir(CONFIG_DIR);
247
- }
248
- function ensureConfigSubdir(path) {
249
- mkdirSync(path, { recursive: true, mode: CONFIG_DIR_MODE });
250
- }
251
- function repairConfigDirMode() {
252
- const base = {
253
- path: CONFIG_DIR,
254
- exists: false,
255
- modeOctal: null,
256
- repaired: false,
257
- skippedNonPosix: process.platform === "win32"
258
- };
259
- if (base.skippedNonPosix) return base;
260
- let mode;
261
- try {
262
- mode = statSync(CONFIG_DIR).mode & 511;
263
- } catch (err) {
264
- const message = err instanceof Error ? err.message : String(err);
265
- const missing = err.code === "ENOENT";
266
- return missing ? base : { ...base, error: message };
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");
267
221
  }
268
- if ((mode & 63) === 0) {
269
- return { ...base, exists: true, modeOctal: toOctal(mode) };
222
+ if (!Number.isFinite(btcUsdRate) || btcUsdRate <= 0) {
223
+ throw new RangeError("BTC/USD rate must be finite and positive");
270
224
  }
271
- try {
272
- chmodSync(CONFIG_DIR, CONFIG_DIR_MODE);
273
- } catch (err) {
274
- return {
275
- ...base,
276
- exists: true,
277
- modeOctal: toOctal(mode),
278
- error: err instanceof Error ? err.message : String(err)
279
- };
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");
280
235
  }
281
- return {
282
- ...base,
283
- exists: true,
284
- modeOctal: toOctal(CONFIG_DIR_MODE),
285
- previousModeOctal: toOctal(mode),
286
- repaired: true
287
- };
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);
288
243
  }
289
- function toOctal(mode) {
290
- return "0" + mode.toString(8).padStart(3, "0");
244
+ function microToSats(micro, btcRate) {
245
+ return Math.ceil(usdToMsats(micro / 1e6, btcRate) / 1e3);
291
246
  }
292
247
 
293
248
  // src/lib/payment-rails/rpc.ts
@@ -339,33 +294,13 @@ export {
339
294
  decodePaymentRequiredHeader,
340
295
  exactEvmAuthorization,
341
296
  encodeSettleResponseHeader,
342
- CONFIG_DIR,
343
- CONFIG_FILE,
344
- CONFIG_BACKUP_FILE,
345
- CONFIG_AUDIT_FILE,
346
- CONFIG_PINNED_FILE,
347
- JOBS_FILE,
348
- REQUEST_INTENTS_DIR,
349
- FAVORITES_FILE,
350
- MESSAGES_DIR,
351
- RECEIPTS_FILE,
352
- CREDITS_FILE,
353
- X402_CHANNELS_FILE,
354
- TEMPO_CHANNELS_FILE,
355
- FEEDBACK_NUDGES_FILE,
356
- RECOVERY_MNEMONIC_FILE,
357
- WALLET_FILE,
358
- AGENT_MNEMONIC_FILE,
359
- IDENTITIES_FILE,
360
- PAIRINGS_DIR,
361
- BUDGET_FILE,
362
- BTC_RATE_FILE,
363
- BUILDER_CONFIG_DIR,
364
- BUILDER_FILE,
365
- BUILDER_KEY_FILE,
366
- ensureConfigDir,
367
- ensureConfigSubdir,
368
- repairConfigDirMode,
297
+ msatsToUsd,
298
+ usdToMsats,
299
+ msatsToUsdCents,
300
+ msatsToUsdc,
301
+ usdcToMsats,
302
+ msatsToMicro,
303
+ microToSats,
369
304
  resolveRpcOverride,
370
305
  resolveRpcHttpTransportOptions
371
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
+ };