@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/client.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { P as PaymentClientConfig, b as PaymentClient } from './createMantleClient-DVFkbBfS.js';
|
|
2
|
+
export { C as CallWithPaymentResult, M as MantleClient, a as MantleClientConfig, c as createMantleClient } from './createMantleClient-DVFkbBfS.js';
|
|
3
|
+
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.js';
|
|
4
|
+
export { M as MANTLE_DEFAULTS } from './constants-CVFF0ray.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a high-level payment client that:
|
|
8
|
+
* - makes an initial request
|
|
9
|
+
* - if it receives 402 + paymentRequirements, builds & signs an authorization
|
|
10
|
+
* - calls facilitator /settle
|
|
11
|
+
* - retries the original request with X-PAYMENT header
|
|
12
|
+
*
|
|
13
|
+
* This logic is x402 and tailored for Mantle + USDC.
|
|
14
|
+
*/
|
|
15
|
+
declare function createPaymentClient(config: PaymentClientConfig): PaymentClient;
|
|
16
|
+
|
|
17
|
+
export { PaymentClient, PaymentClientConfig, createPaymentClient };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
/**
|
|
64
|
+
* Default values for Mantle mainnet x402 payments.
|
|
65
|
+
* These are used by the simplified API (mantlePaywall, createMantleClient).
|
|
66
|
+
*/
|
|
67
|
+
declare const MANTLE_DEFAULTS: {
|
|
68
|
+
readonly NETWORK: "mantle-mainnet";
|
|
69
|
+
readonly CHAIN_ID: 5000;
|
|
70
|
+
readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
|
|
71
|
+
readonly USDC_DECIMALS: 6;
|
|
72
|
+
readonly CURRENCY: "USD";
|
|
73
|
+
readonly SCHEME: "exact";
|
|
74
|
+
readonly FACILITATOR_URL: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { type AssetConfig as A, type EIP1193Provider as E, MANTLE_DEFAULTS as M, type NetworkId as N, type PaymentRequirements as P, type Authorization as a, type PaymentHeaderPayload as b, type PaymentHeaderObject as c, type PaymentHeaderBase64 as d };
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
/**
|
|
64
|
+
* Default values for Mantle mainnet x402 payments.
|
|
65
|
+
* These are used by the simplified API (mantlePaywall, createMantleClient).
|
|
66
|
+
*/
|
|
67
|
+
declare const MANTLE_DEFAULTS: {
|
|
68
|
+
readonly NETWORK: "mantle-mainnet";
|
|
69
|
+
readonly CHAIN_ID: 5000;
|
|
70
|
+
readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
|
|
71
|
+
readonly USDC_DECIMALS: 6;
|
|
72
|
+
readonly CURRENCY: "USD";
|
|
73
|
+
readonly SCHEME: "exact";
|
|
74
|
+
readonly FACILITATOR_URL: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { type AssetConfig as A, type EIP1193Provider as E, MANTLE_DEFAULTS as M, type NetworkId as N, type PaymentRequirements as P, type Authorization as a, type PaymentHeaderPayload as b, type PaymentHeaderObject as c, type PaymentHeaderBase64 as d };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './types-2zqbJvcz.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default values for Mantle mainnet x402 payments.
|
|
5
|
+
* These are used by the simplified API (mantlePaywall, createMantleClient).
|
|
6
|
+
*/
|
|
7
|
+
declare const MANTLE_DEFAULTS: {
|
|
8
|
+
readonly NETWORK: "mantle-mainnet";
|
|
9
|
+
readonly CHAIN_ID: 5000;
|
|
10
|
+
readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
|
|
11
|
+
readonly USDC_DECIMALS: 6;
|
|
12
|
+
readonly CURRENCY: "USD";
|
|
13
|
+
readonly SCHEME: "exact";
|
|
14
|
+
readonly FACILITATOR_URL: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { MANTLE_DEFAULTS as M };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './types-2zqbJvcz.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Default values for Mantle mainnet x402 payments.
|
|
5
|
+
* These are used by the simplified API (mantlePaywall, createMantleClient).
|
|
6
|
+
*/
|
|
7
|
+
declare const MANTLE_DEFAULTS: {
|
|
8
|
+
readonly NETWORK: "mantle-mainnet";
|
|
9
|
+
readonly CHAIN_ID: 5000;
|
|
10
|
+
readonly USDC_ADDRESS: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9";
|
|
11
|
+
readonly USDC_DECIMALS: 6;
|
|
12
|
+
readonly CURRENCY: "USD";
|
|
13
|
+
readonly SCHEME: "exact";
|
|
14
|
+
readonly FACILITATOR_URL: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { MANTLE_DEFAULTS as M };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for createMantleClient().
|
|
3
|
+
* All fields are optional - the client auto-detects sensible defaults.
|
|
4
|
+
*/
|
|
5
|
+
interface MantleClientConfig {
|
|
6
|
+
/** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
|
|
7
|
+
facilitatorUrl?: string;
|
|
8
|
+
/** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
|
|
9
|
+
resourceUrl?: string;
|
|
10
|
+
/** Function to get user's wallet address (required for payments). */
|
|
11
|
+
getAccount?: () => Promise<string | undefined> | string | undefined;
|
|
12
|
+
/** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
|
|
13
|
+
getProvider?: () => any;
|
|
14
|
+
/** Optional project key for hosted facilitator billing. */
|
|
15
|
+
projectKey?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simplified Mantle payment client interface.
|
|
19
|
+
* Provides a clean API for making paid POST requests.
|
|
20
|
+
*/
|
|
21
|
+
interface MantleClient {
|
|
22
|
+
/**
|
|
23
|
+
* Make a paid POST request to a protected endpoint.
|
|
24
|
+
* Automatically handles x402 flow (402 response, signing, payment, retry).
|
|
25
|
+
*
|
|
26
|
+
* @param url - API endpoint path (e.g., "/api/generate-image").
|
|
27
|
+
* @param body - Request body (will be JSON stringified).
|
|
28
|
+
* @returns Response data from the protected endpoint.
|
|
29
|
+
* @throws Error if wallet is not connected or payment fails.
|
|
30
|
+
*/
|
|
31
|
+
postWithPayment<TResp = any>(url: string, body?: any): Promise<TResp>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a simplified Mantle payment client with auto-detected defaults.
|
|
35
|
+
*
|
|
36
|
+
* Usage:
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = createMantleClient({
|
|
39
|
+
* getAccount: () => account?.address,
|
|
40
|
+
* getProvider: () => walletClient,
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const data = await client.postWithPayment("/api/generate", { prompt: "..." });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
|
|
47
|
+
* @returns MantleClient instance with simplified postWithPayment() method.
|
|
48
|
+
*/
|
|
49
|
+
declare function createMantleClient(config?: MantleClientConfig): MantleClient;
|
|
50
|
+
|
|
51
|
+
export { type MantleClient as M, type MantleClientConfig as a, createMantleClient as c };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for createMantleClient().
|
|
3
|
+
* All fields are optional - the client auto-detects sensible defaults.
|
|
4
|
+
*/
|
|
5
|
+
interface MantleClientConfig {
|
|
6
|
+
/** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
|
|
7
|
+
facilitatorUrl?: string;
|
|
8
|
+
/** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
|
|
9
|
+
resourceUrl?: string;
|
|
10
|
+
/** Function to get user's wallet address (required for payments). */
|
|
11
|
+
getAccount?: () => Promise<string | undefined> | string | undefined;
|
|
12
|
+
/** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
|
|
13
|
+
getProvider?: () => any;
|
|
14
|
+
/** Optional project key for hosted facilitator billing. */
|
|
15
|
+
projectKey?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Simplified Mantle payment client interface.
|
|
19
|
+
* Provides a clean API for making paid POST requests.
|
|
20
|
+
*/
|
|
21
|
+
interface MantleClient {
|
|
22
|
+
/**
|
|
23
|
+
* Make a paid POST request to a protected endpoint.
|
|
24
|
+
* Automatically handles x402 flow (402 response, signing, payment, retry).
|
|
25
|
+
*
|
|
26
|
+
* @param url - API endpoint path (e.g., "/api/generate-image").
|
|
27
|
+
* @param body - Request body (will be JSON stringified).
|
|
28
|
+
* @returns Response data from the protected endpoint.
|
|
29
|
+
* @throws Error if wallet is not connected or payment fails.
|
|
30
|
+
*/
|
|
31
|
+
postWithPayment<TResp = any>(url: string, body?: any): Promise<TResp>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a simplified Mantle payment client with auto-detected defaults.
|
|
35
|
+
*
|
|
36
|
+
* Usage:
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const client = createMantleClient({
|
|
39
|
+
* getAccount: () => account?.address,
|
|
40
|
+
* getProvider: () => walletClient,
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const data = await client.postWithPayment("/api/generate", { prompt: "..." });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
|
|
47
|
+
* @returns MantleClient instance with simplified postWithPayment() method.
|
|
48
|
+
*/
|
|
49
|
+
declare function createMantleClient(config?: MantleClientConfig): MantleClient;
|
|
50
|
+
|
|
51
|
+
export { type MantleClient as M, type MantleClientConfig as a, createMantleClient as c };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { d as PaymentHeaderBase64, P as PaymentRequirements } from './types-2zqbJvcz.js';
|
|
2
|
+
|
|
3
|
+
/** Config for the client-side payment helper. */
|
|
4
|
+
interface PaymentClientConfig {
|
|
5
|
+
/** Base URL of your protected resource server. */
|
|
6
|
+
resourceUrl: string;
|
|
7
|
+
/** Facilitator URL (hosted or self-hosted). */
|
|
8
|
+
facilitatorUrl: string;
|
|
9
|
+
/** EIP-1193 provider (window.ethereum) or similar. */
|
|
10
|
+
provider: unknown;
|
|
11
|
+
/** Optional user address override; otherwise derived from provider. */
|
|
12
|
+
userAddress?: string;
|
|
13
|
+
/** Optional: Project key for hosted facilitator billing. */
|
|
14
|
+
projectKey?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Result of a callWithPayment() client operation. */
|
|
17
|
+
interface CallWithPaymentResult<TResponseBody = unknown> {
|
|
18
|
+
response: TResponseBody;
|
|
19
|
+
txHash?: string;
|
|
20
|
+
paymentHeader?: PaymentHeaderBase64;
|
|
21
|
+
paymentRequirements?: PaymentRequirements;
|
|
22
|
+
}
|
|
23
|
+
/** Shape of the client instance returned by createPaymentClient. */
|
|
24
|
+
interface PaymentClient {
|
|
25
|
+
callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
|
|
26
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
27
|
+
body?: TBody;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Optional override if you want to send less than maxAmountRequired.
|
|
31
|
+
* In most cases you won't need this and will just pay maxAmountRequired.
|
|
32
|
+
*/
|
|
33
|
+
valueOverrideAtomic?: string;
|
|
34
|
+
}): Promise<CallWithPaymentResult<TResp>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for createMantleClient().
|
|
39
|
+
* All fields are optional - the client auto-detects sensible defaults.
|
|
40
|
+
*/
|
|
41
|
+
interface MantleClientConfig {
|
|
42
|
+
/** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
|
|
43
|
+
facilitatorUrl?: string;
|
|
44
|
+
/** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
|
|
45
|
+
resourceUrl?: string;
|
|
46
|
+
/** Function to get user's wallet address (required for payments). */
|
|
47
|
+
getAccount?: () => Promise<string | undefined> | string | undefined;
|
|
48
|
+
/** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
|
|
49
|
+
getProvider?: () => any;
|
|
50
|
+
/** Optional project key for hosted facilitator billing. */
|
|
51
|
+
projectKey?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Simplified Mantle payment client interface.
|
|
55
|
+
* Provides a clean API for making paid POST requests.
|
|
56
|
+
*/
|
|
57
|
+
interface MantleClient {
|
|
58
|
+
/**
|
|
59
|
+
* Make a paid POST request to a protected endpoint.
|
|
60
|
+
* Automatically handles x402 flow (402 response, signing, payment, retry).
|
|
61
|
+
*
|
|
62
|
+
* @param url - API endpoint path (e.g., "/api/generate-image").
|
|
63
|
+
* @param body - Request body (will be JSON stringified).
|
|
64
|
+
* @returns Full payment result including response body and tx hash.
|
|
65
|
+
* @throws Error if wallet is not connected or payment fails.
|
|
66
|
+
*/
|
|
67
|
+
postWithPayment<TResp = any>(url: string, body?: any): Promise<CallWithPaymentResult<TResp>>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a simplified Mantle payment client with auto-detected defaults.
|
|
71
|
+
*
|
|
72
|
+
* Usage:
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const client = createMantleClient({
|
|
75
|
+
* getAccount: () => account?.address,
|
|
76
|
+
* getProvider: () => walletClient,
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* const data = await client.postWithPayment("/api/generate", { prompt: "..." });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
|
|
83
|
+
* @returns MantleClient instance with simplified postWithPayment() method.
|
|
84
|
+
*/
|
|
85
|
+
declare function createMantleClient(config?: MantleClientConfig): MantleClient;
|
|
86
|
+
|
|
87
|
+
export { type CallWithPaymentResult as C, type MantleClient as M, type PaymentClientConfig as P, type MantleClientConfig as a, type PaymentClient as b, createMantleClient as c };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { d as PaymentHeaderBase64, P as PaymentRequirements } from './types-2zqbJvcz.cjs';
|
|
2
|
+
|
|
3
|
+
/** Config for the client-side payment helper. */
|
|
4
|
+
interface PaymentClientConfig {
|
|
5
|
+
/** Base URL of your protected resource server. */
|
|
6
|
+
resourceUrl: string;
|
|
7
|
+
/** Facilitator URL (hosted or self-hosted). */
|
|
8
|
+
facilitatorUrl: string;
|
|
9
|
+
/** EIP-1193 provider (window.ethereum) or similar. */
|
|
10
|
+
provider: unknown;
|
|
11
|
+
/** Optional user address override; otherwise derived from provider. */
|
|
12
|
+
userAddress?: string;
|
|
13
|
+
/** Optional: Project key for hosted facilitator billing. */
|
|
14
|
+
projectKey?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Result of a callWithPayment() client operation. */
|
|
17
|
+
interface CallWithPaymentResult<TResponseBody = unknown> {
|
|
18
|
+
response: TResponseBody;
|
|
19
|
+
txHash?: string;
|
|
20
|
+
paymentHeader?: PaymentHeaderBase64;
|
|
21
|
+
paymentRequirements?: PaymentRequirements;
|
|
22
|
+
}
|
|
23
|
+
/** Shape of the client instance returned by createPaymentClient. */
|
|
24
|
+
interface PaymentClient {
|
|
25
|
+
callWithPayment<TBody = unknown, TResp = unknown>(path: string, options?: {
|
|
26
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
27
|
+
body?: TBody;
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Optional override if you want to send less than maxAmountRequired.
|
|
31
|
+
* In most cases you won't need this and will just pay maxAmountRequired.
|
|
32
|
+
*/
|
|
33
|
+
valueOverrideAtomic?: string;
|
|
34
|
+
}): Promise<CallWithPaymentResult<TResp>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for createMantleClient().
|
|
39
|
+
* All fields are optional - the client auto-detects sensible defaults.
|
|
40
|
+
*/
|
|
41
|
+
interface MantleClientConfig {
|
|
42
|
+
/** Optional facilitator URL (auto-detects from NEXT_PUBLIC_FACILITATOR_URL or defaults to localhost:8080). */
|
|
43
|
+
facilitatorUrl?: string;
|
|
44
|
+
/** Optional resource URL (defaults to current origin in browser, or empty string for relative paths). */
|
|
45
|
+
resourceUrl?: string;
|
|
46
|
+
/** Function to get user's wallet address (required for payments). */
|
|
47
|
+
getAccount?: () => Promise<string | undefined> | string | undefined;
|
|
48
|
+
/** Function to get wallet provider/client (e.g., viem WalletClient or window.ethereum). */
|
|
49
|
+
getProvider?: () => any;
|
|
50
|
+
/** Optional project key for hosted facilitator billing. */
|
|
51
|
+
projectKey?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Simplified Mantle payment client interface.
|
|
55
|
+
* Provides a clean API for making paid POST requests.
|
|
56
|
+
*/
|
|
57
|
+
interface MantleClient {
|
|
58
|
+
/**
|
|
59
|
+
* Make a paid POST request to a protected endpoint.
|
|
60
|
+
* Automatically handles x402 flow (402 response, signing, payment, retry).
|
|
61
|
+
*
|
|
62
|
+
* @param url - API endpoint path (e.g., "/api/generate-image").
|
|
63
|
+
* @param body - Request body (will be JSON stringified).
|
|
64
|
+
* @returns Full payment result including response body and tx hash.
|
|
65
|
+
* @throws Error if wallet is not connected or payment fails.
|
|
66
|
+
*/
|
|
67
|
+
postWithPayment<TResp = any>(url: string, body?: any): Promise<CallWithPaymentResult<TResp>>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a simplified Mantle payment client with auto-detected defaults.
|
|
71
|
+
*
|
|
72
|
+
* Usage:
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const client = createMantleClient({
|
|
75
|
+
* getAccount: () => account?.address,
|
|
76
|
+
* getProvider: () => walletClient,
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* const data = await client.postWithPayment("/api/generate", { prompt: "..." });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param config - Optional configuration (auto-detects facilitatorUrl and resourceUrl).
|
|
83
|
+
* @returns MantleClient instance with simplified postWithPayment() method.
|
|
84
|
+
*/
|
|
85
|
+
declare function createMantleClient(config?: MantleClientConfig): MantleClient;
|
|
86
|
+
|
|
87
|
+
export { type CallWithPaymentResult as C, type MantleClient as M, type PaymentClientConfig as P, type MantleClientConfig as a, type PaymentClient as b, createMantleClient as c };
|