@agent-score/commerce 2.6.2 → 2.6.4
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/dist/{checkout-C4RD7M0Z.d.ts → checkout-B-Z5_EQP.d.ts} +9 -0
- package/dist/{checkout-CzB9f_jf.d.mts → checkout-BtdHSF_w.d.mts} +9 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/discovery/index.d.mts +1 -1
- package/dist/discovery/index.d.ts +1 -1
- package/dist/identity/express.js +1 -1
- package/dist/identity/express.js.map +1 -1
- package/dist/identity/express.mjs +1 -1
- package/dist/identity/express.mjs.map +1 -1
- package/dist/identity/fastify.js +1 -1
- package/dist/identity/fastify.js.map +1 -1
- package/dist/identity/fastify.mjs +1 -1
- package/dist/identity/fastify.mjs.map +1 -1
- package/dist/identity/hono.js +1 -1
- package/dist/identity/hono.js.map +1 -1
- package/dist/identity/hono.mjs +1 -1
- package/dist/identity/hono.mjs.map +1 -1
- package/dist/identity/nextjs.js +1 -1
- package/dist/identity/nextjs.js.map +1 -1
- package/dist/identity/nextjs.mjs +1 -1
- package/dist/identity/nextjs.mjs.map +1 -1
- package/dist/identity/web.js +1 -1
- package/dist/identity/web.js.map +1 -1
- package/dist/identity/web.mjs +1 -1
- package/dist/identity/web.mjs.map +1 -1
- package/dist/index.d.mts +35 -17
- package/dist/index.d.ts +35 -17
- package/dist/index.js +101 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -18
- package/dist/index.mjs.map +1 -1
- package/dist/{network_kind-BIJM2peR.d.ts → network_kind-BmbWKNud.d.ts} +23 -1
- package/dist/{network_kind-C0EMkdzz.d.mts → network_kind-D2xpo2Fj.d.mts} +23 -1
- package/dist/payment/index.d.mts +27 -20
- package/dist/payment/index.d.ts +27 -20
- package/dist/payment/index.js +35 -0
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +34 -0
- package/dist/payment/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { VerifyWalletSignerResult, DenialReason } from './core.mjs';
|
|
2
2
|
export { AccountVerification, AgentIdentity, AgentMemoryHint, AgentScoreCore, AssessResult, CreateSessionOnMissing, DenialCode, EvaluateOutcome, OperatorVerification, PolicyCheck, PolicyResult, SignerVerdict, buildAgentMemoryHint } from './core.mjs';
|
|
3
3
|
export { P as PaymentSigner, S as SignerNetwork, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from './signer-3FAit11j.mjs';
|
|
4
|
-
import { q as UCPSigningKey, n as UCPProfile } from './checkout-
|
|
5
|
-
export { A as AGENTSCORE_UCP_CAPABILITY, a as AgentScoreGatePolicy, C as Checkout, b as CheckoutContext, c as CheckoutGateConfig, d as CheckoutRailSpec, e as CheckoutRequest, f as CheckoutResult, g as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, h as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, i as PricingFn, j as PricingResult, R as RecipientsFn, k as ReferenceIdFn, l as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, m as UCPPaymentHandlerBinding, o as UCPProfileBody, p as UCPServiceBinding, r as buildAipTrustedIssuers, s as buildUCPProfile, t as getIdentityStatus, u as makeMppxComposeHook, v as mppPaymentHandler, w as pricingResult, x as stripeSptPaymentHandler, y as validationEnvelope, z as validationResponseExpress, B as validationResponseFastify, E as validationResponseHono, F as validationResponseNextjs, H as validationResponseWeb, J as x402PaymentHandler } from './checkout-
|
|
4
|
+
import { q as UCPSigningKey, n as UCPProfile } from './checkout-BtdHSF_w.mjs';
|
|
5
|
+
export { A as AGENTSCORE_UCP_CAPABILITY, a as AgentScoreGatePolicy, C as Checkout, b as CheckoutContext, c as CheckoutGateConfig, d as CheckoutRailSpec, e as CheckoutRequest, f as CheckoutResult, g as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, h as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, i as PricingFn, j as PricingResult, R as RecipientsFn, k as ReferenceIdFn, l as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, m as UCPPaymentHandlerBinding, o as UCPProfileBody, p as UCPServiceBinding, r as buildAipTrustedIssuers, s as buildUCPProfile, t as getIdentityStatus, u as makeMppxComposeHook, v as mppPaymentHandler, w as pricingResult, x as stripeSptPaymentHandler, y as validationEnvelope, z as validationResponseExpress, B as validationResponseFastify, E as validationResponseHono, F as validationResponseNextjs, H as validationResponseWeb, J as x402PaymentHandler } from './checkout-BtdHSF_w.mjs';
|
|
6
6
|
export { EnforcementMode, GateResult, IdentityStatus, PolicyBlock, buildGateFromPolicy, runGateWithEnforcement, shippingCountryAllowed, shippingStateAllowed, validateShippingAgainstPolicy } from './identity/policy.mjs';
|
|
7
|
-
import { H as HeadersLike } from './network_kind-
|
|
8
|
-
export { c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer } from './network_kind-
|
|
7
|
+
import { H as HeadersLike } from './network_kind-D2xpo2Fj.mjs';
|
|
8
|
+
export { M as MalformedPaymentCredential, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer, m as malformedPaymentCredential } from './network_kind-D2xpo2Fj.mjs';
|
|
9
9
|
import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-BFZmW9RN.mjs';
|
|
10
10
|
export { c as TempoSessionRailSpec } from './rail_spec-BFZmW9RN.mjs';
|
|
11
11
|
import { Context } from 'hono';
|
|
@@ -653,21 +653,26 @@ declare class CheckoutValidationError extends Error {
|
|
|
653
653
|
}
|
|
654
654
|
|
|
655
655
|
/**
|
|
656
|
-
* Short-TTL body-hash
|
|
657
|
-
* (see {@link computeFirstCheckout}).
|
|
656
|
+
* Short-TTL body-hash caches.
|
|
658
657
|
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
658
|
+
* `createResultCache` is the neutral primitive: a keyed JSON-value cache with
|
|
659
|
+
* a stable content-hash key builder. Use it to cache any per-request result a
|
|
660
|
+
* merchant computes on the probe leg and replays on the settle leg — e.g. the
|
|
661
|
+
* output of a paid upstream call made in a `Checkout.preValidate` hook, so a
|
|
662
|
+
* payment retry (or a junk payment header) never pays upstream twice.
|
|
663
|
+
*
|
|
664
|
+
* `createQuoteCache` is the compute-first-flavored wrapper used by
|
|
665
|
+
* {@link computeFirstCheckout}: the cached value is a `CachedQuote`
|
|
666
|
+
* (`{body, priceCents, recipients}`). Standard x402-fetch retry semantics
|
|
667
|
+
* resign the buyer's ORIGINAL request body — there's no `result_id` echo
|
|
668
|
+
* channel through the protocol — so both caches key by a stable content-hash
|
|
669
|
+
* of the request body. Same body → same hash → same cache slot.
|
|
665
670
|
*
|
|
666
671
|
* Default in-memory `Map`; optional `redisUrl` lazy-imports `ioredis` for
|
|
667
672
|
* multi-instance deployments. `ioredis` is an optional peer dep.
|
|
668
673
|
*/
|
|
669
|
-
interface
|
|
670
|
-
/**
|
|
674
|
+
interface ResultCacheOptions {
|
|
675
|
+
/** Entry lifetime in milliseconds. Default `5 * 60_000` (5 min). */
|
|
671
676
|
ttlMs?: number;
|
|
672
677
|
/** Redis connection URL. Default: `process.env.REDIS_URL`. When unset or the
|
|
673
678
|
* lazy `ioredis` import fails, falls back to in-process `Map`. */
|
|
@@ -675,6 +680,7 @@ interface QuoteCacheOptions {
|
|
|
675
680
|
/** Per-instance key prefix so multiple caches sharing a Redis don't collide. */
|
|
676
681
|
keyPrefix?: string;
|
|
677
682
|
}
|
|
683
|
+
type QuoteCacheOptions = ResultCacheOptions;
|
|
678
684
|
interface CachedQuote {
|
|
679
685
|
body: Record<string, unknown>;
|
|
680
686
|
priceCents: number;
|
|
@@ -683,6 +689,15 @@ interface CachedQuote {
|
|
|
683
689
|
* same logical purchase). Empty object when no `mintRecipients` hook is wired. */
|
|
684
690
|
recipients: Record<string, string>;
|
|
685
691
|
}
|
|
692
|
+
interface ResultCache<T> {
|
|
693
|
+
/** Build a stable content-hash key from a per-merchant prefix and a request body.
|
|
694
|
+
* Property order in the body does NOT affect the hash (keys are sorted recursively). */
|
|
695
|
+
bodyHashKey(prefix: string, body: Record<string, unknown>): string;
|
|
696
|
+
read(key: string): Promise<T | null>;
|
|
697
|
+
write(key: string, value: T): Promise<void>;
|
|
698
|
+
/** Clear all entries. Primarily for tests. */
|
|
699
|
+
clear(): Promise<void>;
|
|
700
|
+
}
|
|
686
701
|
interface QuoteCache {
|
|
687
702
|
/** Build a stable content-hash key from a per-merchant prefix and a request body.
|
|
688
703
|
* Property order in the body does NOT affect the hash (keys are sorted recursively). */
|
|
@@ -692,8 +707,11 @@ interface QuoteCache {
|
|
|
692
707
|
/** Clear all entries. Primarily for tests. */
|
|
693
708
|
clear(): Promise<void>;
|
|
694
709
|
}
|
|
695
|
-
/** Build a fresh cache. Each call owns its own state (memory
|
|
696
|
-
* client). */
|
|
710
|
+
/** Build a fresh neutral result cache. Each call owns its own state (memory
|
|
711
|
+
* map + Redis client). Values must survive `JSON.stringify` round-trips. */
|
|
712
|
+
declare function createResultCache<T>(opts?: ResultCacheOptions): ResultCache<T>;
|
|
713
|
+
/** Build a fresh compute-first quote cache (a `ResultCache<CachedQuote>` with
|
|
714
|
+
* the quote-shaped `write` signature). */
|
|
697
715
|
declare function createQuoteCache(opts?: QuoteCacheOptions): QuoteCache;
|
|
698
716
|
|
|
699
717
|
/**
|
|
@@ -1088,4 +1106,4 @@ declare const buildVerifyContextFromRequest: (req: Request, authority?: string)
|
|
|
1088
1106
|
/** True when the request carries an AIP credential (at least one `Agent-Identity` header). */
|
|
1089
1107
|
declare const hasAgentIdentityHeader: (req: Request) => boolean;
|
|
1090
1108
|
|
|
1091
|
-
export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, AIP_A2A_EXTENSION_URI, AIP_COVERED_COMPONENTS, AIP_SIGNATURE_TAG, type CachedQuote, CheckoutValidationError, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstMppContext, type ComputeFirstOptions, type ComputeFirstRails, type ComputeFirstSettledContext, type ComputeFirstWorkContext, type CreateDefaultOnDeniedOptions, type DefaultOnDeniedResult, DenialReason, FIXABLE_DENIAL_REASONS, type GeneratedUCPKey, type JWKSResponse, MAX_POP_WINDOW_SECONDS, type MintedRecipients, type OwnerScope, type QuoteCache, type QuoteCacheOptions, type SignMessageInput, type SignedUCPProfile, SolanaMppRailSpec, StripeRailSpec, type SuccessBodyArgs, TempoRailSpec, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, type VerifyFailureReason, type VerifyMessageSignatureInput, type VerifyMessageSignatureResult, VerifyRequestContext, VerifyWalletSignerResult, type WorkOutcome, X402BaseRailSpec, aipA2AExtension, buildA2AAgentCard, buildContactSupportNextSteps, buildJWKSResponse, buildSignerMismatchBody, buildVerificationRequiredBody, buildVerifyContextFromRequest, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hasAgentIdentityHeader, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, normalizeAddress, signMessage, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyMessageSignature, verifyUCPProfile };
|
|
1109
|
+
export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, AIP_A2A_EXTENSION_URI, AIP_COVERED_COMPONENTS, AIP_SIGNATURE_TAG, type CachedQuote, CheckoutValidationError, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstMppContext, type ComputeFirstOptions, type ComputeFirstRails, type ComputeFirstSettledContext, type ComputeFirstWorkContext, type CreateDefaultOnDeniedOptions, type DefaultOnDeniedResult, DenialReason, FIXABLE_DENIAL_REASONS, type GeneratedUCPKey, type JWKSResponse, MAX_POP_WINDOW_SECONDS, type MintedRecipients, type OwnerScope, type QuoteCache, type QuoteCacheOptions, type ResultCache, type ResultCacheOptions, type SignMessageInput, type SignedUCPProfile, SolanaMppRailSpec, StripeRailSpec, type SuccessBodyArgs, TempoRailSpec, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, type VerifyFailureReason, type VerifyMessageSignatureInput, type VerifyMessageSignatureResult, VerifyRequestContext, VerifyWalletSignerResult, type WorkOutcome, X402BaseRailSpec, aipA2AExtension, buildA2AAgentCard, buildContactSupportNextSteps, buildJWKSResponse, buildSignerMismatchBody, buildVerificationRequiredBody, buildVerifyContextFromRequest, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, createResultCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hasAgentIdentityHeader, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, normalizeAddress, signMessage, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyMessageSignature, verifyUCPProfile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { VerifyWalletSignerResult, DenialReason } from './core.js';
|
|
2
2
|
export { AccountVerification, AgentIdentity, AgentMemoryHint, AgentScoreCore, AssessResult, CreateSessionOnMissing, DenialCode, EvaluateOutcome, OperatorVerification, PolicyCheck, PolicyResult, SignerVerdict, buildAgentMemoryHint } from './core.js';
|
|
3
3
|
export { P as PaymentSigner, S as SignerNetwork, e as extractPaymentSigner, a as extractPaymentSignerFromAuth, b as extractSignerForPrecheck, r as readX402PaymentHeader } from './signer-3FAit11j.js';
|
|
4
|
-
import { q as UCPSigningKey, n as UCPProfile } from './checkout-
|
|
5
|
-
export { A as AGENTSCORE_UCP_CAPABILITY, a as AgentScoreGatePolicy, C as Checkout, b as CheckoutContext, c as CheckoutGateConfig, d as CheckoutRailSpec, e as CheckoutRequest, f as CheckoutResult, g as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, h as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, i as PricingFn, j as PricingResult, R as RecipientsFn, k as ReferenceIdFn, l as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, m as UCPPaymentHandlerBinding, o as UCPProfileBody, p as UCPServiceBinding, r as buildAipTrustedIssuers, s as buildUCPProfile, t as getIdentityStatus, u as makeMppxComposeHook, v as mppPaymentHandler, w as pricingResult, x as stripeSptPaymentHandler, y as validationEnvelope, z as validationResponseExpress, B as validationResponseFastify, E as validationResponseHono, F as validationResponseNextjs, H as validationResponseWeb, J as x402PaymentHandler } from './checkout-
|
|
4
|
+
import { q as UCPSigningKey, n as UCPProfile } from './checkout-B-Z5_EQP.js';
|
|
5
|
+
export { A as AGENTSCORE_UCP_CAPABILITY, a as AgentScoreGatePolicy, C as Checkout, b as CheckoutContext, c as CheckoutGateConfig, d as CheckoutRailSpec, e as CheckoutRequest, f as CheckoutResult, g as ComposeMppxFn, D as DiscoveryProbeConfig, G as GateDenial, I as IsCachedAddressFn, M as MountUcpRoutesOptions, h as MppxComposeOutcome, O as OnSettledFn, P as PreValidateFn, i as PricingFn, j as PricingResult, R as RecipientsFn, k as ReferenceIdFn, l as RunGateFn, S as SettleOutcome, U as UCPCapabilityBinding, m as UCPPaymentHandlerBinding, o as UCPProfileBody, p as UCPServiceBinding, r as buildAipTrustedIssuers, s as buildUCPProfile, t as getIdentityStatus, u as makeMppxComposeHook, v as mppPaymentHandler, w as pricingResult, x as stripeSptPaymentHandler, y as validationEnvelope, z as validationResponseExpress, B as validationResponseFastify, E as validationResponseHono, F as validationResponseNextjs, H as validationResponseWeb, J as x402PaymentHandler } from './checkout-B-Z5_EQP.js';
|
|
6
6
|
export { EnforcementMode, GateResult, IdentityStatus, PolicyBlock, buildGateFromPolicy, runGateWithEnforcement, shippingCountryAllowed, shippingStateAllowed, validateShippingAgainstPolicy } from './identity/policy.js';
|
|
7
|
-
import { H as HeadersLike } from './network_kind-
|
|
8
|
-
export { c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer } from './network_kind-
|
|
7
|
+
import { H as HeadersLike } from './network_kind-BmbWKNud.js';
|
|
8
|
+
export { M as MalformedPaymentCredential, c as buildDefaultCheckoutRails, d as buildMppxComposeRails, f as formatUsdCents, h as hasMppxHeader, e as hasPaymentHeader, g as hasX402Header, i as isEvmNetwork, j as isSolanaNetwork, l as loadSolanaFeePayer, m as malformedPaymentCredential } from './network_kind-BmbWKNud.js';
|
|
9
9
|
import { T as TempoRailSpec, X as X402BaseRailSpec, S as SolanaMppRailSpec, b as StripeRailSpec } from './rail_spec-BFZmW9RN.js';
|
|
10
10
|
export { c as TempoSessionRailSpec } from './rail_spec-BFZmW9RN.js';
|
|
11
11
|
import { Context } from 'hono';
|
|
@@ -653,21 +653,26 @@ declare class CheckoutValidationError extends Error {
|
|
|
653
653
|
}
|
|
654
654
|
|
|
655
655
|
/**
|
|
656
|
-
* Short-TTL body-hash
|
|
657
|
-
* (see {@link computeFirstCheckout}).
|
|
656
|
+
* Short-TTL body-hash caches.
|
|
658
657
|
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*
|
|
658
|
+
* `createResultCache` is the neutral primitive: a keyed JSON-value cache with
|
|
659
|
+
* a stable content-hash key builder. Use it to cache any per-request result a
|
|
660
|
+
* merchant computes on the probe leg and replays on the settle leg — e.g. the
|
|
661
|
+
* output of a paid upstream call made in a `Checkout.preValidate` hook, so a
|
|
662
|
+
* payment retry (or a junk payment header) never pays upstream twice.
|
|
663
|
+
*
|
|
664
|
+
* `createQuoteCache` is the compute-first-flavored wrapper used by
|
|
665
|
+
* {@link computeFirstCheckout}: the cached value is a `CachedQuote`
|
|
666
|
+
* (`{body, priceCents, recipients}`). Standard x402-fetch retry semantics
|
|
667
|
+
* resign the buyer's ORIGINAL request body — there's no `result_id` echo
|
|
668
|
+
* channel through the protocol — so both caches key by a stable content-hash
|
|
669
|
+
* of the request body. Same body → same hash → same cache slot.
|
|
665
670
|
*
|
|
666
671
|
* Default in-memory `Map`; optional `redisUrl` lazy-imports `ioredis` for
|
|
667
672
|
* multi-instance deployments. `ioredis` is an optional peer dep.
|
|
668
673
|
*/
|
|
669
|
-
interface
|
|
670
|
-
/**
|
|
674
|
+
interface ResultCacheOptions {
|
|
675
|
+
/** Entry lifetime in milliseconds. Default `5 * 60_000` (5 min). */
|
|
671
676
|
ttlMs?: number;
|
|
672
677
|
/** Redis connection URL. Default: `process.env.REDIS_URL`. When unset or the
|
|
673
678
|
* lazy `ioredis` import fails, falls back to in-process `Map`. */
|
|
@@ -675,6 +680,7 @@ interface QuoteCacheOptions {
|
|
|
675
680
|
/** Per-instance key prefix so multiple caches sharing a Redis don't collide. */
|
|
676
681
|
keyPrefix?: string;
|
|
677
682
|
}
|
|
683
|
+
type QuoteCacheOptions = ResultCacheOptions;
|
|
678
684
|
interface CachedQuote {
|
|
679
685
|
body: Record<string, unknown>;
|
|
680
686
|
priceCents: number;
|
|
@@ -683,6 +689,15 @@ interface CachedQuote {
|
|
|
683
689
|
* same logical purchase). Empty object when no `mintRecipients` hook is wired. */
|
|
684
690
|
recipients: Record<string, string>;
|
|
685
691
|
}
|
|
692
|
+
interface ResultCache<T> {
|
|
693
|
+
/** Build a stable content-hash key from a per-merchant prefix and a request body.
|
|
694
|
+
* Property order in the body does NOT affect the hash (keys are sorted recursively). */
|
|
695
|
+
bodyHashKey(prefix: string, body: Record<string, unknown>): string;
|
|
696
|
+
read(key: string): Promise<T | null>;
|
|
697
|
+
write(key: string, value: T): Promise<void>;
|
|
698
|
+
/** Clear all entries. Primarily for tests. */
|
|
699
|
+
clear(): Promise<void>;
|
|
700
|
+
}
|
|
686
701
|
interface QuoteCache {
|
|
687
702
|
/** Build a stable content-hash key from a per-merchant prefix and a request body.
|
|
688
703
|
* Property order in the body does NOT affect the hash (keys are sorted recursively). */
|
|
@@ -692,8 +707,11 @@ interface QuoteCache {
|
|
|
692
707
|
/** Clear all entries. Primarily for tests. */
|
|
693
708
|
clear(): Promise<void>;
|
|
694
709
|
}
|
|
695
|
-
/** Build a fresh cache. Each call owns its own state (memory
|
|
696
|
-
* client). */
|
|
710
|
+
/** Build a fresh neutral result cache. Each call owns its own state (memory
|
|
711
|
+
* map + Redis client). Values must survive `JSON.stringify` round-trips. */
|
|
712
|
+
declare function createResultCache<T>(opts?: ResultCacheOptions): ResultCache<T>;
|
|
713
|
+
/** Build a fresh compute-first quote cache (a `ResultCache<CachedQuote>` with
|
|
714
|
+
* the quote-shaped `write` signature). */
|
|
697
715
|
declare function createQuoteCache(opts?: QuoteCacheOptions): QuoteCache;
|
|
698
716
|
|
|
699
717
|
/**
|
|
@@ -1088,4 +1106,4 @@ declare const buildVerifyContextFromRequest: (req: Request, authority?: string)
|
|
|
1088
1106
|
/** True when the request carries an AIP credential (at least one `Agent-Identity` header). */
|
|
1089
1107
|
declare const hasAgentIdentityHeader: (req: Request) => boolean;
|
|
1090
1108
|
|
|
1091
|
-
export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, AIP_A2A_EXTENSION_URI, AIP_COVERED_COMPONENTS, AIP_SIGNATURE_TAG, type CachedQuote, CheckoutValidationError, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstMppContext, type ComputeFirstOptions, type ComputeFirstRails, type ComputeFirstSettledContext, type ComputeFirstWorkContext, type CreateDefaultOnDeniedOptions, type DefaultOnDeniedResult, DenialReason, FIXABLE_DENIAL_REASONS, type GeneratedUCPKey, type JWKSResponse, MAX_POP_WINDOW_SECONDS, type MintedRecipients, type OwnerScope, type QuoteCache, type QuoteCacheOptions, type SignMessageInput, type SignedUCPProfile, SolanaMppRailSpec, StripeRailSpec, type SuccessBodyArgs, TempoRailSpec, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, type VerifyFailureReason, type VerifyMessageSignatureInput, type VerifyMessageSignatureResult, VerifyRequestContext, VerifyWalletSignerResult, type WorkOutcome, X402BaseRailSpec, aipA2AExtension, buildA2AAgentCard, buildContactSupportNextSteps, buildJWKSResponse, buildSignerMismatchBody, buildVerificationRequiredBody, buildVerifyContextFromRequest, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hasAgentIdentityHeader, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, normalizeAddress, signMessage, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyMessageSignature, verifyUCPProfile };
|
|
1109
|
+
export { type A2AAgentCard, type A2AAgentCardCapabilities, type A2AAgentCardExtension, type A2AAgentCardSignature, type A2AAgentInterface, type A2AAgentProvider, type A2AAgentSkill, A2A_DEFAULT_TRANSPORT, A2A_PROTOCOL_VERSION, AIP_A2A_EXTENSION_URI, AIP_COVERED_COMPONENTS, AIP_SIGNATURE_TAG, type CachedQuote, CheckoutValidationError, type ComputeFirstHandler, type ComputeFirstMintContext, type ComputeFirstMppContext, type ComputeFirstOptions, type ComputeFirstRails, type ComputeFirstSettledContext, type ComputeFirstWorkContext, type CreateDefaultOnDeniedOptions, type DefaultOnDeniedResult, DenialReason, FIXABLE_DENIAL_REASONS, type GeneratedUCPKey, type JWKSResponse, MAX_POP_WINDOW_SECONDS, type MintedRecipients, type OwnerScope, type QuoteCache, type QuoteCacheOptions, type ResultCache, type ResultCacheOptions, type SignMessageInput, type SignedUCPProfile, SolanaMppRailSpec, StripeRailSpec, type SuccessBodyArgs, TempoRailSpec, UCPProfile, UCPSigningKey, UCPVerificationError, UCP_A2A_EXTENSION_URI, type VerifyFailureReason, type VerifyMessageSignatureInput, type VerifyMessageSignatureResult, VerifyRequestContext, VerifyWalletSignerResult, type WorkOutcome, X402BaseRailSpec, aipA2AExtension, buildA2AAgentCard, buildContactSupportNextSteps, buildJWKSResponse, buildSignerMismatchBody, buildVerificationRequiredBody, buildVerifyContextFromRequest, computeFirstCheckout, createDefaultOnDenied, createQuoteCache, createResultCache, defaultReadOnlyOnDenied, denialReasonStatus, denialReasonToBody, extractOwnerScope, generateUCPSigningKey, hasAgentIdentityHeader, hashOperatorToken, isFixableDenial, loadUCPSigningKeyFromEnv, normalizeAddress, signMessage, signUCPProfile, ucpA2AExtension, verificationAgentInstructions, verifyMessageSignature, verifyUCPProfile };
|
package/dist/index.js
CHANGED
|
@@ -22253,6 +22253,7 @@ __export(index_exports, {
|
|
|
22253
22253
|
computeFirstCheckout: () => computeFirstCheckout,
|
|
22254
22254
|
createDefaultOnDenied: () => createDefaultOnDenied,
|
|
22255
22255
|
createQuoteCache: () => createQuoteCache,
|
|
22256
|
+
createResultCache: () => createResultCache,
|
|
22256
22257
|
defaultReadOnlyOnDenied: () => defaultReadOnlyOnDenied,
|
|
22257
22258
|
denialReasonStatus: () => denialReasonStatus,
|
|
22258
22259
|
denialReasonToBody: () => denialReasonToBody,
|
|
@@ -22277,6 +22278,7 @@ __export(index_exports, {
|
|
|
22277
22278
|
loadSolanaFeePayer: () => loadSolanaFeePayer,
|
|
22278
22279
|
loadUCPSigningKeyFromEnv: () => loadUCPSigningKeyFromEnv,
|
|
22279
22280
|
makeMppxComposeHook: () => makeMppxComposeHook,
|
|
22281
|
+
malformedPaymentCredential: () => malformedPaymentCredential,
|
|
22280
22282
|
mppPaymentHandler: () => mppPaymentHandler,
|
|
22281
22283
|
normalizeAddress: () => normalizeAddress,
|
|
22282
22284
|
pricingResult: () => pricingResult,
|
|
@@ -22664,7 +22666,7 @@ function createAgentScoreCore(options) {
|
|
|
22664
22666
|
} = options;
|
|
22665
22667
|
const baseUrl = stripTrailingSlashes(rawBaseUrl);
|
|
22666
22668
|
const agentMemoryHint = buildAgentMemoryHint(aipTrustedIssuers);
|
|
22667
|
-
const defaultUa = `@agent-score/commerce@${"2.6.
|
|
22669
|
+
const defaultUa = `@agent-score/commerce@${"2.6.4"}`;
|
|
22668
22670
|
const userAgentHeader = userAgent ? `${userAgent} (${defaultUa})` : defaultUa;
|
|
22669
22671
|
const sdk = new import_sdk.AgentScore({ apiKey, baseUrl, userAgent: userAgentHeader });
|
|
22670
22672
|
const sessionSdkCache = /* @__PURE__ */ new Map();
|
|
@@ -23291,6 +23293,39 @@ function hasMppxHeader(input) {
|
|
|
23291
23293
|
const headers = asHeaders(input);
|
|
23292
23294
|
return Boolean(readHeader(headers, "authorization")?.startsWith("Payment "));
|
|
23293
23295
|
}
|
|
23296
|
+
var JWT_SHAPE_RE = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
|
|
23297
|
+
function decodesToJsonObject(token) {
|
|
23298
|
+
try {
|
|
23299
|
+
const parsed = JSON.parse(Buffer.from(token, "base64").toString("utf8"));
|
|
23300
|
+
return typeof parsed === "object" && parsed !== null;
|
|
23301
|
+
} catch {
|
|
23302
|
+
return false;
|
|
23303
|
+
}
|
|
23304
|
+
}
|
|
23305
|
+
function malformedPaymentCredential(input) {
|
|
23306
|
+
const headers = asHeaders(input);
|
|
23307
|
+
const x402Token = readHeader(headers, "payment-signature") ?? readHeader(headers, "x-payment");
|
|
23308
|
+
if (x402Token !== null && x402Token.length > 0) {
|
|
23309
|
+
if (!decodesToJsonObject(x402Token)) {
|
|
23310
|
+
return {
|
|
23311
|
+
channel: "x402",
|
|
23312
|
+
message: "X-Payment header is not decodable base64 JSON."
|
|
23313
|
+
};
|
|
23314
|
+
}
|
|
23315
|
+
return null;
|
|
23316
|
+
}
|
|
23317
|
+
const auth = readHeader(headers, "authorization");
|
|
23318
|
+
if (auth !== null && auth.startsWith("Payment ")) {
|
|
23319
|
+
const token = auth.slice("Payment ".length).trim();
|
|
23320
|
+
if (token.length === 0 || !decodesToJsonObject(token) && !JWT_SHAPE_RE.test(token)) {
|
|
23321
|
+
return {
|
|
23322
|
+
channel: "mpp",
|
|
23323
|
+
message: "Authorization: Payment credential is neither base64-encoded JSON nor a token-shaped value."
|
|
23324
|
+
};
|
|
23325
|
+
}
|
|
23326
|
+
}
|
|
23327
|
+
return null;
|
|
23328
|
+
}
|
|
23294
23329
|
|
|
23295
23330
|
// src/identity/tokens.ts
|
|
23296
23331
|
function hashOperatorToken(plaintext) {
|
|
@@ -25530,6 +25565,7 @@ var Checkout = class {
|
|
|
25530
25565
|
* agent-supplied `payTo` to this set (anti funds-drain). Empty for pure per-order minting. */
|
|
25531
25566
|
x402StaticRecipients;
|
|
25532
25567
|
zeroSettleCarveOut;
|
|
25568
|
+
credentialPreCheck;
|
|
25533
25569
|
gate;
|
|
25534
25570
|
discoveryExtensions;
|
|
25535
25571
|
resourceInfo;
|
|
@@ -25611,6 +25647,7 @@ var Checkout = class {
|
|
|
25611
25647
|
this.isCachedAddress = opts.isCachedAddress;
|
|
25612
25648
|
this.x402StaticRecipients = collectStaticX402Recipients(opts.rails);
|
|
25613
25649
|
this.zeroSettleCarveOut = opts.zeroSettleCarveOut ?? false;
|
|
25650
|
+
this.credentialPreCheck = opts.credentialPreCheck ?? true;
|
|
25614
25651
|
this.gate = opts.gate;
|
|
25615
25652
|
this.discoveryExtensions = opts.discoveryExtensions;
|
|
25616
25653
|
this.resourceInfo = opts.resourceInfo;
|
|
@@ -25748,6 +25785,27 @@ var Checkout = class {
|
|
|
25748
25785
|
};
|
|
25749
25786
|
}
|
|
25750
25787
|
}
|
|
25788
|
+
if (this.credentialPreCheck) {
|
|
25789
|
+
const malformed = malformedPaymentCredential(request.headers);
|
|
25790
|
+
const enforced = malformed !== null && (malformed.channel === "x402" ? this.x402ServerAvailable() && this.x402BaseNetwork !== null : this.composeMppx !== void 0);
|
|
25791
|
+
if (enforced) {
|
|
25792
|
+
return {
|
|
25793
|
+
status: 400,
|
|
25794
|
+
body: buildValidationError({
|
|
25795
|
+
code: "payment_proof_invalid",
|
|
25796
|
+
message: malformed.message,
|
|
25797
|
+
nextSteps: {
|
|
25798
|
+
action: "regenerate_payment_credential",
|
|
25799
|
+
user_message: "The payment credential could not be decoded. Rebuild it from a fresh 402 challenge and retry."
|
|
25800
|
+
}
|
|
25801
|
+
}),
|
|
25802
|
+
headers: {},
|
|
25803
|
+
referenceId: ctx.referenceId,
|
|
25804
|
+
settled: false,
|
|
25805
|
+
settlePhase: "credential_malformed"
|
|
25806
|
+
};
|
|
25807
|
+
}
|
|
25808
|
+
}
|
|
25751
25809
|
if (this.preValidate !== void 0) {
|
|
25752
25810
|
try {
|
|
25753
25811
|
const state = await this.preValidate(ctx);
|
|
@@ -26070,21 +26128,34 @@ var Checkout = class {
|
|
|
26070
26128
|
if (ctx.pricing.amountUsd !== 0) return null;
|
|
26071
26129
|
const headers = normalizeHeadersToLowercase(ctx.request.headers);
|
|
26072
26130
|
let zero;
|
|
26131
|
+
let railKey;
|
|
26073
26132
|
if (rail === "x402-base") {
|
|
26074
|
-
const
|
|
26075
|
-
|
|
26076
|
-
|
|
26077
|
-
|
|
26078
|
-
|
|
26079
|
-
|
|
26080
|
-
|
|
26081
|
-
|
|
26133
|
+
const fakeRequest = new Request(ctx.request.url, {
|
|
26134
|
+
method: ctx.request.method,
|
|
26135
|
+
headers: ctx.request.headers
|
|
26136
|
+
});
|
|
26137
|
+
const verified = await verifyX402Request({
|
|
26138
|
+
request: fakeRequest,
|
|
26139
|
+
isCachedAddress: (addr) => this.asyncIsCachedAddress(addr, ctx),
|
|
26140
|
+
acceptedNetwork: this.x402BaseNetwork ?? ""
|
|
26141
|
+
});
|
|
26142
|
+
if (!verified.ok) {
|
|
26143
|
+
return {
|
|
26144
|
+
status: verified.status,
|
|
26145
|
+
body: verified.body,
|
|
26146
|
+
headers: {},
|
|
26147
|
+
referenceId: ctx.referenceId,
|
|
26148
|
+
settled: false,
|
|
26149
|
+
settlePhase: "verify_failed"
|
|
26150
|
+
};
|
|
26082
26151
|
}
|
|
26083
|
-
zero = zeroAmountCarveOut({ rail, payload });
|
|
26152
|
+
zero = zeroAmountCarveOut({ rail, payload: verified.payload });
|
|
26153
|
+
railKey = this.x402RailKey();
|
|
26084
26154
|
} else {
|
|
26085
26155
|
zero = zeroAmountCarveOut({ rail, authorizationHeader: headers["authorization"] });
|
|
26156
|
+
if (zero.signerNetwork !== "solana") return null;
|
|
26157
|
+
railKey = this.railsKeyForMppxMethod("solana") ?? this.mppRailKey();
|
|
26086
26158
|
}
|
|
26087
|
-
const railKey = rail === "x402-base" ? this.x402RailKey() : this.mppRailKey();
|
|
26088
26159
|
const outcome = {
|
|
26089
26160
|
rail: rail === "x402-base" ? "x402" : "mpp",
|
|
26090
26161
|
paymentResponseHeader: null,
|
|
@@ -26880,11 +26951,11 @@ function canonicalize2(value) {
|
|
|
26880
26951
|
}
|
|
26881
26952
|
return value;
|
|
26882
26953
|
}
|
|
26883
|
-
function
|
|
26954
|
+
function createResultCache(opts = {}) {
|
|
26884
26955
|
const ttlMs = opts.ttlMs ?? 5 * 6e4;
|
|
26885
|
-
const keyPrefix = opts.keyPrefix ?? "
|
|
26956
|
+
const keyPrefix = opts.keyPrefix ?? "result:";
|
|
26886
26957
|
const memMap = /* @__PURE__ */ new Map();
|
|
26887
|
-
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "
|
|
26958
|
+
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "result-cache" });
|
|
26888
26959
|
const evictExpired = () => {
|
|
26889
26960
|
const now = Date.now();
|
|
26890
26961
|
for (const [k, v] of memMap.entries()) {
|
|
@@ -26911,17 +26982,16 @@ function createQuoteCache(opts = {}) {
|
|
|
26911
26982
|
const entry = memMap.get(key);
|
|
26912
26983
|
return entry ? entry.entry : null;
|
|
26913
26984
|
},
|
|
26914
|
-
async write(key,
|
|
26915
|
-
const cached2 = { body, priceCents, recipients };
|
|
26985
|
+
async write(key, value) {
|
|
26916
26986
|
const r = await getRedis();
|
|
26917
26987
|
if (r) {
|
|
26918
26988
|
try {
|
|
26919
|
-
await r.set(`${keyPrefix}${key}`, JSON.stringify(
|
|
26989
|
+
await r.set(`${keyPrefix}${key}`, JSON.stringify(value), "PX", ttlMs);
|
|
26920
26990
|
return;
|
|
26921
26991
|
} catch {
|
|
26922
26992
|
}
|
|
26923
26993
|
}
|
|
26924
|
-
memMap.set(key, { entry:
|
|
26994
|
+
memMap.set(key, { entry: value, expiresAt: Date.now() + ttlMs });
|
|
26925
26995
|
},
|
|
26926
26996
|
async clear() {
|
|
26927
26997
|
memMap.clear();
|
|
@@ -26935,6 +27005,17 @@ function createQuoteCache(opts = {}) {
|
|
|
26935
27005
|
}
|
|
26936
27006
|
};
|
|
26937
27007
|
}
|
|
27008
|
+
function createQuoteCache(opts = {}) {
|
|
27009
|
+
const cache = createResultCache({ ...opts, keyPrefix: opts.keyPrefix ?? "quote:" });
|
|
27010
|
+
return {
|
|
27011
|
+
bodyHashKey: cache.bodyHashKey,
|
|
27012
|
+
read: cache.read,
|
|
27013
|
+
async write(key, body, priceCents, recipients = {}) {
|
|
27014
|
+
await cache.write(key, { body, priceCents, recipients });
|
|
27015
|
+
},
|
|
27016
|
+
clear: cache.clear
|
|
27017
|
+
};
|
|
27018
|
+
}
|
|
26938
27019
|
|
|
26939
27020
|
// src/checkout_compute_first.ts
|
|
26940
27021
|
var DEFAULT_TTL_MS = 5 * 6e4;
|
|
@@ -27452,6 +27533,7 @@ function defaultReadOnlyOnDenied(reason) {
|
|
|
27452
27533
|
computeFirstCheckout,
|
|
27453
27534
|
createDefaultOnDenied,
|
|
27454
27535
|
createQuoteCache,
|
|
27536
|
+
createResultCache,
|
|
27455
27537
|
defaultReadOnlyOnDenied,
|
|
27456
27538
|
denialReasonStatus,
|
|
27457
27539
|
denialReasonToBody,
|
|
@@ -27476,6 +27558,7 @@ function defaultReadOnlyOnDenied(reason) {
|
|
|
27476
27558
|
loadSolanaFeePayer,
|
|
27477
27559
|
loadUCPSigningKeyFromEnv,
|
|
27478
27560
|
makeMppxComposeHook,
|
|
27561
|
+
malformedPaymentCredential,
|
|
27479
27562
|
mppPaymentHandler,
|
|
27480
27563
|
normalizeAddress,
|
|
27481
27564
|
pricingResult,
|