@agent-score/commerce 2.7.4 → 2.7.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.
@@ -403,27 +403,27 @@ declare function classifyX402SettleResult(result: ProcessX402SettleResult): Clas
403
403
  */
404
404
  declare function classifyOrchestrationError(err: unknown): ClassifiedX402Error | null;
405
405
  /**
406
- * Reshape a decoded X-Payment payload into the lean canonical x402 PaymentPayload the
407
- * facilitator's verify/settle endpoints validate: `{ x402Version, scheme, network, payload }`.
408
- *
409
- * agentscore-pay (and other x402 clients) transmit a richer wire shape: the chosen
410
- * requirement is nested under `accepted` (which `verifyX402Request` reads for network/payTo),
411
- * and the 402 challenge's `extensions` (Bazaar input schema) + `resource` blocks are echoed
412
- * alongside the signed `payload`. None of that is part of the EIP-3009 signature; the
413
- * signature covers only `payload.authorization`; but CDP's `/x402/verify` validates the
414
- * paymentPayload against the `x402V2PaymentPayload` union, which requires top-level
415
- * `scheme` + `network`: a payload that carries them only under `accepted` matches neither
416
- * branch, and the echoed `extensions.bazaar.schema` bloats the body enough that CDP rejects
417
- * it on larger schemas while tolerating small ones ("must match one of [x402V2PaymentPayload,
418
- * x402V1PaymentPayload]"). Forwarding the four canonical fields only fixes it regardless of size.
419
- *
420
- * `scheme`/`network` are lifted out of `accepted`, falling back to any top-level values a
421
- * canonical client already sent. The full `accepted`/`extensions`/`resource` stay on the wire
422
- * for `verifyX402Request`; they are dropped only here, at the facilitator boundary. A payload
423
- * that lacks the canonical pieces (unexpected shape) passes through untouched so it reaches the
424
- * facilitator unchanged rather than silently mangled.
425
- */
426
- declare function toCanonicalX402PaymentPayload(payload: unknown): unknown;
406
+ * Strip the non-signed `extensions` + `resource` blocks from a decoded X-Payment payload
407
+ * before it is forwarded to the facilitator's verify/settle endpoints.
408
+ *
409
+ * agentscore-pay (and other x402 clients) echo the 402 challenge's `extensions` (Bazaar
410
+ * input schema) and `resource` blocks into the payload alongside the signed `payload` +
411
+ * `accepted`. Neither is part of the EIP-3009 signature (which covers only
412
+ * `payload.authorization`). CDP's `/x402/verify` validates the paymentPayload against its
413
+ * `x402V2PaymentPayload` schema, which is `{ x402Version, payload, accepted }` and admits
414
+ * neither `extensions` nor `resource`: their presence makes the payload match no union
415
+ * branch and CDP rejects it ("must match one of [x402V2PaymentPayload, x402V1PaymentPayload]").
416
+ * Endpoints whose echoed Bazaar schema is large fail while small ones happen to slip through,
417
+ * so it presents as "works on some routes, fails on others" but is one shape bug.
418
+ *
419
+ * Confirmed against the live CDP facilitator: accepted-nested WITHOUT extensions/resource
420
+ * passes schema and reaches signature verify; a flat `{ x402Version, scheme, network, payload }`
421
+ * is rejected with "x402V2PaymentPayload requires 'accepted'". So `accepted` (which
422
+ * `verifyX402Request` reads for network/payTo) and every other field stay intact; only the
423
+ * two echoed challenge blocks are dropped, and only here at the facilitator boundary.
424
+ * Non-object payloads, and payloads carrying neither field, pass through untouched.
425
+ */
426
+ declare function stripUnsignedX402PayloadFields(payload: unknown): unknown;
427
427
  declare function processX402Settle({ x402Server, payload, resourceConfig, resourceMeta, extension, transportContext, }: {
428
428
  /** The x402 server instance from `createX402Server`. */
429
429
  x402Server: X402Server;
@@ -923,4 +923,4 @@ declare function lazyMppxServer(opts: {
923
923
  secretKey: string;
924
924
  }): () => Promise<unknown>;
925
925
 
926
- export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppCredentialPayloadType, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, toCanonicalX402PaymentPayload, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
926
+ export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppCredentialPayloadType, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, stripUnsignedX402PayloadFields, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
@@ -403,27 +403,27 @@ declare function classifyX402SettleResult(result: ProcessX402SettleResult): Clas
403
403
  */
404
404
  declare function classifyOrchestrationError(err: unknown): ClassifiedX402Error | null;
405
405
  /**
406
- * Reshape a decoded X-Payment payload into the lean canonical x402 PaymentPayload the
407
- * facilitator's verify/settle endpoints validate: `{ x402Version, scheme, network, payload }`.
408
- *
409
- * agentscore-pay (and other x402 clients) transmit a richer wire shape: the chosen
410
- * requirement is nested under `accepted` (which `verifyX402Request` reads for network/payTo),
411
- * and the 402 challenge's `extensions` (Bazaar input schema) + `resource` blocks are echoed
412
- * alongside the signed `payload`. None of that is part of the EIP-3009 signature; the
413
- * signature covers only `payload.authorization`; but CDP's `/x402/verify` validates the
414
- * paymentPayload against the `x402V2PaymentPayload` union, which requires top-level
415
- * `scheme` + `network`: a payload that carries them only under `accepted` matches neither
416
- * branch, and the echoed `extensions.bazaar.schema` bloats the body enough that CDP rejects
417
- * it on larger schemas while tolerating small ones ("must match one of [x402V2PaymentPayload,
418
- * x402V1PaymentPayload]"). Forwarding the four canonical fields only fixes it regardless of size.
419
- *
420
- * `scheme`/`network` are lifted out of `accepted`, falling back to any top-level values a
421
- * canonical client already sent. The full `accepted`/`extensions`/`resource` stay on the wire
422
- * for `verifyX402Request`; they are dropped only here, at the facilitator boundary. A payload
423
- * that lacks the canonical pieces (unexpected shape) passes through untouched so it reaches the
424
- * facilitator unchanged rather than silently mangled.
425
- */
426
- declare function toCanonicalX402PaymentPayload(payload: unknown): unknown;
406
+ * Strip the non-signed `extensions` + `resource` blocks from a decoded X-Payment payload
407
+ * before it is forwarded to the facilitator's verify/settle endpoints.
408
+ *
409
+ * agentscore-pay (and other x402 clients) echo the 402 challenge's `extensions` (Bazaar
410
+ * input schema) and `resource` blocks into the payload alongside the signed `payload` +
411
+ * `accepted`. Neither is part of the EIP-3009 signature (which covers only
412
+ * `payload.authorization`). CDP's `/x402/verify` validates the paymentPayload against its
413
+ * `x402V2PaymentPayload` schema, which is `{ x402Version, payload, accepted }` and admits
414
+ * neither `extensions` nor `resource`: their presence makes the payload match no union
415
+ * branch and CDP rejects it ("must match one of [x402V2PaymentPayload, x402V1PaymentPayload]").
416
+ * Endpoints whose echoed Bazaar schema is large fail while small ones happen to slip through,
417
+ * so it presents as "works on some routes, fails on others" but is one shape bug.
418
+ *
419
+ * Confirmed against the live CDP facilitator: accepted-nested WITHOUT extensions/resource
420
+ * passes schema and reaches signature verify; a flat `{ x402Version, scheme, network, payload }`
421
+ * is rejected with "x402V2PaymentPayload requires 'accepted'". So `accepted` (which
422
+ * `verifyX402Request` reads for network/payTo) and every other field stay intact; only the
423
+ * two echoed challenge blocks are dropped, and only here at the facilitator boundary.
424
+ * Non-object payloads, and payloads carrying neither field, pass through untouched.
425
+ */
426
+ declare function stripUnsignedX402PayloadFields(payload: unknown): unknown;
427
427
  declare function processX402Settle({ x402Server, payload, resourceConfig, resourceMeta, extension, transportContext, }: {
428
428
  /** The x402 server instance from `createX402Server`. */
429
429
  x402Server: X402Server;
@@ -923,4 +923,4 @@ declare function lazyMppxServer(opts: {
923
923
  secretKey: string;
924
924
  }): () => Promise<unknown>;
925
925
 
926
- export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppCredentialPayloadType, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, toCanonicalX402PaymentPayload, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
926
+ export { type ClassifiedX402Error, type MppxComposeResult, type MppxRailSpec, type NetworkFamily, type PaymentHeadersRail, type PaymentHeadersResult, type ProcessX402SettleFailure, type ProcessX402SettleResult, type ProcessX402SettleSuccess, type RailDefinition, type RailName, SETTLEMENT_OVERRIDES_HEADER, type SettlementHandlers, type SettlementOverrides, type SettlementPayloadLike, SignerNetwork, SolanaMppRailSpec, StripeRailSpec, TempoRailSpec, TempoSessionRailSpec, USDC, type VerifyX402RequestResult, X402BaseRailSpec, X402Server, type X402ServerLike, X402_SUPPORTED_BASE_NETWORKS, type ZeroSettleRail, type ZeroSettleResult, buildIdempotencyKey, buildPaymentDirective, buildPaymentHeaders, buildPaymentRequestBlob, classifyOrchestrationError, classifyX402SettleResult, composeMppxRequest, createMppxServer, detectRailFromHeaders, dispatchSettlementByNetwork, lazyMppxServer, lazyX402Server, lookupRail, mppCredentialPayloadType, mppxChallengeHeaders, networkFamily, networks, paymentDirective, processX402Settle, rails, registerX402SchemesV1V2, runWithMppxFailureCapture, settlementOverrideHeader, stripUnsignedX402PayloadFields, validateX402NetworkConfig, verifyX402Request, wrapSolanaChargeWithFinalizedBlockhash, zeroAmountCarveOut };
@@ -68,7 +68,7 @@ __export(payment_exports, {
68
68
  resolveRecipient: () => resolveRecipient,
69
69
  runWithMppxFailureCapture: () => runWithMppxFailureCapture,
70
70
  settlementOverrideHeader: () => settlementOverrideHeader,
71
- toCanonicalX402PaymentPayload: () => toCanonicalX402PaymentPayload,
71
+ stripUnsignedX402PayloadFields: () => stripUnsignedX402PayloadFields,
72
72
  usdToAtomic: () => usdToAtomic,
73
73
  validateX402NetworkConfig: () => validateX402NetworkConfig,
74
74
  verifyX402Request: () => verifyX402Request,
@@ -520,20 +520,16 @@ function classifyOrchestrationError(err) {
520
520
  }
521
521
  return null;
522
522
  }
523
- function toCanonicalX402PaymentPayload(payload) {
523
+ function stripUnsignedX402PayloadFields(payload) {
524
524
  if (typeof payload !== "object" || payload === null) return payload;
525
525
  const p = payload;
526
- const accepted = typeof p.accepted === "object" && p.accepted !== null ? p.accepted : void 0;
527
- const scheme = p.scheme ?? accepted?.scheme;
528
- const network = p.network ?? accepted?.network;
529
- const inner = p.payload;
530
- if (scheme === void 0 || network === void 0 || inner === void 0) return payload;
531
- return {
532
- x402Version: p.x402Version ?? 2,
533
- scheme,
534
- network,
535
- payload: inner
536
- };
526
+ if (!("extensions" in p) && !("resource" in p)) return payload;
527
+ const rest = {};
528
+ for (const [k, v] of Object.entries(p)) {
529
+ if (k === "extensions" || k === "resource") continue;
530
+ rest[k] = v;
531
+ }
532
+ return rest;
537
533
  }
538
534
  async function processX402Settle({
539
535
  x402Server,
@@ -555,7 +551,7 @@ async function processX402Settle({
555
551
  if (!matchedRequirement) {
556
552
  return { success: false, phase: "no_requirements", reason: "x402Server.buildPaymentRequirements returned empty" };
557
553
  }
558
- const canonicalPayload = toCanonicalX402PaymentPayload(payload);
554
+ const facilitatorPayload = stripUnsignedX402PayloadFields(payload);
559
555
  const resolvedTransportContext = transportContext ?? (() => {
560
556
  const path = new URL(resourceMeta.url).pathname;
561
557
  return { method: "POST", adapter: { getPath: () => path }, routePattern: path };
@@ -570,7 +566,7 @@ async function processX402Settle({
570
566
  let verifyResult;
571
567
  try {
572
568
  verifyResult = await server.verifyPayment(
573
- canonicalPayload,
569
+ facilitatorPayload,
574
570
  matchedRequirement,
575
571
  enrichedExt,
576
572
  resolvedTransportContext
@@ -585,7 +581,7 @@ async function processX402Settle({
585
581
  }
586
582
  try {
587
583
  const settleResult = await server.settlePayment(
588
- canonicalPayload,
584
+ facilitatorPayload,
589
585
  matchedRequirement,
590
586
  enrichedExt,
591
587
  resolvedTransportContext
@@ -1559,7 +1555,7 @@ function isSolanaNetwork(input) {
1559
1555
  resolveRecipient,
1560
1556
  runWithMppxFailureCapture,
1561
1557
  settlementOverrideHeader,
1562
- toCanonicalX402PaymentPayload,
1558
+ stripUnsignedX402PayloadFields,
1563
1559
  usdToAtomic,
1564
1560
  validateX402NetworkConfig,
1565
1561
  verifyX402Request,