starknet 8.5.2 → 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/dist/index.js CHANGED
@@ -1280,7 +1280,8 @@ var CairoFelt252 = class _CairoFelt252 {
1280
1280
  static abiSelector = "core::felt252";
1281
1281
  constructor(data) {
1282
1282
  _CairoFelt252.validate(data);
1283
- this.data = _CairoFelt252.__processData(data);
1283
+ const processedData = _CairoFelt252.__processData(data);
1284
+ this.data = processedData.subarray(processedData.findIndex((x) => x > 0));
1284
1285
  }
1285
1286
  static __processData(data) {
1286
1287
  if (isString(data)) {
@@ -1883,7 +1884,9 @@ var CairoBytes31 = class _CairoBytes31 {
1883
1884
  static abiSelector = "core::bytes_31::bytes31";
1884
1885
  constructor(data) {
1885
1886
  _CairoBytes31.validate(data);
1886
- this.data = _CairoBytes31.__processData(data);
1887
+ const processedData = _CairoBytes31.__processData(data);
1888
+ this.data = new Uint8Array(_CairoBytes31.MAX_BYTE_SIZE);
1889
+ this.data.set(processedData, _CairoBytes31.MAX_BYTE_SIZE - processedData.length);
1887
1890
  }
1888
1891
  static __processData(data) {
1889
1892
  if (isString(data)) {
@@ -1904,11 +1907,16 @@ var CairoBytes31 = class _CairoBytes31 {
1904
1907
  return uint8ArrayToBigInt(this.data);
1905
1908
  }
1906
1909
  decodeUtf8() {
1907
- return new TextDecoder().decode(this.data);
1910
+ const cutoff = this.data.findIndex((x) => x > 0);
1911
+ const pruned = this.data.subarray(cutoff >= 0 ? cutoff : Infinity);
1912
+ return new TextDecoder().decode(pruned);
1908
1913
  }
1909
- toHexString() {
1910
- const hexValue = this.data.length === 0 ? "0" : buf2hex(this.data);
1911
- return addHexPrefix(hexValue);
1914
+ /**
1915
+ * @param padded flag for including leading zeros
1916
+ */
1917
+ toHexString(padded) {
1918
+ const hex = padded === "padded" ? buf2hex(this.data) : this.toBigInt().toString(16);
1919
+ return addHexPrefix(hex);
1912
1920
  }
1913
1921
  static validate(data) {
1914
1922
  const byteLength = _CairoBytes31.__processData(data).length;
@@ -2204,11 +2212,11 @@ var CairoByteArray = class _CairoByteArray {
2204
2212
  ]);
2205
2213
  }
2206
2214
  decodeUtf8() {
2207
- const allBytes = this.reconstructBytes();
2215
+ const allBytes = concatenateArrayBuffer(this.toElements());
2208
2216
  return new TextDecoder().decode(allBytes);
2209
2217
  }
2210
2218
  toBigInt() {
2211
- const allBytes = this.reconstructBytes();
2219
+ const allBytes = concatenateArrayBuffer(this.toElements());
2212
2220
  if (allBytes.length === 0) {
2213
2221
  return 0n;
2214
2222
  }
@@ -2219,15 +2227,39 @@ var CairoByteArray = class _CairoByteArray {
2219
2227
  return result;
2220
2228
  }
2221
2229
  toHexString() {
2222
- const allBytes = this.reconstructBytes();
2230
+ const allBytes = concatenateArrayBuffer(this.toElements());
2223
2231
  const hexValue = allBytes.length === 0 ? "0" : buf2hex(allBytes);
2224
2232
  return addHexPrefix(hexValue);
2225
2233
  }
2226
2234
  toBuffer() {
2227
- this.assertInitialized();
2228
- const allBytes = this.reconstructBytes();
2235
+ const allBytes = concatenateArrayBuffer(this.toElements());
2229
2236
  return buffer_default.from(allBytes);
2230
2237
  }
2238
+ /**
2239
+ * returns an array of all the data chunks and the pending word
2240
+ * when concatenated, represents the original bytes sequence
2241
+ */
2242
+ toElements() {
2243
+ this.assertInitialized();
2244
+ const allChunks = this.data.flatMap((chunk) => chunk.data);
2245
+ const pendingLen = Number(this.pending_word_len.toBigInt());
2246
+ if (pendingLen) {
2247
+ const pending = new Uint8Array(pendingLen);
2248
+ const paddingDifference = pendingLen - this.pending_word.data.length;
2249
+ pending.set(this.pending_word.data, paddingDifference);
2250
+ allChunks.push(pending);
2251
+ }
2252
+ return allChunks;
2253
+ }
2254
+ /**
2255
+ * Private helper to check if the CairoByteArray is properly initialized
2256
+ */
2257
+ assertInitialized() {
2258
+ assert(
2259
+ this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
2260
+ "CairoByteArray is not properly initialized"
2261
+ );
2262
+ }
2231
2263
  static validate(data) {
2232
2264
  assert(data !== null && data !== void 0, "Invalid input: null or undefined");
2233
2265
  assert(
@@ -2275,30 +2307,6 @@ var CairoByteArray = class _CairoByteArray {
2275
2307
  static isAbiType(abiType) {
2276
2308
  return abiType === _CairoByteArray.abiSelector;
2277
2309
  }
2278
- /**
2279
- * Private helper to check if the CairoByteArray is properly initialized
2280
- */
2281
- assertInitialized() {
2282
- assert(
2283
- this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
2284
- "CairoByteArray is not properly initialized"
2285
- );
2286
- }
2287
- /**
2288
- * Private helper to reconstruct the full byte sequence from chunks and pending word
2289
- */
2290
- reconstructBytes() {
2291
- this.assertInitialized();
2292
- const allChunks = this.data.flatMap((chunk) => chunk.data);
2293
- const pendingLen = Number(this.pending_word_len.toBigInt());
2294
- if (pendingLen) {
2295
- const pending = new Uint8Array(pendingLen);
2296
- const paddingDifference = pendingLen - this.pending_word.data.length;
2297
- pending.set(this.pending_word.data, paddingDifference);
2298
- allChunks.push(pending);
2299
- }
2300
- return concatenateArrayBuffer(allChunks);
2301
- }
2302
2310
  static factoryFromApiResponse(responseIterator) {
2303
2311
  const data = Array.from(
2304
2312
  { length: Number(getNext(responseIterator)) },