starknet 10.3.0 → 10.3.2

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
@@ -6126,18 +6140,20 @@ var RpcChannel = class {
6126
6140
  }
6127
6141
  async fetchEndpoint(method, params) {
6128
6142
  try {
6143
+ let error;
6144
+ let result;
6129
6145
  if (this.batchClient) {
6130
- const { error: error2, result: result2 } = await this.batchClient.fetch(
6131
- method,
6132
- params,
6133
- this.requestId += 1
6134
- );
6135
- this.errorHandler(method, params, error2);
6136
- return result2;
6146
+ ({ error, result } = await this.batchClient.fetch(method, params, this.requestId += 1));
6147
+ } else {
6148
+ const rawResult = await this.fetch(method, params, this.requestId += 1);
6149
+ ({ error, result } = await rawResult.json());
6137
6150
  }
6138
- const rawResult = await this.fetch(method, params, this.requestId += 1);
6139
- const { error, result } = await rawResult.json();
6140
6151
  this.errorHandler(method, params, error);
6152
+ if (result === void 0) {
6153
+ throw new LibraryError(
6154
+ `RPC: '${method}' returned an empty response (no result and no error). The node reply is malformed or not a valid JSON-RPC response.`
6155
+ );
6156
+ }
6141
6157
  return result;
6142
6158
  } catch (error) {
6143
6159
  this.errorHandler(method, params, error?.response?.data, error);
@@ -6681,18 +6697,20 @@ var RpcChannel2 = class {
6681
6697
  }
6682
6698
  async fetchEndpoint(method, params) {
6683
6699
  try {
6700
+ let error;
6701
+ let result;
6684
6702
  if (this.batchClient) {
6685
- const { error: error2, result: result2 } = await this.batchClient.fetch(
6686
- method,
6687
- params,
6688
- this.requestId += 1
6689
- );
6690
- this.errorHandler(method, params, error2);
6691
- return result2;
6703
+ ({ error, result } = await this.batchClient.fetch(method, params, this.requestId += 1));
6704
+ } else {
6705
+ const rawResult = await this.fetch(method, params, this.requestId += 1);
6706
+ ({ error, result } = await rawResult.json());
6692
6707
  }
6693
- const rawResult = await this.fetch(method, params, this.requestId += 1);
6694
- const { error, result } = await rawResult.json();
6695
6708
  this.errorHandler(method, params, error);
6709
+ if (result === void 0) {
6710
+ throw new LibraryError(
6711
+ `RPC: '${method}' returned an empty response (no result and no error). The node reply is malformed or not a valid JSON-RPC response.`
6712
+ );
6713
+ }
6696
6714
  return result;
6697
6715
  } catch (error) {
6698
6716
  this.errorHandler(method, params, error?.response?.data, error);
@@ -9008,7 +9026,19 @@ function dynamicCallData(hardcoded, reference = void 0, arrayReference = void 0)
9008
9026
  });
9009
9027
  }
9010
9028
  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);
9029
+ const starkSuffix = ".stark";
9030
+ if (!domain.endsWith(starkSuffix)) {
9031
+ return false;
9032
+ }
9033
+ const name = domain.slice(0, -starkSuffix.length);
9034
+ if (name.length === 0) {
9035
+ return false;
9036
+ }
9037
+ return name.split(".").every((label) => {
9038
+ return label.length > 0 && label.length <= 48 && [...label].every((char) => {
9039
+ return char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-";
9040
+ });
9041
+ });
9012
9042
  }
9013
9043
 
9014
9044
  // src/plugins/starknet-id/index.ts