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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [10.2.0](https://github.com/starknet-io/starknet.js/compare/v10.1.0...v10.2.0) (2026-06-10)
2
+
3
+ ### Features
4
+
5
+ - in class CairoByteArray hash added. Solve a code cycling ([1ab4c06](https://github.com/starknet-io/starknet.js/commit/1ab4c06884f1decf0317010c4ae97e8ec40d9fd4))
6
+
1
7
  # [10.1.0](https://github.com/starknet-io/starknet.js/compare/v10.0.4...v10.1.0) (2026-06-09)
2
8
 
3
9
  ### Features
package/README.md CHANGED
@@ -50,11 +50,11 @@ $ npm install starknet@next
50
50
  $ npm install starknet@beta
51
51
  ```
52
52
 
53
- Import `starknet` and use the [API](https://www.starknetjs.com/docs/API/).
53
+ Import `starknet` and use the [API](https://starknet-io.github.io/starknet.js/docs/API/).
54
54
 
55
55
  ## 🌐 Documentation
56
56
 
57
- How to [Guides](https://www.starknetjs.com/docs/guides/intro) :book: & [API](https://www.starknetjs.com/docs/API/) 💻
57
+ How to [Guides](https://starknet-io.github.io/starknet.js/docs/guides/intro) :book: & [API](https://starknet-io.github.io/starknet.js/docs/API/) 💻
58
58
 
59
59
  Play with [Code Examples](https://github.com/PhilippeR26/starknet.js-workshop-typescript) :video_game:
60
60
 
package/dist/index.d.ts CHANGED
@@ -3613,7 +3613,7 @@ type ParsedEvents = Array<ParsedEvent> & {
3613
3613
  };
3614
3614
  /**
3615
3615
  * Advance formatting used to get js types data as result
3616
- * @description https://starknetjs.com/docs/guides/define_call_message/#formatresponse
3616
+ * @description https://starknet-io.github.io/starknet.js/docs/guides/define_call_message/#formatresponse
3617
3617
  * @example
3618
3618
  * ```typescript
3619
3619
  * // assign custom or existing method to resulting data
@@ -6629,7 +6629,7 @@ type CalcDeployAccountTxHashArgs = CalcV3DeployAccountTxHashArgs;
6629
6629
  declare function calculateDeployAccountTransactionHash$1(args: CalcDeployAccountTxHashArgs): string;
6630
6630
 
6631
6631
  /**
6632
- * Cairo 0 Class Hash computation using Pedersen hash
6632
+ * Pure Pedersen hash utilities no calldata dependency
6633
6633
  */
6634
6634
 
6635
6635
  declare function computePedersenHash(a: BigNumberish, b: BigNumberish): string;
@@ -6647,6 +6647,11 @@ declare function computePedersenHash(a: BigNumberish, b: BigNumberish): string;
6647
6647
  */
6648
6648
  declare function computeHashOnElements(data: BigNumberish[]): string;
6649
6649
  declare const computePedersenHashOnElements: typeof computeHashOnElements;
6650
+
6651
+ /**
6652
+ * Cairo 0 Class Hash computation using Pedersen hash
6653
+ */
6654
+
6650
6655
  /**
6651
6656
  * Calculate contract address from class hash
6652
6657
  *
@@ -9416,6 +9421,22 @@ declare class CairoByteArray {
9416
9421
  toBigInt(): bigint;
9417
9422
  toHexString(): string;
9418
9423
  toBuffer(): any;
9424
+ /**
9425
+ * Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
9426
+ *
9427
+ * Serializes the ByteArray to its felt252 components (data array length, each data chunk,
9428
+ * pending_word, pending_word_len), then chains Pedersen hash over all elements starting
9429
+ * from 0, and finalizes with the total element count.
9430
+ *
9431
+ * @returns {string} hex-string felt252 Pedersen hash of the ByteArray
9432
+ * @example
9433
+ * ```typescript
9434
+ * const ba = new CairoByteArray('Hello');
9435
+ * const result = ba.hash();
9436
+ * // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
9437
+ * ```
9438
+ */
9439
+ hash(): string;
9419
9440
  /**
9420
9441
  * returns an array of all the data chunks and the pending word
9421
9442
  * when concatenated, represents the original bytes sequence
@@ -6261,6 +6261,22 @@ ${indent}}` : "}";
6261
6261
  }
6262
6262
  };
6263
6263
 
6264
+ // src/utils/ec.ts
6265
+ var ec_exports = {};
6266
+ __export(ec_exports, {
6267
+ starkCurve: () => esm_exports4,
6268
+ weierstrass: () => weierstrass_exports
6269
+ });
6270
+
6271
+ // src/utils/hash/pedersenCore.ts
6272
+ function computePedersenHash(a, b) {
6273
+ return esm_exports4.pedersen(BigInt(a), BigInt(b));
6274
+ }
6275
+ function computeHashOnElements2(data) {
6276
+ return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
6277
+ }
6278
+ var computePedersenHashOnElements = computeHashOnElements2;
6279
+
6264
6280
  // src/utils/errors/rpc.ts
6265
6281
  var errorCodes = {
6266
6282
  FAILED_TO_RECEIVE_TXN: 1,
@@ -6555,6 +6571,31 @@ ${indent}}` : "}";
6555
6571
  const allBytes = concatenateArrayBuffer(this.toElements());
6556
6572
  return buffer_default.from(allBytes);
6557
6573
  }
6574
+ /**
6575
+ * Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
6576
+ *
6577
+ * Serializes the ByteArray to its felt252 components (data array length, each data chunk,
6578
+ * pending_word, pending_word_len), then chains Pedersen hash over all elements starting
6579
+ * from 0, and finalizes with the total element count.
6580
+ *
6581
+ * @returns {string} hex-string felt252 Pedersen hash of the ByteArray
6582
+ * @example
6583
+ * ```typescript
6584
+ * const ba = new CairoByteArray('Hello');
6585
+ * const result = ba.hash();
6586
+ * // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
6587
+ * ```
6588
+ */
6589
+ hash() {
6590
+ this.assertInitialized();
6591
+ const serialized = [
6592
+ addHexPrefix(this.data.length.toString(16)),
6593
+ ...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
6594
+ ...this.pending_word.toApiRequest(),
6595
+ ...this.pending_word_len.toApiRequest()
6596
+ ];
6597
+ return computeHashOnElements2(serialized);
6598
+ }
6558
6599
  /**
6559
6600
  * returns an array of all the data chunks and the pending word
6560
6601
  * when concatenated, represents the original bytes sequence
@@ -9115,7 +9156,7 @@ ${indent}}` : "}";
9115
9156
  computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
9116
9157
  computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
9117
9158
  computeContractClassHash: () => computeContractClassHash,
9118
- computeHashOnElements: () => computeHashOnElements3,
9159
+ computeHashOnElements: () => computeHashOnElements2,
9119
9160
  computeHintedClassHash: () => computeHintedClassHash,
9120
9161
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
9121
9162
  computePedersenHash: () => computePedersenHash,
@@ -9253,22 +9294,13 @@ ${indent}}` : "}";
9253
9294
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
9254
9295
  calculateTransactionHash: () => calculateTransactionHash,
9255
9296
  calculateTransactionHashCommon: () => calculateTransactionHashCommon2,
9256
- computeHashOnElements: () => computeHashOnElements2
9257
- });
9258
-
9259
- // src/utils/ec.ts
9260
- var ec_exports = {};
9261
- __export(ec_exports, {
9262
- starkCurve: () => esm_exports4,
9263
- weierstrass: () => weierstrass_exports
9297
+ computeHashOnElements: () => computeHashOnElements3
9264
9298
  });
9265
-
9266
- // src/utils/hash/transactionHash/v2.ts
9267
- function computeHashOnElements2(data) {
9299
+ function computeHashOnElements3(data) {
9268
9300
  return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
9269
9301
  }
9270
9302
  function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
9271
- const calldataHash = computeHashOnElements2(calldata);
9303
+ const calldataHash = computeHashOnElements3(calldata);
9272
9304
  const dataToHash = [
9273
9305
  txHashPrefix,
9274
9306
  version,
@@ -9279,7 +9311,7 @@ ${indent}}` : "}";
9279
9311
  chainId,
9280
9312
  ...additionalData
9281
9313
  ];
9282
- return computeHashOnElements2(dataToHash);
9314
+ return computeHashOnElements3(dataToHash);
9283
9315
  }
9284
9316
  function calculateDeclareTransactionHash2(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
9285
9317
  return calculateTransactionHashCommon2(
@@ -9438,18 +9470,11 @@ ${indent}}` : "}";
9438
9470
  }
9439
9471
 
9440
9472
  // src/utils/hash/classHash/pedersen.ts
9441
- function computePedersenHash(a, b) {
9442
- return esm_exports4.pedersen(BigInt(a), BigInt(b));
9443
- }
9444
- function computeHashOnElements3(data) {
9445
- return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
9446
- }
9447
- var computePedersenHashOnElements = computeHashOnElements3;
9448
9473
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
9449
9474
  const compiledCalldata = CallData.compile(constructorCalldata);
9450
- const constructorCalldataHash = computeHashOnElements3(compiledCalldata);
9475
+ const constructorCalldataHash = computeHashOnElements2(compiledCalldata);
9451
9476
  const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
9452
- const hash = computeHashOnElements3([
9477
+ const hash = computeHashOnElements2([
9453
9478
  CONTRACT_ADDRESS_PREFIX,
9454
9479
  deployerAddress,
9455
9480
  salt,
@@ -9467,21 +9492,21 @@ ${indent}}` : "}";
9467
9492
  function computeLegacyContractClassHash(contract) {
9468
9493
  const compiledContract = isString(contract) ? parse2(contract) : contract;
9469
9494
  const apiVersion = toHex(API_VERSION);
9470
- const externalEntryPointsHash = computeHashOnElements3(
9495
+ const externalEntryPointsHash = computeHashOnElements2(
9471
9496
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
9472
9497
  );
9473
- const l1HandlerEntryPointsHash = computeHashOnElements3(
9498
+ const l1HandlerEntryPointsHash = computeHashOnElements2(
9474
9499
  compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
9475
9500
  );
9476
- const constructorEntryPointHash = computeHashOnElements3(
9501
+ const constructorEntryPointHash = computeHashOnElements2(
9477
9502
  compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
9478
9503
  );
9479
- const builtinsHash = computeHashOnElements3(
9504
+ const builtinsHash = computeHashOnElements2(
9480
9505
  compiledContract.program.builtins.map((s) => encodeShortString(s))
9481
9506
  );
9482
9507
  const hintedClassHash = computeHintedClassHash(compiledContract);
9483
- const dataHash = computeHashOnElements3(compiledContract.program.data);
9484
- return computeHashOnElements3([
9508
+ const dataHash = computeHashOnElements2(compiledContract.program.data);
9509
+ return computeHashOnElements2([
9485
9510
  apiVersion,
9486
9511
  externalEntryPointsHash,
9487
9512
  l1HandlerEntryPointsHash,