x402z-client 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
@@ -31,7 +31,7 @@ console.log(response.status);
31
31
  ```
32
32
 
33
33
  `createX402zClient` builds the confidential payment input automatically using the
34
- `confidential.facilitatorAddress` provided by the server’s payment requirements.
34
+ `confidential.batcherAddress` provided by the server’s payment requirements.
35
35
 
36
36
  ## API
37
37
 
package/dist/index.js CHANGED
@@ -33,6 +33,18 @@ module.exports = __toCommonJS(index_exports);
33
33
  var import_viem = require("viem");
34
34
  var import_x402z_shared = require("x402z-shared");
35
35
  var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
36
+ var DECIMAL_POINT = ".";
37
+ function normalizeIntegerAmount(value, fallback) {
38
+ const normalized = (0, import_x402z_shared.normalizeAmount)(value);
39
+ if (!normalized.includes(DECIMAL_POINT)) {
40
+ return normalized;
41
+ }
42
+ const fallbackNormalized = (0, import_x402z_shared.normalizeAmount)(fallback);
43
+ if (fallbackNormalized.includes(DECIMAL_POINT)) {
44
+ throw new Error(`Invalid amount: ${normalized}`);
45
+ }
46
+ return fallbackNormalized;
47
+ }
36
48
  var ConfidentialEvmScheme = class {
37
49
  constructor(config) {
38
50
  this.config = config;
@@ -51,7 +63,10 @@ var ConfidentialEvmScheme = class {
51
63
  const validAfter = input.validAfter ?? Math.max(0, now - 60);
52
64
  const validBefore = input.validBefore ?? now + paymentRequirements.maxTimeoutSeconds;
53
65
  const nonce = input.nonce ?? (0, import_x402z_shared.createNonce)();
54
- const maxClearAmount = input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? (0, import_x402z_shared.normalizeAmount)(paymentRequirements.amount);
66
+ const maxClearAmount = normalizeIntegerAmount(
67
+ input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? paymentRequirements.amount,
68
+ paymentRequirements.amount
69
+ );
55
70
  const resourceHash = input.resourceHash ?? extra?.confidential?.resourceHash ?? ZERO_BYTES32;
56
71
  const authorization = {
57
72
  holder: this.config.signer.address,
@@ -113,14 +128,14 @@ function registerConfidentialEvmScheme(client, config) {
113
128
  var import_x402z_shared2 = require("x402z-shared");
114
129
  async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
115
130
  const extra = requirements.extra;
116
- const facilitatorAddress = extra?.confidential?.facilitatorAddress;
117
- if (!facilitatorAddress) {
118
- throw new Error("Missing confidential.facilitatorAddress in payment requirements");
131
+ const batcherAddress = extra?.confidential?.batcherAddress;
132
+ if (!batcherAddress) {
133
+ throw new Error("Missing confidential.batcherAddress in payment requirements");
119
134
  }
120
135
  const encrypted = await (0, import_x402z_shared2.createEncryptedAmountInput)(
121
136
  relayer,
122
137
  requirements.asset,
123
- facilitatorAddress,
138
+ batcherAddress,
124
139
  amount
125
140
  );
126
141
  return {
@@ -146,14 +161,14 @@ function createX402zClient(config) {
146
161
  throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
147
162
  }
148
163
  const extra = requirements.extra;
149
- const facilitatorAddress = extra?.confidential?.facilitatorAddress;
150
- if (!facilitatorAddress) {
151
- throw new Error("Missing confidential.facilitatorAddress in payment requirements");
164
+ const batcherAddress = extra?.confidential?.batcherAddress;
165
+ if (!batcherAddress) {
166
+ throw new Error("Missing confidential.batcherAddress in payment requirements");
152
167
  }
153
168
  const encrypted = await (0, import_x402z_shared3.createEncryptedAmountInput)(
154
169
  config.relayer,
155
170
  requirements.asset,
156
- facilitatorAddress,
171
+ batcherAddress,
157
172
  Number(requirements.amount)
158
173
  );
159
174
  return {
package/dist/index.mjs CHANGED
@@ -7,6 +7,18 @@ import {
7
7
  normalizeAmount
8
8
  } from "x402z-shared";
9
9
  var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
10
+ var DECIMAL_POINT = ".";
11
+ function normalizeIntegerAmount(value, fallback) {
12
+ const normalized = normalizeAmount(value);
13
+ if (!normalized.includes(DECIMAL_POINT)) {
14
+ return normalized;
15
+ }
16
+ const fallbackNormalized = normalizeAmount(fallback);
17
+ if (fallbackNormalized.includes(DECIMAL_POINT)) {
18
+ throw new Error(`Invalid amount: ${normalized}`);
19
+ }
20
+ return fallbackNormalized;
21
+ }
10
22
  var ConfidentialEvmScheme = class {
11
23
  constructor(config) {
12
24
  this.config = config;
@@ -25,7 +37,10 @@ var ConfidentialEvmScheme = class {
25
37
  const validAfter = input.validAfter ?? Math.max(0, now - 60);
26
38
  const validBefore = input.validBefore ?? now + paymentRequirements.maxTimeoutSeconds;
27
39
  const nonce = input.nonce ?? createNonce();
28
- const maxClearAmount = input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? normalizeAmount(paymentRequirements.amount);
40
+ const maxClearAmount = normalizeIntegerAmount(
41
+ input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? paymentRequirements.amount,
42
+ paymentRequirements.amount
43
+ );
29
44
  const resourceHash = input.resourceHash ?? extra?.confidential?.resourceHash ?? ZERO_BYTES32;
30
45
  const authorization = {
31
46
  holder: this.config.signer.address,
@@ -87,14 +102,14 @@ function registerConfidentialEvmScheme(client, config) {
87
102
  import { createEncryptedAmountInput } from "x402z-shared";
88
103
  async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
89
104
  const extra = requirements.extra;
90
- const facilitatorAddress = extra?.confidential?.facilitatorAddress;
91
- if (!facilitatorAddress) {
92
- throw new Error("Missing confidential.facilitatorAddress in payment requirements");
105
+ const batcherAddress = extra?.confidential?.batcherAddress;
106
+ if (!batcherAddress) {
107
+ throw new Error("Missing confidential.batcherAddress in payment requirements");
93
108
  }
94
109
  const encrypted = await createEncryptedAmountInput(
95
110
  relayer,
96
111
  requirements.asset,
97
- facilitatorAddress,
112
+ batcherAddress,
98
113
  amount
99
114
  );
100
115
  return {
@@ -122,14 +137,14 @@ function createX402zClient(config) {
122
137
  throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
123
138
  }
124
139
  const extra = requirements.extra;
125
- const facilitatorAddress = extra?.confidential?.facilitatorAddress;
126
- if (!facilitatorAddress) {
127
- throw new Error("Missing confidential.facilitatorAddress in payment requirements");
140
+ const batcherAddress = extra?.confidential?.batcherAddress;
141
+ if (!batcherAddress) {
142
+ throw new Error("Missing confidential.batcherAddress in payment requirements");
128
143
  }
129
144
  const encrypted = await createEncryptedAmountInput2(
130
145
  config.relayer,
131
146
  requirements.asset,
132
- facilitatorAddress,
147
+ batcherAddress,
133
148
  Number(requirements.amount)
134
149
  );
135
150
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-client",
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.3"
14
+ "x402z-shared": "0.0.4"
15
15
  },
16
16
  "devDependencies": {
17
17
  "jest": "^29.7.0",