@t402/evm 2.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 +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 +36 -0
- package/dist/cjs/exact/server/index.js +438 -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 +1537 -0
- package/dist/cjs/index.js +2368 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/scheme-C6uD7PdY.d.ts +130 -0
- package/dist/cjs/scheme-OojTBKAz.d.ts +35 -0
- package/dist/cjs/scheme-yqGaK9rK.d.ts +130 -0
- package/dist/cjs/signer-BkcAzwYi.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-ACDQ5QNT.mjs +305 -0
- package/dist/esm/chunk-ACDQ5QNT.mjs.map +1 -0
- package/dist/esm/chunk-JBWWBRYY.mjs +92 -0
- package/dist/esm/chunk-JBWWBRYY.mjs.map +1 -0
- package/dist/esm/chunk-LGSG73NJ.mjs +88 -0
- package/dist/esm/chunk-LGSG73NJ.mjs.map +1 -0
- package/dist/esm/chunk-OEXW2OK2.mjs +251 -0
- package/dist/esm/chunk-OEXW2OK2.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-XYKAO6KJ.mjs +141 -0
- package/dist/esm/chunk-XYKAO6KJ.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 +36 -0
- package/dist/esm/exact/server/index.mjs +218 -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 +1537 -0
- package/dist/esm/index.mjs +1875 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/scheme-D4mOqq9l.d.mts +35 -0
- package/dist/esm/scheme-yqGaK9rK.d.mts +130 -0
- package/dist/esm/signer-BkcAzwYi.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,118 @@
|
|
|
1
|
+
import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, Network } from '@t402/core/types';
|
|
2
|
+
import { F as FacilitatorEvmSigner } from '../../signer-BkcAzwYi.mjs';
|
|
3
|
+
import { t402Facilitator } from '@t402/core/facilitator';
|
|
4
|
+
|
|
5
|
+
interface ExactEvmSchemeConfig {
|
|
6
|
+
/**
|
|
7
|
+
* If enabled, the facilitator will deploy ERC-4337 smart wallets
|
|
8
|
+
* via EIP-6492 when encountering undeployed contract signatures.
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
deployERC4337WithEIP6492?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* EVM facilitator implementation for the Exact payment scheme.
|
|
16
|
+
*/
|
|
17
|
+
declare class ExactEvmScheme implements SchemeNetworkFacilitator {
|
|
18
|
+
private readonly signer;
|
|
19
|
+
readonly scheme = "exact";
|
|
20
|
+
readonly caipFamily = "eip155:*";
|
|
21
|
+
private readonly config;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new ExactEvmFacilitator instance.
|
|
24
|
+
*
|
|
25
|
+
* @param signer - The EVM signer for facilitator operations
|
|
26
|
+
* @param config - Optional configuration for the facilitator
|
|
27
|
+
*/
|
|
28
|
+
constructor(signer: FacilitatorEvmSigner, config?: ExactEvmSchemeConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
31
|
+
* For EVM, no extra data is needed.
|
|
32
|
+
*
|
|
33
|
+
* @param _ - The network identifier (unused for EVM)
|
|
34
|
+
* @returns undefined (EVM has no extra data)
|
|
35
|
+
*/
|
|
36
|
+
getExtra(_: string): Record<string, unknown> | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get signer addresses used by this facilitator.
|
|
39
|
+
* Returns all addresses this facilitator can use for signing/settling transactions.
|
|
40
|
+
*
|
|
41
|
+
* @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
|
|
42
|
+
* @returns Array of facilitator wallet addresses
|
|
43
|
+
*/
|
|
44
|
+
getSigners(_: string): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Verifies a payment payload.
|
|
47
|
+
*
|
|
48
|
+
* @param payload - The payment payload to verify
|
|
49
|
+
* @param requirements - The payment requirements
|
|
50
|
+
* @returns Promise resolving to verification response
|
|
51
|
+
*/
|
|
52
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Settles a payment by executing the transfer.
|
|
55
|
+
*
|
|
56
|
+
* @param payload - The payment payload to settle
|
|
57
|
+
* @param requirements - The payment requirements
|
|
58
|
+
* @returns Promise resolving to settlement response
|
|
59
|
+
*/
|
|
60
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Configuration options for registering EVM schemes to an t402Facilitator
|
|
65
|
+
*/
|
|
66
|
+
interface EvmFacilitatorConfig {
|
|
67
|
+
/**
|
|
68
|
+
* The EVM signer for facilitator operations (verify and settle)
|
|
69
|
+
*/
|
|
70
|
+
signer: FacilitatorEvmSigner;
|
|
71
|
+
/**
|
|
72
|
+
* Networks to register (single network or array of networks)
|
|
73
|
+
* Examples: "eip155:84532", ["eip155:84532", "eip155:1"]
|
|
74
|
+
*/
|
|
75
|
+
networks: Network | Network[];
|
|
76
|
+
/**
|
|
77
|
+
* If enabled, the facilitator will deploy ERC-4337 smart wallets
|
|
78
|
+
* via EIP-6492 when encountering undeployed contract signatures.
|
|
79
|
+
*
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
deployERC4337WithEIP6492?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Registers EVM exact payment schemes to an t402Facilitator instance.
|
|
86
|
+
*
|
|
87
|
+
* This function registers:
|
|
88
|
+
* - V2: Specified networks with ExactEvmScheme
|
|
89
|
+
* - V1: All supported EVM networks with ExactEvmSchemeV1
|
|
90
|
+
*
|
|
91
|
+
* @param facilitator - The t402Facilitator instance to register schemes to
|
|
92
|
+
* @param config - Configuration for EVM facilitator registration
|
|
93
|
+
* @returns The facilitator instance for chaining
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { registerExactEvmScheme } from "@t402/evm/exact/facilitator/register";
|
|
98
|
+
* import { t402Facilitator } from "@t402/core/facilitator";
|
|
99
|
+
* import { createPublicClient, createWalletClient } from "viem";
|
|
100
|
+
*
|
|
101
|
+
* const facilitator = new t402Facilitator();
|
|
102
|
+
*
|
|
103
|
+
* // Single network
|
|
104
|
+
* registerExactEvmScheme(facilitator, {
|
|
105
|
+
* signer: combinedClient,
|
|
106
|
+
* networks: "eip155:84532" // Base Sepolia
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* // Multiple networks (will auto-derive eip155:* pattern)
|
|
110
|
+
* registerExactEvmScheme(facilitator, {
|
|
111
|
+
* signer: combinedClient,
|
|
112
|
+
* networks: ["eip155:84532", "eip155:1"] // Base Sepolia and Mainnet
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function registerExactEvmScheme(facilitator: t402Facilitator, config: EvmFacilitatorConfig): t402Facilitator;
|
|
117
|
+
|
|
118
|
+
export { type EvmFacilitatorConfig, ExactEvmScheme, type ExactEvmSchemeConfig, registerExactEvmScheme };
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NETWORKS
|
|
3
|
+
} from "../../chunk-QLXM7BIB.mjs";
|
|
4
|
+
import "../../chunk-JBWWBRYY.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ExactEvmSchemeV1
|
|
7
|
+
} from "../../chunk-ACDQ5QNT.mjs";
|
|
8
|
+
import {
|
|
9
|
+
authorizationTypes,
|
|
10
|
+
eip3009ABI
|
|
11
|
+
} from "../../chunk-XYKAO6KJ.mjs";
|
|
12
|
+
|
|
13
|
+
// src/exact/facilitator/scheme.ts
|
|
14
|
+
import { getAddress, isAddressEqual, parseErc6492Signature, parseSignature } from "viem";
|
|
15
|
+
var ExactEvmScheme = class {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new ExactEvmFacilitator instance.
|
|
18
|
+
*
|
|
19
|
+
* @param signer - The EVM signer for facilitator operations
|
|
20
|
+
* @param config - Optional configuration for the facilitator
|
|
21
|
+
*/
|
|
22
|
+
constructor(signer, config) {
|
|
23
|
+
this.signer = signer;
|
|
24
|
+
this.scheme = "exact";
|
|
25
|
+
this.caipFamily = "eip155:*";
|
|
26
|
+
this.config = {
|
|
27
|
+
deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get mechanism-specific extra data for the supported kinds endpoint.
|
|
32
|
+
* For EVM, no extra data is needed.
|
|
33
|
+
*
|
|
34
|
+
* @param _ - The network identifier (unused for EVM)
|
|
35
|
+
* @returns undefined (EVM has no extra data)
|
|
36
|
+
*/
|
|
37
|
+
getExtra(_) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get signer addresses used by this facilitator.
|
|
42
|
+
* Returns all addresses this facilitator can use for signing/settling transactions.
|
|
43
|
+
*
|
|
44
|
+
* @param _ - The network identifier (unused for EVM, addresses are network-agnostic)
|
|
45
|
+
* @returns Array of facilitator wallet addresses
|
|
46
|
+
*/
|
|
47
|
+
getSigners(_) {
|
|
48
|
+
return [...this.signer.getAddresses()];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Verifies a payment payload.
|
|
52
|
+
*
|
|
53
|
+
* @param payload - The payment payload to verify
|
|
54
|
+
* @param requirements - The payment requirements
|
|
55
|
+
* @returns Promise resolving to verification response
|
|
56
|
+
*/
|
|
57
|
+
async verify(payload, requirements) {
|
|
58
|
+
const exactEvmPayload = payload.payload;
|
|
59
|
+
if (payload.accepted.scheme !== "exact" || requirements.scheme !== "exact") {
|
|
60
|
+
return {
|
|
61
|
+
isValid: false,
|
|
62
|
+
invalidReason: "unsupported_scheme",
|
|
63
|
+
payer: exactEvmPayload.authorization.from
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (!requirements.extra?.name || !requirements.extra?.version) {
|
|
67
|
+
return {
|
|
68
|
+
isValid: false,
|
|
69
|
+
invalidReason: "missing_eip712_domain",
|
|
70
|
+
payer: exactEvmPayload.authorization.from
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const { name, version } = requirements.extra;
|
|
74
|
+
const erc20Address = getAddress(requirements.asset);
|
|
75
|
+
if (payload.accepted.network !== requirements.network) {
|
|
76
|
+
return {
|
|
77
|
+
isValid: false,
|
|
78
|
+
invalidReason: "network_mismatch",
|
|
79
|
+
payer: exactEvmPayload.authorization.from
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const permitTypedData = {
|
|
83
|
+
types: authorizationTypes,
|
|
84
|
+
primaryType: "TransferWithAuthorization",
|
|
85
|
+
domain: {
|
|
86
|
+
name,
|
|
87
|
+
version,
|
|
88
|
+
chainId: parseInt(requirements.network.split(":")[1]),
|
|
89
|
+
verifyingContract: erc20Address
|
|
90
|
+
},
|
|
91
|
+
message: {
|
|
92
|
+
from: exactEvmPayload.authorization.from,
|
|
93
|
+
to: exactEvmPayload.authorization.to,
|
|
94
|
+
value: BigInt(exactEvmPayload.authorization.value),
|
|
95
|
+
validAfter: BigInt(exactEvmPayload.authorization.validAfter),
|
|
96
|
+
validBefore: BigInt(exactEvmPayload.authorization.validBefore),
|
|
97
|
+
nonce: exactEvmPayload.authorization.nonce
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
try {
|
|
101
|
+
const recoveredAddress = await this.signer.verifyTypedData({
|
|
102
|
+
address: exactEvmPayload.authorization.from,
|
|
103
|
+
...permitTypedData,
|
|
104
|
+
signature: exactEvmPayload.signature
|
|
105
|
+
});
|
|
106
|
+
if (!recoveredAddress) {
|
|
107
|
+
return {
|
|
108
|
+
isValid: false,
|
|
109
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
110
|
+
payer: exactEvmPayload.authorization.from
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
const signature = exactEvmPayload.signature;
|
|
115
|
+
const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
|
|
116
|
+
const isSmartWallet = signatureLength > 130;
|
|
117
|
+
if (isSmartWallet) {
|
|
118
|
+
const payerAddress = exactEvmPayload.authorization.from;
|
|
119
|
+
const bytecode = await this.signer.getCode({ address: payerAddress });
|
|
120
|
+
if (!bytecode || bytecode === "0x") {
|
|
121
|
+
const erc6492Data = parseErc6492Signature(signature);
|
|
122
|
+
const hasDeploymentInfo = erc6492Data.address && erc6492Data.data && !isAddressEqual(erc6492Data.address, "0x0000000000000000000000000000000000000000");
|
|
123
|
+
if (!hasDeploymentInfo) {
|
|
124
|
+
return {
|
|
125
|
+
isValid: false,
|
|
126
|
+
invalidReason: "invalid_exact_evm_payload_undeployed_smart_wallet",
|
|
127
|
+
payer: payerAddress
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
return {
|
|
132
|
+
isValid: false,
|
|
133
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
134
|
+
payer: exactEvmPayload.authorization.from
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
return {
|
|
139
|
+
isValid: false,
|
|
140
|
+
invalidReason: "invalid_exact_evm_payload_signature",
|
|
141
|
+
payer: exactEvmPayload.authorization.from
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (getAddress(exactEvmPayload.authorization.to) !== getAddress(requirements.payTo)) {
|
|
146
|
+
return {
|
|
147
|
+
isValid: false,
|
|
148
|
+
invalidReason: "invalid_exact_evm_payload_recipient_mismatch",
|
|
149
|
+
payer: exactEvmPayload.authorization.from
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
153
|
+
if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {
|
|
154
|
+
return {
|
|
155
|
+
isValid: false,
|
|
156
|
+
invalidReason: "invalid_exact_evm_payload_authorization_valid_before",
|
|
157
|
+
payer: exactEvmPayload.authorization.from
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {
|
|
161
|
+
return {
|
|
162
|
+
isValid: false,
|
|
163
|
+
invalidReason: "invalid_exact_evm_payload_authorization_valid_after",
|
|
164
|
+
payer: exactEvmPayload.authorization.from
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const balance = await this.signer.readContract({
|
|
169
|
+
address: erc20Address,
|
|
170
|
+
abi: eip3009ABI,
|
|
171
|
+
functionName: "balanceOf",
|
|
172
|
+
args: [exactEvmPayload.authorization.from]
|
|
173
|
+
});
|
|
174
|
+
if (BigInt(balance) < BigInt(requirements.amount)) {
|
|
175
|
+
return {
|
|
176
|
+
isValid: false,
|
|
177
|
+
invalidReason: "insufficient_funds",
|
|
178
|
+
payer: exactEvmPayload.authorization.from
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirements.amount)) {
|
|
184
|
+
return {
|
|
185
|
+
isValid: false,
|
|
186
|
+
invalidReason: "invalid_exact_evm_payload_authorization_value",
|
|
187
|
+
payer: exactEvmPayload.authorization.from
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
isValid: true,
|
|
192
|
+
invalidReason: void 0,
|
|
193
|
+
payer: exactEvmPayload.authorization.from
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Settles a payment by executing the transfer.
|
|
198
|
+
*
|
|
199
|
+
* @param payload - The payment payload to settle
|
|
200
|
+
* @param requirements - The payment requirements
|
|
201
|
+
* @returns Promise resolving to settlement response
|
|
202
|
+
*/
|
|
203
|
+
async settle(payload, requirements) {
|
|
204
|
+
const exactEvmPayload = payload.payload;
|
|
205
|
+
const valid = await this.verify(payload, requirements);
|
|
206
|
+
if (!valid.isValid) {
|
|
207
|
+
return {
|
|
208
|
+
success: false,
|
|
209
|
+
network: payload.accepted.network,
|
|
210
|
+
transaction: "",
|
|
211
|
+
errorReason: valid.invalidReason ?? "invalid_scheme",
|
|
212
|
+
payer: exactEvmPayload.authorization.from
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const parseResult = parseErc6492Signature(exactEvmPayload.signature);
|
|
217
|
+
const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;
|
|
218
|
+
if (this.config.deployERC4337WithEIP6492 && factoryAddress && factoryCalldata && !isAddressEqual(factoryAddress, "0x0000000000000000000000000000000000000000")) {
|
|
219
|
+
const payerAddress = exactEvmPayload.authorization.from;
|
|
220
|
+
const bytecode = await this.signer.getCode({ address: payerAddress });
|
|
221
|
+
if (!bytecode || bytecode === "0x") {
|
|
222
|
+
try {
|
|
223
|
+
console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);
|
|
224
|
+
const deployTx = await this.signer.sendTransaction({
|
|
225
|
+
to: factoryAddress,
|
|
226
|
+
data: factoryCalldata
|
|
227
|
+
});
|
|
228
|
+
await this.signer.waitForTransactionReceipt({ hash: deployTx });
|
|
229
|
+
console.log(`Successfully deployed smart wallet for ${payerAddress}`);
|
|
230
|
+
} catch (deployError) {
|
|
231
|
+
console.error("Smart wallet deployment failed:", deployError);
|
|
232
|
+
throw deployError;
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const signatureLength = signature.startsWith("0x") ? signature.length - 2 : signature.length;
|
|
239
|
+
const isECDSA = signatureLength === 130;
|
|
240
|
+
let tx;
|
|
241
|
+
if (isECDSA) {
|
|
242
|
+
const parsedSig = parseSignature(signature);
|
|
243
|
+
tx = await this.signer.writeContract({
|
|
244
|
+
address: getAddress(requirements.asset),
|
|
245
|
+
abi: eip3009ABI,
|
|
246
|
+
functionName: "transferWithAuthorization",
|
|
247
|
+
args: [
|
|
248
|
+
getAddress(exactEvmPayload.authorization.from),
|
|
249
|
+
getAddress(exactEvmPayload.authorization.to),
|
|
250
|
+
BigInt(exactEvmPayload.authorization.value),
|
|
251
|
+
BigInt(exactEvmPayload.authorization.validAfter),
|
|
252
|
+
BigInt(exactEvmPayload.authorization.validBefore),
|
|
253
|
+
exactEvmPayload.authorization.nonce,
|
|
254
|
+
parsedSig.v || parsedSig.yParity,
|
|
255
|
+
parsedSig.r,
|
|
256
|
+
parsedSig.s
|
|
257
|
+
]
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
tx = await this.signer.writeContract({
|
|
261
|
+
address: getAddress(requirements.asset),
|
|
262
|
+
abi: eip3009ABI,
|
|
263
|
+
functionName: "transferWithAuthorization",
|
|
264
|
+
args: [
|
|
265
|
+
getAddress(exactEvmPayload.authorization.from),
|
|
266
|
+
getAddress(exactEvmPayload.authorization.to),
|
|
267
|
+
BigInt(exactEvmPayload.authorization.value),
|
|
268
|
+
BigInt(exactEvmPayload.authorization.validAfter),
|
|
269
|
+
BigInt(exactEvmPayload.authorization.validBefore),
|
|
270
|
+
exactEvmPayload.authorization.nonce,
|
|
271
|
+
signature
|
|
272
|
+
]
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });
|
|
276
|
+
if (receipt.status !== "success") {
|
|
277
|
+
return {
|
|
278
|
+
success: false,
|
|
279
|
+
errorReason: "invalid_transaction_state",
|
|
280
|
+
transaction: tx,
|
|
281
|
+
network: payload.accepted.network,
|
|
282
|
+
payer: exactEvmPayload.authorization.from
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
success: true,
|
|
287
|
+
transaction: tx,
|
|
288
|
+
network: payload.accepted.network,
|
|
289
|
+
payer: exactEvmPayload.authorization.from
|
|
290
|
+
};
|
|
291
|
+
} catch (error) {
|
|
292
|
+
console.error("Failed to settle transaction:", error);
|
|
293
|
+
return {
|
|
294
|
+
success: false,
|
|
295
|
+
errorReason: "transaction_failed",
|
|
296
|
+
transaction: "",
|
|
297
|
+
network: payload.accepted.network,
|
|
298
|
+
payer: exactEvmPayload.authorization.from
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/exact/facilitator/register.ts
|
|
305
|
+
function registerExactEvmScheme(facilitator, config) {
|
|
306
|
+
facilitator.register(
|
|
307
|
+
config.networks,
|
|
308
|
+
new ExactEvmScheme(config.signer, {
|
|
309
|
+
deployERC4337WithEIP6492: config.deployERC4337WithEIP6492
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
facilitator.registerV1(
|
|
313
|
+
NETWORKS,
|
|
314
|
+
new ExactEvmSchemeV1(config.signer, {
|
|
315
|
+
deployERC4337WithEIP6492: config.deployERC4337WithEIP6492
|
|
316
|
+
})
|
|
317
|
+
);
|
|
318
|
+
return facilitator;
|
|
319
|
+
}
|
|
320
|
+
export {
|
|
321
|
+
ExactEvmScheme,
|
|
322
|
+
registerExactEvmScheme
|
|
323
|
+
};
|
|
324
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/facilitator/scheme.ts","../../../../src/exact/facilitator/register.ts"],"sourcesContent":["import {\n PaymentPayload,\n PaymentRequirements,\n SchemeNetworkFacilitator,\n SettleResponse,\n VerifyResponse,\n} from \"@t402/core/types\";\nimport { getAddress, Hex, isAddressEqual, parseErc6492Signature, parseSignature } from \"viem\";\nimport { authorizationTypes, eip3009ABI } from \"../../constants\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmPayloadV2 } from \"../../types\";\n\nexport interface ExactEvmSchemeConfig {\n /**\n * If enabled, the facilitator will deploy ERC-4337 smart wallets\n * via EIP-6492 when encountering undeployed contract signatures.\n *\n * @default false\n */\n deployERC4337WithEIP6492?: boolean;\n}\n\n/**\n * EVM facilitator implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkFacilitator {\n readonly scheme = \"exact\";\n readonly caipFamily = \"eip155:*\";\n private readonly config: Required<ExactEvmSchemeConfig>;\n\n /**\n * Creates a new ExactEvmFacilitator instance.\n *\n * @param signer - The EVM signer for facilitator operations\n * @param config - Optional configuration for the facilitator\n */\n constructor(\n private readonly signer: FacilitatorEvmSigner,\n config?: ExactEvmSchemeConfig,\n ) {\n this.config = {\n deployERC4337WithEIP6492: config?.deployERC4337WithEIP6492 ?? false,\n };\n }\n\n /**\n * Get mechanism-specific extra data for the supported kinds endpoint.\n * For EVM, no extra data is needed.\n *\n * @param _ - The network identifier (unused for EVM)\n * @returns undefined (EVM has no extra data)\n */\n getExtra(_: string): Record<string, unknown> | undefined {\n return undefined;\n }\n\n /**\n * Get signer addresses used by this facilitator.\n * Returns all addresses this facilitator can use for signing/settling transactions.\n *\n * @param _ - The network identifier (unused for EVM, addresses are network-agnostic)\n * @returns Array of facilitator wallet addresses\n */\n getSigners(_: string): string[] {\n return [...this.signer.getAddresses()];\n }\n\n /**\n * Verifies a payment payload.\n *\n * @param payload - The payment payload to verify\n * @param requirements - The payment requirements\n * @returns Promise resolving to verification response\n */\n async verify(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<VerifyResponse> {\n const exactEvmPayload = payload.payload as ExactEvmPayloadV2;\n\n // Verify scheme matches\n if (payload.accepted.scheme !== \"exact\" || requirements.scheme !== \"exact\") {\n return {\n isValid: false,\n invalidReason: \"unsupported_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Get chain configuration\n if (!requirements.extra?.name || !requirements.extra?.version) {\n return {\n isValid: false,\n invalidReason: \"missing_eip712_domain\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n const { name, version } = requirements.extra;\n const erc20Address = getAddress(requirements.asset);\n\n // Verify network matches\n if (payload.accepted.network !== requirements.network) {\n return {\n isValid: false,\n invalidReason: \"network_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Build typed data for signature verification\n const permitTypedData = {\n types: authorizationTypes,\n primaryType: \"TransferWithAuthorization\" as const,\n domain: {\n name,\n version,\n chainId: parseInt(requirements.network.split(\":\")[1]),\n verifyingContract: erc20Address,\n },\n message: {\n from: exactEvmPayload.authorization.from,\n to: exactEvmPayload.authorization.to,\n value: BigInt(exactEvmPayload.authorization.value),\n validAfter: BigInt(exactEvmPayload.authorization.validAfter),\n validBefore: BigInt(exactEvmPayload.authorization.validBefore),\n nonce: exactEvmPayload.authorization.nonce,\n },\n };\n\n // Verify signature\n try {\n const recoveredAddress = await this.signer.verifyTypedData({\n address: exactEvmPayload.authorization.from,\n ...permitTypedData,\n signature: exactEvmPayload.signature!,\n });\n\n if (!recoveredAddress) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // Signature verification failed - could be an undeployed smart wallet\n // Check if smart wallet is deployed\n const signature = exactEvmPayload.signature!;\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isSmartWallet = signatureLength > 130; // 65 bytes = 130 hex chars for EOA\n\n if (isSmartWallet) {\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet is not deployed. Check if it's EIP-6492 with deployment info.\n // EIP-6492 signatures contain factory address and calldata needed for deployment.\n // Non-EIP-6492 undeployed wallets cannot succeed (no way to deploy them).\n const erc6492Data = parseErc6492Signature(signature);\n const hasDeploymentInfo =\n erc6492Data.address &&\n erc6492Data.data &&\n !isAddressEqual(erc6492Data.address, \"0x0000000000000000000000000000000000000000\");\n\n if (!hasDeploymentInfo) {\n // Non-EIP-6492 undeployed smart wallet - will always fail at settlement\n // since EIP-3009 requires on-chain EIP-1271 validation\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_undeployed_smart_wallet\",\n payer: payerAddress,\n };\n }\n // EIP-6492 signature with deployment info - allow through\n // Facilitators with sponsored deployment support can handle this in settle()\n } else {\n // Wallet is deployed but signature still failed - invalid signature\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } else {\n // EOA signature failed\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_signature\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n\n // Verify payment recipient matches\n if (getAddress(exactEvmPayload.authorization.to) !== getAddress(requirements.payTo)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_recipient_mismatch\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validBefore is in the future (with 6 second buffer for block time)\n const now = Math.floor(Date.now() / 1000);\n if (BigInt(exactEvmPayload.authorization.validBefore) < BigInt(now + 6)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_before\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Verify validAfter is not in the future\n if (BigInt(exactEvmPayload.authorization.validAfter) > BigInt(now)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_valid_after\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n // Check balance\n try {\n const balance = (await this.signer.readContract({\n address: erc20Address,\n abi: eip3009ABI,\n functionName: \"balanceOf\",\n args: [exactEvmPayload.authorization.from],\n })) as bigint;\n\n if (BigInt(balance) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"insufficient_funds\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n } catch {\n // If we can't check balance, continue with other validations\n }\n\n // Verify amount is sufficient\n if (BigInt(exactEvmPayload.authorization.value) < BigInt(requirements.amount)) {\n return {\n isValid: false,\n invalidReason: \"invalid_exact_evm_payload_authorization_value\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n isValid: true,\n invalidReason: undefined,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n /**\n * Settles a payment by executing the transfer.\n *\n * @param payload - The payment payload to settle\n * @param requirements - The payment requirements\n * @returns Promise resolving to settlement response\n */\n async settle(\n payload: PaymentPayload,\n requirements: PaymentRequirements,\n ): Promise<SettleResponse> {\n const exactEvmPayload = payload.payload as ExactEvmPayloadV2;\n\n // Re-verify before settling\n const valid = await this.verify(payload, requirements);\n if (!valid.isValid) {\n return {\n success: false,\n network: payload.accepted.network,\n transaction: \"\",\n errorReason: valid.invalidReason ?? \"invalid_scheme\",\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n try {\n // Parse ERC-6492 signature if applicable\n const parseResult = parseErc6492Signature(exactEvmPayload.signature!);\n const { signature, address: factoryAddress, data: factoryCalldata } = parseResult;\n\n // Deploy ERC-4337 smart wallet via EIP-6492 if configured and needed\n if (\n this.config.deployERC4337WithEIP6492 &&\n factoryAddress &&\n factoryCalldata &&\n !isAddressEqual(factoryAddress, \"0x0000000000000000000000000000000000000000\")\n ) {\n // Check if smart wallet is already deployed\n const payerAddress = exactEvmPayload.authorization.from;\n const bytecode = await this.signer.getCode({ address: payerAddress });\n\n if (!bytecode || bytecode === \"0x\") {\n // Wallet not deployed - attempt deployment\n try {\n console.log(`Deploying ERC-4337 smart wallet for ${payerAddress} via EIP-6492`);\n\n // Send the factory calldata directly as a transaction\n // The factoryCalldata already contains the complete encoded function call\n const deployTx = await this.signer.sendTransaction({\n to: factoryAddress as Hex,\n data: factoryCalldata as Hex,\n });\n\n // Wait for deployment transaction\n await this.signer.waitForTransactionReceipt({ hash: deployTx });\n console.log(`Successfully deployed smart wallet for ${payerAddress}`);\n } catch (deployError) {\n console.error(\"Smart wallet deployment failed:\", deployError);\n // Deployment failed - cannot proceed\n throw deployError;\n }\n } else {\n console.log(`Smart wallet for ${payerAddress} already deployed, skipping deployment`);\n }\n }\n\n // Determine if this is an ECDSA signature (EOA) or smart wallet signature\n // ECDSA signatures are exactly 65 bytes (130 hex chars without 0x)\n const signatureLength = signature.startsWith(\"0x\") ? signature.length - 2 : signature.length;\n const isECDSA = signatureLength === 130;\n\n let tx: Hex;\n if (isECDSA) {\n // For EOA wallets, parse signature into v, r, s and use that overload\n const parsedSig = parseSignature(signature);\n\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n (parsedSig.v as number | undefined) || parsedSig.yParity,\n parsedSig.r,\n parsedSig.s,\n ],\n });\n } else {\n // For smart wallets, use the bytes signature overload\n // The signature contains WebAuthn/P256 or other ERC-1271 compatible signature data\n tx = await this.signer.writeContract({\n address: getAddress(requirements.asset),\n abi: eip3009ABI,\n functionName: \"transferWithAuthorization\",\n args: [\n getAddress(exactEvmPayload.authorization.from),\n getAddress(exactEvmPayload.authorization.to),\n BigInt(exactEvmPayload.authorization.value),\n BigInt(exactEvmPayload.authorization.validAfter),\n BigInt(exactEvmPayload.authorization.validBefore),\n exactEvmPayload.authorization.nonce,\n signature,\n ],\n });\n }\n\n // Wait for transaction confirmation\n const receipt = await this.signer.waitForTransactionReceipt({ hash: tx });\n\n if (receipt.status !== \"success\") {\n return {\n success: false,\n errorReason: \"invalid_transaction_state\",\n transaction: tx,\n network: payload.accepted.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n\n return {\n success: true,\n transaction: tx,\n network: payload.accepted.network,\n payer: exactEvmPayload.authorization.from,\n };\n } catch (error) {\n console.error(\"Failed to settle transaction:\", error);\n return {\n success: false,\n errorReason: \"transaction_failed\",\n transaction: \"\",\n network: payload.accepted.network,\n payer: exactEvmPayload.authorization.from,\n };\n }\n }\n}\n","import { t402Facilitator } from \"@t402/core/facilitator\";\nimport { Network } from \"@t402/core/types\";\nimport { FacilitatorEvmSigner } from \"../../signer\";\nimport { ExactEvmScheme } from \"./scheme\";\nimport { ExactEvmSchemeV1 } from \"../v1/facilitator/scheme\";\nimport { NETWORKS } from \"../../v1\";\n\n/**\n * Configuration options for registering EVM schemes to an t402Facilitator\n */\nexport interface EvmFacilitatorConfig {\n /**\n * The EVM signer for facilitator operations (verify and settle)\n */\n signer: FacilitatorEvmSigner;\n\n /**\n * Networks to register (single network or array of networks)\n * Examples: \"eip155:84532\", [\"eip155:84532\", \"eip155:1\"]\n */\n networks: Network | Network[];\n\n /**\n * If enabled, the facilitator will deploy ERC-4337 smart wallets\n * via EIP-6492 when encountering undeployed contract signatures.\n *\n * @default false\n */\n deployERC4337WithEIP6492?: boolean;\n}\n\n/**\n * Registers EVM exact payment schemes to an t402Facilitator instance.\n *\n * This function registers:\n * - V2: Specified networks with ExactEvmScheme\n * - V1: All supported EVM networks with ExactEvmSchemeV1\n *\n * @param facilitator - The t402Facilitator instance to register schemes to\n * @param config - Configuration for EVM facilitator registration\n * @returns The facilitator instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@t402/evm/exact/facilitator/register\";\n * import { t402Facilitator } from \"@t402/core/facilitator\";\n * import { createPublicClient, createWalletClient } from \"viem\";\n *\n * const facilitator = new t402Facilitator();\n *\n * // Single network\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: \"eip155:84532\" // Base Sepolia\n * });\n *\n * // Multiple networks (will auto-derive eip155:* pattern)\n * registerExactEvmScheme(facilitator, {\n * signer: combinedClient,\n * networks: [\"eip155:84532\", \"eip155:1\"] // Base Sepolia and Mainnet\n * });\n * ```\n */\nexport function registerExactEvmScheme(\n facilitator: t402Facilitator,\n config: EvmFacilitatorConfig,\n): t402Facilitator {\n // Register V2 scheme with specified networks\n facilitator.register(\n config.networks,\n new ExactEvmScheme(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n // Register all V1 networks\n facilitator.registerV1(\n NETWORKS as Network[],\n new ExactEvmSchemeV1(config.signer, {\n deployERC4337WithEIP6492: config.deployERC4337WithEIP6492,\n }),\n );\n\n return facilitator;\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAS,YAAiB,gBAAgB,uBAAuB,sBAAsB;AAkBhF,IAAM,iBAAN,MAAyD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9D,YACmB,QACjB,QACA;AAFiB;AAXnB,SAAS,SAAS;AAClB,SAAS,aAAa;AAapB,SAAK,SAAS;AAAA,MACZ,0BAA0B,QAAQ,4BAA4B;AAAA,IAChE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,SAAS,GAAgD;AACvD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW,GAAqB;AAC9B,WAAO,CAAC,GAAG,KAAK,OAAO,aAAa,CAAC;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OACJ,SACA,cACyB;AACzB,UAAM,kBAAkB,QAAQ;AAGhC,QAAI,QAAQ,SAAS,WAAW,WAAW,aAAa,WAAW,SAAS;AAC1E,aAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,QACf,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAGA,QAAI,CAAC,aAAa,OAAO,QAAQ,CAAC,aAAa,OAAO,SAAS;AAC7D,aAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,QACf,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAEA,UAAM,EAAE,MAAM,QAAQ,IAAI,aAAa;AACvC,UAAM,eAAe,WAAW,aAAa,KA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F,CAAC;AAAA,MACH;AAGA,YAAM,UAAU,MAAM,KAAK,OAAO,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAExE,UAAI,QAAQ,WAAW,WAAW;AAChC,eAAO;AAAA,UACL,SAAS;AAAA,UACT,aAAa;AAAA,UACb,aAAa;AAAA,UACb,SAAS,QAAQ,SAAS;AAAA,UAC1B,OAAO,gBAAgB,cAAc;AAAA,QACvC;AAAA,MACF;AAEA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,SAAS,QAAQ,SAAS;AAAA,QAC1B,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,iCAAiC,KAAK;AACpD,aAAO;AAAA,QACL,SAAS;AAAA,QACT,aAAa;AAAA,QACb,aAAa;AAAA,QACb,SAAS,QAAQ,SAAS;AAAA,QAC1B,OAAO,gBAAgB,cAAc;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACF;;;ACjVO,SAAS,uBACd,aACA,QACiB;AAEjB,cAAY;AAAA,IACV,OAAO;AAAA,IACP,IAAI,eAAe,OAAO,QAAQ;AAAA,MAChC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAGA,cAAY;AAAA,IACV;AAAA,IACA,IAAI,iBAAiB,OAAO,QAAQ;AAAA,MAClC,0BAA0B,OAAO;AAAA,IACnC,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { E as ExactEvmScheme } from '../../scheme-yqGaK9rK.mjs';
|
|
2
|
+
import { t402ResourceServer } from '@t402/core/server';
|
|
3
|
+
import { Network } from '@t402/core/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for registering EVM schemes to an t402ResourceServer
|
|
7
|
+
*/
|
|
8
|
+
interface EvmResourceServerConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Optional specific networks to register
|
|
11
|
+
* If not provided, registers wildcard support (eip155:*)
|
|
12
|
+
*/
|
|
13
|
+
networks?: Network[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers EVM exact payment schemes to an t402ResourceServer instance.
|
|
17
|
+
*
|
|
18
|
+
* This function registers:
|
|
19
|
+
* - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)
|
|
20
|
+
*
|
|
21
|
+
* @param server - The t402ResourceServer instance to register schemes to
|
|
22
|
+
* @param config - Configuration for EVM resource server registration
|
|
23
|
+
* @returns The server instance for chaining
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { registerExactEvmScheme } from "@t402/evm/exact/server/register";
|
|
28
|
+
* import { t402ResourceServer } from "@t402/core/server";
|
|
29
|
+
*
|
|
30
|
+
* const server = new t402ResourceServer(facilitatorClient);
|
|
31
|
+
* registerExactEvmScheme(server, {});
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function registerExactEvmScheme(server: t402ResourceServer, config?: EvmResourceServerConfig): t402ResourceServer;
|
|
35
|
+
|
|
36
|
+
export { type EvmResourceServerConfig, registerExactEvmScheme };
|