uvd-x402-sdk 2.78.0 → 2.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3915,7 +3915,23 @@ function buildPaymentRequirements(options) {
3915
3915
  }
3916
3916
  function buildVerifyRequest(paymentHeader, requirements) {
3917
3917
  return {
3918
- x402Version: paymentHeader.x402Version,
3918
+ // The literal `1` names THIS ENVELOPE, not the payer's header. Echoing
3919
+ // `paymentHeader.x402Version` here -- what this did until 2026-09-04 --
3920
+ // let a buyer who declared `2` produce a body that says "2" while carrying
3921
+ // `paymentRequirements`, which is the v1 shape. The facilitator serves it
3922
+ // anyway because its envelope enum is untagged and matches on shape, so
3923
+ // nothing broke; but it ALREADY picks the hint in its 400 off this marker:
3924
+ //
3925
+ // "This body declares `x402Version: 2`. x402 v2 is a JSON object with
3926
+ // `paymentPayload`, `resource` and `accepted`..."
3927
+ //
3928
+ // So the day that body fails for any other reason, the diagnosis sends the
3929
+ // integrator to document the wrong shape. That inversion -- being told to
3930
+ // fix the fields when the wrapper is what is wrong -- is what cost two
3931
+ // teams a day. The payer's own marker survives untouched inside
3932
+ // `paymentPayload`, where it belongs: it describes the payment, not the
3933
+ // envelope carrying it.
3934
+ x402Version: 1,
3919
3935
  paymentPayload: paymentHeader,
3920
3936
  paymentRequirements: requirements
3921
3937
  };
@@ -3938,13 +3954,21 @@ function buildSettleRequestV2(payload, resource, accepted) {
3938
3954
  }
3939
3955
  function buildSettleRequest(paymentHeader, requirements) {
3940
3956
  return {
3941
- x402Version: paymentHeader.x402Version,
3957
+ // `1` for the same reason as {@link buildVerifyRequest}: it names the
3958
+ // envelope, and `/settle` takes the same body as `/verify`.
3959
+ x402Version: 1,
3942
3960
  paymentPayload: paymentHeader,
3943
3961
  paymentRequirements: requirements
3944
3962
  };
3945
3963
  }
3946
3964
  function isCaip2Network(network) {
3947
- return network.includes(":");
3965
+ return typeof network === "string" && network.includes(":");
3966
+ }
3967
+ function networkOfPayload(payload) {
3968
+ const top = payload.network;
3969
+ if (typeof top === "string") return top;
3970
+ const accepted = payload.accepted;
3971
+ return typeof accepted?.network === "string" ? accepted.network : void 0;
3948
3972
  }
3949
3973
  function toResourceInfoV2(requirements) {
3950
3974
  return {
@@ -3954,9 +3978,15 @@ function toResourceInfoV2(requirements) {
3954
3978
  };
3955
3979
  }
3956
3980
  function toPaymentRequirementsV2(requirements) {
3981
+ const network = isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network);
3982
+ if (!isCaip2Network(network)) {
3983
+ throw new Error(
3984
+ `Network '${requirements.network}' has no CAIP-2 form, so it cannot travel in the x402 v2 envelope. Use x402Version: 1 for this network.`
3985
+ );
3986
+ }
3957
3987
  return {
3958
3988
  scheme: requirements.scheme,
3959
- network: isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network),
3989
+ network,
3960
3990
  asset: requirements.asset,
3961
3991
  amount: requirements.maxAmountRequired,
3962
3992
  payTo: requirements.payTo,
@@ -3969,7 +3999,7 @@ function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto")
3969
3999
  if (requested !== "auto") {
3970
4000
  return requested;
3971
4001
  }
3972
- return isCaip2Network(paymentHeader.network) || isCaip2Network(requirements.network) ? 2 : 1;
4002
+ return isCaip2Network(networkOfPayload(paymentHeader)) || isCaip2Network(requirements.network) ? 2 : 1;
3973
4003
  }
3974
4004
  function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
3975
4005
  if (version === 2) {