@devlab.group/agent-commerce 2.7.2 → 2.8.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 +71 -24
- package/dist/ap2.d.ts +3 -11
- package/dist/ap2.js +96 -27
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-77HLISG4.js → chunk-2PVRHMVT.js} +14 -10
- package/dist/chunk-2PVRHMVT.js.map +1 -0
- package/dist/chunk-ENK63GKR.js +22 -0
- package/dist/chunk-ENK63GKR.js.map +1 -0
- package/dist/{chunk-YHNTTMED.js → chunk-MDOGXTZD.js} +2 -2
- package/dist/chunk-MDOGXTZD.js.map +1 -0
- package/dist/chunk-MNI6APE6.js +64 -0
- package/dist/chunk-MNI6APE6.js.map +1 -0
- package/dist/{chunk-XXHC6AA3.js → chunk-QZW5YL3G.js} +160 -41
- package/dist/chunk-QZW5YL3G.js.map +1 -0
- package/dist/{chunk-DJRWYDKJ.js → chunk-RXYGC7A3.js} +3 -3
- package/dist/{chunk-DJRWYDKJ.js.map → chunk-RXYGC7A3.js.map} +1 -1
- package/dist/{chunk-5AO5N2XY.js → chunk-VHS6MGXJ.js} +621 -4
- package/dist/chunk-VHS6MGXJ.js.map +1 -0
- package/dist/cli/{ap2-O3HJSS2E.js → ap2-GYKFGE66.js} +35 -8
- package/dist/cli/ap2-GYKFGE66.js.map +1 -0
- package/dist/cli/chunk-2PO65227.js +619 -0
- package/dist/cli/chunk-2PO65227.js.map +1 -0
- package/dist/cli/{chunk-GBBG66O6.js → chunk-3PGFOEVJ.js} +132 -103
- package/dist/cli/chunk-3PGFOEVJ.js.map +1 -0
- package/dist/cli/chunk-4YZULHX2.js +64 -0
- package/dist/cli/chunk-4YZULHX2.js.map +1 -0
- package/dist/cli/chunk-526C4KZA.js +93 -0
- package/dist/cli/chunk-526C4KZA.js.map +1 -0
- package/dist/cli/{chunk-FETTSOMT.js → chunk-5CH5VFC6.js} +139 -4
- package/dist/cli/chunk-5CH5VFC6.js.map +1 -0
- package/dist/cli/chunk-6BWEHQPJ.js +215 -0
- package/dist/cli/chunk-6BWEHQPJ.js.map +1 -0
- package/dist/cli/chunk-GISJ73ML.js +20 -0
- package/dist/cli/chunk-GISJ73ML.js.map +1 -0
- package/dist/cli/chunk-MASLG557.js +26 -0
- package/dist/cli/chunk-MASLG557.js.map +1 -0
- package/dist/cli/chunk-RQ7W3NA5.js +143 -0
- package/dist/cli/chunk-RQ7W3NA5.js.map +1 -0
- package/dist/cli/chunk-RWBUHDU7.js +48 -0
- package/dist/cli/chunk-RWBUHDU7.js.map +1 -0
- package/dist/cli/chunk-SAAT2XFX.js +8 -0
- package/dist/cli/{chunk-B4QJV7OC.js.map → chunk-SAAT2XFX.js.map} +1 -1
- package/dist/cli/{chunk-S5TQXKQ7.js → chunk-SYXLQ5BS.js} +7 -5
- package/dist/cli/chunk-SYXLQ5BS.js.map +1 -0
- package/dist/cli/{chunk-FL4HPCD4.js → chunk-THH7Y3OO.js} +3 -35
- package/dist/cli/chunk-THH7Y3OO.js.map +1 -0
- package/dist/cli/{chunk-55AI6CLW.js → chunk-USIXWAXZ.js} +2 -2
- package/dist/cli/chunk-USIXWAXZ.js.map +1 -0
- package/dist/cli/{chunk-QUFFT5K3.js → chunk-VWQMSWDF.js} +141 -42
- package/dist/cli/chunk-VWQMSWDF.js.map +1 -0
- package/dist/cli/{chunk-OETKXDGA.js → chunk-WFIR374D.js} +89 -272
- package/dist/cli/chunk-WFIR374D.js.map +1 -0
- package/dist/cli/{chunk-XRG5UTIC.js → chunk-YXXPZFWC.js} +4 -4
- package/dist/cli/{chunk-XRG5UTIC.js.map → chunk-YXXPZFWC.js.map} +1 -1
- package/dist/cli/config-JWMHWVRT.js +14 -0
- package/dist/cli/{config-ODN4IEMZ.js.map → config-JWMHWVRT.js.map} +1 -1
- package/dist/cli/index.js +349 -78
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-G2D2Z77G.js → mcp-OW5GY7TT.js} +84 -45
- package/dist/cli/mcp-OW5GY7TT.js.map +1 -0
- package/dist/cli/payment-providers-QL2BJYMD.js +6 -0
- package/dist/cli/{payment-providers-7RIIZ5OF.js.map → payment-providers-QL2BJYMD.js.map} +1 -1
- package/dist/cli/{provider-ARV3VAQ7.js → provider-3A2LVEQS.js} +145 -23
- package/dist/cli/provider-3A2LVEQS.js.map +1 -0
- package/dist/cli/receipts-FQUFGEQD.js +9 -0
- package/dist/cli/{receipts-HLQ7D722.js.map → receipts-FQUFGEQD.js.map} +1 -1
- package/dist/cli/{run-BHODKC6H.js → run-KF5OQYPL.js} +92 -63
- package/dist/cli/run-KF5OQYPL.js.map +1 -0
- package/dist/cli/{x402-LHW2YQ6W.js → x402-5A7CVCIJ.js} +12 -8
- package/dist/cli/x402-5A7CVCIJ.js.map +1 -0
- package/dist/index.d.ts +36 -12
- package/dist/index.js +340 -394
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +80 -42
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +3 -2
- package/dist/mpp.js +139 -20
- package/dist/mpp.js.map +1 -1
- package/dist/{protocol-adapter-DdFL5LBU.d.ts → protocol-adapter-D6JH_kk-.d.ts} +2 -2
- package/dist/{runtime-BmaSp2Ce.d.ts → runtime-D8u6lYfx.d.ts} +10 -0
- package/dist/{store-DQwbKhnc.d.ts → store-BzgwHOPu.d.ts} +2 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{transaction-BXXJltZ-.d.ts → transaction-F9ZvhokH.d.ts} +1 -1
- package/dist/types-Dl27vhEc.d.ts +167 -0
- package/dist/x402.d.ts +7 -110
- package/dist/x402.js +6 -5
- package/dist/x402.js.map +1 -1
- package/package.json +3 -1
- package/dist/chunk-2573DASO.js +0 -8
- package/dist/chunk-2573DASO.js.map +0 -1
- package/dist/chunk-5AO5N2XY.js.map +0 -1
- package/dist/chunk-77HLISG4.js.map +0 -1
- package/dist/chunk-XXHC6AA3.js.map +0 -1
- package/dist/chunk-YHNTTMED.js.map +0 -1
- package/dist/cli/ap2-O3HJSS2E.js.map +0 -1
- package/dist/cli/chunk-3NVJAQRO.js +0 -119
- package/dist/cli/chunk-3NVJAQRO.js.map +0 -1
- package/dist/cli/chunk-55AI6CLW.js.map +0 -1
- package/dist/cli/chunk-66NTYSXI.js +0 -277
- package/dist/cli/chunk-66NTYSXI.js.map +0 -1
- package/dist/cli/chunk-B4QJV7OC.js +0 -8
- package/dist/cli/chunk-FETTSOMT.js.map +0 -1
- package/dist/cli/chunk-FL4HPCD4.js.map +0 -1
- package/dist/cli/chunk-GBBG66O6.js.map +0 -1
- package/dist/cli/chunk-H7EBJ4I3.js +0 -53
- package/dist/cli/chunk-H7EBJ4I3.js.map +0 -1
- package/dist/cli/chunk-OETKXDGA.js.map +0 -1
- package/dist/cli/chunk-QUFFT5K3.js.map +0 -1
- package/dist/cli/chunk-S5TQXKQ7.js.map +0 -1
- package/dist/cli/chunk-TPC4EJLT.js +0 -11
- package/dist/cli/chunk-TPC4EJLT.js.map +0 -1
- package/dist/cli/config-ODN4IEMZ.js +0 -13
- package/dist/cli/mcp-G2D2Z77G.js.map +0 -1
- package/dist/cli/payment-providers-7RIIZ5OF.js +0 -6
- package/dist/cli/provider-ARV3VAQ7.js.map +0 -1
- package/dist/cli/receipts-HLQ7D722.js +0 -9
- package/dist/cli/run-BHODKC6H.js.map +0 -1
- package/dist/cli/x402-LHW2YQ6W.js.map +0 -1
- package/dist/networks-DDHYJLcg.d.ts +0 -39
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { gotNoAnswer } from './chunk-MASLG557.js';
|
|
2
|
+
import { x402_default } from './chunk-RQ7W3NA5.js';
|
|
3
|
+
import { exclusionNames, descriptorStatus } from './chunk-GISJ73ML.js';
|
|
4
|
+
import { isWellKnownDevKey, assertPayToIsNotDevAddress, resolveX402Deployment, assertDevKeyIsLocalOnly, describeRpc, BAZAAR_EXTENSION_KEY, x402OfferName, CDP_FACILITATOR_URL } from './chunk-5CH5VFC6.js';
|
|
5
|
+
import { findX402Network, normalizeAddress, canonicalJson, X402_DEFAULT_PAYMENT_FLOW, REUSE_REJECTED_AUTHORIZATION_METADATA_KEY, SETTLE_AFTER_BACKEND_METADATA_KEY, sameAddress, LOCAL_CHAIN_ID, isTransactionReference, isEvmAddress, describeDeploymentMode } from './chunk-2PO65227.js';
|
|
6
|
+
import { PACKAGE_VERSION } from './chunk-SAAT2XFX.js';
|
|
7
|
+
import { systemClock, NOOP_LOGGER, RECONCILIATION_METADATA_KEY } from './chunk-USIXWAXZ.js';
|
|
5
8
|
import { CommerceError, redactedErrorText, isCommerceError } from './chunk-C5YISPT6.js';
|
|
6
9
|
import { LOCATOR_VERSION, eip3009Locator, computeReplayKey, permit2Locator, computePermit2ReplayKey, isoFromSeconds } from './chunk-663ALDZA.js';
|
|
7
10
|
import { isRecord } from './chunk-3M6U7ILB.js';
|
|
@@ -53,6 +56,54 @@ function parseCanonicalAmount(amount, decimals) {
|
|
|
53
56
|
return BigInt(combined);
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
// src/payments/x402/provider/bazaar-forwarding.ts
|
|
60
|
+
var SUPPORTED_GRACE_MS = 1e3;
|
|
61
|
+
var MAX_LOGGED_REASON_LENGTH = 200;
|
|
62
|
+
function createBazaarForwarding(ctx, currentSupported) {
|
|
63
|
+
const { remoteBinding, logger } = ctx;
|
|
64
|
+
let unlistedLogged = false;
|
|
65
|
+
const rejectedLogged = /* @__PURE__ */ new Set();
|
|
66
|
+
async function listed() {
|
|
67
|
+
if (remoteBinding?.kind !== "remote") return false;
|
|
68
|
+
let timer;
|
|
69
|
+
const late = new Promise((resolve) => {
|
|
70
|
+
timer = setTimeout(() => resolve(void 0), SUPPORTED_GRACE_MS);
|
|
71
|
+
timer.unref();
|
|
72
|
+
});
|
|
73
|
+
const supported = await Promise.race([currentSupported(), late]).catch(() => void 0).finally(() => clearTimeout(timer));
|
|
74
|
+
if (supported === void 0) return false;
|
|
75
|
+
const lists = Array.isArray(supported.extensions) && supported.extensions.includes(BAZAAR_EXTENSION_KEY);
|
|
76
|
+
if (!lists && !unlistedLogged) {
|
|
77
|
+
unlistedLogged = true;
|
|
78
|
+
logger.warn(
|
|
79
|
+
{ facilitator: remoteBinding.describe },
|
|
80
|
+
"x402: the facilitator does not list the bazaar extension in /supported; Bazaar metadata stays in challenges but is not sent to it"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return lists;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
async issuedFor(issued) {
|
|
87
|
+
if (issued?.extensions?.[BAZAAR_EXTENSION_KEY] === void 0) return void 0;
|
|
88
|
+
return await listed() ? issued : void 0;
|
|
89
|
+
},
|
|
90
|
+
report(resourceId, extensionResponses) {
|
|
91
|
+
const outcome = extensionResponses?.[BAZAAR_EXTENSION_KEY];
|
|
92
|
+
if (!isRecord(outcome) || outcome["status"] !== "rejected") return;
|
|
93
|
+
if (rejectedLogged.has(resourceId)) return;
|
|
94
|
+
rejectedLogged.add(resourceId);
|
|
95
|
+
const reason = outcome["rejectedReason"];
|
|
96
|
+
logger.warn(
|
|
97
|
+
{
|
|
98
|
+
resourceId,
|
|
99
|
+
...typeof reason === "string" ? { reportedReason: redactedErrorText(reason).slice(0, MAX_LOGGED_REASON_LENGTH) } : {}
|
|
100
|
+
},
|
|
101
|
+
"x402: the facilitator rejected the Bazaar metadata of a resource and will not catalog it. Payment is unaffected"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
56
107
|
// src/payments/x402/provider/fee-payer.ts
|
|
57
108
|
var SUPPORTED_TTL_MS = 6e4;
|
|
58
109
|
function createSupportedSource(ctx) {
|
|
@@ -336,10 +387,14 @@ function createHealthCheck(ctx) {
|
|
|
336
387
|
};
|
|
337
388
|
const results = await Promise.all(
|
|
338
389
|
offers.map(
|
|
339
|
-
(offer) => offerHealth(offer, kinds).catch(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
390
|
+
(offer) => offerHealth(offer, kinds).catch(
|
|
391
|
+
(err) => ({
|
|
392
|
+
status: "fail",
|
|
393
|
+
detail: `x402 health check failed: ${redactedErrorText(err)}`,
|
|
394
|
+
// The SDK throws its own timeout error from `/supported`
|
|
395
|
+
...gotNoAnswer(err, ["FacilitatorTimeoutError"]) ? { undetermined: "unreachable" } : {}
|
|
396
|
+
})
|
|
397
|
+
)
|
|
343
398
|
)
|
|
344
399
|
);
|
|
345
400
|
const failed = results.some((result) => result.status === "fail");
|
|
@@ -351,10 +406,14 @@ function createHealthCheck(ctx) {
|
|
|
351
406
|
return {
|
|
352
407
|
status: failed ? "fail" : "pass",
|
|
353
408
|
detail: details.join("; "),
|
|
354
|
-
components: offers.map((offer, index) =>
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
409
|
+
components: offers.map((offer, index) => {
|
|
410
|
+
const { status, undetermined } = results[index];
|
|
411
|
+
return {
|
|
412
|
+
name: x402OfferName(offer),
|
|
413
|
+
status,
|
|
414
|
+
...undetermined !== void 0 ? { undetermined } : {}
|
|
415
|
+
};
|
|
416
|
+
}),
|
|
358
417
|
checkedAt,
|
|
359
418
|
durationMs: clock.monotonicMs() - startedAt
|
|
360
419
|
};
|
|
@@ -603,15 +662,14 @@ function createRemoteFacilitatorBinding(options) {
|
|
|
603
662
|
function withDeadline(call, ms) {
|
|
604
663
|
let timer;
|
|
605
664
|
const deadline = new Promise((_, reject) => {
|
|
606
|
-
timer = setTimeout(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
)
|
|
612
|
-
)
|
|
613
|
-
|
|
614
|
-
);
|
|
665
|
+
timer = setTimeout(() => {
|
|
666
|
+
const message = `x402 provider: facilitator /supported did not answer within ${ms / 1e3} s`;
|
|
667
|
+
reject(
|
|
668
|
+
new CommerceError("PAYMENT_PROVIDER_UNAVAILABLE", message, {
|
|
669
|
+
cause: new DOMException(message, "TimeoutError")
|
|
670
|
+
})
|
|
671
|
+
);
|
|
672
|
+
}, ms);
|
|
615
673
|
timer.unref();
|
|
616
674
|
});
|
|
617
675
|
return Promise.race([call, deadline]).finally(() => clearTimeout(timer));
|
|
@@ -884,9 +942,10 @@ function declaredX402Version(payloadBase64) {
|
|
|
884
942
|
const json = decodeJson(payloadBase64);
|
|
885
943
|
return typeof json === "object" && json !== null ? json["x402Version"] : void 0;
|
|
886
944
|
}
|
|
887
|
-
function forFacilitator(payload) {
|
|
945
|
+
function forFacilitator(payload, issued) {
|
|
888
946
|
const { resource: _resource, extensions: _extensions, ...rest } = payload;
|
|
889
|
-
|
|
947
|
+
const bazaar = issued?.extensions?.[BAZAAR_EXTENSION_KEY];
|
|
948
|
+
return issued !== void 0 && bazaar !== void 0 ? { ...rest, resource: issued.resource, extensions: { [BAZAAR_EXTENSION_KEY]: bazaar } } : rest;
|
|
890
949
|
}
|
|
891
950
|
function decodeJson(payloadBase64) {
|
|
892
951
|
try {
|
|
@@ -1664,6 +1723,12 @@ function createReconcile(ctx) {
|
|
|
1664
1723
|
}
|
|
1665
1724
|
|
|
1666
1725
|
// src/payments/x402/provider/requirement.ts
|
|
1726
|
+
var MAX_HTTP_HEADER_BYTES = 8192;
|
|
1727
|
+
var PROOF_RESERVE_BYTES = {
|
|
1728
|
+
evm: 1024,
|
|
1729
|
+
svm: 2304,
|
|
1730
|
+
near: 1280
|
|
1731
|
+
};
|
|
1667
1732
|
var SELECTED_OFFER_KEY = "x402.offer";
|
|
1668
1733
|
function offerIndexOf(requirement) {
|
|
1669
1734
|
const selected = requirement.metadata?.[SELECTED_OFFER_KEY];
|
|
@@ -1679,7 +1744,8 @@ function acceptedMatchesOffer(offered, accepted, network) {
|
|
|
1679
1744
|
return accepted.scheme === offered.scheme && accepted.network === offered.network && accepted.amount === offered.amount && same(accepted.asset, offered.asset) && same(accepted.payTo, offered.payTo) && Object.entries(offeredExtra).every(([key, value]) => acceptedExtra[key] === value) && flow(acceptedExtra) === flow(offeredExtra);
|
|
1680
1745
|
}
|
|
1681
1746
|
function createRequirementBuilders(ctx, svmFeePayer) {
|
|
1682
|
-
const { options, offersFor, clock, ids, maxTimeoutSeconds } = ctx;
|
|
1747
|
+
const { options, offersFor, clock, ids, maxTimeoutSeconds, logger } = ctx;
|
|
1748
|
+
const oversizedLogged = /* @__PURE__ */ new Set();
|
|
1683
1749
|
async function createRequirement(context) {
|
|
1684
1750
|
const offers = offersFor(context.resource.id);
|
|
1685
1751
|
const paymentFlow = options.resourcePaymentFlows?.[context.resource.id] ?? options.paymentFlow ?? X402_DEFAULT_PAYMENT_FLOW;
|
|
@@ -1716,11 +1782,14 @@ function createRequirementBuilders(ctx, svmFeePayer) {
|
|
|
1716
1782
|
);
|
|
1717
1783
|
const identifier = paymentIdentifierExtensions(context.resource);
|
|
1718
1784
|
const extensions = identifier === void 0 ? quoteExtensions : { ...quoteExtensions, ...identifier };
|
|
1785
|
+
const bazaar = context.protocol === "http" || context.protocol === "mcp" ? options.resourceBazaar?.[context.resource.id]?.[context.protocol] : void 0;
|
|
1719
1786
|
const resourceId = encodeURIComponent(context.resource.id);
|
|
1787
|
+
const surface = context.protocol === "acp" ? void 0 : context.protocol;
|
|
1788
|
+
const publicUrl = surface !== void 0 ? options.resourceUrls?.[context.resource.id]?.[surface] : void 0;
|
|
1720
1789
|
const envelope = {
|
|
1721
1790
|
x402Version: X402_VERSION,
|
|
1722
1791
|
resource: {
|
|
1723
|
-
url: single ? `resource://agent-commerce/${encodeURIComponent(single.network)}/${single.payTo}/resources/${resourceId}` : `resource://agent-commerce/resources/${resourceId}
|
|
1792
|
+
url: publicUrl ?? (single ? `resource://agent-commerce/${encodeURIComponent(single.network)}/${single.payTo}/resources/${resourceId}` : `resource://agent-commerce/resources/${resourceId}`),
|
|
1724
1793
|
description: context.resource.description ?? context.resource.name,
|
|
1725
1794
|
// The media type the merchant declares, else `application/json`; an HTTP
|
|
1726
1795
|
// delivery carries the backend's own type when it is text and fits the body
|
|
@@ -1729,6 +1798,13 @@ function createRequirementBuilders(ctx, svmFeePayer) {
|
|
|
1729
1798
|
accepts,
|
|
1730
1799
|
...extensions !== void 0 ? { extensions } : {}
|
|
1731
1800
|
};
|
|
1801
|
+
const challenge = bazaar === void 0 ? envelope : withBazaar(
|
|
1802
|
+
envelope,
|
|
1803
|
+
bazaar,
|
|
1804
|
+
// MCP carries the challenge in the result body, not a header
|
|
1805
|
+
context.protocol === "http" ? Math.max(...offers.map((offer) => PROOF_RESERVE_BYTES[offer.family])) : void 0,
|
|
1806
|
+
context.resource.id
|
|
1807
|
+
);
|
|
1732
1808
|
const expiresAt = new Date(clock.now().getTime() + maxTimeoutSeconds * 1e3).toISOString();
|
|
1733
1809
|
return {
|
|
1734
1810
|
id: ids.next("payreq"),
|
|
@@ -1744,7 +1820,7 @@ function createRequirementBuilders(ctx, svmFeePayer) {
|
|
|
1744
1820
|
provider: "x402",
|
|
1745
1821
|
version: X402_PROTOCOL_VERSION,
|
|
1746
1822
|
accepts,
|
|
1747
|
-
envelope
|
|
1823
|
+
envelope: challenge
|
|
1748
1824
|
},
|
|
1749
1825
|
metadata: {
|
|
1750
1826
|
[SETTLE_AFTER_BACKEND_METADATA_KEY]: paymentFlow === "authorization",
|
|
@@ -1754,6 +1830,23 @@ function createRequirementBuilders(ctx, svmFeePayer) {
|
|
|
1754
1830
|
}
|
|
1755
1831
|
};
|
|
1756
1832
|
}
|
|
1833
|
+
function withBazaar(envelope, bazaar, headerReserve, resourceId) {
|
|
1834
|
+
const extended = {
|
|
1835
|
+
...envelope,
|
|
1836
|
+
extensions: { ...envelope.extensions, [BAZAAR_EXTENSION_KEY]: bazaar }
|
|
1837
|
+
};
|
|
1838
|
+
if (headerReserve === void 0) return extended;
|
|
1839
|
+
const encoded = 4 * Math.ceil(Buffer.byteLength(JSON.stringify(extended)) / 3);
|
|
1840
|
+
if (encoded + headerReserve <= MAX_HTTP_HEADER_BYTES) return extended;
|
|
1841
|
+
if (!oversizedLogged.has(resourceId)) {
|
|
1842
|
+
oversizedLogged.add(resourceId);
|
|
1843
|
+
logger.warn(
|
|
1844
|
+
{ resourceId, bytes: encoded, reservedBytes: headerReserve },
|
|
1845
|
+
"x402: Bazaar metadata left out of an HTTP challenge too large to leave room for the signed proof in an 8 KiB header"
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
return envelope;
|
|
1849
|
+
}
|
|
1757
1850
|
async function selectRequirement(context) {
|
|
1758
1851
|
const { requirement, submission } = context;
|
|
1759
1852
|
const offered = requirement.challenge.accepts;
|
|
@@ -1828,7 +1921,7 @@ function readTransfer(payload, offer) {
|
|
|
1828
1921
|
}
|
|
1829
1922
|
|
|
1830
1923
|
// src/payments/x402/provider/settle.ts
|
|
1831
|
-
function createSettle(ctx) {
|
|
1924
|
+
function createSettle(ctx, bazaar) {
|
|
1832
1925
|
const { offersFor, clock, logger } = ctx;
|
|
1833
1926
|
async function settle(context) {
|
|
1834
1927
|
const { requirement, submission, verification } = context;
|
|
@@ -1866,10 +1959,13 @@ function createSettle(ctx) {
|
|
|
1866
1959
|
...verification.replayKey !== void 0 ? { replayKey: verification.replayKey } : {},
|
|
1867
1960
|
rejectionReason
|
|
1868
1961
|
});
|
|
1962
|
+
const issued = await bazaar.issuedFor(
|
|
1963
|
+
requirement.challenge.envelope
|
|
1964
|
+
);
|
|
1869
1965
|
const scope = offer.binding.open();
|
|
1870
1966
|
let sdkResult;
|
|
1871
1967
|
try {
|
|
1872
|
-
sdkResult = await scope.settle(forFacilitator(payload), requirements);
|
|
1968
|
+
sdkResult = await scope.settle(forFacilitator(payload, issued), requirements);
|
|
1873
1969
|
} catch (err) {
|
|
1874
1970
|
if (isProviderUnavailableError(err) || scope.transportFailed()) {
|
|
1875
1971
|
throw new CommerceError(
|
|
@@ -1895,6 +1991,7 @@ function createSettle(ctx) {
|
|
|
1895
1991
|
);
|
|
1896
1992
|
return rejectedSettlement("transaction_reverted");
|
|
1897
1993
|
}
|
|
1994
|
+
bazaar.report(requirement.resourceId, sdkResult.extensionResponses);
|
|
1898
1995
|
const payer = verification.payer ?? sdkResult.payer;
|
|
1899
1996
|
if (!sdkResult.success) {
|
|
1900
1997
|
if (isTransactionFailedReason(sdkResult.errorReason) && !reference(sdkResult.transaction)) {
|
|
@@ -1997,7 +2094,7 @@ function createSettle(ctx) {
|
|
|
1997
2094
|
return settle;
|
|
1998
2095
|
}
|
|
1999
2096
|
var RELAYER_GRACE_MS = 1e3;
|
|
2000
|
-
function createVerify(ctx, nearRelayers) {
|
|
2097
|
+
function createVerify(ctx, nearRelayers, bazaar) {
|
|
2001
2098
|
const { offersFor, clock, logger, svm, near } = ctx;
|
|
2002
2099
|
async function verify(context) {
|
|
2003
2100
|
const { requirement, submission } = context;
|
|
@@ -2098,10 +2195,13 @@ function createVerify(ctx, nearRelayers) {
|
|
|
2098
2195
|
}
|
|
2099
2196
|
}
|
|
2100
2197
|
const relayers = offer.family === "near" ? nearRelayers(offer) : void 0;
|
|
2198
|
+
const issued = await bazaar.issuedFor(
|
|
2199
|
+
requirement.challenge.envelope
|
|
2200
|
+
);
|
|
2101
2201
|
const scope = offer.binding.open();
|
|
2102
2202
|
let sdkResult;
|
|
2103
2203
|
try {
|
|
2104
|
-
sdkResult = await scope.verify(forFacilitator(payload), requirements);
|
|
2204
|
+
sdkResult = await scope.verify(forFacilitator(payload, issued), requirements);
|
|
2105
2205
|
} catch (err) {
|
|
2106
2206
|
if (!isProviderUnavailableError(err) && !scope.transportFailed()) {
|
|
2107
2207
|
logger.warn({ err: redactedErrorText(err) }, "x402 verify(): unexpected SDK error");
|
|
@@ -2112,6 +2212,7 @@ function createVerify(ctx, nearRelayers) {
|
|
|
2112
2212
|
{ cause: err }
|
|
2113
2213
|
);
|
|
2114
2214
|
}
|
|
2215
|
+
bazaar.report(requirement.resourceId, sdkResult.extensionResponses);
|
|
2115
2216
|
if (!sdkResult.isValid) {
|
|
2116
2217
|
if (scope.transportFailed() || NO_VERDICT_REASONS.has(sdkResult.invalidReason ?? "")) {
|
|
2117
2218
|
if (sdkResult.invalidReason !== void 0) {
|
|
@@ -2224,15 +2325,12 @@ function createX402PaymentProvider(options) {
|
|
|
2224
2325
|
"authorization-flow",
|
|
2225
2326
|
"upfront-flow",
|
|
2226
2327
|
...severalOffers ? ["multiple-offers"] : [],
|
|
2227
|
-
...quotes ? ["erc-8409-quotes"] : []
|
|
2328
|
+
...quotes ? ["erc-8409-quotes"] : [],
|
|
2329
|
+
...options.resourceUrls !== void 0 ? ["public-resource-url"] : [],
|
|
2330
|
+
...options.resourceBazaar !== void 0 ? ["bazaar"] : []
|
|
2228
2331
|
],
|
|
2229
|
-
status:
|
|
2230
|
-
unsupported:
|
|
2231
|
-
"permit2 gas sponsoring extensions",
|
|
2232
|
-
"upto scheme",
|
|
2233
|
-
"batch-settlement scheme",
|
|
2234
|
-
"auth-capture scheme"
|
|
2235
|
-
]
|
|
2332
|
+
status: descriptorStatus(x402_default),
|
|
2333
|
+
unsupported: exclusionNames(x402_default)
|
|
2236
2334
|
};
|
|
2237
2335
|
const svmModule = hasSvm ? loadOptionalModule(() => import('./svm-NBZY7H6W.js'), "Solana offers need @x402/svm and @solana/kit") : void 0;
|
|
2238
2336
|
const nearModule = hasNear ? loadOptionalModule(() => import('./near-U6365VFX.js'), "NEAR offers need @x402/near") : void 0;
|
|
@@ -2265,8 +2363,9 @@ function createX402PaymentProvider(options) {
|
|
|
2265
2363
|
ctx,
|
|
2266
2364
|
createSvmFeePayerSource(supported)
|
|
2267
2365
|
);
|
|
2268
|
-
const
|
|
2269
|
-
const
|
|
2366
|
+
const bazaar = createBazaarForwarding(ctx, supported);
|
|
2367
|
+
const verify = createVerify(ctx, createNearRelayerSource(supported, logger), bazaar);
|
|
2368
|
+
const settle = createSettle(ctx, bazaar);
|
|
2270
2369
|
const health = createHealthCheck(ctx);
|
|
2271
2370
|
return {
|
|
2272
2371
|
name: "x402",
|
|
@@ -2300,5 +2399,5 @@ function loadOptionalModule(load, missing) {
|
|
|
2300
2399
|
}
|
|
2301
2400
|
|
|
2302
2401
|
export { DEFAULT_IDS, chainIdFromCaip2, createX402PaymentProvider, parseCanonicalAmount };
|
|
2303
|
-
//# sourceMappingURL=chunk-
|
|
2304
|
-
//# sourceMappingURL=chunk-
|
|
2402
|
+
//# sourceMappingURL=chunk-VWQMSWDF.js.map
|
|
2403
|
+
//# sourceMappingURL=chunk-VWQMSWDF.js.map
|