starknet 8.5.0 → 8.5.1

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
+ ## [8.5.1](https://github.com/starknet-io/starknet.js/compare/v8.5.0...v8.5.1) (2025-08-27)
2
+
3
+ ### Bug Fixes
4
+
5
+ - preserve leading zeros for pending word within byte array ([5d7ab04](https://github.com/starknet-io/starknet.js/commit/5d7ab042ce1a81e4f31a5ec4488db758308e872a))
6
+
1
7
  # [8.5.0](https://github.com/starknet-io/starknet.js/compare/v8.4.0...v8.5.0) (2025-08-18)
2
8
 
3
9
  ### Features
@@ -6247,8 +6247,7 @@ ${indent}}` : "}";
6247
6247
  }
6248
6248
  decodeUtf8() {
6249
6249
  const allBytes = this.reconstructBytes();
6250
- const fullBytes = new Uint8Array(allBytes);
6251
- return new TextDecoder().decode(fullBytes);
6250
+ return new TextDecoder().decode(allBytes);
6252
6251
  }
6253
6252
  toBigInt() {
6254
6253
  const allBytes = this.reconstructBytes();
@@ -6262,32 +6261,13 @@ ${indent}}` : "}";
6262
6261
  return result;
6263
6262
  }
6264
6263
  toHexString() {
6265
- return addHexPrefix(this.toBigInt().toString(16));
6264
+ const allBytes = this.reconstructBytes();
6265
+ const hexValue = allBytes.length === 0 ? "0" : buf2hex(allBytes);
6266
+ return addHexPrefix(hexValue);
6266
6267
  }
6267
6268
  toBuffer() {
6268
6269
  this.assertInitialized();
6269
- const allBytes = [];
6270
- this.data.forEach((chunk) => {
6271
- const chunkBytes = chunk.data;
6272
- for (let i = 0; i < chunkBytes.length; i += 1) {
6273
- allBytes.push(chunkBytes[i]);
6274
- }
6275
- });
6276
- const pendingLen = Number(this.pending_word_len.toBigInt());
6277
- if (pendingLen > 0) {
6278
- const hex = this.pending_word.toHexString();
6279
- const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
6280
- const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
6281
- for (let i = 0; i < pendingLen; i += 1) {
6282
- const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
6283
- if (byteHex.length >= 2) {
6284
- const byteValue = parseInt(byteHex, 16);
6285
- if (!Number.isNaN(byteValue)) {
6286
- allBytes.push(byteValue);
6287
- }
6288
- }
6289
- }
6290
- }
6270
+ const allBytes = this.reconstructBytes();
6291
6271
  return buffer_default.from(allBytes);
6292
6272
  }
6293
6273
  static validate(data) {
@@ -6351,32 +6331,15 @@ ${indent}}` : "}";
6351
6331
  */
6352
6332
  reconstructBytes() {
6353
6333
  this.assertInitialized();
6354
- const allBytes = [];
6355
- this.data.forEach((chunk) => {
6356
- const chunkBytes = chunk.data;
6357
- for (let i = 0; i < chunkBytes.length; i += 1) {
6358
- allBytes.push(chunkBytes[i]);
6359
- }
6360
- });
6334
+ const allChunks = this.data.flatMap((chunk) => chunk.data);
6361
6335
  const pendingLen = Number(this.pending_word_len.toBigInt());
6362
- if (pendingLen > 0) {
6363
- const hex = this.pending_word.toHexString();
6364
- const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
6365
- const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
6366
- for (let i = 0; i < pendingLen; i += 1) {
6367
- const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
6368
- if (byteHex.length < 2) {
6369
- allBytes.push(0);
6370
- } else {
6371
- const byteValue = parseInt(byteHex, 16);
6372
- if (Number.isNaN(byteValue)) {
6373
- throw new Error(`Invalid hex byte: ${byteHex}`);
6374
- }
6375
- allBytes.push(byteValue);
6376
- }
6377
- }
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);
6378
6341
  }
6379
- return allBytes;
6342
+ return concatenateArrayBuffer(allChunks);
6380
6343
  }
6381
6344
  static factoryFromApiResponse(responseIterator) {
6382
6345
  const data = Array.from(