@t402/extensions 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 (43) hide show
  1. package/dist/cjs/bazaar/index.js +1 -1
  2. package/dist/cjs/bazaar/index.js.map +1 -1
  3. package/dist/cjs/eip2612-gas-sponsoring/index.d.ts +337 -0
  4. package/dist/cjs/eip2612-gas-sponsoring/index.js +314 -0
  5. package/dist/cjs/eip2612-gas-sponsoring/index.js.map +1 -0
  6. package/dist/cjs/erc20-approval-gas-sponsoring/index.d.ts +316 -0
  7. package/dist/cjs/erc20-approval-gas-sponsoring/index.js +264 -0
  8. package/dist/cjs/erc20-approval-gas-sponsoring/index.js.map +1 -0
  9. package/dist/cjs/index.d.ts +3 -0
  10. package/dist/cjs/index.js +651 -1
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/payment-id/index.d.ts +142 -0
  13. package/dist/cjs/payment-id/index.js +101 -0
  14. package/dist/cjs/payment-id/index.js.map +1 -0
  15. package/dist/cjs/sign-in-with-x/index.d.ts +2 -1
  16. package/dist/cjs/sign-in-with-x/index.js +55 -0
  17. package/dist/cjs/sign-in-with-x/index.js.map +1 -1
  18. package/dist/esm/bazaar/index.mjs +1 -1
  19. package/dist/esm/{chunk-HMNJHSWM.mjs → chunk-2DKNRJSJ.mjs} +2 -2
  20. package/dist/esm/{chunk-HMNJHSWM.mjs.map → chunk-2DKNRJSJ.mjs.map} +1 -1
  21. package/dist/esm/chunk-OAWKCEAR.mjs +226 -0
  22. package/dist/esm/chunk-OAWKCEAR.mjs.map +1 -0
  23. package/dist/esm/chunk-S36A7YLQ.mjs +70 -0
  24. package/dist/esm/chunk-S36A7YLQ.mjs.map +1 -0
  25. package/dist/esm/chunk-VINC22RD.mjs +278 -0
  26. package/dist/esm/chunk-VINC22RD.mjs.map +1 -0
  27. package/dist/esm/{chunk-J3ZMNCIA.mjs → chunk-YKZ5P2JW.mjs} +56 -1
  28. package/dist/esm/chunk-YKZ5P2JW.mjs.map +1 -0
  29. package/dist/esm/eip2612-gas-sponsoring/index.d.mts +337 -0
  30. package/dist/esm/eip2612-gas-sponsoring/index.mjs +27 -0
  31. package/dist/esm/eip2612-gas-sponsoring/index.mjs.map +1 -0
  32. package/dist/esm/erc20-approval-gas-sponsoring/index.d.mts +316 -0
  33. package/dist/esm/erc20-approval-gas-sponsoring/index.mjs +31 -0
  34. package/dist/esm/erc20-approval-gas-sponsoring/index.mjs.map +1 -0
  35. package/dist/esm/index.d.mts +3 -0
  36. package/dist/esm/index.mjs +68 -2
  37. package/dist/esm/payment-id/index.d.mts +142 -0
  38. package/dist/esm/payment-id/index.mjs +17 -0
  39. package/dist/esm/payment-id/index.mjs.map +1 -0
  40. package/dist/esm/sign-in-with-x/index.d.mts +2 -1
  41. package/dist/esm/sign-in-with-x/index.mjs +1 -1
  42. package/package.json +48 -11
  43. package/dist/esm/chunk-J3ZMNCIA.mjs.map +0 -1
@@ -0,0 +1,337 @@
1
+ /**
2
+ * EIP-2612 Gas Sponsoring Extension Type Definitions
3
+ *
4
+ * EIP-2612 permit-based gas sponsoring for the t402 payment protocol.
5
+ * Allows facilitators to sponsor gas fees by having clients sign off-chain
6
+ * permits instead of submitting on-chain approval transactions.
7
+ */
8
+ /**
9
+ * Information provided by server about gas sponsoring availability.
10
+ */
11
+ interface Eip2612GasSponsorExtensionInfo {
12
+ /** CAIP-2 network identifiers where gas sponsoring is available */
13
+ sponsoredNetworks: string[];
14
+ /** Maximum token amount (in base units) the sponsor will cover per permit */
15
+ maxAmount: string;
16
+ /** Default permit deadline in seconds from now */
17
+ permitDeadline: number;
18
+ /** Address of the sponsor/facilitator that will call permit + transferFrom */
19
+ sponsorAddress: string;
20
+ }
21
+ /**
22
+ * Gas sponsor extension declaration for server responses.
23
+ */
24
+ interface Eip2612GasSponsorExtension {
25
+ /** Extension information */
26
+ info: Eip2612GasSponsorExtensionInfo;
27
+ /** JSON Schema for validation */
28
+ schema: object;
29
+ }
30
+ /**
31
+ * Complete gas sponsor payload from client including permit signature.
32
+ */
33
+ interface Eip2612GasSponsorPayload {
34
+ /** CAIP-2 network identifier (must be in sponsoredNetworks) */
35
+ network: string;
36
+ /** Full hex-encoded EIP-2612 permit signature (65 bytes, r + s + v) */
37
+ permitSignature: string;
38
+ /** Token owner address (the client's wallet) */
39
+ owner: string;
40
+ /** Spender address (must match sponsorAddress) */
41
+ spender: string;
42
+ /** Token amount in base units */
43
+ value: string;
44
+ /** Unix timestamp for permit expiry */
45
+ deadline: number;
46
+ /** Recovery parameter from signature */
47
+ v: number;
48
+ /** Signature r component (32 bytes hex) */
49
+ r: string;
50
+ /** Signature s component (32 bytes hex) */
51
+ s: string;
52
+ }
53
+ /**
54
+ * Options for declaring gas sponsor extension on server.
55
+ */
56
+ interface DeclareEip2612GasSponsorOptions {
57
+ /** CAIP-2 network identifiers where gas sponsoring is available */
58
+ sponsoredNetworks: string[];
59
+ /** Maximum token amount (in base units) the sponsor will cover per permit */
60
+ maxAmount: string;
61
+ /** Default permit deadline in seconds from now (defaults to 300 = 5 minutes) */
62
+ permitDeadline?: number;
63
+ /** Address of the sponsor/facilitator */
64
+ sponsorAddress: string;
65
+ }
66
+ /**
67
+ * Options for validating gas sponsor payloads.
68
+ */
69
+ interface ValidateEip2612GasSponsorOptions {
70
+ /** Custom time function for testing (defaults to Date.now) */
71
+ now?: () => number;
72
+ }
73
+ /**
74
+ * Result of gas sponsor payload validation.
75
+ */
76
+ interface Eip2612GasSponsorValidationResult {
77
+ /** Whether the payload is valid */
78
+ valid: boolean;
79
+ /** Error message if invalid */
80
+ error?: string;
81
+ }
82
+ /**
83
+ * Parameters for creating an EIP-2612 permit signature.
84
+ */
85
+ interface CreatePermitParams {
86
+ /** EIP-712 signer interface */
87
+ signer: PermitSigner;
88
+ /** ERC-20 token contract address */
89
+ tokenAddress: string;
90
+ /** Token name (used in EIP-712 domain) */
91
+ tokenName: string;
92
+ /** Chain ID (numeric, e.g. 8453 for Base) */
93
+ chainId: number;
94
+ /** Spender address (the facilitator/sponsor) */
95
+ spender: string;
96
+ /** Token amount in base units */
97
+ value: string;
98
+ /** Unix timestamp for permit expiry */
99
+ deadline: number;
100
+ /** Current permit nonce for the owner (defaults to 0) */
101
+ nonce?: number;
102
+ }
103
+ /**
104
+ * Signer interface for EIP-2612 permit signing.
105
+ */
106
+ interface PermitSigner {
107
+ /** Wallet address */
108
+ address: string;
109
+ /**
110
+ * Sign EIP-712 typed data and return hex-encoded signature.
111
+ *
112
+ * @param data - EIP-712 typed data to sign
113
+ * @returns Hex-encoded signature
114
+ */
115
+ signTypedData(data: {
116
+ domain: Record<string, unknown>;
117
+ types: Record<string, Array<{
118
+ name: string;
119
+ type: string;
120
+ }>>;
121
+ primaryType: string;
122
+ message: Record<string, unknown>;
123
+ }): Promise<string>;
124
+ }
125
+
126
+ /**
127
+ * EIP-2612 Gas Sponsoring Extension Server-Side Implementation
128
+ *
129
+ * Provides functions for servers to declare gas sponsoring requirements,
130
+ * parse client headers, and validate permit payloads.
131
+ */
132
+
133
+ /**
134
+ * Declares an EIP-2612 gas sponsor extension for server responses.
135
+ *
136
+ * @param options - Extension declaration options
137
+ * @returns Gas sponsor extension object ready for response
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const extension = declareEip2612GasSponsorExtension({
142
+ * sponsoredNetworks: ["eip155:8453", "eip155:42161"],
143
+ * maxAmount: "1000000000",
144
+ * sponsorAddress: "0xFacilitator...",
145
+ * });
146
+ * ```
147
+ */
148
+ declare function declareEip2612GasSponsorExtension(options: DeclareEip2612GasSponsorOptions): Eip2612GasSponsorExtension;
149
+ /**
150
+ * Parses an EIP-2612 gas sponsor header from client request.
151
+ *
152
+ * The header format is base64-encoded JSON.
153
+ *
154
+ * @param header - Base64-encoded gas sponsor header value
155
+ * @returns Parsed gas sponsor payload
156
+ * @throws Error if header is invalid
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const payload = parseEip2612GasSponsorHeader(
161
+ * request.headers['x-t402-eip2612-gas-sponsoring']
162
+ * );
163
+ * ```
164
+ */
165
+ declare function parseEip2612GasSponsorHeader(header: string): Eip2612GasSponsorPayload;
166
+ /**
167
+ * Validates an EIP-2612 gas sponsor payload against server extension info.
168
+ *
169
+ * @param payload - The gas sponsor payload from the client
170
+ * @param extensionInfo - The server's gas sponsor extension info
171
+ * @param options - Validation options
172
+ * @returns Validation result
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const result = validateEip2612GasSponsorPayload(payload, extension.info);
177
+ * if (!result.valid) {
178
+ * throw new Error(result.error);
179
+ * }
180
+ * ```
181
+ */
182
+ declare function validateEip2612GasSponsorPayload(payload: Eip2612GasSponsorPayload, extensionInfo: Eip2612GasSponsorExtensionInfo, options?: ValidateEip2612GasSponsorOptions): Eip2612GasSponsorValidationResult;
183
+
184
+ /**
185
+ * EIP-2612 Gas Sponsoring Extension Client-Side Implementation
186
+ *
187
+ * Provides functions for clients to create EIP-2612 permit signatures
188
+ * and encode gas sponsor payloads for transmission.
189
+ */
190
+
191
+ /**
192
+ * Extension key for EIP-2612 gas sponsoring in payment requirements.
193
+ */
194
+ declare const EIP2612_GAS_SPONSOR_EXTENSION_KEY = "eip2612GasSponsoring";
195
+ /**
196
+ * HTTP header name for EIP-2612 gas sponsor payload.
197
+ */
198
+ declare const EIP2612_GAS_SPONSOR_HEADER_NAME = "X-T402-EIP2612-Gas-Sponsoring";
199
+ /**
200
+ * Creates an EIP-2612 permit signature using EIP-712 typed data signing.
201
+ *
202
+ * @param params - Permit signing parameters
203
+ * @returns Permit data including the signature components
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const permit = await createPermitSignature({
208
+ * signer: wallet,
209
+ * tokenAddress: "0xUSDT...",
210
+ * tokenName: "Tether USD",
211
+ * chainId: 8453,
212
+ * spender: facilitatorAddress,
213
+ * value: "1000000",
214
+ * deadline: Math.floor(Date.now() / 1000) + 300,
215
+ * });
216
+ * ```
217
+ */
218
+ declare function createPermitSignature(params: CreatePermitParams): Promise<{
219
+ owner: string;
220
+ spender: string;
221
+ value: string;
222
+ deadline: number;
223
+ v: number;
224
+ r: string;
225
+ s: string;
226
+ permitSignature: string;
227
+ }>;
228
+ /**
229
+ * Creates a gas sponsor payload from permit data and network.
230
+ *
231
+ * @param permit - Permit signature data from createPermitSignature
232
+ * @param network - CAIP-2 network identifier (e.g., "eip155:8453")
233
+ * @returns Gas sponsor payload ready for header encoding
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const payload = createEip2612GasSponsorPayload(permit, "eip155:8453");
238
+ * ```
239
+ */
240
+ declare function createEip2612GasSponsorPayload(permit: {
241
+ owner: string;
242
+ spender: string;
243
+ value: string;
244
+ deadline: number;
245
+ v: number;
246
+ r: string;
247
+ s: string;
248
+ permitSignature: string;
249
+ }, network: string): Eip2612GasSponsorPayload;
250
+ /**
251
+ * Encodes a gas sponsor payload for transmission in HTTP header.
252
+ *
253
+ * @param payload - The gas sponsor payload to encode
254
+ * @returns Base64-encoded JSON string
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const header = encodeEip2612GasSponsorHeader(payload);
259
+ * fetch(url, {
260
+ * headers: { [EIP2612_GAS_SPONSOR_HEADER_NAME]: header }
261
+ * });
262
+ * ```
263
+ */
264
+ declare function encodeEip2612GasSponsorHeader(payload: Eip2612GasSponsorPayload): string;
265
+
266
+ /**
267
+ * EIP-2612 Gas Sponsoring Extension Facilitator-Side Implementation
268
+ *
269
+ * Provides functions for facilitators to extract permit data from payment
270
+ * extensions, validate permits, and prepare on-chain submission.
271
+ */
272
+
273
+ /**
274
+ * Extracts the EIP-2612 gas sponsor payload from payment extensions.
275
+ *
276
+ * @param extensions - The extensions map from a PaymentPayload
277
+ * @returns The gas sponsor payload if present, or null
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * const permit = extractEip2612GasSponsorPayload(paymentPayload.extensions);
282
+ * if (permit) {
283
+ * // Submit permit tx then settle via Permit2
284
+ * }
285
+ * ```
286
+ */
287
+ declare function extractEip2612GasSponsorPayload(extensions: Record<string, unknown> | undefined): Eip2612GasSponsorPayload | null;
288
+ /**
289
+ * Validates and extracts the EIP-2612 gas sponsor payload in one step.
290
+ *
291
+ * This is a convenience function for facilitators that combines extraction
292
+ * and validation against the server's extension info.
293
+ *
294
+ * @param extensions - The extensions map from a PaymentPayload
295
+ * @param extensionInfo - The server's gas sponsor extension info
296
+ * @returns Validation result with the extracted payload if valid
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * const result = validateAndExtractPermit(
301
+ * paymentPayload.extensions,
302
+ * extensionInfo
303
+ * );
304
+ * if (result.valid && result.payload) {
305
+ * // Submit permit() on token contract, then settle via Permit2
306
+ * }
307
+ * ```
308
+ */
309
+ declare function validateAndExtractPermit(extensions: Record<string, unknown> | undefined, extensionInfo: Eip2612GasSponsorExtensionInfo): Eip2612GasSponsorValidationResult & {
310
+ payload?: Eip2612GasSponsorPayload;
311
+ };
312
+ /**
313
+ * Builds the EIP-2612 permit function call data for on-chain submission.
314
+ *
315
+ * Returns the ABI-encoded parameters needed to call `permit(owner, spender, value, deadline, v, r, s)`
316
+ * on the token contract.
317
+ *
318
+ * @param payload - The validated gas sponsor payload
319
+ * @returns Object with the permit call parameters
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * const permitCall = buildPermitCallData(payload);
324
+ * // Use permitCall with your preferred web3 library to submit the tx
325
+ * ```
326
+ */
327
+ declare function buildPermitCallData(payload: Eip2612GasSponsorPayload): {
328
+ owner: string;
329
+ spender: string;
330
+ value: string;
331
+ deadline: number;
332
+ v: number;
333
+ r: string;
334
+ s: string;
335
+ };
336
+
337
+ export { type CreatePermitParams, type DeclareEip2612GasSponsorOptions, EIP2612_GAS_SPONSOR_EXTENSION_KEY, EIP2612_GAS_SPONSOR_HEADER_NAME, type Eip2612GasSponsorExtension, type Eip2612GasSponsorExtensionInfo, type Eip2612GasSponsorPayload, type Eip2612GasSponsorValidationResult, type PermitSigner, type ValidateEip2612GasSponsorOptions, buildPermitCallData, createEip2612GasSponsorPayload, createPermitSignature, declareEip2612GasSponsorExtension, encodeEip2612GasSponsorHeader, extractEip2612GasSponsorPayload, parseEip2612GasSponsorHeader, validateAndExtractPermit, validateEip2612GasSponsorPayload };
@@ -0,0 +1,27 @@
1
+ import {
2
+ EIP2612_GAS_SPONSOR_EXTENSION_KEY,
3
+ EIP2612_GAS_SPONSOR_HEADER_NAME,
4
+ buildPermitCallData,
5
+ createEip2612GasSponsorPayload,
6
+ createPermitSignature,
7
+ declareEip2612GasSponsorExtension,
8
+ encodeEip2612GasSponsorHeader,
9
+ extractEip2612GasSponsorPayload,
10
+ parseEip2612GasSponsorHeader,
11
+ validateAndExtractPermit,
12
+ validateEip2612GasSponsorPayload
13
+ } from "../chunk-VINC22RD.mjs";
14
+ export {
15
+ EIP2612_GAS_SPONSOR_EXTENSION_KEY,
16
+ EIP2612_GAS_SPONSOR_HEADER_NAME,
17
+ buildPermitCallData,
18
+ createEip2612GasSponsorPayload,
19
+ createPermitSignature,
20
+ declareEip2612GasSponsorExtension,
21
+ encodeEip2612GasSponsorHeader,
22
+ extractEip2612GasSponsorPayload,
23
+ parseEip2612GasSponsorHeader,
24
+ validateAndExtractPermit,
25
+ validateEip2612GasSponsorPayload
26
+ };
27
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,316 @@
1
+ /**
2
+ * ERC-20 Approval Gas Sponsoring Extension Type Definitions
3
+ *
4
+ * ERC-20 approve()-based gas sponsoring for the t402 payment protocol.
5
+ * For tokens WITHOUT EIP-2612 permit support, the client signs an offline
6
+ * approve() transaction and the facilitator broadcasts it on their behalf.
7
+ */
8
+ /**
9
+ * Information provided by server about ERC-20 approval gas sponsoring availability.
10
+ */
11
+ interface ERC20ApprovalGasSponsorExtensionInfo {
12
+ /** CAIP-2 network identifiers where gas sponsoring is available */
13
+ sponsoredNetworks: string[];
14
+ /** Maximum token amount (in base units) the sponsor will cover per approval */
15
+ maxAmount: string;
16
+ /** Address of the sponsor/facilitator that will submit transactions */
17
+ sponsorAddress: string;
18
+ /** Optional Permit2 proxy address for advanced settlement flows */
19
+ permit2Address?: string;
20
+ /** Whether atomic batch execution is required (e.g., via Multicall3) */
21
+ requiresAtomicBatch: boolean;
22
+ }
23
+ /**
24
+ * ERC-20 approval gas sponsor extension declaration for server responses.
25
+ */
26
+ interface ERC20ApprovalGasSponsorExtension {
27
+ /** Extension information */
28
+ info: ERC20ApprovalGasSponsorExtensionInfo;
29
+ /** JSON Schema for validation */
30
+ schema: object;
31
+ }
32
+ /**
33
+ * Complete ERC-20 approval gas sponsor payload from client.
34
+ */
35
+ interface ERC20ApprovalGasSponsorPayload {
36
+ /** CAIP-2 network identifier (must be in sponsoredNetworks) */
37
+ network: string;
38
+ /** Client wallet address that signed the transaction */
39
+ from: string;
40
+ /** ERC-20 token contract address */
41
+ asset: string;
42
+ /** Approval amount in base units */
43
+ amount: string;
44
+ /** Raw signed approve() transaction (hex-encoded with 0x prefix) */
45
+ signedApprovalTx: string;
46
+ /** Chain ID for replay protection */
47
+ chainId: number;
48
+ /** Client's account nonce (if known) */
49
+ nonce?: number;
50
+ }
51
+ /**
52
+ * Options for declaring ERC-20 approval gas sponsor extension on server.
53
+ */
54
+ interface DeclareERC20ApprovalGasSponsorOptions {
55
+ /** CAIP-2 network identifiers where gas sponsoring is available */
56
+ sponsoredNetworks: string[];
57
+ /** Maximum token amount (in base units) the sponsor will cover per approval */
58
+ maxAmount: string;
59
+ /** Address of the sponsor/facilitator */
60
+ sponsorAddress: string;
61
+ /** Optional Permit2 proxy address */
62
+ permit2Address?: string;
63
+ /** Whether atomic batch execution is required (defaults to false) */
64
+ requiresAtomicBatch?: boolean;
65
+ }
66
+ /**
67
+ * Options for validating ERC-20 approval gas sponsor payloads.
68
+ */
69
+ interface ValidateERC20ApprovalGasSponsorOptions {
70
+ /** Expected chain IDs per CAIP-2 network (e.g., { "eip155:8453": 8453 }) */
71
+ expectedChainIds?: Record<string, number>;
72
+ }
73
+ /**
74
+ * Result of ERC-20 approval gas sponsor payload validation.
75
+ */
76
+ interface ERC20ApprovalGasSponsorValidationResult {
77
+ /** Whether the payload is valid */
78
+ valid: boolean;
79
+ /** Error message if invalid */
80
+ error?: string;
81
+ }
82
+ /**
83
+ * Parameters for creating an ERC-20 approval gas sponsor payload.
84
+ */
85
+ interface CreateERC20ApprovalParams {
86
+ /** CAIP-2 network identifier */
87
+ network: string;
88
+ /** Client wallet address */
89
+ from: string;
90
+ /** ERC-20 token contract address */
91
+ asset: string;
92
+ /** Approval amount in base units */
93
+ amount: string;
94
+ /** Raw signed approve() transaction (hex-encoded) */
95
+ signedApprovalTx: string;
96
+ /** Chain ID for replay protection */
97
+ chainId: number;
98
+ /** Client's account nonce (if known) */
99
+ nonce?: number;
100
+ }
101
+
102
+ /**
103
+ * ERC-20 Approval Gas Sponsoring Extension Server-Side Implementation
104
+ *
105
+ * Provides functions for servers to declare gas sponsoring requirements,
106
+ * parse client headers, and validate approval payloads.
107
+ */
108
+
109
+ /**
110
+ * Declares an ERC-20 approval gas sponsor extension for server responses.
111
+ *
112
+ * @param options - Extension declaration options
113
+ * @returns Gas sponsor extension object ready for response
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const extension = declareERC20ApprovalGasSponsorExtension({
118
+ * sponsoredNetworks: ["eip155:8453", "eip155:42161"],
119
+ * maxAmount: "1000000000",
120
+ * sponsorAddress: "0xFacilitator...",
121
+ * requiresAtomicBatch: true,
122
+ * });
123
+ * ```
124
+ */
125
+ declare function declareERC20ApprovalGasSponsorExtension(options: DeclareERC20ApprovalGasSponsorOptions): ERC20ApprovalGasSponsorExtension;
126
+ /**
127
+ * Parses an ERC-20 approval gas sponsor header from client request.
128
+ *
129
+ * The header format is base64-encoded JSON.
130
+ *
131
+ * @param header - Base64-encoded gas sponsor header value
132
+ * @returns Parsed gas sponsor payload
133
+ * @throws Error if header is invalid
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const payload = parseERC20ApprovalGasSponsorHeader(
138
+ * request.headers['x-t402-erc20-approval-gas-sponsoring']
139
+ * );
140
+ * ```
141
+ */
142
+ declare function parseERC20ApprovalGasSponsorHeader(header: string): ERC20ApprovalGasSponsorPayload;
143
+ /**
144
+ * Validates an ERC-20 approval gas sponsor payload against server extension info.
145
+ *
146
+ * @param payload - The gas sponsor payload from the client
147
+ * @param extensionInfo - The server's gas sponsor extension info
148
+ * @param options - Validation options
149
+ * @returns Validation result
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const result = validateERC20ApprovalGasSponsorPayload(payload, extension.info);
154
+ * if (!result.valid) {
155
+ * throw new Error(result.error);
156
+ * }
157
+ * ```
158
+ */
159
+ declare function validateERC20ApprovalGasSponsorPayload(payload: ERC20ApprovalGasSponsorPayload, extensionInfo: ERC20ApprovalGasSponsorExtensionInfo, options?: ValidateERC20ApprovalGasSponsorOptions): ERC20ApprovalGasSponsorValidationResult;
160
+
161
+ /**
162
+ * ERC-20 Approval Gas Sponsoring Extension Client-Side Implementation
163
+ *
164
+ * Provides functions for clients to construct ERC-20 approve() calldata
165
+ * and encode gas sponsor payloads for transmission.
166
+ */
167
+
168
+ /**
169
+ * Extension key for ERC-20 approval gas sponsoring in payment requirements.
170
+ */
171
+ declare const ERC20_APPROVAL_GAS_SPONSOR_EXTENSION_KEY = "erc20ApprovalGasSponsoring";
172
+ /**
173
+ * HTTP header name for ERC-20 approval gas sponsor payload.
174
+ */
175
+ declare const ERC20_APPROVAL_GAS_SPONSOR_HEADER_NAME = "X-T402-ERC20-Approval-Gas-Sponsoring";
176
+ /**
177
+ * ERC-20 approve(address,uint256) function selector.
178
+ */
179
+ declare const APPROVE_FUNCTION_SELECTOR = "0x095ea7b3";
180
+ /**
181
+ * Encodes ERC-20 approve(address spender, uint256 amount) calldata.
182
+ *
183
+ * @param spender - The spender address to approve
184
+ * @param amount - The approval amount in base units
185
+ * @returns Hex-encoded calldata with 0x prefix
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const calldata = encodeApproveCalldata("0xFacilitator...", "1000000");
190
+ * // Returns "0x095ea7b3" + abi-encoded args
191
+ * ```
192
+ */
193
+ declare function encodeApproveCalldata(spender: string, amount: string): string;
194
+ /**
195
+ * Creates an ERC-20 approval gas sponsor payload from params and extension info.
196
+ *
197
+ * @param info - The server's extension info
198
+ * @param params - The approval parameters
199
+ * @returns Gas sponsor payload ready for header encoding
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const payload = createERC20ApprovalGasSponsorPayload(extensionInfo, {
204
+ * network: "eip155:8453",
205
+ * from: wallet.address,
206
+ * asset: "0xUSDT...",
207
+ * amount: "1000000",
208
+ * signedApprovalTx: signedTx,
209
+ * chainId: 8453,
210
+ * });
211
+ * ```
212
+ */
213
+ declare function createERC20ApprovalGasSponsorPayload(_info: ERC20ApprovalGasSponsorExtensionInfo, params: CreateERC20ApprovalParams): ERC20ApprovalGasSponsorPayload;
214
+ /**
215
+ * Encodes an ERC-20 approval gas sponsor payload for transmission in HTTP header.
216
+ *
217
+ * @param payload - The gas sponsor payload to encode
218
+ * @returns Base64-encoded JSON string
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const header = encodeERC20ApprovalGasSponsorHeader(payload);
223
+ * fetch(url, {
224
+ * headers: { [ERC20_APPROVAL_GAS_SPONSOR_HEADER_NAME]: header }
225
+ * });
226
+ * ```
227
+ */
228
+ declare function encodeERC20ApprovalGasSponsorHeader(payload: ERC20ApprovalGasSponsorPayload): string;
229
+
230
+ /**
231
+ * ERC-20 Approval Gas Sponsoring Extension Facilitator-Side Implementation
232
+ *
233
+ * Provides functions for facilitators to extract approval data from payment
234
+ * extensions, validate the signed approve() transaction, and prepare for
235
+ * on-chain submission.
236
+ */
237
+
238
+ /**
239
+ * Extracts the ERC-20 approval gas sponsor payload from payment extensions.
240
+ *
241
+ * @param extensions - The extensions map from a PaymentPayload
242
+ * @returns The gas sponsor payload if present, or null
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * const approval = extractERC20ApprovalGasSponsorPayload(paymentPayload.extensions);
247
+ * if (approval) {
248
+ * // Validate and broadcast the approval tx, then settle
249
+ * }
250
+ * ```
251
+ */
252
+ declare function extractERC20ApprovalGasSponsorPayload(extensions: Record<string, unknown> | undefined): ERC20ApprovalGasSponsorPayload | null;
253
+ /**
254
+ * Processes and validates an ERC-20 approval payload for the facilitator.
255
+ *
256
+ * Combines extraction validation with approve() function selector verification.
257
+ * Checks that the signed transaction data contains the correct approve() selector
258
+ * and that the approval amount matches the declared amount.
259
+ *
260
+ * @param payload - The ERC-20 approval gas sponsor payload
261
+ * @param extensionInfo - The server's gas sponsor extension info
262
+ * @returns Validation result
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * const result = processERC20ApprovalPayload(payload, extensionInfo);
267
+ * if (result.valid) {
268
+ * // Safe to broadcast the approval tx and settle
269
+ * }
270
+ * ```
271
+ */
272
+ declare function processERC20ApprovalPayload(payload: ERC20ApprovalGasSponsorPayload, extensionInfo: ERC20ApprovalGasSponsorExtensionInfo): ERC20ApprovalGasSponsorValidationResult;
273
+ /**
274
+ * Validates and extracts the ERC-20 approval gas sponsor payload in one step.
275
+ *
276
+ * This is a convenience function for facilitators that combines extraction
277
+ * and validation against the server's extension info.
278
+ *
279
+ * @param extensions - The extensions map from a PaymentPayload
280
+ * @param extensionInfo - The server's gas sponsor extension info
281
+ * @returns Validation result with the extracted payload if valid
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * const result = validateAndExtractApproval(
286
+ * paymentPayload.extensions,
287
+ * extensionInfo
288
+ * );
289
+ * if (result.valid && result.payload) {
290
+ * // Broadcast approval tx, then settle
291
+ * }
292
+ * ```
293
+ */
294
+ declare function validateAndExtractApproval(extensions: Record<string, unknown> | undefined, extensionInfo: ERC20ApprovalGasSponsorExtensionInfo): ERC20ApprovalGasSponsorValidationResult & {
295
+ payload?: ERC20ApprovalGasSponsorPayload;
296
+ };
297
+ /**
298
+ * Decodes the approve() calldata from a hex string to extract spender and amount.
299
+ *
300
+ * @param calldata - Hex-encoded approve() calldata (with or without 0x prefix)
301
+ * @returns Decoded spender and amount, or null if not valid approve() calldata
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const decoded = decodeApproveCalldata("0x095ea7b3...");
306
+ * if (decoded) {
307
+ * console.log(decoded.spender, decoded.amount);
308
+ * }
309
+ * ```
310
+ */
311
+ declare function decodeApproveCalldata(calldata: string): {
312
+ spender: string;
313
+ amount: string;
314
+ } | null;
315
+
316
+ export { APPROVE_FUNCTION_SELECTOR, type CreateERC20ApprovalParams, type DeclareERC20ApprovalGasSponsorOptions, type ERC20ApprovalGasSponsorExtension, type ERC20ApprovalGasSponsorExtensionInfo, type ERC20ApprovalGasSponsorPayload, type ERC20ApprovalGasSponsorValidationResult, ERC20_APPROVAL_GAS_SPONSOR_EXTENSION_KEY, ERC20_APPROVAL_GAS_SPONSOR_HEADER_NAME, type ValidateERC20ApprovalGasSponsorOptions, createERC20ApprovalGasSponsorPayload, declareERC20ApprovalGasSponsorExtension, decodeApproveCalldata, encodeApproveCalldata, encodeERC20ApprovalGasSponsorHeader, extractERC20ApprovalGasSponsorPayload, parseERC20ApprovalGasSponsorHeader, processERC20ApprovalPayload, validateAndExtractApproval, validateERC20ApprovalGasSponsorPayload };