@puga-labs/x402-mantle-sdk 0.3.2 → 0.3.3

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.
Files changed (53) hide show
  1. package/dist/{chunk-GHUWTX7J.js → chunk-CXRILT3C.js} +4 -2
  2. package/dist/{chunk-6GLR5EBK.js → chunk-QWQUSRLY.js} +5 -2
  3. package/dist/{chunk-BRGW36P7.js → chunk-ZLCKBFVJ.js} +27 -1
  4. package/dist/{chunk-WFUDGBKK.js → chunk-ZROK2XOB.js} +4 -2
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/server-express.cjs +1 -1
  8. package/dist/server-express.js +2 -2
  9. package/dist/server-nextjs.cjs +1 -1
  10. package/dist/server-nextjs.js +2 -2
  11. package/dist/server-web.cjs +1 -1
  12. package/dist/server-web.js +2 -2
  13. package/dist/server.cjs +1 -1
  14. package/dist/server.js +4 -4
  15. package/package.json +2 -2
  16. package/dist/chunk-CTI5CRDY.js +0 -274
  17. package/dist/chunk-DA6ZBXNO.js +0 -275
  18. package/dist/chunk-FD4HG7KR.js +0 -135
  19. package/dist/chunk-FHU6CFHF.js +0 -0
  20. package/dist/chunk-GWVWPS3R.js +0 -277
  21. package/dist/chunk-HTZ3QFY4.js +0 -135
  22. package/dist/chunk-MQALBRGV.js +0 -135
  23. package/dist/chunk-PYIYE3HI.js +0 -135
  24. package/dist/chunk-Q6SPMEIW.js +0 -235
  25. package/dist/chunk-RNKXSBT7.js +0 -135
  26. package/dist/chunk-SPCXFN7C.js +0 -284
  27. package/dist/chunk-T5DRYLNB.js +0 -135
  28. package/dist/chunk-TSEE5NSJ.js +0 -297
  29. package/dist/chunk-WAKJRVUP.js +0 -135
  30. package/dist/chunk-WELDWRDX.js +0 -307
  31. package/dist/chunk-XAQGMFSR.js +0 -56
  32. package/dist/constants-C7aY8u5b.d.cts +0 -77
  33. package/dist/constants-C7aY8u5b.d.ts +0 -77
  34. package/dist/constants-CVFF0ray.d.ts +0 -17
  35. package/dist/constants-DzCGK0Q3.d.cts +0 -17
  36. package/dist/createMantleClient-DS1Ghqrz.d.cts +0 -51
  37. package/dist/createMantleClient-DS1Ghqrz.d.ts +0 -51
  38. package/dist/createMantleClient-DVFkbBfS.d.ts +0 -87
  39. package/dist/createMantleClient-NN0Nitp9.d.cts +0 -87
  40. package/dist/express-Ck7eryef.d.cts +0 -66
  41. package/dist/express-CmEg5hR3.d.ts +0 -66
  42. package/dist/nextjs-Bp8DxYDN.d.ts +0 -45
  43. package/dist/nextjs-CliiaTPe.d.cts +0 -45
  44. package/dist/nextjs-D7t-BC4N.d.ts +0 -45
  45. package/dist/nextjs-ZO2J9mdo.d.cts +0 -45
  46. package/dist/types-2zqbJvcz.d.cts +0 -63
  47. package/dist/types-2zqbJvcz.d.ts +0 -63
  48. package/dist/types-C7EPJ6Hd.d.ts +0 -85
  49. package/dist/types-CEttmr1U.d.cts +0 -97
  50. package/dist/types-D20K36pc.d.ts +0 -97
  51. package/dist/types-xkNm0uzE.d.cts +0 -85
  52. package/dist/web-standards-C3D2vdTg.d.ts +0 -77
  53. package/dist/web-standards-DOYp0UDT.d.cts +0 -77
@@ -1,307 +0,0 @@
1
- import {
2
- __require,
3
- getChainIdForNetwork
4
- } from "./chunk-XAQGMFSR.js";
5
-
6
- // src/shared/utils.ts
7
- function encodeJsonToBase64(value) {
8
- const json = JSON.stringify(value);
9
- if (typeof btoa === "function") {
10
- const bytes = new TextEncoder().encode(json);
11
- const binString = Array.from(
12
- bytes,
13
- (byte) => String.fromCodePoint(byte)
14
- ).join("");
15
- return btoa(binString);
16
- }
17
- if (typeof globalThis.Buffer !== "undefined") {
18
- return globalThis.Buffer.from(json, "utf8").toString("base64");
19
- }
20
- throw new Error("No base64 implementation found in this environment");
21
- }
22
- function randomBytes32Hex() {
23
- if (typeof crypto !== "undefined" && "getRandomValues" in crypto) {
24
- const arr = new Uint8Array(32);
25
- crypto.getRandomValues(arr);
26
- return "0x" + Array.from(arr).map((b) => b.toString(16).padStart(2, "0")).join("");
27
- }
28
- try {
29
- const nodeCrypto = __require("crypto");
30
- const buf = nodeCrypto.randomBytes(32);
31
- return "0x" + buf.toString("hex");
32
- } catch {
33
- throw new Error(
34
- "No cryptographically secure random number generator found. This environment does not support crypto.getRandomValues or Node.js crypto module."
35
- );
36
- }
37
- }
38
-
39
- // src/client/paymentClient.ts
40
- function joinUrl(base, path) {
41
- const normalizedBase = base.replace(/\/+$/, "");
42
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
43
- return `${normalizedBase}${normalizedPath}`;
44
- }
45
- async function getUserAddressFromProvider(provider) {
46
- const p = provider;
47
- if (!p || typeof p.request !== "function") {
48
- throw new Error("provider must implement EIP-1193 request()");
49
- }
50
- const accounts = await p.request({
51
- method: "eth_requestAccounts"
52
- });
53
- if (!accounts || accounts.length === 0) {
54
- throw new Error("No accounts returned from provider");
55
- }
56
- return accounts[0];
57
- }
58
- function buildTypedDataForAuthorization(authorization, paymentRequirements) {
59
- const chainId = getChainIdForNetwork(paymentRequirements.network);
60
- const verifyingContract = paymentRequirements.asset;
61
- const domain = {
62
- name: "USD Coin",
63
- version: "2",
64
- chainId,
65
- verifyingContract
66
- };
67
- const types = {
68
- TransferWithAuthorization: [
69
- { name: "from", type: "address" },
70
- { name: "to", type: "address" },
71
- { name: "value", type: "uint256" },
72
- { name: "validAfter", type: "uint256" },
73
- { name: "validBefore", type: "uint256" },
74
- { name: "nonce", type: "bytes32" }
75
- ]
76
- };
77
- return {
78
- domain,
79
- types,
80
- primaryType: "TransferWithAuthorization",
81
- message: authorization
82
- };
83
- }
84
- async function signAuthorizationWithProvider(provider, address, authorization, paymentRequirements) {
85
- const p = provider;
86
- if (!p || typeof p.request !== "function") {
87
- throw new Error("provider must implement EIP-1193 request()");
88
- }
89
- const typedData = buildTypedDataForAuthorization(
90
- authorization,
91
- paymentRequirements
92
- );
93
- const params = [address, JSON.stringify(typedData)];
94
- const signature = await p.request({
95
- method: "eth_signTypedData_v4",
96
- params
97
- });
98
- if (typeof signature !== "string" || !signature.startsWith("0x")) {
99
- throw new Error("Invalid signature returned from provider");
100
- }
101
- return signature;
102
- }
103
- function createPaymentClient(config) {
104
- const {
105
- resourceUrl,
106
- facilitatorUrl,
107
- provider,
108
- userAddress: userAddressOverride,
109
- projectKey
110
- } = config;
111
- if (!resourceUrl) {
112
- throw new Error("resourceUrl is required");
113
- }
114
- if (!facilitatorUrl) {
115
- throw new Error("facilitatorUrl is required");
116
- }
117
- if (!provider) {
118
- throw new Error("provider is required (e.g. window.ethereum)");
119
- }
120
- return {
121
- async callWithPayment(path, options) {
122
- const method = options?.method ?? "GET";
123
- const headers = {
124
- ...options?.headers ?? {}
125
- };
126
- let body;
127
- if (options?.body !== void 0) {
128
- headers["Content-Type"] = headers["Content-Type"] ?? "application/json";
129
- body = JSON.stringify(options.body);
130
- }
131
- const initialUrl = joinUrl(resourceUrl, path);
132
- const initialRes = await fetch(initialUrl, {
133
- method,
134
- headers,
135
- body
136
- });
137
- if (initialRes.status !== 402) {
138
- const json = await initialRes.json().catch((err) => {
139
- console.error("[x402] Failed to parse initial response JSON:", err);
140
- return null;
141
- });
142
- return {
143
- response: json,
144
- txHash: void 0
145
- };
146
- }
147
- const bodyJson = await initialRes.json();
148
- const paymentRequirements = bodyJson.paymentRequirements;
149
- if (!paymentRequirements) {
150
- throw new Error(
151
- "402 response did not include paymentRequirements field"
152
- );
153
- }
154
- const fromAddress = userAddressOverride ?? await getUserAddressFromProvider(provider);
155
- try {
156
- const p = provider;
157
- const accounts = await p.request({ method: "eth_accounts" });
158
- console.log("[SDK] Wallet accounts:", accounts);
159
- console.log("[SDK] Using fromAddress:", fromAddress);
160
- } catch (err) {
161
- }
162
- const nowSec = Math.floor(Date.now() / 1e3);
163
- const validAfter = "0";
164
- const validBefore = String(nowSec + 10 * 60);
165
- const nonce = randomBytes32Hex();
166
- const valueAtomic = options?.valueOverrideAtomic ?? paymentRequirements.maxAmountRequired;
167
- let authorization = {
168
- from: fromAddress,
169
- to: paymentRequirements.payTo,
170
- value: valueAtomic,
171
- validAfter,
172
- validBefore,
173
- nonce
174
- };
175
- const signature = await signAuthorizationWithProvider(
176
- provider,
177
- fromAddress,
178
- authorization,
179
- paymentRequirements
180
- );
181
- const { ethers } = await import("ethers");
182
- const typedData = buildTypedDataForAuthorization(
183
- authorization,
184
- paymentRequirements
185
- );
186
- const recovered = ethers.verifyTypedData(
187
- typedData.domain,
188
- typedData.types,
189
- typedData.message,
190
- signature
191
- );
192
- if (recovered.toLowerCase() !== authorization.from.toLowerCase()) {
193
- console.warn("[SDK WARNING] Signer address differs from expected, using recovered address", {
194
- expected: authorization.from,
195
- recovered,
196
- message: "This may indicate multiple accounts in wallet or wrong active account"
197
- });
198
- authorization = {
199
- ...authorization,
200
- from: recovered
201
- };
202
- }
203
- console.log("[SDK] Using authorization.from:", authorization.from);
204
- const paymentHeaderObject = {
205
- x402Version: 1,
206
- scheme: paymentRequirements.scheme,
207
- network: paymentRequirements.network,
208
- payload: {
209
- signature,
210
- authorization
211
- }
212
- };
213
- const paymentHeader = encodeJsonToBase64(paymentHeaderObject);
214
- const settleUrl = joinUrl(facilitatorUrl, "/settle");
215
- const settleRes = await fetch(settleUrl, {
216
- method: "POST",
217
- headers: {
218
- "Content-Type": "application/json",
219
- ...projectKey ? { "X-Project-Key": projectKey } : {}
220
- },
221
- body: JSON.stringify({
222
- x402Version: 1,
223
- paymentHeader,
224
- paymentRequirements
225
- })
226
- });
227
- if (!settleRes.ok) {
228
- const text = await settleRes.text().catch((err) => {
229
- console.error("[x402] Failed to read settle response text:", err);
230
- return "";
231
- });
232
- throw new Error(
233
- `Facilitator /settle failed with HTTP ${settleRes.status}: ${text}`
234
- );
235
- }
236
- const settleJson = await settleRes.json();
237
- if (!settleJson.success) {
238
- throw new Error(
239
- `Facilitator /settle returned error: ${settleJson.error ?? "unknown error"}`
240
- );
241
- }
242
- const txHash = settleJson.txHash ?? void 0;
243
- const retryHeaders = {
244
- ...headers,
245
- "X-PAYMENT": paymentHeader
246
- };
247
- const retryRes = await fetch(initialUrl, {
248
- method,
249
- headers: retryHeaders,
250
- body
251
- });
252
- if (!retryRes.ok) {
253
- const text = await retryRes.text().catch((err) => {
254
- console.error("[x402] Failed to read retry response text:", err);
255
- return "";
256
- });
257
- throw new Error(
258
- `Protected request with X-PAYMENT failed: HTTP ${retryRes.status} ${text}`
259
- );
260
- }
261
- const finalJson = await retryRes.json();
262
- return {
263
- response: finalJson,
264
- txHash,
265
- paymentHeader,
266
- paymentRequirements
267
- };
268
- }
269
- };
270
- }
271
-
272
- // src/client/createMantleClient.ts
273
- function createMantleClient(config) {
274
- const resourceUrl = config?.resourceUrl ?? (typeof window !== "undefined" ? window.location.origin : "");
275
- const facilitatorUrl = config?.facilitatorUrl ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) ?? "http://localhost:8080";
276
- return {
277
- async postWithPayment(url, body) {
278
- const account = await config?.getAccount?.();
279
- if (!account) {
280
- throw new Error(
281
- "Wallet not connected. Please connect your wallet first."
282
- );
283
- }
284
- const provider = config?.getProvider?.();
285
- if (!provider) {
286
- throw new Error("Wallet provider not available");
287
- }
288
- const client = createPaymentClient({
289
- resourceUrl,
290
- facilitatorUrl,
291
- provider,
292
- userAddress: account,
293
- projectKey: config?.projectKey
294
- });
295
- const result = await client.callWithPayment(url, {
296
- method: "POST",
297
- body
298
- });
299
- return result.response;
300
- }
301
- };
302
- }
303
-
304
- export {
305
- createPaymentClient,
306
- createMantleClient
307
- };
@@ -1,56 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/shared/constants.ts
9
- var MANTLE_MAINNET_NETWORK_ID = "mantle-mainnet";
10
- var MANTLE_MAINNET_CHAIN_ID = 5e3;
11
- var MANTLE_MAINNET_USDC = {
12
- symbol: "USDC",
13
- address: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
14
- decimals: 6
15
- };
16
- var MANTLE_DEFAULTS = {
17
- NETWORK: "mantle-mainnet",
18
- CHAIN_ID: 5e3,
19
- USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
20
- USDC_DECIMALS: 6,
21
- CURRENCY: "USD",
22
- SCHEME: "exact",
23
- FACILITATOR_URL: (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) || "http://localhost:8080"
24
- };
25
- function getDefaultAssetForNetwork(network) {
26
- switch (network) {
27
- case MANTLE_MAINNET_NETWORK_ID:
28
- default:
29
- return MANTLE_MAINNET_USDC;
30
- }
31
- }
32
- function getChainIdForNetwork(network) {
33
- switch (network) {
34
- case MANTLE_MAINNET_NETWORK_ID:
35
- default:
36
- return MANTLE_MAINNET_CHAIN_ID;
37
- }
38
- }
39
- function usdCentsToAtomic(cents, decimals) {
40
- if (cents < 0) {
41
- throw new Error("priceUsdCents must be non-negative");
42
- }
43
- if (decimals < 2) {
44
- throw new Error("token decimals must be >= 2 for USD cent conversion");
45
- }
46
- const base = BigInt(10) ** BigInt(decimals - 2);
47
- return BigInt(cents) * base;
48
- }
49
-
50
- export {
51
- __require,
52
- MANTLE_DEFAULTS,
53
- getDefaultAssetForNetwork,
54
- getChainIdForNetwork,
55
- usdCentsToAtomic
56
- };
@@ -1,77 +0,0 @@
1
- /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
- type NetworkId = "mantle-mainnet" | (string & {});
3
- /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
- interface AssetConfig {
5
- symbol: string;
6
- address: string;
7
- decimals: number;
8
- }
9
- /** x402-style payment requirements (returned in 402 response). */
10
- interface PaymentRequirements {
11
- scheme: "exact";
12
- network: NetworkId;
13
- asset: string;
14
- maxAmountRequired: string;
15
- payTo: `0x${string}`;
16
- price?: string;
17
- currency?: string;
18
- }
19
- /** EIP-3009 TransferWithAuthorization payload. */
20
- interface Authorization {
21
- from: string;
22
- to: string;
23
- value: string;
24
- validAfter: string;
25
- validBefore: string;
26
- nonce: string;
27
- }
28
- /** Inner payload of x402-style payment header. */
29
- interface PaymentHeaderPayload {
30
- signature: string;
31
- authorization: Authorization;
32
- }
33
- /** Structured x402-style payment header (before base64 encoding). */
34
- interface PaymentHeaderObject {
35
- x402Version: number;
36
- scheme: "exact";
37
- network: NetworkId;
38
- payload: PaymentHeaderPayload;
39
- }
40
- /** Base64-encoded payment header, sent in X-PAYMENT. */
41
- type PaymentHeaderBase64 = string;
42
- /**
43
- * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
- * Standard interface for Ethereum wallet providers.
45
- */
46
- interface EIP1193Provider {
47
- request(args: {
48
- method: string;
49
- params?: unknown[];
50
- }): Promise<unknown>;
51
- on?(event: string, listener: (...args: unknown[]) => void): void;
52
- removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
- }
54
- /**
55
- * Window ethereum extension for TypeScript
56
- */
57
- declare global {
58
- interface Window {
59
- ethereum?: EIP1193Provider;
60
- }
61
- }
62
-
63
- /**
64
- * Default values for Mantle mainnet x402 payments.
65
- * These are used by the simplified API (mantlePaywall, createMantleClient).
66
- */
67
- declare const MANTLE_DEFAULTS: {
68
- readonly NETWORK: "mantle-mainnet";
69
- readonly CHAIN_ID: 5000;
70
- readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
71
- readonly USDC_DECIMALS: 6;
72
- readonly CURRENCY: "USD";
73
- readonly SCHEME: "exact";
74
- readonly FACILITATOR_URL: string;
75
- };
76
-
77
- export { type AssetConfig as A, type EIP1193Provider as E, MANTLE_DEFAULTS as M, type NetworkId as N, type PaymentRequirements as P, type Authorization as a, type PaymentHeaderPayload as b, type PaymentHeaderObject as c, type PaymentHeaderBase64 as d };
@@ -1,77 +0,0 @@
1
- /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
- type NetworkId = "mantle-mainnet" | (string & {});
3
- /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
- interface AssetConfig {
5
- symbol: string;
6
- address: string;
7
- decimals: number;
8
- }
9
- /** x402-style payment requirements (returned in 402 response). */
10
- interface PaymentRequirements {
11
- scheme: "exact";
12
- network: NetworkId;
13
- asset: string;
14
- maxAmountRequired: string;
15
- payTo: `0x${string}`;
16
- price?: string;
17
- currency?: string;
18
- }
19
- /** EIP-3009 TransferWithAuthorization payload. */
20
- interface Authorization {
21
- from: string;
22
- to: string;
23
- value: string;
24
- validAfter: string;
25
- validBefore: string;
26
- nonce: string;
27
- }
28
- /** Inner payload of x402-style payment header. */
29
- interface PaymentHeaderPayload {
30
- signature: string;
31
- authorization: Authorization;
32
- }
33
- /** Structured x402-style payment header (before base64 encoding). */
34
- interface PaymentHeaderObject {
35
- x402Version: number;
36
- scheme: "exact";
37
- network: NetworkId;
38
- payload: PaymentHeaderPayload;
39
- }
40
- /** Base64-encoded payment header, sent in X-PAYMENT. */
41
- type PaymentHeaderBase64 = string;
42
- /**
43
- * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
- * Standard interface for Ethereum wallet providers.
45
- */
46
- interface EIP1193Provider {
47
- request(args: {
48
- method: string;
49
- params?: unknown[];
50
- }): Promise<unknown>;
51
- on?(event: string, listener: (...args: unknown[]) => void): void;
52
- removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
- }
54
- /**
55
- * Window ethereum extension for TypeScript
56
- */
57
- declare global {
58
- interface Window {
59
- ethereum?: EIP1193Provider;
60
- }
61
- }
62
-
63
- /**
64
- * Default values for Mantle mainnet x402 payments.
65
- * These are used by the simplified API (mantlePaywall, createMantleClient).
66
- */
67
- declare const MANTLE_DEFAULTS: {
68
- readonly NETWORK: "mantle-mainnet";
69
- readonly CHAIN_ID: 5000;
70
- readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
71
- readonly USDC_DECIMALS: 6;
72
- readonly CURRENCY: "USD";
73
- readonly SCHEME: "exact";
74
- readonly FACILITATOR_URL: string;
75
- };
76
-
77
- export { type AssetConfig as A, type EIP1193Provider as E, MANTLE_DEFAULTS as M, type NetworkId as N, type PaymentRequirements as P, type Authorization as a, type PaymentHeaderPayload as b, type PaymentHeaderObject as c, type PaymentHeaderBase64 as d };
@@ -1,17 +0,0 @@
1
- import './types-2zqbJvcz.js';
2
-
3
- /**
4
- * Default values for Mantle mainnet x402 payments.
5
- * These are used by the simplified API (mantlePaywall, createMantleClient).
6
- */
7
- declare const MANTLE_DEFAULTS: {
8
- readonly NETWORK: "mantle-mainnet";
9
- readonly CHAIN_ID: 5000;
10
- readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
11
- readonly USDC_DECIMALS: 6;
12
- readonly CURRENCY: "USD";
13
- readonly SCHEME: "exact";
14
- readonly FACILITATOR_URL: string;
15
- };
16
-
17
- export { MANTLE_DEFAULTS as M };
@@ -1,17 +0,0 @@
1
- import './types-2zqbJvcz.cjs';
2
-
3
- /**
4
- * Default values for Mantle mainnet x402 payments.
5
- * These are used by the simplified API (mantlePaywall, createMantleClient).
6
- */
7
- declare const MANTLE_DEFAULTS: {
8
- readonly NETWORK: "mantle-mainnet";
9
- readonly CHAIN_ID: 5000;
10
- readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
11
- readonly USDC_DECIMALS: 6;
12
- readonly CURRENCY: "USD";
13
- readonly SCHEME: "exact";
14
- readonly FACILITATOR_URL: string;
15
- };
16
-
17
- export { MANTLE_DEFAULTS as M };
@@ -1,51 +0,0 @@
1
- /**
2
- * Configuration for createMantleClient().
3
- * All fields are optional - the client auto-detects sensible defaults.
4
- */
5
- interface MantleClientConfig {
6
- /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
7
- facilitatorUrl?: string;
8
- /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
9
- resourceUrl?: string;
10
- /** Function to get user's wallet address (required for payments). */
11
- getAccount?: () => Promise<string | undefined> | string | undefined;
12
- /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
13
- getProvider?: () => any;
14
- /** Optional project key for hosted facilitator billing. */
15
- projectKey?: string;
16
- }
17
- /**
18
- * Simplified Mantle payment client interface.
19
- * Provides a clean API for making paid POST requests.
20
- */
21
- interface MantleClient {
22
- /**
23
- * Make a paid POST request to a protected endpoint.
24
- * Automatically handles x402 flow (402 response, signing, payment, retry).
25
- *
26
- * @param url - API endpoint path (e.g., "/api/generate-image").
27
- * @param body - Request body (will be JSON stringified).
28
- * @returns Response data from the protected endpoint.
29
- * @throws Error if wallet is not connected or payment fails.
30
- */
31
- postWithPayment<TResp = any>(url: string, body?: any): Promise<TResp>;
32
- }
33
- /**
34
- * Create a simplified Mantle payment client with auto-detected defaults.
35
- *
36
- * Usage:
37
- * ```typescript
38
- * const client = createMantleClient({
39
- * getAccount: () => account?.address,
40
- * getProvider: () => walletClient,
41
- * });
42
- *
43
- * const data = await client.postWithPayment("/api/generate", { prompt: "..." });
44
- * ```
45
- *
46
- * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
47
- * @returns MantleClient instance with simplified postWithPayment() method.
48
- */
49
- declare function createMantleClient(config?: MantleClientConfig): MantleClient;
50
-
51
- export { type MantleClient as M, type MantleClientConfig as a, createMantleClient as c };
@@ -1,51 +0,0 @@
1
- /**
2
- * Configuration for createMantleClient().
3
- * All fields are optional - the client auto-detects sensible defaults.
4
- */
5
- interface MantleClientConfig {
6
- /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
7
- facilitatorUrl?: string;
8
- /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
9
- resourceUrl?: string;
10
- /** Function to get user's wallet address (required for payments). */
11
- getAccount?: () => Promise<string | undefined> | string | undefined;
12
- /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
13
- getProvider?: () => any;
14
- /** Optional project key for hosted facilitator billing. */
15
- projectKey?: string;
16
- }
17
- /**
18
- * Simplified Mantle payment client interface.
19
- * Provides a clean API for making paid POST requests.
20
- */
21
- interface MantleClient {
22
- /**
23
- * Make a paid POST request to a protected endpoint.
24
- * Automatically handles x402 flow (402 response, signing, payment, retry).
25
- *
26
- * @param url - API endpoint path (e.g., "/api/generate-image").
27
- * @param body - Request body (will be JSON stringified).
28
- * @returns Response data from the protected endpoint.
29
- * @throws Error if wallet is not connected or payment fails.
30
- */
31
- postWithPayment<TResp = any>(url: string, body?: any): Promise<TResp>;
32
- }
33
- /**
34
- * Create a simplified Mantle payment client with auto-detected defaults.
35
- *
36
- * Usage:
37
- * ```typescript
38
- * const client = createMantleClient({
39
- * getAccount: () => account?.address,
40
- * getProvider: () => walletClient,
41
- * });
42
- *
43
- * const data = await client.postWithPayment("/api/generate", { prompt: "..." });
44
- * ```
45
- *
46
- * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
47
- * @returns MantleClient instance with simplified postWithPayment() method.
48
- */
49
- declare function createMantleClient(config?: MantleClientConfig): MantleClient;
50
-
51
- export { type MantleClient as M, type MantleClientConfig as a, createMantleClient as c };