@faremeter/payment-evm 0.11.1 → 0.13.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/dist/src/exact/client.js
CHANGED
|
@@ -11,7 +11,7 @@ export function createPaymentHandler(wallet, opts = {}) {
|
|
|
11
11
|
throw new Error(`Couldn't look up USDC information on network '${x402Network}'`);
|
|
12
12
|
}
|
|
13
13
|
const { isMatchingRequirement } = generateMatcher(x402Network, assetInfo.address);
|
|
14
|
-
return async function handlePayment(
|
|
14
|
+
return async function handlePayment(_context, accepts) {
|
|
15
15
|
const compatibleRequirements = accepts.filter(isMatchingRequirement);
|
|
16
16
|
return compatibleRequirements.map((requirements) => ({
|
|
17
17
|
requirements,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAQA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,MAAM,CAAC;AAYpD,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAuB7B,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AACF,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,uBAAuB,EACxC,IAAI,GAAE,4BAAiC,GACtC,OAAO,CAAC,kBAAkB,CAAC,CA2U7B"}
|
|
@@ -6,14 +6,6 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
6
6
|
import { lookupX402Network, findAssetInfo, } from "@faremeter/info/evm";
|
|
7
7
|
import { X402_EXACT_SCHEME, TRANSFER_WITH_AUTHORIZATION_ABI, EIP712_TYPES, x402ExactPayload, } from "./constants.js";
|
|
8
8
|
import { generateMatcher, generateDomain, generateForwarderDomain, } from "./common.js";
|
|
9
|
-
function errorResponse(msg) {
|
|
10
|
-
return {
|
|
11
|
-
success: false,
|
|
12
|
-
error: msg,
|
|
13
|
-
txHash: null,
|
|
14
|
-
networkId: null,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
9
|
function parseSignature(signature) {
|
|
18
10
|
const sig = signature.slice(2); // Remove 0x
|
|
19
11
|
const r = `0x${sig.slice(0, 64)}`;
|
|
@@ -89,10 +81,8 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
89
81
|
},
|
|
90
82
|
}));
|
|
91
83
|
};
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
return null; // Not for us, let another handler try
|
|
95
|
-
}
|
|
84
|
+
const verifyTransaction = async (requirements, payment) => {
|
|
85
|
+
const errorResponse = (error) => ({ error });
|
|
96
86
|
// For the exact scheme with EIP-3009, validate the authorization payload
|
|
97
87
|
const payloadResult = x402ExactPayload(payment.payload);
|
|
98
88
|
if (payloadResult instanceof type.errors) {
|
|
@@ -142,7 +132,7 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
142
132
|
if (!assetInfo.forwarderVersion ||
|
|
143
133
|
!assetInfo.forwarderName ||
|
|
144
134
|
!assetInfo.forwarder) {
|
|
145
|
-
throw new Error("Secondary
|
|
135
|
+
throw new Error("Secondary Forwarding Information Missing");
|
|
146
136
|
}
|
|
147
137
|
domain = generateForwarderDomain(chainId, {
|
|
148
138
|
version: assetInfo.forwarderVersion,
|
|
@@ -180,6 +170,40 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
180
170
|
if (!isValidSignature) {
|
|
181
171
|
return errorResponse("Invalid signature");
|
|
182
172
|
}
|
|
173
|
+
return {
|
|
174
|
+
authorization,
|
|
175
|
+
signature,
|
|
176
|
+
validAfter,
|
|
177
|
+
validBefore,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
const handleVerify = async (requirements, payment) => {
|
|
181
|
+
if (!isMatchingRequirement(requirements)) {
|
|
182
|
+
return null; // Not for us, let another handler try
|
|
183
|
+
}
|
|
184
|
+
const verifyResult = await verifyTransaction(requirements, payment);
|
|
185
|
+
if ("error" in verifyResult) {
|
|
186
|
+
return { isValid: false, invalidReason: verifyResult.error };
|
|
187
|
+
}
|
|
188
|
+
return { isValid: true };
|
|
189
|
+
};
|
|
190
|
+
const handleSettle = async (requirements, payment) => {
|
|
191
|
+
if (!isMatchingRequirement(requirements)) {
|
|
192
|
+
return null; // Not for us, let another handler try
|
|
193
|
+
}
|
|
194
|
+
const errorResponse = (msg) => {
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
error: msg,
|
|
198
|
+
txHash: null,
|
|
199
|
+
networkId: null,
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
const verifyResult = await verifyTransaction(requirements, payment);
|
|
203
|
+
if ("error" in verifyResult) {
|
|
204
|
+
return errorResponse(verifyResult.error);
|
|
205
|
+
}
|
|
206
|
+
const { authorization, signature, validAfter, validBefore } = verifyResult;
|
|
183
207
|
// Verify contract supports EIP-712
|
|
184
208
|
try {
|
|
185
209
|
await publicClient.readContract({
|
|
@@ -243,6 +267,7 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
243
267
|
return {
|
|
244
268
|
getSupported,
|
|
245
269
|
getRequirements,
|
|
270
|
+
handleVerify,
|
|
246
271
|
handleSettle,
|
|
247
272
|
};
|
|
248
273
|
}
|