starknet 10.3.0 → 10.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
@@ -1509,8 +1509,11 @@ var CairoUint512 = class _CairoUint512 {
1509
1509
  var isLen = (name) => /_len$/.test(name);
1510
1510
  var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
1511
1511
  var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
1512
- var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
1513
- var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
1512
+ var isTypeTuple = (type) => type.startsWith("(") && type.endsWith(")");
1513
+ var isTypeNamedTuple = (type) => {
1514
+ const start = type.indexOf("(");
1515
+ return start !== -1 && type.indexOf(")", start + 1) !== -1 && type.includes(":");
1516
+ };
1514
1517
  var isTypeStruct = (type, structs) => type in structs;
1515
1518
  var isTypeEnum = (type, enums) => type in enums;
1516
1519
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
@@ -1526,7 +1529,7 @@ var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0,
1526
1529
  var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
1527
1530
  var isCairo1Type = (type) => type.includes("::");
1528
1531
  var getArrayType = (type) => {
1529
- return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replace("*", "");
1532
+ return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replaceAll("*", "");
1530
1533
  };
1531
1534
  function isCairo1Abi(abi) {
1532
1535
  const { cairo } = getAbiContractVersion(abi);
@@ -3329,6 +3332,18 @@ var CairoFixedArray = class _CairoFixedArray {
3329
3332
  * Cairo fixed array type.
3330
3333
  */
3331
3334
  arrayType;
3335
+ static parseFixedArrayType(type) {
3336
+ if (!type.startsWith("[") || !type.endsWith("]")) {
3337
+ return void 0;
3338
+ }
3339
+ const separator = type.lastIndexOf("; ");
3340
+ const itemType = type.slice(1, separator);
3341
+ const size = type.slice(separator + 2, -1);
3342
+ if (separator <= 1 || size.length === 0 || ![...size].every((char) => char >= "0" && char <= "9")) {
3343
+ return void 0;
3344
+ }
3345
+ return { itemType, size };
3346
+ }
3332
3347
  /**
3333
3348
  * Create an instance representing a Cairo fixed Array.
3334
3349
  * @param {any[]} content JS array representing a Cairo fixed array.
@@ -3372,10 +3387,10 @@ var CairoFixedArray = class _CairoFixedArray {
3372
3387
  * ```
3373
3388
  */
3374
3389
  static getFixedArraySize(type) {
3375
- const matchArray = type.match(/(?<=; )\d+(?=\])/);
3376
- if (matchArray === null)
3390
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3391
+ if (!fixedArrayType)
3377
3392
  throw new Error(`ABI type ${type} do not includes a valid number after ';' character.`);
3378
- return Number(matchArray[0]);
3393
+ return Number(fixedArrayType.size);
3379
3394
  }
3380
3395
  /**
3381
3396
  * Retrieves the Cairo fixed array size from the CairoFixedArray instance.
@@ -3401,10 +3416,9 @@ var CairoFixedArray = class _CairoFixedArray {
3401
3416
  * ```
3402
3417
  */
3403
3418
  static getFixedArrayType = (type) => {
3404
- const matchArray = type.match(/(?<=\[).+(?=;)/);
3405
- if (matchArray === null)
3406
- throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3407
- return matchArray[0];
3419
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3420
+ if (!fixedArrayType) throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3421
+ return fixedArrayType.itemType;
3408
3422
  };
3409
3423
  /**
3410
3424
  * Retrieve the Cairo content type of the Cairo fixed array.
@@ -3462,7 +3476,7 @@ var CairoFixedArray = class _CairoFixedArray {
3462
3476
  * // result = true
3463
3477
  */
3464
3478
  static isTypeFixedArray(type) {
3465
- return /^\[.*;\s.*\]$/.test(type) && /(?<=\[).+(?=;)/.test(type) && /(?<=; )\d+(?=\])/.test(type);
3479
+ return _CairoFixedArray.parseFixedArrayType(type) !== void 0;
3466
3480
  }
3467
3481
  };
3468
3482
 
@@ -4130,7 +4144,7 @@ function responseParser({
4130
4144
  parsedDataArr.push(
4131
4145
  parseResponseValue(
4132
4146
  responseIterator,
4133
- { name, type: output.type.replace("*", "") },
4147
+ { name, type: output.type.replaceAll("*", "") },
4134
4148
  parser,
4135
4149
  structs,
4136
4150
  enums
@@ -9008,7 +9022,19 @@ function dynamicCallData(hardcoded, reference = void 0, arrayReference = void 0)
9008
9022
  });
9009
9023
  }
9010
9024
  function isStarkDomain(domain) {
9011
- return /^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$/.test(domain);
9025
+ const starkSuffix = ".stark";
9026
+ if (!domain.endsWith(starkSuffix)) {
9027
+ return false;
9028
+ }
9029
+ const name = domain.slice(0, -starkSuffix.length);
9030
+ if (name.length === 0) {
9031
+ return false;
9032
+ }
9033
+ return name.split(".").every((label) => {
9034
+ return label.length > 0 && label.length <= 48 && [...label].every((char) => {
9035
+ return char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-";
9036
+ });
9037
+ });
9012
9038
  }
9013
9039
 
9014
9040
  // src/plugins/starknet-id/index.ts