starknet 8.5.2 → 8.5.4

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;
@@ -1966,10 +1974,13 @@ var errorCodes = {
1966
1974
  UNSUPPORTED_TX_VERSION: 61,
1967
1975
  UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
1968
1976
  UNEXPECTED_ERROR: 63,
1977
+ REPLACEMENT_TRANSACTION_UNDERPRICED: 64,
1978
+ FEE_BELOW_MINIMUM: 65,
1969
1979
  INVALID_SUBSCRIPTION_ID: 66,
1970
1980
  TOO_MANY_ADDRESSES_IN_FILTER: 67,
1971
1981
  TOO_MANY_BLOCKS_BACK: 68,
1972
1982
  COMPILATION_ERROR: 100,
1983
+ //
1973
1984
  INVALID_ADDRESS: 150,
1974
1985
  TOKEN_NOT_SUPPORTED: 151,
1975
1986
  INVALID_SIGNATURE: 153,
@@ -2204,11 +2215,11 @@ var CairoByteArray = class _CairoByteArray {
2204
2215
  ]);
2205
2216
  }
2206
2217
  decodeUtf8() {
2207
- const allBytes = this.reconstructBytes();
2218
+ const allBytes = concatenateArrayBuffer(this.toElements());
2208
2219
  return new TextDecoder().decode(allBytes);
2209
2220
  }
2210
2221
  toBigInt() {
2211
- const allBytes = this.reconstructBytes();
2222
+ const allBytes = concatenateArrayBuffer(this.toElements());
2212
2223
  if (allBytes.length === 0) {
2213
2224
  return 0n;
2214
2225
  }
@@ -2219,15 +2230,39 @@ var CairoByteArray = class _CairoByteArray {
2219
2230
  return result;
2220
2231
  }
2221
2232
  toHexString() {
2222
- const allBytes = this.reconstructBytes();
2233
+ const allBytes = concatenateArrayBuffer(this.toElements());
2223
2234
  const hexValue = allBytes.length === 0 ? "0" : buf2hex(allBytes);
2224
2235
  return addHexPrefix(hexValue);
2225
2236
  }
2226
2237
  toBuffer() {
2227
- this.assertInitialized();
2228
- const allBytes = this.reconstructBytes();
2238
+ const allBytes = concatenateArrayBuffer(this.toElements());
2229
2239
  return buffer_default.from(allBytes);
2230
2240
  }
2241
+ /**
2242
+ * returns an array of all the data chunks and the pending word
2243
+ * when concatenated, represents the original bytes sequence
2244
+ */
2245
+ toElements() {
2246
+ this.assertInitialized();
2247
+ const allChunks = this.data.flatMap((chunk) => chunk.data);
2248
+ const pendingLen = Number(this.pending_word_len.toBigInt());
2249
+ if (pendingLen) {
2250
+ const pending = new Uint8Array(pendingLen);
2251
+ const paddingDifference = pendingLen - this.pending_word.data.length;
2252
+ pending.set(this.pending_word.data, paddingDifference);
2253
+ allChunks.push(pending);
2254
+ }
2255
+ return allChunks;
2256
+ }
2257
+ /**
2258
+ * Private helper to check if the CairoByteArray is properly initialized
2259
+ */
2260
+ assertInitialized() {
2261
+ assert(
2262
+ this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
2263
+ "CairoByteArray is not properly initialized"
2264
+ );
2265
+ }
2231
2266
  static validate(data) {
2232
2267
  assert(data !== null && data !== void 0, "Invalid input: null or undefined");
2233
2268
  assert(
@@ -2275,30 +2310,6 @@ var CairoByteArray = class _CairoByteArray {
2275
2310
  static isAbiType(abiType) {
2276
2311
  return abiType === _CairoByteArray.abiSelector;
2277
2312
  }
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
2313
  static factoryFromApiResponse(responseIterator) {
2303
2314
  const data = Array.from(
2304
2315
  { length: Number(getNext(responseIterator)) },
@@ -5873,7 +5884,7 @@ var RpcChannel = class {
5873
5884
  }
5874
5885
  /**
5875
5886
  * fetch rpc node specVersion
5876
- * @example this.specVersion = "0.7.1"
5887
+ * @example this.specVersion = "0.8.1"
5877
5888
  */
5878
5889
  getSpecVersion() {
5879
5890
  return this.fetchEndpoint("starknet_specVersion");
@@ -6024,21 +6035,22 @@ var RpcChannel = class {
6024
6035
  }
6025
6036
  async waitForTransaction(txHash, options) {
6026
6037
  const transactionHash = toHex(txHash);
6027
- let { retries } = this;
6038
+ let retries = options?.retries ?? this.retries;
6039
+ let lifeCycleRetries = options?.lifeCycleRetries ?? 3;
6028
6040
  let onchain = false;
6029
6041
  let isErrorState = false;
6030
6042
  const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault;
6031
- const errorStates = options?.errorStates ?? [
6032
- RPCSPEC08.ETransactionStatus.REJECTED
6033
- // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
6034
- // should decide which behavior to keep in the future
6035
- // RPC.ETransactionExecutionStatus.REVERTED,
6036
- ];
6043
+ const errorStates = options?.errorStates ?? [RPCSPEC08.ETransactionStatus.REJECTED];
6037
6044
  const successStates = options?.successStates ?? [
6038
6045
  // RPC.ETransactionExecutionStatus.SUCCEEDED, Starknet 0.14.0 this one can have incomplete events
6039
6046
  RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L2,
6040
6047
  RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L1
6041
6048
  ];
6049
+ const LifeCycleErrorMessages = {
6050
+ [RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6051
+ [RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6052
+ [RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6053
+ };
6042
6054
  const txLife = [];
6043
6055
  let txStatus;
6044
6056
  while (!onchain) {
@@ -6067,15 +6079,11 @@ var RpcChannel = class {
6067
6079
  }
6068
6080
  if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
6069
6081
  logger.info("txLife: ", txLife);
6070
- const errorMessages = {
6071
- [RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6072
- [RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6073
- [RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6074
- };
6075
- const errorMessage = errorMessages[txLife.at(-1)];
6076
- if (errorMessage) {
6082
+ const errorMessage = LifeCycleErrorMessages[txLife.at(-1)];
6083
+ if (errorMessage && lifeCycleRetries <= 0) {
6077
6084
  throw new Error(errorMessage);
6078
6085
  }
6086
+ lifeCycleRetries -= 1;
6079
6087
  }
6080
6088
  if (retries <= 0) {
6081
6089
  throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
@@ -6465,14 +6473,14 @@ var RpcChannel2 = class {
6465
6473
  }
6466
6474
  /**
6467
6475
  * fetch rpc node specVersion
6468
- * @example this.specVersion = "0.7.1"
6476
+ * @example this.specVersion = "0.9.0"
6469
6477
  */
6470
6478
  getSpecVersion() {
6471
6479
  return this.fetchEndpoint("starknet_specVersion");
6472
6480
  }
6473
6481
  /**
6474
6482
  * fetch if undefined else just return this.specVersion
6475
- * @example this.specVersion = "0.8.1"
6483
+ * @example this.specVersion = "0.9.0"
6476
6484
  */
6477
6485
  async setUpSpecVersion() {
6478
6486
  if (!this.specVersion) {
@@ -6616,7 +6624,8 @@ var RpcChannel2 = class {
6616
6624
  }
6617
6625
  async waitForTransaction(txHash, options) {
6618
6626
  const transactionHash = toHex(txHash);
6619
- let { retries } = this;
6627
+ let retries = options?.retries ?? this.retries;
6628
+ let lifeCycleRetries = options?.lifeCycleRetries ?? 3;
6620
6629
  let onchain = false;
6621
6630
  let isErrorState = false;
6622
6631
  const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault;
@@ -6626,6 +6635,11 @@ var RpcChannel2 = class {
6626
6635
  RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
6627
6636
  RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1
6628
6637
  ];
6638
+ const errorMessages = {
6639
+ [RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6640
+ [RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6641
+ [RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6642
+ };
6629
6643
  const txLife = [];
6630
6644
  let txStatus;
6631
6645
  while (!onchain) {
@@ -6654,15 +6668,11 @@ var RpcChannel2 = class {
6654
6668
  }
6655
6669
  if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
6656
6670
  logger.info("txLife: ", txLife);
6657
- const errorMessages = {
6658
- [RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6659
- [RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6660
- [RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6661
- };
6662
6671
  const errorMessage = errorMessages[txLife.at(-1)];
6663
- if (errorMessage) {
6672
+ if (errorMessage && lifeCycleRetries <= 0) {
6664
6673
  throw new Error(errorMessage);
6665
6674
  }
6675
+ lifeCycleRetries -= 1;
6666
6676
  }
6667
6677
  if (retries <= 0) {
6668
6678
  throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
@@ -7849,12 +7859,15 @@ function createTransactionReceipt(receipt) {
7849
7859
  match(callbacks) {
7850
7860
  return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
7851
7861
  },
7862
+ // @ts-ignore - docs
7852
7863
  isSuccess() {
7853
7864
  return statusReceipt === "SUCCEEDED";
7854
7865
  },
7866
+ // @ts-ignore - docs
7855
7867
  isReverted() {
7856
7868
  return statusReceipt === "REVERTED";
7857
7869
  },
7870
+ // @ts-ignore - docs
7858
7871
  isError() {
7859
7872
  return false;
7860
7873
  }
@@ -7867,12 +7880,15 @@ function createTransactionReceipt(receipt) {
7867
7880
  match(callbacks) {
7868
7881
  return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
7869
7882
  },
7883
+ // @ts-ignore - docs
7870
7884
  isSuccess() {
7871
7885
  return false;
7872
7886
  },
7887
+ // @ts-ignore - docs
7873
7888
  isReverted() {
7874
7889
  return false;
7875
7890
  },
7891
+ // @ts-ignore - docs
7876
7892
  isError() {
7877
7893
  return true;
7878
7894
  }