@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.
- package/dist/chunk-23QNUJIB.js +136 -0
- package/dist/chunk-6GLR5EBK.js +96 -0
- package/dist/chunk-BRGW36P7.js +211 -0
- package/dist/chunk-CTI5CRDY.js +274 -0
- package/dist/chunk-DA6ZBXNO.js +275 -0
- package/dist/chunk-E46A7I6B.js +274 -0
- package/dist/chunk-FD4HG7KR.js +135 -0
- package/dist/chunk-FHU6CFHF.js +0 -0
- package/dist/chunk-GHUWTX7J.js +66 -0
- package/dist/chunk-GWVWPS3R.js +277 -0
- package/dist/chunk-HEZZ74SI.js +62 -0
- package/dist/chunk-HTZ3QFY4.js +135 -0
- package/dist/chunk-MQALBRGV.js +135 -0
- package/dist/chunk-NQWSCY44.js +70 -0
- package/dist/chunk-PCJEJYP6.js +68 -0
- package/dist/chunk-PPVS3X5Z.js +99 -0
- package/dist/chunk-PYIYE3HI.js +135 -0
- package/dist/chunk-Q6SPMEIW.js +235 -0
- package/dist/chunk-RNKXSBT7.js +135 -0
- package/dist/chunk-SPCXFN7C.js +284 -0
- package/dist/chunk-T5DRYLNB.js +135 -0
- package/dist/chunk-TSEE5NSJ.js +297 -0
- package/dist/chunk-U73CZU3X.js +237 -0
- package/dist/chunk-WAKJRVUP.js +135 -0
- package/dist/chunk-WELDWRDX.js +307 -0
- package/dist/chunk-WFUDGBKK.js +68 -0
- package/dist/chunk-WO2MYZXT.js +0 -0
- package/dist/chunk-XAQGMFSR.js +56 -0
- package/dist/client.cjs +328 -0
- package/dist/client.d.cts +17 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.js +12 -0
- package/dist/constants-0ncqvV_O.d.ts +17 -0
- package/dist/constants-C7aY8u5b.d.cts +77 -0
- package/dist/constants-C7aY8u5b.d.ts +77 -0
- package/dist/constants-CVFF0ray.d.ts +17 -0
- package/dist/constants-CsIL25uQ.d.cts +17 -0
- package/dist/constants-DzCGK0Q3.d.cts +17 -0
- package/dist/createMantleClient-CO0uWPb-.d.cts +87 -0
- package/dist/createMantleClient-CuiPsTa6.d.ts +87 -0
- package/dist/createMantleClient-DS1Ghqrz.d.cts +51 -0
- package/dist/createMantleClient-DS1Ghqrz.d.ts +51 -0
- package/dist/createMantleClient-DVFkbBfS.d.ts +87 -0
- package/dist/createMantleClient-NN0Nitp9.d.cts +87 -0
- package/dist/express-Ck7eryef.d.cts +66 -0
- package/dist/express-CmEg5hR3.d.ts +66 -0
- package/dist/express-D8EwEcOL.d.ts +66 -0
- package/dist/express-eQOPxfnI.d.cts +66 -0
- package/dist/index.cjs +342 -155
- package/dist/index.d.cts +10 -290
- package/dist/index.d.ts +10 -290
- package/dist/index.js +18 -567
- package/dist/nextjs-Bp8DxYDN.d.ts +45 -0
- package/dist/nextjs-CliiaTPe.d.cts +45 -0
- package/dist/nextjs-D7t-BC4N.d.ts +45 -0
- package/dist/nextjs-Duecps0q.d.cts +45 -0
- package/dist/nextjs-TFhFiQuL.d.ts +45 -0
- package/dist/nextjs-ZO2J9mdo.d.cts +45 -0
- package/dist/react.cjs +454 -0
- package/dist/react.d.cts +93 -0
- package/dist/react.d.ts +93 -0
- package/dist/react.js +10 -0
- package/dist/server-express.cjs +368 -0
- package/dist/server-express.d.cts +5 -0
- package/dist/server-express.d.ts +5 -0
- package/dist/server-express.js +13 -0
- package/dist/server-nextjs.cjs +339 -0
- package/dist/server-nextjs.d.cts +5 -0
- package/dist/server-nextjs.d.ts +5 -0
- package/dist/server-nextjs.js +11 -0
- package/dist/server-web.cjs +339 -0
- package/dist/server-web.d.cts +4 -0
- package/dist/server-web.d.ts +4 -0
- package/dist/server-web.js +11 -0
- package/dist/server.cjs +497 -0
- package/dist/server.d.cts +79 -0
- package/dist/server.d.ts +79 -0
- package/dist/server.js +36 -0
- package/dist/types-2zqbJvcz.d.cts +63 -0
- package/dist/types-2zqbJvcz.d.ts +63 -0
- package/dist/types-BFUqKBBO.d.cts +63 -0
- package/dist/types-BFUqKBBO.d.ts +63 -0
- package/dist/types-C7EPJ6Hd.d.ts +85 -0
- package/dist/types-CEttmr1U.d.cts +97 -0
- package/dist/types-CoOdbZSp.d.cts +97 -0
- package/dist/types-CqQ6OgRi.d.ts +85 -0
- package/dist/types-CrOsOHcX.d.cts +85 -0
- package/dist/types-D20K36pc.d.ts +97 -0
- package/dist/types-DTzov_EE.d.ts +97 -0
- package/dist/types-xkNm0uzE.d.cts +85 -0
- package/dist/web-standards-BNQyWzBC.d.cts +77 -0
- package/dist/web-standards-C3D2vdTg.d.ts +77 -0
- package/dist/web-standards-D8j1kZxd.d.ts +77 -0
- package/dist/web-standards-DOYp0UDT.d.cts +77 -0
- package/package.json +80 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,290 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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-BFUqKBBO.cjs';
|
|
2
|
+
export { M as MANTLE_DEFAULTS } from './constants-CsIL25uQ.cjs';
|
|
3
|
+
export { M as MantleMiddleware, e as MinimalPaywallOptions, P as PaymentLogEntry, d as PaymentMiddlewareConfig, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig, c as TelemetryEvent } from './types-CoOdbZSp.cjs';
|
|
4
|
+
export { c as createPaymentMiddleware, m as mantlePaywall } from './express-eQOPxfnI.cjs';
|
|
5
|
+
export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-CO0uWPb-.cjs';
|
|
6
|
+
export { createPaymentClient } from './client.cjs';
|
|
7
|
+
export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.cjs';
|
|
8
|
+
import 'express';
|
|
9
|
+
import './types-CrOsOHcX.cjs';
|
|
10
|
+
import 'ethers';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,290 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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-BFUqKBBO.js';
|
|
2
|
+
export { M as MANTLE_DEFAULTS } from './constants-0ncqvV_O.js';
|
|
3
|
+
export { M as MantleMiddleware, e as MinimalPaywallOptions, P as PaymentLogEntry, d as PaymentMiddlewareConfig, R as RouteKey, a as RoutePricingConfig, b as RoutesConfig, T as TelemetryConfig, c as TelemetryEvent } from './types-DTzov_EE.js';
|
|
4
|
+
export { c as createPaymentMiddleware, m as mantlePaywall } from './express-D8EwEcOL.js';
|
|
5
|
+
export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, b as PaymentClient, P as PaymentClientConfig, c as createMantleClient } from './createMantleClient-CuiPsTa6.js';
|
|
6
|
+
export { createPaymentClient } from './client.js';
|
|
7
|
+
export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.js';
|
|
8
|
+
import 'express';
|
|
9
|
+
import './types-CqQ6OgRi.js';
|
|
10
|
+
import 'ethers';
|