@wtflabs/x402-server 0.0.1-beta.8 → 0.0.1-beta.9
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 +449 -212
- package/dist/cjs/index.d.ts +1313 -0
- package/dist/cjs/index.js +599 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.mts +1313 -0
- package/dist/esm/index.mjs +558 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +43 -15
- package/dist/index.d.mts +0 -217
- package/dist/index.d.ts +0 -217
- package/dist/index.js +0 -640
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -610
- package/dist/index.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,38 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtflabs/x402-server",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
4
|
-
"main": "./dist/index.js",
|
|
5
|
-
"module": "./dist/index.
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
3
|
+
"version": "0.0.1-beta.9",
|
|
4
|
+
"main": "./dist/cjs/index.js",
|
|
5
|
+
"module": "./dist/esm/index.js",
|
|
6
|
+
"types": "./dist/cjs/index.d.ts",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"x402",
|
|
9
9
|
"payment",
|
|
10
|
-
"server"
|
|
10
|
+
"server",
|
|
11
|
+
"permit",
|
|
12
|
+
"eip3009",
|
|
13
|
+
"permit2"
|
|
11
14
|
],
|
|
12
15
|
"license": "Apache-2.0",
|
|
13
|
-
"
|
|
16
|
+
"author": "WTFLabs",
|
|
17
|
+
"repository": "https://github.com/coinbase/x402",
|
|
18
|
+
"description": "Server SDK for x402 Payment Protocol - handle payment verification and settlement",
|
|
14
19
|
"devDependencies": {
|
|
15
20
|
"@types/node": "^22.13.4",
|
|
21
|
+
"@eslint/js": "^9.24.0",
|
|
22
|
+
"eslint": "^9.24.0",
|
|
23
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
24
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
26
|
+
"@typescript-eslint/parser": "^8.29.1",
|
|
27
|
+
"eslint-plugin-import": "^2.31.0",
|
|
28
|
+
"prettier": "3.5.2",
|
|
16
29
|
"tsup": "^8.4.0",
|
|
17
30
|
"tsx": "^4.19.2",
|
|
18
31
|
"typescript": "^5.7.3",
|
|
19
|
-
"
|
|
32
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
33
|
+
"vitest": "^3.0.5",
|
|
34
|
+
"vite": "^6.2.6"
|
|
20
35
|
},
|
|
21
36
|
"dependencies": {
|
|
22
|
-
"@wtflabs/x402": "^0.0.1-beta.4",
|
|
23
37
|
"viem": "^2.21.26",
|
|
24
|
-
"
|
|
25
|
-
"@wtflabs/x402-
|
|
38
|
+
"zod": "^3.24.2",
|
|
39
|
+
"@wtflabs/x402-detector": "^0.0.1-beta.2",
|
|
40
|
+
"@wtflabs/x402-facilitator": "^0.0.1-beta.9"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"express": "^4.0.0 || ^5.0.0",
|
|
44
|
+
"hono": "^4.0.0 || ^5.0.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"express": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"hono": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
26
53
|
},
|
|
27
54
|
"exports": {
|
|
28
55
|
".": {
|
|
29
56
|
"import": {
|
|
30
|
-
"types": "./dist/index.d.mts",
|
|
31
|
-
"default": "./dist/index.mjs"
|
|
57
|
+
"types": "./dist/esm/index.d.mts",
|
|
58
|
+
"default": "./dist/esm/index.mjs"
|
|
32
59
|
},
|
|
33
60
|
"require": {
|
|
34
|
-
"types": "./dist/index.d.ts",
|
|
35
|
-
"default": "./dist/index.js"
|
|
61
|
+
"types": "./dist/cjs/index.d.ts",
|
|
62
|
+
"default": "./dist/cjs/index.js"
|
|
36
63
|
}
|
|
37
64
|
}
|
|
38
65
|
},
|
|
@@ -40,9 +67,10 @@
|
|
|
40
67
|
"dist"
|
|
41
68
|
],
|
|
42
69
|
"scripts": {
|
|
43
|
-
"
|
|
70
|
+
"start": "tsx --env-file=.env index.ts",
|
|
44
71
|
"test": "vitest run",
|
|
45
72
|
"test:watch": "vitest",
|
|
73
|
+
"build": "tsup",
|
|
46
74
|
"watch": "tsc --watch",
|
|
47
75
|
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
48
76
|
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
package/dist/index.d.mts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { Facilitator } from '@wtflabs/x402-facilitator';
|
|
2
|
-
import { X402PaymentSchema } from '@wtflabs/x402-schema';
|
|
3
|
-
import { PublicClient } from 'viem';
|
|
4
|
-
import { PaymentPayload, PaymentRequirements } from '@wtflabs/x402/types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* X402Server 配置选项
|
|
8
|
-
*/
|
|
9
|
-
interface X402ServerConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Facilitator 实例
|
|
12
|
-
*/
|
|
13
|
-
facilitator: Facilitator;
|
|
14
|
-
/**
|
|
15
|
-
* Payment Schema 实例
|
|
16
|
-
*/
|
|
17
|
-
schema: X402PaymentSchema;
|
|
18
|
-
/**
|
|
19
|
-
* Viem Public Client 实例
|
|
20
|
-
*/
|
|
21
|
-
client: PublicClient;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 初始化结果
|
|
25
|
-
*/
|
|
26
|
-
interface InitializeResult {
|
|
27
|
-
success: boolean;
|
|
28
|
-
error?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 验证结果
|
|
32
|
-
*/
|
|
33
|
-
interface VerifyResult {
|
|
34
|
-
success: boolean;
|
|
35
|
-
errors?: string[];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 结算结果
|
|
39
|
-
*/
|
|
40
|
-
interface SettleResult {
|
|
41
|
-
success: boolean;
|
|
42
|
-
transaction?: string;
|
|
43
|
-
error?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* X402Server 类
|
|
48
|
-
* 集成 facilitator, schema 和 client,提供完整的服务端支付处理
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { X402Server } from "@wtflabs/x402-server";
|
|
53
|
-
* import { Facilitator } from "@wtflabs/x402-facilitator";
|
|
54
|
-
* import { X402PaymentSchema } from "@wtflabs/x402-schema";
|
|
55
|
-
* import { createPublicClient, http } from "viem";
|
|
56
|
-
* import { bscTestnet } from "viem/chains";
|
|
57
|
-
*
|
|
58
|
-
* const facilitator = new Facilitator({
|
|
59
|
-
* recipientAddress: "0x1234...",
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* const schema = new X402PaymentSchema({
|
|
63
|
-
* scheme: "exact",
|
|
64
|
-
* network: "bsc-testnet",
|
|
65
|
-
* maxAmountRequired: "100000",
|
|
66
|
-
* resource: "http://localhost:3000/protected-resource",
|
|
67
|
-
* description: "Access to protected resource",
|
|
68
|
-
* mimeType: "application/json",
|
|
69
|
-
* payTo: "0x1234...",
|
|
70
|
-
* maxTimeoutSeconds: 3600,
|
|
71
|
-
* asset: "0x5678...",
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* const client = createPublicClient({
|
|
75
|
-
* chain: bscTestnet,
|
|
76
|
-
* transport: http(),
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* const server = new X402Server({
|
|
80
|
-
* facilitator,
|
|
81
|
-
* schema,
|
|
82
|
-
* client,
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* // 初始化和校验
|
|
86
|
-
* await server.initialize();
|
|
87
|
-
*
|
|
88
|
-
* // 验证
|
|
89
|
-
* const verifyResult = await server.verify();
|
|
90
|
-
*
|
|
91
|
-
* // 结算
|
|
92
|
-
* const settleResult = await server.settle(paymentPayload, paymentRequirements);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
declare class X402Server {
|
|
96
|
-
private facilitator;
|
|
97
|
-
private schema;
|
|
98
|
-
private client;
|
|
99
|
-
private initialized;
|
|
100
|
-
constructor(config: X402ServerConfig);
|
|
101
|
-
_initialize(): Promise<InitializeResult>;
|
|
102
|
-
/**
|
|
103
|
-
* 验证配置
|
|
104
|
-
* 1. 验证 client network 是否和 schema 的 network 匹配
|
|
105
|
-
* 2. 验证 facilitator recipientAddress 和 schema payTo 是否一致
|
|
106
|
-
*/
|
|
107
|
-
_verify(): Promise<VerifyResult>;
|
|
108
|
-
/**
|
|
109
|
-
* 结算支付
|
|
110
|
-
* @param paymentPayload 支付负载
|
|
111
|
-
* @param paymentRequirements 支付要求
|
|
112
|
-
*/
|
|
113
|
-
settle(paymentPayload: any, paymentRequirements: any): Promise<SettleResult>;
|
|
114
|
-
/**
|
|
115
|
-
* 验证支付负载
|
|
116
|
-
* @param paymentPayload 支付负载
|
|
117
|
-
* @param paymentRequirements 支付要求
|
|
118
|
-
*/
|
|
119
|
-
verify(paymentPayload: any, paymentRequirements: any): Promise<{
|
|
120
|
-
success: boolean;
|
|
121
|
-
data?: string;
|
|
122
|
-
error?: string;
|
|
123
|
-
}>;
|
|
124
|
-
/**
|
|
125
|
-
* 获取 facilitator
|
|
126
|
-
*/
|
|
127
|
-
getFacilitator(): Facilitator;
|
|
128
|
-
/**
|
|
129
|
-
* 获取 schema
|
|
130
|
-
*/
|
|
131
|
-
getSchema(): X402PaymentSchema;
|
|
132
|
-
/**
|
|
133
|
-
* 获取 client
|
|
134
|
-
*/
|
|
135
|
-
getClient(): PublicClient;
|
|
136
|
-
/**
|
|
137
|
-
* 检查是否已初始化
|
|
138
|
-
*/
|
|
139
|
-
isInitialized(): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* 验证网络是否匹配
|
|
142
|
-
* @param schemaNetwork schema 中的 network
|
|
143
|
-
* @param clientChainId client 的 chainId
|
|
144
|
-
* @returns 是否匹配
|
|
145
|
-
*/
|
|
146
|
-
private validateNetwork;
|
|
147
|
-
/**
|
|
148
|
-
* 解析支付 header
|
|
149
|
-
* @param paymentHeaderBase64 Base64 编码的支付 header
|
|
150
|
-
* @returns 解析结果,成功时返回 paymentPayload 和 paymentRequirements,失败时返回服务端的支付要求
|
|
151
|
-
*/
|
|
152
|
-
parsePaymentHeader(paymentHeaderBase64: string): {
|
|
153
|
-
success: true;
|
|
154
|
-
data: {
|
|
155
|
-
paymentPayload: PaymentPayload;
|
|
156
|
-
paymentRequirements: PaymentRequirements;
|
|
157
|
-
};
|
|
158
|
-
} | {
|
|
159
|
-
success: false;
|
|
160
|
-
data: PaymentRequirements;
|
|
161
|
-
error: string;
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* 验证客户端的支付数据是否与服务端要求一致
|
|
165
|
-
* @param paymentPayload 客户端的支付负载
|
|
166
|
-
* @param paymentRequirements 服务端的支付要求
|
|
167
|
-
* @returns 错误信息,如果验证通过则返回 null
|
|
168
|
-
*/
|
|
169
|
-
private validatePaymentPayload;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Token 信息
|
|
174
|
-
*/
|
|
175
|
-
interface TokenInfo {
|
|
176
|
-
name: string;
|
|
177
|
-
version: string;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 支持的支付方式
|
|
181
|
-
*/
|
|
182
|
-
type PaymentMethod = "eip3009" | "permit" | "permit2" | "permit2-witness";
|
|
183
|
-
/**
|
|
184
|
-
* 检测结果
|
|
185
|
-
*/
|
|
186
|
-
interface TokenPaymentCapabilities {
|
|
187
|
-
address: string;
|
|
188
|
-
supportedMethods: PaymentMethod[];
|
|
189
|
-
details: {
|
|
190
|
-
hasEIP3009: boolean;
|
|
191
|
-
hasPermit: boolean;
|
|
192
|
-
hasPermit2Approval: boolean;
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* 检测代币支持的支付方式
|
|
197
|
-
* @param tokenAddress 代币地址
|
|
198
|
-
* @param client viem PublicClient
|
|
199
|
-
* @returns 检测结果
|
|
200
|
-
*/
|
|
201
|
-
declare function detectTokenPaymentMethods(tokenAddress: string, client: PublicClient): Promise<TokenPaymentCapabilities>;
|
|
202
|
-
/**
|
|
203
|
-
* 获取推荐的支付方式(仅返回 schema 支持的类型)
|
|
204
|
-
* 按优先级排序:eip3009 > permit > permit2
|
|
205
|
-
* 注意:permit2-witness 会被映射为 permit2,因为它们在 schema 中是同一种支付类型
|
|
206
|
-
*/
|
|
207
|
-
declare function getRecommendedPaymentMethod(capabilities: TokenPaymentCapabilities): "eip3009" | "permit2" | "permit" | null;
|
|
208
|
-
/**
|
|
209
|
-
* 获取 token 的 name 和 version 信息(用于 EIP-712 签名)
|
|
210
|
-
* 支持代理合约(会自动从代理合约读取,因为代理合约会 delegatecall 到实现合约)
|
|
211
|
-
* @param tokenAddress 代币地址
|
|
212
|
-
* @param client viem PublicClient
|
|
213
|
-
* @returns Token 的 name 和 version
|
|
214
|
-
*/
|
|
215
|
-
declare function getTokenInfo(tokenAddress: string, client: PublicClient): Promise<TokenInfo>;
|
|
216
|
-
|
|
217
|
-
export { type InitializeResult, type PaymentMethod, type SettleResult, type TokenInfo, type TokenPaymentCapabilities, type VerifyResult, X402Server, type X402ServerConfig, detectTokenPaymentMethods, getRecommendedPaymentMethod, getTokenInfo };
|
package/dist/index.d.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { Facilitator } from '@wtflabs/x402-facilitator';
|
|
2
|
-
import { X402PaymentSchema } from '@wtflabs/x402-schema';
|
|
3
|
-
import { PublicClient } from 'viem';
|
|
4
|
-
import { PaymentPayload, PaymentRequirements } from '@wtflabs/x402/types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* X402Server 配置选项
|
|
8
|
-
*/
|
|
9
|
-
interface X402ServerConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Facilitator 实例
|
|
12
|
-
*/
|
|
13
|
-
facilitator: Facilitator;
|
|
14
|
-
/**
|
|
15
|
-
* Payment Schema 实例
|
|
16
|
-
*/
|
|
17
|
-
schema: X402PaymentSchema;
|
|
18
|
-
/**
|
|
19
|
-
* Viem Public Client 实例
|
|
20
|
-
*/
|
|
21
|
-
client: PublicClient;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 初始化结果
|
|
25
|
-
*/
|
|
26
|
-
interface InitializeResult {
|
|
27
|
-
success: boolean;
|
|
28
|
-
error?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 验证结果
|
|
32
|
-
*/
|
|
33
|
-
interface VerifyResult {
|
|
34
|
-
success: boolean;
|
|
35
|
-
errors?: string[];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 结算结果
|
|
39
|
-
*/
|
|
40
|
-
interface SettleResult {
|
|
41
|
-
success: boolean;
|
|
42
|
-
transaction?: string;
|
|
43
|
-
error?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* X402Server 类
|
|
48
|
-
* 集成 facilitator, schema 和 client,提供完整的服务端支付处理
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { X402Server } from "@wtflabs/x402-server";
|
|
53
|
-
* import { Facilitator } from "@wtflabs/x402-facilitator";
|
|
54
|
-
* import { X402PaymentSchema } from "@wtflabs/x402-schema";
|
|
55
|
-
* import { createPublicClient, http } from "viem";
|
|
56
|
-
* import { bscTestnet } from "viem/chains";
|
|
57
|
-
*
|
|
58
|
-
* const facilitator = new Facilitator({
|
|
59
|
-
* recipientAddress: "0x1234...",
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* const schema = new X402PaymentSchema({
|
|
63
|
-
* scheme: "exact",
|
|
64
|
-
* network: "bsc-testnet",
|
|
65
|
-
* maxAmountRequired: "100000",
|
|
66
|
-
* resource: "http://localhost:3000/protected-resource",
|
|
67
|
-
* description: "Access to protected resource",
|
|
68
|
-
* mimeType: "application/json",
|
|
69
|
-
* payTo: "0x1234...",
|
|
70
|
-
* maxTimeoutSeconds: 3600,
|
|
71
|
-
* asset: "0x5678...",
|
|
72
|
-
* });
|
|
73
|
-
*
|
|
74
|
-
* const client = createPublicClient({
|
|
75
|
-
* chain: bscTestnet,
|
|
76
|
-
* transport: http(),
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* const server = new X402Server({
|
|
80
|
-
* facilitator,
|
|
81
|
-
* schema,
|
|
82
|
-
* client,
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* // 初始化和校验
|
|
86
|
-
* await server.initialize();
|
|
87
|
-
*
|
|
88
|
-
* // 验证
|
|
89
|
-
* const verifyResult = await server.verify();
|
|
90
|
-
*
|
|
91
|
-
* // 结算
|
|
92
|
-
* const settleResult = await server.settle(paymentPayload, paymentRequirements);
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
declare class X402Server {
|
|
96
|
-
private facilitator;
|
|
97
|
-
private schema;
|
|
98
|
-
private client;
|
|
99
|
-
private initialized;
|
|
100
|
-
constructor(config: X402ServerConfig);
|
|
101
|
-
_initialize(): Promise<InitializeResult>;
|
|
102
|
-
/**
|
|
103
|
-
* 验证配置
|
|
104
|
-
* 1. 验证 client network 是否和 schema 的 network 匹配
|
|
105
|
-
* 2. 验证 facilitator recipientAddress 和 schema payTo 是否一致
|
|
106
|
-
*/
|
|
107
|
-
_verify(): Promise<VerifyResult>;
|
|
108
|
-
/**
|
|
109
|
-
* 结算支付
|
|
110
|
-
* @param paymentPayload 支付负载
|
|
111
|
-
* @param paymentRequirements 支付要求
|
|
112
|
-
*/
|
|
113
|
-
settle(paymentPayload: any, paymentRequirements: any): Promise<SettleResult>;
|
|
114
|
-
/**
|
|
115
|
-
* 验证支付负载
|
|
116
|
-
* @param paymentPayload 支付负载
|
|
117
|
-
* @param paymentRequirements 支付要求
|
|
118
|
-
*/
|
|
119
|
-
verify(paymentPayload: any, paymentRequirements: any): Promise<{
|
|
120
|
-
success: boolean;
|
|
121
|
-
data?: string;
|
|
122
|
-
error?: string;
|
|
123
|
-
}>;
|
|
124
|
-
/**
|
|
125
|
-
* 获取 facilitator
|
|
126
|
-
*/
|
|
127
|
-
getFacilitator(): Facilitator;
|
|
128
|
-
/**
|
|
129
|
-
* 获取 schema
|
|
130
|
-
*/
|
|
131
|
-
getSchema(): X402PaymentSchema;
|
|
132
|
-
/**
|
|
133
|
-
* 获取 client
|
|
134
|
-
*/
|
|
135
|
-
getClient(): PublicClient;
|
|
136
|
-
/**
|
|
137
|
-
* 检查是否已初始化
|
|
138
|
-
*/
|
|
139
|
-
isInitialized(): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* 验证网络是否匹配
|
|
142
|
-
* @param schemaNetwork schema 中的 network
|
|
143
|
-
* @param clientChainId client 的 chainId
|
|
144
|
-
* @returns 是否匹配
|
|
145
|
-
*/
|
|
146
|
-
private validateNetwork;
|
|
147
|
-
/**
|
|
148
|
-
* 解析支付 header
|
|
149
|
-
* @param paymentHeaderBase64 Base64 编码的支付 header
|
|
150
|
-
* @returns 解析结果,成功时返回 paymentPayload 和 paymentRequirements,失败时返回服务端的支付要求
|
|
151
|
-
*/
|
|
152
|
-
parsePaymentHeader(paymentHeaderBase64: string): {
|
|
153
|
-
success: true;
|
|
154
|
-
data: {
|
|
155
|
-
paymentPayload: PaymentPayload;
|
|
156
|
-
paymentRequirements: PaymentRequirements;
|
|
157
|
-
};
|
|
158
|
-
} | {
|
|
159
|
-
success: false;
|
|
160
|
-
data: PaymentRequirements;
|
|
161
|
-
error: string;
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* 验证客户端的支付数据是否与服务端要求一致
|
|
165
|
-
* @param paymentPayload 客户端的支付负载
|
|
166
|
-
* @param paymentRequirements 服务端的支付要求
|
|
167
|
-
* @returns 错误信息,如果验证通过则返回 null
|
|
168
|
-
*/
|
|
169
|
-
private validatePaymentPayload;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Token 信息
|
|
174
|
-
*/
|
|
175
|
-
interface TokenInfo {
|
|
176
|
-
name: string;
|
|
177
|
-
version: string;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 支持的支付方式
|
|
181
|
-
*/
|
|
182
|
-
type PaymentMethod = "eip3009" | "permit" | "permit2" | "permit2-witness";
|
|
183
|
-
/**
|
|
184
|
-
* 检测结果
|
|
185
|
-
*/
|
|
186
|
-
interface TokenPaymentCapabilities {
|
|
187
|
-
address: string;
|
|
188
|
-
supportedMethods: PaymentMethod[];
|
|
189
|
-
details: {
|
|
190
|
-
hasEIP3009: boolean;
|
|
191
|
-
hasPermit: boolean;
|
|
192
|
-
hasPermit2Approval: boolean;
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* 检测代币支持的支付方式
|
|
197
|
-
* @param tokenAddress 代币地址
|
|
198
|
-
* @param client viem PublicClient
|
|
199
|
-
* @returns 检测结果
|
|
200
|
-
*/
|
|
201
|
-
declare function detectTokenPaymentMethods(tokenAddress: string, client: PublicClient): Promise<TokenPaymentCapabilities>;
|
|
202
|
-
/**
|
|
203
|
-
* 获取推荐的支付方式(仅返回 schema 支持的类型)
|
|
204
|
-
* 按优先级排序:eip3009 > permit > permit2
|
|
205
|
-
* 注意:permit2-witness 会被映射为 permit2,因为它们在 schema 中是同一种支付类型
|
|
206
|
-
*/
|
|
207
|
-
declare function getRecommendedPaymentMethod(capabilities: TokenPaymentCapabilities): "eip3009" | "permit2" | "permit" | null;
|
|
208
|
-
/**
|
|
209
|
-
* 获取 token 的 name 和 version 信息(用于 EIP-712 签名)
|
|
210
|
-
* 支持代理合约(会自动从代理合约读取,因为代理合约会 delegatecall 到实现合约)
|
|
211
|
-
* @param tokenAddress 代币地址
|
|
212
|
-
* @param client viem PublicClient
|
|
213
|
-
* @returns Token 的 name 和 version
|
|
214
|
-
*/
|
|
215
|
-
declare function getTokenInfo(tokenAddress: string, client: PublicClient): Promise<TokenInfo>;
|
|
216
|
-
|
|
217
|
-
export { type InitializeResult, type PaymentMethod, type SettleResult, type TokenInfo, type TokenPaymentCapabilities, type VerifyResult, X402Server, type X402ServerConfig, detectTokenPaymentMethods, getRecommendedPaymentMethod, getTokenInfo };
|