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.mjs CHANGED
@@ -2248,7 +2248,8 @@ __export(num_exports, {
2248
2248
  toBigInt: () => toBigInt,
2249
2249
  toCairoBool: () => toCairoBool,
2250
2250
  toHex: () => toHex,
2251
- toHexString: () => toHexString
2251
+ toHexString: () => toHexString,
2252
+ toStorageKey: () => toStorageKey
2252
2253
  });
2253
2254
  import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
2254
2255
  function isHex(hex) {
@@ -2263,6 +2264,10 @@ function isBigInt(value) {
2263
2264
  function toHex(number2) {
2264
2265
  return addHexPrefix(toBigInt(number2).toString(16));
2265
2266
  }
2267
+ function toStorageKey(number2) {
2268
+ const res = addHexPrefix(toBigInt(number2).toString(16).padStart(64, "0"));
2269
+ return res;
2270
+ }
2266
2271
  function hexToDecimalString(hex) {
2267
2272
  return BigInt(addHexPrefix(hex)).toString(10);
2268
2273
  }
@@ -3407,18 +3412,18 @@ function nullSkipReplacer(key, value) {
3407
3412
  }
3408
3413
  function formatSpaces(json2) {
3409
3414
  let insideQuotes = false;
3410
- let newString = "";
3415
+ const newString = [];
3411
3416
  for (const char of json2) {
3412
- if (char === '"' && newString.endsWith("\\") === false) {
3417
+ if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
3413
3418
  insideQuotes = !insideQuotes;
3414
3419
  }
3415
3420
  if (insideQuotes) {
3416
- newString += char;
3421
+ newString.push(char);
3417
3422
  } else {
3418
- newString += char === ":" ? ": " : char === "," ? ", " : char;
3423
+ newString.push(char === ":" ? ": " : char === "," ? ", " : char);
3419
3424
  }
3420
3425
  }
3421
- return newString;
3426
+ return newString.join("");
3422
3427
  }
3423
3428
  function computeHintedClassHash(compiledContract) {
3424
3429
  const { abi, program } = compiledContract;
@@ -3682,6 +3687,12 @@ var RPCResponseParser = class {
3682
3687
  };
3683
3688
  });
3684
3689
  }
3690
+ parseContractClassResponse(res) {
3691
+ return {
3692
+ ...res,
3693
+ abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
3694
+ };
3695
+ }
3685
3696
  };
3686
3697
 
3687
3698
  // src/provider/errors.ts
@@ -4007,7 +4018,7 @@ var RpcProvider = class {
4007
4018
  return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
4008
4019
  }
4009
4020
  async getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
4010
- const parsedKey = toHex(key);
4021
+ const parsedKey = toStorageKey(key);
4011
4022
  const block_id = new Block(blockIdentifier).identifier;
4012
4023
  return this.fetchEndpoint("starknet_getStorageAt", {
4013
4024
  contract_address: contractAddress,
@@ -4034,14 +4045,17 @@ var RpcProvider = class {
4034
4045
  }
4035
4046
  async getClass(classHash, blockIdentifier = this.blockIdentifier) {
4036
4047
  const block_id = new Block(blockIdentifier).identifier;
4037
- return this.fetchEndpoint("starknet_getClass", { class_hash: classHash, block_id });
4048
+ return this.fetchEndpoint("starknet_getClass", {
4049
+ class_hash: classHash,
4050
+ block_id
4051
+ }).then(this.responseParser.parseContractClassResponse);
4038
4052
  }
4039
4053
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4040
4054
  const block_id = new Block(blockIdentifier).identifier;
4041
4055
  return this.fetchEndpoint("starknet_getClassAt", {
4042
4056
  block_id,
4043
4057
  contract_address: contractAddress
4044
- });
4058
+ }).then(this.responseParser.parseContractClassResponse);
4045
4059
  }
4046
4060
  async getCode(_contractAddress, _blockIdentifier) {
4047
4061
  throw new Error("RPC does not implement getCode function");
@@ -4487,11 +4501,11 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4487
4501
  }
4488
4502
  };
4489
4503
  }
4490
- // TODO: Define response as new type as it diff from ContractClass
4491
- parseSierraContractClassResponse(res) {
4504
+ parseContractClassResponse(res) {
4505
+ const response = isSierra(res) ? res : parseContract(res);
4492
4506
  return {
4493
- ...res,
4494
- abi: JSON.parse(res.abi)
4507
+ ...response,
4508
+ abi: typeof response.abi === "string" ? JSON.parse(response.abi) : response.abi
4495
4509
  };
4496
4510
  }
4497
4511
  };
@@ -4706,24 +4720,16 @@ var SequencerProvider = class {
4706
4720
  }
4707
4721
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4708
4722
  return this.fetchEndpoint("get_full_contract", { blockIdentifier, contractAddress }).then(
4709
- (res) => {
4710
- if (isSierra(res)) {
4711
- return this.responseParser.parseSierraContractClassResponse(res);
4712
- }
4713
- return parseContract(res);
4714
- }
4723
+ this.responseParser.parseContractClassResponse
4715
4724
  );
4716
4725
  }
4717
4726
  async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
4718
4727
  return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
4719
4728
  }
4720
4729
  async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
4721
- return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then((res) => {
4722
- if (isSierra(res)) {
4723
- return this.responseParser.parseSierraContractClassResponse(res);
4724
- }
4725
- return parseContract(res);
4726
- });
4730
+ return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
4731
+ this.responseParser.parseContractClassResponse
4732
+ );
4727
4733
  }
4728
4734
  async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
4729
4735
  return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });