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

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 (95) hide show
  1. package/dist/chunk-23QNUJIB.js +136 -0
  2. package/dist/chunk-6GLR5EBK.js +96 -0
  3. package/dist/chunk-BRGW36P7.js +211 -0
  4. package/dist/chunk-CTI5CRDY.js +274 -0
  5. package/dist/chunk-DA6ZBXNO.js +275 -0
  6. package/dist/chunk-E46A7I6B.js +274 -0
  7. package/dist/chunk-FD4HG7KR.js +135 -0
  8. package/dist/chunk-FHU6CFHF.js +0 -0
  9. package/dist/chunk-GHUWTX7J.js +66 -0
  10. package/dist/chunk-GWVWPS3R.js +277 -0
  11. package/dist/chunk-HEZZ74SI.js +62 -0
  12. package/dist/chunk-HTZ3QFY4.js +135 -0
  13. package/dist/chunk-MQALBRGV.js +135 -0
  14. package/dist/chunk-NQWSCY44.js +70 -0
  15. package/dist/chunk-PCJEJYP6.js +68 -0
  16. package/dist/chunk-PPVS3X5Z.js +99 -0
  17. package/dist/chunk-PYIYE3HI.js +135 -0
  18. package/dist/chunk-Q6SPMEIW.js +235 -0
  19. package/dist/chunk-RNKXSBT7.js +135 -0
  20. package/dist/chunk-SPCXFN7C.js +284 -0
  21. package/dist/chunk-T5DRYLNB.js +135 -0
  22. package/dist/chunk-TSEE5NSJ.js +297 -0
  23. package/dist/chunk-U73CZU3X.js +237 -0
  24. package/dist/chunk-WAKJRVUP.js +135 -0
  25. package/dist/chunk-WELDWRDX.js +307 -0
  26. package/dist/chunk-WFUDGBKK.js +68 -0
  27. package/dist/chunk-WO2MYZXT.js +0 -0
  28. package/dist/chunk-XAQGMFSR.js +56 -0
  29. package/dist/client.cjs +328 -0
  30. package/dist/client.d.cts +17 -0
  31. package/dist/client.d.ts +17 -0
  32. package/dist/client.js +12 -0
  33. package/dist/constants-0ncqvV_O.d.ts +17 -0
  34. package/dist/constants-C7aY8u5b.d.cts +77 -0
  35. package/dist/constants-C7aY8u5b.d.ts +77 -0
  36. package/dist/constants-CVFF0ray.d.ts +17 -0
  37. package/dist/constants-CsIL25uQ.d.cts +17 -0
  38. package/dist/constants-DzCGK0Q3.d.cts +17 -0
  39. package/dist/createMantleClient-CO0uWPb-.d.cts +87 -0
  40. package/dist/createMantleClient-CuiPsTa6.d.ts +87 -0
  41. package/dist/createMantleClient-DS1Ghqrz.d.cts +51 -0
  42. package/dist/createMantleClient-DS1Ghqrz.d.ts +51 -0
  43. package/dist/createMantleClient-DVFkbBfS.d.ts +87 -0
  44. package/dist/createMantleClient-NN0Nitp9.d.cts +87 -0
  45. package/dist/express-Ck7eryef.d.cts +66 -0
  46. package/dist/express-CmEg5hR3.d.ts +66 -0
  47. package/dist/express-D8EwEcOL.d.ts +66 -0
  48. package/dist/express-eQOPxfnI.d.cts +66 -0
  49. package/dist/index.cjs +342 -155
  50. package/dist/index.d.cts +10 -290
  51. package/dist/index.d.ts +10 -290
  52. package/dist/index.js +18 -567
  53. package/dist/nextjs-Bp8DxYDN.d.ts +45 -0
  54. package/dist/nextjs-CliiaTPe.d.cts +45 -0
  55. package/dist/nextjs-D7t-BC4N.d.ts +45 -0
  56. package/dist/nextjs-Duecps0q.d.cts +45 -0
  57. package/dist/nextjs-TFhFiQuL.d.ts +45 -0
  58. package/dist/nextjs-ZO2J9mdo.d.cts +45 -0
  59. package/dist/react.cjs +454 -0
  60. package/dist/react.d.cts +93 -0
  61. package/dist/react.d.ts +93 -0
  62. package/dist/react.js +10 -0
  63. package/dist/server-express.cjs +368 -0
  64. package/dist/server-express.d.cts +5 -0
  65. package/dist/server-express.d.ts +5 -0
  66. package/dist/server-express.js +13 -0
  67. package/dist/server-nextjs.cjs +339 -0
  68. package/dist/server-nextjs.d.cts +5 -0
  69. package/dist/server-nextjs.d.ts +5 -0
  70. package/dist/server-nextjs.js +11 -0
  71. package/dist/server-web.cjs +339 -0
  72. package/dist/server-web.d.cts +4 -0
  73. package/dist/server-web.d.ts +4 -0
  74. package/dist/server-web.js +11 -0
  75. package/dist/server.cjs +497 -0
  76. package/dist/server.d.cts +79 -0
  77. package/dist/server.d.ts +79 -0
  78. package/dist/server.js +36 -0
  79. package/dist/types-2zqbJvcz.d.cts +63 -0
  80. package/dist/types-2zqbJvcz.d.ts +63 -0
  81. package/dist/types-BFUqKBBO.d.cts +63 -0
  82. package/dist/types-BFUqKBBO.d.ts +63 -0
  83. package/dist/types-C7EPJ6Hd.d.ts +85 -0
  84. package/dist/types-CEttmr1U.d.cts +97 -0
  85. package/dist/types-CoOdbZSp.d.cts +97 -0
  86. package/dist/types-CqQ6OgRi.d.ts +85 -0
  87. package/dist/types-CrOsOHcX.d.cts +85 -0
  88. package/dist/types-D20K36pc.d.ts +97 -0
  89. package/dist/types-DTzov_EE.d.ts +97 -0
  90. package/dist/types-xkNm0uzE.d.cts +85 -0
  91. package/dist/web-standards-BNQyWzBC.d.cts +77 -0
  92. package/dist/web-standards-C3D2vdTg.d.ts +77 -0
  93. package/dist/web-standards-D8j1kZxd.d.ts +77 -0
  94. package/dist/web-standards-DOYp0UDT.d.cts +77 -0
  95. package/package.json +80 -8
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/client.ts
31
+ var client_exports = {};
32
+ __export(client_exports, {
33
+ MANTLE_DEFAULTS: () => MANTLE_DEFAULTS,
34
+ createMantleClient: () => createMantleClient,
35
+ createPaymentClient: () => createPaymentClient
36
+ });
37
+ module.exports = __toCommonJS(client_exports);
38
+
39
+ // src/shared/constants.ts
40
+ var MANTLE_MAINNET_NETWORK_ID = "mantle-mainnet";
41
+ var MANTLE_MAINNET_CHAIN_ID = 5e3;
42
+ var MANTLE_DEFAULTS = {
43
+ NETWORK: "mantle-mainnet",
44
+ CHAIN_ID: 5e3,
45
+ USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
46
+ USDC_DECIMALS: 6,
47
+ CURRENCY: "USD",
48
+ SCHEME: "exact",
49
+ FACILITATOR_URL: (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) || "http://localhost:8080"
50
+ };
51
+ function getChainIdForNetwork(network) {
52
+ switch (network) {
53
+ case MANTLE_MAINNET_NETWORK_ID:
54
+ default:
55
+ return MANTLE_MAINNET_CHAIN_ID;
56
+ }
57
+ }
58
+
59
+ // src/shared/utils.ts
60
+ function encodeJsonToBase64(value) {
61
+ const json = JSON.stringify(value);
62
+ if (typeof btoa === "function") {
63
+ const bytes = new TextEncoder().encode(json);
64
+ const binString = Array.from(
65
+ bytes,
66
+ (byte) => String.fromCodePoint(byte)
67
+ ).join("");
68
+ return btoa(binString);
69
+ }
70
+ if (typeof globalThis.Buffer !== "undefined") {
71
+ return globalThis.Buffer.from(json, "utf8").toString("base64");
72
+ }
73
+ throw new Error("No base64 implementation found in this environment");
74
+ }
75
+ function randomBytes32Hex() {
76
+ if (typeof crypto !== "undefined" && "getRandomValues" in crypto) {
77
+ const arr = new Uint8Array(32);
78
+ crypto.getRandomValues(arr);
79
+ return "0x" + Array.from(arr).map((b) => b.toString(16).padStart(2, "0")).join("");
80
+ }
81
+ try {
82
+ const nodeCrypto = require("crypto");
83
+ const buf = nodeCrypto.randomBytes(32);
84
+ return "0x" + buf.toString("hex");
85
+ } catch {
86
+ throw new Error(
87
+ "No cryptographically secure random number generator found. This environment does not support crypto.getRandomValues or Node.js crypto module."
88
+ );
89
+ }
90
+ }
91
+
92
+ // src/client/paymentClient.ts
93
+ function joinUrl(base, path) {
94
+ const normalizedBase = base.replace(/\/+$/, "");
95
+ const normalizedPath = path.startsWith("/") ? path : `/${path}`;
96
+ return `${normalizedBase}${normalizedPath}`;
97
+ }
98
+ function buildTypedDataForAuthorization(authorization, paymentRequirements) {
99
+ const chainId = getChainIdForNetwork(paymentRequirements.network);
100
+ const verifyingContract = paymentRequirements.asset;
101
+ const domain = {
102
+ name: "USD Coin",
103
+ version: "2",
104
+ chainId,
105
+ verifyingContract
106
+ };
107
+ const types = {
108
+ TransferWithAuthorization: [
109
+ { name: "from", type: "address" },
110
+ { name: "to", type: "address" },
111
+ { name: "value", type: "uint256" },
112
+ { name: "validAfter", type: "uint256" },
113
+ { name: "validBefore", type: "uint256" },
114
+ { name: "nonce", type: "bytes32" }
115
+ ]
116
+ };
117
+ return {
118
+ domain,
119
+ types,
120
+ primaryType: "TransferWithAuthorization",
121
+ message: authorization
122
+ };
123
+ }
124
+ async function signAuthorizationWithProvider(provider, authorization, paymentRequirements) {
125
+ const { BrowserProvider } = await import("ethers");
126
+ const chainId = getChainIdForNetwork(paymentRequirements.network);
127
+ const browserProvider = new BrowserProvider(provider, chainId);
128
+ const signer = await browserProvider.getSigner();
129
+ const from = await signer.getAddress();
130
+ const authWithFrom = {
131
+ ...authorization,
132
+ from
133
+ };
134
+ const typedData = buildTypedDataForAuthorization(
135
+ authWithFrom,
136
+ paymentRequirements
137
+ );
138
+ const signature = await signer.signTypedData(
139
+ typedData.domain,
140
+ typedData.types,
141
+ typedData.message
142
+ );
143
+ return { signature, from };
144
+ }
145
+ function createPaymentClient(config) {
146
+ const {
147
+ resourceUrl,
148
+ facilitatorUrl,
149
+ provider,
150
+ userAddress: userAddressOverride,
151
+ projectKey
152
+ } = config;
153
+ if (!resourceUrl) {
154
+ throw new Error("resourceUrl is required");
155
+ }
156
+ if (!facilitatorUrl) {
157
+ throw new Error("facilitatorUrl is required");
158
+ }
159
+ if (!provider) {
160
+ throw new Error("provider is required (e.g. window.ethereum)");
161
+ }
162
+ return {
163
+ async callWithPayment(path, options) {
164
+ const method = options?.method ?? "GET";
165
+ const headers = {
166
+ ...options?.headers ?? {}
167
+ };
168
+ let body;
169
+ if (options?.body !== void 0) {
170
+ headers["Content-Type"] = headers["Content-Type"] ?? "application/json";
171
+ body = JSON.stringify(options.body);
172
+ }
173
+ const initialUrl = joinUrl(resourceUrl, path);
174
+ const initialRes = await fetch(initialUrl, {
175
+ method,
176
+ headers,
177
+ body
178
+ });
179
+ if (initialRes.status !== 402) {
180
+ const json = await initialRes.json().catch((err) => {
181
+ console.error("[x402] Failed to parse initial response JSON:", err);
182
+ return null;
183
+ });
184
+ return {
185
+ response: json,
186
+ txHash: void 0
187
+ };
188
+ }
189
+ const bodyJson = await initialRes.json();
190
+ const paymentRequirements = bodyJson.paymentRequirements;
191
+ if (!paymentRequirements) {
192
+ throw new Error(
193
+ "402 response did not include paymentRequirements field"
194
+ );
195
+ }
196
+ const nowSec = Math.floor(Date.now() / 1e3);
197
+ const validAfter = "0";
198
+ const validBefore = String(nowSec + 10 * 60);
199
+ const nonce = randomBytes32Hex();
200
+ const valueAtomic = options?.valueOverrideAtomic ?? paymentRequirements.maxAmountRequired;
201
+ let authorization = {
202
+ from: "0x0000000000000000000000000000000000000000",
203
+ to: paymentRequirements.payTo,
204
+ value: valueAtomic,
205
+ validAfter,
206
+ validBefore,
207
+ nonce
208
+ };
209
+ const { signature, from } = await signAuthorizationWithProvider(
210
+ provider,
211
+ authorization,
212
+ paymentRequirements
213
+ );
214
+ authorization = {
215
+ ...authorization,
216
+ from
217
+ };
218
+ if (userAddressOverride && userAddressOverride.toLowerCase() !== from.toLowerCase()) {
219
+ console.warn(
220
+ "[SDK WARNING] userAddress override differs from signer address",
221
+ { override: userAddressOverride, signer: from }
222
+ );
223
+ }
224
+ const paymentHeaderObject = {
225
+ x402Version: 1,
226
+ scheme: paymentRequirements.scheme,
227
+ network: paymentRequirements.network,
228
+ payload: {
229
+ signature,
230
+ authorization
231
+ }
232
+ };
233
+ const paymentHeader = encodeJsonToBase64(paymentHeaderObject);
234
+ const settleUrl = joinUrl(facilitatorUrl, "/settle");
235
+ const settleRes = await fetch(settleUrl, {
236
+ method: "POST",
237
+ headers: {
238
+ "Content-Type": "application/json",
239
+ ...projectKey ? { "X-Project-Key": projectKey } : {}
240
+ },
241
+ body: JSON.stringify({
242
+ x402Version: 1,
243
+ paymentHeader,
244
+ paymentRequirements
245
+ })
246
+ });
247
+ if (!settleRes.ok) {
248
+ const text = await settleRes.text().catch((err) => {
249
+ console.error("[x402] Failed to read settle response text:", err);
250
+ return "";
251
+ });
252
+ throw new Error(
253
+ `Facilitator /settle failed with HTTP ${settleRes.status}: ${text}`
254
+ );
255
+ }
256
+ const settleJson = await settleRes.json();
257
+ if (!settleJson.success) {
258
+ throw new Error(
259
+ `Facilitator /settle returned error: ${settleJson.error ?? "unknown error"}`
260
+ );
261
+ }
262
+ const txHash = settleJson.txHash ?? void 0;
263
+ const retryHeaders = {
264
+ ...headers,
265
+ "X-PAYMENT": paymentHeader
266
+ };
267
+ const retryRes = await fetch(initialUrl, {
268
+ method,
269
+ headers: retryHeaders,
270
+ body
271
+ });
272
+ if (!retryRes.ok) {
273
+ const text = await retryRes.text().catch((err) => {
274
+ console.error("[x402] Failed to read retry response text:", err);
275
+ return "";
276
+ });
277
+ throw new Error(
278
+ `Protected request with X-PAYMENT failed: HTTP ${retryRes.status} ${text}`
279
+ );
280
+ }
281
+ const finalJson = await retryRes.json();
282
+ return {
283
+ response: finalJson,
284
+ txHash,
285
+ paymentHeader,
286
+ paymentRequirements
287
+ };
288
+ }
289
+ };
290
+ }
291
+
292
+ // src/client/createMantleClient.ts
293
+ function createMantleClient(config) {
294
+ const resourceUrl = config?.resourceUrl ?? (typeof window !== "undefined" ? window.location.origin : "");
295
+ const facilitatorUrl = config?.facilitatorUrl ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) ?? "http://localhost:8080";
296
+ return {
297
+ async postWithPayment(url, body) {
298
+ const account = await config?.getAccount?.();
299
+ if (!account) {
300
+ throw new Error(
301
+ "Wallet not connected. Please connect your wallet first."
302
+ );
303
+ }
304
+ const provider = config?.getProvider?.();
305
+ if (!provider) {
306
+ throw new Error("Wallet provider not available");
307
+ }
308
+ const client = createPaymentClient({
309
+ resourceUrl,
310
+ facilitatorUrl,
311
+ provider,
312
+ userAddress: account,
313
+ projectKey: config?.projectKey
314
+ });
315
+ const result = await client.callWithPayment(url, {
316
+ method: "POST",
317
+ body
318
+ });
319
+ return result;
320
+ }
321
+ };
322
+ }
323
+ // Annotate the CommonJS export names for ESM import in node:
324
+ 0 && (module.exports = {
325
+ MANTLE_DEFAULTS,
326
+ createMantleClient,
327
+ createPaymentClient
328
+ });
@@ -0,0 +1,17 @@
1
+ import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-CO0uWPb-.cjs';
2
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-CO0uWPb-.cjs';
3
+ export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
4
+ export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
5
+
6
+ /**
7
+ * Creates a high-level payment client that:
8
+ * - makes an initial request
9
+ * - if it receives 402 + paymentRequirements, builds & signs an authorization
10
+ * - calls facilitator /settle
11
+ * - retries the original request with X-PAYMENT header
12
+ *
13
+ * This logic is x402 and tailored for Mantle + USDC.
14
+ */
15
+ declare function createPaymentClient(config: PaymentClientConfig): PaymentClient;
16
+
17
+ export { PaymentClient, PaymentClientConfig, createPaymentClient };
@@ -0,0 +1,17 @@
1
+ import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-CuiPsTa6.js';
2
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-CuiPsTa6.js';
3
+ export { A as AssetConfig, a as Authorization, E as EIP1193Provider, N as NetworkId, d as PaymentHeaderBase64, c as PaymentHeaderObject, b as PaymentHeaderPayload, P as PaymentRequirements } from './types-BFUqKBBO.js';
4
+ export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
5
+
6
+ /**
7
+ * Creates a high-level payment client that:
8
+ * - makes an initial request
9
+ * - if it receives 402 + paymentRequirements, builds & signs an authorization
10
+ * - calls facilitator /settle
11
+ * - retries the original request with X-PAYMENT header
12
+ *
13
+ * This logic is x402 and tailored for Mantle + USDC.
14
+ */
15
+ declare function createPaymentClient(config: PaymentClientConfig): PaymentClient;
16
+
17
+ export { PaymentClient, PaymentClientConfig, createPaymentClient };
package/dist/client.js ADDED
@@ -0,0 +1,12 @@
1
+ import {
2
+ createMantleClient,
3
+ createPaymentClient
4
+ } from "./chunk-E46A7I6B.js";
5
+ import {
6
+ MANTLE_DEFAULTS
7
+ } from "./chunk-HEZZ74SI.js";
8
+ export {
9
+ MANTLE_DEFAULTS,
10
+ createMantleClient,
11
+ createPaymentClient
12
+ };
@@ -0,0 +1,17 @@
1
+ import './types-BFUqKBBO.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 };
@@ -0,0 +1,77 @@
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 };
@@ -0,0 +1,77 @@
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 };
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,17 @@
1
+ import './types-BFUqKBBO.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 };
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,87 @@
1
+ import { d as PaymentHeaderBase64, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
2
+
3
+ /** Config for the client-side payment helper. */
4
+ interface PaymentClientConfig {
5
+ /** Base URL of your protected resource server. */
6
+ resourceUrl: string;
7
+ /** Facilitator URL (hosted or self-hosted). */
8
+ facilitatorUrl: string;
9
+ /** EIP-1193 provider (window.ethereum) or similar. */
10
+ provider: unknown;
11
+ /** Optional user address override; otherwise derived from provider. */
12
+ userAddress?: string;
13
+ /** Optional: Project key for hosted facilitator billing. */
14
+ projectKey?: string;
15
+ }
16
+ /** Result of a callWithPayment() client operation. */
17
+ interface CallWithPaymentResult<TResponseBody = unknown> {
18
+ response: TResponseBody;
19
+ txHash?: string;
20
+ paymentHeader?: PaymentHeaderBase64;
21
+ paymentRequirements?: PaymentRequirements;
22
+ }
23
+ /** Shape of the client instance returned by createPaymentClient. */
24
+ interface PaymentClient {
25
+ callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
26
+ method?: "GET" | "POST" | "PUT" | "DELETE";
27
+ body?: TBody;
28
+ headers?: Record<string, string>;
29
+ /**
30
+ * Optional override if you want to send less than maxAmountRequired.
31
+ * In most cases you won't need this and will just pay maxAmountRequired.
32
+ */
33
+ valueOverrideAtomic?: string;
34
+ }): Promise<CallWithPaymentResult<TResp>>;
35
+ }
36
+
37
+ /**
38
+ * Configuration for createMantleClient().
39
+ * All fields are optional - the client auto-detects sensible defaults.
40
+ */
41
+ interface MantleClientConfig {
42
+ /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
43
+ facilitatorUrl?: string;
44
+ /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
45
+ resourceUrl?: string;
46
+ /** Function to get user's wallet address (required for payments). */
47
+ getAccount?: () => Promise<string | undefined> | string | undefined;
48
+ /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
49
+ getProvider?: () => any;
50
+ /** Optional project key for hosted facilitator billing. */
51
+ projectKey?: string;
52
+ }
53
+ /**
54
+ * Simplified Mantle payment client interface.
55
+ * Provides a clean API for making paid POST requests.
56
+ */
57
+ interface MantleClient {
58
+ /**
59
+ * Make a paid POST request to a protected endpoint.
60
+ * Automatically handles x402 flow (402 response, signing, payment, retry).
61
+ *
62
+ * @param url - API endpoint path (e.g., "/api/generate-image").
63
+ * @param body - Request body (will be JSON stringified).
64
+ * @returns Full payment result including response body and tx hash.
65
+ * @throws Error if wallet is not connected or payment fails.
66
+ */
67
+ postWithPayment<TResp = any>(url: string, body?: any): Promise<CallWithPaymentResult<TResp>>;
68
+ }
69
+ /**
70
+ * Create a simplified Mantle payment client with auto-detected defaults.
71
+ *
72
+ * Usage:
73
+ * ```typescript
74
+ * const client = createMantleClient({
75
+ * getAccount: () => account?.address,
76
+ * getProvider: () => walletClient,
77
+ * });
78
+ *
79
+ * const data = await client.postWithPayment("/api/generate", { prompt: "..." });
80
+ * ```
81
+ *
82
+ * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
83
+ * @returns MantleClient instance with simplified postWithPayment() method.
84
+ */
85
+ declare function createMantleClient(config?: MantleClientConfig): MantleClient;
86
+
87
+ export { type CallWithPaymentResult as C, type MantleClient as M, type PaymentClientConfig as P, type MantleClientConfig as a, type PaymentClient as b, createMantleClient as c };