starknet 8.1.1 → 8.2.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +877 -139
- package/dist/index.global.js +2122 -396
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2143 -396
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2122 -396
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -21,19 +21,33 @@ var starknet = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
AbiParser1: () => AbiParser1,
|
|
25
|
+
AbiParser2: () => AbiParser2,
|
|
26
|
+
AbiParserInterface: () => AbiParserInterface,
|
|
24
27
|
Account: () => Account,
|
|
25
28
|
AccountInterface: () => AccountInterface,
|
|
26
29
|
BatchClient: () => BatchClient,
|
|
27
30
|
BlockStatus: () => BlockStatus,
|
|
28
31
|
BlockTag: () => BlockTag,
|
|
32
|
+
CairoByteArray: () => CairoByteArray,
|
|
29
33
|
CairoCustomEnum: () => CairoCustomEnum,
|
|
30
34
|
CairoFixedArray: () => CairoFixedArray,
|
|
35
|
+
CairoInt128: () => CairoInt128,
|
|
36
|
+
CairoInt16: () => CairoInt16,
|
|
37
|
+
CairoInt32: () => CairoInt32,
|
|
38
|
+
CairoInt64: () => CairoInt64,
|
|
39
|
+
CairoInt8: () => CairoInt8,
|
|
31
40
|
CairoOption: () => CairoOption,
|
|
32
41
|
CairoOptionVariant: () => CairoOptionVariant,
|
|
33
42
|
CairoResult: () => CairoResult,
|
|
34
43
|
CairoResultVariant: () => CairoResultVariant,
|
|
44
|
+
CairoUint128: () => CairoUint128,
|
|
45
|
+
CairoUint16: () => CairoUint16,
|
|
35
46
|
CairoUint256: () => CairoUint256,
|
|
36
47
|
CairoUint512: () => CairoUint512,
|
|
48
|
+
CairoUint64: () => CairoUint64,
|
|
49
|
+
CairoUint8: () => CairoUint8,
|
|
50
|
+
CairoUint96: () => CairoUint96,
|
|
37
51
|
CallData: () => CallData,
|
|
38
52
|
Contract: () => Contract,
|
|
39
53
|
ContractInterface: () => ContractInterface,
|
|
@@ -49,6 +63,7 @@ var starknet = (() => {
|
|
|
49
63
|
ETransactionVersion3: () => ETransactionVersion33,
|
|
50
64
|
EntryPointType: () => EntryPointType,
|
|
51
65
|
EthSigner: () => EthSigner,
|
|
66
|
+
Int: () => Int,
|
|
52
67
|
LedgerSigner: () => LedgerSigner111,
|
|
53
68
|
LedgerSigner111: () => LedgerSigner111,
|
|
54
69
|
LedgerSigner221: () => LedgerSigner221,
|
|
@@ -102,6 +117,8 @@ var starknet = (() => {
|
|
|
102
117
|
config: () => config,
|
|
103
118
|
constants: () => constants_exports,
|
|
104
119
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
120
|
+
createAbiParser: () => createAbiParser,
|
|
121
|
+
createTransactionReceipt: () => createTransactionReceipt,
|
|
105
122
|
defaultDeployer: () => defaultDeployer,
|
|
106
123
|
defaultPaymaster: () => defaultPaymaster,
|
|
107
124
|
defaultProvider: () => defaultProvider,
|
|
@@ -110,6 +127,8 @@ var starknet = (() => {
|
|
|
110
127
|
eth: () => eth_exports,
|
|
111
128
|
events: () => events_exports,
|
|
112
129
|
extractContractHashes: () => extractContractHashes,
|
|
130
|
+
fastParsingStrategy: () => fastParsingStrategy,
|
|
131
|
+
getAbiVersion: () => getAbiVersion,
|
|
113
132
|
getChecksumAddress: () => getChecksumAddress,
|
|
114
133
|
getGasPrices: () => getGasPrices,
|
|
115
134
|
getLedgerPathBuffer: () => getLedgerPathBuffer111,
|
|
@@ -117,7 +136,9 @@ var starknet = (() => {
|
|
|
117
136
|
getLedgerPathBuffer221: () => getLedgerPathBuffer221,
|
|
118
137
|
getTipStatsFromBlocks: () => getTipStatsFromBlocks,
|
|
119
138
|
hash: () => hash_exports,
|
|
139
|
+
hdParsingStrategy: () => hdParsingStrategy,
|
|
120
140
|
isAccount: () => isAccount,
|
|
141
|
+
isNoConstructorValid: () => isNoConstructorValid,
|
|
121
142
|
isPendingBlock: () => isPendingBlock,
|
|
122
143
|
isPendingStateUpdate: () => isPendingStateUpdate,
|
|
123
144
|
isPendingTransaction: () => isPendingTransaction,
|
|
@@ -175,7 +196,16 @@ var starknet = (() => {
|
|
|
175
196
|
PRIME: () => PRIME,
|
|
176
197
|
RANGE_FELT: () => RANGE_FELT,
|
|
177
198
|
RANGE_I128: () => RANGE_I128,
|
|
199
|
+
RANGE_I16: () => RANGE_I16,
|
|
200
|
+
RANGE_I32: () => RANGE_I32,
|
|
201
|
+
RANGE_I64: () => RANGE_I64,
|
|
202
|
+
RANGE_I8: () => RANGE_I8,
|
|
178
203
|
RANGE_U128: () => RANGE_U128,
|
|
204
|
+
RANGE_U16: () => RANGE_U16,
|
|
205
|
+
RANGE_U32: () => RANGE_U32,
|
|
206
|
+
RANGE_U64: () => RANGE_U64,
|
|
207
|
+
RANGE_U8: () => RANGE_U8,
|
|
208
|
+
RANGE_U96: () => RANGE_U96,
|
|
179
209
|
RPC_DEFAULT_NODES: () => RPC_DEFAULT_NODES,
|
|
180
210
|
SNIP9_V1_INTERFACE_ID: () => SNIP9_V1_INTERFACE_ID,
|
|
181
211
|
SNIP9_V2_INTERFACE_ID: () => SNIP9_V2_INTERFACE_ID,
|
|
@@ -717,16 +747,22 @@ var starknet = (() => {
|
|
|
717
747
|
addHexPrefix: () => addHexPrefix,
|
|
718
748
|
arrayBufferToString: () => arrayBufferToString,
|
|
719
749
|
atobUniversal: () => atobUniversal,
|
|
750
|
+
bigIntToUint8Array: () => bigIntToUint8Array,
|
|
720
751
|
btoaUniversal: () => btoaUniversal,
|
|
721
752
|
buf2hex: () => buf2hex,
|
|
722
753
|
calcByteLength: () => calcByteLength,
|
|
723
754
|
concatenateArrayBuffer: () => concatenateArrayBuffer,
|
|
755
|
+
hexStringToUint8Array: () => hexStringToUint8Array,
|
|
724
756
|
padLeft: () => padLeft,
|
|
725
757
|
pascalToSnake: () => pascalToSnake,
|
|
726
758
|
removeHexPrefix: () => removeHexPrefix,
|
|
727
759
|
sanitizeBytes: () => sanitizeBytes,
|
|
728
760
|
sanitizeHex: () => sanitizeHex,
|
|
729
|
-
|
|
761
|
+
stringToUint8Array: () => stringToUint8Array,
|
|
762
|
+
uint8ArrayToBigInt: () => uint8ArrayToBigInt,
|
|
763
|
+
utf8ToArray: () => utf8ToArray,
|
|
764
|
+
utf8ToBigInt: () => utf8ToBigInt,
|
|
765
|
+
utf8ToUint8Array: () => utf8ToUint8Array
|
|
730
766
|
});
|
|
731
767
|
|
|
732
768
|
// node_modules/@scure/base/lib/esm/index.js
|
|
@@ -913,9 +949,13 @@ var starknet = (() => {
|
|
|
913
949
|
function arrayBufferToString(array) {
|
|
914
950
|
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
915
951
|
}
|
|
916
|
-
function
|
|
952
|
+
function utf8ToUint8Array(str) {
|
|
917
953
|
return new TextEncoder().encode(str);
|
|
918
954
|
}
|
|
955
|
+
var utf8ToArray = utf8ToUint8Array;
|
|
956
|
+
function utf8ToBigInt(str) {
|
|
957
|
+
return uint8ArrayToBigInt(utf8ToUint8Array(str));
|
|
958
|
+
}
|
|
919
959
|
function atobUniversal(a) {
|
|
920
960
|
return base64.decode(a);
|
|
921
961
|
}
|
|
@@ -967,6 +1007,61 @@ var starknet = (() => {
|
|
|
967
1007
|
});
|
|
968
1008
|
return result;
|
|
969
1009
|
}
|
|
1010
|
+
function hexStringToUint8Array(hex) {
|
|
1011
|
+
const cleanHex2 = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
1012
|
+
if (cleanHex2.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanHex2)) {
|
|
1013
|
+
throw new Error(`Invalid hex string: "${hex}" contains non-hexadecimal characters`);
|
|
1014
|
+
}
|
|
1015
|
+
const paddedHex = cleanHex2.length % 2 !== 0 ? `0${cleanHex2}` : cleanHex2;
|
|
1016
|
+
const bytes = new Uint8Array(paddedHex.length / 2);
|
|
1017
|
+
for (let i = 0; i < paddedHex.length; i += 2) {
|
|
1018
|
+
bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
|
|
1019
|
+
}
|
|
1020
|
+
return bytes;
|
|
1021
|
+
}
|
|
1022
|
+
function isHexString(hex) {
|
|
1023
|
+
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
1024
|
+
}
|
|
1025
|
+
function isDecimalString(str) {
|
|
1026
|
+
return /^[0-9]+$/.test(str);
|
|
1027
|
+
}
|
|
1028
|
+
function stringToUint8Array(str) {
|
|
1029
|
+
if (isHexString(str)) {
|
|
1030
|
+
return hexStringToUint8Array(str);
|
|
1031
|
+
}
|
|
1032
|
+
if (isDecimalString(str)) {
|
|
1033
|
+
const value = BigInt(str);
|
|
1034
|
+
return bigIntToUint8Array(value);
|
|
1035
|
+
}
|
|
1036
|
+
return utf8ToUint8Array(str);
|
|
1037
|
+
}
|
|
1038
|
+
function bigIntToUint8Array(value) {
|
|
1039
|
+
if (value < 0n) {
|
|
1040
|
+
throw new Error(`Cannot convert negative bigint ${value} to Uint8Array`);
|
|
1041
|
+
}
|
|
1042
|
+
if (value === 0n) {
|
|
1043
|
+
return new Uint8Array([0]);
|
|
1044
|
+
}
|
|
1045
|
+
let hex = value.toString(16);
|
|
1046
|
+
if (hex.length % 2 !== 0) {
|
|
1047
|
+
hex = `0${hex}`;
|
|
1048
|
+
}
|
|
1049
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
1050
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
1051
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
1052
|
+
}
|
|
1053
|
+
return bytes;
|
|
1054
|
+
}
|
|
1055
|
+
function uint8ArrayToBigInt(data) {
|
|
1056
|
+
if (!data || data.length === 0) {
|
|
1057
|
+
return 0n;
|
|
1058
|
+
}
|
|
1059
|
+
let hex = "0x";
|
|
1060
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
1061
|
+
hex += data[i].toString(16).padStart(2, "0");
|
|
1062
|
+
}
|
|
1063
|
+
return BigInt(hex);
|
|
1064
|
+
}
|
|
970
1065
|
|
|
971
1066
|
// src/global/constants.ts
|
|
972
1067
|
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
@@ -979,8 +1074,17 @@ var starknet = (() => {
|
|
|
979
1074
|
var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
980
1075
|
var range = (min, max) => ({ min, max });
|
|
981
1076
|
var RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
982
|
-
var
|
|
1077
|
+
var RANGE_U8 = range(ZERO, 2n ** 8n - 1n);
|
|
1078
|
+
var RANGE_U16 = range(ZERO, 2n ** 16n - 1n);
|
|
1079
|
+
var RANGE_U32 = range(ZERO, 2n ** 32n - 1n);
|
|
1080
|
+
var RANGE_U64 = range(ZERO, 2n ** 64n - 1n);
|
|
1081
|
+
var RANGE_U96 = range(ZERO, 2n ** 96n - 1n);
|
|
983
1082
|
var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
1083
|
+
var RANGE_I8 = range(-(2n ** 7n), 2n ** 7n - 1n);
|
|
1084
|
+
var RANGE_I16 = range(-(2n ** 15n), 2n ** 15n - 1n);
|
|
1085
|
+
var RANGE_I32 = range(-(2n ** 31n), 2n ** 31n - 1n);
|
|
1086
|
+
var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
|
|
1087
|
+
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
984
1088
|
var LegacyUDC = {
|
|
985
1089
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
986
1090
|
ENTRYPOINT: "deployContract"
|
|
@@ -1047,7 +1151,8 @@ var starknet = (() => {
|
|
|
1047
1151
|
},
|
|
1048
1152
|
defaultTipType: "recommendedTip",
|
|
1049
1153
|
fetch: void 0,
|
|
1050
|
-
websocket: void 0
|
|
1154
|
+
websocket: void 0,
|
|
1155
|
+
buffer: void 0
|
|
1051
1156
|
};
|
|
1052
1157
|
var RPC_DEFAULT_NODES = {
|
|
1053
1158
|
SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
|
|
@@ -1065,7 +1170,10 @@ var starknet = (() => {
|
|
|
1065
1170
|
unsupportedSpecVersion: "The connected node specification version is not supported by this library",
|
|
1066
1171
|
maxFeeInV3: "maxFee is not supported in V3 transactions, use resourceBounds instead",
|
|
1067
1172
|
declareNonSierra: "Declaring non Sierra (Cairo0)contract using RPC 0.8+",
|
|
1068
|
-
unsupportedMethodForRpcVersion: "Unsupported method for RPC version"
|
|
1173
|
+
unsupportedMethodForRpcVersion: "Unsupported method for RPC version",
|
|
1174
|
+
txEvictedFromMempool: "Transaction TTL, evicted from the mempool, try to increase the tip",
|
|
1175
|
+
consensusFailed: "Consensus failed to finalize the block proposal",
|
|
1176
|
+
txFailsBlockBuildingValidation: "Transaction fails block building validation"
|
|
1069
1177
|
};
|
|
1070
1178
|
|
|
1071
1179
|
// src/global/config.ts
|
|
@@ -1288,12 +1396,20 @@ ${JSON.stringify(data, null, 2)}`;
|
|
|
1288
1396
|
u16: "core::integer::u16",
|
|
1289
1397
|
u32: "core::integer::u32",
|
|
1290
1398
|
u64: "core::integer::u64",
|
|
1399
|
+
u96: "core::integer::u96",
|
|
1291
1400
|
u128: "core::integer::u128",
|
|
1292
1401
|
u256: "core::integer::u256",
|
|
1293
1402
|
// This one is struct
|
|
1294
1403
|
u512: "core::integer::u512"
|
|
1295
1404
|
// This one is struct
|
|
1296
1405
|
};
|
|
1406
|
+
var Int = {
|
|
1407
|
+
i8: "core::integer::i8",
|
|
1408
|
+
i16: "core::integer::i16",
|
|
1409
|
+
i32: "core::integer::i32",
|
|
1410
|
+
i64: "core::integer::i64",
|
|
1411
|
+
i128: "core::integer::i128"
|
|
1412
|
+
};
|
|
1297
1413
|
var Literal = {
|
|
1298
1414
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
1299
1415
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
@@ -2052,10 +2168,12 @@ ${indent}}` : "}";
|
|
|
2052
2168
|
getDecimalString: () => getDecimalString,
|
|
2053
2169
|
getHexString: () => getHexString,
|
|
2054
2170
|
getHexStringArray: () => getHexStringArray,
|
|
2171
|
+
getNext: () => getNext,
|
|
2055
2172
|
hexToBytes: () => hexToBytes2,
|
|
2056
2173
|
hexToDecimalString: () => hexToDecimalString,
|
|
2057
2174
|
isBigNumberish: () => isBigNumberish,
|
|
2058
2175
|
isHex: () => isHex2,
|
|
2176
|
+
isHexString: () => isHexString2,
|
|
2059
2177
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
2060
2178
|
stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
|
|
2061
2179
|
toBigInt: () => toBigInt,
|
|
@@ -2709,14 +2827,21 @@ ${indent}}` : "}";
|
|
|
2709
2827
|
function isString(value) {
|
|
2710
2828
|
return typeof value === "string";
|
|
2711
2829
|
}
|
|
2830
|
+
function isBuffer(obj) {
|
|
2831
|
+
return typeof Buffer !== "undefined" && obj instanceof Buffer;
|
|
2832
|
+
}
|
|
2712
2833
|
function isObject2(item) {
|
|
2713
2834
|
return !!item && typeof item === "object" && !Array.isArray(item);
|
|
2714
2835
|
}
|
|
2836
|
+
function isInteger2(value) {
|
|
2837
|
+
return Number.isInteger(value);
|
|
2838
|
+
}
|
|
2715
2839
|
|
|
2716
2840
|
// src/utils/num.ts
|
|
2717
2841
|
function isHex2(hex) {
|
|
2718
2842
|
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
2719
2843
|
}
|
|
2844
|
+
var isHexString2 = isHex2;
|
|
2720
2845
|
function toBigInt(value) {
|
|
2721
2846
|
return BigInt(value);
|
|
2722
2847
|
}
|
|
@@ -2804,6 +2929,11 @@ ${indent}}` : "}";
|
|
|
2804
2929
|
function isBigNumberish(input) {
|
|
2805
2930
|
return isNumber2(input) || isBigInt(input) || isString(input) && (isHex2(input) || isStringWholeNumber(input));
|
|
2806
2931
|
}
|
|
2932
|
+
function getNext(iterator) {
|
|
2933
|
+
const it = iterator.next();
|
|
2934
|
+
if (it.done) throw new Error("Unexpected end of response");
|
|
2935
|
+
return it.value;
|
|
2936
|
+
}
|
|
2807
2937
|
|
|
2808
2938
|
// src/utils/hash/selector.ts
|
|
2809
2939
|
var selector_exports = {};
|
|
@@ -5051,7 +5181,7 @@ ${indent}}` : "}";
|
|
|
5051
5181
|
decodeShortString: () => decodeShortString,
|
|
5052
5182
|
encodeShortString: () => encodeShortString,
|
|
5053
5183
|
isASCII: () => isASCII,
|
|
5054
|
-
isDecimalString: () =>
|
|
5184
|
+
isDecimalString: () => isDecimalString2,
|
|
5055
5185
|
isLongText: () => isLongText,
|
|
5056
5186
|
isShortString: () => isShortString,
|
|
5057
5187
|
isShortText: () => isShortText,
|
|
@@ -5064,7 +5194,7 @@ ${indent}}` : "}";
|
|
|
5064
5194
|
function isShortString(str) {
|
|
5065
5195
|
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
5066
5196
|
}
|
|
5067
|
-
function
|
|
5197
|
+
function isDecimalString2(str) {
|
|
5068
5198
|
return /^[0-9]*$/i.test(str);
|
|
5069
5199
|
}
|
|
5070
5200
|
function isText(val) {
|
|
@@ -5086,7 +5216,7 @@ ${indent}}` : "}";
|
|
|
5086
5216
|
if (isHex2(str)) {
|
|
5087
5217
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
5088
5218
|
}
|
|
5089
|
-
if (
|
|
5219
|
+
if (isDecimalString2(str)) {
|
|
5090
5220
|
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
5091
5221
|
}
|
|
5092
5222
|
throw new Error(`${str} is not Hex or decimal`);
|
|
@@ -5128,12 +5258,11 @@ ${indent}}` : "}";
|
|
|
5128
5258
|
isLen: () => isLen,
|
|
5129
5259
|
isTypeArray: () => isTypeArray,
|
|
5130
5260
|
isTypeBool: () => isTypeBool,
|
|
5131
|
-
isTypeByteArray: () => isTypeByteArray,
|
|
5132
|
-
isTypeBytes31: () => isTypeBytes31,
|
|
5133
5261
|
isTypeContractAddress: () => isTypeContractAddress,
|
|
5134
5262
|
isTypeEnum: () => isTypeEnum,
|
|
5135
5263
|
isTypeEthAddress: () => isTypeEthAddress,
|
|
5136
5264
|
isTypeFelt: () => isTypeFelt,
|
|
5265
|
+
isTypeInt: () => isTypeInt,
|
|
5137
5266
|
isTypeLiteral: () => isTypeLiteral,
|
|
5138
5267
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
5139
5268
|
isTypeNonZero: () => isTypeNonZero,
|
|
@@ -5150,6 +5279,16 @@ ${indent}}` : "}";
|
|
|
5150
5279
|
uint512: () => uint512
|
|
5151
5280
|
});
|
|
5152
5281
|
|
|
5282
|
+
// src/utils/helpers.ts
|
|
5283
|
+
function addCompiledFlag(compiled) {
|
|
5284
|
+
Object.defineProperty(compiled, "__compiled__", {
|
|
5285
|
+
enumerable: false,
|
|
5286
|
+
writable: false,
|
|
5287
|
+
value: true
|
|
5288
|
+
});
|
|
5289
|
+
return compiled;
|
|
5290
|
+
}
|
|
5291
|
+
|
|
5153
5292
|
// src/utils/cairoDataTypes/felt.ts
|
|
5154
5293
|
function CairoFelt(it) {
|
|
5155
5294
|
if (isBigInt(it) || Number.isInteger(it)) {
|
|
@@ -5176,6 +5315,69 @@ ${indent}}` : "}";
|
|
|
5176
5315
|
}
|
|
5177
5316
|
throw new Error(`${it} can't be computed by felt()`);
|
|
5178
5317
|
}
|
|
5318
|
+
var CairoFelt252 = class _CairoFelt252 {
|
|
5319
|
+
/**
|
|
5320
|
+
* byte representation of the felt252
|
|
5321
|
+
*/
|
|
5322
|
+
data;
|
|
5323
|
+
static abiSelector = "core::felt252";
|
|
5324
|
+
constructor(data) {
|
|
5325
|
+
_CairoFelt252.validate(data);
|
|
5326
|
+
this.data = _CairoFelt252.__processData(data);
|
|
5327
|
+
}
|
|
5328
|
+
static __processData(data) {
|
|
5329
|
+
if (isString(data)) {
|
|
5330
|
+
return stringToUint8Array(data);
|
|
5331
|
+
}
|
|
5332
|
+
if (isBigInt(data)) {
|
|
5333
|
+
return bigIntToUint8Array(data);
|
|
5334
|
+
}
|
|
5335
|
+
if (Number.isInteger(data)) {
|
|
5336
|
+
return bigIntToUint8Array(BigInt(data));
|
|
5337
|
+
}
|
|
5338
|
+
if (isBoolean(data)) {
|
|
5339
|
+
return bigIntToUint8Array(BigInt(data ? 1 : 0));
|
|
5340
|
+
}
|
|
5341
|
+
throw new Error(`${data} can't be computed by felt()`);
|
|
5342
|
+
}
|
|
5343
|
+
toBigInt() {
|
|
5344
|
+
return uint8ArrayToBigInt(this.data);
|
|
5345
|
+
}
|
|
5346
|
+
decodeUtf8() {
|
|
5347
|
+
return new TextDecoder().decode(this.data);
|
|
5348
|
+
}
|
|
5349
|
+
toHexString() {
|
|
5350
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
5351
|
+
}
|
|
5352
|
+
toApiRequest() {
|
|
5353
|
+
return addCompiledFlag([this.toHexString()]);
|
|
5354
|
+
}
|
|
5355
|
+
static validate(data) {
|
|
5356
|
+
assert(data !== null, "null value is not allowed for felt252");
|
|
5357
|
+
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
5358
|
+
assert(
|
|
5359
|
+
isString(data) || isNumber2(data) || isBigInt(data) || isBoolean(data),
|
|
5360
|
+
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
5361
|
+
);
|
|
5362
|
+
const value = _CairoFelt252.__processData(data);
|
|
5363
|
+
const bn = uint8ArrayToBigInt(value);
|
|
5364
|
+
assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
|
|
5365
|
+
}
|
|
5366
|
+
static is(data) {
|
|
5367
|
+
try {
|
|
5368
|
+
_CairoFelt252.validate(data);
|
|
5369
|
+
return true;
|
|
5370
|
+
} catch {
|
|
5371
|
+
return false;
|
|
5372
|
+
}
|
|
5373
|
+
}
|
|
5374
|
+
static isAbiType(abiType) {
|
|
5375
|
+
return abiType === _CairoFelt252.abiSelector;
|
|
5376
|
+
}
|
|
5377
|
+
static factoryFromApiResponse(responseIterator) {
|
|
5378
|
+
return new _CairoFelt252(getNext(responseIterator));
|
|
5379
|
+
}
|
|
5380
|
+
};
|
|
5179
5381
|
|
|
5180
5382
|
// src/utils/cairoDataTypes/uint256.ts
|
|
5181
5383
|
var UINT_128_MAX = (1n << 128n) - 1n;
|
|
@@ -5187,11 +5389,16 @@ ${indent}}` : "}";
|
|
|
5187
5389
|
var UINT_256_HIGH_MIN = 0n;
|
|
5188
5390
|
var CairoUint256 = class _CairoUint256 {
|
|
5189
5391
|
low;
|
|
5392
|
+
// TODO should be u128
|
|
5190
5393
|
high;
|
|
5394
|
+
// TODO should be u128
|
|
5191
5395
|
static abiSelector = "core::integer::u256";
|
|
5192
5396
|
constructor(...arr) {
|
|
5193
5397
|
if (isObject2(arr[0]) && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
|
|
5194
|
-
const props = _CairoUint256.validateProps(
|
|
5398
|
+
const props = _CairoUint256.validateProps(
|
|
5399
|
+
arr[0].low,
|
|
5400
|
+
arr[0].high
|
|
5401
|
+
);
|
|
5195
5402
|
this.low = props.low;
|
|
5196
5403
|
this.high = props.high;
|
|
5197
5404
|
} else if (arr.length === 1) {
|
|
@@ -5210,9 +5417,15 @@ ${indent}}` : "}";
|
|
|
5210
5417
|
* Validate if BigNumberish can be represented as Unit256
|
|
5211
5418
|
*/
|
|
5212
5419
|
static validate(bigNumberish) {
|
|
5420
|
+
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
5421
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
5422
|
+
assert(
|
|
5423
|
+
isBigNumberish(bigNumberish) || isObject2(bigNumberish),
|
|
5424
|
+
`Unsupported data type '${typeof bigNumberish}' for u256. Expected string, number, bigint, or Uint256 object`
|
|
5425
|
+
);
|
|
5213
5426
|
const bigInt = BigInt(bigNumberish);
|
|
5214
|
-
|
|
5215
|
-
|
|
5427
|
+
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
5428
|
+
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
5216
5429
|
return bigInt;
|
|
5217
5430
|
}
|
|
5218
5431
|
/**
|
|
@@ -5221,12 +5434,14 @@ ${indent}}` : "}";
|
|
|
5221
5434
|
static validateProps(low, high) {
|
|
5222
5435
|
const bigIntLow = BigInt(low);
|
|
5223
5436
|
const bigIntHigh = BigInt(high);
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5437
|
+
assert(
|
|
5438
|
+
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
5439
|
+
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
5440
|
+
);
|
|
5441
|
+
assert(
|
|
5442
|
+
bigIntHigh >= UINT_256_HIGH_MIN && bigIntHigh <= UINT_256_HIGH_MAX,
|
|
5443
|
+
"high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX"
|
|
5444
|
+
);
|
|
5230
5445
|
return { low: bigIntLow, high: bigIntHigh };
|
|
5231
5446
|
}
|
|
5232
5447
|
/**
|
|
@@ -5246,6 +5461,11 @@ ${indent}}` : "}";
|
|
|
5246
5461
|
static isAbiType(abiType) {
|
|
5247
5462
|
return abiType === _CairoUint256.abiSelector;
|
|
5248
5463
|
}
|
|
5464
|
+
static factoryFromApiResponse(responseIterator) {
|
|
5465
|
+
const low = getNext(responseIterator);
|
|
5466
|
+
const high = getNext(responseIterator);
|
|
5467
|
+
return new _CairoUint256(low, high);
|
|
5468
|
+
}
|
|
5249
5469
|
/**
|
|
5250
5470
|
* Return bigint representation
|
|
5251
5471
|
*/
|
|
@@ -5286,9 +5506,13 @@ ${indent}}` : "}";
|
|
|
5286
5506
|
var UINT_128_MIN = 0n;
|
|
5287
5507
|
var CairoUint512 = class _CairoUint512 {
|
|
5288
5508
|
limb0;
|
|
5509
|
+
// TODO should be u128
|
|
5289
5510
|
limb1;
|
|
5511
|
+
// TODO should be u128
|
|
5290
5512
|
limb2;
|
|
5513
|
+
// TODO should be u128
|
|
5291
5514
|
limb3;
|
|
5515
|
+
// TODO should be u128
|
|
5292
5516
|
static abiSelector = "core::integer::u512";
|
|
5293
5517
|
constructor(...arr) {
|
|
5294
5518
|
if (isObject2(arr[0]) && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
@@ -5322,9 +5546,15 @@ ${indent}}` : "}";
|
|
|
5322
5546
|
* Validate if BigNumberish can be represented as Uint512
|
|
5323
5547
|
*/
|
|
5324
5548
|
static validate(bigNumberish) {
|
|
5549
|
+
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
5550
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
5551
|
+
assert(
|
|
5552
|
+
isBigNumberish(bigNumberish) || isObject2(bigNumberish),
|
|
5553
|
+
`Unsupported data type '${typeof bigNumberish}' for u512. Expected string, number, bigint, or Uint512 object`
|
|
5554
|
+
);
|
|
5325
5555
|
const bigInt = BigInt(bigNumberish);
|
|
5326
|
-
|
|
5327
|
-
|
|
5556
|
+
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
5557
|
+
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
5328
5558
|
return bigInt;
|
|
5329
5559
|
}
|
|
5330
5560
|
/**
|
|
@@ -5336,9 +5566,10 @@ ${indent}}` : "}";
|
|
|
5336
5566
|
const l2 = BigInt(limb2);
|
|
5337
5567
|
const l3 = BigInt(limb3);
|
|
5338
5568
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5569
|
+
assert(
|
|
5570
|
+
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
5571
|
+
`limb${index} is not in the range of a u128 number`
|
|
5572
|
+
);
|
|
5342
5573
|
});
|
|
5343
5574
|
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
5344
5575
|
}
|
|
@@ -5359,6 +5590,13 @@ ${indent}}` : "}";
|
|
|
5359
5590
|
static isAbiType(abiType) {
|
|
5360
5591
|
return abiType === _CairoUint512.abiSelector;
|
|
5361
5592
|
}
|
|
5593
|
+
static factoryFromApiResponse(responseIterator) {
|
|
5594
|
+
const limb0 = getNext(responseIterator);
|
|
5595
|
+
const limb1 = getNext(responseIterator);
|
|
5596
|
+
const limb2 = getNext(responseIterator);
|
|
5597
|
+
const limb3 = getNext(responseIterator);
|
|
5598
|
+
return new _CairoUint512(limb0, limb1, limb2, limb3);
|
|
5599
|
+
}
|
|
5362
5600
|
/**
|
|
5363
5601
|
* Return bigint representation
|
|
5364
5602
|
*/
|
|
@@ -5413,13 +5651,12 @@ ${indent}}` : "}";
|
|
|
5413
5651
|
var isTypeOption = (type) => type.startsWith("core::option::Option::");
|
|
5414
5652
|
var isTypeResult = (type) => type.startsWith("core::result::Result::");
|
|
5415
5653
|
var isTypeUint = (type) => Object.values(Uint).includes(type);
|
|
5654
|
+
var isTypeInt = (type) => Object.values(Int).includes(type);
|
|
5416
5655
|
var isTypeUint256 = (type) => CairoUint256.isAbiType(type);
|
|
5417
5656
|
var isTypeLiteral = (type) => Object.values(Literal).includes(type);
|
|
5418
5657
|
var isTypeBool = (type) => type === "core::bool";
|
|
5419
5658
|
var isTypeContractAddress = (type) => type === Literal.ContractAddress;
|
|
5420
5659
|
var isTypeEthAddress = (type) => type === ETH_ADDRESS;
|
|
5421
|
-
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
5422
|
-
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
5423
5660
|
var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>";
|
|
5424
5661
|
var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
|
|
5425
5662
|
var isCairo1Type = (type) => type.includes("::");
|
|
@@ -5674,15 +5911,1348 @@ ${indent}}` : "}";
|
|
|
5674
5911
|
guard.unknown(data, type, key);
|
|
5675
5912
|
return acc;
|
|
5676
5913
|
},
|
|
5677
|
-
{}
|
|
5678
|
-
);
|
|
5679
|
-
}
|
|
5914
|
+
{}
|
|
5915
|
+
);
|
|
5916
|
+
}
|
|
5917
|
+
|
|
5918
|
+
// src/utils/calldata/parser/interface.ts
|
|
5919
|
+
var AbiParserInterface = class {
|
|
5920
|
+
};
|
|
5921
|
+
|
|
5922
|
+
// src/utils/cairoDataTypes/bytes31.ts
|
|
5923
|
+
var CairoBytes31 = class _CairoBytes31 {
|
|
5924
|
+
static MAX_BYTE_SIZE = 31;
|
|
5925
|
+
data;
|
|
5926
|
+
static abiSelector = "core::bytes_31::bytes31";
|
|
5927
|
+
constructor(data) {
|
|
5928
|
+
_CairoBytes31.validate(data);
|
|
5929
|
+
this.data = _CairoBytes31.__processData(data);
|
|
5930
|
+
}
|
|
5931
|
+
static __processData(data) {
|
|
5932
|
+
if (isString(data)) {
|
|
5933
|
+
return stringToUint8Array(data);
|
|
5934
|
+
}
|
|
5935
|
+
if (isBuffer(data)) {
|
|
5936
|
+
return new Uint8Array(data);
|
|
5937
|
+
}
|
|
5938
|
+
if (data instanceof Uint8Array) {
|
|
5939
|
+
return new Uint8Array(data);
|
|
5940
|
+
}
|
|
5941
|
+
throw new Error("Invalid input type for CairoBytes31. Expected string, Buffer, or Uint8Array");
|
|
5942
|
+
}
|
|
5943
|
+
toApiRequest() {
|
|
5944
|
+
return addCompiledFlag([this.toHexString()]);
|
|
5945
|
+
}
|
|
5946
|
+
toBigInt() {
|
|
5947
|
+
return uint8ArrayToBigInt(this.data);
|
|
5948
|
+
}
|
|
5949
|
+
decodeUtf8() {
|
|
5950
|
+
return new TextDecoder().decode(this.data);
|
|
5951
|
+
}
|
|
5952
|
+
toHexString() {
|
|
5953
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
5954
|
+
}
|
|
5955
|
+
static validate(data) {
|
|
5956
|
+
const byteLength = _CairoBytes31.__processData(data).length;
|
|
5957
|
+
assert(
|
|
5958
|
+
byteLength <= this.MAX_BYTE_SIZE,
|
|
5959
|
+
`Data is too long: ${byteLength} bytes (max ${this.MAX_BYTE_SIZE} bytes)`
|
|
5960
|
+
);
|
|
5961
|
+
}
|
|
5962
|
+
static is(data) {
|
|
5963
|
+
try {
|
|
5964
|
+
_CairoBytes31.validate(data);
|
|
5965
|
+
return true;
|
|
5966
|
+
} catch {
|
|
5967
|
+
return false;
|
|
5968
|
+
}
|
|
5969
|
+
}
|
|
5970
|
+
/**
|
|
5971
|
+
* Check if provided abi type is this data type
|
|
5972
|
+
*/
|
|
5973
|
+
static isAbiType(abiType) {
|
|
5974
|
+
return abiType === _CairoBytes31.abiSelector;
|
|
5975
|
+
}
|
|
5976
|
+
static factoryFromApiResponse(responseIterator) {
|
|
5977
|
+
return new _CairoBytes31(getNext(responseIterator));
|
|
5978
|
+
}
|
|
5979
|
+
};
|
|
5980
|
+
|
|
5981
|
+
// src/utils/errors/rpc.ts
|
|
5982
|
+
var errorCodes = {
|
|
5983
|
+
FAILED_TO_RECEIVE_TXN: 1,
|
|
5984
|
+
NO_TRACE_AVAILABLE: 10,
|
|
5985
|
+
CONTRACT_NOT_FOUND: 20,
|
|
5986
|
+
ENTRYPOINT_NOT_FOUND: 21,
|
|
5987
|
+
BLOCK_NOT_FOUND: 24,
|
|
5988
|
+
INVALID_TXN_INDEX: 27,
|
|
5989
|
+
CLASS_HASH_NOT_FOUND: 28,
|
|
5990
|
+
TXN_HASH_NOT_FOUND: 29,
|
|
5991
|
+
PAGE_SIZE_TOO_BIG: 31,
|
|
5992
|
+
NO_BLOCKS: 32,
|
|
5993
|
+
INVALID_CONTINUATION_TOKEN: 33,
|
|
5994
|
+
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
5995
|
+
CONTRACT_ERROR: 40,
|
|
5996
|
+
TRANSACTION_EXECUTION_ERROR: 41,
|
|
5997
|
+
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
5998
|
+
CLASS_ALREADY_DECLARED: 51,
|
|
5999
|
+
INVALID_TRANSACTION_NONCE: 52,
|
|
6000
|
+
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
6001
|
+
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
6002
|
+
VALIDATION_FAILURE: 55,
|
|
6003
|
+
COMPILATION_FAILED: 56,
|
|
6004
|
+
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
6005
|
+
NON_ACCOUNT: 58,
|
|
6006
|
+
DUPLICATE_TX: 59,
|
|
6007
|
+
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
6008
|
+
UNSUPPORTED_TX_VERSION: 61,
|
|
6009
|
+
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
6010
|
+
UNEXPECTED_ERROR: 63,
|
|
6011
|
+
INVALID_SUBSCRIPTION_ID: 66,
|
|
6012
|
+
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
6013
|
+
TOO_MANY_BLOCKS_BACK: 68,
|
|
6014
|
+
COMPILATION_ERROR: 100,
|
|
6015
|
+
INVALID_ADDRESS: 150,
|
|
6016
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
6017
|
+
INVALID_SIGNATURE: 153,
|
|
6018
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
6019
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
6020
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
6021
|
+
INVALID_TIME_BOUNDS: 157,
|
|
6022
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
6023
|
+
INVALID_CLASS_HASH: 159,
|
|
6024
|
+
INVALID_ID: 160,
|
|
6025
|
+
UNKNOWN_ERROR: 163
|
|
6026
|
+
};
|
|
6027
|
+
var rpc_default = errorCodes;
|
|
6028
|
+
|
|
6029
|
+
// src/utils/errors/index.ts
|
|
6030
|
+
function fixStack(target, fn = target.constructor) {
|
|
6031
|
+
const { captureStackTrace } = Error;
|
|
6032
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
6033
|
+
}
|
|
6034
|
+
function fixProto(target, prototype) {
|
|
6035
|
+
const { setPrototypeOf } = Object;
|
|
6036
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
6037
|
+
}
|
|
6038
|
+
var CustomError = class extends Error {
|
|
6039
|
+
name;
|
|
6040
|
+
constructor(message) {
|
|
6041
|
+
super(message);
|
|
6042
|
+
Object.defineProperty(this, "name", {
|
|
6043
|
+
value: new.target.name,
|
|
6044
|
+
enumerable: false,
|
|
6045
|
+
configurable: true
|
|
6046
|
+
});
|
|
6047
|
+
fixProto(this, new.target.prototype);
|
|
6048
|
+
fixStack(this);
|
|
6049
|
+
}
|
|
6050
|
+
};
|
|
6051
|
+
var LibraryError = class extends CustomError {
|
|
6052
|
+
};
|
|
6053
|
+
var RpcError = class extends LibraryError {
|
|
6054
|
+
constructor(baseError, method, params) {
|
|
6055
|
+
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
6056
|
+
|
|
6057
|
+
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
6058
|
+
this.baseError = baseError;
|
|
6059
|
+
this.request = { method, params };
|
|
6060
|
+
}
|
|
6061
|
+
request;
|
|
6062
|
+
get code() {
|
|
6063
|
+
return this.baseError.code;
|
|
6064
|
+
}
|
|
6065
|
+
/**
|
|
6066
|
+
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
6067
|
+
* @example
|
|
6068
|
+
* ```typescript
|
|
6069
|
+
* SomeError.isType('UNEXPECTED_ERROR');
|
|
6070
|
+
* ```
|
|
6071
|
+
*/
|
|
6072
|
+
isType(typeName) {
|
|
6073
|
+
return rpc_default[typeName] === this.code;
|
|
6074
|
+
}
|
|
6075
|
+
};
|
|
6076
|
+
var TimeoutError = class extends LibraryError {
|
|
6077
|
+
constructor(message) {
|
|
6078
|
+
super(message);
|
|
6079
|
+
this.name = "TimeoutError";
|
|
6080
|
+
}
|
|
6081
|
+
};
|
|
6082
|
+
var WebSocketNotConnectedError = class extends LibraryError {
|
|
6083
|
+
constructor(message) {
|
|
6084
|
+
super(message);
|
|
6085
|
+
this.name = "WebSocketNotConnectedError";
|
|
6086
|
+
}
|
|
6087
|
+
};
|
|
6088
|
+
|
|
6089
|
+
// src/utils/connect/buffer.ts
|
|
6090
|
+
var buffer_default = config.get("buffer") || typeof Buffer !== "undefined" && Buffer || typeof globalThis !== "undefined" && globalThis.Buffer || typeof window !== "undefined" && window.Buffer || typeof global !== "undefined" && global.Buffer || class {
|
|
6091
|
+
constructor() {
|
|
6092
|
+
throw new LibraryError(
|
|
6093
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
6094
|
+
);
|
|
6095
|
+
}
|
|
6096
|
+
static from(_data) {
|
|
6097
|
+
throw new LibraryError(
|
|
6098
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
6099
|
+
);
|
|
6100
|
+
}
|
|
6101
|
+
static isBuffer(obj) {
|
|
6102
|
+
const BufferImpl = config.get("buffer") || typeof Buffer !== "undefined" && Buffer;
|
|
6103
|
+
return BufferImpl && BufferImpl.isBuffer && BufferImpl.isBuffer(obj);
|
|
6104
|
+
}
|
|
6105
|
+
};
|
|
6106
|
+
|
|
6107
|
+
// src/utils/cairoDataTypes/uint32.ts
|
|
6108
|
+
var CairoUint32 = class _CairoUint32 {
|
|
6109
|
+
data;
|
|
6110
|
+
static abiSelector = "core::u32::u32";
|
|
6111
|
+
constructor(data) {
|
|
6112
|
+
_CairoUint32.validate(data);
|
|
6113
|
+
this.data = _CairoUint32.__processData(data);
|
|
6114
|
+
}
|
|
6115
|
+
static __processData(data) {
|
|
6116
|
+
if (isString(data) && isText(data)) {
|
|
6117
|
+
return utf8ToBigInt(data);
|
|
6118
|
+
}
|
|
6119
|
+
return BigInt(data);
|
|
6120
|
+
}
|
|
6121
|
+
toApiRequest() {
|
|
6122
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6123
|
+
}
|
|
6124
|
+
toBigInt() {
|
|
6125
|
+
return this.data;
|
|
6126
|
+
}
|
|
6127
|
+
decodeUtf8() {
|
|
6128
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6129
|
+
}
|
|
6130
|
+
toHexString() {
|
|
6131
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6132
|
+
}
|
|
6133
|
+
static validate(data) {
|
|
6134
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6135
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6136
|
+
assert(
|
|
6137
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6138
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6139
|
+
);
|
|
6140
|
+
const value = _CairoUint32.__processData(data);
|
|
6141
|
+
assert(value >= 0n && value <= 2n ** 32n - 1n, "Value is out of u32 range [0, 2^32)");
|
|
6142
|
+
}
|
|
6143
|
+
static is(data) {
|
|
6144
|
+
try {
|
|
6145
|
+
_CairoUint32.validate(data);
|
|
6146
|
+
return true;
|
|
6147
|
+
} catch {
|
|
6148
|
+
return false;
|
|
6149
|
+
}
|
|
6150
|
+
}
|
|
6151
|
+
/**
|
|
6152
|
+
* Check if provided abi type is this data type
|
|
6153
|
+
*/
|
|
6154
|
+
static isAbiType(abiType) {
|
|
6155
|
+
return abiType === _CairoUint32.abiSelector;
|
|
6156
|
+
}
|
|
6157
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6158
|
+
return new _CairoUint32(getNext(responseIterator));
|
|
6159
|
+
}
|
|
6160
|
+
};
|
|
6161
|
+
|
|
6162
|
+
// src/utils/cairoDataTypes/byteArray.ts
|
|
6163
|
+
var CairoByteArray = class _CairoByteArray {
|
|
6164
|
+
/**
|
|
6165
|
+
* entire dataset
|
|
6166
|
+
*/
|
|
6167
|
+
data = [];
|
|
6168
|
+
/**
|
|
6169
|
+
* cairo specific implementation helper
|
|
6170
|
+
*/
|
|
6171
|
+
pending_word;
|
|
6172
|
+
// felt
|
|
6173
|
+
/**
|
|
6174
|
+
* cairo specific implementation helper
|
|
6175
|
+
*/
|
|
6176
|
+
pending_word_len;
|
|
6177
|
+
// u32
|
|
6178
|
+
static abiSelector = "core::byte_array::ByteArray";
|
|
6179
|
+
constructor(...arr) {
|
|
6180
|
+
if (arr.length === 3) {
|
|
6181
|
+
const [dataArg, pendingWord, pendingWordLen] = arr;
|
|
6182
|
+
assert(
|
|
6183
|
+
Array.isArray(dataArg) && pendingWord instanceof CairoFelt252 && pendingWordLen instanceof CairoUint32,
|
|
6184
|
+
"Invalid constructor parameters. Expected (CairoBytes31[], CairoFelt252, CairoUint32)"
|
|
6185
|
+
);
|
|
6186
|
+
this.data = dataArg;
|
|
6187
|
+
this.pending_word = pendingWord;
|
|
6188
|
+
this.pending_word_len = pendingWordLen;
|
|
6189
|
+
return;
|
|
6190
|
+
}
|
|
6191
|
+
const inData = arr[0];
|
|
6192
|
+
_CairoByteArray.validate(inData);
|
|
6193
|
+
const { data, pending_word, pending_word_len } = _CairoByteArray.__processData(inData);
|
|
6194
|
+
this.data = data;
|
|
6195
|
+
this.pending_word = pending_word;
|
|
6196
|
+
this.pending_word_len = pending_word_len;
|
|
6197
|
+
}
|
|
6198
|
+
static __processData(inData) {
|
|
6199
|
+
let fullData;
|
|
6200
|
+
if (inData instanceof Uint8Array) {
|
|
6201
|
+
fullData = inData;
|
|
6202
|
+
} else if (isBuffer(inData)) {
|
|
6203
|
+
fullData = new Uint8Array(inData);
|
|
6204
|
+
} else if (isString(inData)) {
|
|
6205
|
+
fullData = stringToUint8Array(inData);
|
|
6206
|
+
} else if (isBigInt(inData)) {
|
|
6207
|
+
fullData = bigIntToUint8Array(inData);
|
|
6208
|
+
} else if (isInteger2(inData)) {
|
|
6209
|
+
fullData = bigIntToUint8Array(BigInt(inData));
|
|
6210
|
+
} else {
|
|
6211
|
+
throw new Error("Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint");
|
|
6212
|
+
}
|
|
6213
|
+
const CHUNK_SIZE = CairoBytes31.MAX_BYTE_SIZE;
|
|
6214
|
+
const completeChunks = Math.floor(fullData.length / CHUNK_SIZE);
|
|
6215
|
+
const remainderLength = fullData.length % CHUNK_SIZE;
|
|
6216
|
+
const data = [];
|
|
6217
|
+
let pending_word;
|
|
6218
|
+
let pending_word_len;
|
|
6219
|
+
for (let i = 0; i < completeChunks; i += 1) {
|
|
6220
|
+
const chunkStart = i * CHUNK_SIZE;
|
|
6221
|
+
const chunkEnd = chunkStart + CHUNK_SIZE;
|
|
6222
|
+
const chunk = fullData.slice(chunkStart, chunkEnd);
|
|
6223
|
+
data.push(new CairoBytes31(chunk));
|
|
6224
|
+
}
|
|
6225
|
+
if (remainderLength > 0) {
|
|
6226
|
+
const remainder = fullData.slice(completeChunks * CHUNK_SIZE);
|
|
6227
|
+
let hex = "0x";
|
|
6228
|
+
for (let i = 0; i < remainder.length; i += 1) {
|
|
6229
|
+
hex += remainder[i].toString(16).padStart(2, "0");
|
|
6230
|
+
}
|
|
6231
|
+
pending_word = new CairoFelt252(hex);
|
|
6232
|
+
pending_word_len = new CairoUint32(remainderLength);
|
|
6233
|
+
} else {
|
|
6234
|
+
pending_word = new CairoFelt252(0);
|
|
6235
|
+
pending_word_len = new CairoUint32(0);
|
|
6236
|
+
}
|
|
6237
|
+
return { data, pending_word, pending_word_len };
|
|
6238
|
+
}
|
|
6239
|
+
toApiRequest() {
|
|
6240
|
+
this.assertInitialized();
|
|
6241
|
+
return addCompiledFlag([
|
|
6242
|
+
addHexPrefix(this.data.length.toString(16)),
|
|
6243
|
+
...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
|
|
6244
|
+
...this.pending_word.toApiRequest(),
|
|
6245
|
+
...this.pending_word_len.toApiRequest()
|
|
6246
|
+
]);
|
|
6247
|
+
}
|
|
6248
|
+
decodeUtf8() {
|
|
6249
|
+
const allBytes = this.reconstructBytes();
|
|
6250
|
+
const fullBytes = new Uint8Array(allBytes);
|
|
6251
|
+
return new TextDecoder().decode(fullBytes);
|
|
6252
|
+
}
|
|
6253
|
+
toBigInt() {
|
|
6254
|
+
const allBytes = this.reconstructBytes();
|
|
6255
|
+
if (allBytes.length === 0) {
|
|
6256
|
+
return 0n;
|
|
6257
|
+
}
|
|
6258
|
+
let result = 0n;
|
|
6259
|
+
allBytes.forEach((byte) => {
|
|
6260
|
+
result = result * 256n + BigInt(byte);
|
|
6261
|
+
});
|
|
6262
|
+
return result;
|
|
6263
|
+
}
|
|
6264
|
+
toHexString() {
|
|
6265
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6266
|
+
}
|
|
6267
|
+
toBuffer() {
|
|
6268
|
+
this.assertInitialized();
|
|
6269
|
+
const allBytes = [];
|
|
6270
|
+
this.data.forEach((chunk) => {
|
|
6271
|
+
const chunkBytes = chunk.data;
|
|
6272
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
6273
|
+
allBytes.push(chunkBytes[i]);
|
|
6274
|
+
}
|
|
6275
|
+
});
|
|
6276
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
6277
|
+
if (pendingLen > 0) {
|
|
6278
|
+
const hex = this.pending_word.toHexString();
|
|
6279
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
6280
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
6281
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
6282
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
6283
|
+
if (byteHex.length >= 2) {
|
|
6284
|
+
const byteValue = parseInt(byteHex, 16);
|
|
6285
|
+
if (!Number.isNaN(byteValue)) {
|
|
6286
|
+
allBytes.push(byteValue);
|
|
6287
|
+
}
|
|
6288
|
+
}
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
return buffer_default.from(allBytes);
|
|
6292
|
+
}
|
|
6293
|
+
static validate(data) {
|
|
6294
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6295
|
+
assert(
|
|
6296
|
+
!Array.isArray(data) || data instanceof Uint8Array,
|
|
6297
|
+
"Invalid input: arrays are not supported, use Uint8Array"
|
|
6298
|
+
);
|
|
6299
|
+
assert(
|
|
6300
|
+
typeof data !== "object" || isBuffer(data) || data instanceof Uint8Array,
|
|
6301
|
+
"Invalid input for CairoByteArray: objects are not supported"
|
|
6302
|
+
);
|
|
6303
|
+
assert(
|
|
6304
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6305
|
+
"Invalid input for CairoByteArray: decimal numbers are not supported, only integers"
|
|
6306
|
+
);
|
|
6307
|
+
assert(
|
|
6308
|
+
!isNumber2(data) || data >= 0,
|
|
6309
|
+
"Invalid input for CairoByteArray: negative numbers are not supported"
|
|
6310
|
+
);
|
|
6311
|
+
assert(
|
|
6312
|
+
!isBigInt(data) || data >= 0n,
|
|
6313
|
+
"Invalid input for CairoByteArray: negative bigints are not supported"
|
|
6314
|
+
);
|
|
6315
|
+
assert(
|
|
6316
|
+
data instanceof Uint8Array || isBuffer(data) || isString(data) || isNumber2(data) || isBigInt(data),
|
|
6317
|
+
"Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint"
|
|
6318
|
+
);
|
|
6319
|
+
}
|
|
6320
|
+
/**
|
|
6321
|
+
* Check if the provided data is a valid CairoByteArray
|
|
6322
|
+
*
|
|
6323
|
+
* @param data - The data to check
|
|
6324
|
+
* @returns True if the data is a valid CairoByteArray, false otherwise
|
|
6325
|
+
*/
|
|
6326
|
+
static is(data) {
|
|
6327
|
+
try {
|
|
6328
|
+
_CairoByteArray.validate(data);
|
|
6329
|
+
return true;
|
|
6330
|
+
} catch {
|
|
6331
|
+
return false;
|
|
6332
|
+
}
|
|
6333
|
+
}
|
|
6334
|
+
/**
|
|
6335
|
+
* Check if provided abi type is this data type
|
|
6336
|
+
*/
|
|
6337
|
+
static isAbiType(abiType) {
|
|
6338
|
+
return abiType === _CairoByteArray.abiSelector;
|
|
6339
|
+
}
|
|
6340
|
+
/**
|
|
6341
|
+
* Private helper to check if the CairoByteArray is properly initialized
|
|
6342
|
+
*/
|
|
6343
|
+
assertInitialized() {
|
|
6344
|
+
assert(
|
|
6345
|
+
this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
|
|
6346
|
+
"CairoByteArray is not properly initialized"
|
|
6347
|
+
);
|
|
6348
|
+
}
|
|
6349
|
+
/**
|
|
6350
|
+
* Private helper to reconstruct the full byte sequence from chunks and pending word
|
|
6351
|
+
*/
|
|
6352
|
+
reconstructBytes() {
|
|
6353
|
+
this.assertInitialized();
|
|
6354
|
+
const allBytes = [];
|
|
6355
|
+
this.data.forEach((chunk) => {
|
|
6356
|
+
const chunkBytes = chunk.data;
|
|
6357
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
6358
|
+
allBytes.push(chunkBytes[i]);
|
|
6359
|
+
}
|
|
6360
|
+
});
|
|
6361
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
6362
|
+
if (pendingLen > 0) {
|
|
6363
|
+
const hex = this.pending_word.toHexString();
|
|
6364
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
6365
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
6366
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
6367
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
6368
|
+
if (byteHex.length < 2) {
|
|
6369
|
+
allBytes.push(0);
|
|
6370
|
+
} else {
|
|
6371
|
+
const byteValue = parseInt(byteHex, 16);
|
|
6372
|
+
if (Number.isNaN(byteValue)) {
|
|
6373
|
+
throw new Error(`Invalid hex byte: ${byteHex}`);
|
|
6374
|
+
}
|
|
6375
|
+
allBytes.push(byteValue);
|
|
6376
|
+
}
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6379
|
+
return allBytes;
|
|
6380
|
+
}
|
|
6381
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6382
|
+
const data = Array.from(
|
|
6383
|
+
{ length: Number(getNext(responseIterator)) },
|
|
6384
|
+
() => CairoBytes31.factoryFromApiResponse(responseIterator)
|
|
6385
|
+
);
|
|
6386
|
+
const pending_word = CairoFelt252.factoryFromApiResponse(responseIterator);
|
|
6387
|
+
const pending_word_len = CairoUint32.factoryFromApiResponse(responseIterator);
|
|
6388
|
+
return new _CairoByteArray(data, pending_word, pending_word_len);
|
|
6389
|
+
}
|
|
6390
|
+
};
|
|
6391
|
+
|
|
6392
|
+
// src/utils/cairoDataTypes/uint8.ts
|
|
6393
|
+
var CairoUint8 = class _CairoUint8 {
|
|
6394
|
+
data;
|
|
6395
|
+
static abiSelector = "core::integer::u8";
|
|
6396
|
+
constructor(data) {
|
|
6397
|
+
_CairoUint8.validate(data);
|
|
6398
|
+
this.data = _CairoUint8.__processData(data);
|
|
6399
|
+
}
|
|
6400
|
+
static __processData(data) {
|
|
6401
|
+
if (isString(data) && isText(data)) {
|
|
6402
|
+
return utf8ToBigInt(data);
|
|
6403
|
+
}
|
|
6404
|
+
return BigInt(data);
|
|
6405
|
+
}
|
|
6406
|
+
toApiRequest() {
|
|
6407
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6408
|
+
}
|
|
6409
|
+
toBigInt() {
|
|
6410
|
+
return this.data;
|
|
6411
|
+
}
|
|
6412
|
+
decodeUtf8() {
|
|
6413
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6414
|
+
}
|
|
6415
|
+
toHexString() {
|
|
6416
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6417
|
+
}
|
|
6418
|
+
static validate(data) {
|
|
6419
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6420
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6421
|
+
assert(
|
|
6422
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6423
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6424
|
+
);
|
|
6425
|
+
const value = _CairoUint8.__processData(data);
|
|
6426
|
+
assert(
|
|
6427
|
+
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
6428
|
+
`Value is out of u8 range [${RANGE_U8.min}, ${RANGE_U8.max}]`
|
|
6429
|
+
);
|
|
6430
|
+
}
|
|
6431
|
+
static is(data) {
|
|
6432
|
+
try {
|
|
6433
|
+
_CairoUint8.validate(data);
|
|
6434
|
+
return true;
|
|
6435
|
+
} catch {
|
|
6436
|
+
return false;
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
/**
|
|
6440
|
+
* Check if provided abi type is this data type
|
|
6441
|
+
*/
|
|
6442
|
+
static isAbiType(abiType) {
|
|
6443
|
+
return abiType === _CairoUint8.abiSelector;
|
|
6444
|
+
}
|
|
6445
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6446
|
+
return new _CairoUint8(getNext(responseIterator));
|
|
6447
|
+
}
|
|
6448
|
+
};
|
|
6449
|
+
|
|
6450
|
+
// src/utils/cairoDataTypes/uint16.ts
|
|
6451
|
+
var CairoUint16 = class _CairoUint16 {
|
|
6452
|
+
data;
|
|
6453
|
+
static abiSelector = "core::integer::u16";
|
|
6454
|
+
constructor(data) {
|
|
6455
|
+
_CairoUint16.validate(data);
|
|
6456
|
+
this.data = _CairoUint16.__processData(data);
|
|
6457
|
+
}
|
|
6458
|
+
static __processData(data) {
|
|
6459
|
+
if (isString(data) && isText(data)) {
|
|
6460
|
+
return utf8ToBigInt(data);
|
|
6461
|
+
}
|
|
6462
|
+
return BigInt(data);
|
|
6463
|
+
}
|
|
6464
|
+
toApiRequest() {
|
|
6465
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6466
|
+
}
|
|
6467
|
+
toBigInt() {
|
|
6468
|
+
return this.data;
|
|
6469
|
+
}
|
|
6470
|
+
decodeUtf8() {
|
|
6471
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6472
|
+
}
|
|
6473
|
+
toHexString() {
|
|
6474
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6475
|
+
}
|
|
6476
|
+
static validate(data) {
|
|
6477
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6478
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6479
|
+
assert(
|
|
6480
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6481
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6482
|
+
);
|
|
6483
|
+
const value = _CairoUint16.__processData(data);
|
|
6484
|
+
assert(
|
|
6485
|
+
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
6486
|
+
`Value is out of u16 range [${RANGE_U16.min}, ${RANGE_U16.max}]`
|
|
6487
|
+
);
|
|
6488
|
+
}
|
|
6489
|
+
static is(data) {
|
|
6490
|
+
try {
|
|
6491
|
+
_CairoUint16.validate(data);
|
|
6492
|
+
return true;
|
|
6493
|
+
} catch {
|
|
6494
|
+
return false;
|
|
6495
|
+
}
|
|
6496
|
+
}
|
|
6497
|
+
/**
|
|
6498
|
+
* Check if provided abi type is this data type
|
|
6499
|
+
*/
|
|
6500
|
+
static isAbiType(abiType) {
|
|
6501
|
+
return abiType === _CairoUint16.abiSelector;
|
|
6502
|
+
}
|
|
6503
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6504
|
+
return new _CairoUint16(getNext(responseIterator));
|
|
6505
|
+
}
|
|
6506
|
+
};
|
|
6507
|
+
|
|
6508
|
+
// src/utils/cairoDataTypes/uint64.ts
|
|
6509
|
+
var CairoUint64 = class _CairoUint64 {
|
|
6510
|
+
data;
|
|
6511
|
+
static abiSelector = "core::integer::u64";
|
|
6512
|
+
constructor(data) {
|
|
6513
|
+
_CairoUint64.validate(data);
|
|
6514
|
+
this.data = _CairoUint64.__processData(data);
|
|
6515
|
+
}
|
|
6516
|
+
static __processData(data) {
|
|
6517
|
+
if (isString(data) && isText(data)) {
|
|
6518
|
+
return utf8ToBigInt(data);
|
|
6519
|
+
}
|
|
6520
|
+
return BigInt(data);
|
|
6521
|
+
}
|
|
6522
|
+
toApiRequest() {
|
|
6523
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6524
|
+
}
|
|
6525
|
+
toBigInt() {
|
|
6526
|
+
return this.data;
|
|
6527
|
+
}
|
|
6528
|
+
decodeUtf8() {
|
|
6529
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6530
|
+
}
|
|
6531
|
+
toHexString() {
|
|
6532
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6533
|
+
}
|
|
6534
|
+
static validate(data) {
|
|
6535
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6536
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6537
|
+
assert(
|
|
6538
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6539
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6540
|
+
);
|
|
6541
|
+
const value = _CairoUint64.__processData(data);
|
|
6542
|
+
assert(
|
|
6543
|
+
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
6544
|
+
`Value is out of u64 range [${RANGE_U64.min}, ${RANGE_U64.max}]`
|
|
6545
|
+
);
|
|
6546
|
+
}
|
|
6547
|
+
static is(data) {
|
|
6548
|
+
try {
|
|
6549
|
+
_CairoUint64.validate(data);
|
|
6550
|
+
return true;
|
|
6551
|
+
} catch {
|
|
6552
|
+
return false;
|
|
6553
|
+
}
|
|
6554
|
+
}
|
|
6555
|
+
/**
|
|
6556
|
+
* Check if provided abi type is this data type
|
|
6557
|
+
*/
|
|
6558
|
+
static isAbiType(abiType) {
|
|
6559
|
+
return abiType === _CairoUint64.abiSelector;
|
|
6560
|
+
}
|
|
6561
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6562
|
+
return new _CairoUint64(getNext(responseIterator));
|
|
6563
|
+
}
|
|
6564
|
+
};
|
|
6565
|
+
|
|
6566
|
+
// src/utils/cairoDataTypes/uint96.ts
|
|
6567
|
+
var CairoUint96 = class _CairoUint96 {
|
|
6568
|
+
data;
|
|
6569
|
+
static abiSelector = "core::integer::u96";
|
|
6570
|
+
constructor(data) {
|
|
6571
|
+
_CairoUint96.validate(data);
|
|
6572
|
+
this.data = _CairoUint96.__processData(data);
|
|
6573
|
+
}
|
|
6574
|
+
static __processData(data) {
|
|
6575
|
+
if (isString(data) && isText(data)) {
|
|
6576
|
+
return utf8ToBigInt(data);
|
|
6577
|
+
}
|
|
6578
|
+
return BigInt(data);
|
|
6579
|
+
}
|
|
6580
|
+
toApiRequest() {
|
|
6581
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6582
|
+
}
|
|
6583
|
+
toBigInt() {
|
|
6584
|
+
return this.data;
|
|
6585
|
+
}
|
|
6586
|
+
decodeUtf8() {
|
|
6587
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6588
|
+
}
|
|
6589
|
+
toHexString() {
|
|
6590
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6591
|
+
}
|
|
6592
|
+
static validate(data) {
|
|
6593
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6594
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6595
|
+
assert(
|
|
6596
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6597
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6598
|
+
);
|
|
6599
|
+
const value = _CairoUint96.__processData(data);
|
|
6600
|
+
assert(
|
|
6601
|
+
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
6602
|
+
`Value is out of u96 range [${RANGE_U96.min}, ${RANGE_U96.max}]`
|
|
6603
|
+
);
|
|
6604
|
+
}
|
|
6605
|
+
static is(data) {
|
|
6606
|
+
try {
|
|
6607
|
+
_CairoUint96.validate(data);
|
|
6608
|
+
return true;
|
|
6609
|
+
} catch {
|
|
6610
|
+
return false;
|
|
6611
|
+
}
|
|
6612
|
+
}
|
|
6613
|
+
/**
|
|
6614
|
+
* Check if provided abi type is this data type
|
|
6615
|
+
*/
|
|
6616
|
+
static isAbiType(abiType) {
|
|
6617
|
+
return abiType === _CairoUint96.abiSelector;
|
|
6618
|
+
}
|
|
6619
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6620
|
+
return new _CairoUint96(getNext(responseIterator));
|
|
6621
|
+
}
|
|
6622
|
+
};
|
|
6623
|
+
|
|
6624
|
+
// src/utils/cairoDataTypes/uint128.ts
|
|
6625
|
+
var CairoUint128 = class _CairoUint128 {
|
|
6626
|
+
data;
|
|
6627
|
+
static abiSelector = "core::integer::u128";
|
|
6628
|
+
constructor(data) {
|
|
6629
|
+
_CairoUint128.validate(data);
|
|
6630
|
+
this.data = _CairoUint128.__processData(data);
|
|
6631
|
+
}
|
|
6632
|
+
static __processData(data) {
|
|
6633
|
+
if (isString(data) && isText(data)) {
|
|
6634
|
+
return utf8ToBigInt(data);
|
|
6635
|
+
}
|
|
6636
|
+
return BigInt(data);
|
|
6637
|
+
}
|
|
6638
|
+
toApiRequest() {
|
|
6639
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6640
|
+
}
|
|
6641
|
+
toBigInt() {
|
|
6642
|
+
return this.data;
|
|
6643
|
+
}
|
|
6644
|
+
decodeUtf8() {
|
|
6645
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
6646
|
+
}
|
|
6647
|
+
toHexString() {
|
|
6648
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
6649
|
+
}
|
|
6650
|
+
static validate(data) {
|
|
6651
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6652
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6653
|
+
assert(
|
|
6654
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6655
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6656
|
+
);
|
|
6657
|
+
const value = _CairoUint128.__processData(data);
|
|
6658
|
+
assert(
|
|
6659
|
+
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
6660
|
+
`Value is out of u128 range [${RANGE_U128.min}, ${RANGE_U128.max}]`
|
|
6661
|
+
);
|
|
6662
|
+
}
|
|
6663
|
+
static is(data) {
|
|
6664
|
+
try {
|
|
6665
|
+
_CairoUint128.validate(data);
|
|
6666
|
+
return true;
|
|
6667
|
+
} catch {
|
|
6668
|
+
return false;
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
/**
|
|
6672
|
+
* Check if provided abi type is this data type
|
|
6673
|
+
*/
|
|
6674
|
+
static isAbiType(abiType) {
|
|
6675
|
+
return abiType === _CairoUint128.abiSelector;
|
|
6676
|
+
}
|
|
6677
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6678
|
+
return new _CairoUint128(getNext(responseIterator));
|
|
6679
|
+
}
|
|
6680
|
+
};
|
|
6681
|
+
|
|
6682
|
+
// src/utils/cairoDataTypes/int8.ts
|
|
6683
|
+
var CairoInt8 = class _CairoInt8 {
|
|
6684
|
+
data;
|
|
6685
|
+
static abiSelector = "core::integer::i8";
|
|
6686
|
+
constructor(data) {
|
|
6687
|
+
_CairoInt8.validate(data);
|
|
6688
|
+
this.data = _CairoInt8.__processData(data);
|
|
6689
|
+
}
|
|
6690
|
+
static __processData(data) {
|
|
6691
|
+
if (isString(data) && isText(data)) {
|
|
6692
|
+
return utf8ToBigInt(data);
|
|
6693
|
+
}
|
|
6694
|
+
return BigInt(data);
|
|
6695
|
+
}
|
|
6696
|
+
toApiRequest() {
|
|
6697
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6698
|
+
}
|
|
6699
|
+
toBigInt() {
|
|
6700
|
+
return this.data;
|
|
6701
|
+
}
|
|
6702
|
+
decodeUtf8() {
|
|
6703
|
+
return new TextDecoder().decode(
|
|
6704
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 256n + this.data)
|
|
6705
|
+
);
|
|
6706
|
+
}
|
|
6707
|
+
/**
|
|
6708
|
+
* For negative values field element representation as positive hex string.
|
|
6709
|
+
* @returns cairo field arithmetic hex string
|
|
6710
|
+
*/
|
|
6711
|
+
toHexString() {
|
|
6712
|
+
const value = this.toBigInt();
|
|
6713
|
+
if (value < 0n) {
|
|
6714
|
+
const fieldElement = PRIME + value;
|
|
6715
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
6716
|
+
}
|
|
6717
|
+
return addHexPrefix(value.toString(16));
|
|
6718
|
+
}
|
|
6719
|
+
static validate(data) {
|
|
6720
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6721
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6722
|
+
assert(
|
|
6723
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6724
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6725
|
+
);
|
|
6726
|
+
const value = _CairoInt8.__processData(data);
|
|
6727
|
+
assert(
|
|
6728
|
+
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
6729
|
+
`Value is out of i8 range [${RANGE_I8.min}, ${RANGE_I8.max}]`
|
|
6730
|
+
);
|
|
6731
|
+
}
|
|
6732
|
+
static is(data) {
|
|
6733
|
+
try {
|
|
6734
|
+
_CairoInt8.validate(data);
|
|
6735
|
+
return true;
|
|
6736
|
+
} catch {
|
|
6737
|
+
return false;
|
|
6738
|
+
}
|
|
6739
|
+
}
|
|
6740
|
+
/**
|
|
6741
|
+
* Check if provided abi type is this data type
|
|
6742
|
+
*/
|
|
6743
|
+
static isAbiType(abiType) {
|
|
6744
|
+
return abiType === _CairoInt8.abiSelector;
|
|
6745
|
+
}
|
|
6746
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6747
|
+
const response = getNext(responseIterator);
|
|
6748
|
+
const value = BigInt(response);
|
|
6749
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
6750
|
+
return new _CairoInt8(signedValue);
|
|
6751
|
+
}
|
|
6752
|
+
};
|
|
6753
|
+
|
|
6754
|
+
// src/utils/cairoDataTypes/int16.ts
|
|
6755
|
+
var CairoInt16 = class _CairoInt16 {
|
|
6756
|
+
data;
|
|
6757
|
+
static abiSelector = "core::integer::i16";
|
|
6758
|
+
constructor(data) {
|
|
6759
|
+
_CairoInt16.validate(data);
|
|
6760
|
+
this.data = _CairoInt16.__processData(data);
|
|
6761
|
+
}
|
|
6762
|
+
static __processData(data) {
|
|
6763
|
+
if (isString(data) && isText(data)) {
|
|
6764
|
+
return utf8ToBigInt(data);
|
|
6765
|
+
}
|
|
6766
|
+
return BigInt(data);
|
|
6767
|
+
}
|
|
6768
|
+
toApiRequest() {
|
|
6769
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6770
|
+
}
|
|
6771
|
+
toBigInt() {
|
|
6772
|
+
return this.data;
|
|
6773
|
+
}
|
|
6774
|
+
decodeUtf8() {
|
|
6775
|
+
return new TextDecoder().decode(
|
|
6776
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 65536n + this.data)
|
|
6777
|
+
);
|
|
6778
|
+
}
|
|
6779
|
+
/**
|
|
6780
|
+
* For negative values field element representation as positive hex string.
|
|
6781
|
+
* @returns cairo field arithmetic hex string
|
|
6782
|
+
*/
|
|
6783
|
+
toHexString() {
|
|
6784
|
+
const value = this.toBigInt();
|
|
6785
|
+
if (value < 0n) {
|
|
6786
|
+
const fieldElement = PRIME + value;
|
|
6787
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
6788
|
+
}
|
|
6789
|
+
return addHexPrefix(value.toString(16));
|
|
6790
|
+
}
|
|
6791
|
+
static validate(data) {
|
|
6792
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6793
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6794
|
+
assert(
|
|
6795
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6796
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6797
|
+
);
|
|
6798
|
+
const value = _CairoInt16.__processData(data);
|
|
6799
|
+
assert(
|
|
6800
|
+
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
6801
|
+
`Value is out of i16 range [${RANGE_I16.min}, ${RANGE_I16.max}]`
|
|
6802
|
+
);
|
|
6803
|
+
}
|
|
6804
|
+
static is(data) {
|
|
6805
|
+
try {
|
|
6806
|
+
_CairoInt16.validate(data);
|
|
6807
|
+
return true;
|
|
6808
|
+
} catch {
|
|
6809
|
+
return false;
|
|
6810
|
+
}
|
|
6811
|
+
}
|
|
6812
|
+
/**
|
|
6813
|
+
* Check if provided abi type is this data type
|
|
6814
|
+
*/
|
|
6815
|
+
static isAbiType(abiType) {
|
|
6816
|
+
return abiType === _CairoInt16.abiSelector;
|
|
6817
|
+
}
|
|
6818
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6819
|
+
const response = getNext(responseIterator);
|
|
6820
|
+
const value = BigInt(response);
|
|
6821
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
6822
|
+
return new _CairoInt16(signedValue);
|
|
6823
|
+
}
|
|
6824
|
+
};
|
|
6825
|
+
|
|
6826
|
+
// src/utils/cairoDataTypes/int32.ts
|
|
6827
|
+
var CairoInt32 = class _CairoInt32 {
|
|
6828
|
+
data;
|
|
6829
|
+
static abiSelector = "core::integer::i32";
|
|
6830
|
+
constructor(data) {
|
|
6831
|
+
_CairoInt32.validate(data);
|
|
6832
|
+
this.data = _CairoInt32.__processData(data);
|
|
6833
|
+
}
|
|
6834
|
+
static __processData(data) {
|
|
6835
|
+
if (isString(data) && isText(data)) {
|
|
6836
|
+
return utf8ToBigInt(data);
|
|
6837
|
+
}
|
|
6838
|
+
return BigInt(data);
|
|
6839
|
+
}
|
|
6840
|
+
toApiRequest() {
|
|
6841
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6842
|
+
}
|
|
6843
|
+
toBigInt() {
|
|
6844
|
+
return this.data;
|
|
6845
|
+
}
|
|
6846
|
+
decodeUtf8() {
|
|
6847
|
+
return new TextDecoder().decode(
|
|
6848
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 4294967296n + this.data)
|
|
6849
|
+
);
|
|
6850
|
+
}
|
|
6851
|
+
/**
|
|
6852
|
+
* For negative values field element representation as positive hex string.
|
|
6853
|
+
* @returns cairo field arithmetic hex string
|
|
6854
|
+
*/
|
|
6855
|
+
toHexString() {
|
|
6856
|
+
const value = this.toBigInt();
|
|
6857
|
+
if (value < 0n) {
|
|
6858
|
+
const fieldElement = PRIME + value;
|
|
6859
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
6860
|
+
}
|
|
6861
|
+
return addHexPrefix(value.toString(16));
|
|
6862
|
+
}
|
|
6863
|
+
static validate(data) {
|
|
6864
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6865
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6866
|
+
assert(
|
|
6867
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6868
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6869
|
+
);
|
|
6870
|
+
const value = _CairoInt32.__processData(data);
|
|
6871
|
+
assert(
|
|
6872
|
+
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
6873
|
+
`Value is out of i32 range [${RANGE_I32.min}, ${RANGE_I32.max}]`
|
|
6874
|
+
);
|
|
6875
|
+
}
|
|
6876
|
+
static is(data) {
|
|
6877
|
+
try {
|
|
6878
|
+
_CairoInt32.validate(data);
|
|
6879
|
+
return true;
|
|
6880
|
+
} catch {
|
|
6881
|
+
return false;
|
|
6882
|
+
}
|
|
6883
|
+
}
|
|
6884
|
+
/**
|
|
6885
|
+
* Check if provided abi type is this data type
|
|
6886
|
+
*/
|
|
6887
|
+
static isAbiType(abiType) {
|
|
6888
|
+
return abiType === _CairoInt32.abiSelector;
|
|
6889
|
+
}
|
|
6890
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6891
|
+
const response = getNext(responseIterator);
|
|
6892
|
+
const value = BigInt(response);
|
|
6893
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
6894
|
+
return new _CairoInt32(signedValue);
|
|
6895
|
+
}
|
|
6896
|
+
};
|
|
6897
|
+
|
|
6898
|
+
// src/utils/cairoDataTypes/int64.ts
|
|
6899
|
+
var CairoInt64 = class _CairoInt64 {
|
|
6900
|
+
data;
|
|
6901
|
+
static abiSelector = "core::integer::i64";
|
|
6902
|
+
constructor(data) {
|
|
6903
|
+
_CairoInt64.validate(data);
|
|
6904
|
+
this.data = _CairoInt64.__processData(data);
|
|
6905
|
+
}
|
|
6906
|
+
static __processData(data) {
|
|
6907
|
+
if (isString(data) && isText(data)) {
|
|
6908
|
+
return utf8ToBigInt(data);
|
|
6909
|
+
}
|
|
6910
|
+
return BigInt(data);
|
|
6911
|
+
}
|
|
6912
|
+
toApiRequest() {
|
|
6913
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6914
|
+
}
|
|
6915
|
+
toBigInt() {
|
|
6916
|
+
return this.data;
|
|
6917
|
+
}
|
|
6918
|
+
decodeUtf8() {
|
|
6919
|
+
return new TextDecoder().decode(
|
|
6920
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 64n + this.data)
|
|
6921
|
+
);
|
|
6922
|
+
}
|
|
6923
|
+
/**
|
|
6924
|
+
* For negative values field element representation as positive hex string.
|
|
6925
|
+
* @returns cairo field arithmetic hex string
|
|
6926
|
+
*/
|
|
6927
|
+
toHexString() {
|
|
6928
|
+
const value = this.toBigInt();
|
|
6929
|
+
if (value < 0n) {
|
|
6930
|
+
const fieldElement = PRIME + value;
|
|
6931
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
6932
|
+
}
|
|
6933
|
+
return addHexPrefix(value.toString(16));
|
|
6934
|
+
}
|
|
6935
|
+
static validate(data) {
|
|
6936
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
6937
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
6938
|
+
assert(
|
|
6939
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
6940
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6941
|
+
);
|
|
6942
|
+
const value = _CairoInt64.__processData(data);
|
|
6943
|
+
assert(
|
|
6944
|
+
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
6945
|
+
`Value is out of i64 range [${RANGE_I64.min}, ${RANGE_I64.max}]`
|
|
6946
|
+
);
|
|
6947
|
+
}
|
|
6948
|
+
static is(data) {
|
|
6949
|
+
try {
|
|
6950
|
+
_CairoInt64.validate(data);
|
|
6951
|
+
return true;
|
|
6952
|
+
} catch {
|
|
6953
|
+
return false;
|
|
6954
|
+
}
|
|
6955
|
+
}
|
|
6956
|
+
/**
|
|
6957
|
+
* Check if provided abi type is this data type
|
|
6958
|
+
*/
|
|
6959
|
+
static isAbiType(abiType) {
|
|
6960
|
+
return abiType === _CairoInt64.abiSelector;
|
|
6961
|
+
}
|
|
6962
|
+
static factoryFromApiResponse(responseIterator) {
|
|
6963
|
+
const response = getNext(responseIterator);
|
|
6964
|
+
const value = BigInt(response);
|
|
6965
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
6966
|
+
return new _CairoInt64(signedValue);
|
|
6967
|
+
}
|
|
6968
|
+
};
|
|
6969
|
+
|
|
6970
|
+
// src/utils/cairoDataTypes/int128.ts
|
|
6971
|
+
var CairoInt128 = class _CairoInt128 {
|
|
6972
|
+
data;
|
|
6973
|
+
static abiSelector = "core::integer::i128";
|
|
6974
|
+
constructor(data) {
|
|
6975
|
+
_CairoInt128.validate(data);
|
|
6976
|
+
this.data = _CairoInt128.__processData(data);
|
|
6977
|
+
}
|
|
6978
|
+
static __processData(data) {
|
|
6979
|
+
if (isString(data) && isText(data)) {
|
|
6980
|
+
return utf8ToBigInt(data);
|
|
6981
|
+
}
|
|
6982
|
+
return BigInt(data);
|
|
6983
|
+
}
|
|
6984
|
+
toApiRequest() {
|
|
6985
|
+
return addCompiledFlag([this.toHexString()]);
|
|
6986
|
+
}
|
|
6987
|
+
toBigInt() {
|
|
6988
|
+
return this.data;
|
|
6989
|
+
}
|
|
6990
|
+
decodeUtf8() {
|
|
6991
|
+
return new TextDecoder().decode(
|
|
6992
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 128n + this.data)
|
|
6993
|
+
);
|
|
6994
|
+
}
|
|
6995
|
+
/**
|
|
6996
|
+
* For negative values field element representation as positive hex string.
|
|
6997
|
+
* @returns cairo field arithmetic hex string
|
|
6998
|
+
*/
|
|
6999
|
+
toHexString() {
|
|
7000
|
+
const value = this.toBigInt();
|
|
7001
|
+
if (value < 0n) {
|
|
7002
|
+
const fieldElement = PRIME + value;
|
|
7003
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
7004
|
+
}
|
|
7005
|
+
return addHexPrefix(value.toString(16));
|
|
7006
|
+
}
|
|
7007
|
+
static validate(data) {
|
|
7008
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
7009
|
+
assert(!isObject2(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
7010
|
+
assert(
|
|
7011
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
7012
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7013
|
+
);
|
|
7014
|
+
const value = _CairoInt128.__processData(data);
|
|
7015
|
+
assert(
|
|
7016
|
+
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
7017
|
+
`Value is out of i128 range [${RANGE_I128.min}, ${RANGE_I128.max}]`
|
|
7018
|
+
);
|
|
7019
|
+
}
|
|
7020
|
+
static is(data) {
|
|
7021
|
+
try {
|
|
7022
|
+
_CairoInt128.validate(data);
|
|
7023
|
+
return true;
|
|
7024
|
+
} catch {
|
|
7025
|
+
return false;
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Check if provided abi type is this data type
|
|
7030
|
+
*/
|
|
7031
|
+
static isAbiType(abiType) {
|
|
7032
|
+
return abiType === _CairoInt128.abiSelector;
|
|
7033
|
+
}
|
|
7034
|
+
static factoryFromApiResponse(responseIterator) {
|
|
7035
|
+
const response = getNext(responseIterator);
|
|
7036
|
+
const value = BigInt(response);
|
|
7037
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
7038
|
+
return new _CairoInt128(signedValue);
|
|
7039
|
+
}
|
|
7040
|
+
};
|
|
7041
|
+
|
|
7042
|
+
// src/utils/calldata/parser/parsingStrategy.ts
|
|
7043
|
+
var hdParsingStrategy = {
|
|
7044
|
+
// TODO: provjeri svi request parseri stvaraju array, dali je to ok sa requstParserom
|
|
7045
|
+
request: {
|
|
7046
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
7047
|
+
return new CairoBytes31(val).toApiRequest();
|
|
7048
|
+
},
|
|
7049
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
7050
|
+
return new CairoByteArray(val).toApiRequest();
|
|
7051
|
+
},
|
|
7052
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
7053
|
+
return new CairoFelt252(val).toApiRequest();
|
|
7054
|
+
},
|
|
7055
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
7056
|
+
return new CairoUint256(val).toApiRequest();
|
|
7057
|
+
},
|
|
7058
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
7059
|
+
return new CairoUint512(val).toApiRequest();
|
|
7060
|
+
},
|
|
7061
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
7062
|
+
return new CairoUint8(val).toApiRequest();
|
|
7063
|
+
},
|
|
7064
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
7065
|
+
return new CairoUint16(val).toApiRequest();
|
|
7066
|
+
},
|
|
7067
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
7068
|
+
return new CairoUint64(val).toApiRequest();
|
|
7069
|
+
},
|
|
7070
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
7071
|
+
return new CairoUint96(val).toApiRequest();
|
|
7072
|
+
},
|
|
7073
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
7074
|
+
return new CairoUint128(val).toApiRequest();
|
|
7075
|
+
},
|
|
7076
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
7077
|
+
return new CairoInt8(val).toApiRequest();
|
|
7078
|
+
},
|
|
7079
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
7080
|
+
return new CairoInt16(val).toApiRequest();
|
|
7081
|
+
},
|
|
7082
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
7083
|
+
return new CairoInt32(val).toApiRequest();
|
|
7084
|
+
},
|
|
7085
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
7086
|
+
return new CairoInt64(val).toApiRequest();
|
|
7087
|
+
},
|
|
7088
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
7089
|
+
return new CairoInt128(val).toApiRequest();
|
|
7090
|
+
}
|
|
7091
|
+
},
|
|
7092
|
+
response: {
|
|
7093
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
7094
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
7095
|
+
},
|
|
7096
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
7097
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
7098
|
+
},
|
|
7099
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
7100
|
+
return CairoFelt252.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7101
|
+
},
|
|
7102
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
7103
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7104
|
+
},
|
|
7105
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
7106
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7107
|
+
},
|
|
7108
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
7109
|
+
return CairoUint8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7110
|
+
},
|
|
7111
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
7112
|
+
return CairoUint16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7113
|
+
},
|
|
7114
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
7115
|
+
return CairoUint64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7116
|
+
},
|
|
7117
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
7118
|
+
return CairoUint96.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7119
|
+
},
|
|
7120
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
7121
|
+
return CairoUint128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7122
|
+
},
|
|
7123
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
7124
|
+
return CairoInt8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7125
|
+
},
|
|
7126
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
7127
|
+
return CairoInt16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7128
|
+
},
|
|
7129
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
7130
|
+
return CairoInt32.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7131
|
+
},
|
|
7132
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
7133
|
+
return CairoInt64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7134
|
+
},
|
|
7135
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
7136
|
+
return CairoInt128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7137
|
+
}
|
|
7138
|
+
}
|
|
7139
|
+
};
|
|
7140
|
+
var fastParsingStrategy = {
|
|
7141
|
+
request: {
|
|
7142
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
7143
|
+
return new CairoBytes31(val).toApiRequest();
|
|
7144
|
+
},
|
|
7145
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
7146
|
+
return new CairoByteArray(val).toApiRequest();
|
|
7147
|
+
},
|
|
7148
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
7149
|
+
return felt(val);
|
|
7150
|
+
},
|
|
7151
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
7152
|
+
return new CairoUint256(val).toApiRequest();
|
|
7153
|
+
},
|
|
7154
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
7155
|
+
return new CairoUint512(val).toApiRequest();
|
|
7156
|
+
},
|
|
7157
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
7158
|
+
return felt(val);
|
|
7159
|
+
},
|
|
7160
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
7161
|
+
return felt(val);
|
|
7162
|
+
},
|
|
7163
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
7164
|
+
return felt(val);
|
|
7165
|
+
},
|
|
7166
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
7167
|
+
return felt(val);
|
|
7168
|
+
},
|
|
7169
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
7170
|
+
return felt(val);
|
|
7171
|
+
},
|
|
7172
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
7173
|
+
return new CairoInt8(val).toApiRequest();
|
|
7174
|
+
},
|
|
7175
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
7176
|
+
return new CairoInt16(val).toApiRequest();
|
|
7177
|
+
},
|
|
7178
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
7179
|
+
return new CairoInt32(val).toApiRequest();
|
|
7180
|
+
},
|
|
7181
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
7182
|
+
return new CairoInt64(val).toApiRequest();
|
|
7183
|
+
},
|
|
7184
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
7185
|
+
return new CairoInt128(val).toApiRequest();
|
|
7186
|
+
}
|
|
7187
|
+
},
|
|
7188
|
+
response: {
|
|
7189
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
7190
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
7191
|
+
},
|
|
7192
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
7193
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
7194
|
+
},
|
|
7195
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
7196
|
+
return BigInt(getNext(responseIterator));
|
|
7197
|
+
},
|
|
7198
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
7199
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7200
|
+
},
|
|
7201
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
7202
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
7203
|
+
},
|
|
7204
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
7205
|
+
return BigInt(getNext(responseIterator));
|
|
7206
|
+
},
|
|
7207
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
7208
|
+
return BigInt(getNext(responseIterator));
|
|
7209
|
+
},
|
|
7210
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
7211
|
+
return BigInt(getNext(responseIterator));
|
|
7212
|
+
},
|
|
7213
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
7214
|
+
return BigInt(getNext(responseIterator));
|
|
7215
|
+
},
|
|
7216
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
7217
|
+
return BigInt(getNext(responseIterator));
|
|
7218
|
+
},
|
|
7219
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
7220
|
+
return BigInt(getNext(responseIterator));
|
|
7221
|
+
},
|
|
7222
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
7223
|
+
return BigInt(getNext(responseIterator));
|
|
7224
|
+
},
|
|
7225
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
7226
|
+
return BigInt(getNext(responseIterator));
|
|
7227
|
+
},
|
|
7228
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
7229
|
+
return BigInt(getNext(responseIterator));
|
|
7230
|
+
},
|
|
7231
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
7232
|
+
return BigInt(getNext(responseIterator));
|
|
7233
|
+
}
|
|
7234
|
+
}
|
|
7235
|
+
};
|
|
5680
7236
|
|
|
5681
7237
|
// src/utils/calldata/parser/parser-0-1.1.0.ts
|
|
5682
7238
|
var AbiParser1 = class {
|
|
5683
7239
|
abi;
|
|
5684
|
-
|
|
7240
|
+
parsingStrategy;
|
|
7241
|
+
constructor(abi, parsingStrategy) {
|
|
5685
7242
|
this.abi = abi;
|
|
7243
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
7244
|
+
}
|
|
7245
|
+
getRequestParser(abiType) {
|
|
7246
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
7247
|
+
return this.parsingStrategy.request[abiType];
|
|
7248
|
+
}
|
|
7249
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
7250
|
+
}
|
|
7251
|
+
getResponseParser(abiType) {
|
|
7252
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
7253
|
+
return this.parsingStrategy.response[abiType];
|
|
7254
|
+
}
|
|
7255
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
5686
7256
|
}
|
|
5687
7257
|
/**
|
|
5688
7258
|
* abi method inputs length without '_len' inputs
|
|
@@ -5713,8 +7283,22 @@ ${indent}}` : "}";
|
|
|
5713
7283
|
// src/utils/calldata/parser/parser-2.0.0.ts
|
|
5714
7284
|
var AbiParser2 = class {
|
|
5715
7285
|
abi;
|
|
5716
|
-
|
|
7286
|
+
parsingStrategy;
|
|
7287
|
+
constructor(abi, parsingStrategy) {
|
|
5717
7288
|
this.abi = abi;
|
|
7289
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
7290
|
+
}
|
|
7291
|
+
getRequestParser(abiType) {
|
|
7292
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
7293
|
+
return this.parsingStrategy.request[abiType];
|
|
7294
|
+
}
|
|
7295
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
7296
|
+
}
|
|
7297
|
+
getResponseParser(abiType) {
|
|
7298
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
7299
|
+
return this.parsingStrategy.response[abiType];
|
|
7300
|
+
}
|
|
7301
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
5718
7302
|
}
|
|
5719
7303
|
/**
|
|
5720
7304
|
* abi method inputs length
|
|
@@ -5747,13 +7331,13 @@ ${indent}}` : "}";
|
|
|
5747
7331
|
};
|
|
5748
7332
|
|
|
5749
7333
|
// src/utils/calldata/parser/index.ts
|
|
5750
|
-
function createAbiParser(abi) {
|
|
7334
|
+
function createAbiParser(abi, parsingStrategy) {
|
|
5751
7335
|
const version = getAbiVersion(abi);
|
|
5752
7336
|
if (version === 0 || version === 1) {
|
|
5753
|
-
return new AbiParser1(abi);
|
|
7337
|
+
return new AbiParser1(abi, parsingStrategy);
|
|
5754
7338
|
}
|
|
5755
7339
|
if (version === 2) {
|
|
5756
|
-
return new AbiParser2(abi);
|
|
7340
|
+
return new AbiParser2(abi, parsingStrategy);
|
|
5757
7341
|
}
|
|
5758
7342
|
throw Error(`Unsupported ABI version ${version}`);
|
|
5759
7343
|
}
|
|
@@ -5880,16 +7464,17 @@ ${indent}}` : "}";
|
|
|
5880
7464
|
`The type ${arrayType} do not includes any content type. Needs [type; length].`
|
|
5881
7465
|
);
|
|
5882
7466
|
}
|
|
7467
|
+
let arraySize;
|
|
5883
7468
|
try {
|
|
5884
|
-
_CairoFixedArray.getFixedArraySize(arrayType);
|
|
7469
|
+
arraySize = _CairoFixedArray.getFixedArraySize(arrayType);
|
|
5885
7470
|
} catch {
|
|
5886
7471
|
throw new Error(
|
|
5887
7472
|
`The type ${arrayType} type do not includes any length. Needs [type; length].`
|
|
5888
7473
|
);
|
|
5889
7474
|
}
|
|
5890
7475
|
assert(
|
|
5891
|
-
|
|
5892
|
-
`The ABI type ${arrayType} is expecting ${
|
|
7476
|
+
arraySize === content.length,
|
|
7477
|
+
`The ABI type ${arrayType} is expecting ${arraySize} items. ${content.length} items provided.`
|
|
5893
7478
|
);
|
|
5894
7479
|
this.content = content;
|
|
5895
7480
|
this.arrayType = arrayType;
|
|
@@ -5986,6 +7571,7 @@ ${indent}}` : "}";
|
|
|
5986
7571
|
}
|
|
5987
7572
|
/**
|
|
5988
7573
|
* Checks if the given Cairo type is a fixed-array type.
|
|
7574
|
+
* structure: [string; number]
|
|
5989
7575
|
*
|
|
5990
7576
|
* @param {string} type - The type to check.
|
|
5991
7577
|
* @returns - `true` if the type is a fixed array type, `false` otherwise.
|
|
@@ -6030,7 +7616,7 @@ ${indent}}` : "}";
|
|
|
6030
7616
|
if (isTypeNonZero(abiType)) {
|
|
6031
7617
|
return unorderedItem;
|
|
6032
7618
|
}
|
|
6033
|
-
if (
|
|
7619
|
+
if (CairoByteArray.isAbiType(abiType)) {
|
|
6034
7620
|
return unorderedItem;
|
|
6035
7621
|
}
|
|
6036
7622
|
if (isTypeU96(abiType)) {
|
|
@@ -6188,14 +7774,38 @@ ${indent}}` : "}";
|
|
|
6188
7774
|
}
|
|
6189
7775
|
|
|
6190
7776
|
// src/utils/calldata/requestParser.ts
|
|
6191
|
-
function parseBaseTypes(
|
|
7777
|
+
function parseBaseTypes({
|
|
7778
|
+
type,
|
|
7779
|
+
val,
|
|
7780
|
+
parser
|
|
7781
|
+
}) {
|
|
6192
7782
|
switch (true) {
|
|
6193
7783
|
case CairoUint256.isAbiType(type):
|
|
6194
|
-
return
|
|
7784
|
+
return parser.getRequestParser(type)(val);
|
|
6195
7785
|
case CairoUint512.isAbiType(type):
|
|
6196
|
-
return
|
|
6197
|
-
case
|
|
6198
|
-
return
|
|
7786
|
+
return parser.getRequestParser(type)(val);
|
|
7787
|
+
case CairoUint8.isAbiType(type):
|
|
7788
|
+
return parser.getRequestParser(type)(val);
|
|
7789
|
+
case CairoUint16.isAbiType(type):
|
|
7790
|
+
return parser.getRequestParser(type)(val);
|
|
7791
|
+
case CairoUint64.isAbiType(type):
|
|
7792
|
+
return parser.getRequestParser(type)(val);
|
|
7793
|
+
case CairoUint96.isAbiType(type):
|
|
7794
|
+
return parser.getRequestParser(type)(val);
|
|
7795
|
+
case CairoUint128.isAbiType(type):
|
|
7796
|
+
return parser.getRequestParser(type)(val);
|
|
7797
|
+
case CairoInt8.isAbiType(type):
|
|
7798
|
+
return parser.getRequestParser(type)(val);
|
|
7799
|
+
case CairoInt16.isAbiType(type):
|
|
7800
|
+
return parser.getRequestParser(type)(val);
|
|
7801
|
+
case CairoInt32.isAbiType(type):
|
|
7802
|
+
return parser.getRequestParser(type)(val);
|
|
7803
|
+
case CairoInt64.isAbiType(type):
|
|
7804
|
+
return parser.getRequestParser(type)(val);
|
|
7805
|
+
case CairoInt128.isAbiType(type):
|
|
7806
|
+
return parser.getRequestParser(type)(val);
|
|
7807
|
+
case CairoBytes31.isAbiType(type):
|
|
7808
|
+
return parser.getRequestParser(type)(val);
|
|
6199
7809
|
case isTypeSecp256k1Point(type): {
|
|
6200
7810
|
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
6201
7811
|
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
@@ -6208,7 +7818,7 @@ ${indent}}` : "}";
|
|
|
6208
7818
|
];
|
|
6209
7819
|
}
|
|
6210
7820
|
default:
|
|
6211
|
-
return
|
|
7821
|
+
return parser.getRequestParser(CairoFelt252.abiSelector)(val);
|
|
6212
7822
|
}
|
|
6213
7823
|
}
|
|
6214
7824
|
function parseTuple(element, typeStr) {
|
|
@@ -6228,16 +7838,13 @@ ${indent}}` : "}";
|
|
|
6228
7838
|
};
|
|
6229
7839
|
});
|
|
6230
7840
|
}
|
|
6231
|
-
function
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
];
|
|
6239
|
-
}
|
|
6240
|
-
function parseCalldataValue(element, type, structs, enums) {
|
|
7841
|
+
function parseCalldataValue({
|
|
7842
|
+
element,
|
|
7843
|
+
type,
|
|
7844
|
+
structs,
|
|
7845
|
+
enums,
|
|
7846
|
+
parser
|
|
7847
|
+
}) {
|
|
6241
7848
|
if (element === void 0) {
|
|
6242
7849
|
throw Error(`Missing parameter for type ${type}`);
|
|
6243
7850
|
}
|
|
@@ -6257,7 +7864,9 @@ ${indent}}` : "}";
|
|
|
6257
7864
|
throw new Error(`ABI type ${type}: not an Array representing a cairo.fixedArray() provided.`);
|
|
6258
7865
|
}
|
|
6259
7866
|
return values.reduce((acc, it) => {
|
|
6260
|
-
return acc.concat(
|
|
7867
|
+
return acc.concat(
|
|
7868
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
7869
|
+
);
|
|
6261
7870
|
}, []);
|
|
6262
7871
|
}
|
|
6263
7872
|
if (Array.isArray(element)) {
|
|
@@ -6265,37 +7874,51 @@ ${indent}}` : "}";
|
|
|
6265
7874
|
result.push(felt(element.length));
|
|
6266
7875
|
const arrayType = getArrayType(type);
|
|
6267
7876
|
return element.reduce((acc, it) => {
|
|
6268
|
-
return acc.concat(
|
|
7877
|
+
return acc.concat(
|
|
7878
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
7879
|
+
);
|
|
6269
7880
|
}, result);
|
|
6270
7881
|
}
|
|
7882
|
+
if (CairoUint256.isAbiType(type)) {
|
|
7883
|
+
return parser.getRequestParser(type)(element);
|
|
7884
|
+
}
|
|
7885
|
+
if (CairoUint512.isAbiType(type)) {
|
|
7886
|
+
return parser.getRequestParser(type)(element);
|
|
7887
|
+
}
|
|
6271
7888
|
if (structs[type] && structs[type].members.length) {
|
|
6272
|
-
if (
|
|
6273
|
-
return
|
|
7889
|
+
if (isTypeEthAddress(type)) {
|
|
7890
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
6274
7891
|
}
|
|
6275
|
-
if (
|
|
6276
|
-
return
|
|
7892
|
+
if (CairoByteArray.isAbiType(type)) {
|
|
7893
|
+
return parser.getRequestParser(type)(element);
|
|
6277
7894
|
}
|
|
6278
|
-
if (isTypeEthAddress(type)) return parseBaseTypes(type, element);
|
|
6279
|
-
if (isTypeByteArray(type)) return parseByteArray(element);
|
|
6280
7895
|
const { members } = structs[type];
|
|
6281
7896
|
const subElement = element;
|
|
6282
7897
|
return members.reduce((acc, it) => {
|
|
6283
|
-
return acc.concat(
|
|
7898
|
+
return acc.concat(
|
|
7899
|
+
parseCalldataValue({
|
|
7900
|
+
element: subElement[it.name],
|
|
7901
|
+
type: it.type,
|
|
7902
|
+
structs,
|
|
7903
|
+
enums,
|
|
7904
|
+
parser
|
|
7905
|
+
})
|
|
7906
|
+
);
|
|
6284
7907
|
}, []);
|
|
6285
7908
|
}
|
|
6286
7909
|
if (isTypeTuple(type)) {
|
|
6287
7910
|
const tupled = parseTuple(element, type);
|
|
6288
7911
|
return tupled.reduce((acc, it) => {
|
|
6289
|
-
const parsedData = parseCalldataValue(
|
|
7912
|
+
const parsedData = parseCalldataValue({
|
|
7913
|
+
element: it.element,
|
|
7914
|
+
type: it.type,
|
|
7915
|
+
structs,
|
|
7916
|
+
enums,
|
|
7917
|
+
parser
|
|
7918
|
+
});
|
|
6290
7919
|
return acc.concat(parsedData);
|
|
6291
7920
|
}, []);
|
|
6292
7921
|
}
|
|
6293
|
-
if (CairoUint256.isAbiType(type)) {
|
|
6294
|
-
return new CairoUint256(element).toApiRequest();
|
|
6295
|
-
}
|
|
6296
|
-
if (CairoUint512.isAbiType(type)) {
|
|
6297
|
-
return new CairoUint512(element).toApiRequest();
|
|
6298
|
-
}
|
|
6299
7922
|
if (isTypeEnum(type, enums)) {
|
|
6300
7923
|
const { variants } = enums[type];
|
|
6301
7924
|
if (isTypeOption(type)) {
|
|
@@ -6309,12 +7932,13 @@ ${indent}}` : "}";
|
|
|
6309
7932
|
if (typeVariantSome === "()") {
|
|
6310
7933
|
return CairoOptionVariant.Some.toString();
|
|
6311
7934
|
}
|
|
6312
|
-
const parsedParameter2 = parseCalldataValue(
|
|
6313
|
-
myOption.unwrap(),
|
|
6314
|
-
typeVariantSome,
|
|
7935
|
+
const parsedParameter2 = parseCalldataValue({
|
|
7936
|
+
element: myOption.unwrap(),
|
|
7937
|
+
type: typeVariantSome,
|
|
6315
7938
|
structs,
|
|
6316
|
-
enums
|
|
6317
|
-
|
|
7939
|
+
enums,
|
|
7940
|
+
parser
|
|
7941
|
+
});
|
|
6318
7942
|
if (Array.isArray(parsedParameter2)) {
|
|
6319
7943
|
return [CairoOptionVariant.Some.toString(), ...parsedParameter2];
|
|
6320
7944
|
}
|
|
@@ -6333,12 +7957,13 @@ ${indent}}` : "}";
|
|
|
6333
7957
|
if (typeVariantOk === "()") {
|
|
6334
7958
|
return CairoResultVariant.Ok.toString();
|
|
6335
7959
|
}
|
|
6336
|
-
const parsedParameter3 = parseCalldataValue(
|
|
6337
|
-
myResult.unwrap(),
|
|
6338
|
-
typeVariantOk,
|
|
7960
|
+
const parsedParameter3 = parseCalldataValue({
|
|
7961
|
+
element: myResult.unwrap(),
|
|
7962
|
+
type: typeVariantOk,
|
|
6339
7963
|
structs,
|
|
6340
|
-
enums
|
|
6341
|
-
|
|
7964
|
+
enums,
|
|
7965
|
+
parser
|
|
7966
|
+
});
|
|
6342
7967
|
if (Array.isArray(parsedParameter3)) {
|
|
6343
7968
|
return [CairoResultVariant.Ok.toString(), ...parsedParameter3];
|
|
6344
7969
|
}
|
|
@@ -6352,7 +7977,13 @@ ${indent}}` : "}";
|
|
|
6352
7977
|
if (typeVariantErr === "()") {
|
|
6353
7978
|
return CairoResultVariant.Err.toString();
|
|
6354
7979
|
}
|
|
6355
|
-
const parsedParameter2 = parseCalldataValue(
|
|
7980
|
+
const parsedParameter2 = parseCalldataValue({
|
|
7981
|
+
element: myResult.unwrap(),
|
|
7982
|
+
type: typeVariantErr,
|
|
7983
|
+
structs,
|
|
7984
|
+
enums,
|
|
7985
|
+
parser
|
|
7986
|
+
});
|
|
6356
7987
|
if (Array.isArray(parsedParameter2)) {
|
|
6357
7988
|
return [CairoResultVariant.Err.toString(), ...parsedParameter2];
|
|
6358
7989
|
}
|
|
@@ -6369,21 +8000,33 @@ ${indent}}` : "}";
|
|
|
6369
8000
|
if (typeActiveVariant === "()") {
|
|
6370
8001
|
return numActiveVariant.toString();
|
|
6371
8002
|
}
|
|
6372
|
-
const parsedParameter = parseCalldataValue(
|
|
8003
|
+
const parsedParameter = parseCalldataValue({
|
|
8004
|
+
element: myEnum.unwrap(),
|
|
8005
|
+
type: typeActiveVariant,
|
|
8006
|
+
structs,
|
|
8007
|
+
enums,
|
|
8008
|
+
parser
|
|
8009
|
+
});
|
|
6373
8010
|
if (Array.isArray(parsedParameter)) {
|
|
6374
8011
|
return [numActiveVariant.toString(), ...parsedParameter];
|
|
6375
8012
|
}
|
|
6376
8013
|
return [numActiveVariant.toString(), parsedParameter];
|
|
6377
8014
|
}
|
|
6378
8015
|
if (isTypeNonZero(type)) {
|
|
6379
|
-
return parseBaseTypes(getArrayType(type), element);
|
|
8016
|
+
return parseBaseTypes({ type: getArrayType(type), val: element, parser });
|
|
6380
8017
|
}
|
|
6381
8018
|
if (typeof element === "object") {
|
|
6382
8019
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
6383
8020
|
}
|
|
6384
|
-
return parseBaseTypes(type, element);
|
|
8021
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
6385
8022
|
}
|
|
6386
|
-
function parseCalldataField(
|
|
8023
|
+
function parseCalldataField({
|
|
8024
|
+
argsIterator,
|
|
8025
|
+
input,
|
|
8026
|
+
structs,
|
|
8027
|
+
enums,
|
|
8028
|
+
parser
|
|
8029
|
+
}) {
|
|
6387
8030
|
const { name, type } = input;
|
|
6388
8031
|
let { value } = argsIterator.next();
|
|
6389
8032
|
switch (true) {
|
|
@@ -6392,7 +8035,7 @@ ${indent}}` : "}";
|
|
|
6392
8035
|
if (!Array.isArray(value) && !(typeof value === "object")) {
|
|
6393
8036
|
throw Error(`ABI expected parameter ${name} to be an array or an object, got ${value}`);
|
|
6394
8037
|
}
|
|
6395
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
8038
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
6396
8039
|
// Normal Array
|
|
6397
8040
|
case isTypeArray(type):
|
|
6398
8041
|
if (!Array.isArray(value) && !isText(value)) {
|
|
@@ -6401,51 +8044,71 @@ ${indent}}` : "}";
|
|
|
6401
8044
|
if (isString(value)) {
|
|
6402
8045
|
value = splitLongString(value);
|
|
6403
8046
|
}
|
|
6404
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
8047
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
6405
8048
|
case isTypeNonZero(type):
|
|
6406
|
-
return parseBaseTypes(getArrayType(type), value);
|
|
8049
|
+
return parseBaseTypes({ type: getArrayType(type), val: value, parser });
|
|
6407
8050
|
case isTypeEthAddress(type):
|
|
6408
|
-
return parseBaseTypes(type, value);
|
|
8051
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
6409
8052
|
// Struct or Tuple
|
|
6410
8053
|
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
6411
|
-
return parseCalldataValue(
|
|
8054
|
+
return parseCalldataValue({
|
|
8055
|
+
element: value,
|
|
8056
|
+
type,
|
|
8057
|
+
structs,
|
|
8058
|
+
enums,
|
|
8059
|
+
parser
|
|
8060
|
+
});
|
|
6412
8061
|
// Enums
|
|
6413
8062
|
case isTypeEnum(type, enums):
|
|
6414
|
-
return parseCalldataValue(
|
|
6415
|
-
value,
|
|
8063
|
+
return parseCalldataValue({
|
|
8064
|
+
element: value,
|
|
6416
8065
|
type,
|
|
6417
8066
|
structs,
|
|
6418
|
-
enums
|
|
6419
|
-
|
|
8067
|
+
enums,
|
|
8068
|
+
parser
|
|
8069
|
+
});
|
|
6420
8070
|
// Felt or unhandled
|
|
6421
8071
|
default:
|
|
6422
|
-
return parseBaseTypes(type, value);
|
|
8072
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
6423
8073
|
}
|
|
6424
8074
|
}
|
|
6425
8075
|
|
|
6426
8076
|
// src/utils/calldata/responseParser.ts
|
|
6427
|
-
function parseBaseTypes2(type, it) {
|
|
8077
|
+
function parseBaseTypes2(type, it, parser) {
|
|
6428
8078
|
let temp;
|
|
6429
8079
|
switch (true) {
|
|
6430
8080
|
case isTypeBool(type):
|
|
6431
8081
|
temp = it.next().value;
|
|
6432
8082
|
return Boolean(BigInt(temp));
|
|
6433
8083
|
case CairoUint256.isAbiType(type):
|
|
6434
|
-
|
|
6435
|
-
const high = it.next().value;
|
|
6436
|
-
return new CairoUint256(low, high).toBigInt();
|
|
8084
|
+
return parser.getResponseParser(type)(it);
|
|
6437
8085
|
case CairoUint512.isAbiType(type):
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
return
|
|
8086
|
+
return parser.getResponseParser(type)(it);
|
|
8087
|
+
case CairoUint8.isAbiType(type):
|
|
8088
|
+
return parser.getResponseParser(type)(it);
|
|
8089
|
+
case CairoUint16.isAbiType(type):
|
|
8090
|
+
return parser.getResponseParser(type)(it);
|
|
8091
|
+
case CairoUint64.isAbiType(type):
|
|
8092
|
+
return parser.getResponseParser(type)(it);
|
|
8093
|
+
case CairoUint96.isAbiType(type):
|
|
8094
|
+
return parser.getResponseParser(type)(it);
|
|
8095
|
+
case CairoUint128.isAbiType(type):
|
|
8096
|
+
return parser.getResponseParser(type)(it);
|
|
8097
|
+
case CairoInt8.isAbiType(type):
|
|
8098
|
+
return parser.getResponseParser(type)(it);
|
|
8099
|
+
case CairoInt16.isAbiType(type):
|
|
8100
|
+
return parser.getResponseParser(type)(it);
|
|
8101
|
+
case CairoInt32.isAbiType(type):
|
|
8102
|
+
return parser.getResponseParser(type)(it);
|
|
8103
|
+
case CairoInt64.isAbiType(type):
|
|
8104
|
+
return parser.getResponseParser(type)(it);
|
|
8105
|
+
case CairoInt128.isAbiType(type):
|
|
8106
|
+
return parser.getResponseParser(type)(it);
|
|
6443
8107
|
case isTypeEthAddress(type):
|
|
6444
8108
|
temp = it.next().value;
|
|
6445
8109
|
return BigInt(temp);
|
|
6446
|
-
case
|
|
6447
|
-
|
|
6448
|
-
return decodeShortString(temp);
|
|
8110
|
+
case CairoBytes31.isAbiType(type):
|
|
8111
|
+
return parser.getResponseParser(type)(it);
|
|
6449
8112
|
case isTypeSecp256k1Point(type):
|
|
6450
8113
|
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
6451
8114
|
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
@@ -6454,47 +8117,28 @@ ${indent}}` : "}";
|
|
|
6454
8117
|
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
6455
8118
|
return pubK;
|
|
6456
8119
|
default:
|
|
6457
|
-
|
|
6458
|
-
return BigInt(temp);
|
|
8120
|
+
return parser.getResponseParser(CairoFelt252.abiSelector)(it);
|
|
6459
8121
|
}
|
|
6460
8122
|
}
|
|
6461
|
-
function parseResponseValue(responseIterator, element, structs, enums) {
|
|
8123
|
+
function parseResponseValue(responseIterator, element, parser, structs, enums) {
|
|
6462
8124
|
if (element.type === "()") {
|
|
6463
8125
|
return {};
|
|
6464
8126
|
}
|
|
6465
8127
|
if (CairoUint256.isAbiType(element.type)) {
|
|
6466
|
-
|
|
6467
|
-
const high = responseIterator.next().value;
|
|
6468
|
-
return new CairoUint256(low, high).toBigInt();
|
|
8128
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
6469
8129
|
}
|
|
6470
8130
|
if (CairoUint512.isAbiType(element.type)) {
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
6476
|
-
}
|
|
6477
|
-
if (isTypeByteArray(element.type)) {
|
|
6478
|
-
const parsedBytes31Arr = [];
|
|
6479
|
-
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
6480
|
-
while (parsedBytes31Arr.length < bytes31ArrLen) {
|
|
6481
|
-
parsedBytes31Arr.push(toHex(responseIterator.next().value));
|
|
6482
|
-
}
|
|
6483
|
-
const pending_word = toHex(responseIterator.next().value);
|
|
6484
|
-
const pending_word_len = BigInt(responseIterator.next().value);
|
|
6485
|
-
const myByteArray = {
|
|
6486
|
-
data: parsedBytes31Arr,
|
|
6487
|
-
pending_word,
|
|
6488
|
-
pending_word_len
|
|
6489
|
-
};
|
|
6490
|
-
return stringFromByteArray(myByteArray);
|
|
8131
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
8132
|
+
}
|
|
8133
|
+
if (CairoByteArray.isAbiType(element.type)) {
|
|
8134
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
6491
8135
|
}
|
|
6492
8136
|
if (CairoFixedArray.isTypeFixedArray(element.type)) {
|
|
6493
8137
|
const parsedDataArr = [];
|
|
6494
8138
|
const el = { name: "", type: CairoFixedArray.getFixedArrayType(element.type) };
|
|
6495
8139
|
const arraySize = CairoFixedArray.getFixedArraySize(element.type);
|
|
6496
8140
|
while (parsedDataArr.length < arraySize) {
|
|
6497
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
8141
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
6498
8142
|
}
|
|
6499
8143
|
return parsedDataArr;
|
|
6500
8144
|
}
|
|
@@ -6503,20 +8147,20 @@ ${indent}}` : "}";
|
|
|
6503
8147
|
const el = { name: "", type: getArrayType(element.type) };
|
|
6504
8148
|
const len = BigInt(responseIterator.next().value);
|
|
6505
8149
|
while (parsedDataArr.length < len) {
|
|
6506
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
8150
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
6507
8151
|
}
|
|
6508
8152
|
return parsedDataArr;
|
|
6509
8153
|
}
|
|
6510
8154
|
if (isTypeNonZero(element.type)) {
|
|
6511
8155
|
const el = { name: "", type: getArrayType(element.type) };
|
|
6512
|
-
return parseResponseValue(responseIterator, el, structs, enums);
|
|
8156
|
+
return parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
6513
8157
|
}
|
|
6514
8158
|
if (structs && element.type in structs && structs[element.type]) {
|
|
6515
8159
|
if (isTypeEthAddress(element.type)) {
|
|
6516
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
8160
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
6517
8161
|
}
|
|
6518
8162
|
return structs[element.type].members.reduce((acc, el) => {
|
|
6519
|
-
acc[el.name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
8163
|
+
acc[el.name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
6520
8164
|
return acc;
|
|
6521
8165
|
}, {});
|
|
6522
8166
|
}
|
|
@@ -6527,6 +8171,7 @@ ${indent}}` : "}";
|
|
|
6527
8171
|
acc[variant.name] = parseResponseValue(
|
|
6528
8172
|
responseIterator,
|
|
6529
8173
|
{ name: "", type: variant.type },
|
|
8174
|
+
parser,
|
|
6530
8175
|
structs,
|
|
6531
8176
|
enums
|
|
6532
8177
|
);
|
|
@@ -6557,7 +8202,7 @@ ${indent}}` : "}";
|
|
|
6557
8202
|
const name = it?.name ? it.name : idx;
|
|
6558
8203
|
const type = it?.type ? it.type : it;
|
|
6559
8204
|
const el = { name, type };
|
|
6560
|
-
acc[name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
8205
|
+
acc[name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
6561
8206
|
return acc;
|
|
6562
8207
|
}, {});
|
|
6563
8208
|
}
|
|
@@ -6566,13 +8211,20 @@ ${indent}}` : "}";
|
|
|
6566
8211
|
const el = { name: "", type: getArrayType(element.type) };
|
|
6567
8212
|
const len = BigInt(responseIterator.next().value);
|
|
6568
8213
|
while (parsedDataArr.length < len) {
|
|
6569
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
8214
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
6570
8215
|
}
|
|
6571
8216
|
return parsedDataArr;
|
|
6572
8217
|
}
|
|
6573
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
8218
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
6574
8219
|
}
|
|
6575
|
-
function responseParser(
|
|
8220
|
+
function responseParser({
|
|
8221
|
+
responseIterator,
|
|
8222
|
+
output,
|
|
8223
|
+
structs,
|
|
8224
|
+
enums,
|
|
8225
|
+
parsedResult,
|
|
8226
|
+
parser
|
|
8227
|
+
}) {
|
|
6576
8228
|
const { name, type } = output;
|
|
6577
8229
|
let temp;
|
|
6578
8230
|
switch (true) {
|
|
@@ -6580,14 +8232,14 @@ ${indent}}` : "}";
|
|
|
6580
8232
|
temp = responseIterator.next().value;
|
|
6581
8233
|
return BigInt(temp);
|
|
6582
8234
|
case (structs && type in structs || isTypeTuple(type)):
|
|
6583
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
8235
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
6584
8236
|
case (enums && isTypeEnum(type, enums)):
|
|
6585
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
8237
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
6586
8238
|
case CairoFixedArray.isTypeFixedArray(type):
|
|
6587
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
8239
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
6588
8240
|
case isTypeArray(type):
|
|
6589
8241
|
if (isCairo1Type(type)) {
|
|
6590
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
8242
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
6591
8243
|
}
|
|
6592
8244
|
const parsedDataArr = [];
|
|
6593
8245
|
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
@@ -6597,6 +8249,7 @@ ${indent}}` : "}";
|
|
|
6597
8249
|
parseResponseValue(
|
|
6598
8250
|
responseIterator,
|
|
6599
8251
|
{ name, type: output.type.replace("*", "") },
|
|
8252
|
+
parser,
|
|
6600
8253
|
structs,
|
|
6601
8254
|
enums
|
|
6602
8255
|
)
|
|
@@ -6605,9 +8258,9 @@ ${indent}}` : "}";
|
|
|
6605
8258
|
}
|
|
6606
8259
|
return parsedDataArr;
|
|
6607
8260
|
case isTypeNonZero(type):
|
|
6608
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
8261
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
6609
8262
|
default:
|
|
6610
|
-
return parseBaseTypes2(type, responseIterator);
|
|
8263
|
+
return parseBaseTypes2(type, responseIterator, parser);
|
|
6611
8264
|
}
|
|
6612
8265
|
}
|
|
6613
8266
|
|
|
@@ -6625,16 +8278,6 @@ ${indent}}` : "}";
|
|
|
6625
8278
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
6626
8279
|
);
|
|
6627
8280
|
};
|
|
6628
|
-
var validateBytes31 = (parameter, input) => {
|
|
6629
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
6630
|
-
assert(
|
|
6631
|
-
parameter.length < 32,
|
|
6632
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
6633
|
-
);
|
|
6634
|
-
};
|
|
6635
|
-
var validateByteArray = (parameter, input) => {
|
|
6636
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
6637
|
-
};
|
|
6638
8281
|
var validateUint = (parameter, input) => {
|
|
6639
8282
|
if (isNumber2(parameter)) {
|
|
6640
8283
|
assert(
|
|
@@ -6886,8 +8529,8 @@ ${indent}}` : "}";
|
|
|
6886
8529
|
case isTypeFelt(input.type):
|
|
6887
8530
|
validateFelt(parameter, input);
|
|
6888
8531
|
break;
|
|
6889
|
-
case
|
|
6890
|
-
|
|
8532
|
+
case CairoBytes31.isAbiType(input.type):
|
|
8533
|
+
CairoBytes31.validate(parameter);
|
|
6891
8534
|
break;
|
|
6892
8535
|
case (isTypeUint(input.type) || isTypeLiteral(input.type)):
|
|
6893
8536
|
validateUint(parameter, input);
|
|
@@ -6895,8 +8538,23 @@ ${indent}}` : "}";
|
|
|
6895
8538
|
case isTypeBool(input.type):
|
|
6896
8539
|
validateBool(parameter, input);
|
|
6897
8540
|
break;
|
|
6898
|
-
case
|
|
6899
|
-
|
|
8541
|
+
case CairoByteArray.isAbiType(input.type):
|
|
8542
|
+
CairoByteArray.validate(parameter);
|
|
8543
|
+
break;
|
|
8544
|
+
case CairoInt8.isAbiType(input.type):
|
|
8545
|
+
CairoInt8.validate(parameter);
|
|
8546
|
+
break;
|
|
8547
|
+
case CairoInt16.isAbiType(input.type):
|
|
8548
|
+
CairoInt16.validate(parameter);
|
|
8549
|
+
break;
|
|
8550
|
+
case CairoInt32.isAbiType(input.type):
|
|
8551
|
+
CairoInt32.validate(parameter);
|
|
8552
|
+
break;
|
|
8553
|
+
case CairoInt64.isAbiType(input.type):
|
|
8554
|
+
CairoInt64.validate(parameter);
|
|
8555
|
+
break;
|
|
8556
|
+
case CairoInt128.isAbiType(input.type):
|
|
8557
|
+
CairoInt128.validate(parameter);
|
|
6900
8558
|
break;
|
|
6901
8559
|
case (isTypeArray(input.type) || CairoFixedArray.isTypeFixedArray(input.type)):
|
|
6902
8560
|
validateArray(parameter, input, structs, enums);
|
|
@@ -6928,10 +8586,10 @@ ${indent}}` : "}";
|
|
|
6928
8586
|
parser;
|
|
6929
8587
|
structs;
|
|
6930
8588
|
enums;
|
|
6931
|
-
constructor(abi) {
|
|
8589
|
+
constructor(abi, parsingStrategy) {
|
|
6932
8590
|
this.structs = _CallData.getAbiStruct(abi);
|
|
6933
8591
|
this.enums = _CallData.getAbiEnum(abi);
|
|
6934
|
-
this.parser = createAbiParser(abi);
|
|
8592
|
+
this.parser = createAbiParser(abi, parsingStrategy);
|
|
6935
8593
|
this.abi = this.parser.getLegacyFormat();
|
|
6936
8594
|
}
|
|
6937
8595
|
/**
|
|
@@ -7000,7 +8658,15 @@ ${indent}}` : "}";
|
|
|
7000
8658
|
}
|
|
7001
8659
|
const argsIterator = args[Symbol.iterator]();
|
|
7002
8660
|
const callArray = abiMethod.inputs.reduce(
|
|
7003
|
-
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
8661
|
+
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
8662
|
+
parseCalldataField({
|
|
8663
|
+
argsIterator,
|
|
8664
|
+
input,
|
|
8665
|
+
structs: this.structs,
|
|
8666
|
+
enums: this.enums,
|
|
8667
|
+
parser: this.parser
|
|
8668
|
+
})
|
|
8669
|
+
),
|
|
7004
8670
|
[]
|
|
7005
8671
|
);
|
|
7006
8672
|
Object.defineProperty(callArray, "__compiled__", {
|
|
@@ -7087,7 +8753,14 @@ ${indent}}` : "}";
|
|
|
7087
8753
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
7088
8754
|
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
7089
8755
|
const propName = output.name ?? idx;
|
|
7090
|
-
acc[propName] = responseParser(
|
|
8756
|
+
acc[propName] = responseParser({
|
|
8757
|
+
responseIterator,
|
|
8758
|
+
output,
|
|
8759
|
+
structs: this.structs,
|
|
8760
|
+
enums: this.enums,
|
|
8761
|
+
parsedResult: acc,
|
|
8762
|
+
parser: this.parser
|
|
8763
|
+
});
|
|
7091
8764
|
if (acc[propName] && acc[`${propName}_len`]) {
|
|
7092
8765
|
delete acc[`${propName}_len`];
|
|
7093
8766
|
}
|
|
@@ -7167,12 +8840,13 @@ ${indent}}` : "}";
|
|
|
7167
8840
|
const typeCairoArray = Array.isArray(typeCairo) ? typeCairo : [typeCairo];
|
|
7168
8841
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
7169
8842
|
const decodedArray = typeCairoArray.map(
|
|
7170
|
-
(typeParam) => responseParser(
|
|
8843
|
+
(typeParam) => responseParser({
|
|
7171
8844
|
responseIterator,
|
|
7172
|
-
{ name: "", type: typeParam },
|
|
7173
|
-
this.
|
|
7174
|
-
this.
|
|
7175
|
-
|
|
8845
|
+
output: { name: "", type: typeParam },
|
|
8846
|
+
parser: this.parser,
|
|
8847
|
+
structs: this.structs,
|
|
8848
|
+
enums: this.enums
|
|
8849
|
+
})
|
|
7176
8850
|
);
|
|
7177
8851
|
return decodedArray.length === 1 ? decodedArray[0] : decodedArray;
|
|
7178
8852
|
}
|
|
@@ -7635,7 +9309,7 @@ ${indent}}` : "}";
|
|
|
7635
9309
|
intDAM: () => intDAM,
|
|
7636
9310
|
randomAddress: () => randomAddress,
|
|
7637
9311
|
resourceBoundsToBigInt: () => resourceBoundsToBigInt,
|
|
7638
|
-
|
|
9312
|
+
resourceBoundsToEstimateFeeResponse: () => resourceBoundsToEstimateFeeResponse,
|
|
7639
9313
|
resourceBoundsToHexString: () => resourceBoundsToHexString,
|
|
7640
9314
|
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
7641
9315
|
signatureToHexArray: () => signatureToHexArray,
|
|
@@ -7643,7 +9317,8 @@ ${indent}}` : "}";
|
|
|
7643
9317
|
toOverheadOverallFee: () => toOverheadOverallFee,
|
|
7644
9318
|
toOverheadResourceBounds: () => toOverheadResourceBounds,
|
|
7645
9319
|
toTransactionVersion: () => toTransactionVersion,
|
|
7646
|
-
v3Details: () => v3Details
|
|
9320
|
+
v3Details: () => v3Details,
|
|
9321
|
+
zeroResourceBounds: () => zeroResourceBounds
|
|
7647
9322
|
});
|
|
7648
9323
|
|
|
7649
9324
|
// node_modules/pako/dist/pako.esm.mjs
|
|
@@ -11854,26 +13529,44 @@ ${indent}}` : "}";
|
|
|
11854
13529
|
function signatureToHexArray(sig) {
|
|
11855
13530
|
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
11856
13531
|
}
|
|
13532
|
+
function zeroResourceBounds() {
|
|
13533
|
+
return toOverheadResourceBounds(ZeroFeeEstimate(), false);
|
|
13534
|
+
}
|
|
11857
13535
|
function toOverheadResourceBounds(estimate, overhead = config.get("resourceBoundsOverhead")) {
|
|
11858
13536
|
return {
|
|
11859
13537
|
l2_gas: {
|
|
11860
|
-
max_amount: addPercent(
|
|
11861
|
-
|
|
13538
|
+
max_amount: addPercent(
|
|
13539
|
+
estimate.l2_gas_consumed,
|
|
13540
|
+
overhead !== false ? overhead.l2_gas.max_amount : 0
|
|
13541
|
+
),
|
|
13542
|
+
max_price_per_unit: addPercent(
|
|
13543
|
+
estimate.l2_gas_price,
|
|
13544
|
+
overhead !== false ? overhead.l2_gas.max_price_per_unit : 0
|
|
13545
|
+
)
|
|
11862
13546
|
},
|
|
11863
13547
|
l1_gas: {
|
|
11864
|
-
max_amount: addPercent(
|
|
11865
|
-
|
|
13548
|
+
max_amount: addPercent(
|
|
13549
|
+
estimate.l1_gas_consumed,
|
|
13550
|
+
overhead !== false ? overhead.l1_gas.max_amount : 0
|
|
13551
|
+
),
|
|
13552
|
+
max_price_per_unit: addPercent(
|
|
13553
|
+
estimate.l1_gas_price,
|
|
13554
|
+
overhead !== false ? overhead.l1_gas.max_price_per_unit : 0
|
|
13555
|
+
)
|
|
11866
13556
|
},
|
|
11867
13557
|
l1_data_gas: {
|
|
11868
|
-
max_amount: addPercent(
|
|
13558
|
+
max_amount: addPercent(
|
|
13559
|
+
estimate.l1_data_gas_consumed,
|
|
13560
|
+
overhead !== false ? overhead.l1_data_gas.max_amount : 0
|
|
13561
|
+
),
|
|
11869
13562
|
max_price_per_unit: addPercent(
|
|
11870
13563
|
estimate.l1_data_gas_price,
|
|
11871
|
-
overhead.l1_data_gas.max_price_per_unit
|
|
13564
|
+
overhead !== false ? overhead.l1_data_gas.max_price_per_unit : 0
|
|
11872
13565
|
)
|
|
11873
13566
|
}
|
|
11874
13567
|
};
|
|
11875
13568
|
}
|
|
11876
|
-
function
|
|
13569
|
+
function resourceBoundsToEstimateFeeResponse(resourceBounds) {
|
|
11877
13570
|
return {
|
|
11878
13571
|
resourceBounds,
|
|
11879
13572
|
/**
|
|
@@ -11884,7 +13577,16 @@ ${indent}}` : "}";
|
|
|
11884
13577
|
};
|
|
11885
13578
|
}
|
|
11886
13579
|
function toOverheadOverallFee(estimate, overhead = config.get("resourceBoundsOverhead")) {
|
|
11887
|
-
return addPercent(estimate.l1_gas_consumed, overhead
|
|
13580
|
+
return addPercent(estimate.l1_gas_consumed, overhead !== false ? overhead.l1_gas.max_amount : 0) * addPercent(
|
|
13581
|
+
estimate.l1_gas_price,
|
|
13582
|
+
overhead !== false ? overhead.l1_gas.max_price_per_unit : 0
|
|
13583
|
+
) + addPercent(
|
|
13584
|
+
estimate.l1_data_gas_consumed,
|
|
13585
|
+
overhead !== false ? overhead.l1_data_gas.max_amount : 0
|
|
13586
|
+
) * addPercent(
|
|
13587
|
+
estimate.l1_data_gas_price,
|
|
13588
|
+
overhead !== false ? overhead.l1_data_gas.max_price_per_unit : 0
|
|
13589
|
+
) + addPercent(estimate.l2_gas_consumed, overhead !== false ? overhead.l2_gas.max_amount : 0) * addPercent(estimate.l2_gas_price, overhead !== false ? overhead.l2_gas.max_price_per_unit : 0);
|
|
11888
13590
|
}
|
|
11889
13591
|
function ZeroFeeEstimate() {
|
|
11890
13592
|
return {
|
|
@@ -11929,7 +13631,7 @@ ${indent}}` : "}";
|
|
|
11929
13631
|
accountDeploymentData: details.accountDeploymentData || [],
|
|
11930
13632
|
nonceDataAvailabilityMode: details.nonceDataAvailabilityMode || EDataAvailabilityMode3.L1,
|
|
11931
13633
|
feeDataAvailabilityMode: details.feeDataAvailabilityMode || EDataAvailabilityMode3.L1,
|
|
11932
|
-
resourceBounds: details.resourceBounds ??
|
|
13634
|
+
resourceBounds: details.resourceBounds ?? zeroResourceBounds()
|
|
11933
13635
|
};
|
|
11934
13636
|
}
|
|
11935
13637
|
function getFullPublicKey(privateKey) {
|
|
@@ -11999,114 +13701,6 @@ ${indent}}` : "}";
|
|
|
11999
13701
|
return { ...contract, program: decompressProgram(contract.program) };
|
|
12000
13702
|
}
|
|
12001
13703
|
|
|
12002
|
-
// src/utils/errors/rpc.ts
|
|
12003
|
-
var errorCodes = {
|
|
12004
|
-
FAILED_TO_RECEIVE_TXN: 1,
|
|
12005
|
-
NO_TRACE_AVAILABLE: 10,
|
|
12006
|
-
CONTRACT_NOT_FOUND: 20,
|
|
12007
|
-
ENTRYPOINT_NOT_FOUND: 21,
|
|
12008
|
-
BLOCK_NOT_FOUND: 24,
|
|
12009
|
-
INVALID_TXN_INDEX: 27,
|
|
12010
|
-
CLASS_HASH_NOT_FOUND: 28,
|
|
12011
|
-
TXN_HASH_NOT_FOUND: 29,
|
|
12012
|
-
PAGE_SIZE_TOO_BIG: 31,
|
|
12013
|
-
NO_BLOCKS: 32,
|
|
12014
|
-
INVALID_CONTINUATION_TOKEN: 33,
|
|
12015
|
-
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
12016
|
-
CONTRACT_ERROR: 40,
|
|
12017
|
-
TRANSACTION_EXECUTION_ERROR: 41,
|
|
12018
|
-
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
12019
|
-
CLASS_ALREADY_DECLARED: 51,
|
|
12020
|
-
INVALID_TRANSACTION_NONCE: 52,
|
|
12021
|
-
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
12022
|
-
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
12023
|
-
VALIDATION_FAILURE: 55,
|
|
12024
|
-
COMPILATION_FAILED: 56,
|
|
12025
|
-
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
12026
|
-
NON_ACCOUNT: 58,
|
|
12027
|
-
DUPLICATE_TX: 59,
|
|
12028
|
-
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
12029
|
-
UNSUPPORTED_TX_VERSION: 61,
|
|
12030
|
-
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
12031
|
-
UNEXPECTED_ERROR: 63,
|
|
12032
|
-
INVALID_SUBSCRIPTION_ID: 66,
|
|
12033
|
-
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
12034
|
-
TOO_MANY_BLOCKS_BACK: 68,
|
|
12035
|
-
COMPILATION_ERROR: 100,
|
|
12036
|
-
INVALID_ADDRESS: 150,
|
|
12037
|
-
TOKEN_NOT_SUPPORTED: 151,
|
|
12038
|
-
INVALID_SIGNATURE: 153,
|
|
12039
|
-
MAX_AMOUNT_TOO_LOW: 154,
|
|
12040
|
-
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
12041
|
-
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
12042
|
-
INVALID_TIME_BOUNDS: 157,
|
|
12043
|
-
INVALID_DEPLOYMENT_DATA: 158,
|
|
12044
|
-
INVALID_CLASS_HASH: 159,
|
|
12045
|
-
INVALID_ID: 160,
|
|
12046
|
-
UNKNOWN_ERROR: 163
|
|
12047
|
-
};
|
|
12048
|
-
var rpc_default = errorCodes;
|
|
12049
|
-
|
|
12050
|
-
// src/utils/errors/index.ts
|
|
12051
|
-
function fixStack(target, fn = target.constructor) {
|
|
12052
|
-
const { captureStackTrace } = Error;
|
|
12053
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
12054
|
-
}
|
|
12055
|
-
function fixProto(target, prototype) {
|
|
12056
|
-
const { setPrototypeOf } = Object;
|
|
12057
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
12058
|
-
}
|
|
12059
|
-
var CustomError = class extends Error {
|
|
12060
|
-
name;
|
|
12061
|
-
constructor(message) {
|
|
12062
|
-
super(message);
|
|
12063
|
-
Object.defineProperty(this, "name", {
|
|
12064
|
-
value: new.target.name,
|
|
12065
|
-
enumerable: false,
|
|
12066
|
-
configurable: true
|
|
12067
|
-
});
|
|
12068
|
-
fixProto(this, new.target.prototype);
|
|
12069
|
-
fixStack(this);
|
|
12070
|
-
}
|
|
12071
|
-
};
|
|
12072
|
-
var LibraryError = class extends CustomError {
|
|
12073
|
-
};
|
|
12074
|
-
var RpcError = class extends LibraryError {
|
|
12075
|
-
constructor(baseError, method, params) {
|
|
12076
|
-
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
12077
|
-
|
|
12078
|
-
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
12079
|
-
this.baseError = baseError;
|
|
12080
|
-
this.request = { method, params };
|
|
12081
|
-
}
|
|
12082
|
-
request;
|
|
12083
|
-
get code() {
|
|
12084
|
-
return this.baseError.code;
|
|
12085
|
-
}
|
|
12086
|
-
/**
|
|
12087
|
-
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
12088
|
-
* @example
|
|
12089
|
-
* ```typescript
|
|
12090
|
-
* SomeError.isType('UNEXPECTED_ERROR');
|
|
12091
|
-
* ```
|
|
12092
|
-
*/
|
|
12093
|
-
isType(typeName) {
|
|
12094
|
-
return rpc_default[typeName] === this.code;
|
|
12095
|
-
}
|
|
12096
|
-
};
|
|
12097
|
-
var TimeoutError = class extends LibraryError {
|
|
12098
|
-
constructor(message) {
|
|
12099
|
-
super(message);
|
|
12100
|
-
this.name = "TimeoutError";
|
|
12101
|
-
}
|
|
12102
|
-
};
|
|
12103
|
-
var WebSocketNotConnectedError = class extends LibraryError {
|
|
12104
|
-
constructor(message) {
|
|
12105
|
-
super(message);
|
|
12106
|
-
this.name = "WebSocketNotConnectedError";
|
|
12107
|
-
}
|
|
12108
|
-
};
|
|
12109
|
-
|
|
12110
13704
|
// src/utils/eth.ts
|
|
12111
13705
|
var eth_exports = {};
|
|
12112
13706
|
__export(eth_exports, {
|
|
@@ -12326,7 +13920,7 @@ ${indent}}` : "}";
|
|
|
12326
13920
|
tag = null;
|
|
12327
13921
|
setIdentifier(__identifier) {
|
|
12328
13922
|
if (isString(__identifier)) {
|
|
12329
|
-
if (
|
|
13923
|
+
if (isDecimalString2(__identifier)) {
|
|
12330
13924
|
this.number = parseInt(__identifier, 10);
|
|
12331
13925
|
} else if (isHex2(__identifier)) {
|
|
12332
13926
|
this.hash = __identifier;
|
|
@@ -12775,11 +14369,13 @@ ${indent}}` : "}";
|
|
|
12775
14369
|
esm_exports.ETransactionStatus.ACCEPTED_ON_L2,
|
|
12776
14370
|
esm_exports.ETransactionStatus.ACCEPTED_ON_L1
|
|
12777
14371
|
];
|
|
14372
|
+
const txLife = [];
|
|
12778
14373
|
let txStatus;
|
|
12779
14374
|
while (!onchain) {
|
|
12780
14375
|
await wait(retryInterval);
|
|
12781
14376
|
try {
|
|
12782
14377
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
14378
|
+
txLife.push(txStatus.finality_status);
|
|
12783
14379
|
const executionStatus = txStatus.execution_status;
|
|
12784
14380
|
const finalityStatus = txStatus.finality_status;
|
|
12785
14381
|
if (!finalityStatus) {
|
|
@@ -12799,6 +14395,18 @@ ${indent}}` : "}";
|
|
|
12799
14395
|
if (error instanceof Error && isErrorState) {
|
|
12800
14396
|
throw error;
|
|
12801
14397
|
}
|
|
14398
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
14399
|
+
logger.info("txLife: ", txLife);
|
|
14400
|
+
const errorMessages = {
|
|
14401
|
+
[esm_exports2.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
14402
|
+
[esm_exports2.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
14403
|
+
[esm_exports2.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
14404
|
+
};
|
|
14405
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
14406
|
+
if (errorMessage) {
|
|
14407
|
+
throw new Error(errorMessage);
|
|
14408
|
+
}
|
|
14409
|
+
}
|
|
12802
14410
|
if (retries <= 0) {
|
|
12803
14411
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
12804
14412
|
}
|
|
@@ -13348,11 +14956,13 @@ ${indent}}` : "}";
|
|
|
13348
14956
|
esm_exports2.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
13349
14957
|
esm_exports2.ETransactionFinalityStatus.ACCEPTED_ON_L1
|
|
13350
14958
|
];
|
|
14959
|
+
const txLife = [];
|
|
13351
14960
|
let txStatus;
|
|
13352
14961
|
while (!onchain) {
|
|
13353
14962
|
await wait(retryInterval);
|
|
13354
14963
|
try {
|
|
13355
14964
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
14965
|
+
txLife.push(txStatus.finality_status);
|
|
13356
14966
|
const executionStatus = txStatus.execution_status;
|
|
13357
14967
|
const finalityStatus = txStatus.finality_status;
|
|
13358
14968
|
if (!finalityStatus) {
|
|
@@ -13372,6 +14982,18 @@ ${indent}}` : "}";
|
|
|
13372
14982
|
if (error instanceof Error && isErrorState) {
|
|
13373
14983
|
throw error;
|
|
13374
14984
|
}
|
|
14985
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
14986
|
+
logger.info("txLife: ", txLife);
|
|
14987
|
+
const errorMessages = {
|
|
14988
|
+
[esm_exports2.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
14989
|
+
[esm_exports2.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
14990
|
+
[esm_exports2.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
14991
|
+
};
|
|
14992
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
14993
|
+
if (errorMessage) {
|
|
14994
|
+
throw new Error(errorMessage);
|
|
14995
|
+
}
|
|
14996
|
+
}
|
|
13375
14997
|
if (retries <= 0) {
|
|
13376
14998
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
13377
14999
|
}
|
|
@@ -14417,56 +16039,123 @@ ${indent}}` : "}";
|
|
|
14417
16039
|
statusReceipt;
|
|
14418
16040
|
value;
|
|
14419
16041
|
constructor(receipt) {
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
}
|
|
14426
|
-
for (const [key, value] of Object.entries(receipt)) {
|
|
14427
|
-
Object.defineProperty(this, key, {
|
|
14428
|
-
enumerable: true,
|
|
16042
|
+
Object.assign(this, receipt);
|
|
16043
|
+
const [statusReceipt, value] = _ReceiptTx.isSuccess(receipt) ? ["SUCCEEDED", receipt] : _ReceiptTx.isReverted(receipt) ? ["REVERTED", receipt] : ["ERROR", new Error("Unknown response type")];
|
|
16044
|
+
Object.defineProperties(this, {
|
|
16045
|
+
statusReceipt: {
|
|
16046
|
+
value: statusReceipt,
|
|
14429
16047
|
writable: false,
|
|
14430
|
-
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
|
|
14444
|
-
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
14452
|
-
|
|
16048
|
+
enumerable: false,
|
|
16049
|
+
configurable: false
|
|
16050
|
+
},
|
|
16051
|
+
value: {
|
|
16052
|
+
value,
|
|
16053
|
+
writable: false,
|
|
16054
|
+
enumerable: false,
|
|
16055
|
+
configurable: false
|
|
16056
|
+
},
|
|
16057
|
+
match: {
|
|
16058
|
+
value(callbacks) {
|
|
16059
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
16060
|
+
},
|
|
16061
|
+
writable: false,
|
|
16062
|
+
enumerable: false,
|
|
16063
|
+
configurable: false
|
|
16064
|
+
},
|
|
16065
|
+
isSuccess: {
|
|
16066
|
+
value: () => statusReceipt === "SUCCEEDED",
|
|
16067
|
+
writable: false,
|
|
16068
|
+
enumerable: false,
|
|
16069
|
+
configurable: false
|
|
16070
|
+
},
|
|
16071
|
+
isReverted: {
|
|
16072
|
+
value: () => statusReceipt === "REVERTED",
|
|
16073
|
+
writable: false,
|
|
16074
|
+
enumerable: false,
|
|
16075
|
+
configurable: false
|
|
16076
|
+
},
|
|
16077
|
+
isError: {
|
|
16078
|
+
value: () => statusReceipt === "ERROR",
|
|
16079
|
+
writable: false,
|
|
16080
|
+
enumerable: false,
|
|
16081
|
+
configurable: false
|
|
16082
|
+
}
|
|
16083
|
+
});
|
|
14453
16084
|
}
|
|
16085
|
+
match;
|
|
16086
|
+
isSuccess;
|
|
16087
|
+
isReverted;
|
|
16088
|
+
isError;
|
|
14454
16089
|
static isSuccess(transactionReceipt) {
|
|
14455
16090
|
return transactionReceipt.execution_status === TransactionExecutionStatus.SUCCEEDED;
|
|
14456
16091
|
}
|
|
14457
16092
|
static isReverted(transactionReceipt) {
|
|
14458
16093
|
return transactionReceipt.execution_status === TransactionExecutionStatus.REVERTED;
|
|
14459
16094
|
}
|
|
14460
|
-
// Status do not exist on receipts
|
|
14461
|
-
/* static isRejected(
|
|
14462
|
-
transactionReceipt: GetTxReceiptResponseWithoutHelper
|
|
14463
|
-
): transactionReceipt is RejectedTransactionReceiptResponse {
|
|
14464
|
-
return (
|
|
14465
|
-
(transactionReceipt as RejectedTransactionReceiptResponse).status ===
|
|
14466
|
-
TransactionExecutionStatus.REJECTED
|
|
14467
|
-
);
|
|
14468
|
-
} */
|
|
14469
16095
|
};
|
|
16096
|
+
var RECEIPT_CONFIG = {
|
|
16097
|
+
[TransactionExecutionStatus.SUCCEEDED]: {
|
|
16098
|
+
statusReceipt: "SUCCEEDED",
|
|
16099
|
+
getBaseData: (receipt) => receipt,
|
|
16100
|
+
getValue: (receipt) => receipt
|
|
16101
|
+
},
|
|
16102
|
+
[TransactionExecutionStatus.REVERTED]: {
|
|
16103
|
+
statusReceipt: "REVERTED",
|
|
16104
|
+
getBaseData: (receipt) => receipt,
|
|
16105
|
+
getValue: (receipt) => receipt
|
|
16106
|
+
}
|
|
16107
|
+
};
|
|
16108
|
+
function createTransactionReceipt(receipt) {
|
|
16109
|
+
const config3 = RECEIPT_CONFIG[receipt.execution_status];
|
|
16110
|
+
let obj;
|
|
16111
|
+
if (config3) {
|
|
16112
|
+
const { statusReceipt, getBaseData, getValue } = config3;
|
|
16113
|
+
const value = getValue(receipt);
|
|
16114
|
+
obj = {
|
|
16115
|
+
...getBaseData(receipt),
|
|
16116
|
+
statusReceipt,
|
|
16117
|
+
value,
|
|
16118
|
+
match(callbacks) {
|
|
16119
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
16120
|
+
},
|
|
16121
|
+
isSuccess() {
|
|
16122
|
+
return statusReceipt === "SUCCEEDED";
|
|
16123
|
+
},
|
|
16124
|
+
isReverted() {
|
|
16125
|
+
return statusReceipt === "REVERTED";
|
|
16126
|
+
},
|
|
16127
|
+
isError() {
|
|
16128
|
+
return false;
|
|
16129
|
+
}
|
|
16130
|
+
};
|
|
16131
|
+
} else {
|
|
16132
|
+
const errorValue = new Error("Unknown response type");
|
|
16133
|
+
obj = {
|
|
16134
|
+
statusReceipt: "ERROR",
|
|
16135
|
+
value: errorValue,
|
|
16136
|
+
match(callbacks) {
|
|
16137
|
+
return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
|
|
16138
|
+
},
|
|
16139
|
+
isSuccess() {
|
|
16140
|
+
return false;
|
|
16141
|
+
},
|
|
16142
|
+
isReverted() {
|
|
16143
|
+
return false;
|
|
16144
|
+
},
|
|
16145
|
+
isError() {
|
|
16146
|
+
return true;
|
|
16147
|
+
}
|
|
16148
|
+
};
|
|
16149
|
+
}
|
|
16150
|
+
Object.setPrototypeOf(obj, ReceiptTx.prototype);
|
|
16151
|
+
Object.defineProperty(obj, "constructor", {
|
|
16152
|
+
value: ReceiptTx,
|
|
16153
|
+
writable: false,
|
|
16154
|
+
enumerable: false,
|
|
16155
|
+
configurable: false
|
|
16156
|
+
});
|
|
16157
|
+
return obj;
|
|
16158
|
+
}
|
|
14470
16159
|
|
|
14471
16160
|
// src/utils/typedData.ts
|
|
14472
16161
|
var typedData_exports = {};
|
|
@@ -15135,7 +16824,7 @@ ${indent}}` : "}";
|
|
|
15135
16824
|
async getTransactionReceipt(txHash) {
|
|
15136
16825
|
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
15137
16826
|
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
15138
|
-
return
|
|
16827
|
+
return createTransactionReceipt(txReceiptWoHelperModified);
|
|
15139
16828
|
}
|
|
15140
16829
|
async getTransactionTrace(txHash) {
|
|
15141
16830
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -15151,7 +16840,7 @@ ${indent}}` : "}";
|
|
|
15151
16840
|
txHash,
|
|
15152
16841
|
options
|
|
15153
16842
|
);
|
|
15154
|
-
return
|
|
16843
|
+
return createTransactionReceipt(receiptWoHelper);
|
|
15155
16844
|
}
|
|
15156
16845
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
15157
16846
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -16376,12 +18065,12 @@ ${indent}}` : "}";
|
|
|
16376
18065
|
*/
|
|
16377
18066
|
async signRaw(msgHash) {
|
|
16378
18067
|
addHexPrefix(
|
|
16379
|
-
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0,
|
|
18068
|
+
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, buffer_default.from(this.pathBuffer)))
|
|
16380
18069
|
);
|
|
16381
18070
|
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
16382
18071
|
const buff2 = hexToBytes2(shiftedHash);
|
|
16383
18072
|
const respSign2 = Uint8Array.from(
|
|
16384
|
-
await this._transporter.send(Number("0x5a"), 2, 1, 0,
|
|
18073
|
+
await this._transporter.send(Number("0x5a"), 2, 1, 0, buffer_default.from(buff2))
|
|
16385
18074
|
);
|
|
16386
18075
|
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
16387
18076
|
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
@@ -16394,7 +18083,7 @@ ${indent}}` : "}";
|
|
|
16394
18083
|
async getPublicKeys() {
|
|
16395
18084
|
const pathBuff = this.pathBuffer;
|
|
16396
18085
|
const respGetPublic = Uint8Array.from(
|
|
16397
|
-
await this._transporter.send(Number("0x5a"), 1, 0, 0,
|
|
18086
|
+
await this._transporter.send(Number("0x5a"), 1, 0, 0, buffer_default.from(pathBuff))
|
|
16398
18087
|
);
|
|
16399
18088
|
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
16400
18089
|
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
@@ -16649,7 +18338,7 @@ ${indent}}` : "}";
|
|
|
16649
18338
|
txDetails.accountDeploymentData.length <= 7,
|
|
16650
18339
|
"accountDeploymentData includes more than 7 items"
|
|
16651
18340
|
);
|
|
16652
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
18341
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
16653
18342
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
16654
18343
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16655
18344
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
@@ -16671,30 +18360,30 @@ ${indent}}` : "}";
|
|
|
16671
18360
|
nonceBuf,
|
|
16672
18361
|
dAModeHashBuf
|
|
16673
18362
|
]);
|
|
16674
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
18363
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
16675
18364
|
const paymasterBuf = concatenateArrayBuffer(
|
|
16676
18365
|
txDetails.paymasterData.map((value) => {
|
|
16677
18366
|
const a = this.convertBnToLedger(value);
|
|
16678
18367
|
return a;
|
|
16679
18368
|
})
|
|
16680
18369
|
);
|
|
16681
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
18370
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
|
|
16682
18371
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
16683
18372
|
txDetails.paymasterData.map((value) => {
|
|
16684
18373
|
const a = this.convertBnToLedger(value);
|
|
16685
18374
|
return a;
|
|
16686
18375
|
})
|
|
16687
18376
|
);
|
|
16688
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
18377
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
|
|
16689
18378
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
16690
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
18379
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
|
|
16691
18380
|
let respSign = new Uint8Array(0);
|
|
16692
18381
|
for (const call of calls) {
|
|
16693
18382
|
const calldatas = this.encodeCall(call);
|
|
16694
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
18383
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
|
|
16695
18384
|
if (calldatas.length > 1) {
|
|
16696
18385
|
calldatas.slice(1).forEach(async (part) => {
|
|
16697
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 1,
|
|
18386
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
|
|
16698
18387
|
});
|
|
16699
18388
|
}
|
|
16700
18389
|
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
@@ -16731,7 +18420,7 @@ ${indent}}` : "}";
|
|
|
16731
18420
|
* ```
|
|
16732
18421
|
*/
|
|
16733
18422
|
async signDeployAccountV3(deployAccountDetail) {
|
|
16734
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
18423
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
16735
18424
|
const accountAddressBuf = this.convertBnToLedger(
|
|
16736
18425
|
deployAccountDetail.contractAddress
|
|
16737
18426
|
);
|
|
@@ -16753,7 +18442,7 @@ ${indent}}` : "}";
|
|
|
16753
18442
|
classHashBuf,
|
|
16754
18443
|
saltBuf
|
|
16755
18444
|
]);
|
|
16756
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
18445
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
16757
18446
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
16758
18447
|
const l1_gasBuf = this.convertBnToLedger(
|
|
16759
18448
|
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
@@ -16762,17 +18451,17 @@ ${indent}}` : "}";
|
|
|
16762
18451
|
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
16763
18452
|
);
|
|
16764
18453
|
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
16765
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
18454
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
16766
18455
|
const paymasterBuf = concatenateArrayBuffer(
|
|
16767
18456
|
deployAccountDetail.paymasterData.map((value) => {
|
|
16768
18457
|
const a = this.convertBnToLedger(value);
|
|
16769
18458
|
return a;
|
|
16770
18459
|
})
|
|
16771
18460
|
);
|
|
16772
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
18461
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
16773
18462
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
16774
18463
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
16775
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
18464
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
16776
18465
|
const constructorBuf = concatenateArrayBuffer(
|
|
16777
18466
|
compiledConstructor.map((parameter) => {
|
|
16778
18467
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -16785,7 +18474,7 @@ ${indent}}` : "}";
|
|
|
16785
18474
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
16786
18475
|
let respSign = new Uint8Array(0);
|
|
16787
18476
|
for (const chunk of constructorChunks) {
|
|
16788
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
18477
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
16789
18478
|
}
|
|
16790
18479
|
return this.decodeSignatureLedger(respSign);
|
|
16791
18480
|
}
|
|
@@ -16875,7 +18564,7 @@ ${indent}}` : "}";
|
|
|
16875
18564
|
txDetails.accountDeploymentData.length <= 7,
|
|
16876
18565
|
"accountDeploymentData includes more than 7 items"
|
|
16877
18566
|
);
|
|
16878
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
18567
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
16879
18568
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
16880
18569
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
16881
18570
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
@@ -16891,7 +18580,7 @@ ${indent}}` : "}";
|
|
|
16891
18580
|
nonceBuf,
|
|
16892
18581
|
dAModeHashBuf
|
|
16893
18582
|
]);
|
|
16894
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
18583
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
16895
18584
|
if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
|
|
16896
18585
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
16897
18586
|
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
@@ -16905,7 +18594,7 @@ ${indent}}` : "}";
|
|
|
16905
18594
|
l2_gasBuf,
|
|
16906
18595
|
l1_data_gasBuf
|
|
16907
18596
|
]);
|
|
16908
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
18597
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
|
|
16909
18598
|
}
|
|
16910
18599
|
const paymasterBuf = concatenateArrayBuffer(
|
|
16911
18600
|
txDetails.paymasterData.map((value) => {
|
|
@@ -16913,23 +18602,23 @@ ${indent}}` : "}";
|
|
|
16913
18602
|
return a;
|
|
16914
18603
|
})
|
|
16915
18604
|
);
|
|
16916
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
18605
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(paymasterBuf));
|
|
16917
18606
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
16918
18607
|
txDetails.paymasterData.map((value) => {
|
|
16919
18608
|
const a = this.convertBnToLedger(value);
|
|
16920
18609
|
return a;
|
|
16921
18610
|
})
|
|
16922
18611
|
);
|
|
16923
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
18612
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(accountDeployDataBuf));
|
|
16924
18613
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
16925
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
18614
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(nbCallsBuf));
|
|
16926
18615
|
let respSign = new Uint8Array(0);
|
|
16927
18616
|
for (const call of calls) {
|
|
16928
18617
|
const calldatas = this.encodeCall(call);
|
|
16929
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0,
|
|
18618
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, buffer_default.from(calldatas[0]));
|
|
16930
18619
|
if (calldatas.length > 1) {
|
|
16931
18620
|
calldatas.slice(1).forEach(async (part) => {
|
|
16932
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1,
|
|
18621
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, buffer_default.from(part));
|
|
16933
18622
|
});
|
|
16934
18623
|
}
|
|
16935
18624
|
}
|
|
@@ -16965,7 +18654,7 @@ ${indent}}` : "}";
|
|
|
16965
18654
|
* ```
|
|
16966
18655
|
*/
|
|
16967
18656
|
async signDeployAccountV3(deployAccountDetail) {
|
|
16968
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
18657
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
16969
18658
|
const accountAddressBuf = this.convertBnToLedger(
|
|
16970
18659
|
deployAccountDetail.contractAddress
|
|
16971
18660
|
);
|
|
@@ -16987,7 +18676,7 @@ ${indent}}` : "}";
|
|
|
16987
18676
|
classHashBuf,
|
|
16988
18677
|
saltBuf
|
|
16989
18678
|
]);
|
|
16990
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
18679
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
16991
18680
|
if (isRPC08Plus_ResourceBoundsBN(deployAccountDetail.resourceBounds)) {
|
|
16992
18681
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
16993
18682
|
const l1_gasBuf = this.convertBnToLedger(
|
|
@@ -17005,7 +18694,7 @@ ${indent}}` : "}";
|
|
|
17005
18694
|
l2_gasBuf,
|
|
17006
18695
|
l1_data_gasBuf
|
|
17007
18696
|
]);
|
|
17008
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
18697
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
17009
18698
|
}
|
|
17010
18699
|
const paymasterBuf = concatenateArrayBuffer(
|
|
17011
18700
|
deployAccountDetail.paymasterData.map((value) => {
|
|
@@ -17013,10 +18702,10 @@ ${indent}}` : "}";
|
|
|
17013
18702
|
return a;
|
|
17014
18703
|
})
|
|
17015
18704
|
);
|
|
17016
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
18705
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
17017
18706
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
17018
18707
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
17019
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
18708
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
17020
18709
|
const constructorBuf = concatenateArrayBuffer(
|
|
17021
18710
|
compiledConstructor.map((parameter) => {
|
|
17022
18711
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -17029,7 +18718,7 @@ ${indent}}` : "}";
|
|
|
17029
18718
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
17030
18719
|
let respSign = new Uint8Array(0);
|
|
17031
18720
|
for (const chunk of constructorChunks) {
|
|
17032
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
18721
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
17033
18722
|
}
|
|
17034
18723
|
return this.decodeSignatureLedger(respSign);
|
|
17035
18724
|
}
|
|
@@ -17698,7 +19387,8 @@ ${indent}}` : "}";
|
|
|
17698
19387
|
}
|
|
17699
19388
|
async estimateFeeBulk(invocations, details = {}) {
|
|
17700
19389
|
if (!invocations.length) throw TypeError("Invocations should be non-empty array");
|
|
17701
|
-
if (details.resourceBounds)
|
|
19390
|
+
if (details.resourceBounds)
|
|
19391
|
+
return [resourceBoundsToEstimateFeeResponse(details.resourceBounds)];
|
|
17702
19392
|
const { nonce, blockIdentifier, version, skipValidate } = details;
|
|
17703
19393
|
const detailsWithTip = await this.resolveDetailsWithTip(details);
|
|
17704
19394
|
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
@@ -18556,7 +20246,11 @@ ${indent}}` : "}";
|
|
|
18556
20246
|
Object.keys(source).forEach((key) => {
|
|
18557
20247
|
if (isObject2(source[key])) {
|
|
18558
20248
|
if (!(key in target)) Object.assign(output, { [key]: source[key] });
|
|
18559
|
-
else
|
|
20249
|
+
else
|
|
20250
|
+
output[key] = mergeAbiEvents(
|
|
20251
|
+
target[key],
|
|
20252
|
+
source[key]
|
|
20253
|
+
);
|
|
18560
20254
|
} else {
|
|
18561
20255
|
Object.assign(output, { [key]: source[key] });
|
|
18562
20256
|
}
|
|
@@ -18564,7 +20258,7 @@ ${indent}}` : "}";
|
|
|
18564
20258
|
}
|
|
18565
20259
|
return output;
|
|
18566
20260
|
}
|
|
18567
|
-
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
|
|
20261
|
+
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums, parser) {
|
|
18568
20262
|
const ret = providerReceivedEvents.flat().reduce((acc, recEvent) => {
|
|
18569
20263
|
const currentEvent = JSON.parse(JSON.stringify(recEvent));
|
|
18570
20264
|
let abiEvent = abiEvents[currentEvent.keys.shift() ?? 0];
|
|
@@ -18583,22 +20277,24 @@ ${indent}}` : "}";
|
|
|
18583
20277
|
const abiEventKeys = abiEvent.members?.filter((it) => it.kind === "key") || abiEvent.keys;
|
|
18584
20278
|
const abiEventData = abiEvent.members?.filter((it) => it.kind === "data") || abiEvent.data;
|
|
18585
20279
|
abiEventKeys.forEach((key) => {
|
|
18586
|
-
parsedEvent[abiEvent.name][key.name] = responseParser(
|
|
18587
|
-
keysIter,
|
|
18588
|
-
key,
|
|
18589
|
-
abiStructs,
|
|
18590
|
-
abiEnums,
|
|
18591
|
-
|
|
18592
|
-
|
|
20280
|
+
parsedEvent[abiEvent.name][key.name] = responseParser({
|
|
20281
|
+
responseIterator: keysIter,
|
|
20282
|
+
output: key,
|
|
20283
|
+
structs: abiStructs,
|
|
20284
|
+
enums: abiEnums,
|
|
20285
|
+
parser,
|
|
20286
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
20287
|
+
});
|
|
18593
20288
|
});
|
|
18594
20289
|
abiEventData.forEach((data) => {
|
|
18595
|
-
parsedEvent[abiEvent.name][data.name] = responseParser(
|
|
18596
|
-
dataIter,
|
|
18597
|
-
data,
|
|
18598
|
-
abiStructs,
|
|
18599
|
-
abiEnums,
|
|
18600
|
-
|
|
18601
|
-
|
|
20290
|
+
parsedEvent[abiEvent.name][data.name] = responseParser({
|
|
20291
|
+
responseIterator: dataIter,
|
|
20292
|
+
output: data,
|
|
20293
|
+
structs: abiStructs,
|
|
20294
|
+
enums: abiEnums,
|
|
20295
|
+
parser,
|
|
20296
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
20297
|
+
});
|
|
18602
20298
|
});
|
|
18603
20299
|
if ("block_hash" in currentEvent) parsedEvent.block_hash = currentEvent.block_hash;
|
|
18604
20300
|
if ("block_number" in currentEvent) parsedEvent.block_number = currentEvent.block_number;
|
|
@@ -18616,8 +20312,8 @@ ${indent}}` : "}";
|
|
|
18616
20312
|
const options = { ...contract.withOptionsProps };
|
|
18617
20313
|
contract.withOptionsProps = void 0;
|
|
18618
20314
|
return contract.call(functionAbi.name, args, {
|
|
18619
|
-
parseRequest:
|
|
18620
|
-
parseResponse:
|
|
20315
|
+
parseRequest: contract.parseRequest,
|
|
20316
|
+
parseResponse: contract.parseResponse,
|
|
18621
20317
|
...options
|
|
18622
20318
|
});
|
|
18623
20319
|
};
|
|
@@ -18627,7 +20323,7 @@ ${indent}}` : "}";
|
|
|
18627
20323
|
const options = { ...contract.withOptionsProps };
|
|
18628
20324
|
contract.withOptionsProps = void 0;
|
|
18629
20325
|
return contract.invoke(functionAbi.name, args, {
|
|
18630
|
-
parseRequest:
|
|
20326
|
+
parseRequest: contract.parseRequest,
|
|
18631
20327
|
...options
|
|
18632
20328
|
});
|
|
18633
20329
|
};
|
|
@@ -18655,6 +20351,8 @@ ${indent}}` : "}";
|
|
|
18655
20351
|
address;
|
|
18656
20352
|
providerOrAccount;
|
|
18657
20353
|
classHash;
|
|
20354
|
+
parseRequest;
|
|
20355
|
+
parseResponse;
|
|
18658
20356
|
structs;
|
|
18659
20357
|
events;
|
|
18660
20358
|
functions;
|
|
@@ -18663,6 +20361,7 @@ ${indent}}` : "}";
|
|
|
18663
20361
|
estimateFee;
|
|
18664
20362
|
callData;
|
|
18665
20363
|
withOptionsProps;
|
|
20364
|
+
parsingStrategy;
|
|
18666
20365
|
/**
|
|
18667
20366
|
* @param options
|
|
18668
20367
|
* - abi: Abi of the contract object (required)
|
|
@@ -18670,14 +20369,18 @@ ${indent}}` : "}";
|
|
|
18670
20369
|
* - providerOrAccount?: Provider or Account to attach to (fallback to defaultProvider)
|
|
18671
20370
|
* - parseRequest?: compile and validate arguments (optional, default true)
|
|
18672
20371
|
* - parseResponse?: Parse elements of the response array and structuring them into response object (optional, default true)
|
|
20372
|
+
* - parser?: Abi parser (optional, default createAbiParser(options.abi))
|
|
18673
20373
|
*/
|
|
18674
20374
|
constructor(options) {
|
|
18675
|
-
|
|
18676
|
-
|
|
20375
|
+
this.parsingStrategy = options.parsingStrategy;
|
|
20376
|
+
const parser = createAbiParser(options.abi, options.parsingStrategy);
|
|
18677
20377
|
this.abi = parser.getLegacyFormat();
|
|
20378
|
+
this.address = options.address && options.address.toLowerCase();
|
|
18678
20379
|
this.providerOrAccount = options.providerOrAccount ?? defaultProvider;
|
|
20380
|
+
this.parseRequest = options.parseRequest ?? true;
|
|
20381
|
+
this.parseResponse = options.parseResponse ?? true;
|
|
18679
20382
|
this.classHash = options.classHash;
|
|
18680
|
-
this.callData = new CallData(options.abi);
|
|
20383
|
+
this.callData = new CallData(options.abi, options.parsingStrategy);
|
|
18681
20384
|
this.structs = CallData.getAbiStruct(options.abi);
|
|
18682
20385
|
this.events = getAbiEvents(options.abi);
|
|
18683
20386
|
const methodTypes = { enumerable: true, value: {}, writable: false };
|
|
@@ -18729,8 +20432,9 @@ ${indent}}` : "}";
|
|
|
18729
20432
|
attach(address, abi) {
|
|
18730
20433
|
this.address = address;
|
|
18731
20434
|
if (abi) {
|
|
18732
|
-
|
|
18733
|
-
this.
|
|
20435
|
+
const parser = createAbiParser(abi, this.parsingStrategy);
|
|
20436
|
+
this.abi = parser.getLegacyFormat();
|
|
20437
|
+
this.callData = new CallData(abi, this.parsingStrategy);
|
|
18734
20438
|
this.structs = CallData.getAbiStruct(abi);
|
|
18735
20439
|
this.events = getAbiEvents(abi);
|
|
18736
20440
|
}
|
|
@@ -18776,7 +20480,8 @@ ${indent}}` : "}";
|
|
|
18776
20480
|
return this.callData.parse(method, it);
|
|
18777
20481
|
});
|
|
18778
20482
|
}
|
|
18779
|
-
invoke(method, args = [],
|
|
20483
|
+
async invoke(method, args = [], options = {}) {
|
|
20484
|
+
const { parseRequest = true, signature, waitForTransaction, ...RestInvokeOptions } = options;
|
|
18780
20485
|
assert(this.address !== null, "contract is not connected to an address");
|
|
18781
20486
|
const calldata = getCompiledCalldata(args, () => {
|
|
18782
20487
|
if (parseRequest) {
|
|
@@ -18792,9 +20497,17 @@ ${indent}}` : "}";
|
|
|
18792
20497
|
entrypoint: method
|
|
18793
20498
|
};
|
|
18794
20499
|
if (isAccount(this.providerOrAccount)) {
|
|
18795
|
-
|
|
20500
|
+
const result = await this.providerOrAccount.execute(invocation, {
|
|
18796
20501
|
...RestInvokeOptions
|
|
18797
20502
|
});
|
|
20503
|
+
if (waitForTransaction) {
|
|
20504
|
+
const result2 = await this.providerOrAccount.waitForTransaction(result.transaction_hash);
|
|
20505
|
+
if (result2.isSuccess()) {
|
|
20506
|
+
return result2;
|
|
20507
|
+
}
|
|
20508
|
+
throw new Error("Transaction failed", { cause: result2 });
|
|
20509
|
+
}
|
|
20510
|
+
return result;
|
|
18798
20511
|
}
|
|
18799
20512
|
if (!RestInvokeOptions.nonce)
|
|
18800
20513
|
throw new Error(`Manual nonce is required when invoking a function without an account`);
|
|
@@ -18832,9 +20545,9 @@ ${indent}}` : "}";
|
|
|
18832
20545
|
// TODO: Demistify what is going on here ???
|
|
18833
20546
|
// TODO: receipt status filtering test and fix this do not look right
|
|
18834
20547
|
parseEvents(receipt) {
|
|
18835
|
-
let parsed;
|
|
20548
|
+
let parsed = [];
|
|
18836
20549
|
receipt.match({
|
|
18837
|
-
|
|
20550
|
+
SUCCEEDED: (txR) => {
|
|
18838
20551
|
const emittedEvents = txR.events?.map((event) => {
|
|
18839
20552
|
return {
|
|
18840
20553
|
// TODO: this do not check that block is production and block_hash and block_number actually exists
|
|
@@ -18847,16 +20560,26 @@ ${indent}}` : "}";
|
|
|
18847
20560
|
}).filter((event) => cleanHex(event.from_address) === cleanHex(this.address), []) || [];
|
|
18848
20561
|
parsed = parseEvents(
|
|
18849
20562
|
emittedEvents,
|
|
18850
|
-
// TODO: any temp hotfix, fix this
|
|
18851
20563
|
this.events,
|
|
18852
20564
|
this.structs,
|
|
18853
|
-
CallData.getAbiEnum(this.abi)
|
|
20565
|
+
CallData.getAbiEnum(this.abi),
|
|
20566
|
+
this.callData.parser
|
|
18854
20567
|
);
|
|
18855
20568
|
},
|
|
18856
20569
|
_: () => {
|
|
18857
20570
|
throw Error("This transaction was not successful.");
|
|
18858
20571
|
}
|
|
18859
20572
|
});
|
|
20573
|
+
Object.defineProperty(parsed, "getByPath", {
|
|
20574
|
+
value: (path) => {
|
|
20575
|
+
const event = parsed.find((ev) => Object.keys(ev).some((key) => key.includes(path)));
|
|
20576
|
+
const eventKey = Object.keys(event || {}).find((key) => key.includes(path));
|
|
20577
|
+
return eventKey && event ? event[eventKey] : null;
|
|
20578
|
+
},
|
|
20579
|
+
writable: false,
|
|
20580
|
+
enumerable: false,
|
|
20581
|
+
configurable: false
|
|
20582
|
+
});
|
|
18860
20583
|
return parsed;
|
|
18861
20584
|
}
|
|
18862
20585
|
isCairo1() {
|
|
@@ -18973,7 +20696,10 @@ ${indent}}` : "}";
|
|
|
18973
20696
|
abi,
|
|
18974
20697
|
address: contract_address,
|
|
18975
20698
|
providerOrAccount: account,
|
|
18976
|
-
classHash
|
|
20699
|
+
classHash,
|
|
20700
|
+
parseRequest: params.parseRequest,
|
|
20701
|
+
parseResponse: params.parseResponse,
|
|
20702
|
+
parsingStrategy: params.parsingStrategy
|
|
18977
20703
|
});
|
|
18978
20704
|
}
|
|
18979
20705
|
};
|