@x402x/extensions 2.3.0 → 2.4.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
@@ -179,10 +179,17 @@ function isValidHex(hex) {
179
179
  var NETWORK_ALIASES_V1_TO_V2 = {
180
180
  // V1 human-readable names -> V2 CAIP-2 canonical keys
181
181
  "base-sepolia": "eip155:84532",
182
+ "xlayer-testnet": "eip155:1952",
183
+ // Legacy alias for backward compatibility
182
184
  "x-layer-testnet": "eip155:1952",
185
+ // Canonical alias (must come after legacy to override)
183
186
  "skale-base-sepolia": "eip155:324705682",
187
+ "skale-base": "eip155:1187947933",
184
188
  base: "eip155:8453",
189
+ xlayer: "eip155:196",
190
+ // Legacy alias for backward compatibility
185
191
  "x-layer": "eip155:196",
192
+ // Canonical alias (must come after legacy to override)
186
193
  "bsc-testnet": "eip155:97",
187
194
  bsc: "eip155:56"
188
195
  };
@@ -251,6 +258,14 @@ var DEFAULT_ASSETS = {
251
258
  name: "x402 Wrapped USDT",
252
259
  version: "1"
253
260
  }
261
+ },
262
+ "eip155:1187947933": {
263
+ address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
264
+ decimals: 6,
265
+ eip712: {
266
+ name: "Bridged USDC (SKALE Bridge)",
267
+ version: "2"
268
+ }
254
269
  }
255
270
  };
256
271
  function getNetworkAlias(network) {
@@ -415,7 +430,7 @@ var networks = {
415
430
  },
416
431
  metadata: {
417
432
  gasModel: "legacy",
418
- nativeToken: "Credits"
433
+ nativeToken: "CREDIT"
419
434
  }
420
435
  },
421
436
  "eip155:97": {
@@ -506,6 +521,28 @@ var networks = {
506
521
  gasModel: "legacy",
507
522
  nativeToken: "BNB"
508
523
  }
524
+ },
525
+ "eip155:1187947933": {
526
+ chainId: 1187947933,
527
+ name: "SKALE on Base",
528
+ type: "mainnet",
529
+ addressExplorerBaseUrl: "https://skale-base-explorer.skalenodes.com/address/",
530
+ txExplorerBaseUrl: "https://skale-base-explorer.skalenodes.com/tx/",
531
+ settlementRouter: "0x1Ae0E196dC18355aF3a19985faf67354213F833D",
532
+ defaultAsset: getDefaultAssetConfig("eip155:1187947933"),
533
+ hooks: {
534
+ transfer: "0x2f05fe5674aE756E25C26855258B4877E9e021Fd"
535
+ },
536
+ demoHooks: {
537
+ nftMint: "0x73fc659Cd5494E69852bE8D9D23FE05Aab14b29B",
538
+ randomNFT: "0x081258287F692D61575387ee2a4075f34dd7Aef7",
539
+ reward: "0xC20634ea518985901e32Fbc1bA27fa673D37601A",
540
+ rewardToken: "0x9Fc2c199170B039f093ABCd54008038F0C0a31d6"
541
+ },
542
+ metadata: {
543
+ gasModel: "legacy",
544
+ nativeToken: "CREDIT"
545
+ }
509
546
  }
510
547
  };
511
548
  function getNetworkConfig(network) {
@@ -550,16 +587,16 @@ var customChains = {
550
587
  324705682: defineChain({
551
588
  id: 324705682,
552
589
  name: "SKALE Nebula Testnet",
553
- nativeCurrency: { name: "sFUEL", symbol: "sFUEL", decimals: 18 },
590
+ nativeCurrency: { name: "CREDIT", symbol: "CREDIT", decimals: 18 },
554
591
  rpcUrls: {
555
592
  default: {
556
- http: ["https://testnet.skalenodes.com/v1/lanky-ill-funny-testnet"]
593
+ http: ["https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha"]
557
594
  }
558
595
  },
559
596
  blockExplorers: {
560
597
  default: {
561
598
  name: "SKALE Explorer",
562
- url: "https://lanky-ill-funny-testnet.explorer.testnet.skalenodes.com"
599
+ url: "https://base-sepolia-testnet-explorer.skalenodes.com"
563
600
  }
564
601
  },
565
602
  testnet: true
@@ -576,6 +613,22 @@ var customChains = {
576
613
  default: { name: "OKLink", url: "https://www.oklink.com/xlayer" }
577
614
  },
578
615
  testnet: false
616
+ }),
617
+ // SKALE Base Mainnet
618
+ 1187947933: defineChain({
619
+ id: 1187947933,
620
+ name: "SKALE Base",
621
+ nativeCurrency: { name: "CREDIT", symbol: "CREDIT", decimals: 18 },
622
+ rpcUrls: {
623
+ default: { http: ["https://skale-base.skalenodes.com/v1/base"] }
624
+ },
625
+ blockExplorers: {
626
+ default: {
627
+ name: "SKALE Explorer",
628
+ url: "https://skale-base-explorer.skalenodes.com"
629
+ }
630
+ },
631
+ testnet: false
579
632
  })
580
633
  };
581
634
  function getChain(network) {
@@ -749,6 +802,28 @@ var RewardHook;
749
802
  })(RewardHook || (RewardHook = {}));
750
803
 
751
804
  // src/validation.ts
805
+ function validateX402Version(version) {
806
+ if (typeof version === "number" && version === 2) {
807
+ return;
808
+ }
809
+ 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.";
810
+ if (version === void 0 || version === null) {
811
+ throw new Error(baseMessage);
812
+ }
813
+ if (typeof version !== "number") {
814
+ throw new Error(
815
+ `Invalid x402Version: expected number, got ${typeof version}. ${baseMessage}`
816
+ );
817
+ }
818
+ if (version === 1) {
819
+ throw new Error(
820
+ "x402Version 1 is deprecated. Please use x402Version=2. See https://github.com/nuwa-protocol/x402-exec for migration guide."
821
+ );
822
+ }
823
+ throw new Error(
824
+ `Version not supported: x402Version ${version} is not supported. Please use x402Version=2. See https://github.com/nuwa-protocol/x402-exec for migration guide.`
825
+ );
826
+ }
752
827
  function isValidAddress2(address) {
753
828
  return /^0x[a-fA-F0-9]{40}$/.test(address);
754
829
  }
@@ -1054,7 +1129,9 @@ async function verify(facilitatorUrl, paymentPayload, paymentRequirements) {
1054
1129
  },
1055
1130
  body: JSON.stringify({
1056
1131
  paymentPayload,
1057
- paymentRequirements
1132
+ paymentRequirements,
1133
+ x402Version: paymentPayload.x402Version ?? 2
1134
+ // Include x402Version at top level, default to 2
1058
1135
  }),
1059
1136
  // Add timeout
1060
1137
  signal: AbortSignal.timeout(1e4)
@@ -1093,7 +1170,9 @@ async function settle(facilitatorUrl, paymentPayload, paymentRequirements, timeo
1093
1170
  },
1094
1171
  body: JSON.stringify({
1095
1172
  paymentPayload,
1096
- paymentRequirements
1173
+ paymentRequirements,
1174
+ x402Version: paymentPayload.x402Version ?? 2
1175
+ // Include x402Version at top level, default to 2
1097
1176
  }),
1098
1177
  signal: controller.signal
1099
1178
  });
@@ -1268,6 +1347,7 @@ function registerSettlementHooks(server, config = {}) {
1268
1347
  if (enableSaltExtraction) {
1269
1348
  server.onBeforeVerify(async (context) => {
1270
1349
  const { paymentPayload, requirements } = context;
1350
+ validateX402Version(paymentPayload.x402Version);
1271
1351
  if (paymentPayload.extensions && "x402x-router-settlement" in paymentPayload.extensions) {
1272
1352
  const extension = paymentPayload.extensions["x402x-router-settlement"];
1273
1353
  if (extension?.info) {
@@ -1291,6 +1371,7 @@ function registerSettlementHooks(server, config = {}) {
1291
1371
  if (validateSettlementParams) {
1292
1372
  server.onBeforeSettle(async (context) => {
1293
1373
  const { paymentPayload, requirements } = context;
1374
+ validateX402Version(paymentPayload.x402Version);
1294
1375
  let settlementParams = {};
1295
1376
  if (paymentPayload.extensions && "x402x-router-settlement" in paymentPayload.extensions) {
1296
1377
  const extension = paymentPayload.extensions["x402x-router-settlement"];