starknet 6.10.2 → 7.0.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.
package/dist/index.mjs CHANGED
@@ -527,8 +527,7 @@ function toCairoBool(value) {
527
527
  return (+value).toString();
528
528
  }
529
529
  function hexToBytes(str) {
530
- if (!isHex(str))
531
- throw new Error(`${str} needs to be a hex-string`);
530
+ if (!isHex(str)) throw new Error(`${str} needs to be a hex-string`);
532
531
  let adaptedValue = removeHexPrefix(str);
533
532
  if (adaptedValue.length % 2 !== 0) {
534
533
  adaptedValue = `0${adaptedValue}`;
@@ -616,15 +615,12 @@ function splitLongString(longStr) {
616
615
  return longStr.match(regex) || [];
617
616
  }
618
617
  function encodeShortString(str) {
619
- if (!isASCII(str))
620
- throw new Error(`${str} is not an ASCII string`);
621
- if (!isShortString(str))
622
- throw new Error(`${str} is too long`);
618
+ if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
619
+ if (!isShortString(str)) throw new Error(`${str} is too long`);
623
620
  return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
624
621
  }
625
622
  function decodeShortString(str) {
626
- if (!isASCII(str))
627
- throw new Error(`${str} is not an ASCII string`);
623
+ if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
628
624
  if (isHex(str)) {
629
625
  return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
630
626
  }
@@ -752,10 +748,8 @@ var CairoUint256 = class _CairoUint256 {
752
748
  */
753
749
  static validate(bigNumberish) {
754
750
  const bigInt = BigInt(bigNumberish);
755
- if (bigInt < UINT_256_MIN)
756
- throw Error("bigNumberish is smaller than UINT_256_MIN");
757
- if (bigInt > UINT_256_MAX)
758
- throw new Error("bigNumberish is bigger than UINT_256_MAX");
751
+ if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
752
+ if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
759
753
  return bigInt;
760
754
  }
761
755
  /**
@@ -866,10 +860,8 @@ var CairoUint512 = class _CairoUint512 {
866
860
  */
867
861
  static validate(bigNumberish) {
868
862
  const bigInt = BigInt(bigNumberish);
869
- if (bigInt < UINT_512_MIN)
870
- throw Error("bigNumberish is smaller than UINT_512_MIN.");
871
- if (bigInt > UINT_512_MAX)
872
- throw Error("bigNumberish is bigger than UINT_512_MAX.");
863
+ if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
864
+ if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
873
865
  return bigInt;
874
866
  }
875
867
  /**
@@ -1306,10 +1298,8 @@ function createAbiParser(abi) {
1306
1298
  throw Error(`Unsupported ABI version ${version}`);
1307
1299
  }
1308
1300
  function getAbiVersion(abi) {
1309
- if (abi.find((it) => it.type === "interface"))
1310
- return 2;
1311
- if (isCairo1Abi(abi))
1312
- return 1;
1301
+ if (abi.find((it) => it.type === "interface")) return 2;
1302
+ if (isCairo1Abi(abi)) return 1;
1313
1303
  return 0;
1314
1304
  }
1315
1305
  function isNoConstructorValid(method, argsCalldata, abiMethod) {
@@ -1323,8 +1313,7 @@ function parseNamedTuple(namedTuple) {
1323
1313
  return { name, type };
1324
1314
  }
1325
1315
  function parseSubTuple(s) {
1326
- if (!s.includes("("))
1327
- return { subTuple: [], result: s };
1316
+ if (!s.includes("(")) return { subTuple: [], result: s };
1328
1317
  const subTuple = [];
1329
1318
  let result = "";
1330
1319
  let i = 0;
@@ -1334,10 +1323,8 @@ function parseSubTuple(s) {
1334
1323
  const lBracket = i;
1335
1324
  i++;
1336
1325
  while (counter) {
1337
- if (s[i] === ")")
1338
- counter--;
1339
- if (s[i] === "(")
1340
- counter++;
1326
+ if (s[i] === ")") counter--;
1327
+ if (s[i] === "(") counter++;
1341
1328
  i++;
1342
1329
  }
1343
1330
  subTuple.push(s.substring(lBracket, i));
@@ -1644,8 +1631,7 @@ function parseCalldataValue(element, type, structs, enums) {
1644
1631
  }
1645
1632
  if (type === "core::starknet::eth_address::EthAddress")
1646
1633
  return parseBaseTypes(type, element);
1647
- if (type === "core::byte_array::ByteArray")
1648
- return parseByteArray(element);
1634
+ if (type === "core::byte_array::ByteArray") return parseByteArray(element);
1649
1635
  const { members } = structs[type];
1650
1636
  const subElement = element;
1651
1637
  return members.reduce((acc, it) => {
@@ -1965,8 +1951,7 @@ var validateFelt = (parameter, input) => {
1965
1951
  isString(parameter) || isNumber(parameter) || isBigInt(parameter),
1966
1952
  `Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
1967
1953
  );
1968
- if (isString(parameter) && !isHex(parameter))
1969
- return;
1954
+ if (isString(parameter) && !isHex(parameter)) return;
1970
1955
  const param = BigInt(parameter.toString(10));
1971
1956
  assert(
1972
1957
  // from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1266
@@ -2272,8 +2257,7 @@ var CallData = class _CallData {
2272
2257
  validate(type, method, args = []) {
2273
2258
  if (type !== "DEPLOY" /* DEPLOY */) {
2274
2259
  const invocableFunctionNames = this.abi.filter((abi) => {
2275
- if (abi.type !== "function")
2276
- return false;
2260
+ if (abi.type !== "function") return false;
2277
2261
  const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
2278
2262
  return type === "INVOKE" /* INVOKE */ ? !isView : isView;
2279
2263
  }).map((abi) => abi.name);
@@ -2351,13 +2335,10 @@ var CallData = class _CallData {
2351
2335
  const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
2352
2336
  return Object.entries(oe).flatMap(([k, v]) => {
2353
2337
  let value = v;
2354
- if (k === "entrypoint")
2355
- value = getSelectorFromName(value);
2356
- else if (isLongText(value))
2357
- value = byteArrayFromString(value);
2338
+ if (k === "entrypoint") value = getSelectorFromName(value);
2339
+ else if (isLongText(value)) value = byteArrayFromString(value);
2358
2340
  const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
2359
- if (isBigInt(value))
2360
- return [[`${prefix}${kk}`, felt(value)]];
2341
+ if (isBigInt(value)) return [[`${prefix}${kk}`, felt(value)]];
2361
2342
  if (Object(value) === value) {
2362
2343
  const methodsKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(value));
2363
2344
  const keys = [...Object.getOwnPropertyNames(value), ...methodsKeys];
@@ -2805,8 +2786,7 @@ __export(json_exports, {
2805
2786
  });
2806
2787
  import * as json from "lossless-json";
2807
2788
  var parseIntAsNumberOrBigInt = (str) => {
2808
- if (!json.isInteger(str))
2809
- return parseFloat(str);
2789
+ if (!json.isInteger(str)) return parseFloat(str);
2810
2790
  const num = parseInt(str, 10);
2811
2791
  return Number.isSafeInteger(num) ? num : BigInt(str);
2812
2792
  };
@@ -3002,8 +2982,7 @@ function compressProgram(jsonProgram) {
3002
2982
  return btoaUniversal(compressedProgram);
3003
2983
  }
3004
2984
  function decompressProgram(base642) {
3005
- if (Array.isArray(base642))
3006
- return base642;
2985
+ if (Array.isArray(base642)) return base642;
3007
2986
  const decompressed = arrayBufferToString(ungzip(atobUniversal(base642)));
3008
2987
  return parse2(decompressed);
3009
2988
  }
@@ -3015,8 +2994,7 @@ function makeAddress(input) {
3015
2994
  return addHexPrefix(input).toLowerCase();
3016
2995
  }
3017
2996
  function formatSignature(sig) {
3018
- if (!sig)
3019
- throw Error("formatSignature: provided signature is undefined");
2997
+ if (!sig) throw Error("formatSignature: provided signature is undefined");
3020
2998
  if (Array.isArray(sig)) {
3021
2999
  return sig.map((it) => toHex(it));
3022
3000
  }
@@ -3054,10 +3032,8 @@ function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUN
3054
3032
  };
3055
3033
  }
3056
3034
  function intDAM(dam) {
3057
- if (dam === api_exports.EDataAvailabilityMode.L1)
3058
- return api_exports.EDAMode.L1;
3059
- if (dam === api_exports.EDataAvailabilityMode.L2)
3060
- return api_exports.EDAMode.L2;
3035
+ if (dam === api_exports.EDataAvailabilityMode.L1) return api_exports.EDAMode.L1;
3036
+ if (dam === api_exports.EDataAvailabilityMode.L2) return api_exports.EDAMode.L2;
3061
3037
  throw Error("EDAM conversion");
3062
3038
  }
3063
3039
  function toTransactionVersion(defaultVersion, providedVersion) {
@@ -3072,17 +3048,12 @@ function toTransactionVersion(defaultVersion, providedVersion) {
3072
3048
  return providedVersion ? providedVersion0xs : defaultVersion0xs;
3073
3049
  }
3074
3050
  function toFeeVersion(providedVersion) {
3075
- if (!providedVersion)
3076
- return void 0;
3051
+ if (!providedVersion) return void 0;
3077
3052
  const version = toHex(providedVersion);
3078
- if (version === api_exports.ETransactionVersion.V0)
3079
- return api_exports.ETransactionVersion.F0;
3080
- if (version === api_exports.ETransactionVersion.V1)
3081
- return api_exports.ETransactionVersion.F1;
3082
- if (version === api_exports.ETransactionVersion.V2)
3083
- return api_exports.ETransactionVersion.F2;
3084
- if (version === api_exports.ETransactionVersion.V3)
3085
- return api_exports.ETransactionVersion.F3;
3053
+ if (version === api_exports.ETransactionVersion.V0) return api_exports.ETransactionVersion.F0;
3054
+ if (version === api_exports.ETransactionVersion.V1) return api_exports.ETransactionVersion.F1;
3055
+ if (version === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.F2;
3056
+ if (version === api_exports.ETransactionVersion.V3) return api_exports.ETransactionVersion.F3;
3086
3057
  throw Error(`toFeeVersion: ${version} is not supported`);
3087
3058
  }
3088
3059
  function v3Details(details) {
@@ -3096,10 +3067,8 @@ function v3Details(details) {
3096
3067
  };
3097
3068
  }
3098
3069
  function reduceV2(providedVersion) {
3099
- if (providedVersion === api_exports.ETransactionVersion.F2)
3100
- return api_exports.ETransactionVersion.F1;
3101
- if (providedVersion === api_exports.ETransactionVersion.V2)
3102
- return api_exports.ETransactionVersion.V1;
3070
+ if (providedVersion === api_exports.ETransactionVersion.F2) return api_exports.ETransactionVersion.F1;
3071
+ if (providedVersion === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.V1;
3103
3072
  return providedVersion;
3104
3073
  }
3105
3074
 
@@ -3589,10 +3558,8 @@ var RpcChannel = class {
3589
3558
  } = simulateTransactionOptions;
3590
3559
  const block_id = new Block(blockIdentifier).identifier;
3591
3560
  const simulationFlags = [];
3592
- if (skipValidate)
3593
- simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
3594
- if (skipFeeCharge)
3595
- simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3561
+ if (skipValidate) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
3562
+ if (skipFeeCharge) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3596
3563
  return this.fetchEndpoint("starknet_simulateTransactions", {
3597
3564
  block_id,
3598
3565
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -4141,10 +4108,8 @@ var RpcChannel2 = class {
4141
4108
  } = simulateTransactionOptions;
4142
4109
  const block_id = new Block(blockIdentifier).identifier;
4143
4110
  const simulationFlags = [];
4144
- if (skipValidate)
4145
- simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_VALIDATE);
4146
- if (skipFeeCharge)
4147
- simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
4111
+ if (skipValidate) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_VALIDATE);
4112
+ if (skipFeeCharge) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
4148
4113
  return this.fetchEndpoint("starknet_simulateTransactions", {
4149
4114
  block_id,
4150
4115
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -4689,12 +4654,10 @@ var RpcProvider = class {
4689
4654
  * ```
4690
4655
  */
4691
4656
  async waitForBlock(blockIdentifier = "pending", retryInterval = 5e3) {
4692
- if (blockIdentifier === "latest" /* LATEST */)
4693
- return;
4657
+ if (blockIdentifier === "latest" /* LATEST */) return;
4694
4658
  const currentBlock = await this.getBlockNumber();
4695
4659
  const targetBlock = blockIdentifier === "pending" /* PENDING */ ? currentBlock + 1 : Number(toHex(blockIdentifier));
4696
- if (targetBlock <= currentBlock)
4697
- return;
4660
+ if (targetBlock <= currentBlock) return;
4698
4661
  const { retries } = this.channel;
4699
4662
  let retriesCount = retries;
4700
4663
  let isTargetBlock = false;
@@ -4968,17 +4931,14 @@ function useDecoded(encoded) {
4968
4931
  if (nextSubdomain === ZERO) {
4969
4932
  const code2 = subdomain % bigAlphabetSizePlusOne;
4970
4933
  subdomain = nextSubdomain;
4971
- if (code2 === ZERO)
4972
- decoded += basicAlphabet[0];
4973
- else
4974
- decoded += bigAlphabet[Number(code2) - 1];
4934
+ if (code2 === ZERO) decoded += basicAlphabet[0];
4935
+ else decoded += bigAlphabet[Number(code2) - 1];
4975
4936
  } else {
4976
4937
  const code2 = subdomain % bigAlphabetSize;
4977
4938
  decoded += bigAlphabet[Number(code2)];
4978
4939
  subdomain /= bigAlphabetSize;
4979
4940
  }
4980
- } else
4981
- decoded += basicAlphabet[Number(code)];
4941
+ } else decoded += basicAlphabet[Number(code)];
4982
4942
  }
4983
4943
  const [str, k] = extractStars(decoded);
4984
4944
  if (k)
@@ -4998,8 +4958,7 @@ function useEncoded(decoded) {
4998
4958
  decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
4999
4959
  } else {
5000
4960
  const [str, k] = extractStars(decoded);
5001
- if (k)
5002
- decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
4961
+ if (k) decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
5003
4962
  }
5004
4963
  for (let i = 0; i < decoded.length; i += 1) {
5005
4964
  const char = decoded[i];
@@ -5654,8 +5613,7 @@ function encodeValue(types, type, data, ctx = {}, revision = TypedDataRevision.L
5654
5613
  const variantType = enumType.find((t) => t.name === variantKey);
5655
5614
  const variantIndex = enumType.indexOf(variantType);
5656
5615
  const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
5657
- if (!subtype)
5658
- return subtype;
5616
+ if (!subtype) return subtype;
5659
5617
  const subtypeData = variantData[index];
5660
5618
  return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
5661
5619
  });
@@ -6046,19 +6004,16 @@ function getCairo1AbiEvents(abi) {
6046
6004
  const findName = (variant) => variant.type === name;
6047
6005
  while (true) {
6048
6006
  const eventEnum = abiEventsEnums.find((eventE) => eventE.variants.some(findName));
6049
- if (typeof eventEnum === "undefined")
6050
- break;
6007
+ if (typeof eventEnum === "undefined") break;
6051
6008
  const variant = eventEnum.variants.find(findName);
6052
6009
  nameList.unshift(variant.name);
6053
- if (variant.kind === "flat")
6054
- flat = true;
6010
+ if (variant.kind === "flat") flat = true;
6055
6011
  name = eventEnum.name;
6056
6012
  }
6057
6013
  if (nameList.length === 0) {
6058
6014
  throw new Error("inconsistency in ABI events definition.");
6059
6015
  }
6060
- if (flat)
6061
- nameList = [nameList[nameList.length - 1]];
6016
+ if (flat) nameList = [nameList[nameList.length - 1]];
6062
6017
  const final = nameList.pop();
6063
6018
  let result = {
6064
6019
  [addHexPrefix(starkCurve.keccak(utf8ToArray(final)).toString(16))]: event
@@ -6084,10 +6039,8 @@ function mergeAbiEvents(target, source) {
6084
6039
  if (isObject(target) && isObject(source)) {
6085
6040
  Object.keys(source).forEach((key) => {
6086
6041
  if (isObject(source[key])) {
6087
- if (!(key in target))
6088
- Object.assign(output, { [key]: source[key] });
6089
- else
6090
- output[key] = mergeAbiEvents(target[key], source[key]);
6042
+ if (!(key in target)) Object.assign(output, { [key]: source[key] });
6043
+ else output[key] = mergeAbiEvents(target[key], source[key]);
6091
6044
  } else {
6092
6045
  Object.assign(output, { [key]: source[key] });
6093
6046
  }
@@ -6174,10 +6127,8 @@ var Account = class extends RpcProvider2 {
6174
6127
  }
6175
6128
  // provided version or contract based preferred transactionVersion
6176
6129
  getPreferredVersion(type12, type3) {
6177
- if (this.transactionVersion === api_exports.ETransactionVersion.V3)
6178
- return type3;
6179
- if (this.transactionVersion === api_exports.ETransactionVersion.V2)
6180
- return type12;
6130
+ if (this.transactionVersion === api_exports.ETransactionVersion.V3) return type3;
6131
+ if (this.transactionVersion === api_exports.ETransactionVersion.V2) return type12;
6181
6132
  return api_exports.ETransactionVersion.V3;
6182
6133
  }
6183
6134
  async getNonce(blockIdentifier) {
@@ -6883,13 +6834,11 @@ var WalletAccount = class extends Account {
6883
6834
  super(providerOrOptions, "", "", cairoVersion);
6884
6835
  this.walletProvider = walletProvider;
6885
6836
  this.walletProvider.on("accountsChanged", (res) => {
6886
- if (!res)
6887
- return;
6837
+ if (!res) return;
6888
6838
  this.address = res[0].toLowerCase();
6889
6839
  });
6890
6840
  this.walletProvider.on("networkChanged", (res) => {
6891
- if (!res)
6892
- return;
6841
+ if (!res) return;
6893
6842
  this.channel.setChainId(res);
6894
6843
  });
6895
6844
  walletProvider.request({
@@ -7029,8 +6978,7 @@ function buildEstimate(contract, functionAbi) {
7029
6978
  };
7030
6979
  }
7031
6980
  function getCalldata(args, callback) {
7032
- if (Array.isArray(args) && "__compiled__" in args)
7033
- return args;
6981
+ if (Array.isArray(args) && "__compiled__" in args) return args;
7034
6982
  if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
7035
6983
  return args[0];
7036
6984
  return callback();
@@ -7070,8 +7018,7 @@ var Contract = class {
7070
7018
  estimateFee: { enumerable: true, value: {}, writable: false }
7071
7019
  });
7072
7020
  this.abi.forEach((abiElement) => {
7073
- if (abiElement.type !== "function")
7074
- return;
7021
+ if (abiElement.type !== "function") return;
7075
7022
  const signature = abiElement.name;
7076
7023
  if (!this[signature]) {
7077
7024
  Object.defineProperty(this, signature, {
@@ -7171,8 +7118,7 @@ var Contract = class {
7171
7118
  nonce
7172
7119
  });
7173
7120
  }
7174
- if (!nonce)
7175
- throw new Error(`Nonce is required when invoking a function without an account`);
7121
+ if (!nonce) throw new Error(`Nonce is required when invoking a function without an account`);
7176
7122
  console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
7177
7123
  return this.providerOrAccount.invokeFunction(
7178
7124
  {