starknet 6.6.0 → 6.7.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
@@ -14,6 +14,10 @@ __export(constants_exports, {
14
14
  MASK_250: () => MASK_250,
15
15
  MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
16
16
  NetworkName: () => NetworkName,
17
+ PRIME: () => PRIME,
18
+ RANGE_FELT: () => RANGE_FELT,
19
+ RANGE_I128: () => RANGE_I128,
20
+ RANGE_U128: () => RANGE_U128,
17
21
  RPC_DEFAULT_VERSION: () => RPC_DEFAULT_VERSION,
18
22
  RPC_NODES: () => RPC_NODES,
19
23
  StarknetChainId: () => StarknetChainId,
@@ -321,8 +325,13 @@ var TEXT_TO_FELT_MAX_LEN = 31;
321
325
  var ZERO = 0n;
322
326
  var MASK_250 = 2n ** 250n - 1n;
323
327
  var API_VERSION = ZERO;
328
+ var PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
324
329
  var MAX_STORAGE_ITEM_SIZE = 256n;
325
330
  var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
331
+ var range = (min, max) => ({ min, max });
332
+ var RANGE_FELT = range(ZERO, PRIME - 1n);
333
+ var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
334
+ var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
326
335
  var BaseUrl = /* @__PURE__ */ ((BaseUrl2) => {
327
336
  BaseUrl2["SN_MAIN"] = "https://alpha-mainnet.starknet.io";
328
337
  BaseUrl2["SN_GOERLI"] = "https://alpha4.starknet.io";
@@ -457,11 +466,13 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
457
466
  Uint2["u64"] = "core::integer::u64";
458
467
  Uint2["u128"] = "core::integer::u128";
459
468
  Uint2["u256"] = "core::integer::u256";
469
+ Uint2["u512"] = "core::integer::u512";
460
470
  return Uint2;
461
471
  })(Uint || {});
462
472
  var Literal = /* @__PURE__ */ ((Literal2) => {
463
473
  Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
464
474
  Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
475
+ Literal2["Secp256k1Point"] = "core::starknet::secp256k1::Secp256k1Point";
465
476
  return Literal2;
466
477
  })(Literal || {});
467
478
 
@@ -517,11 +528,9 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
517
528
  })(BlockTag || {});
518
529
 
519
530
  // src/types/typedData.ts
520
- var TypedDataRevision = /* @__PURE__ */ ((TypedDataRevision2) => {
521
- TypedDataRevision2["Active"] = "1";
522
- TypedDataRevision2["Legacy"] = "0";
523
- return TypedDataRevision2;
524
- })(TypedDataRevision || {});
531
+ import {
532
+ TypedDataRevision
533
+ } from "starknet-types";
525
534
 
526
535
  // src/utils/assert.ts
527
536
  function assert(condition, message) {
@@ -544,7 +553,9 @@ __export(num_exports, {
544
553
  hexToBytes: () => hexToBytes,
545
554
  hexToDecimalString: () => hexToDecimalString,
546
555
  isBigInt: () => isBigInt,
556
+ isBoolean: () => isBoolean,
547
557
  isHex: () => isHex,
558
+ isNumber: () => isNumber,
548
559
  isStringWholeNumber: () => isStringWholeNumber,
549
560
  toBigInt: () => toBigInt,
550
561
  toCairoBool: () => toCairoBool,
@@ -626,6 +637,12 @@ function addPercent(number2, percent) {
626
637
  const bigIntNum = BigInt(number2);
627
638
  return bigIntNum + bigIntNum * BigInt(percent) / 100n;
628
639
  }
640
+ function isNumber(value) {
641
+ return typeof value === "number";
642
+ }
643
+ function isBoolean(value) {
644
+ return typeof value === "boolean";
645
+ }
629
646
 
630
647
  // src/utils/selector.ts
631
648
  var selector_exports = {};
@@ -671,6 +688,7 @@ __export(shortString_exports, {
671
688
  isLongText: () => isLongText,
672
689
  isShortString: () => isShortString,
673
690
  isShortText: () => isShortText,
691
+ isString: () => isString,
674
692
  isText: () => isText,
675
693
  splitLongString: () => splitLongString
676
694
  });
@@ -683,8 +701,11 @@ function isShortString(str) {
683
701
  function isDecimalString(str) {
684
702
  return /^[0-9]*$/i.test(str);
685
703
  }
704
+ function isString(value) {
705
+ return typeof value === "string";
706
+ }
686
707
  function isText(val) {
687
- return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
708
+ return isString(val) && !isHex(val) && !isStringWholeNumber(val);
688
709
  }
689
710
  var isShortText = (val) => isText(val) && isShortString(val);
690
711
  var isLongText = (val) => isText(val) && !isShortString(val);
@@ -757,34 +778,38 @@ __export(cairo_exports, {
757
778
  isTypeNamedTuple: () => isTypeNamedTuple,
758
779
  isTypeOption: () => isTypeOption,
759
780
  isTypeResult: () => isTypeResult,
781
+ isTypeSecp256k1Point: () => isTypeSecp256k1Point,
760
782
  isTypeStruct: () => isTypeStruct,
761
783
  isTypeTuple: () => isTypeTuple,
762
784
  isTypeUint: () => isTypeUint,
763
785
  isTypeUint256: () => isTypeUint256,
764
786
  tuple: () => tuple,
765
- uint256: () => uint256
787
+ uint256: () => uint256,
788
+ uint512: () => uint512
766
789
  });
767
790
 
768
791
  // src/utils/cairoDataTypes/felt.ts
769
792
  function CairoFelt(it) {
770
- if (isBigInt(it) || typeof it === "number" && Number.isInteger(it)) {
793
+ if (isBigInt(it) || Number.isInteger(it)) {
771
794
  return it.toString();
772
795
  }
773
- if (isText(it)) {
774
- if (!isShortString(it))
775
- throw new Error(
776
- `${it} is a long string > 31 chars, felt can store short strings, split it to array of short strings`
777
- );
778
- const encoded = encodeShortString(it);
779
- return BigInt(encoded).toString();
780
- }
781
- if (typeof it === "string" && isHex(it)) {
782
- return BigInt(it).toString();
783
- }
784
- if (typeof it === "string" && isStringWholeNumber(it)) {
785
- return it;
796
+ if (isString(it)) {
797
+ if (isHex(it)) {
798
+ return BigInt(it).toString();
799
+ }
800
+ if (isText(it)) {
801
+ if (!isShortString(it)) {
802
+ throw new Error(
803
+ `${it} is a long string > 31 chars. Please split it into an array of short strings.`
804
+ );
805
+ }
806
+ return BigInt(encodeShortString(it)).toString();
807
+ }
808
+ if (isStringWholeNumber(it)) {
809
+ return it;
810
+ }
786
811
  }
787
- if (typeof it === "boolean") {
812
+ if (isBoolean(it)) {
788
813
  return `${+it}`;
789
814
  }
790
815
  throw new Error(`${it} can't be computed by felt()`);
@@ -895,6 +920,130 @@ var CairoUint256 = class _CairoUint256 {
895
920
  }
896
921
  };
897
922
 
923
+ // src/utils/cairoDataTypes/uint512.ts
924
+ var UINT_512_MAX = (1n << 512n) - 1n;
925
+ var UINT_512_MIN = 0n;
926
+ var UINT_128_MIN = 0n;
927
+ var CairoUint512 = class _CairoUint512 {
928
+ limb0;
929
+ limb1;
930
+ limb2;
931
+ limb3;
932
+ static abiSelector = "core::integer::u512";
933
+ constructor(...arr) {
934
+ if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
935
+ const props = _CairoUint512.validateProps(
936
+ arr[0].limb0,
937
+ arr[0].limb1,
938
+ arr[0].limb2,
939
+ arr[0].limb3
940
+ );
941
+ this.limb0 = props.limb0;
942
+ this.limb1 = props.limb1;
943
+ this.limb2 = props.limb2;
944
+ this.limb3 = props.limb3;
945
+ } else if (arr.length === 1) {
946
+ const bigInt = _CairoUint512.validate(arr[0]);
947
+ this.limb0 = bigInt & UINT_128_MAX;
948
+ this.limb1 = (bigInt & UINT_128_MAX << 128n) >> 128n;
949
+ this.limb2 = (bigInt & UINT_128_MAX << 256n) >> 256n;
950
+ this.limb3 = bigInt >> 384n;
951
+ } else if (arr.length === 4) {
952
+ const props = _CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
953
+ this.limb0 = props.limb0;
954
+ this.limb1 = props.limb1;
955
+ this.limb2 = props.limb2;
956
+ this.limb3 = props.limb3;
957
+ } else {
958
+ throw Error("Incorrect Uint512 constructor parameters");
959
+ }
960
+ }
961
+ /**
962
+ * Validate if BigNumberish can be represented as Uint512
963
+ */
964
+ static validate(bigNumberish) {
965
+ const bigInt = BigInt(bigNumberish);
966
+ if (bigInt < UINT_512_MIN)
967
+ throw Error("bigNumberish is smaller than UINT_512_MIN.");
968
+ if (bigInt > UINT_512_MAX)
969
+ throw Error("bigNumberish is bigger than UINT_512_MAX.");
970
+ return bigInt;
971
+ }
972
+ /**
973
+ * Validate if limbs can be represented as Uint512
974
+ */
975
+ static validateProps(limb0, limb1, limb2, limb3) {
976
+ const l0 = BigInt(limb0);
977
+ const l1 = BigInt(limb1);
978
+ const l2 = BigInt(limb2);
979
+ const l3 = BigInt(limb3);
980
+ [l0, l1, l2, l3].forEach((value, index) => {
981
+ if (value < UINT_128_MIN || value > UINT_128_MAX) {
982
+ throw Error(`limb${index} is not in the range of a u128 number`);
983
+ }
984
+ });
985
+ return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
986
+ }
987
+ /**
988
+ * Check if BigNumberish can be represented as Uint512
989
+ */
990
+ static is(bigNumberish) {
991
+ try {
992
+ _CairoUint512.validate(bigNumberish);
993
+ } catch (error) {
994
+ return false;
995
+ }
996
+ return true;
997
+ }
998
+ /**
999
+ * Check if provided abi type is this data type
1000
+ */
1001
+ static isAbiType(abiType) {
1002
+ return abiType === _CairoUint512.abiSelector;
1003
+ }
1004
+ /**
1005
+ * Return bigint representation
1006
+ */
1007
+ toBigInt() {
1008
+ return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
1009
+ }
1010
+ /**
1011
+ * Return Uint512 structure with HexString props
1012
+ * limbx: HexString
1013
+ */
1014
+ toUint512HexString() {
1015
+ return {
1016
+ limb0: addHexPrefix(this.limb0.toString(16)),
1017
+ limb1: addHexPrefix(this.limb1.toString(16)),
1018
+ limb2: addHexPrefix(this.limb2.toString(16)),
1019
+ limb3: addHexPrefix(this.limb3.toString(16))
1020
+ };
1021
+ }
1022
+ /**
1023
+ * Return Uint512 structure with DecimalString props
1024
+ * limbx DecString
1025
+ */
1026
+ toUint512DecimalString() {
1027
+ return {
1028
+ limb0: this.limb0.toString(10),
1029
+ limb1: this.limb1.toString(10),
1030
+ limb2: this.limb2.toString(10),
1031
+ limb3: this.limb3.toString(10)
1032
+ };
1033
+ }
1034
+ /**
1035
+ * Return api requests representation witch is felt array
1036
+ */
1037
+ toApiRequest() {
1038
+ return [
1039
+ CairoFelt(this.limb0),
1040
+ CairoFelt(this.limb1),
1041
+ CairoFelt(this.limb2),
1042
+ CairoFelt(this.limb3)
1043
+ ];
1044
+ }
1045
+ };
1046
+
898
1047
  // src/utils/calldata/cairo.ts
899
1048
  var isLen = (name) => /_len$/.test(name);
900
1049
  var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
@@ -913,6 +1062,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
913
1062
  var isTypeEthAddress = (type) => type === "core::starknet::eth_address::EthAddress";
914
1063
  var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
915
1064
  var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
1065
+ var isTypeSecp256k1Point = (type) => type === "core::starknet::secp256k1::Secp256k1Point";
916
1066
  var isCairo1Type = (type) => type.includes("::");
917
1067
  var getArrayType = (type) => {
918
1068
  if (isCairo1Type(type)) {
@@ -946,6 +1096,9 @@ function getAbiContractVersion(abi) {
946
1096
  var uint256 = (it) => {
947
1097
  return new CairoUint256(it).toUint256DecimalString();
948
1098
  };
1099
+ var uint512 = (it) => {
1100
+ return new CairoUint512(it).toUint512DecimalString();
1101
+ };
949
1102
  var tuple = (...args) => ({ ...args });
950
1103
  function felt(it) {
951
1104
  return CairoFelt(it);
@@ -1350,6 +1503,11 @@ function errorU256(key) {
1350
1503
  `Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
1351
1504
  );
1352
1505
  }
1506
+ function errorU512(key) {
1507
+ return Error(
1508
+ `Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
1509
+ );
1510
+ }
1353
1511
  function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
1354
1512
  const orderInput = (unorderedItem, abiType) => {
1355
1513
  if (isTypeArray(abiType)) {
@@ -1368,6 +1526,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
1368
1526
  if (isTypeByteArray(abiType)) {
1369
1527
  return unorderedItem;
1370
1528
  }
1529
+ if (isTypeSecp256k1Point(abiType)) {
1530
+ return unorderedItem;
1531
+ }
1371
1532
  if (CairoUint256.isAbiType(abiType)) {
1372
1533
  const u256 = unorderedItem;
1373
1534
  if (typeof u256 !== "object") {
@@ -1378,6 +1539,16 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
1378
1539
  }
1379
1540
  return { low: u256.low, high: u256.high };
1380
1541
  }
1542
+ if (CairoUint512.isAbiType(abiType)) {
1543
+ const u512 = unorderedItem;
1544
+ if (typeof u512 !== "object") {
1545
+ return u512;
1546
+ }
1547
+ if (!["limb0", "limb1", "limb2", "limb3"].every((key) => key in u512)) {
1548
+ throw errorU512(abiType);
1549
+ }
1550
+ return { limb0: u512.limb0, limb1: u512.limb1, limb2: u512.limb2, limb3: u512.limb3 };
1551
+ }
1381
1552
  if (isTypeStruct(abiType, structs)) {
1382
1553
  const abiOfStruct = structs[abiType].members;
1383
1554
  return orderStruct(unorderedItem, abiOfStruct);
@@ -1402,7 +1573,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
1402
1573
  };
1403
1574
  function orderArray(myArray, abiParam) {
1404
1575
  const typeInArray = getArrayType(abiParam);
1405
- if (typeof myArray === "string") {
1576
+ if (isString(myArray)) {
1406
1577
  return myArray;
1407
1578
  }
1408
1579
  return myArray.map((myElem) => orderInput(myElem, typeInArray));
@@ -1493,8 +1664,21 @@ function parseBaseTypes(type, val) {
1493
1664
  switch (true) {
1494
1665
  case CairoUint256.isAbiType(type):
1495
1666
  return new CairoUint256(val).toApiRequest();
1667
+ case CairoUint512.isAbiType(type):
1668
+ return new CairoUint512(val).toApiRequest();
1496
1669
  case isTypeBytes31(type):
1497
1670
  return encodeShortString(val.toString());
1671
+ case isTypeSecp256k1Point(type): {
1672
+ const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
1673
+ const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
1674
+ const pubKeyETHx = uint256(addHexPrefix(pubKeyETH.slice(0, -64)));
1675
+ return [
1676
+ felt(pubKeyETHx.low),
1677
+ felt(pubKeyETHx.high),
1678
+ felt(pubKeyETHy.low),
1679
+ felt(pubKeyETHy.high)
1680
+ ];
1681
+ }
1498
1682
  default:
1499
1683
  return felt(val);
1500
1684
  }
@@ -1541,6 +1725,9 @@ function parseCalldataValue(element, type, structs, enums) {
1541
1725
  if (CairoUint256.isAbiType(type)) {
1542
1726
  return new CairoUint256(element).toApiRequest();
1543
1727
  }
1728
+ if (CairoUint512.isAbiType(type)) {
1729
+ return new CairoUint512(element).toApiRequest();
1730
+ }
1544
1731
  if (type === "core::starknet::eth_address::EthAddress")
1545
1732
  return parseBaseTypes(type, element);
1546
1733
  if (type === "core::byte_array::ByteArray")
@@ -1561,6 +1748,9 @@ function parseCalldataValue(element, type, structs, enums) {
1561
1748
  if (CairoUint256.isAbiType(type)) {
1562
1749
  return new CairoUint256(element).toApiRequest();
1563
1750
  }
1751
+ if (CairoUint512.isAbiType(type)) {
1752
+ return new CairoUint512(element).toApiRequest();
1753
+ }
1564
1754
  if (isTypeEnum(type, enums)) {
1565
1755
  const { variants } = enums[type];
1566
1756
  if (isTypeOption(type)) {
@@ -1653,13 +1843,13 @@ function parseCalldataField(argsIterator, input, structs, enums) {
1653
1843
  if (!Array.isArray(value) && !isText(value)) {
1654
1844
  throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
1655
1845
  }
1656
- if (typeof value === "string") {
1846
+ if (isString(value)) {
1657
1847
  value = splitLongString(value);
1658
1848
  }
1659
1849
  return parseCalldataValue(value, input.type, structs, enums);
1660
1850
  case type === "core::starknet::eth_address::EthAddress":
1661
1851
  return parseBaseTypes(type, value);
1662
- case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
1852
+ case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type) || CairoUint256.isAbiType(type)):
1663
1853
  return parseCalldataValue(value, type, structs, enums);
1664
1854
  case isTypeEnum(type, enums):
1665
1855
  return parseCalldataValue(
@@ -1684,12 +1874,25 @@ function parseBaseTypes2(type, it) {
1684
1874
  const low = it.next().value;
1685
1875
  const high = it.next().value;
1686
1876
  return new CairoUint256(low, high).toBigInt();
1877
+ case CairoUint512.isAbiType(type):
1878
+ const limb0 = it.next().value;
1879
+ const limb1 = it.next().value;
1880
+ const limb2 = it.next().value;
1881
+ const limb3 = it.next().value;
1882
+ return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
1687
1883
  case type === "core::starknet::eth_address::EthAddress":
1688
1884
  temp = it.next().value;
1689
1885
  return BigInt(temp);
1690
1886
  case type === "core::bytes_31::bytes31":
1691
1887
  temp = it.next().value;
1692
1888
  return decodeShortString(temp);
1889
+ case isTypeSecp256k1Point(type):
1890
+ const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
1891
+ const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
1892
+ const yLow = removeHexPrefix(it.next().value).padStart(32, "0");
1893
+ const yHigh = removeHexPrefix(it.next().value).padStart(32, "0");
1894
+ const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
1895
+ return pubK;
1693
1896
  default:
1694
1897
  temp = it.next().value;
1695
1898
  return BigInt(temp);
@@ -1704,6 +1907,13 @@ function parseResponseValue(responseIterator, element, structs, enums) {
1704
1907
  const high = responseIterator.next().value;
1705
1908
  return new CairoUint256(low, high).toBigInt();
1706
1909
  }
1910
+ if (CairoUint512.isAbiType(element.type)) {
1911
+ const limb0 = responseIterator.next().value;
1912
+ const limb1 = responseIterator.next().value;
1913
+ const limb2 = responseIterator.next().value;
1914
+ const limb3 = responseIterator.next().value;
1915
+ return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
1916
+ }
1707
1917
  if (isTypeByteArray(element.type)) {
1708
1918
  const parsedBytes31Arr = [];
1709
1919
  const bytes31ArrLen = BigInt(responseIterator.next().value);
@@ -1827,10 +2037,10 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
1827
2037
  // src/utils/calldata/validate.ts
1828
2038
  var validateFelt = (parameter, input) => {
1829
2039
  assert(
1830
- typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
2040
+ isString(parameter) || isNumber(parameter) || isBigInt(parameter),
1831
2041
  `Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
1832
2042
  );
1833
- if (typeof parameter === "string" && !isHex(parameter))
2043
+ if (isString(parameter) && !isHex(parameter))
1834
2044
  return;
1835
2045
  const param = BigInt(parameter.toString(10));
1836
2046
  assert(
@@ -1840,27 +2050,37 @@ var validateFelt = (parameter, input) => {
1840
2050
  );
1841
2051
  };
1842
2052
  var validateBytes31 = (parameter, input) => {
1843
- assert(typeof parameter === "string", `Validate: arg ${input.name} should be a string.`);
2053
+ assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
1844
2054
  assert(
1845
2055
  parameter.length < 32,
1846
2056
  `Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
1847
2057
  );
1848
2058
  };
1849
2059
  var validateByteArray = (parameter, input) => {
1850
- assert(typeof parameter === "string", `Validate: arg ${input.name} should be a string.`);
2060
+ assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
1851
2061
  };
1852
2062
  var validateUint = (parameter, input) => {
1853
- if (typeof parameter === "number") {
2063
+ if (isNumber(parameter)) {
1854
2064
  assert(
1855
2065
  parameter <= Number.MAX_SAFE_INTEGER,
1856
2066
  `Validation: Parameter is to large to be typed as Number use (BigInt or String)`
1857
2067
  );
1858
2068
  }
1859
2069
  assert(
1860
- typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
2070
+ isString(parameter) || isNumber(parameter) || isBigInt(parameter) || typeof parameter === "object" && "low" in parameter && "high" in parameter || typeof parameter === "object" && ["limb0", "limb1", "limb2", "limb3"].every((key) => key in parameter),
1861
2071
  `Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt), but is ${typeof parameter} ${parameter}.`
1862
2072
  );
1863
- const param = typeof parameter === "object" ? new CairoUint256(parameter).toBigInt() : toBigInt(parameter);
2073
+ let param;
2074
+ switch (input.type) {
2075
+ case "core::integer::u256" /* u256 */:
2076
+ param = new CairoUint256(parameter).toBigInt();
2077
+ break;
2078
+ case "core::integer::u512" /* u512 */:
2079
+ param = new CairoUint512(parameter).toBigInt();
2080
+ break;
2081
+ default:
2082
+ param = toBigInt(parameter);
2083
+ }
1864
2084
  switch (input.type) {
1865
2085
  case "core::integer::u8" /* u8 */:
1866
2086
  assert(
@@ -1898,6 +2118,9 @@ var validateUint = (parameter, input) => {
1898
2118
  `Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
1899
2119
  );
1900
2120
  break;
2121
+ case "core::integer::u512" /* u512 */:
2122
+ assert(CairoUint512.is(param), `Validate: arg ${input.name} is ${input.type} 0 - 2^512-1`);
2123
+ break;
1901
2124
  case "core::starknet::class_hash::ClassHash" /* ClassHash */:
1902
2125
  assert(
1903
2126
  // from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1670
@@ -1912,18 +2135,25 @@ var validateUint = (parameter, input) => {
1912
2135
  `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
1913
2136
  );
1914
2137
  break;
2138
+ case "core::starknet::secp256k1::Secp256k1Point" /* Secp256k1Point */: {
2139
+ assert(
2140
+ param >= 0n && param <= 2n ** 512n - 1n,
2141
+ `Validate: arg ${input.name} must be ${input.type} : a 512 bits number.`
2142
+ );
2143
+ break;
2144
+ }
1915
2145
  default:
1916
2146
  break;
1917
2147
  }
1918
2148
  };
1919
2149
  var validateBool = (parameter, input) => {
1920
2150
  assert(
1921
- typeof parameter === "boolean",
2151
+ isBoolean(parameter),
1922
2152
  `Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
1923
2153
  );
1924
2154
  };
1925
2155
  var validateStruct = (parameter, input, structs) => {
1926
- if (input.type === "core::integer::u256" /* u256 */) {
2156
+ if (input.type === "core::integer::u256" /* u256 */ || input.type === "core::integer::u512" /* u512 */) {
1927
2157
  validateUint(parameter, input);
1928
2158
  return;
1929
2159
  }
@@ -2004,7 +2234,7 @@ var validateArray = (parameter, input, structs, enums) => {
2004
2234
  parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
2005
2235
  break;
2006
2236
  case (isTypeUint(baseType) || isTypeLiteral(baseType)):
2007
- parameter.forEach((param) => validateUint(param, input));
2237
+ parameter.forEach((param) => validateUint(param, { name: "", type: baseType }));
2008
2238
  break;
2009
2239
  case isTypeBool(baseType):
2010
2240
  parameter.forEach((param) => validateBool(param, input));
@@ -2684,7 +2914,7 @@ function computeHintedClassHash(compiledContract) {
2684
2914
  return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
2685
2915
  }
2686
2916
  function computeLegacyContractClassHash(contract) {
2687
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2917
+ const compiledContract = isString(contract) ? parse2(contract) : contract;
2688
2918
  const apiVersion = toHex(API_VERSION);
2689
2919
  const externalEntryPointsHash = computeHashOnElements2(
2690
2920
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
@@ -2780,7 +3010,7 @@ function computeSierraContractClassHash(sierra) {
2780
3010
  );
2781
3011
  }
2782
3012
  function computeContractClassHash(contract) {
2783
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3013
+ const compiledContract = isString(contract) ? parse2(contract) : contract;
2784
3014
  if ("sierra_program" in compiledContract) {
2785
3015
  return computeSierraContractClassHash(compiledContract);
2786
3016
  }
@@ -2808,7 +3038,7 @@ __export(stark_exports, {
2808
3038
  import { getStarkKey, utils } from "@scure/starknet";
2809
3039
  import { gzip, ungzip } from "pako";
2810
3040
  function compressProgram(jsonProgram) {
2811
- const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
3041
+ const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
2812
3042
  const compressedProgram = gzip(stringified);
2813
3043
  return btoaUniversal(compressedProgram);
2814
3044
  }
@@ -2848,7 +3078,7 @@ function estimatedFeeToMaxFee(estimatedFee, overhead = 50 /* MAX_FEE */) {
2848
3078
  return addPercent(estimatedFee, overhead);
2849
3079
  }
2850
3080
  function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUNT */, priceOverhead = 50 /* L1_BOUND_MAX_PRICE_PER_UNIT */) {
2851
- if (typeof estimate === "bigint") {
3081
+ if (isBigInt(estimate)) {
2852
3082
  return {
2853
3083
  l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
2854
3084
  l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
@@ -2916,7 +3146,7 @@ function reduceV2(providedVersion) {
2916
3146
 
2917
3147
  // src/utils/contract.ts
2918
3148
  function isSierra(contract) {
2919
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3149
+ const compiledContract = isString(contract) ? parse2(contract) : contract;
2920
3150
  return "sierra_program" in compiledContract;
2921
3151
  }
2922
3152
  function extractContractHashes(payload) {
@@ -2943,6 +3173,23 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
2943
3173
  return { ...contract, program: decompressProgram(contract.program) };
2944
3174
  }
2945
3175
 
3176
+ // src/utils/eth.ts
3177
+ var eth_exports = {};
3178
+ __export(eth_exports, {
3179
+ ethRandomPrivateKey: () => ethRandomPrivateKey,
3180
+ validateAndParseEthAddress: () => validateAndParseEthAddress
3181
+ });
3182
+ import { secp256k1 } from "@noble/curves/secp256k1";
3183
+ function ethRandomPrivateKey() {
3184
+ return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
3185
+ }
3186
+ function validateAndParseEthAddress(address) {
3187
+ assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address ");
3188
+ const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
3189
+ assert(result.match(/^(0x)?[0-9a-f]{40}$/), "Invalid Ethereum Address Format");
3190
+ return result;
3191
+ }
3192
+
2946
3193
  // src/utils/fetchPonyfill.ts
2947
3194
  import makeFetchCookie from "fetch-cookie";
2948
3195
  import isomorphicFetch from "isomorphic-fetch";
@@ -2981,7 +3228,7 @@ function createSierraContractClass(contract) {
2981
3228
  return result;
2982
3229
  }
2983
3230
  function parseContract(contract) {
2984
- const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
3231
+ const parsedContract = isString(contract) ? parse2(contract) : contract;
2985
3232
  if (!isSierra(contract)) {
2986
3233
  return {
2987
3234
  ...parsedContract,
@@ -2998,7 +3245,7 @@ var getDefaultNodeUrl = (networkName, mute = false) => {
2998
3245
  return nodes[randIdx];
2999
3246
  };
3000
3247
  function formatHash(hashValue) {
3001
- if (typeof hashValue === "string")
3248
+ if (isString(hashValue))
3002
3249
  return hashValue;
3003
3250
  return toHex(hashValue);
3004
3251
  }
@@ -3015,14 +3262,16 @@ var Block = class {
3015
3262
  number = null;
3016
3263
  tag = null;
3017
3264
  setIdentifier(__identifier) {
3018
- if (typeof __identifier === "string" && isHex(__identifier)) {
3019
- this.hash = __identifier;
3020
- } else if (typeof __identifier === "bigint") {
3265
+ if (isString(__identifier)) {
3266
+ if (isHex(__identifier)) {
3267
+ this.hash = __identifier;
3268
+ } else if (validBlockTags.includes(__identifier)) {
3269
+ this.tag = __identifier;
3270
+ }
3271
+ } else if (isBigInt(__identifier)) {
3021
3272
  this.hash = toHex(__identifier);
3022
- } else if (typeof __identifier === "number") {
3273
+ } else if (isNumber(__identifier)) {
3023
3274
  this.number = __identifier;
3024
- } else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
3025
- this.tag = __identifier;
3026
3275
  } else {
3027
3276
  this.tag = "pending" /* pending */;
3028
3277
  }
@@ -3619,7 +3868,7 @@ var RpcChannel = class {
3619
3868
  estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
3620
3869
  const { from_address, to_address, entry_point_selector, payload } = message;
3621
3870
  const formattedMessage = {
3622
- from_address: toHex(from_address),
3871
+ from_address: validateAndParseEthAddress(from_address),
3623
3872
  to_address: toHex(to_address),
3624
3873
  entry_point_selector: getSelector(entry_point_selector),
3625
3874
  payload: getHexStringArray(payload)
@@ -3731,11 +3980,11 @@ var RpcChannel2 = class {
3731
3980
  requestId;
3732
3981
  blockIdentifier;
3733
3982
  chainId;
3734
- speckVersion;
3983
+ specVersion;
3735
3984
  waitMode;
3736
3985
  // behave like web2 rpc and return when tx is processed
3737
3986
  constructor(optionsOrProvider) {
3738
- const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
3987
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
3739
3988
  if (Object.values(NetworkName).includes(nodeUrl)) {
3740
3989
  this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
3741
3990
  } else if (nodeUrl) {
@@ -3747,6 +3996,7 @@ var RpcChannel2 = class {
3747
3996
  this.headers = { ...defaultOptions2.headers, ...headers };
3748
3997
  this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
3749
3998
  this.chainId = chainId;
3999
+ this.specVersion = specVersion;
3750
4000
  this.waitMode = waitMode || false;
3751
4001
  this.requestId = 0;
3752
4002
  }
@@ -3798,8 +4048,8 @@ var RpcChannel2 = class {
3798
4048
  return this.chainId;
3799
4049
  }
3800
4050
  async getSpecVersion() {
3801
- this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
3802
- return this.speckVersion;
4051
+ this.specVersion ??= await this.fetchEndpoint("starknet_specVersion");
4052
+ return this.specVersion;
3803
4053
  }
3804
4054
  getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
3805
4055
  const contract_address = toHex(contractAddress);
@@ -4156,7 +4406,7 @@ var RpcChannel2 = class {
4156
4406
  estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
4157
4407
  const { from_address, to_address, entry_point_selector, payload } = message;
4158
4408
  const formattedMessage = {
4159
- from_address: toHex(from_address),
4409
+ from_address: validateAndParseEthAddress(from_address),
4160
4410
  to_address: toHex(to_address),
4161
4411
  entry_point_selector: getSelector(entry_point_selector),
4162
4412
  payload: getHexStringArray(payload)
@@ -4271,7 +4521,7 @@ var RPCResponseParser = class {
4271
4521
  return { status: "PENDING", ...res };
4272
4522
  }
4273
4523
  parseTransactionReceipt(res) {
4274
- if ("actual_fee" in res && typeof res.actual_fee === "string") {
4524
+ if ("actual_fee" in res && isString(res.actual_fee)) {
4275
4525
  return {
4276
4526
  ...res,
4277
4527
  actual_fee: {
@@ -4290,7 +4540,9 @@ var RPCResponseParser = class {
4290
4540
  gas_price: toBigInt(val.gas_price),
4291
4541
  unit: val.unit,
4292
4542
  suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4293
- resourceBounds: this.estimateFeeToBounds(val)
4543
+ resourceBounds: this.estimateFeeToBounds(val),
4544
+ data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
4545
+ data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
4294
4546
  };
4295
4547
  }
4296
4548
  parseFeeEstimateBulkResponse(res) {
@@ -4300,7 +4552,9 @@ var RPCResponseParser = class {
4300
4552
  gas_price: toBigInt(val.gas_price),
4301
4553
  unit: val.unit,
4302
4554
  suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4303
- resourceBounds: this.estimateFeeToBounds(val)
4555
+ resourceBounds: this.estimateFeeToBounds(val),
4556
+ data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
4557
+ data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
4304
4558
  }));
4305
4559
  }
4306
4560
  parseSimulateTransactionResponse(res) {
@@ -4315,11 +4569,59 @@ var RPCResponseParser = class {
4315
4569
  parseContractClassResponse(res) {
4316
4570
  return {
4317
4571
  ...res,
4318
- abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
4572
+ abi: isString(res.abi) ? JSON.parse(res.abi) : res.abi
4319
4573
  };
4320
4574
  }
4321
4575
  };
4322
4576
 
4577
+ // src/utils/transactionReceipt.ts
4578
+ var ReceiptTx = class _ReceiptTx {
4579
+ statusReceipt;
4580
+ value;
4581
+ constructor(receipt) {
4582
+ [this.statusReceipt, this.value] = _ReceiptTx.isSuccess(receipt) ? ["success", receipt] : _ReceiptTx.isReverted(receipt) ? ["reverted", receipt] : _ReceiptTx.isRejected(receipt) ? ["rejected", receipt] : ["error", new Error("Unknown response type")];
4583
+ for (const [key] of Object.entries(this)) {
4584
+ Object.defineProperty(this, key, {
4585
+ enumerable: false
4586
+ });
4587
+ }
4588
+ for (const [key, value] of Object.entries(receipt)) {
4589
+ Object.defineProperty(this, key, {
4590
+ enumerable: true,
4591
+ writable: false,
4592
+ value
4593
+ });
4594
+ }
4595
+ }
4596
+ match(callbacks) {
4597
+ if (this.statusReceipt in callbacks) {
4598
+ return callbacks[this.statusReceipt](this.value);
4599
+ }
4600
+ return callbacks._();
4601
+ }
4602
+ isSuccess() {
4603
+ return this.statusReceipt === "success";
4604
+ }
4605
+ isReverted() {
4606
+ return this.statusReceipt === "reverted";
4607
+ }
4608
+ isRejected() {
4609
+ return this.statusReceipt === "rejected";
4610
+ }
4611
+ isError() {
4612
+ return this.statusReceipt === "error";
4613
+ }
4614
+ static isSuccess(transactionReceipt) {
4615
+ return transactionReceipt.execution_status === "SUCCEEDED" /* SUCCEEDED */;
4616
+ }
4617
+ static isReverted(transactionReceipt) {
4618
+ return transactionReceipt.execution_status === "REVERTED" /* REVERTED */;
4619
+ }
4620
+ static isRejected(transactionReceipt) {
4621
+ return transactionReceipt.status === "REJECTED" /* REJECTED */;
4622
+ }
4623
+ };
4624
+
4323
4625
  // src/provider/rpc.ts
4324
4626
  var RpcProvider = class {
4325
4627
  responseParser;
@@ -4404,7 +4706,9 @@ var RpcProvider = class {
4404
4706
  return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index);
4405
4707
  }
4406
4708
  async getTransactionReceipt(txHash) {
4407
- return this.channel.getTransactionReceipt(txHash).then(this.responseParser.parseTransactionReceipt);
4709
+ const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
4710
+ const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
4711
+ return new ReceiptTx(txReceiptWoHelperModified);
4408
4712
  }
4409
4713
  async getTransactionTrace(txHash) {
4410
4714
  return this.channel.getTransactionTrace(txHash);
@@ -4426,7 +4730,11 @@ var RpcProvider = class {
4426
4730
  return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
4427
4731
  }
4428
4732
  async waitForTransaction(txHash, options) {
4429
- return this.channel.waitForTransaction(txHash, options);
4733
+ const receiptWoHelper = await this.channel.waitForTransaction(
4734
+ txHash,
4735
+ options
4736
+ );
4737
+ return new ReceiptTx(receiptWoHelper);
4430
4738
  }
4431
4739
  async getStorageAt(contractAddress, key, blockIdentifier) {
4432
4740
  return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
@@ -5116,14 +5424,14 @@ var presetTypes = {
5116
5424
  )
5117
5425
  };
5118
5426
  var revisionConfiguration = {
5119
- ["1" /* Active */]: {
5427
+ [TypedDataRevision.Active]: {
5120
5428
  domain: "StarknetDomain",
5121
5429
  hashMethod: computePoseidonHashOnElements,
5122
5430
  hashMerkleMethod: computePoseidonHash,
5123
5431
  escapeTypeString: (s) => `"${s}"`,
5124
5432
  presetTypes
5125
5433
  },
5126
- ["0" /* Legacy */]: {
5434
+ [TypedDataRevision.Legacy]: {
5127
5435
  domain: "StarkNetDomain",
5128
5436
  hashMethod: computePedersenHashOnElements,
5129
5437
  hashMerkleMethod: computePedersenHash,
@@ -5131,18 +5439,22 @@ var revisionConfiguration = {
5131
5439
  presetTypes: {}
5132
5440
  }
5133
5441
  };
5442
+ function assertRange(data, type, { min, max }) {
5443
+ const value = BigInt(data);
5444
+ assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
5445
+ }
5134
5446
  function identifyRevision({ types, domain }) {
5135
- if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
5136
- return "1" /* Active */;
5137
- if (revisionConfiguration["0" /* Legacy */].domain in types && (domain.revision ?? "0" /* Legacy */) === "0" /* Legacy */)
5138
- return "0" /* Legacy */;
5447
+ if (revisionConfiguration[TypedDataRevision.Active].domain in types && domain.revision === TypedDataRevision.Active)
5448
+ return TypedDataRevision.Active;
5449
+ if (revisionConfiguration[TypedDataRevision.Legacy].domain in types && (domain.revision ?? TypedDataRevision.Legacy) === TypedDataRevision.Legacy)
5450
+ return TypedDataRevision.Legacy;
5139
5451
  return void 0;
5140
5452
  }
5141
5453
  function getHex(value) {
5142
5454
  try {
5143
5455
  return toHex(value);
5144
5456
  } catch (e) {
5145
- if (typeof value === "string") {
5457
+ if (isString(value)) {
5146
5458
  return toHex(encodeShortString(value));
5147
5459
  }
5148
5460
  throw new Error(`Invalid BigNumberish: ${value}`);
@@ -5160,10 +5472,10 @@ function prepareSelector(selector) {
5160
5472
  function isMerkleTreeType(type) {
5161
5473
  return type.type === "merkletree";
5162
5474
  }
5163
- function getDependencies(types, type, dependencies = [], contains = "", revision = "0" /* Legacy */) {
5475
+ function getDependencies(types, type, dependencies = [], contains = "", revision = TypedDataRevision.Legacy) {
5164
5476
  if (type[type.length - 1] === "*") {
5165
5477
  type = type.slice(0, -1);
5166
- } else if (revision === "1" /* Active */) {
5478
+ } else if (revision === TypedDataRevision.Active) {
5167
5479
  if (type === "enum") {
5168
5480
  type = contains;
5169
5481
  } else if (type.match(/^\(.*\)$/)) {
@@ -5201,8 +5513,8 @@ function getMerkleTreeType(types, ctx) {
5201
5513
  }
5202
5514
  return "raw";
5203
5515
  }
5204
- function encodeType(types, type, revision = "0" /* Legacy */) {
5205
- const allTypes = revision === "1" /* Active */ ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
5516
+ function encodeType(types, type, revision = TypedDataRevision.Legacy) {
5517
+ const allTypes = revision === TypedDataRevision.Active ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
5206
5518
  const [primary, ...dependencies] = getDependencies(
5207
5519
  allTypes,
5208
5520
  type,
@@ -5214,17 +5526,17 @@ function encodeType(types, type, revision = "0" /* Legacy */) {
5214
5526
  const esc = revisionConfiguration[revision].escapeTypeString;
5215
5527
  return newTypes.map((dependency) => {
5216
5528
  const dependencyElements = allTypes[dependency].map((t) => {
5217
- const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
5529
+ const targetType = t.type === "enum" && revision === TypedDataRevision.Active ? t.contains : t.type;
5218
5530
  const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
5219
5531
  return `${esc(t.name)}:${typeString}`;
5220
5532
  });
5221
5533
  return `${esc(dependency)}(${dependencyElements})`;
5222
5534
  }).join("");
5223
5535
  }
5224
- function getTypeHash(types, type, revision = "0" /* Legacy */) {
5536
+ function getTypeHash(types, type, revision = TypedDataRevision.Legacy) {
5225
5537
  return getSelectorFromName(encodeType(types, type, revision));
5226
5538
  }
5227
- function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5539
+ function encodeValue(types, type, data, ctx = {}, revision = TypedDataRevision.Legacy) {
5228
5540
  if (types[type]) {
5229
5541
  return [type, getStructHash(types, type, data, revision)];
5230
5542
  }
@@ -5247,7 +5559,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5247
5559
  }
5248
5560
  switch (type) {
5249
5561
  case "enum": {
5250
- if (revision === "1" /* Active */) {
5562
+ if (revision === TypedDataRevision.Active) {
5251
5563
  const [variantKey, variantData] = Object.entries(data)[0];
5252
5564
  const parentType = types[ctx.parent][0];
5253
5565
  const enumType = types[parentType.contains];
@@ -5281,7 +5593,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5281
5593
  return ["felt", prepareSelector(data)];
5282
5594
  }
5283
5595
  case "string": {
5284
- if (revision === "1" /* Active */) {
5596
+ if (revision === TypedDataRevision.Active) {
5285
5597
  const byteArray = byteArrayFromString(data);
5286
5598
  const elements = [
5287
5599
  byteArray.data.length,
@@ -5293,24 +5605,50 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5293
5605
  }
5294
5606
  return [type, getHex(data)];
5295
5607
  }
5608
+ case "i128": {
5609
+ if (revision === TypedDataRevision.Active) {
5610
+ const value = BigInt(data);
5611
+ assertRange(value, type, RANGE_I128);
5612
+ return [type, getHex(value < 0n ? PRIME + value : value)];
5613
+ }
5614
+ return [type, getHex(data)];
5615
+ }
5616
+ case "timestamp":
5617
+ case "u128": {
5618
+ if (revision === TypedDataRevision.Active) {
5619
+ assertRange(data, type, RANGE_U128);
5620
+ }
5621
+ return [type, getHex(data)];
5622
+ }
5296
5623
  case "felt":
5297
- case "bool":
5298
- case "u128":
5299
- case "i128":
5300
- case "ContractAddress":
5624
+ case "shortstring": {
5625
+ if (revision === TypedDataRevision.Active) {
5626
+ assertRange(getHex(data), type, RANGE_FELT);
5627
+ }
5628
+ return [type, getHex(data)];
5629
+ }
5301
5630
  case "ClassHash":
5302
- case "timestamp":
5303
- case "shortstring":
5631
+ case "ContractAddress": {
5632
+ if (revision === TypedDataRevision.Active) {
5633
+ assertRange(data, type, RANGE_FELT);
5634
+ }
5304
5635
  return [type, getHex(data)];
5636
+ }
5637
+ case "bool": {
5638
+ if (revision === TypedDataRevision.Active) {
5639
+ assert(typeof data === "boolean", `Type mismatch for ${type} ${data}`);
5640
+ }
5641
+ return [type, getHex(data)];
5642
+ }
5305
5643
  default: {
5306
- if (revision === "1" /* Active */) {
5644
+ if (revision === TypedDataRevision.Active) {
5307
5645
  throw new Error(`Unsupported type: ${type}`);
5308
5646
  }
5309
5647
  return [type, getHex(data)];
5310
5648
  }
5311
5649
  }
5312
5650
  }
5313
- function encodeData(types, type, data, revision = "0" /* Legacy */) {
5651
+ function encodeData(types, type, data, revision = TypedDataRevision.Legacy) {
5314
5652
  const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
5315
5653
  const [returnTypes, values] = targetType.reduce(
5316
5654
  ([ts, vs], field) => {
@@ -5329,7 +5667,7 @@ function encodeData(types, type, data, revision = "0" /* Legacy */) {
5329
5667
  );
5330
5668
  return [returnTypes, values];
5331
5669
  }
5332
- function getStructHash(types, type, data, revision = "0" /* Legacy */) {
5670
+ function getStructHash(types, type, data, revision = TypedDataRevision.Legacy) {
5333
5671
  return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
5334
5672
  }
5335
5673
  function getMessageHash(typedData, account) {
@@ -5441,29 +5779,48 @@ var Signer = class {
5441
5779
  // src/signer/ethSigner.ts
5442
5780
  import { secp256k1 as secp256k12 } from "@noble/curves/secp256k1";
5443
5781
 
5444
- // src/utils/eth.ts
5445
- var eth_exports = {};
5446
- __export(eth_exports, {
5447
- ethRandomPrivateKey: () => ethRandomPrivateKey
5782
+ // src/utils/uint256.ts
5783
+ var uint256_exports = {};
5784
+ __export(uint256_exports, {
5785
+ UINT_128_MAX: () => UINT_128_MAX,
5786
+ UINT_256_MAX: () => UINT_256_MAX,
5787
+ bnToUint256: () => bnToUint256,
5788
+ isUint256: () => isUint256,
5789
+ uint256ToBN: () => uint256ToBN
5448
5790
  });
5449
- import { secp256k1 } from "@noble/curves/secp256k1";
5450
- function ethRandomPrivateKey() {
5451
- return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
5791
+ function uint256ToBN(uint2562) {
5792
+ return new CairoUint256(uint2562).toBigInt();
5793
+ }
5794
+ function isUint256(bn) {
5795
+ return CairoUint256.is(bn);
5796
+ }
5797
+ function bnToUint256(bn) {
5798
+ return new CairoUint256(bn).toUint256HexString();
5452
5799
  }
5453
5800
 
5454
5801
  // src/signer/ethSigner.ts
5455
5802
  var EthSigner = class {
5456
5803
  pk;
5457
- // hex string without 0x and odd number of characters
5804
+ // hex string without 0x and with an odd number of characters
5458
5805
  constructor(pk = ethRandomPrivateKey()) {
5459
- this.pk = pk instanceof Uint8Array ? removeHexPrefix(sanitizeHex(buf2hex(pk))) : removeHexPrefix(sanitizeHex(toHex(pk)));
5806
+ this.pk = pk instanceof Uint8Array ? buf2hex(pk).padStart(64, "0") : removeHexPrefix(toHex(pk)).padStart(64, "0");
5460
5807
  }
5808
+ /**
5809
+ * provides the Ethereum full public key (without parity prefix)
5810
+ * @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
5811
+ */
5461
5812
  async getPubKey() {
5462
- return addHexPrefix(buf2hex(secp256k12.getPublicKey(this.pk)));
5813
+ return addHexPrefix(
5814
+ buf2hex(secp256k12.getPublicKey(this.pk, false)).padStart(130, "0").slice(2)
5815
+ );
5463
5816
  }
5464
5817
  async signMessage(typedData, accountAddress) {
5465
5818
  const msgHash = getMessageHash(typedData, accountAddress);
5466
- return secp256k12.sign(removeHexPrefix(sanitizeHex(msgHash)), this.pk);
5819
+ const signature = secp256k12.sign(
5820
+ removeHexPrefix(sanitizeHex(msgHash)),
5821
+ this.pk
5822
+ );
5823
+ return this.formatEthSignature(signature);
5467
5824
  }
5468
5825
  async signTransaction(transactions, details) {
5469
5826
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
@@ -5489,7 +5846,11 @@ var EthSigner = class {
5489
5846
  } else {
5490
5847
  throw Error("unsupported signTransaction version");
5491
5848
  }
5492
- return secp256k12.sign(removeHexPrefix(sanitizeHex(msgHash)), this.pk);
5849
+ const signature = secp256k12.sign(
5850
+ removeHexPrefix(sanitizeHex(msgHash)),
5851
+ this.pk
5852
+ );
5853
+ return this.formatEthSignature(signature);
5493
5854
  }
5494
5855
  async signDeployAccountTransaction(details) {
5495
5856
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
@@ -5515,7 +5876,11 @@ var EthSigner = class {
5515
5876
  } else {
5516
5877
  throw Error("unsupported signDeployAccountTransaction version");
5517
5878
  }
5518
- return secp256k12.sign(removeHexPrefix(sanitizeHex(msgHash)), this.pk);
5879
+ const signature = secp256k12.sign(
5880
+ removeHexPrefix(sanitizeHex(msgHash)),
5881
+ this.pk
5882
+ );
5883
+ return this.formatEthSignature(signature);
5519
5884
  }
5520
5885
  async signDeclareTransaction(details) {
5521
5886
  let msgHash;
@@ -5536,7 +5901,27 @@ var EthSigner = class {
5536
5901
  } else {
5537
5902
  throw Error("unsupported signDeclareTransaction version");
5538
5903
  }
5539
- return secp256k12.sign(removeHexPrefix(sanitizeHex(msgHash)), this.pk);
5904
+ const signature = secp256k12.sign(
5905
+ removeHexPrefix(sanitizeHex(msgHash)),
5906
+ this.pk
5907
+ );
5908
+ return this.formatEthSignature(signature);
5909
+ }
5910
+ /**
5911
+ * Serialize the signature in conformity with starknet::eth_signature::Signature
5912
+ * @param ethSignature secp256k1 signature from Noble curves library
5913
+ * @return an array of felts, representing a Cairo Eth Signature.
5914
+ */
5915
+ formatEthSignature(ethSignature) {
5916
+ const r = bnToUint256(ethSignature.r);
5917
+ const s = bnToUint256(ethSignature.s);
5918
+ return [
5919
+ toHex(r.low),
5920
+ toHex(r.high),
5921
+ toHex(s.low),
5922
+ toHex(s.high),
5923
+ toHex(ethSignature.recovery)
5924
+ ];
5540
5925
  }
5541
5926
  };
5542
5927
 
@@ -5572,7 +5957,7 @@ var Account = class extends RpcProvider2 {
5572
5957
  constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = "0x2" /* V2 */) {
5573
5958
  super(providerOrOptions);
5574
5959
  this.address = address.toLowerCase();
5575
- this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
5960
+ this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
5576
5961
  if (cairoVersion) {
5577
5962
  this.cairoVersion = cairoVersion.toString();
5578
5963
  }
@@ -5713,7 +6098,7 @@ var Account = class extends RpcProvider2 {
5713
6098
  return this.estimateInvokeFee(calls, details);
5714
6099
  }
5715
6100
  async estimateFeeBulk(invocations, details = {}) {
5716
- const { nonce, blockIdentifier, version } = details;
6101
+ const { nonce, blockIdentifier, version, skipValidate } = details;
5717
6102
  const accountInvocations = await this.accountInvocationsFactory(invocations, {
5718
6103
  ...v3Details(details),
5719
6104
  versions: [
@@ -5726,11 +6111,12 @@ var Account = class extends RpcProvider2 {
5726
6111
  // sierra
5727
6112
  ],
5728
6113
  nonce,
5729
- blockIdentifier
6114
+ blockIdentifier,
6115
+ skipValidate
5730
6116
  });
5731
6117
  return super.getEstimateFeeBulk(accountInvocations, {
5732
6118
  blockIdentifier,
5733
- skipValidate: details.skipValidate
6119
+ skipValidate
5734
6120
  });
5735
6121
  }
5736
6122
  async simulateTransaction(invocations, details = {}) {
@@ -5755,8 +6141,9 @@ var Account = class extends RpcProvider2 {
5755
6141
  skipExecute
5756
6142
  });
5757
6143
  }
5758
- async execute(calls, abis = void 0, details = {}) {
5759
- const transactions = Array.isArray(calls) ? calls : [calls];
6144
+ async execute(transactions, arg2, transactionsDetail = {}) {
6145
+ const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
6146
+ const calls = Array.isArray(transactions) ? transactions : [transactions];
5760
6147
  const nonce = toBigInt(details.nonce ?? await this.getNonce());
5761
6148
  const version = toTransactionVersion(
5762
6149
  this.getPreferredVersion("0x1" /* V1 */, "0x3" /* V3 */),
@@ -5765,7 +6152,7 @@ var Account = class extends RpcProvider2 {
5765
6152
  );
5766
6153
  const estimate = await this.getUniversalSuggestedFee(
5767
6154
  version,
5768
- { type: "INVOKE_FUNCTION" /* INVOKE */, payload: calls },
6155
+ { type: "INVOKE_FUNCTION" /* INVOKE */, payload: transactions },
5769
6156
  {
5770
6157
  ...details,
5771
6158
  version
@@ -5782,8 +6169,8 @@ var Account = class extends RpcProvider2 {
5782
6169
  chainId,
5783
6170
  cairoVersion: await this.getCairoVersion()
5784
6171
  };
5785
- const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
5786
- const calldata = getExecuteCalldata(transactions, await this.getCairoVersion());
6172
+ const signature = await this.signer.signTransaction(calls, signerDetails);
6173
+ const calldata = getExecuteCalldata(calls, await this.getCairoVersion());
5787
6174
  return this.invokeFunction(
5788
6175
  { contractAddress: this.address, calldata, signature },
5789
6176
  {
@@ -5995,7 +6382,9 @@ var Account = class extends RpcProvider2 {
5995
6382
  overall_fee: ZERO,
5996
6383
  unit: "FRI",
5997
6384
  suggestedMaxFee: ZERO,
5998
- resourceBounds: estimateFeeToBounds(ZERO)
6385
+ resourceBounds: estimateFeeToBounds(ZERO),
6386
+ data_gas_consumed: 0n,
6387
+ data_gas_price: 0n
5999
6388
  };
6000
6389
  break;
6001
6390
  }
@@ -6164,6 +6553,23 @@ var AccountInterface = class extends ProviderInterface {
6164
6553
  };
6165
6554
 
6166
6555
  // src/wallet/connect.ts
6556
+ var connect_exports = {};
6557
+ __export(connect_exports, {
6558
+ addDeclareTransaction: () => addDeclareTransaction,
6559
+ addDeployAccountTransaction: () => addDeployAccountTransaction,
6560
+ addInvokeTransaction: () => addInvokeTransaction,
6561
+ addStarknetChain: () => addStarknetChain,
6562
+ deploymentData: () => deploymentData,
6563
+ getPermissions: () => getPermissions,
6564
+ onAccountChange: () => onAccountChange,
6565
+ onNetworkChanged: () => onNetworkChanged,
6566
+ requestAccounts: () => requestAccounts,
6567
+ requestChainId: () => requestChainId,
6568
+ signMessage: () => signMessage,
6569
+ supportedSpecs: () => supportedSpecs,
6570
+ switchStarknetChain: () => switchStarknetChain,
6571
+ watchAsset: () => watchAsset
6572
+ });
6167
6573
  function requestAccounts(swo, silentMode = false) {
6168
6574
  return swo.request({
6169
6575
  type: "wallet_requestAccounts",
@@ -6734,25 +7140,6 @@ var ContractFactory = class {
6734
7140
  // ethers.js' getDeployTransaction can't be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
6735
7141
  };
6736
7142
 
6737
- // src/utils/uint256.ts
6738
- var uint256_exports = {};
6739
- __export(uint256_exports, {
6740
- UINT_128_MAX: () => UINT_128_MAX,
6741
- UINT_256_MAX: () => UINT_256_MAX,
6742
- bnToUint256: () => bnToUint256,
6743
- isUint256: () => isUint256,
6744
- uint256ToBN: () => uint256ToBN
6745
- });
6746
- function uint256ToBN(uint2562) {
6747
- return new CairoUint256(uint2562).toBigInt();
6748
- }
6749
- function isUint256(bn) {
6750
- return CairoUint256.is(bn);
6751
- }
6752
- function bnToUint256(bn) {
6753
- return new CairoUint256(bn).toUint256HexString();
6754
- }
6755
-
6756
7143
  // src/utils/address.ts
6757
7144
  import { hexToBytes as hexToBytes2 } from "@noble/curves/abstract/utils";
6758
7145
  function addAddressPadding(address) {
@@ -6825,6 +7212,8 @@ export {
6825
7212
  CairoOptionVariant,
6826
7213
  CairoResult,
6827
7214
  CairoResultVariant,
7215
+ CairoUint256,
7216
+ CairoUint512,
6828
7217
  CallData,
6829
7218
  Contract,
6830
7219
  ContractFactory,
@@ -6841,6 +7230,7 @@ export {
6841
7230
  api_exports as RPC,
6842
7231
  rpc_0_6_exports as RPC06,
6843
7232
  rpc_0_7_exports as RPC07,
7233
+ ReceiptTx,
6844
7234
  RpcChannel2 as RpcChannel,
6845
7235
  RpcProvider2 as RpcProvider,
6846
7236
  SIMULATION_FLAG,
@@ -6851,21 +7241,26 @@ export {
6851
7241
  TransactionStatus,
6852
7242
  TransactionType,
6853
7243
  TypedDataRevision,
7244
+ UINT_128_MAX,
7245
+ UINT_128_MIN,
7246
+ UINT_256_HIGH_MAX,
7247
+ UINT_256_HIGH_MIN,
7248
+ UINT_256_LOW_MAX,
7249
+ UINT_256_LOW_MIN,
7250
+ UINT_256_MAX,
7251
+ UINT_256_MIN,
7252
+ UINT_512_MAX,
7253
+ UINT_512_MIN,
6854
7254
  Uint,
6855
7255
  ValidateType,
6856
7256
  WalletAccount,
6857
7257
  addAddressPadding,
6858
- addDeclareTransaction,
6859
- addDeployAccountTransaction,
6860
- addInvokeTransaction,
6861
- addStarknetChain,
6862
7258
  buildUrl,
6863
7259
  byteArray_exports as byteArray,
6864
7260
  cairo_exports as cairo,
6865
7261
  constants_exports as constants,
6866
7262
  contractClassResponseToLegacyCompiledContract,
6867
7263
  defaultProvider,
6868
- deploymentData,
6869
7264
  ec_exports as ec,
6870
7265
  encode_exports as encode,
6871
7266
  eth_exports as eth,
@@ -6875,7 +7270,6 @@ export {
6875
7270
  fixStack,
6876
7271
  getCalldata,
6877
7272
  getChecksumAddress,
6878
- getPermissions,
6879
7273
  hash_exports as hash,
6880
7274
  isSierra,
6881
7275
  isUrl,
@@ -6883,20 +7277,13 @@ export {
6883
7277
  merkle_exports as merkle,
6884
7278
  num_exports as num,
6885
7279
  number,
6886
- onAccountChange,
6887
- onNetworkChanged,
6888
7280
  parseUDCEvent,
6889
7281
  provider_exports as provider,
6890
- requestAccounts,
6891
- requestChainId,
6892
7282
  selector_exports as selector,
6893
7283
  shortString_exports as shortString,
6894
- signMessage,
6895
7284
  splitArgsAndOptions,
6896
7285
  stark_exports as stark,
6897
7286
  starknetId_exports as starknetId,
6898
- supportedSpecs,
6899
- switchStarknetChain,
6900
7287
  transaction_exports as transaction,
6901
7288
  typedData_exports as typedData,
6902
7289
  types_exports as types,
@@ -6905,6 +7292,6 @@ export {
6905
7292
  v3_exports as v3hash,
6906
7293
  validateAndParseAddress,
6907
7294
  validateChecksumAddress,
6908
- watchAsset
7295
+ connect_exports as wallet
6909
7296
  };
6910
7297
  //# sourceMappingURL=index.mjs.map