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.
@@ -1259,7 +1259,23 @@ function buildPaymentRequirements(options) {
1259
1259
  }
1260
1260
  function buildVerifyRequest(paymentHeader, requirements) {
1261
1261
  return {
1262
- x402Version: paymentHeader.x402Version,
1262
+ // The literal `1` names THIS ENVELOPE, not the payer's header. Echoing
1263
+ // `paymentHeader.x402Version` here -- what this did until 2026-09-04 --
1264
+ // let a buyer who declared `2` produce a body that says "2" while carrying
1265
+ // `paymentRequirements`, which is the v1 shape. The facilitator serves it
1266
+ // anyway because its envelope enum is untagged and matches on shape, so
1267
+ // nothing broke; but it ALREADY picks the hint in its 400 off this marker:
1268
+ //
1269
+ // "This body declares `x402Version: 2`. x402 v2 is a JSON object with
1270
+ // `paymentPayload`, `resource` and `accepted`..."
1271
+ //
1272
+ // So the day that body fails for any other reason, the diagnosis sends the
1273
+ // integrator to document the wrong shape. That inversion -- being told to
1274
+ // fix the fields when the wrapper is what is wrong -- is what cost two
1275
+ // teams a day. The payer's own marker survives untouched inside
1276
+ // `paymentPayload`, where it belongs: it describes the payment, not the
1277
+ // envelope carrying it.
1278
+ x402Version: 1,
1263
1279
  paymentPayload: paymentHeader,
1264
1280
  paymentRequirements: requirements
1265
1281
  };
@@ -1282,13 +1298,21 @@ function buildSettleRequestV2(payload, resource, accepted) {
1282
1298
  }
1283
1299
  function buildSettleRequest(paymentHeader, requirements) {
1284
1300
  return {
1285
- x402Version: paymentHeader.x402Version,
1301
+ // `1` for the same reason as {@link buildVerifyRequest}: it names the
1302
+ // envelope, and `/settle` takes the same body as `/verify`.
1303
+ x402Version: 1,
1286
1304
  paymentPayload: paymentHeader,
1287
1305
  paymentRequirements: requirements
1288
1306
  };
1289
1307
  }
1290
1308
  function isCaip2Network(network) {
1291
- return network.includes(":");
1309
+ return typeof network === "string" && network.includes(":");
1310
+ }
1311
+ function networkOfPayload(payload) {
1312
+ const top = payload.network;
1313
+ if (typeof top === "string") return top;
1314
+ const accepted = payload.accepted;
1315
+ return typeof accepted?.network === "string" ? accepted.network : void 0;
1292
1316
  }
1293
1317
  function toResourceInfoV2(requirements) {
1294
1318
  return {
@@ -1298,9 +1322,15 @@ function toResourceInfoV2(requirements) {
1298
1322
  };
1299
1323
  }
1300
1324
  function toPaymentRequirementsV2(requirements) {
1325
+ const network = isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network);
1326
+ if (!isCaip2Network(network)) {
1327
+ throw new Error(
1328
+ `Network '${requirements.network}' has no CAIP-2 form, so it cannot travel in the x402 v2 envelope. Use x402Version: 1 for this network.`
1329
+ );
1330
+ }
1301
1331
  return {
1302
1332
  scheme: requirements.scheme,
1303
- network: isCaip2Network(requirements.network) ? requirements.network : chainToCAIP2(requirements.network),
1333
+ network,
1304
1334
  asset: requirements.asset,
1305
1335
  amount: requirements.maxAmountRequired,
1306
1336
  payTo: requirements.payTo,
@@ -1313,7 +1343,7 @@ function resolveEnvelopeVersion(paymentHeader, requirements, requested = "auto")
1313
1343
  if (requested !== "auto") {
1314
1344
  return requested;
1315
1345
  }
1316
- return isCaip2Network(paymentHeader.network) || isCaip2Network(requirements.network) ? 2 : 1;
1346
+ return isCaip2Network(networkOfPayload(paymentHeader)) || isCaip2Network(requirements.network) ? 2 : 1;
1317
1347
  }
1318
1348
  function buildVerifyRequestForVersion(paymentHeader, requirements, version) {
1319
1349
  if (version === 2) {