starknet 5.13.0 → 5.13.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.js CHANGED
@@ -2325,7 +2325,8 @@ __export(num_exports, {
2325
2325
  toBigInt: () => toBigInt,
2326
2326
  toCairoBool: () => toCairoBool,
2327
2327
  toHex: () => toHex,
2328
- toHexString: () => toHexString
2328
+ toHexString: () => toHexString,
2329
+ toStorageKey: () => toStorageKey
2329
2330
  });
2330
2331
  var import_utils = require("@noble/curves/abstract/utils");
2331
2332
  function isHex(hex) {
@@ -2340,6 +2341,10 @@ function isBigInt(value) {
2340
2341
  function toHex(number2) {
2341
2342
  return addHexPrefix(toBigInt(number2).toString(16));
2342
2343
  }
2344
+ function toStorageKey(number2) {
2345
+ const res = addHexPrefix(toBigInt(number2).toString(16).padStart(64, "0"));
2346
+ return res;
2347
+ }
2343
2348
  function hexToDecimalString(hex) {
2344
2349
  return BigInt(addHexPrefix(hex)).toString(10);
2345
2350
  }
@@ -3484,18 +3489,18 @@ function nullSkipReplacer(key, value) {
3484
3489
  }
3485
3490
  function formatSpaces(json2) {
3486
3491
  let insideQuotes = false;
3487
- let newString = "";
3492
+ const newString = [];
3488
3493
  for (const char of json2) {
3489
- if (char === '"' && newString.endsWith("\\") === false) {
3494
+ if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
3490
3495
  insideQuotes = !insideQuotes;
3491
3496
  }
3492
3497
  if (insideQuotes) {
3493
- newString += char;
3498
+ newString.push(char);
3494
3499
  } else {
3495
- newString += char === ":" ? ": " : char === "," ? ", " : char;
3500
+ newString.push(char === ":" ? ": " : char === "," ? ", " : char);
3496
3501
  }
3497
3502
  }
3498
- return newString;
3503
+ return newString.join("");
3499
3504
  }
3500
3505
  function computeHintedClassHash(compiledContract) {
3501
3506
  const { abi, program } = compiledContract;
@@ -3759,6 +3764,12 @@ var RPCResponseParser = class {
3759
3764
  };
3760
3765
  });
3761
3766
  }
3767
+ parseContractClassResponse(res) {
3768
+ return {
3769
+ ...res,
3770
+ abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
3771
+ };
3772
+ }
3762
3773
  };
3763
3774
 
3764
3775
  // src/provider/errors.ts
@@ -4084,7 +4095,7 @@ var RpcProvider = class {
4084
4095
  return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
4085
4096
  }
4086
4097
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
4087
- const parsedKey = toHex(key);
4098
+ const parsedKey = toStorageKey(key);
4088
4099
  const block_id = new Block(blockIdentifier).identifier;
4089
4100
  return this.fetchEndpoint("starknet_getStorageAt", {
4090
4101
  contract_address: contractAddress,
@@ -4111,14 +4122,17 @@ var RpcProvider = class {
4111
4122
  }
4112
4123
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
4113
4124
  const block_id = new Block(blockIdentifier).identifier;
4114
- return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
4125
+ return this.fetchEndpoint("starknet_getClass", {
4126
+ class_hash: classHash,
4127
+ block_id
4128
+ }).then(this.responseParser.parseContractClassResponse);
4115
4129
  }
4116
4130
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4117
4131
  const block_id = new Block(blockIdentifier).identifier;
4118
4132
  return this.fetchEndpoint("starknet_getClassAt", {
4119
4133
  block_id,
4120
4134
  contract_address: contractAddress
4121
- });
4135
+ }).then(this.responseParser.parseContractClassResponse);
4122
4136
  }
4123
4137
  async getCode(_contractAddress, _blockIdentifier) {
4124
4138
  throw new Error("RPC does not implement getCode function");
@@ -4564,11 +4578,11 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4564
4578
  }
4565
4579
  };
4566
4580
  }
4567
- // TODO: Define response as new type as it diff from ContractClass
4568
- parseSierraContractClassResponse(res) {
4581
+ parseContractClassResponse(res) {
4582
+ const response = isSierra(res) ? res : parseContract(res);
4569
4583
  return {
4570
- ...res,
4571
- abi: JSON.parse(res.abi)
4584
+ ...response,
4585
+ abi: typeof response.abi === "string" ? JSON.parse(response.abi) : response.abi
4572
4586
  };
4573
4587
  }
4574
4588
  };
@@ -4783,24 +4797,16 @@ var SequencerProvider = class {
4783
4797
  }
4784
4798
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4785
4799
  return this.fetchEndpoint("get_full_contract", { blockIdentifier, contractAddress }).then(
4786
- (res) => {
4787
- if (isSierra(res)) {
4788
- return this.responseParser.parseSierraContractClassResponse(res);
4789
- }
4790
- return parseContract(res);
4791
- }
4800
+ this.responseParser.parseContractClassResponse
4792
4801
  );
4793
4802
  }
4794
4803
  async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4795
4804
  return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
4796
4805
  }
4797
4806
  async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
4798
- return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then((res) => {
4799
- if (isSierra(res)) {
4800
- return this.responseParser.parseSierraContractClassResponse(res);
4801
- }
4802
- return parseContract(res);
4803
- });
4807
+ return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
4808
+ this.responseParser.parseContractClassResponse
4809
+ );
4804
4810
  }
4805
4811
  async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
4806
4812
  return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });