@agent-score/commerce 2.6.3 → 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.
Files changed (41) hide show
  1. package/dist/{checkout-C4RD7M0Z.d.ts → checkout-B-Z5_EQP.d.ts} +9 -0
  2. package/dist/{checkout-CzB9f_jf.d.mts → checkout-BtdHSF_w.d.mts} +9 -0
  3. package/dist/core.js +1 -1
  4. package/dist/core.mjs +1 -1
  5. package/dist/discovery/index.d.mts +1 -1
  6. package/dist/discovery/index.d.ts +1 -1
  7. package/dist/identity/express.js +1 -1
  8. package/dist/identity/express.js.map +1 -1
  9. package/dist/identity/express.mjs +1 -1
  10. package/dist/identity/express.mjs.map +1 -1
  11. package/dist/identity/fastify.js +1 -1
  12. package/dist/identity/fastify.js.map +1 -1
  13. package/dist/identity/fastify.mjs +1 -1
  14. package/dist/identity/fastify.mjs.map +1 -1
  15. package/dist/identity/hono.js +1 -1
  16. package/dist/identity/hono.js.map +1 -1
  17. package/dist/identity/hono.mjs +1 -1
  18. package/dist/identity/hono.mjs.map +1 -1
  19. package/dist/identity/nextjs.js +1 -1
  20. package/dist/identity/nextjs.js.map +1 -1
  21. package/dist/identity/nextjs.mjs +1 -1
  22. package/dist/identity/nextjs.mjs.map +1 -1
  23. package/dist/identity/web.js +1 -1
  24. package/dist/identity/web.js.map +1 -1
  25. package/dist/identity/web.mjs +1 -1
  26. package/dist/identity/web.mjs.map +1 -1
  27. package/dist/index.d.mts +35 -17
  28. package/dist/index.d.ts +35 -17
  29. package/dist/index.js +80 -9
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +78 -9
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/{network_kind-BIJM2peR.d.ts → network_kind-BmbWKNud.d.ts} +23 -1
  34. package/dist/{network_kind-C0EMkdzz.d.mts → network_kind-D2xpo2Fj.d.mts} +23 -1
  35. package/dist/payment/index.d.mts +27 -20
  36. package/dist/payment/index.d.ts +27 -20
  37. package/dist/payment/index.js +35 -0
  38. package/dist/payment/index.js.map +1 -1
  39. package/dist/payment/index.mjs +34 -0
  40. package/dist/payment/index.mjs.map +1 -1
  41. package/package.json +1 -1
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-CzB9f_jf.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-CzB9f_jf.mjs';
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-C0EMkdzz.mjs';
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-C0EMkdzz.mjs';
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 quote cache for the compute-first + exact-x402 pattern
657
- * (see {@link computeFirstCheckout}).
656
+ * Short-TTL body-hash caches.
658
657
  *
659
- * Standard x402-fetch retry semantics resign the buyer's ORIGINAL request body
660
- * there's no `result_id` echo channel through the protocol. The cache is
661
- * therefore keyed by a stable content-hash of the request body. Same body
662
- * same hash same cache slot. The probe leg writes (run-work cache); the
663
- * settle leg reads (cache hit settle exact at the cached price → return the
664
- * cached body).
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 QuoteCacheOptions {
670
- /** Quote lifetime in milliseconds. Default `5 * 60_000` (5 min). */
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 map + Redis
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-C4RD7M0Z.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-C4RD7M0Z.js';
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-BIJM2peR.js';
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-BIJM2peR.js';
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 quote cache for the compute-first + exact-x402 pattern
657
- * (see {@link computeFirstCheckout}).
656
+ * Short-TTL body-hash caches.
658
657
  *
659
- * Standard x402-fetch retry semantics resign the buyer's ORIGINAL request body
660
- * there's no `result_id` echo channel through the protocol. The cache is
661
- * therefore keyed by a stable content-hash of the request body. Same body
662
- * same hash same cache slot. The probe leg writes (run-work cache); the
663
- * settle leg reads (cache hit settle exact at the cached price → return the
664
- * cached body).
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 QuoteCacheOptions {
670
- /** Quote lifetime in milliseconds. Default `5 * 60_000` (5 min). */
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 map + Redis
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.3"}`;
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);
@@ -26095,7 +26153,8 @@ var Checkout = class {
26095
26153
  railKey = this.x402RailKey();
26096
26154
  } else {
26097
26155
  zero = zeroAmountCarveOut({ rail, authorizationHeader: headers["authorization"] });
26098
- railKey = (zero.signerNetwork !== null ? this.railsKeyForMppxMethod(zero.signerNetwork === "solana" ? "solana" : "tempo") : void 0) ?? this.mppRailKey();
26156
+ if (zero.signerNetwork !== "solana") return null;
26157
+ railKey = this.railsKeyForMppxMethod("solana") ?? this.mppRailKey();
26099
26158
  }
26100
26159
  const outcome = {
26101
26160
  rail: rail === "x402-base" ? "x402" : "mpp",
@@ -26892,11 +26951,11 @@ function canonicalize2(value) {
26892
26951
  }
26893
26952
  return value;
26894
26953
  }
26895
- function createQuoteCache(opts = {}) {
26954
+ function createResultCache(opts = {}) {
26896
26955
  const ttlMs = opts.ttlMs ?? 5 * 6e4;
26897
- const keyPrefix = opts.keyPrefix ?? "quote:";
26956
+ const keyPrefix = opts.keyPrefix ?? "result:";
26898
26957
  const memMap = /* @__PURE__ */ new Map();
26899
- const getRedis = memoizedRedis({ url: opts.redisUrl, label: "quote-cache" });
26958
+ const getRedis = memoizedRedis({ url: opts.redisUrl, label: "result-cache" });
26900
26959
  const evictExpired = () => {
26901
26960
  const now = Date.now();
26902
26961
  for (const [k, v] of memMap.entries()) {
@@ -26923,17 +26982,16 @@ function createQuoteCache(opts = {}) {
26923
26982
  const entry = memMap.get(key);
26924
26983
  return entry ? entry.entry : null;
26925
26984
  },
26926
- async write(key, body, priceCents, recipients = {}) {
26927
- const cached2 = { body, priceCents, recipients };
26985
+ async write(key, value) {
26928
26986
  const r = await getRedis();
26929
26987
  if (r) {
26930
26988
  try {
26931
- await r.set(`${keyPrefix}${key}`, JSON.stringify(cached2), "PX", ttlMs);
26989
+ await r.set(`${keyPrefix}${key}`, JSON.stringify(value), "PX", ttlMs);
26932
26990
  return;
26933
26991
  } catch {
26934
26992
  }
26935
26993
  }
26936
- memMap.set(key, { entry: cached2, expiresAt: Date.now() + ttlMs });
26994
+ memMap.set(key, { entry: value, expiresAt: Date.now() + ttlMs });
26937
26995
  },
26938
26996
  async clear() {
26939
26997
  memMap.clear();
@@ -26947,6 +27005,17 @@ function createQuoteCache(opts = {}) {
26947
27005
  }
26948
27006
  };
26949
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
+ }
26950
27019
 
26951
27020
  // src/checkout_compute_first.ts
26952
27021
  var DEFAULT_TTL_MS = 5 * 6e4;
@@ -27464,6 +27533,7 @@ function defaultReadOnlyOnDenied(reason) {
27464
27533
  computeFirstCheckout,
27465
27534
  createDefaultOnDenied,
27466
27535
  createQuoteCache,
27536
+ createResultCache,
27467
27537
  defaultReadOnlyOnDenied,
27468
27538
  denialReasonStatus,
27469
27539
  denialReasonToBody,
@@ -27488,6 +27558,7 @@ function defaultReadOnlyOnDenied(reason) {
27488
27558
  loadSolanaFeePayer,
27489
27559
  loadUCPSigningKeyFromEnv,
27490
27560
  makeMppxComposeHook,
27561
+ malformedPaymentCredential,
27491
27562
  mppPaymentHandler,
27492
27563
  normalizeAddress,
27493
27564
  pricingResult,