@faremeter/payment-evm 0.8.0 → 0.10.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.d.ts +5 -1
- package/dist/src/exact/client.d.ts.map +1 -1
- package/dist/src/exact/client.js +3 -3
- package/dist/src/exact/facilitator.d.ts +3 -3
- package/dist/src/exact/facilitator.d.ts.map +1 -1
- package/dist/src/exact/facilitator.js +12 -15
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PaymentHandler } from "@faremeter/types/client";
|
|
2
|
+
import { type AssetNameOrContractInfo } from "@faremeter/info/evm";
|
|
2
3
|
import type { Hex } from "viem";
|
|
3
4
|
interface WalletForPayment {
|
|
4
5
|
chain: {
|
|
@@ -15,6 +16,9 @@ interface WalletForPayment {
|
|
|
15
16
|
}) => Promise<Hex>;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
+
export type CreatePaymentHandlerOpts = {
|
|
20
|
+
asset?: AssetNameOrContractInfo;
|
|
21
|
+
};
|
|
22
|
+
export declare function createPaymentHandler(wallet: WalletForPayment, opts?: CreatePaymentHandlerOpts): PaymentHandler;
|
|
19
23
|
export {};
|
|
20
24
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/exact/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAGf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAWhC,UAAU,gBAAgB;IACxB,KAAK,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE;QACP,aAAa,EAAE,CAAC,MAAM,EAAE;YACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC/B,WAAW,EAAE,MAAM,CAAC;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAClC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;KACpB,CAAC;CACH;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,CAAC,EAAE,uBAAuB,CAAC;CACjC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,gBAAgB,EACxB,IAAI,GAAE,wBAA6B,GAClC,cAAc,CAkGhB"}
|
package/dist/src/exact/client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomBytes } from "crypto";
|
|
2
|
-
import { lookupX402Network,
|
|
2
|
+
import { lookupX402Network, findAssetInfo, } from "@faremeter/info/evm";
|
|
3
3
|
import { isAddress } from "viem";
|
|
4
4
|
import { type } from "arktype";
|
|
5
5
|
import { X402_EXACT_SCHEME, EIP712_TYPES, eip712Domain, } from "./constants.js";
|
|
6
|
-
export function createPaymentHandler(wallet) {
|
|
6
|
+
export function createPaymentHandler(wallet, opts = {}) {
|
|
7
7
|
const x402Network = lookupX402Network(wallet.chain.id);
|
|
8
|
-
const assetInfo =
|
|
8
|
+
const assetInfo = findAssetInfo(x402Network, opts.asset ?? "USDC");
|
|
9
9
|
if (!assetInfo) {
|
|
10
10
|
throw new Error(`Couldn't look up USDC information on network '${x402Network}'`);
|
|
11
11
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type FacilitatorHandler } from "@faremeter/types/facilitator";
|
|
2
2
|
import type { Chain, Transport } from "viem";
|
|
3
|
-
import { type
|
|
3
|
+
import { type KnownX402Network, type AssetNameOrContractInfo } from "@faremeter/info/evm";
|
|
4
4
|
type CreateFacilitatorHandlerOpts = {
|
|
5
|
-
network?:
|
|
5
|
+
network?: KnownX402Network;
|
|
6
6
|
transport?: Transport;
|
|
7
7
|
};
|
|
8
|
-
export declare function createFacilitatorHandler(chain: Chain, privateKey: string, assetNameOrInfo:
|
|
8
|
+
export declare function createFacilitatorHandler(chain: Chain, privateKey: string, assetNameOrInfo: AssetNameOrContractInfo, opts?: CreateFacilitatorHandlerOpts): Promise<FacilitatorHandler>;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=facilitator.d.ts.map
|
|
@@ -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":"AASA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,KAAK,EAAgB,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAY3D,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AA8B7B,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AACF,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,uBAAuB,EACxC,IAAI,GAAE,4BAAiC,GACtC,OAAO,CAAC,kBAAkB,CAAC,CA+S7B"}
|
|
@@ -4,7 +4,7 @@ import {} from "@faremeter/types/facilitator";
|
|
|
4
4
|
import { type } from "arktype";
|
|
5
5
|
import { createPublicClient, createWalletClient, http, verifyTypedData, encodeFunctionData, isAddress, } from "viem";
|
|
6
6
|
import { privateKeyToAccount } from "viem/accounts";
|
|
7
|
-
import {
|
|
7
|
+
import { lookupX402Network, findAssetInfo, } from "@faremeter/info/evm";
|
|
8
8
|
import { X402_EXACT_SCHEME, TRANSFER_WITH_AUTHORIZATION_ABI, EIP712_TYPES, x402ExactPayload, } from "./constants.js";
|
|
9
9
|
import { generateDomain, generateForwarderDomain } from "./common.js";
|
|
10
10
|
function errorResponse(msg) {
|
|
@@ -29,20 +29,7 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
29
29
|
}
|
|
30
30
|
const network = opts.network ?? lookupX402Network(chain.id);
|
|
31
31
|
const chainId = chain.id;
|
|
32
|
-
|
|
33
|
-
if (typeof assetNameOrInfo == "string") {
|
|
34
|
-
if (!isKnownAsset(assetNameOrInfo)) {
|
|
35
|
-
throw new Error(`Unknown asset: ${assetNameOrInfo}`);
|
|
36
|
-
}
|
|
37
|
-
const t = lookupKnownAsset(network, assetNameOrInfo);
|
|
38
|
-
if (!t) {
|
|
39
|
-
throw new Error(`Couldn't look up asset ${assetNameOrInfo} on ${network}`);
|
|
40
|
-
}
|
|
41
|
-
assetInfo = t;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
assetInfo = assetNameOrInfo;
|
|
45
|
-
}
|
|
32
|
+
const assetInfo = findAssetInfo(network, assetNameOrInfo);
|
|
46
33
|
const asset = assetInfo.address;
|
|
47
34
|
const useForwarder = assetInfo.forwarder !== undefined && assetInfo.forwarderName !== undefined;
|
|
48
35
|
if (!isAddress(asset)) {
|
|
@@ -89,6 +76,15 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
89
76
|
const checkTupleAndAsset = checkTuple.and({
|
|
90
77
|
asset: caseInsensitiveLiteral(asset),
|
|
91
78
|
});
|
|
79
|
+
const getSupported = () => {
|
|
80
|
+
return [
|
|
81
|
+
Promise.resolve({
|
|
82
|
+
x402Version: 1,
|
|
83
|
+
network,
|
|
84
|
+
scheme: X402_EXACT_SCHEME,
|
|
85
|
+
}),
|
|
86
|
+
];
|
|
87
|
+
};
|
|
92
88
|
const getRequirements = async (req) => {
|
|
93
89
|
return req
|
|
94
90
|
.filter((x) => !isValidationError(checkTupleAndAsset(x)))
|
|
@@ -264,6 +260,7 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
264
260
|
}
|
|
265
261
|
};
|
|
266
262
|
return {
|
|
263
|
+
getSupported,
|
|
267
264
|
getRequirements,
|
|
268
265
|
handleSettle,
|
|
269
266
|
};
|