@dvmkit/sdk 0.1.2-rc.7 → 0.1.4-rc.7

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 (45) hide show
  1. package/README.md +121 -8
  2. package/dist/chunk-BIFLRKMO.js +87 -0
  3. package/dist/chunk-BQ2NMWKE.js +160 -0
  4. package/dist/{chunk-LDTWX7JW.js → chunk-BTZY7VPH.js} +13 -1
  5. package/dist/{chunk-FJDCFHW5.js → chunk-C6JHBLMW.js} +3 -81
  6. package/dist/{chunk-EXHBXA4U.js → chunk-DBCLBYHP.js} +13 -1
  7. package/dist/chunk-E4EVGPDX.js +391 -0
  8. package/dist/chunk-EDDYHZ6W.js +1010 -0
  9. package/dist/{chunk-2ABMGUDS.js → chunk-EVBK675R.js} +88 -10
  10. package/dist/{chunk-P4RUVDU7.js → chunk-H2MEFVH6.js} +12 -141
  11. package/dist/chunk-KXZUCCEY.js +142 -0
  12. package/dist/{chunk-LWUR4CGG.js → chunk-MLRCSJYX.js} +11 -3
  13. package/dist/{chunk-N4VTG3KH.js → chunk-QK3VJNCK.js} +930 -3011
  14. package/dist/chunk-RW5LP57K.js +44 -0
  15. package/dist/{chunk-6JZIX5WW.js → chunk-SSSZUVWM.js} +178 -8
  16. package/dist/{chunk-TKA6ZP4M.js → chunk-U6M3ATSG.js} +56 -426
  17. package/dist/chunk-VRQDX5P4.js +1742 -0
  18. package/dist/{chunk-JGGI65I3.js → chunk-Z4BNLUZF.js} +1 -150
  19. package/dist/{credit-ledger-ED6JXKVD.js → credit-ledger-2DFQHNLB.js} +2 -2
  20. package/dist/{credit-menu-BM4qCD5U.d.ts → credit-menu-C1ezIFlJ.d.ts} +1699 -1941
  21. package/dist/{fx-C-liI3oY.d.ts → fx-C6dl2LVI.d.ts} +1 -1
  22. package/dist/index.d.ts +7 -6
  23. package/dist/index.js +8 -4
  24. package/dist/internal/caller.d.ts +10441 -0
  25. package/dist/internal/caller.js +10078 -0
  26. package/dist/internal/index.d.ts +2 -10816
  27. package/dist/internal/index.js +2 -10130
  28. package/dist/internal/server.d.ts +404 -0
  29. package/dist/internal/server.js +202 -0
  30. package/dist/job-store-DHnW4Cg_.d.ts +591 -0
  31. package/dist/lightning-backend-Ci1nogk_.d.ts +367 -0
  32. package/dist/{memory-credit-ledger-XJ5VQEVP.js → memory-credit-ledger-OP24Z2KO.js} +3 -3
  33. package/dist/{postgres-job-store-J5F4GUWU.js → postgres-job-store-3RAXMNSY.js} +1 -1
  34. package/dist/{revenue-reporter-JIKUPXOK.js → revenue-reporter-ASZ7SHHH.js} +1 -1
  35. package/dist/server/index.d.ts +41 -11
  36. package/dist/server/index.js +93 -69
  37. package/dist/{job-store-C53VQ5uu.d.ts → step-cache-BLPZNizw.d.ts} +176 -585
  38. package/dist/{tempo-session-store-DALMRIWN.js → tempo-session-store-2JNOKJGX.js} +2 -2
  39. package/dist/testing/index.d.ts +25 -3
  40. package/dist/testing/index.js +36 -3
  41. package/dist/{usd-gLcJB1ps.d.ts → usd-BgOfZlk6.d.ts} +1 -1
  42. package/dist/wallet-CJC8lwxx.d.ts +29 -0
  43. package/dist/{x402-FTG2GRAQ.js → x402-T2C5MX3T.js} +6 -3
  44. package/package.json +11 -5
  45. package/dist/{chunk-RU7SXHLO.js → chunk-UP2F5RRT.js} +3 -3
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  DvmError
3
3
  } from "./chunk-MKI6OVW4.js";
4
- import {
5
- callerLoggers
6
- } from "./chunk-66HGCPBU.js";
7
4
 
8
5
  // src/lib/x402/constants.ts
9
6
  var X402_DEFAULT_FACILITATOR = "https://x402.org/facilitator";
@@ -104,76 +101,6 @@ function x402SupportedNetworksHint() {
104
101
  var BY_CAIP2 = new Map(X402_NETWORKS.map((n) => [n.caip2, n]));
105
102
  var BY_SLUG = new Map(X402_NETWORKS.map((n) => [n.slug, n]));
106
103
 
107
- // src/lib/x402/facilitator.ts
108
- import { createPrivateKey, randomBytes } from "crypto";
109
- import { HTTPFacilitatorClient } from "@x402/core/server";
110
- import { importJWK, importPKCS8, SignJWT } from "jose";
111
- var AUTH_HEADER_TTL_MS = 6e4;
112
- var AUTH_TOKEN_TTL_SECONDS = 120;
113
- var FACILITATOR_PATHS = {
114
- verify: "POST",
115
- settle: "POST",
116
- supported: "GET"
117
- };
118
- function createX402FacilitatorAuthHeaders(config) {
119
- const auth = config.facilitatorAuth;
120
- if (!auth) return void 0;
121
- const facilitator = new URL(config.facilitator ?? X402_DEFAULT_FACILITATOR);
122
- const basePath = facilitator.pathname.replace(/\/+$/, "");
123
- let cached;
124
- return async () => {
125
- const nowMs = Date.now();
126
- if (cached && nowMs < cached.refreshAtMs) return cached.headers;
127
- const entries = await Promise.all(
128
- Object.entries(FACILITATOR_PATHS).map(async ([path, method]) => {
129
- const requestPath = `${basePath}/${path}`;
130
- const jwt = await generateCdpJwt(
131
- auth.keyId,
132
- auth.keySecret,
133
- `${method} ${facilitator.host}${requestPath}`
134
- );
135
- return [path, { Authorization: `Bearer ${jwt}` }];
136
- })
137
- );
138
- const headers = Object.fromEntries(entries);
139
- cached = { headers, refreshAtMs: nowMs + AUTH_HEADER_TTL_MS };
140
- return headers;
141
- };
142
- }
143
- function createX402FacilitatorClient(config, opts = {}) {
144
- return new HTTPFacilitatorClient({
145
- url: config.facilitator ?? X402_DEFAULT_FACILITATOR,
146
- ...opts.timeoutMs !== void 0 ? { timeoutMs: opts.timeoutMs } : {},
147
- ...config.facilitatorAuth ? { createAuthHeaders: createX402FacilitatorAuthHeaders(config) } : {}
148
- });
149
- }
150
- async function generateCdpJwt(keyId, keySecret, uri) {
151
- const now = Math.floor(Date.now() / 1e3);
152
- const nonce = randomBytes(16).toString("hex");
153
- const claims = { sub: keyId, iss: "cdp", uris: [uri] };
154
- try {
155
- const ecKey = await importPKCS8(normalizeEs256KeySecret(keySecret), "ES256");
156
- return await new SignJWT(claims).setProtectedHeader({ alg: "ES256", kid: keyId, typ: "JWT", nonce }).setIssuedAt(now).setNotBefore(now).setExpirationTime(now + AUTH_TOKEN_TTL_SECONDS).sign(ecKey);
157
- } catch {
158
- }
159
- const decoded = Buffer.from(keySecret, "base64");
160
- if (decoded.length !== 64) {
161
- throw new Error("Invalid CDP key secret: expected an ES256 PEM or base64 Ed25519 key");
162
- }
163
- const jwk = {
164
- kty: "OKP",
165
- crv: "Ed25519",
166
- d: decoded.subarray(0, 32).toString("base64url"),
167
- x: decoded.subarray(32).toString("base64url")
168
- };
169
- const edKey = await importJWK(jwk, "EdDSA");
170
- return new SignJWT(claims).setProtectedHeader({ alg: "EdDSA", kid: keyId, typ: "JWT", nonce }).setIssuedAt(now).setNotBefore(now).setExpirationTime(now + AUTH_TOKEN_TTL_SECONDS).sign(edKey);
171
- }
172
- function normalizeEs256KeySecret(keySecret) {
173
- if (!keySecret.includes("-----BEGIN EC PRIVATE KEY-----")) return keySecret;
174
- return createPrivateKey(keySecret).export({ format: "pem", type: "pkcs8" });
175
- }
176
-
177
104
  // src/lib/x402/spec.ts
178
105
  var X402_VERSION = 2;
179
106
  var X402_V1_VERSION = 1;
@@ -315,78 +242,6 @@ function exactEvmAuthorization(payload) {
315
242
  function encodeSettleResponseHeader(response) {
316
243
  return Buffer.from(JSON.stringify(response), "utf-8").toString("base64");
317
244
  }
318
- async function verifyWithFacilitator(payload, requirements, config = {}, createAuthHeaders = createX402FacilitatorAuthHeaders(config)) {
319
- const facilitator = config.facilitator ?? X402_DEFAULT_FACILITATOR;
320
- const url = facilitator.replace(/\/$/, "") + "/verify";
321
- return callerLoggers.x402.span(
322
- "x402.verify_with_facilitator",
323
- { facilitator_url: url },
324
- async () => {
325
- const authHeaders = (await createAuthHeaders?.())?.verify ?? {};
326
- const res = await fetch(url, {
327
- method: "POST",
328
- headers: { "Content-Type": "application/json", ...authHeaders },
329
- body: JSON.stringify({
330
- x402Version: payload.x402Version,
331
- paymentPayload: payload,
332
- paymentRequirements: requirements
333
- })
334
- });
335
- if (!res.ok) {
336
- const rejection = await readFacilitatorRejection(res);
337
- if (rejection?.isValid === false && typeof rejection.invalidReason === "string" && rejection.invalidReason.length > 0) {
338
- return rejection;
339
- }
340
- return { isValid: false, invalidReason: `facilitator_status_${res.status}` };
341
- }
342
- const data = await res.json();
343
- callerLoggers.x402.info("x402.verify_with_facilitator.result", { is_valid: data.isValid });
344
- return data;
345
- }
346
- );
347
- }
348
- async function settleWithFacilitator(payload, requirements, config = {}, createAuthHeaders = createX402FacilitatorAuthHeaders(config)) {
349
- const facilitator = config.facilitator ?? X402_DEFAULT_FACILITATOR;
350
- const url = facilitator.replace(/\/$/, "") + "/settle";
351
- return callerLoggers.x402.span(
352
- "x402.settle_with_facilitator",
353
- { facilitator_url: url },
354
- async () => {
355
- const authHeaders = (await createAuthHeaders?.())?.settle ?? {};
356
- const res = await fetch(url, {
357
- method: "POST",
358
- headers: { "Content-Type": "application/json", ...authHeaders },
359
- body: JSON.stringify({
360
- x402Version: payload.x402Version,
361
- paymentPayload: payload,
362
- paymentRequirements: requirements
363
- })
364
- });
365
- if (!res.ok) {
366
- const rejection = await readFacilitatorRejection(res);
367
- if (rejection?.success === false && typeof rejection.errorReason === "string" && rejection.errorReason.length > 0) {
368
- return rejection;
369
- }
370
- return { success: false, errorReason: `facilitator_status_${res.status}` };
371
- }
372
- const data = await res.json();
373
- callerLoggers.x402.info("x402.settle_with_facilitator.result", {
374
- success: data.success,
375
- tx_hash: data.transaction
376
- });
377
- return data;
378
- }
379
- );
380
- }
381
- async function readFacilitatorRejection(res) {
382
- if (res.status !== 400) return null;
383
- try {
384
- const body = await res.json();
385
- return isRecord(body) ? body : null;
386
- } catch {
387
- return null;
388
- }
389
- }
390
245
  var PAYMENT_SCHEME_DECODERS = {
391
246
  exact: decodeExactPayment
392
247
  };
@@ -446,8 +301,6 @@ function isOptionalRecord(value) {
446
301
 
447
302
  export {
448
303
  X402_DEFAULT_FACILITATOR,
449
- createX402FacilitatorAuthHeaders,
450
- createX402FacilitatorClient,
451
304
  X402_NETWORKS,
452
305
  x402NetworkByCaip2,
453
306
  x402NetworkBySlug,
@@ -475,7 +328,5 @@ export {
475
328
  encodePaymentRequiredHeader,
476
329
  decodePaymentRequiredHeader,
477
330
  exactEvmAuthorization,
478
- encodeSettleResponseHeader,
479
- verifyWithFacilitator,
480
- settleWithFacilitator
331
+ encodeSettleResponseHeader
481
332
  };
@@ -10,9 +10,9 @@ import {
10
10
  isDrainMethod,
11
11
  isFundingRail,
12
12
  x402SettlementPending
13
- } from "./chunk-LWUR4CGG.js";
14
- import "./chunk-C3MTFLC6.js";
13
+ } from "./chunk-MLRCSJYX.js";
15
14
  import "./chunk-S3XAHZQY.js";
15
+ import "./chunk-C3MTFLC6.js";
16
16
  export {
17
17
  CreditLedger,
18
18
  CreditLedgerError,