x402z-client 0.0.1

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 ADDED
@@ -0,0 +1,47 @@
1
+ # x402z-client
2
+
3
+ Client-side helpers for the erc7984-mind-v1 x402 scheme.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add x402z-client x402z-shared
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createX402zClient } from "x402z-client";
15
+ import { createRelayerInstance, SepoliaConfig } from "x402z-shared";
16
+ import { privateKeyToAccount } from "viem/accounts";
17
+
18
+ const account = privateKeyToAccount("0x...");
19
+ const relayer = await createRelayerInstance(SepoliaConfig);
20
+
21
+ const client = createX402zClient({
22
+ signer: {
23
+ address: account.address,
24
+ signTypedData: account.signTypedData,
25
+ },
26
+ relayer,
27
+ });
28
+
29
+ const response = await client.pay("https://example.com/demo");
30
+ console.log(response.status);
31
+ ```
32
+
33
+ `createX402zClient` builds the confidential payment input automatically using the
34
+ `confidential.facilitatorAddress` provided by the server’s payment requirements.
35
+
36
+ ## API
37
+
38
+ - `createX402zClient(config)`
39
+ - `signer` (required): EIP-712 signer for x402 payloads
40
+ - `relayer` (required): Zama relayer instance used to build encrypted inputs
41
+ - `fetch` (optional): custom fetch implementation
42
+ - `client.pay(url, options?)`: performs the 402 handshake and retries with payment headers
43
+
44
+ ## Notes
45
+
46
+ - Scheme name: `erc7984-mind-v1`
47
+ - The client does not expose balance helpers; use `x402z-shared` for that.
@@ -0,0 +1,46 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from '@x402/core/types';
2
+ export * from '@x402/core/types';
3
+ import { ClientEvmSigner } from '@x402/evm';
4
+ import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared';
5
+ import { x402Client } from '@x402/core/client';
6
+ export { AfterPaymentCreationHook, BeforePaymentCreationHook, OnPaymentCreationFailureHook, PaymentCreatedContext, PaymentCreationContext, PaymentCreationFailureContext, PaymentPolicy, SchemeRegistration, SelectPaymentRequirements, x402Client, x402ClientConfig, x402HTTPClient } from '@x402/core/client';
7
+
8
+ type ConfidentialClientConfig = {
9
+ signer: ClientEvmSigner;
10
+ buildPayment: (requirements: PaymentRequirements) => ConfidentialPaymentInput | Promise<ConfidentialPaymentInput>;
11
+ eip712?: {
12
+ name: string;
13
+ version: string;
14
+ };
15
+ hashEncryptedAmountInput?: (encryptedAmountInput: `0x${string}`) => `0x${string}`;
16
+ clock?: () => number;
17
+ };
18
+ declare class ConfidentialEvmScheme implements SchemeNetworkClient {
19
+ private readonly config;
20
+ readonly scheme = "erc7984-mind-v1";
21
+ private readonly hashFn;
22
+ private readonly clock;
23
+ constructor(config: ConfidentialClientConfig);
24
+ createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
25
+ }
26
+
27
+ type ConfidentialClientRegisterConfig = ConfidentialClientConfig & {
28
+ networks?: Network[];
29
+ };
30
+ declare function registerConfidentialEvmScheme(client: x402Client, config: ConfidentialClientRegisterConfig): x402Client;
31
+
32
+ declare function buildPaymentInputFromRelayer(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
33
+
34
+ type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment"> & {
35
+ relayer: RelayerInstance;
36
+ fetch?: typeof fetch;
37
+ debug?: boolean;
38
+ };
39
+ type PayOptions = {
40
+ headers?: Record<string, string>;
41
+ };
42
+ declare function createX402zClient(config: X402zClientConfig): {
43
+ pay(url: string, options?: PayOptions): Promise<Response>;
44
+ };
45
+
46
+ export { type ConfidentialClientConfig, type ConfidentialClientRegisterConfig, ConfidentialEvmScheme, type PayOptions, type X402zClientConfig, buildPaymentInputFromRelayer, createX402zClient, registerConfidentialEvmScheme };
@@ -0,0 +1,46 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from '@x402/core/types';
2
+ export * from '@x402/core/types';
3
+ import { ClientEvmSigner } from '@x402/evm';
4
+ import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared';
5
+ import { x402Client } from '@x402/core/client';
6
+ export { AfterPaymentCreationHook, BeforePaymentCreationHook, OnPaymentCreationFailureHook, PaymentCreatedContext, PaymentCreationContext, PaymentCreationFailureContext, PaymentPolicy, SchemeRegistration, SelectPaymentRequirements, x402Client, x402ClientConfig, x402HTTPClient } from '@x402/core/client';
7
+
8
+ type ConfidentialClientConfig = {
9
+ signer: ClientEvmSigner;
10
+ buildPayment: (requirements: PaymentRequirements) => ConfidentialPaymentInput | Promise<ConfidentialPaymentInput>;
11
+ eip712?: {
12
+ name: string;
13
+ version: string;
14
+ };
15
+ hashEncryptedAmountInput?: (encryptedAmountInput: `0x${string}`) => `0x${string}`;
16
+ clock?: () => number;
17
+ };
18
+ declare class ConfidentialEvmScheme implements SchemeNetworkClient {
19
+ private readonly config;
20
+ readonly scheme = "erc7984-mind-v1";
21
+ private readonly hashFn;
22
+ private readonly clock;
23
+ constructor(config: ConfidentialClientConfig);
24
+ createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
25
+ }
26
+
27
+ type ConfidentialClientRegisterConfig = ConfidentialClientConfig & {
28
+ networks?: Network[];
29
+ };
30
+ declare function registerConfidentialEvmScheme(client: x402Client, config: ConfidentialClientRegisterConfig): x402Client;
31
+
32
+ declare function buildPaymentInputFromRelayer(relayer: RelayerInstance, requirements: PaymentRequirements, amount: number): Promise<ConfidentialPaymentInput>;
33
+
34
+ type X402zClientConfig = Omit<ConfidentialClientRegisterConfig, "buildPayment"> & {
35
+ relayer: RelayerInstance;
36
+ fetch?: typeof fetch;
37
+ debug?: boolean;
38
+ };
39
+ type PayOptions = {
40
+ headers?: Record<string, string>;
41
+ };
42
+ declare function createX402zClient(config: X402zClientConfig): {
43
+ pay(url: string, options?: PayOptions): Promise<Response>;
44
+ };
45
+
46
+ export { type ConfidentialClientConfig, type ConfidentialClientRegisterConfig, ConfidentialEvmScheme, type PayOptions, type X402zClientConfig, buildPaymentInputFromRelayer, createX402zClient, registerConfidentialEvmScheme };
package/dist/index.js ADDED
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ConfidentialEvmScheme: () => ConfidentialEvmScheme,
24
+ buildPaymentInputFromRelayer: () => buildPaymentInputFromRelayer,
25
+ createX402zClient: () => createX402zClient,
26
+ registerConfidentialEvmScheme: () => registerConfidentialEvmScheme,
27
+ x402Client: () => import_client2.x402Client,
28
+ x402HTTPClient: () => import_client2.x402HTTPClient
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+
32
+ // src/scheme.ts
33
+ var import_viem = require("viem");
34
+ var import_x402z_shared = require("x402z-shared");
35
+ var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
36
+ var ConfidentialEvmScheme = class {
37
+ constructor(config) {
38
+ this.config = config;
39
+ this.scheme = "erc7984-mind-v1";
40
+ this.hashFn = config.hashEncryptedAmountInput ?? import_x402z_shared.hashEncryptedAmountInput;
41
+ this.clock = config.clock ?? (() => Math.floor(Date.now() / 1e3));
42
+ }
43
+ async createPaymentPayload(x402Version, paymentRequirements) {
44
+ const input = await this.config.buildPayment(paymentRequirements);
45
+ const extra = paymentRequirements.extra;
46
+ const eip712 = extra?.eip712 ?? this.config.eip712;
47
+ if (!eip712?.name || !eip712?.version) {
48
+ throw new Error("Missing EIP-712 domain parameters (name, version) in requirements or config");
49
+ }
50
+ const now = this.clock();
51
+ const validAfter = input.validAfter ?? Math.max(0, now - 60);
52
+ const validBefore = input.validBefore ?? now + paymentRequirements.maxTimeoutSeconds;
53
+ const nonce = input.nonce ?? (0, import_x402z_shared.createNonce)();
54
+ const maxClearAmount = input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? (0, import_x402z_shared.normalizeAmount)(paymentRequirements.amount);
55
+ const resourceHash = input.resourceHash ?? extra?.confidential?.resourceHash ?? ZERO_BYTES32;
56
+ const authorization = {
57
+ holder: this.config.signer.address,
58
+ payee: (0, import_viem.getAddress)(paymentRequirements.payTo),
59
+ maxClearAmount,
60
+ resourceHash,
61
+ validAfter: (0, import_x402z_shared.normalizeAmount)(validAfter),
62
+ validBefore: (0, import_x402z_shared.normalizeAmount)(validBefore),
63
+ nonce,
64
+ encryptedAmountHash: this.hashFn(input.encryptedAmountInput)
65
+ };
66
+ const chainId = parseInt(paymentRequirements.network.split(":")[1]);
67
+ const signature = await this.config.signer.signTypedData({
68
+ domain: {
69
+ name: eip712.name,
70
+ version: eip712.version,
71
+ chainId,
72
+ verifyingContract: (0, import_viem.getAddress)(paymentRequirements.asset)
73
+ },
74
+ types: import_x402z_shared.confidentialPaymentTypes,
75
+ primaryType: "ConfidentialPayment",
76
+ message: {
77
+ holder: (0, import_viem.getAddress)(authorization.holder),
78
+ payee: (0, import_viem.getAddress)(authorization.payee),
79
+ maxClearAmount: BigInt(authorization.maxClearAmount),
80
+ resourceHash: authorization.resourceHash,
81
+ validAfter: BigInt(authorization.validAfter),
82
+ validBefore: BigInt(authorization.validBefore),
83
+ nonce: authorization.nonce,
84
+ encryptedAmountHash: authorization.encryptedAmountHash
85
+ }
86
+ });
87
+ const payload = {
88
+ authorization,
89
+ signature,
90
+ encryptedAmountInput: input.encryptedAmountInput,
91
+ inputProof: input.inputProof
92
+ };
93
+ return {
94
+ x402Version,
95
+ payload
96
+ };
97
+ }
98
+ };
99
+
100
+ // src/register.ts
101
+ function registerConfidentialEvmScheme(client, config) {
102
+ if (config.networks && config.networks.length > 0) {
103
+ for (const network of config.networks) {
104
+ client.register(network, new ConfidentialEvmScheme(config));
105
+ }
106
+ return client;
107
+ }
108
+ client.register("eip155:*", new ConfidentialEvmScheme(config));
109
+ return client;
110
+ }
111
+
112
+ // src/relayer.ts
113
+ var import_x402z_shared2 = require("x402z-shared");
114
+ async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
115
+ const extra = requirements.extra;
116
+ const facilitatorAddress = extra?.confidential?.facilitatorAddress;
117
+ if (!facilitatorAddress) {
118
+ throw new Error("Missing confidential.facilitatorAddress in payment requirements");
119
+ }
120
+ const encrypted = await (0, import_x402z_shared2.createEncryptedAmountInput)(
121
+ relayer,
122
+ requirements.asset,
123
+ facilitatorAddress,
124
+ amount
125
+ );
126
+ return {
127
+ encryptedAmountInput: encrypted.handle,
128
+ inputProof: encrypted.inputProof
129
+ };
130
+ }
131
+
132
+ // src/http.ts
133
+ var import_client = require("@x402/core/client");
134
+ var import_http = require("@x402/core/http");
135
+ var import_viem2 = require("viem");
136
+ var import_x402z_shared3 = require("x402z-shared");
137
+ function createX402zClient(config) {
138
+ const { fetch: fetchOverride, ...registerConfig } = config;
139
+ const fetchFn = fetchOverride ?? globalThis.fetch;
140
+ const debugEnabled = config.debug ?? process.env.X402Z_DEBUG === "1";
141
+ if (!fetchFn) {
142
+ throw new Error("fetch is not available; provide a fetch implementation");
143
+ }
144
+ const buildPayment = async (requirements) => {
145
+ if (!(0, import_viem2.isAddress)(requirements.asset)) {
146
+ throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
147
+ }
148
+ const extra = requirements.extra;
149
+ const facilitatorAddress = extra?.confidential?.facilitatorAddress;
150
+ if (!facilitatorAddress) {
151
+ throw new Error("Missing confidential.facilitatorAddress in payment requirements");
152
+ }
153
+ const encrypted = await (0, import_x402z_shared3.createEncryptedAmountInput)(
154
+ config.relayer,
155
+ requirements.asset,
156
+ facilitatorAddress,
157
+ Number(requirements.amount)
158
+ );
159
+ return {
160
+ encryptedAmountInput: encrypted.handle,
161
+ inputProof: encrypted.inputProof
162
+ };
163
+ };
164
+ const client = new import_client.x402Client();
165
+ registerConfidentialEvmScheme(client, {
166
+ ...registerConfig,
167
+ buildPayment
168
+ });
169
+ const httpClient = new import_http.x402HTTPClient(client);
170
+ return {
171
+ async pay(url, options) {
172
+ const initial = await fetchFn(url, { headers: options?.headers });
173
+ if (initial.status !== 402) {
174
+ return initial;
175
+ }
176
+ const paymentRequired = httpClient.getPaymentRequiredResponse(
177
+ (name) => initial.headers.get(name),
178
+ await initial.json().catch(() => ({}))
179
+ );
180
+ const payload = await httpClient.createPaymentPayload(paymentRequired);
181
+ const payHeaders = httpClient.encodePaymentSignatureHeader(payload);
182
+ if (debugEnabled) {
183
+ console.debug("[x402z-client] payment payload", payload);
184
+ console.debug("[x402z-client] payment headers", payHeaders);
185
+ }
186
+ const mergedHeaders = { ...options?.headers ?? {}, ...payHeaders };
187
+ const paidResponse = await fetchFn(url, { headers: mergedHeaders });
188
+ if (debugEnabled) {
189
+ try {
190
+ const body = await paidResponse.clone().text();
191
+ console.debug("[x402z-client] response", {
192
+ status: paidResponse.status,
193
+ headers: Object.fromEntries(paidResponse.headers.entries()),
194
+ body
195
+ });
196
+ } catch (error) {
197
+ console.debug("[x402z-client] response", {
198
+ status: paidResponse.status,
199
+ headers: Object.fromEntries(paidResponse.headers.entries()),
200
+ body: "<unavailable>"
201
+ });
202
+ }
203
+ }
204
+ return paidResponse;
205
+ }
206
+ };
207
+ }
208
+
209
+ // src/index.ts
210
+ var import_client2 = require("@x402/core/client");
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ ConfidentialEvmScheme,
214
+ buildPaymentInputFromRelayer,
215
+ createX402zClient,
216
+ registerConfidentialEvmScheme,
217
+ x402Client,
218
+ x402HTTPClient
219
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,197 @@
1
+ // src/scheme.ts
2
+ import { getAddress } from "viem";
3
+ import {
4
+ confidentialPaymentTypes,
5
+ createNonce,
6
+ hashEncryptedAmountInput,
7
+ normalizeAmount
8
+ } from "x402z-shared";
9
+ var ZERO_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
10
+ var ConfidentialEvmScheme = class {
11
+ constructor(config) {
12
+ this.config = config;
13
+ this.scheme = "erc7984-mind-v1";
14
+ this.hashFn = config.hashEncryptedAmountInput ?? hashEncryptedAmountInput;
15
+ this.clock = config.clock ?? (() => Math.floor(Date.now() / 1e3));
16
+ }
17
+ async createPaymentPayload(x402Version, paymentRequirements) {
18
+ const input = await this.config.buildPayment(paymentRequirements);
19
+ const extra = paymentRequirements.extra;
20
+ const eip712 = extra?.eip712 ?? this.config.eip712;
21
+ if (!eip712?.name || !eip712?.version) {
22
+ throw new Error("Missing EIP-712 domain parameters (name, version) in requirements or config");
23
+ }
24
+ const now = this.clock();
25
+ const validAfter = input.validAfter ?? Math.max(0, now - 60);
26
+ const validBefore = input.validBefore ?? now + paymentRequirements.maxTimeoutSeconds;
27
+ const nonce = input.nonce ?? createNonce();
28
+ const maxClearAmount = input.maxClearAmount ?? extra?.confidential?.maxClearAmount ?? normalizeAmount(paymentRequirements.amount);
29
+ const resourceHash = input.resourceHash ?? extra?.confidential?.resourceHash ?? ZERO_BYTES32;
30
+ const authorization = {
31
+ holder: this.config.signer.address,
32
+ payee: getAddress(paymentRequirements.payTo),
33
+ maxClearAmount,
34
+ resourceHash,
35
+ validAfter: normalizeAmount(validAfter),
36
+ validBefore: normalizeAmount(validBefore),
37
+ nonce,
38
+ encryptedAmountHash: this.hashFn(input.encryptedAmountInput)
39
+ };
40
+ const chainId = parseInt(paymentRequirements.network.split(":")[1]);
41
+ const signature = await this.config.signer.signTypedData({
42
+ domain: {
43
+ name: eip712.name,
44
+ version: eip712.version,
45
+ chainId,
46
+ verifyingContract: getAddress(paymentRequirements.asset)
47
+ },
48
+ types: confidentialPaymentTypes,
49
+ primaryType: "ConfidentialPayment",
50
+ message: {
51
+ holder: getAddress(authorization.holder),
52
+ payee: getAddress(authorization.payee),
53
+ maxClearAmount: BigInt(authorization.maxClearAmount),
54
+ resourceHash: authorization.resourceHash,
55
+ validAfter: BigInt(authorization.validAfter),
56
+ validBefore: BigInt(authorization.validBefore),
57
+ nonce: authorization.nonce,
58
+ encryptedAmountHash: authorization.encryptedAmountHash
59
+ }
60
+ });
61
+ const payload = {
62
+ authorization,
63
+ signature,
64
+ encryptedAmountInput: input.encryptedAmountInput,
65
+ inputProof: input.inputProof
66
+ };
67
+ return {
68
+ x402Version,
69
+ payload
70
+ };
71
+ }
72
+ };
73
+
74
+ // src/register.ts
75
+ function registerConfidentialEvmScheme(client, config) {
76
+ if (config.networks && config.networks.length > 0) {
77
+ for (const network of config.networks) {
78
+ client.register(network, new ConfidentialEvmScheme(config));
79
+ }
80
+ return client;
81
+ }
82
+ client.register("eip155:*", new ConfidentialEvmScheme(config));
83
+ return client;
84
+ }
85
+
86
+ // src/relayer.ts
87
+ import { createEncryptedAmountInput } from "x402z-shared";
88
+ async function buildPaymentInputFromRelayer(relayer, requirements, amount) {
89
+ const extra = requirements.extra;
90
+ const facilitatorAddress = extra?.confidential?.facilitatorAddress;
91
+ if (!facilitatorAddress) {
92
+ throw new Error("Missing confidential.facilitatorAddress in payment requirements");
93
+ }
94
+ const encrypted = await createEncryptedAmountInput(
95
+ relayer,
96
+ requirements.asset,
97
+ facilitatorAddress,
98
+ amount
99
+ );
100
+ return {
101
+ encryptedAmountInput: encrypted.handle,
102
+ inputProof: encrypted.inputProof
103
+ };
104
+ }
105
+
106
+ // src/http.ts
107
+ import { x402Client } from "@x402/core/client";
108
+ import { x402HTTPClient } from "@x402/core/http";
109
+ import { isAddress } from "viem";
110
+ import {
111
+ createEncryptedAmountInput as createEncryptedAmountInput2
112
+ } from "x402z-shared";
113
+ function createX402zClient(config) {
114
+ const { fetch: fetchOverride, ...registerConfig } = config;
115
+ const fetchFn = fetchOverride ?? globalThis.fetch;
116
+ const debugEnabled = config.debug ?? process.env.X402Z_DEBUG === "1";
117
+ if (!fetchFn) {
118
+ throw new Error("fetch is not available; provide a fetch implementation");
119
+ }
120
+ const buildPayment = async (requirements) => {
121
+ if (!isAddress(requirements.asset)) {
122
+ throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
123
+ }
124
+ const extra = requirements.extra;
125
+ const facilitatorAddress = extra?.confidential?.facilitatorAddress;
126
+ if (!facilitatorAddress) {
127
+ throw new Error("Missing confidential.facilitatorAddress in payment requirements");
128
+ }
129
+ const encrypted = await createEncryptedAmountInput2(
130
+ config.relayer,
131
+ requirements.asset,
132
+ facilitatorAddress,
133
+ Number(requirements.amount)
134
+ );
135
+ return {
136
+ encryptedAmountInput: encrypted.handle,
137
+ inputProof: encrypted.inputProof
138
+ };
139
+ };
140
+ const client = new x402Client();
141
+ registerConfidentialEvmScheme(client, {
142
+ ...registerConfig,
143
+ buildPayment
144
+ });
145
+ const httpClient = new x402HTTPClient(client);
146
+ return {
147
+ async pay(url, options) {
148
+ const initial = await fetchFn(url, { headers: options?.headers });
149
+ if (initial.status !== 402) {
150
+ return initial;
151
+ }
152
+ const paymentRequired = httpClient.getPaymentRequiredResponse(
153
+ (name) => initial.headers.get(name),
154
+ await initial.json().catch(() => ({}))
155
+ );
156
+ const payload = await httpClient.createPaymentPayload(paymentRequired);
157
+ const payHeaders = httpClient.encodePaymentSignatureHeader(payload);
158
+ if (debugEnabled) {
159
+ console.debug("[x402z-client] payment payload", payload);
160
+ console.debug("[x402z-client] payment headers", payHeaders);
161
+ }
162
+ const mergedHeaders = { ...options?.headers ?? {}, ...payHeaders };
163
+ const paidResponse = await fetchFn(url, { headers: mergedHeaders });
164
+ if (debugEnabled) {
165
+ try {
166
+ const body = await paidResponse.clone().text();
167
+ console.debug("[x402z-client] response", {
168
+ status: paidResponse.status,
169
+ headers: Object.fromEntries(paidResponse.headers.entries()),
170
+ body
171
+ });
172
+ } catch (error) {
173
+ console.debug("[x402z-client] response", {
174
+ status: paidResponse.status,
175
+ headers: Object.fromEntries(paidResponse.headers.entries()),
176
+ body: "<unavailable>"
177
+ });
178
+ }
179
+ }
180
+ return paidResponse;
181
+ }
182
+ };
183
+ }
184
+
185
+ // src/index.ts
186
+ import {
187
+ x402Client as x402Client2,
188
+ x402HTTPClient as x402HTTPClient2
189
+ } from "@x402/core/client";
190
+ export {
191
+ ConfidentialEvmScheme,
192
+ buildPaymentInputFromRelayer,
193
+ createX402zClient,
194
+ registerConfidentialEvmScheme,
195
+ x402Client2 as x402Client,
196
+ x402HTTPClient2 as x402HTTPClient
197
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "x402z-client",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@x402/core": "^2.0.0",
12
+ "@x402/evm": "^2.0.0",
13
+ "viem": "^2.39.3",
14
+ "x402z-shared": "0.0.1"
15
+ },
16
+ "devDependencies": {
17
+ "jest": "^29.7.0",
18
+ "ts-jest": "^29.2.5",
19
+ "@types/jest": "^29.5.12"
20
+ },
21
+ "scripts": {
22
+ "build": "tsup src/index.ts --format cjs,esm --dts",
23
+ "test": "jest"
24
+ }
25
+ }