x402z-facilitator 0.0.3 → 0.0.4

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.
@@ -1,104 +1,7 @@
1
1
  import {
2
- ConfidentialEvmFacilitator,
3
- __require,
4
- createFacilitatorService
5
- } from "./chunk-4LCQ4MN3.mjs";
6
-
7
- // src/bootstrap.ts
8
- import { x402Facilitator } from "@x402/core/facilitator";
9
- import { toFacilitatorEvmSigner } from "@x402/evm";
10
- import { createWalletClient, http, publicActions } from "viem";
11
- import { privateKeyToAccount } from "viem/accounts";
12
- function requireEnv(key) {
13
- const value = process.env[key];
14
- if (!value) {
15
- throw new Error(`Missing required env var: ${key}`);
16
- }
17
- return value;
18
- }
19
- function createConfidentialFacilitatorFromEnv() {
20
- const privateKey = requireEnv("FACILITATOR_EVM_PRIVATE_KEY");
21
- const chainId = Number(process.env.FACILITATOR_EVM_CHAIN_ID ?? "11155111");
22
- const rpcUrl = requireEnv("FACILITATOR_EVM_RPC_URL");
23
- const networks = (process.env.FACILITATOR_NETWORKS ?? "eip155:11155111").split(",").map((network) => network.trim()).filter(Boolean);
24
- const waitForReceipt = (process.env.FACILITATOR_WAIT_FOR_RECEIPT ?? "true") === "true";
25
- const receiptTimeoutMs = process.env.FACILITATOR_RECEIPT_TIMEOUT_MS ? Number(process.env.FACILITATOR_RECEIPT_TIMEOUT_MS) : void 0;
26
- const receiptConfirmations = process.env.FACILITATOR_RECEIPT_CONFIRMATIONS ? Number(process.env.FACILITATOR_RECEIPT_CONFIRMATIONS) : void 0;
27
- const receiptPollingIntervalMs = process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS ? Number(process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS) : void 0;
28
- const debugEnabled = process.env.X402Z_DEBUG === "1";
29
- const account = privateKeyToAccount(privateKey);
30
- if (debugEnabled) {
31
- console.debug("[x402z-facilitator] config", {
32
- chainId,
33
- networks,
34
- rpcUrl,
35
- waitForReceipt,
36
- receipt: {
37
- confirmations: receiptConfirmations,
38
- timeoutMs: receiptTimeoutMs,
39
- pollingIntervalMs: receiptPollingIntervalMs
40
- },
41
- address: account.address
42
- });
43
- }
44
- const client = createWalletClient({
45
- account,
46
- chain: {
47
- id: chainId,
48
- name: "custom",
49
- nativeCurrency: { name: "native", symbol: "NATIVE", decimals: 18 },
50
- rpcUrls: { default: { http: [rpcUrl] } }
51
- },
52
- transport: http(rpcUrl)
53
- }).extend(publicActions);
54
- const signer = toFacilitatorEvmSigner({
55
- address: account.address,
56
- readContract: (args) => client.readContract({
57
- ...args,
58
- args: args.args || []
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- }),
61
- verifyTypedData: (args) => client.verifyTypedData(args),
62
- writeContract: (args) => client.writeContract({
63
- ...args,
64
- args: args.args || []
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- }),
67
- sendTransaction: (args) => (
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- client.sendTransaction({ to: args.to, data: args.data })
70
- ),
71
- waitForTransactionReceipt: (args) => client.waitForTransactionReceipt(args),
72
- getCode: (args) => client.getCode(args)
73
- });
74
- const facilitator = new x402Facilitator();
75
- for (const network of networks) {
76
- facilitator.register(
77
- network,
78
- new ConfidentialEvmFacilitator({
79
- signer,
80
- waitForReceipt,
81
- receipt: {
82
- confirmations: receiptConfirmations,
83
- timeoutMs: receiptTimeoutMs,
84
- pollingIntervalMs: receiptPollingIntervalMs
85
- }
86
- })
87
- );
88
- }
89
- return facilitator;
90
- }
91
- function startConfidentialFacilitator() {
92
- const facilitator = createConfidentialFacilitatorFromEnv();
93
- const port = Number(process.env.FACILITATOR_PORT ?? "8040");
94
- const server = createFacilitatorService({ facilitator, port });
95
- server.listen(port);
96
- return { port };
97
- }
98
- if (__require.main === module) {
99
- const { port } = startConfidentialFacilitator();
100
- console.log(`Confidential facilitator listening on :${port}`);
101
- }
2
+ createConfidentialFacilitatorFromEnv,
3
+ startConfidentialFacilitator
4
+ } from "./chunk-H6QEA2EB.mjs";
102
5
  export {
103
6
  createConfidentialFacilitatorFromEnv,
104
7
  startConfidentialFacilitator
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import { FacilitatorEvmSigner } from '@x402/evm';
3
3
  import { x402Facilitator } from '@x402/core/facilitator';
4
4
  import * as http from 'http';
5
5
  import { IncomingMessage, ServerResponse } from 'node:http';
6
+ export { startConfidentialFacilitator } from './bootstrap.mjs';
6
7
 
7
8
  type ConfidentialFacilitatorConfig = {
8
9
  signer: FacilitatorEvmSigner;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { FacilitatorEvmSigner } from '@x402/evm';
3
3
  import { x402Facilitator } from '@x402/core/facilitator';
4
4
  import * as http from 'http';
5
5
  import { IncomingMessage, ServerResponse } from 'node:http';
6
+ export { startConfidentialFacilitator } from './bootstrap.js';
6
7
 
7
8
  type ConfidentialFacilitatorConfig = {
8
9
  signer: FacilitatorEvmSigner;
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  ConfidentialEvmFacilitator: () => ConfidentialEvmFacilitator,
24
24
  createFacilitatorService: () => createFacilitatorService,
25
25
  registerConfidentialEvmScheme: () => registerConfidentialEvmScheme,
26
+ startConfidentialFacilitator: () => startConfidentialFacilitator,
26
27
  startFacilitatorService: () => startFacilitatorService
27
28
  });
28
29
  module.exports = __toCommonJS(index_exports);
@@ -272,10 +273,107 @@ function startFacilitatorService(config) {
272
273
  server.listen(port);
273
274
  return { port };
274
275
  }
276
+
277
+ // src/bootstrap.ts
278
+ var import_facilitator = require("@x402/core/facilitator");
279
+ var import_evm = require("@x402/evm");
280
+ var import_viem2 = require("viem");
281
+ var import_accounts = require("viem/accounts");
282
+ function requireEnv(key) {
283
+ const value = process.env[key];
284
+ if (!value) {
285
+ throw new Error(`Missing required env var: ${key}`);
286
+ }
287
+ return value;
288
+ }
289
+ function createConfidentialFacilitatorFromEnv() {
290
+ const privateKey = requireEnv("FACILITATOR_EVM_PRIVATE_KEY");
291
+ const chainId = Number(process.env.FACILITATOR_EVM_CHAIN_ID ?? "11155111");
292
+ const rpcUrl = requireEnv("FACILITATOR_EVM_RPC_URL");
293
+ const networks = (process.env.FACILITATOR_NETWORKS ?? "eip155:11155111").split(",").map((network) => network.trim()).filter(Boolean);
294
+ const waitForReceipt = (process.env.FACILITATOR_WAIT_FOR_RECEIPT ?? "true") === "true";
295
+ const receiptTimeoutMs = process.env.FACILITATOR_RECEIPT_TIMEOUT_MS ? Number(process.env.FACILITATOR_RECEIPT_TIMEOUT_MS) : void 0;
296
+ const receiptConfirmations = process.env.FACILITATOR_RECEIPT_CONFIRMATIONS ? Number(process.env.FACILITATOR_RECEIPT_CONFIRMATIONS) : void 0;
297
+ const receiptPollingIntervalMs = process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS ? Number(process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS) : void 0;
298
+ const debugEnabled = process.env.X402Z_DEBUG === "1";
299
+ const account = (0, import_accounts.privateKeyToAccount)(privateKey);
300
+ if (debugEnabled) {
301
+ console.debug("[x402z-facilitator] config", {
302
+ chainId,
303
+ networks,
304
+ rpcUrl,
305
+ waitForReceipt,
306
+ receipt: {
307
+ confirmations: receiptConfirmations,
308
+ timeoutMs: receiptTimeoutMs,
309
+ pollingIntervalMs: receiptPollingIntervalMs
310
+ },
311
+ address: account.address
312
+ });
313
+ }
314
+ const client = (0, import_viem2.createWalletClient)({
315
+ account,
316
+ chain: {
317
+ id: chainId,
318
+ name: "custom",
319
+ nativeCurrency: { name: "native", symbol: "NATIVE", decimals: 18 },
320
+ rpcUrls: { default: { http: [rpcUrl] } }
321
+ },
322
+ transport: (0, import_viem2.http)(rpcUrl)
323
+ }).extend(import_viem2.publicActions);
324
+ const signer = (0, import_evm.toFacilitatorEvmSigner)({
325
+ address: account.address,
326
+ readContract: (args) => client.readContract({
327
+ ...args,
328
+ args: args.args || []
329
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
330
+ }),
331
+ verifyTypedData: (args) => client.verifyTypedData(args),
332
+ writeContract: (args) => client.writeContract({
333
+ ...args,
334
+ args: args.args || []
335
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
336
+ }),
337
+ sendTransaction: (args) => (
338
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
339
+ client.sendTransaction({ to: args.to, data: args.data })
340
+ ),
341
+ waitForTransactionReceipt: (args) => client.waitForTransactionReceipt(args),
342
+ getCode: (args) => client.getCode(args)
343
+ });
344
+ const facilitator = new import_facilitator.x402Facilitator();
345
+ for (const network of networks) {
346
+ facilitator.register(
347
+ network,
348
+ new ConfidentialEvmFacilitator({
349
+ signer,
350
+ waitForReceipt,
351
+ receipt: {
352
+ confirmations: receiptConfirmations,
353
+ timeoutMs: receiptTimeoutMs,
354
+ pollingIntervalMs: receiptPollingIntervalMs
355
+ }
356
+ })
357
+ );
358
+ }
359
+ return facilitator;
360
+ }
361
+ function startConfidentialFacilitator() {
362
+ const facilitator = createConfidentialFacilitatorFromEnv();
363
+ const port = Number(process.env.FACILITATOR_PORT ?? "8040");
364
+ const server = createFacilitatorService({ facilitator, port });
365
+ server.listen(port);
366
+ return { port };
367
+ }
368
+ if (require.main === module) {
369
+ const { port } = startConfidentialFacilitator();
370
+ console.log(`Confidential facilitator listening on :${port}`);
371
+ }
275
372
  // Annotate the CommonJS export names for ESM import in node:
276
373
  0 && (module.exports = {
277
374
  ConfidentialEvmFacilitator,
278
375
  createFacilitatorService,
279
376
  registerConfidentialEvmScheme,
377
+ startConfidentialFacilitator,
280
378
  startFacilitatorService
281
379
  });
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  ConfidentialEvmFacilitator,
3
3
  createFacilitatorService,
4
+ startConfidentialFacilitator,
4
5
  startFacilitatorService
5
- } from "./chunk-4LCQ4MN3.mjs";
6
+ } from "./chunk-H6QEA2EB.mjs";
6
7
 
7
8
  // src/register.ts
8
9
  function registerConfidentialEvmScheme(facilitator, config) {
@@ -17,5 +18,6 @@ export {
17
18
  ConfidentialEvmFacilitator,
18
19
  createFacilitatorService,
19
20
  registerConfidentialEvmScheme,
21
+ startConfidentialFacilitator,
20
22
  startFacilitatorService
21
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-facilitator",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "@x402/core": "^2.0.0",
12
12
  "@x402/evm": "^2.0.0",
13
13
  "viem": "^2.39.3",
14
- "x402z-shared": "0.0.2"
14
+ "x402z-shared": "0.0.3"
15
15
  },
16
16
  "devDependencies": {
17
17
  "jest": "^29.7.0",