starknet 8.1.2 → 8.3.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 +818 -114
- package/dist/index.global.js +2137 -421
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2158 -421
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2137 -421
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,19 +31,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
AbiParser1: () => AbiParser1,
|
|
35
|
+
AbiParser2: () => AbiParser2,
|
|
36
|
+
AbiParserInterface: () => AbiParserInterface,
|
|
34
37
|
Account: () => Account,
|
|
35
38
|
AccountInterface: () => AccountInterface,
|
|
36
39
|
BatchClient: () => BatchClient,
|
|
37
40
|
BlockStatus: () => BlockStatus,
|
|
38
41
|
BlockTag: () => BlockTag,
|
|
42
|
+
CairoByteArray: () => CairoByteArray,
|
|
39
43
|
CairoCustomEnum: () => CairoCustomEnum,
|
|
40
44
|
CairoFixedArray: () => CairoFixedArray,
|
|
45
|
+
CairoInt128: () => CairoInt128,
|
|
46
|
+
CairoInt16: () => CairoInt16,
|
|
47
|
+
CairoInt32: () => CairoInt32,
|
|
48
|
+
CairoInt64: () => CairoInt64,
|
|
49
|
+
CairoInt8: () => CairoInt8,
|
|
41
50
|
CairoOption: () => CairoOption,
|
|
42
51
|
CairoOptionVariant: () => CairoOptionVariant,
|
|
43
52
|
CairoResult: () => CairoResult,
|
|
44
53
|
CairoResultVariant: () => CairoResultVariant,
|
|
54
|
+
CairoUint128: () => CairoUint128,
|
|
55
|
+
CairoUint16: () => CairoUint16,
|
|
45
56
|
CairoUint256: () => CairoUint256,
|
|
46
57
|
CairoUint512: () => CairoUint512,
|
|
58
|
+
CairoUint64: () => CairoUint64,
|
|
59
|
+
CairoUint8: () => CairoUint8,
|
|
60
|
+
CairoUint96: () => CairoUint96,
|
|
47
61
|
CallData: () => CallData,
|
|
48
62
|
Contract: () => Contract,
|
|
49
63
|
ContractInterface: () => ContractInterface,
|
|
@@ -59,6 +73,7 @@ __export(index_exports, {
|
|
|
59
73
|
ETransactionVersion3: () => ETransactionVersion3,
|
|
60
74
|
EntryPointType: () => EntryPointType,
|
|
61
75
|
EthSigner: () => EthSigner,
|
|
76
|
+
Int: () => Int,
|
|
62
77
|
LedgerSigner: () => LedgerSigner111,
|
|
63
78
|
LedgerSigner111: () => LedgerSigner111,
|
|
64
79
|
LedgerSigner221: () => LedgerSigner221,
|
|
@@ -112,6 +127,8 @@ __export(index_exports, {
|
|
|
112
127
|
config: () => config,
|
|
113
128
|
constants: () => constants_exports,
|
|
114
129
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
130
|
+
createAbiParser: () => createAbiParser,
|
|
131
|
+
createTransactionReceipt: () => createTransactionReceipt,
|
|
115
132
|
defaultDeployer: () => defaultDeployer,
|
|
116
133
|
defaultPaymaster: () => defaultPaymaster,
|
|
117
134
|
defaultProvider: () => defaultProvider,
|
|
@@ -120,6 +137,8 @@ __export(index_exports, {
|
|
|
120
137
|
eth: () => eth_exports,
|
|
121
138
|
events: () => events_exports,
|
|
122
139
|
extractContractHashes: () => extractContractHashes,
|
|
140
|
+
fastParsingStrategy: () => fastParsingStrategy,
|
|
141
|
+
getAbiVersion: () => getAbiVersion,
|
|
123
142
|
getChecksumAddress: () => getChecksumAddress,
|
|
124
143
|
getGasPrices: () => getGasPrices,
|
|
125
144
|
getLedgerPathBuffer: () => getLedgerPathBuffer111,
|
|
@@ -127,7 +146,9 @@ __export(index_exports, {
|
|
|
127
146
|
getLedgerPathBuffer221: () => getLedgerPathBuffer221,
|
|
128
147
|
getTipStatsFromBlocks: () => getTipStatsFromBlocks,
|
|
129
148
|
hash: () => hash_exports,
|
|
149
|
+
hdParsingStrategy: () => hdParsingStrategy,
|
|
130
150
|
isAccount: () => isAccount,
|
|
151
|
+
isNoConstructorValid: () => isNoConstructorValid,
|
|
131
152
|
isPendingBlock: () => isPendingBlock,
|
|
132
153
|
isPendingStateUpdate: () => isPendingStateUpdate,
|
|
133
154
|
isPendingTransaction: () => isPendingTransaction,
|
|
@@ -186,7 +207,16 @@ __export(constants_exports, {
|
|
|
186
207
|
PRIME: () => PRIME,
|
|
187
208
|
RANGE_FELT: () => RANGE_FELT,
|
|
188
209
|
RANGE_I128: () => RANGE_I128,
|
|
210
|
+
RANGE_I16: () => RANGE_I16,
|
|
211
|
+
RANGE_I32: () => RANGE_I32,
|
|
212
|
+
RANGE_I64: () => RANGE_I64,
|
|
213
|
+
RANGE_I8: () => RANGE_I8,
|
|
189
214
|
RANGE_U128: () => RANGE_U128,
|
|
215
|
+
RANGE_U16: () => RANGE_U16,
|
|
216
|
+
RANGE_U32: () => RANGE_U32,
|
|
217
|
+
RANGE_U64: () => RANGE_U64,
|
|
218
|
+
RANGE_U8: () => RANGE_U8,
|
|
219
|
+
RANGE_U96: () => RANGE_U96,
|
|
190
220
|
RPC_DEFAULT_NODES: () => RPC_DEFAULT_NODES,
|
|
191
221
|
SNIP9_V1_INTERFACE_ID: () => SNIP9_V1_INTERFACE_ID,
|
|
192
222
|
SNIP9_V2_INTERFACE_ID: () => SNIP9_V2_INTERFACE_ID,
|
|
@@ -230,16 +260,22 @@ __export(encode_exports, {
|
|
|
230
260
|
addHexPrefix: () => addHexPrefix,
|
|
231
261
|
arrayBufferToString: () => arrayBufferToString,
|
|
232
262
|
atobUniversal: () => atobUniversal,
|
|
263
|
+
bigIntToUint8Array: () => bigIntToUint8Array,
|
|
233
264
|
btoaUniversal: () => btoaUniversal,
|
|
234
265
|
buf2hex: () => buf2hex,
|
|
235
266
|
calcByteLength: () => calcByteLength,
|
|
236
267
|
concatenateArrayBuffer: () => concatenateArrayBuffer,
|
|
268
|
+
hexStringToUint8Array: () => hexStringToUint8Array,
|
|
237
269
|
padLeft: () => padLeft,
|
|
238
270
|
pascalToSnake: () => pascalToSnake,
|
|
239
271
|
removeHexPrefix: () => removeHexPrefix,
|
|
240
272
|
sanitizeBytes: () => sanitizeBytes,
|
|
241
273
|
sanitizeHex: () => sanitizeHex,
|
|
242
|
-
|
|
274
|
+
stringToUint8Array: () => stringToUint8Array,
|
|
275
|
+
uint8ArrayToBigInt: () => uint8ArrayToBigInt,
|
|
276
|
+
utf8ToArray: () => utf8ToArray,
|
|
277
|
+
utf8ToBigInt: () => utf8ToBigInt,
|
|
278
|
+
utf8ToUint8Array: () => utf8ToUint8Array
|
|
243
279
|
});
|
|
244
280
|
var import_base = require("@scure/base");
|
|
245
281
|
var IS_BROWSER = typeof window !== "undefined";
|
|
@@ -247,9 +283,13 @@ var STRING_ZERO = "0";
|
|
|
247
283
|
function arrayBufferToString(array) {
|
|
248
284
|
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
249
285
|
}
|
|
250
|
-
function
|
|
286
|
+
function utf8ToUint8Array(str) {
|
|
251
287
|
return new TextEncoder().encode(str);
|
|
252
288
|
}
|
|
289
|
+
var utf8ToArray = utf8ToUint8Array;
|
|
290
|
+
function utf8ToBigInt(str) {
|
|
291
|
+
return uint8ArrayToBigInt(utf8ToUint8Array(str));
|
|
292
|
+
}
|
|
253
293
|
function atobUniversal(a) {
|
|
254
294
|
return import_base.base64.decode(a);
|
|
255
295
|
}
|
|
@@ -301,6 +341,61 @@ function concatenateArrayBuffer(uint8arrays) {
|
|
|
301
341
|
});
|
|
302
342
|
return result;
|
|
303
343
|
}
|
|
344
|
+
function hexStringToUint8Array(hex) {
|
|
345
|
+
const cleanHex2 = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
346
|
+
if (cleanHex2.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanHex2)) {
|
|
347
|
+
throw new Error(`Invalid hex string: "${hex}" contains non-hexadecimal characters`);
|
|
348
|
+
}
|
|
349
|
+
const paddedHex = cleanHex2.length % 2 !== 0 ? `0${cleanHex2}` : cleanHex2;
|
|
350
|
+
const bytes = new Uint8Array(paddedHex.length / 2);
|
|
351
|
+
for (let i = 0; i < paddedHex.length; i += 2) {
|
|
352
|
+
bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
|
|
353
|
+
}
|
|
354
|
+
return bytes;
|
|
355
|
+
}
|
|
356
|
+
function isHexString(hex) {
|
|
357
|
+
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
358
|
+
}
|
|
359
|
+
function isDecimalString(str) {
|
|
360
|
+
return /^[0-9]+$/.test(str);
|
|
361
|
+
}
|
|
362
|
+
function stringToUint8Array(str) {
|
|
363
|
+
if (isHexString(str)) {
|
|
364
|
+
return hexStringToUint8Array(str);
|
|
365
|
+
}
|
|
366
|
+
if (isDecimalString(str)) {
|
|
367
|
+
const value = BigInt(str);
|
|
368
|
+
return bigIntToUint8Array(value);
|
|
369
|
+
}
|
|
370
|
+
return utf8ToUint8Array(str);
|
|
371
|
+
}
|
|
372
|
+
function bigIntToUint8Array(value) {
|
|
373
|
+
if (value < 0n) {
|
|
374
|
+
throw new Error(`Cannot convert negative bigint ${value} to Uint8Array`);
|
|
375
|
+
}
|
|
376
|
+
if (value === 0n) {
|
|
377
|
+
return new Uint8Array([0]);
|
|
378
|
+
}
|
|
379
|
+
let hex = value.toString(16);
|
|
380
|
+
if (hex.length % 2 !== 0) {
|
|
381
|
+
hex = `0${hex}`;
|
|
382
|
+
}
|
|
383
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
384
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
385
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
386
|
+
}
|
|
387
|
+
return bytes;
|
|
388
|
+
}
|
|
389
|
+
function uint8ArrayToBigInt(data) {
|
|
390
|
+
if (!data || data.length === 0) {
|
|
391
|
+
return 0n;
|
|
392
|
+
}
|
|
393
|
+
let hex = "0x";
|
|
394
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
395
|
+
hex += data[i].toString(16).padStart(2, "0");
|
|
396
|
+
}
|
|
397
|
+
return BigInt(hex);
|
|
398
|
+
}
|
|
304
399
|
|
|
305
400
|
// src/global/constants.ts
|
|
306
401
|
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
@@ -313,8 +408,17 @@ var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
|
313
408
|
var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
314
409
|
var range = (min, max) => ({ min, max });
|
|
315
410
|
var RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
316
|
-
var
|
|
411
|
+
var RANGE_U8 = range(ZERO, 2n ** 8n - 1n);
|
|
412
|
+
var RANGE_U16 = range(ZERO, 2n ** 16n - 1n);
|
|
413
|
+
var RANGE_U32 = range(ZERO, 2n ** 32n - 1n);
|
|
414
|
+
var RANGE_U64 = range(ZERO, 2n ** 64n - 1n);
|
|
415
|
+
var RANGE_U96 = range(ZERO, 2n ** 96n - 1n);
|
|
317
416
|
var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
417
|
+
var RANGE_I8 = range(-(2n ** 7n), 2n ** 7n - 1n);
|
|
418
|
+
var RANGE_I16 = range(-(2n ** 15n), 2n ** 15n - 1n);
|
|
419
|
+
var RANGE_I32 = range(-(2n ** 31n), 2n ** 31n - 1n);
|
|
420
|
+
var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
|
|
421
|
+
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
318
422
|
var LegacyUDC = {
|
|
319
423
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
320
424
|
ENTRYPOINT: "deployContract"
|
|
@@ -381,7 +485,8 @@ var DEFAULT_GLOBAL_CONFIG = {
|
|
|
381
485
|
},
|
|
382
486
|
defaultTipType: "recommendedTip",
|
|
383
487
|
fetch: void 0,
|
|
384
|
-
websocket: void 0
|
|
488
|
+
websocket: void 0,
|
|
489
|
+
buffer: void 0
|
|
385
490
|
};
|
|
386
491
|
var RPC_DEFAULT_NODES = {
|
|
387
492
|
SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
|
|
@@ -399,7 +504,10 @@ var SYSTEM_MESSAGES = {
|
|
|
399
504
|
unsupportedSpecVersion: "The connected node specification version is not supported by this library",
|
|
400
505
|
maxFeeInV3: "maxFee is not supported in V3 transactions, use resourceBounds instead",
|
|
401
506
|
declareNonSierra: "Declaring non Sierra (Cairo0)contract using RPC 0.8+",
|
|
402
|
-
unsupportedMethodForRpcVersion: "Unsupported method for RPC version"
|
|
507
|
+
unsupportedMethodForRpcVersion: "Unsupported method for RPC version",
|
|
508
|
+
txEvictedFromMempool: "Transaction TTL, evicted from the mempool, try to increase the tip",
|
|
509
|
+
consensusFailed: "Consensus failed to finalize the block proposal",
|
|
510
|
+
txFailsBlockBuildingValidation: "Transaction fails block building validation"
|
|
403
511
|
};
|
|
404
512
|
|
|
405
513
|
// src/global/config.ts
|
|
@@ -622,12 +730,20 @@ var Uint = {
|
|
|
622
730
|
u16: "core::integer::u16",
|
|
623
731
|
u32: "core::integer::u32",
|
|
624
732
|
u64: "core::integer::u64",
|
|
733
|
+
u96: "core::integer::u96",
|
|
625
734
|
u128: "core::integer::u128",
|
|
626
735
|
u256: "core::integer::u256",
|
|
627
736
|
// This one is struct
|
|
628
737
|
u512: "core::integer::u512"
|
|
629
738
|
// This one is struct
|
|
630
739
|
};
|
|
740
|
+
var Int = {
|
|
741
|
+
i8: "core::integer::i8",
|
|
742
|
+
i16: "core::integer::i16",
|
|
743
|
+
i32: "core::integer::i32",
|
|
744
|
+
i64: "core::integer::i64",
|
|
745
|
+
i128: "core::integer::i128"
|
|
746
|
+
};
|
|
631
747
|
var Literal = {
|
|
632
748
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
633
749
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
@@ -811,10 +927,12 @@ __export(num_exports, {
|
|
|
811
927
|
getDecimalString: () => getDecimalString,
|
|
812
928
|
getHexString: () => getHexString,
|
|
813
929
|
getHexStringArray: () => getHexStringArray,
|
|
930
|
+
getNext: () => getNext,
|
|
814
931
|
hexToBytes: () => hexToBytes,
|
|
815
932
|
hexToDecimalString: () => hexToDecimalString,
|
|
816
933
|
isBigNumberish: () => isBigNumberish,
|
|
817
934
|
isHex: () => isHex,
|
|
935
|
+
isHexString: () => isHexString2,
|
|
818
936
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
819
937
|
stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
|
|
820
938
|
toBigInt: () => toBigInt,
|
|
@@ -844,14 +962,21 @@ function isBigInt(value) {
|
|
|
844
962
|
function isString(value) {
|
|
845
963
|
return typeof value === "string";
|
|
846
964
|
}
|
|
965
|
+
function isBuffer(obj) {
|
|
966
|
+
return typeof Buffer !== "undefined" && obj instanceof Buffer;
|
|
967
|
+
}
|
|
847
968
|
function isObject(item) {
|
|
848
969
|
return !!item && typeof item === "object" && !Array.isArray(item);
|
|
849
970
|
}
|
|
971
|
+
function isInteger2(value) {
|
|
972
|
+
return Number.isInteger(value);
|
|
973
|
+
}
|
|
850
974
|
|
|
851
975
|
// src/utils/num.ts
|
|
852
976
|
function isHex(hex) {
|
|
853
977
|
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
854
978
|
}
|
|
979
|
+
var isHexString2 = isHex;
|
|
855
980
|
function toBigInt(value) {
|
|
856
981
|
return BigInt(value);
|
|
857
982
|
}
|
|
@@ -939,6 +1064,11 @@ function stringToSha256ToArrayBuff4(str) {
|
|
|
939
1064
|
function isBigNumberish(input) {
|
|
940
1065
|
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) || isStringWholeNumber(input));
|
|
941
1066
|
}
|
|
1067
|
+
function getNext(iterator) {
|
|
1068
|
+
const it = iterator.next();
|
|
1069
|
+
if (it.done) throw new Error("Unexpected end of response");
|
|
1070
|
+
return it.value;
|
|
1071
|
+
}
|
|
942
1072
|
|
|
943
1073
|
// src/utils/hash/selector.ts
|
|
944
1074
|
var selector_exports = {};
|
|
@@ -1004,7 +1134,7 @@ __export(shortString_exports, {
|
|
|
1004
1134
|
decodeShortString: () => decodeShortString,
|
|
1005
1135
|
encodeShortString: () => encodeShortString,
|
|
1006
1136
|
isASCII: () => isASCII,
|
|
1007
|
-
isDecimalString: () =>
|
|
1137
|
+
isDecimalString: () => isDecimalString2,
|
|
1008
1138
|
isLongText: () => isLongText,
|
|
1009
1139
|
isShortString: () => isShortString,
|
|
1010
1140
|
isShortText: () => isShortText,
|
|
@@ -1017,7 +1147,7 @@ function isASCII(str) {
|
|
|
1017
1147
|
function isShortString(str) {
|
|
1018
1148
|
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
1019
1149
|
}
|
|
1020
|
-
function
|
|
1150
|
+
function isDecimalString2(str) {
|
|
1021
1151
|
return /^[0-9]*$/i.test(str);
|
|
1022
1152
|
}
|
|
1023
1153
|
function isText(val) {
|
|
@@ -1039,7 +1169,7 @@ function decodeShortString(str) {
|
|
|
1039
1169
|
if (isHex(str)) {
|
|
1040
1170
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
1041
1171
|
}
|
|
1042
|
-
if (
|
|
1172
|
+
if (isDecimalString2(str)) {
|
|
1043
1173
|
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
1044
1174
|
}
|
|
1045
1175
|
throw new Error(`${str} is not Hex or decimal`);
|
|
@@ -1081,12 +1211,11 @@ __export(cairo_exports, {
|
|
|
1081
1211
|
isLen: () => isLen,
|
|
1082
1212
|
isTypeArray: () => isTypeArray,
|
|
1083
1213
|
isTypeBool: () => isTypeBool,
|
|
1084
|
-
isTypeByteArray: () => isTypeByteArray,
|
|
1085
|
-
isTypeBytes31: () => isTypeBytes31,
|
|
1086
1214
|
isTypeContractAddress: () => isTypeContractAddress,
|
|
1087
1215
|
isTypeEnum: () => isTypeEnum,
|
|
1088
1216
|
isTypeEthAddress: () => isTypeEthAddress,
|
|
1089
1217
|
isTypeFelt: () => isTypeFelt,
|
|
1218
|
+
isTypeInt: () => isTypeInt,
|
|
1090
1219
|
isTypeLiteral: () => isTypeLiteral,
|
|
1091
1220
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
1092
1221
|
isTypeNonZero: () => isTypeNonZero,
|
|
@@ -1103,6 +1232,16 @@ __export(cairo_exports, {
|
|
|
1103
1232
|
uint512: () => uint512
|
|
1104
1233
|
});
|
|
1105
1234
|
|
|
1235
|
+
// src/utils/helpers.ts
|
|
1236
|
+
function addCompiledFlag(compiled) {
|
|
1237
|
+
Object.defineProperty(compiled, "__compiled__", {
|
|
1238
|
+
enumerable: false,
|
|
1239
|
+
writable: false,
|
|
1240
|
+
value: true
|
|
1241
|
+
});
|
|
1242
|
+
return compiled;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1106
1245
|
// src/utils/cairoDataTypes/felt.ts
|
|
1107
1246
|
function CairoFelt(it) {
|
|
1108
1247
|
if (isBigInt(it) || Number.isInteger(it)) {
|
|
@@ -1129,6 +1268,69 @@ function CairoFelt(it) {
|
|
|
1129
1268
|
}
|
|
1130
1269
|
throw new Error(`${it} can't be computed by felt()`);
|
|
1131
1270
|
}
|
|
1271
|
+
var CairoFelt252 = class _CairoFelt252 {
|
|
1272
|
+
/**
|
|
1273
|
+
* byte representation of the felt252
|
|
1274
|
+
*/
|
|
1275
|
+
data;
|
|
1276
|
+
static abiSelector = "core::felt252";
|
|
1277
|
+
constructor(data) {
|
|
1278
|
+
_CairoFelt252.validate(data);
|
|
1279
|
+
this.data = _CairoFelt252.__processData(data);
|
|
1280
|
+
}
|
|
1281
|
+
static __processData(data) {
|
|
1282
|
+
if (isString(data)) {
|
|
1283
|
+
return stringToUint8Array(data);
|
|
1284
|
+
}
|
|
1285
|
+
if (isBigInt(data)) {
|
|
1286
|
+
return bigIntToUint8Array(data);
|
|
1287
|
+
}
|
|
1288
|
+
if (Number.isInteger(data)) {
|
|
1289
|
+
return bigIntToUint8Array(BigInt(data));
|
|
1290
|
+
}
|
|
1291
|
+
if (isBoolean(data)) {
|
|
1292
|
+
return bigIntToUint8Array(BigInt(data ? 1 : 0));
|
|
1293
|
+
}
|
|
1294
|
+
throw new Error(`${data} can't be computed by felt()`);
|
|
1295
|
+
}
|
|
1296
|
+
toBigInt() {
|
|
1297
|
+
return uint8ArrayToBigInt(this.data);
|
|
1298
|
+
}
|
|
1299
|
+
decodeUtf8() {
|
|
1300
|
+
return new TextDecoder().decode(this.data);
|
|
1301
|
+
}
|
|
1302
|
+
toHexString() {
|
|
1303
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
1304
|
+
}
|
|
1305
|
+
toApiRequest() {
|
|
1306
|
+
return addCompiledFlag([this.toHexString()]);
|
|
1307
|
+
}
|
|
1308
|
+
static validate(data) {
|
|
1309
|
+
assert(data !== null, "null value is not allowed for felt252");
|
|
1310
|
+
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
1311
|
+
assert(
|
|
1312
|
+
isString(data) || isNumber(data) || isBigInt(data) || isBoolean(data),
|
|
1313
|
+
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
1314
|
+
);
|
|
1315
|
+
const value = _CairoFelt252.__processData(data);
|
|
1316
|
+
const bn = uint8ArrayToBigInt(value);
|
|
1317
|
+
assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
|
|
1318
|
+
}
|
|
1319
|
+
static is(data) {
|
|
1320
|
+
try {
|
|
1321
|
+
_CairoFelt252.validate(data);
|
|
1322
|
+
return true;
|
|
1323
|
+
} catch {
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
static isAbiType(abiType) {
|
|
1328
|
+
return abiType === _CairoFelt252.abiSelector;
|
|
1329
|
+
}
|
|
1330
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1331
|
+
return new _CairoFelt252(getNext(responseIterator));
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1132
1334
|
|
|
1133
1335
|
// src/utils/cairoDataTypes/uint256.ts
|
|
1134
1336
|
var UINT_128_MAX = (1n << 128n) - 1n;
|
|
@@ -1140,11 +1342,16 @@ var UINT_256_LOW_MIN = 0n;
|
|
|
1140
1342
|
var UINT_256_HIGH_MIN = 0n;
|
|
1141
1343
|
var CairoUint256 = class _CairoUint256 {
|
|
1142
1344
|
low;
|
|
1345
|
+
// TODO should be u128
|
|
1143
1346
|
high;
|
|
1347
|
+
// TODO should be u128
|
|
1144
1348
|
static abiSelector = "core::integer::u256";
|
|
1145
1349
|
constructor(...arr) {
|
|
1146
1350
|
if (isObject(arr[0]) && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
|
|
1147
|
-
const props = _CairoUint256.validateProps(
|
|
1351
|
+
const props = _CairoUint256.validateProps(
|
|
1352
|
+
arr[0].low,
|
|
1353
|
+
arr[0].high
|
|
1354
|
+
);
|
|
1148
1355
|
this.low = props.low;
|
|
1149
1356
|
this.high = props.high;
|
|
1150
1357
|
} else if (arr.length === 1) {
|
|
@@ -1163,9 +1370,15 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1163
1370
|
* Validate if BigNumberish can be represented as Unit256
|
|
1164
1371
|
*/
|
|
1165
1372
|
static validate(bigNumberish) {
|
|
1373
|
+
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
1374
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
1375
|
+
assert(
|
|
1376
|
+
isBigNumberish(bigNumberish) || isObject(bigNumberish),
|
|
1377
|
+
`Unsupported data type '${typeof bigNumberish}' for u256. Expected string, number, bigint, or Uint256 object`
|
|
1378
|
+
);
|
|
1166
1379
|
const bigInt = BigInt(bigNumberish);
|
|
1167
|
-
|
|
1168
|
-
|
|
1380
|
+
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
1381
|
+
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
1169
1382
|
return bigInt;
|
|
1170
1383
|
}
|
|
1171
1384
|
/**
|
|
@@ -1174,12 +1387,14 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1174
1387
|
static validateProps(low, high) {
|
|
1175
1388
|
const bigIntLow = BigInt(low);
|
|
1176
1389
|
const bigIntHigh = BigInt(high);
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1390
|
+
assert(
|
|
1391
|
+
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
1392
|
+
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
1393
|
+
);
|
|
1394
|
+
assert(
|
|
1395
|
+
bigIntHigh >= UINT_256_HIGH_MIN && bigIntHigh <= UINT_256_HIGH_MAX,
|
|
1396
|
+
"high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX"
|
|
1397
|
+
);
|
|
1183
1398
|
return { low: bigIntLow, high: bigIntHigh };
|
|
1184
1399
|
}
|
|
1185
1400
|
/**
|
|
@@ -1199,6 +1414,11 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1199
1414
|
static isAbiType(abiType) {
|
|
1200
1415
|
return abiType === _CairoUint256.abiSelector;
|
|
1201
1416
|
}
|
|
1417
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1418
|
+
const low = getNext(responseIterator);
|
|
1419
|
+
const high = getNext(responseIterator);
|
|
1420
|
+
return new _CairoUint256(low, high);
|
|
1421
|
+
}
|
|
1202
1422
|
/**
|
|
1203
1423
|
* Return bigint representation
|
|
1204
1424
|
*/
|
|
@@ -1239,9 +1459,13 @@ var UINT_512_MIN = 0n;
|
|
|
1239
1459
|
var UINT_128_MIN = 0n;
|
|
1240
1460
|
var CairoUint512 = class _CairoUint512 {
|
|
1241
1461
|
limb0;
|
|
1462
|
+
// TODO should be u128
|
|
1242
1463
|
limb1;
|
|
1464
|
+
// TODO should be u128
|
|
1243
1465
|
limb2;
|
|
1466
|
+
// TODO should be u128
|
|
1244
1467
|
limb3;
|
|
1468
|
+
// TODO should be u128
|
|
1245
1469
|
static abiSelector = "core::integer::u512";
|
|
1246
1470
|
constructor(...arr) {
|
|
1247
1471
|
if (isObject(arr[0]) && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
@@ -1275,9 +1499,15 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1275
1499
|
* Validate if BigNumberish can be represented as Uint512
|
|
1276
1500
|
*/
|
|
1277
1501
|
static validate(bigNumberish) {
|
|
1502
|
+
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
1503
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
1504
|
+
assert(
|
|
1505
|
+
isBigNumberish(bigNumberish) || isObject(bigNumberish),
|
|
1506
|
+
`Unsupported data type '${typeof bigNumberish}' for u512. Expected string, number, bigint, or Uint512 object`
|
|
1507
|
+
);
|
|
1278
1508
|
const bigInt = BigInt(bigNumberish);
|
|
1279
|
-
|
|
1280
|
-
|
|
1509
|
+
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
1510
|
+
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
1281
1511
|
return bigInt;
|
|
1282
1512
|
}
|
|
1283
1513
|
/**
|
|
@@ -1289,9 +1519,10 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1289
1519
|
const l2 = BigInt(limb2);
|
|
1290
1520
|
const l3 = BigInt(limb3);
|
|
1291
1521
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1522
|
+
assert(
|
|
1523
|
+
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
1524
|
+
`limb${index} is not in the range of a u128 number`
|
|
1525
|
+
);
|
|
1295
1526
|
});
|
|
1296
1527
|
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
1297
1528
|
}
|
|
@@ -1312,6 +1543,13 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1312
1543
|
static isAbiType(abiType) {
|
|
1313
1544
|
return abiType === _CairoUint512.abiSelector;
|
|
1314
1545
|
}
|
|
1546
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1547
|
+
const limb0 = getNext(responseIterator);
|
|
1548
|
+
const limb1 = getNext(responseIterator);
|
|
1549
|
+
const limb2 = getNext(responseIterator);
|
|
1550
|
+
const limb3 = getNext(responseIterator);
|
|
1551
|
+
return new _CairoUint512(limb0, limb1, limb2, limb3);
|
|
1552
|
+
}
|
|
1315
1553
|
/**
|
|
1316
1554
|
* Return bigint representation
|
|
1317
1555
|
*/
|
|
@@ -1366,13 +1604,12 @@ var isTypeEnum = (type, enums) => type in enums;
|
|
|
1366
1604
|
var isTypeOption = (type) => type.startsWith("core::option::Option::");
|
|
1367
1605
|
var isTypeResult = (type) => type.startsWith("core::result::Result::");
|
|
1368
1606
|
var isTypeUint = (type) => Object.values(Uint).includes(type);
|
|
1607
|
+
var isTypeInt = (type) => Object.values(Int).includes(type);
|
|
1369
1608
|
var isTypeUint256 = (type) => CairoUint256.isAbiType(type);
|
|
1370
1609
|
var isTypeLiteral = (type) => Object.values(Literal).includes(type);
|
|
1371
1610
|
var isTypeBool = (type) => type === "core::bool";
|
|
1372
1611
|
var isTypeContractAddress = (type) => type === Literal.ContractAddress;
|
|
1373
1612
|
var isTypeEthAddress = (type) => type === ETH_ADDRESS;
|
|
1374
|
-
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
1375
|
-
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
1376
1613
|
var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>";
|
|
1377
1614
|
var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
|
|
1378
1615
|
var isCairo1Type = (type) => type.includes("::");
|
|
@@ -1631,11 +1868,1344 @@ function formatter(data, type, sameType) {
|
|
|
1631
1868
|
);
|
|
1632
1869
|
}
|
|
1633
1870
|
|
|
1634
|
-
// src/utils/calldata/parser/
|
|
1635
|
-
var
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1871
|
+
// src/utils/calldata/parser/interface.ts
|
|
1872
|
+
var AbiParserInterface = class {
|
|
1873
|
+
};
|
|
1874
|
+
|
|
1875
|
+
// src/utils/cairoDataTypes/bytes31.ts
|
|
1876
|
+
var CairoBytes31 = class _CairoBytes31 {
|
|
1877
|
+
static MAX_BYTE_SIZE = 31;
|
|
1878
|
+
data;
|
|
1879
|
+
static abiSelector = "core::bytes_31::bytes31";
|
|
1880
|
+
constructor(data) {
|
|
1881
|
+
_CairoBytes31.validate(data);
|
|
1882
|
+
this.data = _CairoBytes31.__processData(data);
|
|
1883
|
+
}
|
|
1884
|
+
static __processData(data) {
|
|
1885
|
+
if (isString(data)) {
|
|
1886
|
+
return stringToUint8Array(data);
|
|
1887
|
+
}
|
|
1888
|
+
if (isBuffer(data)) {
|
|
1889
|
+
return new Uint8Array(data);
|
|
1890
|
+
}
|
|
1891
|
+
if (data instanceof Uint8Array) {
|
|
1892
|
+
return new Uint8Array(data);
|
|
1893
|
+
}
|
|
1894
|
+
throw new Error("Invalid input type for CairoBytes31. Expected string, Buffer, or Uint8Array");
|
|
1895
|
+
}
|
|
1896
|
+
toApiRequest() {
|
|
1897
|
+
return addCompiledFlag([this.toHexString()]);
|
|
1898
|
+
}
|
|
1899
|
+
toBigInt() {
|
|
1900
|
+
return uint8ArrayToBigInt(this.data);
|
|
1901
|
+
}
|
|
1902
|
+
decodeUtf8() {
|
|
1903
|
+
return new TextDecoder().decode(this.data);
|
|
1904
|
+
}
|
|
1905
|
+
toHexString() {
|
|
1906
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
1907
|
+
}
|
|
1908
|
+
static validate(data) {
|
|
1909
|
+
const byteLength = _CairoBytes31.__processData(data).length;
|
|
1910
|
+
assert(
|
|
1911
|
+
byteLength <= this.MAX_BYTE_SIZE,
|
|
1912
|
+
`Data is too long: ${byteLength} bytes (max ${this.MAX_BYTE_SIZE} bytes)`
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
static is(data) {
|
|
1916
|
+
try {
|
|
1917
|
+
_CairoBytes31.validate(data);
|
|
1918
|
+
return true;
|
|
1919
|
+
} catch {
|
|
1920
|
+
return false;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Check if provided abi type is this data type
|
|
1925
|
+
*/
|
|
1926
|
+
static isAbiType(abiType) {
|
|
1927
|
+
return abiType === _CairoBytes31.abiSelector;
|
|
1928
|
+
}
|
|
1929
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1930
|
+
return new _CairoBytes31(getNext(responseIterator));
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
// src/utils/errors/rpc.ts
|
|
1935
|
+
var errorCodes = {
|
|
1936
|
+
FAILED_TO_RECEIVE_TXN: 1,
|
|
1937
|
+
NO_TRACE_AVAILABLE: 10,
|
|
1938
|
+
CONTRACT_NOT_FOUND: 20,
|
|
1939
|
+
ENTRYPOINT_NOT_FOUND: 21,
|
|
1940
|
+
BLOCK_NOT_FOUND: 24,
|
|
1941
|
+
INVALID_TXN_INDEX: 27,
|
|
1942
|
+
CLASS_HASH_NOT_FOUND: 28,
|
|
1943
|
+
TXN_HASH_NOT_FOUND: 29,
|
|
1944
|
+
PAGE_SIZE_TOO_BIG: 31,
|
|
1945
|
+
NO_BLOCKS: 32,
|
|
1946
|
+
INVALID_CONTINUATION_TOKEN: 33,
|
|
1947
|
+
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
1948
|
+
CONTRACT_ERROR: 40,
|
|
1949
|
+
TRANSACTION_EXECUTION_ERROR: 41,
|
|
1950
|
+
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
1951
|
+
CLASS_ALREADY_DECLARED: 51,
|
|
1952
|
+
INVALID_TRANSACTION_NONCE: 52,
|
|
1953
|
+
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
1954
|
+
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
1955
|
+
VALIDATION_FAILURE: 55,
|
|
1956
|
+
COMPILATION_FAILED: 56,
|
|
1957
|
+
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
1958
|
+
NON_ACCOUNT: 58,
|
|
1959
|
+
DUPLICATE_TX: 59,
|
|
1960
|
+
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
1961
|
+
UNSUPPORTED_TX_VERSION: 61,
|
|
1962
|
+
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
1963
|
+
UNEXPECTED_ERROR: 63,
|
|
1964
|
+
INVALID_SUBSCRIPTION_ID: 66,
|
|
1965
|
+
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
1966
|
+
TOO_MANY_BLOCKS_BACK: 68,
|
|
1967
|
+
COMPILATION_ERROR: 100,
|
|
1968
|
+
INVALID_ADDRESS: 150,
|
|
1969
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
1970
|
+
INVALID_SIGNATURE: 153,
|
|
1971
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
1972
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
1973
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
1974
|
+
INVALID_TIME_BOUNDS: 157,
|
|
1975
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
1976
|
+
INVALID_CLASS_HASH: 159,
|
|
1977
|
+
INVALID_ID: 160,
|
|
1978
|
+
UNKNOWN_ERROR: 163
|
|
1979
|
+
};
|
|
1980
|
+
var rpc_default = errorCodes;
|
|
1981
|
+
|
|
1982
|
+
// src/utils/errors/index.ts
|
|
1983
|
+
function fixStack(target, fn = target.constructor) {
|
|
1984
|
+
const { captureStackTrace } = Error;
|
|
1985
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
1986
|
+
}
|
|
1987
|
+
function fixProto(target, prototype) {
|
|
1988
|
+
const { setPrototypeOf } = Object;
|
|
1989
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
1990
|
+
}
|
|
1991
|
+
var CustomError = class extends Error {
|
|
1992
|
+
name;
|
|
1993
|
+
constructor(message) {
|
|
1994
|
+
super(message);
|
|
1995
|
+
Object.defineProperty(this, "name", {
|
|
1996
|
+
value: new.target.name,
|
|
1997
|
+
enumerable: false,
|
|
1998
|
+
configurable: true
|
|
1999
|
+
});
|
|
2000
|
+
fixProto(this, new.target.prototype);
|
|
2001
|
+
fixStack(this);
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
var LibraryError = class extends CustomError {
|
|
2005
|
+
};
|
|
2006
|
+
var RpcError = class extends LibraryError {
|
|
2007
|
+
constructor(baseError, method, params) {
|
|
2008
|
+
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
2009
|
+
|
|
2010
|
+
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
2011
|
+
this.baseError = baseError;
|
|
2012
|
+
this.request = { method, params };
|
|
2013
|
+
}
|
|
2014
|
+
request;
|
|
2015
|
+
get code() {
|
|
2016
|
+
return this.baseError.code;
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
2020
|
+
* @example
|
|
2021
|
+
* ```typescript
|
|
2022
|
+
* SomeError.isType('UNEXPECTED_ERROR');
|
|
2023
|
+
* ```
|
|
2024
|
+
*/
|
|
2025
|
+
isType(typeName) {
|
|
2026
|
+
return rpc_default[typeName] === this.code;
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
var TimeoutError = class extends LibraryError {
|
|
2030
|
+
constructor(message) {
|
|
2031
|
+
super(message);
|
|
2032
|
+
this.name = "TimeoutError";
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
var WebSocketNotConnectedError = class extends LibraryError {
|
|
2036
|
+
constructor(message) {
|
|
2037
|
+
super(message);
|
|
2038
|
+
this.name = "WebSocketNotConnectedError";
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
|
|
2042
|
+
// src/utils/connect/buffer.ts
|
|
2043
|
+
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 {
|
|
2044
|
+
constructor() {
|
|
2045
|
+
throw new LibraryError(
|
|
2046
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
static from(_data) {
|
|
2050
|
+
throw new LibraryError(
|
|
2051
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
2052
|
+
);
|
|
2053
|
+
}
|
|
2054
|
+
static isBuffer(obj) {
|
|
2055
|
+
const BufferImpl = config.get("buffer") || typeof Buffer !== "undefined" && Buffer;
|
|
2056
|
+
return BufferImpl && BufferImpl.isBuffer && BufferImpl.isBuffer(obj);
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
|
|
2060
|
+
// src/utils/cairoDataTypes/uint32.ts
|
|
2061
|
+
var CairoUint32 = class _CairoUint32 {
|
|
2062
|
+
data;
|
|
2063
|
+
static abiSelector = "core::u32::u32";
|
|
2064
|
+
constructor(data) {
|
|
2065
|
+
_CairoUint32.validate(data);
|
|
2066
|
+
this.data = _CairoUint32.__processData(data);
|
|
2067
|
+
}
|
|
2068
|
+
static __processData(data) {
|
|
2069
|
+
if (isString(data) && isText(data)) {
|
|
2070
|
+
return utf8ToBigInt(data);
|
|
2071
|
+
}
|
|
2072
|
+
return BigInt(data);
|
|
2073
|
+
}
|
|
2074
|
+
toApiRequest() {
|
|
2075
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2076
|
+
}
|
|
2077
|
+
toBigInt() {
|
|
2078
|
+
return this.data;
|
|
2079
|
+
}
|
|
2080
|
+
decodeUtf8() {
|
|
2081
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2082
|
+
}
|
|
2083
|
+
toHexString() {
|
|
2084
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2085
|
+
}
|
|
2086
|
+
static validate(data) {
|
|
2087
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2088
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2089
|
+
assert(
|
|
2090
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2091
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2092
|
+
);
|
|
2093
|
+
const value = _CairoUint32.__processData(data);
|
|
2094
|
+
assert(value >= 0n && value <= 2n ** 32n - 1n, "Value is out of u32 range [0, 2^32)");
|
|
2095
|
+
}
|
|
2096
|
+
static is(data) {
|
|
2097
|
+
try {
|
|
2098
|
+
_CairoUint32.validate(data);
|
|
2099
|
+
return true;
|
|
2100
|
+
} catch {
|
|
2101
|
+
return false;
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Check if provided abi type is this data type
|
|
2106
|
+
*/
|
|
2107
|
+
static isAbiType(abiType) {
|
|
2108
|
+
return abiType === _CairoUint32.abiSelector;
|
|
2109
|
+
}
|
|
2110
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2111
|
+
return new _CairoUint32(getNext(responseIterator));
|
|
2112
|
+
}
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
// src/utils/cairoDataTypes/byteArray.ts
|
|
2116
|
+
var CairoByteArray = class _CairoByteArray {
|
|
2117
|
+
/**
|
|
2118
|
+
* entire dataset
|
|
2119
|
+
*/
|
|
2120
|
+
data = [];
|
|
2121
|
+
/**
|
|
2122
|
+
* cairo specific implementation helper
|
|
2123
|
+
*/
|
|
2124
|
+
pending_word;
|
|
2125
|
+
// felt
|
|
2126
|
+
/**
|
|
2127
|
+
* cairo specific implementation helper
|
|
2128
|
+
*/
|
|
2129
|
+
pending_word_len;
|
|
2130
|
+
// u32
|
|
2131
|
+
static abiSelector = "core::byte_array::ByteArray";
|
|
2132
|
+
constructor(...arr) {
|
|
2133
|
+
if (arr.length === 3) {
|
|
2134
|
+
const [dataArg, pendingWord, pendingWordLen] = arr;
|
|
2135
|
+
assert(
|
|
2136
|
+
Array.isArray(dataArg) && pendingWord instanceof CairoFelt252 && pendingWordLen instanceof CairoUint32,
|
|
2137
|
+
"Invalid constructor parameters. Expected (CairoBytes31[], CairoFelt252, CairoUint32)"
|
|
2138
|
+
);
|
|
2139
|
+
this.data = dataArg;
|
|
2140
|
+
this.pending_word = pendingWord;
|
|
2141
|
+
this.pending_word_len = pendingWordLen;
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
const inData = arr[0];
|
|
2145
|
+
_CairoByteArray.validate(inData);
|
|
2146
|
+
const { data, pending_word, pending_word_len } = _CairoByteArray.__processData(inData);
|
|
2147
|
+
this.data = data;
|
|
2148
|
+
this.pending_word = pending_word;
|
|
2149
|
+
this.pending_word_len = pending_word_len;
|
|
2150
|
+
}
|
|
2151
|
+
static __processData(inData) {
|
|
2152
|
+
let fullData;
|
|
2153
|
+
if (inData instanceof Uint8Array) {
|
|
2154
|
+
fullData = inData;
|
|
2155
|
+
} else if (isBuffer(inData)) {
|
|
2156
|
+
fullData = new Uint8Array(inData);
|
|
2157
|
+
} else if (isString(inData)) {
|
|
2158
|
+
fullData = stringToUint8Array(inData);
|
|
2159
|
+
} else if (isBigInt(inData)) {
|
|
2160
|
+
fullData = bigIntToUint8Array(inData);
|
|
2161
|
+
} else if (isInteger2(inData)) {
|
|
2162
|
+
fullData = bigIntToUint8Array(BigInt(inData));
|
|
2163
|
+
} else {
|
|
2164
|
+
throw new Error("Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint");
|
|
2165
|
+
}
|
|
2166
|
+
const CHUNK_SIZE = CairoBytes31.MAX_BYTE_SIZE;
|
|
2167
|
+
const completeChunks = Math.floor(fullData.length / CHUNK_SIZE);
|
|
2168
|
+
const remainderLength = fullData.length % CHUNK_SIZE;
|
|
2169
|
+
const data = [];
|
|
2170
|
+
let pending_word;
|
|
2171
|
+
let pending_word_len;
|
|
2172
|
+
for (let i = 0; i < completeChunks; i += 1) {
|
|
2173
|
+
const chunkStart = i * CHUNK_SIZE;
|
|
2174
|
+
const chunkEnd = chunkStart + CHUNK_SIZE;
|
|
2175
|
+
const chunk = fullData.slice(chunkStart, chunkEnd);
|
|
2176
|
+
data.push(new CairoBytes31(chunk));
|
|
2177
|
+
}
|
|
2178
|
+
if (remainderLength > 0) {
|
|
2179
|
+
const remainder = fullData.slice(completeChunks * CHUNK_SIZE);
|
|
2180
|
+
let hex = "0x";
|
|
2181
|
+
for (let i = 0; i < remainder.length; i += 1) {
|
|
2182
|
+
hex += remainder[i].toString(16).padStart(2, "0");
|
|
2183
|
+
}
|
|
2184
|
+
pending_word = new CairoFelt252(hex);
|
|
2185
|
+
pending_word_len = new CairoUint32(remainderLength);
|
|
2186
|
+
} else {
|
|
2187
|
+
pending_word = new CairoFelt252(0);
|
|
2188
|
+
pending_word_len = new CairoUint32(0);
|
|
2189
|
+
}
|
|
2190
|
+
return { data, pending_word, pending_word_len };
|
|
2191
|
+
}
|
|
2192
|
+
toApiRequest() {
|
|
2193
|
+
this.assertInitialized();
|
|
2194
|
+
return addCompiledFlag([
|
|
2195
|
+
addHexPrefix(this.data.length.toString(16)),
|
|
2196
|
+
...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
|
|
2197
|
+
...this.pending_word.toApiRequest(),
|
|
2198
|
+
...this.pending_word_len.toApiRequest()
|
|
2199
|
+
]);
|
|
2200
|
+
}
|
|
2201
|
+
decodeUtf8() {
|
|
2202
|
+
const allBytes = this.reconstructBytes();
|
|
2203
|
+
const fullBytes = new Uint8Array(allBytes);
|
|
2204
|
+
return new TextDecoder().decode(fullBytes);
|
|
2205
|
+
}
|
|
2206
|
+
toBigInt() {
|
|
2207
|
+
const allBytes = this.reconstructBytes();
|
|
2208
|
+
if (allBytes.length === 0) {
|
|
2209
|
+
return 0n;
|
|
2210
|
+
}
|
|
2211
|
+
let result = 0n;
|
|
2212
|
+
allBytes.forEach((byte) => {
|
|
2213
|
+
result = result * 256n + BigInt(byte);
|
|
2214
|
+
});
|
|
2215
|
+
return result;
|
|
2216
|
+
}
|
|
2217
|
+
toHexString() {
|
|
2218
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2219
|
+
}
|
|
2220
|
+
toBuffer() {
|
|
2221
|
+
this.assertInitialized();
|
|
2222
|
+
const allBytes = [];
|
|
2223
|
+
this.data.forEach((chunk) => {
|
|
2224
|
+
const chunkBytes = chunk.data;
|
|
2225
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
2226
|
+
allBytes.push(chunkBytes[i]);
|
|
2227
|
+
}
|
|
2228
|
+
});
|
|
2229
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2230
|
+
if (pendingLen > 0) {
|
|
2231
|
+
const hex = this.pending_word.toHexString();
|
|
2232
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
2233
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2234
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
2235
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
2236
|
+
if (byteHex.length >= 2) {
|
|
2237
|
+
const byteValue = parseInt(byteHex, 16);
|
|
2238
|
+
if (!Number.isNaN(byteValue)) {
|
|
2239
|
+
allBytes.push(byteValue);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return buffer_default.from(allBytes);
|
|
2245
|
+
}
|
|
2246
|
+
static validate(data) {
|
|
2247
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2248
|
+
assert(
|
|
2249
|
+
!Array.isArray(data) || data instanceof Uint8Array,
|
|
2250
|
+
"Invalid input: arrays are not supported, use Uint8Array"
|
|
2251
|
+
);
|
|
2252
|
+
assert(
|
|
2253
|
+
typeof data !== "object" || isBuffer(data) || data instanceof Uint8Array,
|
|
2254
|
+
"Invalid input for CairoByteArray: objects are not supported"
|
|
2255
|
+
);
|
|
2256
|
+
assert(
|
|
2257
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2258
|
+
"Invalid input for CairoByteArray: decimal numbers are not supported, only integers"
|
|
2259
|
+
);
|
|
2260
|
+
assert(
|
|
2261
|
+
!isNumber(data) || data >= 0,
|
|
2262
|
+
"Invalid input for CairoByteArray: negative numbers are not supported"
|
|
2263
|
+
);
|
|
2264
|
+
assert(
|
|
2265
|
+
!isBigInt(data) || data >= 0n,
|
|
2266
|
+
"Invalid input for CairoByteArray: negative bigints are not supported"
|
|
2267
|
+
);
|
|
2268
|
+
assert(
|
|
2269
|
+
data instanceof Uint8Array || isBuffer(data) || isString(data) || isNumber(data) || isBigInt(data),
|
|
2270
|
+
"Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint"
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Check if the provided data is a valid CairoByteArray
|
|
2275
|
+
*
|
|
2276
|
+
* @param data - The data to check
|
|
2277
|
+
* @returns True if the data is a valid CairoByteArray, false otherwise
|
|
2278
|
+
*/
|
|
2279
|
+
static is(data) {
|
|
2280
|
+
try {
|
|
2281
|
+
_CairoByteArray.validate(data);
|
|
2282
|
+
return true;
|
|
2283
|
+
} catch {
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Check if provided abi type is this data type
|
|
2289
|
+
*/
|
|
2290
|
+
static isAbiType(abiType) {
|
|
2291
|
+
return abiType === _CairoByteArray.abiSelector;
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Private helper to check if the CairoByteArray is properly initialized
|
|
2295
|
+
*/
|
|
2296
|
+
assertInitialized() {
|
|
2297
|
+
assert(
|
|
2298
|
+
this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
|
|
2299
|
+
"CairoByteArray is not properly initialized"
|
|
2300
|
+
);
|
|
2301
|
+
}
|
|
2302
|
+
/**
|
|
2303
|
+
* Private helper to reconstruct the full byte sequence from chunks and pending word
|
|
2304
|
+
*/
|
|
2305
|
+
reconstructBytes() {
|
|
2306
|
+
this.assertInitialized();
|
|
2307
|
+
const allBytes = [];
|
|
2308
|
+
this.data.forEach((chunk) => {
|
|
2309
|
+
const chunkBytes = chunk.data;
|
|
2310
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
2311
|
+
allBytes.push(chunkBytes[i]);
|
|
2312
|
+
}
|
|
2313
|
+
});
|
|
2314
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2315
|
+
if (pendingLen > 0) {
|
|
2316
|
+
const hex = this.pending_word.toHexString();
|
|
2317
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
2318
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2319
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
2320
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
2321
|
+
if (byteHex.length < 2) {
|
|
2322
|
+
allBytes.push(0);
|
|
2323
|
+
} else {
|
|
2324
|
+
const byteValue = parseInt(byteHex, 16);
|
|
2325
|
+
if (Number.isNaN(byteValue)) {
|
|
2326
|
+
throw new Error(`Invalid hex byte: ${byteHex}`);
|
|
2327
|
+
}
|
|
2328
|
+
allBytes.push(byteValue);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
return allBytes;
|
|
2333
|
+
}
|
|
2334
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2335
|
+
const data = Array.from(
|
|
2336
|
+
{ length: Number(getNext(responseIterator)) },
|
|
2337
|
+
() => CairoBytes31.factoryFromApiResponse(responseIterator)
|
|
2338
|
+
);
|
|
2339
|
+
const pending_word = CairoFelt252.factoryFromApiResponse(responseIterator);
|
|
2340
|
+
const pending_word_len = CairoUint32.factoryFromApiResponse(responseIterator);
|
|
2341
|
+
return new _CairoByteArray(data, pending_word, pending_word_len);
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
|
|
2345
|
+
// src/utils/cairoDataTypes/uint8.ts
|
|
2346
|
+
var CairoUint8 = class _CairoUint8 {
|
|
2347
|
+
data;
|
|
2348
|
+
static abiSelector = "core::integer::u8";
|
|
2349
|
+
constructor(data) {
|
|
2350
|
+
_CairoUint8.validate(data);
|
|
2351
|
+
this.data = _CairoUint8.__processData(data);
|
|
2352
|
+
}
|
|
2353
|
+
static __processData(data) {
|
|
2354
|
+
if (isString(data) && isText(data)) {
|
|
2355
|
+
return utf8ToBigInt(data);
|
|
2356
|
+
}
|
|
2357
|
+
return BigInt(data);
|
|
2358
|
+
}
|
|
2359
|
+
toApiRequest() {
|
|
2360
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2361
|
+
}
|
|
2362
|
+
toBigInt() {
|
|
2363
|
+
return this.data;
|
|
2364
|
+
}
|
|
2365
|
+
decodeUtf8() {
|
|
2366
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2367
|
+
}
|
|
2368
|
+
toHexString() {
|
|
2369
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2370
|
+
}
|
|
2371
|
+
static validate(data) {
|
|
2372
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2373
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2374
|
+
assert(
|
|
2375
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2376
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2377
|
+
);
|
|
2378
|
+
const value = _CairoUint8.__processData(data);
|
|
2379
|
+
assert(
|
|
2380
|
+
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
2381
|
+
`Value is out of u8 range [${RANGE_U8.min}, ${RANGE_U8.max}]`
|
|
2382
|
+
);
|
|
2383
|
+
}
|
|
2384
|
+
static is(data) {
|
|
2385
|
+
try {
|
|
2386
|
+
_CairoUint8.validate(data);
|
|
2387
|
+
return true;
|
|
2388
|
+
} catch {
|
|
2389
|
+
return false;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Check if provided abi type is this data type
|
|
2394
|
+
*/
|
|
2395
|
+
static isAbiType(abiType) {
|
|
2396
|
+
return abiType === _CairoUint8.abiSelector;
|
|
2397
|
+
}
|
|
2398
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2399
|
+
return new _CairoUint8(getNext(responseIterator));
|
|
2400
|
+
}
|
|
2401
|
+
};
|
|
2402
|
+
|
|
2403
|
+
// src/utils/cairoDataTypes/uint16.ts
|
|
2404
|
+
var CairoUint16 = class _CairoUint16 {
|
|
2405
|
+
data;
|
|
2406
|
+
static abiSelector = "core::integer::u16";
|
|
2407
|
+
constructor(data) {
|
|
2408
|
+
_CairoUint16.validate(data);
|
|
2409
|
+
this.data = _CairoUint16.__processData(data);
|
|
2410
|
+
}
|
|
2411
|
+
static __processData(data) {
|
|
2412
|
+
if (isString(data) && isText(data)) {
|
|
2413
|
+
return utf8ToBigInt(data);
|
|
2414
|
+
}
|
|
2415
|
+
return BigInt(data);
|
|
2416
|
+
}
|
|
2417
|
+
toApiRequest() {
|
|
2418
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2419
|
+
}
|
|
2420
|
+
toBigInt() {
|
|
2421
|
+
return this.data;
|
|
2422
|
+
}
|
|
2423
|
+
decodeUtf8() {
|
|
2424
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2425
|
+
}
|
|
2426
|
+
toHexString() {
|
|
2427
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2428
|
+
}
|
|
2429
|
+
static validate(data) {
|
|
2430
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2431
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2432
|
+
assert(
|
|
2433
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2434
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2435
|
+
);
|
|
2436
|
+
const value = _CairoUint16.__processData(data);
|
|
2437
|
+
assert(
|
|
2438
|
+
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
2439
|
+
`Value is out of u16 range [${RANGE_U16.min}, ${RANGE_U16.max}]`
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
static is(data) {
|
|
2443
|
+
try {
|
|
2444
|
+
_CairoUint16.validate(data);
|
|
2445
|
+
return true;
|
|
2446
|
+
} catch {
|
|
2447
|
+
return false;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
/**
|
|
2451
|
+
* Check if provided abi type is this data type
|
|
2452
|
+
*/
|
|
2453
|
+
static isAbiType(abiType) {
|
|
2454
|
+
return abiType === _CairoUint16.abiSelector;
|
|
2455
|
+
}
|
|
2456
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2457
|
+
return new _CairoUint16(getNext(responseIterator));
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
|
|
2461
|
+
// src/utils/cairoDataTypes/uint64.ts
|
|
2462
|
+
var CairoUint64 = class _CairoUint64 {
|
|
2463
|
+
data;
|
|
2464
|
+
static abiSelector = "core::integer::u64";
|
|
2465
|
+
constructor(data) {
|
|
2466
|
+
_CairoUint64.validate(data);
|
|
2467
|
+
this.data = _CairoUint64.__processData(data);
|
|
2468
|
+
}
|
|
2469
|
+
static __processData(data) {
|
|
2470
|
+
if (isString(data) && isText(data)) {
|
|
2471
|
+
return utf8ToBigInt(data);
|
|
2472
|
+
}
|
|
2473
|
+
return BigInt(data);
|
|
2474
|
+
}
|
|
2475
|
+
toApiRequest() {
|
|
2476
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2477
|
+
}
|
|
2478
|
+
toBigInt() {
|
|
2479
|
+
return this.data;
|
|
2480
|
+
}
|
|
2481
|
+
decodeUtf8() {
|
|
2482
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2483
|
+
}
|
|
2484
|
+
toHexString() {
|
|
2485
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2486
|
+
}
|
|
2487
|
+
static validate(data) {
|
|
2488
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2489
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2490
|
+
assert(
|
|
2491
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2492
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2493
|
+
);
|
|
2494
|
+
const value = _CairoUint64.__processData(data);
|
|
2495
|
+
assert(
|
|
2496
|
+
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
2497
|
+
`Value is out of u64 range [${RANGE_U64.min}, ${RANGE_U64.max}]`
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2500
|
+
static is(data) {
|
|
2501
|
+
try {
|
|
2502
|
+
_CairoUint64.validate(data);
|
|
2503
|
+
return true;
|
|
2504
|
+
} catch {
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Check if provided abi type is this data type
|
|
2510
|
+
*/
|
|
2511
|
+
static isAbiType(abiType) {
|
|
2512
|
+
return abiType === _CairoUint64.abiSelector;
|
|
2513
|
+
}
|
|
2514
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2515
|
+
return new _CairoUint64(getNext(responseIterator));
|
|
2516
|
+
}
|
|
2517
|
+
};
|
|
2518
|
+
|
|
2519
|
+
// src/utils/cairoDataTypes/uint96.ts
|
|
2520
|
+
var CairoUint96 = class _CairoUint96 {
|
|
2521
|
+
data;
|
|
2522
|
+
static abiSelector = "core::integer::u96";
|
|
2523
|
+
constructor(data) {
|
|
2524
|
+
_CairoUint96.validate(data);
|
|
2525
|
+
this.data = _CairoUint96.__processData(data);
|
|
2526
|
+
}
|
|
2527
|
+
static __processData(data) {
|
|
2528
|
+
if (isString(data) && isText(data)) {
|
|
2529
|
+
return utf8ToBigInt(data);
|
|
2530
|
+
}
|
|
2531
|
+
return BigInt(data);
|
|
2532
|
+
}
|
|
2533
|
+
toApiRequest() {
|
|
2534
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2535
|
+
}
|
|
2536
|
+
toBigInt() {
|
|
2537
|
+
return this.data;
|
|
2538
|
+
}
|
|
2539
|
+
decodeUtf8() {
|
|
2540
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2541
|
+
}
|
|
2542
|
+
toHexString() {
|
|
2543
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2544
|
+
}
|
|
2545
|
+
static validate(data) {
|
|
2546
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2547
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2548
|
+
assert(
|
|
2549
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2550
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2551
|
+
);
|
|
2552
|
+
const value = _CairoUint96.__processData(data);
|
|
2553
|
+
assert(
|
|
2554
|
+
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
2555
|
+
`Value is out of u96 range [${RANGE_U96.min}, ${RANGE_U96.max}]`
|
|
2556
|
+
);
|
|
2557
|
+
}
|
|
2558
|
+
static is(data) {
|
|
2559
|
+
try {
|
|
2560
|
+
_CairoUint96.validate(data);
|
|
2561
|
+
return true;
|
|
2562
|
+
} catch {
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
/**
|
|
2567
|
+
* Check if provided abi type is this data type
|
|
2568
|
+
*/
|
|
2569
|
+
static isAbiType(abiType) {
|
|
2570
|
+
return abiType === _CairoUint96.abiSelector;
|
|
2571
|
+
}
|
|
2572
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2573
|
+
return new _CairoUint96(getNext(responseIterator));
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
|
|
2577
|
+
// src/utils/cairoDataTypes/uint128.ts
|
|
2578
|
+
var CairoUint128 = class _CairoUint128 {
|
|
2579
|
+
data;
|
|
2580
|
+
static abiSelector = "core::integer::u128";
|
|
2581
|
+
constructor(data) {
|
|
2582
|
+
_CairoUint128.validate(data);
|
|
2583
|
+
this.data = _CairoUint128.__processData(data);
|
|
2584
|
+
}
|
|
2585
|
+
static __processData(data) {
|
|
2586
|
+
if (isString(data) && isText(data)) {
|
|
2587
|
+
return utf8ToBigInt(data);
|
|
2588
|
+
}
|
|
2589
|
+
return BigInt(data);
|
|
2590
|
+
}
|
|
2591
|
+
toApiRequest() {
|
|
2592
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2593
|
+
}
|
|
2594
|
+
toBigInt() {
|
|
2595
|
+
return this.data;
|
|
2596
|
+
}
|
|
2597
|
+
decodeUtf8() {
|
|
2598
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2599
|
+
}
|
|
2600
|
+
toHexString() {
|
|
2601
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2602
|
+
}
|
|
2603
|
+
static validate(data) {
|
|
2604
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2605
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2606
|
+
assert(
|
|
2607
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2608
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2609
|
+
);
|
|
2610
|
+
const value = _CairoUint128.__processData(data);
|
|
2611
|
+
assert(
|
|
2612
|
+
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
2613
|
+
`Value is out of u128 range [${RANGE_U128.min}, ${RANGE_U128.max}]`
|
|
2614
|
+
);
|
|
2615
|
+
}
|
|
2616
|
+
static is(data) {
|
|
2617
|
+
try {
|
|
2618
|
+
_CairoUint128.validate(data);
|
|
2619
|
+
return true;
|
|
2620
|
+
} catch {
|
|
2621
|
+
return false;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
/**
|
|
2625
|
+
* Check if provided abi type is this data type
|
|
2626
|
+
*/
|
|
2627
|
+
static isAbiType(abiType) {
|
|
2628
|
+
return abiType === _CairoUint128.abiSelector;
|
|
2629
|
+
}
|
|
2630
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2631
|
+
return new _CairoUint128(getNext(responseIterator));
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
|
|
2635
|
+
// src/utils/cairoDataTypes/int8.ts
|
|
2636
|
+
var CairoInt8 = class _CairoInt8 {
|
|
2637
|
+
data;
|
|
2638
|
+
static abiSelector = "core::integer::i8";
|
|
2639
|
+
constructor(data) {
|
|
2640
|
+
_CairoInt8.validate(data);
|
|
2641
|
+
this.data = _CairoInt8.__processData(data);
|
|
2642
|
+
}
|
|
2643
|
+
static __processData(data) {
|
|
2644
|
+
if (isString(data) && isText(data)) {
|
|
2645
|
+
return utf8ToBigInt(data);
|
|
2646
|
+
}
|
|
2647
|
+
return BigInt(data);
|
|
2648
|
+
}
|
|
2649
|
+
toApiRequest() {
|
|
2650
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2651
|
+
}
|
|
2652
|
+
toBigInt() {
|
|
2653
|
+
return this.data;
|
|
2654
|
+
}
|
|
2655
|
+
decodeUtf8() {
|
|
2656
|
+
return new TextDecoder().decode(
|
|
2657
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 256n + this.data)
|
|
2658
|
+
);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* For negative values field element representation as positive hex string.
|
|
2662
|
+
* @returns cairo field arithmetic hex string
|
|
2663
|
+
*/
|
|
2664
|
+
toHexString() {
|
|
2665
|
+
const value = this.toBigInt();
|
|
2666
|
+
if (value < 0n) {
|
|
2667
|
+
const fieldElement = PRIME + value;
|
|
2668
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2669
|
+
}
|
|
2670
|
+
return addHexPrefix(value.toString(16));
|
|
2671
|
+
}
|
|
2672
|
+
static validate(data) {
|
|
2673
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2674
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2675
|
+
assert(
|
|
2676
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2677
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2678
|
+
);
|
|
2679
|
+
const value = _CairoInt8.__processData(data);
|
|
2680
|
+
assert(
|
|
2681
|
+
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
2682
|
+
`Value is out of i8 range [${RANGE_I8.min}, ${RANGE_I8.max}]`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
static is(data) {
|
|
2686
|
+
try {
|
|
2687
|
+
_CairoInt8.validate(data);
|
|
2688
|
+
return true;
|
|
2689
|
+
} catch {
|
|
2690
|
+
return false;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Check if provided abi type is this data type
|
|
2695
|
+
*/
|
|
2696
|
+
static isAbiType(abiType) {
|
|
2697
|
+
return abiType === _CairoInt8.abiSelector;
|
|
2698
|
+
}
|
|
2699
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2700
|
+
const response = getNext(responseIterator);
|
|
2701
|
+
const value = BigInt(response);
|
|
2702
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2703
|
+
return new _CairoInt8(signedValue);
|
|
2704
|
+
}
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
// src/utils/cairoDataTypes/int16.ts
|
|
2708
|
+
var CairoInt16 = class _CairoInt16 {
|
|
2709
|
+
data;
|
|
2710
|
+
static abiSelector = "core::integer::i16";
|
|
2711
|
+
constructor(data) {
|
|
2712
|
+
_CairoInt16.validate(data);
|
|
2713
|
+
this.data = _CairoInt16.__processData(data);
|
|
2714
|
+
}
|
|
2715
|
+
static __processData(data) {
|
|
2716
|
+
if (isString(data) && isText(data)) {
|
|
2717
|
+
return utf8ToBigInt(data);
|
|
2718
|
+
}
|
|
2719
|
+
return BigInt(data);
|
|
2720
|
+
}
|
|
2721
|
+
toApiRequest() {
|
|
2722
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2723
|
+
}
|
|
2724
|
+
toBigInt() {
|
|
2725
|
+
return this.data;
|
|
2726
|
+
}
|
|
2727
|
+
decodeUtf8() {
|
|
2728
|
+
return new TextDecoder().decode(
|
|
2729
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 65536n + this.data)
|
|
2730
|
+
);
|
|
2731
|
+
}
|
|
2732
|
+
/**
|
|
2733
|
+
* For negative values field element representation as positive hex string.
|
|
2734
|
+
* @returns cairo field arithmetic hex string
|
|
2735
|
+
*/
|
|
2736
|
+
toHexString() {
|
|
2737
|
+
const value = this.toBigInt();
|
|
2738
|
+
if (value < 0n) {
|
|
2739
|
+
const fieldElement = PRIME + value;
|
|
2740
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2741
|
+
}
|
|
2742
|
+
return addHexPrefix(value.toString(16));
|
|
2743
|
+
}
|
|
2744
|
+
static validate(data) {
|
|
2745
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2746
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2747
|
+
assert(
|
|
2748
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2749
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2750
|
+
);
|
|
2751
|
+
const value = _CairoInt16.__processData(data);
|
|
2752
|
+
assert(
|
|
2753
|
+
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
2754
|
+
`Value is out of i16 range [${RANGE_I16.min}, ${RANGE_I16.max}]`
|
|
2755
|
+
);
|
|
2756
|
+
}
|
|
2757
|
+
static is(data) {
|
|
2758
|
+
try {
|
|
2759
|
+
_CairoInt16.validate(data);
|
|
2760
|
+
return true;
|
|
2761
|
+
} catch {
|
|
2762
|
+
return false;
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Check if provided abi type is this data type
|
|
2767
|
+
*/
|
|
2768
|
+
static isAbiType(abiType) {
|
|
2769
|
+
return abiType === _CairoInt16.abiSelector;
|
|
2770
|
+
}
|
|
2771
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2772
|
+
const response = getNext(responseIterator);
|
|
2773
|
+
const value = BigInt(response);
|
|
2774
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2775
|
+
return new _CairoInt16(signedValue);
|
|
2776
|
+
}
|
|
2777
|
+
};
|
|
2778
|
+
|
|
2779
|
+
// src/utils/cairoDataTypes/int32.ts
|
|
2780
|
+
var CairoInt32 = class _CairoInt32 {
|
|
2781
|
+
data;
|
|
2782
|
+
static abiSelector = "core::integer::i32";
|
|
2783
|
+
constructor(data) {
|
|
2784
|
+
_CairoInt32.validate(data);
|
|
2785
|
+
this.data = _CairoInt32.__processData(data);
|
|
2786
|
+
}
|
|
2787
|
+
static __processData(data) {
|
|
2788
|
+
if (isString(data) && isText(data)) {
|
|
2789
|
+
return utf8ToBigInt(data);
|
|
2790
|
+
}
|
|
2791
|
+
return BigInt(data);
|
|
2792
|
+
}
|
|
2793
|
+
toApiRequest() {
|
|
2794
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2795
|
+
}
|
|
2796
|
+
toBigInt() {
|
|
2797
|
+
return this.data;
|
|
2798
|
+
}
|
|
2799
|
+
decodeUtf8() {
|
|
2800
|
+
return new TextDecoder().decode(
|
|
2801
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 4294967296n + this.data)
|
|
2802
|
+
);
|
|
2803
|
+
}
|
|
2804
|
+
/**
|
|
2805
|
+
* For negative values field element representation as positive hex string.
|
|
2806
|
+
* @returns cairo field arithmetic hex string
|
|
2807
|
+
*/
|
|
2808
|
+
toHexString() {
|
|
2809
|
+
const value = this.toBigInt();
|
|
2810
|
+
if (value < 0n) {
|
|
2811
|
+
const fieldElement = PRIME + value;
|
|
2812
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2813
|
+
}
|
|
2814
|
+
return addHexPrefix(value.toString(16));
|
|
2815
|
+
}
|
|
2816
|
+
static validate(data) {
|
|
2817
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2818
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2819
|
+
assert(
|
|
2820
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2821
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2822
|
+
);
|
|
2823
|
+
const value = _CairoInt32.__processData(data);
|
|
2824
|
+
assert(
|
|
2825
|
+
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
2826
|
+
`Value is out of i32 range [${RANGE_I32.min}, ${RANGE_I32.max}]`
|
|
2827
|
+
);
|
|
2828
|
+
}
|
|
2829
|
+
static is(data) {
|
|
2830
|
+
try {
|
|
2831
|
+
_CairoInt32.validate(data);
|
|
2832
|
+
return true;
|
|
2833
|
+
} catch {
|
|
2834
|
+
return false;
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
/**
|
|
2838
|
+
* Check if provided abi type is this data type
|
|
2839
|
+
*/
|
|
2840
|
+
static isAbiType(abiType) {
|
|
2841
|
+
return abiType === _CairoInt32.abiSelector;
|
|
2842
|
+
}
|
|
2843
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2844
|
+
const response = getNext(responseIterator);
|
|
2845
|
+
const value = BigInt(response);
|
|
2846
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2847
|
+
return new _CairoInt32(signedValue);
|
|
2848
|
+
}
|
|
2849
|
+
};
|
|
2850
|
+
|
|
2851
|
+
// src/utils/cairoDataTypes/int64.ts
|
|
2852
|
+
var CairoInt64 = class _CairoInt64 {
|
|
2853
|
+
data;
|
|
2854
|
+
static abiSelector = "core::integer::i64";
|
|
2855
|
+
constructor(data) {
|
|
2856
|
+
_CairoInt64.validate(data);
|
|
2857
|
+
this.data = _CairoInt64.__processData(data);
|
|
2858
|
+
}
|
|
2859
|
+
static __processData(data) {
|
|
2860
|
+
if (isString(data) && isText(data)) {
|
|
2861
|
+
return utf8ToBigInt(data);
|
|
2862
|
+
}
|
|
2863
|
+
return BigInt(data);
|
|
2864
|
+
}
|
|
2865
|
+
toApiRequest() {
|
|
2866
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2867
|
+
}
|
|
2868
|
+
toBigInt() {
|
|
2869
|
+
return this.data;
|
|
2870
|
+
}
|
|
2871
|
+
decodeUtf8() {
|
|
2872
|
+
return new TextDecoder().decode(
|
|
2873
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 64n + this.data)
|
|
2874
|
+
);
|
|
2875
|
+
}
|
|
2876
|
+
/**
|
|
2877
|
+
* For negative values field element representation as positive hex string.
|
|
2878
|
+
* @returns cairo field arithmetic hex string
|
|
2879
|
+
*/
|
|
2880
|
+
toHexString() {
|
|
2881
|
+
const value = this.toBigInt();
|
|
2882
|
+
if (value < 0n) {
|
|
2883
|
+
const fieldElement = PRIME + value;
|
|
2884
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2885
|
+
}
|
|
2886
|
+
return addHexPrefix(value.toString(16));
|
|
2887
|
+
}
|
|
2888
|
+
static validate(data) {
|
|
2889
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2890
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2891
|
+
assert(
|
|
2892
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2893
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2894
|
+
);
|
|
2895
|
+
const value = _CairoInt64.__processData(data);
|
|
2896
|
+
assert(
|
|
2897
|
+
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
2898
|
+
`Value is out of i64 range [${RANGE_I64.min}, ${RANGE_I64.max}]`
|
|
2899
|
+
);
|
|
2900
|
+
}
|
|
2901
|
+
static is(data) {
|
|
2902
|
+
try {
|
|
2903
|
+
_CairoInt64.validate(data);
|
|
2904
|
+
return true;
|
|
2905
|
+
} catch {
|
|
2906
|
+
return false;
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
/**
|
|
2910
|
+
* Check if provided abi type is this data type
|
|
2911
|
+
*/
|
|
2912
|
+
static isAbiType(abiType) {
|
|
2913
|
+
return abiType === _CairoInt64.abiSelector;
|
|
2914
|
+
}
|
|
2915
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2916
|
+
const response = getNext(responseIterator);
|
|
2917
|
+
const value = BigInt(response);
|
|
2918
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2919
|
+
return new _CairoInt64(signedValue);
|
|
2920
|
+
}
|
|
2921
|
+
};
|
|
2922
|
+
|
|
2923
|
+
// src/utils/cairoDataTypes/int128.ts
|
|
2924
|
+
var CairoInt128 = class _CairoInt128 {
|
|
2925
|
+
data;
|
|
2926
|
+
static abiSelector = "core::integer::i128";
|
|
2927
|
+
constructor(data) {
|
|
2928
|
+
_CairoInt128.validate(data);
|
|
2929
|
+
this.data = _CairoInt128.__processData(data);
|
|
2930
|
+
}
|
|
2931
|
+
static __processData(data) {
|
|
2932
|
+
if (isString(data) && isText(data)) {
|
|
2933
|
+
return utf8ToBigInt(data);
|
|
2934
|
+
}
|
|
2935
|
+
return BigInt(data);
|
|
2936
|
+
}
|
|
2937
|
+
toApiRequest() {
|
|
2938
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2939
|
+
}
|
|
2940
|
+
toBigInt() {
|
|
2941
|
+
return this.data;
|
|
2942
|
+
}
|
|
2943
|
+
decodeUtf8() {
|
|
2944
|
+
return new TextDecoder().decode(
|
|
2945
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 128n + this.data)
|
|
2946
|
+
);
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* For negative values field element representation as positive hex string.
|
|
2950
|
+
* @returns cairo field arithmetic hex string
|
|
2951
|
+
*/
|
|
2952
|
+
toHexString() {
|
|
2953
|
+
const value = this.toBigInt();
|
|
2954
|
+
if (value < 0n) {
|
|
2955
|
+
const fieldElement = PRIME + value;
|
|
2956
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2957
|
+
}
|
|
2958
|
+
return addHexPrefix(value.toString(16));
|
|
2959
|
+
}
|
|
2960
|
+
static validate(data) {
|
|
2961
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2962
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2963
|
+
assert(
|
|
2964
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2965
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2966
|
+
);
|
|
2967
|
+
const value = _CairoInt128.__processData(data);
|
|
2968
|
+
assert(
|
|
2969
|
+
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
2970
|
+
`Value is out of i128 range [${RANGE_I128.min}, ${RANGE_I128.max}]`
|
|
2971
|
+
);
|
|
2972
|
+
}
|
|
2973
|
+
static is(data) {
|
|
2974
|
+
try {
|
|
2975
|
+
_CairoInt128.validate(data);
|
|
2976
|
+
return true;
|
|
2977
|
+
} catch {
|
|
2978
|
+
return false;
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
/**
|
|
2982
|
+
* Check if provided abi type is this data type
|
|
2983
|
+
*/
|
|
2984
|
+
static isAbiType(abiType) {
|
|
2985
|
+
return abiType === _CairoInt128.abiSelector;
|
|
2986
|
+
}
|
|
2987
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2988
|
+
const response = getNext(responseIterator);
|
|
2989
|
+
const value = BigInt(response);
|
|
2990
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2991
|
+
return new _CairoInt128(signedValue);
|
|
2992
|
+
}
|
|
2993
|
+
};
|
|
2994
|
+
|
|
2995
|
+
// src/utils/calldata/parser/parsingStrategy.ts
|
|
2996
|
+
var hdParsingStrategy = {
|
|
2997
|
+
// TODO: provjeri svi request parseri stvaraju array, dali je to ok sa requstParserom
|
|
2998
|
+
request: {
|
|
2999
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
3000
|
+
return new CairoBytes31(val).toApiRequest();
|
|
3001
|
+
},
|
|
3002
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
3003
|
+
return new CairoByteArray(val).toApiRequest();
|
|
3004
|
+
},
|
|
3005
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
3006
|
+
return new CairoFelt252(val).toApiRequest();
|
|
3007
|
+
},
|
|
3008
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
3009
|
+
return new CairoUint256(val).toApiRequest();
|
|
3010
|
+
},
|
|
3011
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
3012
|
+
return new CairoUint512(val).toApiRequest();
|
|
3013
|
+
},
|
|
3014
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
3015
|
+
return new CairoUint8(val).toApiRequest();
|
|
3016
|
+
},
|
|
3017
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
3018
|
+
return new CairoUint16(val).toApiRequest();
|
|
3019
|
+
},
|
|
3020
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
3021
|
+
return new CairoUint64(val).toApiRequest();
|
|
3022
|
+
},
|
|
3023
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
3024
|
+
return new CairoUint96(val).toApiRequest();
|
|
3025
|
+
},
|
|
3026
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
3027
|
+
return new CairoUint128(val).toApiRequest();
|
|
3028
|
+
},
|
|
3029
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
3030
|
+
return new CairoInt8(val).toApiRequest();
|
|
3031
|
+
},
|
|
3032
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
3033
|
+
return new CairoInt16(val).toApiRequest();
|
|
3034
|
+
},
|
|
3035
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
3036
|
+
return new CairoInt32(val).toApiRequest();
|
|
3037
|
+
},
|
|
3038
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
3039
|
+
return new CairoInt64(val).toApiRequest();
|
|
3040
|
+
},
|
|
3041
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
3042
|
+
return new CairoInt128(val).toApiRequest();
|
|
3043
|
+
}
|
|
3044
|
+
},
|
|
3045
|
+
response: {
|
|
3046
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
3047
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
3048
|
+
},
|
|
3049
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
3050
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
3051
|
+
},
|
|
3052
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
3053
|
+
return CairoFelt252.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3054
|
+
},
|
|
3055
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
3056
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3057
|
+
},
|
|
3058
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
3059
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3060
|
+
},
|
|
3061
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
3062
|
+
return CairoUint8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3063
|
+
},
|
|
3064
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
3065
|
+
return CairoUint16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3066
|
+
},
|
|
3067
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
3068
|
+
return CairoUint64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3069
|
+
},
|
|
3070
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
3071
|
+
return CairoUint96.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3072
|
+
},
|
|
3073
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
3074
|
+
return CairoUint128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3075
|
+
},
|
|
3076
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
3077
|
+
return CairoInt8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3078
|
+
},
|
|
3079
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
3080
|
+
return CairoInt16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3081
|
+
},
|
|
3082
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
3083
|
+
return CairoInt32.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3084
|
+
},
|
|
3085
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
3086
|
+
return CairoInt64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3087
|
+
},
|
|
3088
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
3089
|
+
return CairoInt128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
};
|
|
3093
|
+
var fastParsingStrategy = {
|
|
3094
|
+
request: {
|
|
3095
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
3096
|
+
return new CairoBytes31(val).toApiRequest();
|
|
3097
|
+
},
|
|
3098
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
3099
|
+
return new CairoByteArray(val).toApiRequest();
|
|
3100
|
+
},
|
|
3101
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
3102
|
+
return felt(val);
|
|
3103
|
+
},
|
|
3104
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
3105
|
+
return new CairoUint256(val).toApiRequest();
|
|
3106
|
+
},
|
|
3107
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
3108
|
+
return new CairoUint512(val).toApiRequest();
|
|
3109
|
+
},
|
|
3110
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
3111
|
+
return felt(val);
|
|
3112
|
+
},
|
|
3113
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
3114
|
+
return felt(val);
|
|
3115
|
+
},
|
|
3116
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
3117
|
+
return felt(val);
|
|
3118
|
+
},
|
|
3119
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
3120
|
+
return felt(val);
|
|
3121
|
+
},
|
|
3122
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
3123
|
+
return felt(val);
|
|
3124
|
+
},
|
|
3125
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
3126
|
+
return new CairoInt8(val).toApiRequest();
|
|
3127
|
+
},
|
|
3128
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
3129
|
+
return new CairoInt16(val).toApiRequest();
|
|
3130
|
+
},
|
|
3131
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
3132
|
+
return new CairoInt32(val).toApiRequest();
|
|
3133
|
+
},
|
|
3134
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
3135
|
+
return new CairoInt64(val).toApiRequest();
|
|
3136
|
+
},
|
|
3137
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
3138
|
+
return new CairoInt128(val).toApiRequest();
|
|
3139
|
+
}
|
|
3140
|
+
},
|
|
3141
|
+
response: {
|
|
3142
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
3143
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
3144
|
+
},
|
|
3145
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
3146
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
3147
|
+
},
|
|
3148
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
3149
|
+
return BigInt(getNext(responseIterator));
|
|
3150
|
+
},
|
|
3151
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
3152
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3153
|
+
},
|
|
3154
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
3155
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
3156
|
+
},
|
|
3157
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
3158
|
+
return BigInt(getNext(responseIterator));
|
|
3159
|
+
},
|
|
3160
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
3161
|
+
return BigInt(getNext(responseIterator));
|
|
3162
|
+
},
|
|
3163
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
3164
|
+
return BigInt(getNext(responseIterator));
|
|
3165
|
+
},
|
|
3166
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
3167
|
+
return BigInt(getNext(responseIterator));
|
|
3168
|
+
},
|
|
3169
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
3170
|
+
return BigInt(getNext(responseIterator));
|
|
3171
|
+
},
|
|
3172
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
3173
|
+
return BigInt(getNext(responseIterator));
|
|
3174
|
+
},
|
|
3175
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
3176
|
+
return BigInt(getNext(responseIterator));
|
|
3177
|
+
},
|
|
3178
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
3179
|
+
return BigInt(getNext(responseIterator));
|
|
3180
|
+
},
|
|
3181
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
3182
|
+
return BigInt(getNext(responseIterator));
|
|
3183
|
+
},
|
|
3184
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
3185
|
+
return BigInt(getNext(responseIterator));
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
|
|
3190
|
+
// src/utils/calldata/parser/parser-0-1.1.0.ts
|
|
3191
|
+
var AbiParser1 = class {
|
|
3192
|
+
abi;
|
|
3193
|
+
parsingStrategy;
|
|
3194
|
+
constructor(abi, parsingStrategy) {
|
|
3195
|
+
this.abi = abi;
|
|
3196
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
3197
|
+
}
|
|
3198
|
+
getRequestParser(abiType) {
|
|
3199
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
3200
|
+
return this.parsingStrategy.request[abiType];
|
|
3201
|
+
}
|
|
3202
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
3203
|
+
}
|
|
3204
|
+
getResponseParser(abiType) {
|
|
3205
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
3206
|
+
return this.parsingStrategy.response[abiType];
|
|
3207
|
+
}
|
|
3208
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
1639
3209
|
}
|
|
1640
3210
|
/**
|
|
1641
3211
|
* abi method inputs length without '_len' inputs
|
|
@@ -1666,8 +3236,22 @@ var AbiParser1 = class {
|
|
|
1666
3236
|
// src/utils/calldata/parser/parser-2.0.0.ts
|
|
1667
3237
|
var AbiParser2 = class {
|
|
1668
3238
|
abi;
|
|
1669
|
-
|
|
3239
|
+
parsingStrategy;
|
|
3240
|
+
constructor(abi, parsingStrategy) {
|
|
1670
3241
|
this.abi = abi;
|
|
3242
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
3243
|
+
}
|
|
3244
|
+
getRequestParser(abiType) {
|
|
3245
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
3246
|
+
return this.parsingStrategy.request[abiType];
|
|
3247
|
+
}
|
|
3248
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
3249
|
+
}
|
|
3250
|
+
getResponseParser(abiType) {
|
|
3251
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
3252
|
+
return this.parsingStrategy.response[abiType];
|
|
3253
|
+
}
|
|
3254
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
1671
3255
|
}
|
|
1672
3256
|
/**
|
|
1673
3257
|
* abi method inputs length
|
|
@@ -1700,13 +3284,13 @@ var AbiParser2 = class {
|
|
|
1700
3284
|
};
|
|
1701
3285
|
|
|
1702
3286
|
// src/utils/calldata/parser/index.ts
|
|
1703
|
-
function createAbiParser(abi) {
|
|
3287
|
+
function createAbiParser(abi, parsingStrategy) {
|
|
1704
3288
|
const version = getAbiVersion(abi);
|
|
1705
3289
|
if (version === 0 || version === 1) {
|
|
1706
|
-
return new AbiParser1(abi);
|
|
3290
|
+
return new AbiParser1(abi, parsingStrategy);
|
|
1707
3291
|
}
|
|
1708
3292
|
if (version === 2) {
|
|
1709
|
-
return new AbiParser2(abi);
|
|
3293
|
+
return new AbiParser2(abi, parsingStrategy);
|
|
1710
3294
|
}
|
|
1711
3295
|
throw Error(`Unsupported ABI version ${version}`);
|
|
1712
3296
|
}
|
|
@@ -1833,16 +3417,17 @@ var CairoFixedArray = class _CairoFixedArray {
|
|
|
1833
3417
|
`The type ${arrayType} do not includes any content type. Needs [type; length].`
|
|
1834
3418
|
);
|
|
1835
3419
|
}
|
|
3420
|
+
let arraySize;
|
|
1836
3421
|
try {
|
|
1837
|
-
_CairoFixedArray.getFixedArraySize(arrayType);
|
|
3422
|
+
arraySize = _CairoFixedArray.getFixedArraySize(arrayType);
|
|
1838
3423
|
} catch {
|
|
1839
3424
|
throw new Error(
|
|
1840
3425
|
`The type ${arrayType} type do not includes any length. Needs [type; length].`
|
|
1841
3426
|
);
|
|
1842
3427
|
}
|
|
1843
3428
|
assert(
|
|
1844
|
-
|
|
1845
|
-
`The ABI type ${arrayType} is expecting ${
|
|
3429
|
+
arraySize === content.length,
|
|
3430
|
+
`The ABI type ${arrayType} is expecting ${arraySize} items. ${content.length} items provided.`
|
|
1846
3431
|
);
|
|
1847
3432
|
this.content = content;
|
|
1848
3433
|
this.arrayType = arrayType;
|
|
@@ -1939,6 +3524,7 @@ var CairoFixedArray = class _CairoFixedArray {
|
|
|
1939
3524
|
}
|
|
1940
3525
|
/**
|
|
1941
3526
|
* Checks if the given Cairo type is a fixed-array type.
|
|
3527
|
+
* structure: [string; number]
|
|
1942
3528
|
*
|
|
1943
3529
|
* @param {string} type - The type to check.
|
|
1944
3530
|
* @returns - `true` if the type is a fixed array type, `false` otherwise.
|
|
@@ -1983,7 +3569,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1983
3569
|
if (isTypeNonZero(abiType)) {
|
|
1984
3570
|
return unorderedItem;
|
|
1985
3571
|
}
|
|
1986
|
-
if (
|
|
3572
|
+
if (CairoByteArray.isAbiType(abiType)) {
|
|
1987
3573
|
return unorderedItem;
|
|
1988
3574
|
}
|
|
1989
3575
|
if (isTypeU96(abiType)) {
|
|
@@ -2141,14 +3727,38 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
2141
3727
|
}
|
|
2142
3728
|
|
|
2143
3729
|
// src/utils/calldata/requestParser.ts
|
|
2144
|
-
function parseBaseTypes(
|
|
3730
|
+
function parseBaseTypes({
|
|
3731
|
+
type,
|
|
3732
|
+
val,
|
|
3733
|
+
parser
|
|
3734
|
+
}) {
|
|
2145
3735
|
switch (true) {
|
|
2146
3736
|
case CairoUint256.isAbiType(type):
|
|
2147
|
-
return
|
|
3737
|
+
return parser.getRequestParser(type)(val);
|
|
2148
3738
|
case CairoUint512.isAbiType(type):
|
|
2149
|
-
return
|
|
2150
|
-
case
|
|
2151
|
-
return
|
|
3739
|
+
return parser.getRequestParser(type)(val);
|
|
3740
|
+
case CairoUint8.isAbiType(type):
|
|
3741
|
+
return parser.getRequestParser(type)(val);
|
|
3742
|
+
case CairoUint16.isAbiType(type):
|
|
3743
|
+
return parser.getRequestParser(type)(val);
|
|
3744
|
+
case CairoUint64.isAbiType(type):
|
|
3745
|
+
return parser.getRequestParser(type)(val);
|
|
3746
|
+
case CairoUint96.isAbiType(type):
|
|
3747
|
+
return parser.getRequestParser(type)(val);
|
|
3748
|
+
case CairoUint128.isAbiType(type):
|
|
3749
|
+
return parser.getRequestParser(type)(val);
|
|
3750
|
+
case CairoInt8.isAbiType(type):
|
|
3751
|
+
return parser.getRequestParser(type)(val);
|
|
3752
|
+
case CairoInt16.isAbiType(type):
|
|
3753
|
+
return parser.getRequestParser(type)(val);
|
|
3754
|
+
case CairoInt32.isAbiType(type):
|
|
3755
|
+
return parser.getRequestParser(type)(val);
|
|
3756
|
+
case CairoInt64.isAbiType(type):
|
|
3757
|
+
return parser.getRequestParser(type)(val);
|
|
3758
|
+
case CairoInt128.isAbiType(type):
|
|
3759
|
+
return parser.getRequestParser(type)(val);
|
|
3760
|
+
case CairoBytes31.isAbiType(type):
|
|
3761
|
+
return parser.getRequestParser(type)(val);
|
|
2152
3762
|
case isTypeSecp256k1Point(type): {
|
|
2153
3763
|
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
2154
3764
|
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
@@ -2161,7 +3771,7 @@ function parseBaseTypes(type, val) {
|
|
|
2161
3771
|
];
|
|
2162
3772
|
}
|
|
2163
3773
|
default:
|
|
2164
|
-
return
|
|
3774
|
+
return parser.getRequestParser(CairoFelt252.abiSelector)(val);
|
|
2165
3775
|
}
|
|
2166
3776
|
}
|
|
2167
3777
|
function parseTuple(element, typeStr) {
|
|
@@ -2181,16 +3791,13 @@ function parseTuple(element, typeStr) {
|
|
|
2181
3791
|
};
|
|
2182
3792
|
});
|
|
2183
3793
|
}
|
|
2184
|
-
function
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
];
|
|
2192
|
-
}
|
|
2193
|
-
function parseCalldataValue(element, type, structs, enums) {
|
|
3794
|
+
function parseCalldataValue({
|
|
3795
|
+
element,
|
|
3796
|
+
type,
|
|
3797
|
+
structs,
|
|
3798
|
+
enums,
|
|
3799
|
+
parser
|
|
3800
|
+
}) {
|
|
2194
3801
|
if (element === void 0) {
|
|
2195
3802
|
throw Error(`Missing parameter for type ${type}`);
|
|
2196
3803
|
}
|
|
@@ -2210,7 +3817,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2210
3817
|
throw new Error(`ABI type ${type}: not an Array representing a cairo.fixedArray() provided.`);
|
|
2211
3818
|
}
|
|
2212
3819
|
return values.reduce((acc, it) => {
|
|
2213
|
-
return acc.concat(
|
|
3820
|
+
return acc.concat(
|
|
3821
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
3822
|
+
);
|
|
2214
3823
|
}, []);
|
|
2215
3824
|
}
|
|
2216
3825
|
if (Array.isArray(element)) {
|
|
@@ -2218,37 +3827,51 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2218
3827
|
result.push(felt(element.length));
|
|
2219
3828
|
const arrayType = getArrayType(type);
|
|
2220
3829
|
return element.reduce((acc, it) => {
|
|
2221
|
-
return acc.concat(
|
|
3830
|
+
return acc.concat(
|
|
3831
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
3832
|
+
);
|
|
2222
3833
|
}, result);
|
|
2223
3834
|
}
|
|
3835
|
+
if (CairoUint256.isAbiType(type)) {
|
|
3836
|
+
return parser.getRequestParser(type)(element);
|
|
3837
|
+
}
|
|
3838
|
+
if (CairoUint512.isAbiType(type)) {
|
|
3839
|
+
return parser.getRequestParser(type)(element);
|
|
3840
|
+
}
|
|
2224
3841
|
if (structs[type] && structs[type].members.length) {
|
|
2225
|
-
if (
|
|
2226
|
-
return
|
|
3842
|
+
if (isTypeEthAddress(type)) {
|
|
3843
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
2227
3844
|
}
|
|
2228
|
-
if (
|
|
2229
|
-
return
|
|
3845
|
+
if (CairoByteArray.isAbiType(type)) {
|
|
3846
|
+
return parser.getRequestParser(type)(element);
|
|
2230
3847
|
}
|
|
2231
|
-
if (isTypeEthAddress(type)) return parseBaseTypes(type, element);
|
|
2232
|
-
if (isTypeByteArray(type)) return parseByteArray(element);
|
|
2233
3848
|
const { members } = structs[type];
|
|
2234
3849
|
const subElement = element;
|
|
2235
3850
|
return members.reduce((acc, it) => {
|
|
2236
|
-
return acc.concat(
|
|
3851
|
+
return acc.concat(
|
|
3852
|
+
parseCalldataValue({
|
|
3853
|
+
element: subElement[it.name],
|
|
3854
|
+
type: it.type,
|
|
3855
|
+
structs,
|
|
3856
|
+
enums,
|
|
3857
|
+
parser
|
|
3858
|
+
})
|
|
3859
|
+
);
|
|
2237
3860
|
}, []);
|
|
2238
3861
|
}
|
|
2239
3862
|
if (isTypeTuple(type)) {
|
|
2240
3863
|
const tupled = parseTuple(element, type);
|
|
2241
3864
|
return tupled.reduce((acc, it) => {
|
|
2242
|
-
const parsedData = parseCalldataValue(
|
|
3865
|
+
const parsedData = parseCalldataValue({
|
|
3866
|
+
element: it.element,
|
|
3867
|
+
type: it.type,
|
|
3868
|
+
structs,
|
|
3869
|
+
enums,
|
|
3870
|
+
parser
|
|
3871
|
+
});
|
|
2243
3872
|
return acc.concat(parsedData);
|
|
2244
3873
|
}, []);
|
|
2245
3874
|
}
|
|
2246
|
-
if (CairoUint256.isAbiType(type)) {
|
|
2247
|
-
return new CairoUint256(element).toApiRequest();
|
|
2248
|
-
}
|
|
2249
|
-
if (CairoUint512.isAbiType(type)) {
|
|
2250
|
-
return new CairoUint512(element).toApiRequest();
|
|
2251
|
-
}
|
|
2252
3875
|
if (isTypeEnum(type, enums)) {
|
|
2253
3876
|
const { variants } = enums[type];
|
|
2254
3877
|
if (isTypeOption(type)) {
|
|
@@ -2262,12 +3885,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2262
3885
|
if (typeVariantSome === "()") {
|
|
2263
3886
|
return CairoOptionVariant.Some.toString();
|
|
2264
3887
|
}
|
|
2265
|
-
const parsedParameter2 = parseCalldataValue(
|
|
2266
|
-
myOption.unwrap(),
|
|
2267
|
-
typeVariantSome,
|
|
3888
|
+
const parsedParameter2 = parseCalldataValue({
|
|
3889
|
+
element: myOption.unwrap(),
|
|
3890
|
+
type: typeVariantSome,
|
|
2268
3891
|
structs,
|
|
2269
|
-
enums
|
|
2270
|
-
|
|
3892
|
+
enums,
|
|
3893
|
+
parser
|
|
3894
|
+
});
|
|
2271
3895
|
if (Array.isArray(parsedParameter2)) {
|
|
2272
3896
|
return [CairoOptionVariant.Some.toString(), ...parsedParameter2];
|
|
2273
3897
|
}
|
|
@@ -2286,12 +3910,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2286
3910
|
if (typeVariantOk === "()") {
|
|
2287
3911
|
return CairoResultVariant.Ok.toString();
|
|
2288
3912
|
}
|
|
2289
|
-
const parsedParameter3 = parseCalldataValue(
|
|
2290
|
-
myResult.unwrap(),
|
|
2291
|
-
typeVariantOk,
|
|
3913
|
+
const parsedParameter3 = parseCalldataValue({
|
|
3914
|
+
element: myResult.unwrap(),
|
|
3915
|
+
type: typeVariantOk,
|
|
2292
3916
|
structs,
|
|
2293
|
-
enums
|
|
2294
|
-
|
|
3917
|
+
enums,
|
|
3918
|
+
parser
|
|
3919
|
+
});
|
|
2295
3920
|
if (Array.isArray(parsedParameter3)) {
|
|
2296
3921
|
return [CairoResultVariant.Ok.toString(), ...parsedParameter3];
|
|
2297
3922
|
}
|
|
@@ -2305,7 +3930,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2305
3930
|
if (typeVariantErr === "()") {
|
|
2306
3931
|
return CairoResultVariant.Err.toString();
|
|
2307
3932
|
}
|
|
2308
|
-
const parsedParameter2 = parseCalldataValue(
|
|
3933
|
+
const parsedParameter2 = parseCalldataValue({
|
|
3934
|
+
element: myResult.unwrap(),
|
|
3935
|
+
type: typeVariantErr,
|
|
3936
|
+
structs,
|
|
3937
|
+
enums,
|
|
3938
|
+
parser
|
|
3939
|
+
});
|
|
2309
3940
|
if (Array.isArray(parsedParameter2)) {
|
|
2310
3941
|
return [CairoResultVariant.Err.toString(), ...parsedParameter2];
|
|
2311
3942
|
}
|
|
@@ -2322,21 +3953,33 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2322
3953
|
if (typeActiveVariant === "()") {
|
|
2323
3954
|
return numActiveVariant.toString();
|
|
2324
3955
|
}
|
|
2325
|
-
const parsedParameter = parseCalldataValue(
|
|
3956
|
+
const parsedParameter = parseCalldataValue({
|
|
3957
|
+
element: myEnum.unwrap(),
|
|
3958
|
+
type: typeActiveVariant,
|
|
3959
|
+
structs,
|
|
3960
|
+
enums,
|
|
3961
|
+
parser
|
|
3962
|
+
});
|
|
2326
3963
|
if (Array.isArray(parsedParameter)) {
|
|
2327
3964
|
return [numActiveVariant.toString(), ...parsedParameter];
|
|
2328
3965
|
}
|
|
2329
3966
|
return [numActiveVariant.toString(), parsedParameter];
|
|
2330
3967
|
}
|
|
2331
3968
|
if (isTypeNonZero(type)) {
|
|
2332
|
-
return parseBaseTypes(getArrayType(type), element);
|
|
3969
|
+
return parseBaseTypes({ type: getArrayType(type), val: element, parser });
|
|
2333
3970
|
}
|
|
2334
3971
|
if (typeof element === "object") {
|
|
2335
3972
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
2336
3973
|
}
|
|
2337
|
-
return parseBaseTypes(type, element);
|
|
3974
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
2338
3975
|
}
|
|
2339
|
-
function parseCalldataField(
|
|
3976
|
+
function parseCalldataField({
|
|
3977
|
+
argsIterator,
|
|
3978
|
+
input,
|
|
3979
|
+
structs,
|
|
3980
|
+
enums,
|
|
3981
|
+
parser
|
|
3982
|
+
}) {
|
|
2340
3983
|
const { name, type } = input;
|
|
2341
3984
|
let { value } = argsIterator.next();
|
|
2342
3985
|
switch (true) {
|
|
@@ -2345,7 +3988,7 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
2345
3988
|
if (!Array.isArray(value) && !(typeof value === "object")) {
|
|
2346
3989
|
throw Error(`ABI expected parameter ${name} to be an array or an object, got ${value}`);
|
|
2347
3990
|
}
|
|
2348
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
3991
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
2349
3992
|
// Normal Array
|
|
2350
3993
|
case isTypeArray(type):
|
|
2351
3994
|
if (!Array.isArray(value) && !isText(value)) {
|
|
@@ -2354,51 +3997,71 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
2354
3997
|
if (isString(value)) {
|
|
2355
3998
|
value = splitLongString(value);
|
|
2356
3999
|
}
|
|
2357
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
4000
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
2358
4001
|
case isTypeNonZero(type):
|
|
2359
|
-
return parseBaseTypes(getArrayType(type), value);
|
|
4002
|
+
return parseBaseTypes({ type: getArrayType(type), val: value, parser });
|
|
2360
4003
|
case isTypeEthAddress(type):
|
|
2361
|
-
return parseBaseTypes(type, value);
|
|
4004
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
2362
4005
|
// Struct or Tuple
|
|
2363
4006
|
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
2364
|
-
return parseCalldataValue(
|
|
4007
|
+
return parseCalldataValue({
|
|
4008
|
+
element: value,
|
|
4009
|
+
type,
|
|
4010
|
+
structs,
|
|
4011
|
+
enums,
|
|
4012
|
+
parser
|
|
4013
|
+
});
|
|
2365
4014
|
// Enums
|
|
2366
4015
|
case isTypeEnum(type, enums):
|
|
2367
|
-
return parseCalldataValue(
|
|
2368
|
-
value,
|
|
4016
|
+
return parseCalldataValue({
|
|
4017
|
+
element: value,
|
|
2369
4018
|
type,
|
|
2370
4019
|
structs,
|
|
2371
|
-
enums
|
|
2372
|
-
|
|
4020
|
+
enums,
|
|
4021
|
+
parser
|
|
4022
|
+
});
|
|
2373
4023
|
// Felt or unhandled
|
|
2374
4024
|
default:
|
|
2375
|
-
return parseBaseTypes(type, value);
|
|
4025
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
2376
4026
|
}
|
|
2377
4027
|
}
|
|
2378
4028
|
|
|
2379
4029
|
// src/utils/calldata/responseParser.ts
|
|
2380
|
-
function parseBaseTypes2(type, it) {
|
|
4030
|
+
function parseBaseTypes2(type, it, parser) {
|
|
2381
4031
|
let temp;
|
|
2382
4032
|
switch (true) {
|
|
2383
4033
|
case isTypeBool(type):
|
|
2384
4034
|
temp = it.next().value;
|
|
2385
4035
|
return Boolean(BigInt(temp));
|
|
2386
4036
|
case CairoUint256.isAbiType(type):
|
|
2387
|
-
|
|
2388
|
-
const high = it.next().value;
|
|
2389
|
-
return new CairoUint256(low, high).toBigInt();
|
|
4037
|
+
return parser.getResponseParser(type)(it);
|
|
2390
4038
|
case CairoUint512.isAbiType(type):
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
return
|
|
4039
|
+
return parser.getResponseParser(type)(it);
|
|
4040
|
+
case CairoUint8.isAbiType(type):
|
|
4041
|
+
return parser.getResponseParser(type)(it);
|
|
4042
|
+
case CairoUint16.isAbiType(type):
|
|
4043
|
+
return parser.getResponseParser(type)(it);
|
|
4044
|
+
case CairoUint64.isAbiType(type):
|
|
4045
|
+
return parser.getResponseParser(type)(it);
|
|
4046
|
+
case CairoUint96.isAbiType(type):
|
|
4047
|
+
return parser.getResponseParser(type)(it);
|
|
4048
|
+
case CairoUint128.isAbiType(type):
|
|
4049
|
+
return parser.getResponseParser(type)(it);
|
|
4050
|
+
case CairoInt8.isAbiType(type):
|
|
4051
|
+
return parser.getResponseParser(type)(it);
|
|
4052
|
+
case CairoInt16.isAbiType(type):
|
|
4053
|
+
return parser.getResponseParser(type)(it);
|
|
4054
|
+
case CairoInt32.isAbiType(type):
|
|
4055
|
+
return parser.getResponseParser(type)(it);
|
|
4056
|
+
case CairoInt64.isAbiType(type):
|
|
4057
|
+
return parser.getResponseParser(type)(it);
|
|
4058
|
+
case CairoInt128.isAbiType(type):
|
|
4059
|
+
return parser.getResponseParser(type)(it);
|
|
2396
4060
|
case isTypeEthAddress(type):
|
|
2397
4061
|
temp = it.next().value;
|
|
2398
4062
|
return BigInt(temp);
|
|
2399
|
-
case
|
|
2400
|
-
|
|
2401
|
-
return decodeShortString(temp);
|
|
4063
|
+
case CairoBytes31.isAbiType(type):
|
|
4064
|
+
return parser.getResponseParser(type)(it);
|
|
2402
4065
|
case isTypeSecp256k1Point(type):
|
|
2403
4066
|
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2404
4067
|
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
@@ -2407,47 +4070,28 @@ function parseBaseTypes2(type, it) {
|
|
|
2407
4070
|
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
2408
4071
|
return pubK;
|
|
2409
4072
|
default:
|
|
2410
|
-
|
|
2411
|
-
return BigInt(temp);
|
|
4073
|
+
return parser.getResponseParser(CairoFelt252.abiSelector)(it);
|
|
2412
4074
|
}
|
|
2413
4075
|
}
|
|
2414
|
-
function parseResponseValue(responseIterator, element, structs, enums) {
|
|
4076
|
+
function parseResponseValue(responseIterator, element, parser, structs, enums) {
|
|
2415
4077
|
if (element.type === "()") {
|
|
2416
4078
|
return {};
|
|
2417
4079
|
}
|
|
2418
4080
|
if (CairoUint256.isAbiType(element.type)) {
|
|
2419
|
-
|
|
2420
|
-
const high = responseIterator.next().value;
|
|
2421
|
-
return new CairoUint256(low, high).toBigInt();
|
|
4081
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
2422
4082
|
}
|
|
2423
4083
|
if (CairoUint512.isAbiType(element.type)) {
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
2429
|
-
}
|
|
2430
|
-
if (isTypeByteArray(element.type)) {
|
|
2431
|
-
const parsedBytes31Arr = [];
|
|
2432
|
-
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
2433
|
-
while (parsedBytes31Arr.length < bytes31ArrLen) {
|
|
2434
|
-
parsedBytes31Arr.push(toHex(responseIterator.next().value));
|
|
2435
|
-
}
|
|
2436
|
-
const pending_word = toHex(responseIterator.next().value);
|
|
2437
|
-
const pending_word_len = BigInt(responseIterator.next().value);
|
|
2438
|
-
const myByteArray = {
|
|
2439
|
-
data: parsedBytes31Arr,
|
|
2440
|
-
pending_word,
|
|
2441
|
-
pending_word_len
|
|
2442
|
-
};
|
|
2443
|
-
return stringFromByteArray(myByteArray);
|
|
4084
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
4085
|
+
}
|
|
4086
|
+
if (CairoByteArray.isAbiType(element.type)) {
|
|
4087
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
2444
4088
|
}
|
|
2445
4089
|
if (CairoFixedArray.isTypeFixedArray(element.type)) {
|
|
2446
4090
|
const parsedDataArr = [];
|
|
2447
4091
|
const el = { name: "", type: CairoFixedArray.getFixedArrayType(element.type) };
|
|
2448
4092
|
const arraySize = CairoFixedArray.getFixedArraySize(element.type);
|
|
2449
4093
|
while (parsedDataArr.length < arraySize) {
|
|
2450
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
4094
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2451
4095
|
}
|
|
2452
4096
|
return parsedDataArr;
|
|
2453
4097
|
}
|
|
@@ -2456,20 +4100,20 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2456
4100
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2457
4101
|
const len = BigInt(responseIterator.next().value);
|
|
2458
4102
|
while (parsedDataArr.length < len) {
|
|
2459
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
4103
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2460
4104
|
}
|
|
2461
4105
|
return parsedDataArr;
|
|
2462
4106
|
}
|
|
2463
4107
|
if (isTypeNonZero(element.type)) {
|
|
2464
4108
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2465
|
-
return parseResponseValue(responseIterator, el, structs, enums);
|
|
4109
|
+
return parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2466
4110
|
}
|
|
2467
4111
|
if (structs && element.type in structs && structs[element.type]) {
|
|
2468
4112
|
if (isTypeEthAddress(element.type)) {
|
|
2469
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
4113
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
2470
4114
|
}
|
|
2471
4115
|
return structs[element.type].members.reduce((acc, el) => {
|
|
2472
|
-
acc[el.name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
4116
|
+
acc[el.name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2473
4117
|
return acc;
|
|
2474
4118
|
}, {});
|
|
2475
4119
|
}
|
|
@@ -2480,6 +4124,7 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2480
4124
|
acc[variant.name] = parseResponseValue(
|
|
2481
4125
|
responseIterator,
|
|
2482
4126
|
{ name: "", type: variant.type },
|
|
4127
|
+
parser,
|
|
2483
4128
|
structs,
|
|
2484
4129
|
enums
|
|
2485
4130
|
);
|
|
@@ -2510,7 +4155,7 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2510
4155
|
const name = it?.name ? it.name : idx;
|
|
2511
4156
|
const type = it?.type ? it.type : it;
|
|
2512
4157
|
const el = { name, type };
|
|
2513
|
-
acc[name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
4158
|
+
acc[name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2514
4159
|
return acc;
|
|
2515
4160
|
}, {});
|
|
2516
4161
|
}
|
|
@@ -2519,13 +4164,20 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2519
4164
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2520
4165
|
const len = BigInt(responseIterator.next().value);
|
|
2521
4166
|
while (parsedDataArr.length < len) {
|
|
2522
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
4167
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2523
4168
|
}
|
|
2524
4169
|
return parsedDataArr;
|
|
2525
4170
|
}
|
|
2526
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
4171
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
2527
4172
|
}
|
|
2528
|
-
function responseParser(
|
|
4173
|
+
function responseParser({
|
|
4174
|
+
responseIterator,
|
|
4175
|
+
output,
|
|
4176
|
+
structs,
|
|
4177
|
+
enums,
|
|
4178
|
+
parsedResult,
|
|
4179
|
+
parser
|
|
4180
|
+
}) {
|
|
2529
4181
|
const { name, type } = output;
|
|
2530
4182
|
let temp;
|
|
2531
4183
|
switch (true) {
|
|
@@ -2533,14 +4185,14 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2533
4185
|
temp = responseIterator.next().value;
|
|
2534
4186
|
return BigInt(temp);
|
|
2535
4187
|
case (structs && type in structs || isTypeTuple(type)):
|
|
2536
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4188
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2537
4189
|
case (enums && isTypeEnum(type, enums)):
|
|
2538
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4190
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2539
4191
|
case CairoFixedArray.isTypeFixedArray(type):
|
|
2540
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4192
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2541
4193
|
case isTypeArray(type):
|
|
2542
4194
|
if (isCairo1Type(type)) {
|
|
2543
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4195
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2544
4196
|
}
|
|
2545
4197
|
const parsedDataArr = [];
|
|
2546
4198
|
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
@@ -2550,6 +4202,7 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2550
4202
|
parseResponseValue(
|
|
2551
4203
|
responseIterator,
|
|
2552
4204
|
{ name, type: output.type.replace("*", "") },
|
|
4205
|
+
parser,
|
|
2553
4206
|
structs,
|
|
2554
4207
|
enums
|
|
2555
4208
|
)
|
|
@@ -2558,9 +4211,9 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2558
4211
|
}
|
|
2559
4212
|
return parsedDataArr;
|
|
2560
4213
|
case isTypeNonZero(type):
|
|
2561
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4214
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2562
4215
|
default:
|
|
2563
|
-
return parseBaseTypes2(type, responseIterator);
|
|
4216
|
+
return parseBaseTypes2(type, responseIterator, parser);
|
|
2564
4217
|
}
|
|
2565
4218
|
}
|
|
2566
4219
|
|
|
@@ -2578,16 +4231,6 @@ var validateFelt = (parameter, input) => {
|
|
|
2578
4231
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
2579
4232
|
);
|
|
2580
4233
|
};
|
|
2581
|
-
var validateBytes31 = (parameter, input) => {
|
|
2582
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
2583
|
-
assert(
|
|
2584
|
-
parameter.length < 32,
|
|
2585
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
2586
|
-
);
|
|
2587
|
-
};
|
|
2588
|
-
var validateByteArray = (parameter, input) => {
|
|
2589
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
2590
|
-
};
|
|
2591
4234
|
var validateUint = (parameter, input) => {
|
|
2592
4235
|
if (isNumber(parameter)) {
|
|
2593
4236
|
assert(
|
|
@@ -2839,8 +4482,8 @@ function validateFields(abiMethod, args, structs, enums) {
|
|
|
2839
4482
|
case isTypeFelt(input.type):
|
|
2840
4483
|
validateFelt(parameter, input);
|
|
2841
4484
|
break;
|
|
2842
|
-
case
|
|
2843
|
-
|
|
4485
|
+
case CairoBytes31.isAbiType(input.type):
|
|
4486
|
+
CairoBytes31.validate(parameter);
|
|
2844
4487
|
break;
|
|
2845
4488
|
case (isTypeUint(input.type) || isTypeLiteral(input.type)):
|
|
2846
4489
|
validateUint(parameter, input);
|
|
@@ -2848,8 +4491,23 @@ function validateFields(abiMethod, args, structs, enums) {
|
|
|
2848
4491
|
case isTypeBool(input.type):
|
|
2849
4492
|
validateBool(parameter, input);
|
|
2850
4493
|
break;
|
|
2851
|
-
case
|
|
2852
|
-
|
|
4494
|
+
case CairoByteArray.isAbiType(input.type):
|
|
4495
|
+
CairoByteArray.validate(parameter);
|
|
4496
|
+
break;
|
|
4497
|
+
case CairoInt8.isAbiType(input.type):
|
|
4498
|
+
CairoInt8.validate(parameter);
|
|
4499
|
+
break;
|
|
4500
|
+
case CairoInt16.isAbiType(input.type):
|
|
4501
|
+
CairoInt16.validate(parameter);
|
|
4502
|
+
break;
|
|
4503
|
+
case CairoInt32.isAbiType(input.type):
|
|
4504
|
+
CairoInt32.validate(parameter);
|
|
4505
|
+
break;
|
|
4506
|
+
case CairoInt64.isAbiType(input.type):
|
|
4507
|
+
CairoInt64.validate(parameter);
|
|
4508
|
+
break;
|
|
4509
|
+
case CairoInt128.isAbiType(input.type):
|
|
4510
|
+
CairoInt128.validate(parameter);
|
|
2853
4511
|
break;
|
|
2854
4512
|
case (isTypeArray(input.type) || CairoFixedArray.isTypeFixedArray(input.type)):
|
|
2855
4513
|
validateArray(parameter, input, structs, enums);
|
|
@@ -2881,10 +4539,10 @@ var CallData = class _CallData {
|
|
|
2881
4539
|
parser;
|
|
2882
4540
|
structs;
|
|
2883
4541
|
enums;
|
|
2884
|
-
constructor(abi) {
|
|
4542
|
+
constructor(abi, parsingStrategy) {
|
|
2885
4543
|
this.structs = _CallData.getAbiStruct(abi);
|
|
2886
4544
|
this.enums = _CallData.getAbiEnum(abi);
|
|
2887
|
-
this.parser = createAbiParser(abi);
|
|
4545
|
+
this.parser = createAbiParser(abi, parsingStrategy);
|
|
2888
4546
|
this.abi = this.parser.getLegacyFormat();
|
|
2889
4547
|
}
|
|
2890
4548
|
/**
|
|
@@ -2953,7 +4611,15 @@ var CallData = class _CallData {
|
|
|
2953
4611
|
}
|
|
2954
4612
|
const argsIterator = args[Symbol.iterator]();
|
|
2955
4613
|
const callArray = abiMethod.inputs.reduce(
|
|
2956
|
-
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
4614
|
+
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
4615
|
+
parseCalldataField({
|
|
4616
|
+
argsIterator,
|
|
4617
|
+
input,
|
|
4618
|
+
structs: this.structs,
|
|
4619
|
+
enums: this.enums,
|
|
4620
|
+
parser: this.parser
|
|
4621
|
+
})
|
|
4622
|
+
),
|
|
2957
4623
|
[]
|
|
2958
4624
|
);
|
|
2959
4625
|
Object.defineProperty(callArray, "__compiled__", {
|
|
@@ -3040,7 +4706,14 @@ var CallData = class _CallData {
|
|
|
3040
4706
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3041
4707
|
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3042
4708
|
const propName = output.name ?? idx;
|
|
3043
|
-
acc[propName] = responseParser(
|
|
4709
|
+
acc[propName] = responseParser({
|
|
4710
|
+
responseIterator,
|
|
4711
|
+
output,
|
|
4712
|
+
structs: this.structs,
|
|
4713
|
+
enums: this.enums,
|
|
4714
|
+
parsedResult: acc,
|
|
4715
|
+
parser: this.parser
|
|
4716
|
+
});
|
|
3044
4717
|
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3045
4718
|
delete acc[`${propName}_len`];
|
|
3046
4719
|
}
|
|
@@ -3120,12 +4793,13 @@ var CallData = class _CallData {
|
|
|
3120
4793
|
const typeCairoArray = Array.isArray(typeCairo) ? typeCairo : [typeCairo];
|
|
3121
4794
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3122
4795
|
const decodedArray = typeCairoArray.map(
|
|
3123
|
-
(typeParam) => responseParser(
|
|
4796
|
+
(typeParam) => responseParser({
|
|
3124
4797
|
responseIterator,
|
|
3125
|
-
{ name: "", type: typeParam },
|
|
3126
|
-
this.
|
|
3127
|
-
this.
|
|
3128
|
-
|
|
4798
|
+
output: { name: "", type: typeParam },
|
|
4799
|
+
parser: this.parser,
|
|
4800
|
+
structs: this.structs,
|
|
4801
|
+
enums: this.enums
|
|
4802
|
+
})
|
|
3129
4803
|
);
|
|
3130
4804
|
return decodedArray.length === 1 ? decodedArray[0] : decodedArray;
|
|
3131
4805
|
}
|
|
@@ -3810,114 +5484,6 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
|
3810
5484
|
return { ...contract, program: decompressProgram(contract.program) };
|
|
3811
5485
|
}
|
|
3812
5486
|
|
|
3813
|
-
// src/utils/errors/rpc.ts
|
|
3814
|
-
var errorCodes = {
|
|
3815
|
-
FAILED_TO_RECEIVE_TXN: 1,
|
|
3816
|
-
NO_TRACE_AVAILABLE: 10,
|
|
3817
|
-
CONTRACT_NOT_FOUND: 20,
|
|
3818
|
-
ENTRYPOINT_NOT_FOUND: 21,
|
|
3819
|
-
BLOCK_NOT_FOUND: 24,
|
|
3820
|
-
INVALID_TXN_INDEX: 27,
|
|
3821
|
-
CLASS_HASH_NOT_FOUND: 28,
|
|
3822
|
-
TXN_HASH_NOT_FOUND: 29,
|
|
3823
|
-
PAGE_SIZE_TOO_BIG: 31,
|
|
3824
|
-
NO_BLOCKS: 32,
|
|
3825
|
-
INVALID_CONTINUATION_TOKEN: 33,
|
|
3826
|
-
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
3827
|
-
CONTRACT_ERROR: 40,
|
|
3828
|
-
TRANSACTION_EXECUTION_ERROR: 41,
|
|
3829
|
-
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
3830
|
-
CLASS_ALREADY_DECLARED: 51,
|
|
3831
|
-
INVALID_TRANSACTION_NONCE: 52,
|
|
3832
|
-
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
3833
|
-
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
3834
|
-
VALIDATION_FAILURE: 55,
|
|
3835
|
-
COMPILATION_FAILED: 56,
|
|
3836
|
-
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
3837
|
-
NON_ACCOUNT: 58,
|
|
3838
|
-
DUPLICATE_TX: 59,
|
|
3839
|
-
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
3840
|
-
UNSUPPORTED_TX_VERSION: 61,
|
|
3841
|
-
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
3842
|
-
UNEXPECTED_ERROR: 63,
|
|
3843
|
-
INVALID_SUBSCRIPTION_ID: 66,
|
|
3844
|
-
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
3845
|
-
TOO_MANY_BLOCKS_BACK: 68,
|
|
3846
|
-
COMPILATION_ERROR: 100,
|
|
3847
|
-
INVALID_ADDRESS: 150,
|
|
3848
|
-
TOKEN_NOT_SUPPORTED: 151,
|
|
3849
|
-
INVALID_SIGNATURE: 153,
|
|
3850
|
-
MAX_AMOUNT_TOO_LOW: 154,
|
|
3851
|
-
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
3852
|
-
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
3853
|
-
INVALID_TIME_BOUNDS: 157,
|
|
3854
|
-
INVALID_DEPLOYMENT_DATA: 158,
|
|
3855
|
-
INVALID_CLASS_HASH: 159,
|
|
3856
|
-
INVALID_ID: 160,
|
|
3857
|
-
UNKNOWN_ERROR: 163
|
|
3858
|
-
};
|
|
3859
|
-
var rpc_default = errorCodes;
|
|
3860
|
-
|
|
3861
|
-
// src/utils/errors/index.ts
|
|
3862
|
-
function fixStack(target, fn = target.constructor) {
|
|
3863
|
-
const { captureStackTrace } = Error;
|
|
3864
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
3865
|
-
}
|
|
3866
|
-
function fixProto(target, prototype) {
|
|
3867
|
-
const { setPrototypeOf } = Object;
|
|
3868
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3869
|
-
}
|
|
3870
|
-
var CustomError = class extends Error {
|
|
3871
|
-
name;
|
|
3872
|
-
constructor(message) {
|
|
3873
|
-
super(message);
|
|
3874
|
-
Object.defineProperty(this, "name", {
|
|
3875
|
-
value: new.target.name,
|
|
3876
|
-
enumerable: false,
|
|
3877
|
-
configurable: true
|
|
3878
|
-
});
|
|
3879
|
-
fixProto(this, new.target.prototype);
|
|
3880
|
-
fixStack(this);
|
|
3881
|
-
}
|
|
3882
|
-
};
|
|
3883
|
-
var LibraryError = class extends CustomError {
|
|
3884
|
-
};
|
|
3885
|
-
var RpcError = class extends LibraryError {
|
|
3886
|
-
constructor(baseError, method, params) {
|
|
3887
|
-
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
3888
|
-
|
|
3889
|
-
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
3890
|
-
this.baseError = baseError;
|
|
3891
|
-
this.request = { method, params };
|
|
3892
|
-
}
|
|
3893
|
-
request;
|
|
3894
|
-
get code() {
|
|
3895
|
-
return this.baseError.code;
|
|
3896
|
-
}
|
|
3897
|
-
/**
|
|
3898
|
-
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
3899
|
-
* @example
|
|
3900
|
-
* ```typescript
|
|
3901
|
-
* SomeError.isType('UNEXPECTED_ERROR');
|
|
3902
|
-
* ```
|
|
3903
|
-
*/
|
|
3904
|
-
isType(typeName) {
|
|
3905
|
-
return rpc_default[typeName] === this.code;
|
|
3906
|
-
}
|
|
3907
|
-
};
|
|
3908
|
-
var TimeoutError = class extends LibraryError {
|
|
3909
|
-
constructor(message) {
|
|
3910
|
-
super(message);
|
|
3911
|
-
this.name = "TimeoutError";
|
|
3912
|
-
}
|
|
3913
|
-
};
|
|
3914
|
-
var WebSocketNotConnectedError = class extends LibraryError {
|
|
3915
|
-
constructor(message) {
|
|
3916
|
-
super(message);
|
|
3917
|
-
this.name = "WebSocketNotConnectedError";
|
|
3918
|
-
}
|
|
3919
|
-
};
|
|
3920
|
-
|
|
3921
5487
|
// src/utils/eth.ts
|
|
3922
5488
|
var eth_exports = {};
|
|
3923
5489
|
__export(eth_exports, {
|
|
@@ -4056,7 +5622,7 @@ var Block = class {
|
|
|
4056
5622
|
tag = null;
|
|
4057
5623
|
setIdentifier(__identifier) {
|
|
4058
5624
|
if (isString(__identifier)) {
|
|
4059
|
-
if (
|
|
5625
|
+
if (isDecimalString2(__identifier)) {
|
|
4060
5626
|
this.number = parseInt(__identifier, 10);
|
|
4061
5627
|
} else if (isHex(__identifier)) {
|
|
4062
5628
|
this.hash = __identifier;
|
|
@@ -4505,11 +6071,13 @@ var RpcChannel = class {
|
|
|
4505
6071
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L2,
|
|
4506
6072
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L1
|
|
4507
6073
|
];
|
|
6074
|
+
const txLife = [];
|
|
4508
6075
|
let txStatus;
|
|
4509
6076
|
while (!onchain) {
|
|
4510
6077
|
await wait(retryInterval);
|
|
4511
6078
|
try {
|
|
4512
6079
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
6080
|
+
txLife.push(txStatus.finality_status);
|
|
4513
6081
|
const executionStatus = txStatus.execution_status;
|
|
4514
6082
|
const finalityStatus = txStatus.finality_status;
|
|
4515
6083
|
if (!finalityStatus) {
|
|
@@ -4529,6 +6097,18 @@ var RpcChannel = class {
|
|
|
4529
6097
|
if (error instanceof Error && isErrorState) {
|
|
4530
6098
|
throw error;
|
|
4531
6099
|
}
|
|
6100
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
6101
|
+
logger.info("txLife: ", txLife);
|
|
6102
|
+
const errorMessages = {
|
|
6103
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
6104
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
6105
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
6106
|
+
};
|
|
6107
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
6108
|
+
if (errorMessage) {
|
|
6109
|
+
throw new Error(errorMessage);
|
|
6110
|
+
}
|
|
6111
|
+
}
|
|
4532
6112
|
if (retries <= 0) {
|
|
4533
6113
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
4534
6114
|
}
|
|
@@ -5078,11 +6658,13 @@ var RpcChannel2 = class {
|
|
|
5078
6658
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
5079
6659
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1
|
|
5080
6660
|
];
|
|
6661
|
+
const txLife = [];
|
|
5081
6662
|
let txStatus;
|
|
5082
6663
|
while (!onchain) {
|
|
5083
6664
|
await wait(retryInterval);
|
|
5084
6665
|
try {
|
|
5085
6666
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
6667
|
+
txLife.push(txStatus.finality_status);
|
|
5086
6668
|
const executionStatus = txStatus.execution_status;
|
|
5087
6669
|
const finalityStatus = txStatus.finality_status;
|
|
5088
6670
|
if (!finalityStatus) {
|
|
@@ -5102,6 +6684,18 @@ var RpcChannel2 = class {
|
|
|
5102
6684
|
if (error instanceof Error && isErrorState) {
|
|
5103
6685
|
throw error;
|
|
5104
6686
|
}
|
|
6687
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
6688
|
+
logger.info("txLife: ", txLife);
|
|
6689
|
+
const errorMessages = {
|
|
6690
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
6691
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
6692
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
6693
|
+
};
|
|
6694
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
6695
|
+
if (errorMessage) {
|
|
6696
|
+
throw new Error(errorMessage);
|
|
6697
|
+
}
|
|
6698
|
+
}
|
|
5105
6699
|
if (retries <= 0) {
|
|
5106
6700
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
5107
6701
|
}
|
|
@@ -5445,7 +7039,7 @@ var Subscription = class {
|
|
|
5445
7039
|
}
|
|
5446
7040
|
};
|
|
5447
7041
|
|
|
5448
|
-
// src/channel/ws/
|
|
7042
|
+
// src/channel/ws/ws_0_9.ts
|
|
5449
7043
|
var WebSocketChannel = class {
|
|
5450
7044
|
/**
|
|
5451
7045
|
* The URL of the WebSocket RPC Node.
|
|
@@ -5793,19 +7387,19 @@ var WebSocketChannel = class {
|
|
|
5793
7387
|
}
|
|
5794
7388
|
/**
|
|
5795
7389
|
* Subscribes to new block headers.
|
|
5796
|
-
* @param {
|
|
7390
|
+
* @param {SubscribeNewHeadsParams} params - The parameters for the subscription.
|
|
5797
7391
|
* @returns {Promise<Subscription<BLOCK_HEADER>>} A Promise that resolves with a `Subscription` object for new block headers.
|
|
5798
7392
|
*/
|
|
5799
|
-
async subscribeNewHeads(
|
|
7393
|
+
async subscribeNewHeads(params = {}) {
|
|
5800
7394
|
const method = "starknet_subscribeNewHeads";
|
|
5801
|
-
const
|
|
5802
|
-
block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
|
|
7395
|
+
const rpcParams = {
|
|
7396
|
+
block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0
|
|
5803
7397
|
};
|
|
5804
|
-
const subId = await this.sendReceive(method,
|
|
7398
|
+
const subId = await this.sendReceive(method, rpcParams);
|
|
5805
7399
|
const subscription = new Subscription({
|
|
5806
7400
|
channel: this,
|
|
5807
7401
|
method,
|
|
5808
|
-
params,
|
|
7402
|
+
params: rpcParams,
|
|
5809
7403
|
id: subId,
|
|
5810
7404
|
maxBufferSize: this.maxBufferSize
|
|
5811
7405
|
});
|
|
@@ -5814,23 +7408,22 @@ var WebSocketChannel = class {
|
|
|
5814
7408
|
}
|
|
5815
7409
|
/**
|
|
5816
7410
|
* Subscribes to events matching a given filter.
|
|
5817
|
-
* @param {
|
|
5818
|
-
* @param {string[][]} [keys] - The event keys to filter by.
|
|
5819
|
-
* @param {SubscriptionBlockIdentifier} [blockIdentifier] - The block to start receiving notifications from. Defaults to 'latest'.
|
|
7411
|
+
* @param {SubscribeEventsParams} params - The parameters for the subscription.
|
|
5820
7412
|
* @returns {Promise<Subscription<EMITTED_EVENT>>} A Promise that resolves with a `Subscription` object for the specified events.
|
|
5821
7413
|
*/
|
|
5822
|
-
async subscribeEvents(
|
|
7414
|
+
async subscribeEvents(params = {}) {
|
|
5823
7415
|
const method = "starknet_subscribeEvents";
|
|
5824
|
-
const
|
|
5825
|
-
from_address: fromAddress !== void 0 ? toHex(fromAddress) : void 0,
|
|
5826
|
-
keys,
|
|
5827
|
-
block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
|
|
7416
|
+
const rpcParams = {
|
|
7417
|
+
from_address: params.fromAddress !== void 0 ? toHex(params.fromAddress) : void 0,
|
|
7418
|
+
keys: params.keys,
|
|
7419
|
+
block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0,
|
|
7420
|
+
finality_status: params.finalityStatus
|
|
5828
7421
|
};
|
|
5829
|
-
const subId = await this.sendReceive(method,
|
|
7422
|
+
const subId = await this.sendReceive(method, rpcParams);
|
|
5830
7423
|
const subscription = new Subscription({
|
|
5831
7424
|
channel: this,
|
|
5832
7425
|
method,
|
|
5833
|
-
params,
|
|
7426
|
+
params: rpcParams,
|
|
5834
7427
|
id: subId,
|
|
5835
7428
|
maxBufferSize: this.maxBufferSize
|
|
5836
7429
|
});
|
|
@@ -5839,21 +7432,20 @@ var WebSocketChannel = class {
|
|
|
5839
7432
|
}
|
|
5840
7433
|
/**
|
|
5841
7434
|
* Subscribes to status updates for a specific transaction.
|
|
5842
|
-
* @param {
|
|
5843
|
-
* @param {SubscriptionBlockIdentifier} [blockIdentifier] - The block context. Not typically required.
|
|
7435
|
+
* @param {SubscribeTransactionStatusParams} params - The parameters for the subscription.
|
|
5844
7436
|
* @returns {Promise<Subscription<NEW_TXN_STATUS>>} A Promise that resolves with a `Subscription` object for the transaction's status.
|
|
5845
7437
|
*/
|
|
5846
|
-
async subscribeTransactionStatus(
|
|
7438
|
+
async subscribeTransactionStatus(params) {
|
|
5847
7439
|
const method = "starknet_subscribeTransactionStatus";
|
|
5848
|
-
const
|
|
5849
|
-
transaction_hash: toHex(transactionHash),
|
|
5850
|
-
block_id: blockIdentifier ? new Block(blockIdentifier).identifier : void 0
|
|
7440
|
+
const rpcParams = {
|
|
7441
|
+
transaction_hash: toHex(params.transactionHash),
|
|
7442
|
+
block_id: params.blockIdentifier ? new Block(params.blockIdentifier).identifier : void 0
|
|
5851
7443
|
};
|
|
5852
|
-
const subId = await this.sendReceive(method,
|
|
7444
|
+
const subId = await this.sendReceive(method, rpcParams);
|
|
5853
7445
|
const subscription = new Subscription({
|
|
5854
7446
|
channel: this,
|
|
5855
7447
|
method,
|
|
5856
|
-
params,
|
|
7448
|
+
params: rpcParams,
|
|
5857
7449
|
id: subId,
|
|
5858
7450
|
maxBufferSize: this.maxBufferSize
|
|
5859
7451
|
});
|
|
@@ -5861,22 +7453,43 @@ var WebSocketChannel = class {
|
|
|
5861
7453
|
return subscription;
|
|
5862
7454
|
}
|
|
5863
7455
|
/**
|
|
5864
|
-
* Subscribes to
|
|
5865
|
-
* @param {
|
|
5866
|
-
* @
|
|
5867
|
-
* @returns {Promise<Subscription<TXN_HASH | TXN_WITH_HASH>>} A Promise that resolves with a `Subscription` object for pending transactions.
|
|
7456
|
+
* Subscribes to new transaction receipts.
|
|
7457
|
+
* @param {SubscribeNewTransactionReceiptsParams} params - The parameters for the subscription.
|
|
7458
|
+
* @returns {Promise<Subscription<NewTransactionReceiptsEvent['result']>>} A Promise that resolves with a `Subscription` object for new transaction receipts.
|
|
5868
7459
|
*/
|
|
5869
|
-
async
|
|
5870
|
-
const method = "
|
|
5871
|
-
const
|
|
5872
|
-
|
|
5873
|
-
sender_address: senderAddress && bigNumberishArrayToHexadecimalStringArray(senderAddress)
|
|
7460
|
+
async subscribeNewTransactionReceipts(params = {}) {
|
|
7461
|
+
const method = "starknet_subscribeNewTransactionReceipts";
|
|
7462
|
+
const rpcParams = {
|
|
7463
|
+
finality_status: params.finalityStatus,
|
|
7464
|
+
sender_address: params.senderAddress && bigNumberishArrayToHexadecimalStringArray(params.senderAddress)
|
|
7465
|
+
};
|
|
7466
|
+
const subId = await this.sendReceive(method, rpcParams);
|
|
7467
|
+
const subscription = new Subscription({
|
|
7468
|
+
channel: this,
|
|
7469
|
+
method,
|
|
7470
|
+
params: rpcParams,
|
|
7471
|
+
id: subId,
|
|
7472
|
+
maxBufferSize: this.maxBufferSize
|
|
7473
|
+
});
|
|
7474
|
+
this.activeSubscriptions.set(subId, subscription);
|
|
7475
|
+
return subscription;
|
|
7476
|
+
}
|
|
7477
|
+
/**
|
|
7478
|
+
* Subscribes to new transactions.
|
|
7479
|
+
* @param {SubscribeNewTransactionsParams} params - The parameters for the subscription.
|
|
7480
|
+
* @returns {Promise<Subscription<NewTransactionEvent['result']>>} A Promise that resolves with a `Subscription` object for new transactions.
|
|
7481
|
+
*/
|
|
7482
|
+
async subscribeNewTransactions(params = {}) {
|
|
7483
|
+
const method = "starknet_subscribeNewTransactions";
|
|
7484
|
+
const rpcParams = {
|
|
7485
|
+
finality_status: params.finalityStatus,
|
|
7486
|
+
sender_address: params.senderAddress && bigNumberishArrayToHexadecimalStringArray(params.senderAddress)
|
|
5874
7487
|
};
|
|
5875
|
-
const subId = await this.sendReceive(method,
|
|
7488
|
+
const subId = await this.sendReceive(method, rpcParams);
|
|
5876
7489
|
const subscription = new Subscription({
|
|
5877
7490
|
channel: this,
|
|
5878
7491
|
method,
|
|
5879
|
-
params,
|
|
7492
|
+
params: rpcParams,
|
|
5880
7493
|
id: subId,
|
|
5881
7494
|
maxBufferSize: this.maxBufferSize
|
|
5882
7495
|
});
|
|
@@ -6147,56 +7760,123 @@ var ReceiptTx = class _ReceiptTx {
|
|
|
6147
7760
|
statusReceipt;
|
|
6148
7761
|
value;
|
|
6149
7762
|
constructor(receipt) {
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
}
|
|
6156
|
-
for (const [key, value] of Object.entries(receipt)) {
|
|
6157
|
-
Object.defineProperty(this, key, {
|
|
6158
|
-
enumerable: true,
|
|
7763
|
+
Object.assign(this, receipt);
|
|
7764
|
+
const [statusReceipt, value] = _ReceiptTx.isSuccess(receipt) ? ["SUCCEEDED", receipt] : _ReceiptTx.isReverted(receipt) ? ["REVERTED", receipt] : ["ERROR", new Error("Unknown response type")];
|
|
7765
|
+
Object.defineProperties(this, {
|
|
7766
|
+
statusReceipt: {
|
|
7767
|
+
value: statusReceipt,
|
|
6159
7768
|
writable: false,
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
7769
|
+
enumerable: false,
|
|
7770
|
+
configurable: false
|
|
7771
|
+
},
|
|
7772
|
+
value: {
|
|
7773
|
+
value,
|
|
7774
|
+
writable: false,
|
|
7775
|
+
enumerable: false,
|
|
7776
|
+
configurable: false
|
|
7777
|
+
},
|
|
7778
|
+
match: {
|
|
7779
|
+
value(callbacks) {
|
|
7780
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
7781
|
+
},
|
|
7782
|
+
writable: false,
|
|
7783
|
+
enumerable: false,
|
|
7784
|
+
configurable: false
|
|
7785
|
+
},
|
|
7786
|
+
isSuccess: {
|
|
7787
|
+
value: () => statusReceipt === "SUCCEEDED",
|
|
7788
|
+
writable: false,
|
|
7789
|
+
enumerable: false,
|
|
7790
|
+
configurable: false
|
|
7791
|
+
},
|
|
7792
|
+
isReverted: {
|
|
7793
|
+
value: () => statusReceipt === "REVERTED",
|
|
7794
|
+
writable: false,
|
|
7795
|
+
enumerable: false,
|
|
7796
|
+
configurable: false
|
|
7797
|
+
},
|
|
7798
|
+
isError: {
|
|
7799
|
+
value: () => statusReceipt === "ERROR",
|
|
7800
|
+
writable: false,
|
|
7801
|
+
enumerable: false,
|
|
7802
|
+
configurable: false
|
|
7803
|
+
}
|
|
7804
|
+
});
|
|
6183
7805
|
}
|
|
7806
|
+
match;
|
|
7807
|
+
isSuccess;
|
|
7808
|
+
isReverted;
|
|
7809
|
+
isError;
|
|
6184
7810
|
static isSuccess(transactionReceipt) {
|
|
6185
7811
|
return transactionReceipt.execution_status === TransactionExecutionStatus.SUCCEEDED;
|
|
6186
7812
|
}
|
|
6187
7813
|
static isReverted(transactionReceipt) {
|
|
6188
7814
|
return transactionReceipt.execution_status === TransactionExecutionStatus.REVERTED;
|
|
6189
7815
|
}
|
|
6190
|
-
// Status do not exist on receipts
|
|
6191
|
-
/* static isRejected(
|
|
6192
|
-
transactionReceipt: GetTxReceiptResponseWithoutHelper
|
|
6193
|
-
): transactionReceipt is RejectedTransactionReceiptResponse {
|
|
6194
|
-
return (
|
|
6195
|
-
(transactionReceipt as RejectedTransactionReceiptResponse).status ===
|
|
6196
|
-
TransactionExecutionStatus.REJECTED
|
|
6197
|
-
);
|
|
6198
|
-
} */
|
|
6199
7816
|
};
|
|
7817
|
+
var RECEIPT_CONFIG = {
|
|
7818
|
+
[TransactionExecutionStatus.SUCCEEDED]: {
|
|
7819
|
+
statusReceipt: "SUCCEEDED",
|
|
7820
|
+
getBaseData: (receipt) => receipt,
|
|
7821
|
+
getValue: (receipt) => receipt
|
|
7822
|
+
},
|
|
7823
|
+
[TransactionExecutionStatus.REVERTED]: {
|
|
7824
|
+
statusReceipt: "REVERTED",
|
|
7825
|
+
getBaseData: (receipt) => receipt,
|
|
7826
|
+
getValue: (receipt) => receipt
|
|
7827
|
+
}
|
|
7828
|
+
};
|
|
7829
|
+
function createTransactionReceipt(receipt) {
|
|
7830
|
+
const config2 = RECEIPT_CONFIG[receipt.execution_status];
|
|
7831
|
+
let obj;
|
|
7832
|
+
if (config2) {
|
|
7833
|
+
const { statusReceipt, getBaseData, getValue } = config2;
|
|
7834
|
+
const value = getValue(receipt);
|
|
7835
|
+
obj = {
|
|
7836
|
+
...getBaseData(receipt),
|
|
7837
|
+
statusReceipt,
|
|
7838
|
+
value,
|
|
7839
|
+
match(callbacks) {
|
|
7840
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
7841
|
+
},
|
|
7842
|
+
isSuccess() {
|
|
7843
|
+
return statusReceipt === "SUCCEEDED";
|
|
7844
|
+
},
|
|
7845
|
+
isReverted() {
|
|
7846
|
+
return statusReceipt === "REVERTED";
|
|
7847
|
+
},
|
|
7848
|
+
isError() {
|
|
7849
|
+
return false;
|
|
7850
|
+
}
|
|
7851
|
+
};
|
|
7852
|
+
} else {
|
|
7853
|
+
const errorValue = new Error("Unknown response type");
|
|
7854
|
+
obj = {
|
|
7855
|
+
statusReceipt: "ERROR",
|
|
7856
|
+
value: errorValue,
|
|
7857
|
+
match(callbacks) {
|
|
7858
|
+
return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
|
|
7859
|
+
},
|
|
7860
|
+
isSuccess() {
|
|
7861
|
+
return false;
|
|
7862
|
+
},
|
|
7863
|
+
isReverted() {
|
|
7864
|
+
return false;
|
|
7865
|
+
},
|
|
7866
|
+
isError() {
|
|
7867
|
+
return true;
|
|
7868
|
+
}
|
|
7869
|
+
};
|
|
7870
|
+
}
|
|
7871
|
+
Object.setPrototypeOf(obj, ReceiptTx.prototype);
|
|
7872
|
+
Object.defineProperty(obj, "constructor", {
|
|
7873
|
+
value: ReceiptTx,
|
|
7874
|
+
writable: false,
|
|
7875
|
+
enumerable: false,
|
|
7876
|
+
configurable: false
|
|
7877
|
+
});
|
|
7878
|
+
return obj;
|
|
7879
|
+
}
|
|
6200
7880
|
|
|
6201
7881
|
// src/utils/typedData.ts
|
|
6202
7882
|
var typedData_exports = {};
|
|
@@ -6865,7 +8545,7 @@ var RpcProvider = class {
|
|
|
6865
8545
|
async getTransactionReceipt(txHash) {
|
|
6866
8546
|
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
6867
8547
|
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
6868
|
-
return
|
|
8548
|
+
return createTransactionReceipt(txReceiptWoHelperModified);
|
|
6869
8549
|
}
|
|
6870
8550
|
async getTransactionTrace(txHash) {
|
|
6871
8551
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -6881,7 +8561,7 @@ var RpcProvider = class {
|
|
|
6881
8561
|
txHash,
|
|
6882
8562
|
options
|
|
6883
8563
|
);
|
|
6884
|
-
return
|
|
8564
|
+
return createTransactionReceipt(receiptWoHelper);
|
|
6885
8565
|
}
|
|
6886
8566
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
6887
8567
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -7888,12 +9568,12 @@ var LedgerSigner111 = class {
|
|
|
7888
9568
|
*/
|
|
7889
9569
|
async signRaw(msgHash) {
|
|
7890
9570
|
addHexPrefix(
|
|
7891
|
-
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0,
|
|
9571
|
+
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, buffer_default.from(this.pathBuffer)))
|
|
7892
9572
|
);
|
|
7893
9573
|
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
7894
9574
|
const buff2 = hexToBytes(shiftedHash);
|
|
7895
9575
|
const respSign2 = Uint8Array.from(
|
|
7896
|
-
await this._transporter.send(Number("0x5a"), 2, 1, 0,
|
|
9576
|
+
await this._transporter.send(Number("0x5a"), 2, 1, 0, buffer_default.from(buff2))
|
|
7897
9577
|
);
|
|
7898
9578
|
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
7899
9579
|
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
@@ -7906,7 +9586,7 @@ var LedgerSigner111 = class {
|
|
|
7906
9586
|
async getPublicKeys() {
|
|
7907
9587
|
const pathBuff = this.pathBuffer;
|
|
7908
9588
|
const respGetPublic = Uint8Array.from(
|
|
7909
|
-
await this._transporter.send(Number("0x5a"), 1, 0, 0,
|
|
9589
|
+
await this._transporter.send(Number("0x5a"), 1, 0, 0, buffer_default.from(pathBuff))
|
|
7910
9590
|
);
|
|
7911
9591
|
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
7912
9592
|
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
@@ -8162,7 +9842,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8162
9842
|
txDetails.accountDeploymentData.length <= 7,
|
|
8163
9843
|
"accountDeploymentData includes more than 7 items"
|
|
8164
9844
|
);
|
|
8165
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
9845
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8166
9846
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
8167
9847
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8168
9848
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
@@ -8184,30 +9864,30 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8184
9864
|
nonceBuf,
|
|
8185
9865
|
dAModeHashBuf
|
|
8186
9866
|
]);
|
|
8187
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
9867
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
8188
9868
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8189
9869
|
txDetails.paymasterData.map((value) => {
|
|
8190
9870
|
const a = this.convertBnToLedger(value);
|
|
8191
9871
|
return a;
|
|
8192
9872
|
})
|
|
8193
9873
|
);
|
|
8194
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
9874
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
|
|
8195
9875
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
8196
9876
|
txDetails.paymasterData.map((value) => {
|
|
8197
9877
|
const a = this.convertBnToLedger(value);
|
|
8198
9878
|
return a;
|
|
8199
9879
|
})
|
|
8200
9880
|
);
|
|
8201
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
9881
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
|
|
8202
9882
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8203
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
9883
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
|
|
8204
9884
|
let respSign = new Uint8Array(0);
|
|
8205
9885
|
for (const call of calls) {
|
|
8206
9886
|
const calldatas = this.encodeCall(call);
|
|
8207
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
9887
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
|
|
8208
9888
|
if (calldatas.length > 1) {
|
|
8209
9889
|
calldatas.slice(1).forEach(async (part) => {
|
|
8210
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 1,
|
|
9890
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
|
|
8211
9891
|
});
|
|
8212
9892
|
}
|
|
8213
9893
|
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
@@ -8244,7 +9924,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8244
9924
|
* ```
|
|
8245
9925
|
*/
|
|
8246
9926
|
async signDeployAccountV3(deployAccountDetail) {
|
|
8247
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
9927
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8248
9928
|
const accountAddressBuf = this.convertBnToLedger(
|
|
8249
9929
|
deployAccountDetail.contractAddress
|
|
8250
9930
|
);
|
|
@@ -8266,7 +9946,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8266
9946
|
classHashBuf,
|
|
8267
9947
|
saltBuf
|
|
8268
9948
|
]);
|
|
8269
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
9949
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
8270
9950
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8271
9951
|
const l1_gasBuf = this.convertBnToLedger(
|
|
8272
9952
|
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
@@ -8275,17 +9955,17 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8275
9955
|
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
8276
9956
|
);
|
|
8277
9957
|
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
8278
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
9958
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
8279
9959
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8280
9960
|
deployAccountDetail.paymasterData.map((value) => {
|
|
8281
9961
|
const a = this.convertBnToLedger(value);
|
|
8282
9962
|
return a;
|
|
8283
9963
|
})
|
|
8284
9964
|
);
|
|
8285
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
9965
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
8286
9966
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8287
9967
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8288
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
9968
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
8289
9969
|
const constructorBuf = concatenateArrayBuffer(
|
|
8290
9970
|
compiledConstructor.map((parameter) => {
|
|
8291
9971
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -8298,7 +9978,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8298
9978
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8299
9979
|
let respSign = new Uint8Array(0);
|
|
8300
9980
|
for (const chunk of constructorChunks) {
|
|
8301
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
9981
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
8302
9982
|
}
|
|
8303
9983
|
return this.decodeSignatureLedger(respSign);
|
|
8304
9984
|
}
|
|
@@ -8388,7 +10068,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8388
10068
|
txDetails.accountDeploymentData.length <= 7,
|
|
8389
10069
|
"accountDeploymentData includes more than 7 items"
|
|
8390
10070
|
);
|
|
8391
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
10071
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8392
10072
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
8393
10073
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
8394
10074
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
@@ -8404,7 +10084,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8404
10084
|
nonceBuf,
|
|
8405
10085
|
dAModeHashBuf
|
|
8406
10086
|
]);
|
|
8407
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
10087
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
8408
10088
|
if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
|
|
8409
10089
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8410
10090
|
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
@@ -8418,7 +10098,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8418
10098
|
l2_gasBuf,
|
|
8419
10099
|
l1_data_gasBuf
|
|
8420
10100
|
]);
|
|
8421
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
10101
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
|
|
8422
10102
|
}
|
|
8423
10103
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8424
10104
|
txDetails.paymasterData.map((value) => {
|
|
@@ -8426,23 +10106,23 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8426
10106
|
return a;
|
|
8427
10107
|
})
|
|
8428
10108
|
);
|
|
8429
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
10109
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(paymasterBuf));
|
|
8430
10110
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
8431
10111
|
txDetails.paymasterData.map((value) => {
|
|
8432
10112
|
const a = this.convertBnToLedger(value);
|
|
8433
10113
|
return a;
|
|
8434
10114
|
})
|
|
8435
10115
|
);
|
|
8436
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
10116
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(accountDeployDataBuf));
|
|
8437
10117
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8438
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
10118
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(nbCallsBuf));
|
|
8439
10119
|
let respSign = new Uint8Array(0);
|
|
8440
10120
|
for (const call of calls) {
|
|
8441
10121
|
const calldatas = this.encodeCall(call);
|
|
8442
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0,
|
|
10122
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, buffer_default.from(calldatas[0]));
|
|
8443
10123
|
if (calldatas.length > 1) {
|
|
8444
10124
|
calldatas.slice(1).forEach(async (part) => {
|
|
8445
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1,
|
|
10125
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, buffer_default.from(part));
|
|
8446
10126
|
});
|
|
8447
10127
|
}
|
|
8448
10128
|
}
|
|
@@ -8478,7 +10158,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8478
10158
|
* ```
|
|
8479
10159
|
*/
|
|
8480
10160
|
async signDeployAccountV3(deployAccountDetail) {
|
|
8481
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
10161
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8482
10162
|
const accountAddressBuf = this.convertBnToLedger(
|
|
8483
10163
|
deployAccountDetail.contractAddress
|
|
8484
10164
|
);
|
|
@@ -8500,7 +10180,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8500
10180
|
classHashBuf,
|
|
8501
10181
|
saltBuf
|
|
8502
10182
|
]);
|
|
8503
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
10183
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
8504
10184
|
if (isRPC08Plus_ResourceBoundsBN(deployAccountDetail.resourceBounds)) {
|
|
8505
10185
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8506
10186
|
const l1_gasBuf = this.convertBnToLedger(
|
|
@@ -8518,7 +10198,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8518
10198
|
l2_gasBuf,
|
|
8519
10199
|
l1_data_gasBuf
|
|
8520
10200
|
]);
|
|
8521
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
10201
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
8522
10202
|
}
|
|
8523
10203
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8524
10204
|
deployAccountDetail.paymasterData.map((value) => {
|
|
@@ -8526,10 +10206,10 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8526
10206
|
return a;
|
|
8527
10207
|
})
|
|
8528
10208
|
);
|
|
8529
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
10209
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
8530
10210
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8531
10211
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8532
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
10212
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
8533
10213
|
const constructorBuf = concatenateArrayBuffer(
|
|
8534
10214
|
compiledConstructor.map((parameter) => {
|
|
8535
10215
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -8542,7 +10222,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8542
10222
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8543
10223
|
let respSign = new Uint8Array(0);
|
|
8544
10224
|
for (const chunk of constructorChunks) {
|
|
8545
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
10225
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
8546
10226
|
}
|
|
8547
10227
|
return this.decodeSignatureLedger(respSign);
|
|
8548
10228
|
}
|
|
@@ -10070,7 +11750,11 @@ function mergeAbiEvents(target, source) {
|
|
|
10070
11750
|
Object.keys(source).forEach((key) => {
|
|
10071
11751
|
if (isObject(source[key])) {
|
|
10072
11752
|
if (!(key in target)) Object.assign(output, { [key]: source[key] });
|
|
10073
|
-
else
|
|
11753
|
+
else
|
|
11754
|
+
output[key] = mergeAbiEvents(
|
|
11755
|
+
target[key],
|
|
11756
|
+
source[key]
|
|
11757
|
+
);
|
|
10074
11758
|
} else {
|
|
10075
11759
|
Object.assign(output, { [key]: source[key] });
|
|
10076
11760
|
}
|
|
@@ -10078,7 +11762,7 @@ function mergeAbiEvents(target, source) {
|
|
|
10078
11762
|
}
|
|
10079
11763
|
return output;
|
|
10080
11764
|
}
|
|
10081
|
-
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
|
|
11765
|
+
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums, parser) {
|
|
10082
11766
|
const ret = providerReceivedEvents.flat().reduce((acc, recEvent) => {
|
|
10083
11767
|
const currentEvent = JSON.parse(JSON.stringify(recEvent));
|
|
10084
11768
|
let abiEvent = abiEvents[currentEvent.keys.shift() ?? 0];
|
|
@@ -10097,22 +11781,24 @@ function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
|
|
|
10097
11781
|
const abiEventKeys = abiEvent.members?.filter((it) => it.kind === "key") || abiEvent.keys;
|
|
10098
11782
|
const abiEventData = abiEvent.members?.filter((it) => it.kind === "data") || abiEvent.data;
|
|
10099
11783
|
abiEventKeys.forEach((key) => {
|
|
10100
|
-
parsedEvent[abiEvent.name][key.name] = responseParser(
|
|
10101
|
-
keysIter,
|
|
10102
|
-
key,
|
|
10103
|
-
abiStructs,
|
|
10104
|
-
abiEnums,
|
|
10105
|
-
|
|
10106
|
-
|
|
11784
|
+
parsedEvent[abiEvent.name][key.name] = responseParser({
|
|
11785
|
+
responseIterator: keysIter,
|
|
11786
|
+
output: key,
|
|
11787
|
+
structs: abiStructs,
|
|
11788
|
+
enums: abiEnums,
|
|
11789
|
+
parser,
|
|
11790
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
11791
|
+
});
|
|
10107
11792
|
});
|
|
10108
11793
|
abiEventData.forEach((data) => {
|
|
10109
|
-
parsedEvent[abiEvent.name][data.name] = responseParser(
|
|
10110
|
-
dataIter,
|
|
10111
|
-
data,
|
|
10112
|
-
abiStructs,
|
|
10113
|
-
abiEnums,
|
|
10114
|
-
|
|
10115
|
-
|
|
11794
|
+
parsedEvent[abiEvent.name][data.name] = responseParser({
|
|
11795
|
+
responseIterator: dataIter,
|
|
11796
|
+
output: data,
|
|
11797
|
+
structs: abiStructs,
|
|
11798
|
+
enums: abiEnums,
|
|
11799
|
+
parser,
|
|
11800
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
11801
|
+
});
|
|
10116
11802
|
});
|
|
10117
11803
|
if ("block_hash" in currentEvent) parsedEvent.block_hash = currentEvent.block_hash;
|
|
10118
11804
|
if ("block_number" in currentEvent) parsedEvent.block_number = currentEvent.block_number;
|
|
@@ -10130,8 +11816,8 @@ function buildCall(contract, functionAbi) {
|
|
|
10130
11816
|
const options = { ...contract.withOptionsProps };
|
|
10131
11817
|
contract.withOptionsProps = void 0;
|
|
10132
11818
|
return contract.call(functionAbi.name, args, {
|
|
10133
|
-
parseRequest:
|
|
10134
|
-
parseResponse:
|
|
11819
|
+
parseRequest: contract.parseRequest,
|
|
11820
|
+
parseResponse: contract.parseResponse,
|
|
10135
11821
|
...options
|
|
10136
11822
|
});
|
|
10137
11823
|
};
|
|
@@ -10141,7 +11827,7 @@ function buildInvoke(contract, functionAbi) {
|
|
|
10141
11827
|
const options = { ...contract.withOptionsProps };
|
|
10142
11828
|
contract.withOptionsProps = void 0;
|
|
10143
11829
|
return contract.invoke(functionAbi.name, args, {
|
|
10144
|
-
parseRequest:
|
|
11830
|
+
parseRequest: contract.parseRequest,
|
|
10145
11831
|
...options
|
|
10146
11832
|
});
|
|
10147
11833
|
};
|
|
@@ -10169,6 +11855,8 @@ var Contract = class _Contract {
|
|
|
10169
11855
|
address;
|
|
10170
11856
|
providerOrAccount;
|
|
10171
11857
|
classHash;
|
|
11858
|
+
parseRequest;
|
|
11859
|
+
parseResponse;
|
|
10172
11860
|
structs;
|
|
10173
11861
|
events;
|
|
10174
11862
|
functions;
|
|
@@ -10177,6 +11865,7 @@ var Contract = class _Contract {
|
|
|
10177
11865
|
estimateFee;
|
|
10178
11866
|
callData;
|
|
10179
11867
|
withOptionsProps;
|
|
11868
|
+
parsingStrategy;
|
|
10180
11869
|
/**
|
|
10181
11870
|
* @param options
|
|
10182
11871
|
* - abi: Abi of the contract object (required)
|
|
@@ -10184,14 +11873,18 @@ var Contract = class _Contract {
|
|
|
10184
11873
|
* - providerOrAccount?: Provider or Account to attach to (fallback to defaultProvider)
|
|
10185
11874
|
* - parseRequest?: compile and validate arguments (optional, default true)
|
|
10186
11875
|
* - parseResponse?: Parse elements of the response array and structuring them into response object (optional, default true)
|
|
11876
|
+
* - parser?: Abi parser (optional, default createAbiParser(options.abi))
|
|
10187
11877
|
*/
|
|
10188
11878
|
constructor(options) {
|
|
10189
|
-
|
|
10190
|
-
|
|
11879
|
+
this.parsingStrategy = options.parsingStrategy;
|
|
11880
|
+
const parser = createAbiParser(options.abi, options.parsingStrategy);
|
|
10191
11881
|
this.abi = parser.getLegacyFormat();
|
|
11882
|
+
this.address = options.address && options.address.toLowerCase();
|
|
10192
11883
|
this.providerOrAccount = options.providerOrAccount ?? defaultProvider;
|
|
11884
|
+
this.parseRequest = options.parseRequest ?? true;
|
|
11885
|
+
this.parseResponse = options.parseResponse ?? true;
|
|
10193
11886
|
this.classHash = options.classHash;
|
|
10194
|
-
this.callData = new CallData(options.abi);
|
|
11887
|
+
this.callData = new CallData(options.abi, options.parsingStrategy);
|
|
10195
11888
|
this.structs = CallData.getAbiStruct(options.abi);
|
|
10196
11889
|
this.events = getAbiEvents(options.abi);
|
|
10197
11890
|
const methodTypes = { enumerable: true, value: {}, writable: false };
|
|
@@ -10243,8 +11936,9 @@ var Contract = class _Contract {
|
|
|
10243
11936
|
attach(address, abi) {
|
|
10244
11937
|
this.address = address;
|
|
10245
11938
|
if (abi) {
|
|
10246
|
-
|
|
10247
|
-
this.
|
|
11939
|
+
const parser = createAbiParser(abi, this.parsingStrategy);
|
|
11940
|
+
this.abi = parser.getLegacyFormat();
|
|
11941
|
+
this.callData = new CallData(abi, this.parsingStrategy);
|
|
10248
11942
|
this.structs = CallData.getAbiStruct(abi);
|
|
10249
11943
|
this.events = getAbiEvents(abi);
|
|
10250
11944
|
}
|
|
@@ -10290,7 +11984,8 @@ var Contract = class _Contract {
|
|
|
10290
11984
|
return this.callData.parse(method, it);
|
|
10291
11985
|
});
|
|
10292
11986
|
}
|
|
10293
|
-
invoke(method, args = [],
|
|
11987
|
+
async invoke(method, args = [], options = {}) {
|
|
11988
|
+
const { parseRequest = true, signature, waitForTransaction, ...RestInvokeOptions } = options;
|
|
10294
11989
|
assert(this.address !== null, "contract is not connected to an address");
|
|
10295
11990
|
const calldata = getCompiledCalldata(args, () => {
|
|
10296
11991
|
if (parseRequest) {
|
|
@@ -10306,9 +12001,17 @@ var Contract = class _Contract {
|
|
|
10306
12001
|
entrypoint: method
|
|
10307
12002
|
};
|
|
10308
12003
|
if (isAccount(this.providerOrAccount)) {
|
|
10309
|
-
|
|
12004
|
+
const result = await this.providerOrAccount.execute(invocation, {
|
|
10310
12005
|
...RestInvokeOptions
|
|
10311
12006
|
});
|
|
12007
|
+
if (waitForTransaction) {
|
|
12008
|
+
const result2 = await this.providerOrAccount.waitForTransaction(result.transaction_hash);
|
|
12009
|
+
if (result2.isSuccess()) {
|
|
12010
|
+
return result2;
|
|
12011
|
+
}
|
|
12012
|
+
throw new Error("Transaction failed", { cause: result2 });
|
|
12013
|
+
}
|
|
12014
|
+
return result;
|
|
10312
12015
|
}
|
|
10313
12016
|
if (!RestInvokeOptions.nonce)
|
|
10314
12017
|
throw new Error(`Manual nonce is required when invoking a function without an account`);
|
|
@@ -10346,9 +12049,9 @@ var Contract = class _Contract {
|
|
|
10346
12049
|
// TODO: Demistify what is going on here ???
|
|
10347
12050
|
// TODO: receipt status filtering test and fix this do not look right
|
|
10348
12051
|
parseEvents(receipt) {
|
|
10349
|
-
let parsed;
|
|
12052
|
+
let parsed = [];
|
|
10350
12053
|
receipt.match({
|
|
10351
|
-
|
|
12054
|
+
SUCCEEDED: (txR) => {
|
|
10352
12055
|
const emittedEvents = txR.events?.map((event) => {
|
|
10353
12056
|
return {
|
|
10354
12057
|
// TODO: this do not check that block is production and block_hash and block_number actually exists
|
|
@@ -10361,16 +12064,26 @@ var Contract = class _Contract {
|
|
|
10361
12064
|
}).filter((event) => cleanHex(event.from_address) === cleanHex(this.address), []) || [];
|
|
10362
12065
|
parsed = parseEvents(
|
|
10363
12066
|
emittedEvents,
|
|
10364
|
-
// TODO: any temp hotfix, fix this
|
|
10365
12067
|
this.events,
|
|
10366
12068
|
this.structs,
|
|
10367
|
-
CallData.getAbiEnum(this.abi)
|
|
12069
|
+
CallData.getAbiEnum(this.abi),
|
|
12070
|
+
this.callData.parser
|
|
10368
12071
|
);
|
|
10369
12072
|
},
|
|
10370
12073
|
_: () => {
|
|
10371
12074
|
throw Error("This transaction was not successful.");
|
|
10372
12075
|
}
|
|
10373
12076
|
});
|
|
12077
|
+
Object.defineProperty(parsed, "getByPath", {
|
|
12078
|
+
value: (path) => {
|
|
12079
|
+
const event = parsed.find((ev) => Object.keys(ev).some((key) => key.includes(path)));
|
|
12080
|
+
const eventKey = Object.keys(event || {}).find((key) => key.includes(path));
|
|
12081
|
+
return eventKey && event ? event[eventKey] : null;
|
|
12082
|
+
},
|
|
12083
|
+
writable: false,
|
|
12084
|
+
enumerable: false,
|
|
12085
|
+
configurable: false
|
|
12086
|
+
});
|
|
10374
12087
|
return parsed;
|
|
10375
12088
|
}
|
|
10376
12089
|
isCairo1() {
|
|
@@ -10487,7 +12200,10 @@ var Contract = class _Contract {
|
|
|
10487
12200
|
abi,
|
|
10488
12201
|
address: contract_address,
|
|
10489
12202
|
providerOrAccount: account,
|
|
10490
|
-
classHash
|
|
12203
|
+
classHash,
|
|
12204
|
+
parseRequest: params.parseRequest,
|
|
12205
|
+
parseResponse: params.parseResponse,
|
|
12206
|
+
parsingStrategy: params.parsingStrategy
|
|
10491
12207
|
});
|
|
10492
12208
|
}
|
|
10493
12209
|
};
|
|
@@ -10543,19 +12259,33 @@ function units(amount, simbol = "fri") {
|
|
|
10543
12259
|
}
|
|
10544
12260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10545
12261
|
0 && (module.exports = {
|
|
12262
|
+
AbiParser1,
|
|
12263
|
+
AbiParser2,
|
|
12264
|
+
AbiParserInterface,
|
|
10546
12265
|
Account,
|
|
10547
12266
|
AccountInterface,
|
|
10548
12267
|
BatchClient,
|
|
10549
12268
|
BlockStatus,
|
|
10550
12269
|
BlockTag,
|
|
12270
|
+
CairoByteArray,
|
|
10551
12271
|
CairoCustomEnum,
|
|
10552
12272
|
CairoFixedArray,
|
|
12273
|
+
CairoInt128,
|
|
12274
|
+
CairoInt16,
|
|
12275
|
+
CairoInt32,
|
|
12276
|
+
CairoInt64,
|
|
12277
|
+
CairoInt8,
|
|
10553
12278
|
CairoOption,
|
|
10554
12279
|
CairoOptionVariant,
|
|
10555
12280
|
CairoResult,
|
|
10556
12281
|
CairoResultVariant,
|
|
12282
|
+
CairoUint128,
|
|
12283
|
+
CairoUint16,
|
|
10557
12284
|
CairoUint256,
|
|
10558
12285
|
CairoUint512,
|
|
12286
|
+
CairoUint64,
|
|
12287
|
+
CairoUint8,
|
|
12288
|
+
CairoUint96,
|
|
10559
12289
|
CallData,
|
|
10560
12290
|
Contract,
|
|
10561
12291
|
ContractInterface,
|
|
@@ -10571,6 +12301,7 @@ function units(amount, simbol = "fri") {
|
|
|
10571
12301
|
ETransactionVersion3,
|
|
10572
12302
|
EntryPointType,
|
|
10573
12303
|
EthSigner,
|
|
12304
|
+
Int,
|
|
10574
12305
|
LedgerSigner,
|
|
10575
12306
|
LedgerSigner111,
|
|
10576
12307
|
LedgerSigner221,
|
|
@@ -10624,6 +12355,8 @@ function units(amount, simbol = "fri") {
|
|
|
10624
12355
|
config,
|
|
10625
12356
|
constants,
|
|
10626
12357
|
contractClassResponseToLegacyCompiledContract,
|
|
12358
|
+
createAbiParser,
|
|
12359
|
+
createTransactionReceipt,
|
|
10627
12360
|
defaultDeployer,
|
|
10628
12361
|
defaultPaymaster,
|
|
10629
12362
|
defaultProvider,
|
|
@@ -10632,6 +12365,8 @@ function units(amount, simbol = "fri") {
|
|
|
10632
12365
|
eth,
|
|
10633
12366
|
events,
|
|
10634
12367
|
extractContractHashes,
|
|
12368
|
+
fastParsingStrategy,
|
|
12369
|
+
getAbiVersion,
|
|
10635
12370
|
getChecksumAddress,
|
|
10636
12371
|
getGasPrices,
|
|
10637
12372
|
getLedgerPathBuffer,
|
|
@@ -10639,7 +12374,9 @@ function units(amount, simbol = "fri") {
|
|
|
10639
12374
|
getLedgerPathBuffer221,
|
|
10640
12375
|
getTipStatsFromBlocks,
|
|
10641
12376
|
hash,
|
|
12377
|
+
hdParsingStrategy,
|
|
10642
12378
|
isAccount,
|
|
12379
|
+
isNoConstructorValid,
|
|
10643
12380
|
isPendingBlock,
|
|
10644
12381
|
isPendingStateUpdate,
|
|
10645
12382
|
isPendingTransaction,
|