x402-evm-mantle 2.1.1-mantle
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 +183 -0
- package/dist/cjs/exact/client/index.d.ts +53 -0
- package/dist/cjs/exact/client/index.js +270 -0
- package/dist/cjs/exact/client/index.js.map +1 -0
- package/dist/cjs/exact/facilitator/index.d.ts +118 -0
- package/dist/cjs/exact/facilitator/index.js +735 -0
- package/dist/cjs/exact/facilitator/index.js.map +1 -0
- package/dist/cjs/exact/server/index.d.ts +140 -0
- package/dist/cjs/exact/server/index.js +247 -0
- package/dist/cjs/exact/server/index.js.map +1 -0
- package/dist/cjs/exact/v1/client/index.d.ts +37 -0
- package/dist/cjs/exact/v1/client/index.js +147 -0
- package/dist/cjs/exact/v1/client/index.js.map +1 -0
- package/dist/cjs/exact/v1/facilitator/index.d.ts +62 -0
- package/dist/cjs/exact/v1/facilitator/index.js +401 -0
- package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
- package/dist/cjs/index.d.ts +36 -0
- package/dist/cjs/index.js +148 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/signer-5OVDxViv.d.ts +79 -0
- package/dist/cjs/v1/index.d.ts +7 -0
- package/dist/cjs/v1/index.js +171 -0
- package/dist/cjs/v1/index.js.map +1 -0
- package/dist/esm/chunk-CYGMVQCG.mjs +88 -0
- package/dist/esm/chunk-CYGMVQCG.mjs.map +1 -0
- package/dist/esm/chunk-DI3EK7PR.mjs +305 -0
- package/dist/esm/chunk-DI3EK7PR.mjs.map +1 -0
- package/dist/esm/chunk-QLXM7BIB.mjs +23 -0
- package/dist/esm/chunk-QLXM7BIB.mjs.map +1 -0
- package/dist/esm/chunk-S5OEANGR.mjs +92 -0
- package/dist/esm/chunk-S5OEANGR.mjs.map +1 -0
- package/dist/esm/chunk-T3FPOH7F.mjs +88 -0
- package/dist/esm/chunk-T3FPOH7F.mjs.map +1 -0
- package/dist/esm/exact/client/index.d.mts +53 -0
- package/dist/esm/exact/client/index.mjs +36 -0
- package/dist/esm/exact/client/index.mjs.map +1 -0
- package/dist/esm/exact/facilitator/index.d.mts +118 -0
- package/dist/esm/exact/facilitator/index.mjs +324 -0
- package/dist/esm/exact/facilitator/index.mjs.map +1 -0
- package/dist/esm/exact/server/index.d.mts +140 -0
- package/dist/esm/exact/server/index.mjs +219 -0
- package/dist/esm/exact/server/index.mjs.map +1 -0
- package/dist/esm/exact/v1/client/index.d.mts +37 -0
- package/dist/esm/exact/v1/client/index.mjs +8 -0
- package/dist/esm/exact/v1/client/index.mjs.map +1 -0
- package/dist/esm/exact/v1/facilitator/index.d.mts +62 -0
- package/dist/esm/exact/v1/facilitator/index.mjs +8 -0
- package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
- package/dist/esm/index.d.mts +36 -0
- package/dist/esm/index.mjs +21 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/signer-5OVDxViv.d.mts +79 -0
- package/dist/esm/v1/index.d.mts +7 -0
- package/dist/esm/v1/index.mjs +13 -0
- package/dist/esm/v1/index.mjs.map +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from 'x402-core-mantle/types';
|
|
2
|
+
import { x402ResourceServer } from 'x402-core-mantle/server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EVM server implementation for the Exact payment scheme.
|
|
6
|
+
*/
|
|
7
|
+
declare class ExactEvmScheme implements SchemeNetworkServer {
|
|
8
|
+
readonly scheme = "exact";
|
|
9
|
+
private moneyParsers;
|
|
10
|
+
/**
|
|
11
|
+
* Register a custom money parser in the parser chain.
|
|
12
|
+
* Multiple parsers can be registered - they will be tried in registration order.
|
|
13
|
+
* Each parser receives a decimal amount (e.g., 1.50 for $1.50).
|
|
14
|
+
* If a parser returns null, the next parser in the chain will be tried.
|
|
15
|
+
* The default parser is always the final fallback.
|
|
16
|
+
*
|
|
17
|
+
* @param parser - Custom function to convert amount to AssetAmount (or null to skip)
|
|
18
|
+
* @returns The server instance for chaining
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* evmServer.registerMoneyParser(async (amount, network) => {
|
|
22
|
+
* // Custom conversion logic
|
|
23
|
+
* if (amount > 100) {
|
|
24
|
+
* // Use different token for large amounts
|
|
25
|
+
* return { amount: (amount * 1e18).toString(), asset: "0xCustomToken" };
|
|
26
|
+
* }
|
|
27
|
+
* return null; // Use next parser
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
registerMoneyParser(parser: MoneyParser): ExactEvmScheme;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a price into an asset amount.
|
|
33
|
+
* If price is already an AssetAmount, returns it directly.
|
|
34
|
+
* If price is Money (string | number), parses to decimal and tries custom parsers.
|
|
35
|
+
* Falls back to default conversion if all custom parsers return null.
|
|
36
|
+
*
|
|
37
|
+
* @param price - The price to parse
|
|
38
|
+
* @param network - The network to use
|
|
39
|
+
* @returns Promise that resolves to the parsed asset amount
|
|
40
|
+
*/
|
|
41
|
+
parsePrice(price: Price, network: Network): Promise<AssetAmount>;
|
|
42
|
+
/**
|
|
43
|
+
* Build payment requirements for this scheme/network combination
|
|
44
|
+
*
|
|
45
|
+
* @param paymentRequirements - The base payment requirements
|
|
46
|
+
* @param supportedKind - The supported kind from facilitator (unused)
|
|
47
|
+
* @param supportedKind.x402Version - The x402 version
|
|
48
|
+
* @param supportedKind.scheme - The logical payment scheme
|
|
49
|
+
* @param supportedKind.network - The network identifier in CAIP-2 format
|
|
50
|
+
* @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details
|
|
51
|
+
* @param extensionKeys - Extension keys supported by the facilitator (unused)
|
|
52
|
+
* @returns Payment requirements ready to be sent to clients
|
|
53
|
+
*/
|
|
54
|
+
enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
|
|
55
|
+
x402Version: number;
|
|
56
|
+
scheme: string;
|
|
57
|
+
network: Network;
|
|
58
|
+
extra?: Record<string, unknown>;
|
|
59
|
+
}, extensionKeys: string[]): Promise<PaymentRequirements>;
|
|
60
|
+
/**
|
|
61
|
+
* Parse Money (string | number) to a decimal number.
|
|
62
|
+
* Handles formats like "$1.50", "1.50", 1.50, etc.
|
|
63
|
+
*
|
|
64
|
+
* @param money - The money value to parse
|
|
65
|
+
* @returns Decimal number
|
|
66
|
+
*/
|
|
67
|
+
private parseMoneyToDecimal;
|
|
68
|
+
/**
|
|
69
|
+
* Default money conversion implementation.
|
|
70
|
+
* Converts decimal amount to USDC on the specified network.
|
|
71
|
+
*
|
|
72
|
+
* @param amount - The decimal amount (e.g., 1.50)
|
|
73
|
+
* @param network - The network to use
|
|
74
|
+
* @returns The parsed asset amount in USDC
|
|
75
|
+
*/
|
|
76
|
+
private defaultMoneyConversion;
|
|
77
|
+
/**
|
|
78
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)
|
|
79
|
+
*
|
|
80
|
+
* @param decimalAmount - The decimal amount to convert
|
|
81
|
+
* @param network - The network to use
|
|
82
|
+
* @returns The token amount as a string
|
|
83
|
+
*/
|
|
84
|
+
private convertToTokenAmount;
|
|
85
|
+
/**
|
|
86
|
+
* Get the default asset info for a network (typically USDC)
|
|
87
|
+
*
|
|
88
|
+
* @param network - The network to get asset info for
|
|
89
|
+
* @returns The asset information including address, name, and version
|
|
90
|
+
*/
|
|
91
|
+
private getDefaultAsset;
|
|
92
|
+
/**
|
|
93
|
+
* Get asset info for a given symbol on a network
|
|
94
|
+
*
|
|
95
|
+
* @param symbol - The asset symbol
|
|
96
|
+
* @param network - The network to use
|
|
97
|
+
* @returns The asset information including address, name, and version
|
|
98
|
+
*/
|
|
99
|
+
private getAssetInfo;
|
|
100
|
+
/**
|
|
101
|
+
* Get the number of decimals for the asset
|
|
102
|
+
*
|
|
103
|
+
* @param _ - The network to use (unused)
|
|
104
|
+
* @returns The number of decimals for the asset
|
|
105
|
+
*/
|
|
106
|
+
private getAssetDecimals;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Configuration options for registering EVM schemes to an x402ResourceServer
|
|
111
|
+
*/
|
|
112
|
+
interface EvmResourceServerConfig {
|
|
113
|
+
/**
|
|
114
|
+
* Optional specific networks to register
|
|
115
|
+
* If not provided, registers wildcard support (eip155:*)
|
|
116
|
+
*/
|
|
117
|
+
networks?: Network[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Registers EVM exact payment schemes to an x402ResourceServer instance.
|
|
121
|
+
*
|
|
122
|
+
* This function registers:
|
|
123
|
+
* - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)
|
|
124
|
+
*
|
|
125
|
+
* @param server - The x402ResourceServer instance to register schemes to
|
|
126
|
+
* @param config - Configuration for EVM resource server registration
|
|
127
|
+
* @returns The server instance for chaining
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { registerExactEvmScheme } from "@x402/evm/exact/server/register";
|
|
132
|
+
* import { x402ResourceServer } from "x402-core-mantle/server";
|
|
133
|
+
*
|
|
134
|
+
* const server = new x402ResourceServer(facilitatorClient);
|
|
135
|
+
* registerExactEvmScheme(server, {});
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function registerExactEvmScheme(server: x402ResourceServer, config?: EvmResourceServerConfig): x402ResourceServer;
|
|
139
|
+
|
|
140
|
+
export { type EvmResourceServerConfig, ExactEvmScheme, registerExactEvmScheme };
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// src/exact/server/scheme.ts
|
|
2
|
+
var ExactEvmScheme = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.scheme = "exact";
|
|
5
|
+
this.moneyParsers = [];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Register a custom money parser in the parser chain.
|
|
9
|
+
* Multiple parsers can be registered - they will be tried in registration order.
|
|
10
|
+
* Each parser receives a decimal amount (e.g., 1.50 for $1.50).
|
|
11
|
+
* If a parser returns null, the next parser in the chain will be tried.
|
|
12
|
+
* The default parser is always the final fallback.
|
|
13
|
+
*
|
|
14
|
+
* @param parser - Custom function to convert amount to AssetAmount (or null to skip)
|
|
15
|
+
* @returns The server instance for chaining
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* evmServer.registerMoneyParser(async (amount, network) => {
|
|
19
|
+
* // Custom conversion logic
|
|
20
|
+
* if (amount > 100) {
|
|
21
|
+
* // Use different token for large amounts
|
|
22
|
+
* return { amount: (amount * 1e18).toString(), asset: "0xCustomToken" };
|
|
23
|
+
* }
|
|
24
|
+
* return null; // Use next parser
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
registerMoneyParser(parser) {
|
|
28
|
+
this.moneyParsers.push(parser);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses a price into an asset amount.
|
|
33
|
+
* If price is already an AssetAmount, returns it directly.
|
|
34
|
+
* If price is Money (string | number), parses to decimal and tries custom parsers.
|
|
35
|
+
* Falls back to default conversion if all custom parsers return null.
|
|
36
|
+
*
|
|
37
|
+
* @param price - The price to parse
|
|
38
|
+
* @param network - The network to use
|
|
39
|
+
* @returns Promise that resolves to the parsed asset amount
|
|
40
|
+
*/
|
|
41
|
+
async parsePrice(price, network) {
|
|
42
|
+
if (typeof price === "object" && price !== null && "amount" in price) {
|
|
43
|
+
if (!price.asset) {
|
|
44
|
+
throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
amount: price.amount,
|
|
48
|
+
asset: price.asset,
|
|
49
|
+
extra: price.extra || {}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const amount = this.parseMoneyToDecimal(price);
|
|
53
|
+
for (const parser of this.moneyParsers) {
|
|
54
|
+
const result = await parser(amount, network);
|
|
55
|
+
if (result !== null) {
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return this.defaultMoneyConversion(amount, network);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build payment requirements for this scheme/network combination
|
|
63
|
+
*
|
|
64
|
+
* @param paymentRequirements - The base payment requirements
|
|
65
|
+
* @param supportedKind - The supported kind from facilitator (unused)
|
|
66
|
+
* @param supportedKind.x402Version - The x402 version
|
|
67
|
+
* @param supportedKind.scheme - The logical payment scheme
|
|
68
|
+
* @param supportedKind.network - The network identifier in CAIP-2 format
|
|
69
|
+
* @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details
|
|
70
|
+
* @param extensionKeys - Extension keys supported by the facilitator (unused)
|
|
71
|
+
* @returns Payment requirements ready to be sent to clients
|
|
72
|
+
*/
|
|
73
|
+
enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
|
|
74
|
+
void supportedKind;
|
|
75
|
+
void extensionKeys;
|
|
76
|
+
return Promise.resolve(paymentRequirements);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parse Money (string | number) to a decimal number.
|
|
80
|
+
* Handles formats like "$1.50", "1.50", 1.50, etc.
|
|
81
|
+
*
|
|
82
|
+
* @param money - The money value to parse
|
|
83
|
+
* @returns Decimal number
|
|
84
|
+
*/
|
|
85
|
+
parseMoneyToDecimal(money) {
|
|
86
|
+
if (typeof money === "number") {
|
|
87
|
+
return money;
|
|
88
|
+
}
|
|
89
|
+
const cleanMoney = money.replace(/^\$/, "").trim();
|
|
90
|
+
const amount = parseFloat(cleanMoney);
|
|
91
|
+
if (isNaN(amount)) {
|
|
92
|
+
throw new Error(`Invalid money format: ${money}`);
|
|
93
|
+
}
|
|
94
|
+
return amount;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Default money conversion implementation.
|
|
98
|
+
* Converts decimal amount to USDC on the specified network.
|
|
99
|
+
*
|
|
100
|
+
* @param amount - The decimal amount (e.g., 1.50)
|
|
101
|
+
* @param network - The network to use
|
|
102
|
+
* @returns The parsed asset amount in USDC
|
|
103
|
+
*/
|
|
104
|
+
defaultMoneyConversion(amount, network) {
|
|
105
|
+
const tokenAmount = this.convertToTokenAmount(amount.toString(), network);
|
|
106
|
+
const assetInfo = this.getDefaultAsset(network);
|
|
107
|
+
return {
|
|
108
|
+
amount: tokenAmount,
|
|
109
|
+
asset: assetInfo.address,
|
|
110
|
+
extra: {
|
|
111
|
+
name: assetInfo.name,
|
|
112
|
+
version: assetInfo.version
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)
|
|
118
|
+
*
|
|
119
|
+
* @param decimalAmount - The decimal amount to convert
|
|
120
|
+
* @param network - The network to use
|
|
121
|
+
* @returns The token amount as a string
|
|
122
|
+
*/
|
|
123
|
+
convertToTokenAmount(decimalAmount, network) {
|
|
124
|
+
const decimals = this.getAssetDecimals(network);
|
|
125
|
+
const amount = parseFloat(decimalAmount);
|
|
126
|
+
if (isNaN(amount)) {
|
|
127
|
+
throw new Error(`Invalid amount: ${decimalAmount}`);
|
|
128
|
+
}
|
|
129
|
+
const [intPart, decPart = ""] = String(amount).split(".");
|
|
130
|
+
const paddedDec = decPart.padEnd(decimals, "0").slice(0, decimals);
|
|
131
|
+
const tokenAmount = (intPart + paddedDec).replace(/^0+/, "") || "0";
|
|
132
|
+
return tokenAmount;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the default asset info for a network (typically USDC)
|
|
136
|
+
*
|
|
137
|
+
* @param network - The network to get asset info for
|
|
138
|
+
* @returns The asset information including address, name, and version
|
|
139
|
+
*/
|
|
140
|
+
getDefaultAsset(network) {
|
|
141
|
+
const usdcInfo = {
|
|
142
|
+
"eip155:8453": {
|
|
143
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
144
|
+
name: "USD Coin",
|
|
145
|
+
version: "2"
|
|
146
|
+
},
|
|
147
|
+
// Base mainnet USDC
|
|
148
|
+
"eip155:84532": {
|
|
149
|
+
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
150
|
+
name: "USDC",
|
|
151
|
+
version: "2"
|
|
152
|
+
},
|
|
153
|
+
// Base Sepolia USDC
|
|
154
|
+
"eip155:1": {
|
|
155
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
156
|
+
name: "USD Coin",
|
|
157
|
+
version: "2"
|
|
158
|
+
},
|
|
159
|
+
// Ethereum mainnet USDC
|
|
160
|
+
"eip155:11155111": {
|
|
161
|
+
address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
162
|
+
name: "USDC",
|
|
163
|
+
version: "2"
|
|
164
|
+
},
|
|
165
|
+
// Sepolia USDC
|
|
166
|
+
"eip155:5003": {
|
|
167
|
+
address: "0x3D884Eca2a1E65A41Cd54b1CF55537dAe35d7BDC",
|
|
168
|
+
name: "USDC Token",
|
|
169
|
+
version: "1"
|
|
170
|
+
}
|
|
171
|
+
// Mantle testnet USDC
|
|
172
|
+
};
|
|
173
|
+
const assetInfo = usdcInfo[network];
|
|
174
|
+
if (!assetInfo) {
|
|
175
|
+
throw new Error(`No default asset configured for network ${network}`);
|
|
176
|
+
}
|
|
177
|
+
return assetInfo;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get asset info for a given symbol on a network
|
|
181
|
+
*
|
|
182
|
+
* @param symbol - The asset symbol
|
|
183
|
+
* @param network - The network to use
|
|
184
|
+
* @returns The asset information including address, name, and version
|
|
185
|
+
*/
|
|
186
|
+
getAssetInfo(symbol, network) {
|
|
187
|
+
const upperSymbol = symbol.toUpperCase();
|
|
188
|
+
if (upperSymbol === "USDC" || upperSymbol === "USD") {
|
|
189
|
+
return this.getDefaultAsset(network);
|
|
190
|
+
}
|
|
191
|
+
throw new Error(`Unsupported asset: ${symbol} on network ${network}`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the number of decimals for the asset
|
|
195
|
+
*
|
|
196
|
+
* @param _ - The network to use (unused)
|
|
197
|
+
* @returns The number of decimals for the asset
|
|
198
|
+
*/
|
|
199
|
+
getAssetDecimals(_) {
|
|
200
|
+
return 6;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/exact/server/register.ts
|
|
205
|
+
function registerExactEvmScheme(server, config = {}) {
|
|
206
|
+
if (config.networks && config.networks.length > 0) {
|
|
207
|
+
config.networks.forEach((network) => {
|
|
208
|
+
server.register(network, new ExactEvmScheme());
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
server.register("eip155:*", new ExactEvmScheme());
|
|
212
|
+
}
|
|
213
|
+
return server;
|
|
214
|
+
}
|
|
215
|
+
export {
|
|
216
|
+
ExactEvmScheme,
|
|
217
|
+
registerExactEvmScheme
|
|
218
|
+
};
|
|
219
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"x402-core-mantle/types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to USDC on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in USDC\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n // Convert decimal amount to token amount (USDC has 6 decimals)\n const tokenAmount = this.convertToTokenAmount(amount.toString(), network);\n const assetInfo = this.getDefaultAsset(network);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param network - The network to use\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, network: Network): string {\n const decimals = this.getAssetDecimals(network);\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n }\n\n /**\n * Get the default asset info for a network (typically USDC)\n *\n * @param network - The network to get asset info for\n * @returns The asset information including address, name, and version\n */\n private getDefaultAsset(network: Network): { address: string; name: string; version: string } {\n // Map of network to USDC info including EIP-712 domain parameters\n const usdcInfo: Record<string, { address: string; name: string; version: string }> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n }, // Base Sepolia USDC\n \"eip155:1\": {\n address: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Ethereum mainnet USDC\n \"eip155:11155111\": {\n address: \"0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238\",\n name: \"USDC\",\n version: \"2\",\n }, // Sepolia USDC\n \"eip155:5003\": {\n address: \"0x3D884Eca2a1E65A41Cd54b1CF55537dAe35d7BDC\",\n name: \"USDC Token\",\n version: \"1\",\n }, // Mantle testnet USDC\n };\n\n const assetInfo = usdcInfo[network];\n if (!assetInfo) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n\n return assetInfo;\n }\n\n /**\n * Get asset info for a given symbol on a network\n *\n * @param symbol - The asset symbol\n * @param network - The network to use\n * @returns The asset information including address, name, and version\n */\n private getAssetInfo(\n symbol: string,\n network: Network,\n ): { address: string; name: string; version: string } {\n const upperSymbol = symbol.toUpperCase();\n\n // For now, only support USDC\n if (upperSymbol === \"USDC\" || upperSymbol === \"USD\") {\n return this.getDefaultAsset(network);\n }\n\n // Could extend to support other tokens\n throw new Error(`Unsupported asset: ${symbol} on network ${network}`);\n }\n\n /**\n * Get the number of decimals for the asset\n *\n * @param _ - The network to use (unused)\n * @returns The number of decimals for the asset\n */\n private getAssetDecimals(_: Network): number {\n // USDC has 6 decimals on all EVM chains\n return 6;\n }\n}\n","import { x402ResourceServer } from \"x402-core-mantle/server\";\nimport { Network } from \"x402-core-mantle/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"x402-core-mantle/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from 'x402-core-mantle/types';
|
|
2
|
+
import { C as ClientEvmSigner } from '../../../signer-5OVDxViv.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EVM client implementation for the Exact payment scheme (V1).
|
|
6
|
+
*/
|
|
7
|
+
declare class ExactEvmSchemeV1 implements SchemeNetworkClient {
|
|
8
|
+
private readonly signer;
|
|
9
|
+
readonly scheme = "exact";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new ExactEvmClientV1 instance.
|
|
12
|
+
*
|
|
13
|
+
* @param signer - The EVM signer for client operations
|
|
14
|
+
*/
|
|
15
|
+
constructor(signer: ClientEvmSigner);
|
|
16
|
+
/**
|
|
17
|
+
* Creates a payment payload for the Exact scheme (V1).
|
|
18
|
+
*
|
|
19
|
+
* @param x402Version - The x402 protocol version
|
|
20
|
+
* @param paymentRequirements - The payment requirements
|
|
21
|
+
* @returns Promise resolving to a payment payload
|
|
22
|
+
*/
|
|
23
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload"> & {
|
|
24
|
+
scheme: string;
|
|
25
|
+
network: Network;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Sign the EIP-3009 authorization using EIP-712
|
|
29
|
+
*
|
|
30
|
+
* @param authorization - The authorization to sign
|
|
31
|
+
* @param requirements - The payment requirements
|
|
32
|
+
* @returns Promise resolving to the signature
|
|
33
|
+
*/
|
|
34
|
+
private signAuthorization;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { ExactEvmSchemeV1 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse } from 'x402-core-mantle/types';
|
|
2
|
+
import { F as FacilitatorEvmSigner } from '../../../signer-5OVDxViv.mjs';
|
|
3
|
+
|
|
4
|
+
interface ExactEvmSchemeV1Config {
|
|
5
|
+
/**
|
|
6
|
+
* If enabled, the facilitator will deploy ERC-4337 smart wallets
|
|
7
|
+
* via EIP-6492 when encountering undeployed contract signatures.
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
deployERC4337WithEIP6492?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* EVM facilitator implementation for the Exact payment scheme (V1).
|
|
15
|
+
*/
|
|
16
|
+
declare class ExactEvmSchemeV1 implements SchemeNetworkFacilitator {
|
|
17
|
+
private readonly signer;
|
|
18
|
+
readonly scheme = "exact";
|
|
19
|
+
readonly caipFamily = "eip155:*";
|
|
20
|
+
private readonly config;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ExactEvmFacilitatorV1 instance.
|
|
23
|
+
*
|
|
24
|
+
* @param signer - The EVM signer for facilitator operations
|
|
25
|
+
* @param config - Optional configuration for the facilitator
|
|
26
|
+
*/
|
|
27
|
+
constructor(signer: FacilitatorEvmSigner, config?: ExactEvmSchemeV1Config);
|
|
28
|
+
/**
|
|
29
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
30
|
+
* For EVM, no extra data is needed.
|
|
31
|
+
*
|
|
32
|
+
* @param _ - The network identifier (unused for EVM)
|
|
33
|
+
* @returns undefined (EVM has no extra data)
|
|
34
|
+
*/
|
|
35
|
+
getExtra(_: string): Record<string, unknown> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Get signer addresses used by this facilitator.
|
|
38
|
+
* Returns all addresses this facilitator can use for signing/settling transactions.
|
|
39
|
+
*
|
|
40
|
+
* @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
|
|
41
|
+
* @returns Array of facilitator wallet addresses
|
|
42
|
+
*/
|
|
43
|
+
getSigners(_: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Verifies a payment payload (V1).
|
|
46
|
+
*
|
|
47
|
+
* @param payload - The payment payload to verify
|
|
48
|
+
* @param requirements - The payment requirements
|
|
49
|
+
* @returns Promise resolving to verification response
|
|
50
|
+
*/
|
|
51
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Settles a payment by executing the transfer (V1).
|
|
54
|
+
*
|
|
55
|
+
* @param payload - The payment payload to settle
|
|
56
|
+
* @param requirements - The payment requirements
|
|
57
|
+
* @returns Promise resolving to settlement response
|
|
58
|
+
*/
|
|
59
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { ExactEvmSchemeV1, type ExactEvmSchemeV1Config };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SchemeNetworkClient, PaymentRequirements, PaymentPayload } from 'x402-core-mantle/types';
|
|
2
|
+
import { C as ClientEvmSigner } from './signer-5OVDxViv.mjs';
|
|
3
|
+
export { F as FacilitatorEvmSigner, t as toClientEvmSigner, a as toFacilitatorEvmSigner } from './signer-5OVDxViv.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* EVM client implementation for the Exact payment scheme.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
declare class ExactEvmScheme implements SchemeNetworkClient {
|
|
10
|
+
private readonly signer;
|
|
11
|
+
readonly scheme = "exact";
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new ExactEvmClient instance.
|
|
14
|
+
*
|
|
15
|
+
* @param signer - The EVM signer for client operations
|
|
16
|
+
*/
|
|
17
|
+
constructor(signer: ClientEvmSigner);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a payment payload for the Exact scheme.
|
|
20
|
+
*
|
|
21
|
+
* @param x402Version - The x402 protocol version
|
|
22
|
+
* @param paymentRequirements - The payment requirements
|
|
23
|
+
* @returns Promise resolving to a payment payload
|
|
24
|
+
*/
|
|
25
|
+
createPaymentPayload(x402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "x402Version" | "payload">>;
|
|
26
|
+
/**
|
|
27
|
+
* Sign the EIP-3009 authorization using EIP-712
|
|
28
|
+
*
|
|
29
|
+
* @param authorization - The authorization to sign
|
|
30
|
+
* @param requirements - The payment requirements
|
|
31
|
+
* @returns Promise resolving to the signature
|
|
32
|
+
*/
|
|
33
|
+
private signAuthorization;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { ClientEvmSigner, ExactEvmScheme };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExactEvmScheme
|
|
3
|
+
} from "./chunk-T3FPOH7F.mjs";
|
|
4
|
+
import "./chunk-CYGMVQCG.mjs";
|
|
5
|
+
|
|
6
|
+
// src/signer.ts
|
|
7
|
+
function toClientEvmSigner(signer) {
|
|
8
|
+
return signer;
|
|
9
|
+
}
|
|
10
|
+
function toFacilitatorEvmSigner(client) {
|
|
11
|
+
return {
|
|
12
|
+
...client,
|
|
13
|
+
getAddresses: () => [client.address]
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
ExactEvmScheme,
|
|
18
|
+
toClientEvmSigner,
|
|
19
|
+
toFacilitatorEvmSigner
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/signer.ts"],"sourcesContent":["/**\n * ClientEvmSigner - Used by x402 clients to sign payment authorizations\n * This is typically a LocalAccount or wallet that holds private keys\n * and can sign EIP-712 typed data for payment authorizations\n */\nexport type ClientEvmSigner = {\n readonly address: `0x${string}`;\n signTypedData(message: {\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<`0x${string}`>;\n};\n\n/**\n * FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments\n * This is typically a viem PublicClient + WalletClient combination that can\n * read contract state, verify signatures, write transactions, and wait for receipts\n *\n * Supports multiple addresses for load balancing, key rotation, and high availability\n */\nexport type FacilitatorEvmSigner = {\n /**\n * Get all addresses this facilitator can use for signing\n * Enables dynamic address selection for load balancing and key rotation\n */\n getAddresses(): readonly `0x${string}`[];\n\n readContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args?: readonly unknown[];\n }): Promise<unknown>;\n verifyTypedData(args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }): Promise<boolean>;\n writeContract(args: {\n address: `0x${string}`;\n abi: readonly unknown[];\n functionName: string;\n args: readonly unknown[];\n }): Promise<`0x${string}`>;\n sendTransaction(args: { to: `0x${string}`; data: `0x${string}` }): Promise<`0x${string}`>;\n waitForTransactionReceipt(args: { hash: `0x${string}` }): Promise<{ status: string }>;\n getCode(args: { address: `0x${string}` }): Promise<`0x${string}` | undefined>;\n};\n\n/**\n * Converts a signer to a ClientEvmSigner\n *\n * @param signer - The signer to convert to a ClientEvmSigner\n * @returns The converted signer\n */\nexport function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner {\n return signer;\n}\n\n/**\n * Converts a viem client with single address to a FacilitatorEvmSigner\n * Wraps the single address in a getAddresses() function for compatibility\n *\n * @param client - The client to convert (must have 'address' property)\n * @returns FacilitatorEvmSigner with getAddresses() support\n */\nexport function toFacilitatorEvmSigner(\n client: Omit<FacilitatorEvmSigner, \"getAddresses\"> & { address: `0x${string}` },\n): FacilitatorEvmSigner {\n return {\n ...client,\n getAddresses: () => [client.address],\n };\n}\n"],"mappings":";;;;;;AA4DO,SAAS,kBAAkB,QAA0C;AAC1E,SAAO;AACT;AASO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,MAAM,CAAC,OAAO,OAAO;AAAA,EACrC;AACF;","names":[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClientEvmSigner - Used by x402 clients to sign payment authorizations
|
|
3
|
+
* This is typically a LocalAccount or wallet that holds private keys
|
|
4
|
+
* and can sign EIP-712 typed data for payment authorizations
|
|
5
|
+
*/
|
|
6
|
+
type ClientEvmSigner = {
|
|
7
|
+
readonly address: `0x${string}`;
|
|
8
|
+
signTypedData(message: {
|
|
9
|
+
domain: Record<string, unknown>;
|
|
10
|
+
types: Record<string, unknown>;
|
|
11
|
+
primaryType: string;
|
|
12
|
+
message: Record<string, unknown>;
|
|
13
|
+
}): Promise<`0x${string}`>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* FacilitatorEvmSigner - Used by x402 facilitators to verify and settle payments
|
|
17
|
+
* This is typically a viem PublicClient + WalletClient combination that can
|
|
18
|
+
* read contract state, verify signatures, write transactions, and wait for receipts
|
|
19
|
+
*
|
|
20
|
+
* Supports multiple addresses for load balancing, key rotation, and high availability
|
|
21
|
+
*/
|
|
22
|
+
type FacilitatorEvmSigner = {
|
|
23
|
+
/**
|
|
24
|
+
* Get all addresses this facilitator can use for signing
|
|
25
|
+
* Enables dynamic address selection for load balancing and key rotation
|
|
26
|
+
*/
|
|
27
|
+
getAddresses(): readonly `0x${string}`[];
|
|
28
|
+
readContract(args: {
|
|
29
|
+
address: `0x${string}`;
|
|
30
|
+
abi: readonly unknown[];
|
|
31
|
+
functionName: string;
|
|
32
|
+
args?: readonly unknown[];
|
|
33
|
+
}): Promise<unknown>;
|
|
34
|
+
verifyTypedData(args: {
|
|
35
|
+
address: `0x${string}`;
|
|
36
|
+
domain: Record<string, unknown>;
|
|
37
|
+
types: Record<string, unknown>;
|
|
38
|
+
primaryType: string;
|
|
39
|
+
message: Record<string, unknown>;
|
|
40
|
+
signature: `0x${string}`;
|
|
41
|
+
}): Promise<boolean>;
|
|
42
|
+
writeContract(args: {
|
|
43
|
+
address: `0x${string}`;
|
|
44
|
+
abi: readonly unknown[];
|
|
45
|
+
functionName: string;
|
|
46
|
+
args: readonly unknown[];
|
|
47
|
+
}): Promise<`0x${string}`>;
|
|
48
|
+
sendTransaction(args: {
|
|
49
|
+
to: `0x${string}`;
|
|
50
|
+
data: `0x${string}`;
|
|
51
|
+
}): Promise<`0x${string}`>;
|
|
52
|
+
waitForTransactionReceipt(args: {
|
|
53
|
+
hash: `0x${string}`;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
status: string;
|
|
56
|
+
}>;
|
|
57
|
+
getCode(args: {
|
|
58
|
+
address: `0x${string}`;
|
|
59
|
+
}): Promise<`0x${string}` | undefined>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Converts a signer to a ClientEvmSigner
|
|
63
|
+
*
|
|
64
|
+
* @param signer - The signer to convert to a ClientEvmSigner
|
|
65
|
+
* @returns The converted signer
|
|
66
|
+
*/
|
|
67
|
+
declare function toClientEvmSigner(signer: ClientEvmSigner): ClientEvmSigner;
|
|
68
|
+
/**
|
|
69
|
+
* Converts a viem client with single address to a FacilitatorEvmSigner
|
|
70
|
+
* Wraps the single address in a getAddresses() function for compatibility
|
|
71
|
+
*
|
|
72
|
+
* @param client - The client to convert (must have 'address' property)
|
|
73
|
+
* @returns FacilitatorEvmSigner with getAddresses() support
|
|
74
|
+
*/
|
|
75
|
+
declare function toFacilitatorEvmSigner(client: Omit<FacilitatorEvmSigner, "getAddresses"> & {
|
|
76
|
+
address: `0x${string}`;
|
|
77
|
+
}): FacilitatorEvmSigner;
|
|
78
|
+
|
|
79
|
+
export { type ClientEvmSigner as C, type FacilitatorEvmSigner as F, toFacilitatorEvmSigner as a, toClientEvmSigner as t };
|