x402z-client 0.0.8 → 0.0.9

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
@@ -8,15 +8,22 @@ Client-side helpers for the erc7984-mind-v1 x402 scheme.
8
8
  pnpm add x402z-client x402z-shared
9
9
  ```
10
10
 
11
+ ## Folder map
12
+
13
+ - `src/http/`: HTTP client helpers
14
+ - `src/scheme/`: scheme implementation + registration
15
+ - `src/relayer/`: relayer payment input helpers
16
+ - `src/index.ts`: public exports
17
+
11
18
  ## Usage
12
19
 
13
20
  ```ts
14
21
  import { createX402zClient } from "x402z-client";
15
- import { createRelayerInstance, SepoliaConfig } from "x402z-shared";
22
+ import { createRelayer, SepoliaConfig } from "x402z-shared";
16
23
  import { privateKeyToAccount } from "viem/accounts";
17
24
 
18
25
  const account = privateKeyToAccount("0x...");
19
- const relayer = await createRelayerInstance(SepoliaConfig);
26
+ const relayer = await createRelayer(SepoliaConfig);
20
27
 
21
28
  const client = createX402zClient({
22
29
  signer: {
@@ -30,24 +37,6 @@ const response = await client.pay("https://example.com/demo");
30
37
  console.log(response.status);
31
38
  ```
32
39
 
33
- ## Usage (Browser)
34
-
35
- ```ts
36
- import { createX402zWebClient } from "x402z-client/web";
37
- import { SepoliaConfig } from "x402z-shared/web";
38
-
39
- const client = await createX402zWebClient({
40
- signer: {
41
- address: "0x...",
42
- signTypedData: async args => window.ethereum.request({ method: "eth_signTypedData_v4", params: [args] }),
43
- },
44
- relayerConfig: { ...SepoliaConfig, network: window.ethereum },
45
- });
46
-
47
- const response = await client.pay("https://example.com/demo");
48
- console.log(response.status);
49
- ```
50
-
51
40
  `createX402zClient` builds the confidential payment input automatically using the
52
41
  `confidential.batcherAddress` provided by the server’s payment requirements.
53
42
 
@@ -57,14 +46,10 @@ console.log(response.status);
57
46
  - `signer` (required): EIP-712 signer for x402 payloads
58
47
  - `relayer` (required): Zama relayer instance used to build encrypted inputs
59
48
  - `fetch` (optional): custom fetch implementation
60
- - `createX402zWebClient(config)`
61
- - `signer` (required): EIP-712 signer for x402 payloads
62
- - `relayerConfig` (required): relayer instance config (browser)
63
- - `fetch` (optional): custom fetch implementation
64
49
  - `client.pay(url, options?)`: performs the 402 handshake and retries with payment headers
65
50
 
66
51
  ## Notes
67
52
 
68
53
  - Scheme name: `erc7984-mind-v1`
69
54
  - The client does not expose balance helpers; use `x402z-shared` for that.
70
- - The browser entry (`x402z-client/web`) uses a web-only scheme implementation wired to `x402z-shared/web`.
55
+ - For browser usage, use `x402z-client-web` with `x402z-shared-web`.
package/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@ import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared';
5
5
  import { x402Client } from '@x402/core/client';
6
6
  export { AfterPaymentCreationHook, BeforePaymentCreationHook, OnPaymentCreationFailureHook, PaymentCreatedContext, PaymentCreationContext, PaymentCreationFailureContext, PaymentPolicy, SchemeRegistration, SelectPaymentRequirements, x402Client, x402ClientConfig, x402HTTPClient } from '@x402/core/client';
7
7
 
8
- type ConfidentialClientConfig = {
8
+ type X402zClientSchemeOptions = {
9
9
  signer: ClientEvmSigner;
10
10
  buildPayment: (requirements: PaymentRequirements) => ConfidentialPaymentInput | Promise<ConfidentialPaymentInput>;
11
11
  eip712?: {
@@ -15,23 +15,23 @@ type ConfidentialClientConfig = {
15
15
  hashEncryptedAmountInput?: (encryptedAmountInput: `0x${string}`) => `0x${string}`;
16
16
  clock?: () => number;
17
17
  };
18
- declare class ConfidentialEvmScheme implements SchemeNetworkClient {
18
+ declare class X402zEvmClientScheme implements SchemeNetworkClient {
19
19
  private readonly config;
20
20
  readonly scheme = "erc7984-mind-v1";
21
21
  private readonly hashFn;
22
22
  private readonly clock;
23
- constructor(config: ConfidentialClientConfig);
23
+ constructor(config: X402zClientSchemeOptions);
24
24
  createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
25
25
  }
26
26
 
27
- type ConfidentialClientRegisterConfig = ConfidentialClientConfig & {
27
+ type X402zClientRegistrationOptions = X402zClientSchemeOptions & {
28
28
  networks?: Network[];
29
29
  };
30
- declare function registerConfidentialEvmScheme(client: x402Client, config: ConfidentialClientRegisterConfig): x402Client;
30
+ declare function registerX402zEvmClientScheme(client: x402Client, config: X402zClientRegistrationOptions): x402Client;
31
31
 
32
- declare function buildPaymentInputFromRelayer(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
32
+ declare function buildPaymentInput(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
33
33
 
34
- type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment"> & {
34
+ type X402zClientOptions = Omit<X402zClientRegistrationOptions, "buildPayment"> & {
35
35
  relayer: RelayerInstance;
36
36
  fetch?: typeof fetch;
37
37
  debug?: boolean;
@@ -39,8 +39,8 @@ type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment">
39
39
  type PayOptions = {
40
40
  headers?: Record<string, string>;
41
41
  };
42
- declare function createX402zClient(config: X402zClientConfig): {
42
+ declare function createX402zClient(config: X402zClientOptions): {
43
43
  pay(url: string, options?: PayOptions): Promise<Response>;
44
44
  };
45
45
 
46
- export { type ConfidentialClientConfig, type ConfidentialClientRegisterConfig, ConfidentialEvmScheme, type PayOptions, type X402zClientConfig, buildPaymentInputFromRelayer, createX402zClient, registerConfidentialEvmScheme };
46
+ export { type PayOptions, type X402zClientOptions, type X402zClientRegistrationOptions, type X402zClientSchemeOptions, X402zEvmClientScheme, buildPaymentInput, createX402zClient, registerX402zEvmClientScheme };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared';
5
5
  import { x402Client } from '@x402/core/client';
6
6
  export { AfterPaymentCreationHook, BeforePaymentCreationHook, OnPaymentCreationFailureHook, PaymentCreatedContext, PaymentCreationContext, PaymentCreationFailureContext, PaymentPolicy, SchemeRegistration, SelectPaymentRequirements, x402Client, x402ClientConfig, x402HTTPClient } from '@x402/core/client';
7
7
 
8
- type ConfidentialClientConfig = {
8
+ type X402zClientSchemeOptions = {
9
9
  signer: ClientEvmSigner;
10
10
  buildPayment: (requirements: PaymentRequirements) => ConfidentialPaymentInput | Promise<ConfidentialPaymentInput>;
11
11
  eip712?: {
@@ -15,23 +15,23 @@ type ConfidentialClientConfig = {
15
15
  hashEncryptedAmountInput?: (encryptedAmountInput: `0x${string}`) => `0x${string}`;
16
16
  clock?: () => number;
17
17
  };
18
- declare class ConfidentialEvmScheme implements SchemeNetworkClient {
18
+ declare class X402zEvmClientScheme implements SchemeNetworkClient {
19
19
  private readonly config;
20
20
  readonly scheme = "erc7984-mind-v1";
21
21
  private readonly hashFn;
22
22
  private readonly clock;
23
- constructor(config: ConfidentialClientConfig);
23
+ constructor(config: X402zClientSchemeOptions);
24
24
  createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
25
25
  }
26
26
 
27
- type ConfidentialClientRegisterConfig = ConfidentialClientConfig & {
27
+ type X402zClientRegistrationOptions = X402zClientSchemeOptions & {
28
28
  networks?: Network[];
29
29
  };
30
- declare function registerConfidentialEvmScheme(client: x402Client, config: ConfidentialClientRegisterConfig): x402Client;
30
+ declare function registerX402zEvmClientScheme(client: x402Client, config: X402zClientRegistrationOptions): x402Client;
31
31
 
32
- declare function buildPaymentInputFromRelayer(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
32
+ declare function buildPaymentInput(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
33
33
 
34
- type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment"> & {
34
+ type X402zClientOptions = Omit<X402zClientRegistrationOptions, "buildPayment"> & {
35
35
  relayer: RelayerInstance;
36
36
  fetch?: typeof fetch;
37
37
  debug?: boolean;
@@ -39,8 +39,8 @@ type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment">
39
39
  type PayOptions = {
40
40
  headers?: Record<string, string>;
41
41
  };
42
- declare function createX402zClient(config: X402zClientConfig): {
42
+ declare function createX402zClient(config: X402zClientOptions): {
43
43
  pay(url: string, options?: PayOptions): Promise<Response>;
44
44
  };
45
45
 
46
- export { type ConfidentialClientConfig, type ConfidentialClientRegisterConfig, ConfidentialEvmScheme, type PayOptions, type X402zClientConfig, buildPaymentInputFromRelayer, createX402zClient, registerConfidentialEvmScheme };
46
+ export { type PayOptions, type X402zClientOptions, type X402zClientRegistrationOptions, type X402zClientSchemeOptions, X402zEvmClientScheme, buildPaymentInput, createX402zClient, registerX402zEvmClientScheme };
package/dist/index.js CHANGED
@@ -20,16 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- ConfidentialEvmScheme: () => ConfidentialEvmScheme,
24
- buildPaymentInputFromRelayer: () => buildPaymentInputFromRelayer,
23
+ X402zEvmClientScheme: () => X402zEvmClientScheme,
24
+ buildPaymentInput: () => buildPaymentInput,
25
25
  createX402zClient: () => createX402zClient,
26
- registerConfidentialEvmScheme: () => registerConfidentialEvmScheme,
27
- x402Client: () => import_client2.x402Client,
28
- x402HTTPClient: () => import_client2.x402HTTPClient
26
+ registerX402zEvmClientScheme: () => registerX402zEvmClientScheme,
27
+ x402Client: () => import_client3.x402Client,
28
+ x402HTTPClient: () => import_client3.x402HTTPClient
29
29
  });
30
30
  module.exports = __toCommonJS(index_exports);
31
31
 
32
- // src/scheme.ts
32
+ // src/scheme/scheme.ts
33
33
  var import_viem = require("viem");
34
34
  var import_x402z_shared = require("x402z-shared");
35
35
  var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
@@ -45,7 +45,7 @@ function normalizeIntegerAmount(value, fallback) {
45
45
  }
46
46
  return fallbackNormalized;
47
47
  }
48
- var ConfidentialEvmScheme = class {
48
+ var X402zEvmClientScheme = class {
49
49
  constructor(config) {
50
50
  this.config = config;
51
51
  this.scheme = "erc7984-mind-v1";
@@ -112,21 +112,21 @@ var ConfidentialEvmScheme = class {
112
112
  }
113
113
  };
114
114
 
115
- // src/register.ts
116
- function registerConfidentialEvmScheme(client, config) {
115
+ // src/scheme/register.ts
116
+ function registerX402zEvmClientScheme(client, config) {
117
117
  if (config.networks && config.networks.length > 0) {
118
118
  for (const network of config.networks) {
119
- client.register(network, new ConfidentialEvmScheme(config));
119
+ client.register(network, new X402zEvmClientScheme(config));
120
120
  }
121
121
  return client;
122
122
  }
123
- client.register("eip155:*", new ConfidentialEvmScheme(config));
123
+ client.register("eip155:*", new X402zEvmClientScheme(config));
124
124
  return client;
125
125
  }
126
126
 
127
- // src/relayer.ts
127
+ // src/relayer/build.ts
128
128
  var import_x402z_shared2 = require("x402z-shared");
129
- async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
129
+ async function buildPaymentInput(relayer, requirements, amount) {
130
130
  const extra = requirements.extra;
131
131
  const batcherAddress = extra?.confidential?.batcherAddress;
132
132
  if (!batcherAddress) {
@@ -144,7 +144,7 @@ async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
144
144
  };
145
145
  }
146
146
 
147
- // src/http.ts
147
+ // src/http/client.ts
148
148
  var import_client = require("@x402/core/client");
149
149
  var import_http = require("@x402/core/http");
150
150
  var import_viem2 = require("viem");
@@ -165,6 +165,13 @@ function createX402zClient(config) {
165
165
  if (!batcherAddress) {
166
166
  throw new Error("Missing confidential.batcherAddress in payment requirements");
167
167
  }
168
+ if (debugEnabled) {
169
+ console.debug("[x402z-client] encrypt input", {
170
+ tokenAddress: requirements.asset,
171
+ batcherAddress,
172
+ amount: requirements.amount
173
+ });
174
+ }
168
175
  const encrypted = await (0, import_x402z_shared3.createEncryptedAmountInput)(
169
176
  config.relayer,
170
177
  requirements.asset,
@@ -177,7 +184,7 @@ function createX402zClient(config) {
177
184
  };
178
185
  };
179
186
  const client = new import_client.x402Client();
180
- registerConfidentialEvmScheme(client, {
187
+ registerX402zEvmClientScheme(client, {
181
188
  ...registerConfig,
182
189
  buildPayment
183
190
  });
@@ -222,13 +229,13 @@ function createX402zClient(config) {
222
229
  }
223
230
 
224
231
  // src/index.ts
225
- var import_client2 = require("@x402/core/client");
232
+ var import_client3 = require("@x402/core/client");
226
233
  // Annotate the CommonJS export names for ESM import in node:
227
234
  0 && (module.exports = {
228
- ConfidentialEvmScheme,
229
- buildPaymentInputFromRelayer,
235
+ X402zEvmClientScheme,
236
+ buildPaymentInput,
230
237
  createX402zClient,
231
- registerConfidentialEvmScheme,
238
+ registerX402zEvmClientScheme,
232
239
  x402Client,
233
240
  x402HTTPClient
234
241
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // src/scheme.ts
1
+ // src/scheme/scheme.ts
2
2
  import { getAddress } from "viem";
3
3
  import {
4
4
  confidentialPaymentTypes,
@@ -19,7 +19,7 @@ function normalizeIntegerAmount(value, fallback) {
19
19
  }
20
20
  return fallbackNormalized;
21
21
  }
22
- var ConfidentialEvmScheme = class {
22
+ var X402zEvmClientScheme = class {
23
23
  constructor(config) {
24
24
  this.config = config;
25
25
  this.scheme = "erc7984-mind-v1";
@@ -86,21 +86,21 @@ var ConfidentialEvmScheme = class {
86
86
  }
87
87
  };
88
88
 
89
- // src/register.ts
90
- function registerConfidentialEvmScheme(client, config) {
89
+ // src/scheme/register.ts
90
+ function registerX402zEvmClientScheme(client, config) {
91
91
  if (config.networks && config.networks.length > 0) {
92
92
  for (const network of config.networks) {
93
- client.register(network, new ConfidentialEvmScheme(config));
93
+ client.register(network, new X402zEvmClientScheme(config));
94
94
  }
95
95
  return client;
96
96
  }
97
- client.register("eip155:*", new ConfidentialEvmScheme(config));
97
+ client.register("eip155:*", new X402zEvmClientScheme(config));
98
98
  return client;
99
99
  }
100
100
 
101
- // src/relayer.ts
101
+ // src/relayer/build.ts
102
102
  import { createEncryptedAmountInput } from "x402z-shared";
103
- async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
103
+ async function buildPaymentInput(relayer, requirements, amount) {
104
104
  const extra = requirements.extra;
105
105
  const batcherAddress = extra?.confidential?.batcherAddress;
106
106
  if (!batcherAddress) {
@@ -118,7 +118,7 @@ async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
118
118
  };
119
119
  }
120
120
 
121
- // src/http.ts
121
+ // src/http/client.ts
122
122
  import { x402Client } from "@x402/core/client";
123
123
  import { x402HTTPClient } from "@x402/core/http";
124
124
  import { isAddress } from "viem";
@@ -141,6 +141,13 @@ function createX402zClient(config) {
141
141
  if (!batcherAddress) {
142
142
  throw new Error("Missing confidential.batcherAddress in payment requirements");
143
143
  }
144
+ if (debugEnabled) {
145
+ console.debug("[x402z-client] encrypt input", {
146
+ tokenAddress: requirements.asset,
147
+ batcherAddress,
148
+ amount: requirements.amount
149
+ });
150
+ }
144
151
  const encrypted = await createEncryptedAmountInput2(
145
152
  config.relayer,
146
153
  requirements.asset,
@@ -153,7 +160,7 @@ function createX402zClient(config) {
153
160
  };
154
161
  };
155
162
  const client = new x402Client();
156
- registerConfidentialEvmScheme(client, {
163
+ registerX402zEvmClientScheme(client, {
157
164
  ...registerConfig,
158
165
  buildPayment
159
166
  });
@@ -203,10 +210,10 @@ import {
203
210
  x402HTTPClient as x402HTTPClient2
204
211
  } from "@x402/core/client";
205
212
  export {
206
- ConfidentialEvmScheme,
207
- buildPaymentInputFromRelayer,
213
+ X402zEvmClientScheme,
214
+ buildPaymentInput,
208
215
  createX402zClient,
209
- registerConfidentialEvmScheme,
216
+ registerX402zEvmClientScheme,
210
217
  x402Client2 as x402Client,
211
218
  x402HTTPClient2 as x402HTTPClient
212
219
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-client",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -12,18 +12,13 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.mjs",
14
14
  "require": "./dist/index.js"
15
- },
16
- "./web": {
17
- "types": "./dist/web.d.ts",
18
- "import": "./dist/web.mjs",
19
- "require": "./dist/web.js"
20
15
  }
21
16
  },
22
17
  "dependencies": {
23
18
  "@x402/core": "^2.0.0",
24
19
  "@x402/evm": "^2.0.0",
25
20
  "viem": "^2.39.3",
26
- "x402z-shared": "0.0.8"
21
+ "x402z-shared": "0.0.9"
27
22
  },
28
23
  "devDependencies": {
29
24
  "jest": "^29.7.0",
@@ -31,7 +26,7 @@
31
26
  "@types/jest": "^29.5.12"
32
27
  },
33
28
  "scripts": {
34
- "build": "tsup src/index.ts src/web.ts --format cjs,esm --dts",
29
+ "build": "tsup src/index.ts --format cjs,esm --dts",
35
30
  "test": "jest"
36
31
  }
37
32
  }