x402z-client-web 0.0.9 → 0.0.10
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 +17 -5
- package/dist/index.d.mts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +3 -8
- package/dist/index.mjs +4 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,15 +18,26 @@ pnpm add x402z-client-web x402z-shared-web
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import { createX402zClient } from "x402z-client-web";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
import {
|
|
22
|
+
createRelayer,
|
|
23
|
+
getSepoliaConfig,
|
|
24
|
+
} from "x402z-shared-web";
|
|
25
|
+
import type { FhevmInstanceConfig } from "x402z-shared-web";
|
|
26
|
+
|
|
27
|
+
const relayerConfig: FhevmInstanceConfig = {
|
|
28
|
+
...(getSepoliaConfig() as object),
|
|
29
|
+
network: window.ethereum,
|
|
30
|
+
relayerUrl: "https://relayer.testnet.zama.org",
|
|
31
|
+
};
|
|
32
|
+
const relayer = await createRelayer(relayerConfig);
|
|
33
|
+
|
|
34
|
+
const client = createX402zClient({
|
|
24
35
|
signer: {
|
|
25
36
|
address: "0x...",
|
|
26
37
|
signTypedData: async args =>
|
|
27
38
|
window.ethereum.request({ method: "eth_signTypedData_v4", params: [args] }),
|
|
28
39
|
},
|
|
29
|
-
|
|
40
|
+
relayer,
|
|
30
41
|
});
|
|
31
42
|
|
|
32
43
|
const response = await client.pay("https://example.com/demo");
|
|
@@ -35,12 +46,13 @@ console.log(response.status);
|
|
|
35
46
|
|
|
36
47
|
`createX402zClient` builds the confidential payment input automatically using the
|
|
37
48
|
`confidential.batcherAddress` provided by the server’s payment requirements.
|
|
49
|
+
`createRelayer` calls `initSDK()` automatically on first use.
|
|
38
50
|
|
|
39
51
|
## API
|
|
40
52
|
|
|
41
53
|
- `createX402zClient(config)`
|
|
42
54
|
- `signer` (required): EIP-712 signer for x402 payloads
|
|
43
|
-
- `
|
|
55
|
+
- `relayer` (required): relayer instance (browser)
|
|
44
56
|
- `fetch` (optional): custom fetch implementation
|
|
45
57
|
- `client.pay(url, options?)`: performs the 402 handshake and retries with payment headers
|
|
46
58
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfidentialPaymentInput,
|
|
1
|
+
import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared-web';
|
|
2
2
|
export { ConfidentialRequirementsExtra, RelayerInstance } from 'x402z-shared-web';
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { PaymentRequirements, SchemeNetworkClient, PaymentPayload, Network } from '@x402/core/types';
|
|
@@ -30,9 +30,7 @@ type X402zClientRegistrationOptions = X402zClientSchemeOptions & {
|
|
|
30
30
|
declare function registerX402zEvmClientScheme(client: x402Client, config: X402zClientRegistrationOptions): x402Client;
|
|
31
31
|
|
|
32
32
|
type X402zClientOptions = Omit<X402zClientRegistrationOptions, "buildPayment"> & {
|
|
33
|
-
|
|
34
|
-
relayerConfig: unknown;
|
|
35
|
-
initSdkParams?: Parameters<typeof initSDK>[0];
|
|
33
|
+
relayer: RelayerInstance;
|
|
36
34
|
fetch?: typeof fetch;
|
|
37
35
|
debug?: boolean;
|
|
38
36
|
};
|
|
@@ -43,6 +41,6 @@ type X402zClient = {
|
|
|
43
41
|
relayer: RelayerInstance;
|
|
44
42
|
pay: (url: string, options?: PayOptions) => Promise<Response>;
|
|
45
43
|
};
|
|
46
|
-
declare function createX402zClient(config: X402zClientOptions):
|
|
44
|
+
declare function createX402zClient(config: X402zClientOptions): X402zClient;
|
|
47
45
|
|
|
48
46
|
export { type PayOptions, type X402zClient, type X402zClientOptions, type X402zClientRegistrationOptions, type X402zClientSchemeOptions, X402zEvmClientScheme, createX402zClient, registerX402zEvmClientScheme };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfidentialPaymentInput,
|
|
1
|
+
import { ConfidentialPaymentInput, RelayerInstance } from 'x402z-shared-web';
|
|
2
2
|
export { ConfidentialRequirementsExtra, RelayerInstance } from 'x402z-shared-web';
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { PaymentRequirements, SchemeNetworkClient, PaymentPayload, Network } from '@x402/core/types';
|
|
@@ -30,9 +30,7 @@ type X402zClientRegistrationOptions = X402zClientSchemeOptions & {
|
|
|
30
30
|
declare function registerX402zEvmClientScheme(client: x402Client, config: X402zClientRegistrationOptions): x402Client;
|
|
31
31
|
|
|
32
32
|
type X402zClientOptions = Omit<X402zClientRegistrationOptions, "buildPayment"> & {
|
|
33
|
-
|
|
34
|
-
relayerConfig: unknown;
|
|
35
|
-
initSdkParams?: Parameters<typeof initSDK>[0];
|
|
33
|
+
relayer: RelayerInstance;
|
|
36
34
|
fetch?: typeof fetch;
|
|
37
35
|
debug?: boolean;
|
|
38
36
|
};
|
|
@@ -43,6 +41,6 @@ type X402zClient = {
|
|
|
43
41
|
relayer: RelayerInstance;
|
|
44
42
|
pay: (url: string, options?: PayOptions) => Promise<Response>;
|
|
45
43
|
};
|
|
46
|
-
declare function createX402zClient(config: X402zClientOptions):
|
|
44
|
+
declare function createX402zClient(config: X402zClientOptions): X402zClient;
|
|
47
45
|
|
|
48
46
|
export { type PayOptions, type X402zClient, type X402zClientOptions, type X402zClientRegistrationOptions, type X402zClientSchemeOptions, X402zEvmClientScheme, createX402zClient, registerX402zEvmClientScheme };
|
package/dist/index.js
CHANGED
|
@@ -128,18 +128,13 @@ function registerX402zEvmClientScheme(client, config) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/http/client.ts
|
|
131
|
-
|
|
131
|
+
function createX402zClient(config) {
|
|
132
132
|
const { fetch: fetchOverride, ...registerConfig } = config;
|
|
133
133
|
const fetchFn = fetchOverride ?? globalThis.fetch;
|
|
134
134
|
const debugEnabled = config.debug ?? false;
|
|
135
135
|
if (!fetchFn) {
|
|
136
136
|
throw new Error("fetch is not available; provide a fetch implementation");
|
|
137
137
|
}
|
|
138
|
-
if (config.relayerSdk) {
|
|
139
|
-
(0, import_x402z_shared_web2.configureRelayerSdk)(config.relayerSdk);
|
|
140
|
-
}
|
|
141
|
-
await (0, import_x402z_shared_web2.initSDK)(config.initSdkParams);
|
|
142
|
-
const relayer = await (0, import_x402z_shared_web2.createRelayer)(config.relayerConfig);
|
|
143
138
|
const buildPayment = async (requirements) => {
|
|
144
139
|
if (!(0, import_viem2.isAddress)(requirements.asset)) {
|
|
145
140
|
throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
|
|
@@ -157,7 +152,7 @@ async function createX402zClient(config) {
|
|
|
157
152
|
});
|
|
158
153
|
}
|
|
159
154
|
const encrypted = await (0, import_x402z_shared_web2.createEncryptedAmountInput)(
|
|
160
|
-
relayer,
|
|
155
|
+
config.relayer,
|
|
161
156
|
requirements.asset,
|
|
162
157
|
batcherAddress,
|
|
163
158
|
Number(requirements.amount)
|
|
@@ -174,7 +169,7 @@ async function createX402zClient(config) {
|
|
|
174
169
|
});
|
|
175
170
|
const httpClient = new import_http.x402HTTPClient(client);
|
|
176
171
|
return {
|
|
177
|
-
relayer,
|
|
172
|
+
relayer: config.relayer,
|
|
178
173
|
async pay(url, options) {
|
|
179
174
|
const initial = await fetchFn(url, { headers: options?.headers });
|
|
180
175
|
if (initial.status !== 402) {
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,7 @@ import { x402Client } from "@x402/core/client";
|
|
|
3
3
|
import { x402HTTPClient } from "@x402/core/http";
|
|
4
4
|
import { isAddress } from "viem";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
createEncryptedAmountInput,
|
|
8
|
-
createRelayer,
|
|
9
|
-
initSDK
|
|
6
|
+
createEncryptedAmountInput
|
|
10
7
|
} from "x402z-shared-web";
|
|
11
8
|
|
|
12
9
|
// src/scheme/scheme.ts
|
|
@@ -110,18 +107,13 @@ function registerX402zEvmClientScheme(client, config) {
|
|
|
110
107
|
}
|
|
111
108
|
|
|
112
109
|
// src/http/client.ts
|
|
113
|
-
|
|
110
|
+
function createX402zClient(config) {
|
|
114
111
|
const { fetch: fetchOverride, ...registerConfig } = config;
|
|
115
112
|
const fetchFn = fetchOverride ?? globalThis.fetch;
|
|
116
113
|
const debugEnabled = config.debug ?? false;
|
|
117
114
|
if (!fetchFn) {
|
|
118
115
|
throw new Error("fetch is not available; provide a fetch implementation");
|
|
119
116
|
}
|
|
120
|
-
if (config.relayerSdk) {
|
|
121
|
-
configureRelayerSdk(config.relayerSdk);
|
|
122
|
-
}
|
|
123
|
-
await initSDK(config.initSdkParams);
|
|
124
|
-
const relayer = await createRelayer(config.relayerConfig);
|
|
125
117
|
const buildPayment = async (requirements) => {
|
|
126
118
|
if (!isAddress(requirements.asset)) {
|
|
127
119
|
throw new Error(`Invalid TOKEN_ADDRESS from requirements: ${requirements.asset}`);
|
|
@@ -139,7 +131,7 @@ async function createX402zClient(config) {
|
|
|
139
131
|
});
|
|
140
132
|
}
|
|
141
133
|
const encrypted = await createEncryptedAmountInput(
|
|
142
|
-
relayer,
|
|
134
|
+
config.relayer,
|
|
143
135
|
requirements.asset,
|
|
144
136
|
batcherAddress,
|
|
145
137
|
Number(requirements.amount)
|
|
@@ -156,7 +148,7 @@ async function createX402zClient(config) {
|
|
|
156
148
|
});
|
|
157
149
|
const httpClient = new x402HTTPClient(client);
|
|
158
150
|
return {
|
|
159
|
-
relayer,
|
|
151
|
+
relayer: config.relayer,
|
|
160
152
|
async pay(url, options) {
|
|
161
153
|
const initial = await fetchFn(url, { headers: options?.headers });
|
|
162
154
|
if (initial.status !== 402) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x402z-client-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@x402/core": "^2.0.0",
|
|
19
19
|
"@x402/evm": "^2.0.0",
|
|
20
20
|
"viem": "^2.39.3",
|
|
21
|
-
"x402z-shared-web": "0.0.
|
|
21
|
+
"x402z-shared-web": "0.0.10"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"jest": "^29.7.0",
|