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.
- package/README.md +23 -3
- package/dist/bootstrap.js +106 -89
- package/dist/chunk-3E55KK5J.mjs +633 -0
- package/dist/chunk-B6WVQBNK.mjs +636 -0
- package/dist/chunk-TDT6WJI7.mjs +711 -0
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +165 -30
- package/dist/index.mjs +1 -1
- package/dist/service/bootstrap.js +165 -30
- package/dist/service/bootstrap.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,8 +23,10 @@ Set env vars:
|
|
|
23
23
|
- `FACILITATOR_EVM_CHAIN_ID` (default 11155111)
|
|
24
24
|
- `FACILITATOR_NETWORKS` (default `eip155:11155111`)
|
|
25
25
|
- `FACILITATOR_PORT` (default 8040)
|
|
26
|
-
- `FACILITATOR_BATCHER_ADDRESS` (
|
|
26
|
+
- `FACILITATOR_BATCHER_ADDRESS` (required FHETokenBatcher address)
|
|
27
|
+
- `FACILITATOR_BATCH_INTERVAL_MS` (default 15000)
|
|
27
28
|
- `FACILITATOR_GAS_MULTIPLIER` (optional, e.g. `2` to double estimated gas)
|
|
29
|
+
- `FACILITATOR_FEE_MULTIPLIER` (optional, scales estimated max fee + priority fee)
|
|
28
30
|
|
|
29
31
|
Then run:
|
|
30
32
|
|
|
@@ -33,8 +35,26 @@ pnpm -C packages/x402z-facilitator build
|
|
|
33
35
|
node packages/x402z-facilitator/dist/bootstrap.js
|
|
34
36
|
```
|
|
35
37
|
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
See `examples/README.md` for the full-process facilitator + server setup.
|
|
41
|
+
|
|
36
42
|
## Notes
|
|
37
43
|
|
|
38
44
|
- This service receives `/verify` and `/settle` HTTP calls from the server.
|
|
39
|
-
- It submits `
|
|
40
|
-
-
|
|
45
|
+
- It queues settle requests and submits `batchConfidentialTransferWithAuthorization` on an interval.
|
|
46
|
+
- It validates per-item results from batch events and reports them back to the server.
|
|
47
|
+
|
|
48
|
+
## API surface
|
|
49
|
+
|
|
50
|
+
Exports:
|
|
51
|
+
- `X402zEvmFacilitator`: facilitator scheme implementation for erc7984-mind-v1.
|
|
52
|
+
- `registerX402zEvmFacilitatorScheme`: registers the scheme with facilitator.
|
|
53
|
+
- `createFacilitatorService`: builds the facilitator HTTP service.
|
|
54
|
+
- `startFacilitatorService`: starts the service with a config.
|
|
55
|
+
- `startFacilitator`: CLI/bootstrap entrypoint.
|
|
56
|
+
|
|
57
|
+
Types:
|
|
58
|
+
- `X402zFacilitatorSchemeOptions`: scheme config for facilitator registration.
|
|
59
|
+
- `X402zFacilitatorRegistrationOptions`: registration options for the scheme.
|
|
60
|
+
- `FacilitatorServiceOptions`: service configuration options.
|
package/dist/bootstrap.js
CHANGED
|
@@ -4,14 +4,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
for (var name in all) __defProp(target, name, { get: all[name], enumerable: true });
|
|
9
8
|
};
|
|
10
9
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
12
11
|
for (let key of __getOwnPropNames(from))
|
|
13
12
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
@@ -21,7 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
23
|
var bootstrap_exports = {};
|
|
22
24
|
__export(bootstrap_exports, {
|
|
23
25
|
createConfidentialFacilitatorFromEnv: () => createConfidentialFacilitatorFromEnv,
|
|
24
|
-
startConfidentialFacilitator: () => startConfidentialFacilitator
|
|
26
|
+
startConfidentialFacilitator: () => startConfidentialFacilitator,
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(bootstrap_exports);
|
|
27
29
|
var import_facilitator = require("@x402/core/facilitator");
|
|
@@ -98,47 +100,47 @@ var batcherAbi = [
|
|
|
98
100
|
{ internalType: "uint48", name: "validAfter", type: "uint48" },
|
|
99
101
|
{ internalType: "uint48", name: "validBefore", type: "uint48" },
|
|
100
102
|
{ internalType: "bytes32", name: "nonce", type: "bytes32" },
|
|
101
|
-
{ internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
|
|
103
|
+
{ internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" },
|
|
102
104
|
],
|
|
103
105
|
internalType: "struct IFHEToken.ConfidentialPayment",
|
|
104
106
|
name: "p",
|
|
105
|
-
type: "tuple"
|
|
107
|
+
type: "tuple",
|
|
106
108
|
},
|
|
107
109
|
{ internalType: "externalEuint64", name: "encryptedAmountInput", type: "bytes32" },
|
|
108
110
|
{ internalType: "bytes", name: "inputProof", type: "bytes" },
|
|
109
|
-
{ internalType: "bytes", name: "sig", type: "bytes" }
|
|
111
|
+
{ internalType: "bytes", name: "sig", type: "bytes" },
|
|
110
112
|
],
|
|
111
113
|
internalType: "struct FHETokenBatcher.Request[]",
|
|
112
114
|
name: "requests",
|
|
113
|
-
type: "tuple[]"
|
|
114
|
-
}
|
|
115
|
+
type: "tuple[]",
|
|
116
|
+
},
|
|
115
117
|
],
|
|
116
118
|
name: "batchConfidentialTransferWithAuthorization",
|
|
117
119
|
outputs: [
|
|
118
120
|
{ internalType: "bool[]", name: "successes", type: "bool[]" },
|
|
119
|
-
{ internalType: "bytes32[]", name: "transferredHandles", type: "bytes32[]" }
|
|
121
|
+
{ internalType: "bytes32[]", name: "transferredHandles", type: "bytes32[]" },
|
|
120
122
|
],
|
|
121
123
|
stateMutability: "nonpayable",
|
|
122
|
-
type: "function"
|
|
124
|
+
type: "function",
|
|
123
125
|
},
|
|
124
126
|
{
|
|
125
127
|
anonymous: false,
|
|
126
128
|
inputs: [
|
|
127
129
|
{ indexed: true, internalType: "uint256", name: "index", type: "uint256" },
|
|
128
|
-
{ indexed: false, internalType: "bytes32", name: "transferredHandle", type: "bytes32" }
|
|
130
|
+
{ indexed: false, internalType: "bytes32", name: "transferredHandle", type: "bytes32" },
|
|
129
131
|
],
|
|
130
132
|
name: "BatchItemSuccess",
|
|
131
|
-
type: "event"
|
|
133
|
+
type: "event",
|
|
132
134
|
},
|
|
133
135
|
{
|
|
134
136
|
anonymous: false,
|
|
135
137
|
inputs: [
|
|
136
138
|
{ indexed: true, internalType: "uint256", name: "index", type: "uint256" },
|
|
137
|
-
{ indexed: false, internalType: "bytes", name: "reason", type: "bytes" }
|
|
139
|
+
{ indexed: false, internalType: "bytes", name: "reason", type: "bytes" },
|
|
138
140
|
],
|
|
139
141
|
name: "BatchItemFailure",
|
|
140
|
-
type: "event"
|
|
141
|
-
}
|
|
142
|
+
type: "event",
|
|
143
|
+
},
|
|
142
144
|
];
|
|
143
145
|
var ConfidentialEvmFacilitator = class {
|
|
144
146
|
constructor(config) {
|
|
@@ -166,14 +168,14 @@ var ConfidentialEvmFacilitator = class {
|
|
|
166
168
|
return {
|
|
167
169
|
isValid: false,
|
|
168
170
|
invalidReason: "unsupported_scheme",
|
|
169
|
-
payer: confidentialPayload?.authorization?.holder
|
|
171
|
+
payer: confidentialPayload?.authorization?.holder,
|
|
170
172
|
};
|
|
171
173
|
}
|
|
172
174
|
if (payload.accepted.network !== requirements.network) {
|
|
173
175
|
return {
|
|
174
176
|
isValid: false,
|
|
175
177
|
invalidReason: "network_mismatch",
|
|
176
|
-
payer: confidentialPayload.authorization.holder
|
|
178
|
+
payer: confidentialPayload.authorization.holder,
|
|
177
179
|
};
|
|
178
180
|
}
|
|
179
181
|
const extra = requirements.extra;
|
|
@@ -182,7 +184,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
182
184
|
return {
|
|
183
185
|
isValid: false,
|
|
184
186
|
invalidReason: "missing_eip712_domain",
|
|
185
|
-
payer: confidentialPayload.authorization.holder
|
|
187
|
+
payer: confidentialPayload.authorization.holder,
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
190
|
const now = this.clock();
|
|
@@ -192,21 +194,26 @@ var ConfidentialEvmFacilitator = class {
|
|
|
192
194
|
return {
|
|
193
195
|
isValid: false,
|
|
194
196
|
invalidReason: "invalid_validity_window",
|
|
195
|
-
payer: confidentialPayload.authorization.holder
|
|
197
|
+
payer: confidentialPayload.authorization.holder,
|
|
196
198
|
};
|
|
197
199
|
}
|
|
198
200
|
if (now < validAfter || now > validBefore) {
|
|
199
201
|
return {
|
|
200
202
|
isValid: false,
|
|
201
203
|
invalidReason: "authorization_expired",
|
|
202
|
-
payer: confidentialPayload.authorization.holder
|
|
204
|
+
payer: confidentialPayload.authorization.holder,
|
|
203
205
|
};
|
|
204
206
|
}
|
|
205
|
-
if (
|
|
207
|
+
if (
|
|
208
|
+
!(0, import_viem.isAddressEqual)(
|
|
209
|
+
(0, import_viem.getAddress)(confidentialPayload.authorization.payee),
|
|
210
|
+
(0, import_viem.getAddress)(requirements.payTo),
|
|
211
|
+
)
|
|
212
|
+
) {
|
|
206
213
|
return {
|
|
207
214
|
isValid: false,
|
|
208
215
|
invalidReason: "recipient_mismatch",
|
|
209
|
-
payer: confidentialPayload.authorization.holder
|
|
216
|
+
payer: confidentialPayload.authorization.holder,
|
|
210
217
|
};
|
|
211
218
|
}
|
|
212
219
|
const computedHash = this.hashFn(confidentialPayload.encryptedAmountInput);
|
|
@@ -214,7 +221,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
214
221
|
return {
|
|
215
222
|
isValid: false,
|
|
216
223
|
invalidReason: "encrypted_amount_mismatch",
|
|
217
|
-
payer: confidentialPayload.authorization.holder
|
|
224
|
+
payer: confidentialPayload.authorization.holder,
|
|
218
225
|
};
|
|
219
226
|
}
|
|
220
227
|
const chainId = parseInt(requirements.network.split(":")[1]);
|
|
@@ -224,7 +231,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
224
231
|
name: eip712.name,
|
|
225
232
|
version: eip712.version,
|
|
226
233
|
chainId,
|
|
227
|
-
verifyingContract: (0, import_viem.getAddress)(requirements.asset)
|
|
234
|
+
verifyingContract: (0, import_viem.getAddress)(requirements.asset),
|
|
228
235
|
},
|
|
229
236
|
types: import_x402z_shared.confidentialPaymentTypes,
|
|
230
237
|
primaryType: "ConfidentialPayment",
|
|
@@ -236,15 +243,15 @@ var ConfidentialEvmFacilitator = class {
|
|
|
236
243
|
validAfter: BigInt(confidentialPayload.authorization.validAfter),
|
|
237
244
|
validBefore: BigInt(confidentialPayload.authorization.validBefore),
|
|
238
245
|
nonce: confidentialPayload.authorization.nonce,
|
|
239
|
-
encryptedAmountHash: confidentialPayload.authorization.encryptedAmountHash
|
|
246
|
+
encryptedAmountHash: confidentialPayload.authorization.encryptedAmountHash,
|
|
240
247
|
},
|
|
241
|
-
signature: confidentialPayload.signature
|
|
248
|
+
signature: confidentialPayload.signature,
|
|
242
249
|
});
|
|
243
250
|
if (!isValidSignature) {
|
|
244
251
|
return {
|
|
245
252
|
isValid: false,
|
|
246
253
|
invalidReason: "invalid_signature",
|
|
247
|
-
payer: confidentialPayload.authorization.holder
|
|
254
|
+
payer: confidentialPayload.authorization.holder,
|
|
248
255
|
};
|
|
249
256
|
}
|
|
250
257
|
if (this.checkUsedNonces) {
|
|
@@ -252,19 +259,19 @@ var ConfidentialEvmFacilitator = class {
|
|
|
252
259
|
address: (0, import_viem.getAddress)(requirements.asset),
|
|
253
260
|
abi: import_x402z_shared.confidentialTokenAbi,
|
|
254
261
|
functionName: "usedNonces",
|
|
255
|
-
args: [confidentialPayload.authorization.holder, confidentialPayload.authorization.nonce]
|
|
262
|
+
args: [confidentialPayload.authorization.holder, confidentialPayload.authorization.nonce],
|
|
256
263
|
});
|
|
257
264
|
if (used) {
|
|
258
265
|
return {
|
|
259
266
|
isValid: false,
|
|
260
267
|
invalidReason: "nonce_already_used",
|
|
261
|
-
payer: confidentialPayload.authorization.holder
|
|
268
|
+
payer: confidentialPayload.authorization.holder,
|
|
262
269
|
};
|
|
263
270
|
}
|
|
264
271
|
}
|
|
265
272
|
return {
|
|
266
273
|
isValid: true,
|
|
267
|
-
payer: confidentialPayload.authorization.holder
|
|
274
|
+
payer: confidentialPayload.authorization.holder,
|
|
268
275
|
};
|
|
269
276
|
}
|
|
270
277
|
async settle(payload, requirements) {
|
|
@@ -276,7 +283,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
276
283
|
errorReason: valid.invalidReason ?? "invalid_payment",
|
|
277
284
|
payer: confidentialPayload.authorization.holder,
|
|
278
285
|
transaction: "",
|
|
279
|
-
network: requirements.network
|
|
286
|
+
network: requirements.network,
|
|
280
287
|
};
|
|
281
288
|
}
|
|
282
289
|
return new Promise((resolve) => {
|
|
@@ -321,14 +328,14 @@ var ConfidentialEvmFacilitator = class {
|
|
|
321
328
|
p: confidentialPayload.authorization,
|
|
322
329
|
encryptedAmountInput: confidentialPayload.encryptedAmountInput,
|
|
323
330
|
inputProof: confidentialPayload.inputProof,
|
|
324
|
-
sig: confidentialPayload.signature
|
|
331
|
+
sig: confidentialPayload.signature,
|
|
325
332
|
};
|
|
326
333
|
});
|
|
327
334
|
const txRequest = {
|
|
328
335
|
address: this.batcherAddress,
|
|
329
336
|
abi: batcherAbi,
|
|
330
337
|
functionName: "batchConfidentialTransferWithAuthorization",
|
|
331
|
-
args: [tokenAddress, requests]
|
|
338
|
+
args: [tokenAddress, requests],
|
|
332
339
|
};
|
|
333
340
|
if (process.env.X402Z_DEBUG === "1") {
|
|
334
341
|
console.debug("[x402z-facilitator] settle tx", {
|
|
@@ -336,7 +343,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
336
343
|
tokenAddress,
|
|
337
344
|
functionName: txRequest.functionName,
|
|
338
345
|
to: txRequest.address,
|
|
339
|
-
size: requests.length
|
|
346
|
+
size: requests.length,
|
|
340
347
|
});
|
|
341
348
|
}
|
|
342
349
|
let txHash;
|
|
@@ -350,7 +357,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
350
357
|
errorReason: "settlement_failed",
|
|
351
358
|
payer: confidentialPayload.authorization.holder,
|
|
352
359
|
transaction: "",
|
|
353
|
-
network: entry.requirements.network
|
|
360
|
+
network: entry.requirements.network,
|
|
354
361
|
});
|
|
355
362
|
}
|
|
356
363
|
return;
|
|
@@ -372,7 +379,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
372
379
|
errorReason: "settlement_failed",
|
|
373
380
|
payer: confidentialPayload.authorization.holder,
|
|
374
381
|
transaction: txHash,
|
|
375
|
-
network: entry.requirements.network
|
|
382
|
+
network: entry.requirements.network,
|
|
376
383
|
});
|
|
377
384
|
}
|
|
378
385
|
return;
|
|
@@ -385,7 +392,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
385
392
|
success: true,
|
|
386
393
|
payer: confidentialPayload.authorization.holder,
|
|
387
394
|
transaction: txHash,
|
|
388
|
-
network: entry.requirements.network
|
|
395
|
+
network: entry.requirements.network,
|
|
389
396
|
});
|
|
390
397
|
});
|
|
391
398
|
return;
|
|
@@ -402,7 +409,7 @@ var ConfidentialEvmFacilitator = class {
|
|
|
402
409
|
const decoded = (0, import_viem.decodeEventLog)({
|
|
403
410
|
abi: batcherAbi,
|
|
404
411
|
data: log.data,
|
|
405
|
-
topics: log.topics
|
|
412
|
+
topics: log.topics,
|
|
406
413
|
});
|
|
407
414
|
if (process.env.X402Z_DEBUG === "1") {
|
|
408
415
|
console.debug("[x402z-facilitator] batch log", decoded);
|
|
@@ -411,13 +418,13 @@ var ConfidentialEvmFacilitator = class {
|
|
|
411
418
|
const args = decoded.args;
|
|
412
419
|
batchResults.set(Number(args.index), {
|
|
413
420
|
success: true,
|
|
414
|
-
transferredHandle: args.transferredHandle
|
|
421
|
+
transferredHandle: args.transferredHandle,
|
|
415
422
|
});
|
|
416
423
|
} else if (decoded.eventName === "BatchItemFailure") {
|
|
417
424
|
const args = decoded.args;
|
|
418
425
|
batchResults.set(Number(args.index), {
|
|
419
426
|
success: false,
|
|
420
|
-
failureReason: args.reason
|
|
427
|
+
failureReason: args.reason,
|
|
421
428
|
});
|
|
422
429
|
}
|
|
423
430
|
}
|
|
@@ -426,27 +433,23 @@ var ConfidentialEvmFacilitator = class {
|
|
|
426
433
|
const confidentialPayload = entry.payload.payload;
|
|
427
434
|
const batchResult = batchResults.get(index);
|
|
428
435
|
if (!batchResult || !batchResult.success) {
|
|
429
|
-
entry.resolve(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
errorReason: "settlement_failed",
|
|
433
|
-
payer: confidentialPayload.authorization.holder,
|
|
434
|
-
transaction: txHash,
|
|
435
|
-
network: entry.requirements.network,
|
|
436
|
-
...batchResult ? { batch: { index, ...batchResult } } : {}
|
|
437
|
-
}
|
|
438
|
-
);
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
entry.resolve(
|
|
442
|
-
{
|
|
443
|
-
success: true,
|
|
436
|
+
entry.resolve({
|
|
437
|
+
success: false,
|
|
438
|
+
errorReason: "settlement_failed",
|
|
444
439
|
payer: confidentialPayload.authorization.holder,
|
|
445
440
|
transaction: txHash,
|
|
446
441
|
network: entry.requirements.network,
|
|
447
|
-
batch: { index, ...batchResult }
|
|
448
|
-
}
|
|
449
|
-
|
|
442
|
+
...(batchResult ? { batch: { index, ...batchResult } } : {}),
|
|
443
|
+
});
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
entry.resolve({
|
|
447
|
+
success: true,
|
|
448
|
+
payer: confidentialPayload.authorization.holder,
|
|
449
|
+
transaction: txHash,
|
|
450
|
+
network: entry.requirements.network,
|
|
451
|
+
batch: { index, ...batchResult },
|
|
452
|
+
});
|
|
450
453
|
});
|
|
451
454
|
}
|
|
452
455
|
};
|
|
@@ -463,17 +466,30 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
463
466
|
const privateKey = requireEnv("FACILITATOR_EVM_PRIVATE_KEY");
|
|
464
467
|
const chainId = Number(process.env.FACILITATOR_EVM_CHAIN_ID ?? "11155111");
|
|
465
468
|
const rpcUrl = requireEnv("FACILITATOR_EVM_RPC_URL");
|
|
466
|
-
const networks = (process.env.FACILITATOR_NETWORKS ?? "eip155:11155111")
|
|
469
|
+
const networks = (process.env.FACILITATOR_NETWORKS ?? "eip155:11155111")
|
|
470
|
+
.split(",")
|
|
471
|
+
.map((network) => network.trim())
|
|
472
|
+
.filter(Boolean);
|
|
467
473
|
const waitForReceipt = (process.env.FACILITATOR_WAIT_FOR_RECEIPT ?? "true") === "true";
|
|
468
474
|
const batcherAddress = process.env.FACILITATOR_BATCHER_ADDRESS;
|
|
469
475
|
if (!batcherAddress) {
|
|
470
476
|
throw new Error("FACILITATOR_BATCHER_ADDRESS is required");
|
|
471
477
|
}
|
|
472
|
-
const batchIntervalMs = process.env.FACILITATOR_BATCH_INTERVAL_MS
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
|
|
478
|
+
const batchIntervalMs = process.env.FACILITATOR_BATCH_INTERVAL_MS
|
|
479
|
+
? Number(process.env.FACILITATOR_BATCH_INTERVAL_MS)
|
|
480
|
+
: void 0;
|
|
481
|
+
const receiptTimeoutMs = process.env.FACILITATOR_RECEIPT_TIMEOUT_MS
|
|
482
|
+
? Number(process.env.FACILITATOR_RECEIPT_TIMEOUT_MS)
|
|
483
|
+
: void 0;
|
|
484
|
+
const receiptConfirmations = process.env.FACILITATOR_RECEIPT_CONFIRMATIONS
|
|
485
|
+
? Number(process.env.FACILITATOR_RECEIPT_CONFIRMATIONS)
|
|
486
|
+
: void 0;
|
|
487
|
+
const receiptPollingIntervalMs = process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS
|
|
488
|
+
? Number(process.env.FACILITATOR_RECEIPT_POLLING_INTERVAL_MS)
|
|
489
|
+
: void 0;
|
|
490
|
+
const gasMultiplier = process.env.FACILITATOR_GAS_MULTIPLIER
|
|
491
|
+
? Number(process.env.FACILITATOR_GAS_MULTIPLIER)
|
|
492
|
+
: void 0;
|
|
477
493
|
const debugEnabled = process.env.X402Z_DEBUG === "1";
|
|
478
494
|
const account = (0, import_accounts.privateKeyToAccount)(privateKey);
|
|
479
495
|
if (debugEnabled) {
|
|
@@ -488,9 +504,9 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
488
504
|
receipt: {
|
|
489
505
|
confirmations: receiptConfirmations,
|
|
490
506
|
timeoutMs: receiptTimeoutMs,
|
|
491
|
-
pollingIntervalMs: receiptPollingIntervalMs
|
|
507
|
+
pollingIntervalMs: receiptPollingIntervalMs,
|
|
492
508
|
},
|
|
493
|
-
address: account.address
|
|
509
|
+
address: account.address,
|
|
494
510
|
});
|
|
495
511
|
}
|
|
496
512
|
const client = (0, import_viem2.createWalletClient)({
|
|
@@ -499,17 +515,18 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
499
515
|
id: chainId,
|
|
500
516
|
name: "custom",
|
|
501
517
|
nativeCurrency: { name: "native", symbol: "NATIVE", decimals: 18 },
|
|
502
|
-
rpcUrls: { default: { http: [rpcUrl] } }
|
|
518
|
+
rpcUrls: { default: { http: [rpcUrl] } },
|
|
503
519
|
},
|
|
504
|
-
transport: (0, import_viem2.http)(rpcUrl)
|
|
520
|
+
transport: (0, import_viem2.http)(rpcUrl),
|
|
505
521
|
}).extend(import_viem2.publicActions);
|
|
506
522
|
const signer = (0, import_evm.toFacilitatorEvmSigner)({
|
|
507
523
|
address: account.address,
|
|
508
|
-
readContract: (args) =>
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
524
|
+
readContract: (args) =>
|
|
525
|
+
client.readContract({
|
|
526
|
+
...args,
|
|
527
|
+
args: args.args || [],
|
|
528
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
529
|
+
}),
|
|
513
530
|
verifyTypedData: (args) => client.verifyTypedData(args),
|
|
514
531
|
writeContract: async (args) => {
|
|
515
532
|
let gas;
|
|
@@ -518,11 +535,11 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
518
535
|
const estimated = await client.estimateContractGas({
|
|
519
536
|
...args,
|
|
520
537
|
args: args.args || [],
|
|
521
|
-
account
|
|
538
|
+
account,
|
|
522
539
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
523
540
|
});
|
|
524
541
|
const scale = BigInt(Math.round(gasMultiplier * 1e3));
|
|
525
|
-
const scaled = estimated * scale / 1000n;
|
|
542
|
+
const scaled = (estimated * scale) / 1000n;
|
|
526
543
|
gas = scaled > estimated ? scaled : estimated;
|
|
527
544
|
} catch (error) {
|
|
528
545
|
if (debugEnabled) {
|
|
@@ -533,16 +550,15 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
533
550
|
return client.writeContract({
|
|
534
551
|
...args,
|
|
535
552
|
args: args.args || [],
|
|
536
|
-
...gas ? { gas } : {}
|
|
553
|
+
...(gas ? { gas } : {}),
|
|
537
554
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
538
555
|
});
|
|
539
556
|
},
|
|
540
|
-
sendTransaction: (args) =>
|
|
557
|
+
sendTransaction: (args) =>
|
|
541
558
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
542
|
-
client.sendTransaction({ to: args.to, data: args.data })
|
|
543
|
-
),
|
|
559
|
+
client.sendTransaction({ to: args.to, data: args.data }),
|
|
544
560
|
waitForTransactionReceipt: (args) => client.waitForTransactionReceipt(args),
|
|
545
|
-
getCode: (args) => client.getCode(args)
|
|
561
|
+
getCode: (args) => client.getCode(args),
|
|
546
562
|
});
|
|
547
563
|
const facilitator = new import_facilitator.x402Facilitator();
|
|
548
564
|
for (const network of networks) {
|
|
@@ -556,9 +572,9 @@ function createConfidentialFacilitatorFromEnv() {
|
|
|
556
572
|
receipt: {
|
|
557
573
|
confirmations: receiptConfirmations,
|
|
558
574
|
timeoutMs: receiptTimeoutMs,
|
|
559
|
-
pollingIntervalMs: receiptPollingIntervalMs
|
|
560
|
-
}
|
|
561
|
-
})
|
|
575
|
+
pollingIntervalMs: receiptPollingIntervalMs,
|
|
576
|
+
},
|
|
577
|
+
}),
|
|
562
578
|
);
|
|
563
579
|
}
|
|
564
580
|
return facilitator;
|
|
@@ -575,7 +591,8 @@ if (require.main === module) {
|
|
|
575
591
|
console.log(`Confidential facilitator listening on :${port}`);
|
|
576
592
|
}
|
|
577
593
|
// Annotate the CommonJS export names for ESM import in node:
|
|
578
|
-
0 &&
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
594
|
+
0 &&
|
|
595
|
+
(module.exports = {
|
|
596
|
+
createConfidentialFacilitatorFromEnv,
|
|
597
|
+
startConfidentialFacilitator,
|
|
598
|
+
});
|