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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/chunk-23QNUJIB.js +136 -0
  2. package/dist/chunk-6GLR5EBK.js +96 -0
  3. package/dist/chunk-BRGW36P7.js +211 -0
  4. package/dist/chunk-CTI5CRDY.js +274 -0
  5. package/dist/chunk-DA6ZBXNO.js +275 -0
  6. package/dist/chunk-E46A7I6B.js +274 -0
  7. package/dist/chunk-FD4HG7KR.js +135 -0
  8. package/dist/chunk-FHU6CFHF.js +0 -0
  9. package/dist/chunk-GHUWTX7J.js +66 -0
  10. package/dist/chunk-GWVWPS3R.js +277 -0
  11. package/dist/chunk-HEZZ74SI.js +62 -0
  12. package/dist/chunk-HTZ3QFY4.js +135 -0
  13. package/dist/chunk-MQALBRGV.js +135 -0
  14. package/dist/chunk-NQWSCY44.js +70 -0
  15. package/dist/chunk-PCJEJYP6.js +68 -0
  16. package/dist/chunk-PPVS3X5Z.js +99 -0
  17. package/dist/chunk-PYIYE3HI.js +135 -0
  18. package/dist/chunk-Q6SPMEIW.js +235 -0
  19. package/dist/chunk-RNKXSBT7.js +135 -0
  20. package/dist/chunk-SPCXFN7C.js +284 -0
  21. package/dist/chunk-T5DRYLNB.js +135 -0
  22. package/dist/chunk-TSEE5NSJ.js +297 -0
  23. package/dist/chunk-U73CZU3X.js +237 -0
  24. package/dist/chunk-WAKJRVUP.js +135 -0
  25. package/dist/chunk-WELDWRDX.js +307 -0
  26. package/dist/chunk-WFUDGBKK.js +68 -0
  27. package/dist/chunk-WO2MYZXT.js +0 -0
  28. package/dist/chunk-XAQGMFSR.js +56 -0
  29. package/dist/client.cjs +328 -0
  30. package/dist/client.d.cts +17 -0
  31. package/dist/client.d.ts +17 -0
  32. package/dist/client.js +12 -0
  33. package/dist/constants-0ncqvV_O.d.ts +17 -0
  34. package/dist/constants-C7aY8u5b.d.cts +77 -0
  35. package/dist/constants-C7aY8u5b.d.ts +77 -0
  36. package/dist/constants-CVFF0ray.d.ts +17 -0
  37. package/dist/constants-CsIL25uQ.d.cts +17 -0
  38. package/dist/constants-DzCGK0Q3.d.cts +17 -0
  39. package/dist/createMantleClient-CO0uWPb-.d.cts +87 -0
  40. package/dist/createMantleClient-CuiPsTa6.d.ts +87 -0
  41. package/dist/createMantleClient-DS1Ghqrz.d.cts +51 -0
  42. package/dist/createMantleClient-DS1Ghqrz.d.ts +51 -0
  43. package/dist/createMantleClient-DVFkbBfS.d.ts +87 -0
  44. package/dist/createMantleClient-NN0Nitp9.d.cts +87 -0
  45. package/dist/express-Ck7eryef.d.cts +66 -0
  46. package/dist/express-CmEg5hR3.d.ts +66 -0
  47. package/dist/express-D8EwEcOL.d.ts +66 -0
  48. package/dist/express-eQOPxfnI.d.cts +66 -0
  49. package/dist/index.cjs +342 -155
  50. package/dist/index.d.cts +10 -290
  51. package/dist/index.d.ts +10 -290
  52. package/dist/index.js +18 -567
  53. package/dist/nextjs-Bp8DxYDN.d.ts +45 -0
  54. package/dist/nextjs-CliiaTPe.d.cts +45 -0
  55. package/dist/nextjs-D7t-BC4N.d.ts +45 -0
  56. package/dist/nextjs-Duecps0q.d.cts +45 -0
  57. package/dist/nextjs-TFhFiQuL.d.ts +45 -0
  58. package/dist/nextjs-ZO2J9mdo.d.cts +45 -0
  59. package/dist/react.cjs +454 -0
  60. package/dist/react.d.cts +93 -0
  61. package/dist/react.d.ts +93 -0
  62. package/dist/react.js +10 -0
  63. package/dist/server-express.cjs +368 -0
  64. package/dist/server-express.d.cts +5 -0
  65. package/dist/server-express.d.ts +5 -0
  66. package/dist/server-express.js +13 -0
  67. package/dist/server-nextjs.cjs +339 -0
  68. package/dist/server-nextjs.d.cts +5 -0
  69. package/dist/server-nextjs.d.ts +5 -0
  70. package/dist/server-nextjs.js +11 -0
  71. package/dist/server-web.cjs +339 -0
  72. package/dist/server-web.d.cts +4 -0
  73. package/dist/server-web.d.ts +4 -0
  74. package/dist/server-web.js +11 -0
  75. package/dist/server.cjs +497 -0
  76. package/dist/server.d.cts +79 -0
  77. package/dist/server.d.ts +79 -0
  78. package/dist/server.js +36 -0
  79. package/dist/types-2zqbJvcz.d.cts +63 -0
  80. package/dist/types-2zqbJvcz.d.ts +63 -0
  81. package/dist/types-BFUqKBBO.d.cts +63 -0
  82. package/dist/types-BFUqKBBO.d.ts +63 -0
  83. package/dist/types-C7EPJ6Hd.d.ts +85 -0
  84. package/dist/types-CEttmr1U.d.cts +97 -0
  85. package/dist/types-CoOdbZSp.d.cts +97 -0
  86. package/dist/types-CqQ6OgRi.d.ts +85 -0
  87. package/dist/types-CrOsOHcX.d.cts +85 -0
  88. package/dist/types-D20K36pc.d.ts +97 -0
  89. package/dist/types-DTzov_EE.d.ts +97 -0
  90. package/dist/types-xkNm0uzE.d.cts +85 -0
  91. package/dist/web-standards-BNQyWzBC.d.cts +77 -0
  92. package/dist/web-standards-C3D2vdTg.d.ts +77 -0
  93. package/dist/web-standards-D8j1kZxd.d.ts +77 -0
  94. package/dist/web-standards-DOYp0UDT.d.cts +77 -0
  95. package/package.json +80 -8
package/dist/server.js ADDED
@@ -0,0 +1,36 @@
1
+ import "./chunk-WO2MYZXT.js";
2
+ import {
3
+ createPaymentMiddleware,
4
+ express_exports,
5
+ mantlePaywall
6
+ } from "./chunk-PPVS3X5Z.js";
7
+ import {
8
+ nextjs_exports
9
+ } from "./chunk-PCJEJYP6.js";
10
+ import {
11
+ web_standards_exports
12
+ } from "./chunk-NQWSCY44.js";
13
+ import {
14
+ DEFAULT_TELEMETRY_ENDPOINT,
15
+ buildRouteKey,
16
+ checkPayment,
17
+ createTelemetryEvent,
18
+ decodePaymentHeader,
19
+ sendTelemetry,
20
+ validateAddress
21
+ } from "./chunk-U73CZU3X.js";
22
+ import "./chunk-HEZZ74SI.js";
23
+ export {
24
+ DEFAULT_TELEMETRY_ENDPOINT,
25
+ buildRouteKey,
26
+ checkPayment,
27
+ createPaymentMiddleware,
28
+ createTelemetryEvent,
29
+ decodePaymentHeader,
30
+ express_exports as express,
31
+ mantlePaywall,
32
+ nextjs_exports as nextjs,
33
+ sendTelemetry,
34
+ validateAddress,
35
+ web_standards_exports as web
36
+ };
@@ -0,0 +1,63 @@
1
+ /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
+ type NetworkId = "mantle-mainnet" | (string & {});
3
+ /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
+ interface AssetConfig {
5
+ symbol: string;
6
+ address: string;
7
+ decimals: number;
8
+ }
9
+ /** x402-style payment requirements (returned in 402 response). */
10
+ interface PaymentRequirements {
11
+ scheme: "exact";
12
+ network: NetworkId;
13
+ asset: string;
14
+ maxAmountRequired: string;
15
+ payTo: `0x${string}`;
16
+ price?: string;
17
+ currency?: string;
18
+ }
19
+ /** EIP-3009 TransferWithAuthorization payload. */
20
+ interface Authorization {
21
+ from: string;
22
+ to: string;
23
+ value: string;
24
+ validAfter: string;
25
+ validBefore: string;
26
+ nonce: string;
27
+ }
28
+ /** Inner payload of x402-style payment header. */
29
+ interface PaymentHeaderPayload {
30
+ signature: string;
31
+ authorization: Authorization;
32
+ }
33
+ /** Structured x402-style payment header (before base64 encoding). */
34
+ interface PaymentHeaderObject {
35
+ x402Version: number;
36
+ scheme: "exact";
37
+ network: NetworkId;
38
+ payload: PaymentHeaderPayload;
39
+ }
40
+ /** Base64-encoded payment header, sent in X-PAYMENT. */
41
+ type PaymentHeaderBase64 = string;
42
+ /**
43
+ * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
+ * Standard interface for Ethereum wallet providers.
45
+ */
46
+ interface EIP1193Provider {
47
+ request(args: {
48
+ method: string;
49
+ params?: unknown[];
50
+ }): Promise<unknown>;
51
+ on?(event: string, listener: (...args: unknown[]) => void): void;
52
+ removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
+ }
54
+ /**
55
+ * Window ethereum extension for TypeScript
56
+ */
57
+ declare global {
58
+ interface Window {
59
+ ethereum?: EIP1193Provider;
60
+ }
61
+ }
62
+
63
+ export type { AssetConfig as A, EIP1193Provider as E, NetworkId as N, PaymentRequirements as P, Authorization as a, PaymentHeaderPayload as b, PaymentHeaderObject as c, PaymentHeaderBase64 as d };
@@ -0,0 +1,63 @@
1
+ /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
+ type NetworkId = "mantle-mainnet" | (string & {});
3
+ /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
+ interface AssetConfig {
5
+ symbol: string;
6
+ address: string;
7
+ decimals: number;
8
+ }
9
+ /** x402-style payment requirements (returned in 402 response). */
10
+ interface PaymentRequirements {
11
+ scheme: "exact";
12
+ network: NetworkId;
13
+ asset: string;
14
+ maxAmountRequired: string;
15
+ payTo: `0x${string}`;
16
+ price?: string;
17
+ currency?: string;
18
+ }
19
+ /** EIP-3009 TransferWithAuthorization payload. */
20
+ interface Authorization {
21
+ from: string;
22
+ to: string;
23
+ value: string;
24
+ validAfter: string;
25
+ validBefore: string;
26
+ nonce: string;
27
+ }
28
+ /** Inner payload of x402-style payment header. */
29
+ interface PaymentHeaderPayload {
30
+ signature: string;
31
+ authorization: Authorization;
32
+ }
33
+ /** Structured x402-style payment header (before base64 encoding). */
34
+ interface PaymentHeaderObject {
35
+ x402Version: number;
36
+ scheme: "exact";
37
+ network: NetworkId;
38
+ payload: PaymentHeaderPayload;
39
+ }
40
+ /** Base64-encoded payment header, sent in X-PAYMENT. */
41
+ type PaymentHeaderBase64 = string;
42
+ /**
43
+ * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
+ * Standard interface for Ethereum wallet providers.
45
+ */
46
+ interface EIP1193Provider {
47
+ request(args: {
48
+ method: string;
49
+ params?: unknown[];
50
+ }): Promise<unknown>;
51
+ on?(event: string, listener: (...args: unknown[]) => void): void;
52
+ removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
+ }
54
+ /**
55
+ * Window ethereum extension for TypeScript
56
+ */
57
+ declare global {
58
+ interface Window {
59
+ ethereum?: EIP1193Provider;
60
+ }
61
+ }
62
+
63
+ export type { AssetConfig as A, EIP1193Provider as E, NetworkId as N, PaymentRequirements as P, Authorization as a, PaymentHeaderPayload as b, PaymentHeaderObject as c, PaymentHeaderBase64 as d };
@@ -0,0 +1,63 @@
1
+ /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
+ type NetworkId = "mantle-mainnet" | (string & {});
3
+ /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
+ interface AssetConfig {
5
+ symbol: string;
6
+ address: string;
7
+ decimals: number;
8
+ }
9
+ /** x402-style payment requirements (returned in 402 response). */
10
+ interface PaymentRequirements {
11
+ scheme: "exact";
12
+ network: NetworkId;
13
+ asset: string;
14
+ maxAmountRequired: string;
15
+ payTo: string;
16
+ price?: string;
17
+ currency?: string;
18
+ }
19
+ /** EIP-3009 TransferWithAuthorization payload. */
20
+ interface Authorization {
21
+ from: string;
22
+ to: string;
23
+ value: string;
24
+ validAfter: string;
25
+ validBefore: string;
26
+ nonce: string;
27
+ }
28
+ /** Inner payload of x402-style payment header. */
29
+ interface PaymentHeaderPayload {
30
+ signature: string;
31
+ authorization: Authorization;
32
+ }
33
+ /** Structured x402-style payment header (before base64 encoding). */
34
+ interface PaymentHeaderObject {
35
+ x402Version: number;
36
+ scheme: "exact";
37
+ network: NetworkId;
38
+ payload: PaymentHeaderPayload;
39
+ }
40
+ /** Base64-encoded payment header, sent in X-PAYMENT. */
41
+ type PaymentHeaderBase64 = string;
42
+ /**
43
+ * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
+ * Standard interface for Ethereum wallet providers.
45
+ */
46
+ interface EIP1193Provider {
47
+ request(args: {
48
+ method: string;
49
+ params?: unknown[];
50
+ }): Promise<unknown>;
51
+ on?(event: string, listener: (...args: unknown[]) => void): void;
52
+ removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
+ }
54
+ /**
55
+ * Window ethereum extension for TypeScript
56
+ */
57
+ declare global {
58
+ interface Window {
59
+ ethereum?: EIP1193Provider;
60
+ }
61
+ }
62
+
63
+ export type { AssetConfig as A, EIP1193Provider as E, NetworkId as N, PaymentRequirements as P, Authorization as a, PaymentHeaderPayload as b, PaymentHeaderObject as c, PaymentHeaderBase64 as d };
@@ -0,0 +1,63 @@
1
+ /** Network identifier used in x402 paymentRequirements / paymentHeader. */
2
+ type NetworkId = "mantle-mainnet" | (string & {});
3
+ /** Basic ERC-20 asset config (e.g. USDC on Mantle). */
4
+ interface AssetConfig {
5
+ symbol: string;
6
+ address: string;
7
+ decimals: number;
8
+ }
9
+ /** x402-style payment requirements (returned in 402 response). */
10
+ interface PaymentRequirements {
11
+ scheme: "exact";
12
+ network: NetworkId;
13
+ asset: string;
14
+ maxAmountRequired: string;
15
+ payTo: string;
16
+ price?: string;
17
+ currency?: string;
18
+ }
19
+ /** EIP-3009 TransferWithAuthorization payload. */
20
+ interface Authorization {
21
+ from: string;
22
+ to: string;
23
+ value: string;
24
+ validAfter: string;
25
+ validBefore: string;
26
+ nonce: string;
27
+ }
28
+ /** Inner payload of x402-style payment header. */
29
+ interface PaymentHeaderPayload {
30
+ signature: string;
31
+ authorization: Authorization;
32
+ }
33
+ /** Structured x402-style payment header (before base64 encoding). */
34
+ interface PaymentHeaderObject {
35
+ x402Version: number;
36
+ scheme: "exact";
37
+ network: NetworkId;
38
+ payload: PaymentHeaderPayload;
39
+ }
40
+ /** Base64-encoded payment header, sent in X-PAYMENT. */
41
+ type PaymentHeaderBase64 = string;
42
+ /**
43
+ * EIP-1193 provider interface (window.ethereum, MetaMask, etc.)
44
+ * Standard interface for Ethereum wallet providers.
45
+ */
46
+ interface EIP1193Provider {
47
+ request(args: {
48
+ method: string;
49
+ params?: unknown[];
50
+ }): Promise<unknown>;
51
+ on?(event: string, listener: (...args: unknown[]) => void): void;
52
+ removeListener?(event: string, listener: (...args: unknown[]) => void): void;
53
+ }
54
+ /**
55
+ * Window ethereum extension for TypeScript
56
+ */
57
+ declare global {
58
+ interface Window {
59
+ ethereum?: EIP1193Provider;
60
+ }
61
+ }
62
+
63
+ export type { AssetConfig as A, EIP1193Provider as E, NetworkId as N, PaymentRequirements as P, Authorization as a, PaymentHeaderPayload as b, PaymentHeaderObject as c, PaymentHeaderBase64 as d };
@@ -0,0 +1,85 @@
1
+ import { N as NetworkId, P as PaymentRequirements } from './types-2zqbJvcz.js';
2
+
3
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
4
+ type RouteKey = string;
5
+ /** Pricing config for a single route. */
6
+ interface RoutePricingConfig {
7
+ /** Price in USD cents, e.g. 1 => $0.01. */
8
+ priceUsdCents: number;
9
+ /** Network identifier (e.g. "mantle-mainnet"). */
10
+ network: NetworkId;
11
+ }
12
+ /** Map of route keys to pricing config. */
13
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
14
+ /** Log entry for a successfully settled payment. */
15
+ interface PaymentLogEntry {
16
+ id: string;
17
+ from: string;
18
+ to: string;
19
+ valueAtomic: string;
20
+ network: NetworkId;
21
+ asset: string;
22
+ route?: RouteKey;
23
+ txHash?: string;
24
+ timestamp: number;
25
+ facilitatorUrl?: string;
26
+ paymentRequirements?: PaymentRequirements;
27
+ }
28
+ /** Config for optional telemetry (billing/analytics). */
29
+ interface TelemetryConfig {
30
+ /** Project key from nosubs.ai dashboard. */
31
+ projectKey: string;
32
+ /**
33
+ * Telemetry endpoint URL.
34
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
35
+ */
36
+ endpoint?: string;
37
+ }
38
+ /**
39
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
40
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
41
+ */
42
+ interface MinimalPaywallOptions {
43
+ /** Price in USD (e.g. 0.01 for 1 cent). */
44
+ priceUsd: number;
45
+ /** Recipient address (developer wallet). */
46
+ payTo: `0x${string}`;
47
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
48
+ facilitatorUrl?: string;
49
+ /** Optional telemetry config. */
50
+ telemetry?: TelemetryConfig;
51
+ /** Optional payment settled hook. */
52
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
53
+ }
54
+ /** Input for checkPayment function. */
55
+ interface PaymentCheckInput {
56
+ /** X-PAYMENT header value (base64 encoded), or null if not present. */
57
+ paymentHeader: string | null;
58
+ /** Payment requirements for this route. */
59
+ paymentRequirements: PaymentRequirements;
60
+ /** Facilitator URL for verification. */
61
+ facilitatorUrl: string;
62
+ /** Route key for logging, e.g. "POST /api/generate-image". */
63
+ routeKey?: RouteKey;
64
+ /** Network ID for this payment. */
65
+ network: NetworkId;
66
+ /** Asset address (ERC-20 token). */
67
+ asset: string;
68
+ /** Telemetry config (optional). */
69
+ telemetry?: TelemetryConfig;
70
+ /** Payment settled callback (optional). */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ }
73
+ /** Result from checkPayment function. */
74
+ interface PaymentCheckResult {
75
+ /** Status of the payment check. */
76
+ status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
77
+ /** HTTP status code to return. */
78
+ statusCode: 402 | 500 | 200;
79
+ /** Response body to return (null if verified). */
80
+ responseBody: any | null;
81
+ /** Whether payment is valid (only true if status is "verified"). */
82
+ isValid: boolean;
83
+ }
84
+
85
+ export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };
@@ -0,0 +1,97 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { N as NetworkId, P as PaymentRequirements } from './types-2zqbJvcz.cjs';
3
+
4
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
5
+ type RouteKey = string;
6
+ /** Pricing config for a single route. */
7
+ interface RoutePricingConfig {
8
+ /** Price in USD cents, e.g. 1 => $0.01. */
9
+ priceUsdCents: number;
10
+ /** Network identifier (e.g. "mantle-mainnet"). */
11
+ network: NetworkId;
12
+ }
13
+ /** Map of route keys to pricing config. */
14
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
15
+ /** Log entry for a successfully settled payment. */
16
+ interface PaymentLogEntry {
17
+ id: string;
18
+ from: string;
19
+ to: string;
20
+ valueAtomic: string;
21
+ network: NetworkId;
22
+ asset: string;
23
+ route?: RouteKey;
24
+ txHash?: string;
25
+ timestamp: number;
26
+ facilitatorUrl?: string;
27
+ paymentRequirements?: PaymentRequirements;
28
+ }
29
+ /** Config for optional telemetry (billing/analytics). */
30
+ interface TelemetryConfig {
31
+ /** Project key from nosubs.ai dashboard. */
32
+ projectKey: string;
33
+ /**
34
+ * Telemetry endpoint URL.
35
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
36
+ * If both are undefined, telemetry is not sent.
37
+ */
38
+ endpoint?: string;
39
+ }
40
+ /** Telemetry event payload for payment_verified. */
41
+ interface TelemetryEvent {
42
+ event: "payment_verified";
43
+ ts: number;
44
+ projectKey: string;
45
+ network: string;
46
+ buyer: string;
47
+ payTo: string;
48
+ amountAtomic: string;
49
+ asset: string;
50
+ decimals: number;
51
+ nonce: string;
52
+ route: string;
53
+ facilitatorType: "hosted" | "self-hosted";
54
+ facilitatorUrl?: string;
55
+ facilitatorAddress?: string;
56
+ txHash?: string;
57
+ priceUsd?: string;
58
+ }
59
+ /** Config for createPaymentMiddleware. */
60
+ interface PaymentMiddlewareConfig {
61
+ /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
62
+ facilitatorUrl: string;
63
+ /** Recipient address (developer). */
64
+ receiverAddress: `0x${string}`;
65
+ /** Map of protected routes and their pricing. */
66
+ routes: RoutesConfig;
67
+ /**
68
+ * Optional hook called whenever a payment is successfully settled.
69
+ * You can use this to push logs into your DB / analytics pipeline.
70
+ */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ /** Optional: Send usage telemetry for billing/analytics. */
73
+ telemetry?: TelemetryConfig;
74
+ }
75
+ /**
76
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
77
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
78
+ */
79
+ interface MinimalPaywallOptions {
80
+ /** Price in USD (e.g. 0.01 for 1 cent). */
81
+ priceUsd: number;
82
+ /** Recipient address (developer wallet). */
83
+ payTo: `0x${string}`;
84
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
85
+ facilitatorUrl?: string;
86
+ /** Optional telemetry config. */
87
+ telemetry?: TelemetryConfig;
88
+ /** Optional payment settled hook. */
89
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
90
+ }
91
+ /**
92
+ * Express middleware function type for Mantle paywall.
93
+ * Async function that returns Promise<void>.
94
+ */
95
+ type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
96
+
97
+ export type { MantleMiddleware as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, TelemetryEvent as c, PaymentMiddlewareConfig as d, MinimalPaywallOptions as e };
@@ -0,0 +1,97 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.cjs';
3
+
4
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
5
+ type RouteKey = string;
6
+ /** Pricing config for a single route. */
7
+ interface RoutePricingConfig {
8
+ /** Price in USD cents, e.g. 1 => $0.01. */
9
+ priceUsdCents: number;
10
+ /** Network identifier (e.g. "mantle-mainnet"). */
11
+ network: NetworkId;
12
+ }
13
+ /** Map of route keys to pricing config. */
14
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
15
+ /** Log entry for a successfully settled payment. */
16
+ interface PaymentLogEntry {
17
+ id: string;
18
+ from: string;
19
+ to: string;
20
+ valueAtomic: string;
21
+ network: NetworkId;
22
+ asset: string;
23
+ route?: RouteKey;
24
+ txHash?: string;
25
+ timestamp: number;
26
+ facilitatorUrl?: string;
27
+ paymentRequirements?: PaymentRequirements;
28
+ }
29
+ /** Config for optional telemetry (billing/analytics). */
30
+ interface TelemetryConfig {
31
+ /** Project key from nosubs.ai dashboard. */
32
+ projectKey: string;
33
+ /**
34
+ * Telemetry endpoint URL.
35
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
36
+ * If both are undefined, telemetry is not sent.
37
+ */
38
+ endpoint?: string;
39
+ }
40
+ /** Telemetry event payload for payment_verified. */
41
+ interface TelemetryEvent {
42
+ event: "payment_verified";
43
+ ts: number;
44
+ projectKey: string;
45
+ network: string;
46
+ buyer: string;
47
+ payTo: string;
48
+ amountAtomic: string;
49
+ asset: string;
50
+ decimals: number;
51
+ nonce: string;
52
+ route: string;
53
+ facilitatorType: "hosted" | "self-hosted";
54
+ facilitatorUrl?: string;
55
+ facilitatorAddress?: string;
56
+ txHash?: string;
57
+ priceUsd?: string;
58
+ }
59
+ /** Config for createPaymentMiddleware. */
60
+ interface PaymentMiddlewareConfig {
61
+ /** Base URL of facilitator, e.g. https://facilitator.nosubs.ai */
62
+ facilitatorUrl: string;
63
+ /** Recipient address (developer). Validated at runtime. */
64
+ receiverAddress: string;
65
+ /** Map of protected routes and their pricing. */
66
+ routes: RoutesConfig;
67
+ /**
68
+ * Optional hook called whenever a payment is successfully settled.
69
+ * You can use this to push logs into your DB / analytics pipeline.
70
+ */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ /** Optional: Send usage telemetry for billing/analytics. */
73
+ telemetry?: TelemetryConfig;
74
+ }
75
+ /**
76
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
77
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
78
+ */
79
+ interface MinimalPaywallOptions {
80
+ /** Price in USD (e.g. 0.01 for 1 cent). */
81
+ priceUsd: number;
82
+ /** Recipient address (developer wallet). Validated at runtime. */
83
+ payTo: string;
84
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
85
+ facilitatorUrl?: string;
86
+ /** Optional telemetry config. */
87
+ telemetry?: TelemetryConfig;
88
+ /** Optional payment settled hook. */
89
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
90
+ }
91
+ /**
92
+ * Express middleware function type for Mantle paywall.
93
+ * Async function that returns Promise<void>.
94
+ */
95
+ type MantleMiddleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
96
+
97
+ export type { MantleMiddleware as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, TelemetryEvent as c, PaymentMiddlewareConfig as d, MinimalPaywallOptions as e };
@@ -0,0 +1,85 @@
1
+ import { N as NetworkId, P as PaymentRequirements } from './types-BFUqKBBO.js';
2
+
3
+ /** Unique key for a protected route, e.g. "GET /api/protected". */
4
+ type RouteKey = string;
5
+ /** Pricing config for a single route. */
6
+ interface RoutePricingConfig {
7
+ /** Price in USD cents, e.g. 1 => $0.01. */
8
+ priceUsdCents: number;
9
+ /** Network identifier (e.g. "mantle-mainnet"). */
10
+ network: NetworkId;
11
+ }
12
+ /** Map of route keys to pricing config. */
13
+ type RoutesConfig = Record<RouteKey, RoutePricingConfig>;
14
+ /** Log entry for a successfully settled payment. */
15
+ interface PaymentLogEntry {
16
+ id: string;
17
+ from: string;
18
+ to: string;
19
+ valueAtomic: string;
20
+ network: NetworkId;
21
+ asset: string;
22
+ route?: RouteKey;
23
+ txHash?: string;
24
+ timestamp: number;
25
+ facilitatorUrl?: string;
26
+ paymentRequirements?: PaymentRequirements;
27
+ }
28
+ /** Config for optional telemetry (billing/analytics). */
29
+ interface TelemetryConfig {
30
+ /** Project key from nosubs.ai dashboard. */
31
+ projectKey: string;
32
+ /**
33
+ * Telemetry endpoint URL.
34
+ * If not specified, uses DEFAULT_TELEMETRY_ENDPOINT (see server/constants.ts).
35
+ */
36
+ endpoint?: string;
37
+ }
38
+ /**
39
+ * Minimal config for mantlePaywall() - simplified API for single-route protection.
40
+ * This is the "sweet path" for Mantle mainnet + USDC with sensible defaults.
41
+ */
42
+ interface MinimalPaywallOptions {
43
+ /** Price in USD (e.g. 0.01 for 1 cent). */
44
+ priceUsd: number;
45
+ /** Recipient address (developer wallet). Validated at runtime. */
46
+ payTo: string;
47
+ /** Optional facilitator URL (defaults to localhost:8080 or NEXT_PUBLIC_FACILITATOR_URL). */
48
+ facilitatorUrl?: string;
49
+ /** Optional telemetry config. */
50
+ telemetry?: TelemetryConfig;
51
+ /** Optional payment settled hook. */
52
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
53
+ }
54
+ /** Input for checkPayment function. */
55
+ interface PaymentCheckInput {
56
+ /** X-PAYMENT header value (base64 encoded), or null if not present. */
57
+ paymentHeader: string | null;
58
+ /** Payment requirements for this route. */
59
+ paymentRequirements: PaymentRequirements;
60
+ /** Facilitator URL for verification. */
61
+ facilitatorUrl: string;
62
+ /** Route key for logging, e.g. "POST /api/generate-image". */
63
+ routeKey?: RouteKey;
64
+ /** Network ID for this payment. */
65
+ network: NetworkId;
66
+ /** Asset address (ERC-20 token). */
67
+ asset: string;
68
+ /** Telemetry config (optional). */
69
+ telemetry?: TelemetryConfig;
70
+ /** Payment settled callback (optional). */
71
+ onPaymentSettled?: (entry: PaymentLogEntry) => void;
72
+ }
73
+ /** Result from checkPayment function. */
74
+ interface PaymentCheckResult {
75
+ /** Status of the payment check. */
76
+ status: "require_payment" | "verification_error" | "invalid_payment" | "verified";
77
+ /** HTTP status code to return. */
78
+ statusCode: 402 | 500 | 200;
79
+ /** Response body to return (null if verified). */
80
+ responseBody: any | null;
81
+ /** Whether payment is valid (only true if status is "verified"). */
82
+ isValid: boolean;
83
+ }
84
+
85
+ export type { MinimalPaywallOptions as M, PaymentLogEntry as P, RouteKey as R, TelemetryConfig as T, RoutePricingConfig as a, RoutesConfig as b, PaymentCheckInput as c, PaymentCheckResult as d };