starknet 8.1.2 → 8.3.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.
@@ -21,19 +21,33 @@ var starknet = (() => {
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ AbiParser1: () => AbiParser1,
25
+ AbiParser2: () => AbiParser2,
26
+ AbiParserInterface: () => AbiParserInterface,
24
27
  Account: () => Account,
25
28
  AccountInterface: () => AccountInterface,
26
29
  BatchClient: () => BatchClient,
27
30
  BlockStatus: () => BlockStatus,
28
31
  BlockTag: () => BlockTag,
32
+ CairoByteArray: () => CairoByteArray,
29
33
  CairoCustomEnum: () => CairoCustomEnum,
30
34
  CairoFixedArray: () => CairoFixedArray,
35
+ CairoInt128: () => CairoInt128,
36
+ CairoInt16: () => CairoInt16,
37
+ CairoInt32: () => CairoInt32,
38
+ CairoInt64: () => CairoInt64,
39
+ CairoInt8: () => CairoInt8,
31
40
  CairoOption: () => CairoOption,
32
41
  CairoOptionVariant: () => CairoOptionVariant,
33
42
  CairoResult: () => CairoResult,
34
43
  CairoResultVariant: () => CairoResultVariant,
44
+ CairoUint128: () => CairoUint128,
45
+ CairoUint16: () => CairoUint16,
35
46
  CairoUint256: () => CairoUint256,
36
47
  CairoUint512: () => CairoUint512,
48
+ CairoUint64: () => CairoUint64,
49
+ CairoUint8: () => CairoUint8,
50
+ CairoUint96: () => CairoUint96,
37
51
  CallData: () => CallData,
38
52
  Contract: () => Contract,
39
53
  ContractInterface: () => ContractInterface,
@@ -49,6 +63,7 @@ var starknet = (() => {
49
63
  ETransactionVersion3: () => ETransactionVersion33,
50
64
  EntryPointType: () => EntryPointType,
51
65
  EthSigner: () => EthSigner,
66
+ Int: () => Int,
52
67
  LedgerSigner: () => LedgerSigner111,
53
68
  LedgerSigner111: () => LedgerSigner111,
54
69
  LedgerSigner221: () => LedgerSigner221,
@@ -102,6 +117,8 @@ var starknet = (() => {
102
117
  config: () => config,
103
118
  constants: () => constants_exports,
104
119
  contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
120
+ createAbiParser: () => createAbiParser,
121
+ createTransactionReceipt: () => createTransactionReceipt,
105
122
  defaultDeployer: () => defaultDeployer,
106
123
  defaultPaymaster: () => defaultPaymaster,
107
124
  defaultProvider: () => defaultProvider,
@@ -110,6 +127,8 @@ var starknet = (() => {
110
127
  eth: () => eth_exports,
111
128
  events: () => events_exports,
112
129
  extractContractHashes: () => extractContractHashes,
130
+ fastParsingStrategy: () => fastParsingStrategy,
131
+ getAbiVersion: () => getAbiVersion,
113
132
  getChecksumAddress: () => getChecksumAddress,
114
133
  getGasPrices: () => getGasPrices,
115
134
  getLedgerPathBuffer: () => getLedgerPathBuffer111,
@@ -117,7 +136,9 @@ var starknet = (() => {
117
136
  getLedgerPathBuffer221: () => getLedgerPathBuffer221,
118
137
  getTipStatsFromBlocks: () => getTipStatsFromBlocks,
119
138
  hash: () => hash_exports,
139
+ hdParsingStrategy: () => hdParsingStrategy,
120
140
  isAccount: () => isAccount,
141
+ isNoConstructorValid: () => isNoConstructorValid,
121
142
  isPendingBlock: () => isPendingBlock,
122
143
  isPendingStateUpdate: () => isPendingStateUpdate,
123
144
  isPendingTransaction: () => isPendingTransaction,
@@ -175,7 +196,16 @@ var starknet = (() => {
175
196
  PRIME: () => PRIME,
176
197
  RANGE_FELT: () => RANGE_FELT,
177
198
  RANGE_I128: () => RANGE_I128,
199
+ RANGE_I16: () => RANGE_I16,
200
+ RANGE_I32: () => RANGE_I32,
201
+ RANGE_I64: () => RANGE_I64,
202
+ RANGE_I8: () => RANGE_I8,
178
203
  RANGE_U128: () => RANGE_U128,
204
+ RANGE_U16: () => RANGE_U16,
205
+ RANGE_U32: () => RANGE_U32,
206
+ RANGE_U64: () => RANGE_U64,
207
+ RANGE_U8: () => RANGE_U8,
208
+ RANGE_U96: () => RANGE_U96,
179
209
  RPC_DEFAULT_NODES: () => RPC_DEFAULT_NODES,
180
210
  SNIP9_V1_INTERFACE_ID: () => SNIP9_V1_INTERFACE_ID,
181
211
  SNIP9_V2_INTERFACE_ID: () => SNIP9_V2_INTERFACE_ID,
@@ -717,16 +747,22 @@ var starknet = (() => {
717
747
  addHexPrefix: () => addHexPrefix,
718
748
  arrayBufferToString: () => arrayBufferToString,
719
749
  atobUniversal: () => atobUniversal,
750
+ bigIntToUint8Array: () => bigIntToUint8Array,
720
751
  btoaUniversal: () => btoaUniversal,
721
752
  buf2hex: () => buf2hex,
722
753
  calcByteLength: () => calcByteLength,
723
754
  concatenateArrayBuffer: () => concatenateArrayBuffer,
755
+ hexStringToUint8Array: () => hexStringToUint8Array,
724
756
  padLeft: () => padLeft,
725
757
  pascalToSnake: () => pascalToSnake,
726
758
  removeHexPrefix: () => removeHexPrefix,
727
759
  sanitizeBytes: () => sanitizeBytes,
728
760
  sanitizeHex: () => sanitizeHex,
729
- utf8ToArray: () => utf8ToArray
761
+ stringToUint8Array: () => stringToUint8Array,
762
+ uint8ArrayToBigInt: () => uint8ArrayToBigInt,
763
+ utf8ToArray: () => utf8ToArray,
764
+ utf8ToBigInt: () => utf8ToBigInt,
765
+ utf8ToUint8Array: () => utf8ToUint8Array
730
766
  });
731
767
 
732
768
  // node_modules/@scure/base/lib/esm/index.js
@@ -913,9 +949,13 @@ var starknet = (() => {
913
949
  function arrayBufferToString(array) {
914
950
  return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
915
951
  }
916
- function utf8ToArray(str) {
952
+ function utf8ToUint8Array(str) {
917
953
  return new TextEncoder().encode(str);
918
954
  }
955
+ var utf8ToArray = utf8ToUint8Array;
956
+ function utf8ToBigInt(str) {
957
+ return uint8ArrayToBigInt(utf8ToUint8Array(str));
958
+ }
919
959
  function atobUniversal(a) {
920
960
  return base64.decode(a);
921
961
  }
@@ -967,6 +1007,61 @@ var starknet = (() => {
967
1007
  });
968
1008
  return result;
969
1009
  }
1010
+ function hexStringToUint8Array(hex) {
1011
+ const cleanHex2 = hex.startsWith("0x") ? hex.slice(2) : hex;
1012
+ if (cleanHex2.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanHex2)) {
1013
+ throw new Error(`Invalid hex string: "${hex}" contains non-hexadecimal characters`);
1014
+ }
1015
+ const paddedHex = cleanHex2.length % 2 !== 0 ? `0${cleanHex2}` : cleanHex2;
1016
+ const bytes = new Uint8Array(paddedHex.length / 2);
1017
+ for (let i = 0; i < paddedHex.length; i += 2) {
1018
+ bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
1019
+ }
1020
+ return bytes;
1021
+ }
1022
+ function isHexString(hex) {
1023
+ return /^0[xX][0-9a-fA-F]*$/.test(hex);
1024
+ }
1025
+ function isDecimalString(str) {
1026
+ return /^[0-9]+$/.test(str);
1027
+ }
1028
+ function stringToUint8Array(str) {
1029
+ if (isHexString(str)) {
1030
+ return hexStringToUint8Array(str);
1031
+ }
1032
+ if (isDecimalString(str)) {
1033
+ const value = BigInt(str);
1034
+ return bigIntToUint8Array(value);
1035
+ }
1036
+ return utf8ToUint8Array(str);
1037
+ }
1038
+ function bigIntToUint8Array(value) {
1039
+ if (value < 0n) {
1040
+ throw new Error(`Cannot convert negative bigint ${value} to Uint8Array`);
1041
+ }
1042
+ if (value === 0n) {
1043
+ return new Uint8Array([0]);
1044
+ }
1045
+ let hex = value.toString(16);
1046
+ if (hex.length % 2 !== 0) {
1047
+ hex = `0${hex}`;
1048
+ }
1049
+ const bytes = new Uint8Array(hex.length / 2);
1050
+ for (let i = 0; i < hex.length; i += 2) {
1051
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
1052
+ }
1053
+ return bytes;
1054
+ }
1055
+ function uint8ArrayToBigInt(data) {
1056
+ if (!data || data.length === 0) {
1057
+ return 0n;
1058
+ }
1059
+ let hex = "0x";
1060
+ for (let i = 0; i < data.length; i += 1) {
1061
+ hex += data[i].toString(16).padStart(2, "0");
1062
+ }
1063
+ return BigInt(hex);
1064
+ }
970
1065
 
971
1066
  // src/global/constants.ts
972
1067
  var TEXT_TO_FELT_MAX_LEN = 31;
@@ -979,8 +1074,17 @@ var starknet = (() => {
979
1074
  var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
980
1075
  var range = (min, max) => ({ min, max });
981
1076
  var RANGE_FELT = range(ZERO, PRIME - 1n);
982
- var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
1077
+ var RANGE_U8 = range(ZERO, 2n ** 8n - 1n);
1078
+ var RANGE_U16 = range(ZERO, 2n ** 16n - 1n);
1079
+ var RANGE_U32 = range(ZERO, 2n ** 32n - 1n);
1080
+ var RANGE_U64 = range(ZERO, 2n ** 64n - 1n);
1081
+ var RANGE_U96 = range(ZERO, 2n ** 96n - 1n);
983
1082
  var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
1083
+ var RANGE_I8 = range(-(2n ** 7n), 2n ** 7n - 1n);
1084
+ var RANGE_I16 = range(-(2n ** 15n), 2n ** 15n - 1n);
1085
+ var RANGE_I32 = range(-(2n ** 31n), 2n ** 31n - 1n);
1086
+ var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
1087
+ var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
984
1088
  var LegacyUDC = {
985
1089
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
986
1090
  ENTRYPOINT: "deployContract"
@@ -1047,7 +1151,8 @@ var starknet = (() => {
1047
1151
  },
1048
1152
  defaultTipType: "recommendedTip",
1049
1153
  fetch: void 0,
1050
- websocket: void 0
1154
+ websocket: void 0,
1155
+ buffer: void 0
1051
1156
  };
1052
1157
  var RPC_DEFAULT_NODES = {
1053
1158
  SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
@@ -1065,7 +1170,10 @@ var starknet = (() => {
1065
1170
  unsupportedSpecVersion: "The connected node specification version is not supported by this library",
1066
1171
  maxFeeInV3: "maxFee is not supported in V3 transactions, use resourceBounds instead",
1067
1172
  declareNonSierra: "Declaring non Sierra (Cairo0)contract using RPC 0.8+",
1068
- unsupportedMethodForRpcVersion: "Unsupported method for RPC version"
1173
+ unsupportedMethodForRpcVersion: "Unsupported method for RPC version",
1174
+ txEvictedFromMempool: "Transaction TTL, evicted from the mempool, try to increase the tip",
1175
+ consensusFailed: "Consensus failed to finalize the block proposal",
1176
+ txFailsBlockBuildingValidation: "Transaction fails block building validation"
1069
1177
  };
1070
1178
 
1071
1179
  // src/global/config.ts
@@ -1288,12 +1396,20 @@ ${JSON.stringify(data, null, 2)}`;
1288
1396
  u16: "core::integer::u16",
1289
1397
  u32: "core::integer::u32",
1290
1398
  u64: "core::integer::u64",
1399
+ u96: "core::integer::u96",
1291
1400
  u128: "core::integer::u128",
1292
1401
  u256: "core::integer::u256",
1293
1402
  // This one is struct
1294
1403
  u512: "core::integer::u512"
1295
1404
  // This one is struct
1296
1405
  };
1406
+ var Int = {
1407
+ i8: "core::integer::i8",
1408
+ i16: "core::integer::i16",
1409
+ i32: "core::integer::i32",
1410
+ i64: "core::integer::i64",
1411
+ i128: "core::integer::i128"
1412
+ };
1297
1413
  var Literal = {
1298
1414
  ClassHash: "core::starknet::class_hash::ClassHash",
1299
1415
  ContractAddress: "core::starknet::contract_address::ContractAddress",
@@ -2052,10 +2168,12 @@ ${indent}}` : "}";
2052
2168
  getDecimalString: () => getDecimalString,
2053
2169
  getHexString: () => getHexString,
2054
2170
  getHexStringArray: () => getHexStringArray,
2171
+ getNext: () => getNext,
2055
2172
  hexToBytes: () => hexToBytes2,
2056
2173
  hexToDecimalString: () => hexToDecimalString,
2057
2174
  isBigNumberish: () => isBigNumberish,
2058
2175
  isHex: () => isHex2,
2176
+ isHexString: () => isHexString2,
2059
2177
  isStringWholeNumber: () => isStringWholeNumber,
2060
2178
  stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
2061
2179
  toBigInt: () => toBigInt,
@@ -2709,14 +2827,21 @@ ${indent}}` : "}";
2709
2827
  function isString(value) {
2710
2828
  return typeof value === "string";
2711
2829
  }
2830
+ function isBuffer(obj) {
2831
+ return typeof Buffer !== "undefined" && obj instanceof Buffer;
2832
+ }
2712
2833
  function isObject2(item) {
2713
2834
  return !!item && typeof item === "object" && !Array.isArray(item);
2714
2835
  }
2836
+ function isInteger2(value) {
2837
+ return Number.isInteger(value);
2838
+ }
2715
2839
 
2716
2840
  // src/utils/num.ts
2717
2841
  function isHex2(hex) {
2718
2842
  return /^0[xX][0-9a-fA-F]*$/.test(hex);
2719
2843
  }
2844
+ var isHexString2 = isHex2;
2720
2845
  function toBigInt(value) {
2721
2846
  return BigInt(value);
2722
2847
  }
@@ -2804,6 +2929,11 @@ ${indent}}` : "}";
2804
2929
  function isBigNumberish(input) {
2805
2930
  return isNumber2(input) || isBigInt(input) || isString(input) && (isHex2(input) || isStringWholeNumber(input));
2806
2931
  }
2932
+ function getNext(iterator) {
2933
+ const it = iterator.next();
2934
+ if (it.done) throw new Error("Unexpected end of response");
2935
+ return it.value;
2936
+ }
2807
2937
 
2808
2938
  // src/utils/hash/selector.ts
2809
2939
  var selector_exports = {};
@@ -5051,7 +5181,7 @@ ${indent}}` : "}";
5051
5181
  decodeShortString: () => decodeShortString,
5052
5182
  encodeShortString: () => encodeShortString,
5053
5183
  isASCII: () => isASCII,
5054
- isDecimalString: () => isDecimalString,
5184
+ isDecimalString: () => isDecimalString2,
5055
5185
  isLongText: () => isLongText,
5056
5186
  isShortString: () => isShortString,
5057
5187
  isShortText: () => isShortText,
@@ -5064,7 +5194,7 @@ ${indent}}` : "}";
5064
5194
  function isShortString(str) {
5065
5195
  return str.length <= TEXT_TO_FELT_MAX_LEN;
5066
5196
  }
5067
- function isDecimalString(str) {
5197
+ function isDecimalString2(str) {
5068
5198
  return /^[0-9]*$/i.test(str);
5069
5199
  }
5070
5200
  function isText(val) {
@@ -5086,7 +5216,7 @@ ${indent}}` : "}";
5086
5216
  if (isHex2(str)) {
5087
5217
  return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
5088
5218
  }
5089
- if (isDecimalString(str)) {
5219
+ if (isDecimalString2(str)) {
5090
5220
  return decodeShortString("0X".concat(BigInt(str).toString(16)));
5091
5221
  }
5092
5222
  throw new Error(`${str} is not Hex or decimal`);
@@ -5128,12 +5258,11 @@ ${indent}}` : "}";
5128
5258
  isLen: () => isLen,
5129
5259
  isTypeArray: () => isTypeArray,
5130
5260
  isTypeBool: () => isTypeBool,
5131
- isTypeByteArray: () => isTypeByteArray,
5132
- isTypeBytes31: () => isTypeBytes31,
5133
5261
  isTypeContractAddress: () => isTypeContractAddress,
5134
5262
  isTypeEnum: () => isTypeEnum,
5135
5263
  isTypeEthAddress: () => isTypeEthAddress,
5136
5264
  isTypeFelt: () => isTypeFelt,
5265
+ isTypeInt: () => isTypeInt,
5137
5266
  isTypeLiteral: () => isTypeLiteral,
5138
5267
  isTypeNamedTuple: () => isTypeNamedTuple,
5139
5268
  isTypeNonZero: () => isTypeNonZero,
@@ -5150,6 +5279,16 @@ ${indent}}` : "}";
5150
5279
  uint512: () => uint512
5151
5280
  });
5152
5281
 
5282
+ // src/utils/helpers.ts
5283
+ function addCompiledFlag(compiled) {
5284
+ Object.defineProperty(compiled, "__compiled__", {
5285
+ enumerable: false,
5286
+ writable: false,
5287
+ value: true
5288
+ });
5289
+ return compiled;
5290
+ }
5291
+
5153
5292
  // src/utils/cairoDataTypes/felt.ts
5154
5293
  function CairoFelt(it) {
5155
5294
  if (isBigInt(it) || Number.isInteger(it)) {
@@ -5176,6 +5315,69 @@ ${indent}}` : "}";
5176
5315
  }
5177
5316
  throw new Error(`${it} can't be computed by felt()`);
5178
5317
  }
5318
+ var CairoFelt252 = class _CairoFelt252 {
5319
+ /**
5320
+ * byte representation of the felt252
5321
+ */
5322
+ data;
5323
+ static abiSelector = "core::felt252";
5324
+ constructor(data) {
5325
+ _CairoFelt252.validate(data);
5326
+ this.data = _CairoFelt252.__processData(data);
5327
+ }
5328
+ static __processData(data) {
5329
+ if (isString(data)) {
5330
+ return stringToUint8Array(data);
5331
+ }
5332
+ if (isBigInt(data)) {
5333
+ return bigIntToUint8Array(data);
5334
+ }
5335
+ if (Number.isInteger(data)) {
5336
+ return bigIntToUint8Array(BigInt(data));
5337
+ }
5338
+ if (isBoolean(data)) {
5339
+ return bigIntToUint8Array(BigInt(data ? 1 : 0));
5340
+ }
5341
+ throw new Error(`${data} can't be computed by felt()`);
5342
+ }
5343
+ toBigInt() {
5344
+ return uint8ArrayToBigInt(this.data);
5345
+ }
5346
+ decodeUtf8() {
5347
+ return new TextDecoder().decode(this.data);
5348
+ }
5349
+ toHexString() {
5350
+ return addHexPrefix(this.toBigInt().toString(16));
5351
+ }
5352
+ toApiRequest() {
5353
+ return addCompiledFlag([this.toHexString()]);
5354
+ }
5355
+ static validate(data) {
5356
+ assert(data !== null, "null value is not allowed for felt252");
5357
+ assert(data !== void 0, "undefined value is not allowed for felt252");
5358
+ assert(
5359
+ isString(data) || isNumber2(data) || isBigInt(data) || isBoolean(data),
5360
+ `Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
5361
+ );
5362
+ const value = _CairoFelt252.__processData(data);
5363
+ const bn = uint8ArrayToBigInt(value);
5364
+ assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
5365
+ }
5366
+ static is(data) {
5367
+ try {
5368
+ _CairoFelt252.validate(data);
5369
+ return true;
5370
+ } catch {
5371
+ return false;
5372
+ }
5373
+ }
5374
+ static isAbiType(abiType) {
5375
+ return abiType === _CairoFelt252.abiSelector;
5376
+ }
5377
+ static factoryFromApiResponse(responseIterator) {
5378
+ return new _CairoFelt252(getNext(responseIterator));
5379
+ }
5380
+ };
5179
5381
 
5180
5382
  // src/utils/cairoDataTypes/uint256.ts
5181
5383
  var UINT_128_MAX = (1n << 128n) - 1n;
@@ -5187,11 +5389,16 @@ ${indent}}` : "}";
5187
5389
  var UINT_256_HIGH_MIN = 0n;
5188
5390
  var CairoUint256 = class _CairoUint256 {
5189
5391
  low;
5392
+ // TODO should be u128
5190
5393
  high;
5394
+ // TODO should be u128
5191
5395
  static abiSelector = "core::integer::u256";
5192
5396
  constructor(...arr) {
5193
5397
  if (isObject2(arr[0]) && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
5194
- const props = _CairoUint256.validateProps(arr[0].low, arr[0].high);
5398
+ const props = _CairoUint256.validateProps(
5399
+ arr[0].low,
5400
+ arr[0].high
5401
+ );
5195
5402
  this.low = props.low;
5196
5403
  this.high = props.high;
5197
5404
  } else if (arr.length === 1) {
@@ -5210,9 +5417,15 @@ ${indent}}` : "}";
5210
5417
  * Validate if BigNumberish can be represented as Unit256
5211
5418
  */
5212
5419
  static validate(bigNumberish) {
5420
+ assert(bigNumberish !== null, "null value is not allowed for u256");
5421
+ assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
5422
+ assert(
5423
+ isBigNumberish(bigNumberish) || isObject2(bigNumberish),
5424
+ `Unsupported data type '${typeof bigNumberish}' for u256. Expected string, number, bigint, or Uint256 object`
5425
+ );
5213
5426
  const bigInt = BigInt(bigNumberish);
5214
- if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
5215
- if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
5427
+ assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
5428
+ assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
5216
5429
  return bigInt;
5217
5430
  }
5218
5431
  /**
@@ -5221,12 +5434,14 @@ ${indent}}` : "}";
5221
5434
  static validateProps(low, high) {
5222
5435
  const bigIntLow = BigInt(low);
5223
5436
  const bigIntHigh = BigInt(high);
5224
- if (bigIntLow < UINT_256_LOW_MIN || bigIntLow > UINT_256_LOW_MAX) {
5225
- throw new Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX");
5226
- }
5227
- if (bigIntHigh < UINT_256_HIGH_MIN || bigIntHigh > UINT_256_HIGH_MAX) {
5228
- throw new Error("high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX");
5229
- }
5437
+ assert(
5438
+ bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
5439
+ "low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
5440
+ );
5441
+ assert(
5442
+ bigIntHigh >= UINT_256_HIGH_MIN && bigIntHigh <= UINT_256_HIGH_MAX,
5443
+ "high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX"
5444
+ );
5230
5445
  return { low: bigIntLow, high: bigIntHigh };
5231
5446
  }
5232
5447
  /**
@@ -5246,6 +5461,11 @@ ${indent}}` : "}";
5246
5461
  static isAbiType(abiType) {
5247
5462
  return abiType === _CairoUint256.abiSelector;
5248
5463
  }
5464
+ static factoryFromApiResponse(responseIterator) {
5465
+ const low = getNext(responseIterator);
5466
+ const high = getNext(responseIterator);
5467
+ return new _CairoUint256(low, high);
5468
+ }
5249
5469
  /**
5250
5470
  * Return bigint representation
5251
5471
  */
@@ -5286,9 +5506,13 @@ ${indent}}` : "}";
5286
5506
  var UINT_128_MIN = 0n;
5287
5507
  var CairoUint512 = class _CairoUint512 {
5288
5508
  limb0;
5509
+ // TODO should be u128
5289
5510
  limb1;
5511
+ // TODO should be u128
5290
5512
  limb2;
5513
+ // TODO should be u128
5291
5514
  limb3;
5515
+ // TODO should be u128
5292
5516
  static abiSelector = "core::integer::u512";
5293
5517
  constructor(...arr) {
5294
5518
  if (isObject2(arr[0]) && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
@@ -5322,9 +5546,15 @@ ${indent}}` : "}";
5322
5546
  * Validate if BigNumberish can be represented as Uint512
5323
5547
  */
5324
5548
  static validate(bigNumberish) {
5549
+ assert(bigNumberish !== null, "null value is not allowed for u512");
5550
+ assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
5551
+ assert(
5552
+ isBigNumberish(bigNumberish) || isObject2(bigNumberish),
5553
+ `Unsupported data type '${typeof bigNumberish}' for u512. Expected string, number, bigint, or Uint512 object`
5554
+ );
5325
5555
  const bigInt = BigInt(bigNumberish);
5326
- if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
5327
- if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
5556
+ assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
5557
+ assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
5328
5558
  return bigInt;
5329
5559
  }
5330
5560
  /**
@@ -5336,9 +5566,10 @@ ${indent}}` : "}";
5336
5566
  const l2 = BigInt(limb2);
5337
5567
  const l3 = BigInt(limb3);
5338
5568
  [l0, l1, l2, l3].forEach((value, index) => {
5339
- if (value < UINT_128_MIN || value > UINT_128_MAX) {
5340
- throw Error(`limb${index} is not in the range of a u128 number`);
5341
- }
5569
+ assert(
5570
+ value >= UINT_128_MIN && value <= UINT_128_MAX,
5571
+ `limb${index} is not in the range of a u128 number`
5572
+ );
5342
5573
  });
5343
5574
  return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
5344
5575
  }
@@ -5359,6 +5590,13 @@ ${indent}}` : "}";
5359
5590
  static isAbiType(abiType) {
5360
5591
  return abiType === _CairoUint512.abiSelector;
5361
5592
  }
5593
+ static factoryFromApiResponse(responseIterator) {
5594
+ const limb0 = getNext(responseIterator);
5595
+ const limb1 = getNext(responseIterator);
5596
+ const limb2 = getNext(responseIterator);
5597
+ const limb3 = getNext(responseIterator);
5598
+ return new _CairoUint512(limb0, limb1, limb2, limb3);
5599
+ }
5362
5600
  /**
5363
5601
  * Return bigint representation
5364
5602
  */
@@ -5413,13 +5651,12 @@ ${indent}}` : "}";
5413
5651
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
5414
5652
  var isTypeResult = (type) => type.startsWith("core::result::Result::");
5415
5653
  var isTypeUint = (type) => Object.values(Uint).includes(type);
5654
+ var isTypeInt = (type) => Object.values(Int).includes(type);
5416
5655
  var isTypeUint256 = (type) => CairoUint256.isAbiType(type);
5417
5656
  var isTypeLiteral = (type) => Object.values(Literal).includes(type);
5418
5657
  var isTypeBool = (type) => type === "core::bool";
5419
5658
  var isTypeContractAddress = (type) => type === Literal.ContractAddress;
5420
5659
  var isTypeEthAddress = (type) => type === ETH_ADDRESS;
5421
- var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
5422
- var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
5423
5660
  var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>";
5424
5661
  var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
5425
5662
  var isCairo1Type = (type) => type.includes("::");
@@ -5678,11 +5915,1344 @@ ${indent}}` : "}";
5678
5915
  );
5679
5916
  }
5680
5917
 
5681
- // src/utils/calldata/parser/parser-0-1.1.0.ts
5682
- var AbiParser1 = class {
5683
- abi;
5684
- constructor(abi) {
5685
- this.abi = abi;
5918
+ // src/utils/calldata/parser/interface.ts
5919
+ var AbiParserInterface = class {
5920
+ };
5921
+
5922
+ // src/utils/cairoDataTypes/bytes31.ts
5923
+ var CairoBytes31 = class _CairoBytes31 {
5924
+ static MAX_BYTE_SIZE = 31;
5925
+ data;
5926
+ static abiSelector = "core::bytes_31::bytes31";
5927
+ constructor(data) {
5928
+ _CairoBytes31.validate(data);
5929
+ this.data = _CairoBytes31.__processData(data);
5930
+ }
5931
+ static __processData(data) {
5932
+ if (isString(data)) {
5933
+ return stringToUint8Array(data);
5934
+ }
5935
+ if (isBuffer(data)) {
5936
+ return new Uint8Array(data);
5937
+ }
5938
+ if (data instanceof Uint8Array) {
5939
+ return new Uint8Array(data);
5940
+ }
5941
+ throw new Error("Invalid input type for CairoBytes31. Expected string, Buffer, or Uint8Array");
5942
+ }
5943
+ toApiRequest() {
5944
+ return addCompiledFlag([this.toHexString()]);
5945
+ }
5946
+ toBigInt() {
5947
+ return uint8ArrayToBigInt(this.data);
5948
+ }
5949
+ decodeUtf8() {
5950
+ return new TextDecoder().decode(this.data);
5951
+ }
5952
+ toHexString() {
5953
+ return addHexPrefix(this.toBigInt().toString(16));
5954
+ }
5955
+ static validate(data) {
5956
+ const byteLength = _CairoBytes31.__processData(data).length;
5957
+ assert(
5958
+ byteLength <= this.MAX_BYTE_SIZE,
5959
+ `Data is too long: ${byteLength} bytes (max ${this.MAX_BYTE_SIZE} bytes)`
5960
+ );
5961
+ }
5962
+ static is(data) {
5963
+ try {
5964
+ _CairoBytes31.validate(data);
5965
+ return true;
5966
+ } catch {
5967
+ return false;
5968
+ }
5969
+ }
5970
+ /**
5971
+ * Check if provided abi type is this data type
5972
+ */
5973
+ static isAbiType(abiType) {
5974
+ return abiType === _CairoBytes31.abiSelector;
5975
+ }
5976
+ static factoryFromApiResponse(responseIterator) {
5977
+ return new _CairoBytes31(getNext(responseIterator));
5978
+ }
5979
+ };
5980
+
5981
+ // src/utils/errors/rpc.ts
5982
+ var errorCodes = {
5983
+ FAILED_TO_RECEIVE_TXN: 1,
5984
+ NO_TRACE_AVAILABLE: 10,
5985
+ CONTRACT_NOT_FOUND: 20,
5986
+ ENTRYPOINT_NOT_FOUND: 21,
5987
+ BLOCK_NOT_FOUND: 24,
5988
+ INVALID_TXN_INDEX: 27,
5989
+ CLASS_HASH_NOT_FOUND: 28,
5990
+ TXN_HASH_NOT_FOUND: 29,
5991
+ PAGE_SIZE_TOO_BIG: 31,
5992
+ NO_BLOCKS: 32,
5993
+ INVALID_CONTINUATION_TOKEN: 33,
5994
+ TOO_MANY_KEYS_IN_FILTER: 34,
5995
+ CONTRACT_ERROR: 40,
5996
+ TRANSACTION_EXECUTION_ERROR: 41,
5997
+ STORAGE_PROOF_NOT_SUPPORTED: 42,
5998
+ CLASS_ALREADY_DECLARED: 51,
5999
+ INVALID_TRANSACTION_NONCE: 52,
6000
+ INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
6001
+ INSUFFICIENT_ACCOUNT_BALANCE: 54,
6002
+ VALIDATION_FAILURE: 55,
6003
+ COMPILATION_FAILED: 56,
6004
+ CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
6005
+ NON_ACCOUNT: 58,
6006
+ DUPLICATE_TX: 59,
6007
+ COMPILED_CLASS_HASH_MISMATCH: 60,
6008
+ UNSUPPORTED_TX_VERSION: 61,
6009
+ UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
6010
+ UNEXPECTED_ERROR: 63,
6011
+ INVALID_SUBSCRIPTION_ID: 66,
6012
+ TOO_MANY_ADDRESSES_IN_FILTER: 67,
6013
+ TOO_MANY_BLOCKS_BACK: 68,
6014
+ COMPILATION_ERROR: 100,
6015
+ INVALID_ADDRESS: 150,
6016
+ TOKEN_NOT_SUPPORTED: 151,
6017
+ INVALID_SIGNATURE: 153,
6018
+ MAX_AMOUNT_TOO_LOW: 154,
6019
+ CLASS_HASH_NOT_SUPPORTED: 155,
6020
+ PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
6021
+ INVALID_TIME_BOUNDS: 157,
6022
+ INVALID_DEPLOYMENT_DATA: 158,
6023
+ INVALID_CLASS_HASH: 159,
6024
+ INVALID_ID: 160,
6025
+ UNKNOWN_ERROR: 163
6026
+ };
6027
+ var rpc_default = errorCodes;
6028
+
6029
+ // src/utils/errors/index.ts
6030
+ function fixStack(target, fn = target.constructor) {
6031
+ const { captureStackTrace } = Error;
6032
+ captureStackTrace && captureStackTrace(target, fn);
6033
+ }
6034
+ function fixProto(target, prototype) {
6035
+ const { setPrototypeOf } = Object;
6036
+ setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
6037
+ }
6038
+ var CustomError = class extends Error {
6039
+ name;
6040
+ constructor(message) {
6041
+ super(message);
6042
+ Object.defineProperty(this, "name", {
6043
+ value: new.target.name,
6044
+ enumerable: false,
6045
+ configurable: true
6046
+ });
6047
+ fixProto(this, new.target.prototype);
6048
+ fixStack(this);
6049
+ }
6050
+ };
6051
+ var LibraryError = class extends CustomError {
6052
+ };
6053
+ var RpcError = class extends LibraryError {
6054
+ constructor(baseError, method, params) {
6055
+ super(`RPC: ${method} with params ${stringify2(params, null, 2)}
6056
+
6057
+ ${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
6058
+ this.baseError = baseError;
6059
+ this.request = { method, params };
6060
+ }
6061
+ request;
6062
+ get code() {
6063
+ return this.baseError.code;
6064
+ }
6065
+ /**
6066
+ * Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
6067
+ * @example
6068
+ * ```typescript
6069
+ * SomeError.isType('UNEXPECTED_ERROR');
6070
+ * ```
6071
+ */
6072
+ isType(typeName) {
6073
+ return rpc_default[typeName] === this.code;
6074
+ }
6075
+ };
6076
+ var TimeoutError = class extends LibraryError {
6077
+ constructor(message) {
6078
+ super(message);
6079
+ this.name = "TimeoutError";
6080
+ }
6081
+ };
6082
+ var WebSocketNotConnectedError = class extends LibraryError {
6083
+ constructor(message) {
6084
+ super(message);
6085
+ this.name = "WebSocketNotConnectedError";
6086
+ }
6087
+ };
6088
+
6089
+ // src/utils/connect/buffer.ts
6090
+ var buffer_default = config.get("buffer") || typeof Buffer !== "undefined" && Buffer || typeof globalThis !== "undefined" && globalThis.Buffer || typeof window !== "undefined" && window.Buffer || typeof global !== "undefined" && global.Buffer || class {
6091
+ constructor() {
6092
+ throw new LibraryError(
6093
+ `Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
6094
+ );
6095
+ }
6096
+ static from(_data) {
6097
+ throw new LibraryError(
6098
+ `Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
6099
+ );
6100
+ }
6101
+ static isBuffer(obj) {
6102
+ const BufferImpl = config.get("buffer") || typeof Buffer !== "undefined" && Buffer;
6103
+ return BufferImpl && BufferImpl.isBuffer && BufferImpl.isBuffer(obj);
6104
+ }
6105
+ };
6106
+
6107
+ // src/utils/cairoDataTypes/uint32.ts
6108
+ var CairoUint32 = class _CairoUint32 {
6109
+ data;
6110
+ static abiSelector = "core::u32::u32";
6111
+ constructor(data) {
6112
+ _CairoUint32.validate(data);
6113
+ this.data = _CairoUint32.__processData(data);
6114
+ }
6115
+ static __processData(data) {
6116
+ if (isString(data) && isText(data)) {
6117
+ return utf8ToBigInt(data);
6118
+ }
6119
+ return BigInt(data);
6120
+ }
6121
+ toApiRequest() {
6122
+ return addCompiledFlag([this.toHexString()]);
6123
+ }
6124
+ toBigInt() {
6125
+ return this.data;
6126
+ }
6127
+ decodeUtf8() {
6128
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6129
+ }
6130
+ toHexString() {
6131
+ return addHexPrefix(this.toBigInt().toString(16));
6132
+ }
6133
+ static validate(data) {
6134
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6135
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6136
+ assert(
6137
+ !isNumber2(data) || Number.isInteger(data),
6138
+ "Invalid input: decimal numbers are not supported, only integers"
6139
+ );
6140
+ const value = _CairoUint32.__processData(data);
6141
+ assert(value >= 0n && value <= 2n ** 32n - 1n, "Value is out of u32 range [0, 2^32)");
6142
+ }
6143
+ static is(data) {
6144
+ try {
6145
+ _CairoUint32.validate(data);
6146
+ return true;
6147
+ } catch {
6148
+ return false;
6149
+ }
6150
+ }
6151
+ /**
6152
+ * Check if provided abi type is this data type
6153
+ */
6154
+ static isAbiType(abiType) {
6155
+ return abiType === _CairoUint32.abiSelector;
6156
+ }
6157
+ static factoryFromApiResponse(responseIterator) {
6158
+ return new _CairoUint32(getNext(responseIterator));
6159
+ }
6160
+ };
6161
+
6162
+ // src/utils/cairoDataTypes/byteArray.ts
6163
+ var CairoByteArray = class _CairoByteArray {
6164
+ /**
6165
+ * entire dataset
6166
+ */
6167
+ data = [];
6168
+ /**
6169
+ * cairo specific implementation helper
6170
+ */
6171
+ pending_word;
6172
+ // felt
6173
+ /**
6174
+ * cairo specific implementation helper
6175
+ */
6176
+ pending_word_len;
6177
+ // u32
6178
+ static abiSelector = "core::byte_array::ByteArray";
6179
+ constructor(...arr) {
6180
+ if (arr.length === 3) {
6181
+ const [dataArg, pendingWord, pendingWordLen] = arr;
6182
+ assert(
6183
+ Array.isArray(dataArg) && pendingWord instanceof CairoFelt252 && pendingWordLen instanceof CairoUint32,
6184
+ "Invalid constructor parameters. Expected (CairoBytes31[], CairoFelt252, CairoUint32)"
6185
+ );
6186
+ this.data = dataArg;
6187
+ this.pending_word = pendingWord;
6188
+ this.pending_word_len = pendingWordLen;
6189
+ return;
6190
+ }
6191
+ const inData = arr[0];
6192
+ _CairoByteArray.validate(inData);
6193
+ const { data, pending_word, pending_word_len } = _CairoByteArray.__processData(inData);
6194
+ this.data = data;
6195
+ this.pending_word = pending_word;
6196
+ this.pending_word_len = pending_word_len;
6197
+ }
6198
+ static __processData(inData) {
6199
+ let fullData;
6200
+ if (inData instanceof Uint8Array) {
6201
+ fullData = inData;
6202
+ } else if (isBuffer(inData)) {
6203
+ fullData = new Uint8Array(inData);
6204
+ } else if (isString(inData)) {
6205
+ fullData = stringToUint8Array(inData);
6206
+ } else if (isBigInt(inData)) {
6207
+ fullData = bigIntToUint8Array(inData);
6208
+ } else if (isInteger2(inData)) {
6209
+ fullData = bigIntToUint8Array(BigInt(inData));
6210
+ } else {
6211
+ throw new Error("Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint");
6212
+ }
6213
+ const CHUNK_SIZE = CairoBytes31.MAX_BYTE_SIZE;
6214
+ const completeChunks = Math.floor(fullData.length / CHUNK_SIZE);
6215
+ const remainderLength = fullData.length % CHUNK_SIZE;
6216
+ const data = [];
6217
+ let pending_word;
6218
+ let pending_word_len;
6219
+ for (let i = 0; i < completeChunks; i += 1) {
6220
+ const chunkStart = i * CHUNK_SIZE;
6221
+ const chunkEnd = chunkStart + CHUNK_SIZE;
6222
+ const chunk = fullData.slice(chunkStart, chunkEnd);
6223
+ data.push(new CairoBytes31(chunk));
6224
+ }
6225
+ if (remainderLength > 0) {
6226
+ const remainder = fullData.slice(completeChunks * CHUNK_SIZE);
6227
+ let hex = "0x";
6228
+ for (let i = 0; i < remainder.length; i += 1) {
6229
+ hex += remainder[i].toString(16).padStart(2, "0");
6230
+ }
6231
+ pending_word = new CairoFelt252(hex);
6232
+ pending_word_len = new CairoUint32(remainderLength);
6233
+ } else {
6234
+ pending_word = new CairoFelt252(0);
6235
+ pending_word_len = new CairoUint32(0);
6236
+ }
6237
+ return { data, pending_word, pending_word_len };
6238
+ }
6239
+ toApiRequest() {
6240
+ this.assertInitialized();
6241
+ return addCompiledFlag([
6242
+ addHexPrefix(this.data.length.toString(16)),
6243
+ ...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
6244
+ ...this.pending_word.toApiRequest(),
6245
+ ...this.pending_word_len.toApiRequest()
6246
+ ]);
6247
+ }
6248
+ decodeUtf8() {
6249
+ const allBytes = this.reconstructBytes();
6250
+ const fullBytes = new Uint8Array(allBytes);
6251
+ return new TextDecoder().decode(fullBytes);
6252
+ }
6253
+ toBigInt() {
6254
+ const allBytes = this.reconstructBytes();
6255
+ if (allBytes.length === 0) {
6256
+ return 0n;
6257
+ }
6258
+ let result = 0n;
6259
+ allBytes.forEach((byte) => {
6260
+ result = result * 256n + BigInt(byte);
6261
+ });
6262
+ return result;
6263
+ }
6264
+ toHexString() {
6265
+ return addHexPrefix(this.toBigInt().toString(16));
6266
+ }
6267
+ toBuffer() {
6268
+ 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
+ }
6291
+ return buffer_default.from(allBytes);
6292
+ }
6293
+ static validate(data) {
6294
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6295
+ assert(
6296
+ !Array.isArray(data) || data instanceof Uint8Array,
6297
+ "Invalid input: arrays are not supported, use Uint8Array"
6298
+ );
6299
+ assert(
6300
+ typeof data !== "object" || isBuffer(data) || data instanceof Uint8Array,
6301
+ "Invalid input for CairoByteArray: objects are not supported"
6302
+ );
6303
+ assert(
6304
+ !isNumber2(data) || Number.isInteger(data),
6305
+ "Invalid input for CairoByteArray: decimal numbers are not supported, only integers"
6306
+ );
6307
+ assert(
6308
+ !isNumber2(data) || data >= 0,
6309
+ "Invalid input for CairoByteArray: negative numbers are not supported"
6310
+ );
6311
+ assert(
6312
+ !isBigInt(data) || data >= 0n,
6313
+ "Invalid input for CairoByteArray: negative bigints are not supported"
6314
+ );
6315
+ assert(
6316
+ data instanceof Uint8Array || isBuffer(data) || isString(data) || isNumber2(data) || isBigInt(data),
6317
+ "Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint"
6318
+ );
6319
+ }
6320
+ /**
6321
+ * Check if the provided data is a valid CairoByteArray
6322
+ *
6323
+ * @param data - The data to check
6324
+ * @returns True if the data is a valid CairoByteArray, false otherwise
6325
+ */
6326
+ static is(data) {
6327
+ try {
6328
+ _CairoByteArray.validate(data);
6329
+ return true;
6330
+ } catch {
6331
+ return false;
6332
+ }
6333
+ }
6334
+ /**
6335
+ * Check if provided abi type is this data type
6336
+ */
6337
+ static isAbiType(abiType) {
6338
+ return abiType === _CairoByteArray.abiSelector;
6339
+ }
6340
+ /**
6341
+ * Private helper to check if the CairoByteArray is properly initialized
6342
+ */
6343
+ assertInitialized() {
6344
+ assert(
6345
+ this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
6346
+ "CairoByteArray is not properly initialized"
6347
+ );
6348
+ }
6349
+ /**
6350
+ * Private helper to reconstruct the full byte sequence from chunks and pending word
6351
+ */
6352
+ reconstructBytes() {
6353
+ 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
+ });
6361
+ 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
+ }
6378
+ }
6379
+ return allBytes;
6380
+ }
6381
+ static factoryFromApiResponse(responseIterator) {
6382
+ const data = Array.from(
6383
+ { length: Number(getNext(responseIterator)) },
6384
+ () => CairoBytes31.factoryFromApiResponse(responseIterator)
6385
+ );
6386
+ const pending_word = CairoFelt252.factoryFromApiResponse(responseIterator);
6387
+ const pending_word_len = CairoUint32.factoryFromApiResponse(responseIterator);
6388
+ return new _CairoByteArray(data, pending_word, pending_word_len);
6389
+ }
6390
+ };
6391
+
6392
+ // src/utils/cairoDataTypes/uint8.ts
6393
+ var CairoUint8 = class _CairoUint8 {
6394
+ data;
6395
+ static abiSelector = "core::integer::u8";
6396
+ constructor(data) {
6397
+ _CairoUint8.validate(data);
6398
+ this.data = _CairoUint8.__processData(data);
6399
+ }
6400
+ static __processData(data) {
6401
+ if (isString(data) && isText(data)) {
6402
+ return utf8ToBigInt(data);
6403
+ }
6404
+ return BigInt(data);
6405
+ }
6406
+ toApiRequest() {
6407
+ return addCompiledFlag([this.toHexString()]);
6408
+ }
6409
+ toBigInt() {
6410
+ return this.data;
6411
+ }
6412
+ decodeUtf8() {
6413
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6414
+ }
6415
+ toHexString() {
6416
+ return addHexPrefix(this.toBigInt().toString(16));
6417
+ }
6418
+ static validate(data) {
6419
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6420
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6421
+ assert(
6422
+ !isNumber2(data) || Number.isInteger(data),
6423
+ "Invalid input: decimal numbers are not supported, only integers"
6424
+ );
6425
+ const value = _CairoUint8.__processData(data);
6426
+ assert(
6427
+ value >= RANGE_U8.min && value <= RANGE_U8.max,
6428
+ `Value is out of u8 range [${RANGE_U8.min}, ${RANGE_U8.max}]`
6429
+ );
6430
+ }
6431
+ static is(data) {
6432
+ try {
6433
+ _CairoUint8.validate(data);
6434
+ return true;
6435
+ } catch {
6436
+ return false;
6437
+ }
6438
+ }
6439
+ /**
6440
+ * Check if provided abi type is this data type
6441
+ */
6442
+ static isAbiType(abiType) {
6443
+ return abiType === _CairoUint8.abiSelector;
6444
+ }
6445
+ static factoryFromApiResponse(responseIterator) {
6446
+ return new _CairoUint8(getNext(responseIterator));
6447
+ }
6448
+ };
6449
+
6450
+ // src/utils/cairoDataTypes/uint16.ts
6451
+ var CairoUint16 = class _CairoUint16 {
6452
+ data;
6453
+ static abiSelector = "core::integer::u16";
6454
+ constructor(data) {
6455
+ _CairoUint16.validate(data);
6456
+ this.data = _CairoUint16.__processData(data);
6457
+ }
6458
+ static __processData(data) {
6459
+ if (isString(data) && isText(data)) {
6460
+ return utf8ToBigInt(data);
6461
+ }
6462
+ return BigInt(data);
6463
+ }
6464
+ toApiRequest() {
6465
+ return addCompiledFlag([this.toHexString()]);
6466
+ }
6467
+ toBigInt() {
6468
+ return this.data;
6469
+ }
6470
+ decodeUtf8() {
6471
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6472
+ }
6473
+ toHexString() {
6474
+ return addHexPrefix(this.toBigInt().toString(16));
6475
+ }
6476
+ static validate(data) {
6477
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6478
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6479
+ assert(
6480
+ !isNumber2(data) || Number.isInteger(data),
6481
+ "Invalid input: decimal numbers are not supported, only integers"
6482
+ );
6483
+ const value = _CairoUint16.__processData(data);
6484
+ assert(
6485
+ value >= RANGE_U16.min && value <= RANGE_U16.max,
6486
+ `Value is out of u16 range [${RANGE_U16.min}, ${RANGE_U16.max}]`
6487
+ );
6488
+ }
6489
+ static is(data) {
6490
+ try {
6491
+ _CairoUint16.validate(data);
6492
+ return true;
6493
+ } catch {
6494
+ return false;
6495
+ }
6496
+ }
6497
+ /**
6498
+ * Check if provided abi type is this data type
6499
+ */
6500
+ static isAbiType(abiType) {
6501
+ return abiType === _CairoUint16.abiSelector;
6502
+ }
6503
+ static factoryFromApiResponse(responseIterator) {
6504
+ return new _CairoUint16(getNext(responseIterator));
6505
+ }
6506
+ };
6507
+
6508
+ // src/utils/cairoDataTypes/uint64.ts
6509
+ var CairoUint64 = class _CairoUint64 {
6510
+ data;
6511
+ static abiSelector = "core::integer::u64";
6512
+ constructor(data) {
6513
+ _CairoUint64.validate(data);
6514
+ this.data = _CairoUint64.__processData(data);
6515
+ }
6516
+ static __processData(data) {
6517
+ if (isString(data) && isText(data)) {
6518
+ return utf8ToBigInt(data);
6519
+ }
6520
+ return BigInt(data);
6521
+ }
6522
+ toApiRequest() {
6523
+ return addCompiledFlag([this.toHexString()]);
6524
+ }
6525
+ toBigInt() {
6526
+ return this.data;
6527
+ }
6528
+ decodeUtf8() {
6529
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6530
+ }
6531
+ toHexString() {
6532
+ return addHexPrefix(this.toBigInt().toString(16));
6533
+ }
6534
+ static validate(data) {
6535
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6536
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6537
+ assert(
6538
+ !isNumber2(data) || Number.isInteger(data),
6539
+ "Invalid input: decimal numbers are not supported, only integers"
6540
+ );
6541
+ const value = _CairoUint64.__processData(data);
6542
+ assert(
6543
+ value >= RANGE_U64.min && value <= RANGE_U64.max,
6544
+ `Value is out of u64 range [${RANGE_U64.min}, ${RANGE_U64.max}]`
6545
+ );
6546
+ }
6547
+ static is(data) {
6548
+ try {
6549
+ _CairoUint64.validate(data);
6550
+ return true;
6551
+ } catch {
6552
+ return false;
6553
+ }
6554
+ }
6555
+ /**
6556
+ * Check if provided abi type is this data type
6557
+ */
6558
+ static isAbiType(abiType) {
6559
+ return abiType === _CairoUint64.abiSelector;
6560
+ }
6561
+ static factoryFromApiResponse(responseIterator) {
6562
+ return new _CairoUint64(getNext(responseIterator));
6563
+ }
6564
+ };
6565
+
6566
+ // src/utils/cairoDataTypes/uint96.ts
6567
+ var CairoUint96 = class _CairoUint96 {
6568
+ data;
6569
+ static abiSelector = "core::integer::u96";
6570
+ constructor(data) {
6571
+ _CairoUint96.validate(data);
6572
+ this.data = _CairoUint96.__processData(data);
6573
+ }
6574
+ static __processData(data) {
6575
+ if (isString(data) && isText(data)) {
6576
+ return utf8ToBigInt(data);
6577
+ }
6578
+ return BigInt(data);
6579
+ }
6580
+ toApiRequest() {
6581
+ return addCompiledFlag([this.toHexString()]);
6582
+ }
6583
+ toBigInt() {
6584
+ return this.data;
6585
+ }
6586
+ decodeUtf8() {
6587
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6588
+ }
6589
+ toHexString() {
6590
+ return addHexPrefix(this.toBigInt().toString(16));
6591
+ }
6592
+ static validate(data) {
6593
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6594
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6595
+ assert(
6596
+ !isNumber2(data) || Number.isInteger(data),
6597
+ "Invalid input: decimal numbers are not supported, only integers"
6598
+ );
6599
+ const value = _CairoUint96.__processData(data);
6600
+ assert(
6601
+ value >= RANGE_U96.min && value <= RANGE_U96.max,
6602
+ `Value is out of u96 range [${RANGE_U96.min}, ${RANGE_U96.max}]`
6603
+ );
6604
+ }
6605
+ static is(data) {
6606
+ try {
6607
+ _CairoUint96.validate(data);
6608
+ return true;
6609
+ } catch {
6610
+ return false;
6611
+ }
6612
+ }
6613
+ /**
6614
+ * Check if provided abi type is this data type
6615
+ */
6616
+ static isAbiType(abiType) {
6617
+ return abiType === _CairoUint96.abiSelector;
6618
+ }
6619
+ static factoryFromApiResponse(responseIterator) {
6620
+ return new _CairoUint96(getNext(responseIterator));
6621
+ }
6622
+ };
6623
+
6624
+ // src/utils/cairoDataTypes/uint128.ts
6625
+ var CairoUint128 = class _CairoUint128 {
6626
+ data;
6627
+ static abiSelector = "core::integer::u128";
6628
+ constructor(data) {
6629
+ _CairoUint128.validate(data);
6630
+ this.data = _CairoUint128.__processData(data);
6631
+ }
6632
+ static __processData(data) {
6633
+ if (isString(data) && isText(data)) {
6634
+ return utf8ToBigInt(data);
6635
+ }
6636
+ return BigInt(data);
6637
+ }
6638
+ toApiRequest() {
6639
+ return addCompiledFlag([this.toHexString()]);
6640
+ }
6641
+ toBigInt() {
6642
+ return this.data;
6643
+ }
6644
+ decodeUtf8() {
6645
+ return new TextDecoder().decode(bigIntToUint8Array(this.data));
6646
+ }
6647
+ toHexString() {
6648
+ return addHexPrefix(this.toBigInt().toString(16));
6649
+ }
6650
+ static validate(data) {
6651
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6652
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6653
+ assert(
6654
+ !isNumber2(data) || Number.isInteger(data),
6655
+ "Invalid input: decimal numbers are not supported, only integers"
6656
+ );
6657
+ const value = _CairoUint128.__processData(data);
6658
+ assert(
6659
+ value >= RANGE_U128.min && value <= RANGE_U128.max,
6660
+ `Value is out of u128 range [${RANGE_U128.min}, ${RANGE_U128.max}]`
6661
+ );
6662
+ }
6663
+ static is(data) {
6664
+ try {
6665
+ _CairoUint128.validate(data);
6666
+ return true;
6667
+ } catch {
6668
+ return false;
6669
+ }
6670
+ }
6671
+ /**
6672
+ * Check if provided abi type is this data type
6673
+ */
6674
+ static isAbiType(abiType) {
6675
+ return abiType === _CairoUint128.abiSelector;
6676
+ }
6677
+ static factoryFromApiResponse(responseIterator) {
6678
+ return new _CairoUint128(getNext(responseIterator));
6679
+ }
6680
+ };
6681
+
6682
+ // src/utils/cairoDataTypes/int8.ts
6683
+ var CairoInt8 = class _CairoInt8 {
6684
+ data;
6685
+ static abiSelector = "core::integer::i8";
6686
+ constructor(data) {
6687
+ _CairoInt8.validate(data);
6688
+ this.data = _CairoInt8.__processData(data);
6689
+ }
6690
+ static __processData(data) {
6691
+ if (isString(data) && isText(data)) {
6692
+ return utf8ToBigInt(data);
6693
+ }
6694
+ return BigInt(data);
6695
+ }
6696
+ toApiRequest() {
6697
+ return addCompiledFlag([this.toHexString()]);
6698
+ }
6699
+ toBigInt() {
6700
+ return this.data;
6701
+ }
6702
+ decodeUtf8() {
6703
+ return new TextDecoder().decode(
6704
+ bigIntToUint8Array(this.data >= 0n ? this.data : 256n + this.data)
6705
+ );
6706
+ }
6707
+ /**
6708
+ * For negative values field element representation as positive hex string.
6709
+ * @returns cairo field arithmetic hex string
6710
+ */
6711
+ toHexString() {
6712
+ const value = this.toBigInt();
6713
+ if (value < 0n) {
6714
+ const fieldElement = PRIME + value;
6715
+ return addHexPrefix(fieldElement.toString(16));
6716
+ }
6717
+ return addHexPrefix(value.toString(16));
6718
+ }
6719
+ static validate(data) {
6720
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6721
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6722
+ assert(
6723
+ !isNumber2(data) || Number.isInteger(data),
6724
+ "Invalid input: decimal numbers are not supported, only integers"
6725
+ );
6726
+ const value = _CairoInt8.__processData(data);
6727
+ assert(
6728
+ value >= RANGE_I8.min && value <= RANGE_I8.max,
6729
+ `Value is out of i8 range [${RANGE_I8.min}, ${RANGE_I8.max}]`
6730
+ );
6731
+ }
6732
+ static is(data) {
6733
+ try {
6734
+ _CairoInt8.validate(data);
6735
+ return true;
6736
+ } catch {
6737
+ return false;
6738
+ }
6739
+ }
6740
+ /**
6741
+ * Check if provided abi type is this data type
6742
+ */
6743
+ static isAbiType(abiType) {
6744
+ return abiType === _CairoInt8.abiSelector;
6745
+ }
6746
+ static factoryFromApiResponse(responseIterator) {
6747
+ const response = getNext(responseIterator);
6748
+ const value = BigInt(response);
6749
+ const signedValue = value > PRIME / 2n ? value - PRIME : value;
6750
+ return new _CairoInt8(signedValue);
6751
+ }
6752
+ };
6753
+
6754
+ // src/utils/cairoDataTypes/int16.ts
6755
+ var CairoInt16 = class _CairoInt16 {
6756
+ data;
6757
+ static abiSelector = "core::integer::i16";
6758
+ constructor(data) {
6759
+ _CairoInt16.validate(data);
6760
+ this.data = _CairoInt16.__processData(data);
6761
+ }
6762
+ static __processData(data) {
6763
+ if (isString(data) && isText(data)) {
6764
+ return utf8ToBigInt(data);
6765
+ }
6766
+ return BigInt(data);
6767
+ }
6768
+ toApiRequest() {
6769
+ return addCompiledFlag([this.toHexString()]);
6770
+ }
6771
+ toBigInt() {
6772
+ return this.data;
6773
+ }
6774
+ decodeUtf8() {
6775
+ return new TextDecoder().decode(
6776
+ bigIntToUint8Array(this.data >= 0n ? this.data : 65536n + this.data)
6777
+ );
6778
+ }
6779
+ /**
6780
+ * For negative values field element representation as positive hex string.
6781
+ * @returns cairo field arithmetic hex string
6782
+ */
6783
+ toHexString() {
6784
+ const value = this.toBigInt();
6785
+ if (value < 0n) {
6786
+ const fieldElement = PRIME + value;
6787
+ return addHexPrefix(fieldElement.toString(16));
6788
+ }
6789
+ return addHexPrefix(value.toString(16));
6790
+ }
6791
+ static validate(data) {
6792
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6793
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6794
+ assert(
6795
+ !isNumber2(data) || Number.isInteger(data),
6796
+ "Invalid input: decimal numbers are not supported, only integers"
6797
+ );
6798
+ const value = _CairoInt16.__processData(data);
6799
+ assert(
6800
+ value >= RANGE_I16.min && value <= RANGE_I16.max,
6801
+ `Value is out of i16 range [${RANGE_I16.min}, ${RANGE_I16.max}]`
6802
+ );
6803
+ }
6804
+ static is(data) {
6805
+ try {
6806
+ _CairoInt16.validate(data);
6807
+ return true;
6808
+ } catch {
6809
+ return false;
6810
+ }
6811
+ }
6812
+ /**
6813
+ * Check if provided abi type is this data type
6814
+ */
6815
+ static isAbiType(abiType) {
6816
+ return abiType === _CairoInt16.abiSelector;
6817
+ }
6818
+ static factoryFromApiResponse(responseIterator) {
6819
+ const response = getNext(responseIterator);
6820
+ const value = BigInt(response);
6821
+ const signedValue = value > PRIME / 2n ? value - PRIME : value;
6822
+ return new _CairoInt16(signedValue);
6823
+ }
6824
+ };
6825
+
6826
+ // src/utils/cairoDataTypes/int32.ts
6827
+ var CairoInt32 = class _CairoInt32 {
6828
+ data;
6829
+ static abiSelector = "core::integer::i32";
6830
+ constructor(data) {
6831
+ _CairoInt32.validate(data);
6832
+ this.data = _CairoInt32.__processData(data);
6833
+ }
6834
+ static __processData(data) {
6835
+ if (isString(data) && isText(data)) {
6836
+ return utf8ToBigInt(data);
6837
+ }
6838
+ return BigInt(data);
6839
+ }
6840
+ toApiRequest() {
6841
+ return addCompiledFlag([this.toHexString()]);
6842
+ }
6843
+ toBigInt() {
6844
+ return this.data;
6845
+ }
6846
+ decodeUtf8() {
6847
+ return new TextDecoder().decode(
6848
+ bigIntToUint8Array(this.data >= 0n ? this.data : 4294967296n + this.data)
6849
+ );
6850
+ }
6851
+ /**
6852
+ * For negative values field element representation as positive hex string.
6853
+ * @returns cairo field arithmetic hex string
6854
+ */
6855
+ toHexString() {
6856
+ const value = this.toBigInt();
6857
+ if (value < 0n) {
6858
+ const fieldElement = PRIME + value;
6859
+ return addHexPrefix(fieldElement.toString(16));
6860
+ }
6861
+ return addHexPrefix(value.toString(16));
6862
+ }
6863
+ static validate(data) {
6864
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6865
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6866
+ assert(
6867
+ !isNumber2(data) || Number.isInteger(data),
6868
+ "Invalid input: decimal numbers are not supported, only integers"
6869
+ );
6870
+ const value = _CairoInt32.__processData(data);
6871
+ assert(
6872
+ value >= RANGE_I32.min && value <= RANGE_I32.max,
6873
+ `Value is out of i32 range [${RANGE_I32.min}, ${RANGE_I32.max}]`
6874
+ );
6875
+ }
6876
+ static is(data) {
6877
+ try {
6878
+ _CairoInt32.validate(data);
6879
+ return true;
6880
+ } catch {
6881
+ return false;
6882
+ }
6883
+ }
6884
+ /**
6885
+ * Check if provided abi type is this data type
6886
+ */
6887
+ static isAbiType(abiType) {
6888
+ return abiType === _CairoInt32.abiSelector;
6889
+ }
6890
+ static factoryFromApiResponse(responseIterator) {
6891
+ const response = getNext(responseIterator);
6892
+ const value = BigInt(response);
6893
+ const signedValue = value > PRIME / 2n ? value - PRIME : value;
6894
+ return new _CairoInt32(signedValue);
6895
+ }
6896
+ };
6897
+
6898
+ // src/utils/cairoDataTypes/int64.ts
6899
+ var CairoInt64 = class _CairoInt64 {
6900
+ data;
6901
+ static abiSelector = "core::integer::i64";
6902
+ constructor(data) {
6903
+ _CairoInt64.validate(data);
6904
+ this.data = _CairoInt64.__processData(data);
6905
+ }
6906
+ static __processData(data) {
6907
+ if (isString(data) && isText(data)) {
6908
+ return utf8ToBigInt(data);
6909
+ }
6910
+ return BigInt(data);
6911
+ }
6912
+ toApiRequest() {
6913
+ return addCompiledFlag([this.toHexString()]);
6914
+ }
6915
+ toBigInt() {
6916
+ return this.data;
6917
+ }
6918
+ decodeUtf8() {
6919
+ return new TextDecoder().decode(
6920
+ bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 64n + this.data)
6921
+ );
6922
+ }
6923
+ /**
6924
+ * For negative values field element representation as positive hex string.
6925
+ * @returns cairo field arithmetic hex string
6926
+ */
6927
+ toHexString() {
6928
+ const value = this.toBigInt();
6929
+ if (value < 0n) {
6930
+ const fieldElement = PRIME + value;
6931
+ return addHexPrefix(fieldElement.toString(16));
6932
+ }
6933
+ return addHexPrefix(value.toString(16));
6934
+ }
6935
+ static validate(data) {
6936
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
6937
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
6938
+ assert(
6939
+ !isNumber2(data) || Number.isInteger(data),
6940
+ "Invalid input: decimal numbers are not supported, only integers"
6941
+ );
6942
+ const value = _CairoInt64.__processData(data);
6943
+ assert(
6944
+ value >= RANGE_I64.min && value <= RANGE_I64.max,
6945
+ `Value is out of i64 range [${RANGE_I64.min}, ${RANGE_I64.max}]`
6946
+ );
6947
+ }
6948
+ static is(data) {
6949
+ try {
6950
+ _CairoInt64.validate(data);
6951
+ return true;
6952
+ } catch {
6953
+ return false;
6954
+ }
6955
+ }
6956
+ /**
6957
+ * Check if provided abi type is this data type
6958
+ */
6959
+ static isAbiType(abiType) {
6960
+ return abiType === _CairoInt64.abiSelector;
6961
+ }
6962
+ static factoryFromApiResponse(responseIterator) {
6963
+ const response = getNext(responseIterator);
6964
+ const value = BigInt(response);
6965
+ const signedValue = value > PRIME / 2n ? value - PRIME : value;
6966
+ return new _CairoInt64(signedValue);
6967
+ }
6968
+ };
6969
+
6970
+ // src/utils/cairoDataTypes/int128.ts
6971
+ var CairoInt128 = class _CairoInt128 {
6972
+ data;
6973
+ static abiSelector = "core::integer::i128";
6974
+ constructor(data) {
6975
+ _CairoInt128.validate(data);
6976
+ this.data = _CairoInt128.__processData(data);
6977
+ }
6978
+ static __processData(data) {
6979
+ if (isString(data) && isText(data)) {
6980
+ return utf8ToBigInt(data);
6981
+ }
6982
+ return BigInt(data);
6983
+ }
6984
+ toApiRequest() {
6985
+ return addCompiledFlag([this.toHexString()]);
6986
+ }
6987
+ toBigInt() {
6988
+ return this.data;
6989
+ }
6990
+ decodeUtf8() {
6991
+ return new TextDecoder().decode(
6992
+ bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 128n + this.data)
6993
+ );
6994
+ }
6995
+ /**
6996
+ * For negative values field element representation as positive hex string.
6997
+ * @returns cairo field arithmetic hex string
6998
+ */
6999
+ toHexString() {
7000
+ const value = this.toBigInt();
7001
+ if (value < 0n) {
7002
+ const fieldElement = PRIME + value;
7003
+ return addHexPrefix(fieldElement.toString(16));
7004
+ }
7005
+ return addHexPrefix(value.toString(16));
7006
+ }
7007
+ static validate(data) {
7008
+ assert(data !== null && data !== void 0, "Invalid input: null or undefined");
7009
+ assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
7010
+ assert(
7011
+ !isNumber2(data) || Number.isInteger(data),
7012
+ "Invalid input: decimal numbers are not supported, only integers"
7013
+ );
7014
+ const value = _CairoInt128.__processData(data);
7015
+ assert(
7016
+ value >= RANGE_I128.min && value <= RANGE_I128.max,
7017
+ `Value is out of i128 range [${RANGE_I128.min}, ${RANGE_I128.max}]`
7018
+ );
7019
+ }
7020
+ static is(data) {
7021
+ try {
7022
+ _CairoInt128.validate(data);
7023
+ return true;
7024
+ } catch {
7025
+ return false;
7026
+ }
7027
+ }
7028
+ /**
7029
+ * Check if provided abi type is this data type
7030
+ */
7031
+ static isAbiType(abiType) {
7032
+ return abiType === _CairoInt128.abiSelector;
7033
+ }
7034
+ static factoryFromApiResponse(responseIterator) {
7035
+ const response = getNext(responseIterator);
7036
+ const value = BigInt(response);
7037
+ const signedValue = value > PRIME / 2n ? value - PRIME : value;
7038
+ return new _CairoInt128(signedValue);
7039
+ }
7040
+ };
7041
+
7042
+ // src/utils/calldata/parser/parsingStrategy.ts
7043
+ var hdParsingStrategy = {
7044
+ // TODO: provjeri svi request parseri stvaraju array, dali je to ok sa requstParserom
7045
+ request: {
7046
+ [CairoBytes31.abiSelector]: (val) => {
7047
+ return new CairoBytes31(val).toApiRequest();
7048
+ },
7049
+ [CairoByteArray.abiSelector]: (val) => {
7050
+ return new CairoByteArray(val).toApiRequest();
7051
+ },
7052
+ [CairoFelt252.abiSelector]: (val) => {
7053
+ return new CairoFelt252(val).toApiRequest();
7054
+ },
7055
+ [CairoUint256.abiSelector]: (val) => {
7056
+ return new CairoUint256(val).toApiRequest();
7057
+ },
7058
+ [CairoUint512.abiSelector]: (val) => {
7059
+ return new CairoUint512(val).toApiRequest();
7060
+ },
7061
+ [CairoUint8.abiSelector]: (val) => {
7062
+ return new CairoUint8(val).toApiRequest();
7063
+ },
7064
+ [CairoUint16.abiSelector]: (val) => {
7065
+ return new CairoUint16(val).toApiRequest();
7066
+ },
7067
+ [CairoUint64.abiSelector]: (val) => {
7068
+ return new CairoUint64(val).toApiRequest();
7069
+ },
7070
+ [CairoUint96.abiSelector]: (val) => {
7071
+ return new CairoUint96(val).toApiRequest();
7072
+ },
7073
+ [CairoUint128.abiSelector]: (val) => {
7074
+ return new CairoUint128(val).toApiRequest();
7075
+ },
7076
+ [CairoInt8.abiSelector]: (val) => {
7077
+ return new CairoInt8(val).toApiRequest();
7078
+ },
7079
+ [CairoInt16.abiSelector]: (val) => {
7080
+ return new CairoInt16(val).toApiRequest();
7081
+ },
7082
+ [CairoInt32.abiSelector]: (val) => {
7083
+ return new CairoInt32(val).toApiRequest();
7084
+ },
7085
+ [CairoInt64.abiSelector]: (val) => {
7086
+ return new CairoInt64(val).toApiRequest();
7087
+ },
7088
+ [CairoInt128.abiSelector]: (val) => {
7089
+ return new CairoInt128(val).toApiRequest();
7090
+ }
7091
+ },
7092
+ response: {
7093
+ [CairoBytes31.abiSelector]: (responseIterator) => {
7094
+ return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
7095
+ },
7096
+ [CairoByteArray.abiSelector]: (responseIterator) => {
7097
+ return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
7098
+ },
7099
+ [CairoFelt252.abiSelector]: (responseIterator) => {
7100
+ return CairoFelt252.factoryFromApiResponse(responseIterator).toBigInt();
7101
+ },
7102
+ [CairoUint256.abiSelector]: (responseIterator) => {
7103
+ return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
7104
+ },
7105
+ [CairoUint512.abiSelector]: (responseIterator) => {
7106
+ return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
7107
+ },
7108
+ [CairoUint8.abiSelector]: (responseIterator) => {
7109
+ return CairoUint8.factoryFromApiResponse(responseIterator).toBigInt();
7110
+ },
7111
+ [CairoUint16.abiSelector]: (responseIterator) => {
7112
+ return CairoUint16.factoryFromApiResponse(responseIterator).toBigInt();
7113
+ },
7114
+ [CairoUint64.abiSelector]: (responseIterator) => {
7115
+ return CairoUint64.factoryFromApiResponse(responseIterator).toBigInt();
7116
+ },
7117
+ [CairoUint96.abiSelector]: (responseIterator) => {
7118
+ return CairoUint96.factoryFromApiResponse(responseIterator).toBigInt();
7119
+ },
7120
+ [CairoUint128.abiSelector]: (responseIterator) => {
7121
+ return CairoUint128.factoryFromApiResponse(responseIterator).toBigInt();
7122
+ },
7123
+ [CairoInt8.abiSelector]: (responseIterator) => {
7124
+ return CairoInt8.factoryFromApiResponse(responseIterator).toBigInt();
7125
+ },
7126
+ [CairoInt16.abiSelector]: (responseIterator) => {
7127
+ return CairoInt16.factoryFromApiResponse(responseIterator).toBigInt();
7128
+ },
7129
+ [CairoInt32.abiSelector]: (responseIterator) => {
7130
+ return CairoInt32.factoryFromApiResponse(responseIterator).toBigInt();
7131
+ },
7132
+ [CairoInt64.abiSelector]: (responseIterator) => {
7133
+ return CairoInt64.factoryFromApiResponse(responseIterator).toBigInt();
7134
+ },
7135
+ [CairoInt128.abiSelector]: (responseIterator) => {
7136
+ return CairoInt128.factoryFromApiResponse(responseIterator).toBigInt();
7137
+ }
7138
+ }
7139
+ };
7140
+ var fastParsingStrategy = {
7141
+ request: {
7142
+ [CairoBytes31.abiSelector]: (val) => {
7143
+ return new CairoBytes31(val).toApiRequest();
7144
+ },
7145
+ [CairoByteArray.abiSelector]: (val) => {
7146
+ return new CairoByteArray(val).toApiRequest();
7147
+ },
7148
+ [CairoFelt252.abiSelector]: (val) => {
7149
+ return felt(val);
7150
+ },
7151
+ [CairoUint256.abiSelector]: (val) => {
7152
+ return new CairoUint256(val).toApiRequest();
7153
+ },
7154
+ [CairoUint512.abiSelector]: (val) => {
7155
+ return new CairoUint512(val).toApiRequest();
7156
+ },
7157
+ [CairoUint8.abiSelector]: (val) => {
7158
+ return felt(val);
7159
+ },
7160
+ [CairoUint16.abiSelector]: (val) => {
7161
+ return felt(val);
7162
+ },
7163
+ [CairoUint64.abiSelector]: (val) => {
7164
+ return felt(val);
7165
+ },
7166
+ [CairoUint96.abiSelector]: (val) => {
7167
+ return felt(val);
7168
+ },
7169
+ [CairoUint128.abiSelector]: (val) => {
7170
+ return felt(val);
7171
+ },
7172
+ [CairoInt8.abiSelector]: (val) => {
7173
+ return new CairoInt8(val).toApiRequest();
7174
+ },
7175
+ [CairoInt16.abiSelector]: (val) => {
7176
+ return new CairoInt16(val).toApiRequest();
7177
+ },
7178
+ [CairoInt32.abiSelector]: (val) => {
7179
+ return new CairoInt32(val).toApiRequest();
7180
+ },
7181
+ [CairoInt64.abiSelector]: (val) => {
7182
+ return new CairoInt64(val).toApiRequest();
7183
+ },
7184
+ [CairoInt128.abiSelector]: (val) => {
7185
+ return new CairoInt128(val).toApiRequest();
7186
+ }
7187
+ },
7188
+ response: {
7189
+ [CairoBytes31.abiSelector]: (responseIterator) => {
7190
+ return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
7191
+ },
7192
+ [CairoByteArray.abiSelector]: (responseIterator) => {
7193
+ return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
7194
+ },
7195
+ [CairoFelt252.abiSelector]: (responseIterator) => {
7196
+ return BigInt(getNext(responseIterator));
7197
+ },
7198
+ [CairoUint256.abiSelector]: (responseIterator) => {
7199
+ return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
7200
+ },
7201
+ [CairoUint512.abiSelector]: (responseIterator) => {
7202
+ return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
7203
+ },
7204
+ [CairoUint8.abiSelector]: (responseIterator) => {
7205
+ return BigInt(getNext(responseIterator));
7206
+ },
7207
+ [CairoUint16.abiSelector]: (responseIterator) => {
7208
+ return BigInt(getNext(responseIterator));
7209
+ },
7210
+ [CairoUint64.abiSelector]: (responseIterator) => {
7211
+ return BigInt(getNext(responseIterator));
7212
+ },
7213
+ [CairoUint96.abiSelector]: (responseIterator) => {
7214
+ return BigInt(getNext(responseIterator));
7215
+ },
7216
+ [CairoUint128.abiSelector]: (responseIterator) => {
7217
+ return BigInt(getNext(responseIterator));
7218
+ },
7219
+ [CairoInt8.abiSelector]: (responseIterator) => {
7220
+ return BigInt(getNext(responseIterator));
7221
+ },
7222
+ [CairoInt16.abiSelector]: (responseIterator) => {
7223
+ return BigInt(getNext(responseIterator));
7224
+ },
7225
+ [CairoInt32.abiSelector]: (responseIterator) => {
7226
+ return BigInt(getNext(responseIterator));
7227
+ },
7228
+ [CairoInt64.abiSelector]: (responseIterator) => {
7229
+ return BigInt(getNext(responseIterator));
7230
+ },
7231
+ [CairoInt128.abiSelector]: (responseIterator) => {
7232
+ return BigInt(getNext(responseIterator));
7233
+ }
7234
+ }
7235
+ };
7236
+
7237
+ // src/utils/calldata/parser/parser-0-1.1.0.ts
7238
+ var AbiParser1 = class {
7239
+ abi;
7240
+ parsingStrategy;
7241
+ constructor(abi, parsingStrategy) {
7242
+ this.abi = abi;
7243
+ this.parsingStrategy = parsingStrategy || fastParsingStrategy;
7244
+ }
7245
+ getRequestParser(abiType) {
7246
+ if (this.parsingStrategy.request[abiType]) {
7247
+ return this.parsingStrategy.request[abiType];
7248
+ }
7249
+ throw new Error(`Parser for ${abiType} not found`);
7250
+ }
7251
+ getResponseParser(abiType) {
7252
+ if (this.parsingStrategy.response[abiType]) {
7253
+ return this.parsingStrategy.response[abiType];
7254
+ }
7255
+ throw new Error(`Parser for ${abiType} not found`);
5686
7256
  }
5687
7257
  /**
5688
7258
  * abi method inputs length without '_len' inputs
@@ -5713,8 +7283,22 @@ ${indent}}` : "}";
5713
7283
  // src/utils/calldata/parser/parser-2.0.0.ts
5714
7284
  var AbiParser2 = class {
5715
7285
  abi;
5716
- constructor(abi) {
7286
+ parsingStrategy;
7287
+ constructor(abi, parsingStrategy) {
5717
7288
  this.abi = abi;
7289
+ this.parsingStrategy = parsingStrategy || fastParsingStrategy;
7290
+ }
7291
+ getRequestParser(abiType) {
7292
+ if (this.parsingStrategy.request[abiType]) {
7293
+ return this.parsingStrategy.request[abiType];
7294
+ }
7295
+ throw new Error(`Parser for ${abiType} not found`);
7296
+ }
7297
+ getResponseParser(abiType) {
7298
+ if (this.parsingStrategy.response[abiType]) {
7299
+ return this.parsingStrategy.response[abiType];
7300
+ }
7301
+ throw new Error(`Parser for ${abiType} not found`);
5718
7302
  }
5719
7303
  /**
5720
7304
  * abi method inputs length
@@ -5747,13 +7331,13 @@ ${indent}}` : "}";
5747
7331
  };
5748
7332
 
5749
7333
  // src/utils/calldata/parser/index.ts
5750
- function createAbiParser(abi) {
7334
+ function createAbiParser(abi, parsingStrategy) {
5751
7335
  const version = getAbiVersion(abi);
5752
7336
  if (version === 0 || version === 1) {
5753
- return new AbiParser1(abi);
7337
+ return new AbiParser1(abi, parsingStrategy);
5754
7338
  }
5755
7339
  if (version === 2) {
5756
- return new AbiParser2(abi);
7340
+ return new AbiParser2(abi, parsingStrategy);
5757
7341
  }
5758
7342
  throw Error(`Unsupported ABI version ${version}`);
5759
7343
  }
@@ -5880,16 +7464,17 @@ ${indent}}` : "}";
5880
7464
  `The type ${arrayType} do not includes any content type. Needs [type; length].`
5881
7465
  );
5882
7466
  }
7467
+ let arraySize;
5883
7468
  try {
5884
- _CairoFixedArray.getFixedArraySize(arrayType);
7469
+ arraySize = _CairoFixedArray.getFixedArraySize(arrayType);
5885
7470
  } catch {
5886
7471
  throw new Error(
5887
7472
  `The type ${arrayType} type do not includes any length. Needs [type; length].`
5888
7473
  );
5889
7474
  }
5890
7475
  assert(
5891
- _CairoFixedArray.getFixedArraySize(arrayType) === content.length,
5892
- `The ABI type ${arrayType} is expecting ${_CairoFixedArray.getFixedArraySize(arrayType)} items. ${content.length} items provided.`
7476
+ arraySize === content.length,
7477
+ `The ABI type ${arrayType} is expecting ${arraySize} items. ${content.length} items provided.`
5893
7478
  );
5894
7479
  this.content = content;
5895
7480
  this.arrayType = arrayType;
@@ -5986,6 +7571,7 @@ ${indent}}` : "}";
5986
7571
  }
5987
7572
  /**
5988
7573
  * Checks if the given Cairo type is a fixed-array type.
7574
+ * structure: [string; number]
5989
7575
  *
5990
7576
  * @param {string} type - The type to check.
5991
7577
  * @returns - `true` if the type is a fixed array type, `false` otherwise.
@@ -6030,7 +7616,7 @@ ${indent}}` : "}";
6030
7616
  if (isTypeNonZero(abiType)) {
6031
7617
  return unorderedItem;
6032
7618
  }
6033
- if (isTypeByteArray(abiType)) {
7619
+ if (CairoByteArray.isAbiType(abiType)) {
6034
7620
  return unorderedItem;
6035
7621
  }
6036
7622
  if (isTypeU96(abiType)) {
@@ -6188,14 +7774,38 @@ ${indent}}` : "}";
6188
7774
  }
6189
7775
 
6190
7776
  // src/utils/calldata/requestParser.ts
6191
- function parseBaseTypes(type, val) {
7777
+ function parseBaseTypes({
7778
+ type,
7779
+ val,
7780
+ parser
7781
+ }) {
6192
7782
  switch (true) {
6193
7783
  case CairoUint256.isAbiType(type):
6194
- return new CairoUint256(val).toApiRequest();
7784
+ return parser.getRequestParser(type)(val);
6195
7785
  case CairoUint512.isAbiType(type):
6196
- return new CairoUint512(val).toApiRequest();
6197
- case isTypeBytes31(type):
6198
- return encodeShortString(val.toString());
7786
+ return parser.getRequestParser(type)(val);
7787
+ case CairoUint8.isAbiType(type):
7788
+ return parser.getRequestParser(type)(val);
7789
+ case CairoUint16.isAbiType(type):
7790
+ return parser.getRequestParser(type)(val);
7791
+ case CairoUint64.isAbiType(type):
7792
+ return parser.getRequestParser(type)(val);
7793
+ case CairoUint96.isAbiType(type):
7794
+ return parser.getRequestParser(type)(val);
7795
+ case CairoUint128.isAbiType(type):
7796
+ return parser.getRequestParser(type)(val);
7797
+ case CairoInt8.isAbiType(type):
7798
+ return parser.getRequestParser(type)(val);
7799
+ case CairoInt16.isAbiType(type):
7800
+ return parser.getRequestParser(type)(val);
7801
+ case CairoInt32.isAbiType(type):
7802
+ return parser.getRequestParser(type)(val);
7803
+ case CairoInt64.isAbiType(type):
7804
+ return parser.getRequestParser(type)(val);
7805
+ case CairoInt128.isAbiType(type):
7806
+ return parser.getRequestParser(type)(val);
7807
+ case CairoBytes31.isAbiType(type):
7808
+ return parser.getRequestParser(type)(val);
6199
7809
  case isTypeSecp256k1Point(type): {
6200
7810
  const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
6201
7811
  const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
@@ -6208,7 +7818,7 @@ ${indent}}` : "}";
6208
7818
  ];
6209
7819
  }
6210
7820
  default:
6211
- return felt(val);
7821
+ return parser.getRequestParser(CairoFelt252.abiSelector)(val);
6212
7822
  }
6213
7823
  }
6214
7824
  function parseTuple(element, typeStr) {
@@ -6228,16 +7838,13 @@ ${indent}}` : "}";
6228
7838
  };
6229
7839
  });
6230
7840
  }
6231
- function parseByteArray(element) {
6232
- const myByteArray = byteArrayFromString(element);
6233
- return [
6234
- myByteArray.data.length.toString(),
6235
- ...myByteArray.data.map((bn) => bn.toString()),
6236
- myByteArray.pending_word.toString(),
6237
- myByteArray.pending_word_len.toString()
6238
- ];
6239
- }
6240
- function parseCalldataValue(element, type, structs, enums) {
7841
+ function parseCalldataValue({
7842
+ element,
7843
+ type,
7844
+ structs,
7845
+ enums,
7846
+ parser
7847
+ }) {
6241
7848
  if (element === void 0) {
6242
7849
  throw Error(`Missing parameter for type ${type}`);
6243
7850
  }
@@ -6257,7 +7864,9 @@ ${indent}}` : "}";
6257
7864
  throw new Error(`ABI type ${type}: not an Array representing a cairo.fixedArray() provided.`);
6258
7865
  }
6259
7866
  return values.reduce((acc, it) => {
6260
- return acc.concat(parseCalldataValue(it, arrayType, structs, enums));
7867
+ return acc.concat(
7868
+ parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
7869
+ );
6261
7870
  }, []);
6262
7871
  }
6263
7872
  if (Array.isArray(element)) {
@@ -6265,37 +7874,51 @@ ${indent}}` : "}";
6265
7874
  result.push(felt(element.length));
6266
7875
  const arrayType = getArrayType(type);
6267
7876
  return element.reduce((acc, it) => {
6268
- return acc.concat(parseCalldataValue(it, arrayType, structs, enums));
7877
+ return acc.concat(
7878
+ parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
7879
+ );
6269
7880
  }, result);
6270
7881
  }
7882
+ if (CairoUint256.isAbiType(type)) {
7883
+ return parser.getRequestParser(type)(element);
7884
+ }
7885
+ if (CairoUint512.isAbiType(type)) {
7886
+ return parser.getRequestParser(type)(element);
7887
+ }
6271
7888
  if (structs[type] && structs[type].members.length) {
6272
- if (CairoUint256.isAbiType(type)) {
6273
- return new CairoUint256(element).toApiRequest();
7889
+ if (isTypeEthAddress(type)) {
7890
+ return parseBaseTypes({ type, val: element, parser });
6274
7891
  }
6275
- if (CairoUint512.isAbiType(type)) {
6276
- return new CairoUint512(element).toApiRequest();
7892
+ if (CairoByteArray.isAbiType(type)) {
7893
+ return parser.getRequestParser(type)(element);
6277
7894
  }
6278
- if (isTypeEthAddress(type)) return parseBaseTypes(type, element);
6279
- if (isTypeByteArray(type)) return parseByteArray(element);
6280
7895
  const { members } = structs[type];
6281
7896
  const subElement = element;
6282
7897
  return members.reduce((acc, it) => {
6283
- return acc.concat(parseCalldataValue(subElement[it.name], it.type, structs, enums));
7898
+ return acc.concat(
7899
+ parseCalldataValue({
7900
+ element: subElement[it.name],
7901
+ type: it.type,
7902
+ structs,
7903
+ enums,
7904
+ parser
7905
+ })
7906
+ );
6284
7907
  }, []);
6285
7908
  }
6286
7909
  if (isTypeTuple(type)) {
6287
7910
  const tupled = parseTuple(element, type);
6288
7911
  return tupled.reduce((acc, it) => {
6289
- const parsedData = parseCalldataValue(it.element, it.type, structs, enums);
7912
+ const parsedData = parseCalldataValue({
7913
+ element: it.element,
7914
+ type: it.type,
7915
+ structs,
7916
+ enums,
7917
+ parser
7918
+ });
6290
7919
  return acc.concat(parsedData);
6291
7920
  }, []);
6292
7921
  }
6293
- if (CairoUint256.isAbiType(type)) {
6294
- return new CairoUint256(element).toApiRequest();
6295
- }
6296
- if (CairoUint512.isAbiType(type)) {
6297
- return new CairoUint512(element).toApiRequest();
6298
- }
6299
7922
  if (isTypeEnum(type, enums)) {
6300
7923
  const { variants } = enums[type];
6301
7924
  if (isTypeOption(type)) {
@@ -6309,12 +7932,13 @@ ${indent}}` : "}";
6309
7932
  if (typeVariantSome === "()") {
6310
7933
  return CairoOptionVariant.Some.toString();
6311
7934
  }
6312
- const parsedParameter2 = parseCalldataValue(
6313
- myOption.unwrap(),
6314
- typeVariantSome,
7935
+ const parsedParameter2 = parseCalldataValue({
7936
+ element: myOption.unwrap(),
7937
+ type: typeVariantSome,
6315
7938
  structs,
6316
- enums
6317
- );
7939
+ enums,
7940
+ parser
7941
+ });
6318
7942
  if (Array.isArray(parsedParameter2)) {
6319
7943
  return [CairoOptionVariant.Some.toString(), ...parsedParameter2];
6320
7944
  }
@@ -6333,12 +7957,13 @@ ${indent}}` : "}";
6333
7957
  if (typeVariantOk === "()") {
6334
7958
  return CairoResultVariant.Ok.toString();
6335
7959
  }
6336
- const parsedParameter3 = parseCalldataValue(
6337
- myResult.unwrap(),
6338
- typeVariantOk,
7960
+ const parsedParameter3 = parseCalldataValue({
7961
+ element: myResult.unwrap(),
7962
+ type: typeVariantOk,
6339
7963
  structs,
6340
- enums
6341
- );
7964
+ enums,
7965
+ parser
7966
+ });
6342
7967
  if (Array.isArray(parsedParameter3)) {
6343
7968
  return [CairoResultVariant.Ok.toString(), ...parsedParameter3];
6344
7969
  }
@@ -6352,7 +7977,13 @@ ${indent}}` : "}";
6352
7977
  if (typeVariantErr === "()") {
6353
7978
  return CairoResultVariant.Err.toString();
6354
7979
  }
6355
- const parsedParameter2 = parseCalldataValue(myResult.unwrap(), typeVariantErr, structs, enums);
7980
+ const parsedParameter2 = parseCalldataValue({
7981
+ element: myResult.unwrap(),
7982
+ type: typeVariantErr,
7983
+ structs,
7984
+ enums,
7985
+ parser
7986
+ });
6356
7987
  if (Array.isArray(parsedParameter2)) {
6357
7988
  return [CairoResultVariant.Err.toString(), ...parsedParameter2];
6358
7989
  }
@@ -6369,21 +8000,33 @@ ${indent}}` : "}";
6369
8000
  if (typeActiveVariant === "()") {
6370
8001
  return numActiveVariant.toString();
6371
8002
  }
6372
- const parsedParameter = parseCalldataValue(myEnum.unwrap(), typeActiveVariant, structs, enums);
8003
+ const parsedParameter = parseCalldataValue({
8004
+ element: myEnum.unwrap(),
8005
+ type: typeActiveVariant,
8006
+ structs,
8007
+ enums,
8008
+ parser
8009
+ });
6373
8010
  if (Array.isArray(parsedParameter)) {
6374
8011
  return [numActiveVariant.toString(), ...parsedParameter];
6375
8012
  }
6376
8013
  return [numActiveVariant.toString(), parsedParameter];
6377
8014
  }
6378
8015
  if (isTypeNonZero(type)) {
6379
- return parseBaseTypes(getArrayType(type), element);
8016
+ return parseBaseTypes({ type: getArrayType(type), val: element, parser });
6380
8017
  }
6381
8018
  if (typeof element === "object") {
6382
8019
  throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
6383
8020
  }
6384
- return parseBaseTypes(type, element);
8021
+ return parseBaseTypes({ type, val: element, parser });
6385
8022
  }
6386
- function parseCalldataField(argsIterator, input, structs, enums) {
8023
+ function parseCalldataField({
8024
+ argsIterator,
8025
+ input,
8026
+ structs,
8027
+ enums,
8028
+ parser
8029
+ }) {
6387
8030
  const { name, type } = input;
6388
8031
  let { value } = argsIterator.next();
6389
8032
  switch (true) {
@@ -6392,7 +8035,7 @@ ${indent}}` : "}";
6392
8035
  if (!Array.isArray(value) && !(typeof value === "object")) {
6393
8036
  throw Error(`ABI expected parameter ${name} to be an array or an object, got ${value}`);
6394
8037
  }
6395
- return parseCalldataValue(value, input.type, structs, enums);
8038
+ return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
6396
8039
  // Normal Array
6397
8040
  case isTypeArray(type):
6398
8041
  if (!Array.isArray(value) && !isText(value)) {
@@ -6401,51 +8044,71 @@ ${indent}}` : "}";
6401
8044
  if (isString(value)) {
6402
8045
  value = splitLongString(value);
6403
8046
  }
6404
- return parseCalldataValue(value, input.type, structs, enums);
8047
+ return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
6405
8048
  case isTypeNonZero(type):
6406
- return parseBaseTypes(getArrayType(type), value);
8049
+ return parseBaseTypes({ type: getArrayType(type), val: value, parser });
6407
8050
  case isTypeEthAddress(type):
6408
- return parseBaseTypes(type, value);
8051
+ return parseBaseTypes({ type, val: value, parser });
6409
8052
  // Struct or Tuple
6410
8053
  case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
6411
- return parseCalldataValue(value, type, structs, enums);
8054
+ return parseCalldataValue({
8055
+ element: value,
8056
+ type,
8057
+ structs,
8058
+ enums,
8059
+ parser
8060
+ });
6412
8061
  // Enums
6413
8062
  case isTypeEnum(type, enums):
6414
- return parseCalldataValue(
6415
- value,
8063
+ return parseCalldataValue({
8064
+ element: value,
6416
8065
  type,
6417
8066
  structs,
6418
- enums
6419
- );
8067
+ enums,
8068
+ parser
8069
+ });
6420
8070
  // Felt or unhandled
6421
8071
  default:
6422
- return parseBaseTypes(type, value);
8072
+ return parseBaseTypes({ type, val: value, parser });
6423
8073
  }
6424
8074
  }
6425
8075
 
6426
8076
  // src/utils/calldata/responseParser.ts
6427
- function parseBaseTypes2(type, it) {
8077
+ function parseBaseTypes2(type, it, parser) {
6428
8078
  let temp;
6429
8079
  switch (true) {
6430
8080
  case isTypeBool(type):
6431
8081
  temp = it.next().value;
6432
8082
  return Boolean(BigInt(temp));
6433
8083
  case CairoUint256.isAbiType(type):
6434
- const low = it.next().value;
6435
- const high = it.next().value;
6436
- return new CairoUint256(low, high).toBigInt();
8084
+ return parser.getResponseParser(type)(it);
6437
8085
  case CairoUint512.isAbiType(type):
6438
- const limb0 = it.next().value;
6439
- const limb1 = it.next().value;
6440
- const limb2 = it.next().value;
6441
- const limb3 = it.next().value;
6442
- return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
8086
+ return parser.getResponseParser(type)(it);
8087
+ case CairoUint8.isAbiType(type):
8088
+ return parser.getResponseParser(type)(it);
8089
+ case CairoUint16.isAbiType(type):
8090
+ return parser.getResponseParser(type)(it);
8091
+ case CairoUint64.isAbiType(type):
8092
+ return parser.getResponseParser(type)(it);
8093
+ case CairoUint96.isAbiType(type):
8094
+ return parser.getResponseParser(type)(it);
8095
+ case CairoUint128.isAbiType(type):
8096
+ return parser.getResponseParser(type)(it);
8097
+ case CairoInt8.isAbiType(type):
8098
+ return parser.getResponseParser(type)(it);
8099
+ case CairoInt16.isAbiType(type):
8100
+ return parser.getResponseParser(type)(it);
8101
+ case CairoInt32.isAbiType(type):
8102
+ return parser.getResponseParser(type)(it);
8103
+ case CairoInt64.isAbiType(type):
8104
+ return parser.getResponseParser(type)(it);
8105
+ case CairoInt128.isAbiType(type):
8106
+ return parser.getResponseParser(type)(it);
6443
8107
  case isTypeEthAddress(type):
6444
8108
  temp = it.next().value;
6445
8109
  return BigInt(temp);
6446
- case isTypeBytes31(type):
6447
- temp = it.next().value;
6448
- return decodeShortString(temp);
8110
+ case CairoBytes31.isAbiType(type):
8111
+ return parser.getResponseParser(type)(it);
6449
8112
  case isTypeSecp256k1Point(type):
6450
8113
  const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
6451
8114
  const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
@@ -6454,47 +8117,28 @@ ${indent}}` : "}";
6454
8117
  const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
6455
8118
  return pubK;
6456
8119
  default:
6457
- temp = it.next().value;
6458
- return BigInt(temp);
8120
+ return parser.getResponseParser(CairoFelt252.abiSelector)(it);
6459
8121
  }
6460
8122
  }
6461
- function parseResponseValue(responseIterator, element, structs, enums) {
8123
+ function parseResponseValue(responseIterator, element, parser, structs, enums) {
6462
8124
  if (element.type === "()") {
6463
8125
  return {};
6464
8126
  }
6465
8127
  if (CairoUint256.isAbiType(element.type)) {
6466
- const low = responseIterator.next().value;
6467
- const high = responseIterator.next().value;
6468
- return new CairoUint256(low, high).toBigInt();
8128
+ return parser.getResponseParser(element.type)(responseIterator);
6469
8129
  }
6470
8130
  if (CairoUint512.isAbiType(element.type)) {
6471
- const limb0 = responseIterator.next().value;
6472
- const limb1 = responseIterator.next().value;
6473
- const limb2 = responseIterator.next().value;
6474
- const limb3 = responseIterator.next().value;
6475
- return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
6476
- }
6477
- if (isTypeByteArray(element.type)) {
6478
- const parsedBytes31Arr = [];
6479
- const bytes31ArrLen = BigInt(responseIterator.next().value);
6480
- while (parsedBytes31Arr.length < bytes31ArrLen) {
6481
- parsedBytes31Arr.push(toHex(responseIterator.next().value));
6482
- }
6483
- const pending_word = toHex(responseIterator.next().value);
6484
- const pending_word_len = BigInt(responseIterator.next().value);
6485
- const myByteArray = {
6486
- data: parsedBytes31Arr,
6487
- pending_word,
6488
- pending_word_len
6489
- };
6490
- return stringFromByteArray(myByteArray);
8131
+ return parser.getResponseParser(element.type)(responseIterator);
8132
+ }
8133
+ if (CairoByteArray.isAbiType(element.type)) {
8134
+ return parser.getResponseParser(element.type)(responseIterator);
6491
8135
  }
6492
8136
  if (CairoFixedArray.isTypeFixedArray(element.type)) {
6493
8137
  const parsedDataArr = [];
6494
8138
  const el = { name: "", type: CairoFixedArray.getFixedArrayType(element.type) };
6495
8139
  const arraySize = CairoFixedArray.getFixedArraySize(element.type);
6496
8140
  while (parsedDataArr.length < arraySize) {
6497
- parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
8141
+ parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
6498
8142
  }
6499
8143
  return parsedDataArr;
6500
8144
  }
@@ -6503,20 +8147,20 @@ ${indent}}` : "}";
6503
8147
  const el = { name: "", type: getArrayType(element.type) };
6504
8148
  const len = BigInt(responseIterator.next().value);
6505
8149
  while (parsedDataArr.length < len) {
6506
- parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
8150
+ parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
6507
8151
  }
6508
8152
  return parsedDataArr;
6509
8153
  }
6510
8154
  if (isTypeNonZero(element.type)) {
6511
8155
  const el = { name: "", type: getArrayType(element.type) };
6512
- return parseResponseValue(responseIterator, el, structs, enums);
8156
+ return parseResponseValue(responseIterator, el, parser, structs, enums);
6513
8157
  }
6514
8158
  if (structs && element.type in structs && structs[element.type]) {
6515
8159
  if (isTypeEthAddress(element.type)) {
6516
- return parseBaseTypes2(element.type, responseIterator);
8160
+ return parseBaseTypes2(element.type, responseIterator, parser);
6517
8161
  }
6518
8162
  return structs[element.type].members.reduce((acc, el) => {
6519
- acc[el.name] = parseResponseValue(responseIterator, el, structs, enums);
8163
+ acc[el.name] = parseResponseValue(responseIterator, el, parser, structs, enums);
6520
8164
  return acc;
6521
8165
  }, {});
6522
8166
  }
@@ -6527,6 +8171,7 @@ ${indent}}` : "}";
6527
8171
  acc[variant.name] = parseResponseValue(
6528
8172
  responseIterator,
6529
8173
  { name: "", type: variant.type },
8174
+ parser,
6530
8175
  structs,
6531
8176
  enums
6532
8177
  );
@@ -6557,7 +8202,7 @@ ${indent}}` : "}";
6557
8202
  const name = it?.name ? it.name : idx;
6558
8203
  const type = it?.type ? it.type : it;
6559
8204
  const el = { name, type };
6560
- acc[name] = parseResponseValue(responseIterator, el, structs, enums);
8205
+ acc[name] = parseResponseValue(responseIterator, el, parser, structs, enums);
6561
8206
  return acc;
6562
8207
  }, {});
6563
8208
  }
@@ -6566,13 +8211,20 @@ ${indent}}` : "}";
6566
8211
  const el = { name: "", type: getArrayType(element.type) };
6567
8212
  const len = BigInt(responseIterator.next().value);
6568
8213
  while (parsedDataArr.length < len) {
6569
- parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
8214
+ parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
6570
8215
  }
6571
8216
  return parsedDataArr;
6572
8217
  }
6573
- return parseBaseTypes2(element.type, responseIterator);
8218
+ return parseBaseTypes2(element.type, responseIterator, parser);
6574
8219
  }
6575
- function responseParser(responseIterator, output, structs, enums, parsedResult) {
8220
+ function responseParser({
8221
+ responseIterator,
8222
+ output,
8223
+ structs,
8224
+ enums,
8225
+ parsedResult,
8226
+ parser
8227
+ }) {
6576
8228
  const { name, type } = output;
6577
8229
  let temp;
6578
8230
  switch (true) {
@@ -6580,14 +8232,14 @@ ${indent}}` : "}";
6580
8232
  temp = responseIterator.next().value;
6581
8233
  return BigInt(temp);
6582
8234
  case (structs && type in structs || isTypeTuple(type)):
6583
- return parseResponseValue(responseIterator, output, structs, enums);
8235
+ return parseResponseValue(responseIterator, output, parser, structs, enums);
6584
8236
  case (enums && isTypeEnum(type, enums)):
6585
- return parseResponseValue(responseIterator, output, structs, enums);
8237
+ return parseResponseValue(responseIterator, output, parser, structs, enums);
6586
8238
  case CairoFixedArray.isTypeFixedArray(type):
6587
- return parseResponseValue(responseIterator, output, structs, enums);
8239
+ return parseResponseValue(responseIterator, output, parser, structs, enums);
6588
8240
  case isTypeArray(type):
6589
8241
  if (isCairo1Type(type)) {
6590
- return parseResponseValue(responseIterator, output, structs, enums);
8242
+ return parseResponseValue(responseIterator, output, parser, structs, enums);
6591
8243
  }
6592
8244
  const parsedDataArr = [];
6593
8245
  if (parsedResult && parsedResult[`${name}_len`]) {
@@ -6597,6 +8249,7 @@ ${indent}}` : "}";
6597
8249
  parseResponseValue(
6598
8250
  responseIterator,
6599
8251
  { name, type: output.type.replace("*", "") },
8252
+ parser,
6600
8253
  structs,
6601
8254
  enums
6602
8255
  )
@@ -6605,9 +8258,9 @@ ${indent}}` : "}";
6605
8258
  }
6606
8259
  return parsedDataArr;
6607
8260
  case isTypeNonZero(type):
6608
- return parseResponseValue(responseIterator, output, structs, enums);
8261
+ return parseResponseValue(responseIterator, output, parser, structs, enums);
6609
8262
  default:
6610
- return parseBaseTypes2(type, responseIterator);
8263
+ return parseBaseTypes2(type, responseIterator, parser);
6611
8264
  }
6612
8265
  }
6613
8266
 
@@ -6625,16 +8278,6 @@ ${indent}}` : "}";
6625
8278
  `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
6626
8279
  );
6627
8280
  };
6628
- var validateBytes31 = (parameter, input) => {
6629
- assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
6630
- assert(
6631
- parameter.length < 32,
6632
- `Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
6633
- );
6634
- };
6635
- var validateByteArray = (parameter, input) => {
6636
- assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
6637
- };
6638
8281
  var validateUint = (parameter, input) => {
6639
8282
  if (isNumber2(parameter)) {
6640
8283
  assert(
@@ -6886,8 +8529,8 @@ ${indent}}` : "}";
6886
8529
  case isTypeFelt(input.type):
6887
8530
  validateFelt(parameter, input);
6888
8531
  break;
6889
- case isTypeBytes31(input.type):
6890
- validateBytes31(parameter, input);
8532
+ case CairoBytes31.isAbiType(input.type):
8533
+ CairoBytes31.validate(parameter);
6891
8534
  break;
6892
8535
  case (isTypeUint(input.type) || isTypeLiteral(input.type)):
6893
8536
  validateUint(parameter, input);
@@ -6895,8 +8538,23 @@ ${indent}}` : "}";
6895
8538
  case isTypeBool(input.type):
6896
8539
  validateBool(parameter, input);
6897
8540
  break;
6898
- case isTypeByteArray(input.type):
6899
- validateByteArray(parameter, input);
8541
+ case CairoByteArray.isAbiType(input.type):
8542
+ CairoByteArray.validate(parameter);
8543
+ break;
8544
+ case CairoInt8.isAbiType(input.type):
8545
+ CairoInt8.validate(parameter);
8546
+ break;
8547
+ case CairoInt16.isAbiType(input.type):
8548
+ CairoInt16.validate(parameter);
8549
+ break;
8550
+ case CairoInt32.isAbiType(input.type):
8551
+ CairoInt32.validate(parameter);
8552
+ break;
8553
+ case CairoInt64.isAbiType(input.type):
8554
+ CairoInt64.validate(parameter);
8555
+ break;
8556
+ case CairoInt128.isAbiType(input.type):
8557
+ CairoInt128.validate(parameter);
6900
8558
  break;
6901
8559
  case (isTypeArray(input.type) || CairoFixedArray.isTypeFixedArray(input.type)):
6902
8560
  validateArray(parameter, input, structs, enums);
@@ -6928,10 +8586,10 @@ ${indent}}` : "}";
6928
8586
  parser;
6929
8587
  structs;
6930
8588
  enums;
6931
- constructor(abi) {
8589
+ constructor(abi, parsingStrategy) {
6932
8590
  this.structs = _CallData.getAbiStruct(abi);
6933
8591
  this.enums = _CallData.getAbiEnum(abi);
6934
- this.parser = createAbiParser(abi);
8592
+ this.parser = createAbiParser(abi, parsingStrategy);
6935
8593
  this.abi = this.parser.getLegacyFormat();
6936
8594
  }
6937
8595
  /**
@@ -7000,7 +8658,15 @@ ${indent}}` : "}";
7000
8658
  }
7001
8659
  const argsIterator = args[Symbol.iterator]();
7002
8660
  const callArray = abiMethod.inputs.reduce(
7003
- (acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs, this.enums)),
8661
+ (acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
8662
+ parseCalldataField({
8663
+ argsIterator,
8664
+ input,
8665
+ structs: this.structs,
8666
+ enums: this.enums,
8667
+ parser: this.parser
8668
+ })
8669
+ ),
7004
8670
  []
7005
8671
  );
7006
8672
  Object.defineProperty(callArray, "__compiled__", {
@@ -7087,7 +8753,14 @@ ${indent}}` : "}";
7087
8753
  const responseIterator = response.flat()[Symbol.iterator]();
7088
8754
  const parsed = outputs.flat().reduce((acc, output, idx) => {
7089
8755
  const propName = output.name ?? idx;
7090
- acc[propName] = responseParser(responseIterator, output, this.structs, this.enums, acc);
8756
+ acc[propName] = responseParser({
8757
+ responseIterator,
8758
+ output,
8759
+ structs: this.structs,
8760
+ enums: this.enums,
8761
+ parsedResult: acc,
8762
+ parser: this.parser
8763
+ });
7091
8764
  if (acc[propName] && acc[`${propName}_len`]) {
7092
8765
  delete acc[`${propName}_len`];
7093
8766
  }
@@ -7167,12 +8840,13 @@ ${indent}}` : "}";
7167
8840
  const typeCairoArray = Array.isArray(typeCairo) ? typeCairo : [typeCairo];
7168
8841
  const responseIterator = response.flat()[Symbol.iterator]();
7169
8842
  const decodedArray = typeCairoArray.map(
7170
- (typeParam) => responseParser(
8843
+ (typeParam) => responseParser({
7171
8844
  responseIterator,
7172
- { name: "", type: typeParam },
7173
- this.structs,
7174
- this.enums
7175
- )
8845
+ output: { name: "", type: typeParam },
8846
+ parser: this.parser,
8847
+ structs: this.structs,
8848
+ enums: this.enums
8849
+ })
7176
8850
  );
7177
8851
  return decodedArray.length === 1 ? decodedArray[0] : decodedArray;
7178
8852
  }
@@ -12027,114 +13701,6 @@ ${indent}}` : "}";
12027
13701
  return { ...contract, program: decompressProgram(contract.program) };
12028
13702
  }
12029
13703
 
12030
- // src/utils/errors/rpc.ts
12031
- var errorCodes = {
12032
- FAILED_TO_RECEIVE_TXN: 1,
12033
- NO_TRACE_AVAILABLE: 10,
12034
- CONTRACT_NOT_FOUND: 20,
12035
- ENTRYPOINT_NOT_FOUND: 21,
12036
- BLOCK_NOT_FOUND: 24,
12037
- INVALID_TXN_INDEX: 27,
12038
- CLASS_HASH_NOT_FOUND: 28,
12039
- TXN_HASH_NOT_FOUND: 29,
12040
- PAGE_SIZE_TOO_BIG: 31,
12041
- NO_BLOCKS: 32,
12042
- INVALID_CONTINUATION_TOKEN: 33,
12043
- TOO_MANY_KEYS_IN_FILTER: 34,
12044
- CONTRACT_ERROR: 40,
12045
- TRANSACTION_EXECUTION_ERROR: 41,
12046
- STORAGE_PROOF_NOT_SUPPORTED: 42,
12047
- CLASS_ALREADY_DECLARED: 51,
12048
- INVALID_TRANSACTION_NONCE: 52,
12049
- INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
12050
- INSUFFICIENT_ACCOUNT_BALANCE: 54,
12051
- VALIDATION_FAILURE: 55,
12052
- COMPILATION_FAILED: 56,
12053
- CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
12054
- NON_ACCOUNT: 58,
12055
- DUPLICATE_TX: 59,
12056
- COMPILED_CLASS_HASH_MISMATCH: 60,
12057
- UNSUPPORTED_TX_VERSION: 61,
12058
- UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
12059
- UNEXPECTED_ERROR: 63,
12060
- INVALID_SUBSCRIPTION_ID: 66,
12061
- TOO_MANY_ADDRESSES_IN_FILTER: 67,
12062
- TOO_MANY_BLOCKS_BACK: 68,
12063
- COMPILATION_ERROR: 100,
12064
- INVALID_ADDRESS: 150,
12065
- TOKEN_NOT_SUPPORTED: 151,
12066
- INVALID_SIGNATURE: 153,
12067
- MAX_AMOUNT_TOO_LOW: 154,
12068
- CLASS_HASH_NOT_SUPPORTED: 155,
12069
- PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
12070
- INVALID_TIME_BOUNDS: 157,
12071
- INVALID_DEPLOYMENT_DATA: 158,
12072
- INVALID_CLASS_HASH: 159,
12073
- INVALID_ID: 160,
12074
- UNKNOWN_ERROR: 163
12075
- };
12076
- var rpc_default = errorCodes;
12077
-
12078
- // src/utils/errors/index.ts
12079
- function fixStack(target, fn = target.constructor) {
12080
- const { captureStackTrace } = Error;
12081
- captureStackTrace && captureStackTrace(target, fn);
12082
- }
12083
- function fixProto(target, prototype) {
12084
- const { setPrototypeOf } = Object;
12085
- setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
12086
- }
12087
- var CustomError = class extends Error {
12088
- name;
12089
- constructor(message) {
12090
- super(message);
12091
- Object.defineProperty(this, "name", {
12092
- value: new.target.name,
12093
- enumerable: false,
12094
- configurable: true
12095
- });
12096
- fixProto(this, new.target.prototype);
12097
- fixStack(this);
12098
- }
12099
- };
12100
- var LibraryError = class extends CustomError {
12101
- };
12102
- var RpcError = class extends LibraryError {
12103
- constructor(baseError, method, params) {
12104
- super(`RPC: ${method} with params ${stringify2(params, null, 2)}
12105
-
12106
- ${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
12107
- this.baseError = baseError;
12108
- this.request = { method, params };
12109
- }
12110
- request;
12111
- get code() {
12112
- return this.baseError.code;
12113
- }
12114
- /**
12115
- * Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
12116
- * @example
12117
- * ```typescript
12118
- * SomeError.isType('UNEXPECTED_ERROR');
12119
- * ```
12120
- */
12121
- isType(typeName) {
12122
- return rpc_default[typeName] === this.code;
12123
- }
12124
- };
12125
- var TimeoutError = class extends LibraryError {
12126
- constructor(message) {
12127
- super(message);
12128
- this.name = "TimeoutError";
12129
- }
12130
- };
12131
- var WebSocketNotConnectedError = class extends LibraryError {
12132
- constructor(message) {
12133
- super(message);
12134
- this.name = "WebSocketNotConnectedError";
12135
- }
12136
- };
12137
-
12138
13704
  // src/utils/eth.ts
12139
13705
  var eth_exports = {};
12140
13706
  __export(eth_exports, {
@@ -12354,7 +13920,7 @@ ${indent}}` : "}";
12354
13920
  tag = null;
12355
13921
  setIdentifier(__identifier) {
12356
13922
  if (isString(__identifier)) {
12357
- if (isDecimalString(__identifier)) {
13923
+ if (isDecimalString2(__identifier)) {
12358
13924
  this.number = parseInt(__identifier, 10);
12359
13925
  } else if (isHex2(__identifier)) {
12360
13926
  this.hash = __identifier;
@@ -12803,11 +14369,13 @@ ${indent}}` : "}";
12803
14369
  esm_exports.ETransactionStatus.ACCEPTED_ON_L2,
12804
14370
  esm_exports.ETransactionStatus.ACCEPTED_ON_L1
12805
14371
  ];
14372
+ const txLife = [];
12806
14373
  let txStatus;
12807
14374
  while (!onchain) {
12808
14375
  await wait(retryInterval);
12809
14376
  try {
12810
14377
  txStatus = await this.getTransactionStatus(transactionHash);
14378
+ txLife.push(txStatus.finality_status);
12811
14379
  const executionStatus = txStatus.execution_status;
12812
14380
  const finalityStatus = txStatus.finality_status;
12813
14381
  if (!finalityStatus) {
@@ -12827,6 +14395,18 @@ ${indent}}` : "}";
12827
14395
  if (error instanceof Error && isErrorState) {
12828
14396
  throw error;
12829
14397
  }
14398
+ if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
14399
+ logger.info("txLife: ", txLife);
14400
+ const errorMessages = {
14401
+ [esm_exports2.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
14402
+ [esm_exports2.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
14403
+ [esm_exports2.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
14404
+ };
14405
+ const errorMessage = errorMessages[txLife.at(-1)];
14406
+ if (errorMessage) {
14407
+ throw new Error(errorMessage);
14408
+ }
14409
+ }
12830
14410
  if (retries <= 0) {
12831
14411
  throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
12832
14412
  }
@@ -13376,11 +14956,13 @@ ${indent}}` : "}";
13376
14956
  esm_exports2.ETransactionFinalityStatus.ACCEPTED_ON_L2,
13377
14957
  esm_exports2.ETransactionFinalityStatus.ACCEPTED_ON_L1
13378
14958
  ];
14959
+ const txLife = [];
13379
14960
  let txStatus;
13380
14961
  while (!onchain) {
13381
14962
  await wait(retryInterval);
13382
14963
  try {
13383
14964
  txStatus = await this.getTransactionStatus(transactionHash);
14965
+ txLife.push(txStatus.finality_status);
13384
14966
  const executionStatus = txStatus.execution_status;
13385
14967
  const finalityStatus = txStatus.finality_status;
13386
14968
  if (!finalityStatus) {
@@ -13400,6 +14982,18 @@ ${indent}}` : "}";
13400
14982
  if (error instanceof Error && isErrorState) {
13401
14983
  throw error;
13402
14984
  }
14985
+ if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
14986
+ logger.info("txLife: ", txLife);
14987
+ const errorMessages = {
14988
+ [esm_exports2.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
14989
+ [esm_exports2.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
14990
+ [esm_exports2.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
14991
+ };
14992
+ const errorMessage = errorMessages[txLife.at(-1)];
14993
+ if (errorMessage) {
14994
+ throw new Error(errorMessage);
14995
+ }
14996
+ }
13403
14997
  if (retries <= 0) {
13404
14998
  throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
13405
14999
  }
@@ -13743,7 +15337,7 @@ ${indent}}` : "}";
13743
15337
  }
13744
15338
  };
13745
15339
 
13746
- // src/channel/ws/ws_0_8.ts
15340
+ // src/channel/ws/ws_0_9.ts
13747
15341
  var WebSocketChannel = class {
13748
15342
  /**
13749
15343
  * The URL of the WebSocket RPC Node.
@@ -14091,19 +15685,19 @@ ${indent}}` : "}";
14091
15685
  }
14092
15686
  /**
14093
15687
  * Subscribes to new block headers.
14094
- * @param {SubscriptionBlockIdentifier} [blockIdentifier] - The block to start receiving notifications from. Defaults to 'latest'.
15688
+ * @param {SubscribeNewHeadsParams} params - The parameters for the subscription.
14095
15689
  * @returns {Promise<Subscription<BLOCK_HEADER>>} A Promise that resolves with a `Subscription` object for new block headers.
14096
15690
  */
14097
- async subscribeNewHeads(blockIdentifier) {
15691
+ async subscribeNewHeads(params = {}) {
14098
15692
  const method = "starknet_subscribeNewHeads";
14099
- const params = {
14100
- block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
15693
+ const rpcParams = {
15694
+ block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0
14101
15695
  };
14102
- const subId = await this.sendReceive(method, params);
15696
+ const subId = await this.sendReceive(method, rpcParams);
14103
15697
  const subscription = new Subscription({
14104
15698
  channel: this,
14105
15699
  method,
14106
- params,
15700
+ params: rpcParams,
14107
15701
  id: subId,
14108
15702
  maxBufferSize: this.maxBufferSize
14109
15703
  });
@@ -14112,23 +15706,22 @@ ${indent}}` : "}";
14112
15706
  }
14113
15707
  /**
14114
15708
  * Subscribes to events matching a given filter.
14115
- * @param {BigNumberish} [fromAddress] - The contract address to filter by.
14116
- * @param {string[][]} [keys] - The event keys to filter by.
14117
- * @param {SubscriptionBlockIdentifier} [blockIdentifier] - The block to start receiving notifications from. Defaults to 'latest'.
15709
+ * @param {SubscribeEventsParams} params - The parameters for the subscription.
14118
15710
  * @returns {Promise<Subscription<EMITTED_EVENT>>} A Promise that resolves with a `Subscription` object for the specified events.
14119
15711
  */
14120
- async subscribeEvents(fromAddress, keys, blockIdentifier) {
15712
+ async subscribeEvents(params = {}) {
14121
15713
  const method = "starknet_subscribeEvents";
14122
- const params = {
14123
- from_address: fromAddress !== void 0 ? toHex(fromAddress) : void 0,
14124
- keys,
14125
- block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
15714
+ const rpcParams = {
15715
+ from_address: params.fromAddress !== void 0 ? toHex(params.fromAddress) : void 0,
15716
+ keys: params.keys,
15717
+ block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0,
15718
+ finality_status: params.finalityStatus
14126
15719
  };
14127
- const subId = await this.sendReceive(method, params);
15720
+ const subId = await this.sendReceive(method, rpcParams);
14128
15721
  const subscription = new Subscription({
14129
15722
  channel: this,
14130
15723
  method,
14131
- params,
15724
+ params: rpcParams,
14132
15725
  id: subId,
14133
15726
  maxBufferSize: this.maxBufferSize
14134
15727
  });
@@ -14137,21 +15730,20 @@ ${indent}}` : "}";
14137
15730
  }
14138
15731
  /**
14139
15732
  * Subscribes to status updates for a specific transaction.
14140
- * @param {BigNumberish} transactionHash - The hash of the transaction to monitor.
14141
- * @param {SubscriptionBlockIdentifier} [blockIdentifier] - The block context. Not typically required.
15733
+ * @param {SubscribeTransactionStatusParams} params - The parameters for the subscription.
14142
15734
  * @returns {Promise<Subscription<NEW_TXN_STATUS>>} A Promise that resolves with a `Subscription` object for the transaction's status.
14143
15735
  */
14144
- async subscribeTransactionStatus(transactionHash, blockIdentifier) {
15736
+ async subscribeTransactionStatus(params) {
14145
15737
  const method = "starknet_subscribeTransactionStatus";
14146
- const params = {
14147
- transaction_hash: toHex(transactionHash),
14148
- block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
15738
+ const rpcParams = {
15739
+ transaction_hash: toHex(params.transactionHash),
15740
+ block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0
14149
15741
  };
14150
- const subId = await this.sendReceive(method, params);
15742
+ const subId = await this.sendReceive(method, rpcParams);
14151
15743
  const subscription = new Subscription({
14152
15744
  channel: this,
14153
15745
  method,
14154
- params,
15746
+ params: rpcParams,
14155
15747
  id: subId,
14156
15748
  maxBufferSize: this.maxBufferSize
14157
15749
  });
@@ -14159,22 +15751,43 @@ ${indent}}` : "}";
14159
15751
  return subscription;
14160
15752
  }
14161
15753
  /**
14162
- * Subscribes to pending transactions.
14163
- * @param {boolean} [transactionDetails] - If `true`, the full transaction details are included. Defaults to `false` (hash only).
14164
- * @param {BigNumberish[]} [senderAddress] - An array of sender addresses to filter by.
14165
- * @returns {Promise<Subscription<TXN_HASH | TXN_WITH_HASH>>} A Promise that resolves with a `Subscription` object for pending transactions.
15754
+ * Subscribes to new transaction receipts.
15755
+ * @param {SubscribeNewTransactionReceiptsParams} params - The parameters for the subscription.
15756
+ * @returns {Promise<Subscription<NewTransactionReceiptsEvent['result']>>} A Promise that resolves with a `Subscription` object for new transaction receipts.
14166
15757
  */
14167
- async subscribePendingTransaction(transactionDetails, senderAddress) {
14168
- const method = "starknet_subscribePendingTransactions";
14169
- const params = {
14170
- transaction_details: transactionDetails,
14171
- sender_address: senderAddress && bigNumberishArrayToHexadecimalStringArray(senderAddress)
15758
+ async subscribeNewTransactionReceipts(params = {}) {
15759
+ const method = "starknet_subscribeNewTransactionReceipts";
15760
+ const rpcParams = {
15761
+ finality_status: params.finalityStatus,
15762
+ sender_address: params.senderAddress && bigNumberishArrayToHexadecimalStringArray(params.senderAddress)
15763
+ };
15764
+ const subId = await this.sendReceive(method, rpcParams);
15765
+ const subscription = new Subscription({
15766
+ channel: this,
15767
+ method,
15768
+ params: rpcParams,
15769
+ id: subId,
15770
+ maxBufferSize: this.maxBufferSize
15771
+ });
15772
+ this.activeSubscriptions.set(subId, subscription);
15773
+ return subscription;
15774
+ }
15775
+ /**
15776
+ * Subscribes to new transactions.
15777
+ * @param {SubscribeNewTransactionsParams} params - The parameters for the subscription.
15778
+ * @returns {Promise<Subscription<NewTransactionEvent['result']>>} A Promise that resolves with a `Subscription` object for new transactions.
15779
+ */
15780
+ async subscribeNewTransactions(params = {}) {
15781
+ const method = "starknet_subscribeNewTransactions";
15782
+ const rpcParams = {
15783
+ finality_status: params.finalityStatus,
15784
+ sender_address: params.senderAddress && bigNumberishArrayToHexadecimalStringArray(params.senderAddress)
14172
15785
  };
14173
- const subId = await this.sendReceive(method, params);
15786
+ const subId = await this.sendReceive(method, rpcParams);
14174
15787
  const subscription = new Subscription({
14175
15788
  channel: this,
14176
15789
  method,
14177
- params,
15790
+ params: rpcParams,
14178
15791
  id: subId,
14179
15792
  maxBufferSize: this.maxBufferSize
14180
15793
  });
@@ -14445,56 +16058,123 @@ ${indent}}` : "}";
14445
16058
  statusReceipt;
14446
16059
  value;
14447
16060
  constructor(receipt) {
14448
- [this.statusReceipt, this.value] = _ReceiptTx.isSuccess(receipt) ? ["success", receipt] : _ReceiptTx.isReverted(receipt) ? ["reverted", receipt] : ["error", new Error("Unknown response type")];
14449
- for (const [key] of Object.entries(this)) {
14450
- Object.defineProperty(this, key, {
14451
- enumerable: false
14452
- });
14453
- }
14454
- for (const [key, value] of Object.entries(receipt)) {
14455
- Object.defineProperty(this, key, {
14456
- enumerable: true,
16061
+ Object.assign(this, receipt);
16062
+ const [statusReceipt, value] = _ReceiptTx.isSuccess(receipt) ? ["SUCCEEDED", receipt] : _ReceiptTx.isReverted(receipt) ? ["REVERTED", receipt] : ["ERROR", new Error("Unknown response type")];
16063
+ Object.defineProperties(this, {
16064
+ statusReceipt: {
16065
+ value: statusReceipt,
14457
16066
  writable: false,
14458
- value
14459
- });
14460
- }
14461
- }
14462
- match(callbacks) {
14463
- if (this.statusReceipt in callbacks) {
14464
- return callbacks[this.statusReceipt](this.value);
14465
- }
14466
- return callbacks._();
14467
- }
14468
- isSuccess() {
14469
- return this.statusReceipt === "success";
14470
- }
14471
- isReverted() {
14472
- return this.statusReceipt === "reverted";
14473
- }
14474
- // TODO: Missing is Pending or Production block
14475
- // Status do not exist on receipts
14476
- /* isRejected(): this is RejectedTransactionReceiptResponse {
14477
- return this.statusReceipt === 'rejected';
14478
- } */
14479
- isError() {
14480
- return this.statusReceipt === "error";
16067
+ enumerable: false,
16068
+ configurable: false
16069
+ },
16070
+ value: {
16071
+ value,
16072
+ writable: false,
16073
+ enumerable: false,
16074
+ configurable: false
16075
+ },
16076
+ match: {
16077
+ value(callbacks) {
16078
+ return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
16079
+ },
16080
+ writable: false,
16081
+ enumerable: false,
16082
+ configurable: false
16083
+ },
16084
+ isSuccess: {
16085
+ value: () => statusReceipt === "SUCCEEDED",
16086
+ writable: false,
16087
+ enumerable: false,
16088
+ configurable: false
16089
+ },
16090
+ isReverted: {
16091
+ value: () => statusReceipt === "REVERTED",
16092
+ writable: false,
16093
+ enumerable: false,
16094
+ configurable: false
16095
+ },
16096
+ isError: {
16097
+ value: () => statusReceipt === "ERROR",
16098
+ writable: false,
16099
+ enumerable: false,
16100
+ configurable: false
16101
+ }
16102
+ });
14481
16103
  }
16104
+ match;
16105
+ isSuccess;
16106
+ isReverted;
16107
+ isError;
14482
16108
  static isSuccess(transactionReceipt) {
14483
16109
  return transactionReceipt.execution_status === TransactionExecutionStatus.SUCCEEDED;
14484
16110
  }
14485
16111
  static isReverted(transactionReceipt) {
14486
16112
  return transactionReceipt.execution_status === TransactionExecutionStatus.REVERTED;
14487
16113
  }
14488
- // Status do not exist on receipts
14489
- /* static isRejected(
14490
- transactionReceipt: GetTxReceiptResponseWithoutHelper
14491
- ): transactionReceipt is RejectedTransactionReceiptResponse {
14492
- return (
14493
- (transactionReceipt as RejectedTransactionReceiptResponse).status ===
14494
- TransactionExecutionStatus.REJECTED
14495
- );
14496
- } */
14497
16114
  };
16115
+ var RECEIPT_CONFIG = {
16116
+ [TransactionExecutionStatus.SUCCEEDED]: {
16117
+ statusReceipt: "SUCCEEDED",
16118
+ getBaseData: (receipt) => receipt,
16119
+ getValue: (receipt) => receipt
16120
+ },
16121
+ [TransactionExecutionStatus.REVERTED]: {
16122
+ statusReceipt: "REVERTED",
16123
+ getBaseData: (receipt) => receipt,
16124
+ getValue: (receipt) => receipt
16125
+ }
16126
+ };
16127
+ function createTransactionReceipt(receipt) {
16128
+ const config3 = RECEIPT_CONFIG[receipt.execution_status];
16129
+ let obj;
16130
+ if (config3) {
16131
+ const { statusReceipt, getBaseData, getValue } = config3;
16132
+ const value = getValue(receipt);
16133
+ obj = {
16134
+ ...getBaseData(receipt),
16135
+ statusReceipt,
16136
+ value,
16137
+ match(callbacks) {
16138
+ return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
16139
+ },
16140
+ isSuccess() {
16141
+ return statusReceipt === "SUCCEEDED";
16142
+ },
16143
+ isReverted() {
16144
+ return statusReceipt === "REVERTED";
16145
+ },
16146
+ isError() {
16147
+ return false;
16148
+ }
16149
+ };
16150
+ } else {
16151
+ const errorValue = new Error("Unknown response type");
16152
+ obj = {
16153
+ statusReceipt: "ERROR",
16154
+ value: errorValue,
16155
+ match(callbacks) {
16156
+ return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
16157
+ },
16158
+ isSuccess() {
16159
+ return false;
16160
+ },
16161
+ isReverted() {
16162
+ return false;
16163
+ },
16164
+ isError() {
16165
+ return true;
16166
+ }
16167
+ };
16168
+ }
16169
+ Object.setPrototypeOf(obj, ReceiptTx.prototype);
16170
+ Object.defineProperty(obj, "constructor", {
16171
+ value: ReceiptTx,
16172
+ writable: false,
16173
+ enumerable: false,
16174
+ configurable: false
16175
+ });
16176
+ return obj;
16177
+ }
14498
16178
 
14499
16179
  // src/utils/typedData.ts
14500
16180
  var typedData_exports = {};
@@ -15163,7 +16843,7 @@ ${indent}}` : "}";
15163
16843
  async getTransactionReceipt(txHash) {
15164
16844
  const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
15165
16845
  const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
15166
- return new ReceiptTx(txReceiptWoHelperModified);
16846
+ return createTransactionReceipt(txReceiptWoHelperModified);
15167
16847
  }
15168
16848
  async getTransactionTrace(txHash) {
15169
16849
  return this.channel.getTransactionTrace(txHash);
@@ -15179,7 +16859,7 @@ ${indent}}` : "}";
15179
16859
  txHash,
15180
16860
  options
15181
16861
  );
15182
- return new ReceiptTx(receiptWoHelper);
16862
+ return createTransactionReceipt(receiptWoHelper);
15183
16863
  }
15184
16864
  async getStorageAt(contractAddress, key, blockIdentifier) {
15185
16865
  return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
@@ -16404,12 +18084,12 @@ ${indent}}` : "}";
16404
18084
  */
16405
18085
  async signRaw(msgHash) {
16406
18086
  addHexPrefix(
16407
- buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, Buffer.from(this.pathBuffer)))
18087
+ buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, buffer_default.from(this.pathBuffer)))
16408
18088
  );
16409
18089
  const shiftedHash = toHex(BigInt(msgHash) << 4n);
16410
18090
  const buff2 = hexToBytes2(shiftedHash);
16411
18091
  const respSign2 = Uint8Array.from(
16412
- await this._transporter.send(Number("0x5a"), 2, 1, 0, Buffer.from(buff2))
18092
+ await this._transporter.send(Number("0x5a"), 2, 1, 0, buffer_default.from(buff2))
16413
18093
  );
16414
18094
  const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
16415
18095
  const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
@@ -16422,7 +18102,7 @@ ${indent}}` : "}";
16422
18102
  async getPublicKeys() {
16423
18103
  const pathBuff = this.pathBuffer;
16424
18104
  const respGetPublic = Uint8Array.from(
16425
- await this._transporter.send(Number("0x5a"), 1, 0, 0, Buffer.from(pathBuff))
18105
+ await this._transporter.send(Number("0x5a"), 1, 0, 0, buffer_default.from(pathBuff))
16426
18106
  );
16427
18107
  this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
16428
18108
  this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
@@ -16677,7 +18357,7 @@ ${indent}}` : "}";
16677
18357
  txDetails.accountDeploymentData.length <= 7,
16678
18358
  "accountDeploymentData includes more than 7 items"
16679
18359
  );
16680
- await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
18360
+ await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
16681
18361
  const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
16682
18362
  const tipBuf = this.convertBnToLedger(txDetails.tip);
16683
18363
  const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
@@ -16699,30 +18379,30 @@ ${indent}}` : "}";
16699
18379
  nonceBuf,
16700
18380
  dAModeHashBuf
16701
18381
  ]);
16702
- await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
18382
+ await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
16703
18383
  const paymasterBuf = concatenateArrayBuffer(
16704
18384
  txDetails.paymasterData.map((value) => {
16705
18385
  const a = this.convertBnToLedger(value);
16706
18386
  return a;
16707
18387
  })
16708
18388
  );
16709
- await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(paymasterBuf));
18389
+ await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
16710
18390
  const accountDeployDataBuf = concatenateArrayBuffer(
16711
18391
  txDetails.paymasterData.map((value) => {
16712
18392
  const a = this.convertBnToLedger(value);
16713
18393
  return a;
16714
18394
  })
16715
18395
  );
16716
- await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(accountDeployDataBuf));
18396
+ await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
16717
18397
  const nbCallsBuf = this.convertBnToLedger(calls.length);
16718
- await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(nbCallsBuf));
18398
+ await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
16719
18399
  let respSign = new Uint8Array(0);
16720
18400
  for (const call of calls) {
16721
18401
  const calldatas = this.encodeCall(call);
16722
- await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(calldatas[0]));
18402
+ await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
16723
18403
  if (calldatas.length > 1) {
16724
18404
  calldatas.slice(1).forEach(async (part) => {
16725
- await this._transporter.send(Number("0x5a"), 3, 5, 1, Buffer.from(part));
18405
+ await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
16726
18406
  });
16727
18407
  }
16728
18408
  respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
@@ -16759,7 +18439,7 @@ ${indent}}` : "}";
16759
18439
  * ```
16760
18440
  */
16761
18441
  async signDeployAccountV3(deployAccountDetail) {
16762
- await this._transporter.send(Number("0x5a"), 5, 0, 0, Buffer.from(this.pathBuffer));
18442
+ await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
16763
18443
  const accountAddressBuf = this.convertBnToLedger(
16764
18444
  deployAccountDetail.contractAddress
16765
18445
  );
@@ -16781,7 +18461,7 @@ ${indent}}` : "}";
16781
18461
  classHashBuf,
16782
18462
  saltBuf
16783
18463
  ]);
16784
- await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
18464
+ await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
16785
18465
  const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
16786
18466
  const l1_gasBuf = this.convertBnToLedger(
16787
18467
  encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
@@ -16790,17 +18470,17 @@ ${indent}}` : "}";
16790
18470
  encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
16791
18471
  );
16792
18472
  const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
16793
- await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
18473
+ await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
16794
18474
  const paymasterBuf = concatenateArrayBuffer(
16795
18475
  deployAccountDetail.paymasterData.map((value) => {
16796
18476
  const a = this.convertBnToLedger(value);
16797
18477
  return a;
16798
18478
  })
16799
18479
  );
16800
- await this._transporter.send(Number("0x5a"), 5, 3, 0, Buffer.from(paymasterBuf));
18480
+ await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
16801
18481
  const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
16802
18482
  const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
16803
- await this._transporter.send(Number("0x5a"), 5, 4, 0, Buffer.from(constructorLengthBuf));
18483
+ await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
16804
18484
  const constructorBuf = concatenateArrayBuffer(
16805
18485
  compiledConstructor.map((parameter) => {
16806
18486
  const a = this.convertBnToLedger(parameter);
@@ -16813,7 +18493,7 @@ ${indent}}` : "}";
16813
18493
  constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
16814
18494
  let respSign = new Uint8Array(0);
16815
18495
  for (const chunk of constructorChunks) {
16816
- respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, Buffer.from(chunk));
18496
+ respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
16817
18497
  }
16818
18498
  return this.decodeSignatureLedger(respSign);
16819
18499
  }
@@ -16903,7 +18583,7 @@ ${indent}}` : "}";
16903
18583
  txDetails.accountDeploymentData.length <= 7,
16904
18584
  "accountDeploymentData includes more than 7 items"
16905
18585
  );
16906
- await this._transporter.send(Number("0x5a"), 3, 0, 0, Buffer.from(this.pathBuffer));
18586
+ await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
16907
18587
  const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
16908
18588
  const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
16909
18589
  const nonceBuf = this.convertBnToLedger(txDetails.nonce);
@@ -16919,7 +18599,7 @@ ${indent}}` : "}";
16919
18599
  nonceBuf,
16920
18600
  dAModeHashBuf
16921
18601
  ]);
16922
- await this._transporter.send(Number("0x5a"), 3, 1, 0, Buffer.from(dataBuf));
18602
+ await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
16923
18603
  if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
16924
18604
  const tipBuf = this.convertBnToLedger(txDetails.tip);
16925
18605
  const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
@@ -16933,7 +18613,7 @@ ${indent}}` : "}";
16933
18613
  l2_gasBuf,
16934
18614
  l1_data_gasBuf
16935
18615
  ]);
16936
- await this._transporter.send(Number("0x5a"), 3, 2, 0, Buffer.from(feeBuf));
18616
+ await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
16937
18617
  }
16938
18618
  const paymasterBuf = concatenateArrayBuffer(
16939
18619
  txDetails.paymasterData.map((value) => {
@@ -16941,23 +18621,23 @@ ${indent}}` : "}";
16941
18621
  return a;
16942
18622
  })
16943
18623
  );
16944
- await this._transporter.send(Number("0x5a"), 3, 3, 0, Buffer.from(paymasterBuf));
18624
+ await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(paymasterBuf));
16945
18625
  const accountDeployDataBuf = concatenateArrayBuffer(
16946
18626
  txDetails.paymasterData.map((value) => {
16947
18627
  const a = this.convertBnToLedger(value);
16948
18628
  return a;
16949
18629
  })
16950
18630
  );
16951
- await this._transporter.send(Number("0x5a"), 3, 4, 0, Buffer.from(accountDeployDataBuf));
18631
+ await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(accountDeployDataBuf));
16952
18632
  const nbCallsBuf = this.convertBnToLedger(calls.length);
16953
- await this._transporter.send(Number("0x5a"), 3, 5, 0, Buffer.from(nbCallsBuf));
18633
+ await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(nbCallsBuf));
16954
18634
  let respSign = new Uint8Array(0);
16955
18635
  for (const call of calls) {
16956
18636
  const calldatas = this.encodeCall(call);
16957
- respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, Buffer.from(calldatas[0]));
18637
+ respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, buffer_default.from(calldatas[0]));
16958
18638
  if (calldatas.length > 1) {
16959
18639
  calldatas.slice(1).forEach(async (part) => {
16960
- respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, Buffer.from(part));
18640
+ respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, buffer_default.from(part));
16961
18641
  });
16962
18642
  }
16963
18643
  }
@@ -16993,7 +18673,7 @@ ${indent}}` : "}";
16993
18673
  * ```
16994
18674
  */
16995
18675
  async signDeployAccountV3(deployAccountDetail) {
16996
- await this._transporter.send(Number("0x5a"), 5, 0, 0, Buffer.from(this.pathBuffer));
18676
+ await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
16997
18677
  const accountAddressBuf = this.convertBnToLedger(
16998
18678
  deployAccountDetail.contractAddress
16999
18679
  );
@@ -17015,7 +18695,7 @@ ${indent}}` : "}";
17015
18695
  classHashBuf,
17016
18696
  saltBuf
17017
18697
  ]);
17018
- await this._transporter.send(Number("0x5a"), 5, 1, 0, Buffer.from(dataBuf));
18698
+ await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
17019
18699
  if (isRPC08Plus_ResourceBoundsBN(deployAccountDetail.resourceBounds)) {
17020
18700
  const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
17021
18701
  const l1_gasBuf = this.convertBnToLedger(
@@ -17033,7 +18713,7 @@ ${indent}}` : "}";
17033
18713
  l2_gasBuf,
17034
18714
  l1_data_gasBuf
17035
18715
  ]);
17036
- await this._transporter.send(Number("0x5a"), 5, 2, 0, Buffer.from(feeBuf));
18716
+ await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
17037
18717
  }
17038
18718
  const paymasterBuf = concatenateArrayBuffer(
17039
18719
  deployAccountDetail.paymasterData.map((value) => {
@@ -17041,10 +18721,10 @@ ${indent}}` : "}";
17041
18721
  return a;
17042
18722
  })
17043
18723
  );
17044
- await this._transporter.send(Number("0x5a"), 5, 3, 0, Buffer.from(paymasterBuf));
18724
+ await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
17045
18725
  const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
17046
18726
  const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
17047
- await this._transporter.send(Number("0x5a"), 5, 4, 0, Buffer.from(constructorLengthBuf));
18727
+ await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
17048
18728
  const constructorBuf = concatenateArrayBuffer(
17049
18729
  compiledConstructor.map((parameter) => {
17050
18730
  const a = this.convertBnToLedger(parameter);
@@ -17057,7 +18737,7 @@ ${indent}}` : "}";
17057
18737
  constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
17058
18738
  let respSign = new Uint8Array(0);
17059
18739
  for (const chunk of constructorChunks) {
17060
- respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, Buffer.from(chunk));
18740
+ respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
17061
18741
  }
17062
18742
  return this.decodeSignatureLedger(respSign);
17063
18743
  }
@@ -18585,7 +20265,11 @@ ${indent}}` : "}";
18585
20265
  Object.keys(source).forEach((key) => {
18586
20266
  if (isObject2(source[key])) {
18587
20267
  if (!(key in target)) Object.assign(output, { [key]: source[key] });
18588
- else output[key] = mergeAbiEvents(target[key], source[key]);
20268
+ else
20269
+ output[key] = mergeAbiEvents(
20270
+ target[key],
20271
+ source[key]
20272
+ );
18589
20273
  } else {
18590
20274
  Object.assign(output, { [key]: source[key] });
18591
20275
  }
@@ -18593,7 +20277,7 @@ ${indent}}` : "}";
18593
20277
  }
18594
20278
  return output;
18595
20279
  }
18596
- function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
20280
+ function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums, parser) {
18597
20281
  const ret = providerReceivedEvents.flat().reduce((acc, recEvent) => {
18598
20282
  const currentEvent = JSON.parse(JSON.stringify(recEvent));
18599
20283
  let abiEvent = abiEvents[currentEvent.keys.shift() ?? 0];
@@ -18612,22 +20296,24 @@ ${indent}}` : "}";
18612
20296
  const abiEventKeys = abiEvent.members?.filter((it) => it.kind === "key") || abiEvent.keys;
18613
20297
  const abiEventData = abiEvent.members?.filter((it) => it.kind === "data") || abiEvent.data;
18614
20298
  abiEventKeys.forEach((key) => {
18615
- parsedEvent[abiEvent.name][key.name] = responseParser(
18616
- keysIter,
18617
- key,
18618
- abiStructs,
18619
- abiEnums,
18620
- parsedEvent[abiEvent.name]
18621
- );
20299
+ parsedEvent[abiEvent.name][key.name] = responseParser({
20300
+ responseIterator: keysIter,
20301
+ output: key,
20302
+ structs: abiStructs,
20303
+ enums: abiEnums,
20304
+ parser,
20305
+ parsedResult: parsedEvent[abiEvent.name]
20306
+ });
18622
20307
  });
18623
20308
  abiEventData.forEach((data) => {
18624
- parsedEvent[abiEvent.name][data.name] = responseParser(
18625
- dataIter,
18626
- data,
18627
- abiStructs,
18628
- abiEnums,
18629
- parsedEvent[abiEvent.name]
18630
- );
20309
+ parsedEvent[abiEvent.name][data.name] = responseParser({
20310
+ responseIterator: dataIter,
20311
+ output: data,
20312
+ structs: abiStructs,
20313
+ enums: abiEnums,
20314
+ parser,
20315
+ parsedResult: parsedEvent[abiEvent.name]
20316
+ });
18631
20317
  });
18632
20318
  if ("block_hash" in currentEvent) parsedEvent.block_hash = currentEvent.block_hash;
18633
20319
  if ("block_number" in currentEvent) parsedEvent.block_number = currentEvent.block_number;
@@ -18645,8 +20331,8 @@ ${indent}}` : "}";
18645
20331
  const options = { ...contract.withOptionsProps };
18646
20332
  contract.withOptionsProps = void 0;
18647
20333
  return contract.call(functionAbi.name, args, {
18648
- parseRequest: true,
18649
- parseResponse: true,
20334
+ parseRequest: contract.parseRequest,
20335
+ parseResponse: contract.parseResponse,
18650
20336
  ...options
18651
20337
  });
18652
20338
  };
@@ -18656,7 +20342,7 @@ ${indent}}` : "}";
18656
20342
  const options = { ...contract.withOptionsProps };
18657
20343
  contract.withOptionsProps = void 0;
18658
20344
  return contract.invoke(functionAbi.name, args, {
18659
- parseRequest: true,
20345
+ parseRequest: contract.parseRequest,
18660
20346
  ...options
18661
20347
  });
18662
20348
  };
@@ -18684,6 +20370,8 @@ ${indent}}` : "}";
18684
20370
  address;
18685
20371
  providerOrAccount;
18686
20372
  classHash;
20373
+ parseRequest;
20374
+ parseResponse;
18687
20375
  structs;
18688
20376
  events;
18689
20377
  functions;
@@ -18692,6 +20380,7 @@ ${indent}}` : "}";
18692
20380
  estimateFee;
18693
20381
  callData;
18694
20382
  withOptionsProps;
20383
+ parsingStrategy;
18695
20384
  /**
18696
20385
  * @param options
18697
20386
  * - abi: Abi of the contract object (required)
@@ -18699,14 +20388,18 @@ ${indent}}` : "}";
18699
20388
  * - providerOrAccount?: Provider or Account to attach to (fallback to defaultProvider)
18700
20389
  * - parseRequest?: compile and validate arguments (optional, default true)
18701
20390
  * - parseResponse?: Parse elements of the response array and structuring them into response object (optional, default true)
20391
+ * - parser?: Abi parser (optional, default createAbiParser(options.abi))
18702
20392
  */
18703
20393
  constructor(options) {
18704
- const parser = createAbiParser(options.abi);
18705
- this.address = options.address && options.address.toLowerCase();
20394
+ this.parsingStrategy = options.parsingStrategy;
20395
+ const parser = createAbiParser(options.abi, options.parsingStrategy);
18706
20396
  this.abi = parser.getLegacyFormat();
20397
+ this.address = options.address && options.address.toLowerCase();
18707
20398
  this.providerOrAccount = options.providerOrAccount ?? defaultProvider;
20399
+ this.parseRequest = options.parseRequest ?? true;
20400
+ this.parseResponse = options.parseResponse ?? true;
18708
20401
  this.classHash = options.classHash;
18709
- this.callData = new CallData(options.abi);
20402
+ this.callData = new CallData(options.abi, options.parsingStrategy);
18710
20403
  this.structs = CallData.getAbiStruct(options.abi);
18711
20404
  this.events = getAbiEvents(options.abi);
18712
20405
  const methodTypes = { enumerable: true, value: {}, writable: false };
@@ -18758,8 +20451,9 @@ ${indent}}` : "}";
18758
20451
  attach(address, abi) {
18759
20452
  this.address = address;
18760
20453
  if (abi) {
18761
- this.abi = createAbiParser(abi).getLegacyFormat();
18762
- this.callData = new CallData(abi);
20454
+ const parser = createAbiParser(abi, this.parsingStrategy);
20455
+ this.abi = parser.getLegacyFormat();
20456
+ this.callData = new CallData(abi, this.parsingStrategy);
18763
20457
  this.structs = CallData.getAbiStruct(abi);
18764
20458
  this.events = getAbiEvents(abi);
18765
20459
  }
@@ -18805,7 +20499,8 @@ ${indent}}` : "}";
18805
20499
  return this.callData.parse(method, it);
18806
20500
  });
18807
20501
  }
18808
- invoke(method, args = [], { parseRequest = true, signature, ...RestInvokeOptions } = {}) {
20502
+ async invoke(method, args = [], options = {}) {
20503
+ const { parseRequest = true, signature, waitForTransaction, ...RestInvokeOptions } = options;
18809
20504
  assert(this.address !== null, "contract is not connected to an address");
18810
20505
  const calldata = getCompiledCalldata(args, () => {
18811
20506
  if (parseRequest) {
@@ -18821,9 +20516,17 @@ ${indent}}` : "}";
18821
20516
  entrypoint: method
18822
20517
  };
18823
20518
  if (isAccount(this.providerOrAccount)) {
18824
- return this.providerOrAccount.execute(invocation, {
20519
+ const result = await this.providerOrAccount.execute(invocation, {
18825
20520
  ...RestInvokeOptions
18826
20521
  });
20522
+ if (waitForTransaction) {
20523
+ const result2 = await this.providerOrAccount.waitForTransaction(result.transaction_hash);
20524
+ if (result2.isSuccess()) {
20525
+ return result2;
20526
+ }
20527
+ throw new Error("Transaction failed", { cause: result2 });
20528
+ }
20529
+ return result;
18827
20530
  }
18828
20531
  if (!RestInvokeOptions.nonce)
18829
20532
  throw new Error(`Manual nonce is required when invoking a function without an account`);
@@ -18861,9 +20564,9 @@ ${indent}}` : "}";
18861
20564
  // TODO: Demistify what is going on here ???
18862
20565
  // TODO: receipt status filtering test and fix this do not look right
18863
20566
  parseEvents(receipt) {
18864
- let parsed;
20567
+ let parsed = [];
18865
20568
  receipt.match({
18866
- success: (txR) => {
20569
+ SUCCEEDED: (txR) => {
18867
20570
  const emittedEvents = txR.events?.map((event) => {
18868
20571
  return {
18869
20572
  // TODO: this do not check that block is production and block_hash and block_number actually exists
@@ -18876,16 +20579,26 @@ ${indent}}` : "}";
18876
20579
  }).filter((event) => cleanHex(event.from_address) === cleanHex(this.address), []) || [];
18877
20580
  parsed = parseEvents(
18878
20581
  emittedEvents,
18879
- // TODO: any temp hotfix, fix this
18880
20582
  this.events,
18881
20583
  this.structs,
18882
- CallData.getAbiEnum(this.abi)
20584
+ CallData.getAbiEnum(this.abi),
20585
+ this.callData.parser
18883
20586
  );
18884
20587
  },
18885
20588
  _: () => {
18886
20589
  throw Error("This transaction was not successful.");
18887
20590
  }
18888
20591
  });
20592
+ Object.defineProperty(parsed, "getByPath", {
20593
+ value: (path) => {
20594
+ const event = parsed.find((ev) => Object.keys(ev).some((key) => key.includes(path)));
20595
+ const eventKey = Object.keys(event || {}).find((key) => key.includes(path));
20596
+ return eventKey && event ? event[eventKey] : null;
20597
+ },
20598
+ writable: false,
20599
+ enumerable: false,
20600
+ configurable: false
20601
+ });
18889
20602
  return parsed;
18890
20603
  }
18891
20604
  isCairo1() {
@@ -19002,7 +20715,10 @@ ${indent}}` : "}";
19002
20715
  abi,
19003
20716
  address: contract_address,
19004
20717
  providerOrAccount: account,
19005
- classHash
20718
+ classHash,
20719
+ parseRequest: params.parseRequest,
20720
+ parseResponse: params.parseResponse,
20721
+ parsingStrategy: params.parsingStrategy
19006
20722
  });
19007
20723
  }
19008
20724
  };