x402-express-mantle 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/lib/cjs/index.d.ts +119 -81
- package/lib/cjs/index.js +3 -3
- package/lib/esm/index.d.mts +5 -5
- package/lib/esm/index.mjs +3 -3
- package/package.json +4 -3
- package/lib/cjs/client/index.d.ts +0 -243
- package/lib/cjs/client/index.js +0 -413
- package/lib/cjs/client/index.js.map +0 -1
- package/lib/cjs/exact/client/index.d.ts +0 -37
- package/lib/cjs/exact/client/index.js +0 -281
- package/lib/cjs/exact/client/index.js.map +0 -1
- package/lib/cjs/exact/facilitator/index.d.ts +0 -110
- package/lib/cjs/exact/facilitator/index.js +0 -714
- package/lib/cjs/exact/facilitator/index.js.map +0 -1
- package/lib/cjs/exact/server/index.d.ts +0 -87
- package/lib/cjs/exact/server/index.js +0 -209
- package/lib/cjs/exact/server/index.js.map +0 -1
- package/lib/cjs/exact/v1/client/index.d.ts +0 -33
- package/lib/cjs/exact/v1/client/index.js +0 -169
- package/lib/cjs/exact/v1/client/index.js.map +0 -1
- package/lib/cjs/exact/v1/facilitator/index.d.ts +0 -71
- package/lib/cjs/exact/v1/facilitator/index.js +0 -384
- package/lib/cjs/exact/v1/facilitator/index.js.map +0 -1
- package/lib/cjs/facilitator/index.d.ts +0 -192
- package/lib/cjs/facilitator/index.js +0 -398
- package/lib/cjs/facilitator/index.js.map +0 -1
- package/lib/cjs/http/index.d.ts +0 -52
- package/lib/cjs/http/index.js +0 -827
- package/lib/cjs/http/index.js.map +0 -1
- package/lib/cjs/mechanisms-CzuGzYsS.d.ts +0 -270
- package/lib/cjs/scheme-MoBRXFM8.d.ts +0 -29
- package/lib/cjs/server/index.d.ts +0 -2
- package/lib/cjs/server/index.js +0 -1305
- package/lib/cjs/server/index.js.map +0 -1
- package/lib/cjs/signer-5OVDxViv.d.ts +0 -79
- package/lib/cjs/signer-BMkbhFYE.d.ts +0 -123
- package/lib/cjs/types/index.d.ts +0 -1
- package/lib/cjs/types/index.js +0 -66
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/types/v1/index.d.ts +0 -1
- package/lib/cjs/types/v1/index.js +0 -19
- package/lib/cjs/types/v1/index.js.map +0 -1
- package/lib/cjs/utils/index.d.ts +0 -48
- package/lib/cjs/utils/index.js +0 -116
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/v1/index.d.ts +0 -12
- package/lib/cjs/v1/index.js +0 -180
- package/lib/cjs/v1/index.js.map +0 -1
- package/lib/cjs/x402HTTPResourceServer-D1YtlH_r.d.ts +0 -719
- package/lib/esm/chunk-3CEIVWNN.mjs +0 -339
- package/lib/esm/chunk-3CEIVWNN.mjs.map +0 -1
- package/lib/esm/chunk-BJTO5JO5.mjs +0 -11
- package/lib/esm/chunk-BJTO5JO5.mjs.map +0 -1
- package/lib/esm/chunk-EEA7DKZI.mjs +0 -111
- package/lib/esm/chunk-EEA7DKZI.mjs.map +0 -1
- package/lib/esm/chunk-FOUXRQAV.mjs +0 -88
- package/lib/esm/chunk-FOUXRQAV.mjs.map +0 -1
- package/lib/esm/chunk-IKSTWKEM.mjs +0 -157
- package/lib/esm/chunk-IKSTWKEM.mjs.map +0 -1
- package/lib/esm/chunk-JYZWCLMP.mjs +0 -305
- package/lib/esm/chunk-JYZWCLMP.mjs.map +0 -1
- package/lib/esm/chunk-PNSAJQCF.mjs +0 -108
- package/lib/esm/chunk-PNSAJQCF.mjs.map +0 -1
- package/lib/esm/chunk-PSA4YVU2.mjs +0 -92
- package/lib/esm/chunk-PSA4YVU2.mjs.map +0 -1
- package/lib/esm/chunk-QLXM7BIB.mjs +0 -23
- package/lib/esm/chunk-QLXM7BIB.mjs.map +0 -1
- package/lib/esm/chunk-TDLQZ6MP.mjs +0 -86
- package/lib/esm/chunk-TDLQZ6MP.mjs.map +0 -1
- package/lib/esm/chunk-VE37GDG2.mjs +0 -7
- package/lib/esm/chunk-VE37GDG2.mjs.map +0 -1
- package/lib/esm/chunk-WWACQNRQ.mjs +0 -7
- package/lib/esm/chunk-WWACQNRQ.mjs.map +0 -1
- package/lib/esm/chunk-X4W4S5RB.mjs +0 -39
- package/lib/esm/chunk-X4W4S5RB.mjs.map +0 -1
- package/lib/esm/chunk-Z4QX3O5V.mjs +0 -748
- package/lib/esm/chunk-Z4QX3O5V.mjs.map +0 -1
- package/lib/esm/chunk-ZYXTTU74.mjs +0 -88
- package/lib/esm/chunk-ZYXTTU74.mjs.map +0 -1
- package/lib/esm/client/index.d.mts +0 -243
- package/lib/esm/client/index.mjs +0 -260
- package/lib/esm/client/index.mjs.map +0 -1
- package/lib/esm/exact/client/index.d.mts +0 -37
- package/lib/esm/exact/client/index.mjs +0 -36
- package/lib/esm/exact/client/index.mjs.map +0 -1
- package/lib/esm/exact/facilitator/index.d.mts +0 -110
- package/lib/esm/exact/facilitator/index.mjs +0 -350
- package/lib/esm/exact/facilitator/index.mjs.map +0 -1
- package/lib/esm/exact/server/index.d.mts +0 -87
- package/lib/esm/exact/server/index.mjs +0 -129
- package/lib/esm/exact/server/index.mjs.map +0 -1
- package/lib/esm/exact/v1/client/index.d.mts +0 -33
- package/lib/esm/exact/v1/client/index.mjs +0 -8
- package/lib/esm/exact/v1/client/index.mjs.map +0 -1
- package/lib/esm/exact/v1/facilitator/index.d.mts +0 -71
- package/lib/esm/exact/v1/facilitator/index.mjs +0 -8
- package/lib/esm/exact/v1/facilitator/index.mjs.map +0 -1
- package/lib/esm/facilitator/index.d.mts +0 -192
- package/lib/esm/facilitator/index.mjs +0 -373
- package/lib/esm/facilitator/index.mjs.map +0 -1
- package/lib/esm/http/index.d.mts +0 -52
- package/lib/esm/http/index.mjs +0 -29
- package/lib/esm/http/index.mjs.map +0 -1
- package/lib/esm/mechanisms-CzuGzYsS.d.mts +0 -270
- package/lib/esm/scheme-fjF-9LhT.d.mts +0 -29
- package/lib/esm/server/index.d.mts +0 -2
- package/lib/esm/server/index.mjs +0 -563
- package/lib/esm/server/index.mjs.map +0 -1
- package/lib/esm/signer-5OVDxViv.d.mts +0 -79
- package/lib/esm/signer-BMkbhFYE.d.mts +0 -123
- package/lib/esm/types/index.d.mts +0 -1
- package/lib/esm/types/index.mjs +0 -10
- package/lib/esm/types/index.mjs.map +0 -1
- package/lib/esm/types/v1/index.d.mts +0 -1
- package/lib/esm/types/v1/index.mjs +0 -1
- package/lib/esm/types/v1/index.mjs.map +0 -1
- package/lib/esm/utils/index.d.mts +0 -48
- package/lib/esm/utils/index.mjs +0 -20
- package/lib/esm/utils/index.mjs.map +0 -1
- package/lib/esm/v1/index.d.mts +0 -12
- package/lib/esm/v1/index.mjs +0 -13
- package/lib/esm/v1/index.mjs.map +0 -1
- package/lib/esm/x402HTTPResourceServer-BIfIK5HS.d.mts +0 -719
- package/src/index.js +0 -4
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ EVM_ADDRESS=0xYourMantleWalletAddress
|
|
|
116
116
|
Check the `examples/` directory for complete working examples:
|
|
117
117
|
|
|
118
118
|
```bash
|
|
119
|
-
cd
|
|
119
|
+
cd examples/express
|
|
120
120
|
npm install
|
|
121
121
|
npm start
|
|
122
122
|
```
|
|
@@ -136,6 +136,24 @@ This SDK includes custom Mantle configurations:
|
|
|
136
136
|
|
|
137
137
|
```bash
|
|
138
138
|
npm install x402-express-mantle
|
|
139
|
+
|
|
140
|
+
## Quick Example
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Try the example server
|
|
144
|
+
cd examples/express
|
|
145
|
+
npm install
|
|
146
|
+
cp .env-local .env
|
|
147
|
+
# Edit .env with your facilitator URL and EVM address
|
|
148
|
+
npm run dev
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The example server demonstrates:
|
|
152
|
+
- Mantle testnet payment integration
|
|
153
|
+
- Multiple pricing tiers ($0.001 and $0.005 USDC)
|
|
154
|
+
- Free and paid endpoints
|
|
155
|
+
- Complete payment flow
|
|
156
|
+
|
|
139
157
|
# Deploy to Vercel with your environment variables
|
|
140
158
|
```
|
|
141
159
|
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,91 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
HTTPAdapter,
|
|
3
|
+
RoutesConfig,
|
|
4
|
+
x402ResourceServer,
|
|
5
|
+
PaywallConfig,
|
|
6
|
+
PaywallProvider,
|
|
7
|
+
FacilitatorClient,
|
|
8
|
+
} from "x402-core-mantle/server";
|
|
9
|
+
export {
|
|
10
|
+
PaywallConfig,
|
|
11
|
+
PaywallProvider,
|
|
12
|
+
RouteConfigurationError,
|
|
13
|
+
RouteValidationError,
|
|
14
|
+
x402HTTPResourceServer,
|
|
15
|
+
x402ResourceServer,
|
|
16
|
+
} from "x402-core-mantle/server";
|
|
17
|
+
import { Network, SchemeNetworkServer } from "x402-core-mantle/types";
|
|
18
|
+
export {
|
|
19
|
+
Network,
|
|
20
|
+
PaymentPayload,
|
|
21
|
+
PaymentRequired,
|
|
22
|
+
PaymentRequirements,
|
|
23
|
+
SchemeNetworkServer,
|
|
24
|
+
} from "x402-core-mantle/types";
|
|
25
|
+
import { Request, Response, NextFunction } from "express";
|
|
6
26
|
|
|
7
27
|
/**
|
|
8
28
|
* Express adapter implementation
|
|
9
29
|
*/
|
|
10
30
|
declare class ExpressAdapter implements HTTPAdapter {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
31
|
+
private req;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new ExpressAdapter instance.
|
|
34
|
+
*
|
|
35
|
+
* @param req - The Express request object
|
|
36
|
+
*/
|
|
37
|
+
constructor(req: Request);
|
|
38
|
+
/**
|
|
39
|
+
* Gets a header value from the request.
|
|
40
|
+
*
|
|
41
|
+
* @param name - The header name
|
|
42
|
+
* @returns The header value or undefined
|
|
43
|
+
*/
|
|
44
|
+
getHeader(name: string): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the HTTP method of the request.
|
|
47
|
+
*
|
|
48
|
+
* @returns The HTTP method
|
|
49
|
+
*/
|
|
50
|
+
getMethod(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the path of the request.
|
|
53
|
+
*
|
|
54
|
+
* @returns The request path
|
|
55
|
+
*/
|
|
56
|
+
getPath(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the full URL of the request.
|
|
59
|
+
*
|
|
60
|
+
* @returns The full request URL
|
|
61
|
+
*/
|
|
62
|
+
getUrl(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the Accept header from the request.
|
|
65
|
+
*
|
|
66
|
+
* @returns The Accept header value or empty string
|
|
67
|
+
*/
|
|
68
|
+
getAcceptHeader(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the User-Agent header from the request.
|
|
71
|
+
*
|
|
72
|
+
* @returns The User-Agent header value or empty string
|
|
73
|
+
*/
|
|
74
|
+
getUserAgent(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Gets all query parameters from the request URL.
|
|
77
|
+
*
|
|
78
|
+
* @returns Record of query parameter key-value pairs
|
|
79
|
+
*/
|
|
80
|
+
getQueryParams(): Record<string, string | string[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets a specific query parameter by name.
|
|
83
|
+
*
|
|
84
|
+
* @param name - The query parameter name
|
|
85
|
+
* @returns The query parameter value(s) or undefined
|
|
86
|
+
*/
|
|
87
|
+
getQueryParam(name: string): string | string[] | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the parsed request body.
|
|
90
|
+
* Requires express.json() or express.urlencoded() middleware.
|
|
91
|
+
*
|
|
92
|
+
* @returns The parsed request body
|
|
93
|
+
*/
|
|
94
|
+
getBody(): unknown;
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
/**
|
|
78
98
|
* Configuration for registering a payment scheme with a specific network
|
|
79
99
|
*/
|
|
80
100
|
interface SchemeRegistration {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The network identifier (e.g., 'eip155:84532', 'solana:mainnet')
|
|
103
|
+
*/
|
|
104
|
+
network: Network;
|
|
105
|
+
/**
|
|
106
|
+
* The scheme server implementation for this network
|
|
107
|
+
*/
|
|
108
|
+
server: SchemeNetworkServer;
|
|
89
109
|
}
|
|
90
110
|
/**
|
|
91
111
|
* Express payment middleware for x402 protocol (direct server instance).
|
|
@@ -104,7 +124,7 @@ interface SchemeRegistration {
|
|
|
104
124
|
* @example
|
|
105
125
|
* ```typescript
|
|
106
126
|
* import { paymentMiddleware } from "@x402/express";
|
|
107
|
-
* import { x402ResourceServer } from "
|
|
127
|
+
* import { x402ResourceServer } from "x402-core-mantle/server";
|
|
108
128
|
* import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
109
129
|
*
|
|
110
130
|
* const server = new x402ResourceServer(myFacilitatorClient);
|
|
@@ -113,7 +133,13 @@ interface SchemeRegistration {
|
|
|
113
133
|
* app.use(paymentMiddleware(routes, server, paywallConfig));
|
|
114
134
|
* ```
|
|
115
135
|
*/
|
|
116
|
-
declare function paymentMiddleware(
|
|
136
|
+
declare function paymentMiddleware(
|
|
137
|
+
routes: RoutesConfig,
|
|
138
|
+
server: x402ResourceServer,
|
|
139
|
+
paywallConfig?: PaywallConfig,
|
|
140
|
+
paywall?: PaywallProvider,
|
|
141
|
+
syncFacilitatorOnStart?: boolean
|
|
142
|
+
): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
117
143
|
/**
|
|
118
144
|
* Express payment middleware for x402 protocol (configuration-based).
|
|
119
145
|
*
|
|
@@ -140,6 +166,18 @@ declare function paymentMiddleware(routes: RoutesConfig, server: x402ResourceSer
|
|
|
140
166
|
* ));
|
|
141
167
|
* ```
|
|
142
168
|
*/
|
|
143
|
-
declare function paymentMiddlewareFromConfig(
|
|
169
|
+
declare function paymentMiddlewareFromConfig(
|
|
170
|
+
routes: RoutesConfig,
|
|
171
|
+
facilitatorClients?: FacilitatorClient | FacilitatorClient[],
|
|
172
|
+
schemes?: SchemeRegistration[],
|
|
173
|
+
paywallConfig?: PaywallConfig,
|
|
174
|
+
paywall?: PaywallProvider,
|
|
175
|
+
syncFacilitatorOnStart?: boolean
|
|
176
|
+
): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
144
177
|
|
|
145
|
-
export {
|
|
178
|
+
export {
|
|
179
|
+
ExpressAdapter,
|
|
180
|
+
type SchemeRegistration,
|
|
181
|
+
paymentMiddleware,
|
|
182
|
+
paymentMiddlewareFromConfig,
|
|
183
|
+
};
|
package/lib/cjs/index.js
CHANGED
|
@@ -38,7 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
x402ResourceServer: () => import_server2.x402ResourceServer
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(src_exports);
|
|
41
|
-
var import_server = require("
|
|
41
|
+
var import_server = require("x402-core-mantle/server");
|
|
42
42
|
|
|
43
43
|
// src/adapter.ts
|
|
44
44
|
var ExpressAdapter = class {
|
|
@@ -130,8 +130,8 @@ var ExpressAdapter = class {
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
// src/index.ts
|
|
133
|
-
var import_server2 = require("
|
|
134
|
-
var import_server3 = require("
|
|
133
|
+
var import_server2 = require("x402-core-mantle/server");
|
|
134
|
+
var import_server3 = require("x402-core-mantle/server");
|
|
135
135
|
function checkIfBazaarNeeded(routes) {
|
|
136
136
|
if ("accepts" in routes) {
|
|
137
137
|
return !!(routes.extensions && "bazaar" in routes.extensions);
|
package/lib/esm/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HTTPAdapter, RoutesConfig, x402ResourceServer, PaywallConfig, PaywallProvider, FacilitatorClient } from '
|
|
2
|
-
export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, x402HTTPResourceServer, x402ResourceServer } from '
|
|
3
|
-
import { Network, SchemeNetworkServer } from '
|
|
4
|
-
export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from '
|
|
1
|
+
import { HTTPAdapter, RoutesConfig, x402ResourceServer, PaywallConfig, PaywallProvider, FacilitatorClient } from 'x402-core-mantle/server';
|
|
2
|
+
export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, x402HTTPResourceServer, x402ResourceServer } from 'x402-core-mantle/server';
|
|
3
|
+
import { Network, SchemeNetworkServer } from 'x402-core-mantle/types';
|
|
4
|
+
export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from 'x402-core-mantle/types';
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -104,7 +104,7 @@ interface SchemeRegistration {
|
|
|
104
104
|
* @example
|
|
105
105
|
* ```typescript
|
|
106
106
|
* import { paymentMiddleware } from "@x402/express";
|
|
107
|
-
* import { x402ResourceServer } from "
|
|
107
|
+
* import { x402ResourceServer } from "x402-core-mantle/server";
|
|
108
108
|
* import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
109
109
|
*
|
|
110
110
|
* const server = new x402ResourceServer(myFacilitatorClient);
|
package/lib/esm/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
x402HTTPResourceServer,
|
|
4
4
|
x402ResourceServer
|
|
5
|
-
} from "
|
|
5
|
+
} from "x402-core-mantle/server";
|
|
6
6
|
|
|
7
7
|
// src/adapter.ts
|
|
8
8
|
var ExpressAdapter = class {
|
|
@@ -94,8 +94,8 @@ var ExpressAdapter = class {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
// src/index.ts
|
|
97
|
-
import { x402ResourceServer as x402ResourceServer2, x402HTTPResourceServer as x402HTTPResourceServer2 } from "
|
|
98
|
-
import { RouteConfigurationError } from "
|
|
97
|
+
import { x402ResourceServer as x402ResourceServer2, x402HTTPResourceServer as x402HTTPResourceServer2 } from "x402-core-mantle/server";
|
|
98
|
+
import { RouteConfigurationError } from "x402-core-mantle/server";
|
|
99
99
|
function checkIfBazaarNeeded(routes) {
|
|
100
100
|
if ("accepts" in routes) {
|
|
101
101
|
return !!(routes.extensions && "bazaar" in routes.extensions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x402-express-mantle",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"author": "Mantle x402 Team",
|
|
21
21
|
"description": "x402 Express middleware SDK with built-in Mantle testnet support and USDC Token configurations",
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"x402-core-mantle": "2.1.1-mantle",
|
|
24
|
+
"x402-evm-mantle": "2.1.1-mantle",
|
|
25
|
+
"x402-svm-mantle": "2.1.1-mantle",
|
|
23
26
|
"@solana/kit": "^2.1.1",
|
|
24
27
|
"viem": "^2.39.3",
|
|
25
28
|
"zod": "^3.24.2"
|
|
@@ -31,9 +34,7 @@
|
|
|
31
34
|
".": "./src/index.js"
|
|
32
35
|
},
|
|
33
36
|
"files": [
|
|
34
|
-
"src",
|
|
35
37
|
"lib",
|
|
36
|
-
"examples",
|
|
37
38
|
"README.md"
|
|
38
39
|
]
|
|
39
40
|
}
|
|
@@ -1,243 +0,0 @@
|
|
|
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 };
|