@x402/extensions 2.3.1 → 2.5.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/README.md +88 -8
- package/dist/cjs/bazaar/index.d.ts +2 -2
- package/dist/cjs/bazaar/index.js +121 -6
- package/dist/cjs/bazaar/index.js.map +1 -1
- package/dist/cjs/{index-DvDlinmy.d.ts → index-G8RNfr6X.d.ts} +150 -63
- package/dist/cjs/index.d.ts +356 -2
- package/dist/cjs/index.js +321 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sign-in-with-x/index.d.ts +1 -1
- package/dist/cjs/sign-in-with-x/index.js +3 -1
- package/dist/cjs/sign-in-with-x/index.js.map +1 -1
- package/dist/esm/bazaar/index.d.mts +2 -2
- package/dist/esm/bazaar/index.mjs +7 -1
- package/dist/esm/{chunk-DFJ4ZQFO.mjs → chunk-ANAQVNUK.mjs} +119 -7
- package/dist/esm/chunk-ANAQVNUK.mjs.map +1 -0
- package/dist/esm/{chunk-IASAX5HM.mjs → chunk-O34SGKEP.mjs} +4 -2
- package/dist/esm/{chunk-IASAX5HM.mjs.map → chunk-O34SGKEP.mjs.map} +1 -1
- package/dist/esm/{index-DvDlinmy.d.mts → index-G8RNfr6X.d.mts} +150 -63
- package/dist/esm/index.d.mts +356 -2
- package/dist/esm/index.mjs +194 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/sign-in-with-x/index.d.mts +1 -1
- package/dist/esm/sign-in-with-x/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/esm/chunk-DFJ4ZQFO.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { FacilitatorExtension, ResourceServerExtension, PaymentPayload, PaymentRequirements, PaymentRequirementsV1 } from '@x402/core/types';
|
|
1
2
|
import { BodyMethods, QueryParamMethods, HTTPFacilitatorClient } from '@x402/core/http';
|
|
2
|
-
import { ResourceServerExtension, PaymentPayload, PaymentRequirements, PaymentRequirementsV1 } from '@x402/core/types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shared type utilities for x402 extensions
|
|
@@ -24,20 +24,17 @@ type WithExtensions<T, E> = T extends {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* HTTP-specific type definitions for the Bazaar Discovery Extension
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* Extension identifier constant for the Bazaar discovery extension
|
|
32
|
-
*/
|
|
33
|
-
declare const BAZAAR = "bazaar";
|
|
34
30
|
/**
|
|
35
31
|
* Discovery info for query parameter methods (GET, HEAD, DELETE)
|
|
36
32
|
*/
|
|
37
33
|
interface QueryDiscoveryInfo {
|
|
38
34
|
input: {
|
|
39
35
|
type: "http";
|
|
40
|
-
|
|
36
|
+
/** Absent at declaration time; set by bazaarResourceServerExtension.enrichDeclaration */
|
|
37
|
+
method?: QueryParamMethods;
|
|
41
38
|
queryParams?: Record<string, unknown>;
|
|
42
39
|
headers?: Record<string, string>;
|
|
43
40
|
};
|
|
@@ -53,7 +50,8 @@ interface QueryDiscoveryInfo {
|
|
|
53
50
|
interface BodyDiscoveryInfo {
|
|
54
51
|
input: {
|
|
55
52
|
type: "http";
|
|
56
|
-
|
|
53
|
+
/** Absent at declaration time; set by bazaarResourceServerExtension.enrichDeclaration */
|
|
54
|
+
method?: BodyMethods;
|
|
57
55
|
bodyType: "json" | "form-data" | "text";
|
|
58
56
|
body: Record<string, unknown>;
|
|
59
57
|
queryParams?: Record<string, unknown>;
|
|
@@ -65,10 +63,6 @@ interface BodyDiscoveryInfo {
|
|
|
65
63
|
example?: unknown;
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Combined discovery info type
|
|
70
|
-
*/
|
|
71
|
-
type DiscoveryInfo = QueryDiscoveryInfo | BodyDiscoveryInfo;
|
|
72
66
|
/**
|
|
73
67
|
* Discovery extension for query parameter methods (GET, HEAD, DELETE)
|
|
74
68
|
*/
|
|
@@ -166,10 +160,6 @@ interface BodyDiscoveryExtension {
|
|
|
166
160
|
required: ["input"];
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Combined discovery extension type
|
|
171
|
-
*/
|
|
172
|
-
type DiscoveryExtension = QueryDiscoveryExtension | BodyDiscoveryExtension;
|
|
173
163
|
interface DeclareQueryDiscoveryExtensionConfig {
|
|
174
164
|
method?: QueryParamMethods;
|
|
175
165
|
input?: Record<string, unknown>;
|
|
@@ -189,7 +179,124 @@ interface DeclareBodyDiscoveryExtensionConfig {
|
|
|
189
179
|
schema?: Record<string, unknown>;
|
|
190
180
|
};
|
|
191
181
|
}
|
|
192
|
-
|
|
182
|
+
interface DiscoveredHTTPResource {
|
|
183
|
+
resourceUrl: string;
|
|
184
|
+
description?: string;
|
|
185
|
+
mimeType?: string;
|
|
186
|
+
/** Present after server extension enrichment; may be absent for pre-enrichment data */
|
|
187
|
+
method?: string;
|
|
188
|
+
x402Version: number;
|
|
189
|
+
discoveryInfo: DiscoveryInfo;
|
|
190
|
+
}
|
|
191
|
+
declare const isQueryExtensionConfig: (config: DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig) => config is DeclareQueryDiscoveryExtensionConfig;
|
|
192
|
+
declare const isBodyExtensionConfig: (config: DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig) => config is DeclareBodyDiscoveryExtensionConfig;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* MCP-specific type definitions for the Bazaar Discovery Extension
|
|
196
|
+
*/
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Discovery info for MCP tools
|
|
200
|
+
*/
|
|
201
|
+
interface McpDiscoveryInfo {
|
|
202
|
+
input: {
|
|
203
|
+
type: "mcp";
|
|
204
|
+
toolName: string;
|
|
205
|
+
description?: string;
|
|
206
|
+
transport?: "streamable-http" | "sse";
|
|
207
|
+
inputSchema: Record<string, unknown>;
|
|
208
|
+
example?: Record<string, unknown>;
|
|
209
|
+
};
|
|
210
|
+
output?: {
|
|
211
|
+
type?: string;
|
|
212
|
+
format?: string;
|
|
213
|
+
example?: unknown;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Discovery extension for MCP tools
|
|
218
|
+
*/
|
|
219
|
+
interface McpDiscoveryExtension {
|
|
220
|
+
info: McpDiscoveryInfo;
|
|
221
|
+
schema: {
|
|
222
|
+
$schema: "https://json-schema.org/draft/2020-12/schema";
|
|
223
|
+
type: "object";
|
|
224
|
+
properties: {
|
|
225
|
+
input: {
|
|
226
|
+
type: "object";
|
|
227
|
+
properties: {
|
|
228
|
+
type: {
|
|
229
|
+
type: "string";
|
|
230
|
+
const: "mcp";
|
|
231
|
+
};
|
|
232
|
+
toolName: {
|
|
233
|
+
type: "string";
|
|
234
|
+
};
|
|
235
|
+
description?: {
|
|
236
|
+
type: "string";
|
|
237
|
+
};
|
|
238
|
+
transport?: {
|
|
239
|
+
type: "string";
|
|
240
|
+
enum: ["streamable-http", "sse"];
|
|
241
|
+
};
|
|
242
|
+
inputSchema: Record<string, unknown>;
|
|
243
|
+
example?: Record<string, unknown>;
|
|
244
|
+
};
|
|
245
|
+
required: ("type" | "toolName" | "inputSchema")[];
|
|
246
|
+
additionalProperties?: boolean;
|
|
247
|
+
};
|
|
248
|
+
output?: {
|
|
249
|
+
type: "object";
|
|
250
|
+
properties?: Record<string, unknown>;
|
|
251
|
+
required?: readonly string[];
|
|
252
|
+
additionalProperties?: boolean;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
required: ["input"];
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
interface DeclareMcpDiscoveryExtensionConfig {
|
|
259
|
+
toolName: string;
|
|
260
|
+
description?: string;
|
|
261
|
+
transport?: "streamable-http" | "sse";
|
|
262
|
+
inputSchema: Record<string, unknown>;
|
|
263
|
+
example?: Record<string, unknown>;
|
|
264
|
+
output?: {
|
|
265
|
+
example?: unknown;
|
|
266
|
+
schema?: Record<string, unknown>;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
interface DiscoveredMCPResource {
|
|
270
|
+
resourceUrl: string;
|
|
271
|
+
description?: string;
|
|
272
|
+
mimeType?: string;
|
|
273
|
+
toolName: string;
|
|
274
|
+
x402Version: number;
|
|
275
|
+
discoveryInfo: DiscoveryInfo;
|
|
276
|
+
}
|
|
277
|
+
declare const isMcpExtensionConfig: (config: DeclareMcpDiscoveryExtensionConfig | Record<string, unknown>) => config is DeclareMcpDiscoveryExtensionConfig;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Shared type definitions for the Bazaar Discovery Extension
|
|
281
|
+
*
|
|
282
|
+
* Protocol-specific types live in their own directories (http/, mcp/).
|
|
283
|
+
* This file defines the shared unions, constants, and utility types,
|
|
284
|
+
* and re-exports all protocol-specific types for backwards compatibility.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Extension identifier for the Bazaar discovery extension.
|
|
289
|
+
*/
|
|
290
|
+
declare const BAZAAR: FacilitatorExtension;
|
|
291
|
+
/**
|
|
292
|
+
* Combined discovery info type
|
|
293
|
+
*/
|
|
294
|
+
type DiscoveryInfo = QueryDiscoveryInfo | BodyDiscoveryInfo | McpDiscoveryInfo;
|
|
295
|
+
/**
|
|
296
|
+
* Combined discovery extension type
|
|
297
|
+
*/
|
|
298
|
+
type DiscoveryExtension = QueryDiscoveryExtension | BodyDiscoveryExtension | McpDiscoveryExtension;
|
|
299
|
+
type DeclareDiscoveryExtensionConfig = DeclareQueryDiscoveryExtensionConfig | DeclareBodyDiscoveryExtensionConfig | DeclareMcpDiscoveryExtensionConfig;
|
|
193
300
|
/**
|
|
194
301
|
* Distributive Omit - properly distributes Omit over union types.
|
|
195
302
|
*
|
|
@@ -202,19 +309,20 @@ type DeclareDiscoveryExtensionConfig = DeclareQueryDiscoveryExtensionConfig | De
|
|
|
202
309
|
type DistributiveOmit<T, K extends keyof T> = T extends T ? Omit<T, K> : never;
|
|
203
310
|
/**
|
|
204
311
|
* Config type for declareDiscoveryExtension function.
|
|
205
|
-
* Uses DistributiveOmit to preserve bodyType discriminant in the union.
|
|
312
|
+
* Uses DistributiveOmit to preserve bodyType discriminant in the union for HTTP configs.
|
|
313
|
+
* MCP config has no `method` field so it's included directly.
|
|
206
314
|
*/
|
|
207
|
-
type DeclareDiscoveryExtensionInput = DistributiveOmit<
|
|
315
|
+
type DeclareDiscoveryExtensionInput = DistributiveOmit<DeclareQueryDiscoveryExtensionConfig, "method"> | DistributiveOmit<DeclareBodyDiscoveryExtensionConfig, "method"> | DeclareMcpDiscoveryExtensionConfig;
|
|
208
316
|
|
|
209
317
|
/**
|
|
210
|
-
* Resource Service
|
|
318
|
+
* Resource Service entry point for creating Bazaar discovery extensions
|
|
211
319
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
320
|
+
* This module provides the unified `declareDiscoveryExtension` function that
|
|
321
|
+
* routes to protocol-specific builders in http/ and mcp/.
|
|
214
322
|
*/
|
|
215
323
|
|
|
216
324
|
/**
|
|
217
|
-
* Create a discovery extension for any HTTP method
|
|
325
|
+
* Create a discovery extension for any HTTP method or MCP tool
|
|
218
326
|
*
|
|
219
327
|
* This function helps servers declare how their endpoint should be called,
|
|
220
328
|
* including the expected input parameters/body and output format.
|
|
@@ -260,6 +368,22 @@ type DeclareDiscoveryExtensionInput = DistributiveOmit<DeclareDiscoveryExtension
|
|
|
260
368
|
* example: { success: true, id: "123" }
|
|
261
369
|
* }
|
|
262
370
|
* });
|
|
371
|
+
*
|
|
372
|
+
* // For an MCP tool
|
|
373
|
+
* const mcpExtension = declareDiscoveryExtension({
|
|
374
|
+
* toolName: "financial_analysis",
|
|
375
|
+
* description: "Analyze financial data for a given ticker",
|
|
376
|
+
* inputSchema: {
|
|
377
|
+
* type: "object",
|
|
378
|
+
* properties: {
|
|
379
|
+
* ticker: { type: "string" },
|
|
380
|
+
* },
|
|
381
|
+
* required: ["ticker"],
|
|
382
|
+
* },
|
|
383
|
+
* output: {
|
|
384
|
+
* example: { pe_ratio: 28.5, recommendation: "hold" }
|
|
385
|
+
* }
|
|
386
|
+
* });
|
|
263
387
|
* ```
|
|
264
388
|
*/
|
|
265
389
|
declare function declareDiscoveryExtension(config: DeclareDiscoveryExtensionInput): Record<string, DiscoveryExtension>;
|
|
@@ -301,44 +425,8 @@ interface ValidationResult {
|
|
|
301
425
|
* ```
|
|
302
426
|
*/
|
|
303
427
|
declare function validateDiscoveryExtension(extension: DiscoveryExtension): ValidationResult;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
* This function handles both v2 (extensions) and v1 (outputSchema) formats.
|
|
308
|
-
*
|
|
309
|
-
* For v2: Discovery info is in PaymentPayload.extensions (client copied it from PaymentRequired)
|
|
310
|
-
* For v1: Discovery info is in PaymentRequirements.outputSchema
|
|
311
|
-
*
|
|
312
|
-
* V1 data is automatically transformed to v2 DiscoveryInfo format, making smart
|
|
313
|
-
* assumptions about field names (queryParams/query/params for GET, bodyFields/body/data for POST, etc.)
|
|
314
|
-
*
|
|
315
|
-
* @param paymentPayload - The payment payload containing extensions (v2) and version info
|
|
316
|
-
* @param paymentRequirements - The payment requirements (contains outputSchema for v1)
|
|
317
|
-
* @param validate - Whether to validate v2 extensions before extracting (default: true)
|
|
318
|
-
* @returns The discovery info in v2 format if present, or null if not discoverable
|
|
319
|
-
*
|
|
320
|
-
* @example
|
|
321
|
-
* ```typescript
|
|
322
|
-
* // V2 - extensions are in PaymentPayload
|
|
323
|
-
* const info = extractDiscoveryInfo(paymentPayload, paymentRequirements);
|
|
324
|
-
*
|
|
325
|
-
* // V1 - discovery info is in PaymentRequirements.outputSchema
|
|
326
|
-
* const info = extractDiscoveryInfo(paymentPayloadV1, paymentRequirementsV1);
|
|
327
|
-
*
|
|
328
|
-
* if (info) {
|
|
329
|
-
* // Both v1 and v2 return the same DiscoveryInfo structure
|
|
330
|
-
* console.log("Method:", info.input.method);
|
|
331
|
-
* }
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
interface DiscoveredResource {
|
|
335
|
-
resourceUrl: string;
|
|
336
|
-
description?: string;
|
|
337
|
-
mimeType?: string;
|
|
338
|
-
method: string;
|
|
339
|
-
x402Version: number;
|
|
340
|
-
discoveryInfo: DiscoveryInfo;
|
|
341
|
-
}
|
|
428
|
+
|
|
429
|
+
type DiscoveredResource = DiscoveredHTTPResource | DiscoveredMCPResource;
|
|
342
430
|
/**
|
|
343
431
|
* Extracts discovery information from payment payload and requirements.
|
|
344
432
|
* Combines resource URL, HTTP method, version, and discovery info into a single object.
|
|
@@ -490,7 +578,6 @@ declare function extractResourceMetadataV1(paymentRequirements: PaymentRequireme
|
|
|
490
578
|
interface ListDiscoveryResourcesParams {
|
|
491
579
|
/**
|
|
492
580
|
* Filter by protocol type (e.g., "http", "mcp").
|
|
493
|
-
* Currently, the only supported protocol type is "http".
|
|
494
581
|
*/
|
|
495
582
|
type?: string;
|
|
496
583
|
/**
|
|
@@ -572,4 +659,4 @@ interface BazaarClientExtension {
|
|
|
572
659
|
*/
|
|
573
660
|
declare function withBazaar<T extends HTTPFacilitatorClient>(client: T): WithExtensions<T, BazaarClientExtension>;
|
|
574
661
|
|
|
575
|
-
export { BAZAAR as B, type
|
|
662
|
+
export { validateAndExtract as A, BAZAAR as B, validateDiscoveryExtension as C, type DeclareBodyDiscoveryExtensionConfig as D, withBazaar as E, type ListDiscoveryResourcesParams as L, type McpDiscoveryExtension as M, type QueryDiscoveryExtension as Q, type ValidationResult as V, type WithExtensions as W, type BazaarClientExtension as a, type BodyDiscoveryExtension as b, type BodyDiscoveryInfo as c, type DeclareDiscoveryExtensionConfig as d, type DeclareDiscoveryExtensionInput as e, type DeclareMcpDiscoveryExtensionConfig as f, type DeclareQueryDiscoveryExtensionConfig as g, type DiscoveredHTTPResource as h, type DiscoveredMCPResource as i, type DiscoveredResource as j, type DiscoveryExtension as k, type DiscoveryInfo as l, type DiscoveryResource as m, type DiscoveryResourcesResponse as n, type McpDiscoveryInfo as o, type QueryDiscoveryInfo as p, bazaarResourceServerExtension as q, declareDiscoveryExtension as r, extractDiscoveryInfo as s, extractDiscoveryInfoFromExtension as t, extractDiscoveryInfoV1 as u, extractResourceMetadataV1 as v, isBodyExtensionConfig as w, isDiscoverableV1 as x, isMcpExtensionConfig as y, isQueryExtensionConfig as z };
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,6 +1,360 @@
|
|
|
1
|
-
export { B as BAZAAR, a as BazaarClientExtension, b as BodyDiscoveryExtension, c as BodyDiscoveryInfo, D as
|
|
1
|
+
export { B as BAZAAR, a as BazaarClientExtension, b as BodyDiscoveryExtension, c as BodyDiscoveryInfo, D as DeclareBodyDiscoveryExtensionConfig, d as DeclareDiscoveryExtensionConfig, e as DeclareDiscoveryExtensionInput, f as DeclareMcpDiscoveryExtensionConfig, g as DeclareQueryDiscoveryExtensionConfig, h as DiscoveredHTTPResource, i as DiscoveredMCPResource, j as DiscoveredResource, k as DiscoveryExtension, l as DiscoveryInfo, m as DiscoveryResource, n as DiscoveryResourcesResponse, L as ListDiscoveryResourcesParams, M as McpDiscoveryExtension, o as McpDiscoveryInfo, Q as QueryDiscoveryExtension, p as QueryDiscoveryInfo, V as ValidationResult, W as WithExtensions, q as bazaarResourceServerExtension, r as declareDiscoveryExtension, s as extractDiscoveryInfo, t as extractDiscoveryInfoFromExtension, u as extractDiscoveryInfoV1, v as extractResourceMetadataV1, w as isBodyExtensionConfig, x as isDiscoverableV1, y as isMcpExtensionConfig, z as isQueryExtensionConfig, A as validateAndExtract, C as validateDiscoveryExtension, E as withBazaar } from './index-G8RNfr6X.mjs';
|
|
2
2
|
export { CompleteSIWxInfo, CreateSIWxHookOptions, DeclareSIWxOptions, EVMMessageVerifier, EVMSigner, InMemorySIWxStorage, SIGN_IN_WITH_X, SIWxExtension, SIWxExtensionInfo, SIWxExtensionSchema, SIWxHookEvent, SIWxPayload, SIWxPayloadSchema, SIWxSigner, SIWxStorage, SIWxValidationOptions, SIWxValidationResult, SIWxVerifyOptions, SIWxVerifyResult, SOLANA_DEVNET, SOLANA_MAINNET, SOLANA_TESTNET, SignatureScheme, SignatureType, SolanaSigner, SupportedChain, buildSIWxSchema, createSIWxClientHook, createSIWxMessage, createSIWxPayload, createSIWxRequestHook, createSIWxSettleHook, declareSIWxExtension, decodeBase58, encodeBase58, encodeSIWxHeader, extractEVMChainId, extractSolanaChainReference, formatSIWEMessage, formatSIWSMessage, getEVMAddress, getSolanaAddress, isEVMSigner, isSolanaSigner, parseSIWxHeader, signEVMMessage, signSolanaMessage, siwxResourceServerExtension, validateSIWxMessage, verifyEVMSignature, verifySIWxSignature, verifySolanaSignature, wrapFetchWithSIWx } from './sign-in-with-x/index.mjs';
|
|
3
3
|
export { PAYMENT_IDENTIFIER, PAYMENT_ID_MAX_LENGTH, PAYMENT_ID_MIN_LENGTH, PAYMENT_ID_PATTERN, PaymentIdentifierExtension, PaymentIdentifierInfo, PaymentIdentifierSchema, PaymentIdentifierValidationResult, appendPaymentIdentifierToExtensions, declarePaymentIdentifierExtension, extractAndValidatePaymentIdentifier, extractPaymentIdentifier, generatePaymentId, hasPaymentIdentifier, isPaymentIdentifierExtension, isPaymentIdentifierRequired, isValidPaymentId, paymentIdentifierResourceServerExtension, paymentIdentifierSchema, validatePaymentIdentifier, validatePaymentIdentifierRequirement } from './payment-identifier/index.mjs';
|
|
4
|
+
import { FacilitatorExtension, PaymentPayload } from '@x402/core/types';
|
|
4
5
|
import '@x402/core/http';
|
|
5
|
-
import '@x402/core/types';
|
|
6
6
|
import 'zod';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type definitions for the EIP-2612 Gas Sponsoring Extension
|
|
10
|
+
*
|
|
11
|
+
* This extension enables gasless approval of the Permit2 contract for tokens
|
|
12
|
+
* that implement EIP-2612. The client signs an off-chain permit, and the
|
|
13
|
+
* facilitator submits it on-chain via `x402Permit2Proxy.settleWithPermit`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Extension identifier for the EIP-2612 gas sponsoring extension.
|
|
18
|
+
*/
|
|
19
|
+
declare const EIP2612_GAS_SPONSORING: FacilitatorExtension;
|
|
20
|
+
/**
|
|
21
|
+
* EIP-2612 gas sponsoring info populated by the client.
|
|
22
|
+
*
|
|
23
|
+
* Contains the EIP-2612 permit signature and parameters that the facilitator
|
|
24
|
+
* needs to call `x402Permit2Proxy.settleWithPermit`.
|
|
25
|
+
*/
|
|
26
|
+
interface Eip2612GasSponsoringInfo {
|
|
27
|
+
/** Index signature for compatibility with Record<string, unknown> */
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
/** The address of the sender (token owner). */
|
|
30
|
+
from: string;
|
|
31
|
+
/** The address of the ERC-20 token contract. */
|
|
32
|
+
asset: string;
|
|
33
|
+
/** The address of the spender (Canonical Permit2). */
|
|
34
|
+
spender: string;
|
|
35
|
+
/** The amount to approve (uint256 as decimal string). Typically MaxUint256. */
|
|
36
|
+
amount: string;
|
|
37
|
+
/** The current EIP-2612 nonce of the sender (decimal string). */
|
|
38
|
+
nonce: string;
|
|
39
|
+
/** The timestamp at which the permit signature expires (decimal string). */
|
|
40
|
+
deadline: string;
|
|
41
|
+
/** The 65-byte concatenated EIP-2612 permit signature (r, s, v) as a hex string. */
|
|
42
|
+
signature: string;
|
|
43
|
+
/** Schema version identifier. */
|
|
44
|
+
version: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Server-side EIP-2612 gas sponsoring info included in PaymentRequired.
|
|
48
|
+
* Contains a description and version; the client populates the rest.
|
|
49
|
+
*/
|
|
50
|
+
interface Eip2612GasSponsoringServerInfo {
|
|
51
|
+
/** Index signature for compatibility with Record<string, unknown> */
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
/** Human-readable description of the extension. */
|
|
54
|
+
description: string;
|
|
55
|
+
/** Schema version identifier. */
|
|
56
|
+
version: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The full extension object as it appears in PaymentRequired.extensions
|
|
60
|
+
* and PaymentPayload.extensions.
|
|
61
|
+
*/
|
|
62
|
+
interface Eip2612GasSponsoringExtension {
|
|
63
|
+
/** Extension info - server-provided or client-enriched. */
|
|
64
|
+
info: Eip2612GasSponsoringServerInfo | Eip2612GasSponsoringInfo;
|
|
65
|
+
/** JSON Schema describing the expected structure of info. */
|
|
66
|
+
schema: Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resource Service functions for declaring the EIP-2612 Gas Sponsoring extension.
|
|
71
|
+
*
|
|
72
|
+
* These functions help servers declare support for EIP-2612 gasless Permit2 approvals
|
|
73
|
+
* in the PaymentRequired response extensions.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Declares the EIP-2612 gas sponsoring extension for inclusion in
|
|
78
|
+
* PaymentRequired.extensions.
|
|
79
|
+
*
|
|
80
|
+
* The server advertises that it (or its facilitator) supports EIP-2612
|
|
81
|
+
* gasless Permit2 approval. The client will populate the info with the
|
|
82
|
+
* actual permit signature data.
|
|
83
|
+
*
|
|
84
|
+
* @returns An object keyed by the extension identifier containing the extension declaration
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { declareEip2612GasSponsoringExtension } from '@x402/extensions';
|
|
89
|
+
*
|
|
90
|
+
* const routes = [
|
|
91
|
+
* {
|
|
92
|
+
* path: "/api/data",
|
|
93
|
+
* price: "$0.01",
|
|
94
|
+
* extensions: {
|
|
95
|
+
* ...declareEip2612GasSponsoringExtension(),
|
|
96
|
+
* },
|
|
97
|
+
* },
|
|
98
|
+
* ];
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function declareEip2612GasSponsoringExtension(): Record<string, Eip2612GasSponsoringExtension>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Facilitator functions for extracting and validating EIP-2612 Gas Sponsoring extension data.
|
|
105
|
+
*
|
|
106
|
+
* These functions help facilitators extract the EIP-2612 permit data from payment
|
|
107
|
+
* payloads and validate it before calling settleWithPermit.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Extracts the EIP-2612 gas sponsoring info from a payment payload's extensions.
|
|
112
|
+
*
|
|
113
|
+
* Returns the info if the extension is present and contains the required client-populated
|
|
114
|
+
* fields (from, asset, spender, amount, nonce, deadline, signature, version).
|
|
115
|
+
*
|
|
116
|
+
* @param paymentPayload - The payment payload to extract from
|
|
117
|
+
* @returns The EIP-2612 gas sponsoring info, or null if not present
|
|
118
|
+
*/
|
|
119
|
+
declare function extractEip2612GasSponsoringInfo(paymentPayload: PaymentPayload): Eip2612GasSponsoringInfo | null;
|
|
120
|
+
/**
|
|
121
|
+
* Validates that the EIP-2612 gas sponsoring info has valid format.
|
|
122
|
+
*
|
|
123
|
+
* Performs basic validation on the info fields:
|
|
124
|
+
* - Addresses are valid hex (0x + 40 hex chars)
|
|
125
|
+
* - Amount, nonce, deadline are numeric strings
|
|
126
|
+
* - Signature is a hex string
|
|
127
|
+
* - Version is a numeric version string
|
|
128
|
+
*
|
|
129
|
+
* @param info - The EIP-2612 gas sponsoring info to validate
|
|
130
|
+
* @returns True if the info is valid, false otherwise
|
|
131
|
+
*/
|
|
132
|
+
declare function validateEip2612GasSponsoringInfo(info: Eip2612GasSponsoringInfo): boolean;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Type definitions for the ERC-20 Approval Gas Sponsoring Extension
|
|
136
|
+
*
|
|
137
|
+
* This extension enables gasless Permit2 approval for generic ERC-20 tokens
|
|
138
|
+
* that do NOT implement EIP-2612. The client signs (but does not broadcast) a
|
|
139
|
+
* raw `approve(Permit2, MaxUint256)` transaction, and the facilitator broadcasts
|
|
140
|
+
* it atomically before settling the Permit2 payment.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Signer capability carried by the ERC-20 approval extension when registered in a facilitator.
|
|
145
|
+
*
|
|
146
|
+
* Mirrors FacilitatorEvmSigner (from @x402/evm) plus `sendRawTransaction`.
|
|
147
|
+
* The extension signer owns the full approve+settle flow: it broadcasts the
|
|
148
|
+
* pre-signed approval transaction AND executes the Permit2 settle call, enabling
|
|
149
|
+
* production implementations to bundle both atomically (e.g., Flashbots, multicall).
|
|
150
|
+
*
|
|
151
|
+
* The method signatures are duplicated here (rather than extending FacilitatorEvmSigner)
|
|
152
|
+
* to avoid a circular dependency between @x402/extensions and @x402/evm.
|
|
153
|
+
*/
|
|
154
|
+
interface Erc20ApprovalGasSponsoringSigner {
|
|
155
|
+
getAddresses(): readonly `0x${string}`[];
|
|
156
|
+
readContract(args: {
|
|
157
|
+
address: `0x${string}`;
|
|
158
|
+
abi: readonly unknown[];
|
|
159
|
+
functionName: string;
|
|
160
|
+
args?: readonly unknown[];
|
|
161
|
+
}): Promise<unknown>;
|
|
162
|
+
verifyTypedData(args: {
|
|
163
|
+
address: `0x${string}`;
|
|
164
|
+
domain: Record<string, unknown>;
|
|
165
|
+
types: Record<string, unknown>;
|
|
166
|
+
primaryType: string;
|
|
167
|
+
message: Record<string, unknown>;
|
|
168
|
+
signature: `0x${string}`;
|
|
169
|
+
}): Promise<boolean>;
|
|
170
|
+
writeContract(args: {
|
|
171
|
+
address: `0x${string}`;
|
|
172
|
+
abi: readonly unknown[];
|
|
173
|
+
functionName: string;
|
|
174
|
+
args: readonly unknown[];
|
|
175
|
+
}): Promise<`0x${string}`>;
|
|
176
|
+
sendTransaction(args: {
|
|
177
|
+
to: `0x${string}`;
|
|
178
|
+
data: `0x${string}`;
|
|
179
|
+
}): Promise<`0x${string}`>;
|
|
180
|
+
waitForTransactionReceipt(args: {
|
|
181
|
+
hash: `0x${string}`;
|
|
182
|
+
}): Promise<{
|
|
183
|
+
status: string;
|
|
184
|
+
}>;
|
|
185
|
+
getCode(args: {
|
|
186
|
+
address: `0x${string}`;
|
|
187
|
+
}): Promise<`0x${string}` | undefined>;
|
|
188
|
+
sendRawTransaction(args: {
|
|
189
|
+
serializedTransaction: `0x${string}`;
|
|
190
|
+
}): Promise<`0x${string}`>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Extension identifier for the ERC-20 approval gas sponsoring extension.
|
|
194
|
+
*/
|
|
195
|
+
declare const ERC20_APPROVAL_GAS_SPONSORING: {
|
|
196
|
+
readonly key: "erc20ApprovalGasSponsoring";
|
|
197
|
+
};
|
|
198
|
+
/** Current schema version for the ERC-20 approval gas sponsoring extension info. */
|
|
199
|
+
declare const ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
|
|
200
|
+
/**
|
|
201
|
+
* Extended extension object registered in a facilitator via registerExtension().
|
|
202
|
+
* Carries the signer that owns the full approve+settle flow for ERC-20 tokens
|
|
203
|
+
* that lack EIP-2612. The signer must have all FacilitatorEvmSigner capabilities
|
|
204
|
+
* plus `sendRawTransaction` for broadcasting the pre-signed approval tx.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* import { createErc20ApprovalGasSponsoringExtension } from '@x402/extensions';
|
|
209
|
+
*
|
|
210
|
+
* facilitator.registerExtension(
|
|
211
|
+
* createErc20ApprovalGasSponsoringExtension(evmSigner, viemClient),
|
|
212
|
+
* );
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
interface Erc20ApprovalGasSponsoringFacilitatorExtension extends FacilitatorExtension {
|
|
216
|
+
key: "erc20ApprovalGasSponsoring";
|
|
217
|
+
/** Signer with broadcast + settle capability. Optional — settlement fails gracefully if absent. */
|
|
218
|
+
signer?: Erc20ApprovalGasSponsoringSigner;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Signer input for {@link createErc20ApprovalGasSponsoringExtension}.
|
|
222
|
+
* Matches the FacilitatorEvmSigner shape from @x402/evm (duplicated to avoid circular dep).
|
|
223
|
+
*/
|
|
224
|
+
type Erc20ApprovalGasSponsoringBaseSigner = Omit<Erc20ApprovalGasSponsoringSigner, "sendRawTransaction">;
|
|
225
|
+
/**
|
|
226
|
+
* Create an ERC-20 approval gas sponsoring extension ready to register in a facilitator.
|
|
227
|
+
*
|
|
228
|
+
* @param signer - The EVM facilitator signer (e.g. from `toFacilitatorEvmSigner()`)
|
|
229
|
+
* @param client - Object providing `sendRawTransaction` (e.g. a viem WalletClient)
|
|
230
|
+
* @param client.sendRawTransaction - Broadcasts a signed transaction to the network
|
|
231
|
+
* @returns A fully configured extension to pass to `facilitator.registerExtension()`
|
|
232
|
+
*/
|
|
233
|
+
declare function createErc20ApprovalGasSponsoringExtension(signer: Erc20ApprovalGasSponsoringBaseSigner, client: {
|
|
234
|
+
sendRawTransaction: (args: {
|
|
235
|
+
serializedTransaction: `0x${string}`;
|
|
236
|
+
}) => Promise<`0x${string}`>;
|
|
237
|
+
}): Erc20ApprovalGasSponsoringFacilitatorExtension;
|
|
238
|
+
/**
|
|
239
|
+
* ERC-20 approval gas sponsoring info populated by the client.
|
|
240
|
+
*
|
|
241
|
+
* Contains the RLP-encoded signed `approve(Permit2, MaxUint256)` transaction
|
|
242
|
+
* that the facilitator broadcasts before settling the Permit2 payment.
|
|
243
|
+
*
|
|
244
|
+
* Note: Unlike EIP-2612, there is no nonce/deadline/signature — instead the
|
|
245
|
+
* entire signed transaction is included as `signedTransaction`.
|
|
246
|
+
*/
|
|
247
|
+
interface Erc20ApprovalGasSponsoringInfo {
|
|
248
|
+
/** Index signature for compatibility with Record<string, unknown> */
|
|
249
|
+
[key: string]: unknown;
|
|
250
|
+
/** The address of the sender (token owner who signed the tx). */
|
|
251
|
+
from: `0x${string}`;
|
|
252
|
+
/** The address of the ERC-20 token contract. */
|
|
253
|
+
asset: `0x${string}`;
|
|
254
|
+
/** The address of the spender (Canonical Permit2). */
|
|
255
|
+
spender: `0x${string}`;
|
|
256
|
+
/** The amount approved (uint256 as decimal string). Always MaxUint256. */
|
|
257
|
+
amount: string;
|
|
258
|
+
/** The RLP-encoded signed EIP-1559 transaction as a hex string. */
|
|
259
|
+
signedTransaction: `0x${string}`;
|
|
260
|
+
/** Schema version identifier. */
|
|
261
|
+
version: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Server-side ERC-20 approval gas sponsoring info included in PaymentRequired.
|
|
265
|
+
* Contains a description and version; the client populates the rest.
|
|
266
|
+
*/
|
|
267
|
+
interface Erc20ApprovalGasSponsoringServerInfo {
|
|
268
|
+
/** Index signature for compatibility with Record<string, unknown> */
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
/** Human-readable description of the extension. */
|
|
271
|
+
description: string;
|
|
272
|
+
/** Schema version identifier. */
|
|
273
|
+
version: string;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The full extension object as it appears in PaymentRequired.extensions
|
|
277
|
+
* and PaymentPayload.extensions.
|
|
278
|
+
*/
|
|
279
|
+
interface Erc20ApprovalGasSponsoringExtension {
|
|
280
|
+
/** Extension info - server-provided or client-enriched. */
|
|
281
|
+
info: Erc20ApprovalGasSponsoringServerInfo | Erc20ApprovalGasSponsoringInfo;
|
|
282
|
+
/** JSON Schema describing the expected structure of info. */
|
|
283
|
+
schema: Record<string, unknown>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Resource Service functions for declaring the ERC-20 Approval Gas Sponsoring extension.
|
|
288
|
+
*
|
|
289
|
+
* These functions help servers declare support for ERC-20 approval gas sponsoring
|
|
290
|
+
* in the PaymentRequired response extensions. Use this for tokens that do NOT
|
|
291
|
+
* implement EIP-2612 (generic ERC-20 tokens).
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The JSON Schema for the ERC-20 approval gas sponsoring extension info.
|
|
296
|
+
* Matches the schema defined in the spec.
|
|
297
|
+
*/
|
|
298
|
+
declare const erc20ApprovalGasSponsoringSchema: Record<string, unknown>;
|
|
299
|
+
/**
|
|
300
|
+
* Declares the ERC-20 approval gas sponsoring extension for inclusion in
|
|
301
|
+
* PaymentRequired.extensions.
|
|
302
|
+
*
|
|
303
|
+
* The server advertises that it (or its facilitator) supports broadcasting
|
|
304
|
+
* a pre-signed `approve(Permit2, MaxUint256)` transaction on the client's behalf.
|
|
305
|
+
* Use this for tokens that do NOT implement EIP-2612.
|
|
306
|
+
*
|
|
307
|
+
* @returns An object keyed by the extension identifier containing the extension declaration
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* import { declareErc20ApprovalGasSponsoringExtension } from '@x402/extensions';
|
|
312
|
+
*
|
|
313
|
+
* const routes = [
|
|
314
|
+
* {
|
|
315
|
+
* path: "/api/data",
|
|
316
|
+
* price: { amount: "1000", asset: "0x...", extra: { assetTransferMethod: "permit2" } },
|
|
317
|
+
* extensions: {
|
|
318
|
+
* ...declareErc20ApprovalGasSponsoringExtension(),
|
|
319
|
+
* },
|
|
320
|
+
* },
|
|
321
|
+
* ];
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare function declareErc20ApprovalGasSponsoringExtension(): Record<string, Erc20ApprovalGasSponsoringExtension>;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Facilitator functions for extracting and validating ERC-20 Approval Gas Sponsoring
|
|
328
|
+
* extension data.
|
|
329
|
+
*
|
|
330
|
+
* These functions help facilitators extract the pre-signed approve() transaction
|
|
331
|
+
* from payment payloads and validate it before broadcasting and settling.
|
|
332
|
+
*/
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Extracts the ERC-20 approval gas sponsoring info from a payment payload's extensions.
|
|
336
|
+
*
|
|
337
|
+
* Performs structural extraction only — checks that the extension is present and
|
|
338
|
+
* contains all required fields. Does NOT validate field formats (use
|
|
339
|
+
* validateErc20ApprovalGasSponsoringInfo for that).
|
|
340
|
+
*
|
|
341
|
+
* @param paymentPayload - The payment payload to extract from
|
|
342
|
+
* @returns The ERC-20 approval gas sponsoring info, or null if not present
|
|
343
|
+
*/
|
|
344
|
+
declare function extractErc20ApprovalGasSponsoringInfo(paymentPayload: PaymentPayload): Erc20ApprovalGasSponsoringInfo | null;
|
|
345
|
+
/**
|
|
346
|
+
* Validates that the ERC-20 approval gas sponsoring info has valid format.
|
|
347
|
+
*
|
|
348
|
+
* Validates the info against the canonical JSON Schema, checking:
|
|
349
|
+
* - All required fields are present
|
|
350
|
+
* - Addresses are valid hex (0x + 40 hex chars)
|
|
351
|
+
* - Amount is a numeric string
|
|
352
|
+
* - signedTransaction is a hex string
|
|
353
|
+
* - Version is a numeric version string
|
|
354
|
+
*
|
|
355
|
+
* @param info - The ERC-20 approval gas sponsoring info to validate
|
|
356
|
+
* @returns True if the info is valid, false otherwise
|
|
357
|
+
*/
|
|
358
|
+
declare function validateErc20ApprovalGasSponsoringInfo(info: Erc20ApprovalGasSponsoringInfo): boolean;
|
|
359
|
+
|
|
360
|
+
export { EIP2612_GAS_SPONSORING, ERC20_APPROVAL_GAS_SPONSORING, ERC20_APPROVAL_GAS_SPONSORING_VERSION, type Eip2612GasSponsoringExtension, type Eip2612GasSponsoringInfo, type Eip2612GasSponsoringServerInfo, type Erc20ApprovalGasSponsoringBaseSigner, type Erc20ApprovalGasSponsoringExtension, type Erc20ApprovalGasSponsoringFacilitatorExtension, type Erc20ApprovalGasSponsoringInfo, type Erc20ApprovalGasSponsoringServerInfo, type Erc20ApprovalGasSponsoringSigner, createErc20ApprovalGasSponsoringExtension, declareEip2612GasSponsoringExtension, declareErc20ApprovalGasSponsoringExtension, erc20ApprovalGasSponsoringSchema, extractEip2612GasSponsoringInfo, extractErc20ApprovalGasSponsoringInfo, validateEip2612GasSponsoringInfo, validateErc20ApprovalGasSponsoringInfo };
|