starknet 10.1.0 → 10.2.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
@@ -1851,6 +1851,24 @@ var CairoBytes31 = class _CairoBytes31 {
1851
1851
  }
1852
1852
  };
1853
1853
 
1854
+ // src/utils/ec.ts
1855
+ var ec_exports = {};
1856
+ __export(ec_exports, {
1857
+ starkCurve: () => starkCurve,
1858
+ weierstrass: () => weierstrass
1859
+ });
1860
+ import * as starkCurve from "@scure/starknet";
1861
+ import * as weierstrass from "@noble/curves/abstract/weierstrass";
1862
+
1863
+ // src/utils/hash/pedersenCore.ts
1864
+ function computePedersenHash(a, b) {
1865
+ return starkCurve.pedersen(BigInt(a), BigInt(b));
1866
+ }
1867
+ function computeHashOnElements(data) {
1868
+ return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
1869
+ }
1870
+ var computePedersenHashOnElements = computeHashOnElements;
1871
+
1854
1872
  // src/utils/errors/rpc.ts
1855
1873
  var errorCodes = {
1856
1874
  FAILED_TO_RECEIVE_TXN: 1,
@@ -2145,6 +2163,31 @@ var CairoByteArray = class _CairoByteArray {
2145
2163
  const allBytes = concatenateArrayBuffer(this.toElements());
2146
2164
  return buffer_default.from(allBytes);
2147
2165
  }
2166
+ /**
2167
+ * Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
2168
+ *
2169
+ * Serializes the ByteArray to its felt252 components (data array length, each data chunk,
2170
+ * pending_word, pending_word_len), then chains Pedersen hash over all elements starting
2171
+ * from 0, and finalizes with the total element count.
2172
+ *
2173
+ * @returns {string} hex-string felt252 Pedersen hash of the ByteArray
2174
+ * @example
2175
+ * ```typescript
2176
+ * const ba = new CairoByteArray('Hello');
2177
+ * const result = ba.hash();
2178
+ * // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
2179
+ * ```
2180
+ */
2181
+ hash() {
2182
+ this.assertInitialized();
2183
+ const serialized = [
2184
+ addHexPrefix(this.data.length.toString(16)),
2185
+ ...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
2186
+ ...this.pending_word.toApiRequest(),
2187
+ ...this.pending_word_len.toApiRequest()
2188
+ ];
2189
+ return computeHashOnElements(serialized);
2190
+ }
2148
2191
  /**
2149
2192
  * returns an array of all the data chunks and the pending word
2150
2193
  * when concatenated, represents the original bytes sequence
@@ -4705,7 +4748,7 @@ __export(hash_exports, {
4705
4748
  computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
4706
4749
  computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
4707
4750
  computeContractClassHash: () => computeContractClassHash,
4708
- computeHashOnElements: () => computeHashOnElements2,
4751
+ computeHashOnElements: () => computeHashOnElements,
4709
4752
  computeHintedClassHash: () => computeHintedClassHash,
4710
4753
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
4711
4754
  computePedersenHash: () => computePedersenHash,
@@ -4845,24 +4888,13 @@ __export(v2_exports, {
4845
4888
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
4846
4889
  calculateTransactionHash: () => calculateTransactionHash,
4847
4890
  calculateTransactionHashCommon: () => calculateTransactionHashCommon2,
4848
- computeHashOnElements: () => computeHashOnElements
4849
- });
4850
-
4851
- // src/utils/ec.ts
4852
- var ec_exports = {};
4853
- __export(ec_exports, {
4854
- starkCurve: () => starkCurve,
4855
- weierstrass: () => weierstrass
4891
+ computeHashOnElements: () => computeHashOnElements2
4856
4892
  });
4857
- import * as starkCurve from "@scure/starknet";
4858
- import * as weierstrass from "@noble/curves/abstract/weierstrass";
4859
-
4860
- // src/utils/hash/transactionHash/v2.ts
4861
- function computeHashOnElements(data) {
4893
+ function computeHashOnElements2(data) {
4862
4894
  return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
4863
4895
  }
4864
4896
  function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
4865
- const calldataHash = computeHashOnElements(calldata);
4897
+ const calldataHash = computeHashOnElements2(calldata);
4866
4898
  const dataToHash = [
4867
4899
  txHashPrefix,
4868
4900
  version,
@@ -4873,7 +4905,7 @@ function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress,
4873
4905
  chainId,
4874
4906
  ...additionalData
4875
4907
  ];
4876
- return computeHashOnElements(dataToHash);
4908
+ return computeHashOnElements2(dataToHash);
4877
4909
  }
4878
4910
  function calculateDeclareTransactionHash2(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
4879
4911
  return calculateTransactionHashCommon2(
@@ -5032,18 +5064,11 @@ function flattenEntryPointData(data, encodedBuiltinsArray) {
5032
5064
  }
5033
5065
 
5034
5066
  // src/utils/hash/classHash/pedersen.ts
5035
- function computePedersenHash(a, b) {
5036
- return starkCurve.pedersen(BigInt(a), BigInt(b));
5037
- }
5038
- function computeHashOnElements2(data) {
5039
- return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
5040
- }
5041
- var computePedersenHashOnElements = computeHashOnElements2;
5042
5067
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
5043
5068
  const compiledCalldata = CallData.compile(constructorCalldata);
5044
- const constructorCalldataHash = computeHashOnElements2(compiledCalldata);
5069
+ const constructorCalldataHash = computeHashOnElements(compiledCalldata);
5045
5070
  const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
5046
- const hash = computeHashOnElements2([
5071
+ const hash = computeHashOnElements([
5047
5072
  CONTRACT_ADDRESS_PREFIX,
5048
5073
  deployerAddress,
5049
5074
  salt,
@@ -5061,21 +5086,21 @@ function computeHintedClassHash(compiledContract) {
5061
5086
  function computeLegacyContractClassHash(contract) {
5062
5087
  const compiledContract = isString(contract) ? parse2(contract) : contract;
5063
5088
  const apiVersion = toHex(API_VERSION);
5064
- const externalEntryPointsHash = computeHashOnElements2(
5089
+ const externalEntryPointsHash = computeHashOnElements(
5065
5090
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
5066
5091
  );
5067
- const l1HandlerEntryPointsHash = computeHashOnElements2(
5092
+ const l1HandlerEntryPointsHash = computeHashOnElements(
5068
5093
  compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
5069
5094
  );
5070
- const constructorEntryPointHash = computeHashOnElements2(
5095
+ const constructorEntryPointHash = computeHashOnElements(
5071
5096
  compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
5072
5097
  );
5073
- const builtinsHash = computeHashOnElements2(
5098
+ const builtinsHash = computeHashOnElements(
5074
5099
  compiledContract.program.builtins.map((s) => encodeShortString(s))
5075
5100
  );
5076
5101
  const hintedClassHash = computeHintedClassHash(compiledContract);
5077
- const dataHash = computeHashOnElements2(compiledContract.program.data);
5078
- return computeHashOnElements2([
5102
+ const dataHash = computeHashOnElements(compiledContract.program.data);
5103
+ return computeHashOnElements([
5079
5104
  apiVersion,
5080
5105
  externalEntryPointsHash,
5081
5106
  l1HandlerEntryPointsHash,