@agent-score/commerce 2.0.2 → 2.1.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 +26 -11
- package/dist/_core-kI7FRAiZ.d.mts +10 -0
- package/dist/_core-kI7FRAiZ.d.ts +10 -0
- package/dist/challenge/index.d.mts +3 -3
- package/dist/challenge/index.d.ts +3 -3
- package/dist/challenge/index.js +21 -14
- package/dist/challenge/index.js.map +1 -1
- package/dist/challenge/index.mjs +21 -14
- package/dist/challenge/index.mjs.map +1 -1
- package/dist/{checkout-DhSj_h94.d.ts → checkout-BH-I_Ns8.d.ts} +13 -12
- package/dist/{checkout-jNUIql6D.d.mts → checkout-Bd_4aQ6c.d.mts} +13 -12
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +1 -1
- package/dist/core.mjs.map +1 -1
- package/dist/default_rails-BWAquZeu.d.mts +188 -0
- package/dist/default_rails-BxBzcCA1.d.ts +188 -0
- package/dist/discovery/index.d.mts +5 -5
- package/dist/discovery/index.d.ts +5 -5
- package/dist/discovery/index.js +14 -1
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/index.mjs +14 -1
- package/dist/discovery/index.mjs.map +1 -1
- package/dist/identity/express.d.mts +7 -3
- package/dist/identity/express.d.ts +7 -3
- package/dist/identity/express.js +39 -96
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +37 -87
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.d.mts +4 -4
- package/dist/identity/fastify.d.ts +4 -4
- package/dist/identity/fastify.js +60 -96
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +58 -87
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.d.mts +11 -3
- package/dist/identity/hono.d.ts +11 -3
- package/dist/identity/hono.js +39 -93
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +37 -84
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.d.mts +10 -3
- package/dist/identity/nextjs.d.ts +10 -3
- package/dist/identity/nextjs.js +49 -93
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +46 -84
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/policy.js +185 -139
- package/dist/identity/policy.js.map +1 -1
- package/dist/identity/policy.mjs +187 -141
- package/dist/identity/policy.mjs.map +1 -1
- package/dist/identity/web.d.mts +9 -3
- package/dist/identity/web.d.ts +9 -3
- package/dist/identity/web.js +45 -93
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +42 -84
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +554 -90
- package/dist/index.d.ts +554 -90
- package/dist/index.js +916 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +904 -162
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/express.d.mts +10 -0
- package/dist/middleware/express.d.ts +10 -0
- package/dist/middleware/express.js +128 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/express.mjs +91 -0
- package/dist/middleware/express.mjs.map +1 -0
- package/dist/middleware/fastify.d.mts +10 -0
- package/dist/middleware/fastify.d.ts +10 -0
- package/dist/middleware/fastify.js +127 -0
- package/dist/middleware/fastify.js.map +1 -0
- package/dist/middleware/fastify.mjs +90 -0
- package/dist/middleware/fastify.mjs.map +1 -0
- package/dist/middleware/hono.d.mts +10 -0
- package/dist/middleware/hono.d.ts +10 -0
- package/dist/middleware/hono.js +122 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/hono.mjs +85 -0
- package/dist/middleware/hono.mjs.map +1 -0
- package/dist/middleware/nextjs.d.mts +22 -0
- package/dist/middleware/nextjs.d.ts +22 -0
- package/dist/middleware/nextjs.js +143 -0
- package/dist/middleware/nextjs.js.map +1 -0
- package/dist/middleware/nextjs.mjs +105 -0
- package/dist/middleware/nextjs.mjs.map +1 -0
- package/dist/middleware/web.d.mts +25 -0
- package/dist/middleware/web.d.ts +25 -0
- package/dist/middleware/web.js +128 -0
- package/dist/middleware/web.js.map +1 -0
- package/dist/middleware/web.mjs +91 -0
- package/dist/middleware/web.mjs.map +1 -0
- package/dist/payment/index.d.mts +21 -6
- package/dist/payment/index.d.ts +21 -6
- package/dist/payment/index.js +136 -9
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +127 -9
- package/dist/payment/index.mjs.map +1 -1
- package/dist/{pricing-CxzwyiO6.d.mts → pricing-4n5Ota0D.d.mts} +14 -4
- package/dist/{pricing-CQ9DIFaw.d.ts → pricing-DHfH3ogG.d.ts} +14 -4
- package/dist/{rail_spec-XP0wKgJV.d.mts → rail_spec-D6qzh3J0.d.mts} +1 -1
- package/dist/{rail_spec-XP0wKgJV.d.ts → rail_spec-D6qzh3J0.d.ts} +1 -1
- package/dist/stripe-multichain/index.d.mts +150 -47
- package/dist/stripe-multichain/index.d.ts +150 -47
- package/dist/stripe-multichain/index.js +19749 -42
- package/dist/stripe-multichain/index.js.map +1 -1
- package/dist/stripe-multichain/index.mjs +19758 -27
- package/dist/stripe-multichain/index.mjs.map +1 -1
- package/dist/{x402_server-hgQzWQwB.d.mts → x402_server-Ciz2mls2.d.mts} +1 -1
- package/dist/{x402_server-hgQzWQwB.d.ts → x402_server-Ciz2mls2.d.ts} +1 -1
- package/package.json +40 -2
- package/dist/_response-BFYN3b6i.d.mts +0 -142
- package/dist/_response-_iPD5AIj.d.ts +0 -142
- package/dist/solana-Cds87OTu.d.mts +0 -67
- package/dist/solana-Cds87OTu.d.ts +0 -67
package/dist/index.js
CHANGED
|
@@ -33,6 +33,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
));
|
|
34
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
35
|
|
|
36
|
+
// src/payment/network_kind.ts
|
|
37
|
+
function readNetwork(input) {
|
|
38
|
+
if (typeof input === "string") return input;
|
|
39
|
+
if (input && typeof input === "object") {
|
|
40
|
+
const network = input.network;
|
|
41
|
+
return typeof network === "string" ? network : "";
|
|
42
|
+
}
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
function isEvmNetwork(input) {
|
|
46
|
+
return readNetwork(input).startsWith("eip155:");
|
|
47
|
+
}
|
|
48
|
+
function isSolanaNetwork(input) {
|
|
49
|
+
return readNetwork(input).startsWith("solana:");
|
|
50
|
+
}
|
|
51
|
+
var init_network_kind = __esm({
|
|
52
|
+
"src/payment/network_kind.ts"() {
|
|
53
|
+
"use strict";
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
36
57
|
// src/identity/ucp.ts
|
|
37
58
|
function ucpSigningKeyFromJWKImpl(jwk) {
|
|
38
59
|
if (!jwk || typeof jwk !== "object") {
|
|
@@ -162,7 +183,7 @@ function isTempoSessionRailSpec(s) {
|
|
|
162
183
|
}
|
|
163
184
|
function mppRailToNetworkEntry(spec) {
|
|
164
185
|
if (isTempoSessionRailSpec(spec)) return tempoSessionToNetworkEntry(spec);
|
|
165
|
-
if ("rpcUrl" in spec || "tokenProgram" in spec || (spec
|
|
186
|
+
if ("rpcUrl" in spec || "tokenProgram" in spec || isSolanaNetwork(spec)) {
|
|
166
187
|
return solanaMppToNetworkEntry(spec);
|
|
167
188
|
}
|
|
168
189
|
if (isTempoRailSpec(spec)) return tempoToNetworkEntry(spec);
|
|
@@ -219,6 +240,7 @@ var UCPSigningKey, DEFAULT_VERSION, AGENTSCORE_CAPABILITY_NAME, AGENTSCORE_CAPAB
|
|
|
219
240
|
var init_ucp = __esm({
|
|
220
241
|
"src/identity/ucp.ts"() {
|
|
221
242
|
"use strict";
|
|
243
|
+
init_network_kind();
|
|
222
244
|
UCPSigningKey = {
|
|
223
245
|
fromJWK: ucpSigningKeyFromJWKImpl
|
|
224
246
|
};
|
|
@@ -638,64 +660,6 @@ var init_ucp_jwks = __esm({
|
|
|
638
660
|
}
|
|
639
661
|
});
|
|
640
662
|
|
|
641
|
-
// src/payment/usdc.ts
|
|
642
|
-
var USDC;
|
|
643
|
-
var init_usdc = __esm({
|
|
644
|
-
"src/payment/usdc.ts"() {
|
|
645
|
-
"use strict";
|
|
646
|
-
USDC = {
|
|
647
|
-
base: {
|
|
648
|
-
mainnet: { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", decimals: 6 },
|
|
649
|
-
sepolia: { address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", decimals: 6 }
|
|
650
|
-
},
|
|
651
|
-
solana: {
|
|
652
|
-
mainnet: { mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", decimals: 6 },
|
|
653
|
-
devnet: { mint: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU", decimals: 6 }
|
|
654
|
-
},
|
|
655
|
-
tempo: {
|
|
656
|
-
mainnet: { address: "0x20C000000000000000000000b9537d11c60E8b50", decimals: 6 },
|
|
657
|
-
testnet: { address: "0x20c0000000000000000000000000000000000000", decimals: 6 }
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
// src/payment/wwwauthenticate.ts
|
|
664
|
-
function paymentRequiredHeader({
|
|
665
|
-
x402Version,
|
|
666
|
-
accepts,
|
|
667
|
-
resource
|
|
668
|
-
}) {
|
|
669
|
-
return Buffer.from(JSON.stringify({ x402Version, accepts, ...resource ? { resource } : {} })).toString("base64");
|
|
670
|
-
}
|
|
671
|
-
var init_wwwauthenticate = __esm({
|
|
672
|
-
"src/payment/wwwauthenticate.ts"() {
|
|
673
|
-
"use strict";
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// src/payment/networks.ts
|
|
678
|
-
var networks;
|
|
679
|
-
var init_networks = __esm({
|
|
680
|
-
"src/payment/networks.ts"() {
|
|
681
|
-
"use strict";
|
|
682
|
-
networks = {
|
|
683
|
-
base: {
|
|
684
|
-
mainnet: { caip2: "eip155:8453", chainId: 8453 },
|
|
685
|
-
sepolia: { caip2: "eip155:84532", chainId: 84532 }
|
|
686
|
-
},
|
|
687
|
-
solana: {
|
|
688
|
-
mainnet: { caip2: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" },
|
|
689
|
-
devnet: { caip2: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1" }
|
|
690
|
-
},
|
|
691
|
-
tempo: {
|
|
692
|
-
mainnet: { caip2: "eip155:4217", chainId: 4217 },
|
|
693
|
-
testnet: { caip2: "eip155:42431", chainId: 42431 }
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
|
|
699
663
|
// node_modules/ox/_esm/core/Abi.js
|
|
700
664
|
var init_Abi = __esm({
|
|
701
665
|
"node_modules/ox/_esm/core/Abi.js"() {
|
|
@@ -20307,6 +20271,64 @@ var init_dist2 = __esm({
|
|
|
20307
20271
|
}
|
|
20308
20272
|
});
|
|
20309
20273
|
|
|
20274
|
+
// src/payment/usdc.ts
|
|
20275
|
+
var USDC;
|
|
20276
|
+
var init_usdc = __esm({
|
|
20277
|
+
"src/payment/usdc.ts"() {
|
|
20278
|
+
"use strict";
|
|
20279
|
+
USDC = {
|
|
20280
|
+
base: {
|
|
20281
|
+
mainnet: { address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", decimals: 6 },
|
|
20282
|
+
sepolia: { address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", decimals: 6 }
|
|
20283
|
+
},
|
|
20284
|
+
solana: {
|
|
20285
|
+
mainnet: { mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", decimals: 6 },
|
|
20286
|
+
devnet: { mint: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU", decimals: 6 }
|
|
20287
|
+
},
|
|
20288
|
+
tempo: {
|
|
20289
|
+
mainnet: { address: "0x20C000000000000000000000b9537d11c60E8b50", decimals: 6 },
|
|
20290
|
+
testnet: { address: "0x20c0000000000000000000000000000000000000", decimals: 6 }
|
|
20291
|
+
}
|
|
20292
|
+
};
|
|
20293
|
+
}
|
|
20294
|
+
});
|
|
20295
|
+
|
|
20296
|
+
// src/payment/wwwauthenticate.ts
|
|
20297
|
+
function paymentRequiredHeader({
|
|
20298
|
+
x402Version,
|
|
20299
|
+
accepts,
|
|
20300
|
+
resource
|
|
20301
|
+
}) {
|
|
20302
|
+
return Buffer.from(JSON.stringify({ x402Version, accepts, ...resource ? { resource } : {} })).toString("base64");
|
|
20303
|
+
}
|
|
20304
|
+
var init_wwwauthenticate = __esm({
|
|
20305
|
+
"src/payment/wwwauthenticate.ts"() {
|
|
20306
|
+
"use strict";
|
|
20307
|
+
}
|
|
20308
|
+
});
|
|
20309
|
+
|
|
20310
|
+
// src/payment/networks.ts
|
|
20311
|
+
var networks;
|
|
20312
|
+
var init_networks = __esm({
|
|
20313
|
+
"src/payment/networks.ts"() {
|
|
20314
|
+
"use strict";
|
|
20315
|
+
networks = {
|
|
20316
|
+
base: {
|
|
20317
|
+
mainnet: { caip2: "eip155:8453", chainId: 8453 },
|
|
20318
|
+
sepolia: { caip2: "eip155:84532", chainId: 84532 }
|
|
20319
|
+
},
|
|
20320
|
+
solana: {
|
|
20321
|
+
mainnet: { caip2: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" },
|
|
20322
|
+
devnet: { caip2: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1" }
|
|
20323
|
+
},
|
|
20324
|
+
tempo: {
|
|
20325
|
+
mainnet: { caip2: "eip155:4217", chainId: 4217 },
|
|
20326
|
+
testnet: { caip2: "eip155:42431", chainId: 42431 }
|
|
20327
|
+
}
|
|
20328
|
+
};
|
|
20329
|
+
}
|
|
20330
|
+
});
|
|
20331
|
+
|
|
20310
20332
|
// src/payment/rails.ts
|
|
20311
20333
|
function lookupRail(name) {
|
|
20312
20334
|
return rails[name];
|
|
@@ -20785,6 +20807,8 @@ var init_well_known = __esm({
|
|
|
20785
20807
|
// src/index.ts
|
|
20786
20808
|
var index_exports = {};
|
|
20787
20809
|
__export(index_exports, {
|
|
20810
|
+
A2A_DEFAULT_TRANSPORT: () => A2A_DEFAULT_TRANSPORT,
|
|
20811
|
+
A2A_PROTOCOL_VERSION: () => A2A_PROTOCOL_VERSION,
|
|
20788
20812
|
AGENTSCORE_UCP_CAPABILITY: () => AGENTSCORE_UCP_CAPABILITY,
|
|
20789
20813
|
Checkout: () => Checkout,
|
|
20790
20814
|
CheckoutValidationError: () => CheckoutValidationError,
|
|
@@ -20795,18 +20819,28 @@ __export(index_exports, {
|
|
|
20795
20819
|
buildA2AAgentCard: () => buildA2AAgentCard,
|
|
20796
20820
|
buildAgentMemoryHint: () => buildAgentMemoryHint,
|
|
20797
20821
|
buildContactSupportNextSteps: () => buildContactSupportNextSteps,
|
|
20822
|
+
buildDefaultCheckoutRails: () => buildDefaultCheckoutRails,
|
|
20798
20823
|
buildGateFromPolicy: () => buildGateFromPolicy,
|
|
20799
20824
|
buildJWKSResponse: () => buildJWKSResponse,
|
|
20825
|
+
buildMppxComposeRails: () => buildMppxComposeRails,
|
|
20800
20826
|
buildSignerMismatchBody: () => buildSignerMismatchBody,
|
|
20801
20827
|
buildUCPProfile: () => buildUCPProfile,
|
|
20828
|
+
computeFirstCheckout: () => computeFirstCheckout,
|
|
20829
|
+
createDefaultOnDenied: () => createDefaultOnDenied,
|
|
20830
|
+
createQuoteCache: () => createQuoteCache,
|
|
20831
|
+
defaultReadOnlyOnDenied: () => defaultReadOnlyOnDenied,
|
|
20802
20832
|
denialReasonStatus: () => denialReasonStatus,
|
|
20803
20833
|
denialReasonToBody: () => denialReasonToBody,
|
|
20834
|
+
extractOwnerScope: () => extractOwnerScope,
|
|
20804
20835
|
extractPaymentSigner: () => extractPaymentSigner,
|
|
20805
20836
|
extractPaymentSignerFromAuth: () => extractPaymentSignerFromAuth,
|
|
20806
20837
|
extractSignerForPrecheck: () => extractSignerForPrecheck,
|
|
20807
20838
|
formatUsdCents: () => formatUsdCents,
|
|
20808
20839
|
generateUCPSigningKey: () => generateUCPSigningKey,
|
|
20809
20840
|
getIdentityStatus: () => getIdentityStatus,
|
|
20841
|
+
hasMppxHeader: () => hasMppxHeader,
|
|
20842
|
+
hasPaymentHeader: () => hasPaymentHeader,
|
|
20843
|
+
hasX402Header: () => hasX402Header,
|
|
20810
20844
|
hashOperatorToken: () => hashOperatorToken,
|
|
20811
20845
|
isFixableDenial: () => isFixableDenial,
|
|
20812
20846
|
loadSolanaFeePayer: () => loadSolanaFeePayer,
|
|
@@ -21172,7 +21206,7 @@ function createAgentScoreCore(options) {
|
|
|
21172
21206
|
} = options;
|
|
21173
21207
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
21174
21208
|
const agentMemoryHint = buildAgentMemoryHint();
|
|
21175
|
-
const defaultUa = `@agent-score/commerce@${"2.0
|
|
21209
|
+
const defaultUa = `@agent-score/commerce@${"2.1.0"}`;
|
|
21176
21210
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
21177
21211
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
21178
21212
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -21464,6 +21498,13 @@ function createAgentScoreCore(options) {
|
|
|
21464
21498
|
return { evaluate, captureWallet, getSignerVerdict };
|
|
21465
21499
|
}
|
|
21466
21500
|
|
|
21501
|
+
// src/_headers.ts
|
|
21502
|
+
function normalizeHeadersToLowercase(headers) {
|
|
21503
|
+
const out = {};
|
|
21504
|
+
for (const [k, v] of Object.entries(headers)) out[k.toLowerCase()] = v;
|
|
21505
|
+
return out;
|
|
21506
|
+
}
|
|
21507
|
+
|
|
21467
21508
|
// src/signer.ts
|
|
21468
21509
|
var TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
21469
21510
|
var TOKEN_2022_PROGRAM = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
@@ -21546,13 +21587,8 @@ async function extractPaymentSignerFromAuth(authHeader, x402PaymentHeader) {
|
|
|
21546
21587
|
function readX402PaymentHeader(request) {
|
|
21547
21588
|
return request.headers.get("payment-signature") ?? request.headers.get("x-payment") ?? void 0;
|
|
21548
21589
|
}
|
|
21549
|
-
function lowerHeaders(headers) {
|
|
21550
|
-
const out = {};
|
|
21551
|
-
for (const [k, v] of Object.entries(headers)) out[k.toLowerCase()] = v;
|
|
21552
|
-
return out;
|
|
21553
|
-
}
|
|
21554
21590
|
async function extractSignerForPrecheck(headers) {
|
|
21555
|
-
const lower =
|
|
21591
|
+
const lower = normalizeHeadersToLowercase(headers);
|
|
21556
21592
|
const x402 = lower["payment-signature"] ?? lower["x-payment"];
|
|
21557
21593
|
if (x402) {
|
|
21558
21594
|
const signer = await extractPaymentSignerFromAuth(void 0, x402);
|
|
@@ -21567,7 +21603,7 @@ async function extractSignerForPrecheck(headers) {
|
|
|
21567
21603
|
|
|
21568
21604
|
// src/identity/a2a.ts
|
|
21569
21605
|
var PROTOCOL_VERSION = "1.0";
|
|
21570
|
-
var
|
|
21606
|
+
var DEFAULT_TRANSPORT = "JSONRPC";
|
|
21571
21607
|
var DEFAULT_INPUT_MODE = "application/json";
|
|
21572
21608
|
var DEFAULT_OUTPUT_MODE = "application/json";
|
|
21573
21609
|
var UCP_A2A_EXTENSION_URI = "https://ucp.dev/2026-04-08/specification/reference";
|
|
@@ -21587,30 +21623,33 @@ function buildA2AAgentCard(input) {
|
|
|
21587
21623
|
}
|
|
21588
21624
|
const capabilities = {};
|
|
21589
21625
|
if (input.streaming !== void 0) capabilities.streaming = input.streaming;
|
|
21590
|
-
if (input.
|
|
21626
|
+
if (input.pushNotifications !== void 0) capabilities.pushNotifications = input.pushNotifications;
|
|
21627
|
+
if (input.stateTransitionHistory !== void 0) capabilities.stateTransitionHistory = input.stateTransitionHistory;
|
|
21591
21628
|
if (input.extensions && input.extensions.length > 0) capabilities.extensions = input.extensions;
|
|
21592
|
-
if (input.extended_agent_card !== void 0) capabilities.extended_agent_card = input.extended_agent_card;
|
|
21593
|
-
const primaryInterface = {
|
|
21594
|
-
url: input.url,
|
|
21595
|
-
protocol_binding: input.protocol_binding ?? DEFAULT_PROTOCOL_BINDING,
|
|
21596
|
-
protocol_version: input.a2a_protocol_version ?? PROTOCOL_VERSION
|
|
21597
|
-
};
|
|
21598
21629
|
const card = {
|
|
21599
21630
|
name: input.name,
|
|
21600
21631
|
description: input.description,
|
|
21601
|
-
|
|
21632
|
+
url: input.url,
|
|
21633
|
+
preferredTransport: input.preferredTransport ?? "HTTP+JSON",
|
|
21634
|
+
protocolVersion: input.protocolVersion ?? PROTOCOL_VERSION,
|
|
21602
21635
|
version: input.version ?? "1.0.0",
|
|
21603
21636
|
capabilities,
|
|
21604
|
-
|
|
21605
|
-
|
|
21637
|
+
defaultInputModes: input.defaultInputModes ?? [DEFAULT_INPUT_MODE],
|
|
21638
|
+
defaultOutputModes: input.defaultOutputModes ?? [DEFAULT_OUTPUT_MODE],
|
|
21606
21639
|
skills: input.skills
|
|
21607
21640
|
};
|
|
21641
|
+
if (input.additionalInterfaces !== void 0 && input.additionalInterfaces.length > 0) {
|
|
21642
|
+
card.additionalInterfaces = input.additionalInterfaces;
|
|
21643
|
+
}
|
|
21608
21644
|
if (input.provider !== void 0) card.provider = input.provider;
|
|
21609
|
-
if (input.
|
|
21610
|
-
if (input.
|
|
21645
|
+
if (input.documentationUrl !== void 0) card.documentationUrl = input.documentationUrl;
|
|
21646
|
+
if (input.iconUrl !== void 0) card.iconUrl = input.iconUrl;
|
|
21647
|
+
if (input.supportsAuthenticatedExtendedCard !== void 0) {
|
|
21648
|
+
card.supportsAuthenticatedExtendedCard = input.supportsAuthenticatedExtendedCard;
|
|
21649
|
+
}
|
|
21611
21650
|
if (input.signatures !== void 0 && input.signatures.length > 0) card.signatures = input.signatures;
|
|
21612
|
-
if (input.
|
|
21613
|
-
if (input.
|
|
21651
|
+
if (input.security !== void 0) card.security = input.security;
|
|
21652
|
+
if (input.securitySchemes !== void 0) card.securitySchemes = input.securitySchemes;
|
|
21614
21653
|
if (input.extras) {
|
|
21615
21654
|
for (const [k, v] of Object.entries(input.extras)) {
|
|
21616
21655
|
card[k] = v;
|
|
@@ -21618,6 +21657,8 @@ function buildA2AAgentCard(input) {
|
|
|
21618
21657
|
}
|
|
21619
21658
|
return card;
|
|
21620
21659
|
}
|
|
21660
|
+
var A2A_PROTOCOL_VERSION = PROTOCOL_VERSION;
|
|
21661
|
+
var A2A_DEFAULT_TRANSPORT = DEFAULT_TRANSPORT;
|
|
21621
21662
|
|
|
21622
21663
|
// src/index.ts
|
|
21623
21664
|
init_ucp();
|
|
@@ -21626,6 +21667,34 @@ init_ucp_jwks();
|
|
|
21626
21667
|
// src/checkout.ts
|
|
21627
21668
|
var import_node_crypto = require("crypto");
|
|
21628
21669
|
|
|
21670
|
+
// src/_mppx_receipt.ts
|
|
21671
|
+
function extractMppxReceiptHeaderFromRaw(raw) {
|
|
21672
|
+
if (!raw || typeof raw !== "object" || !("withReceipt" in raw)) return null;
|
|
21673
|
+
const fn = raw.withReceipt;
|
|
21674
|
+
if (typeof fn !== "function") return null;
|
|
21675
|
+
try {
|
|
21676
|
+
const wrapped = fn.call(raw, new Response());
|
|
21677
|
+
return wrapped.headers.get("Payment-Receipt");
|
|
21678
|
+
} catch {
|
|
21679
|
+
return null;
|
|
21680
|
+
}
|
|
21681
|
+
}
|
|
21682
|
+
async function extractMppxReceiptMethod(header) {
|
|
21683
|
+
try {
|
|
21684
|
+
const { Receipt } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
21685
|
+
return Receipt.deserialize(header).method;
|
|
21686
|
+
} catch {
|
|
21687
|
+
return void 0;
|
|
21688
|
+
}
|
|
21689
|
+
}
|
|
21690
|
+
async function deriveMppxReceiptMethod(raw) {
|
|
21691
|
+
const direct = raw?.receipt?.method;
|
|
21692
|
+
if (direct) return direct;
|
|
21693
|
+
const header = extractMppxReceiptHeaderFromRaw(raw);
|
|
21694
|
+
if (!header) return void 0;
|
|
21695
|
+
return extractMppxReceiptMethod(header);
|
|
21696
|
+
}
|
|
21697
|
+
|
|
21629
21698
|
// src/payment/rail_spec.ts
|
|
21630
21699
|
init_usdc();
|
|
21631
21700
|
async function resolveRecipient(r) {
|
|
@@ -21850,10 +21919,13 @@ function buildHowToPay({
|
|
|
21850
21919
|
totalUsd,
|
|
21851
21920
|
rails: rails2,
|
|
21852
21921
|
opTokenPlaceholder,
|
|
21853
|
-
maxSpend
|
|
21922
|
+
maxSpend,
|
|
21923
|
+
decimals
|
|
21854
21924
|
}) {
|
|
21855
21925
|
const totalNum = typeof totalUsd === "string" ? Number(totalUsd) : totalUsd;
|
|
21856
|
-
const
|
|
21926
|
+
const d = decimals ?? 2;
|
|
21927
|
+
const defaultMaxSpend = totalNum >= 1 ? (Math.ceil(totalNum) + 1).toFixed(d) : totalNum.toFixed(d);
|
|
21928
|
+
const maxSpendStr = String(maxSpend ?? defaultMaxSpend);
|
|
21857
21929
|
const opToken = opTokenPlaceholder ?? "<your_opc_token>";
|
|
21858
21930
|
const block = {};
|
|
21859
21931
|
if (rails2.tempo) {
|
|
@@ -21946,26 +22018,26 @@ function buildPricingBlock({
|
|
|
21946
22018
|
totalCents,
|
|
21947
22019
|
taxRate,
|
|
21948
22020
|
taxState,
|
|
21949
|
-
currency
|
|
22021
|
+
currency,
|
|
22022
|
+
decimals
|
|
21950
22023
|
}) {
|
|
21951
22024
|
const shipping = shippingCents ?? 0;
|
|
21952
22025
|
const discount = discountCents ?? 0;
|
|
21953
22026
|
const total = totalCents ?? Math.max(0, subtotalCents + taxCents + shipping - discount);
|
|
22027
|
+
const d = decimals ?? 2;
|
|
22028
|
+
const fmt = (cents) => (cents / 100).toFixed(d);
|
|
21954
22029
|
const block = {
|
|
21955
|
-
subtotal:
|
|
21956
|
-
tax:
|
|
21957
|
-
total:
|
|
22030
|
+
subtotal: fmt(subtotalCents),
|
|
22031
|
+
tax: fmt(taxCents),
|
|
22032
|
+
total: fmt(total)
|
|
21958
22033
|
};
|
|
21959
|
-
if (shippingCents !== void 0) block.shipping =
|
|
21960
|
-
if (discountCents !== void 0) block.discount =
|
|
22034
|
+
if (shippingCents !== void 0) block.shipping = fmt(shipping);
|
|
22035
|
+
if (discountCents !== void 0) block.discount = fmt(discount);
|
|
21961
22036
|
if (taxRate !== void 0) block.tax_rate = taxRate;
|
|
21962
22037
|
if (taxState !== void 0) block.tax_state = taxState;
|
|
21963
22038
|
if (currency !== void 0) block.currency = currency;
|
|
21964
22039
|
return block;
|
|
21965
22040
|
}
|
|
21966
|
-
function formatCents(cents) {
|
|
21967
|
-
return (cents / 100).toFixed(2);
|
|
21968
|
-
}
|
|
21969
22041
|
|
|
21970
22042
|
// src/challenge/respond_402.ts
|
|
21971
22043
|
init_wwwauthenticate();
|
|
@@ -21974,10 +22046,7 @@ function respond402({
|
|
|
21974
22046
|
body,
|
|
21975
22047
|
x402
|
|
21976
22048
|
}) {
|
|
21977
|
-
const headers =
|
|
21978
|
-
for (const [k, v] of Object.entries(mppxChallengeHeaders)) {
|
|
21979
|
-
headers[k.toLowerCase()] = v;
|
|
21980
|
-
}
|
|
22049
|
+
const headers = normalizeHeadersToLowercase(mppxChallengeHeaders);
|
|
21981
22050
|
headers["content-type"] = "application/json";
|
|
21982
22051
|
if (x402) {
|
|
21983
22052
|
headers["payment-required"] = paymentRequiredHeader(x402);
|
|
@@ -22040,7 +22109,8 @@ function isSolanaMppRailSpec(s) {
|
|
|
22040
22109
|
return s.network?.startsWith("solana:") ?? false;
|
|
22041
22110
|
}
|
|
22042
22111
|
function solanaNetworkFromCAIP2(caip2) {
|
|
22043
|
-
if (caip2 === networks.solana.devnet.caip2) return "devnet";
|
|
22112
|
+
if (caip2 === "devnet" || caip2 === networks.solana.devnet.caip2) return "devnet";
|
|
22113
|
+
if (caip2 === "localnet") return "localnet";
|
|
22044
22114
|
return "mainnet-beta";
|
|
22045
22115
|
}
|
|
22046
22116
|
function solanaDefaultRpcUrl(network) {
|
|
@@ -22324,6 +22394,41 @@ function lazyMppxServer(opts) {
|
|
|
22324
22394
|
};
|
|
22325
22395
|
}
|
|
22326
22396
|
|
|
22397
|
+
// src/checkout.ts
|
|
22398
|
+
init_network_kind();
|
|
22399
|
+
|
|
22400
|
+
// src/payment/payment_header.ts
|
|
22401
|
+
function toTitleCase(name) {
|
|
22402
|
+
return name.replace(/(^|-)([a-z])/g, (_m, sep, c) => sep + c.toUpperCase());
|
|
22403
|
+
}
|
|
22404
|
+
function readHeader(headers, name) {
|
|
22405
|
+
if (typeof headers.get === "function") {
|
|
22406
|
+
return headers.get(name);
|
|
22407
|
+
}
|
|
22408
|
+
const rec = headers;
|
|
22409
|
+
const v = rec[name] ?? rec[name.toLowerCase()] ?? rec[toTitleCase(name)];
|
|
22410
|
+
if (typeof v === "string") return v;
|
|
22411
|
+
if (Array.isArray(v) && typeof v[0] === "string") return v[0];
|
|
22412
|
+
return null;
|
|
22413
|
+
}
|
|
22414
|
+
function asHeaders(input) {
|
|
22415
|
+
return typeof input.headers === "object" && input instanceof Request ? input.headers : input;
|
|
22416
|
+
}
|
|
22417
|
+
function hasPaymentHeader(input) {
|
|
22418
|
+
const headers = asHeaders(input);
|
|
22419
|
+
return Boolean(
|
|
22420
|
+
readHeader(headers, "payment-signature") || readHeader(headers, "x-payment") || readHeader(headers, "authorization")?.startsWith("Payment ")
|
|
22421
|
+
);
|
|
22422
|
+
}
|
|
22423
|
+
function hasX402Header(input) {
|
|
22424
|
+
const headers = asHeaders(input);
|
|
22425
|
+
return Boolean(readHeader(headers, "payment-signature") || readHeader(headers, "x-payment"));
|
|
22426
|
+
}
|
|
22427
|
+
function hasMppxHeader(input) {
|
|
22428
|
+
const headers = asHeaders(input);
|
|
22429
|
+
return Boolean(readHeader(headers, "authorization")?.startsWith("Payment "));
|
|
22430
|
+
}
|
|
22431
|
+
|
|
22327
22432
|
// src/payment/x402_settle.ts
|
|
22328
22433
|
function classifyX402SettleResult(result) {
|
|
22329
22434
|
if (result.success) return null;
|
|
@@ -22615,12 +22720,14 @@ function pricingResult(opts) {
|
|
|
22615
22720
|
...opts.discountCents !== void 0 && { discountCents: opts.discountCents },
|
|
22616
22721
|
...opts.taxRate !== void 0 && { taxRate: opts.taxRate },
|
|
22617
22722
|
...opts.taxState !== void 0 && { taxState: opts.taxState },
|
|
22618
|
-
currency
|
|
22723
|
+
currency,
|
|
22724
|
+
...opts.decimals !== void 0 && { decimals: opts.decimals }
|
|
22619
22725
|
});
|
|
22620
22726
|
return {
|
|
22621
22727
|
amountUsd: derivedAmount,
|
|
22622
22728
|
currency,
|
|
22623
22729
|
block,
|
|
22730
|
+
...opts.decimals !== void 0 && { decimals: opts.decimals },
|
|
22624
22731
|
...opts.product !== void 0 && { product: opts.product },
|
|
22625
22732
|
...opts.bodyExtras !== void 0 && { bodyExtras: opts.bodyExtras }
|
|
22626
22733
|
};
|
|
@@ -22631,6 +22738,7 @@ function pricingResult(opts) {
|
|
|
22631
22738
|
return {
|
|
22632
22739
|
amountUsd: opts.amountUsd,
|
|
22633
22740
|
currency,
|
|
22741
|
+
...opts.decimals !== void 0 && { decimals: opts.decimals },
|
|
22634
22742
|
...opts.product !== void 0 && { product: opts.product },
|
|
22635
22743
|
...opts.bodyExtras !== void 0 && { bodyExtras: opts.bodyExtras }
|
|
22636
22744
|
};
|
|
@@ -22656,21 +22764,8 @@ var CheckoutValidationError = class extends Error {
|
|
|
22656
22764
|
this.extra = opts.extra;
|
|
22657
22765
|
}
|
|
22658
22766
|
};
|
|
22659
|
-
function lowerHeaders2(headers) {
|
|
22660
|
-
const out = {};
|
|
22661
|
-
for (const [k, v] of Object.entries(headers)) out[k.toLowerCase()] = v;
|
|
22662
|
-
return out;
|
|
22663
|
-
}
|
|
22664
|
-
function hasX402Header(headers) {
|
|
22665
|
-
const h = lowerHeaders2(headers);
|
|
22666
|
-
return Boolean(h["payment-signature"] ?? h["x-payment"]);
|
|
22667
|
-
}
|
|
22668
|
-
function hasMppxHeader(headers) {
|
|
22669
|
-
const h = lowerHeaders2(headers);
|
|
22670
|
-
return (h["authorization"] ?? "").startsWith("Payment ");
|
|
22671
|
-
}
|
|
22672
22767
|
function resolveIdentityMetadata(ctx) {
|
|
22673
|
-
const h =
|
|
22768
|
+
const h = normalizeHeadersToLowercase(ctx.request.headers);
|
|
22674
22769
|
const wallet = h["x-wallet-address"];
|
|
22675
22770
|
if (!wallet) return void 0;
|
|
22676
22771
|
let linkedWallets;
|
|
@@ -22699,26 +22794,24 @@ function isTempoSessionRailSpec3(s) {
|
|
|
22699
22794
|
function specRailKey(spec) {
|
|
22700
22795
|
if (isStripeRailSpec2(spec)) return "stripe";
|
|
22701
22796
|
if (isTempoSessionRailSpec3(spec)) return "tempo_mpp";
|
|
22702
|
-
|
|
22703
|
-
if (
|
|
22704
|
-
if (network.startsWith("solana:") || "rpcUrl" in spec) return "solana_mpp";
|
|
22797
|
+
if (isEvmNetwork(spec)) return "x402_base";
|
|
22798
|
+
if (isSolanaNetwork(spec) || "rpcUrl" in spec) return "solana_mpp";
|
|
22705
22799
|
return "tempo_mpp";
|
|
22706
22800
|
}
|
|
22707
22801
|
function specMethodName(spec) {
|
|
22708
22802
|
if (isStripeRailSpec2(spec)) return "stripe/spt";
|
|
22709
22803
|
if (isTempoSessionRailSpec3(spec)) return "tempo/charge";
|
|
22710
|
-
|
|
22711
|
-
if (
|
|
22712
|
-
if (network.startsWith("solana:") || "rpcUrl" in spec) return "solana/charge";
|
|
22804
|
+
if (isEvmNetwork(spec)) return "x402/exact (base)";
|
|
22805
|
+
if (isSolanaNetwork(spec) || "rpcUrl" in spec) return "solana/charge";
|
|
22713
22806
|
return "tempo/charge";
|
|
22714
22807
|
}
|
|
22715
22808
|
function makeMppxComposeHook(opts) {
|
|
22716
22809
|
return async (ctx) => {
|
|
22717
22810
|
if (ctx.pricing === null) return { status: 402 };
|
|
22718
22811
|
const mpp = await opts.serverGetter();
|
|
22719
|
-
const lower =
|
|
22812
|
+
const lower = normalizeHeadersToLowercase(ctx.request.headers);
|
|
22720
22813
|
const authorization = lower["authorization"];
|
|
22721
|
-
const amountStr = ctx.pricing.amountUsd.toFixed(2);
|
|
22814
|
+
const amountStr = ctx.pricing.amountUsd.toFixed(ctx.pricing.decimals ?? 2);
|
|
22722
22815
|
let result;
|
|
22723
22816
|
try {
|
|
22724
22817
|
result = await mpp.charge({ authorization, amount: amountStr });
|
|
@@ -22802,7 +22895,7 @@ var Checkout = class {
|
|
|
22802
22895
|
let x402ServerGetter;
|
|
22803
22896
|
if (x402Server === void 0) {
|
|
22804
22897
|
const baseSpec = Object.values(opts.rails).find(
|
|
22805
|
-
(s) => !isTempoSessionRailSpec3(s) && !isStripeRailSpec2(s) && "recipient" in s && (s
|
|
22898
|
+
(s) => !isTempoSessionRailSpec3(s) && !isStripeRailSpec2(s) && "recipient" in s && isEvmNetwork(s)
|
|
22806
22899
|
);
|
|
22807
22900
|
if (baseSpec !== void 0) {
|
|
22808
22901
|
x402ServerGetter = lazyX402Server({
|
|
@@ -22892,7 +22985,7 @@ var Checkout = class {
|
|
|
22892
22985
|
* `"x402_base"` when no match found. */
|
|
22893
22986
|
x402RailKey() {
|
|
22894
22987
|
for (const [k, v] of Object.entries(this.rails)) {
|
|
22895
|
-
if (!isStripeRailSpec2(v) && !isTempoSessionRailSpec3(v) && (v
|
|
22988
|
+
if (!isStripeRailSpec2(v) && !isTempoSessionRailSpec3(v) && isEvmNetwork(v)) {
|
|
22896
22989
|
return k;
|
|
22897
22990
|
}
|
|
22898
22991
|
}
|
|
@@ -22901,8 +22994,7 @@ var Checkout = class {
|
|
|
22901
22994
|
/** Return the rails-dict key for the primary MPP rail. */
|
|
22902
22995
|
mppRailKey() {
|
|
22903
22996
|
for (const [k, v] of Object.entries(this.rails)) {
|
|
22904
|
-
|
|
22905
|
-
if (!isStripeRailSpec2(v) && !network.startsWith("eip155:")) return k;
|
|
22997
|
+
if (!isStripeRailSpec2(v) && !isEvmNetwork(v)) return k;
|
|
22906
22998
|
}
|
|
22907
22999
|
return "tempo";
|
|
22908
23000
|
}
|
|
@@ -22921,17 +23013,15 @@ var Checkout = class {
|
|
|
22921
23013
|
if (method === "solana") {
|
|
22922
23014
|
for (const [k, v] of Object.entries(this.rails)) {
|
|
22923
23015
|
if (isStripeRailSpec2(v) || isTempoSessionRailSpec3(v)) continue;
|
|
22924
|
-
|
|
22925
|
-
if (network.startsWith("solana:") || "rpcUrl" in v || "tokenProgram" in v) return k;
|
|
23016
|
+
if (isSolanaNetwork(v) || "rpcUrl" in v || "tokenProgram" in v) return k;
|
|
22926
23017
|
}
|
|
22927
23018
|
return void 0;
|
|
22928
23019
|
}
|
|
22929
23020
|
if (method === "tempo") {
|
|
22930
23021
|
for (const [k, v] of Object.entries(this.rails)) {
|
|
22931
23022
|
if (isStripeRailSpec2(v)) continue;
|
|
22932
|
-
|
|
22933
|
-
if (
|
|
22934
|
-
if (network.startsWith("eip155:")) continue;
|
|
23023
|
+
if (isSolanaNetwork(v) || "rpcUrl" in v || "tokenProgram" in v) continue;
|
|
23024
|
+
if (isEvmNetwork(v)) continue;
|
|
22935
23025
|
return k;
|
|
22936
23026
|
}
|
|
22937
23027
|
return void 0;
|
|
@@ -22944,7 +23034,7 @@ var Checkout = class {
|
|
|
22944
23034
|
get x402BaseNetwork() {
|
|
22945
23035
|
if (!this.x402ServerAvailable()) return null;
|
|
22946
23036
|
for (const spec of Object.values(this.rails)) {
|
|
22947
|
-
if (!isStripeRailSpec2(spec) && !isTempoSessionRailSpec3(spec) && (spec
|
|
23037
|
+
if (!isStripeRailSpec2(spec) && !isTempoSessionRailSpec3(spec) && isEvmNetwork(spec)) {
|
|
22948
23038
|
return spec.network ?? "eip155:8453";
|
|
22949
23039
|
}
|
|
22950
23040
|
}
|
|
@@ -22996,8 +23086,8 @@ var Checkout = class {
|
|
|
22996
23086
|
throw err;
|
|
22997
23087
|
}
|
|
22998
23088
|
}
|
|
22999
|
-
const
|
|
23000
|
-
if (this.gate !== void 0 &&
|
|
23089
|
+
const hasPaymentHeader2 = hasX402Header(request.headers) || hasMppxHeader(request.headers);
|
|
23090
|
+
if (this.gate !== void 0 && hasPaymentHeader2) {
|
|
23001
23091
|
const denial = await this.runGate(ctx);
|
|
23002
23092
|
if (denial !== null) {
|
|
23003
23093
|
return {
|
|
@@ -23087,7 +23177,7 @@ var Checkout = class {
|
|
|
23087
23177
|
...policyOverride ?? {}
|
|
23088
23178
|
};
|
|
23089
23179
|
const core = createAgentScoreCore(coreOpts);
|
|
23090
|
-
const headers =
|
|
23180
|
+
const headers = normalizeHeadersToLowercase(ctx.request.headers);
|
|
23091
23181
|
const walletAddress = headers["x-wallet-address"];
|
|
23092
23182
|
const operatorToken = headers["x-operator-token"];
|
|
23093
23183
|
const identity = walletAddress !== void 0 || operatorToken !== void 0 ? {
|
|
@@ -23149,7 +23239,7 @@ var Checkout = class {
|
|
|
23149
23239
|
if (!this.zeroSettleCarveOut || ctx.pricing === null) return null;
|
|
23150
23240
|
const cents = Math.round(ctx.pricing.amountUsd * 100);
|
|
23151
23241
|
if (cents !== 0) return null;
|
|
23152
|
-
const headers =
|
|
23242
|
+
const headers = normalizeHeadersToLowercase(ctx.request.headers);
|
|
23153
23243
|
let zero;
|
|
23154
23244
|
if (rail === "x402-base") {
|
|
23155
23245
|
const x402Header = headers["payment-signature"] ?? headers["x-payment"];
|
|
@@ -23223,7 +23313,7 @@ var Checkout = class {
|
|
|
23223
23313
|
resourceConfig: {
|
|
23224
23314
|
scheme: "exact",
|
|
23225
23315
|
network: verified.signedNetwork,
|
|
23226
|
-
price: `$${ctx.pricing.amountUsd.toFixed(2)}`,
|
|
23316
|
+
price: `$${ctx.pricing.amountUsd.toFixed(ctx.pricing.decimals ?? 2)}`,
|
|
23227
23317
|
payTo: verified.signedPayTo,
|
|
23228
23318
|
maxTimeoutSeconds: 300
|
|
23229
23319
|
},
|
|
@@ -23332,15 +23422,18 @@ var Checkout = class {
|
|
|
23332
23422
|
howToPayRails[k] = v;
|
|
23333
23423
|
}
|
|
23334
23424
|
}
|
|
23425
|
+
const pricingDecimals = ctx.pricing.decimals ?? 2;
|
|
23335
23426
|
const howToPay = buildHowToPay({
|
|
23336
23427
|
url: this.url,
|
|
23337
23428
|
retryBodyJson: JSON.stringify(ctx.request.body),
|
|
23338
|
-
totalUsd: ctx.pricing.amountUsd.toFixed(
|
|
23339
|
-
rails: howToPayRails
|
|
23429
|
+
totalUsd: ctx.pricing.amountUsd.toFixed(pricingDecimals),
|
|
23430
|
+
rails: howToPayRails,
|
|
23431
|
+
...ctx.pricing.decimals !== void 0 && { decimals: ctx.pricing.decimals }
|
|
23340
23432
|
});
|
|
23341
23433
|
const pricingBlock = ctx.pricing.block ?? buildPricingBlock({
|
|
23342
|
-
subtotalCents:
|
|
23343
|
-
currency: ctx.pricing.currency ?? "USD"
|
|
23434
|
+
subtotalCents: ctx.pricing.amountUsd * 100,
|
|
23435
|
+
currency: ctx.pricing.currency ?? "USD",
|
|
23436
|
+
...ctx.pricing.decimals !== void 0 && { decimals: ctx.pricing.decimals }
|
|
23344
23437
|
});
|
|
23345
23438
|
let x402Accepts = [];
|
|
23346
23439
|
let x402Resource;
|
|
@@ -23353,7 +23446,7 @@ var Checkout = class {
|
|
|
23353
23446
|
try {
|
|
23354
23447
|
x402Accepts = await buildX402AcceptsFor402(x402Server, {
|
|
23355
23448
|
network: baseNetwork,
|
|
23356
|
-
price: `$${ctx.pricing.amountUsd.toFixed(
|
|
23449
|
+
price: `$${ctx.pricing.amountUsd.toFixed(pricingDecimals)}`,
|
|
23357
23450
|
payTo: recipient,
|
|
23358
23451
|
maxTimeoutSeconds: 300
|
|
23359
23452
|
});
|
|
@@ -23369,7 +23462,7 @@ var Checkout = class {
|
|
|
23369
23462
|
agentInstructions: buildAgentInstructions({ howToPay }),
|
|
23370
23463
|
...identityMetadata !== void 0 ? { identityMetadata } : {},
|
|
23371
23464
|
pricing: pricingBlock,
|
|
23372
|
-
amountUsd: ctx.pricing.amountUsd.toFixed(
|
|
23465
|
+
amountUsd: ctx.pricing.amountUsd.toFixed(pricingDecimals),
|
|
23373
23466
|
retryBody: ctx.request.body,
|
|
23374
23467
|
agentMemory: firstEncounterAgentMemory({ firstEncounter: true }),
|
|
23375
23468
|
...ctx.pricing.product ? { product: ctx.pricing.product } : {},
|
|
@@ -23477,25 +23570,6 @@ function stripContentType(headers) {
|
|
|
23477
23570
|
}
|
|
23478
23571
|
return out;
|
|
23479
23572
|
}
|
|
23480
|
-
function extractMppxReceiptHeaderFromRaw(raw) {
|
|
23481
|
-
if (!raw || typeof raw !== "object" || !("withReceipt" in raw)) return null;
|
|
23482
|
-
const fn = raw.withReceipt;
|
|
23483
|
-
if (typeof fn !== "function") return null;
|
|
23484
|
-
try {
|
|
23485
|
-
const wrapped = fn.call(raw, new Response());
|
|
23486
|
-
return wrapped.headers.get("Payment-Receipt");
|
|
23487
|
-
} catch {
|
|
23488
|
-
return null;
|
|
23489
|
-
}
|
|
23490
|
-
}
|
|
23491
|
-
async function extractMppxReceiptMethod(header) {
|
|
23492
|
-
try {
|
|
23493
|
-
const { Receipt } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
23494
|
-
return Receipt.deserialize(header).method;
|
|
23495
|
-
} catch {
|
|
23496
|
-
return void 0;
|
|
23497
|
-
}
|
|
23498
|
-
}
|
|
23499
23573
|
function headersToRecord(h) {
|
|
23500
23574
|
if (h === void 0) return {};
|
|
23501
23575
|
if (h instanceof Headers) {
|
|
@@ -23809,6 +23883,15 @@ var import_node_crypto2 = require("crypto");
|
|
|
23809
23883
|
function hashOperatorToken(plaintext) {
|
|
23810
23884
|
return (0, import_node_crypto2.createHash)("sha256").update(plaintext, "utf8").digest("hex");
|
|
23811
23885
|
}
|
|
23886
|
+
function extractOwnerScope(input) {
|
|
23887
|
+
const headers = asHeaders(input);
|
|
23888
|
+
const walletAddress = readHeader(headers, "x-wallet-address");
|
|
23889
|
+
const operatorToken = readHeader(headers, "x-operator-token");
|
|
23890
|
+
return {
|
|
23891
|
+
...walletAddress ? { walletAddress } : {},
|
|
23892
|
+
...operatorToken ? { operatorTokenHash: hashOperatorToken(operatorToken) } : {}
|
|
23893
|
+
};
|
|
23894
|
+
}
|
|
23812
23895
|
|
|
23813
23896
|
// src/payment/index.ts
|
|
23814
23897
|
init_directive();
|
|
@@ -23822,8 +23905,45 @@ init_directive();
|
|
|
23822
23905
|
init_wwwauthenticate();
|
|
23823
23906
|
|
|
23824
23907
|
// src/payment/amounts.ts
|
|
23825
|
-
function
|
|
23826
|
-
|
|
23908
|
+
function usdToAtomic(usd, opts) {
|
|
23909
|
+
const { decimals } = opts;
|
|
23910
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
23911
|
+
throw new RangeError(`decimals must be a non-negative integer, got ${decimals}`);
|
|
23912
|
+
}
|
|
23913
|
+
if (typeof usd === "number") {
|
|
23914
|
+
if (!Number.isFinite(usd)) {
|
|
23915
|
+
throw new RangeError(`usd must be finite, got ${usd}`);
|
|
23916
|
+
}
|
|
23917
|
+
if (usd < 0) {
|
|
23918
|
+
throw new RangeError(`usd must be non-negative, got ${usd}`);
|
|
23919
|
+
}
|
|
23920
|
+
}
|
|
23921
|
+
const s = (typeof usd === "number" ? usd.toString() : usd).trim();
|
|
23922
|
+
if (s.startsWith("-")) {
|
|
23923
|
+
throw new RangeError(`usd must be non-negative, got ${s}`);
|
|
23924
|
+
}
|
|
23925
|
+
if (s === "NaN" || s === "Infinity") {
|
|
23926
|
+
throw new RangeError(`usd must be finite, got ${s}`);
|
|
23927
|
+
}
|
|
23928
|
+
const match = /^(\d*)(?:\.(\d*))?$/.exec(s);
|
|
23929
|
+
if (!match || match[1] === "" && (match[2] === void 0 || match[2] === "")) {
|
|
23930
|
+
throw new SyntaxError(`invalid usd value: ${JSON.stringify(usd)}`);
|
|
23931
|
+
}
|
|
23932
|
+
const intPart = match[1] || "0";
|
|
23933
|
+
const fracPart = match[2] ?? "";
|
|
23934
|
+
if (fracPart.length <= decimals) {
|
|
23935
|
+
return BigInt(intPart + fracPart.padEnd(decimals, "0"));
|
|
23936
|
+
}
|
|
23937
|
+
const kept = fracPart.slice(0, decimals);
|
|
23938
|
+
const roundDigit = fracPart[decimals];
|
|
23939
|
+
let result = BigInt(intPart + kept);
|
|
23940
|
+
if (roundDigit >= "5") {
|
|
23941
|
+
result += 1n;
|
|
23942
|
+
}
|
|
23943
|
+
return result;
|
|
23944
|
+
}
|
|
23945
|
+
function formatUsdCents(cents, decimals = 2) {
|
|
23946
|
+
return (cents / 100).toFixed(decimals);
|
|
23827
23947
|
}
|
|
23828
23948
|
|
|
23829
23949
|
// src/payment/solana.ts
|
|
@@ -23846,8 +23966,632 @@ async function loadSolanaFeePayer(opts) {
|
|
|
23846
23966
|
}
|
|
23847
23967
|
return kit.createKeyPairSignerFromPrivateKeyBytes(bytes);
|
|
23848
23968
|
}
|
|
23969
|
+
|
|
23970
|
+
// src/payment/compose_rails.ts
|
|
23971
|
+
init_usdc();
|
|
23972
|
+
function buildMppxComposeRails(opts) {
|
|
23973
|
+
const rails2 = [];
|
|
23974
|
+
if (opts.tempoRecipient) {
|
|
23975
|
+
rails2.push(["tempo/charge", {
|
|
23976
|
+
amount: opts.amountUsd,
|
|
23977
|
+
currency: opts.tempoTokenAddress ?? USDC.tempo.mainnet.address,
|
|
23978
|
+
decimals: 6,
|
|
23979
|
+
recipient: opts.tempoRecipient
|
|
23980
|
+
}]);
|
|
23981
|
+
}
|
|
23982
|
+
if (opts.solanaRecipient) {
|
|
23983
|
+
const atomic = usdToAtomic(opts.amountUsd, { decimals: 6 });
|
|
23984
|
+
rails2.push(["solana/charge", {
|
|
23985
|
+
amount: atomic.toString(),
|
|
23986
|
+
currency: opts.solanaTokenMint ?? USDC.solana.mainnet.mint,
|
|
23987
|
+
decimals: 6,
|
|
23988
|
+
recipient: opts.solanaRecipient,
|
|
23989
|
+
network: opts.solanaNetwork ?? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
|
|
23990
|
+
}]);
|
|
23991
|
+
}
|
|
23992
|
+
if (opts.includeStripe !== false) {
|
|
23993
|
+
rails2.push(["stripe/charge", { amount: opts.amountUsd, currency: "usd", decimals: 2 }]);
|
|
23994
|
+
}
|
|
23995
|
+
return rails2;
|
|
23996
|
+
}
|
|
23997
|
+
|
|
23998
|
+
// src/payment/default_rails.ts
|
|
23999
|
+
init_networks();
|
|
24000
|
+
init_usdc();
|
|
24001
|
+
function buildDefaultCheckoutRails(opts) {
|
|
24002
|
+
const out = {};
|
|
24003
|
+
if (opts.tempo) {
|
|
24004
|
+
out.tempo = { recipient: "", ...RAIL_SPEC_DEFAULTS.tempo, ...opts.tempo };
|
|
24005
|
+
}
|
|
24006
|
+
if (opts.x402Base) {
|
|
24007
|
+
const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.x402Base, ...opts.x402Base };
|
|
24008
|
+
if (merged.network === networks.base.sepolia.caip2) {
|
|
24009
|
+
if (opts.x402Base.chainId === void 0) merged.chainId = networks.base.sepolia.chainId;
|
|
24010
|
+
if (opts.x402Base.token === void 0) merged.token = USDC.base.sepolia.address;
|
|
24011
|
+
} else if (merged.network === networks.base.mainnet.caip2) {
|
|
24012
|
+
if (opts.x402Base.chainId === void 0) merged.chainId = networks.base.mainnet.chainId;
|
|
24013
|
+
if (opts.x402Base.token === void 0) merged.token = USDC.base.mainnet.address;
|
|
24014
|
+
}
|
|
24015
|
+
out.x402_base = merged;
|
|
24016
|
+
}
|
|
24017
|
+
if (opts.solanaMpp) {
|
|
24018
|
+
const merged = { recipient: "", ...RAIL_SPEC_DEFAULTS.solanaMpp, ...opts.solanaMpp };
|
|
24019
|
+
const isDevnet = merged.network === "devnet" || merged.network === networks.solana.devnet.caip2;
|
|
24020
|
+
if (isDevnet && opts.solanaMpp.token === void 0) {
|
|
24021
|
+
merged.token = USDC.solana.devnet.mint;
|
|
24022
|
+
}
|
|
24023
|
+
out.solana_mpp = merged;
|
|
24024
|
+
}
|
|
24025
|
+
if (opts.stripe) {
|
|
24026
|
+
out.stripe = { ...RAIL_SPEC_DEFAULTS.stripe, ...opts.stripe };
|
|
24027
|
+
}
|
|
24028
|
+
return out;
|
|
24029
|
+
}
|
|
24030
|
+
|
|
24031
|
+
// src/payment/index.ts
|
|
24032
|
+
init_network_kind();
|
|
24033
|
+
|
|
24034
|
+
// src/checkout_compute_first.ts
|
|
24035
|
+
var import_crypto2 = require("crypto");
|
|
24036
|
+
|
|
24037
|
+
// src/discovery/index.ts
|
|
24038
|
+
init_probe();
|
|
24039
|
+
|
|
24040
|
+
// src/discovery/agentscore_content.ts
|
|
24041
|
+
var PURCHASE_MODE_NOTES = Object.freeze({
|
|
24042
|
+
redemption_only: "Requires a single-use redemption code (printed on a mailer or other out-of-band delivery). Submit the code in the request body as `redemption_code`. Without a valid code the order is rejected.",
|
|
24043
|
+
coupon_applicable: "Codes are optional. Without one, settle at list price. With a valid code the discount is applied automatically (percent_off, fixed_off, or fixed_settle).",
|
|
24044
|
+
paid_only: "Codes are NOT accepted. Settle at the listed price. Submitting a `redemption_code` field returns 400 codes_not_accepted."
|
|
24045
|
+
});
|
|
24046
|
+
function buildSuccessNextSteps(opts) {
|
|
24047
|
+
const out = {
|
|
24048
|
+
action: "done",
|
|
24049
|
+
user_message: opts.userMessage ?? "Payment complete. Your AgentScore Passport is now active across every AgentScore-gated merchant."
|
|
24050
|
+
};
|
|
24051
|
+
if (opts.orderStatusUrl) out.order_status_url = opts.orderStatusUrl;
|
|
24052
|
+
if (opts.fulfillmentEta !== void 0) out.fulfillment_eta = opts.fulfillmentEta;
|
|
24053
|
+
return out;
|
|
24054
|
+
}
|
|
24055
|
+
|
|
24056
|
+
// src/discovery/index.ts
|
|
24057
|
+
init_well_known();
|
|
24058
|
+
|
|
24059
|
+
// src/quote_cache.ts
|
|
24060
|
+
var import_crypto = require("crypto");
|
|
24061
|
+
|
|
24062
|
+
// src/_redis.ts
|
|
24063
|
+
async function tryCreateRedis(opts) {
|
|
24064
|
+
const url2 = opts.url ?? process.env.REDIS_URL;
|
|
24065
|
+
if (!url2) return null;
|
|
24066
|
+
try {
|
|
24067
|
+
const mod = await import("ioredis");
|
|
24068
|
+
const client = new mod.default(url2, {
|
|
24069
|
+
connectTimeout: opts.connectTimeout ?? 3e3,
|
|
24070
|
+
maxRetriesPerRequest: opts.maxRetriesPerRequest ?? 1,
|
|
24071
|
+
tls: url2.startsWith("rediss://") ? {} : void 0
|
|
24072
|
+
});
|
|
24073
|
+
client.on("error", (err) => console.error(`[${opts.label}] Redis error:`, err.message));
|
|
24074
|
+
return client;
|
|
24075
|
+
} catch {
|
|
24076
|
+
return null;
|
|
24077
|
+
}
|
|
24078
|
+
}
|
|
24079
|
+
function memoizedRedis(opts) {
|
|
24080
|
+
let promise2 = null;
|
|
24081
|
+
return () => {
|
|
24082
|
+
if (!promise2) promise2 = tryCreateRedis(opts);
|
|
24083
|
+
return promise2;
|
|
24084
|
+
};
|
|
24085
|
+
}
|
|
24086
|
+
|
|
24087
|
+
// src/quote_cache.ts
|
|
24088
|
+
function canonicalize2(value) {
|
|
24089
|
+
if (Array.isArray(value)) return value.map(canonicalize2);
|
|
24090
|
+
if (value && typeof value === "object") {
|
|
24091
|
+
const sorted = {};
|
|
24092
|
+
for (const key of Object.keys(value).sort()) {
|
|
24093
|
+
sorted[key] = canonicalize2(value[key]);
|
|
24094
|
+
}
|
|
24095
|
+
return sorted;
|
|
24096
|
+
}
|
|
24097
|
+
return value;
|
|
24098
|
+
}
|
|
24099
|
+
function createQuoteCache(opts = {}) {
|
|
24100
|
+
const ttlMs = opts.ttlMs ?? 5 * 6e4;
|
|
24101
|
+
const keyPrefix = opts.keyPrefix ?? "quote:";
|
|
24102
|
+
const memMap = /* @__PURE__ */ new Map();
|
|
24103
|
+
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "quote-cache" });
|
|
24104
|
+
const evictExpired = () => {
|
|
24105
|
+
const now = Date.now();
|
|
24106
|
+
for (const [k, v] of memMap.entries()) {
|
|
24107
|
+
if (v.expiresAt <= now) memMap.delete(k);
|
|
24108
|
+
}
|
|
24109
|
+
};
|
|
24110
|
+
return {
|
|
24111
|
+
bodyHashKey(prefix, body) {
|
|
24112
|
+
const canonical = JSON.stringify(canonicalize2(body));
|
|
24113
|
+
const hash3 = (0, import_crypto.createHash)("sha256").update(`${prefix}::${canonical}`).digest("hex").slice(0, 24);
|
|
24114
|
+
return `${prefix}::${hash3}`;
|
|
24115
|
+
},
|
|
24116
|
+
async read(key) {
|
|
24117
|
+
const r = await getRedis();
|
|
24118
|
+
if (r) {
|
|
24119
|
+
try {
|
|
24120
|
+
const raw = await r.get(`${keyPrefix}${key}`);
|
|
24121
|
+
if (!raw) return null;
|
|
24122
|
+
return JSON.parse(raw);
|
|
24123
|
+
} catch {
|
|
24124
|
+
}
|
|
24125
|
+
}
|
|
24126
|
+
evictExpired();
|
|
24127
|
+
const entry = memMap.get(key);
|
|
24128
|
+
return entry ? entry.entry : null;
|
|
24129
|
+
},
|
|
24130
|
+
async write(key, body, priceCents, recipients = {}) {
|
|
24131
|
+
const cached2 = { body, priceCents, recipients };
|
|
24132
|
+
const r = await getRedis();
|
|
24133
|
+
if (r) {
|
|
24134
|
+
try {
|
|
24135
|
+
await r.set(`${keyPrefix}${key}`, JSON.stringify(cached2), "PX", ttlMs);
|
|
24136
|
+
return;
|
|
24137
|
+
} catch {
|
|
24138
|
+
}
|
|
24139
|
+
}
|
|
24140
|
+
memMap.set(key, { entry: cached2, expiresAt: Date.now() + ttlMs });
|
|
24141
|
+
},
|
|
24142
|
+
async clear() {
|
|
24143
|
+
memMap.clear();
|
|
24144
|
+
const r = await getRedis();
|
|
24145
|
+
if (r) {
|
|
24146
|
+
try {
|
|
24147
|
+
await r.flushdb();
|
|
24148
|
+
} catch {
|
|
24149
|
+
}
|
|
24150
|
+
}
|
|
24151
|
+
}
|
|
24152
|
+
};
|
|
24153
|
+
}
|
|
24154
|
+
|
|
24155
|
+
// src/checkout_compute_first.ts
|
|
24156
|
+
var DEFAULT_TTL_MS = 5 * 6e4;
|
|
24157
|
+
function decimalsForUnit(unitPriceCents) {
|
|
24158
|
+
if (Number.isInteger(unitPriceCents)) return 2;
|
|
24159
|
+
const str = unitPriceCents.toString();
|
|
24160
|
+
const dotIdx = str.indexOf(".");
|
|
24161
|
+
const frac = dotIdx === -1 ? 0 : str.length - dotIdx - 1;
|
|
24162
|
+
return 2 + frac;
|
|
24163
|
+
}
|
|
24164
|
+
function computeFirstCheckout(opts) {
|
|
24165
|
+
const cache = opts.cache ?? createQuoteCache({ ttlMs: opts.cacheTtlMs ?? DEFAULT_TTL_MS });
|
|
24166
|
+
const decimals = opts.decimals ?? decimalsForUnit(opts.unitPriceCents);
|
|
24167
|
+
const appUrl = opts.appUrl ?? new URL(opts.url).origin;
|
|
24168
|
+
async function mintAndResolveRecipients(req, body, priceCents) {
|
|
24169
|
+
const minted = opts.mintRecipients ? await opts.mintRecipients({ request: req, body, priceCents }) : {};
|
|
24170
|
+
const out = {};
|
|
24171
|
+
const tempo = minted.tempo ?? (opts.rails.tempo ? await resolveRecipient(opts.rails.tempo.recipient) : void 0);
|
|
24172
|
+
const x402Base = minted.x402_base ?? (opts.rails.x402_base ? await resolveRecipient(opts.rails.x402_base.recipient) : void 0);
|
|
24173
|
+
const solana = minted.solana_mpp ?? (opts.rails.solana_mpp ? await resolveRecipient(opts.rails.solana_mpp.recipient) : void 0);
|
|
24174
|
+
if (tempo) out.tempo = tempo;
|
|
24175
|
+
if (x402Base) out.x402_base = x402Base;
|
|
24176
|
+
if (solana) out.solana_mpp = solana;
|
|
24177
|
+
return out;
|
|
24178
|
+
}
|
|
24179
|
+
async function emit402(req, body, priceCents, recipients) {
|
|
24180
|
+
const totalUsd = formatUsdCents(priceCents, decimals);
|
|
24181
|
+
const tempoRecipient = recipients.tempo;
|
|
24182
|
+
const x402BaseRecipient = recipients.x402_base;
|
|
24183
|
+
const solanaRecipient = recipients.solana_mpp;
|
|
24184
|
+
const accepted = await buildAcceptedMethods({
|
|
24185
|
+
...tempoRecipient && opts.rails.tempo && { tempo: { ...opts.rails.tempo, recipient: tempoRecipient } },
|
|
24186
|
+
...solanaRecipient && opts.rails.solana_mpp && { solana_mpp: { ...opts.rails.solana_mpp, recipient: solanaRecipient } },
|
|
24187
|
+
...opts.rails.stripe && { stripe: opts.rails.stripe }
|
|
24188
|
+
});
|
|
24189
|
+
if (x402BaseRecipient && opts.rails.x402_base) {
|
|
24190
|
+
try {
|
|
24191
|
+
const resolvedX402PayTo = await resolveRecipient(x402BaseRecipient);
|
|
24192
|
+
const x402Entries = await buildX402AcceptsFor402(opts.x402Server, {
|
|
24193
|
+
network: opts.rails.x402_base.network ?? "eip155:8453",
|
|
24194
|
+
price: `$${totalUsd}`,
|
|
24195
|
+
payTo: resolvedX402PayTo,
|
|
24196
|
+
maxTimeoutSeconds: 300
|
|
24197
|
+
});
|
|
24198
|
+
accepted.push(...x402Entries);
|
|
24199
|
+
} catch (err) {
|
|
24200
|
+
console.warn(
|
|
24201
|
+
`[${opts.name}.computeFirst] buildX402AcceptsFor402 failed; dropping x402 from accepts:`,
|
|
24202
|
+
err instanceof Error ? err.message : err
|
|
24203
|
+
);
|
|
24204
|
+
}
|
|
24205
|
+
}
|
|
24206
|
+
const howToPay = buildHowToPay({
|
|
24207
|
+
url: opts.url,
|
|
24208
|
+
retryBodyJson: JSON.stringify(body),
|
|
24209
|
+
totalUsd,
|
|
24210
|
+
decimals,
|
|
24211
|
+
rails: {
|
|
24212
|
+
...tempoRecipient && opts.rails.tempo && { tempo: { ...opts.rails.tempo, recipient: tempoRecipient } },
|
|
24213
|
+
...x402BaseRecipient && opts.rails.x402_base && { x402_base: { ...opts.rails.x402_base, recipient: x402BaseRecipient } },
|
|
24214
|
+
...solanaRecipient && opts.rails.solana_mpp && { solana_mpp: { ...opts.rails.solana_mpp, recipient: solanaRecipient } },
|
|
24215
|
+
...opts.rails.stripe && { stripe: opts.rails.stripe }
|
|
24216
|
+
}
|
|
24217
|
+
});
|
|
24218
|
+
const pricing = buildPricingBlock({ subtotalCents: priceCents, currency: "USD", decimals });
|
|
24219
|
+
const agentInstructions = buildAgentInstructions({
|
|
24220
|
+
howToPay,
|
|
24221
|
+
warnings: [
|
|
24222
|
+
"The quoted price is exact: it was derived from the actual number of results returned by the work on the probe leg.",
|
|
24223
|
+
"The merchant cached the result against a hash of this request body. Retry with the same body within the quote TTL (default 5 min) to settle and receive the cached results; if the quote expires, re-probe."
|
|
24224
|
+
]
|
|
24225
|
+
});
|
|
24226
|
+
let mppChallengeHeaders = {};
|
|
24227
|
+
if (opts.composeMppx) {
|
|
24228
|
+
try {
|
|
24229
|
+
const mppResult = await opts.composeMppx({
|
|
24230
|
+
request: req,
|
|
24231
|
+
cachedBody: body,
|
|
24232
|
+
priceCents,
|
|
24233
|
+
priceUsd: totalUsd,
|
|
24234
|
+
recipients
|
|
24235
|
+
});
|
|
24236
|
+
if (mppResult.status === 402 && mppResult.headers) {
|
|
24237
|
+
mppChallengeHeaders = mppResult.headers;
|
|
24238
|
+
}
|
|
24239
|
+
} catch (err) {
|
|
24240
|
+
console.warn(
|
|
24241
|
+
`[${opts.name}.computeFirst] composeMppx probe-leg failed; dropping MPP rails from 402 challenge:`,
|
|
24242
|
+
err instanceof Error ? err.message : err
|
|
24243
|
+
);
|
|
24244
|
+
}
|
|
24245
|
+
}
|
|
24246
|
+
const body402 = build402Body({
|
|
24247
|
+
product: { id: opts.name, name: opts.name },
|
|
24248
|
+
acceptedMethods: accepted,
|
|
24249
|
+
pricing,
|
|
24250
|
+
agentInstructions,
|
|
24251
|
+
amountUsd: totalUsd,
|
|
24252
|
+
currency: "USD",
|
|
24253
|
+
orderId: null,
|
|
24254
|
+
retryBody: body
|
|
24255
|
+
});
|
|
24256
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
24257
|
+
for (const [k, v] of Object.entries(mppChallengeHeaders)) headers.set(k, v);
|
|
24258
|
+
headers.set(
|
|
24259
|
+
"PAYMENT-REQUIRED",
|
|
24260
|
+
paymentRequiredHeader({ x402Version: 2, accepts: accepted, resource: { url: opts.url } })
|
|
24261
|
+
);
|
|
24262
|
+
return new Response(JSON.stringify(body402), { status: 402, headers });
|
|
24263
|
+
}
|
|
24264
|
+
async function handleX402Settle(req, referenceId, cachedBody, priceCents, recipients) {
|
|
24265
|
+
const verified = await verifyX402Request({
|
|
24266
|
+
request: req,
|
|
24267
|
+
isCachedAddress: async () => true,
|
|
24268
|
+
acceptedNetwork: opts.rails.x402_base?.network ?? "eip155:8453"
|
|
24269
|
+
});
|
|
24270
|
+
if (!verified.ok) {
|
|
24271
|
+
return new Response(JSON.stringify(verified.body), {
|
|
24272
|
+
status: verified.status,
|
|
24273
|
+
headers: { "Content-Type": "application/json" }
|
|
24274
|
+
});
|
|
24275
|
+
}
|
|
24276
|
+
const actualUsd = formatUsdCents(priceCents, decimals);
|
|
24277
|
+
const settle = await processX402Settle({
|
|
24278
|
+
x402Server: opts.x402Server,
|
|
24279
|
+
payload: verified.payload,
|
|
24280
|
+
resourceConfig: {
|
|
24281
|
+
scheme: "exact",
|
|
24282
|
+
network: verified.signedNetwork,
|
|
24283
|
+
price: `$${actualUsd}`,
|
|
24284
|
+
payTo: verified.signedPayTo,
|
|
24285
|
+
maxTimeoutSeconds: 300
|
|
24286
|
+
},
|
|
24287
|
+
resourceMeta: {
|
|
24288
|
+
url: req.url,
|
|
24289
|
+
description: `Agent purchase via x402-exact (${opts.name})`,
|
|
24290
|
+
mimeType: "application/json"
|
|
24291
|
+
}
|
|
24292
|
+
});
|
|
24293
|
+
if (!settle.success) {
|
|
24294
|
+
const detail = settle.error?.message ?? "unknown";
|
|
24295
|
+
return new Response(
|
|
24296
|
+
JSON.stringify({
|
|
24297
|
+
id: referenceId,
|
|
24298
|
+
endpoint: opts.name,
|
|
24299
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24300
|
+
payment_status: "failed",
|
|
24301
|
+
charged_usd: "0.00",
|
|
24302
|
+
rail: `x402-base (${verified.signedNetwork})`,
|
|
24303
|
+
error: {
|
|
24304
|
+
code: "settle_failed",
|
|
24305
|
+
message: "Facilitator rejected the exact settle; no on-chain capture occurred.",
|
|
24306
|
+
detail
|
|
24307
|
+
}
|
|
24308
|
+
}),
|
|
24309
|
+
{ status: 502, headers: { "Content-Type": "application/json" } }
|
|
24310
|
+
);
|
|
24311
|
+
}
|
|
24312
|
+
const signer = await extractPaymentSigner(req, readX402PaymentHeader(req));
|
|
24313
|
+
const signerInfo = signer ? { address: signer.address, network: signer.network } : void 0;
|
|
24314
|
+
const railLabel = `Base (${verified.signedNetwork})`;
|
|
24315
|
+
if (opts.onSettled) {
|
|
24316
|
+
try {
|
|
24317
|
+
await opts.onSettled({
|
|
24318
|
+
request: req,
|
|
24319
|
+
rail: "x402",
|
|
24320
|
+
cachedBody,
|
|
24321
|
+
priceCents,
|
|
24322
|
+
priceUsd: actualUsd,
|
|
24323
|
+
recipients,
|
|
24324
|
+
...signerInfo ? { signer: signerInfo } : {}
|
|
24325
|
+
});
|
|
24326
|
+
} catch (err) {
|
|
24327
|
+
console.warn(`[${opts.name}.computeFirst.onSettled] x402 side-effect failed:`, err instanceof Error ? err.message : err);
|
|
24328
|
+
}
|
|
24329
|
+
}
|
|
24330
|
+
const buildBody = opts.buildSuccessBody ?? defaultSuccessBody(appUrl);
|
|
24331
|
+
const body = buildBody({
|
|
24332
|
+
referenceId,
|
|
24333
|
+
endpoint: opts.name,
|
|
24334
|
+
chargedUsd: actualUsd,
|
|
24335
|
+
rail: railLabel,
|
|
24336
|
+
...signerInfo ? { signer: signerInfo } : {},
|
|
24337
|
+
cachedBody
|
|
24338
|
+
});
|
|
24339
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { "Content-Type": "application/json" } });
|
|
24340
|
+
}
|
|
24341
|
+
function mppRailLabel(method) {
|
|
24342
|
+
const scheme = method?.split("/")[0];
|
|
24343
|
+
if (scheme === "tempo") {
|
|
24344
|
+
const networkName = opts.rails.tempo?.testnet ? "tempo-testnet" : opts.rails.tempo?.network ?? "tempo-mainnet";
|
|
24345
|
+
return `Tempo (${networkName})`;
|
|
24346
|
+
}
|
|
24347
|
+
if (scheme === "solana") {
|
|
24348
|
+
const networkName = opts.rails.solana_mpp?.network ?? "solana";
|
|
24349
|
+
return `Solana (${networkName})`;
|
|
24350
|
+
}
|
|
24351
|
+
if (scheme === "stripe") return "Stripe (card+link)";
|
|
24352
|
+
return "MPP";
|
|
24353
|
+
}
|
|
24354
|
+
async function handleMppSettle(req, referenceId, cachedBody, priceCents, recipients) {
|
|
24355
|
+
if (!opts.composeMppx) {
|
|
24356
|
+
return new Response(
|
|
24357
|
+
JSON.stringify({
|
|
24358
|
+
id: referenceId,
|
|
24359
|
+
endpoint: opts.name,
|
|
24360
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24361
|
+
payment_status: "failed",
|
|
24362
|
+
charged_usd: "0.00",
|
|
24363
|
+
error: { code: "mpp_unavailable", message: "MPP settle hook not configured on this endpoint." }
|
|
24364
|
+
}),
|
|
24365
|
+
{ status: 503, headers: { "Content-Type": "application/json" } }
|
|
24366
|
+
);
|
|
24367
|
+
}
|
|
24368
|
+
const priceUsd = formatUsdCents(priceCents, decimals);
|
|
24369
|
+
const result = await opts.composeMppx({ request: req, cachedBody, priceCents, priceUsd, recipients });
|
|
24370
|
+
if (result.status !== 200) {
|
|
24371
|
+
const headers = result.headers ?? {};
|
|
24372
|
+
return new Response(
|
|
24373
|
+
JSON.stringify({
|
|
24374
|
+
id: referenceId,
|
|
24375
|
+
endpoint: opts.name,
|
|
24376
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24377
|
+
payment_status: "failed",
|
|
24378
|
+
charged_usd: "0.00",
|
|
24379
|
+
error: { code: "mpp_settle_failed", message: "MPP compose did not return 200; credential rejected." }
|
|
24380
|
+
}),
|
|
24381
|
+
{ status: 400, headers: { "Content-Type": "application/json", ...headers } }
|
|
24382
|
+
);
|
|
24383
|
+
}
|
|
24384
|
+
const signer = result.signerAddress ? { address: result.signerAddress, network: result.signerNetwork ?? "evm" } : await extractPaymentSigner(req, readX402PaymentHeader(req)).then((s) => s ? { address: s.address, network: s.network } : void 0);
|
|
24385
|
+
const method = await deriveMppxReceiptMethod(result.raw);
|
|
24386
|
+
const railLabel = mppRailLabel(method);
|
|
24387
|
+
if (opts.onSettled) {
|
|
24388
|
+
try {
|
|
24389
|
+
await opts.onSettled({
|
|
24390
|
+
request: req,
|
|
24391
|
+
rail: "mpp",
|
|
24392
|
+
mppMethod: method,
|
|
24393
|
+
cachedBody,
|
|
24394
|
+
priceCents,
|
|
24395
|
+
priceUsd,
|
|
24396
|
+
recipients,
|
|
24397
|
+
...signer ? { signer } : {},
|
|
24398
|
+
...result.txHash ? { paymentIntentId: result.txHash } : {}
|
|
24399
|
+
});
|
|
24400
|
+
} catch (err) {
|
|
24401
|
+
console.warn(`[${opts.name}.computeFirst.onSettled] MPP side-effect failed:`, err instanceof Error ? err.message : err);
|
|
24402
|
+
}
|
|
24403
|
+
}
|
|
24404
|
+
const buildBody = opts.buildSuccessBody ?? defaultSuccessBody(appUrl);
|
|
24405
|
+
const body = buildBody({
|
|
24406
|
+
referenceId,
|
|
24407
|
+
endpoint: opts.name,
|
|
24408
|
+
chargedUsd: priceUsd,
|
|
24409
|
+
rail: railLabel,
|
|
24410
|
+
...result.txHash ? { paymentIntentId: result.txHash } : {},
|
|
24411
|
+
...signer ? { signer } : {},
|
|
24412
|
+
cachedBody
|
|
24413
|
+
});
|
|
24414
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { "Content-Type": "application/json" } });
|
|
24415
|
+
}
|
|
24416
|
+
async function handle(req) {
|
|
24417
|
+
const referenceId = `${opts.name}_${(0, import_crypto2.randomUUID)()}`;
|
|
24418
|
+
let body;
|
|
24419
|
+
try {
|
|
24420
|
+
body = await req.clone().json();
|
|
24421
|
+
} catch {
|
|
24422
|
+
body = {};
|
|
24423
|
+
}
|
|
24424
|
+
try {
|
|
24425
|
+
opts.validateInput?.(body);
|
|
24426
|
+
} catch (err) {
|
|
24427
|
+
if (err instanceof CheckoutValidationError) {
|
|
24428
|
+
return new Response(
|
|
24429
|
+
JSON.stringify({
|
|
24430
|
+
error: { code: err.code, message: err.message },
|
|
24431
|
+
...err.action ? { next_steps: { action: err.action, user_message: err.message } } : {},
|
|
24432
|
+
...err.extra
|
|
24433
|
+
}),
|
|
24434
|
+
{ status: err.status, headers: { "Content-Type": "application/json" } }
|
|
24435
|
+
);
|
|
24436
|
+
}
|
|
24437
|
+
throw err;
|
|
24438
|
+
}
|
|
24439
|
+
const cacheKey2 = cache.bodyHashKey(opts.name, body);
|
|
24440
|
+
if (hasX402Header(req.headers) || hasMppxHeader(req.headers)) {
|
|
24441
|
+
const quote2 = await cache.read(cacheKey2);
|
|
24442
|
+
if (!quote2) {
|
|
24443
|
+
return new Response(
|
|
24444
|
+
JSON.stringify({
|
|
24445
|
+
id: referenceId,
|
|
24446
|
+
endpoint: opts.name,
|
|
24447
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24448
|
+
payment_status: "failed",
|
|
24449
|
+
charged_usd: "0.00",
|
|
24450
|
+
error: {
|
|
24451
|
+
code: "stale_quote",
|
|
24452
|
+
message: "No active quote for this request body. The quote may have expired or the body changed since the probe."
|
|
24453
|
+
},
|
|
24454
|
+
next_steps: {
|
|
24455
|
+
action: "re_probe",
|
|
24456
|
+
suggestion: "Send the same body without a payment header to get a fresh 402 quote, then retry with the payment credential."
|
|
24457
|
+
}
|
|
24458
|
+
}),
|
|
24459
|
+
{ status: 400, headers: { "Content-Type": "application/json" } }
|
|
24460
|
+
);
|
|
24461
|
+
}
|
|
24462
|
+
if (hasX402Header(req.headers)) return handleX402Settle(req, referenceId, quote2.body, quote2.priceCents, quote2.recipients);
|
|
24463
|
+
return handleMppSettle(req, referenceId, quote2.body, quote2.priceCents, quote2.recipients);
|
|
24464
|
+
}
|
|
24465
|
+
let quote = await cache.read(cacheKey2);
|
|
24466
|
+
if (!quote) {
|
|
24467
|
+
let outcome;
|
|
24468
|
+
try {
|
|
24469
|
+
outcome = await opts.runWork(body, { request: req });
|
|
24470
|
+
} catch {
|
|
24471
|
+
return new Response(
|
|
24472
|
+
JSON.stringify({
|
|
24473
|
+
id: referenceId,
|
|
24474
|
+
endpoint: opts.name,
|
|
24475
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24476
|
+
payment_status: "no_charge",
|
|
24477
|
+
charged_usd: "0.00",
|
|
24478
|
+
result: { matches: [], total: 0 },
|
|
24479
|
+
error: {
|
|
24480
|
+
code: "upstream_failed",
|
|
24481
|
+
message: "The wrapped endpoint failed; no charge was applied."
|
|
24482
|
+
}
|
|
24483
|
+
}),
|
|
24484
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
24485
|
+
);
|
|
24486
|
+
}
|
|
24487
|
+
if (outcome.resultCount === 0) {
|
|
24488
|
+
return new Response(
|
|
24489
|
+
JSON.stringify({
|
|
24490
|
+
id: referenceId,
|
|
24491
|
+
endpoint: opts.name,
|
|
24492
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24493
|
+
payment_status: "no_charge",
|
|
24494
|
+
charged_usd: "0.00",
|
|
24495
|
+
result: outcome.body
|
|
24496
|
+
}),
|
|
24497
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
24498
|
+
);
|
|
24499
|
+
}
|
|
24500
|
+
const priceCents = opts.unitPriceCents * outcome.resultCount;
|
|
24501
|
+
const recipients = await mintAndResolveRecipients(req, body, priceCents);
|
|
24502
|
+
await cache.write(cacheKey2, outcome.body, priceCents, recipients);
|
|
24503
|
+
quote = { body: outcome.body, priceCents, recipients };
|
|
24504
|
+
}
|
|
24505
|
+
return emit402(req, body, quote.priceCents, quote.recipients);
|
|
24506
|
+
}
|
|
24507
|
+
return {
|
|
24508
|
+
handleWeb: handle,
|
|
24509
|
+
async handleHono(c) {
|
|
24510
|
+
return handle(c.req.raw);
|
|
24511
|
+
}
|
|
24512
|
+
};
|
|
24513
|
+
}
|
|
24514
|
+
function defaultSuccessBody(appUrl) {
|
|
24515
|
+
return ({ referenceId, endpoint, chargedUsd, rail, paymentIntentId, signer, cachedBody }) => ({
|
|
24516
|
+
id: referenceId,
|
|
24517
|
+
endpoint,
|
|
24518
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24519
|
+
payment_status: "completed",
|
|
24520
|
+
charged_usd: chargedUsd,
|
|
24521
|
+
rail,
|
|
24522
|
+
...paymentIntentId ? { payment_intent_id: paymentIntentId } : {},
|
|
24523
|
+
...signer ? { signer } : {},
|
|
24524
|
+
result: cachedBody,
|
|
24525
|
+
next_steps: buildSuccessNextSteps({ orderStatusUrl: `${appUrl}/health` }),
|
|
24526
|
+
agent_memory: firstEncounterAgentMemory({ firstEncounter: true })
|
|
24527
|
+
});
|
|
24528
|
+
}
|
|
24529
|
+
|
|
24530
|
+
// src/identity/default_denied.ts
|
|
24531
|
+
function createDefaultOnDenied(opts) {
|
|
24532
|
+
const supportContext = opts.supportContext ?? "Contact support if you believe this denial is in error.";
|
|
24533
|
+
const paymentRequiredMessage = opts.paymentRequiredMessage ?? "AgentScore tier does not support assess. Contact support.";
|
|
24534
|
+
const walletNotTrustedMessage = opts.walletNotTrustedMessage ?? `Identity check did not satisfy policy for ${opts.merchantName}.`;
|
|
24535
|
+
return function defaultOnDenied(reason) {
|
|
24536
|
+
if (reason.code === "wallet_signer_mismatch" || reason.code === "wallet_auth_requires_wallet_signing") {
|
|
24537
|
+
const body = buildSignerMismatchBody({
|
|
24538
|
+
result: {
|
|
24539
|
+
kind: reason.code,
|
|
24540
|
+
claimedOperator: reason.claimed_operator ?? null,
|
|
24541
|
+
actualSignerOperator: reason.actual_signer_operator ?? null,
|
|
24542
|
+
expectedSigner: reason.expected_signer ?? "",
|
|
24543
|
+
actualSigner: reason.actual_signer ?? "",
|
|
24544
|
+
linkedWallets: reason.linked_wallets ?? [],
|
|
24545
|
+
agentInstructions: reason.agent_instructions ?? "",
|
|
24546
|
+
claimedWallet: reason.expected_signer ?? ""
|
|
24547
|
+
}
|
|
24548
|
+
});
|
|
24549
|
+
return { status: 403, body: body ?? denialReasonToBody(reason) };
|
|
24550
|
+
}
|
|
24551
|
+
if (reason.code === "wallet_not_trusted") {
|
|
24552
|
+
return {
|
|
24553
|
+
status: 403,
|
|
24554
|
+
body: {
|
|
24555
|
+
error: { code: "compliance_denied", message: walletNotTrustedMessage },
|
|
24556
|
+
reasons: reason.reasons ?? [],
|
|
24557
|
+
policy_result: reason.data?.policy_result,
|
|
24558
|
+
verify_url: reason.verify_url,
|
|
24559
|
+
next_steps: buildContactSupportNextSteps(opts.supportEmail, supportContext)
|
|
24560
|
+
}
|
|
24561
|
+
};
|
|
24562
|
+
}
|
|
24563
|
+
if (reason.code === "payment_required") {
|
|
24564
|
+
return {
|
|
24565
|
+
status: 403,
|
|
24566
|
+
body: {
|
|
24567
|
+
...denialReasonToBody(reason),
|
|
24568
|
+
error: { code: "compliance_error", message: paymentRequiredMessage }
|
|
24569
|
+
}
|
|
24570
|
+
};
|
|
24571
|
+
}
|
|
24572
|
+
const status = reason.code === "token_expired" || reason.code === "invalid_credential" ? 401 : reason.code === "api_error" ? 503 : 403;
|
|
24573
|
+
return {
|
|
24574
|
+
status,
|
|
24575
|
+
body: denialReasonToBody(reason),
|
|
24576
|
+
...status >= 500 && { headers: { "Cache-Control": "no-store" } }
|
|
24577
|
+
};
|
|
24578
|
+
};
|
|
24579
|
+
}
|
|
24580
|
+
function defaultReadOnlyOnDenied(reason) {
|
|
24581
|
+
const message = reason.code === "missing_identity" ? "X-Wallet-Address or X-Operator-Token header required" : "Invalid identity";
|
|
24582
|
+
return {
|
|
24583
|
+
status: 401,
|
|
24584
|
+
body: {
|
|
24585
|
+
...denialReasonToBody(reason),
|
|
24586
|
+
error: { code: "unauthorized", message }
|
|
24587
|
+
},
|
|
24588
|
+
headers: { "Cache-Control": "no-store" }
|
|
24589
|
+
};
|
|
24590
|
+
}
|
|
23849
24591
|
// Annotate the CommonJS export names for ESM import in node:
|
|
23850
24592
|
0 && (module.exports = {
|
|
24593
|
+
A2A_DEFAULT_TRANSPORT,
|
|
24594
|
+
A2A_PROTOCOL_VERSION,
|
|
23851
24595
|
AGENTSCORE_UCP_CAPABILITY,
|
|
23852
24596
|
Checkout,
|
|
23853
24597
|
CheckoutValidationError,
|
|
@@ -23858,18 +24602,28 @@ async function loadSolanaFeePayer(opts) {
|
|
|
23858
24602
|
buildA2AAgentCard,
|
|
23859
24603
|
buildAgentMemoryHint,
|
|
23860
24604
|
buildContactSupportNextSteps,
|
|
24605
|
+
buildDefaultCheckoutRails,
|
|
23861
24606
|
buildGateFromPolicy,
|
|
23862
24607
|
buildJWKSResponse,
|
|
24608
|
+
buildMppxComposeRails,
|
|
23863
24609
|
buildSignerMismatchBody,
|
|
23864
24610
|
buildUCPProfile,
|
|
24611
|
+
computeFirstCheckout,
|
|
24612
|
+
createDefaultOnDenied,
|
|
24613
|
+
createQuoteCache,
|
|
24614
|
+
defaultReadOnlyOnDenied,
|
|
23865
24615
|
denialReasonStatus,
|
|
23866
24616
|
denialReasonToBody,
|
|
24617
|
+
extractOwnerScope,
|
|
23867
24618
|
extractPaymentSigner,
|
|
23868
24619
|
extractPaymentSignerFromAuth,
|
|
23869
24620
|
extractSignerForPrecheck,
|
|
23870
24621
|
formatUsdCents,
|
|
23871
24622
|
generateUCPSigningKey,
|
|
23872
24623
|
getIdentityStatus,
|
|
24624
|
+
hasMppxHeader,
|
|
24625
|
+
hasPaymentHeader,
|
|
24626
|
+
hasX402Header,
|
|
23873
24627
|
hashOperatorToken,
|
|
23874
24628
|
isFixableDenial,
|
|
23875
24629
|
loadSolanaFeePayer,
|