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