starknet 6.6.0 → 6.6.6
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1639 -3019
- package/dist/index.global.js +460 -90
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +467 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +454 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
|
@@ -544,7 +555,9 @@ __export(num_exports, {
|
|
|
544
555
|
hexToBytes: () => hexToBytes,
|
|
545
556
|
hexToDecimalString: () => hexToDecimalString,
|
|
546
557
|
isBigInt: () => isBigInt,
|
|
558
|
+
isBoolean: () => isBoolean,
|
|
547
559
|
isHex: () => isHex,
|
|
560
|
+
isNumber: () => isNumber,
|
|
548
561
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
549
562
|
toBigInt: () => toBigInt,
|
|
550
563
|
toCairoBool: () => toCairoBool,
|
|
@@ -626,6 +639,12 @@ function addPercent(number2, percent) {
|
|
|
626
639
|
const bigIntNum = BigInt(number2);
|
|
627
640
|
return bigIntNum + bigIntNum * BigInt(percent) / 100n;
|
|
628
641
|
}
|
|
642
|
+
function isNumber(value) {
|
|
643
|
+
return typeof value === "number";
|
|
644
|
+
}
|
|
645
|
+
function isBoolean(value) {
|
|
646
|
+
return typeof value === "boolean";
|
|
647
|
+
}
|
|
629
648
|
|
|
630
649
|
// src/utils/selector.ts
|
|
631
650
|
var selector_exports = {};
|
|
@@ -671,6 +690,7 @@ __export(shortString_exports, {
|
|
|
671
690
|
isLongText: () => isLongText,
|
|
672
691
|
isShortString: () => isShortString,
|
|
673
692
|
isShortText: () => isShortText,
|
|
693
|
+
isString: () => isString,
|
|
674
694
|
isText: () => isText,
|
|
675
695
|
splitLongString: () => splitLongString
|
|
676
696
|
});
|
|
@@ -683,8 +703,11 @@ function isShortString(str) {
|
|
|
683
703
|
function isDecimalString(str) {
|
|
684
704
|
return /^[0-9]*$/i.test(str);
|
|
685
705
|
}
|
|
706
|
+
function isString(value) {
|
|
707
|
+
return typeof value === "string";
|
|
708
|
+
}
|
|
686
709
|
function isText(val) {
|
|
687
|
-
return
|
|
710
|
+
return isString(val) && !isHex(val) && !isStringWholeNumber(val);
|
|
688
711
|
}
|
|
689
712
|
var isShortText = (val) => isText(val) && isShortString(val);
|
|
690
713
|
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
@@ -757,34 +780,38 @@ __export(cairo_exports, {
|
|
|
757
780
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
758
781
|
isTypeOption: () => isTypeOption,
|
|
759
782
|
isTypeResult: () => isTypeResult,
|
|
783
|
+
isTypeSecp256k1Point: () => isTypeSecp256k1Point,
|
|
760
784
|
isTypeStruct: () => isTypeStruct,
|
|
761
785
|
isTypeTuple: () => isTypeTuple,
|
|
762
786
|
isTypeUint: () => isTypeUint,
|
|
763
787
|
isTypeUint256: () => isTypeUint256,
|
|
764
788
|
tuple: () => tuple,
|
|
765
|
-
uint256: () => uint256
|
|
789
|
+
uint256: () => uint256,
|
|
790
|
+
uint512: () => uint512
|
|
766
791
|
});
|
|
767
792
|
|
|
768
793
|
// src/utils/cairoDataTypes/felt.ts
|
|
769
794
|
function CairoFelt(it) {
|
|
770
|
-
if (isBigInt(it) ||
|
|
795
|
+
if (isBigInt(it) || Number.isInteger(it)) {
|
|
771
796
|
return it.toString();
|
|
772
797
|
}
|
|
773
|
-
if (
|
|
774
|
-
if (
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
798
|
+
if (isString(it)) {
|
|
799
|
+
if (isHex(it)) {
|
|
800
|
+
return BigInt(it).toString();
|
|
801
|
+
}
|
|
802
|
+
if (isText(it)) {
|
|
803
|
+
if (!isShortString(it)) {
|
|
804
|
+
throw new Error(
|
|
805
|
+
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
return BigInt(encodeShortString(it)).toString();
|
|
809
|
+
}
|
|
810
|
+
if (isStringWholeNumber(it)) {
|
|
811
|
+
return it;
|
|
812
|
+
}
|
|
786
813
|
}
|
|
787
|
-
if (
|
|
814
|
+
if (isBoolean(it)) {
|
|
788
815
|
return `${+it}`;
|
|
789
816
|
}
|
|
790
817
|
throw new Error(`${it} can't be computed by felt()`);
|
|
@@ -895,6 +922,130 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
895
922
|
}
|
|
896
923
|
};
|
|
897
924
|
|
|
925
|
+
// src/utils/cairoDataTypes/uint512.ts
|
|
926
|
+
var UINT_512_MAX = (1n << 512n) - 1n;
|
|
927
|
+
var UINT_512_MIN = 0n;
|
|
928
|
+
var UINT_128_MIN = 0n;
|
|
929
|
+
var CairoUint512 = class _CairoUint512 {
|
|
930
|
+
limb0;
|
|
931
|
+
limb1;
|
|
932
|
+
limb2;
|
|
933
|
+
limb3;
|
|
934
|
+
static abiSelector = "core::integer::u512";
|
|
935
|
+
constructor(...arr) {
|
|
936
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
937
|
+
const props = _CairoUint512.validateProps(
|
|
938
|
+
arr[0].limb0,
|
|
939
|
+
arr[0].limb1,
|
|
940
|
+
arr[0].limb2,
|
|
941
|
+
arr[0].limb3
|
|
942
|
+
);
|
|
943
|
+
this.limb0 = props.limb0;
|
|
944
|
+
this.limb1 = props.limb1;
|
|
945
|
+
this.limb2 = props.limb2;
|
|
946
|
+
this.limb3 = props.limb3;
|
|
947
|
+
} else if (arr.length === 1) {
|
|
948
|
+
const bigInt = _CairoUint512.validate(arr[0]);
|
|
949
|
+
this.limb0 = bigInt & UINT_128_MAX;
|
|
950
|
+
this.limb1 = (bigInt & UINT_128_MAX << 128n) >> 128n;
|
|
951
|
+
this.limb2 = (bigInt & UINT_128_MAX << 256n) >> 256n;
|
|
952
|
+
this.limb3 = bigInt >> 384n;
|
|
953
|
+
} else if (arr.length === 4) {
|
|
954
|
+
const props = _CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
|
|
955
|
+
this.limb0 = props.limb0;
|
|
956
|
+
this.limb1 = props.limb1;
|
|
957
|
+
this.limb2 = props.limb2;
|
|
958
|
+
this.limb3 = props.limb3;
|
|
959
|
+
} else {
|
|
960
|
+
throw Error("Incorrect Uint512 constructor parameters");
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
965
|
+
*/
|
|
966
|
+
static validate(bigNumberish) {
|
|
967
|
+
const bigInt = BigInt(bigNumberish);
|
|
968
|
+
if (bigInt < UINT_512_MIN)
|
|
969
|
+
throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
970
|
+
if (bigInt > UINT_512_MAX)
|
|
971
|
+
throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
972
|
+
return bigInt;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Validate if limbs can be represented as Uint512
|
|
976
|
+
*/
|
|
977
|
+
static validateProps(limb0, limb1, limb2, limb3) {
|
|
978
|
+
const l0 = BigInt(limb0);
|
|
979
|
+
const l1 = BigInt(limb1);
|
|
980
|
+
const l2 = BigInt(limb2);
|
|
981
|
+
const l3 = BigInt(limb3);
|
|
982
|
+
[l0, l1, l2, l3].forEach((value, index) => {
|
|
983
|
+
if (value < UINT_128_MIN || value > UINT_128_MAX) {
|
|
984
|
+
throw Error(`limb${index} is not in the range of a u128 number`);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Check if BigNumberish can be represented as Uint512
|
|
991
|
+
*/
|
|
992
|
+
static is(bigNumberish) {
|
|
993
|
+
try {
|
|
994
|
+
_CairoUint512.validate(bigNumberish);
|
|
995
|
+
} catch (error) {
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
return true;
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Check if provided abi type is this data type
|
|
1002
|
+
*/
|
|
1003
|
+
static isAbiType(abiType) {
|
|
1004
|
+
return abiType === _CairoUint512.abiSelector;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Return bigint representation
|
|
1008
|
+
*/
|
|
1009
|
+
toBigInt() {
|
|
1010
|
+
return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Return Uint512 structure with HexString props
|
|
1014
|
+
* limbx: HexString
|
|
1015
|
+
*/
|
|
1016
|
+
toUint512HexString() {
|
|
1017
|
+
return {
|
|
1018
|
+
limb0: addHexPrefix(this.limb0.toString(16)),
|
|
1019
|
+
limb1: addHexPrefix(this.limb1.toString(16)),
|
|
1020
|
+
limb2: addHexPrefix(this.limb2.toString(16)),
|
|
1021
|
+
limb3: addHexPrefix(this.limb3.toString(16))
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Return Uint512 structure with DecimalString props
|
|
1026
|
+
* limbx DecString
|
|
1027
|
+
*/
|
|
1028
|
+
toUint512DecimalString() {
|
|
1029
|
+
return {
|
|
1030
|
+
limb0: this.limb0.toString(10),
|
|
1031
|
+
limb1: this.limb1.toString(10),
|
|
1032
|
+
limb2: this.limb2.toString(10),
|
|
1033
|
+
limb3: this.limb3.toString(10)
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Return api requests representation witch is felt array
|
|
1038
|
+
*/
|
|
1039
|
+
toApiRequest() {
|
|
1040
|
+
return [
|
|
1041
|
+
CairoFelt(this.limb0),
|
|
1042
|
+
CairoFelt(this.limb1),
|
|
1043
|
+
CairoFelt(this.limb2),
|
|
1044
|
+
CairoFelt(this.limb3)
|
|
1045
|
+
];
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
|
|
898
1049
|
// src/utils/calldata/cairo.ts
|
|
899
1050
|
var isLen = (name) => /_len$/.test(name);
|
|
900
1051
|
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
@@ -913,6 +1064,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
|
|
|
913
1064
|
var isTypeEthAddress = (type) => type === "core::starknet::eth_address::EthAddress";
|
|
914
1065
|
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
915
1066
|
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
1067
|
+
var isTypeSecp256k1Point = (type) => type === "core::starknet::secp256k1::Secp256k1Point";
|
|
916
1068
|
var isCairo1Type = (type) => type.includes("::");
|
|
917
1069
|
var getArrayType = (type) => {
|
|
918
1070
|
if (isCairo1Type(type)) {
|
|
@@ -946,6 +1098,9 @@ function getAbiContractVersion(abi) {
|
|
|
946
1098
|
var uint256 = (it) => {
|
|
947
1099
|
return new CairoUint256(it).toUint256DecimalString();
|
|
948
1100
|
};
|
|
1101
|
+
var uint512 = (it) => {
|
|
1102
|
+
return new CairoUint512(it).toUint512DecimalString();
|
|
1103
|
+
};
|
|
949
1104
|
var tuple = (...args) => ({ ...args });
|
|
950
1105
|
function felt(it) {
|
|
951
1106
|
return CairoFelt(it);
|
|
@@ -1350,6 +1505,11 @@ function errorU256(key) {
|
|
|
1350
1505
|
`Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
|
|
1351
1506
|
);
|
|
1352
1507
|
}
|
|
1508
|
+
function errorU512(key) {
|
|
1509
|
+
return Error(
|
|
1510
|
+
`Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1353
1513
|
function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
1354
1514
|
const orderInput = (unorderedItem, abiType) => {
|
|
1355
1515
|
if (isTypeArray(abiType)) {
|
|
@@ -1368,6 +1528,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1368
1528
|
if (isTypeByteArray(abiType)) {
|
|
1369
1529
|
return unorderedItem;
|
|
1370
1530
|
}
|
|
1531
|
+
if (isTypeSecp256k1Point(abiType)) {
|
|
1532
|
+
return unorderedItem;
|
|
1533
|
+
}
|
|
1371
1534
|
if (CairoUint256.isAbiType(abiType)) {
|
|
1372
1535
|
const u256 = unorderedItem;
|
|
1373
1536
|
if (typeof u256 !== "object") {
|
|
@@ -1378,6 +1541,16 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1378
1541
|
}
|
|
1379
1542
|
return { low: u256.low, high: u256.high };
|
|
1380
1543
|
}
|
|
1544
|
+
if (CairoUint512.isAbiType(abiType)) {
|
|
1545
|
+
const u512 = unorderedItem;
|
|
1546
|
+
if (typeof u512 !== "object") {
|
|
1547
|
+
return u512;
|
|
1548
|
+
}
|
|
1549
|
+
if (!["limb0", "limb1", "limb2", "limb3"].every((key) => key in u512)) {
|
|
1550
|
+
throw errorU512(abiType);
|
|
1551
|
+
}
|
|
1552
|
+
return { limb0: u512.limb0, limb1: u512.limb1, limb2: u512.limb2, limb3: u512.limb3 };
|
|
1553
|
+
}
|
|
1381
1554
|
if (isTypeStruct(abiType, structs)) {
|
|
1382
1555
|
const abiOfStruct = structs[abiType].members;
|
|
1383
1556
|
return orderStruct(unorderedItem, abiOfStruct);
|
|
@@ -1402,7 +1575,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1402
1575
|
};
|
|
1403
1576
|
function orderArray(myArray, abiParam) {
|
|
1404
1577
|
const typeInArray = getArrayType(abiParam);
|
|
1405
|
-
if (
|
|
1578
|
+
if (isString(myArray)) {
|
|
1406
1579
|
return myArray;
|
|
1407
1580
|
}
|
|
1408
1581
|
return myArray.map((myElem) => orderInput(myElem, typeInArray));
|
|
@@ -1493,8 +1666,21 @@ function parseBaseTypes(type, val) {
|
|
|
1493
1666
|
switch (true) {
|
|
1494
1667
|
case CairoUint256.isAbiType(type):
|
|
1495
1668
|
return new CairoUint256(val).toApiRequest();
|
|
1669
|
+
case CairoUint512.isAbiType(type):
|
|
1670
|
+
return new CairoUint512(val).toApiRequest();
|
|
1496
1671
|
case isTypeBytes31(type):
|
|
1497
1672
|
return encodeShortString(val.toString());
|
|
1673
|
+
case isTypeSecp256k1Point(type): {
|
|
1674
|
+
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
1675
|
+
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
1676
|
+
const pubKeyETHx = uint256(addHexPrefix(pubKeyETH.slice(0, -64)));
|
|
1677
|
+
return [
|
|
1678
|
+
felt(pubKeyETHx.low),
|
|
1679
|
+
felt(pubKeyETHx.high),
|
|
1680
|
+
felt(pubKeyETHy.low),
|
|
1681
|
+
felt(pubKeyETHy.high)
|
|
1682
|
+
];
|
|
1683
|
+
}
|
|
1498
1684
|
default:
|
|
1499
1685
|
return felt(val);
|
|
1500
1686
|
}
|
|
@@ -1541,6 +1727,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1541
1727
|
if (CairoUint256.isAbiType(type)) {
|
|
1542
1728
|
return new CairoUint256(element).toApiRequest();
|
|
1543
1729
|
}
|
|
1730
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1731
|
+
return new CairoUint512(element).toApiRequest();
|
|
1732
|
+
}
|
|
1544
1733
|
if (type === "core::starknet::eth_address::EthAddress")
|
|
1545
1734
|
return parseBaseTypes(type, element);
|
|
1546
1735
|
if (type === "core::byte_array::ByteArray")
|
|
@@ -1561,6 +1750,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1561
1750
|
if (CairoUint256.isAbiType(type)) {
|
|
1562
1751
|
return new CairoUint256(element).toApiRequest();
|
|
1563
1752
|
}
|
|
1753
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1754
|
+
return new CairoUint512(element).toApiRequest();
|
|
1755
|
+
}
|
|
1564
1756
|
if (isTypeEnum(type, enums)) {
|
|
1565
1757
|
const { variants } = enums[type];
|
|
1566
1758
|
if (isTypeOption(type)) {
|
|
@@ -1653,13 +1845,13 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
1653
1845
|
if (!Array.isArray(value) && !isText(value)) {
|
|
1654
1846
|
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
1655
1847
|
}
|
|
1656
|
-
if (
|
|
1848
|
+
if (isString(value)) {
|
|
1657
1849
|
value = splitLongString(value);
|
|
1658
1850
|
}
|
|
1659
1851
|
return parseCalldataValue(value, input.type, structs, enums);
|
|
1660
1852
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1661
1853
|
return parseBaseTypes(type, value);
|
|
1662
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
1854
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type) || CairoUint256.isAbiType(type)):
|
|
1663
1855
|
return parseCalldataValue(value, type, structs, enums);
|
|
1664
1856
|
case isTypeEnum(type, enums):
|
|
1665
1857
|
return parseCalldataValue(
|
|
@@ -1684,12 +1876,25 @@ function parseBaseTypes2(type, it) {
|
|
|
1684
1876
|
const low = it.next().value;
|
|
1685
1877
|
const high = it.next().value;
|
|
1686
1878
|
return new CairoUint256(low, high).toBigInt();
|
|
1879
|
+
case CairoUint512.isAbiType(type):
|
|
1880
|
+
const limb0 = it.next().value;
|
|
1881
|
+
const limb1 = it.next().value;
|
|
1882
|
+
const limb2 = it.next().value;
|
|
1883
|
+
const limb3 = it.next().value;
|
|
1884
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
1687
1885
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1688
1886
|
temp = it.next().value;
|
|
1689
1887
|
return BigInt(temp);
|
|
1690
1888
|
case type === "core::bytes_31::bytes31":
|
|
1691
1889
|
temp = it.next().value;
|
|
1692
1890
|
return decodeShortString(temp);
|
|
1891
|
+
case isTypeSecp256k1Point(type):
|
|
1892
|
+
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
1893
|
+
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
1894
|
+
const yLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
1895
|
+
const yHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
1896
|
+
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
1897
|
+
return pubK;
|
|
1693
1898
|
default:
|
|
1694
1899
|
temp = it.next().value;
|
|
1695
1900
|
return BigInt(temp);
|
|
@@ -1704,6 +1909,13 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
1704
1909
|
const high = responseIterator.next().value;
|
|
1705
1910
|
return new CairoUint256(low, high).toBigInt();
|
|
1706
1911
|
}
|
|
1912
|
+
if (CairoUint512.isAbiType(element.type)) {
|
|
1913
|
+
const limb0 = responseIterator.next().value;
|
|
1914
|
+
const limb1 = responseIterator.next().value;
|
|
1915
|
+
const limb2 = responseIterator.next().value;
|
|
1916
|
+
const limb3 = responseIterator.next().value;
|
|
1917
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
1918
|
+
}
|
|
1707
1919
|
if (isTypeByteArray(element.type)) {
|
|
1708
1920
|
const parsedBytes31Arr = [];
|
|
1709
1921
|
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
@@ -1827,10 +2039,10 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
1827
2039
|
// src/utils/calldata/validate.ts
|
|
1828
2040
|
var validateFelt = (parameter, input) => {
|
|
1829
2041
|
assert(
|
|
1830
|
-
|
|
2042
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
1831
2043
|
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
1832
2044
|
);
|
|
1833
|
-
if (
|
|
2045
|
+
if (isString(parameter) && !isHex(parameter))
|
|
1834
2046
|
return;
|
|
1835
2047
|
const param = BigInt(parameter.toString(10));
|
|
1836
2048
|
assert(
|
|
@@ -1840,27 +2052,37 @@ var validateFelt = (parameter, input) => {
|
|
|
1840
2052
|
);
|
|
1841
2053
|
};
|
|
1842
2054
|
var validateBytes31 = (parameter, input) => {
|
|
1843
|
-
assert(
|
|
2055
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1844
2056
|
assert(
|
|
1845
2057
|
parameter.length < 32,
|
|
1846
2058
|
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
1847
2059
|
);
|
|
1848
2060
|
};
|
|
1849
2061
|
var validateByteArray = (parameter, input) => {
|
|
1850
|
-
assert(
|
|
2062
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1851
2063
|
};
|
|
1852
2064
|
var validateUint = (parameter, input) => {
|
|
1853
|
-
if (
|
|
2065
|
+
if (isNumber(parameter)) {
|
|
1854
2066
|
assert(
|
|
1855
2067
|
parameter <= Number.MAX_SAFE_INTEGER,
|
|
1856
2068
|
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
1857
2069
|
);
|
|
1858
2070
|
}
|
|
1859
2071
|
assert(
|
|
1860
|
-
|
|
2072
|
+
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
2073
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt), but is ${typeof parameter} ${parameter}.`
|
|
1862
2074
|
);
|
|
1863
|
-
|
|
2075
|
+
let param;
|
|
2076
|
+
switch (input.type) {
|
|
2077
|
+
case "core::integer::u256" /* u256 */:
|
|
2078
|
+
param = new CairoUint256(parameter).toBigInt();
|
|
2079
|
+
break;
|
|
2080
|
+
case "core::integer::u512" /* u512 */:
|
|
2081
|
+
param = new CairoUint512(parameter).toBigInt();
|
|
2082
|
+
break;
|
|
2083
|
+
default:
|
|
2084
|
+
param = toBigInt(parameter);
|
|
2085
|
+
}
|
|
1864
2086
|
switch (input.type) {
|
|
1865
2087
|
case "core::integer::u8" /* u8 */:
|
|
1866
2088
|
assert(
|
|
@@ -1898,6 +2120,9 @@ var validateUint = (parameter, input) => {
|
|
|
1898
2120
|
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
1899
2121
|
);
|
|
1900
2122
|
break;
|
|
2123
|
+
case "core::integer::u512" /* u512 */:
|
|
2124
|
+
assert(CairoUint512.is(param), `Validate: arg ${input.name} is ${input.type} 0 - 2^512-1`);
|
|
2125
|
+
break;
|
|
1901
2126
|
case "core::starknet::class_hash::ClassHash" /* ClassHash */:
|
|
1902
2127
|
assert(
|
|
1903
2128
|
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1670
|
|
@@ -1912,18 +2137,25 @@ var validateUint = (parameter, input) => {
|
|
|
1912
2137
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
1913
2138
|
);
|
|
1914
2139
|
break;
|
|
2140
|
+
case "core::starknet::secp256k1::Secp256k1Point" /* Secp256k1Point */: {
|
|
2141
|
+
assert(
|
|
2142
|
+
param >= 0n && param <= 2n ** 512n - 1n,
|
|
2143
|
+
`Validate: arg ${input.name} must be ${input.type} : a 512 bits number.`
|
|
2144
|
+
);
|
|
2145
|
+
break;
|
|
2146
|
+
}
|
|
1915
2147
|
default:
|
|
1916
2148
|
break;
|
|
1917
2149
|
}
|
|
1918
2150
|
};
|
|
1919
2151
|
var validateBool = (parameter, input) => {
|
|
1920
2152
|
assert(
|
|
1921
|
-
|
|
2153
|
+
isBoolean(parameter),
|
|
1922
2154
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
1923
2155
|
);
|
|
1924
2156
|
};
|
|
1925
2157
|
var validateStruct = (parameter, input, structs) => {
|
|
1926
|
-
if (input.type === "core::integer::u256" /* u256 */) {
|
|
2158
|
+
if (input.type === "core::integer::u256" /* u256 */ || input.type === "core::integer::u512" /* u512 */) {
|
|
1927
2159
|
validateUint(parameter, input);
|
|
1928
2160
|
return;
|
|
1929
2161
|
}
|
|
@@ -2004,7 +2236,7 @@ var validateArray = (parameter, input, structs, enums) => {
|
|
|
2004
2236
|
parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
|
|
2005
2237
|
break;
|
|
2006
2238
|
case (isTypeUint(baseType) || isTypeLiteral(baseType)):
|
|
2007
|
-
parameter.forEach((param) => validateUint(param,
|
|
2239
|
+
parameter.forEach((param) => validateUint(param, { name: "", type: baseType }));
|
|
2008
2240
|
break;
|
|
2009
2241
|
case isTypeBool(baseType):
|
|
2010
2242
|
parameter.forEach((param) => validateBool(param, input));
|
|
@@ -2684,7 +2916,7 @@ function computeHintedClassHash(compiledContract) {
|
|
|
2684
2916
|
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2685
2917
|
}
|
|
2686
2918
|
function computeLegacyContractClassHash(contract) {
|
|
2687
|
-
const compiledContract =
|
|
2919
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2688
2920
|
const apiVersion = toHex(API_VERSION);
|
|
2689
2921
|
const externalEntryPointsHash = computeHashOnElements2(
|
|
2690
2922
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
@@ -2780,7 +3012,7 @@ function computeSierraContractClassHash(sierra) {
|
|
|
2780
3012
|
);
|
|
2781
3013
|
}
|
|
2782
3014
|
function computeContractClassHash(contract) {
|
|
2783
|
-
const compiledContract =
|
|
3015
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2784
3016
|
if ("sierra_program" in compiledContract) {
|
|
2785
3017
|
return computeSierraContractClassHash(compiledContract);
|
|
2786
3018
|
}
|
|
@@ -2808,7 +3040,7 @@ __export(stark_exports, {
|
|
|
2808
3040
|
import { getStarkKey, utils } from "@scure/starknet";
|
|
2809
3041
|
import { gzip, ungzip } from "pako";
|
|
2810
3042
|
function compressProgram(jsonProgram) {
|
|
2811
|
-
const stringified =
|
|
3043
|
+
const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
|
|
2812
3044
|
const compressedProgram = gzip(stringified);
|
|
2813
3045
|
return btoaUniversal(compressedProgram);
|
|
2814
3046
|
}
|
|
@@ -2848,7 +3080,7 @@ function estimatedFeeToMaxFee(estimatedFee, overhead = 50 /* MAX_FEE */) {
|
|
|
2848
3080
|
return addPercent(estimatedFee, overhead);
|
|
2849
3081
|
}
|
|
2850
3082
|
function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUNT */, priceOverhead = 50 /* L1_BOUND_MAX_PRICE_PER_UNIT */) {
|
|
2851
|
-
if (
|
|
3083
|
+
if (isBigInt(estimate)) {
|
|
2852
3084
|
return {
|
|
2853
3085
|
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
2854
3086
|
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
@@ -2916,7 +3148,7 @@ function reduceV2(providedVersion) {
|
|
|
2916
3148
|
|
|
2917
3149
|
// src/utils/contract.ts
|
|
2918
3150
|
function isSierra(contract) {
|
|
2919
|
-
const compiledContract =
|
|
3151
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2920
3152
|
return "sierra_program" in compiledContract;
|
|
2921
3153
|
}
|
|
2922
3154
|
function extractContractHashes(payload) {
|
|
@@ -2981,7 +3213,7 @@ function createSierraContractClass(contract) {
|
|
|
2981
3213
|
return result;
|
|
2982
3214
|
}
|
|
2983
3215
|
function parseContract(contract) {
|
|
2984
|
-
const parsedContract =
|
|
3216
|
+
const parsedContract = isString(contract) ? parse2(contract) : contract;
|
|
2985
3217
|
if (!isSierra(contract)) {
|
|
2986
3218
|
return {
|
|
2987
3219
|
...parsedContract,
|
|
@@ -2998,7 +3230,7 @@ var getDefaultNodeUrl = (networkName, mute = false) => {
|
|
|
2998
3230
|
return nodes[randIdx];
|
|
2999
3231
|
};
|
|
3000
3232
|
function formatHash(hashValue) {
|
|
3001
|
-
if (
|
|
3233
|
+
if (isString(hashValue))
|
|
3002
3234
|
return hashValue;
|
|
3003
3235
|
return toHex(hashValue);
|
|
3004
3236
|
}
|
|
@@ -3015,14 +3247,16 @@ var Block = class {
|
|
|
3015
3247
|
number = null;
|
|
3016
3248
|
tag = null;
|
|
3017
3249
|
setIdentifier(__identifier) {
|
|
3018
|
-
if (
|
|
3019
|
-
|
|
3020
|
-
|
|
3250
|
+
if (isString(__identifier)) {
|
|
3251
|
+
if (isHex(__identifier)) {
|
|
3252
|
+
this.hash = __identifier;
|
|
3253
|
+
} else if (validBlockTags.includes(__identifier)) {
|
|
3254
|
+
this.tag = __identifier;
|
|
3255
|
+
}
|
|
3256
|
+
} else if (isBigInt(__identifier)) {
|
|
3021
3257
|
this.hash = toHex(__identifier);
|
|
3022
|
-
} else if (
|
|
3258
|
+
} else if (isNumber(__identifier)) {
|
|
3023
3259
|
this.number = __identifier;
|
|
3024
|
-
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3025
|
-
this.tag = __identifier;
|
|
3026
3260
|
} else {
|
|
3027
3261
|
this.tag = "pending" /* pending */;
|
|
3028
3262
|
}
|
|
@@ -4271,7 +4505,7 @@ var RPCResponseParser = class {
|
|
|
4271
4505
|
return { status: "PENDING", ...res };
|
|
4272
4506
|
}
|
|
4273
4507
|
parseTransactionReceipt(res) {
|
|
4274
|
-
if ("actual_fee" in res &&
|
|
4508
|
+
if ("actual_fee" in res && isString(res.actual_fee)) {
|
|
4275
4509
|
return {
|
|
4276
4510
|
...res,
|
|
4277
4511
|
actual_fee: {
|
|
@@ -4315,11 +4549,59 @@ var RPCResponseParser = class {
|
|
|
4315
4549
|
parseContractClassResponse(res) {
|
|
4316
4550
|
return {
|
|
4317
4551
|
...res,
|
|
4318
|
-
abi:
|
|
4552
|
+
abi: isString(res.abi) ? JSON.parse(res.abi) : res.abi
|
|
4319
4553
|
};
|
|
4320
4554
|
}
|
|
4321
4555
|
};
|
|
4322
4556
|
|
|
4557
|
+
// src/utils/transactionReceipt.ts
|
|
4558
|
+
var ReceiptTx = class _ReceiptTx {
|
|
4559
|
+
statusReceipt;
|
|
4560
|
+
value;
|
|
4561
|
+
constructor(receipt) {
|
|
4562
|
+
[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")];
|
|
4563
|
+
for (const [key] of Object.entries(this)) {
|
|
4564
|
+
Object.defineProperty(this, key, {
|
|
4565
|
+
enumerable: false
|
|
4566
|
+
});
|
|
4567
|
+
}
|
|
4568
|
+
for (const [key, value] of Object.entries(receipt)) {
|
|
4569
|
+
Object.defineProperty(this, key, {
|
|
4570
|
+
enumerable: true,
|
|
4571
|
+
writable: false,
|
|
4572
|
+
value
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
match(callbacks) {
|
|
4577
|
+
if (this.statusReceipt in callbacks) {
|
|
4578
|
+
return callbacks[this.statusReceipt](this.value);
|
|
4579
|
+
}
|
|
4580
|
+
return callbacks._();
|
|
4581
|
+
}
|
|
4582
|
+
isSuccess() {
|
|
4583
|
+
return this.statusReceipt === "success";
|
|
4584
|
+
}
|
|
4585
|
+
isReverted() {
|
|
4586
|
+
return this.statusReceipt === "reverted";
|
|
4587
|
+
}
|
|
4588
|
+
isRejected() {
|
|
4589
|
+
return this.statusReceipt === "rejected";
|
|
4590
|
+
}
|
|
4591
|
+
isError() {
|
|
4592
|
+
return this.statusReceipt === "error";
|
|
4593
|
+
}
|
|
4594
|
+
static isSuccess(transactionReceipt) {
|
|
4595
|
+
return transactionReceipt.execution_status === "SUCCEEDED" /* SUCCEEDED */;
|
|
4596
|
+
}
|
|
4597
|
+
static isReverted(transactionReceipt) {
|
|
4598
|
+
return transactionReceipt.execution_status === "REVERTED" /* REVERTED */;
|
|
4599
|
+
}
|
|
4600
|
+
static isRejected(transactionReceipt) {
|
|
4601
|
+
return transactionReceipt.status === "REJECTED" /* REJECTED */;
|
|
4602
|
+
}
|
|
4603
|
+
};
|
|
4604
|
+
|
|
4323
4605
|
// src/provider/rpc.ts
|
|
4324
4606
|
var RpcProvider = class {
|
|
4325
4607
|
responseParser;
|
|
@@ -4404,7 +4686,9 @@ var RpcProvider = class {
|
|
|
4404
4686
|
return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index);
|
|
4405
4687
|
}
|
|
4406
4688
|
async getTransactionReceipt(txHash) {
|
|
4407
|
-
|
|
4689
|
+
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
4690
|
+
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
4691
|
+
return new ReceiptTx(txReceiptWoHelperModified);
|
|
4408
4692
|
}
|
|
4409
4693
|
async getTransactionTrace(txHash) {
|
|
4410
4694
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -4426,7 +4710,11 @@ var RpcProvider = class {
|
|
|
4426
4710
|
return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
|
|
4427
4711
|
}
|
|
4428
4712
|
async waitForTransaction(txHash, options) {
|
|
4429
|
-
|
|
4713
|
+
const receiptWoHelper = await this.channel.waitForTransaction(
|
|
4714
|
+
txHash,
|
|
4715
|
+
options
|
|
4716
|
+
);
|
|
4717
|
+
return new ReceiptTx(receiptWoHelper);
|
|
4430
4718
|
}
|
|
4431
4719
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4432
4720
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -5131,6 +5419,10 @@ var revisionConfiguration = {
|
|
|
5131
5419
|
presetTypes: {}
|
|
5132
5420
|
}
|
|
5133
5421
|
};
|
|
5422
|
+
function assertRange(data, type, { min, max }) {
|
|
5423
|
+
const value = BigInt(data);
|
|
5424
|
+
assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
|
|
5425
|
+
}
|
|
5134
5426
|
function identifyRevision({ types, domain }) {
|
|
5135
5427
|
if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
|
|
5136
5428
|
return "1" /* Active */;
|
|
@@ -5142,7 +5434,7 @@ function getHex(value) {
|
|
|
5142
5434
|
try {
|
|
5143
5435
|
return toHex(value);
|
|
5144
5436
|
} catch (e) {
|
|
5145
|
-
if (
|
|
5437
|
+
if (isString(value)) {
|
|
5146
5438
|
return toHex(encodeShortString(value));
|
|
5147
5439
|
}
|
|
5148
5440
|
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
@@ -5293,15 +5585,41 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
|
|
|
5293
5585
|
}
|
|
5294
5586
|
return [type, getHex(data)];
|
|
5295
5587
|
}
|
|
5588
|
+
case "i128": {
|
|
5589
|
+
if (revision === "1" /* Active */) {
|
|
5590
|
+
const value = BigInt(data);
|
|
5591
|
+
assertRange(value, type, RANGE_I128);
|
|
5592
|
+
return [type, getHex(value < 0n ? PRIME + value : value)];
|
|
5593
|
+
}
|
|
5594
|
+
return [type, getHex(data)];
|
|
5595
|
+
}
|
|
5596
|
+
case "timestamp":
|
|
5597
|
+
case "u128": {
|
|
5598
|
+
if (revision === "1" /* Active */) {
|
|
5599
|
+
assertRange(data, type, RANGE_U128);
|
|
5600
|
+
}
|
|
5601
|
+
return [type, getHex(data)];
|
|
5602
|
+
}
|
|
5296
5603
|
case "felt":
|
|
5297
|
-
case "
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5604
|
+
case "shortstring": {
|
|
5605
|
+
if (revision === "1" /* Active */) {
|
|
5606
|
+
assertRange(getHex(data), type, RANGE_FELT);
|
|
5607
|
+
}
|
|
5608
|
+
return [type, getHex(data)];
|
|
5609
|
+
}
|
|
5301
5610
|
case "ClassHash":
|
|
5302
|
-
case "
|
|
5303
|
-
|
|
5611
|
+
case "ContractAddress": {
|
|
5612
|
+
if (revision === "1" /* Active */) {
|
|
5613
|
+
assertRange(data, type, RANGE_FELT);
|
|
5614
|
+
}
|
|
5304
5615
|
return [type, getHex(data)];
|
|
5616
|
+
}
|
|
5617
|
+
case "bool": {
|
|
5618
|
+
if (revision === "1" /* Active */) {
|
|
5619
|
+
assert(typeof data === "boolean", `Type mismatch for ${type} ${data}`);
|
|
5620
|
+
}
|
|
5621
|
+
return [type, getHex(data)];
|
|
5622
|
+
}
|
|
5305
5623
|
default: {
|
|
5306
5624
|
if (revision === "1" /* Active */) {
|
|
5307
5625
|
throw new Error(`Unsupported type: ${type}`);
|
|
@@ -5451,19 +5769,48 @@ function ethRandomPrivateKey() {
|
|
|
5451
5769
|
return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
|
|
5452
5770
|
}
|
|
5453
5771
|
|
|
5772
|
+
// src/utils/uint256.ts
|
|
5773
|
+
var uint256_exports = {};
|
|
5774
|
+
__export(uint256_exports, {
|
|
5775
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
5776
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
5777
|
+
bnToUint256: () => bnToUint256,
|
|
5778
|
+
isUint256: () => isUint256,
|
|
5779
|
+
uint256ToBN: () => uint256ToBN
|
|
5780
|
+
});
|
|
5781
|
+
function uint256ToBN(uint2562) {
|
|
5782
|
+
return new CairoUint256(uint2562).toBigInt();
|
|
5783
|
+
}
|
|
5784
|
+
function isUint256(bn) {
|
|
5785
|
+
return CairoUint256.is(bn);
|
|
5786
|
+
}
|
|
5787
|
+
function bnToUint256(bn) {
|
|
5788
|
+
return new CairoUint256(bn).toUint256HexString();
|
|
5789
|
+
}
|
|
5790
|
+
|
|
5454
5791
|
// src/signer/ethSigner.ts
|
|
5455
5792
|
var EthSigner = class {
|
|
5456
5793
|
pk;
|
|
5457
|
-
// hex string without 0x and odd number of characters
|
|
5794
|
+
// hex string without 0x and with an odd number of characters
|
|
5458
5795
|
constructor(pk = ethRandomPrivateKey()) {
|
|
5459
|
-
this.pk = pk instanceof Uint8Array ?
|
|
5796
|
+
this.pk = pk instanceof Uint8Array ? buf2hex(pk).padStart(64, "0") : removeHexPrefix(toHex(pk)).padStart(64, "0");
|
|
5460
5797
|
}
|
|
5798
|
+
/**
|
|
5799
|
+
* provides the Ethereum full public key (without parity prefix)
|
|
5800
|
+
* @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
5801
|
+
*/
|
|
5461
5802
|
async getPubKey() {
|
|
5462
|
-
return addHexPrefix(
|
|
5803
|
+
return addHexPrefix(
|
|
5804
|
+
buf2hex(secp256k12.getPublicKey(this.pk, false)).padStart(130, "0").slice(2)
|
|
5805
|
+
);
|
|
5463
5806
|
}
|
|
5464
5807
|
async signMessage(typedData, accountAddress) {
|
|
5465
5808
|
const msgHash = getMessageHash(typedData, accountAddress);
|
|
5466
|
-
|
|
5809
|
+
const signature = secp256k12.sign(
|
|
5810
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5811
|
+
this.pk
|
|
5812
|
+
);
|
|
5813
|
+
return this.formatEthSignature(signature);
|
|
5467
5814
|
}
|
|
5468
5815
|
async signTransaction(transactions, details) {
|
|
5469
5816
|
const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
|
|
@@ -5489,7 +5836,11 @@ var EthSigner = class {
|
|
|
5489
5836
|
} else {
|
|
5490
5837
|
throw Error("unsupported signTransaction version");
|
|
5491
5838
|
}
|
|
5492
|
-
|
|
5839
|
+
const signature = secp256k12.sign(
|
|
5840
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5841
|
+
this.pk
|
|
5842
|
+
);
|
|
5843
|
+
return this.formatEthSignature(signature);
|
|
5493
5844
|
}
|
|
5494
5845
|
async signDeployAccountTransaction(details) {
|
|
5495
5846
|
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
@@ -5515,7 +5866,11 @@ var EthSigner = class {
|
|
|
5515
5866
|
} else {
|
|
5516
5867
|
throw Error("unsupported signDeployAccountTransaction version");
|
|
5517
5868
|
}
|
|
5518
|
-
|
|
5869
|
+
const signature = secp256k12.sign(
|
|
5870
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5871
|
+
this.pk
|
|
5872
|
+
);
|
|
5873
|
+
return this.formatEthSignature(signature);
|
|
5519
5874
|
}
|
|
5520
5875
|
async signDeclareTransaction(details) {
|
|
5521
5876
|
let msgHash;
|
|
@@ -5536,7 +5891,27 @@ var EthSigner = class {
|
|
|
5536
5891
|
} else {
|
|
5537
5892
|
throw Error("unsupported signDeclareTransaction version");
|
|
5538
5893
|
}
|
|
5539
|
-
|
|
5894
|
+
const signature = secp256k12.sign(
|
|
5895
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5896
|
+
this.pk
|
|
5897
|
+
);
|
|
5898
|
+
return this.formatEthSignature(signature);
|
|
5899
|
+
}
|
|
5900
|
+
/**
|
|
5901
|
+
* Serialize the signature in conformity with starknet::eth_signature::Signature
|
|
5902
|
+
* @param ethSignature secp256k1 signature from Noble curves library
|
|
5903
|
+
* @return an array of felts, representing a Cairo Eth Signature.
|
|
5904
|
+
*/
|
|
5905
|
+
formatEthSignature(ethSignature) {
|
|
5906
|
+
const r = bnToUint256(ethSignature.r);
|
|
5907
|
+
const s = bnToUint256(ethSignature.s);
|
|
5908
|
+
return [
|
|
5909
|
+
toHex(r.low),
|
|
5910
|
+
toHex(r.high),
|
|
5911
|
+
toHex(s.low),
|
|
5912
|
+
toHex(s.high),
|
|
5913
|
+
toHex(ethSignature.recovery)
|
|
5914
|
+
];
|
|
5540
5915
|
}
|
|
5541
5916
|
};
|
|
5542
5917
|
|
|
@@ -5572,7 +5947,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5572
5947
|
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = "0x2" /* V2 */) {
|
|
5573
5948
|
super(providerOrOptions);
|
|
5574
5949
|
this.address = address.toLowerCase();
|
|
5575
|
-
this.signer =
|
|
5950
|
+
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
5576
5951
|
if (cairoVersion) {
|
|
5577
5952
|
this.cairoVersion = cairoVersion.toString();
|
|
5578
5953
|
}
|
|
@@ -5713,7 +6088,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5713
6088
|
return this.estimateInvokeFee(calls, details);
|
|
5714
6089
|
}
|
|
5715
6090
|
async estimateFeeBulk(invocations, details = {}) {
|
|
5716
|
-
const { nonce, blockIdentifier, version } = details;
|
|
6091
|
+
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
5717
6092
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
5718
6093
|
...v3Details(details),
|
|
5719
6094
|
versions: [
|
|
@@ -5726,11 +6101,12 @@ var Account = class extends RpcProvider2 {
|
|
|
5726
6101
|
// sierra
|
|
5727
6102
|
],
|
|
5728
6103
|
nonce,
|
|
5729
|
-
blockIdentifier
|
|
6104
|
+
blockIdentifier,
|
|
6105
|
+
skipValidate
|
|
5730
6106
|
});
|
|
5731
6107
|
return super.getEstimateFeeBulk(accountInvocations, {
|
|
5732
6108
|
blockIdentifier,
|
|
5733
|
-
skipValidate
|
|
6109
|
+
skipValidate
|
|
5734
6110
|
});
|
|
5735
6111
|
}
|
|
5736
6112
|
async simulateTransaction(invocations, details = {}) {
|
|
@@ -6734,25 +7110,6 @@ var ContractFactory = class {
|
|
|
6734
7110
|
// 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
7111
|
};
|
|
6736
7112
|
|
|
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
7113
|
// src/utils/address.ts
|
|
6757
7114
|
import { hexToBytes as hexToBytes2 } from "@noble/curves/abstract/utils";
|
|
6758
7115
|
function addAddressPadding(address) {
|
|
@@ -6825,6 +7182,8 @@ export {
|
|
|
6825
7182
|
CairoOptionVariant,
|
|
6826
7183
|
CairoResult,
|
|
6827
7184
|
CairoResultVariant,
|
|
7185
|
+
CairoUint256,
|
|
7186
|
+
CairoUint512,
|
|
6828
7187
|
CallData,
|
|
6829
7188
|
Contract,
|
|
6830
7189
|
ContractFactory,
|
|
@@ -6841,6 +7200,7 @@ export {
|
|
|
6841
7200
|
api_exports as RPC,
|
|
6842
7201
|
rpc_0_6_exports as RPC06,
|
|
6843
7202
|
rpc_0_7_exports as RPC07,
|
|
7203
|
+
ReceiptTx,
|
|
6844
7204
|
RpcChannel2 as RpcChannel,
|
|
6845
7205
|
RpcProvider2 as RpcProvider,
|
|
6846
7206
|
SIMULATION_FLAG,
|
|
@@ -6851,6 +7211,16 @@ export {
|
|
|
6851
7211
|
TransactionStatus,
|
|
6852
7212
|
TransactionType,
|
|
6853
7213
|
TypedDataRevision,
|
|
7214
|
+
UINT_128_MAX,
|
|
7215
|
+
UINT_128_MIN,
|
|
7216
|
+
UINT_256_HIGH_MAX,
|
|
7217
|
+
UINT_256_HIGH_MIN,
|
|
7218
|
+
UINT_256_LOW_MAX,
|
|
7219
|
+
UINT_256_LOW_MIN,
|
|
7220
|
+
UINT_256_MAX,
|
|
7221
|
+
UINT_256_MIN,
|
|
7222
|
+
UINT_512_MAX,
|
|
7223
|
+
UINT_512_MIN,
|
|
6854
7224
|
Uint,
|
|
6855
7225
|
ValidateType,
|
|
6856
7226
|
WalletAccount,
|