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.js
CHANGED
|
@@ -39,6 +39,8 @@ __export(src_exports, {
|
|
|
39
39
|
CairoOptionVariant: () => CairoOptionVariant,
|
|
40
40
|
CairoResult: () => CairoResult,
|
|
41
41
|
CairoResultVariant: () => CairoResultVariant,
|
|
42
|
+
CairoUint256: () => CairoUint256,
|
|
43
|
+
CairoUint512: () => CairoUint512,
|
|
42
44
|
CallData: () => CallData,
|
|
43
45
|
Contract: () => Contract,
|
|
44
46
|
ContractFactory: () => ContractFactory,
|
|
@@ -55,6 +57,7 @@ __export(src_exports, {
|
|
|
55
57
|
RPC: () => api_exports,
|
|
56
58
|
RPC06: () => rpc_0_6_exports,
|
|
57
59
|
RPC07: () => rpc_0_7_exports,
|
|
60
|
+
ReceiptTx: () => ReceiptTx,
|
|
58
61
|
RpcChannel: () => RpcChannel2,
|
|
59
62
|
RpcProvider: () => RpcProvider2,
|
|
60
63
|
SIMULATION_FLAG: () => SIMULATION_FLAG,
|
|
@@ -65,6 +68,16 @@ __export(src_exports, {
|
|
|
65
68
|
TransactionStatus: () => TransactionStatus,
|
|
66
69
|
TransactionType: () => TransactionType,
|
|
67
70
|
TypedDataRevision: () => TypedDataRevision,
|
|
71
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
72
|
+
UINT_128_MIN: () => UINT_128_MIN,
|
|
73
|
+
UINT_256_HIGH_MAX: () => UINT_256_HIGH_MAX,
|
|
74
|
+
UINT_256_HIGH_MIN: () => UINT_256_HIGH_MIN,
|
|
75
|
+
UINT_256_LOW_MAX: () => UINT_256_LOW_MAX,
|
|
76
|
+
UINT_256_LOW_MIN: () => UINT_256_LOW_MIN,
|
|
77
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
78
|
+
UINT_256_MIN: () => UINT_256_MIN,
|
|
79
|
+
UINT_512_MAX: () => UINT_512_MAX,
|
|
80
|
+
UINT_512_MIN: () => UINT_512_MIN,
|
|
68
81
|
Uint: () => Uint,
|
|
69
82
|
ValidateType: () => ValidateType,
|
|
70
83
|
WalletAccount: () => WalletAccount,
|
|
@@ -133,6 +146,10 @@ __export(constants_exports, {
|
|
|
133
146
|
MASK_250: () => MASK_250,
|
|
134
147
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
135
148
|
NetworkName: () => NetworkName,
|
|
149
|
+
PRIME: () => PRIME,
|
|
150
|
+
RANGE_FELT: () => RANGE_FELT,
|
|
151
|
+
RANGE_I128: () => RANGE_I128,
|
|
152
|
+
RANGE_U128: () => RANGE_U128,
|
|
136
153
|
RPC_DEFAULT_VERSION: () => RPC_DEFAULT_VERSION,
|
|
137
154
|
RPC_NODES: () => RPC_NODES,
|
|
138
155
|
StarknetChainId: () => StarknetChainId,
|
|
@@ -440,8 +457,13 @@ var TEXT_TO_FELT_MAX_LEN = 31;
|
|
|
440
457
|
var ZERO = 0n;
|
|
441
458
|
var MASK_250 = 2n ** 250n - 1n;
|
|
442
459
|
var API_VERSION = ZERO;
|
|
460
|
+
var PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
443
461
|
var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
444
462
|
var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
463
|
+
var range = (min, max) => ({ min, max });
|
|
464
|
+
var RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
465
|
+
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
466
|
+
var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
445
467
|
var BaseUrl = /* @__PURE__ */ ((BaseUrl2) => {
|
|
446
468
|
BaseUrl2["SN_MAIN"] = "https://alpha-mainnet.starknet.io";
|
|
447
469
|
BaseUrl2["SN_GOERLI"] = "https://alpha4.starknet.io";
|
|
@@ -576,11 +598,13 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
|
|
|
576
598
|
Uint2["u64"] = "core::integer::u64";
|
|
577
599
|
Uint2["u128"] = "core::integer::u128";
|
|
578
600
|
Uint2["u256"] = "core::integer::u256";
|
|
601
|
+
Uint2["u512"] = "core::integer::u512";
|
|
579
602
|
return Uint2;
|
|
580
603
|
})(Uint || {});
|
|
581
604
|
var Literal = /* @__PURE__ */ ((Literal2) => {
|
|
582
605
|
Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
|
|
583
606
|
Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
|
|
607
|
+
Literal2["Secp256k1Point"] = "core::starknet::secp256k1::Secp256k1Point";
|
|
584
608
|
return Literal2;
|
|
585
609
|
})(Literal || {});
|
|
586
610
|
|
|
@@ -663,7 +687,9 @@ __export(num_exports, {
|
|
|
663
687
|
hexToBytes: () => hexToBytes,
|
|
664
688
|
hexToDecimalString: () => hexToDecimalString,
|
|
665
689
|
isBigInt: () => isBigInt,
|
|
690
|
+
isBoolean: () => isBoolean,
|
|
666
691
|
isHex: () => isHex,
|
|
692
|
+
isNumber: () => isNumber,
|
|
667
693
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
668
694
|
toBigInt: () => toBigInt,
|
|
669
695
|
toCairoBool: () => toCairoBool,
|
|
@@ -745,6 +771,12 @@ function addPercent(number2, percent) {
|
|
|
745
771
|
const bigIntNum = BigInt(number2);
|
|
746
772
|
return bigIntNum + bigIntNum * BigInt(percent) / 100n;
|
|
747
773
|
}
|
|
774
|
+
function isNumber(value) {
|
|
775
|
+
return typeof value === "number";
|
|
776
|
+
}
|
|
777
|
+
function isBoolean(value) {
|
|
778
|
+
return typeof value === "boolean";
|
|
779
|
+
}
|
|
748
780
|
|
|
749
781
|
// src/utils/selector.ts
|
|
750
782
|
var selector_exports = {};
|
|
@@ -790,6 +822,7 @@ __export(shortString_exports, {
|
|
|
790
822
|
isLongText: () => isLongText,
|
|
791
823
|
isShortString: () => isShortString,
|
|
792
824
|
isShortText: () => isShortText,
|
|
825
|
+
isString: () => isString,
|
|
793
826
|
isText: () => isText,
|
|
794
827
|
splitLongString: () => splitLongString
|
|
795
828
|
});
|
|
@@ -802,8 +835,11 @@ function isShortString(str) {
|
|
|
802
835
|
function isDecimalString(str) {
|
|
803
836
|
return /^[0-9]*$/i.test(str);
|
|
804
837
|
}
|
|
838
|
+
function isString(value) {
|
|
839
|
+
return typeof value === "string";
|
|
840
|
+
}
|
|
805
841
|
function isText(val) {
|
|
806
|
-
return
|
|
842
|
+
return isString(val) && !isHex(val) && !isStringWholeNumber(val);
|
|
807
843
|
}
|
|
808
844
|
var isShortText = (val) => isText(val) && isShortString(val);
|
|
809
845
|
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
@@ -876,34 +912,38 @@ __export(cairo_exports, {
|
|
|
876
912
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
877
913
|
isTypeOption: () => isTypeOption,
|
|
878
914
|
isTypeResult: () => isTypeResult,
|
|
915
|
+
isTypeSecp256k1Point: () => isTypeSecp256k1Point,
|
|
879
916
|
isTypeStruct: () => isTypeStruct,
|
|
880
917
|
isTypeTuple: () => isTypeTuple,
|
|
881
918
|
isTypeUint: () => isTypeUint,
|
|
882
919
|
isTypeUint256: () => isTypeUint256,
|
|
883
920
|
tuple: () => tuple,
|
|
884
|
-
uint256: () => uint256
|
|
921
|
+
uint256: () => uint256,
|
|
922
|
+
uint512: () => uint512
|
|
885
923
|
});
|
|
886
924
|
|
|
887
925
|
// src/utils/cairoDataTypes/felt.ts
|
|
888
926
|
function CairoFelt(it) {
|
|
889
|
-
if (isBigInt(it) ||
|
|
927
|
+
if (isBigInt(it) || Number.isInteger(it)) {
|
|
890
928
|
return it.toString();
|
|
891
929
|
}
|
|
892
|
-
if (
|
|
893
|
-
if (
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
930
|
+
if (isString(it)) {
|
|
931
|
+
if (isHex(it)) {
|
|
932
|
+
return BigInt(it).toString();
|
|
933
|
+
}
|
|
934
|
+
if (isText(it)) {
|
|
935
|
+
if (!isShortString(it)) {
|
|
936
|
+
throw new Error(
|
|
937
|
+
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
return BigInt(encodeShortString(it)).toString();
|
|
941
|
+
}
|
|
942
|
+
if (isStringWholeNumber(it)) {
|
|
943
|
+
return it;
|
|
944
|
+
}
|
|
905
945
|
}
|
|
906
|
-
if (
|
|
946
|
+
if (isBoolean(it)) {
|
|
907
947
|
return `${+it}`;
|
|
908
948
|
}
|
|
909
949
|
throw new Error(`${it} can't be computed by felt()`);
|
|
@@ -1014,6 +1054,130 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1014
1054
|
}
|
|
1015
1055
|
};
|
|
1016
1056
|
|
|
1057
|
+
// src/utils/cairoDataTypes/uint512.ts
|
|
1058
|
+
var UINT_512_MAX = (1n << 512n) - 1n;
|
|
1059
|
+
var UINT_512_MIN = 0n;
|
|
1060
|
+
var UINT_128_MIN = 0n;
|
|
1061
|
+
var CairoUint512 = class _CairoUint512 {
|
|
1062
|
+
limb0;
|
|
1063
|
+
limb1;
|
|
1064
|
+
limb2;
|
|
1065
|
+
limb3;
|
|
1066
|
+
static abiSelector = "core::integer::u512";
|
|
1067
|
+
constructor(...arr) {
|
|
1068
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
1069
|
+
const props = _CairoUint512.validateProps(
|
|
1070
|
+
arr[0].limb0,
|
|
1071
|
+
arr[0].limb1,
|
|
1072
|
+
arr[0].limb2,
|
|
1073
|
+
arr[0].limb3
|
|
1074
|
+
);
|
|
1075
|
+
this.limb0 = props.limb0;
|
|
1076
|
+
this.limb1 = props.limb1;
|
|
1077
|
+
this.limb2 = props.limb2;
|
|
1078
|
+
this.limb3 = props.limb3;
|
|
1079
|
+
} else if (arr.length === 1) {
|
|
1080
|
+
const bigInt = _CairoUint512.validate(arr[0]);
|
|
1081
|
+
this.limb0 = bigInt & UINT_128_MAX;
|
|
1082
|
+
this.limb1 = (bigInt & UINT_128_MAX << 128n) >> 128n;
|
|
1083
|
+
this.limb2 = (bigInt & UINT_128_MAX << 256n) >> 256n;
|
|
1084
|
+
this.limb3 = bigInt >> 384n;
|
|
1085
|
+
} else if (arr.length === 4) {
|
|
1086
|
+
const props = _CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
|
|
1087
|
+
this.limb0 = props.limb0;
|
|
1088
|
+
this.limb1 = props.limb1;
|
|
1089
|
+
this.limb2 = props.limb2;
|
|
1090
|
+
this.limb3 = props.limb3;
|
|
1091
|
+
} else {
|
|
1092
|
+
throw Error("Incorrect Uint512 constructor parameters");
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
1097
|
+
*/
|
|
1098
|
+
static validate(bigNumberish) {
|
|
1099
|
+
const bigInt = BigInt(bigNumberish);
|
|
1100
|
+
if (bigInt < UINT_512_MIN)
|
|
1101
|
+
throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
1102
|
+
if (bigInt > UINT_512_MAX)
|
|
1103
|
+
throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
1104
|
+
return bigInt;
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Validate if limbs can be represented as Uint512
|
|
1108
|
+
*/
|
|
1109
|
+
static validateProps(limb0, limb1, limb2, limb3) {
|
|
1110
|
+
const l0 = BigInt(limb0);
|
|
1111
|
+
const l1 = BigInt(limb1);
|
|
1112
|
+
const l2 = BigInt(limb2);
|
|
1113
|
+
const l3 = BigInt(limb3);
|
|
1114
|
+
[l0, l1, l2, l3].forEach((value, index) => {
|
|
1115
|
+
if (value < UINT_128_MIN || value > UINT_128_MAX) {
|
|
1116
|
+
throw Error(`limb${index} is not in the range of a u128 number`);
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Check if BigNumberish can be represented as Uint512
|
|
1123
|
+
*/
|
|
1124
|
+
static is(bigNumberish) {
|
|
1125
|
+
try {
|
|
1126
|
+
_CairoUint512.validate(bigNumberish);
|
|
1127
|
+
} catch (error) {
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
return true;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Check if provided abi type is this data type
|
|
1134
|
+
*/
|
|
1135
|
+
static isAbiType(abiType) {
|
|
1136
|
+
return abiType === _CairoUint512.abiSelector;
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Return bigint representation
|
|
1140
|
+
*/
|
|
1141
|
+
toBigInt() {
|
|
1142
|
+
return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Return Uint512 structure with HexString props
|
|
1146
|
+
* limbx: HexString
|
|
1147
|
+
*/
|
|
1148
|
+
toUint512HexString() {
|
|
1149
|
+
return {
|
|
1150
|
+
limb0: addHexPrefix(this.limb0.toString(16)),
|
|
1151
|
+
limb1: addHexPrefix(this.limb1.toString(16)),
|
|
1152
|
+
limb2: addHexPrefix(this.limb2.toString(16)),
|
|
1153
|
+
limb3: addHexPrefix(this.limb3.toString(16))
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Return Uint512 structure with DecimalString props
|
|
1158
|
+
* limbx DecString
|
|
1159
|
+
*/
|
|
1160
|
+
toUint512DecimalString() {
|
|
1161
|
+
return {
|
|
1162
|
+
limb0: this.limb0.toString(10),
|
|
1163
|
+
limb1: this.limb1.toString(10),
|
|
1164
|
+
limb2: this.limb2.toString(10),
|
|
1165
|
+
limb3: this.limb3.toString(10)
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Return api requests representation witch is felt array
|
|
1170
|
+
*/
|
|
1171
|
+
toApiRequest() {
|
|
1172
|
+
return [
|
|
1173
|
+
CairoFelt(this.limb0),
|
|
1174
|
+
CairoFelt(this.limb1),
|
|
1175
|
+
CairoFelt(this.limb2),
|
|
1176
|
+
CairoFelt(this.limb3)
|
|
1177
|
+
];
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1017
1181
|
// src/utils/calldata/cairo.ts
|
|
1018
1182
|
var isLen = (name) => /_len$/.test(name);
|
|
1019
1183
|
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
@@ -1032,6 +1196,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
|
|
|
1032
1196
|
var isTypeEthAddress = (type) => type === "core::starknet::eth_address::EthAddress";
|
|
1033
1197
|
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
1034
1198
|
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
1199
|
+
var isTypeSecp256k1Point = (type) => type === "core::starknet::secp256k1::Secp256k1Point";
|
|
1035
1200
|
var isCairo1Type = (type) => type.includes("::");
|
|
1036
1201
|
var getArrayType = (type) => {
|
|
1037
1202
|
if (isCairo1Type(type)) {
|
|
@@ -1065,6 +1230,9 @@ function getAbiContractVersion(abi) {
|
|
|
1065
1230
|
var uint256 = (it) => {
|
|
1066
1231
|
return new CairoUint256(it).toUint256DecimalString();
|
|
1067
1232
|
};
|
|
1233
|
+
var uint512 = (it) => {
|
|
1234
|
+
return new CairoUint512(it).toUint512DecimalString();
|
|
1235
|
+
};
|
|
1068
1236
|
var tuple = (...args) => ({ ...args });
|
|
1069
1237
|
function felt(it) {
|
|
1070
1238
|
return CairoFelt(it);
|
|
@@ -1469,6 +1637,11 @@ function errorU256(key) {
|
|
|
1469
1637
|
`Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
|
|
1470
1638
|
);
|
|
1471
1639
|
}
|
|
1640
|
+
function errorU512(key) {
|
|
1641
|
+
return Error(
|
|
1642
|
+
`Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1472
1645
|
function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
1473
1646
|
const orderInput = (unorderedItem, abiType) => {
|
|
1474
1647
|
if (isTypeArray(abiType)) {
|
|
@@ -1487,6 +1660,9 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1487
1660
|
if (isTypeByteArray(abiType)) {
|
|
1488
1661
|
return unorderedItem;
|
|
1489
1662
|
}
|
|
1663
|
+
if (isTypeSecp256k1Point(abiType)) {
|
|
1664
|
+
return unorderedItem;
|
|
1665
|
+
}
|
|
1490
1666
|
if (CairoUint256.isAbiType(abiType)) {
|
|
1491
1667
|
const u256 = unorderedItem;
|
|
1492
1668
|
if (typeof u256 !== "object") {
|
|
@@ -1497,6 +1673,16 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1497
1673
|
}
|
|
1498
1674
|
return { low: u256.low, high: u256.high };
|
|
1499
1675
|
}
|
|
1676
|
+
if (CairoUint512.isAbiType(abiType)) {
|
|
1677
|
+
const u512 = unorderedItem;
|
|
1678
|
+
if (typeof u512 !== "object") {
|
|
1679
|
+
return u512;
|
|
1680
|
+
}
|
|
1681
|
+
if (!["limb0", "limb1", "limb2", "limb3"].every((key) => key in u512)) {
|
|
1682
|
+
throw errorU512(abiType);
|
|
1683
|
+
}
|
|
1684
|
+
return { limb0: u512.limb0, limb1: u512.limb1, limb2: u512.limb2, limb3: u512.limb3 };
|
|
1685
|
+
}
|
|
1500
1686
|
if (isTypeStruct(abiType, structs)) {
|
|
1501
1687
|
const abiOfStruct = structs[abiType].members;
|
|
1502
1688
|
return orderStruct(unorderedItem, abiOfStruct);
|
|
@@ -1521,7 +1707,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1521
1707
|
};
|
|
1522
1708
|
function orderArray(myArray, abiParam) {
|
|
1523
1709
|
const typeInArray = getArrayType(abiParam);
|
|
1524
|
-
if (
|
|
1710
|
+
if (isString(myArray)) {
|
|
1525
1711
|
return myArray;
|
|
1526
1712
|
}
|
|
1527
1713
|
return myArray.map((myElem) => orderInput(myElem, typeInArray));
|
|
@@ -1612,8 +1798,21 @@ function parseBaseTypes(type, val) {
|
|
|
1612
1798
|
switch (true) {
|
|
1613
1799
|
case CairoUint256.isAbiType(type):
|
|
1614
1800
|
return new CairoUint256(val).toApiRequest();
|
|
1801
|
+
case CairoUint512.isAbiType(type):
|
|
1802
|
+
return new CairoUint512(val).toApiRequest();
|
|
1615
1803
|
case isTypeBytes31(type):
|
|
1616
1804
|
return encodeShortString(val.toString());
|
|
1805
|
+
case isTypeSecp256k1Point(type): {
|
|
1806
|
+
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
1807
|
+
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
1808
|
+
const pubKeyETHx = uint256(addHexPrefix(pubKeyETH.slice(0, -64)));
|
|
1809
|
+
return [
|
|
1810
|
+
felt(pubKeyETHx.low),
|
|
1811
|
+
felt(pubKeyETHx.high),
|
|
1812
|
+
felt(pubKeyETHy.low),
|
|
1813
|
+
felt(pubKeyETHy.high)
|
|
1814
|
+
];
|
|
1815
|
+
}
|
|
1617
1816
|
default:
|
|
1618
1817
|
return felt(val);
|
|
1619
1818
|
}
|
|
@@ -1660,6 +1859,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1660
1859
|
if (CairoUint256.isAbiType(type)) {
|
|
1661
1860
|
return new CairoUint256(element).toApiRequest();
|
|
1662
1861
|
}
|
|
1862
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1863
|
+
return new CairoUint512(element).toApiRequest();
|
|
1864
|
+
}
|
|
1663
1865
|
if (type === "core::starknet::eth_address::EthAddress")
|
|
1664
1866
|
return parseBaseTypes(type, element);
|
|
1665
1867
|
if (type === "core::byte_array::ByteArray")
|
|
@@ -1680,6 +1882,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1680
1882
|
if (CairoUint256.isAbiType(type)) {
|
|
1681
1883
|
return new CairoUint256(element).toApiRequest();
|
|
1682
1884
|
}
|
|
1885
|
+
if (CairoUint512.isAbiType(type)) {
|
|
1886
|
+
return new CairoUint512(element).toApiRequest();
|
|
1887
|
+
}
|
|
1683
1888
|
if (isTypeEnum(type, enums)) {
|
|
1684
1889
|
const { variants } = enums[type];
|
|
1685
1890
|
if (isTypeOption(type)) {
|
|
@@ -1772,13 +1977,13 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
1772
1977
|
if (!Array.isArray(value) && !isText(value)) {
|
|
1773
1978
|
throw Error(`ABI expected parameter ${name} to be array or long string, got ${value}`);
|
|
1774
1979
|
}
|
|
1775
|
-
if (
|
|
1980
|
+
if (isString(value)) {
|
|
1776
1981
|
value = splitLongString(value);
|
|
1777
1982
|
}
|
|
1778
1983
|
return parseCalldataValue(value, input.type, structs, enums);
|
|
1779
1984
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1780
1985
|
return parseBaseTypes(type, value);
|
|
1781
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
1986
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type) || CairoUint256.isAbiType(type)):
|
|
1782
1987
|
return parseCalldataValue(value, type, structs, enums);
|
|
1783
1988
|
case isTypeEnum(type, enums):
|
|
1784
1989
|
return parseCalldataValue(
|
|
@@ -1803,12 +2008,25 @@ function parseBaseTypes2(type, it) {
|
|
|
1803
2008
|
const low = it.next().value;
|
|
1804
2009
|
const high = it.next().value;
|
|
1805
2010
|
return new CairoUint256(low, high).toBigInt();
|
|
2011
|
+
case CairoUint512.isAbiType(type):
|
|
2012
|
+
const limb0 = it.next().value;
|
|
2013
|
+
const limb1 = it.next().value;
|
|
2014
|
+
const limb2 = it.next().value;
|
|
2015
|
+
const limb3 = it.next().value;
|
|
2016
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
1806
2017
|
case type === "core::starknet::eth_address::EthAddress":
|
|
1807
2018
|
temp = it.next().value;
|
|
1808
2019
|
return BigInt(temp);
|
|
1809
2020
|
case type === "core::bytes_31::bytes31":
|
|
1810
2021
|
temp = it.next().value;
|
|
1811
2022
|
return decodeShortString(temp);
|
|
2023
|
+
case isTypeSecp256k1Point(type):
|
|
2024
|
+
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2025
|
+
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2026
|
+
const yLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2027
|
+
const yHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2028
|
+
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
2029
|
+
return pubK;
|
|
1812
2030
|
default:
|
|
1813
2031
|
temp = it.next().value;
|
|
1814
2032
|
return BigInt(temp);
|
|
@@ -1823,6 +2041,13 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
1823
2041
|
const high = responseIterator.next().value;
|
|
1824
2042
|
return new CairoUint256(low, high).toBigInt();
|
|
1825
2043
|
}
|
|
2044
|
+
if (CairoUint512.isAbiType(element.type)) {
|
|
2045
|
+
const limb0 = responseIterator.next().value;
|
|
2046
|
+
const limb1 = responseIterator.next().value;
|
|
2047
|
+
const limb2 = responseIterator.next().value;
|
|
2048
|
+
const limb3 = responseIterator.next().value;
|
|
2049
|
+
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
2050
|
+
}
|
|
1826
2051
|
if (isTypeByteArray(element.type)) {
|
|
1827
2052
|
const parsedBytes31Arr = [];
|
|
1828
2053
|
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
@@ -1946,10 +2171,10 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
1946
2171
|
// src/utils/calldata/validate.ts
|
|
1947
2172
|
var validateFelt = (parameter, input) => {
|
|
1948
2173
|
assert(
|
|
1949
|
-
|
|
2174
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
1950
2175
|
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
1951
2176
|
);
|
|
1952
|
-
if (
|
|
2177
|
+
if (isString(parameter) && !isHex(parameter))
|
|
1953
2178
|
return;
|
|
1954
2179
|
const param = BigInt(parameter.toString(10));
|
|
1955
2180
|
assert(
|
|
@@ -1959,27 +2184,37 @@ var validateFelt = (parameter, input) => {
|
|
|
1959
2184
|
);
|
|
1960
2185
|
};
|
|
1961
2186
|
var validateBytes31 = (parameter, input) => {
|
|
1962
|
-
assert(
|
|
2187
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1963
2188
|
assert(
|
|
1964
2189
|
parameter.length < 32,
|
|
1965
2190
|
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
1966
2191
|
);
|
|
1967
2192
|
};
|
|
1968
2193
|
var validateByteArray = (parameter, input) => {
|
|
1969
|
-
assert(
|
|
2194
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
1970
2195
|
};
|
|
1971
2196
|
var validateUint = (parameter, input) => {
|
|
1972
|
-
if (
|
|
2197
|
+
if (isNumber(parameter)) {
|
|
1973
2198
|
assert(
|
|
1974
2199
|
parameter <= Number.MAX_SAFE_INTEGER,
|
|
1975
2200
|
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
1976
2201
|
);
|
|
1977
2202
|
}
|
|
1978
2203
|
assert(
|
|
1979
|
-
|
|
2204
|
+
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),
|
|
1980
2205
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt), but is ${typeof parameter} ${parameter}.`
|
|
1981
2206
|
);
|
|
1982
|
-
|
|
2207
|
+
let param;
|
|
2208
|
+
switch (input.type) {
|
|
2209
|
+
case "core::integer::u256" /* u256 */:
|
|
2210
|
+
param = new CairoUint256(parameter).toBigInt();
|
|
2211
|
+
break;
|
|
2212
|
+
case "core::integer::u512" /* u512 */:
|
|
2213
|
+
param = new CairoUint512(parameter).toBigInt();
|
|
2214
|
+
break;
|
|
2215
|
+
default:
|
|
2216
|
+
param = toBigInt(parameter);
|
|
2217
|
+
}
|
|
1983
2218
|
switch (input.type) {
|
|
1984
2219
|
case "core::integer::u8" /* u8 */:
|
|
1985
2220
|
assert(
|
|
@@ -2017,6 +2252,9 @@ var validateUint = (parameter, input) => {
|
|
|
2017
2252
|
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
2018
2253
|
);
|
|
2019
2254
|
break;
|
|
2255
|
+
case "core::integer::u512" /* u512 */:
|
|
2256
|
+
assert(CairoUint512.is(param), `Validate: arg ${input.name} is ${input.type} 0 - 2^512-1`);
|
|
2257
|
+
break;
|
|
2020
2258
|
case "core::starknet::class_hash::ClassHash" /* ClassHash */:
|
|
2021
2259
|
assert(
|
|
2022
2260
|
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1670
|
|
@@ -2031,18 +2269,25 @@ var validateUint = (parameter, input) => {
|
|
|
2031
2269
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
2032
2270
|
);
|
|
2033
2271
|
break;
|
|
2272
|
+
case "core::starknet::secp256k1::Secp256k1Point" /* Secp256k1Point */: {
|
|
2273
|
+
assert(
|
|
2274
|
+
param >= 0n && param <= 2n ** 512n - 1n,
|
|
2275
|
+
`Validate: arg ${input.name} must be ${input.type} : a 512 bits number.`
|
|
2276
|
+
);
|
|
2277
|
+
break;
|
|
2278
|
+
}
|
|
2034
2279
|
default:
|
|
2035
2280
|
break;
|
|
2036
2281
|
}
|
|
2037
2282
|
};
|
|
2038
2283
|
var validateBool = (parameter, input) => {
|
|
2039
2284
|
assert(
|
|
2040
|
-
|
|
2285
|
+
isBoolean(parameter),
|
|
2041
2286
|
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
2042
2287
|
);
|
|
2043
2288
|
};
|
|
2044
2289
|
var validateStruct = (parameter, input, structs) => {
|
|
2045
|
-
if (input.type === "core::integer::u256" /* u256 */) {
|
|
2290
|
+
if (input.type === "core::integer::u256" /* u256 */ || input.type === "core::integer::u512" /* u512 */) {
|
|
2046
2291
|
validateUint(parameter, input);
|
|
2047
2292
|
return;
|
|
2048
2293
|
}
|
|
@@ -2123,7 +2368,7 @@ var validateArray = (parameter, input, structs, enums) => {
|
|
|
2123
2368
|
parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
|
|
2124
2369
|
break;
|
|
2125
2370
|
case (isTypeUint(baseType) || isTypeLiteral(baseType)):
|
|
2126
|
-
parameter.forEach((param) => validateUint(param,
|
|
2371
|
+
parameter.forEach((param) => validateUint(param, { name: "", type: baseType }));
|
|
2127
2372
|
break;
|
|
2128
2373
|
case isTypeBool(baseType):
|
|
2129
2374
|
parameter.forEach((param) => validateBool(param, input));
|
|
@@ -2803,7 +3048,7 @@ function computeHintedClassHash(compiledContract) {
|
|
|
2803
3048
|
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2804
3049
|
}
|
|
2805
3050
|
function computeLegacyContractClassHash(contract) {
|
|
2806
|
-
const compiledContract =
|
|
3051
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2807
3052
|
const apiVersion = toHex(API_VERSION);
|
|
2808
3053
|
const externalEntryPointsHash = computeHashOnElements2(
|
|
2809
3054
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
@@ -2899,7 +3144,7 @@ function computeSierraContractClassHash(sierra) {
|
|
|
2899
3144
|
);
|
|
2900
3145
|
}
|
|
2901
3146
|
function computeContractClassHash(contract) {
|
|
2902
|
-
const compiledContract =
|
|
3147
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
2903
3148
|
if ("sierra_program" in compiledContract) {
|
|
2904
3149
|
return computeSierraContractClassHash(compiledContract);
|
|
2905
3150
|
}
|
|
@@ -2927,7 +3172,7 @@ __export(stark_exports, {
|
|
|
2927
3172
|
var import_starknet4 = require("@scure/starknet");
|
|
2928
3173
|
var import_pako = require("pako");
|
|
2929
3174
|
function compressProgram(jsonProgram) {
|
|
2930
|
-
const stringified =
|
|
3175
|
+
const stringified = isString(jsonProgram) ? jsonProgram : stringify2(jsonProgram);
|
|
2931
3176
|
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
2932
3177
|
return btoaUniversal(compressedProgram);
|
|
2933
3178
|
}
|
|
@@ -2967,7 +3212,7 @@ function estimatedFeeToMaxFee(estimatedFee, overhead = 50 /* MAX_FEE */) {
|
|
|
2967
3212
|
return addPercent(estimatedFee, overhead);
|
|
2968
3213
|
}
|
|
2969
3214
|
function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUNT */, priceOverhead = 50 /* L1_BOUND_MAX_PRICE_PER_UNIT */) {
|
|
2970
|
-
if (
|
|
3215
|
+
if (isBigInt(estimate)) {
|
|
2971
3216
|
return {
|
|
2972
3217
|
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
2973
3218
|
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
@@ -3035,7 +3280,7 @@ function reduceV2(providedVersion) {
|
|
|
3035
3280
|
|
|
3036
3281
|
// src/utils/contract.ts
|
|
3037
3282
|
function isSierra(contract) {
|
|
3038
|
-
const compiledContract =
|
|
3283
|
+
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
3039
3284
|
return "sierra_program" in compiledContract;
|
|
3040
3285
|
}
|
|
3041
3286
|
function extractContractHashes(payload) {
|
|
@@ -3100,7 +3345,7 @@ function createSierraContractClass(contract) {
|
|
|
3100
3345
|
return result;
|
|
3101
3346
|
}
|
|
3102
3347
|
function parseContract(contract) {
|
|
3103
|
-
const parsedContract =
|
|
3348
|
+
const parsedContract = isString(contract) ? parse2(contract) : contract;
|
|
3104
3349
|
if (!isSierra(contract)) {
|
|
3105
3350
|
return {
|
|
3106
3351
|
...parsedContract,
|
|
@@ -3117,7 +3362,7 @@ var getDefaultNodeUrl = (networkName, mute = false) => {
|
|
|
3117
3362
|
return nodes[randIdx];
|
|
3118
3363
|
};
|
|
3119
3364
|
function formatHash(hashValue) {
|
|
3120
|
-
if (
|
|
3365
|
+
if (isString(hashValue))
|
|
3121
3366
|
return hashValue;
|
|
3122
3367
|
return toHex(hashValue);
|
|
3123
3368
|
}
|
|
@@ -3134,14 +3379,16 @@ var Block = class {
|
|
|
3134
3379
|
number = null;
|
|
3135
3380
|
tag = null;
|
|
3136
3381
|
setIdentifier(__identifier) {
|
|
3137
|
-
if (
|
|
3138
|
-
|
|
3139
|
-
|
|
3382
|
+
if (isString(__identifier)) {
|
|
3383
|
+
if (isHex(__identifier)) {
|
|
3384
|
+
this.hash = __identifier;
|
|
3385
|
+
} else if (validBlockTags.includes(__identifier)) {
|
|
3386
|
+
this.tag = __identifier;
|
|
3387
|
+
}
|
|
3388
|
+
} else if (isBigInt(__identifier)) {
|
|
3140
3389
|
this.hash = toHex(__identifier);
|
|
3141
|
-
} else if (
|
|
3390
|
+
} else if (isNumber(__identifier)) {
|
|
3142
3391
|
this.number = __identifier;
|
|
3143
|
-
} else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
|
|
3144
|
-
this.tag = __identifier;
|
|
3145
3392
|
} else {
|
|
3146
3393
|
this.tag = "pending" /* pending */;
|
|
3147
3394
|
}
|
|
@@ -4390,7 +4637,7 @@ var RPCResponseParser = class {
|
|
|
4390
4637
|
return { status: "PENDING", ...res };
|
|
4391
4638
|
}
|
|
4392
4639
|
parseTransactionReceipt(res) {
|
|
4393
|
-
if ("actual_fee" in res &&
|
|
4640
|
+
if ("actual_fee" in res && isString(res.actual_fee)) {
|
|
4394
4641
|
return {
|
|
4395
4642
|
...res,
|
|
4396
4643
|
actual_fee: {
|
|
@@ -4434,11 +4681,59 @@ var RPCResponseParser = class {
|
|
|
4434
4681
|
parseContractClassResponse(res) {
|
|
4435
4682
|
return {
|
|
4436
4683
|
...res,
|
|
4437
|
-
abi:
|
|
4684
|
+
abi: isString(res.abi) ? JSON.parse(res.abi) : res.abi
|
|
4438
4685
|
};
|
|
4439
4686
|
}
|
|
4440
4687
|
};
|
|
4441
4688
|
|
|
4689
|
+
// src/utils/transactionReceipt.ts
|
|
4690
|
+
var ReceiptTx = class _ReceiptTx {
|
|
4691
|
+
statusReceipt;
|
|
4692
|
+
value;
|
|
4693
|
+
constructor(receipt) {
|
|
4694
|
+
[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")];
|
|
4695
|
+
for (const [key] of Object.entries(this)) {
|
|
4696
|
+
Object.defineProperty(this, key, {
|
|
4697
|
+
enumerable: false
|
|
4698
|
+
});
|
|
4699
|
+
}
|
|
4700
|
+
for (const [key, value] of Object.entries(receipt)) {
|
|
4701
|
+
Object.defineProperty(this, key, {
|
|
4702
|
+
enumerable: true,
|
|
4703
|
+
writable: false,
|
|
4704
|
+
value
|
|
4705
|
+
});
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
match(callbacks) {
|
|
4709
|
+
if (this.statusReceipt in callbacks) {
|
|
4710
|
+
return callbacks[this.statusReceipt](this.value);
|
|
4711
|
+
}
|
|
4712
|
+
return callbacks._();
|
|
4713
|
+
}
|
|
4714
|
+
isSuccess() {
|
|
4715
|
+
return this.statusReceipt === "success";
|
|
4716
|
+
}
|
|
4717
|
+
isReverted() {
|
|
4718
|
+
return this.statusReceipt === "reverted";
|
|
4719
|
+
}
|
|
4720
|
+
isRejected() {
|
|
4721
|
+
return this.statusReceipt === "rejected";
|
|
4722
|
+
}
|
|
4723
|
+
isError() {
|
|
4724
|
+
return this.statusReceipt === "error";
|
|
4725
|
+
}
|
|
4726
|
+
static isSuccess(transactionReceipt) {
|
|
4727
|
+
return transactionReceipt.execution_status === "SUCCEEDED" /* SUCCEEDED */;
|
|
4728
|
+
}
|
|
4729
|
+
static isReverted(transactionReceipt) {
|
|
4730
|
+
return transactionReceipt.execution_status === "REVERTED" /* REVERTED */;
|
|
4731
|
+
}
|
|
4732
|
+
static isRejected(transactionReceipt) {
|
|
4733
|
+
return transactionReceipt.status === "REJECTED" /* REJECTED */;
|
|
4734
|
+
}
|
|
4735
|
+
};
|
|
4736
|
+
|
|
4442
4737
|
// src/provider/rpc.ts
|
|
4443
4738
|
var RpcProvider = class {
|
|
4444
4739
|
responseParser;
|
|
@@ -4523,7 +4818,9 @@ var RpcProvider = class {
|
|
|
4523
4818
|
return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index);
|
|
4524
4819
|
}
|
|
4525
4820
|
async getTransactionReceipt(txHash) {
|
|
4526
|
-
|
|
4821
|
+
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
4822
|
+
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
4823
|
+
return new ReceiptTx(txReceiptWoHelperModified);
|
|
4527
4824
|
}
|
|
4528
4825
|
async getTransactionTrace(txHash) {
|
|
4529
4826
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -4545,7 +4842,11 @@ var RpcProvider = class {
|
|
|
4545
4842
|
return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
|
|
4546
4843
|
}
|
|
4547
4844
|
async waitForTransaction(txHash, options) {
|
|
4548
|
-
|
|
4845
|
+
const receiptWoHelper = await this.channel.waitForTransaction(
|
|
4846
|
+
txHash,
|
|
4847
|
+
options
|
|
4848
|
+
);
|
|
4849
|
+
return new ReceiptTx(receiptWoHelper);
|
|
4549
4850
|
}
|
|
4550
4851
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
4551
4852
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -5250,6 +5551,10 @@ var revisionConfiguration = {
|
|
|
5250
5551
|
presetTypes: {}
|
|
5251
5552
|
}
|
|
5252
5553
|
};
|
|
5554
|
+
function assertRange(data, type, { min, max }) {
|
|
5555
|
+
const value = BigInt(data);
|
|
5556
|
+
assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
|
|
5557
|
+
}
|
|
5253
5558
|
function identifyRevision({ types, domain }) {
|
|
5254
5559
|
if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
|
|
5255
5560
|
return "1" /* Active */;
|
|
@@ -5261,7 +5566,7 @@ function getHex(value) {
|
|
|
5261
5566
|
try {
|
|
5262
5567
|
return toHex(value);
|
|
5263
5568
|
} catch (e) {
|
|
5264
|
-
if (
|
|
5569
|
+
if (isString(value)) {
|
|
5265
5570
|
return toHex(encodeShortString(value));
|
|
5266
5571
|
}
|
|
5267
5572
|
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
@@ -5412,15 +5717,41 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
|
|
|
5412
5717
|
}
|
|
5413
5718
|
return [type, getHex(data)];
|
|
5414
5719
|
}
|
|
5720
|
+
case "i128": {
|
|
5721
|
+
if (revision === "1" /* Active */) {
|
|
5722
|
+
const value = BigInt(data);
|
|
5723
|
+
assertRange(value, type, RANGE_I128);
|
|
5724
|
+
return [type, getHex(value < 0n ? PRIME + value : value)];
|
|
5725
|
+
}
|
|
5726
|
+
return [type, getHex(data)];
|
|
5727
|
+
}
|
|
5728
|
+
case "timestamp":
|
|
5729
|
+
case "u128": {
|
|
5730
|
+
if (revision === "1" /* Active */) {
|
|
5731
|
+
assertRange(data, type, RANGE_U128);
|
|
5732
|
+
}
|
|
5733
|
+
return [type, getHex(data)];
|
|
5734
|
+
}
|
|
5415
5735
|
case "felt":
|
|
5416
|
-
case "
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5736
|
+
case "shortstring": {
|
|
5737
|
+
if (revision === "1" /* Active */) {
|
|
5738
|
+
assertRange(getHex(data), type, RANGE_FELT);
|
|
5739
|
+
}
|
|
5740
|
+
return [type, getHex(data)];
|
|
5741
|
+
}
|
|
5420
5742
|
case "ClassHash":
|
|
5421
|
-
case "
|
|
5422
|
-
|
|
5743
|
+
case "ContractAddress": {
|
|
5744
|
+
if (revision === "1" /* Active */) {
|
|
5745
|
+
assertRange(data, type, RANGE_FELT);
|
|
5746
|
+
}
|
|
5423
5747
|
return [type, getHex(data)];
|
|
5748
|
+
}
|
|
5749
|
+
case "bool": {
|
|
5750
|
+
if (revision === "1" /* Active */) {
|
|
5751
|
+
assert(typeof data === "boolean", `Type mismatch for ${type} ${data}`);
|
|
5752
|
+
}
|
|
5753
|
+
return [type, getHex(data)];
|
|
5754
|
+
}
|
|
5424
5755
|
default: {
|
|
5425
5756
|
if (revision === "1" /* Active */) {
|
|
5426
5757
|
throw new Error(`Unsupported type: ${type}`);
|
|
@@ -5570,19 +5901,48 @@ function ethRandomPrivateKey() {
|
|
|
5570
5901
|
return sanitizeHex(buf2hex(import_secp256k1.secp256k1.utils.randomPrivateKey()));
|
|
5571
5902
|
}
|
|
5572
5903
|
|
|
5904
|
+
// src/utils/uint256.ts
|
|
5905
|
+
var uint256_exports = {};
|
|
5906
|
+
__export(uint256_exports, {
|
|
5907
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
5908
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
5909
|
+
bnToUint256: () => bnToUint256,
|
|
5910
|
+
isUint256: () => isUint256,
|
|
5911
|
+
uint256ToBN: () => uint256ToBN
|
|
5912
|
+
});
|
|
5913
|
+
function uint256ToBN(uint2562) {
|
|
5914
|
+
return new CairoUint256(uint2562).toBigInt();
|
|
5915
|
+
}
|
|
5916
|
+
function isUint256(bn) {
|
|
5917
|
+
return CairoUint256.is(bn);
|
|
5918
|
+
}
|
|
5919
|
+
function bnToUint256(bn) {
|
|
5920
|
+
return new CairoUint256(bn).toUint256HexString();
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5573
5923
|
// src/signer/ethSigner.ts
|
|
5574
5924
|
var EthSigner = class {
|
|
5575
5925
|
pk;
|
|
5576
|
-
// hex string without 0x and odd number of characters
|
|
5926
|
+
// hex string without 0x and with an odd number of characters
|
|
5577
5927
|
constructor(pk = ethRandomPrivateKey()) {
|
|
5578
|
-
this.pk = pk instanceof Uint8Array ?
|
|
5928
|
+
this.pk = pk instanceof Uint8Array ? buf2hex(pk).padStart(64, "0") : removeHexPrefix(toHex(pk)).padStart(64, "0");
|
|
5579
5929
|
}
|
|
5930
|
+
/**
|
|
5931
|
+
* provides the Ethereum full public key (without parity prefix)
|
|
5932
|
+
* @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
5933
|
+
*/
|
|
5580
5934
|
async getPubKey() {
|
|
5581
|
-
return addHexPrefix(
|
|
5935
|
+
return addHexPrefix(
|
|
5936
|
+
buf2hex(import_secp256k12.secp256k1.getPublicKey(this.pk, false)).padStart(130, "0").slice(2)
|
|
5937
|
+
);
|
|
5582
5938
|
}
|
|
5583
5939
|
async signMessage(typedData, accountAddress) {
|
|
5584
5940
|
const msgHash = getMessageHash(typedData, accountAddress);
|
|
5585
|
-
|
|
5941
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
5942
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5943
|
+
this.pk
|
|
5944
|
+
);
|
|
5945
|
+
return this.formatEthSignature(signature);
|
|
5586
5946
|
}
|
|
5587
5947
|
async signTransaction(transactions, details) {
|
|
5588
5948
|
const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
|
|
@@ -5608,7 +5968,11 @@ var EthSigner = class {
|
|
|
5608
5968
|
} else {
|
|
5609
5969
|
throw Error("unsupported signTransaction version");
|
|
5610
5970
|
}
|
|
5611
|
-
|
|
5971
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
5972
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
5973
|
+
this.pk
|
|
5974
|
+
);
|
|
5975
|
+
return this.formatEthSignature(signature);
|
|
5612
5976
|
}
|
|
5613
5977
|
async signDeployAccountTransaction(details) {
|
|
5614
5978
|
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
@@ -5634,7 +5998,11 @@ var EthSigner = class {
|
|
|
5634
5998
|
} else {
|
|
5635
5999
|
throw Error("unsupported signDeployAccountTransaction version");
|
|
5636
6000
|
}
|
|
5637
|
-
|
|
6001
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
6002
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
6003
|
+
this.pk
|
|
6004
|
+
);
|
|
6005
|
+
return this.formatEthSignature(signature);
|
|
5638
6006
|
}
|
|
5639
6007
|
async signDeclareTransaction(details) {
|
|
5640
6008
|
let msgHash;
|
|
@@ -5655,7 +6023,27 @@ var EthSigner = class {
|
|
|
5655
6023
|
} else {
|
|
5656
6024
|
throw Error("unsupported signDeclareTransaction version");
|
|
5657
6025
|
}
|
|
5658
|
-
|
|
6026
|
+
const signature = import_secp256k12.secp256k1.sign(
|
|
6027
|
+
removeHexPrefix(sanitizeHex(msgHash)),
|
|
6028
|
+
this.pk
|
|
6029
|
+
);
|
|
6030
|
+
return this.formatEthSignature(signature);
|
|
6031
|
+
}
|
|
6032
|
+
/**
|
|
6033
|
+
* Serialize the signature in conformity with starknet::eth_signature::Signature
|
|
6034
|
+
* @param ethSignature secp256k1 signature from Noble curves library
|
|
6035
|
+
* @return an array of felts, representing a Cairo Eth Signature.
|
|
6036
|
+
*/
|
|
6037
|
+
formatEthSignature(ethSignature) {
|
|
6038
|
+
const r = bnToUint256(ethSignature.r);
|
|
6039
|
+
const s = bnToUint256(ethSignature.s);
|
|
6040
|
+
return [
|
|
6041
|
+
toHex(r.low),
|
|
6042
|
+
toHex(r.high),
|
|
6043
|
+
toHex(s.low),
|
|
6044
|
+
toHex(s.high),
|
|
6045
|
+
toHex(ethSignature.recovery)
|
|
6046
|
+
];
|
|
5659
6047
|
}
|
|
5660
6048
|
};
|
|
5661
6049
|
|
|
@@ -5691,7 +6079,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5691
6079
|
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = "0x2" /* V2 */) {
|
|
5692
6080
|
super(providerOrOptions);
|
|
5693
6081
|
this.address = address.toLowerCase();
|
|
5694
|
-
this.signer =
|
|
6082
|
+
this.signer = isString(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
5695
6083
|
if (cairoVersion) {
|
|
5696
6084
|
this.cairoVersion = cairoVersion.toString();
|
|
5697
6085
|
}
|
|
@@ -5832,7 +6220,7 @@ var Account = class extends RpcProvider2 {
|
|
|
5832
6220
|
return this.estimateInvokeFee(calls, details);
|
|
5833
6221
|
}
|
|
5834
6222
|
async estimateFeeBulk(invocations, details = {}) {
|
|
5835
|
-
const { nonce, blockIdentifier, version } = details;
|
|
6223
|
+
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
5836
6224
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
5837
6225
|
...v3Details(details),
|
|
5838
6226
|
versions: [
|
|
@@ -5845,11 +6233,12 @@ var Account = class extends RpcProvider2 {
|
|
|
5845
6233
|
// sierra
|
|
5846
6234
|
],
|
|
5847
6235
|
nonce,
|
|
5848
|
-
blockIdentifier
|
|
6236
|
+
blockIdentifier,
|
|
6237
|
+
skipValidate
|
|
5849
6238
|
});
|
|
5850
6239
|
return super.getEstimateFeeBulk(accountInvocations, {
|
|
5851
6240
|
blockIdentifier,
|
|
5852
|
-
skipValidate
|
|
6241
|
+
skipValidate
|
|
5853
6242
|
});
|
|
5854
6243
|
}
|
|
5855
6244
|
async simulateTransaction(invocations, details = {}) {
|
|
@@ -6853,25 +7242,6 @@ var ContractFactory = class {
|
|
|
6853
7242
|
// 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
|
|
6854
7243
|
};
|
|
6855
7244
|
|
|
6856
|
-
// src/utils/uint256.ts
|
|
6857
|
-
var uint256_exports = {};
|
|
6858
|
-
__export(uint256_exports, {
|
|
6859
|
-
UINT_128_MAX: () => UINT_128_MAX,
|
|
6860
|
-
UINT_256_MAX: () => UINT_256_MAX,
|
|
6861
|
-
bnToUint256: () => bnToUint256,
|
|
6862
|
-
isUint256: () => isUint256,
|
|
6863
|
-
uint256ToBN: () => uint256ToBN
|
|
6864
|
-
});
|
|
6865
|
-
function uint256ToBN(uint2562) {
|
|
6866
|
-
return new CairoUint256(uint2562).toBigInt();
|
|
6867
|
-
}
|
|
6868
|
-
function isUint256(bn) {
|
|
6869
|
-
return CairoUint256.is(bn);
|
|
6870
|
-
}
|
|
6871
|
-
function bnToUint256(bn) {
|
|
6872
|
-
return new CairoUint256(bn).toUint256HexString();
|
|
6873
|
-
}
|
|
6874
|
-
|
|
6875
7245
|
// src/utils/address.ts
|
|
6876
7246
|
var import_utils2 = require("@noble/curves/abstract/utils");
|
|
6877
7247
|
function addAddressPadding(address) {
|
|
@@ -6945,6 +7315,8 @@ var number = num_exports;
|
|
|
6945
7315
|
CairoOptionVariant,
|
|
6946
7316
|
CairoResult,
|
|
6947
7317
|
CairoResultVariant,
|
|
7318
|
+
CairoUint256,
|
|
7319
|
+
CairoUint512,
|
|
6948
7320
|
CallData,
|
|
6949
7321
|
Contract,
|
|
6950
7322
|
ContractFactory,
|
|
@@ -6961,6 +7333,7 @@ var number = num_exports;
|
|
|
6961
7333
|
RPC,
|
|
6962
7334
|
RPC06,
|
|
6963
7335
|
RPC07,
|
|
7336
|
+
ReceiptTx,
|
|
6964
7337
|
RpcChannel,
|
|
6965
7338
|
RpcProvider,
|
|
6966
7339
|
SIMULATION_FLAG,
|
|
@@ -6971,6 +7344,16 @@ var number = num_exports;
|
|
|
6971
7344
|
TransactionStatus,
|
|
6972
7345
|
TransactionType,
|
|
6973
7346
|
TypedDataRevision,
|
|
7347
|
+
UINT_128_MAX,
|
|
7348
|
+
UINT_128_MIN,
|
|
7349
|
+
UINT_256_HIGH_MAX,
|
|
7350
|
+
UINT_256_HIGH_MIN,
|
|
7351
|
+
UINT_256_LOW_MAX,
|
|
7352
|
+
UINT_256_LOW_MIN,
|
|
7353
|
+
UINT_256_MAX,
|
|
7354
|
+
UINT_256_MIN,
|
|
7355
|
+
UINT_512_MAX,
|
|
7356
|
+
UINT_512_MIN,
|
|
6974
7357
|
Uint,
|
|
6975
7358
|
ValidateType,
|
|
6976
7359
|
WalletAccount,
|