@puga-labs/x402-mantle-sdk 0.2.0 → 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.
- package/dist/chunk-CTI5CRDY.js +274 -0
- package/dist/chunk-DA6ZBXNO.js +275 -0
- package/dist/chunk-FD4HG7KR.js +135 -0
- package/dist/chunk-GWVWPS3R.js +277 -0
- package/dist/chunk-HTZ3QFY4.js +135 -0
- package/dist/chunk-MQALBRGV.js +135 -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-WELDWRDX.js +307 -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-C7aY8u5b.d.cts +77 -0
- package/dist/constants-C7aY8u5b.d.ts +77 -0
- package/dist/constants-CVFF0ray.d.ts +17 -0
- package/dist/constants-DzCGK0Q3.d.cts +17 -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/index.cjs +244 -43
- package/dist/index.d.cts +8 -164
- package/dist/index.d.ts +8 -164
- package/dist/index.js +21 -485
- package/dist/react.cjs +453 -0
- package/dist/react.d.cts +90 -0
- package/dist/react.d.ts +90 -0
- package/dist/react.js +10 -0
- package/dist/server.cjs +292 -0
- package/dist/server.d.cts +116 -0
- package/dist/server.d.ts +116 -0
- package/dist/server.js +12 -0
- package/dist/types-2zqbJvcz.d.cts +63 -0
- package/dist/types-2zqbJvcz.d.ts +63 -0
- package/package.json +37 -3
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,13 +17,26 @@ 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
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
33
|
+
MANTLE_DEFAULTS: () => MANTLE_DEFAULTS,
|
|
34
|
+
createMantleClient: () => createMantleClient,
|
|
23
35
|
createPaymentClient: () => createPaymentClient,
|
|
24
|
-
createPaymentMiddleware: () => createPaymentMiddleware
|
|
36
|
+
createPaymentMiddleware: () => createPaymentMiddleware,
|
|
37
|
+
mantlePaywall: () => mantlePaywall,
|
|
38
|
+
useEthersWallet: () => useEthersWallet,
|
|
39
|
+
useMantleX402: () => useMantleX402
|
|
25
40
|
});
|
|
26
41
|
module.exports = __toCommonJS(index_exports);
|
|
27
42
|
|
|
@@ -33,6 +48,15 @@ var MANTLE_MAINNET_USDC = {
|
|
|
33
48
|
address: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
|
|
34
49
|
decimals: 6
|
|
35
50
|
};
|
|
51
|
+
var MANTLE_DEFAULTS = {
|
|
52
|
+
NETWORK: "mantle-mainnet",
|
|
53
|
+
CHAIN_ID: 5e3,
|
|
54
|
+
USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
|
|
55
|
+
USDC_DECIMALS: 6,
|
|
56
|
+
CURRENCY: "USD",
|
|
57
|
+
SCHEME: "exact",
|
|
58
|
+
FACILITATOR_URL: (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) || "http://localhost:8080"
|
|
59
|
+
};
|
|
36
60
|
function getDefaultAssetForNetwork(network) {
|
|
37
61
|
switch (network) {
|
|
38
62
|
case MANTLE_MAINNET_NETWORK_ID:
|
|
@@ -259,6 +283,30 @@ function createPaymentMiddleware(config) {
|
|
|
259
283
|
};
|
|
260
284
|
}
|
|
261
285
|
|
|
286
|
+
// src/server/mantlePaywall.ts
|
|
287
|
+
function mantlePaywall(opts) {
|
|
288
|
+
const { priceUsd, payTo, facilitatorUrl, telemetry, onPaymentSettled } = opts;
|
|
289
|
+
const priceUsdCents = Math.round(priceUsd * 100);
|
|
290
|
+
return async (req, res, next) => {
|
|
291
|
+
const method = (req.method || "GET").toUpperCase();
|
|
292
|
+
const path = req.path || "/";
|
|
293
|
+
const routeKey = `${method} ${path}`;
|
|
294
|
+
const middleware = createPaymentMiddleware({
|
|
295
|
+
facilitatorUrl: facilitatorUrl || MANTLE_DEFAULTS.FACILITATOR_URL,
|
|
296
|
+
receiverAddress: payTo,
|
|
297
|
+
routes: {
|
|
298
|
+
[routeKey]: {
|
|
299
|
+
priceUsdCents,
|
|
300
|
+
network: MANTLE_DEFAULTS.NETWORK
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
telemetry,
|
|
304
|
+
onPaymentSettled
|
|
305
|
+
});
|
|
306
|
+
return middleware(req, res, next);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
262
310
|
// src/shared/utils.ts
|
|
263
311
|
function encodeJsonToBase64(value) {
|
|
264
312
|
const json = JSON.stringify(value);
|
|
@@ -298,19 +346,6 @@ function joinUrl(base, path) {
|
|
|
298
346
|
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
299
347
|
return `${normalizedBase}${normalizedPath}`;
|
|
300
348
|
}
|
|
301
|
-
async function getUserAddressFromProvider(provider) {
|
|
302
|
-
const p = provider;
|
|
303
|
-
if (!p || typeof p.request !== "function") {
|
|
304
|
-
throw new Error("provider must implement EIP-1193 request()");
|
|
305
|
-
}
|
|
306
|
-
const accounts = await p.request({
|
|
307
|
-
method: "eth_requestAccounts"
|
|
308
|
-
});
|
|
309
|
-
if (!accounts || accounts.length === 0) {
|
|
310
|
-
throw new Error("No accounts returned from provider");
|
|
311
|
-
}
|
|
312
|
-
return accounts[0];
|
|
313
|
-
}
|
|
314
349
|
function buildTypedDataForAuthorization(authorization, paymentRequirements) {
|
|
315
350
|
const chainId = getChainIdForNetwork(paymentRequirements.network);
|
|
316
351
|
const verifyingContract = paymentRequirements.asset;
|
|
@@ -337,24 +372,26 @@ function buildTypedDataForAuthorization(authorization, paymentRequirements) {
|
|
|
337
372
|
message: authorization
|
|
338
373
|
};
|
|
339
374
|
}
|
|
340
|
-
async function signAuthorizationWithProvider(provider,
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
+
};
|
|
345
385
|
const typedData = buildTypedDataForAuthorization(
|
|
346
|
-
|
|
386
|
+
authWithFrom,
|
|
347
387
|
paymentRequirements
|
|
348
388
|
);
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
throw new Error("Invalid signature returned from provider");
|
|
356
|
-
}
|
|
357
|
-
return signature;
|
|
389
|
+
const signature = await signer.signTypedData(
|
|
390
|
+
typedData.domain,
|
|
391
|
+
typedData.types,
|
|
392
|
+
typedData.message
|
|
393
|
+
);
|
|
394
|
+
return { signature, from };
|
|
358
395
|
}
|
|
359
396
|
function createPaymentClient(config) {
|
|
360
397
|
const {
|
|
@@ -397,14 +434,6 @@ function createPaymentClient(config) {
|
|
|
397
434
|
});
|
|
398
435
|
return {
|
|
399
436
|
response: json,
|
|
400
|
-
paymentHeader: "",
|
|
401
|
-
paymentRequirements: {
|
|
402
|
-
scheme: "exact",
|
|
403
|
-
network: "mantle-mainnet",
|
|
404
|
-
asset: "",
|
|
405
|
-
maxAmountRequired: "0",
|
|
406
|
-
payTo: ""
|
|
407
|
-
},
|
|
408
437
|
txHash: void 0
|
|
409
438
|
};
|
|
410
439
|
}
|
|
@@ -415,26 +444,34 @@ function createPaymentClient(config) {
|
|
|
415
444
|
"402 response did not include paymentRequirements field"
|
|
416
445
|
);
|
|
417
446
|
}
|
|
418
|
-
const fromAddress = userAddressOverride ?? await getUserAddressFromProvider(provider);
|
|
419
447
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
420
448
|
const validAfter = "0";
|
|
421
449
|
const validBefore = String(nowSec + 10 * 60);
|
|
422
450
|
const nonce = randomBytes32Hex();
|
|
423
451
|
const valueAtomic = options?.valueOverrideAtomic ?? paymentRequirements.maxAmountRequired;
|
|
424
|
-
|
|
425
|
-
from:
|
|
452
|
+
let authorization = {
|
|
453
|
+
from: "0x0000000000000000000000000000000000000000",
|
|
426
454
|
to: paymentRequirements.payTo,
|
|
427
455
|
value: valueAtomic,
|
|
428
456
|
validAfter,
|
|
429
457
|
validBefore,
|
|
430
458
|
nonce
|
|
431
459
|
};
|
|
432
|
-
const signature = await signAuthorizationWithProvider(
|
|
460
|
+
const { signature, from } = await signAuthorizationWithProvider(
|
|
433
461
|
provider,
|
|
434
|
-
fromAddress,
|
|
435
462
|
authorization,
|
|
436
463
|
paymentRequirements
|
|
437
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
|
+
}
|
|
438
475
|
const paymentHeaderObject = {
|
|
439
476
|
x402Version: 1,
|
|
440
477
|
scheme: paymentRequirements.scheme,
|
|
@@ -502,8 +539,172 @@ function createPaymentClient(config) {
|
|
|
502
539
|
}
|
|
503
540
|
};
|
|
504
541
|
}
|
|
542
|
+
|
|
543
|
+
// src/client/createMantleClient.ts
|
|
544
|
+
function createMantleClient(config) {
|
|
545
|
+
const resourceUrl = config?.resourceUrl ?? (typeof window !== "undefined" ? window.location.origin : "");
|
|
546
|
+
const facilitatorUrl = config?.facilitatorUrl ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_FACILITATOR_URL : void 0) ?? "http://localhost:8080";
|
|
547
|
+
return {
|
|
548
|
+
async postWithPayment(url, body) {
|
|
549
|
+
const account = await config?.getAccount?.();
|
|
550
|
+
if (!account) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
"Wallet not connected. Please connect your wallet first."
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
const provider = config?.getProvider?.();
|
|
556
|
+
if (!provider) {
|
|
557
|
+
throw new Error("Wallet provider not available");
|
|
558
|
+
}
|
|
559
|
+
const client = createPaymentClient({
|
|
560
|
+
resourceUrl,
|
|
561
|
+
facilitatorUrl,
|
|
562
|
+
provider,
|
|
563
|
+
userAddress: account,
|
|
564
|
+
projectKey: config?.projectKey
|
|
565
|
+
});
|
|
566
|
+
const result = await client.callWithPayment(url, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
body
|
|
569
|
+
});
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
}
|
|
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
|
+
|
|
679
|
+
// src/client/react/useMantleX402.ts
|
|
680
|
+
function useMantleX402(opts) {
|
|
681
|
+
const { address, isConnected } = useEthersWallet({
|
|
682
|
+
autoConnect: opts?.autoConnect ?? false
|
|
683
|
+
});
|
|
684
|
+
const client = createMantleClient({
|
|
685
|
+
facilitatorUrl: opts?.facilitatorUrl,
|
|
686
|
+
resourceUrl: opts?.resourceUrl,
|
|
687
|
+
projectKey: opts?.projectKey,
|
|
688
|
+
getAccount: () => {
|
|
689
|
+
if (!isConnected || !address) return void 0;
|
|
690
|
+
return address;
|
|
691
|
+
},
|
|
692
|
+
getProvider: () => {
|
|
693
|
+
if (typeof window !== "undefined" && window.ethereum) {
|
|
694
|
+
return window.ethereum;
|
|
695
|
+
}
|
|
696
|
+
return void 0;
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
return client;
|
|
700
|
+
}
|
|
505
701
|
// Annotate the CommonJS export names for ESM import in node:
|
|
506
702
|
0 && (module.exports = {
|
|
703
|
+
MANTLE_DEFAULTS,
|
|
704
|
+
createMantleClient,
|
|
507
705
|
createPaymentClient,
|
|
508
|
-
createPaymentMiddleware
|
|
706
|
+
createPaymentMiddleware,
|
|
707
|
+
mantlePaywall,
|
|
708
|
+
useEthersWallet,
|
|
709
|
+
useMantleX402
|
|
509
710
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,164 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
/** Unique key for a protected route, e.g. "GET /api/protected". */
|
|
46
|
-
type RouteKey = string;
|
|
47
|
-
/** Pricing config for a single route. */
|
|
48
|
-
interface RoutePricingConfig {
|
|
49
|
-
/** Price in USD cents, e.g. 1 => $0.01. */
|
|
50
|
-
priceUsdCents: number;
|
|
51
|
-
/** Network identifier (e.g. "mantle-mainnet"). */
|
|
52
|
-
network: NetworkId;
|
|
53
|
-
}
|
|
54
|
-
/** Map of route keys to pricing config. */
|
|
55
|
-
type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
|
|
56
|
-
/** Log entry for a successfully settled payment. */
|
|
57
|
-
interface PaymentLogEntry {
|
|
58
|
-
id: string;
|
|
59
|
-
from: string;
|
|
60
|
-
to: string;
|
|
61
|
-
valueAtomic: string;
|
|
62
|
-
network: NetworkId;
|
|
63
|
-
asset: string;
|
|
64
|
-
route?: RouteKey;
|
|
65
|
-
txHash?: string;
|
|
66
|
-
timestamp: number;
|
|
67
|
-
facilitatorUrl?: string;
|
|
68
|
-
paymentRequirements?: PaymentRequirements;
|
|
69
|
-
}
|
|
70
|
-
/** Config for optional telemetry (billing/analytics). */
|
|
71
|
-
interface TelemetryConfig {
|
|
72
|
-
/** Project key from nosubs.ai dashboard. */
|
|
73
|
-
projectKey: string;
|
|
74
|
-
/**
|
|
75
|
-
* Telemetry endpoint URL.
|
|
76
|
-
* If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
|
|
77
|
-
* If both are undefined, telemetry is not sent.
|
|
78
|
-
*/
|
|
79
|
-
endpoint?: string;
|
|
80
|
-
}
|
|
81
|
-
/** Telemetry event payload for payment_verified. */
|
|
82
|
-
interface TelemetryEvent {
|
|
83
|
-
event: "payment_verified";
|
|
84
|
-
ts: number;
|
|
85
|
-
projectKey: string;
|
|
86
|
-
network: string;
|
|
87
|
-
buyer: string;
|
|
88
|
-
payTo: string;
|
|
89
|
-
amountAtomic: string;
|
|
90
|
-
asset: string;
|
|
91
|
-
decimals: number;
|
|
92
|
-
nonce: string;
|
|
93
|
-
route: string;
|
|
94
|
-
facilitatorType: "hosted" | "self-hosted";
|
|
95
|
-
facilitatorUrl?: string;
|
|
96
|
-
facilitatorAddress?: string;
|
|
97
|
-
txHash?: string;
|
|
98
|
-
priceUsd?: string;
|
|
99
|
-
}
|
|
100
|
-
/** Config for createPaymentMiddleware. */
|
|
101
|
-
interface PaymentMiddlewareConfig {
|
|
102
|
-
/** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
|
|
103
|
-
facilitatorUrl: string;
|
|
104
|
-
/** Recipient address (developer). */
|
|
105
|
-
receiverAddress: string;
|
|
106
|
-
/** Map of protected routes and their pricing. */
|
|
107
|
-
routes: RoutesConfig;
|
|
108
|
-
/**
|
|
109
|
-
* Optional hook called whenever a payment is successfully settled.
|
|
110
|
-
* You can use this to push logs into your DB / analytics pipeline.
|
|
111
|
-
*/
|
|
112
|
-
onPaymentSettled?: (entry: PaymentLogEntry) => void;
|
|
113
|
-
/** Optional: Send usage telemetry for billing/analytics. */
|
|
114
|
-
telemetry?: TelemetryConfig;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
declare function createPaymentMiddleware(config: PaymentMiddlewareConfig): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
118
|
-
|
|
119
|
-
/** Config for the client-side payment helper. */
|
|
120
|
-
interface PaymentClientConfig {
|
|
121
|
-
/** Base URL of your protected resource server. */
|
|
122
|
-
resourceUrl: string;
|
|
123
|
-
/** Facilitator URL (hosted or self-hosted). */
|
|
124
|
-
facilitatorUrl: string;
|
|
125
|
-
/** EIP-1193 provider (window.ethereum) or similar. */
|
|
126
|
-
provider: unknown;
|
|
127
|
-
/** Optional user address override; otherwise derived from provider. */
|
|
128
|
-
userAddress?: string;
|
|
129
|
-
/** Optional: Project key for hosted facilitator billing. */
|
|
130
|
-
projectKey?: string;
|
|
131
|
-
}
|
|
132
|
-
/** Result of a callWithPayment() client operation. */
|
|
133
|
-
interface CallWithPaymentResult<TResponseBody = unknown> {
|
|
134
|
-
response: TResponseBody;
|
|
135
|
-
txHash?: string;
|
|
136
|
-
paymentHeader: PaymentHeaderBase64;
|
|
137
|
-
paymentRequirements: PaymentRequirements;
|
|
138
|
-
}
|
|
139
|
-
/** Shape of the client instance returned by createPaymentClient. */
|
|
140
|
-
interface PaymentClient {
|
|
141
|
-
callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
|
|
142
|
-
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
143
|
-
body?: TBody;
|
|
144
|
-
headers?: Record<string, string>;
|
|
145
|
-
/**
|
|
146
|
-
* Optional override if you want to send less than maxAmountRequired.
|
|
147
|
-
* In most cases you won't need this and will just pay maxAmountRequired.
|
|
148
|
-
*/
|
|
149
|
-
valueOverrideAtomic?: string;
|
|
150
|
-
}): Promise<CallWithPaymentResult<TResp>>;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Creates a high-level payment client that:
|
|
155
|
-
* - makes an initial request
|
|
156
|
-
* - if it receives 402 + paymentRequirements, builds & signs an authorization
|
|
157
|
-
* - calls facilitator /settle
|
|
158
|
-
* - retries the original request with X-PAYMENT header
|
|
159
|
-
*
|
|
160
|
-
* This logic is x402 and tailored for Mantle + USDC.
|
|
161
|
-
*/
|
|
162
|
-
declare function createPaymentClient(config: PaymentClientConfig): PaymentClient;
|
|
163
|
-
|
|
164
|
-
export { type AssetConfig, type Authorization, type CallWithPaymentResult, 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, createPaymentClient, createPaymentMiddleware };
|
|
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';
|