@puga-labs/x402-mantle-sdk 0.2.1 → 0.3.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.
Files changed (41) hide show
  1. package/dist/chunk-CTI5CRDY.js +274 -0
  2. package/dist/chunk-DA6ZBXNO.js +275 -0
  3. package/dist/chunk-FD4HG7KR.js +135 -0
  4. package/dist/chunk-GWVWPS3R.js +277 -0
  5. package/dist/chunk-HTZ3QFY4.js +135 -0
  6. package/dist/chunk-MQALBRGV.js +135 -0
  7. package/dist/chunk-PYIYE3HI.js +135 -0
  8. package/dist/chunk-Q6SPMEIW.js +235 -0
  9. package/dist/chunk-RNKXSBT7.js +135 -0
  10. package/dist/chunk-SPCXFN7C.js +284 -0
  11. package/dist/chunk-T5DRYLNB.js +135 -0
  12. package/dist/chunk-TSEE5NSJ.js +297 -0
  13. package/dist/chunk-WELDWRDX.js +307 -0
  14. package/dist/chunk-XAQGMFSR.js +56 -0
  15. package/dist/client.cjs +328 -0
  16. package/dist/client.d.cts +17 -0
  17. package/dist/client.d.ts +17 -0
  18. package/dist/client.js +12 -0
  19. package/dist/constants-C7aY8u5b.d.cts +77 -0
  20. package/dist/constants-C7aY8u5b.d.ts +77 -0
  21. package/dist/constants-CVFF0ray.d.ts +17 -0
  22. package/dist/constants-DzCGK0Q3.d.cts +17 -0
  23. package/dist/createMantleClient-DS1Ghqrz.d.cts +51 -0
  24. package/dist/createMantleClient-DS1Ghqrz.d.ts +51 -0
  25. package/dist/createMantleClient-DVFkbBfS.d.ts +87 -0
  26. package/dist/createMantleClient-NN0Nitp9.d.cts +87 -0
  27. package/dist/index.cjs +158 -48
  28. package/dist/index.d.cts +8 -290
  29. package/dist/index.d.ts +8 -290
  30. package/dist/index.js +16 -567
  31. package/dist/react.cjs +453 -0
  32. package/dist/react.d.cts +90 -0
  33. package/dist/react.d.ts +90 -0
  34. package/dist/react.js +10 -0
  35. package/dist/server.cjs +292 -0
  36. package/dist/server.d.cts +116 -0
  37. package/dist/server.d.ts +116 -0
  38. package/dist/server.js +12 -0
  39. package/dist/types-2zqbJvcz.d.cts +63 -0
  40. package/dist/types-2zqbJvcz.d.ts +63 -0
  41. package/package.json +37 -12
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -25,6 +35,7 @@ __export(index_exports, {
25
35
  createPaymentClient: () => createPaymentClient,
26
36
  createPaymentMiddleware: () => createPaymentMiddleware,
27
37
  mantlePaywall: () => mantlePaywall,
38
+ useEthersWallet: () => useEthersWallet,
28
39
  useMantleX402: () => useMantleX402
29
40
  });
30
41
  module.exports = __toCommonJS(index_exports);
@@ -276,7 +287,7 @@ function createPaymentMiddleware(config) {
276
287
  function mantlePaywall(opts) {
277
288
  const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
278
289
  const priceUsdCents = Math.round(priceUsd * 100);
279
- return (req, res, next) => {
290
+ return async (req, res, next) => {
280
291
  const method = (req.method || "GET").toUpperCase();
281
292
  const path = req.path || "/";
282
293
  const routeKey = `${method} ${path}`;
@@ -335,19 +346,6 @@ function joinUrl(base, path) {
335
346
  const normalizedPath = path.startsWith("/") ? path : `/${path}`;
336
347
  return `${normalizedBase}${normalizedPath}`;
337
348
  }
338
- async function getUserAddressFromProvider(provider) {
339
- const p = provider;
340
- if (!p || typeof p.request !== "function") {
341
- throw new Error("provider must implement EIP-1193 request()");
342
- }
343
- const accounts = await p.request({
344
- method: "eth_requestAccounts"
345
- });
346
- if (!accounts || accounts.length === 0) {
347
- throw new Error("No accounts returned from provider");
348
- }
349
- return accounts[0];
350
- }
351
349
  function buildTypedDataForAuthorization(authorization, paymentRequirements) {
352
350
  const chainId = getChainIdForNetwork(paymentRequirements.network);
353
351
  const verifyingContract = paymentRequirements.asset;
@@ -374,24 +372,26 @@ function buildTypedDataForAuthorization(authorization, paymentRequirements) {
374
372
  message: authorization
375
373
  };
376
374
  }
377
- async function signAuthorizationWithProvider(provider, address, authorization, paymentRequirements) {
378
- const p = provider;
379
- if (!p || typeof p.request !== "function") {
380
- throw new Error("provider must implement EIP-1193 request()");
381
- }
375
+ async function signAuthorizationWithProvider(provider, authorization, paymentRequirements) {
376
+ const { BrowserProvider } = await import("ethers");
377
+ const chainId = getChainIdForNetwork(paymentRequirements.network);
378
+ const browserProvider = new BrowserProvider(provider, chainId);
379
+ const signer = await browserProvider.getSigner();
380
+ const from = await signer.getAddress();
381
+ const authWithFrom = {
382
+ ...authorization,
383
+ from
384
+ };
382
385
  const typedData = buildTypedDataForAuthorization(
383
- authorization,
386
+ authWithFrom,
384
387
  paymentRequirements
385
388
  );
386
- const params = [address, JSON.stringify(typedData)];
387
- const signature = await p.request({
388
- method: "eth_signTypedData_v4",
389
- params
390
- });
391
- if (typeof signature !== "string" || !signature.startsWith("0x")) {
392
- throw new Error("Invalid signature returned from provider");
393
- }
394
- return signature;
389
+ const signature = await signer.signTypedData(
390
+ typedData.domain,
391
+ typedData.types,
392
+ typedData.message
393
+ );
394
+ return { signature, from };
395
395
  }
396
396
  function createPaymentClient(config) {
397
397
  const {
@@ -434,14 +434,6 @@ function createPaymentClient(config) {
434
434
  });
435
435
  return {
436
436
  response: json,
437
- paymentHeader: "",
438
- paymentRequirements: {
439
- scheme: "exact",
440
- network: "mantle-mainnet",
441
- asset: "",
442
- maxAmountRequired: "0",
443
- payTo: ""
444
- },
445
437
  txHash: void 0
446
438
  };
447
439
  }
@@ -452,26 +444,34 @@ function createPaymentClient(config) {
452
444
  "402 response did not include paymentRequirements field"
453
445
  );
454
446
  }
455
- const fromAddress = userAddressOverride ?? await getUserAddressFromProvider(provider);
456
447
  const nowSec = Math.floor(Date.now() / 1e3);
457
448
  const validAfter = "0";
458
449
  const validBefore = String(nowSec + 10 * 60);
459
450
  const nonce = randomBytes32Hex();
460
451
  const valueAtomic = options?.valueOverrideAtomic ?? paymentRequirements.maxAmountRequired;
461
- const authorization = {
462
- from: fromAddress,
452
+ let authorization = {
453
+ from: "0x0000000000000000000000000000000000000000",
463
454
  to: paymentRequirements.payTo,
464
455
  value: valueAtomic,
465
456
  validAfter,
466
457
  validBefore,
467
458
  nonce
468
459
  };
469
- const signature = await signAuthorizationWithProvider(
460
+ const { signature, from } = await signAuthorizationWithProvider(
470
461
  provider,
471
- fromAddress,
472
462
  authorization,
473
463
  paymentRequirements
474
464
  );
465
+ authorization = {
466
+ ...authorization,
467
+ from
468
+ };
469
+ if (userAddressOverride && userAddressOverride.toLowerCase() !== from.toLowerCase()) {
470
+ console.warn(
471
+ "[SDK WARNING] userAddress override differs from signer address",
472
+ { override: userAddressOverride, signer: from }
473
+ );
474
+ }
475
475
  const paymentHeaderObject = {
476
476
  x402Version: 1,
477
477
  scheme: paymentRequirements.scheme,
@@ -545,7 +545,7 @@ function createMantleClient(config) {
545
545
  const resourceUrl = config?.resourceUrl ?? (typeof window !== "undefined" ? window.location.origin : "");
546
546
  const facilitatorUrl = config?.facilitatorUrl ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) ?? "http://localhost:8080";
547
547
  return {
548
- async post(url, body) {
548
+ async postWithPayment(url, body) {
549
549
  const account = await config?.getAccount?.();
550
550
  if (!account) {
551
551
  throw new Error(
@@ -567,16 +567,120 @@ function createMantleClient(config) {
567
567
  method: "POST",
568
568
  body
569
569
  });
570
- return result.response;
570
+ return result;
571
571
  }
572
572
  };
573
573
  }
574
574
 
575
+ // src/client/react/useEthersWallet.ts
576
+ var import_react = require("react");
577
+ var import_ethers = require("ethers");
578
+ function useEthersWallet(options) {
579
+ const [address, setAddress] = (0, import_react.useState)(void 0);
580
+ const [isConnected, setIsConnected] = (0, import_react.useState)(false);
581
+ const [provider, setProvider] = (0, import_react.useState)(
582
+ void 0
583
+ );
584
+ const [chainId, setChainId] = (0, import_react.useState)(void 0);
585
+ const [error, setError] = (0, import_react.useState)(void 0);
586
+ const connect = (0, import_react.useCallback)(async () => {
587
+ try {
588
+ setError(void 0);
589
+ if (typeof window === "undefined" || !window.ethereum) {
590
+ throw new Error(
591
+ "No Ethereum wallet detected. Please install MetaMask or another wallet."
592
+ );
593
+ }
594
+ const browserProvider = new import_ethers.ethers.BrowserProvider(
595
+ window.ethereum
596
+ );
597
+ setProvider(browserProvider);
598
+ const accounts = await window.ethereum.request({
599
+ method: "eth_requestAccounts"
600
+ });
601
+ if (!accounts || accounts.length === 0) {
602
+ throw new Error("No accounts returned from wallet");
603
+ }
604
+ const userAddress = accounts[0];
605
+ setAddress(userAddress);
606
+ setIsConnected(true);
607
+ const network = await browserProvider.getNetwork();
608
+ setChainId(Number(network.chainId));
609
+ } catch (err) {
610
+ const errorObj = err instanceof Error ? err : new Error(String(err));
611
+ setError(errorObj);
612
+ setIsConnected(false);
613
+ setAddress(void 0);
614
+ setChainId(void 0);
615
+ throw errorObj;
616
+ }
617
+ }, []);
618
+ const disconnect = (0, import_react.useCallback)(() => {
619
+ setAddress(void 0);
620
+ setIsConnected(false);
621
+ setChainId(void 0);
622
+ setError(void 0);
623
+ }, []);
624
+ (0, import_react.useEffect)(() => {
625
+ if (typeof window === "undefined" || !window.ethereum) return;
626
+ const ethereum = window.ethereum;
627
+ const handleAccountsChanged = (accounts) => {
628
+ const accountsArray = accounts;
629
+ if (!accountsArray || accountsArray.length === 0) {
630
+ disconnect();
631
+ } else {
632
+ setAddress(accountsArray[0]);
633
+ setIsConnected(true);
634
+ }
635
+ };
636
+ if (ethereum.on) {
637
+ ethereum.on("accountsChanged", handleAccountsChanged);
638
+ }
639
+ return () => {
640
+ if (ethereum.removeListener) {
641
+ ethereum.removeListener("accountsChanged", handleAccountsChanged);
642
+ }
643
+ };
644
+ }, [disconnect]);
645
+ (0, import_react.useEffect)(() => {
646
+ if (typeof window === "undefined" || !window.ethereum) return;
647
+ const ethereum = window.ethereum;
648
+ const handleChainChanged = (chainIdHex) => {
649
+ const newChainId = parseInt(chainIdHex, 16);
650
+ setChainId(newChainId);
651
+ };
652
+ if (ethereum.on) {
653
+ ethereum.on("chainChanged", handleChainChanged);
654
+ }
655
+ return () => {
656
+ if (ethereum.removeListener) {
657
+ ethereum.removeListener("chainChanged", handleChainChanged);
658
+ }
659
+ };
660
+ }, []);
661
+ (0, import_react.useEffect)(() => {
662
+ if (options?.autoConnect) {
663
+ connect().catch((err) => {
664
+ console.warn("[useEthersWallet] Auto-connect failed:", err);
665
+ });
666
+ }
667
+ }, [options?.autoConnect, connect]);
668
+ return {
669
+ address,
670
+ isConnected,
671
+ provider,
672
+ chainId,
673
+ connect,
674
+ disconnect,
675
+ error
676
+ };
677
+ }
678
+
575
679
  // src/client/react/useMantleX402.ts
576
- var import_wagmi = require("wagmi");
577
680
  function useMantleX402(opts) {
578
- const { address, isConnected } = (0, import_wagmi.useAccount)();
579
- const { data: walletClient } = (0, import_wagmi.useWalletClient)();
681
+ const { address, isConnected } = useEthersWallet({
682
+ autoConnect: opts?.autoConnect ?? false
683
+ });
580
684
  const client = createMantleClient({
581
685
  facilitatorUrl: opts?.facilitatorUrl,
582
686
  resourceUrl: opts?.resourceUrl,
@@ -585,7 +689,12 @@ function useMantleX402(opts) {
585
689
  if (!isConnected || !address) return void 0;
586
690
  return address;
587
691
  },
588
- getProvider: () => walletClient
692
+ getProvider: () => {
693
+ if (typeof window !== "undefined" && window.ethereum) {
694
+ return window.ethereum;
695
+ }
696
+ return void 0;
697
+ }
589
698
  });
590
699
  return client;
591
700
  }
@@ -596,5 +705,6 @@ function useMantleX402(opts) {
596
705
  createPaymentClient,
597
706
  createPaymentMiddleware,
598
707
  mantlePaywall,
708
+ useEthersWallet,
599
709
  useMantleX402
600
710
  });
package/dist/index.d.cts CHANGED
@@ -1,290 +1,8 @@
1
- import { Request, Response, NextFunction } from 'express';
2
-
3
- /** Network identifier used in x402 paymentRequirements / paymentHeader. */
4
- type NetworkId = "mantle-mainnet" | (string & {});
5
- /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
6
- interface AssetConfig {
7
- symbol: string;
8
- address: string;
9
- decimals: number;
10
- }
11
- /** x402-style payment requirements (returned in 402 response). */
12
- interface PaymentRequirements {
13
- scheme: "exact";
14
- network: NetworkId;
15
- asset: string;
16
- maxAmountRequired: string;
17
- payTo: string;
18
- price?: string;
19
- currency?: string;
20
- }
21
- /** EIP-3009 TransferWithAuthorization payload. */
22
- interface Authorization {
23
- from: string;
24
- to: string;
25
- value: string;
26
- validAfter: string;
27
- validBefore: string;
28
- nonce: string;
29
- }
30
- /** Inner payload of x402-style payment header. */
31
- interface PaymentHeaderPayload {
32
- signature: string;
33
- authorization: Authorization;
34
- }
35
- /** Structured x402-style payment header (before base64 encoding). */
36
- interface PaymentHeaderObject {
37
- x402Version: number;
38
- scheme: "exact";
39
- network: NetworkId;
40
- payload: PaymentHeaderPayload;
41
- }
42
- /** Base64-encoded payment header, sent in X-PAYMENT. */
43
- type PaymentHeaderBase64 = string;
44
-
45
- /**
46
- * Default values for Mantle mainnet x402 payments.
47
- * These are used by the simplified API (mantlePaywall, createMantleClient).
48
- */
49
- declare const MANTLE_DEFAULTS: {
50
- readonly NETWORK: "mantle-mainnet";
51
- readonly CHAIN_ID: 5000;
52
- readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
53
- readonly USDC_DECIMALS: 6;
54
- readonly CURRENCY: "USD";
55
- readonly SCHEME: "exact";
56
- readonly FACILITATOR_URL: string;
57
- };
58
-
59
- /** Unique key for a protected route, e.g. "GET /api/protected". */
60
- type RouteKey = string;
61
- /** Pricing config for a single route. */
62
- interface RoutePricingConfig {
63
- /** Price in USD cents, e.g. 1 => $0.01. */
64
- priceUsdCents: number;
65
- /** Network identifier (e.g. "mantle-mainnet"). */
66
- network: NetworkId;
67
- }
68
- /** Map of route keys to pricing config. */
69
- type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
70
- /** Log entry for a successfully settled payment. */
71
- interface PaymentLogEntry {
72
- id: string;
73
- from: string;
74
- to: string;
75
- valueAtomic: string;
76
- network: NetworkId;
77
- asset: string;
78
- route?: RouteKey;
79
- txHash?: string;
80
- timestamp: number;
81
- facilitatorUrl?: string;
82
- paymentRequirements?: PaymentRequirements;
83
- }
84
- /** Config for optional telemetry (billing/analytics). */
85
- interface TelemetryConfig {
86
- /** Project key from nosubs.ai dashboard. */
87
- projectKey: string;
88
- /**
89
- * Telemetry endpoint URL.
90
- * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
91
- * If both are undefined, telemetry is not sent.
92
- */
93
- endpoint?: string;
94
- }
95
- /** Telemetry event payload for payment_verified. */
96
- interface TelemetryEvent {
97
- event: "payment_verified";
98
- ts: number;
99
- projectKey: string;
100
- network: string;
101
- buyer: string;
102
- payTo: string;
103
- amountAtomic: string;
104
- asset: string;
105
- decimals: number;
106
- nonce: string;
107
- route: string;
108
- facilitatorType: "hosted" | "self-hosted";
109
- facilitatorUrl?: string;
110
- facilitatorAddress?: string;
111
- txHash?: string;
112
- priceUsd?: string;
113
- }
114
- /** Config for createPaymentMiddleware. */
115
- interface PaymentMiddlewareConfig {
116
- /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
117
- facilitatorUrl: string;
118
- /** Recipient address (developer). */
119
- receiverAddress: string;
120
- /** Map of protected routes and their pricing. */
121
- routes: RoutesConfig;
122
- /**
123
- * Optional hook called whenever a payment is successfully settled.
124
- * You can use this to push logs into your DB / analytics pipeline.
125
- */
126
- onPaymentSettled?: (entry: PaymentLogEntry) => void;
127
- /** Optional: Send usage telemetry for billing/analytics. */
128
- telemetry?: TelemetryConfig;
129
- }
130
- /**
131
- * Minimal config for mantlePaywall() - simplified API for single-route protection.
132
- * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
133
- */
134
- interface MinimalPaywallOptions {
135
- /** Price in USD (e.g. 0.01 for 1 cent). */
136
- priceUsd: number;
137
- /** Recipient address (developer wallet). */
138
- payTo: `0x${string}`;
139
- /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
140
- facilitatorUrl?: string;
141
- /** Optional telemetry config. */
142
- telemetry?: TelemetryConfig;
143
- /** Optional payment settled hook. */
144
- onPaymentSettled?: (entry: PaymentLogEntry) => void;
145
- }
146
-
147
- declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): (req: Request, res: Response, next: NextFunction) => Promise<void>;
148
-
149
- /**
150
- * Simplified wrapper for protecting a single route with x402 payments.
151
- * Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
152
- *
153
- * Usage:
154
- * ```typescript
155
- * const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
156
- * export const POST = pay(async (req) => { ... });
157
- * ```
158
- *
159
- * @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
160
- * @returns Express middleware function for single-route protection.
161
- */
162
- declare function mantlePaywall(opts: MinimalPaywallOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
163
-
164
- /** Config for the client-side payment helper. */
165
- interface PaymentClientConfig {
166
- /** Base URL of your protected resource server. */
167
- resourceUrl: string;
168
- /** Facilitator URL (hosted or self-hosted). */
169
- facilitatorUrl: string;
170
- /** EIP-1193 provider (window.ethereum) or similar. */
171
- provider: unknown;
172
- /** Optional user address override; otherwise derived from provider. */
173
- userAddress?: string;
174
- /** Optional: Project key for hosted facilitator billing. */
175
- projectKey?: string;
176
- }
177
- /** Result of a callWithPayment() client operation. */
178
- interface CallWithPaymentResult<TResponseBody = unknown> {
179
- response: TResponseBody;
180
- txHash?: string;
181
- paymentHeader: PaymentHeaderBase64;
182
- paymentRequirements: PaymentRequirements;
183
- }
184
- /** Shape of the client instance returned by createPaymentClient. */
185
- interface PaymentClient {
186
- callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
187
- method?: "GET" | "POST" | "PUT" | "DELETE";
188
- body?: TBody;
189
- headers?: Record<string, string>;
190
- /**
191
- * Optional override if you want to send less than maxAmountRequired.
192
- * In most cases you won't need this and will just pay maxAmountRequired.
193
- */
194
- valueOverrideAtomic?: string;
195
- }): Promise<CallWithPaymentResult<TResp>>;
196
- }
197
-
198
- /**
199
- * Creates a high-level payment client that:
200
- * - makes an initial request
201
- * - if it receives 402 + paymentRequirements, builds & signs an authorization
202
- * - calls facilitator /settle
203
- * - retries the original request with X-PAYMENT header
204
- *
205
- * This logic is x402 and tailored for Mantle + USDC.
206
- */
207
- declare function createPaymentClient(config: PaymentClientConfig): PaymentClient;
208
-
209
- /**
210
- * Configuration for createMantleClient().
211
- * All fields are optional - the client auto-detects sensible defaults.
212
- */
213
- interface MantleClientConfig {
214
- /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
215
- facilitatorUrl?: string;
216
- /** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
217
- resourceUrl?: string;
218
- /** Function to get user's wallet address (required for payments). */
219
- getAccount?: () => Promise<string | undefined> | string | undefined;
220
- /** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
221
- getProvider?: () => any;
222
- /** Optional project key for hosted facilitator billing. */
223
- projectKey?: string;
224
- }
225
- /**
226
- * Simplified Mantle payment client interface.
227
- * Provides a clean API for making paid POST requests.
228
- */
229
- interface MantleClient {
230
- /**
231
- * Make a paid POST request to a protected endpoint.
232
- * Automatically handles x402 flow (402 response, signing, payment, retry).
233
- *
234
- * @param url - API endpoint path (e.g., "/api/generate-image").
235
- * @param body - Request body (will be JSON stringified).
236
- * @returns Response data from the protected endpoint.
237
- * @throws Error if wallet is not connected or payment fails.
238
- */
239
- post<TResp = any>(url: string, body?: any): Promise<TResp>;
240
- }
241
- /**
242
- * Create a simplified Mantle payment client with auto-detected defaults.
243
- *
244
- * Usage:
245
- * ```typescript
246
- * const client = createMantleClient({
247
- * getAccount: () => account?.address,
248
- * getProvider: () => walletClient,
249
- * });
250
- *
251
- * const data = await client.post("/api/generate", { prompt: "..." });
252
- * ```
253
- *
254
- * @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
255
- * @returns MantleClient instance with simplified post() method.
256
- */
257
- declare function createMantleClient(config?: MantleClientConfig): MantleClient;
258
-
259
- /**
260
- * Options for useMantleX402 React hook.
261
- */
262
- interface UseMantleX402Options {
263
- /** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL). */
264
- facilitatorUrl?: string;
265
- /** Optional resource URL (defaults to current origin). */
266
- resourceUrl?: string;
267
- /** Optional project key for hosted facilitator billing. */
268
- projectKey?: string;
269
- }
270
- /**
271
- * React hook for simplified Mantle x402 payments with wagmi integration.
272
- *
273
- * Automatically connects to the user's wallet via wagmi hooks and provides
274
- * a clean API for making paid requests.
275
- *
276
- * Usage:
277
- * ```typescript
278
- * const { post } = useMantleX402();
279
- *
280
- * const data = await post("/api/generate-image", {
281
- * prompt: "A beautiful sunset"
282
- * });
283
- * ```
284
- *
285
- * @param opts - Optional configuration (facilitatorUrl, resourceUrl, projectKey).
286
- * @returns MantleClient instance with post() method.
287
- */
288
- declare function useMantleX402(opts?: UseMantleX402Options): MantleClient;
289
-
290
- export { type AssetConfig, type Authorization, type CallWithPaymentResult, MANTLE_DEFAULTS, type MantleClient, type MantleClientConfig, type MinimalPaywallOptions, type NetworkId, type PaymentClient, type PaymentClientConfig, type PaymentHeaderBase64, type PaymentHeaderObject, type PaymentHeaderPayload, type PaymentLogEntry, type PaymentMiddlewareConfig, type PaymentRequirements, type RouteKey, type RoutePricingConfig, type RoutesConfig, type TelemetryConfig, type TelemetryEvent, type UseMantleX402Options, createMantleClient, createPaymentClient, createPaymentMiddleware, mantlePaywall, useMantleX402 };
1
+ 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-2zqbJvcz.cjs';
2
+ export { M as MANTLE_DEFAULTS } from './constants-DzCGK0Q3.cjs';
3
+ export { MantleMiddleware, MinimalPaywallOptions, PaymentLogEntry, PaymentMiddlewareConfig, RouteKey, RoutePricingConfig, RoutesConfig, TelemetryConfig, TelemetryEvent, createPaymentMiddleware, mantlePaywall } from './server.cjs';
4
+ export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-NN0Nitp9.cjs';
5
+ export { createPaymentClient } from './client.cjs';
6
+ export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.cjs';
7
+ import 'express';
8
+ import 'ethers';