@agent-score/commerce 2.6.3 → 2.6.5
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 +2 -2
- package/dist/{checkout-CzB9f_jf.d.mts → checkout-DOd9GDmt.d.mts} +15 -3
- package/dist/{checkout-C4RD7M0Z.d.ts → checkout-GcDNDzSK.d.ts} +15 -3
- 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 +99 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -9
- 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 +42 -21
- package/dist/payment/index.d.ts +42 -21
- package/dist/payment/index.js +53 -0
- package/dist/payment/index.js.map +1 -1
- package/dist/payment/index.mjs +51 -0
- package/dist/payment/index.mjs.map +1 -1
- 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-
|
|
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-DOd9GDmt.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-DOd9GDmt.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-GcDNDzSK.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-GcDNDzSK.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.5"}`;
|
|
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) {
|
|
@@ -25278,6 +25313,22 @@ function x402SignerFromPayload(payload) {
|
|
|
25278
25313
|
txHash: null
|
|
25279
25314
|
};
|
|
25280
25315
|
}
|
|
25316
|
+
function mppCredentialPayloadType(authorizationHeader) {
|
|
25317
|
+
if (typeof authorizationHeader !== "string") return null;
|
|
25318
|
+
if (!authorizationHeader.toLowerCase().startsWith("payment ")) return null;
|
|
25319
|
+
const token = authorizationHeader.slice("payment ".length).trim();
|
|
25320
|
+
if (!token) return null;
|
|
25321
|
+
try {
|
|
25322
|
+
const credential = JSON.parse(atob(token));
|
|
25323
|
+
if (!credential || typeof credential !== "object") return null;
|
|
25324
|
+
const payload = credential.payload;
|
|
25325
|
+
if (!payload || typeof payload !== "object") return null;
|
|
25326
|
+
const type = payload.type;
|
|
25327
|
+
return typeof type === "string" ? type : null;
|
|
25328
|
+
} catch {
|
|
25329
|
+
return null;
|
|
25330
|
+
}
|
|
25331
|
+
}
|
|
25281
25332
|
function mppSignerFromAuth(authorizationHeader) {
|
|
25282
25333
|
if (typeof authorizationHeader !== "string") return NULL_RESULT;
|
|
25283
25334
|
if (!authorizationHeader.toLowerCase().startsWith("payment ")) return NULL_RESULT;
|
|
@@ -25530,6 +25581,7 @@ var Checkout = class {
|
|
|
25530
25581
|
* agent-supplied `payTo` to this set (anti funds-drain). Empty for pure per-order minting. */
|
|
25531
25582
|
x402StaticRecipients;
|
|
25532
25583
|
zeroSettleCarveOut;
|
|
25584
|
+
credentialPreCheck;
|
|
25533
25585
|
gate;
|
|
25534
25586
|
discoveryExtensions;
|
|
25535
25587
|
resourceInfo;
|
|
@@ -25611,6 +25663,7 @@ var Checkout = class {
|
|
|
25611
25663
|
this.isCachedAddress = opts.isCachedAddress;
|
|
25612
25664
|
this.x402StaticRecipients = collectStaticX402Recipients(opts.rails);
|
|
25613
25665
|
this.zeroSettleCarveOut = opts.zeroSettleCarveOut ?? false;
|
|
25666
|
+
this.credentialPreCheck = opts.credentialPreCheck ?? true;
|
|
25614
25667
|
this.gate = opts.gate;
|
|
25615
25668
|
this.discoveryExtensions = opts.discoveryExtensions;
|
|
25616
25669
|
this.resourceInfo = opts.resourceInfo;
|
|
@@ -25748,6 +25801,27 @@ var Checkout = class {
|
|
|
25748
25801
|
};
|
|
25749
25802
|
}
|
|
25750
25803
|
}
|
|
25804
|
+
if (this.credentialPreCheck) {
|
|
25805
|
+
const malformed = malformedPaymentCredential(request.headers);
|
|
25806
|
+
const enforced = malformed !== null && (malformed.channel === "x402" ? this.x402ServerAvailable() && this.x402BaseNetwork !== null : this.composeMppx !== void 0);
|
|
25807
|
+
if (enforced) {
|
|
25808
|
+
return {
|
|
25809
|
+
status: 400,
|
|
25810
|
+
body: buildValidationError({
|
|
25811
|
+
code: "payment_proof_invalid",
|
|
25812
|
+
message: malformed.message,
|
|
25813
|
+
nextSteps: {
|
|
25814
|
+
action: "regenerate_payment_credential",
|
|
25815
|
+
user_message: "The payment credential could not be decoded. Rebuild it from a fresh 402 challenge and retry."
|
|
25816
|
+
}
|
|
25817
|
+
}),
|
|
25818
|
+
headers: {},
|
|
25819
|
+
referenceId: ctx.referenceId,
|
|
25820
|
+
settled: false,
|
|
25821
|
+
settlePhase: "credential_malformed"
|
|
25822
|
+
};
|
|
25823
|
+
}
|
|
25824
|
+
}
|
|
25751
25825
|
if (this.preValidate !== void 0) {
|
|
25752
25826
|
try {
|
|
25753
25827
|
const state = await this.preValidate(ctx);
|
|
@@ -26094,7 +26168,11 @@ var Checkout = class {
|
|
|
26094
26168
|
zero = zeroAmountCarveOut({ rail, payload: verified.payload });
|
|
26095
26169
|
railKey = this.x402RailKey();
|
|
26096
26170
|
} else {
|
|
26097
|
-
|
|
26171
|
+
const authHeader = headers["authorization"] ?? null;
|
|
26172
|
+
if (mppCredentialPayloadType(authHeader) === "proof") return null;
|
|
26173
|
+
const inline = zeroAmountCarveOut({ rail, authorizationHeader: authHeader });
|
|
26174
|
+
const extracted = await extractPaymentSignerFromAuth(authHeader);
|
|
26175
|
+
zero = extracted !== null ? { signerAddress: extracted.address, signerNetwork: extracted.network, txHash: null } : inline;
|
|
26098
26176
|
railKey = (zero.signerNetwork !== null ? this.railsKeyForMppxMethod(zero.signerNetwork === "solana" ? "solana" : "tempo") : void 0) ?? this.mppRailKey();
|
|
26099
26177
|
}
|
|
26100
26178
|
const outcome = {
|
|
@@ -26892,11 +26970,11 @@ function canonicalize2(value) {
|
|
|
26892
26970
|
}
|
|
26893
26971
|
return value;
|
|
26894
26972
|
}
|
|
26895
|
-
function
|
|
26973
|
+
function createResultCache(opts = {}) {
|
|
26896
26974
|
const ttlMs = opts.ttlMs ?? 5 * 6e4;
|
|
26897
|
-
const keyPrefix = opts.keyPrefix ?? "
|
|
26975
|
+
const keyPrefix = opts.keyPrefix ?? "result:";
|
|
26898
26976
|
const memMap = /* @__PURE__ */ new Map();
|
|
26899
|
-
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "
|
|
26977
|
+
const getRedis = memoizedRedis({ url: opts.redisUrl, label: "result-cache" });
|
|
26900
26978
|
const evictExpired = () => {
|
|
26901
26979
|
const now = Date.now();
|
|
26902
26980
|
for (const [k, v] of memMap.entries()) {
|
|
@@ -26923,17 +27001,16 @@ function createQuoteCache(opts = {}) {
|
|
|
26923
27001
|
const entry = memMap.get(key);
|
|
26924
27002
|
return entry ? entry.entry : null;
|
|
26925
27003
|
},
|
|
26926
|
-
async write(key,
|
|
26927
|
-
const cached2 = { body, priceCents, recipients };
|
|
27004
|
+
async write(key, value) {
|
|
26928
27005
|
const r = await getRedis();
|
|
26929
27006
|
if (r) {
|
|
26930
27007
|
try {
|
|
26931
|
-
await r.set(`${keyPrefix}${key}`, JSON.stringify(
|
|
27008
|
+
await r.set(`${keyPrefix}${key}`, JSON.stringify(value), "PX", ttlMs);
|
|
26932
27009
|
return;
|
|
26933
27010
|
} catch {
|
|
26934
27011
|
}
|
|
26935
27012
|
}
|
|
26936
|
-
memMap.set(key, { entry:
|
|
27013
|
+
memMap.set(key, { entry: value, expiresAt: Date.now() + ttlMs });
|
|
26937
27014
|
},
|
|
26938
27015
|
async clear() {
|
|
26939
27016
|
memMap.clear();
|
|
@@ -26947,6 +27024,17 @@ function createQuoteCache(opts = {}) {
|
|
|
26947
27024
|
}
|
|
26948
27025
|
};
|
|
26949
27026
|
}
|
|
27027
|
+
function createQuoteCache(opts = {}) {
|
|
27028
|
+
const cache = createResultCache({ ...opts, keyPrefix: opts.keyPrefix ?? "quote:" });
|
|
27029
|
+
return {
|
|
27030
|
+
bodyHashKey: cache.bodyHashKey,
|
|
27031
|
+
read: cache.read,
|
|
27032
|
+
async write(key, body, priceCents, recipients = {}) {
|
|
27033
|
+
await cache.write(key, { body, priceCents, recipients });
|
|
27034
|
+
},
|
|
27035
|
+
clear: cache.clear
|
|
27036
|
+
};
|
|
27037
|
+
}
|
|
26950
27038
|
|
|
26951
27039
|
// src/checkout_compute_first.ts
|
|
26952
27040
|
var DEFAULT_TTL_MS = 5 * 6e4;
|
|
@@ -27464,6 +27552,7 @@ function defaultReadOnlyOnDenied(reason) {
|
|
|
27464
27552
|
computeFirstCheckout,
|
|
27465
27553
|
createDefaultOnDenied,
|
|
27466
27554
|
createQuoteCache,
|
|
27555
|
+
createResultCache,
|
|
27467
27556
|
defaultReadOnlyOnDenied,
|
|
27468
27557
|
denialReasonStatus,
|
|
27469
27558
|
denialReasonToBody,
|
|
@@ -27488,6 +27577,7 @@ function defaultReadOnlyOnDenied(reason) {
|
|
|
27488
27577
|
loadSolanaFeePayer,
|
|
27489
27578
|
loadUCPSigningKeyFromEnv,
|
|
27490
27579
|
makeMppxComposeHook,
|
|
27580
|
+
malformedPaymentCredential,
|
|
27491
27581
|
mppPaymentHandler,
|
|
27492
27582
|
normalizeAddress,
|
|
27493
27583
|
pricingResult,
|