@puga-labs/x402-mantle-sdk 0.3.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-E46A7I6B.js +274 -0
- package/dist/chunk-FHU6CFHF.js +0 -0
- package/dist/chunk-GHUWTX7J.js +66 -0
- package/dist/chunk-HEZZ74SI.js +62 -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-U73CZU3X.js +237 -0
- package/dist/chunk-WAKJRVUP.js +135 -0
- package/dist/chunk-WFUDGBKK.js +68 -0
- package/dist/chunk-WO2MYZXT.js +0 -0
- package/dist/client.d.cts +4 -4
- package/dist/client.d.ts +4 -4
- package/dist/client.js +2 -2
- package/dist/constants-0ncqvV_O.d.ts +17 -0
- package/dist/constants-CsIL25uQ.d.cts +17 -0
- package/dist/createMantleClient-CO0uWPb-.d.cts +87 -0
- package/dist/createMantleClient-CuiPsTa6.d.ts +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 +186 -109
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +6 -4
- 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 +3 -2
- package/dist/react.d.cts +7 -4
- package/dist/react.d.ts +7 -4
- package/dist/react.js +3 -3
- 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 +316 -111
- package/dist/server.d.cts +67 -104
- package/dist/server.d.ts +67 -104
- package/dist/server.js +29 -5
- 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 +49 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { b as RoutesConfig, M as MinimalPaywallOptions } from './types-CrOsOHcX.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Express middleware function type for Mantle paywall.
|
|
6
|
+
*/
|
|
7
|
+
type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
8
|
+
/** Config for createPaymentMiddleware. */
|
|
9
|
+
interface PaymentMiddlewareConfig {
|
|
10
|
+
/** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
|
|
11
|
+
facilitatorUrl: string;
|
|
12
|
+
/** Recipient address (developer). Validated at runtime. */
|
|
13
|
+
receiverAddress: string;
|
|
14
|
+
/** Map of protected routes and their pricing. */
|
|
15
|
+
routes: RoutesConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Optional hook called whenever a payment is successfully settled.
|
|
18
|
+
*/
|
|
19
|
+
onPaymentSettled?: MinimalPaywallOptions["onPaymentSettled"];
|
|
20
|
+
/** Optional: Send usage telemetry for billing/analytics. */
|
|
21
|
+
telemetry?: MinimalPaywallOptions["telemetry"];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create Express middleware for x402 payment verification on multiple routes.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const middleware = createPaymentMiddleware({
|
|
29
|
+
* facilitatorUrl: 'https://facilitator.nosubs.ai',
|
|
30
|
+
* receiverAddress: '0x...',
|
|
31
|
+
* routes: {
|
|
32
|
+
* 'POST /api/generate': { priceUsdCents: 1, network: 'mantle-mainnet' },
|
|
33
|
+
* 'GET /api/data': { priceUsdCents: 5, network: 'mantle-mainnet' },
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* app.use(middleware);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): MantleMiddleware;
|
|
41
|
+
/**
|
|
42
|
+
* Simplified wrapper for protecting a single route with x402 payments.
|
|
43
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const pay = mantlePaywall({ priceUsd: 0.01, payTo: "0x..." });
|
|
48
|
+
* app.post('/api/generate', pay, async (req, res) => {
|
|
49
|
+
* // Your handler code here
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
54
|
+
* @returns Express middleware function for single-route protection.
|
|
55
|
+
*/
|
|
56
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): MantleMiddleware;
|
|
57
|
+
|
|
58
|
+
type express_MantleMiddleware = MantleMiddleware;
|
|
59
|
+
type express_PaymentMiddlewareConfig = PaymentMiddlewareConfig;
|
|
60
|
+
declare const express_createPaymentMiddleware: typeof createPaymentMiddleware;
|
|
61
|
+
declare const express_mantlePaywall: typeof mantlePaywall;
|
|
62
|
+
declare namespace express {
|
|
63
|
+
export { type express_MantleMiddleware as MantleMiddleware, type express_PaymentMiddlewareConfig as PaymentMiddlewareConfig, express_createPaymentMiddleware as createPaymentMiddleware, express_mantlePaywall as mantlePaywall };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { type MantleMiddleware as M, type PaymentMiddlewareConfig as P, createPaymentMiddleware as c, express as e, mantlePaywall as m };
|
package/dist/index.cjs
CHANGED
|
@@ -82,6 +82,54 @@ function usdCentsToAtomic(cents, decimals) {
|
|
|
82
82
|
return BigInt(cents) * base;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// src/server/core/utils.ts
|
|
86
|
+
function validateAddress(address, paramName = "address") {
|
|
87
|
+
if (!address) {
|
|
88
|
+
throw new Error(`${paramName} is required`);
|
|
89
|
+
}
|
|
90
|
+
if (typeof address !== "string") {
|
|
91
|
+
throw new Error(`${paramName} must be a string, got ${typeof address}`);
|
|
92
|
+
}
|
|
93
|
+
if (!address.startsWith("0x")) {
|
|
94
|
+
const preview = address.length > 10 ? `${address.substring(0, 10)}...` : address;
|
|
95
|
+
throw new Error(
|
|
96
|
+
`${paramName} must start with "0x", got: ${preview}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (address.length !== 42) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`${paramName} must be 42 characters (0x + 40 hex), got ${address.length} characters`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const hexPart = address.slice(2);
|
|
105
|
+
if (!/^[0-9a-fA-F]{40}$/.test(hexPart)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`${paramName} must contain only hexadecimal characters (0-9, a-f, A-F) after "0x"`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function decodePaymentHeader(paymentHeaderBase64) {
|
|
112
|
+
try {
|
|
113
|
+
if (typeof Buffer !== "undefined") {
|
|
114
|
+
const json = Buffer.from(paymentHeaderBase64, "base64").toString("utf8");
|
|
115
|
+
return JSON.parse(json);
|
|
116
|
+
}
|
|
117
|
+
if (typeof atob === "function") {
|
|
118
|
+
const json = atob(paymentHeaderBase64);
|
|
119
|
+
return JSON.parse(json);
|
|
120
|
+
}
|
|
121
|
+
throw new Error("No base64 decoding available in this environment");
|
|
122
|
+
} catch (err) {
|
|
123
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
124
|
+
throw new Error(`Failed to decode paymentHeader: ${msg}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function buildRouteKey(method, path) {
|
|
128
|
+
const normalizedMethod = (method || "GET").toUpperCase();
|
|
129
|
+
const normalizedPath = path || "/";
|
|
130
|
+
return `${normalizedMethod} ${normalizedPath}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
85
133
|
// src/server/constants.ts
|
|
86
134
|
var DEFAULT_TELEMETRY_ENDPOINT = void 0;
|
|
87
135
|
|
|
@@ -135,28 +183,130 @@ async function sendTelemetry(event, endpoint) {
|
|
|
135
183
|
}
|
|
136
184
|
}
|
|
137
185
|
|
|
138
|
-
// src/server/
|
|
139
|
-
function
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
186
|
+
// src/server/core/verifyPayment.ts
|
|
187
|
+
async function checkPayment(input) {
|
|
188
|
+
const {
|
|
189
|
+
paymentHeader,
|
|
190
|
+
paymentRequirements,
|
|
191
|
+
facilitatorUrl,
|
|
192
|
+
routeKey,
|
|
193
|
+
network,
|
|
194
|
+
asset,
|
|
195
|
+
telemetry,
|
|
196
|
+
onPaymentSettled
|
|
197
|
+
} = input;
|
|
198
|
+
if (!paymentHeader) {
|
|
199
|
+
return {
|
|
200
|
+
status: "require_payment",
|
|
201
|
+
statusCode: 402,
|
|
202
|
+
responseBody: {
|
|
203
|
+
error: "Payment Required",
|
|
204
|
+
paymentRequirements,
|
|
205
|
+
paymentHeader: null
|
|
206
|
+
},
|
|
207
|
+
isValid: false
|
|
208
|
+
};
|
|
209
|
+
}
|
|
145
210
|
try {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
211
|
+
const verifyUrl = `${facilitatorUrl.replace(/\/+$/, "")}/verify`;
|
|
212
|
+
const verifyRes = await fetch(verifyUrl, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: {
|
|
215
|
+
"Content-Type": "application/json"
|
|
216
|
+
},
|
|
217
|
+
body: JSON.stringify({
|
|
218
|
+
x402Version: 1,
|
|
219
|
+
paymentHeader,
|
|
220
|
+
paymentRequirements
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
if (!verifyRes.ok) {
|
|
224
|
+
const text = await verifyRes.text().catch(() => "");
|
|
225
|
+
console.error(
|
|
226
|
+
"[x402-mantle-sdk] Facilitator /verify returned non-OK:",
|
|
227
|
+
verifyRes.status,
|
|
228
|
+
text
|
|
229
|
+
);
|
|
230
|
+
return {
|
|
231
|
+
status: "verification_error",
|
|
232
|
+
statusCode: 500,
|
|
233
|
+
responseBody: {
|
|
234
|
+
error: "Payment verification error",
|
|
235
|
+
details: `Facilitator responded with HTTP ${verifyRes.status}`
|
|
236
|
+
},
|
|
237
|
+
isValid: false
|
|
238
|
+
};
|
|
149
239
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return
|
|
240
|
+
const verifyJson = await verifyRes.json();
|
|
241
|
+
if (!verifyJson.isValid) {
|
|
242
|
+
return {
|
|
243
|
+
status: "invalid_payment",
|
|
244
|
+
statusCode: 402,
|
|
245
|
+
responseBody: {
|
|
246
|
+
error: "Payment verification failed",
|
|
247
|
+
invalidReason: verifyJson.invalidReason ?? null,
|
|
248
|
+
paymentRequirements,
|
|
249
|
+
paymentHeader: null
|
|
250
|
+
},
|
|
251
|
+
isValid: false
|
|
252
|
+
};
|
|
153
253
|
}
|
|
154
|
-
|
|
254
|
+
if (onPaymentSettled) {
|
|
255
|
+
try {
|
|
256
|
+
const headerObj = decodePaymentHeader(paymentHeader);
|
|
257
|
+
const { authorization } = headerObj.payload;
|
|
258
|
+
const assetConfig = getDefaultAssetForNetwork(network);
|
|
259
|
+
const logEntry = {
|
|
260
|
+
id: authorization.nonce,
|
|
261
|
+
from: authorization.from,
|
|
262
|
+
to: authorization.to,
|
|
263
|
+
valueAtomic: authorization.value,
|
|
264
|
+
network,
|
|
265
|
+
asset,
|
|
266
|
+
route: routeKey,
|
|
267
|
+
timestamp: Date.now(),
|
|
268
|
+
facilitatorUrl,
|
|
269
|
+
paymentRequirements
|
|
270
|
+
};
|
|
271
|
+
onPaymentSettled(logEntry);
|
|
272
|
+
if (telemetry) {
|
|
273
|
+
const event = createTelemetryEvent(logEntry, telemetry);
|
|
274
|
+
sendTelemetry(event, telemetry.endpoint).catch(
|
|
275
|
+
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
console.error(
|
|
280
|
+
"[x402-mantle-sdk] Error calling onPaymentSettled hook:",
|
|
281
|
+
err
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
status: "verified",
|
|
287
|
+
statusCode: 200,
|
|
288
|
+
responseBody: null,
|
|
289
|
+
isValid: true
|
|
290
|
+
};
|
|
155
291
|
} catch (err) {
|
|
156
|
-
|
|
157
|
-
|
|
292
|
+
console.error(
|
|
293
|
+
"[x402-mantle-sdk] Error while calling facilitator /verify:",
|
|
294
|
+
err
|
|
295
|
+
);
|
|
296
|
+
const message = err instanceof Error ? err.message : "Unknown verification error";
|
|
297
|
+
return {
|
|
298
|
+
status: "verification_error",
|
|
299
|
+
statusCode: 500,
|
|
300
|
+
responseBody: {
|
|
301
|
+
error: "Payment verification error",
|
|
302
|
+
details: message
|
|
303
|
+
},
|
|
304
|
+
isValid: false
|
|
305
|
+
};
|
|
158
306
|
}
|
|
159
307
|
}
|
|
308
|
+
|
|
309
|
+
// src/server/adapters/express.ts
|
|
160
310
|
function createPaymentMiddleware(config) {
|
|
161
311
|
const { facilitatorUrl, receiverAddress, routes, onPaymentSettled, telemetry } = config;
|
|
162
312
|
if (!facilitatorUrl) {
|
|
@@ -165,11 +315,12 @@ function createPaymentMiddleware(config) {
|
|
|
165
315
|
if (!receiverAddress) {
|
|
166
316
|
throw new Error("receiverAddress is required");
|
|
167
317
|
}
|
|
318
|
+
validateAddress(receiverAddress, "receiverAddress");
|
|
168
319
|
if (!routes || Object.keys(routes).length === 0) {
|
|
169
320
|
throw new Error("routes config must not be empty");
|
|
170
321
|
}
|
|
171
322
|
return async function paymentMiddleware(req, res, next) {
|
|
172
|
-
const routeKey =
|
|
323
|
+
const routeKey = buildRouteKey(req.method, req.path);
|
|
173
324
|
const routeConfig = routes[routeKey];
|
|
174
325
|
if (!routeConfig) {
|
|
175
326
|
next();
|
|
@@ -190,102 +341,27 @@ function createPaymentMiddleware(config) {
|
|
|
190
341
|
price: `$${(priceUsdCents / 100).toFixed(2)}`,
|
|
191
342
|
currency: "USD"
|
|
192
343
|
};
|
|
193
|
-
const paymentHeader = req.header("X-PAYMENT")
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
headers: {
|
|
207
|
-
"Content-Type": "application/json"
|
|
208
|
-
},
|
|
209
|
-
body: JSON.stringify({
|
|
210
|
-
x402Version: 1,
|
|
211
|
-
paymentHeader,
|
|
212
|
-
paymentRequirements
|
|
213
|
-
})
|
|
214
|
-
});
|
|
215
|
-
if (!verifyRes.ok) {
|
|
216
|
-
const text = await verifyRes.text().catch(() => "");
|
|
217
|
-
console.error(
|
|
218
|
-
"[x402-mantle-sdk] Facilitator /verify returned non-OK:",
|
|
219
|
-
verifyRes.status,
|
|
220
|
-
text
|
|
221
|
-
);
|
|
222
|
-
res.status(500).json({
|
|
223
|
-
error: "Payment verification error",
|
|
224
|
-
details: `Facilitator responded with HTTP ${verifyRes.status}`
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const verifyJson = await verifyRes.json();
|
|
229
|
-
if (!verifyJson.isValid) {
|
|
230
|
-
res.status(402).json({
|
|
231
|
-
error: "Payment verification failed",
|
|
232
|
-
invalidReason: verifyJson.invalidReason ?? null,
|
|
233
|
-
paymentRequirements,
|
|
234
|
-
paymentHeader: null
|
|
235
|
-
});
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (onPaymentSettled) {
|
|
239
|
-
try {
|
|
240
|
-
const headerObj = decodePaymentHeader(paymentHeader);
|
|
241
|
-
const { authorization } = headerObj.payload;
|
|
242
|
-
const logEntry = {
|
|
243
|
-
id: authorization.nonce,
|
|
244
|
-
from: authorization.from,
|
|
245
|
-
to: authorization.to,
|
|
246
|
-
valueAtomic: authorization.value,
|
|
247
|
-
network,
|
|
248
|
-
asset: assetConfig.address,
|
|
249
|
-
route: routeKey,
|
|
250
|
-
timestamp: Date.now(),
|
|
251
|
-
facilitatorUrl,
|
|
252
|
-
// Pass from config closure
|
|
253
|
-
paymentRequirements
|
|
254
|
-
};
|
|
255
|
-
onPaymentSettled(logEntry);
|
|
256
|
-
if (telemetry) {
|
|
257
|
-
const event = createTelemetryEvent(logEntry, telemetry);
|
|
258
|
-
sendTelemetry(event, telemetry.endpoint).catch(
|
|
259
|
-
(err) => console.error("[x402-telemetry] Async send failed:", err)
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
} catch (err) {
|
|
263
|
-
console.error(
|
|
264
|
-
"[x402-mantle-sdk] Error calling onPaymentSettled hook:",
|
|
265
|
-
err
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
next();
|
|
270
|
-
return;
|
|
271
|
-
} catch (err) {
|
|
272
|
-
console.error(
|
|
273
|
-
"[x402-mantle-sdk] Error while calling facilitator /verify:",
|
|
274
|
-
err
|
|
275
|
-
);
|
|
276
|
-
const message = err instanceof Error ? err.message : "Unknown verification error";
|
|
277
|
-
res.status(500).json({
|
|
278
|
-
error: "Payment verification error",
|
|
279
|
-
details: message
|
|
280
|
-
});
|
|
344
|
+
const paymentHeader = req.header("X-PAYMENT") || req.header("x-payment") || null;
|
|
345
|
+
const result = await checkPayment({
|
|
346
|
+
paymentHeader,
|
|
347
|
+
paymentRequirements,
|
|
348
|
+
facilitatorUrl,
|
|
349
|
+
routeKey,
|
|
350
|
+
network,
|
|
351
|
+
asset: assetConfig.address,
|
|
352
|
+
telemetry,
|
|
353
|
+
onPaymentSettled
|
|
354
|
+
});
|
|
355
|
+
if (!result.isValid) {
|
|
356
|
+
res.status(result.statusCode).json(result.responseBody);
|
|
281
357
|
return;
|
|
282
358
|
}
|
|
359
|
+
next();
|
|
283
360
|
};
|
|
284
361
|
}
|
|
285
|
-
|
|
286
|
-
// src/server/mantlePaywall.ts
|
|
287
362
|
function mantlePaywall(opts) {
|
|
288
363
|
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
364
|
+
validateAddress(payTo, "payTo");
|
|
289
365
|
const priceUsdCents = Math.round(priceUsd * 100);
|
|
290
366
|
return async (req, res, next) => {
|
|
291
367
|
const method = (req.method || "GET").toUpperCase();
|
|
@@ -658,13 +734,14 @@ function useEthersWallet(options) {
|
|
|
658
734
|
}
|
|
659
735
|
};
|
|
660
736
|
}, []);
|
|
737
|
+
const shouldAutoConnect = options?.autoConnect !== false;
|
|
661
738
|
(0, import_react.useEffect)(() => {
|
|
662
|
-
if (
|
|
739
|
+
if (shouldAutoConnect) {
|
|
663
740
|
connect().catch((err) => {
|
|
664
741
|
console.warn("[useEthersWallet] Auto-connect failed:", err);
|
|
665
742
|
});
|
|
666
743
|
}
|
|
667
|
-
}, [
|
|
744
|
+
}, [shouldAutoConnect, connect]);
|
|
668
745
|
return {
|
|
669
746
|
address,
|
|
670
747
|
isConnected,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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-
|
|
2
|
-
export { M as MANTLE_DEFAULTS } from './constants-
|
|
3
|
-
export { MantleMiddleware, MinimalPaywallOptions, PaymentLogEntry, PaymentMiddlewareConfig, RouteKey, RoutePricingConfig, RoutesConfig, TelemetryConfig,
|
|
4
|
-
export {
|
|
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';
|
|
5
6
|
export { createPaymentClient } from './client.cjs';
|
|
6
7
|
export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.cjs';
|
|
7
8
|
import 'express';
|
|
9
|
+
import './types-CrOsOHcX.cjs';
|
|
8
10
|
import 'ethers';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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-
|
|
2
|
-
export { M as MANTLE_DEFAULTS } from './constants-
|
|
3
|
-
export { MantleMiddleware, MinimalPaywallOptions, PaymentLogEntry, PaymentMiddlewareConfig, RouteKey, RoutePricingConfig, RoutesConfig, TelemetryConfig,
|
|
4
|
-
export {
|
|
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';
|
|
5
6
|
export { createPaymentClient } from './client.js';
|
|
6
7
|
export { UseEthersWalletOptions, UseEthersWalletReturn, UseMantleX402Options, useEthersWallet, useMantleX402 } from './react.js';
|
|
7
8
|
import 'express';
|
|
9
|
+
import './types-CqQ6OgRi.js';
|
|
8
10
|
import 'ethers';
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useEthersWallet,
|
|
3
3
|
useMantleX402
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-23QNUJIB.js";
|
|
5
5
|
import {
|
|
6
6
|
createMantleClient,
|
|
7
7
|
createPaymentClient
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-E46A7I6B.js";
|
|
9
|
+
import "./chunk-WO2MYZXT.js";
|
|
9
10
|
import {
|
|
10
11
|
createPaymentMiddleware,
|
|
11
12
|
mantlePaywall
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PPVS3X5Z.js";
|
|
14
|
+
import "./chunk-U73CZU3X.js";
|
|
13
15
|
import {
|
|
14
16
|
MANTLE_DEFAULTS
|
|
15
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-HEZZ74SI.js";
|
|
16
18
|
export {
|
|
17
19
|
MANTLE_DEFAULTS,
|
|
18
20
|
createMantleClient,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CqQ6OgRi.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Next.js App Router route handler type.
|
|
6
|
+
*/
|
|
7
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
10
|
+
*/
|
|
11
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
14
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // app/api/generate-image/route.ts
|
|
19
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
20
|
+
*
|
|
21
|
+
* const pay = mantlePaywall({
|
|
22
|
+
* priceUsd: 0.01,
|
|
23
|
+
* payTo: process.env.PAY_TO as `0x${string}`,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
27
|
+
* const { prompt } = await req.json();
|
|
28
|
+
* // Your handler code here
|
|
29
|
+
* return NextResponse.json({ success: true });
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
34
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
35
|
+
*/
|
|
36
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
37
|
+
|
|
38
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
39
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
40
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
41
|
+
declare namespace nextjs {
|
|
42
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-xkNm0uzE.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Next.js App Router route handler type.
|
|
6
|
+
*/
|
|
7
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
10
|
+
*/
|
|
11
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
14
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // app/api/generate-image/route.ts
|
|
19
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
20
|
+
*
|
|
21
|
+
* const pay = mantlePaywall({
|
|
22
|
+
* priceUsd: 0.01,
|
|
23
|
+
* payTo: process.env.PAY_TO as `0x${string}`,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
27
|
+
* const { prompt } = await req.json();
|
|
28
|
+
* // Your handler code here
|
|
29
|
+
* return NextResponse.json({ success: true });
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
34
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
35
|
+
*/
|
|
36
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
37
|
+
|
|
38
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
39
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
40
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
41
|
+
declare namespace nextjs {
|
|
42
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-C7EPJ6Hd.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Next.js App Router route handler type.
|
|
6
|
+
*/
|
|
7
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
10
|
+
*/
|
|
11
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
14
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // app/api/generate-image/route.ts
|
|
19
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
20
|
+
*
|
|
21
|
+
* const pay = mantlePaywall({
|
|
22
|
+
* priceUsd: 0.01,
|
|
23
|
+
* payTo: process.env.PAY_TO as `0x${string}`,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
27
|
+
* const { prompt } = await req.json();
|
|
28
|
+
* // Your handler code here
|
|
29
|
+
* return NextResponse.json({ success: true });
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
34
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
35
|
+
*/
|
|
36
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
37
|
+
|
|
38
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
39
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
40
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
41
|
+
declare namespace nextjs {
|
|
42
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { M as MinimalPaywallOptions } from './types-CrOsOHcX.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Next.js App Router route handler type.
|
|
6
|
+
*/
|
|
7
|
+
type NextJSHandler<T = any> = (req: NextRequest) => Promise<NextResponse<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Wrapper function that adds x402 payment verification to Next.js route handler.
|
|
10
|
+
*/
|
|
11
|
+
type NextJSPaywallWrapper = <T>(handler: NextJSHandler<T>) => NextJSHandler<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Create Next.js App Router middleware for x402 payment verification.
|
|
14
|
+
* Uses Mantle mainnet defaults (USDC, exact scheme, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // app/api/generate-image/route.ts
|
|
19
|
+
* import { mantlePaywall } from '@puga-labs/x402-mantle-sdk/server/nextjs'
|
|
20
|
+
*
|
|
21
|
+
* const pay = mantlePaywall({
|
|
22
|
+
* priceUsd: 0.01,
|
|
23
|
+
* payTo: process.env.PAY_TO!,
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* export const POST = pay(async (req: NextRequest) => {
|
|
27
|
+
* const { prompt } = await req.json();
|
|
28
|
+
* // Your handler code here
|
|
29
|
+
* return NextResponse.json({ success: true });
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param opts - Minimal configuration (price, payTo, optional facilitator/telemetry).
|
|
34
|
+
* @returns Function that wraps Next.js route handlers with payment verification.
|
|
35
|
+
*/
|
|
36
|
+
declare function mantlePaywall(opts: MinimalPaywallOptions): NextJSPaywallWrapper;
|
|
37
|
+
|
|
38
|
+
type nextjs_NextJSHandler<T = any> = NextJSHandler<T>;
|
|
39
|
+
type nextjs_NextJSPaywallWrapper = NextJSPaywallWrapper;
|
|
40
|
+
declare const nextjs_mantlePaywall: typeof mantlePaywall;
|
|
41
|
+
declare namespace nextjs {
|
|
42
|
+
export { type nextjs_NextJSHandler as NextJSHandler, type nextjs_NextJSPaywallWrapper as NextJSPaywallWrapper, nextjs_mantlePaywall as mantlePaywall };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { type NextJSHandler as N, type NextJSPaywallWrapper as a, mantlePaywall as m, nextjs as n };
|