x402-express-mantle 1.0.0
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/README.md +155 -0
- package/lib/cjs/client/index.d.ts +243 -0
- package/lib/cjs/client/index.js +413 -0
- package/lib/cjs/client/index.js.map +1 -0
- package/lib/cjs/exact/client/index.d.ts +37 -0
- package/lib/cjs/exact/client/index.js +281 -0
- package/lib/cjs/exact/client/index.js.map +1 -0
- package/lib/cjs/exact/facilitator/index.d.ts +110 -0
- package/lib/cjs/exact/facilitator/index.js +714 -0
- package/lib/cjs/exact/facilitator/index.js.map +1 -0
- package/lib/cjs/exact/server/index.d.ts +87 -0
- package/lib/cjs/exact/server/index.js +209 -0
- package/lib/cjs/exact/server/index.js.map +1 -0
- package/lib/cjs/exact/v1/client/index.d.ts +33 -0
- package/lib/cjs/exact/v1/client/index.js +169 -0
- package/lib/cjs/exact/v1/client/index.js.map +1 -0
- package/lib/cjs/exact/v1/facilitator/index.d.ts +71 -0
- package/lib/cjs/exact/v1/facilitator/index.js +384 -0
- package/lib/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/lib/cjs/facilitator/index.d.ts +192 -0
- package/lib/cjs/facilitator/index.js +398 -0
- package/lib/cjs/facilitator/index.js.map +1 -0
- package/lib/cjs/http/index.d.ts +52 -0
- package/lib/cjs/http/index.js +827 -0
- package/lib/cjs/http/index.js.map +1 -0
- package/lib/cjs/index.d.ts +145 -0
- package/lib/cjs/index.js +314 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/mechanisms-CzuGzYsS.d.ts +270 -0
- package/lib/cjs/scheme-MoBRXFM8.d.ts +29 -0
- package/lib/cjs/server/index.d.ts +2 -0
- package/lib/cjs/server/index.js +1305 -0
- package/lib/cjs/server/index.js.map +1 -0
- package/lib/cjs/signer-5OVDxViv.d.ts +79 -0
- package/lib/cjs/signer-BMkbhFYE.d.ts +123 -0
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +66 -0
- package/lib/cjs/types/index.js.map +1 -0
- package/lib/cjs/types/v1/index.d.ts +1 -0
- package/lib/cjs/types/v1/index.js +19 -0
- package/lib/cjs/types/v1/index.js.map +1 -0
- package/lib/cjs/utils/index.d.ts +48 -0
- package/lib/cjs/utils/index.js +116 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/cjs/v1/index.d.ts +12 -0
- package/lib/cjs/v1/index.js +180 -0
- package/lib/cjs/v1/index.js.map +1 -0
- package/lib/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +719 -0
- package/lib/esm/chunk-3CEIVWNN.mjs +339 -0
- package/lib/esm/chunk-3CEIVWNN.mjs.map +1 -0
- package/lib/esm/chunk-BJTO5JO5.mjs +11 -0
- package/lib/esm/chunk-BJTO5JO5.mjs.map +1 -0
- package/lib/esm/chunk-EEA7DKZI.mjs +111 -0
- package/lib/esm/chunk-EEA7DKZI.mjs.map +1 -0
- package/lib/esm/chunk-FOUXRQAV.mjs +88 -0
- package/lib/esm/chunk-FOUXRQAV.mjs.map +1 -0
- package/lib/esm/chunk-IKSTWKEM.mjs +157 -0
- package/lib/esm/chunk-IKSTWKEM.mjs.map +1 -0
- package/lib/esm/chunk-JYZWCLMP.mjs +305 -0
- package/lib/esm/chunk-JYZWCLMP.mjs.map +1 -0
- package/lib/esm/chunk-PNSAJQCF.mjs +108 -0
- package/lib/esm/chunk-PNSAJQCF.mjs.map +1 -0
- package/lib/esm/chunk-PSA4YVU2.mjs +92 -0
- package/lib/esm/chunk-PSA4YVU2.mjs.map +1 -0
- package/lib/esm/chunk-QLXM7BIB.mjs +23 -0
- package/lib/esm/chunk-QLXM7BIB.mjs.map +1 -0
- package/lib/esm/chunk-TDLQZ6MP.mjs +86 -0
- package/lib/esm/chunk-TDLQZ6MP.mjs.map +1 -0
- package/lib/esm/chunk-VE37GDG2.mjs +7 -0
- package/lib/esm/chunk-VE37GDG2.mjs.map +1 -0
- package/lib/esm/chunk-WWACQNRQ.mjs +7 -0
- package/lib/esm/chunk-WWACQNRQ.mjs.map +1 -0
- package/lib/esm/chunk-X4W4S5RB.mjs +39 -0
- package/lib/esm/chunk-X4W4S5RB.mjs.map +1 -0
- package/lib/esm/chunk-Z4QX3O5V.mjs +748 -0
- package/lib/esm/chunk-Z4QX3O5V.mjs.map +1 -0
- package/lib/esm/chunk-ZYXTTU74.mjs +88 -0
- package/lib/esm/chunk-ZYXTTU74.mjs.map +1 -0
- package/lib/esm/client/index.d.mts +243 -0
- package/lib/esm/client/index.mjs +260 -0
- package/lib/esm/client/index.mjs.map +1 -0
- package/lib/esm/exact/client/index.d.mts +37 -0
- package/lib/esm/exact/client/index.mjs +36 -0
- package/lib/esm/exact/client/index.mjs.map +1 -0
- package/lib/esm/exact/facilitator/index.d.mts +110 -0
- package/lib/esm/exact/facilitator/index.mjs +350 -0
- package/lib/esm/exact/facilitator/index.mjs.map +1 -0
- package/lib/esm/exact/server/index.d.mts +87 -0
- package/lib/esm/exact/server/index.mjs +129 -0
- package/lib/esm/exact/server/index.mjs.map +1 -0
- package/lib/esm/exact/v1/client/index.d.mts +33 -0
- package/lib/esm/exact/v1/client/index.mjs +8 -0
- package/lib/esm/exact/v1/client/index.mjs.map +1 -0
- package/lib/esm/exact/v1/facilitator/index.d.mts +71 -0
- package/lib/esm/exact/v1/facilitator/index.mjs +8 -0
- package/lib/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/lib/esm/facilitator/index.d.mts +192 -0
- package/lib/esm/facilitator/index.mjs +373 -0
- package/lib/esm/facilitator/index.mjs.map +1 -0
- package/lib/esm/http/index.d.mts +52 -0
- package/lib/esm/http/index.mjs +29 -0
- package/lib/esm/http/index.mjs.map +1 -0
- package/lib/esm/index.d.mts +145 -0
- package/lib/esm/index.mjs +277 -0
- package/lib/esm/index.mjs.map +1 -0
- package/lib/esm/mechanisms-CzuGzYsS.d.mts +270 -0
- package/lib/esm/scheme-fjF-9LhT.d.mts +29 -0
- package/lib/esm/server/index.d.mts +2 -0
- package/lib/esm/server/index.mjs +563 -0
- package/lib/esm/server/index.mjs.map +1 -0
- package/lib/esm/signer-5OVDxViv.d.mts +79 -0
- package/lib/esm/signer-BMkbhFYE.d.mts +123 -0
- package/lib/esm/types/index.d.mts +1 -0
- package/lib/esm/types/index.mjs +10 -0
- package/lib/esm/types/index.mjs.map +1 -0
- package/lib/esm/types/v1/index.d.mts +1 -0
- package/lib/esm/types/v1/index.mjs +1 -0
- package/lib/esm/types/v1/index.mjs.map +1 -0
- package/lib/esm/utils/index.d.mts +48 -0
- package/lib/esm/utils/index.mjs +20 -0
- package/lib/esm/utils/index.mjs.map +1 -0
- package/lib/esm/v1/index.d.mts +12 -0
- package/lib/esm/v1/index.mjs +13 -0
- package/lib/esm/v1/index.mjs.map +1 -0
- package/lib/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +719 -0
- package/package.json +39 -0
- package/src/index.js +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# x402-express-mantle
|
|
2
|
+
|
|
3
|
+
Complete x402 Express middleware SDK with built-in Mantle testnet support and USDC Token configurations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Bundled SDK**: No external dependencies on @x402 packages
|
|
8
|
+
- ✅ **Mantle Testnet Ready**: Pre-configured for `eip155:5003` with USDC Token support
|
|
9
|
+
- ✅ **EIP-712 Compatible**: Uses "USDC Token" name and version "1" for Mantle contracts
|
|
10
|
+
- ✅ **Express Integration**: Seamless Express.js middleware
|
|
11
|
+
- ✅ **Zero Configuration**: Works out-of-the-box for Mantle development
|
|
12
|
+
- ✅ **TypeScript Support**: Full type definitions included
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install x402-express-mantle
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import express from 'express';
|
|
24
|
+
import { paymentMiddlewareFromConfig } from 'x402-express-mantle';
|
|
25
|
+
import { ExactEvmScheme } from 'x402-express-mantle';
|
|
26
|
+
import { HTTPFacilitatorClient } from 'x402-express-mantle';
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
|
|
30
|
+
// Connect to your Mantle facilitator
|
|
31
|
+
const facilitatorClient = new HTTPFacilitatorClient({
|
|
32
|
+
url: 'https://your-mantle-facilitator.com'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Routes with automatic Mantle payment processing
|
|
36
|
+
const routes = {
|
|
37
|
+
'GET /premium-data': {
|
|
38
|
+
accepts: [{
|
|
39
|
+
scheme: 'exact',
|
|
40
|
+
price: '$0.001',
|
|
41
|
+
network: 'eip155:5003', // Mantle testnet (pre-configured)
|
|
42
|
+
payTo: '0xYourMantleWalletAddress'
|
|
43
|
+
}],
|
|
44
|
+
description: 'Premium data access'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Configure payment schemes (Mantle support built-in)
|
|
49
|
+
const schemes = [{
|
|
50
|
+
network: 'eip155:5003', // Mantle testnet
|
|
51
|
+
server: new ExactEvmScheme()
|
|
52
|
+
}];
|
|
53
|
+
|
|
54
|
+
// Add payment middleware
|
|
55
|
+
app.use(paymentMiddlewareFromConfig(
|
|
56
|
+
routes,
|
|
57
|
+
facilitatorClient,
|
|
58
|
+
schemes
|
|
59
|
+
));
|
|
60
|
+
|
|
61
|
+
// Your protected route
|
|
62
|
+
app.get('/premium-data', (req, res) => {
|
|
63
|
+
res.json({
|
|
64
|
+
data: 'Premium Mantle content!',
|
|
65
|
+
network: 'Mantle Testnet'
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
app.listen(3000);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Mantle Testnet Configuration
|
|
73
|
+
|
|
74
|
+
This SDK includes pre-built configurations for Mantle testnet:
|
|
75
|
+
|
|
76
|
+
- **Network**: `eip155:5003`
|
|
77
|
+
- **USDC Contract**: `0x3D884Eca2a1E65A41Cd54b1CF55537dAe35d7BDC`
|
|
78
|
+
- **Token Name**: `USDC Token` (EIP-712 domain name)
|
|
79
|
+
- **Version**: `1` (EIP-712 domain version)
|
|
80
|
+
- **RPC**: Uses official Mantle testnet endpoints
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
### `paymentMiddleware(routes, server, paywallConfig?, paywall?, syncFacilitatorOnStart?)`
|
|
85
|
+
|
|
86
|
+
Direct middleware function using a pre-configured server instance.
|
|
87
|
+
|
|
88
|
+
### `paymentMiddlewareFromConfig(routes, facilitatorClients?, schemes?, paywallConfig?, paywall?, syncFacilitatorOnStart?)`
|
|
89
|
+
|
|
90
|
+
Configuration-based middleware that creates the server internally.
|
|
91
|
+
|
|
92
|
+
### Core Classes
|
|
93
|
+
- `x402ResourceServer` - Resource server for advanced configurations
|
|
94
|
+
- `x402HTTPResourceServer` - HTTP resource server
|
|
95
|
+
- `HTTPFacilitatorClient` - Client for connecting to facilitators
|
|
96
|
+
- `ExactEvmScheme` - EVM payment scheme (Mantle-compatible)
|
|
97
|
+
|
|
98
|
+
## Environment Variables
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Your facilitator URL (required)
|
|
102
|
+
FACILITATOR_URL=https://your-facilitator.com
|
|
103
|
+
|
|
104
|
+
# Wallet address for receiving payments (required for routes)
|
|
105
|
+
EVM_ADDRESS=0xYourMantleWalletAddress
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Supported Networks
|
|
109
|
+
|
|
110
|
+
- **Mantle Testnet** (`eip155:5003`) - Primary support with full configurations
|
|
111
|
+
- **Other EVM Networks** - Via standard x402 mechanisms
|
|
112
|
+
- **Solana Networks** - Via standard x402 mechanisms
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
Check the `examples/` directory for complete working examples:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cd node_modules/x402-express-mantle/examples
|
|
120
|
+
npm install
|
|
121
|
+
npm start
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Built-in Mantle Features
|
|
125
|
+
|
|
126
|
+
This SDK includes custom Mantle configurations:
|
|
127
|
+
|
|
128
|
+
1. **USDC Token Support**: Pre-configured with correct contract address and EIP-712 parameters
|
|
129
|
+
2. **Network Definitions**: Mantle testnet properly defined with chain ID 5003
|
|
130
|
+
3. **RPC Endpoints**: Official Mantle testnet RPC configurations
|
|
131
|
+
4. **Scheme Support**: EVM exact scheme configured for Mantle
|
|
132
|
+
|
|
133
|
+
## Deployment
|
|
134
|
+
|
|
135
|
+
### Vercel
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install x402-express-mantle
|
|
139
|
+
# Deploy to Vercel with your environment variables
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Other Platforms
|
|
143
|
+
|
|
144
|
+
Works with any Node.js platform supporting Express.js.
|
|
145
|
+
|
|
146
|
+
## Why This Package?
|
|
147
|
+
|
|
148
|
+
- **No External Dependencies**: Bundled with all x402 functionality
|
|
149
|
+
- **Mantle Optimized**: Custom configurations for Mantle ecosystem
|
|
150
|
+
- **Developer Friendly**: Zero configuration for Mantle development
|
|
151
|
+
- **Production Ready**: Includes all necessary type definitions and examples
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
Apache-2.0
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { c as PaymentRequired, a as PaymentRequirements, P as PaymentPayload, N as Network, d as SchemeNetworkClient, S as SettleResponse } from '../mechanisms-CzuGzYsS.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Client Hook Context Interfaces
|
|
5
|
+
*/
|
|
6
|
+
interface PaymentCreationContext {
|
|
7
|
+
paymentRequired: PaymentRequired;
|
|
8
|
+
selectedRequirements: PaymentRequirements;
|
|
9
|
+
}
|
|
10
|
+
interface PaymentCreatedContext extends PaymentCreationContext {
|
|
11
|
+
paymentPayload: PaymentPayload;
|
|
12
|
+
}
|
|
13
|
+
interface PaymentCreationFailureContext extends PaymentCreationContext {
|
|
14
|
+
error: Error;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Client Hook Type Definitions
|
|
18
|
+
*/
|
|
19
|
+
type BeforePaymentCreationHook = (context: PaymentCreationContext) => Promise<void | {
|
|
20
|
+
abort: true;
|
|
21
|
+
reason: string;
|
|
22
|
+
}>;
|
|
23
|
+
type AfterPaymentCreationHook = (context: PaymentCreatedContext) => Promise<void>;
|
|
24
|
+
type OnPaymentCreationFailureHook = (context: PaymentCreationFailureContext) => Promise<void | {
|
|
25
|
+
recovered: true;
|
|
26
|
+
payload: PaymentPayload;
|
|
27
|
+
}>;
|
|
28
|
+
type SelectPaymentRequirements = (x402Version: number, paymentRequirements: PaymentRequirements[]) => PaymentRequirements;
|
|
29
|
+
/**
|
|
30
|
+
* A policy function that filters or transforms payment requirements.
|
|
31
|
+
* Policies are applied in order before the selector chooses the final option.
|
|
32
|
+
*
|
|
33
|
+
* @param x402Version - The x402 protocol version
|
|
34
|
+
* @param paymentRequirements - Array of payment requirements to filter/transform
|
|
35
|
+
* @returns Filtered array of payment requirements
|
|
36
|
+
*/
|
|
37
|
+
type PaymentPolicy = (x402Version: number, paymentRequirements: PaymentRequirements[]) => PaymentRequirements[];
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for registering a payment scheme with a specific network
|
|
40
|
+
*/
|
|
41
|
+
interface SchemeRegistration {
|
|
42
|
+
/**
|
|
43
|
+
* The network identifier (e.g., 'eip155:8453', 'solana:mainnet')
|
|
44
|
+
*/
|
|
45
|
+
network: Network;
|
|
46
|
+
/**
|
|
47
|
+
* The scheme client implementation for this network
|
|
48
|
+
*/
|
|
49
|
+
client: SchemeNetworkClient;
|
|
50
|
+
/**
|
|
51
|
+
* The x402 protocol version to use for this scheme
|
|
52
|
+
*
|
|
53
|
+
* @default 2
|
|
54
|
+
*/
|
|
55
|
+
x402Version?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Configuration options for the fetch wrapper
|
|
59
|
+
*/
|
|
60
|
+
interface x402ClientConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Array of scheme registrations defining which payment methods are supported
|
|
63
|
+
*/
|
|
64
|
+
schemes: SchemeRegistration[];
|
|
65
|
+
/**
|
|
66
|
+
* Policies to apply to the client
|
|
67
|
+
*/
|
|
68
|
+
policies?: PaymentPolicy[];
|
|
69
|
+
/**
|
|
70
|
+
* Custom payment requirements selector function
|
|
71
|
+
* If not provided, uses the default selector (first available option)
|
|
72
|
+
*/
|
|
73
|
+
paymentRequirementsSelector?: SelectPaymentRequirements;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Core client for managing x402 payment schemes and creating payment payloads.
|
|
77
|
+
*
|
|
78
|
+
* Handles registration of payment schemes, policy-based filtering of payment requirements,
|
|
79
|
+
* and creation of payment payloads based on server requirements.
|
|
80
|
+
*/
|
|
81
|
+
declare class x402Client {
|
|
82
|
+
private readonly paymentRequirementsSelector;
|
|
83
|
+
private readonly registeredClientSchemes;
|
|
84
|
+
private readonly policies;
|
|
85
|
+
private beforePaymentCreationHooks;
|
|
86
|
+
private afterPaymentCreationHooks;
|
|
87
|
+
private onPaymentCreationFailureHooks;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new x402Client instance.
|
|
90
|
+
*
|
|
91
|
+
* @param paymentRequirementsSelector - Function to select payment requirements from available options
|
|
92
|
+
*/
|
|
93
|
+
constructor(paymentRequirementsSelector?: SelectPaymentRequirements);
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new x402Client instance from a configuration object.
|
|
96
|
+
*
|
|
97
|
+
* @param config - The client configuration including schemes, policies, and payment requirements selector
|
|
98
|
+
* @returns A configured x402Client instance
|
|
99
|
+
*/
|
|
100
|
+
static fromConfig(config: x402ClientConfig): x402Client;
|
|
101
|
+
/**
|
|
102
|
+
* Registers a scheme client for the current x402 version.
|
|
103
|
+
*
|
|
104
|
+
* @param network - The network to register the client for
|
|
105
|
+
* @param client - The scheme network client to register
|
|
106
|
+
* @returns The x402Client instance for chaining
|
|
107
|
+
*/
|
|
108
|
+
register(network: Network, client: SchemeNetworkClient): x402Client;
|
|
109
|
+
/**
|
|
110
|
+
* Registers a scheme client for x402 version 1.
|
|
111
|
+
*
|
|
112
|
+
* @param network - The v1 network identifier (e.g., 'base-sepolia', 'solana-devnet')
|
|
113
|
+
* @param client - The scheme network client to register
|
|
114
|
+
* @returns The x402Client instance for chaining
|
|
115
|
+
*/
|
|
116
|
+
registerV1(network: string, client: SchemeNetworkClient): x402Client;
|
|
117
|
+
/**
|
|
118
|
+
* Registers a policy to filter or transform payment requirements.
|
|
119
|
+
*
|
|
120
|
+
* Policies are applied in order after filtering by registered schemes
|
|
121
|
+
* and before the selector chooses the final payment requirement.
|
|
122
|
+
*
|
|
123
|
+
* @param policy - Function to filter/transform payment requirements
|
|
124
|
+
* @returns The x402Client instance for chaining
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Prefer cheaper options
|
|
129
|
+
* client.registerPolicy((version, reqs) =>
|
|
130
|
+
* reqs.filter(r => BigInt(r.value) < BigInt('1000000'))
|
|
131
|
+
* );
|
|
132
|
+
*
|
|
133
|
+
* // Prefer specific networks
|
|
134
|
+
* client.registerPolicy((version, reqs) =>
|
|
135
|
+
* reqs.filter(r => r.network.startsWith('eip155:'))
|
|
136
|
+
* );
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
registerPolicy(policy: PaymentPolicy): x402Client;
|
|
140
|
+
/**
|
|
141
|
+
* Register a hook to execute before payment payload creation.
|
|
142
|
+
* Can abort creation by returning { abort: true, reason: string }
|
|
143
|
+
*
|
|
144
|
+
* @param hook - The hook function to register
|
|
145
|
+
* @returns The x402Client instance for chaining
|
|
146
|
+
*/
|
|
147
|
+
onBeforePaymentCreation(hook: BeforePaymentCreationHook): x402Client;
|
|
148
|
+
/**
|
|
149
|
+
* Register a hook to execute after successful payment payload creation.
|
|
150
|
+
*
|
|
151
|
+
* @param hook - The hook function to register
|
|
152
|
+
* @returns The x402Client instance for chaining
|
|
153
|
+
*/
|
|
154
|
+
onAfterPaymentCreation(hook: AfterPaymentCreationHook): x402Client;
|
|
155
|
+
/**
|
|
156
|
+
* Register a hook to execute when payment payload creation fails.
|
|
157
|
+
* Can recover from failure by returning { recovered: true, payload: PaymentPayload }
|
|
158
|
+
*
|
|
159
|
+
* @param hook - The hook function to register
|
|
160
|
+
* @returns The x402Client instance for chaining
|
|
161
|
+
*/
|
|
162
|
+
onPaymentCreationFailure(hook: OnPaymentCreationFailureHook): x402Client;
|
|
163
|
+
/**
|
|
164
|
+
* Creates a payment payload based on a PaymentRequired response.
|
|
165
|
+
*
|
|
166
|
+
* Automatically extracts x402Version, resource, and extensions from the PaymentRequired
|
|
167
|
+
* response and constructs a complete PaymentPayload with the accepted requirements.
|
|
168
|
+
*
|
|
169
|
+
* @param paymentRequired - The PaymentRequired response from the server
|
|
170
|
+
* @returns Promise resolving to the complete payment payload
|
|
171
|
+
*/
|
|
172
|
+
createPaymentPayload(paymentRequired: PaymentRequired): Promise<PaymentPayload>;
|
|
173
|
+
/**
|
|
174
|
+
* Selects appropriate payment requirements based on registered clients and policies.
|
|
175
|
+
*
|
|
176
|
+
* Selection process:
|
|
177
|
+
* 1. Filter by registered schemes (network + scheme support)
|
|
178
|
+
* 2. Apply all registered policies in order
|
|
179
|
+
* 3. Use selector to choose final requirement
|
|
180
|
+
*
|
|
181
|
+
* @param x402Version - The x402 protocol version
|
|
182
|
+
* @param paymentRequirements - Array of available payment requirements
|
|
183
|
+
* @returns The selected payment requirements
|
|
184
|
+
*/
|
|
185
|
+
private selectPaymentRequirements;
|
|
186
|
+
/**
|
|
187
|
+
* Internal method to register a scheme client.
|
|
188
|
+
*
|
|
189
|
+
* @param x402Version - The x402 protocol version
|
|
190
|
+
* @param network - The network to register the client for
|
|
191
|
+
* @param client - The scheme network client to register
|
|
192
|
+
* @returns The x402Client instance for chaining
|
|
193
|
+
*/
|
|
194
|
+
private _registerScheme;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* HTTP-specific client for handling x402 payment protocol over HTTP.
|
|
199
|
+
*
|
|
200
|
+
* Wraps a x402Client to provide HTTP-specific encoding/decoding functionality
|
|
201
|
+
* for payment headers and responses while maintaining the builder pattern.
|
|
202
|
+
*/
|
|
203
|
+
declare class x402HTTPClient {
|
|
204
|
+
private readonly client;
|
|
205
|
+
/**
|
|
206
|
+
* Creates a new x402HTTPClient instance.
|
|
207
|
+
*
|
|
208
|
+
* @param client - The underlying x402Client for payment logic
|
|
209
|
+
*/
|
|
210
|
+
constructor(client: x402Client);
|
|
211
|
+
/**
|
|
212
|
+
* Encodes a payment payload into appropriate HTTP headers based on version.
|
|
213
|
+
*
|
|
214
|
+
* @param paymentPayload - The payment payload to encode
|
|
215
|
+
* @returns HTTP headers containing the encoded payment signature
|
|
216
|
+
*/
|
|
217
|
+
encodePaymentSignatureHeader(paymentPayload: PaymentPayload): Record<string, string>;
|
|
218
|
+
/**
|
|
219
|
+
* Extracts payment required information from HTTP response.
|
|
220
|
+
*
|
|
221
|
+
* @param getHeader - Function to retrieve header value by name (case-insensitive)
|
|
222
|
+
* @param body - Optional response body for v1 compatibility
|
|
223
|
+
* @returns The payment required object
|
|
224
|
+
*/
|
|
225
|
+
getPaymentRequiredResponse(getHeader: (name: string) => string | null | undefined, body?: unknown): PaymentRequired;
|
|
226
|
+
/**
|
|
227
|
+
* Extracts payment settlement response from HTTP headers.
|
|
228
|
+
*
|
|
229
|
+
* @param getHeader - Function to retrieve header value by name (case-insensitive)
|
|
230
|
+
* @returns The settlement response object
|
|
231
|
+
*/
|
|
232
|
+
getPaymentSettleResponse(getHeader: (name: string) => string | null | undefined): SettleResponse;
|
|
233
|
+
/**
|
|
234
|
+
* Creates a payment payload for the given payment requirements.
|
|
235
|
+
* Delegates to the underlying x402Client.
|
|
236
|
+
*
|
|
237
|
+
* @param paymentRequired - The payment required response from the server
|
|
238
|
+
* @returns Promise resolving to the payment payload
|
|
239
|
+
*/
|
|
240
|
+
createPaymentPayload(paymentRequired: PaymentRequired): Promise<PaymentPayload>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { type AfterPaymentCreationHook, type BeforePaymentCreationHook, type OnPaymentCreationFailureHook, type PaymentCreatedContext, type PaymentCreationContext, type PaymentCreationFailureContext, type PaymentPolicy, type SchemeRegistration, type SelectPaymentRequirements, x402Client, type x402ClientConfig, x402HTTPClient };
|