@t402/evm 2.6.1 → 2.7.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 (37) hide show
  1. package/dist/cjs/constants-05D7IZJA.d.ts +136 -0
  2. package/dist/cjs/permit2/index.d.ts +1 -137
  3. package/dist/cjs/permit2-proxy/client/index.d.ts +83 -0
  4. package/dist/cjs/permit2-proxy/client/index.js +182 -0
  5. package/dist/cjs/permit2-proxy/client/index.js.map +1 -0
  6. package/dist/cjs/permit2-proxy/facilitator/index.d.ts +93 -0
  7. package/dist/cjs/permit2-proxy/facilitator/index.js +368 -0
  8. package/dist/cjs/permit2-proxy/facilitator/index.js.map +1 -0
  9. package/dist/cjs/permit2-proxy/index.d.ts +344 -0
  10. package/dist/cjs/permit2-proxy/index.js +1274 -0
  11. package/dist/cjs/permit2-proxy/index.js.map +1 -0
  12. package/dist/cjs/permit2-proxy/server/index.d.ts +130 -0
  13. package/dist/cjs/permit2-proxy/server/index.js +695 -0
  14. package/dist/cjs/permit2-proxy/server/index.js.map +1 -0
  15. package/dist/esm/chunk-A2U6NWHQ.mjs +199 -0
  16. package/dist/esm/chunk-A2U6NWHQ.mjs.map +1 -0
  17. package/dist/esm/chunk-HUUYTNV2.mjs +138 -0
  18. package/dist/esm/chunk-HUUYTNV2.mjs.map +1 -0
  19. package/dist/esm/chunk-THXENBBU.mjs +251 -0
  20. package/dist/esm/chunk-THXENBBU.mjs.map +1 -0
  21. package/dist/esm/chunk-UK2POASM.mjs +204 -0
  22. package/dist/esm/chunk-UK2POASM.mjs.map +1 -0
  23. package/dist/esm/constants-05D7IZJA.d.mts +136 -0
  24. package/dist/esm/permit2/index.d.mts +1 -137
  25. package/dist/esm/permit2-proxy/client/index.d.mts +83 -0
  26. package/dist/esm/permit2-proxy/client/index.mjs +12 -0
  27. package/dist/esm/permit2-proxy/client/index.mjs.map +1 -0
  28. package/dist/esm/permit2-proxy/facilitator/index.d.mts +93 -0
  29. package/dist/esm/permit2-proxy/facilitator/index.mjs +12 -0
  30. package/dist/esm/permit2-proxy/facilitator/index.mjs.map +1 -0
  31. package/dist/esm/permit2-proxy/index.d.mts +344 -0
  32. package/dist/esm/permit2-proxy/index.mjs +45 -0
  33. package/dist/esm/permit2-proxy/index.mjs.map +1 -0
  34. package/dist/esm/permit2-proxy/server/index.d.mts +130 -0
  35. package/dist/esm/permit2-proxy/server/index.mjs +13 -0
  36. package/dist/esm/permit2-proxy/server/index.mjs.map +1 -0
  37. package/package.json +43 -3
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Permit2 Types
3
+ *
4
+ * Type definitions for Uniswap Permit2 SignatureTransfer scheme.
5
+ */
6
+ /**
7
+ * Token permissions for Permit2
8
+ */
9
+ type TokenPermissions = {
10
+ /** ERC20 token address */
11
+ token: `0x${string}`;
12
+ /** Maximum amount permitted to transfer */
13
+ amount: string;
14
+ };
15
+ /**
16
+ * Permit2 PermitTransferFrom parameters
17
+ */
18
+ type PermitTransferFrom = {
19
+ /** Token and amount permissions */
20
+ permitted: TokenPermissions;
21
+ /** Unique nonce (monotonically increasing per owner on the Permit2 contract) */
22
+ nonce: string;
23
+ /** Unix timestamp deadline for the permit */
24
+ deadline: string;
25
+ };
26
+ /**
27
+ * Transfer details for Permit2
28
+ */
29
+ type SignatureTransferDetails = {
30
+ /** Recipient address */
31
+ to: `0x${string}`;
32
+ /** Requested transfer amount */
33
+ requestedAmount: string;
34
+ };
35
+ /**
36
+ * Permit2 payment payload (V2)
37
+ */
38
+ type Permit2PayloadV2 = {
39
+ /** The permit parameters */
40
+ permit: PermitTransferFrom;
41
+ /** Transfer destination and amount */
42
+ transferDetails: SignatureTransferDetails;
43
+ /** EIP-712 signature */
44
+ signature: `0x${string}`;
45
+ /** Token owner address */
46
+ owner: `0x${string}`;
47
+ };
48
+
49
+ /**
50
+ * Permit2 Constants
51
+ *
52
+ * Uniswap Permit2 contract addresses, type hashes, and ABI fragments.
53
+ */
54
+ /** Canonical Permit2 contract address (same on all EVM chains) */
55
+ declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
56
+ /** EIP-712 type definitions for Permit2 SignatureTransfer */
57
+ declare const permit2Types: {
58
+ readonly PermitTransferFrom: readonly [{
59
+ readonly name: "permitted";
60
+ readonly type: "TokenPermissions";
61
+ }, {
62
+ readonly name: "spender";
63
+ readonly type: "address";
64
+ }, {
65
+ readonly name: "nonce";
66
+ readonly type: "uint256";
67
+ }, {
68
+ readonly name: "deadline";
69
+ readonly type: "uint256";
70
+ }];
71
+ readonly TokenPermissions: readonly [{
72
+ readonly name: "token";
73
+ readonly type: "address";
74
+ }, {
75
+ readonly name: "amount";
76
+ readonly type: "uint256";
77
+ }];
78
+ };
79
+ /** Permit2 ABI for permitTransferFrom */
80
+ declare const permit2ABI: readonly [{
81
+ readonly inputs: readonly [{
82
+ readonly components: readonly [{
83
+ readonly components: readonly [{
84
+ readonly name: "token";
85
+ readonly type: "address";
86
+ }, {
87
+ readonly name: "amount";
88
+ readonly type: "uint256";
89
+ }];
90
+ readonly name: "permitted";
91
+ readonly type: "tuple";
92
+ }, {
93
+ readonly name: "nonce";
94
+ readonly type: "uint256";
95
+ }, {
96
+ readonly name: "deadline";
97
+ readonly type: "uint256";
98
+ }];
99
+ readonly name: "permit";
100
+ readonly type: "tuple";
101
+ }, {
102
+ readonly components: readonly [{
103
+ readonly name: "to";
104
+ readonly type: "address";
105
+ }, {
106
+ readonly name: "requestedAmount";
107
+ readonly type: "uint256";
108
+ }];
109
+ readonly name: "transferDetails";
110
+ readonly type: "tuple";
111
+ }, {
112
+ readonly name: "owner";
113
+ readonly type: "address";
114
+ }, {
115
+ readonly name: "signature";
116
+ readonly type: "bytes";
117
+ }];
118
+ readonly name: "permitTransferFrom";
119
+ readonly outputs: readonly [];
120
+ readonly stateMutability: "nonpayable";
121
+ readonly type: "function";
122
+ }, {
123
+ readonly inputs: readonly [{
124
+ readonly name: "account";
125
+ readonly type: "address";
126
+ }];
127
+ readonly name: "balanceOf";
128
+ readonly outputs: readonly [{
129
+ readonly name: "";
130
+ readonly type: "uint256";
131
+ }];
132
+ readonly stateMutability: "view";
133
+ readonly type: "function";
134
+ }];
135
+
136
+ export { PERMIT2_ADDRESS as P, type SignatureTransferDetails as S, type TokenPermissions as T, type Permit2PayloadV2 as a, type PermitTransferFrom as b, permit2Types as c, permit2ABI as p };
@@ -1,145 +1,9 @@
1
1
  export { Permit2EvmClientConfig, Permit2EvmScheme as Permit2EvmClientScheme, registerPermit2EvmScheme as registerPermit2EvmClientScheme } from './client/index.js';
2
2
  export { P as Permit2EvmResourceServerConfig, a as Permit2EvmServerScheme, b as Permit2EvmServerSchemeConfig, r as registerPermit2EvmServerScheme } from '../index-fzI2FyBT.js';
3
3
  export { Permit2EvmFacilitatorConfig, Permit2EvmScheme as Permit2EvmFacilitatorScheme, Permit2EvmSchemeConfig as Permit2EvmFacilitatorSchemeConfig, registerPermit2EvmScheme as registerPermit2EvmFacilitatorScheme } from './facilitator/index.js';
4
+ export { P as PERMIT2_ADDRESS, a as Permit2PayloadV2, b as PermitTransferFrom, S as SignatureTransferDetails, T as TokenPermissions, p as permit2ABI, c as permit2Types } from '../constants-05D7IZJA.js';
4
5
  import '@t402/core/types';
5
6
  import '../signer-DcavxxZt.js';
6
7
  import '@t402/core/client';
7
8
  import '@t402/core/server';
8
9
  import '@t402/core/facilitator';
9
-
10
- /**
11
- * Permit2 Types
12
- *
13
- * Type definitions for Uniswap Permit2 SignatureTransfer scheme.
14
- */
15
- /**
16
- * Token permissions for Permit2
17
- */
18
- type TokenPermissions = {
19
- /** ERC20 token address */
20
- token: `0x${string}`;
21
- /** Maximum amount permitted to transfer */
22
- amount: string;
23
- };
24
- /**
25
- * Permit2 PermitTransferFrom parameters
26
- */
27
- type PermitTransferFrom = {
28
- /** Token and amount permissions */
29
- permitted: TokenPermissions;
30
- /** Unique nonce (monotonically increasing per owner on the Permit2 contract) */
31
- nonce: string;
32
- /** Unix timestamp deadline for the permit */
33
- deadline: string;
34
- };
35
- /**
36
- * Transfer details for Permit2
37
- */
38
- type SignatureTransferDetails = {
39
- /** Recipient address */
40
- to: `0x${string}`;
41
- /** Requested transfer amount */
42
- requestedAmount: string;
43
- };
44
- /**
45
- * Permit2 payment payload (V2)
46
- */
47
- type Permit2PayloadV2 = {
48
- /** The permit parameters */
49
- permit: PermitTransferFrom;
50
- /** Transfer destination and amount */
51
- transferDetails: SignatureTransferDetails;
52
- /** EIP-712 signature */
53
- signature: `0x${string}`;
54
- /** Token owner address */
55
- owner: `0x${string}`;
56
- };
57
-
58
- /**
59
- * Permit2 Constants
60
- *
61
- * Uniswap Permit2 contract addresses, type hashes, and ABI fragments.
62
- */
63
- /** Canonical Permit2 contract address (same on all EVM chains) */
64
- declare const PERMIT2_ADDRESS: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
65
- /** EIP-712 type definitions for Permit2 SignatureTransfer */
66
- declare const permit2Types: {
67
- readonly PermitTransferFrom: readonly [{
68
- readonly name: "permitted";
69
- readonly type: "TokenPermissions";
70
- }, {
71
- readonly name: "spender";
72
- readonly type: "address";
73
- }, {
74
- readonly name: "nonce";
75
- readonly type: "uint256";
76
- }, {
77
- readonly name: "deadline";
78
- readonly type: "uint256";
79
- }];
80
- readonly TokenPermissions: readonly [{
81
- readonly name: "token";
82
- readonly type: "address";
83
- }, {
84
- readonly name: "amount";
85
- readonly type: "uint256";
86
- }];
87
- };
88
- /** Permit2 ABI for permitTransferFrom */
89
- declare const permit2ABI: readonly [{
90
- readonly inputs: readonly [{
91
- readonly components: readonly [{
92
- readonly components: readonly [{
93
- readonly name: "token";
94
- readonly type: "address";
95
- }, {
96
- readonly name: "amount";
97
- readonly type: "uint256";
98
- }];
99
- readonly name: "permitted";
100
- readonly type: "tuple";
101
- }, {
102
- readonly name: "nonce";
103
- readonly type: "uint256";
104
- }, {
105
- readonly name: "deadline";
106
- readonly type: "uint256";
107
- }];
108
- readonly name: "permit";
109
- readonly type: "tuple";
110
- }, {
111
- readonly components: readonly [{
112
- readonly name: "to";
113
- readonly type: "address";
114
- }, {
115
- readonly name: "requestedAmount";
116
- readonly type: "uint256";
117
- }];
118
- readonly name: "transferDetails";
119
- readonly type: "tuple";
120
- }, {
121
- readonly name: "owner";
122
- readonly type: "address";
123
- }, {
124
- readonly name: "signature";
125
- readonly type: "bytes";
126
- }];
127
- readonly name: "permitTransferFrom";
128
- readonly outputs: readonly [];
129
- readonly stateMutability: "nonpayable";
130
- readonly type: "function";
131
- }, {
132
- readonly inputs: readonly [{
133
- readonly name: "account";
134
- readonly type: "address";
135
- }];
136
- readonly name: "balanceOf";
137
- readonly outputs: readonly [{
138
- readonly name: "";
139
- readonly type: "uint256";
140
- }];
141
- readonly stateMutability: "view";
142
- readonly type: "function";
143
- }];
144
-
145
- export { PERMIT2_ADDRESS, type Permit2PayloadV2, type PermitTransferFrom, type SignatureTransferDetails, type TokenPermissions, permit2ABI, permit2Types };
@@ -0,0 +1,83 @@
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 Proxy payment scheme.
7
+ *
8
+ * Uses Uniswap Permit2 PermitWitnessTransferFrom with a Witness struct
9
+ * that binds the payment to a specific facilitator and destination.
10
+ */
11
+ declare class Permit2ProxyEvmScheme implements SchemeNetworkClient {
12
+ private readonly signer;
13
+ readonly scheme: "permit2-proxy";
14
+ /**
15
+ * Creates a new Permit2ProxyEvmScheme instance.
16
+ *
17
+ * @param signer - The EVM signer for client operations
18
+ */
19
+ constructor(signer: ClientEvmSigner);
20
+ /**
21
+ * Creates a payment payload for the Permit2 Proxy scheme.
22
+ *
23
+ * @param t402Version - The t402 protocol version
24
+ * @param paymentRequirements - The payment requirements
25
+ * @returns Promise resolving to a payment payload
26
+ */
27
+ createPaymentPayload(t402Version: number, paymentRequirements: PaymentRequirements): Promise<Pick<PaymentPayload, "t402Version" | "payload">>;
28
+ /**
29
+ * Sign the Permit2 PermitWitnessTransferFrom using EIP-712.
30
+ *
31
+ * @param permit - The permit transfer data
32
+ * @param witness - The witness data
33
+ * @param spender - The proxy contract address (spender in Permit2)
34
+ * @param requirements - The payment requirements
35
+ * @returns Signed typed data hex string
36
+ */
37
+ private signPermit2Witness;
38
+ }
39
+
40
+ /**
41
+ * Configuration options for registering Permit2 Proxy EVM schemes to an t402Client
42
+ */
43
+ interface Permit2ProxyEvmClientConfig {
44
+ /**
45
+ * The EVM signer to use for creating payment payloads
46
+ */
47
+ signer: ClientEvmSigner;
48
+ /**
49
+ * Optional payment requirements selector function
50
+ * If not provided, uses the default selector (first available option)
51
+ */
52
+ paymentRequirementsSelector?: SelectPaymentRequirements;
53
+ /**
54
+ * Optional policies to apply to the client
55
+ */
56
+ policies?: PaymentPolicy[];
57
+ /**
58
+ * Optional specific networks to register
59
+ * If not provided, registers wildcard support (eip155:*)
60
+ */
61
+ networks?: Network[];
62
+ }
63
+ /**
64
+ * Registers Permit2 Proxy EVM payment schemes to an t402Client instance.
65
+ *
66
+ * @param client - The t402Client instance to register schemes to
67
+ * @param config - Configuration for Permit2 Proxy EVM client registration
68
+ * @returns The client instance for chaining
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * import { registerPermit2ProxyEvmScheme } from "@t402/evm/permit2-proxy/client";
73
+ * import { t402Client } from "@t402/core/client";
74
+ * import { privateKeyToAccount } from "viem/accounts";
75
+ *
76
+ * const account = privateKeyToAccount("0x...");
77
+ * const client = new t402Client();
78
+ * registerPermit2ProxyEvmScheme(client, { signer: account });
79
+ * ```
80
+ */
81
+ declare function registerPermit2ProxyEvmScheme(client: t402Client, config: Permit2ProxyEvmClientConfig): t402Client;
82
+
83
+ export { type Permit2ProxyEvmClientConfig, Permit2ProxyEvmScheme, registerPermit2ProxyEvmScheme };
@@ -0,0 +1,182 @@
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-proxy/client/index.ts
23
+ var client_exports = {};
24
+ __export(client_exports, {
25
+ Permit2ProxyEvmScheme: () => Permit2ProxyEvmScheme,
26
+ registerPermit2ProxyEvmScheme: () => registerPermit2ProxyEvmScheme
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+
30
+ // src/permit2-proxy/client/scheme.ts
31
+ var import_viem = require("viem");
32
+
33
+ // src/permit2/constants.ts
34
+ var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
35
+
36
+ // src/permit2-proxy/constants.ts
37
+ var SCHEME_PERMIT2_PROXY = "permit2-proxy";
38
+ var permit2WitnessTypes = {
39
+ PermitWitnessTransferFrom: [
40
+ { name: "permitted", type: "TokenPermissions" },
41
+ { name: "spender", type: "address" },
42
+ { name: "nonce", type: "uint256" },
43
+ { name: "deadline", type: "uint256" },
44
+ { name: "witness", type: "Witness" }
45
+ ],
46
+ TokenPermissions: [
47
+ { name: "token", type: "address" },
48
+ { name: "amount", type: "uint256" }
49
+ ],
50
+ Witness: [
51
+ { name: "to", type: "address" },
52
+ { name: "facilitator", type: "address" },
53
+ { name: "validAfter", type: "uint256" }
54
+ ]
55
+ };
56
+
57
+ // src/permit2-proxy/client/scheme.ts
58
+ var Permit2ProxyEvmScheme = class {
59
+ /**
60
+ * Creates a new Permit2ProxyEvmScheme instance.
61
+ *
62
+ * @param signer - The EVM signer for client operations
63
+ */
64
+ constructor(signer) {
65
+ this.signer = signer;
66
+ __publicField(this, "scheme", SCHEME_PERMIT2_PROXY);
67
+ }
68
+ /**
69
+ * Creates a payment payload for the Permit2 Proxy scheme.
70
+ *
71
+ * @param t402Version - The t402 protocol version
72
+ * @param paymentRequirements - The payment requirements
73
+ * @returns Promise resolving to a payment payload
74
+ */
75
+ async createPaymentPayload(t402Version, paymentRequirements) {
76
+ const now = Math.floor(Date.now() / 1e3);
77
+ const deadline = now + paymentRequirements.maxTimeoutSeconds;
78
+ const nonce = BigInt(
79
+ "0x" + Array.from(globalThis.crypto.getRandomValues(new Uint8Array(32))).map((b) => b.toString(16).padStart(2, "0")).join("")
80
+ ).toString();
81
+ const proxyAddress = paymentRequirements.extra?.exactProxyAddress || paymentRequirements.extra?.uptoProxyAddress;
82
+ if (!proxyAddress) {
83
+ throw new Error(
84
+ "Missing proxy address in payment requirements extra (exactProxyAddress or uptoProxyAddress)"
85
+ );
86
+ }
87
+ const facilitatorAddress = paymentRequirements.extra?.facilitator;
88
+ if (!facilitatorAddress) {
89
+ throw new Error("Missing facilitator address in payment requirements extra");
90
+ }
91
+ const permit = {
92
+ permitted: {
93
+ token: (0, import_viem.getAddress)(paymentRequirements.asset),
94
+ amount: paymentRequirements.amount
95
+ },
96
+ nonce,
97
+ deadline: deadline.toString()
98
+ };
99
+ const witness = {
100
+ to: (0, import_viem.getAddress)(paymentRequirements.payTo),
101
+ facilitator: (0, import_viem.getAddress)(facilitatorAddress),
102
+ validAfter: "0"
103
+ // Immediate validity
104
+ };
105
+ const signature = await this.signPermit2Witness(
106
+ permit,
107
+ witness,
108
+ proxyAddress,
109
+ paymentRequirements
110
+ );
111
+ const payload = {
112
+ permit,
113
+ witness,
114
+ signature,
115
+ owner: this.signer.address
116
+ };
117
+ return {
118
+ t402Version,
119
+ payload
120
+ };
121
+ }
122
+ /**
123
+ * Sign the Permit2 PermitWitnessTransferFrom using EIP-712.
124
+ *
125
+ * @param permit - The permit transfer data
126
+ * @param witness - The witness data
127
+ * @param spender - The proxy contract address (spender in Permit2)
128
+ * @param requirements - The payment requirements
129
+ * @returns Signed typed data hex string
130
+ */
131
+ async signPermit2Witness(permit, witness, spender, requirements) {
132
+ const chainId = parseInt(requirements.network.split(":")[1]);
133
+ const domain = {
134
+ name: "Permit2",
135
+ chainId,
136
+ verifyingContract: PERMIT2_ADDRESS
137
+ };
138
+ const message = {
139
+ permitted: {
140
+ token: permit.permitted.token,
141
+ amount: BigInt(permit.permitted.amount)
142
+ },
143
+ spender: (0, import_viem.getAddress)(spender),
144
+ nonce: BigInt(permit.nonce),
145
+ deadline: BigInt(permit.deadline),
146
+ witness: {
147
+ to: witness.to,
148
+ facilitator: witness.facilitator,
149
+ validAfter: BigInt(witness.validAfter)
150
+ }
151
+ };
152
+ return await this.signer.signTypedData({
153
+ domain,
154
+ types: permit2WitnessTypes,
155
+ primaryType: "PermitWitnessTransferFrom",
156
+ message
157
+ });
158
+ }
159
+ };
160
+
161
+ // src/permit2-proxy/client/register.ts
162
+ function registerPermit2ProxyEvmScheme(client, config) {
163
+ if (config.networks && config.networks.length > 0) {
164
+ config.networks.forEach((network) => {
165
+ client.register(network, new Permit2ProxyEvmScheme(config.signer));
166
+ });
167
+ } else {
168
+ client.register("eip155:*", new Permit2ProxyEvmScheme(config.signer));
169
+ }
170
+ if (config.policies) {
171
+ config.policies.forEach((policy) => {
172
+ client.registerPolicy(policy);
173
+ });
174
+ }
175
+ return client;
176
+ }
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ Permit2ProxyEvmScheme,
180
+ registerPermit2ProxyEvmScheme
181
+ });
182
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/permit2-proxy/client/index.ts","../../../../src/permit2-proxy/client/scheme.ts","../../../../src/permit2/constants.ts","../../../../src/permit2-proxy/constants.ts","../../../../src/permit2-proxy/client/register.ts"],"sourcesContent":["export { Permit2ProxyEvmScheme } from \"./scheme\";\nexport { registerPermit2ProxyEvmScheme } from \"./register\";\nexport type { Permit2ProxyEvmClientConfig } from \"./register\";\n","import { PaymentPayload, PaymentRequirements, SchemeNetworkClient } from \"@t402/core/types\";\nimport { getAddress } from \"viem\";\nimport { ClientEvmSigner } from \"../../signer\";\nimport { Permit2ProxyPayloadV2, T402Witness } from \"../types\";\nimport { PERMIT2_ADDRESS, SCHEME_PERMIT2_PROXY, permit2WitnessTypes } from \"../constants\";\n\n/**\n * EVM client implementation for the Permit2 Proxy payment scheme.\n *\n * Uses Uniswap Permit2 PermitWitnessTransferFrom with a Witness struct\n * that binds the payment to a specific facilitator and destination.\n */\nexport class Permit2ProxyEvmScheme implements SchemeNetworkClient {\n readonly scheme = SCHEME_PERMIT2_PROXY;\n\n /**\n * Creates a new Permit2ProxyEvmScheme 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 Proxy 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 bitmap-based, not sequential)\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 // Get proxy address from requirements extra (set by server's enhancePaymentRequirements)\n const proxyAddress = (paymentRequirements.extra?.exactProxyAddress ||\n paymentRequirements.extra?.uptoProxyAddress) as `0x${string}` | undefined;\n\n if (!proxyAddress) {\n throw new Error(\n \"Missing proxy address in payment requirements extra (exactProxyAddress or uptoProxyAddress)\",\n );\n }\n\n // Get facilitator address from requirements extra\n const facilitatorAddress = paymentRequirements.extra?.facilitator as\n | `0x${string}`\n | undefined;\n\n if (!facilitatorAddress) {\n throw new Error(\"Missing facilitator address in payment requirements extra\");\n }\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 // Build witness: binds the payment to a destination, facilitator, and time constraint\n const witness: T402Witness = {\n to: getAddress(paymentRequirements.payTo) as `0x${string}`,\n facilitator: getAddress(facilitatorAddress) as `0x${string}`,\n validAfter: \"0\", // Immediate validity\n };\n\n // Sign the PermitWitnessTransferFrom with Witness\n const signature = await this.signPermit2Witness(\n permit,\n witness,\n proxyAddress,\n paymentRequirements,\n );\n\n const payload: Permit2ProxyPayloadV2 = {\n permit,\n witness,\n signature,\n owner: this.signer.address,\n };\n\n return {\n t402Version,\n payload,\n };\n }\n\n /**\n * Sign the Permit2 PermitWitnessTransferFrom using EIP-712.\n *\n * @param permit - The permit transfer data\n * @param witness - The witness data\n * @param spender - The proxy contract address (spender in Permit2)\n * @param requirements - The payment requirements\n * @returns Signed typed data hex string\n */\n private async signPermit2Witness(\n permit: Permit2ProxyPayloadV2[\"permit\"],\n witness: T402Witness,\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: getAddress(spender),\n nonce: BigInt(permit.nonce),\n deadline: BigInt(permit.deadline),\n witness: {\n to: witness.to,\n facilitator: witness.facilitator,\n validAfter: BigInt(witness.validAfter),\n },\n };\n\n return await this.signer.signTypedData({\n domain,\n types: permit2WitnessTypes,\n primaryType: \"PermitWitnessTransferFrom\",\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","/**\n * Permit2 Proxy Constants\n *\n * Contract addresses, EIP-712 type definitions, and ABI fragments\n * for T402 Permit2 proxy contracts with witness-based settlement.\n */\n\n// Re-export shared Permit2 constants\nexport { PERMIT2_ADDRESS, erc20BalanceABI } from \"../permit2/constants\";\n\n/** Scheme identifier for Permit2 proxy */\nexport const SCHEME_PERMIT2_PROXY = \"permit2-proxy\" as const;\n\n/** T402 Exact Permit2 Proxy contract address (TBD - not yet deployed) */\nexport const T402_EXACT_PERMIT2_PROXY =\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`;\n\n/** T402 Upto Permit2 Proxy contract address (TBD - not yet deployed) */\nexport const T402_UPTO_PERMIT2_PROXY =\n \"0x0000000000000000000000000000000000000000\" as `0x${string}`;\n\n/**\n * EIP-712 typehash for the Witness struct.\n * Must match WITNESS_TYPEHASH in T402BasePermit2Proxy.sol:\n * keccak256(\"Witness(address to,address facilitator,uint256 validAfter)\")\n */\nexport const WITNESS_TYPEHASH =\n \"0x5e3bbbe812684a9a24e1e1b7fe7c5b763bfb791ee8423aed3b4e1a5a9e25c255\" as const;\n\n/**\n * Witness type string for Permit2's permitWitnessTransferFrom.\n * Format: \"Witness witness)TokenPermissions(...)Witness(...)\" -- types listed alphabetically.\n * Must match WITNESS_TYPE_STRING in T402BasePermit2Proxy.sol.\n */\nexport const WITNESS_TYPE_STRING =\n \"Witness witness)TokenPermissions(address token,uint256 amount)Witness(address to,address facilitator,uint256 validAfter)\" as const;\n\n/**\n * EIP-712 type definitions for PermitWitnessTransferFrom with Witness.\n * Used by clients when signing the permit with witness data.\n */\nexport const permit2WitnessTypes = {\n PermitWitnessTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"witness\", type: \"Witness\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n Witness: [\n { name: \"to\", type: \"address\" },\n { name: \"facilitator\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * ABI for T402ExactPermit2Proxy contract.\n * Includes settle() and settleWithPermit() functions.\n */\nexport const permit2ProxyExactABI = [\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 { name: \"owner\", type: \"address\" },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"facilitator\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\n ],\n name: \"witness\",\n type: \"tuple\",\n },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"settle\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n {\n components: [\n { name: \"value\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n ],\n name: \"permit2612\",\n type: \"tuple\",\n },\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 { name: \"owner\", type: \"address\" },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"facilitator\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\n ],\n name: \"witness\",\n type: \"tuple\",\n },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"settleWithPermit\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n\n/**\n * ABI for T402UptoPermit2Proxy contract.\n * Includes settle() and settleWithPermit() functions.\n */\nexport const permit2ProxyUptoABI = [\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 { name: \"amount\", type: \"uint256\" },\n { name: \"owner\", type: \"address\" },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"facilitator\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\n ],\n name: \"witness\",\n type: \"tuple\",\n },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"settle\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n {\n components: [\n { name: \"value\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n ],\n name: \"permit2612\",\n type: \"tuple\",\n },\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 { name: \"amount\", type: \"uint256\" },\n { name: \"owner\", type: \"address\" },\n {\n components: [\n { name: \"to\", type: \"address\" },\n { name: \"facilitator\", type: \"address\" },\n { name: \"validAfter\", type: \"uint256\" },\n ],\n name: \"witness\",\n type: \"tuple\",\n },\n { name: \"signature\", type: \"bytes\" },\n ],\n name: \"settleWithPermit\",\n outputs: [],\n stateMutability: \"nonpayable\",\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 { Permit2ProxyEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering Permit2 Proxy EVM schemes to an t402Client\n */\nexport interface Permit2ProxyEvmClientConfig {\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 Proxy EVM payment schemes to an t402Client instance.\n *\n * @param client - The t402Client instance to register schemes to\n * @param config - Configuration for Permit2 Proxy EVM client registration\n * @returns The client instance for chaining\n *\n * @example\n * ```typescript\n * import { registerPermit2ProxyEvmScheme } from \"@t402/evm/permit2-proxy/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 * registerPermit2ProxyEvmScheme(client, { signer: account });\n * ```\n */\nexport function registerPermit2ProxyEvmScheme(\n client: t402Client,\n config: Permit2ProxyEvmClientConfig,\n): t402Client {\n if (config.networks && config.networks.length > 0) {\n config.networks.forEach(network => {\n client.register(network, new Permit2ProxyEvmScheme(config.signer));\n });\n } else {\n client.register(\"eip155:*\", new Permit2ProxyEvmScheme(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":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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