@dvmkit/sdk 0.1.1-rc.7 → 0.1.3-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 (47) hide show
  1. package/README.md +14 -0
  2. package/dist/chunk-2K7E3N2D.js +1709 -0
  3. package/dist/{chunk-Y6W5ZZTW.js → chunk-3ZHMQCYP.js} +666 -3031
  4. package/dist/{chunk-TKA6ZP4M.js → chunk-4B56DEEV.js} +50 -426
  5. package/dist/{chunk-X3IKFWJA.js → chunk-6BQM7TOW.js} +4 -1
  6. package/dist/chunk-BIFLRKMO.js +87 -0
  7. package/dist/chunk-BQ2NMWKE.js +160 -0
  8. package/dist/{chunk-LDTWX7JW.js → chunk-BTZY7VPH.js} +13 -1
  9. package/dist/{chunk-FJDCFHW5.js → chunk-C6JHBLMW.js} +3 -81
  10. package/dist/{chunk-EXHBXA4U.js → chunk-DBCLBYHP.js} +13 -1
  11. package/dist/chunk-EPNDZ5DH.js +1010 -0
  12. package/dist/{chunk-P4RUVDU7.js → chunk-H2MEFVH6.js} +12 -141
  13. package/dist/chunk-KXZUCCEY.js +142 -0
  14. package/dist/{chunk-6JZIX5WW.js → chunk-LLXV32HA.js} +82 -5
  15. package/dist/{chunk-LWUR4CGG.js → chunk-MLRCSJYX.js} +11 -3
  16. package/dist/{chunk-2ABMGUDS.js → chunk-NFRM5QYP.js} +83 -10
  17. package/dist/chunk-RW5LP57K.js +44 -0
  18. package/dist/chunk-YDIYXGYL.js +384 -0
  19. package/dist/{chunk-JGGI65I3.js → chunk-Z4BNLUZF.js} +1 -150
  20. package/dist/{credit-ledger-ED6JXKVD.js → credit-ledger-2DFQHNLB.js} +2 -2
  21. package/dist/{credit-menu-BrTfAr7l.d.ts → credit-menu-C7zAJElJ.d.ts} +1632 -1946
  22. package/dist/{fx-H6K6qcH1.d.ts → fx-BF_SG2i0.d.ts} +1 -1
  23. package/dist/index.d.ts +7 -6
  24. package/dist/index.js +8 -4
  25. package/dist/internal/caller.d.ts +10429 -0
  26. package/dist/internal/caller.js +9957 -0
  27. package/dist/internal/index.d.ts +2 -10816
  28. package/dist/internal/index.js +2 -10130
  29. package/dist/internal/server.d.ts +404 -0
  30. package/dist/internal/server.js +202 -0
  31. package/dist/job-store-Bn23V3QU.d.ts +576 -0
  32. package/dist/lightning-backend-C04nH94l.d.ts +367 -0
  33. package/dist/{memory-credit-ledger-XJ5VQEVP.js → memory-credit-ledger-OP24Z2KO.js} +3 -3
  34. package/dist/{payout-reporter-3UB5WRCV.js → payout-reporter-RG6XNGPI.js} +1 -1
  35. package/dist/{postgres-job-store-J5F4GUWU.js → postgres-job-store-TAONYLIF.js} +1 -1
  36. package/dist/{revenue-reporter-JIKUPXOK.js → revenue-reporter-XXSU5KVB.js} +1 -1
  37. package/dist/server/index.d.ts +27 -11
  38. package/dist/server/index.js +93 -69
  39. package/dist/{job-store-DOSfYnLX.d.ts → step-cache-3cT4Shk0.d.ts} +38 -585
  40. package/dist/{tempo-session-store-DALMRIWN.js → tempo-session-store-2JNOKJGX.js} +2 -2
  41. package/dist/testing/index.d.ts +16 -4
  42. package/dist/testing/index.js +7 -3
  43. package/dist/{usd-Civ738b3.d.ts → usd-BnuXoFl5.d.ts} +1 -1
  44. package/dist/wallet-CJC8lwxx.d.ts +29 -0
  45. package/dist/{x402-FTG2GRAQ.js → x402-T2C5MX3T.js} +6 -3
  46. package/package.json +7 -2
  47. package/dist/{chunk-RU7SXHLO.js → chunk-UP2F5RRT.js} +3 -3
@@ -0,0 +1,44 @@
1
+ // src/sdk/store.ts
2
+ var MemoryKVStore = class {
3
+ data = /* @__PURE__ */ new Map();
4
+ /** Retrieve a value by key. Returns undefined if not found or expired. */
5
+ get(key) {
6
+ const entry = this.data.get(key);
7
+ if (!entry) return Promise.resolve(void 0);
8
+ if (entry.expiry !== void 0 && Date.now() > entry.expiry) {
9
+ this.data.delete(key);
10
+ return Promise.resolve(void 0);
11
+ }
12
+ return Promise.resolve(entry.value);
13
+ }
14
+ /** Store a value. Optionally set a TTL in seconds. */
15
+ set(key, value, opts) {
16
+ const expiry = opts?.ttl !== void 0 ? Date.now() + opts.ttl * 1e3 : void 0;
17
+ this.data.set(key, { value, expiry });
18
+ return Promise.resolve();
19
+ }
20
+ /** Delete a key. */
21
+ delete(key) {
22
+ this.data.delete(key);
23
+ return Promise.resolve();
24
+ }
25
+ /** List keys, optionally filtered by prefix. Excludes expired entries. */
26
+ list(prefix) {
27
+ const now = Date.now();
28
+ const keys = [];
29
+ for (const [key, entry] of this.data) {
30
+ if (entry.expiry !== void 0 && now > entry.expiry) {
31
+ this.data.delete(key);
32
+ continue;
33
+ }
34
+ if (prefix === void 0 || key.startsWith(prefix)) {
35
+ keys.push(key);
36
+ }
37
+ }
38
+ return Promise.resolve(keys);
39
+ }
40
+ };
41
+
42
+ export {
43
+ MemoryKVStore
44
+ };
@@ -0,0 +1,384 @@
1
+ import {
2
+ initCallerLoggers
3
+ } from "./chunk-66HGCPBU.js";
4
+
5
+ // src/sdk/step-cache.ts
6
+ var StepCache = class _StepCache {
7
+ cache = /* @__PURE__ */ new Map();
8
+ /** Check if a step result is cached. */
9
+ has(id) {
10
+ return this.cache.has(id);
11
+ }
12
+ /** Get a cached step result. Throws if not present. */
13
+ get(id) {
14
+ if (!this.cache.has(id)) {
15
+ throw new Error(`StepCache: no cached result for step "${id}"`);
16
+ }
17
+ return this.cache.get(id);
18
+ }
19
+ /** Cache a step result. */
20
+ set(id, value) {
21
+ this.cache.set(id, value);
22
+ }
23
+ /** Export all cached steps for persistence. */
24
+ serialize() {
25
+ return [...this.cache.entries()].map(([id, value]) => ({ id, value }));
26
+ }
27
+ /** Restore a StepCache from persisted records. */
28
+ static deserialize(records) {
29
+ const cache = new _StepCache();
30
+ for (const { id, value } of records) {
31
+ cache.set(id, value);
32
+ }
33
+ return cache;
34
+ }
35
+ };
36
+
37
+ // src/sdk/logger.ts
38
+ function createConsoleLogger(jobId) {
39
+ const fmt = (message, data) => {
40
+ const parts = [`[${jobId}] ${message}`];
41
+ if (data) parts.push(data);
42
+ return parts;
43
+ };
44
+ return {
45
+ debug(message, data) {
46
+ console.debug(...fmt(message, data));
47
+ },
48
+ info(message, data) {
49
+ console.info(...fmt(message, data));
50
+ },
51
+ warn(message, data) {
52
+ console.warn(...fmt(message, data));
53
+ },
54
+ error(message, data) {
55
+ console.error(...fmt(message, data));
56
+ }
57
+ };
58
+ }
59
+ function createStdoutLogger(context) {
60
+ const emit = (sink, level) => (message, data) => {
61
+ sink(JSON.stringify({ level, msg: message, ...context, ...data }));
62
+ };
63
+ return {
64
+ debug: emit(console.debug.bind(console), "debug"),
65
+ info: emit(console.info.bind(console), "info"),
66
+ warn: emit(console.warn.bind(console), "warn"),
67
+ error: emit(console.error.bind(console), "error")
68
+ };
69
+ }
70
+ function createNoopLogger() {
71
+ const noop2 = () => {
72
+ };
73
+ return { debug: noop2, info: noop2, warn: noop2, error: noop2 };
74
+ }
75
+
76
+ // src/observability/context.ts
77
+ import { AsyncLocalStorage } from "async_hooks";
78
+ import { randomBytes, randomUUID } from "crypto";
79
+ var storage = new AsyncLocalStorage();
80
+ var defaultService = "unknown";
81
+ function setDefaultService(service) {
82
+ defaultService = service;
83
+ }
84
+ function randomTraceId() {
85
+ const buf = randomBytes(16);
86
+ const now = Date.now();
87
+ buf.writeUInt16BE(Math.floor(now / 4294967296), 0);
88
+ buf.writeUInt32BE(now % 4294967296, 2);
89
+ buf[6] = buf[6] & 15 | 112;
90
+ buf[8] = buf[8] & 63 | 128;
91
+ return buf.toString("hex");
92
+ }
93
+ function randomSpanId() {
94
+ return randomUUID().replace(/-/g, "").slice(0, 16);
95
+ }
96
+ function withTraceContext(ctx, fn) {
97
+ return storage.run(ctx, fn);
98
+ }
99
+ function currentContext(service) {
100
+ const ctx = storage.getStore();
101
+ if (ctx) return ctx;
102
+ return {
103
+ traceId: randomTraceId(),
104
+ spanId: null,
105
+ dimensions: {},
106
+ service: service ?? defaultService
107
+ };
108
+ }
109
+ function pinDimension(key, value) {
110
+ const ctx = storage.getStore();
111
+ if (ctx) {
112
+ ctx.dimensions = { ...ctx.dimensions, [key]: value };
113
+ }
114
+ }
115
+ function rawContext() {
116
+ return storage.getStore();
117
+ }
118
+
119
+ // src/observability/with-span.ts
120
+ import { hostname } from "os";
121
+
122
+ // src/observability/stdout-sink.ts
123
+ var SENSITIVE_KEY_RE = /secret|token|password|private|bearer|seed|preimage|api[_-]?key|signing[_-]?key|priv[_-]?key/i;
124
+ var isTTY = typeof process.stdout.isTTY === "boolean" && process.stdout.isTTY;
125
+ var RED = isTTY ? "\x1B[31m" : "";
126
+ var YELLOW = isTTY ? "\x1B[33m" : "";
127
+ var RESET = isTTY ? "\x1B[0m" : "";
128
+ function formatSpanLine(span) {
129
+ const ts = new Date(span.started_at_ms).toISOString();
130
+ const levelStr = colorLevel(span.level);
131
+ const parts = [`[${ts}]`, span.dataset, `${levelStr}:`, span.name];
132
+ if (span.trace_id) {
133
+ parts.push(`trace=${span.trace_id}`);
134
+ }
135
+ for (const [k, v] of Object.entries(span.dimensions)) {
136
+ parts.push(formatKV(k, v));
137
+ }
138
+ for (const [k, v] of Object.entries(span.attributes)) {
139
+ parts.push(formatKV(k, v));
140
+ }
141
+ const durationMs = span.ended_at_ms - span.started_at_ms;
142
+ if (durationMs > 0) {
143
+ parts.push(`duration=${durationMs}ms`);
144
+ }
145
+ if (span.error_message) {
146
+ parts.push(`error=${truncate(span.error_message, 120)}`);
147
+ }
148
+ return parts.join(" ");
149
+ }
150
+ function writeSpanLine(span) {
151
+ const line = formatSpanLine(span);
152
+ process.stdout.write(line + "\n");
153
+ }
154
+ function colorLevel(level) {
155
+ if (level === "error") return `${RED}error${RESET}`;
156
+ if (level === "warn") return `${YELLOW}warn${RESET}`;
157
+ return level;
158
+ }
159
+ function formatKV(key, value) {
160
+ if (SENSITIVE_KEY_RE.test(key)) return `${key}=[REDACTED]`;
161
+ return `${key}=${truncate(stringify(value), 80)}`;
162
+ }
163
+ function stringify(value) {
164
+ if (typeof value === "string") return value;
165
+ if (value === void 0) return "undefined";
166
+ if (value === null) return "null";
167
+ if (typeof value === "function") return "[function]";
168
+ if (typeof value === "symbol") return value.toString();
169
+ if (typeof value === "bigint") return value.toString();
170
+ return JSON.stringify(value);
171
+ }
172
+ function truncate(s, max) {
173
+ if (s.length <= max) return s;
174
+ return s.slice(0, max - 3) + "...";
175
+ }
176
+
177
+ // src/observability/with-span.ts
178
+ var emitter = null;
179
+ function setEmitter(fn) {
180
+ emitter = fn;
181
+ }
182
+ var cachedHost = hostname();
183
+ var serviceVersion = process.env.GIT_SHA ?? process.env.FLY_IMAGE_REF ?? "dev";
184
+ async function withSpan(opts, fn) {
185
+ const spanId = randomSpanId();
186
+ const existingCtx = rawContext();
187
+ const ctx = existingCtx ?? currentContext();
188
+ const startMs = opts.startMs ?? Date.now();
189
+ let status = "ok";
190
+ let level = opts.level;
191
+ let errorMessage = null;
192
+ let errorStack = null;
193
+ if (opts.err) {
194
+ status = "error";
195
+ errorMessage = opts.err.message;
196
+ errorStack = opts.err.stack ?? null;
197
+ }
198
+ const childCtx = {
199
+ traceId: ctx.traceId,
200
+ spanId,
201
+ dimensions: { ...ctx.dimensions, ...opts.dims },
202
+ service: ctx.service,
203
+ tracestate: ctx.tracestate
204
+ };
205
+ const emitRow = () => {
206
+ const endMs = opts.endMs ?? Date.now();
207
+ const row = {
208
+ span_id: spanId,
209
+ trace_id: ctx.traceId,
210
+ parent_span_id: ctx.spanId,
211
+ dataset: opts.dataset,
212
+ name: opts.name,
213
+ level: level ?? (status === "error" ? "error" : "info"),
214
+ status,
215
+ started_at_ms: startMs,
216
+ ended_at_ms: endMs,
217
+ service: ctx.service,
218
+ service_version: serviceVersion,
219
+ host: cachedHost,
220
+ pid: process.pid,
221
+ dimensions: childCtx.dimensions,
222
+ attributes: opts.attrs ?? {},
223
+ error_message: errorMessage,
224
+ error_stack: errorStack,
225
+ sample_rate: 1
226
+ };
227
+ writeSpanLine(row);
228
+ if (emitter) emitter(row);
229
+ };
230
+ try {
231
+ const result = await withTraceContext(childCtx, () => fn());
232
+ if (opts.inspect) {
233
+ const overrides = opts.inspect(result);
234
+ if (overrides) {
235
+ if (overrides.status) status = overrides.status;
236
+ if (overrides.level) level = overrides.level;
237
+ if (overrides.errorMessage !== void 0) errorMessage = overrides.errorMessage;
238
+ if (overrides.attrs) Object.assign(opts.attrs ??= {}, overrides.attrs);
239
+ }
240
+ }
241
+ emitRow();
242
+ return result;
243
+ } catch (err) {
244
+ status = "error";
245
+ if (err instanceof Error) {
246
+ errorMessage = err.message;
247
+ errorStack = err.stack ?? null;
248
+ } else {
249
+ errorMessage = String(err);
250
+ }
251
+ if (opts.onError) {
252
+ const overrides = opts.onError(err);
253
+ if (overrides) Object.assign(opts.attrs ??= {}, overrides);
254
+ }
255
+ emitRow();
256
+ throw err;
257
+ }
258
+ }
259
+
260
+ // src/observability/datasets.ts
261
+ var SPANS_DATASETS = [
262
+ { name: "platform", retentionDays: 90 },
263
+ { name: "cashu", retentionDays: 90 },
264
+ { name: "lightning", retentionDays: 90 },
265
+ { name: "stripe", retentionDays: 90 },
266
+ { name: "x402", retentionDays: 90 },
267
+ { name: "tempo", retentionDays: 90 },
268
+ { name: "isolate", retentionDays: 90 },
269
+ { name: "audit", retentionDays: 365 },
270
+ { name: "cron", retentionDays: 30 }
271
+ ];
272
+ var DATASET_NAMES = new Set(SPANS_DATASETS.map((d) => d.name));
273
+
274
+ // src/observability/loggers.ts
275
+ var noop = () => {
276
+ };
277
+ var loggers = buildNoopLoggers();
278
+ function initLoggers(writer, service) {
279
+ setEmitter((row) => {
280
+ writer.enqueue(row);
281
+ });
282
+ setDefaultService(service);
283
+ const result = {};
284
+ for (const ds of SPANS_DATASETS) {
285
+ result[ds.name] = createLogger(ds.name, {});
286
+ }
287
+ loggers = result;
288
+ initCallerLoggers(result);
289
+ return result;
290
+ }
291
+ function createLogger(dataset, bakedDims) {
292
+ const logger = {
293
+ info(name, attrs) {
294
+ void withSpan({ dataset, name, level: "info", attrs, dims: bakedDims }, noop).catch(noop);
295
+ },
296
+ warn(name, attrs) {
297
+ void withSpan({ dataset, name, level: "warn", attrs, dims: bakedDims }, noop).catch(noop);
298
+ },
299
+ error(name, attrs) {
300
+ const err = attrs?.err instanceof Error ? attrs.err : void 0;
301
+ const cleanAttrs = attrs ? { ...attrs } : void 0;
302
+ if (cleanAttrs) delete cleanAttrs.err;
303
+ void withSpan(
304
+ { dataset, name, level: "error", attrs: cleanAttrs, dims: bakedDims, err },
305
+ noop
306
+ ).catch(noop);
307
+ },
308
+ async span(name, attrs, fn, opts) {
309
+ return withSpan({ dataset, name, attrs, dims: bakedDims, onError: opts?.onError }, fn);
310
+ },
311
+ timer(name, attrs) {
312
+ const startMs = Date.now();
313
+ return {
314
+ [Symbol.dispose]() {
315
+ const endMs = Date.now();
316
+ void withSpan({ dataset, name, attrs, dims: bakedDims, startMs, endMs }, noop).catch(
317
+ noop
318
+ );
319
+ }
320
+ };
321
+ },
322
+ set(dims) {
323
+ for (const [k, v] of Object.entries(dims)) {
324
+ pinDimension(k, v);
325
+ }
326
+ },
327
+ extend(dims) {
328
+ return createLogger(dataset, { ...bakedDims, ...dims });
329
+ },
330
+ tracked(name, fn) {
331
+ return ((...args) => logger.span(name, {}, () => fn(...args)));
332
+ }
333
+ };
334
+ return logger;
335
+ }
336
+ function buildNoopLoggers() {
337
+ const noopLogger = {
338
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
339
+ info() {
340
+ },
341
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
342
+ warn() {
343
+ },
344
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
345
+ error() {
346
+ },
347
+ async span(_name, _attrs, fn, _opts) {
348
+ return fn();
349
+ },
350
+ timer() {
351
+ return { [Symbol.dispose]() {
352
+ } };
353
+ },
354
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
355
+ set() {
356
+ },
357
+ extend() {
358
+ return noopLogger;
359
+ },
360
+ tracked(_name, fn) {
361
+ return fn;
362
+ }
363
+ };
364
+ const result = {};
365
+ for (const ds of SPANS_DATASETS) {
366
+ result[ds.name] = noopLogger;
367
+ }
368
+ return result;
369
+ }
370
+
371
+ export {
372
+ StepCache,
373
+ createConsoleLogger,
374
+ createStdoutLogger,
375
+ createNoopLogger,
376
+ randomTraceId,
377
+ withTraceContext,
378
+ currentContext,
379
+ pinDimension,
380
+ setEmitter,
381
+ withSpan,
382
+ loggers,
383
+ initLoggers
384
+ };
@@ -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,