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 +1 -1
- package/dist/index.js +24 -9
- package/dist/index.mjs +24 -9
- package/package.json +2 -2
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.
|
|
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 =
|
|
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
|
|
117
|
-
if (!
|
|
118
|
-
throw new Error("Missing confidential.
|
|
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
|
-
|
|
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
|
|
150
|
-
if (!
|
|
151
|
-
throw new Error("Missing confidential.
|
|
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
|
-
|
|
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 =
|
|
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
|
|
91
|
-
if (!
|
|
92
|
-
throw new Error("Missing confidential.
|
|
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
|
-
|
|
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
|
|
126
|
-
if (!
|
|
127
|
-
throw new Error("Missing confidential.
|
|
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
|
-
|
|
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
|
+
"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.
|
|
14
|
+
"x402z-shared": "0.0.4"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"jest": "^29.7.0",
|