x402z-server 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.
package/README.md CHANGED
@@ -24,7 +24,7 @@ const server = await createX402zServer({
24
24
  asset: "0xToken",
25
25
  eip712: { name: "FHEToken Confidential", version: "1" },
26
26
  decimals: 6,
27
- facilitatorAddress: "0xFacilitator",
27
+ batcherAddress: "0xBatcher",
28
28
  signer: { address, signTypedData },
29
29
  relayer,
30
30
  routes: {
@@ -51,7 +51,7 @@ server.listen(8080);
51
51
 
52
52
  - `createX402zServer(config)`
53
53
  - `facilitatorUrl` (required): HTTP facilitator endpoint
54
- - `asset`, `eip712`, `decimals`, `facilitatorAddress`: scheme config
54
+ - `asset`, `eip712`, `decimals`, `batcherAddress`: scheme config
55
55
  - `signer` (required): signer used to decrypt transfer amounts
56
56
  - `relayer` (required): FHEVM relayer instance used for decryption
57
57
  - `routes`: map of `METHOD /path` to payment requirements
@@ -60,4 +60,4 @@ server.listen(8080);
60
60
  ## Notes
61
61
 
62
62
  - Scheme name: `erc7984-mind-v1`
63
- - `confidential.facilitatorAddress` is included in requirements so clients can bind encrypted inputs.
63
+ - `confidential.batcherAddress` is required in requirements; clients bind encrypted inputs to it.
package/dist/index.d.mts CHANGED
@@ -14,7 +14,7 @@ type ConfidentialServerNetworkConfig = {
14
14
  };
15
15
  decimals?: number;
16
16
  resourceHash?: `0x${string}`;
17
- facilitatorAddress?: `0x${string}`;
17
+ batcherAddress: `0x${string}`;
18
18
  };
19
19
  type ConfidentialServerConfig = ConfidentialServerNetworkConfig | {
20
20
  getNetworkConfig: (network: Network) => ConfidentialServerNetworkConfig;
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ type ConfidentialServerNetworkConfig = {
14
14
  };
15
15
  decimals?: number;
16
16
  resourceHash?: `0x${string}`;
17
- facilitatorAddress?: `0x${string}`;
17
+ batcherAddress: `0x${string}`;
18
18
  };
19
19
  type ConfidentialServerConfig = ConfidentialServerNetworkConfig | {
20
20
  getNetworkConfig: (network: Network) => ConfidentialServerNetworkConfig;
package/dist/index.js CHANGED
@@ -52,15 +52,16 @@ var ConfidentialEvmScheme = class {
52
52
  }
53
53
  const amount = this.parseMoneyToDecimal(price);
54
54
  const config = this.getConfig(network);
55
+ const tokenAmount = this.convertToTokenAmount(amount.toString(), config.decimals ?? 6);
55
56
  return {
56
- amount: this.convertToTokenAmount(amount.toString(), config.decimals ?? 6),
57
+ amount: tokenAmount,
57
58
  asset: config.asset,
58
59
  extra: {
59
60
  eip712: config.eip712,
60
61
  confidential: {
61
- maxClearAmount: amount.toString(),
62
+ maxClearAmount: tokenAmount,
62
63
  resourceHash: config.resourceHash,
63
- facilitatorAddress: config.facilitatorAddress
64
+ batcherAddress: config.batcherAddress
64
65
  }
65
66
  }
66
67
  };
@@ -76,7 +77,7 @@ var ConfidentialEvmScheme = class {
76
77
  confidential: {
77
78
  maxClearAmount: extra?.confidential?.maxClearAmount ?? paymentRequirements.amount,
78
79
  resourceHash: extra?.confidential?.resourceHash ?? config.resourceHash,
79
- facilitatorAddress: extra?.confidential?.facilitatorAddress ?? config.facilitatorAddress
80
+ batcherAddress: extra?.confidential?.batcherAddress ?? config.batcherAddress
80
81
  }
81
82
  };
82
83
  return {
@@ -217,18 +218,22 @@ async function createX402zServer(config) {
217
218
  console.log(`[server] ${method} ${path} -> 500 observer_required`);
218
219
  return;
219
220
  }
220
- const transfers = await (0, import_x402z_shared.viewConfidentialTransferAmounts)({
221
- rpcUrl,
222
- tokenAddress: result.paymentRequirements.asset,
223
- txHash: settle.transaction,
224
- from: settle.payer,
225
- to: result.paymentRequirements.payTo,
221
+ const batch = settle;
222
+ const transferredHandle = batch.batch?.transferredHandle;
223
+ if (!transferredHandle) {
224
+ res.writeHead(500, { "Content-Type": "application/json" });
225
+ res.end(JSON.stringify({ error: "missing_transferred_handle" }));
226
+ console.log(`[server] ${method} ${path} -> 500 missing_transferred_handle`);
227
+ return;
228
+ }
229
+ const decryptedAmount = await (0, import_x402z_shared.userDecryptEuint64)(
226
230
  relayer,
227
- signer: config.signer
228
- });
231
+ transferredHandle,
232
+ result.paymentRequirements.asset,
233
+ config.signer
234
+ );
229
235
  const expected = BigInt(result.paymentRequirements.amount);
230
- const matched = transfers.some((transfer) => transfer.amount === expected);
231
- if (!matched) {
236
+ if (decryptedAmount !== expected) {
232
237
  res.writeHead(500, { "Content-Type": "application/json" });
233
238
  res.end(JSON.stringify({ error: "settlement_amount_mismatch" }));
234
239
  console.log(`[server] ${method} ${path} -> 500 settlement_amount_mismatch`);
package/dist/index.mjs CHANGED
@@ -21,15 +21,16 @@ var ConfidentialEvmScheme = class {
21
21
  }
22
22
  const amount = this.parseMoneyToDecimal(price);
23
23
  const config = this.getConfig(network);
24
+ const tokenAmount = this.convertToTokenAmount(amount.toString(), config.decimals ?? 6);
24
25
  return {
25
- amount: this.convertToTokenAmount(amount.toString(), config.decimals ?? 6),
26
+ amount: tokenAmount,
26
27
  asset: config.asset,
27
28
  extra: {
28
29
  eip712: config.eip712,
29
30
  confidential: {
30
- maxClearAmount: amount.toString(),
31
+ maxClearAmount: tokenAmount,
31
32
  resourceHash: config.resourceHash,
32
- facilitatorAddress: config.facilitatorAddress
33
+ batcherAddress: config.batcherAddress
33
34
  }
34
35
  }
35
36
  };
@@ -45,7 +46,7 @@ var ConfidentialEvmScheme = class {
45
46
  confidential: {
46
47
  maxClearAmount: extra?.confidential?.maxClearAmount ?? paymentRequirements.amount,
47
48
  resourceHash: extra?.confidential?.resourceHash ?? config.resourceHash,
48
- facilitatorAddress: extra?.confidential?.facilitatorAddress ?? config.facilitatorAddress
49
+ batcherAddress: extra?.confidential?.batcherAddress ?? config.batcherAddress
49
50
  }
50
51
  };
51
52
  return {
@@ -93,7 +94,7 @@ import { URL } from "url";
93
94
  import { x402ResourceServer } from "@x402/core/server";
94
95
  import { x402HTTPResourceServer } from "@x402/core/http";
95
96
  import { HTTPFacilitatorClient } from "@x402/core/http";
96
- import { confidentialTokenAbi, viewConfidentialTransferAmounts } from "x402z-shared";
97
+ import { confidentialTokenAbi, userDecryptEuint64 } from "x402z-shared";
97
98
  import { createPublicClient, getAddress, http, isAddressEqual } from "viem";
98
99
  function getRelayerRpcUrl(relayer) {
99
100
  const network = relayer.network;
@@ -186,18 +187,22 @@ async function createX402zServer(config) {
186
187
  console.log(`[server] ${method} ${path} -> 500 observer_required`);
187
188
  return;
188
189
  }
189
- const transfers = await viewConfidentialTransferAmounts({
190
- rpcUrl,
191
- tokenAddress: result.paymentRequirements.asset,
192
- txHash: settle.transaction,
193
- from: settle.payer,
194
- to: result.paymentRequirements.payTo,
190
+ const batch = settle;
191
+ const transferredHandle = batch.batch?.transferredHandle;
192
+ if (!transferredHandle) {
193
+ res.writeHead(500, { "Content-Type": "application/json" });
194
+ res.end(JSON.stringify({ error: "missing_transferred_handle" }));
195
+ console.log(`[server] ${method} ${path} -> 500 missing_transferred_handle`);
196
+ return;
197
+ }
198
+ const decryptedAmount = await userDecryptEuint64(
195
199
  relayer,
196
- signer: config.signer
197
- });
200
+ transferredHandle,
201
+ result.paymentRequirements.asset,
202
+ config.signer
203
+ );
198
204
  const expected = BigInt(result.paymentRequirements.amount);
199
- const matched = transfers.some((transfer) => transfer.amount === expected);
200
- if (!matched) {
205
+ if (decryptedAmount !== expected) {
201
206
  res.writeHead(500, { "Content-Type": "application/json" });
202
207
  res.end(JSON.stringify({ error: "settlement_amount_mismatch" }));
203
208
  console.log(`[server] ${method} ${path} -> 500 settlement_amount_mismatch`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-server",
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",
@@ -10,7 +10,7 @@
10
10
  "dependencies": {
11
11
  "@x402/core": "^2.0.0",
12
12
  "viem": "^2.43.3",
13
- "x402z-shared": "0.0.3"
13
+ "x402z-shared": "0.0.4"
14
14
  },
15
15
  "devDependencies": {
16
16
  "jest": "^29.7.0",