x402z-facilitator 0.0.10 → 0.0.12

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.
@@ -0,0 +1,636 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/service/bootstrap.ts
9
+ import { x402Facilitator } from "@x402/core/facilitator";
10
+ import { toFacilitatorEvmSigner } from "@x402/evm";
11
+ import { createWalletClient, http, publicActions } from "viem";
12
+ import { privateKeyToAccount } from "viem/accounts";
13
+
14
+ // src/service/service.ts
15
+ import { createServer } from "http";
16
+ async function readJson(req) {
17
+ const chunks = [];
18
+ for await (const chunk of req) {
19
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
20
+ }
21
+ const body = Buffer.concat(chunks).toString("utf8");
22
+ return JSON.parse(body);
23
+ }
24
+ function sendJson(res, status, payload) {
25
+ res.writeHead(status, { "content-type": "application/json" });
26
+ res.end(JSON.stringify(payload));
27
+ }
28
+ function createFacilitatorService(config) {
29
+ const server = createServer(async (req, res) => {
30
+ try {
31
+ const method = req.method ?? "GET";
32
+ const url = req.url ?? "/";
33
+ if (process.env.X402Z_DEBUG === "1") {
34
+ console.debug(`[x402z-facilitator] ${method} ${url}`);
35
+ }
36
+ if (!req.url) {
37
+ sendJson(res, 404, { error: "not_found" });
38
+ return;
39
+ }
40
+ if (req.method === "GET" && req.url === "/supported") {
41
+ sendJson(res, 200, config.facilitator.getSupported());
42
+ return;
43
+ }
44
+ if (req.method === "POST" && req.url === "/verify") {
45
+ const body = await readJson(req);
46
+ const result = await config.facilitator.verify(body.paymentPayload, body.paymentRequirements);
47
+ sendJson(res, 200, result);
48
+ return;
49
+ }
50
+ if (req.method === "POST" && req.url === "/settle") {
51
+ const body = await readJson(req);
52
+ const result = await config.facilitator.settle(body.paymentPayload, body.paymentRequirements);
53
+ sendJson(res, 200, result);
54
+ return;
55
+ }
56
+ sendJson(res, 404, { error: "not_found" });
57
+ } catch (error) {
58
+ const message = error instanceof Error ? error.message : "internal_error";
59
+ sendJson(res, 500, { error: message });
60
+ }
61
+ });
62
+ return server;
63
+ }
64
+ function startFacilitatorService(config) {
65
+ const port = config.port ?? 8040;
66
+ const server = createFacilitatorService(config);
67
+ server.listen(port);
68
+ return { port };
69
+ }
70
+
71
+ // src/scheme/scheme.ts
72
+ import { decodeEventLog, getAddress, isAddressEqual } from "viem";
73
+ import {
74
+ confidentialPaymentTypes,
75
+ confidentialTokenAbi,
76
+ hashEncryptedAmountInput
77
+ } from "x402z-shared";
78
+ var batcherAbi = [
79
+ {
80
+ inputs: [
81
+ { internalType: "address", name: "token", type: "address" },
82
+ {
83
+ components: [
84
+ {
85
+ components: [
86
+ { internalType: "address", name: "holder", type: "address" },
87
+ { internalType: "address", name: "payee", type: "address" },
88
+ { internalType: "uint256", name: "maxClearAmount", type: "uint256" },
89
+ { internalType: "bytes32", name: "resourceHash", type: "bytes32" },
90
+ { internalType: "uint48", name: "validAfter", type: "uint48" },
91
+ { internalType: "uint48", name: "validBefore", type: "uint48" },
92
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
93
+ { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
94
+ ],
95
+ internalType: "struct IFHEToken.ConfidentialPayment",
96
+ name: "p",
97
+ type: "tuple"
98
+ },
99
+ { internalType: "externalEuint64", name: "encryptedAmountInput", type: "bytes32" },
100
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
101
+ { internalType: "bytes", name: "sig", type: "bytes" }
102
+ ],
103
+ internalType: "struct FHETokenBatcher.Request[]",
104
+ name: "requests",
105
+ type: "tuple[]"
106
+ }
107
+ ],
108
+ name: "batchConfidentialTransferWithAuthorization",
109
+ outputs: [
110
+ { internalType: "bool[]", name: "successes", type: "bool[]" },
111
+ { internalType: "bytes32[]", name: "transferredHandles", type: "bytes32[]" }
112
+ ],
113
+ stateMutability: "nonpayable",
114
+ type: "function"
115
+ },
116
+ {
117
+ anonymous: false,
118
+ inputs: [
119
+ { indexed: true, internalType: "uint256", name: "index", type: "uint256" },
120
+ { indexed: false, internalType: "bytes32", name: "transferredHandle", type: "bytes32" }
121
+ ],
122
+ name: "BatchItemSuccess",
123
+ type: "event"
124
+ },
125
+ {
126
+ anonymous: false,
127
+ inputs: [
128
+ { indexed: true, internalType: "uint256", name: "index", type: "uint256" },
129
+ { indexed: false, internalType: "bytes", name: "reason", type: "bytes" }
130
+ ],
131
+ name: "BatchItemFailure",
132
+ type: "event"
133
+ }
134
+ ];
135
+ var X402zEvmFacilitator = class {
136
+ constructor(config) {
137
+ this.config = config;
138
+ this.scheme = "erc7984-mind-v1";
139
+ this.caipFamily = "eip155:*";
140
+ this.queue = [];
141
+ this.hashFn = config.hashEncryptedAmountInput ?? hashEncryptedAmountInput;
142
+ this.clock = config.clock ?? (() => Math.floor(Date.now() / 1e3));
143
+ this.checkUsedNonces = config.checkUsedNonces ?? true;
144
+ this.waitForReceipt = config.waitForReceipt ?? true;
145
+ this.batchIntervalMs = Math.max(0, config.batchIntervalMs ?? 15e3);
146
+ this.receiptOptions = config.receipt;
147
+ this.batcherAddress = getAddress(config.batcherAddress);
148
+ }
149
+ getExtra(_) {
150
+ return void 0;
151
+ }
152
+ getSigners(_) {
153
+ return [...this.config.signer.getAddresses()];
154
+ }
155
+ async verify(payload, requirements) {
156
+ const confidentialPayload = payload.payload;
157
+ if (payload.accepted.scheme !== this.scheme || requirements.scheme !== this.scheme) {
158
+ return {
159
+ isValid: false,
160
+ invalidReason: "unsupported_scheme",
161
+ payer: confidentialPayload?.authorization?.holder
162
+ };
163
+ }
164
+ if (payload.accepted.network !== requirements.network) {
165
+ return {
166
+ isValid: false,
167
+ invalidReason: "network_mismatch",
168
+ payer: confidentialPayload.authorization.holder
169
+ };
170
+ }
171
+ const extra = requirements.extra;
172
+ const eip712 = extra?.eip712;
173
+ if (!eip712?.name || !eip712?.version) {
174
+ return {
175
+ isValid: false,
176
+ invalidReason: "missing_eip712_domain",
177
+ payer: confidentialPayload.authorization.holder
178
+ };
179
+ }
180
+ const now = this.clock();
181
+ const validAfter = Number(confidentialPayload.authorization.validAfter);
182
+ const validBefore = Number(confidentialPayload.authorization.validBefore);
183
+ if (Number.isNaN(validAfter) || Number.isNaN(validBefore)) {
184
+ return {
185
+ isValid: false,
186
+ invalidReason: "invalid_validity_window",
187
+ payer: confidentialPayload.authorization.holder
188
+ };
189
+ }
190
+ if (now < validAfter || now > validBefore) {
191
+ return {
192
+ isValid: false,
193
+ invalidReason: "authorization_expired",
194
+ payer: confidentialPayload.authorization.holder
195
+ };
196
+ }
197
+ if (!isAddressEqual(getAddress(confidentialPayload.authorization.payee), getAddress(requirements.payTo))) {
198
+ return {
199
+ isValid: false,
200
+ invalidReason: "recipient_mismatch",
201
+ payer: confidentialPayload.authorization.holder
202
+ };
203
+ }
204
+ const computedHash = this.hashFn(confidentialPayload.encryptedAmountInput);
205
+ if (computedHash !== confidentialPayload.authorization.encryptedAmountHash) {
206
+ return {
207
+ isValid: false,
208
+ invalidReason: "encrypted_amount_mismatch",
209
+ payer: confidentialPayload.authorization.holder
210
+ };
211
+ }
212
+ const chainId = parseInt(requirements.network.split(":")[1]);
213
+ const isValidSignature = await this.config.signer.verifyTypedData({
214
+ address: confidentialPayload.authorization.holder,
215
+ domain: {
216
+ name: eip712.name,
217
+ version: eip712.version,
218
+ chainId,
219
+ verifyingContract: getAddress(requirements.asset)
220
+ },
221
+ types: confidentialPaymentTypes,
222
+ primaryType: "ConfidentialPayment",
223
+ message: {
224
+ holder: getAddress(confidentialPayload.authorization.holder),
225
+ payee: getAddress(confidentialPayload.authorization.payee),
226
+ maxClearAmount: BigInt(confidentialPayload.authorization.maxClearAmount),
227
+ resourceHash: confidentialPayload.authorization.resourceHash,
228
+ validAfter: BigInt(confidentialPayload.authorization.validAfter),
229
+ validBefore: BigInt(confidentialPayload.authorization.validBefore),
230
+ nonce: confidentialPayload.authorization.nonce,
231
+ encryptedAmountHash: confidentialPayload.authorization.encryptedAmountHash
232
+ },
233
+ signature: confidentialPayload.signature
234
+ });
235
+ if (!isValidSignature) {
236
+ return {
237
+ isValid: false,
238
+ invalidReason: "invalid_signature",
239
+ payer: confidentialPayload.authorization.holder
240
+ };
241
+ }
242
+ if (this.checkUsedNonces) {
243
+ const used = await this.config.signer.readContract({
244
+ address: getAddress(requirements.asset),
245
+ abi: confidentialTokenAbi,
246
+ functionName: "usedNonces",
247
+ args: [confidentialPayload.authorization.holder, confidentialPayload.authorization.nonce]
248
+ });
249
+ if (used) {
250
+ return {
251
+ isValid: false,
252
+ invalidReason: "nonce_already_used",
253
+ payer: confidentialPayload.authorization.holder
254
+ };
255
+ }
256
+ }
257
+ return {
258
+ isValid: true,
259
+ payer: confidentialPayload.authorization.holder
260
+ };
261
+ }
262
+ async settle(payload, requirements) {
263
+ const valid = await this.verify(payload, requirements);
264
+ const confidentialPayload = payload.payload;
265
+ if (!valid.isValid) {
266
+ return {
267
+ success: false,
268
+ errorReason: valid.invalidReason ?? "invalid_payment",
269
+ payer: confidentialPayload.authorization.holder,
270
+ transaction: "",
271
+ network: requirements.network
272
+ };
273
+ }
274
+ return new Promise((resolve) => {
275
+ this.queue.push({ payload, requirements, resolve });
276
+ this.scheduleFlush();
277
+ });
278
+ }
279
+ scheduleFlush() {
280
+ if (this.flushTimer) {
281
+ return;
282
+ }
283
+ const delay = this.batchIntervalMs;
284
+ this.flushTimer = setTimeout(() => {
285
+ this.flushTimer = void 0;
286
+ void this.flushQueue();
287
+ }, delay);
288
+ }
289
+ async flushQueue() {
290
+ if (this.queue.length === 0) {
291
+ return;
292
+ }
293
+ const queued = this.queue;
294
+ this.queue = [];
295
+ const byToken = /* @__PURE__ */ new Map();
296
+ for (const entry of queued) {
297
+ const tokenKey = getAddress(entry.requirements.asset);
298
+ const group = byToken.get(tokenKey) ?? [];
299
+ group.push(entry);
300
+ byToken.set(tokenKey, group);
301
+ }
302
+ for (const [tokenAddress, entries] of byToken.entries()) {
303
+ await this.flushBatch(tokenAddress, entries);
304
+ }
305
+ if (this.queue.length > 0) {
306
+ this.scheduleFlush();
307
+ }
308
+ }
309
+ async flushBatch(tokenAddress, entries) {
310
+ const buildRequests = (batchEntries2) => batchEntries2.map(({ entry }) => {
311
+ const confidentialPayload = entry.payload.payload;
312
+ return {
313
+ p: confidentialPayload.authorization,
314
+ encryptedAmountInput: confidentialPayload.encryptedAmountInput,
315
+ inputProof: confidentialPayload.inputProof,
316
+ sig: confidentialPayload.signature
317
+ };
318
+ });
319
+ const originalEntries = entries.map((entry, index) => ({ entry, index }));
320
+ let batchEntries = originalEntries;
321
+ let requests = buildRequests(batchEntries);
322
+ let txRequest = {
323
+ address: this.batcherAddress,
324
+ abi: batcherAbi,
325
+ functionName: "batchConfidentialTransferWithAuthorization",
326
+ args: [tokenAddress, requests]
327
+ };
328
+ if (process.env.X402Z_DEBUG === "1") {
329
+ console.debug("[x402z-facilitator] settle tx", {
330
+ batcherAddress: this.batcherAddress,
331
+ tokenAddress,
332
+ functionName: txRequest.functionName,
333
+ to: txRequest.address,
334
+ size: requests.length
335
+ });
336
+ }
337
+ try {
338
+ const [successes, transferredHandles] = await this.config.signer.simulateContract(txRequest);
339
+ if (successes.length === batchEntries.length && transferredHandles.length === batchEntries.length) {
340
+ const filtered = [];
341
+ batchEntries.forEach((item, index) => {
342
+ if (successes[index]) {
343
+ filtered.push(item);
344
+ return;
345
+ }
346
+ const confidentialPayload = item.entry.payload.payload;
347
+ item.entry.resolve(
348
+ {
349
+ success: false,
350
+ errorReason: "preflight_failed",
351
+ payer: confidentialPayload.authorization.holder,
352
+ transaction: "",
353
+ network: item.entry.requirements.network,
354
+ batch: { index: item.index, success: false, transferredHandle: transferredHandles[index] }
355
+ }
356
+ );
357
+ });
358
+ if (filtered.length === 0) {
359
+ return;
360
+ }
361
+ batchEntries = filtered;
362
+ requests = buildRequests(batchEntries);
363
+ txRequest = {
364
+ ...txRequest,
365
+ args: [tokenAddress, requests]
366
+ };
367
+ }
368
+ } catch (error) {
369
+ for (const entry of entries) {
370
+ const confidentialPayload = entry.payload.payload;
371
+ entry.resolve({
372
+ success: false,
373
+ errorReason: "preflight_failed",
374
+ payer: confidentialPayload.authorization.holder,
375
+ transaction: "",
376
+ network: entry.requirements.network
377
+ });
378
+ }
379
+ return;
380
+ }
381
+ const settleEntries = batchEntries.map((item) => item.entry);
382
+ let txHash;
383
+ try {
384
+ txHash = await this.config.signer.writeContract(txRequest);
385
+ } catch (error) {
386
+ for (const entry of settleEntries) {
387
+ const confidentialPayload = entry.payload.payload;
388
+ entry.resolve({
389
+ success: false,
390
+ errorReason: "settlement_failed",
391
+ payer: confidentialPayload.authorization.holder,
392
+ transaction: "",
393
+ network: entry.requirements.network
394
+ });
395
+ }
396
+ return;
397
+ }
398
+ if (process.env.X402Z_DEBUG === "1") {
399
+ console.debug("[x402z-facilitator] tx submitted", txHash);
400
+ }
401
+ let receipt;
402
+ if (this.waitForReceipt) {
403
+ receipt = await this.config.signer.waitForTransactionReceipt({ hash: txHash });
404
+ if (process.env.X402Z_DEBUG === "1") {
405
+ console.debug("[x402z-facilitator] tx receipt", receipt);
406
+ }
407
+ if (receipt.status !== "success") {
408
+ for (const entry of settleEntries) {
409
+ const confidentialPayload = entry.payload.payload;
410
+ entry.resolve({
411
+ success: false,
412
+ errorReason: "settlement_failed",
413
+ payer: confidentialPayload.authorization.holder,
414
+ transaction: txHash,
415
+ network: entry.requirements.network
416
+ });
417
+ }
418
+ return;
419
+ }
420
+ }
421
+ if (!this.waitForReceipt) {
422
+ settleEntries.forEach((entry) => {
423
+ const confidentialPayload = entry.payload.payload;
424
+ entry.resolve({
425
+ success: true,
426
+ payer: confidentialPayload.authorization.holder,
427
+ transaction: txHash,
428
+ network: entry.requirements.network
429
+ });
430
+ });
431
+ return;
432
+ }
433
+ const batchResults = /* @__PURE__ */ new Map();
434
+ if (receipt?.logs) {
435
+ for (const log of receipt.logs) {
436
+ if (!log?.address) {
437
+ continue;
438
+ }
439
+ if (!isAddressEqual(getAddress(log.address), this.batcherAddress)) {
440
+ continue;
441
+ }
442
+ const decoded = decodeEventLog({
443
+ abi: batcherAbi,
444
+ data: log.data,
445
+ topics: log.topics
446
+ });
447
+ if (process.env.X402Z_DEBUG === "1") {
448
+ console.debug("[x402z-facilitator] batch log", decoded);
449
+ }
450
+ if (decoded.eventName === "BatchItemSuccess") {
451
+ const args = decoded.args;
452
+ batchResults.set(Number(args.index), {
453
+ success: true,
454
+ transferredHandle: args.transferredHandle
455
+ });
456
+ } else if (decoded.eventName === "BatchItemFailure") {
457
+ const args = decoded.args;
458
+ batchResults.set(Number(args.index), {
459
+ success: false,
460
+ failureReason: args.reason
461
+ });
462
+ }
463
+ }
464
+ }
465
+ settleEntries.forEach((entry, index) => {
466
+ const confidentialPayload = entry.payload.payload;
467
+ const batchResult = batchResults.get(index);
468
+ if (!batchResult || !batchResult.success) {
469
+ entry.resolve(
470
+ {
471
+ success: false,
472
+ errorReason: "settlement_failed",
473
+ payer: confidentialPayload.authorization.holder,
474
+ transaction: txHash,
475
+ network: entry.requirements.network,
476
+ ...batchResult ? { batch: { index, ...batchResult } } : {}
477
+ }
478
+ );
479
+ return;
480
+ }
481
+ entry.resolve(
482
+ {
483
+ success: true,
484
+ payer: confidentialPayload.authorization.holder,
485
+ transaction: txHash,
486
+ network: entry.requirements.network,
487
+ batch: { index, ...batchResult }
488
+ }
489
+ );
490
+ });
491
+ }
492
+ };
493
+
494
+ // src/service/bootstrap.ts
495
+ function requireEnv(key) {
496
+ const value = process.env[key];
497
+ if (!value) {
498
+ throw new Error(`Missing required env var: ${key}`);
499
+ }
500
+ return value;
501
+ }
502
+ function createFacilitatorFromEnv() {
503
+ const privateKey = requireEnv("FACILITATOR_EVM_PRIVATE_KEY");
504
+ const chainId = Number(process.env.FACILITATOR_EVM_CHAIN_ID ?? "11155111");
505
+ const rpcUrl = requireEnv("FACILITATOR_EVM_RPC_URL");
506
+ const networks = (process.env.FACILITATOR_NETWORKS ?? "eip155:11155111").split(",").map((network) => network.trim()).filter(Boolean);
507
+ const waitForReceipt = (process.env.FACILITATOR_WAIT_FOR_RECEIPT ?? "true") === "true";
508
+ const batcherAddress = process.env.FACILITATOR_BATCHER_ADDRESS;
509
+ if (!batcherAddress) {
510
+ throw new Error("FACILITATOR_BATCHER_ADDRESS is required");
511
+ }
512
+ const batchIntervalMs = process.env.FACILITATOR_BATCH_INTERVAL_MS ? Number(process.env.FACILITATOR_BATCH_INTERVAL_MS) : void 0;
513
+ const receiptTimeoutMs = process.env.FACILITATOR_RECEIPT_TIMEOUT_MS ? Number(process.env.FACILITATOR_RECEIPT_TIMEOUT_MS) : void 0;
514
+ const receiptConfirmations = process.env.FACILITATOR_RECEIPT_CONFIRMATIONS ? Number(process.env.FACILITATOR_RECEIPT_CONFIRMATIONS) : void 0;
515
+ const receiptPollingIntervalMs = process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS ? Number(process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS) : void 0;
516
+ const gasMultiplier = process.env.FACILITATOR_GAS_MULTIPLIER ? Number(process.env.FACILITATOR_GAS_MULTIPLIER) : void 0;
517
+ const debugEnabled = process.env.X402Z_DEBUG === "1";
518
+ const account = privateKeyToAccount(privateKey);
519
+ if (debugEnabled) {
520
+ console.debug("[x402z-facilitator] config", {
521
+ chainId,
522
+ networks,
523
+ rpcUrl,
524
+ waitForReceipt,
525
+ batcherAddress,
526
+ gasMultiplier,
527
+ batchIntervalMs,
528
+ receipt: {
529
+ confirmations: receiptConfirmations,
530
+ timeoutMs: receiptTimeoutMs,
531
+ pollingIntervalMs: receiptPollingIntervalMs
532
+ },
533
+ address: account.address
534
+ });
535
+ }
536
+ const client = createWalletClient({
537
+ account,
538
+ chain: {
539
+ id: chainId,
540
+ name: "custom",
541
+ nativeCurrency: { name: "native", symbol: "NATIVE", decimals: 18 },
542
+ rpcUrls: { default: { http: [rpcUrl] } }
543
+ },
544
+ transport: http(rpcUrl)
545
+ }).extend(publicActions);
546
+ const baseSigner = toFacilitatorEvmSigner({
547
+ address: account.address,
548
+ readContract: (args) => client.readContract({
549
+ ...args,
550
+ args: args.args || []
551
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
552
+ }),
553
+ verifyTypedData: (args) => client.verifyTypedData(args),
554
+ writeContract: async (args) => {
555
+ let gas;
556
+ if (gasMultiplier && gasMultiplier > 0) {
557
+ try {
558
+ const estimated = await client.estimateContractGas({
559
+ ...args,
560
+ args: args.args || [],
561
+ account
562
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
563
+ });
564
+ const scale = BigInt(Math.round(gasMultiplier * 1e3));
565
+ const scaled = estimated * scale / 1000n;
566
+ gas = scaled > estimated ? scaled : estimated;
567
+ } catch (error) {
568
+ if (debugEnabled) {
569
+ console.debug("[x402z-facilitator] gas estimate failed", error);
570
+ }
571
+ }
572
+ }
573
+ return client.writeContract({
574
+ ...args,
575
+ args: args.args || [],
576
+ ...gas ? { gas } : {}
577
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
578
+ });
579
+ },
580
+ sendTransaction: (args) => (
581
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
582
+ client.sendTransaction({ to: args.to, data: args.data })
583
+ ),
584
+ waitForTransactionReceipt: (args) => client.waitForTransactionReceipt(args),
585
+ getCode: (args) => client.getCode(args)
586
+ });
587
+ const signer = {
588
+ ...baseSigner,
589
+ simulateContract: async (args) => {
590
+ const result = await client.simulateContract({
591
+ ...args,
592
+ args: args.args || [],
593
+ account
594
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
595
+ });
596
+ return result.result;
597
+ }
598
+ };
599
+ const facilitator = new x402Facilitator();
600
+ for (const network of networks) {
601
+ facilitator.register(
602
+ network,
603
+ new X402zEvmFacilitator({
604
+ signer,
605
+ waitForReceipt,
606
+ batcherAddress,
607
+ batchIntervalMs,
608
+ receipt: {
609
+ confirmations: receiptConfirmations,
610
+ timeoutMs: receiptTimeoutMs,
611
+ pollingIntervalMs: receiptPollingIntervalMs
612
+ }
613
+ })
614
+ );
615
+ }
616
+ return facilitator;
617
+ }
618
+ function startFacilitator() {
619
+ const facilitator = createFacilitatorFromEnv();
620
+ const port = Number(process.env.FACILITATOR_PORT ?? "8040");
621
+ const server = createFacilitatorService({ facilitator, port });
622
+ server.listen(port);
623
+ return { port };
624
+ }
625
+ if (__require.main === module) {
626
+ const { port } = startFacilitator();
627
+ console.log(`Confidential facilitator listening on :${port}`);
628
+ }
629
+
630
+ export {
631
+ X402zEvmFacilitator,
632
+ createFacilitatorService,
633
+ startFacilitatorService,
634
+ createFacilitatorFromEnv,
635
+ startFacilitator
636
+ };