@t402/evm 2.5.0 → 2.6.1

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.
Files changed (39) hide show
  1. package/dist/cjs/index-fzI2FyBT.d.ts +122 -0
  2. package/dist/cjs/permit2/client/index.d.ts +81 -0
  3. package/dist/cjs/permit2/client/index.js +150 -0
  4. package/dist/cjs/permit2/client/index.js.map +1 -0
  5. package/dist/cjs/permit2/facilitator/index.d.ts +82 -0
  6. package/dist/cjs/permit2/facilitator/index.js +301 -0
  7. package/dist/cjs/permit2/facilitator/index.js.map +1 -0
  8. package/dist/cjs/permit2/index.d.ts +145 -0
  9. package/dist/cjs/permit2/index.js +1075 -0
  10. package/dist/cjs/permit2/index.js.map +1 -0
  11. package/dist/cjs/permit2/server/index.d.ts +3 -0
  12. package/dist/cjs/permit2/server/index.js +686 -0
  13. package/dist/cjs/permit2/server/index.js.map +1 -0
  14. package/dist/esm/chunk-3KHB6QTD.mjs +112 -0
  15. package/dist/esm/chunk-3KHB6QTD.mjs.map +1 -0
  16. package/dist/esm/{chunk-ZDGWVHD5.mjs → chunk-EEZNFYCW.mjs} +5 -5
  17. package/dist/esm/chunk-MMQSLAA2.mjs +190 -0
  18. package/dist/esm/chunk-MMQSLAA2.mjs.map +1 -0
  19. package/dist/esm/chunk-NIGKNI66.mjs +224 -0
  20. package/dist/esm/chunk-NIGKNI66.mjs.map +1 -0
  21. package/dist/esm/chunk-URG4HEYQ.mjs +74 -0
  22. package/dist/esm/chunk-URG4HEYQ.mjs.map +1 -0
  23. package/dist/esm/index-fzI2FyBT.d.mts +122 -0
  24. package/dist/esm/index.mjs +10 -10
  25. package/dist/esm/permit2/client/index.d.mts +81 -0
  26. package/dist/esm/permit2/client/index.mjs +11 -0
  27. package/dist/esm/permit2/client/index.mjs.map +1 -0
  28. package/dist/esm/permit2/facilitator/index.d.mts +82 -0
  29. package/dist/esm/permit2/facilitator/index.mjs +11 -0
  30. package/dist/esm/permit2/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/permit2/index.d.mts +145 -0
  32. package/dist/esm/permit2/index.mjs +31 -0
  33. package/dist/esm/permit2/index.mjs.map +1 -0
  34. package/dist/esm/permit2/server/index.d.mts +3 -0
  35. package/dist/esm/permit2/server/index.mjs +12 -0
  36. package/dist/esm/permit2/server/index.mjs.map +1 -0
  37. package/dist/esm/upto/index.mjs +2 -2
  38. package/package.json +58 -11
  39. /package/dist/esm/{chunk-ZDGWVHD5.mjs.map → chunk-EEZNFYCW.mjs.map} +0 -0
@@ -0,0 +1,122 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@t402/core/types';
2
+ import { t402ResourceServer } from '@t402/core/server';
3
+
4
+ /**
5
+ * Configuration options for Permit2EvmScheme server
6
+ */
7
+ interface Permit2EvmSchemeConfig {
8
+ /** Preferred token symbol (e.g., "USDT0", "USDC"). Defaults to network's highest priority token. */
9
+ preferredToken?: string;
10
+ }
11
+ /**
12
+ * EVM server implementation for the Permit2 payment scheme.
13
+ * Supports USDT0, USDC, and other ERC20 tokens via Uniswap Permit2.
14
+ */
15
+ declare class Permit2EvmScheme implements SchemeNetworkServer {
16
+ readonly scheme = "permit2";
17
+ private moneyParsers;
18
+ private config;
19
+ /**
20
+ * Creates a new Permit2EvmScheme server instance.
21
+ *
22
+ * @param config - Server configuration options
23
+ */
24
+ constructor(config?: Permit2EvmSchemeConfig);
25
+ /**
26
+ * Get the list of supported EVM networks.
27
+ *
28
+ * @returns Array of supported network identifiers
29
+ */
30
+ static getSupportedNetworks(): string[];
31
+ /**
32
+ * Check if a network is supported.
33
+ *
34
+ * @param network - Network identifier to check
35
+ * @returns Whether the network is supported
36
+ */
37
+ static isNetworkSupported(network: string): boolean;
38
+ /**
39
+ * Register a custom money parser for price conversion.
40
+ *
41
+ * @param parser - The money parser to register
42
+ * @returns This instance for chaining
43
+ */
44
+ registerMoneyParser(parser: MoneyParser): Permit2EvmScheme;
45
+ /**
46
+ * Parse a price into an AssetAmount for the given network.
47
+ *
48
+ * @param price - The price to parse
49
+ * @param network - The target network
50
+ * @returns The parsed asset amount
51
+ */
52
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
53
+ /**
54
+ * Enhance payment requirements with Permit2-specific data.
55
+ *
56
+ * @param paymentRequirements - The base payment requirements
57
+ * @param supportedKind - The supported kind metadata
58
+ * @param supportedKind.t402Version - Protocol version
59
+ * @param supportedKind.scheme - Payment scheme
60
+ * @param supportedKind.network - Target network
61
+ * @param supportedKind.extra - Extra metadata
62
+ * @param extensionKeys - Active extension keys
63
+ * @returns Enhanced payment requirements
64
+ */
65
+ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: {
66
+ t402Version: number;
67
+ scheme: string;
68
+ network: Network;
69
+ extra?: Record<string, unknown>;
70
+ }, extensionKeys: string[]): Promise<PaymentRequirements>;
71
+ /**
72
+ * Parse a money value into a decimal number.
73
+ *
74
+ * @param money - The money value to parse
75
+ * @returns The decimal amount
76
+ */
77
+ private parseMoneyToDecimal;
78
+ /**
79
+ * Convert a decimal amount to a token amount using default network token.
80
+ *
81
+ * @param amount - The decimal amount
82
+ * @param network - The target network
83
+ * @returns The asset amount with token details
84
+ */
85
+ private defaultMoneyConversion;
86
+ /**
87
+ * Convert a decimal amount string to token smallest units.
88
+ *
89
+ * @param decimalAmount - The decimal amount as a string
90
+ * @param decimals - The token's decimal places
91
+ * @returns The amount in smallest units
92
+ */
93
+ private convertToTokenAmount;
94
+ /**
95
+ * Get the default token asset for a network.
96
+ *
97
+ * @param network - The target network
98
+ * @returns The token configuration
99
+ */
100
+ private getDefaultAsset;
101
+ }
102
+
103
+ /**
104
+ * Configuration options for registering Permit2 schemes to an t402ResourceServer
105
+ */
106
+ interface Permit2EvmResourceServerConfig {
107
+ /**
108
+ * Optional specific networks to register
109
+ * If not provided, registers wildcard support (eip155:*)
110
+ */
111
+ networks?: Network[];
112
+ }
113
+ /**
114
+ * Registers Permit2 EVM payment schemes to an t402ResourceServer instance.
115
+ *
116
+ * @param server - The t402ResourceServer instance to register schemes to
117
+ * @param config - Configuration for Permit2 resource server registration
118
+ * @returns The server instance for chaining
119
+ */
120
+ declare function registerPermit2EvmScheme(server: t402ResourceServer, config?: Permit2EvmResourceServerConfig): t402ResourceServer;
121
+
122
+ export { type Permit2EvmResourceServerConfig as P, Permit2EvmScheme as a, type Permit2EvmSchemeConfig as b, registerPermit2EvmScheme as r };
@@ -0,0 +1,81 @@
1
+ import { SchemeNetworkClient, PaymentRequirements, PaymentPayload, Network } from '@t402/core/types';
2
+ import { C as ClientEvmSigner } from '../../signer-DcavxxZt.js';
3
+ import { SelectPaymentRequirements, PaymentPolicy, t402Client } from '@t402/core/client';
4
+
5
+ /**
6
+ * EVM client implementation for the Permit2 payment scheme.
7
+ *
8
+ * Uses Uniswap Permit2 SignatureTransfer for gasless token approvals.
9
+ */
10
+ declare class Permit2EvmScheme implements SchemeNetworkClient {
11
+ private readonly signer;
12
+ readonly scheme = "permit2";
13
+ /**
14
+ * Creates a new Permit2EvmScheme instance.
15
+ *
16
+ * @param signer - The EVM signer for client operations
17
+ */
18
+ constructor(signer: ClientEvmSigner);
19
+ /**
20
+ * Creates a payment payload for the Permit2 scheme.
21
+ *
22
+ * @param t402Version - The t402 protocol version
23
+ * @param paymentRequirements - The payment requirements
24
+ * @returns Promise resolving to a payment payload
25
+ */
26
+ createPaymentPayload(t402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "t402Version" | "payload">>;
27
+ /**
28
+ * Sign the Permit2 SignatureTransfer using EIP-712
29
+ *
30
+ * @param permit - The permit transfer data
31
+ * @param spender - The spender address
32
+ * @param requirements - The payment requirements
33
+ * @returns Signed typed data hex string
34
+ */
35
+ private signPermit2;
36
+ }
37
+
38
+ /**
39
+ * Configuration options for registering Permit2 EVM schemes to an t402Client
40
+ */
41
+ interface Permit2EvmClientConfig {
42
+ /**
43
+ * The EVM signer to use for creating payment payloads
44
+ */
45
+ signer: ClientEvmSigner;
46
+ /**
47
+ * Optional payment requirements selector function
48
+ * If not provided, uses the default selector (first available option)
49
+ */
50
+ paymentRequirementsSelector?: SelectPaymentRequirements;
51
+ /**
52
+ * Optional policies to apply to the client
53
+ */
54
+ policies?: PaymentPolicy[];
55
+ /**
56
+ * Optional specific networks to register
57
+ * If not provided, registers wildcard support (eip155:*)
58
+ */
59
+ networks?: Network[];
60
+ }
61
+ /**
62
+ * Registers Permit2 EVM payment schemes to an t402Client instance.
63
+ *
64
+ * @param client - The t402Client instance to register schemes to
65
+ * @param config - Configuration for Permit2 EVM client registration
66
+ * @returns The client instance for chaining
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { registerPermit2EvmScheme } from "@t402/evm/permit2/client";
71
+ * import { t402Client } from "@t402/core/client";
72
+ * import { privateKeyToAccount } from "viem/accounts";
73
+ *
74
+ * const account = privateKeyToAccount("0x...");
75
+ * const client = new t402Client();
76
+ * registerPermit2EvmScheme(client, { signer: account });
77
+ * ```
78
+ */
79
+ declare function registerPermit2EvmScheme(client: t402Client, config: Permit2EvmClientConfig): t402Client;
80
+
81
+ export { type Permit2EvmClientConfig, Permit2EvmScheme, registerPermit2EvmScheme };
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/permit2/client/index.ts
23
+ var client_exports = {};
24
+ __export(client_exports, {
25
+ Permit2EvmScheme: () => Permit2EvmScheme,
26
+ registerPermit2EvmScheme: () => registerPermit2EvmScheme
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+
30
+ // src/permit2/client/scheme.ts
31
+ var import_viem = require("viem");
32
+
33
+ // src/permit2/constants.ts
34
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
35
+ var permit2Types = {
36
+ PermitTransferFrom: [
37
+ { name: "permitted", type: "TokenPermissions" },
38
+ { name: "spender", type: "address" },
39
+ { name: "nonce", type: "uint256" },
40
+ { name: "deadline", type: "uint256" }
41
+ ],
42
+ TokenPermissions: [
43
+ { name: "token", type: "address" },
44
+ { name: "amount", type: "uint256" }
45
+ ]
46
+ };
47
+
48
+ // src/permit2/client/scheme.ts
49
+ var Permit2EvmScheme = class {
50
+ /**
51
+ * Creates a new Permit2EvmScheme instance.
52
+ *
53
+ * @param signer - The EVM signer for client operations
54
+ */
55
+ constructor(signer) {
56
+ this.signer = signer;
57
+ __publicField(this, "scheme", "permit2");
58
+ }
59
+ /**
60
+ * Creates a payment payload for the Permit2 scheme.
61
+ *
62
+ * @param t402Version - The t402 protocol version
63
+ * @param paymentRequirements - The payment requirements
64
+ * @returns Promise resolving to a payment payload
65
+ */
66
+ async createPaymentPayload(t402Version, paymentRequirements) {
67
+ const now = Math.floor(Date.now() / 1e3);
68
+ const deadline = now + paymentRequirements.maxTimeoutSeconds;
69
+ const nonce = BigInt(
70
+ "0x" + Array.from(globalThis.crypto.getRandomValues(new Uint8Array(32))).map((b) => b.toString(16).padStart(2, "0")).join("")
71
+ ).toString();
72
+ const permit = {
73
+ permitted: {
74
+ token: (0, import_viem.getAddress)(paymentRequirements.asset),
75
+ amount: paymentRequirements.amount
76
+ },
77
+ nonce,
78
+ deadline: deadline.toString()
79
+ };
80
+ const transferDetails = {
81
+ to: (0, import_viem.getAddress)(paymentRequirements.payTo),
82
+ requestedAmount: paymentRequirements.amount
83
+ };
84
+ const signature = await this.signPermit2(permit, transferDetails.to, paymentRequirements);
85
+ const payload = {
86
+ permit,
87
+ transferDetails,
88
+ signature,
89
+ owner: this.signer.address
90
+ };
91
+ return {
92
+ t402Version,
93
+ payload
94
+ };
95
+ }
96
+ /**
97
+ * Sign the Permit2 SignatureTransfer using EIP-712
98
+ *
99
+ * @param permit - The permit transfer data
100
+ * @param spender - The spender address
101
+ * @param requirements - The payment requirements
102
+ * @returns Signed typed data hex string
103
+ */
104
+ async signPermit2(permit, spender, requirements) {
105
+ const chainId = parseInt(requirements.network.split(":")[1]);
106
+ const domain = {
107
+ name: "Permit2",
108
+ chainId,
109
+ verifyingContract: PERMIT2_ADDRESS
110
+ };
111
+ const message = {
112
+ permitted: {
113
+ token: permit.permitted.token,
114
+ amount: BigInt(permit.permitted.amount)
115
+ },
116
+ spender,
117
+ nonce: BigInt(permit.nonce),
118
+ deadline: BigInt(permit.deadline)
119
+ };
120
+ return await this.signer.signTypedData({
121
+ domain,
122
+ types: permit2Types,
123
+ primaryType: "PermitTransferFrom",
124
+ message
125
+ });
126
+ }
127
+ };
128
+
129
+ // src/permit2/client/register.ts
130
+ function registerPermit2EvmScheme(client, config) {
131
+ if (config.networks && config.networks.length > 0) {
132
+ config.networks.forEach((network) => {
133
+ client.register(network, new Permit2EvmScheme(config.signer));
134
+ });
135
+ } else {
136
+ client.register("eip155:*", new Permit2EvmScheme(config.signer));
137
+ }
138
+ if (config.policies) {
139
+ config.policies.forEach((policy) => {
140
+ client.registerPolicy(policy);
141
+ });
142
+ }
143
+ return client;
144
+ }
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ Permit2EvmScheme,
148
+ registerPermit2EvmScheme
149
+ });
150
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/permit2/client/index.ts","../../../../src/permit2/client/scheme.ts","../../../../src/permit2/constants.ts","../../../../src/permit2/client/register.ts"],"sourcesContent":["export { Permit2EvmScheme } from \"./scheme\";\nexport { registerPermit2EvmScheme } from \"./register\";\nexport type { Permit2EvmClientConfig } from \"./register\";\n","import { PaymentPayload, PaymentRequirements, SchemeNetworkClient } from \"@t402/core/types\";\nimport { getAddress } from \"viem\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { Permit2PayloadV2 } from \"../types\";\nimport { PERMIT2_ADDRESS, permit2Types } from \"../constants\";\n\n/**\n * EVM client implementation for the Permit2 payment scheme.\n *\n * Uses Uniswap Permit2 SignatureTransfer for gasless token approvals.\n */\nexport class Permit2EvmScheme implements SchemeNetworkClient {\n readonly scheme = \"permit2\";\n\n /**\n * Creates a new Permit2EvmScheme instance.\n *\n * @param signer - The EVM signer for client operations\n */\n constructor(private readonly signer: ClientEvmSigner) {}\n\n /**\n * Creates a payment payload for the Permit2 scheme.\n *\n * @param t402Version - The t402 protocol version\n * @param paymentRequirements - The payment requirements\n * @returns Promise resolving to a payment payload\n */\n async createPaymentPayload(\n t402Version: number,\n paymentRequirements: PaymentRequirements,\n ): Promise<Pick<PaymentPayload, \"t402Version\" | \"payload\">> {\n const now = Math.floor(Date.now() / 1000);\n const deadline = now + paymentRequirements.maxTimeoutSeconds;\n\n // Use a random nonce (Permit2 nonces are not sequential for SignatureTransfer)\n const nonce = BigInt(\n \"0x\" +\n Array.from(globalThis.crypto.getRandomValues(new Uint8Array(32)))\n .map(b => b.toString(16).padStart(2, \"0\"))\n .join(\"\"),\n ).toString();\n\n const permit = {\n permitted: {\n token: getAddress(paymentRequirements.asset) as `0x${string}`,\n amount: paymentRequirements.amount,\n },\n nonce,\n deadline: deadline.toString(),\n };\n\n const transferDetails = {\n to: getAddress(paymentRequirements.payTo) as `0x${string}`,\n requestedAmount: paymentRequirements.amount,\n };\n\n // Sign the Permit2 typed data\n const signature = await this.signPermit2(permit, transferDetails.to, paymentRequirements);\n\n const payload: Permit2PayloadV2 = {\n permit,\n transferDetails,\n signature,\n owner: this.signer.address,\n };\n\n return {\n t402Version,\n payload,\n };\n }\n\n /**\n * Sign the Permit2 SignatureTransfer using EIP-712\n *\n * @param permit - The permit transfer data\n * @param spender - The spender address\n * @param requirements - The payment requirements\n * @returns Signed typed data hex string\n */\n private async signPermit2(\n permit: Permit2PayloadV2[\"permit\"],\n spender: `0x${string}`,\n requirements: PaymentRequirements,\n ): Promise<`0x${string}`> {\n const chainId = parseInt(requirements.network.split(\":\")[1]);\n\n const domain = {\n name: \"Permit2\",\n chainId,\n verifyingContract: PERMIT2_ADDRESS,\n };\n\n const message = {\n permitted: {\n token: permit.permitted.token,\n amount: BigInt(permit.permitted.amount),\n },\n spender,\n nonce: BigInt(permit.nonce),\n deadline: BigInt(permit.deadline),\n };\n\n return await this.signer.signTypedData({\n domain,\n types: permit2Types,\n primaryType: \"PermitTransferFrom\",\n message,\n });\n }\n}\n","/**\n * Permit2 Constants\n *\n * Uniswap Permit2 contract addresses, type hashes, and ABI fragments.\n */\n\n/** Canonical Permit2 contract address (same on all EVM chains) */\nexport const PERMIT2_ADDRESS = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\" as const;\n\n/** EIP-712 type definitions for Permit2 SignatureTransfer */\nexport const permit2Types = {\n PermitTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n} as const;\n\n/** Permit2 ABI for permitTransferFrom */\nexport const permit2ABI = [\n {\n inputs: [\n {\n components: [\n {\n components: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n name: \"permitted\",\n type: \"tuple\",\n },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n name: \"permit\",\n type: \"tuple\",\n },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"requestedAmount\", type: \"uint256\" },\n ],\n name: \"transferDetails\",\n type: \"tuple\",\n },\n { name: \"owner\", type: \"address\" },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"permitTransferFrom\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n\n/** ERC20 balanceOf ABI for balance checks */\nexport const erc20BalanceABI = [\n {\n inputs: [{ name: \"account\", type: \"address\" }],\n name: \"balanceOf\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n","import { t402Client, SelectPaymentRequirements, PaymentPolicy } from \"@t402/core/client\";\nimport { Network } from \"@t402/core/types\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { Permit2EvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering Permit2 EVM schemes to an t402Client\n */\nexport interface Permit2EvmClientConfig {\n /**\n * The EVM signer to use for creating payment payloads\n */\n signer: ClientEvmSigner;\n\n /**\n * Optional payment requirements selector function\n * If not provided, uses the default selector (first available option)\n */\n paymentRequirementsSelector?: SelectPaymentRequirements;\n\n /**\n * Optional policies to apply to the client\n */\n policies?: PaymentPolicy[];\n\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers Permit2 EVM payment schemes to an t402Client instance.\n *\n * @param client - The t402Client instance to register schemes to\n * @param config - Configuration for Permit2 EVM client registration\n * @returns The client instance for chaining\n *\n * @example\n * ```typescript\n * import { registerPermit2EvmScheme } from \"@t402/evm/permit2/client\";\n * import { t402Client } from \"@t402/core/client\";\n * import { privateKeyToAccount } from \"viem/accounts\";\n *\n * const account = privateKeyToAccount(\"0x...\");\n * const client = new t402Client();\n * registerPermit2EvmScheme(client, { signer: account });\n * ```\n */\nexport function registerPermit2EvmScheme(\n client: t402Client,\n config: Permit2EvmClientConfig,\n): t402Client {\n if (config.networks && config.networks.length > 0) {\n config.networks.forEach(network => {\n client.register(network, new Permit2EvmScheme(config.signer));\n });\n } else {\n client.register(\"eip155:*\", new Permit2EvmScheme(config.signer));\n }\n\n if (config.policies) {\n config.policies.forEach(policy => {\n client.registerPolicy(policy);\n });\n }\n\n return client;\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,82 @@
1
+ import { SchemeNetworkFacilitator, PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, Network } from '@t402/core/types';
2
+ import { F as FacilitatorEvmSigner } from '../../signer-DcavxxZt.js';
3
+ import { t402Facilitator } from '@t402/core/facilitator';
4
+
5
+ /**
6
+ * Configuration for Permit2 EVM facilitator
7
+ */
8
+ interface Permit2EvmSchemeConfig {
9
+ [key: string]: unknown;
10
+ }
11
+ /**
12
+ * EVM facilitator implementation for the Permit2 payment scheme.
13
+ *
14
+ * Verifies Permit2 signatures and settles payments by calling
15
+ * permitTransferFrom on the Permit2 contract.
16
+ */
17
+ declare class Permit2EvmScheme implements SchemeNetworkFacilitator {
18
+ private readonly signer;
19
+ readonly scheme = "permit2";
20
+ readonly caipFamily = "eip155:*";
21
+ /**
22
+ * Creates a new Permit2 facilitator instance.
23
+ *
24
+ * @param signer - The facilitator EVM signer
25
+ */
26
+ constructor(signer: FacilitatorEvmSigner);
27
+ /**
28
+ * Get mechanism-specific extra data for supported kinds.
29
+ *
30
+ * @param _ - The network identifier
31
+ * @returns Extra data including permit2 contract address
32
+ */
33
+ getExtra(_: string): Record<string, unknown> | undefined;
34
+ /**
35
+ * Get signer addresses for this facilitator.
36
+ *
37
+ * @param _ - The network identifier
38
+ * @returns Array of signer addresses
39
+ */
40
+ getSigners(_: string): string[];
41
+ /**
42
+ * Verify a Permit2 payment payload.
43
+ *
44
+ * @param payload - The payment payload to verify
45
+ * @param requirements - The payment requirements
46
+ * @returns Verification result
47
+ */
48
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
49
+ /**
50
+ * Settle a Permit2 payment by executing permitTransferFrom.
51
+ *
52
+ * @param payload - The payment payload
53
+ * @param requirements - The payment requirements
54
+ * @returns Settlement result
55
+ */
56
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
57
+ }
58
+
59
+ /**
60
+ * Configuration options for registering Permit2 schemes to an t402Facilitator
61
+ */
62
+ interface Permit2EvmFacilitatorConfig {
63
+ /**
64
+ * The EVM signer for facilitator operations (verify and settle)
65
+ */
66
+ signer: FacilitatorEvmSigner;
67
+ /**
68
+ * Networks to register (single network or array of networks)
69
+ * Examples: "eip155:84532", ["eip155:84532", "eip155:1"]
70
+ */
71
+ networks: Network | Network[];
72
+ }
73
+ /**
74
+ * Registers Permit2 EVM payment schemes to an t402Facilitator instance.
75
+ *
76
+ * @param facilitator - The t402Facilitator instance to register schemes to
77
+ * @param config - Configuration for Permit2 EVM facilitator registration
78
+ * @returns The facilitator instance for chaining
79
+ */
80
+ declare function registerPermit2EvmScheme(facilitator: t402Facilitator, config: Permit2EvmFacilitatorConfig): t402Facilitator;
81
+
82
+ export { type Permit2EvmFacilitatorConfig, Permit2EvmScheme, type Permit2EvmSchemeConfig, registerPermit2EvmScheme };