starknet 8.5.1 → 8.5.3

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,15 @@
1
+ ## [8.5.3](https://github.com/starknet-io/starknet.js/compare/v8.5.2...v8.5.3) (2025-09-05)
2
+
3
+ ### Bug Fixes
4
+
5
+ - enforce fixed size for cairo bytes ([6a56166](https://github.com/starknet-io/starknet.js/commit/6a56166e65c79d68e012083cefff3fb532e150ac))
6
+
7
+ ## [8.5.2](https://github.com/starknet-io/starknet.js/compare/v8.5.1...v8.5.2) (2025-08-27)
8
+
9
+ ### Bug Fixes
10
+
11
+ - preserve leading zeros for cairo bytes data ([5542a00](https://github.com/starknet-io/starknet.js/commit/5542a0015d0cc3cae186d63fe4258c9942ff07d2))
12
+
1
13
  ## [8.5.1](https://github.com/starknet-io/starknet.js/compare/v8.5.0...v8.5.1) (2025-08-27)
2
14
 
3
15
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -8513,7 +8513,10 @@ declare class CairoBytes31 {
8513
8513
  toApiRequest(): string[];
8514
8514
  toBigInt(): bigint;
8515
8515
  decodeUtf8(): string;
8516
- toHexString(): string;
8516
+ /**
8517
+ * @param padded flag for including leading zeros
8518
+ */
8519
+ toHexString(padded?: 'padded'): string;
8517
8520
  static validate(data: Uint8Array | string | Buffer | unknown): void;
8518
8521
  static is(data: Uint8Array | string | Buffer): boolean;
8519
8522
  /**
@@ -8600,6 +8603,15 @@ declare class CairoByteArray {
8600
8603
  toBigInt(): bigint;
8601
8604
  toHexString(): string;
8602
8605
  toBuffer(): any;
8606
+ /**
8607
+ * returns an array of all the data chunks and the pending word
8608
+ * when concatenated, represents the original bytes sequence
8609
+ */
8610
+ toElements(): Uint8Array[];
8611
+ /**
8612
+ * Private helper to check if the CairoByteArray is properly initialized
8613
+ */
8614
+ private assertInitialized;
8603
8615
  static validate(data: Uint8Array | Buffer | BigNumberish | unknown): void;
8604
8616
  /**
8605
8617
  * Check if the provided data is a valid CairoByteArray
@@ -8612,14 +8624,6 @@ declare class CairoByteArray {
8612
8624
  * Check if provided abi type is this data type
8613
8625
  */
8614
8626
  static isAbiType(abiType: string): boolean;
8615
- /**
8616
- * Private helper to check if the CairoByteArray is properly initialized
8617
- */
8618
- private assertInitialized;
8619
- /**
8620
- * Private helper to reconstruct the full byte sequence from chunks and pending word
8621
- */
8622
- private reconstructBytes;
8623
8627
  static factoryFromApiResponse(responseIterator: Iterator<string>): CairoByteArray;
8624
8628
  }
8625
8629
 
@@ -5323,7 +5323,8 @@ ${indent}}` : "}";
5323
5323
  static abiSelector = "core::felt252";
5324
5324
  constructor(data) {
5325
5325
  _CairoFelt252.validate(data);
5326
- this.data = _CairoFelt252.__processData(data);
5326
+ const processedData = _CairoFelt252.__processData(data);
5327
+ this.data = processedData.subarray(processedData.findIndex((x) => x > 0));
5327
5328
  }
5328
5329
  static __processData(data) {
5329
5330
  if (isString(data)) {
@@ -5926,7 +5927,9 @@ ${indent}}` : "}";
5926
5927
  static abiSelector = "core::bytes_31::bytes31";
5927
5928
  constructor(data) {
5928
5929
  _CairoBytes31.validate(data);
5929
- this.data = _CairoBytes31.__processData(data);
5930
+ const processedData = _CairoBytes31.__processData(data);
5931
+ this.data = new Uint8Array(_CairoBytes31.MAX_BYTE_SIZE);
5932
+ this.data.set(processedData, _CairoBytes31.MAX_BYTE_SIZE - processedData.length);
5930
5933
  }
5931
5934
  static __processData(data) {
5932
5935
  if (isString(data)) {
@@ -5947,10 +5950,16 @@ ${indent}}` : "}";
5947
5950
  return uint8ArrayToBigInt(this.data);
5948
5951
  }
5949
5952
  decodeUtf8() {
5950
- return new TextDecoder().decode(this.data);
5953
+ const cutoff = this.data.findIndex((x) => x > 0);
5954
+ const pruned = this.data.subarray(cutoff >= 0 ? cutoff : Infinity);
5955
+ return new TextDecoder().decode(pruned);
5951
5956
  }
5952
- toHexString() {
5953
- return addHexPrefix(this.toBigInt().toString(16));
5957
+ /**
5958
+ * @param padded flag for including leading zeros
5959
+ */
5960
+ toHexString(padded) {
5961
+ const hex = padded === "padded" ? buf2hex(this.data) : this.toBigInt().toString(16);
5962
+ return addHexPrefix(hex);
5954
5963
  }
5955
5964
  static validate(data) {
5956
5965
  const byteLength = _CairoBytes31.__processData(data).length;
@@ -6246,11 +6255,11 @@ ${indent}}` : "}";
6246
6255
  ]);
6247
6256
  }
6248
6257
  decodeUtf8() {
6249
- const allBytes = this.reconstructBytes();
6258
+ const allBytes = concatenateArrayBuffer(this.toElements());
6250
6259
  return new TextDecoder().decode(allBytes);
6251
6260
  }
6252
6261
  toBigInt() {
6253
- const allBytes = this.reconstructBytes();
6262
+ const allBytes = concatenateArrayBuffer(this.toElements());
6254
6263
  if (allBytes.length === 0) {
6255
6264
  return 0n;
6256
6265
  }
@@ -6261,15 +6270,39 @@ ${indent}}` : "}";
6261
6270
  return result;
6262
6271
  }
6263
6272
  toHexString() {
6264
- const allBytes = this.reconstructBytes();
6273
+ const allBytes = concatenateArrayBuffer(this.toElements());
6265
6274
  const hexValue = allBytes.length === 0 ? "0" : buf2hex(allBytes);
6266
6275
  return addHexPrefix(hexValue);
6267
6276
  }
6268
6277
  toBuffer() {
6269
- this.assertInitialized();
6270
- const allBytes = this.reconstructBytes();
6278
+ const allBytes = concatenateArrayBuffer(this.toElements());
6271
6279
  return buffer_default.from(allBytes);
6272
6280
  }
6281
+ /**
6282
+ * returns an array of all the data chunks and the pending word
6283
+ * when concatenated, represents the original bytes sequence
6284
+ */
6285
+ toElements() {
6286
+ this.assertInitialized();
6287
+ const allChunks = this.data.flatMap((chunk) => chunk.data);
6288
+ const pendingLen = Number(this.pending_word_len.toBigInt());
6289
+ if (pendingLen) {
6290
+ const pending = new Uint8Array(pendingLen);
6291
+ const paddingDifference = pendingLen - this.pending_word.data.length;
6292
+ pending.set(this.pending_word.data, paddingDifference);
6293
+ allChunks.push(pending);
6294
+ }
6295
+ return allChunks;
6296
+ }
6297
+ /**
6298
+ * Private helper to check if the CairoByteArray is properly initialized
6299
+ */
6300
+ assertInitialized() {
6301
+ assert(
6302
+ this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
6303
+ "CairoByteArray is not properly initialized"
6304
+ );
6305
+ }
6273
6306
  static validate(data) {
6274
6307
  assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6275
6308
  assert(
@@ -6317,30 +6350,6 @@ ${indent}}` : "}";
6317
6350
  static isAbiType(abiType) {
6318
6351
  return abiType === _CairoByteArray.abiSelector;
6319
6352
  }
6320
- /**
6321
- * Private helper to check if the CairoByteArray is properly initialized
6322
- */
6323
- assertInitialized() {
6324
- assert(
6325
- this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
6326
- "CairoByteArray is not properly initialized"
6327
- );
6328
- }
6329
- /**
6330
- * Private helper to reconstruct the full byte sequence from chunks and pending word
6331
- */
6332
- reconstructBytes() {
6333
- this.assertInitialized();
6334
- const allChunks = this.data.flatMap((chunk) => chunk.data);
6335
- const pendingLen = Number(this.pending_word_len.toBigInt());
6336
- if (pendingLen) {
6337
- const pending = new Uint8Array(pendingLen);
6338
- const paddingDifference = pendingLen - this.pending_word.data.length;
6339
- pending.set(this.pending_word.data, paddingDifference);
6340
- allChunks.push(pending);
6341
- }
6342
- return concatenateArrayBuffer(allChunks);
6343
- }
6344
6353
  static factoryFromApiResponse(responseIterator) {
6345
6354
  const data = Array.from(
6346
6355
  { length: Number(getNext(responseIterator)) },