@x402/extensions 2.3.1 → 2.4.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 +130 -2
- package/dist/cjs/index.js +216 -6
- package/dist/cjs/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/{index-DvDlinmy.d.mts → index-G8RNfr6X.d.mts} +150 -63
- package/dist/esm/index.d.mts +130 -2
- package/dist/esm/index.mjs +98 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/esm/chunk-DFJ4ZQFO.mjs.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
BAZAAR: () => BAZAAR,
|
|
34
|
+
EIP2612_GAS_SPONSORING: () => EIP2612_GAS_SPONSORING,
|
|
34
35
|
InMemorySIWxStorage: () => InMemorySIWxStorage,
|
|
35
36
|
PAYMENT_IDENTIFIER: () => PAYMENT_IDENTIFIER,
|
|
36
37
|
PAYMENT_ID_MAX_LENGTH: () => PAYMENT_ID_MAX_LENGTH,
|
|
@@ -50,6 +51,7 @@ __export(src_exports, {
|
|
|
50
51
|
createSIWxRequestHook: () => createSIWxRequestHook,
|
|
51
52
|
createSIWxSettleHook: () => createSIWxSettleHook,
|
|
52
53
|
declareDiscoveryExtension: () => declareDiscoveryExtension,
|
|
54
|
+
declareEip2612GasSponsoringExtension: () => declareEip2612GasSponsoringExtension,
|
|
53
55
|
declarePaymentIdentifierExtension: () => declarePaymentIdentifierExtension,
|
|
54
56
|
declareSIWxExtension: () => declareSIWxExtension,
|
|
55
57
|
decodeBase58: () => decodeBase58,
|
|
@@ -60,6 +62,7 @@ __export(src_exports, {
|
|
|
60
62
|
extractDiscoveryInfoFromExtension: () => extractDiscoveryInfoFromExtension,
|
|
61
63
|
extractDiscoveryInfoV1: () => extractDiscoveryInfoV1,
|
|
62
64
|
extractEVMChainId: () => extractEVMChainId,
|
|
65
|
+
extractEip2612GasSponsoringInfo: () => extractEip2612GasSponsoringInfo,
|
|
63
66
|
extractPaymentIdentifier: () => extractPaymentIdentifier,
|
|
64
67
|
extractResourceMetadataV1: () => extractResourceMetadataV1,
|
|
65
68
|
extractSolanaChainReference: () => extractSolanaChainReference,
|
|
@@ -69,10 +72,13 @@ __export(src_exports, {
|
|
|
69
72
|
getEVMAddress: () => getEVMAddress,
|
|
70
73
|
getSolanaAddress: () => getSolanaAddress,
|
|
71
74
|
hasPaymentIdentifier: () => hasPaymentIdentifier,
|
|
75
|
+
isBodyExtensionConfig: () => isBodyExtensionConfig,
|
|
72
76
|
isDiscoverableV1: () => isDiscoverableV1,
|
|
73
77
|
isEVMSigner: () => isEVMSigner,
|
|
78
|
+
isMcpExtensionConfig: () => isMcpExtensionConfig,
|
|
74
79
|
isPaymentIdentifierExtension: () => isPaymentIdentifierExtension,
|
|
75
80
|
isPaymentIdentifierRequired: () => isPaymentIdentifierRequired,
|
|
81
|
+
isQueryExtensionConfig: () => isQueryExtensionConfig,
|
|
76
82
|
isSolanaSigner: () => isSolanaSigner,
|
|
77
83
|
isValidPaymentId: () => isValidPaymentId,
|
|
78
84
|
parseSIWxHeader: () => parseSIWxHeader,
|
|
@@ -83,6 +89,7 @@ __export(src_exports, {
|
|
|
83
89
|
siwxResourceServerExtension: () => siwxResourceServerExtension,
|
|
84
90
|
validateAndExtract: () => validateAndExtract,
|
|
85
91
|
validateDiscoveryExtension: () => validateDiscoveryExtension,
|
|
92
|
+
validateEip2612GasSponsoringInfo: () => validateEip2612GasSponsoringInfo,
|
|
86
93
|
validatePaymentIdentifier: () => validatePaymentIdentifier,
|
|
87
94
|
validatePaymentIdentifierRequirement: () => validatePaymentIdentifierRequirement,
|
|
88
95
|
validateSIWxMessage: () => validateSIWxMessage,
|
|
@@ -94,10 +101,23 @@ __export(src_exports, {
|
|
|
94
101
|
});
|
|
95
102
|
module.exports = __toCommonJS(src_exports);
|
|
96
103
|
|
|
104
|
+
// src/bazaar/http/types.ts
|
|
105
|
+
var isQueryExtensionConfig = (config) => {
|
|
106
|
+
return !("bodyType" in config) && !("toolName" in config);
|
|
107
|
+
};
|
|
108
|
+
var isBodyExtensionConfig = (config) => {
|
|
109
|
+
return "bodyType" in config;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/bazaar/mcp/types.ts
|
|
113
|
+
var isMcpExtensionConfig = (config) => {
|
|
114
|
+
return "toolName" in config;
|
|
115
|
+
};
|
|
116
|
+
|
|
97
117
|
// src/bazaar/types.ts
|
|
98
|
-
var BAZAAR = "bazaar";
|
|
118
|
+
var BAZAAR = { key: "bazaar" };
|
|
99
119
|
|
|
100
|
-
// src/bazaar/resourceService.ts
|
|
120
|
+
// src/bazaar/http/resourceService.ts
|
|
101
121
|
function createQueryDiscoveryExtension({
|
|
102
122
|
method,
|
|
103
123
|
input = {},
|
|
@@ -229,7 +249,97 @@ function createBodyDiscoveryExtension({
|
|
|
229
249
|
}
|
|
230
250
|
};
|
|
231
251
|
}
|
|
252
|
+
|
|
253
|
+
// src/bazaar/mcp/resourceService.ts
|
|
254
|
+
function createMcpDiscoveryExtension({
|
|
255
|
+
toolName,
|
|
256
|
+
description,
|
|
257
|
+
transport,
|
|
258
|
+
inputSchema,
|
|
259
|
+
example,
|
|
260
|
+
output
|
|
261
|
+
}) {
|
|
262
|
+
return {
|
|
263
|
+
info: {
|
|
264
|
+
input: {
|
|
265
|
+
type: "mcp",
|
|
266
|
+
toolName,
|
|
267
|
+
...description !== void 0 ? { description } : {},
|
|
268
|
+
...transport !== void 0 ? { transport } : {},
|
|
269
|
+
inputSchema,
|
|
270
|
+
...example !== void 0 ? { example } : {}
|
|
271
|
+
},
|
|
272
|
+
...output?.example ? {
|
|
273
|
+
output: {
|
|
274
|
+
type: "json",
|
|
275
|
+
example: output.example
|
|
276
|
+
}
|
|
277
|
+
} : {}
|
|
278
|
+
},
|
|
279
|
+
schema: {
|
|
280
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
281
|
+
type: "object",
|
|
282
|
+
properties: {
|
|
283
|
+
input: {
|
|
284
|
+
type: "object",
|
|
285
|
+
properties: {
|
|
286
|
+
type: {
|
|
287
|
+
type: "string",
|
|
288
|
+
const: "mcp"
|
|
289
|
+
},
|
|
290
|
+
toolName: {
|
|
291
|
+
type: "string"
|
|
292
|
+
},
|
|
293
|
+
...description !== void 0 ? {
|
|
294
|
+
description: {
|
|
295
|
+
type: "string"
|
|
296
|
+
}
|
|
297
|
+
} : {},
|
|
298
|
+
...transport !== void 0 ? {
|
|
299
|
+
transport: {
|
|
300
|
+
type: "string",
|
|
301
|
+
enum: ["streamable-http", "sse"]
|
|
302
|
+
}
|
|
303
|
+
} : {},
|
|
304
|
+
inputSchema: {
|
|
305
|
+
type: "object"
|
|
306
|
+
},
|
|
307
|
+
...example !== void 0 ? {
|
|
308
|
+
example: {
|
|
309
|
+
type: "object"
|
|
310
|
+
}
|
|
311
|
+
} : {}
|
|
312
|
+
},
|
|
313
|
+
required: ["type", "toolName", "inputSchema"],
|
|
314
|
+
additionalProperties: false
|
|
315
|
+
},
|
|
316
|
+
...output?.example ? {
|
|
317
|
+
output: {
|
|
318
|
+
type: "object",
|
|
319
|
+
properties: {
|
|
320
|
+
type: {
|
|
321
|
+
type: "string"
|
|
322
|
+
},
|
|
323
|
+
example: {
|
|
324
|
+
type: "object",
|
|
325
|
+
...output.schema && typeof output.schema === "object" ? output.schema : {}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
required: ["type"]
|
|
329
|
+
}
|
|
330
|
+
} : {}
|
|
331
|
+
},
|
|
332
|
+
required: ["input"]
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/bazaar/resourceService.ts
|
|
232
338
|
function declareDiscoveryExtension(config) {
|
|
339
|
+
if ("toolName" in config) {
|
|
340
|
+
const extension2 = createMcpDiscoveryExtension(config);
|
|
341
|
+
return { bazaar: extension2 };
|
|
342
|
+
}
|
|
233
343
|
const bodyType = config.bodyType;
|
|
234
344
|
const isBodyMethod2 = bodyType !== void 0;
|
|
235
345
|
const extension = isBodyMethod2 ? createBodyDiscoveryExtension(config) : createQueryDiscoveryExtension(config);
|
|
@@ -241,12 +351,15 @@ function isHTTPRequestContext(ctx) {
|
|
|
241
351
|
return ctx !== null && typeof ctx === "object" && "method" in ctx && "adapter" in ctx;
|
|
242
352
|
}
|
|
243
353
|
var bazaarResourceServerExtension = {
|
|
244
|
-
key: BAZAAR,
|
|
354
|
+
key: BAZAAR.key,
|
|
245
355
|
enrichDeclaration: (declaration, transportContext) => {
|
|
246
356
|
if (!isHTTPRequestContext(transportContext)) {
|
|
247
357
|
return declaration;
|
|
248
358
|
}
|
|
249
359
|
const extension = declaration;
|
|
360
|
+
if (extension.info?.input?.type === "mcp") {
|
|
361
|
+
return declaration;
|
|
362
|
+
}
|
|
250
363
|
const method = transportContext.method;
|
|
251
364
|
const existingInputProps = extension.schema?.properties?.input?.properties || {};
|
|
252
365
|
const updatedInputProps = {
|
|
@@ -429,7 +542,7 @@ function extractDiscoveryInfo(paymentPayload, paymentRequirements, validate = tr
|
|
|
429
542
|
if (paymentPayload.x402Version === 2) {
|
|
430
543
|
resourceUrl = paymentPayload.resource?.url ?? "";
|
|
431
544
|
if (paymentPayload.extensions) {
|
|
432
|
-
const bazaarExtension = paymentPayload.extensions[BAZAAR];
|
|
545
|
+
const bazaarExtension = paymentPayload.extensions[BAZAAR.key];
|
|
433
546
|
if (bazaarExtension && typeof bazaarExtension === "object") {
|
|
434
547
|
try {
|
|
435
548
|
const extension = bazaarExtension;
|
|
@@ -472,14 +585,17 @@ function extractDiscoveryInfo(paymentPayload, paymentRequirements, validate = tr
|
|
|
472
585
|
description = requirementsV1.description;
|
|
473
586
|
mimeType = requirementsV1.mimeType;
|
|
474
587
|
}
|
|
475
|
-
|
|
588
|
+
const base = {
|
|
476
589
|
resourceUrl: normalizedResourceUrl,
|
|
477
590
|
description,
|
|
478
591
|
mimeType,
|
|
479
|
-
method: discoveryInfo.input.method,
|
|
480
592
|
x402Version: paymentPayload.x402Version,
|
|
481
593
|
discoveryInfo
|
|
482
594
|
};
|
|
595
|
+
if (discoveryInfo.input.type === "mcp") {
|
|
596
|
+
return { ...base, toolName: discoveryInfo.input.toolName };
|
|
597
|
+
}
|
|
598
|
+
return { ...base, method: discoveryInfo.input.method };
|
|
483
599
|
}
|
|
484
600
|
function extractDiscoveryInfoFromExtension(extension, validate = true) {
|
|
485
601
|
if (validate) {
|
|
@@ -1499,9 +1615,97 @@ var paymentIdentifierResourceServerExtension = {
|
|
|
1499
1615
|
// No enrichment needed - the declaration is static
|
|
1500
1616
|
// Future hooks for idempotency could be added here if needed
|
|
1501
1617
|
};
|
|
1618
|
+
|
|
1619
|
+
// src/eip2612-gas-sponsoring/types.ts
|
|
1620
|
+
var EIP2612_GAS_SPONSORING = { key: "eip2612GasSponsoring" };
|
|
1621
|
+
|
|
1622
|
+
// src/eip2612-gas-sponsoring/resourceService.ts
|
|
1623
|
+
var eip2612GasSponsoringSchema = {
|
|
1624
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1625
|
+
type: "object",
|
|
1626
|
+
properties: {
|
|
1627
|
+
from: {
|
|
1628
|
+
type: "string",
|
|
1629
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1630
|
+
description: "The address of the sender."
|
|
1631
|
+
},
|
|
1632
|
+
asset: {
|
|
1633
|
+
type: "string",
|
|
1634
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1635
|
+
description: "The address of the ERC-20 token contract."
|
|
1636
|
+
},
|
|
1637
|
+
spender: {
|
|
1638
|
+
type: "string",
|
|
1639
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
1640
|
+
description: "The address of the spender (Canonical Permit2)."
|
|
1641
|
+
},
|
|
1642
|
+
amount: {
|
|
1643
|
+
type: "string",
|
|
1644
|
+
pattern: "^[0-9]+$",
|
|
1645
|
+
description: "The amount to approve (uint256). Typically MaxUint."
|
|
1646
|
+
},
|
|
1647
|
+
nonce: {
|
|
1648
|
+
type: "string",
|
|
1649
|
+
pattern: "^[0-9]+$",
|
|
1650
|
+
description: "The current nonce of the sender."
|
|
1651
|
+
},
|
|
1652
|
+
deadline: {
|
|
1653
|
+
type: "string",
|
|
1654
|
+
pattern: "^[0-9]+$",
|
|
1655
|
+
description: "The timestamp at which the signature expires."
|
|
1656
|
+
},
|
|
1657
|
+
signature: {
|
|
1658
|
+
type: "string",
|
|
1659
|
+
pattern: "^0x[a-fA-F0-9]+$",
|
|
1660
|
+
description: "The 65-byte concatenated signature (r, s, v) as a hex string."
|
|
1661
|
+
},
|
|
1662
|
+
version: {
|
|
1663
|
+
type: "string",
|
|
1664
|
+
pattern: "^[0-9]+(\\.[0-9]+)*$",
|
|
1665
|
+
description: "Schema version identifier."
|
|
1666
|
+
}
|
|
1667
|
+
},
|
|
1668
|
+
required: ["from", "asset", "spender", "amount", "nonce", "deadline", "signature", "version"]
|
|
1669
|
+
};
|
|
1670
|
+
function declareEip2612GasSponsoringExtension() {
|
|
1671
|
+
const key = EIP2612_GAS_SPONSORING.key;
|
|
1672
|
+
return {
|
|
1673
|
+
[key]: {
|
|
1674
|
+
info: {
|
|
1675
|
+
description: "The facilitator accepts EIP-2612 gasless Permit to `Permit2` canonical contract.",
|
|
1676
|
+
version: "1"
|
|
1677
|
+
},
|
|
1678
|
+
schema: eip2612GasSponsoringSchema
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
// src/eip2612-gas-sponsoring/facilitator.ts
|
|
1684
|
+
function extractEip2612GasSponsoringInfo(paymentPayload) {
|
|
1685
|
+
if (!paymentPayload.extensions) {
|
|
1686
|
+
return null;
|
|
1687
|
+
}
|
|
1688
|
+
const extension = paymentPayload.extensions[EIP2612_GAS_SPONSORING.key];
|
|
1689
|
+
if (!extension?.info) {
|
|
1690
|
+
return null;
|
|
1691
|
+
}
|
|
1692
|
+
const info = extension.info;
|
|
1693
|
+
if (!info.from || !info.asset || !info.spender || !info.amount || !info.nonce || !info.deadline || !info.signature || !info.version) {
|
|
1694
|
+
return null;
|
|
1695
|
+
}
|
|
1696
|
+
return info;
|
|
1697
|
+
}
|
|
1698
|
+
function validateEip2612GasSponsoringInfo(info) {
|
|
1699
|
+
const addressPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
1700
|
+
const numericPattern = /^[0-9]+$/;
|
|
1701
|
+
const hexPattern = /^0x[a-fA-F0-9]+$/;
|
|
1702
|
+
const versionPattern = /^[0-9]+(\.[0-9]+)*$/;
|
|
1703
|
+
return addressPattern.test(info.from) && addressPattern.test(info.asset) && addressPattern.test(info.spender) && numericPattern.test(info.amount) && numericPattern.test(info.nonce) && numericPattern.test(info.deadline) && hexPattern.test(info.signature) && versionPattern.test(info.version);
|
|
1704
|
+
}
|
|
1502
1705
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1503
1706
|
0 && (module.exports = {
|
|
1504
1707
|
BAZAAR,
|
|
1708
|
+
EIP2612_GAS_SPONSORING,
|
|
1505
1709
|
InMemorySIWxStorage,
|
|
1506
1710
|
PAYMENT_IDENTIFIER,
|
|
1507
1711
|
PAYMENT_ID_MAX_LENGTH,
|
|
@@ -1521,6 +1725,7 @@ var paymentIdentifierResourceServerExtension = {
|
|
|
1521
1725
|
createSIWxRequestHook,
|
|
1522
1726
|
createSIWxSettleHook,
|
|
1523
1727
|
declareDiscoveryExtension,
|
|
1728
|
+
declareEip2612GasSponsoringExtension,
|
|
1524
1729
|
declarePaymentIdentifierExtension,
|
|
1525
1730
|
declareSIWxExtension,
|
|
1526
1731
|
decodeBase58,
|
|
@@ -1531,6 +1736,7 @@ var paymentIdentifierResourceServerExtension = {
|
|
|
1531
1736
|
extractDiscoveryInfoFromExtension,
|
|
1532
1737
|
extractDiscoveryInfoV1,
|
|
1533
1738
|
extractEVMChainId,
|
|
1739
|
+
extractEip2612GasSponsoringInfo,
|
|
1534
1740
|
extractPaymentIdentifier,
|
|
1535
1741
|
extractResourceMetadataV1,
|
|
1536
1742
|
extractSolanaChainReference,
|
|
@@ -1540,10 +1746,13 @@ var paymentIdentifierResourceServerExtension = {
|
|
|
1540
1746
|
getEVMAddress,
|
|
1541
1747
|
getSolanaAddress,
|
|
1542
1748
|
hasPaymentIdentifier,
|
|
1749
|
+
isBodyExtensionConfig,
|
|
1543
1750
|
isDiscoverableV1,
|
|
1544
1751
|
isEVMSigner,
|
|
1752
|
+
isMcpExtensionConfig,
|
|
1545
1753
|
isPaymentIdentifierExtension,
|
|
1546
1754
|
isPaymentIdentifierRequired,
|
|
1755
|
+
isQueryExtensionConfig,
|
|
1547
1756
|
isSolanaSigner,
|
|
1548
1757
|
isValidPaymentId,
|
|
1549
1758
|
parseSIWxHeader,
|
|
@@ -1554,6 +1763,7 @@ var paymentIdentifierResourceServerExtension = {
|
|
|
1554
1763
|
siwxResourceServerExtension,
|
|
1555
1764
|
validateAndExtract,
|
|
1556
1765
|
validateDiscoveryExtension,
|
|
1766
|
+
validateEip2612GasSponsoringInfo,
|
|
1557
1767
|
validatePaymentIdentifier,
|
|
1558
1768
|
validatePaymentIdentifierRequirement,
|
|
1559
1769
|
validateSIWxMessage,
|