@x402x/extensions 2.2.1 → 2.3.1

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
@@ -749,6 +749,28 @@ var RewardHook;
749
749
  })(RewardHook || (RewardHook = {}));
750
750
 
751
751
  // src/validation.ts
752
+ function validateX402Version(version) {
753
+ if (typeof version === "number" && version === 2) {
754
+ return;
755
+ }
756
+ const baseMessage = "x402Version is required and must be 2. v1 is deprecated - please use x402Version=2. See https://github.com/nuwa-protocol/x402-exec for migration guide.";
757
+ if (version === void 0 || version === null) {
758
+ throw new Error(baseMessage);
759
+ }
760
+ if (typeof version !== "number") {
761
+ throw new Error(
762
+ `Invalid x402Version: expected number, got ${typeof version}. ${baseMessage}`
763
+ );
764
+ }
765
+ if (version === 1) {
766
+ throw new Error(
767
+ "x402Version 1 is deprecated. Please use x402Version=2. See https://github.com/nuwa-protocol/x402-exec for migration guide."
768
+ );
769
+ }
770
+ throw new Error(
771
+ `Version not supported: x402Version ${version} is not supported. Please use x402Version=2. See https://github.com/nuwa-protocol/x402-exec for migration guide.`
772
+ );
773
+ }
752
774
  function isValidAddress2(address) {
753
775
  return /^0x[a-fA-F0-9]{40}$/.test(address);
754
776
  }
@@ -1054,7 +1076,9 @@ async function verify(facilitatorUrl, paymentPayload, paymentRequirements) {
1054
1076
  },
1055
1077
  body: JSON.stringify({
1056
1078
  paymentPayload,
1057
- paymentRequirements
1079
+ paymentRequirements,
1080
+ x402Version: paymentPayload.x402Version
1081
+ // Include x402Version at top level
1058
1082
  }),
1059
1083
  // Add timeout
1060
1084
  signal: AbortSignal.timeout(1e4)
@@ -1093,7 +1117,9 @@ async function settle(facilitatorUrl, paymentPayload, paymentRequirements, timeo
1093
1117
  },
1094
1118
  body: JSON.stringify({
1095
1119
  paymentPayload,
1096
- paymentRequirements
1120
+ paymentRequirements,
1121
+ x402Version: paymentPayload.x402Version
1122
+ // Include x402Version at top level
1097
1123
  }),
1098
1124
  signal: controller.signal
1099
1125
  });
@@ -1268,6 +1294,7 @@ function registerSettlementHooks(server, config = {}) {
1268
1294
  if (enableSaltExtraction) {
1269
1295
  server.onBeforeVerify(async (context) => {
1270
1296
  const { paymentPayload, requirements } = context;
1297
+ validateX402Version(paymentPayload.x402Version);
1271
1298
  if (paymentPayload.extensions && "x402x-router-settlement" in paymentPayload.extensions) {
1272
1299
  const extension = paymentPayload.extensions["x402x-router-settlement"];
1273
1300
  if (extension?.info) {
@@ -1291,6 +1318,7 @@ function registerSettlementHooks(server, config = {}) {
1291
1318
  if (validateSettlementParams) {
1292
1319
  server.onBeforeSettle(async (context) => {
1293
1320
  const { paymentPayload, requirements } = context;
1321
+ validateX402Version(paymentPayload.x402Version);
1294
1322
  let settlementParams = {};
1295
1323
  if (paymentPayload.extensions && "x402x-router-settlement" in paymentPayload.extensions) {
1296
1324
  const extension = paymentPayload.extensions["x402x-router-settlement"];