starknet 8.1.2 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +764 -86
- package/dist/index.global.js +2081 -384
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2102 -384
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2081 -384
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -36,7 +36,16 @@ __export(constants_exports, {
|
|
|
36
36
|
PRIME: () => PRIME,
|
|
37
37
|
RANGE_FELT: () => RANGE_FELT,
|
|
38
38
|
RANGE_I128: () => RANGE_I128,
|
|
39
|
+
RANGE_I16: () => RANGE_I16,
|
|
40
|
+
RANGE_I32: () => RANGE_I32,
|
|
41
|
+
RANGE_I64: () => RANGE_I64,
|
|
42
|
+
RANGE_I8: () => RANGE_I8,
|
|
39
43
|
RANGE_U128: () => RANGE_U128,
|
|
44
|
+
RANGE_U16: () => RANGE_U16,
|
|
45
|
+
RANGE_U32: () => RANGE_U32,
|
|
46
|
+
RANGE_U64: () => RANGE_U64,
|
|
47
|
+
RANGE_U8: () => RANGE_U8,
|
|
48
|
+
RANGE_U96: () => RANGE_U96,
|
|
40
49
|
RPC_DEFAULT_NODES: () => RPC_DEFAULT_NODES,
|
|
41
50
|
SNIP9_V1_INTERFACE_ID: () => SNIP9_V1_INTERFACE_ID,
|
|
42
51
|
SNIP9_V2_INTERFACE_ID: () => SNIP9_V2_INTERFACE_ID,
|
|
@@ -81,16 +90,22 @@ __export(encode_exports, {
|
|
|
81
90
|
addHexPrefix: () => addHexPrefix,
|
|
82
91
|
arrayBufferToString: () => arrayBufferToString,
|
|
83
92
|
atobUniversal: () => atobUniversal,
|
|
93
|
+
bigIntToUint8Array: () => bigIntToUint8Array,
|
|
84
94
|
btoaUniversal: () => btoaUniversal,
|
|
85
95
|
buf2hex: () => buf2hex,
|
|
86
96
|
calcByteLength: () => calcByteLength,
|
|
87
97
|
concatenateArrayBuffer: () => concatenateArrayBuffer,
|
|
98
|
+
hexStringToUint8Array: () => hexStringToUint8Array,
|
|
88
99
|
padLeft: () => padLeft,
|
|
89
100
|
pascalToSnake: () => pascalToSnake,
|
|
90
101
|
removeHexPrefix: () => removeHexPrefix,
|
|
91
102
|
sanitizeBytes: () => sanitizeBytes,
|
|
92
103
|
sanitizeHex: () => sanitizeHex,
|
|
93
|
-
|
|
104
|
+
stringToUint8Array: () => stringToUint8Array,
|
|
105
|
+
uint8ArrayToBigInt: () => uint8ArrayToBigInt,
|
|
106
|
+
utf8ToArray: () => utf8ToArray,
|
|
107
|
+
utf8ToBigInt: () => utf8ToBigInt,
|
|
108
|
+
utf8ToUint8Array: () => utf8ToUint8Array
|
|
94
109
|
});
|
|
95
110
|
import { base64 } from "@scure/base";
|
|
96
111
|
var IS_BROWSER = typeof window !== "undefined";
|
|
@@ -98,9 +113,13 @@ var STRING_ZERO = "0";
|
|
|
98
113
|
function arrayBufferToString(array) {
|
|
99
114
|
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
100
115
|
}
|
|
101
|
-
function
|
|
116
|
+
function utf8ToUint8Array(str) {
|
|
102
117
|
return new TextEncoder().encode(str);
|
|
103
118
|
}
|
|
119
|
+
var utf8ToArray = utf8ToUint8Array;
|
|
120
|
+
function utf8ToBigInt(str) {
|
|
121
|
+
return uint8ArrayToBigInt(utf8ToUint8Array(str));
|
|
122
|
+
}
|
|
104
123
|
function atobUniversal(a) {
|
|
105
124
|
return base64.decode(a);
|
|
106
125
|
}
|
|
@@ -152,6 +171,61 @@ function concatenateArrayBuffer(uint8arrays) {
|
|
|
152
171
|
});
|
|
153
172
|
return result;
|
|
154
173
|
}
|
|
174
|
+
function hexStringToUint8Array(hex) {
|
|
175
|
+
const cleanHex2 = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
176
|
+
if (cleanHex2.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanHex2)) {
|
|
177
|
+
throw new Error(`Invalid hex string: "${hex}" contains non-hexadecimal characters`);
|
|
178
|
+
}
|
|
179
|
+
const paddedHex = cleanHex2.length % 2 !== 0 ? `0${cleanHex2}` : cleanHex2;
|
|
180
|
+
const bytes = new Uint8Array(paddedHex.length / 2);
|
|
181
|
+
for (let i = 0; i < paddedHex.length; i += 2) {
|
|
182
|
+
bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
|
|
183
|
+
}
|
|
184
|
+
return bytes;
|
|
185
|
+
}
|
|
186
|
+
function isHexString(hex) {
|
|
187
|
+
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
188
|
+
}
|
|
189
|
+
function isDecimalString(str) {
|
|
190
|
+
return /^[0-9]+$/.test(str);
|
|
191
|
+
}
|
|
192
|
+
function stringToUint8Array(str) {
|
|
193
|
+
if (isHexString(str)) {
|
|
194
|
+
return hexStringToUint8Array(str);
|
|
195
|
+
}
|
|
196
|
+
if (isDecimalString(str)) {
|
|
197
|
+
const value = BigInt(str);
|
|
198
|
+
return bigIntToUint8Array(value);
|
|
199
|
+
}
|
|
200
|
+
return utf8ToUint8Array(str);
|
|
201
|
+
}
|
|
202
|
+
function bigIntToUint8Array(value) {
|
|
203
|
+
if (value < 0n) {
|
|
204
|
+
throw new Error(`Cannot convert negative bigint ${value} to Uint8Array`);
|
|
205
|
+
}
|
|
206
|
+
if (value === 0n) {
|
|
207
|
+
return new Uint8Array([0]);
|
|
208
|
+
}
|
|
209
|
+
let hex = value.toString(16);
|
|
210
|
+
if (hex.length % 2 !== 0) {
|
|
211
|
+
hex = `0${hex}`;
|
|
212
|
+
}
|
|
213
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
214
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
215
|
+
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
216
|
+
}
|
|
217
|
+
return bytes;
|
|
218
|
+
}
|
|
219
|
+
function uint8ArrayToBigInt(data) {
|
|
220
|
+
if (!data || data.length === 0) {
|
|
221
|
+
return 0n;
|
|
222
|
+
}
|
|
223
|
+
let hex = "0x";
|
|
224
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
225
|
+
hex += data[i].toString(16).padStart(2, "0");
|
|
226
|
+
}
|
|
227
|
+
return BigInt(hex);
|
|
228
|
+
}
|
|
155
229
|
|
|
156
230
|
// src/global/constants.ts
|
|
157
231
|
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
@@ -164,8 +238,17 @@ var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
|
164
238
|
var ADDR_BOUND = 2n ** 251n - MAX_STORAGE_ITEM_SIZE;
|
|
165
239
|
var range = (min, max) => ({ min, max });
|
|
166
240
|
var RANGE_FELT = range(ZERO, PRIME - 1n);
|
|
167
|
-
var
|
|
241
|
+
var RANGE_U8 = range(ZERO, 2n ** 8n - 1n);
|
|
242
|
+
var RANGE_U16 = range(ZERO, 2n ** 16n - 1n);
|
|
243
|
+
var RANGE_U32 = range(ZERO, 2n ** 32n - 1n);
|
|
244
|
+
var RANGE_U64 = range(ZERO, 2n ** 64n - 1n);
|
|
245
|
+
var RANGE_U96 = range(ZERO, 2n ** 96n - 1n);
|
|
168
246
|
var RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
|
|
247
|
+
var RANGE_I8 = range(-(2n ** 7n), 2n ** 7n - 1n);
|
|
248
|
+
var RANGE_I16 = range(-(2n ** 15n), 2n ** 15n - 1n);
|
|
249
|
+
var RANGE_I32 = range(-(2n ** 31n), 2n ** 31n - 1n);
|
|
250
|
+
var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
|
|
251
|
+
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
169
252
|
var LegacyUDC = {
|
|
170
253
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
171
254
|
ENTRYPOINT: "deployContract"
|
|
@@ -232,7 +315,8 @@ var DEFAULT_GLOBAL_CONFIG = {
|
|
|
232
315
|
},
|
|
233
316
|
defaultTipType: "recommendedTip",
|
|
234
317
|
fetch: void 0,
|
|
235
|
-
websocket: void 0
|
|
318
|
+
websocket: void 0,
|
|
319
|
+
buffer: void 0
|
|
236
320
|
};
|
|
237
321
|
var RPC_DEFAULT_NODES = {
|
|
238
322
|
SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
|
|
@@ -250,7 +334,10 @@ var SYSTEM_MESSAGES = {
|
|
|
250
334
|
unsupportedSpecVersion: "The connected node specification version is not supported by this library",
|
|
251
335
|
maxFeeInV3: "maxFee is not supported in V3 transactions, use resourceBounds instead",
|
|
252
336
|
declareNonSierra: "Declaring non Sierra (Cairo0)contract using RPC 0.8+",
|
|
253
|
-
unsupportedMethodForRpcVersion: "Unsupported method for RPC version"
|
|
337
|
+
unsupportedMethodForRpcVersion: "Unsupported method for RPC version",
|
|
338
|
+
txEvictedFromMempool: "Transaction TTL, evicted from the mempool, try to increase the tip",
|
|
339
|
+
consensusFailed: "Consensus failed to finalize the block proposal",
|
|
340
|
+
txFailsBlockBuildingValidation: "Transaction fails block building validation"
|
|
254
341
|
};
|
|
255
342
|
|
|
256
343
|
// src/global/config.ts
|
|
@@ -473,12 +560,20 @@ var Uint = {
|
|
|
473
560
|
u16: "core::integer::u16",
|
|
474
561
|
u32: "core::integer::u32",
|
|
475
562
|
u64: "core::integer::u64",
|
|
563
|
+
u96: "core::integer::u96",
|
|
476
564
|
u128: "core::integer::u128",
|
|
477
565
|
u256: "core::integer::u256",
|
|
478
566
|
// This one is struct
|
|
479
567
|
u512: "core::integer::u512"
|
|
480
568
|
// This one is struct
|
|
481
569
|
};
|
|
570
|
+
var Int = {
|
|
571
|
+
i8: "core::integer::i8",
|
|
572
|
+
i16: "core::integer::i16",
|
|
573
|
+
i32: "core::integer::i32",
|
|
574
|
+
i64: "core::integer::i64",
|
|
575
|
+
i128: "core::integer::i128"
|
|
576
|
+
};
|
|
482
577
|
var Literal = {
|
|
483
578
|
ClassHash: "core::starknet::class_hash::ClassHash",
|
|
484
579
|
ContractAddress: "core::starknet::contract_address::ContractAddress",
|
|
@@ -662,10 +757,12 @@ __export(num_exports, {
|
|
|
662
757
|
getDecimalString: () => getDecimalString,
|
|
663
758
|
getHexString: () => getHexString,
|
|
664
759
|
getHexStringArray: () => getHexStringArray,
|
|
760
|
+
getNext: () => getNext,
|
|
665
761
|
hexToBytes: () => hexToBytes,
|
|
666
762
|
hexToDecimalString: () => hexToDecimalString,
|
|
667
763
|
isBigNumberish: () => isBigNumberish,
|
|
668
764
|
isHex: () => isHex,
|
|
765
|
+
isHexString: () => isHexString2,
|
|
669
766
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
670
767
|
stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
|
|
671
768
|
toBigInt: () => toBigInt,
|
|
@@ -695,14 +792,21 @@ function isBigInt(value) {
|
|
|
695
792
|
function isString(value) {
|
|
696
793
|
return typeof value === "string";
|
|
697
794
|
}
|
|
795
|
+
function isBuffer(obj) {
|
|
796
|
+
return typeof Buffer !== "undefined" && obj instanceof Buffer;
|
|
797
|
+
}
|
|
698
798
|
function isObject(item) {
|
|
699
799
|
return !!item && typeof item === "object" && !Array.isArray(item);
|
|
700
800
|
}
|
|
801
|
+
function isInteger2(value) {
|
|
802
|
+
return Number.isInteger(value);
|
|
803
|
+
}
|
|
701
804
|
|
|
702
805
|
// src/utils/num.ts
|
|
703
806
|
function isHex(hex) {
|
|
704
807
|
return /^0[xX][0-9a-fA-F]*$/.test(hex);
|
|
705
808
|
}
|
|
809
|
+
var isHexString2 = isHex;
|
|
706
810
|
function toBigInt(value) {
|
|
707
811
|
return BigInt(value);
|
|
708
812
|
}
|
|
@@ -790,6 +894,11 @@ function stringToSha256ToArrayBuff4(str) {
|
|
|
790
894
|
function isBigNumberish(input) {
|
|
791
895
|
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) || isStringWholeNumber(input));
|
|
792
896
|
}
|
|
897
|
+
function getNext(iterator) {
|
|
898
|
+
const it = iterator.next();
|
|
899
|
+
if (it.done) throw new Error("Unexpected end of response");
|
|
900
|
+
return it.value;
|
|
901
|
+
}
|
|
793
902
|
|
|
794
903
|
// src/utils/hash/selector.ts
|
|
795
904
|
var selector_exports = {};
|
|
@@ -855,7 +964,7 @@ __export(shortString_exports, {
|
|
|
855
964
|
decodeShortString: () => decodeShortString,
|
|
856
965
|
encodeShortString: () => encodeShortString,
|
|
857
966
|
isASCII: () => isASCII,
|
|
858
|
-
isDecimalString: () =>
|
|
967
|
+
isDecimalString: () => isDecimalString2,
|
|
859
968
|
isLongText: () => isLongText,
|
|
860
969
|
isShortString: () => isShortString,
|
|
861
970
|
isShortText: () => isShortText,
|
|
@@ -868,7 +977,7 @@ function isASCII(str) {
|
|
|
868
977
|
function isShortString(str) {
|
|
869
978
|
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
870
979
|
}
|
|
871
|
-
function
|
|
980
|
+
function isDecimalString2(str) {
|
|
872
981
|
return /^[0-9]*$/i.test(str);
|
|
873
982
|
}
|
|
874
983
|
function isText(val) {
|
|
@@ -890,7 +999,7 @@ function decodeShortString(str) {
|
|
|
890
999
|
if (isHex(str)) {
|
|
891
1000
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
892
1001
|
}
|
|
893
|
-
if (
|
|
1002
|
+
if (isDecimalString2(str)) {
|
|
894
1003
|
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
895
1004
|
}
|
|
896
1005
|
throw new Error(`${str} is not Hex or decimal`);
|
|
@@ -932,12 +1041,11 @@ __export(cairo_exports, {
|
|
|
932
1041
|
isLen: () => isLen,
|
|
933
1042
|
isTypeArray: () => isTypeArray,
|
|
934
1043
|
isTypeBool: () => isTypeBool,
|
|
935
|
-
isTypeByteArray: () => isTypeByteArray,
|
|
936
|
-
isTypeBytes31: () => isTypeBytes31,
|
|
937
1044
|
isTypeContractAddress: () => isTypeContractAddress,
|
|
938
1045
|
isTypeEnum: () => isTypeEnum,
|
|
939
1046
|
isTypeEthAddress: () => isTypeEthAddress,
|
|
940
1047
|
isTypeFelt: () => isTypeFelt,
|
|
1048
|
+
isTypeInt: () => isTypeInt,
|
|
941
1049
|
isTypeLiteral: () => isTypeLiteral,
|
|
942
1050
|
isTypeNamedTuple: () => isTypeNamedTuple,
|
|
943
1051
|
isTypeNonZero: () => isTypeNonZero,
|
|
@@ -954,6 +1062,16 @@ __export(cairo_exports, {
|
|
|
954
1062
|
uint512: () => uint512
|
|
955
1063
|
});
|
|
956
1064
|
|
|
1065
|
+
// src/utils/helpers.ts
|
|
1066
|
+
function addCompiledFlag(compiled) {
|
|
1067
|
+
Object.defineProperty(compiled, "__compiled__", {
|
|
1068
|
+
enumerable: false,
|
|
1069
|
+
writable: false,
|
|
1070
|
+
value: true
|
|
1071
|
+
});
|
|
1072
|
+
return compiled;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
957
1075
|
// src/utils/cairoDataTypes/felt.ts
|
|
958
1076
|
function CairoFelt(it) {
|
|
959
1077
|
if (isBigInt(it) || Number.isInteger(it)) {
|
|
@@ -980,6 +1098,69 @@ function CairoFelt(it) {
|
|
|
980
1098
|
}
|
|
981
1099
|
throw new Error(`${it} can't be computed by felt()`);
|
|
982
1100
|
}
|
|
1101
|
+
var CairoFelt252 = class _CairoFelt252 {
|
|
1102
|
+
/**
|
|
1103
|
+
* byte representation of the felt252
|
|
1104
|
+
*/
|
|
1105
|
+
data;
|
|
1106
|
+
static abiSelector = "core::felt252";
|
|
1107
|
+
constructor(data) {
|
|
1108
|
+
_CairoFelt252.validate(data);
|
|
1109
|
+
this.data = _CairoFelt252.__processData(data);
|
|
1110
|
+
}
|
|
1111
|
+
static __processData(data) {
|
|
1112
|
+
if (isString(data)) {
|
|
1113
|
+
return stringToUint8Array(data);
|
|
1114
|
+
}
|
|
1115
|
+
if (isBigInt(data)) {
|
|
1116
|
+
return bigIntToUint8Array(data);
|
|
1117
|
+
}
|
|
1118
|
+
if (Number.isInteger(data)) {
|
|
1119
|
+
return bigIntToUint8Array(BigInt(data));
|
|
1120
|
+
}
|
|
1121
|
+
if (isBoolean(data)) {
|
|
1122
|
+
return bigIntToUint8Array(BigInt(data ? 1 : 0));
|
|
1123
|
+
}
|
|
1124
|
+
throw new Error(`${data} can't be computed by felt()`);
|
|
1125
|
+
}
|
|
1126
|
+
toBigInt() {
|
|
1127
|
+
return uint8ArrayToBigInt(this.data);
|
|
1128
|
+
}
|
|
1129
|
+
decodeUtf8() {
|
|
1130
|
+
return new TextDecoder().decode(this.data);
|
|
1131
|
+
}
|
|
1132
|
+
toHexString() {
|
|
1133
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
1134
|
+
}
|
|
1135
|
+
toApiRequest() {
|
|
1136
|
+
return addCompiledFlag([this.toHexString()]);
|
|
1137
|
+
}
|
|
1138
|
+
static validate(data) {
|
|
1139
|
+
assert(data !== null, "null value is not allowed for felt252");
|
|
1140
|
+
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
1141
|
+
assert(
|
|
1142
|
+
isString(data) || isNumber(data) || isBigInt(data) || isBoolean(data),
|
|
1143
|
+
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
1144
|
+
);
|
|
1145
|
+
const value = _CairoFelt252.__processData(data);
|
|
1146
|
+
const bn = uint8ArrayToBigInt(value);
|
|
1147
|
+
assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
|
|
1148
|
+
}
|
|
1149
|
+
static is(data) {
|
|
1150
|
+
try {
|
|
1151
|
+
_CairoFelt252.validate(data);
|
|
1152
|
+
return true;
|
|
1153
|
+
} catch {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
static isAbiType(abiType) {
|
|
1158
|
+
return abiType === _CairoFelt252.abiSelector;
|
|
1159
|
+
}
|
|
1160
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1161
|
+
return new _CairoFelt252(getNext(responseIterator));
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
983
1164
|
|
|
984
1165
|
// src/utils/cairoDataTypes/uint256.ts
|
|
985
1166
|
var UINT_128_MAX = (1n << 128n) - 1n;
|
|
@@ -991,11 +1172,16 @@ var UINT_256_LOW_MIN = 0n;
|
|
|
991
1172
|
var UINT_256_HIGH_MIN = 0n;
|
|
992
1173
|
var CairoUint256 = class _CairoUint256 {
|
|
993
1174
|
low;
|
|
1175
|
+
// TODO should be u128
|
|
994
1176
|
high;
|
|
1177
|
+
// TODO should be u128
|
|
995
1178
|
static abiSelector = "core::integer::u256";
|
|
996
1179
|
constructor(...arr) {
|
|
997
1180
|
if (isObject(arr[0]) && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
|
|
998
|
-
const props = _CairoUint256.validateProps(
|
|
1181
|
+
const props = _CairoUint256.validateProps(
|
|
1182
|
+
arr[0].low,
|
|
1183
|
+
arr[0].high
|
|
1184
|
+
);
|
|
999
1185
|
this.low = props.low;
|
|
1000
1186
|
this.high = props.high;
|
|
1001
1187
|
} else if (arr.length === 1) {
|
|
@@ -1014,9 +1200,15 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1014
1200
|
* Validate if BigNumberish can be represented as Unit256
|
|
1015
1201
|
*/
|
|
1016
1202
|
static validate(bigNumberish) {
|
|
1203
|
+
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
1204
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
1205
|
+
assert(
|
|
1206
|
+
isBigNumberish(bigNumberish) || isObject(bigNumberish),
|
|
1207
|
+
`Unsupported data type '${typeof bigNumberish}' for u256. Expected string, number, bigint, or Uint256 object`
|
|
1208
|
+
);
|
|
1017
1209
|
const bigInt = BigInt(bigNumberish);
|
|
1018
|
-
|
|
1019
|
-
|
|
1210
|
+
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
1211
|
+
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
1020
1212
|
return bigInt;
|
|
1021
1213
|
}
|
|
1022
1214
|
/**
|
|
@@ -1025,12 +1217,14 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1025
1217
|
static validateProps(low, high) {
|
|
1026
1218
|
const bigIntLow = BigInt(low);
|
|
1027
1219
|
const bigIntHigh = BigInt(high);
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1220
|
+
assert(
|
|
1221
|
+
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
1222
|
+
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
1223
|
+
);
|
|
1224
|
+
assert(
|
|
1225
|
+
bigIntHigh >= UINT_256_HIGH_MIN && bigIntHigh <= UINT_256_HIGH_MAX,
|
|
1226
|
+
"high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX"
|
|
1227
|
+
);
|
|
1034
1228
|
return { low: bigIntLow, high: bigIntHigh };
|
|
1035
1229
|
}
|
|
1036
1230
|
/**
|
|
@@ -1050,6 +1244,11 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
1050
1244
|
static isAbiType(abiType) {
|
|
1051
1245
|
return abiType === _CairoUint256.abiSelector;
|
|
1052
1246
|
}
|
|
1247
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1248
|
+
const low = getNext(responseIterator);
|
|
1249
|
+
const high = getNext(responseIterator);
|
|
1250
|
+
return new _CairoUint256(low, high);
|
|
1251
|
+
}
|
|
1053
1252
|
/**
|
|
1054
1253
|
* Return bigint representation
|
|
1055
1254
|
*/
|
|
@@ -1090,9 +1289,13 @@ var UINT_512_MIN = 0n;
|
|
|
1090
1289
|
var UINT_128_MIN = 0n;
|
|
1091
1290
|
var CairoUint512 = class _CairoUint512 {
|
|
1092
1291
|
limb0;
|
|
1292
|
+
// TODO should be u128
|
|
1093
1293
|
limb1;
|
|
1294
|
+
// TODO should be u128
|
|
1094
1295
|
limb2;
|
|
1296
|
+
// TODO should be u128
|
|
1095
1297
|
limb3;
|
|
1298
|
+
// TODO should be u128
|
|
1096
1299
|
static abiSelector = "core::integer::u512";
|
|
1097
1300
|
constructor(...arr) {
|
|
1098
1301
|
if (isObject(arr[0]) && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
@@ -1126,9 +1329,15 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1126
1329
|
* Validate if BigNumberish can be represented as Uint512
|
|
1127
1330
|
*/
|
|
1128
1331
|
static validate(bigNumberish) {
|
|
1332
|
+
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
1333
|
+
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
1334
|
+
assert(
|
|
1335
|
+
isBigNumberish(bigNumberish) || isObject(bigNumberish),
|
|
1336
|
+
`Unsupported data type '${typeof bigNumberish}' for u512. Expected string, number, bigint, or Uint512 object`
|
|
1337
|
+
);
|
|
1129
1338
|
const bigInt = BigInt(bigNumberish);
|
|
1130
|
-
|
|
1131
|
-
|
|
1339
|
+
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
1340
|
+
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
1132
1341
|
return bigInt;
|
|
1133
1342
|
}
|
|
1134
1343
|
/**
|
|
@@ -1140,9 +1349,10 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1140
1349
|
const l2 = BigInt(limb2);
|
|
1141
1350
|
const l3 = BigInt(limb3);
|
|
1142
1351
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1352
|
+
assert(
|
|
1353
|
+
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
1354
|
+
`limb${index} is not in the range of a u128 number`
|
|
1355
|
+
);
|
|
1146
1356
|
});
|
|
1147
1357
|
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
1148
1358
|
}
|
|
@@ -1163,6 +1373,13 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
1163
1373
|
static isAbiType(abiType) {
|
|
1164
1374
|
return abiType === _CairoUint512.abiSelector;
|
|
1165
1375
|
}
|
|
1376
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1377
|
+
const limb0 = getNext(responseIterator);
|
|
1378
|
+
const limb1 = getNext(responseIterator);
|
|
1379
|
+
const limb2 = getNext(responseIterator);
|
|
1380
|
+
const limb3 = getNext(responseIterator);
|
|
1381
|
+
return new _CairoUint512(limb0, limb1, limb2, limb3);
|
|
1382
|
+
}
|
|
1166
1383
|
/**
|
|
1167
1384
|
* Return bigint representation
|
|
1168
1385
|
*/
|
|
@@ -1217,13 +1434,12 @@ var isTypeEnum = (type, enums) => type in enums;
|
|
|
1217
1434
|
var isTypeOption = (type) => type.startsWith("core::option::Option::");
|
|
1218
1435
|
var isTypeResult = (type) => type.startsWith("core::result::Result::");
|
|
1219
1436
|
var isTypeUint = (type) => Object.values(Uint).includes(type);
|
|
1437
|
+
var isTypeInt = (type) => Object.values(Int).includes(type);
|
|
1220
1438
|
var isTypeUint256 = (type) => CairoUint256.isAbiType(type);
|
|
1221
1439
|
var isTypeLiteral = (type) => Object.values(Literal).includes(type);
|
|
1222
1440
|
var isTypeBool = (type) => type === "core::bool";
|
|
1223
1441
|
var isTypeContractAddress = (type) => type === Literal.ContractAddress;
|
|
1224
1442
|
var isTypeEthAddress = (type) => type === ETH_ADDRESS;
|
|
1225
|
-
var isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
1226
|
-
var isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
1227
1443
|
var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>";
|
|
1228
1444
|
var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
|
|
1229
1445
|
var isCairo1Type = (type) => type.includes("::");
|
|
@@ -1478,15 +1694,1348 @@ function formatter(data, type, sameType) {
|
|
|
1478
1694
|
guard.unknown(data, type, key);
|
|
1479
1695
|
return acc;
|
|
1480
1696
|
},
|
|
1481
|
-
{}
|
|
1482
|
-
);
|
|
1483
|
-
}
|
|
1697
|
+
{}
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
// src/utils/calldata/parser/interface.ts
|
|
1702
|
+
var AbiParserInterface = class {
|
|
1703
|
+
};
|
|
1704
|
+
|
|
1705
|
+
// src/utils/cairoDataTypes/bytes31.ts
|
|
1706
|
+
var CairoBytes31 = class _CairoBytes31 {
|
|
1707
|
+
static MAX_BYTE_SIZE = 31;
|
|
1708
|
+
data;
|
|
1709
|
+
static abiSelector = "core::bytes_31::bytes31";
|
|
1710
|
+
constructor(data) {
|
|
1711
|
+
_CairoBytes31.validate(data);
|
|
1712
|
+
this.data = _CairoBytes31.__processData(data);
|
|
1713
|
+
}
|
|
1714
|
+
static __processData(data) {
|
|
1715
|
+
if (isString(data)) {
|
|
1716
|
+
return stringToUint8Array(data);
|
|
1717
|
+
}
|
|
1718
|
+
if (isBuffer(data)) {
|
|
1719
|
+
return new Uint8Array(data);
|
|
1720
|
+
}
|
|
1721
|
+
if (data instanceof Uint8Array) {
|
|
1722
|
+
return new Uint8Array(data);
|
|
1723
|
+
}
|
|
1724
|
+
throw new Error("Invalid input type for CairoBytes31. Expected string, Buffer, or Uint8Array");
|
|
1725
|
+
}
|
|
1726
|
+
toApiRequest() {
|
|
1727
|
+
return addCompiledFlag([this.toHexString()]);
|
|
1728
|
+
}
|
|
1729
|
+
toBigInt() {
|
|
1730
|
+
return uint8ArrayToBigInt(this.data);
|
|
1731
|
+
}
|
|
1732
|
+
decodeUtf8() {
|
|
1733
|
+
return new TextDecoder().decode(this.data);
|
|
1734
|
+
}
|
|
1735
|
+
toHexString() {
|
|
1736
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
1737
|
+
}
|
|
1738
|
+
static validate(data) {
|
|
1739
|
+
const byteLength = _CairoBytes31.__processData(data).length;
|
|
1740
|
+
assert(
|
|
1741
|
+
byteLength <= this.MAX_BYTE_SIZE,
|
|
1742
|
+
`Data is too long: ${byteLength} bytes (max ${this.MAX_BYTE_SIZE} bytes)`
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
static is(data) {
|
|
1746
|
+
try {
|
|
1747
|
+
_CairoBytes31.validate(data);
|
|
1748
|
+
return true;
|
|
1749
|
+
} catch {
|
|
1750
|
+
return false;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Check if provided abi type is this data type
|
|
1755
|
+
*/
|
|
1756
|
+
static isAbiType(abiType) {
|
|
1757
|
+
return abiType === _CairoBytes31.abiSelector;
|
|
1758
|
+
}
|
|
1759
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1760
|
+
return new _CairoBytes31(getNext(responseIterator));
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
|
|
1764
|
+
// src/utils/errors/rpc.ts
|
|
1765
|
+
var errorCodes = {
|
|
1766
|
+
FAILED_TO_RECEIVE_TXN: 1,
|
|
1767
|
+
NO_TRACE_AVAILABLE: 10,
|
|
1768
|
+
CONTRACT_NOT_FOUND: 20,
|
|
1769
|
+
ENTRYPOINT_NOT_FOUND: 21,
|
|
1770
|
+
BLOCK_NOT_FOUND: 24,
|
|
1771
|
+
INVALID_TXN_INDEX: 27,
|
|
1772
|
+
CLASS_HASH_NOT_FOUND: 28,
|
|
1773
|
+
TXN_HASH_NOT_FOUND: 29,
|
|
1774
|
+
PAGE_SIZE_TOO_BIG: 31,
|
|
1775
|
+
NO_BLOCKS: 32,
|
|
1776
|
+
INVALID_CONTINUATION_TOKEN: 33,
|
|
1777
|
+
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
1778
|
+
CONTRACT_ERROR: 40,
|
|
1779
|
+
TRANSACTION_EXECUTION_ERROR: 41,
|
|
1780
|
+
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
1781
|
+
CLASS_ALREADY_DECLARED: 51,
|
|
1782
|
+
INVALID_TRANSACTION_NONCE: 52,
|
|
1783
|
+
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
1784
|
+
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
1785
|
+
VALIDATION_FAILURE: 55,
|
|
1786
|
+
COMPILATION_FAILED: 56,
|
|
1787
|
+
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
1788
|
+
NON_ACCOUNT: 58,
|
|
1789
|
+
DUPLICATE_TX: 59,
|
|
1790
|
+
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
1791
|
+
UNSUPPORTED_TX_VERSION: 61,
|
|
1792
|
+
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
1793
|
+
UNEXPECTED_ERROR: 63,
|
|
1794
|
+
INVALID_SUBSCRIPTION_ID: 66,
|
|
1795
|
+
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
1796
|
+
TOO_MANY_BLOCKS_BACK: 68,
|
|
1797
|
+
COMPILATION_ERROR: 100,
|
|
1798
|
+
INVALID_ADDRESS: 150,
|
|
1799
|
+
TOKEN_NOT_SUPPORTED: 151,
|
|
1800
|
+
INVALID_SIGNATURE: 153,
|
|
1801
|
+
MAX_AMOUNT_TOO_LOW: 154,
|
|
1802
|
+
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
1803
|
+
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
1804
|
+
INVALID_TIME_BOUNDS: 157,
|
|
1805
|
+
INVALID_DEPLOYMENT_DATA: 158,
|
|
1806
|
+
INVALID_CLASS_HASH: 159,
|
|
1807
|
+
INVALID_ID: 160,
|
|
1808
|
+
UNKNOWN_ERROR: 163
|
|
1809
|
+
};
|
|
1810
|
+
var rpc_default = errorCodes;
|
|
1811
|
+
|
|
1812
|
+
// src/utils/errors/index.ts
|
|
1813
|
+
function fixStack(target, fn = target.constructor) {
|
|
1814
|
+
const { captureStackTrace } = Error;
|
|
1815
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
1816
|
+
}
|
|
1817
|
+
function fixProto(target, prototype) {
|
|
1818
|
+
const { setPrototypeOf } = Object;
|
|
1819
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
1820
|
+
}
|
|
1821
|
+
var CustomError = class extends Error {
|
|
1822
|
+
name;
|
|
1823
|
+
constructor(message) {
|
|
1824
|
+
super(message);
|
|
1825
|
+
Object.defineProperty(this, "name", {
|
|
1826
|
+
value: new.target.name,
|
|
1827
|
+
enumerable: false,
|
|
1828
|
+
configurable: true
|
|
1829
|
+
});
|
|
1830
|
+
fixProto(this, new.target.prototype);
|
|
1831
|
+
fixStack(this);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
var LibraryError = class extends CustomError {
|
|
1835
|
+
};
|
|
1836
|
+
var RpcError = class extends LibraryError {
|
|
1837
|
+
constructor(baseError, method, params) {
|
|
1838
|
+
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
1839
|
+
|
|
1840
|
+
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
1841
|
+
this.baseError = baseError;
|
|
1842
|
+
this.request = { method, params };
|
|
1843
|
+
}
|
|
1844
|
+
request;
|
|
1845
|
+
get code() {
|
|
1846
|
+
return this.baseError.code;
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
1850
|
+
* @example
|
|
1851
|
+
* ```typescript
|
|
1852
|
+
* SomeError.isType('UNEXPECTED_ERROR');
|
|
1853
|
+
* ```
|
|
1854
|
+
*/
|
|
1855
|
+
isType(typeName) {
|
|
1856
|
+
return rpc_default[typeName] === this.code;
|
|
1857
|
+
}
|
|
1858
|
+
};
|
|
1859
|
+
var TimeoutError = class extends LibraryError {
|
|
1860
|
+
constructor(message) {
|
|
1861
|
+
super(message);
|
|
1862
|
+
this.name = "TimeoutError";
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
var WebSocketNotConnectedError = class extends LibraryError {
|
|
1866
|
+
constructor(message) {
|
|
1867
|
+
super(message);
|
|
1868
|
+
this.name = "WebSocketNotConnectedError";
|
|
1869
|
+
}
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
// src/utils/connect/buffer.ts
|
|
1873
|
+
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 {
|
|
1874
|
+
constructor() {
|
|
1875
|
+
throw new LibraryError(
|
|
1876
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
1877
|
+
);
|
|
1878
|
+
}
|
|
1879
|
+
static from(_data) {
|
|
1880
|
+
throw new LibraryError(
|
|
1881
|
+
`Buffer not detected, use 'config.set("buffer", YourBufferPolyfill)' or polyfill or Node.js environment for Buffer support`
|
|
1882
|
+
);
|
|
1883
|
+
}
|
|
1884
|
+
static isBuffer(obj) {
|
|
1885
|
+
const BufferImpl = config.get("buffer") || typeof Buffer !== "undefined" && Buffer;
|
|
1886
|
+
return BufferImpl && BufferImpl.isBuffer && BufferImpl.isBuffer(obj);
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
// src/utils/cairoDataTypes/uint32.ts
|
|
1891
|
+
var CairoUint32 = class _CairoUint32 {
|
|
1892
|
+
data;
|
|
1893
|
+
static abiSelector = "core::u32::u32";
|
|
1894
|
+
constructor(data) {
|
|
1895
|
+
_CairoUint32.validate(data);
|
|
1896
|
+
this.data = _CairoUint32.__processData(data);
|
|
1897
|
+
}
|
|
1898
|
+
static __processData(data) {
|
|
1899
|
+
if (isString(data) && isText(data)) {
|
|
1900
|
+
return utf8ToBigInt(data);
|
|
1901
|
+
}
|
|
1902
|
+
return BigInt(data);
|
|
1903
|
+
}
|
|
1904
|
+
toApiRequest() {
|
|
1905
|
+
return addCompiledFlag([this.toHexString()]);
|
|
1906
|
+
}
|
|
1907
|
+
toBigInt() {
|
|
1908
|
+
return this.data;
|
|
1909
|
+
}
|
|
1910
|
+
decodeUtf8() {
|
|
1911
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
1912
|
+
}
|
|
1913
|
+
toHexString() {
|
|
1914
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
1915
|
+
}
|
|
1916
|
+
static validate(data) {
|
|
1917
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
1918
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
1919
|
+
assert(
|
|
1920
|
+
!isNumber(data) || Number.isInteger(data),
|
|
1921
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
1922
|
+
);
|
|
1923
|
+
const value = _CairoUint32.__processData(data);
|
|
1924
|
+
assert(value >= 0n && value <= 2n ** 32n - 1n, "Value is out of u32 range [0, 2^32)");
|
|
1925
|
+
}
|
|
1926
|
+
static is(data) {
|
|
1927
|
+
try {
|
|
1928
|
+
_CairoUint32.validate(data);
|
|
1929
|
+
return true;
|
|
1930
|
+
} catch {
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Check if provided abi type is this data type
|
|
1936
|
+
*/
|
|
1937
|
+
static isAbiType(abiType) {
|
|
1938
|
+
return abiType === _CairoUint32.abiSelector;
|
|
1939
|
+
}
|
|
1940
|
+
static factoryFromApiResponse(responseIterator) {
|
|
1941
|
+
return new _CairoUint32(getNext(responseIterator));
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
// src/utils/cairoDataTypes/byteArray.ts
|
|
1946
|
+
var CairoByteArray = class _CairoByteArray {
|
|
1947
|
+
/**
|
|
1948
|
+
* entire dataset
|
|
1949
|
+
*/
|
|
1950
|
+
data = [];
|
|
1951
|
+
/**
|
|
1952
|
+
* cairo specific implementation helper
|
|
1953
|
+
*/
|
|
1954
|
+
pending_word;
|
|
1955
|
+
// felt
|
|
1956
|
+
/**
|
|
1957
|
+
* cairo specific implementation helper
|
|
1958
|
+
*/
|
|
1959
|
+
pending_word_len;
|
|
1960
|
+
// u32
|
|
1961
|
+
static abiSelector = "core::byte_array::ByteArray";
|
|
1962
|
+
constructor(...arr) {
|
|
1963
|
+
if (arr.length === 3) {
|
|
1964
|
+
const [dataArg, pendingWord, pendingWordLen] = arr;
|
|
1965
|
+
assert(
|
|
1966
|
+
Array.isArray(dataArg) && pendingWord instanceof CairoFelt252 && pendingWordLen instanceof CairoUint32,
|
|
1967
|
+
"Invalid constructor parameters. Expected (CairoBytes31[], CairoFelt252, CairoUint32)"
|
|
1968
|
+
);
|
|
1969
|
+
this.data = dataArg;
|
|
1970
|
+
this.pending_word = pendingWord;
|
|
1971
|
+
this.pending_word_len = pendingWordLen;
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
const inData = arr[0];
|
|
1975
|
+
_CairoByteArray.validate(inData);
|
|
1976
|
+
const { data, pending_word, pending_word_len } = _CairoByteArray.__processData(inData);
|
|
1977
|
+
this.data = data;
|
|
1978
|
+
this.pending_word = pending_word;
|
|
1979
|
+
this.pending_word_len = pending_word_len;
|
|
1980
|
+
}
|
|
1981
|
+
static __processData(inData) {
|
|
1982
|
+
let fullData;
|
|
1983
|
+
if (inData instanceof Uint8Array) {
|
|
1984
|
+
fullData = inData;
|
|
1985
|
+
} else if (isBuffer(inData)) {
|
|
1986
|
+
fullData = new Uint8Array(inData);
|
|
1987
|
+
} else if (isString(inData)) {
|
|
1988
|
+
fullData = stringToUint8Array(inData);
|
|
1989
|
+
} else if (isBigInt(inData)) {
|
|
1990
|
+
fullData = bigIntToUint8Array(inData);
|
|
1991
|
+
} else if (isInteger2(inData)) {
|
|
1992
|
+
fullData = bigIntToUint8Array(BigInt(inData));
|
|
1993
|
+
} else {
|
|
1994
|
+
throw new Error("Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint");
|
|
1995
|
+
}
|
|
1996
|
+
const CHUNK_SIZE = CairoBytes31.MAX_BYTE_SIZE;
|
|
1997
|
+
const completeChunks = Math.floor(fullData.length / CHUNK_SIZE);
|
|
1998
|
+
const remainderLength = fullData.length % CHUNK_SIZE;
|
|
1999
|
+
const data = [];
|
|
2000
|
+
let pending_word;
|
|
2001
|
+
let pending_word_len;
|
|
2002
|
+
for (let i = 0; i < completeChunks; i += 1) {
|
|
2003
|
+
const chunkStart = i * CHUNK_SIZE;
|
|
2004
|
+
const chunkEnd = chunkStart + CHUNK_SIZE;
|
|
2005
|
+
const chunk = fullData.slice(chunkStart, chunkEnd);
|
|
2006
|
+
data.push(new CairoBytes31(chunk));
|
|
2007
|
+
}
|
|
2008
|
+
if (remainderLength > 0) {
|
|
2009
|
+
const remainder = fullData.slice(completeChunks * CHUNK_SIZE);
|
|
2010
|
+
let hex = "0x";
|
|
2011
|
+
for (let i = 0; i < remainder.length; i += 1) {
|
|
2012
|
+
hex += remainder[i].toString(16).padStart(2, "0");
|
|
2013
|
+
}
|
|
2014
|
+
pending_word = new CairoFelt252(hex);
|
|
2015
|
+
pending_word_len = new CairoUint32(remainderLength);
|
|
2016
|
+
} else {
|
|
2017
|
+
pending_word = new CairoFelt252(0);
|
|
2018
|
+
pending_word_len = new CairoUint32(0);
|
|
2019
|
+
}
|
|
2020
|
+
return { data, pending_word, pending_word_len };
|
|
2021
|
+
}
|
|
2022
|
+
toApiRequest() {
|
|
2023
|
+
this.assertInitialized();
|
|
2024
|
+
return addCompiledFlag([
|
|
2025
|
+
addHexPrefix(this.data.length.toString(16)),
|
|
2026
|
+
...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
|
|
2027
|
+
...this.pending_word.toApiRequest(),
|
|
2028
|
+
...this.pending_word_len.toApiRequest()
|
|
2029
|
+
]);
|
|
2030
|
+
}
|
|
2031
|
+
decodeUtf8() {
|
|
2032
|
+
const allBytes = this.reconstructBytes();
|
|
2033
|
+
const fullBytes = new Uint8Array(allBytes);
|
|
2034
|
+
return new TextDecoder().decode(fullBytes);
|
|
2035
|
+
}
|
|
2036
|
+
toBigInt() {
|
|
2037
|
+
const allBytes = this.reconstructBytes();
|
|
2038
|
+
if (allBytes.length === 0) {
|
|
2039
|
+
return 0n;
|
|
2040
|
+
}
|
|
2041
|
+
let result = 0n;
|
|
2042
|
+
allBytes.forEach((byte) => {
|
|
2043
|
+
result = result * 256n + BigInt(byte);
|
|
2044
|
+
});
|
|
2045
|
+
return result;
|
|
2046
|
+
}
|
|
2047
|
+
toHexString() {
|
|
2048
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2049
|
+
}
|
|
2050
|
+
toBuffer() {
|
|
2051
|
+
this.assertInitialized();
|
|
2052
|
+
const allBytes = [];
|
|
2053
|
+
this.data.forEach((chunk) => {
|
|
2054
|
+
const chunkBytes = chunk.data;
|
|
2055
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
2056
|
+
allBytes.push(chunkBytes[i]);
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2060
|
+
if (pendingLen > 0) {
|
|
2061
|
+
const hex = this.pending_word.toHexString();
|
|
2062
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
2063
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2064
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
2065
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
2066
|
+
if (byteHex.length >= 2) {
|
|
2067
|
+
const byteValue = parseInt(byteHex, 16);
|
|
2068
|
+
if (!Number.isNaN(byteValue)) {
|
|
2069
|
+
allBytes.push(byteValue);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
return buffer_default.from(allBytes);
|
|
2075
|
+
}
|
|
2076
|
+
static validate(data) {
|
|
2077
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2078
|
+
assert(
|
|
2079
|
+
!Array.isArray(data) || data instanceof Uint8Array,
|
|
2080
|
+
"Invalid input: arrays are not supported, use Uint8Array"
|
|
2081
|
+
);
|
|
2082
|
+
assert(
|
|
2083
|
+
typeof data !== "object" || isBuffer(data) || data instanceof Uint8Array,
|
|
2084
|
+
"Invalid input for CairoByteArray: objects are not supported"
|
|
2085
|
+
);
|
|
2086
|
+
assert(
|
|
2087
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2088
|
+
"Invalid input for CairoByteArray: decimal numbers are not supported, only integers"
|
|
2089
|
+
);
|
|
2090
|
+
assert(
|
|
2091
|
+
!isNumber(data) || data >= 0,
|
|
2092
|
+
"Invalid input for CairoByteArray: negative numbers are not supported"
|
|
2093
|
+
);
|
|
2094
|
+
assert(
|
|
2095
|
+
!isBigInt(data) || data >= 0n,
|
|
2096
|
+
"Invalid input for CairoByteArray: negative bigints are not supported"
|
|
2097
|
+
);
|
|
2098
|
+
assert(
|
|
2099
|
+
data instanceof Uint8Array || isBuffer(data) || isString(data) || isNumber(data) || isBigInt(data),
|
|
2100
|
+
"Invalid input type. Expected Uint8Array, Buffer, string, number, or bigint"
|
|
2101
|
+
);
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Check if the provided data is a valid CairoByteArray
|
|
2105
|
+
*
|
|
2106
|
+
* @param data - The data to check
|
|
2107
|
+
* @returns True if the data is a valid CairoByteArray, false otherwise
|
|
2108
|
+
*/
|
|
2109
|
+
static is(data) {
|
|
2110
|
+
try {
|
|
2111
|
+
_CairoByteArray.validate(data);
|
|
2112
|
+
return true;
|
|
2113
|
+
} catch {
|
|
2114
|
+
return false;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Check if provided abi type is this data type
|
|
2119
|
+
*/
|
|
2120
|
+
static isAbiType(abiType) {
|
|
2121
|
+
return abiType === _CairoByteArray.abiSelector;
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Private helper to check if the CairoByteArray is properly initialized
|
|
2125
|
+
*/
|
|
2126
|
+
assertInitialized() {
|
|
2127
|
+
assert(
|
|
2128
|
+
this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
|
|
2129
|
+
"CairoByteArray is not properly initialized"
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Private helper to reconstruct the full byte sequence from chunks and pending word
|
|
2134
|
+
*/
|
|
2135
|
+
reconstructBytes() {
|
|
2136
|
+
this.assertInitialized();
|
|
2137
|
+
const allBytes = [];
|
|
2138
|
+
this.data.forEach((chunk) => {
|
|
2139
|
+
const chunkBytes = chunk.data;
|
|
2140
|
+
for (let i = 0; i < chunkBytes.length; i += 1) {
|
|
2141
|
+
allBytes.push(chunkBytes[i]);
|
|
2142
|
+
}
|
|
2143
|
+
});
|
|
2144
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2145
|
+
if (pendingLen > 0) {
|
|
2146
|
+
const hex = this.pending_word.toHexString();
|
|
2147
|
+
const hexWithoutPrefix = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
2148
|
+
const paddedHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2149
|
+
for (let i = 0; i < pendingLen; i += 1) {
|
|
2150
|
+
const byteHex = paddedHex.slice(i * 2, i * 2 + 2);
|
|
2151
|
+
if (byteHex.length < 2) {
|
|
2152
|
+
allBytes.push(0);
|
|
2153
|
+
} else {
|
|
2154
|
+
const byteValue = parseInt(byteHex, 16);
|
|
2155
|
+
if (Number.isNaN(byteValue)) {
|
|
2156
|
+
throw new Error(`Invalid hex byte: ${byteHex}`);
|
|
2157
|
+
}
|
|
2158
|
+
allBytes.push(byteValue);
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
return allBytes;
|
|
2163
|
+
}
|
|
2164
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2165
|
+
const data = Array.from(
|
|
2166
|
+
{ length: Number(getNext(responseIterator)) },
|
|
2167
|
+
() => CairoBytes31.factoryFromApiResponse(responseIterator)
|
|
2168
|
+
);
|
|
2169
|
+
const pending_word = CairoFelt252.factoryFromApiResponse(responseIterator);
|
|
2170
|
+
const pending_word_len = CairoUint32.factoryFromApiResponse(responseIterator);
|
|
2171
|
+
return new _CairoByteArray(data, pending_word, pending_word_len);
|
|
2172
|
+
}
|
|
2173
|
+
};
|
|
2174
|
+
|
|
2175
|
+
// src/utils/cairoDataTypes/uint8.ts
|
|
2176
|
+
var CairoUint8 = class _CairoUint8 {
|
|
2177
|
+
data;
|
|
2178
|
+
static abiSelector = "core::integer::u8";
|
|
2179
|
+
constructor(data) {
|
|
2180
|
+
_CairoUint8.validate(data);
|
|
2181
|
+
this.data = _CairoUint8.__processData(data);
|
|
2182
|
+
}
|
|
2183
|
+
static __processData(data) {
|
|
2184
|
+
if (isString(data) && isText(data)) {
|
|
2185
|
+
return utf8ToBigInt(data);
|
|
2186
|
+
}
|
|
2187
|
+
return BigInt(data);
|
|
2188
|
+
}
|
|
2189
|
+
toApiRequest() {
|
|
2190
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2191
|
+
}
|
|
2192
|
+
toBigInt() {
|
|
2193
|
+
return this.data;
|
|
2194
|
+
}
|
|
2195
|
+
decodeUtf8() {
|
|
2196
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2197
|
+
}
|
|
2198
|
+
toHexString() {
|
|
2199
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2200
|
+
}
|
|
2201
|
+
static validate(data) {
|
|
2202
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2203
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2204
|
+
assert(
|
|
2205
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2206
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2207
|
+
);
|
|
2208
|
+
const value = _CairoUint8.__processData(data);
|
|
2209
|
+
assert(
|
|
2210
|
+
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
2211
|
+
`Value is out of u8 range [${RANGE_U8.min}, ${RANGE_U8.max}]`
|
|
2212
|
+
);
|
|
2213
|
+
}
|
|
2214
|
+
static is(data) {
|
|
2215
|
+
try {
|
|
2216
|
+
_CairoUint8.validate(data);
|
|
2217
|
+
return true;
|
|
2218
|
+
} catch {
|
|
2219
|
+
return false;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Check if provided abi type is this data type
|
|
2224
|
+
*/
|
|
2225
|
+
static isAbiType(abiType) {
|
|
2226
|
+
return abiType === _CairoUint8.abiSelector;
|
|
2227
|
+
}
|
|
2228
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2229
|
+
return new _CairoUint8(getNext(responseIterator));
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
|
|
2233
|
+
// src/utils/cairoDataTypes/uint16.ts
|
|
2234
|
+
var CairoUint16 = class _CairoUint16 {
|
|
2235
|
+
data;
|
|
2236
|
+
static abiSelector = "core::integer::u16";
|
|
2237
|
+
constructor(data) {
|
|
2238
|
+
_CairoUint16.validate(data);
|
|
2239
|
+
this.data = _CairoUint16.__processData(data);
|
|
2240
|
+
}
|
|
2241
|
+
static __processData(data) {
|
|
2242
|
+
if (isString(data) && isText(data)) {
|
|
2243
|
+
return utf8ToBigInt(data);
|
|
2244
|
+
}
|
|
2245
|
+
return BigInt(data);
|
|
2246
|
+
}
|
|
2247
|
+
toApiRequest() {
|
|
2248
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2249
|
+
}
|
|
2250
|
+
toBigInt() {
|
|
2251
|
+
return this.data;
|
|
2252
|
+
}
|
|
2253
|
+
decodeUtf8() {
|
|
2254
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2255
|
+
}
|
|
2256
|
+
toHexString() {
|
|
2257
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2258
|
+
}
|
|
2259
|
+
static validate(data) {
|
|
2260
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2261
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2262
|
+
assert(
|
|
2263
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2264
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2265
|
+
);
|
|
2266
|
+
const value = _CairoUint16.__processData(data);
|
|
2267
|
+
assert(
|
|
2268
|
+
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
2269
|
+
`Value is out of u16 range [${RANGE_U16.min}, ${RANGE_U16.max}]`
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
static is(data) {
|
|
2273
|
+
try {
|
|
2274
|
+
_CairoUint16.validate(data);
|
|
2275
|
+
return true;
|
|
2276
|
+
} catch {
|
|
2277
|
+
return false;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* Check if provided abi type is this data type
|
|
2282
|
+
*/
|
|
2283
|
+
static isAbiType(abiType) {
|
|
2284
|
+
return abiType === _CairoUint16.abiSelector;
|
|
2285
|
+
}
|
|
2286
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2287
|
+
return new _CairoUint16(getNext(responseIterator));
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
// src/utils/cairoDataTypes/uint64.ts
|
|
2292
|
+
var CairoUint64 = class _CairoUint64 {
|
|
2293
|
+
data;
|
|
2294
|
+
static abiSelector = "core::integer::u64";
|
|
2295
|
+
constructor(data) {
|
|
2296
|
+
_CairoUint64.validate(data);
|
|
2297
|
+
this.data = _CairoUint64.__processData(data);
|
|
2298
|
+
}
|
|
2299
|
+
static __processData(data) {
|
|
2300
|
+
if (isString(data) && isText(data)) {
|
|
2301
|
+
return utf8ToBigInt(data);
|
|
2302
|
+
}
|
|
2303
|
+
return BigInt(data);
|
|
2304
|
+
}
|
|
2305
|
+
toApiRequest() {
|
|
2306
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2307
|
+
}
|
|
2308
|
+
toBigInt() {
|
|
2309
|
+
return this.data;
|
|
2310
|
+
}
|
|
2311
|
+
decodeUtf8() {
|
|
2312
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2313
|
+
}
|
|
2314
|
+
toHexString() {
|
|
2315
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2316
|
+
}
|
|
2317
|
+
static validate(data) {
|
|
2318
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2319
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2320
|
+
assert(
|
|
2321
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2322
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2323
|
+
);
|
|
2324
|
+
const value = _CairoUint64.__processData(data);
|
|
2325
|
+
assert(
|
|
2326
|
+
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
2327
|
+
`Value is out of u64 range [${RANGE_U64.min}, ${RANGE_U64.max}]`
|
|
2328
|
+
);
|
|
2329
|
+
}
|
|
2330
|
+
static is(data) {
|
|
2331
|
+
try {
|
|
2332
|
+
_CairoUint64.validate(data);
|
|
2333
|
+
return true;
|
|
2334
|
+
} catch {
|
|
2335
|
+
return false;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Check if provided abi type is this data type
|
|
2340
|
+
*/
|
|
2341
|
+
static isAbiType(abiType) {
|
|
2342
|
+
return abiType === _CairoUint64.abiSelector;
|
|
2343
|
+
}
|
|
2344
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2345
|
+
return new _CairoUint64(getNext(responseIterator));
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
|
|
2349
|
+
// src/utils/cairoDataTypes/uint96.ts
|
|
2350
|
+
var CairoUint96 = class _CairoUint96 {
|
|
2351
|
+
data;
|
|
2352
|
+
static abiSelector = "core::integer::u96";
|
|
2353
|
+
constructor(data) {
|
|
2354
|
+
_CairoUint96.validate(data);
|
|
2355
|
+
this.data = _CairoUint96.__processData(data);
|
|
2356
|
+
}
|
|
2357
|
+
static __processData(data) {
|
|
2358
|
+
if (isString(data) && isText(data)) {
|
|
2359
|
+
return utf8ToBigInt(data);
|
|
2360
|
+
}
|
|
2361
|
+
return BigInt(data);
|
|
2362
|
+
}
|
|
2363
|
+
toApiRequest() {
|
|
2364
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2365
|
+
}
|
|
2366
|
+
toBigInt() {
|
|
2367
|
+
return this.data;
|
|
2368
|
+
}
|
|
2369
|
+
decodeUtf8() {
|
|
2370
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2371
|
+
}
|
|
2372
|
+
toHexString() {
|
|
2373
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2374
|
+
}
|
|
2375
|
+
static validate(data) {
|
|
2376
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2377
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2378
|
+
assert(
|
|
2379
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2380
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2381
|
+
);
|
|
2382
|
+
const value = _CairoUint96.__processData(data);
|
|
2383
|
+
assert(
|
|
2384
|
+
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
2385
|
+
`Value is out of u96 range [${RANGE_U96.min}, ${RANGE_U96.max}]`
|
|
2386
|
+
);
|
|
2387
|
+
}
|
|
2388
|
+
static is(data) {
|
|
2389
|
+
try {
|
|
2390
|
+
_CairoUint96.validate(data);
|
|
2391
|
+
return true;
|
|
2392
|
+
} catch {
|
|
2393
|
+
return false;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Check if provided abi type is this data type
|
|
2398
|
+
*/
|
|
2399
|
+
static isAbiType(abiType) {
|
|
2400
|
+
return abiType === _CairoUint96.abiSelector;
|
|
2401
|
+
}
|
|
2402
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2403
|
+
return new _CairoUint96(getNext(responseIterator));
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
|
|
2407
|
+
// src/utils/cairoDataTypes/uint128.ts
|
|
2408
|
+
var CairoUint128 = class _CairoUint128 {
|
|
2409
|
+
data;
|
|
2410
|
+
static abiSelector = "core::integer::u128";
|
|
2411
|
+
constructor(data) {
|
|
2412
|
+
_CairoUint128.validate(data);
|
|
2413
|
+
this.data = _CairoUint128.__processData(data);
|
|
2414
|
+
}
|
|
2415
|
+
static __processData(data) {
|
|
2416
|
+
if (isString(data) && isText(data)) {
|
|
2417
|
+
return utf8ToBigInt(data);
|
|
2418
|
+
}
|
|
2419
|
+
return BigInt(data);
|
|
2420
|
+
}
|
|
2421
|
+
toApiRequest() {
|
|
2422
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2423
|
+
}
|
|
2424
|
+
toBigInt() {
|
|
2425
|
+
return this.data;
|
|
2426
|
+
}
|
|
2427
|
+
decodeUtf8() {
|
|
2428
|
+
return new TextDecoder().decode(bigIntToUint8Array(this.data));
|
|
2429
|
+
}
|
|
2430
|
+
toHexString() {
|
|
2431
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
2432
|
+
}
|
|
2433
|
+
static validate(data) {
|
|
2434
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2435
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2436
|
+
assert(
|
|
2437
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2438
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2439
|
+
);
|
|
2440
|
+
const value = _CairoUint128.__processData(data);
|
|
2441
|
+
assert(
|
|
2442
|
+
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
2443
|
+
`Value is out of u128 range [${RANGE_U128.min}, ${RANGE_U128.max}]`
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
static is(data) {
|
|
2447
|
+
try {
|
|
2448
|
+
_CairoUint128.validate(data);
|
|
2449
|
+
return true;
|
|
2450
|
+
} catch {
|
|
2451
|
+
return false;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Check if provided abi type is this data type
|
|
2456
|
+
*/
|
|
2457
|
+
static isAbiType(abiType) {
|
|
2458
|
+
return abiType === _CairoUint128.abiSelector;
|
|
2459
|
+
}
|
|
2460
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2461
|
+
return new _CairoUint128(getNext(responseIterator));
|
|
2462
|
+
}
|
|
2463
|
+
};
|
|
2464
|
+
|
|
2465
|
+
// src/utils/cairoDataTypes/int8.ts
|
|
2466
|
+
var CairoInt8 = class _CairoInt8 {
|
|
2467
|
+
data;
|
|
2468
|
+
static abiSelector = "core::integer::i8";
|
|
2469
|
+
constructor(data) {
|
|
2470
|
+
_CairoInt8.validate(data);
|
|
2471
|
+
this.data = _CairoInt8.__processData(data);
|
|
2472
|
+
}
|
|
2473
|
+
static __processData(data) {
|
|
2474
|
+
if (isString(data) && isText(data)) {
|
|
2475
|
+
return utf8ToBigInt(data);
|
|
2476
|
+
}
|
|
2477
|
+
return BigInt(data);
|
|
2478
|
+
}
|
|
2479
|
+
toApiRequest() {
|
|
2480
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2481
|
+
}
|
|
2482
|
+
toBigInt() {
|
|
2483
|
+
return this.data;
|
|
2484
|
+
}
|
|
2485
|
+
decodeUtf8() {
|
|
2486
|
+
return new TextDecoder().decode(
|
|
2487
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 256n + this.data)
|
|
2488
|
+
);
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* For negative values field element representation as positive hex string.
|
|
2492
|
+
* @returns cairo field arithmetic hex string
|
|
2493
|
+
*/
|
|
2494
|
+
toHexString() {
|
|
2495
|
+
const value = this.toBigInt();
|
|
2496
|
+
if (value < 0n) {
|
|
2497
|
+
const fieldElement = PRIME + value;
|
|
2498
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2499
|
+
}
|
|
2500
|
+
return addHexPrefix(value.toString(16));
|
|
2501
|
+
}
|
|
2502
|
+
static validate(data) {
|
|
2503
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2504
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2505
|
+
assert(
|
|
2506
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2507
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2508
|
+
);
|
|
2509
|
+
const value = _CairoInt8.__processData(data);
|
|
2510
|
+
assert(
|
|
2511
|
+
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
2512
|
+
`Value is out of i8 range [${RANGE_I8.min}, ${RANGE_I8.max}]`
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
static is(data) {
|
|
2516
|
+
try {
|
|
2517
|
+
_CairoInt8.validate(data);
|
|
2518
|
+
return true;
|
|
2519
|
+
} catch {
|
|
2520
|
+
return false;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Check if provided abi type is this data type
|
|
2525
|
+
*/
|
|
2526
|
+
static isAbiType(abiType) {
|
|
2527
|
+
return abiType === _CairoInt8.abiSelector;
|
|
2528
|
+
}
|
|
2529
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2530
|
+
const response = getNext(responseIterator);
|
|
2531
|
+
const value = BigInt(response);
|
|
2532
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2533
|
+
return new _CairoInt8(signedValue);
|
|
2534
|
+
}
|
|
2535
|
+
};
|
|
2536
|
+
|
|
2537
|
+
// src/utils/cairoDataTypes/int16.ts
|
|
2538
|
+
var CairoInt16 = class _CairoInt16 {
|
|
2539
|
+
data;
|
|
2540
|
+
static abiSelector = "core::integer::i16";
|
|
2541
|
+
constructor(data) {
|
|
2542
|
+
_CairoInt16.validate(data);
|
|
2543
|
+
this.data = _CairoInt16.__processData(data);
|
|
2544
|
+
}
|
|
2545
|
+
static __processData(data) {
|
|
2546
|
+
if (isString(data) && isText(data)) {
|
|
2547
|
+
return utf8ToBigInt(data);
|
|
2548
|
+
}
|
|
2549
|
+
return BigInt(data);
|
|
2550
|
+
}
|
|
2551
|
+
toApiRequest() {
|
|
2552
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2553
|
+
}
|
|
2554
|
+
toBigInt() {
|
|
2555
|
+
return this.data;
|
|
2556
|
+
}
|
|
2557
|
+
decodeUtf8() {
|
|
2558
|
+
return new TextDecoder().decode(
|
|
2559
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 65536n + this.data)
|
|
2560
|
+
);
|
|
2561
|
+
}
|
|
2562
|
+
/**
|
|
2563
|
+
* For negative values field element representation as positive hex string.
|
|
2564
|
+
* @returns cairo field arithmetic hex string
|
|
2565
|
+
*/
|
|
2566
|
+
toHexString() {
|
|
2567
|
+
const value = this.toBigInt();
|
|
2568
|
+
if (value < 0n) {
|
|
2569
|
+
const fieldElement = PRIME + value;
|
|
2570
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2571
|
+
}
|
|
2572
|
+
return addHexPrefix(value.toString(16));
|
|
2573
|
+
}
|
|
2574
|
+
static validate(data) {
|
|
2575
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2576
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2577
|
+
assert(
|
|
2578
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2579
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2580
|
+
);
|
|
2581
|
+
const value = _CairoInt16.__processData(data);
|
|
2582
|
+
assert(
|
|
2583
|
+
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
2584
|
+
`Value is out of i16 range [${RANGE_I16.min}, ${RANGE_I16.max}]`
|
|
2585
|
+
);
|
|
2586
|
+
}
|
|
2587
|
+
static is(data) {
|
|
2588
|
+
try {
|
|
2589
|
+
_CairoInt16.validate(data);
|
|
2590
|
+
return true;
|
|
2591
|
+
} catch {
|
|
2592
|
+
return false;
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
/**
|
|
2596
|
+
* Check if provided abi type is this data type
|
|
2597
|
+
*/
|
|
2598
|
+
static isAbiType(abiType) {
|
|
2599
|
+
return abiType === _CairoInt16.abiSelector;
|
|
2600
|
+
}
|
|
2601
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2602
|
+
const response = getNext(responseIterator);
|
|
2603
|
+
const value = BigInt(response);
|
|
2604
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2605
|
+
return new _CairoInt16(signedValue);
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
|
|
2609
|
+
// src/utils/cairoDataTypes/int32.ts
|
|
2610
|
+
var CairoInt32 = class _CairoInt32 {
|
|
2611
|
+
data;
|
|
2612
|
+
static abiSelector = "core::integer::i32";
|
|
2613
|
+
constructor(data) {
|
|
2614
|
+
_CairoInt32.validate(data);
|
|
2615
|
+
this.data = _CairoInt32.__processData(data);
|
|
2616
|
+
}
|
|
2617
|
+
static __processData(data) {
|
|
2618
|
+
if (isString(data) && isText(data)) {
|
|
2619
|
+
return utf8ToBigInt(data);
|
|
2620
|
+
}
|
|
2621
|
+
return BigInt(data);
|
|
2622
|
+
}
|
|
2623
|
+
toApiRequest() {
|
|
2624
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2625
|
+
}
|
|
2626
|
+
toBigInt() {
|
|
2627
|
+
return this.data;
|
|
2628
|
+
}
|
|
2629
|
+
decodeUtf8() {
|
|
2630
|
+
return new TextDecoder().decode(
|
|
2631
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 4294967296n + this.data)
|
|
2632
|
+
);
|
|
2633
|
+
}
|
|
2634
|
+
/**
|
|
2635
|
+
* For negative values field element representation as positive hex string.
|
|
2636
|
+
* @returns cairo field arithmetic hex string
|
|
2637
|
+
*/
|
|
2638
|
+
toHexString() {
|
|
2639
|
+
const value = this.toBigInt();
|
|
2640
|
+
if (value < 0n) {
|
|
2641
|
+
const fieldElement = PRIME + value;
|
|
2642
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2643
|
+
}
|
|
2644
|
+
return addHexPrefix(value.toString(16));
|
|
2645
|
+
}
|
|
2646
|
+
static validate(data) {
|
|
2647
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2648
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2649
|
+
assert(
|
|
2650
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2651
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2652
|
+
);
|
|
2653
|
+
const value = _CairoInt32.__processData(data);
|
|
2654
|
+
assert(
|
|
2655
|
+
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
2656
|
+
`Value is out of i32 range [${RANGE_I32.min}, ${RANGE_I32.max}]`
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
static is(data) {
|
|
2660
|
+
try {
|
|
2661
|
+
_CairoInt32.validate(data);
|
|
2662
|
+
return true;
|
|
2663
|
+
} catch {
|
|
2664
|
+
return false;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* Check if provided abi type is this data type
|
|
2669
|
+
*/
|
|
2670
|
+
static isAbiType(abiType) {
|
|
2671
|
+
return abiType === _CairoInt32.abiSelector;
|
|
2672
|
+
}
|
|
2673
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2674
|
+
const response = getNext(responseIterator);
|
|
2675
|
+
const value = BigInt(response);
|
|
2676
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2677
|
+
return new _CairoInt32(signedValue);
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2680
|
+
|
|
2681
|
+
// src/utils/cairoDataTypes/int64.ts
|
|
2682
|
+
var CairoInt64 = class _CairoInt64 {
|
|
2683
|
+
data;
|
|
2684
|
+
static abiSelector = "core::integer::i64";
|
|
2685
|
+
constructor(data) {
|
|
2686
|
+
_CairoInt64.validate(data);
|
|
2687
|
+
this.data = _CairoInt64.__processData(data);
|
|
2688
|
+
}
|
|
2689
|
+
static __processData(data) {
|
|
2690
|
+
if (isString(data) && isText(data)) {
|
|
2691
|
+
return utf8ToBigInt(data);
|
|
2692
|
+
}
|
|
2693
|
+
return BigInt(data);
|
|
2694
|
+
}
|
|
2695
|
+
toApiRequest() {
|
|
2696
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2697
|
+
}
|
|
2698
|
+
toBigInt() {
|
|
2699
|
+
return this.data;
|
|
2700
|
+
}
|
|
2701
|
+
decodeUtf8() {
|
|
2702
|
+
return new TextDecoder().decode(
|
|
2703
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 64n + this.data)
|
|
2704
|
+
);
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* For negative values field element representation as positive hex string.
|
|
2708
|
+
* @returns cairo field arithmetic hex string
|
|
2709
|
+
*/
|
|
2710
|
+
toHexString() {
|
|
2711
|
+
const value = this.toBigInt();
|
|
2712
|
+
if (value < 0n) {
|
|
2713
|
+
const fieldElement = PRIME + value;
|
|
2714
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2715
|
+
}
|
|
2716
|
+
return addHexPrefix(value.toString(16));
|
|
2717
|
+
}
|
|
2718
|
+
static validate(data) {
|
|
2719
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2720
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2721
|
+
assert(
|
|
2722
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2723
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2724
|
+
);
|
|
2725
|
+
const value = _CairoInt64.__processData(data);
|
|
2726
|
+
assert(
|
|
2727
|
+
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
2728
|
+
`Value is out of i64 range [${RANGE_I64.min}, ${RANGE_I64.max}]`
|
|
2729
|
+
);
|
|
2730
|
+
}
|
|
2731
|
+
static is(data) {
|
|
2732
|
+
try {
|
|
2733
|
+
_CairoInt64.validate(data);
|
|
2734
|
+
return true;
|
|
2735
|
+
} catch {
|
|
2736
|
+
return false;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Check if provided abi type is this data type
|
|
2741
|
+
*/
|
|
2742
|
+
static isAbiType(abiType) {
|
|
2743
|
+
return abiType === _CairoInt64.abiSelector;
|
|
2744
|
+
}
|
|
2745
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2746
|
+
const response = getNext(responseIterator);
|
|
2747
|
+
const value = BigInt(response);
|
|
2748
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2749
|
+
return new _CairoInt64(signedValue);
|
|
2750
|
+
}
|
|
2751
|
+
};
|
|
2752
|
+
|
|
2753
|
+
// src/utils/cairoDataTypes/int128.ts
|
|
2754
|
+
var CairoInt128 = class _CairoInt128 {
|
|
2755
|
+
data;
|
|
2756
|
+
static abiSelector = "core::integer::i128";
|
|
2757
|
+
constructor(data) {
|
|
2758
|
+
_CairoInt128.validate(data);
|
|
2759
|
+
this.data = _CairoInt128.__processData(data);
|
|
2760
|
+
}
|
|
2761
|
+
static __processData(data) {
|
|
2762
|
+
if (isString(data) && isText(data)) {
|
|
2763
|
+
return utf8ToBigInt(data);
|
|
2764
|
+
}
|
|
2765
|
+
return BigInt(data);
|
|
2766
|
+
}
|
|
2767
|
+
toApiRequest() {
|
|
2768
|
+
return addCompiledFlag([this.toHexString()]);
|
|
2769
|
+
}
|
|
2770
|
+
toBigInt() {
|
|
2771
|
+
return this.data;
|
|
2772
|
+
}
|
|
2773
|
+
decodeUtf8() {
|
|
2774
|
+
return new TextDecoder().decode(
|
|
2775
|
+
bigIntToUint8Array(this.data >= 0n ? this.data : 2n ** 128n + this.data)
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
/**
|
|
2779
|
+
* For negative values field element representation as positive hex string.
|
|
2780
|
+
* @returns cairo field arithmetic hex string
|
|
2781
|
+
*/
|
|
2782
|
+
toHexString() {
|
|
2783
|
+
const value = this.toBigInt();
|
|
2784
|
+
if (value < 0n) {
|
|
2785
|
+
const fieldElement = PRIME + value;
|
|
2786
|
+
return addHexPrefix(fieldElement.toString(16));
|
|
2787
|
+
}
|
|
2788
|
+
return addHexPrefix(value.toString(16));
|
|
2789
|
+
}
|
|
2790
|
+
static validate(data) {
|
|
2791
|
+
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2792
|
+
assert(!isObject(data) && !Array.isArray(data), "Invalid input: objects are not supported");
|
|
2793
|
+
assert(
|
|
2794
|
+
!isNumber(data) || Number.isInteger(data),
|
|
2795
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
2796
|
+
);
|
|
2797
|
+
const value = _CairoInt128.__processData(data);
|
|
2798
|
+
assert(
|
|
2799
|
+
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
2800
|
+
`Value is out of i128 range [${RANGE_I128.min}, ${RANGE_I128.max}]`
|
|
2801
|
+
);
|
|
2802
|
+
}
|
|
2803
|
+
static is(data) {
|
|
2804
|
+
try {
|
|
2805
|
+
_CairoInt128.validate(data);
|
|
2806
|
+
return true;
|
|
2807
|
+
} catch {
|
|
2808
|
+
return false;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
/**
|
|
2812
|
+
* Check if provided abi type is this data type
|
|
2813
|
+
*/
|
|
2814
|
+
static isAbiType(abiType) {
|
|
2815
|
+
return abiType === _CairoInt128.abiSelector;
|
|
2816
|
+
}
|
|
2817
|
+
static factoryFromApiResponse(responseIterator) {
|
|
2818
|
+
const response = getNext(responseIterator);
|
|
2819
|
+
const value = BigInt(response);
|
|
2820
|
+
const signedValue = value > PRIME / 2n ? value - PRIME : value;
|
|
2821
|
+
return new _CairoInt128(signedValue);
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
|
|
2825
|
+
// src/utils/calldata/parser/parsingStrategy.ts
|
|
2826
|
+
var hdParsingStrategy = {
|
|
2827
|
+
// TODO: provjeri svi request parseri stvaraju array, dali je to ok sa requstParserom
|
|
2828
|
+
request: {
|
|
2829
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
2830
|
+
return new CairoBytes31(val).toApiRequest();
|
|
2831
|
+
},
|
|
2832
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
2833
|
+
return new CairoByteArray(val).toApiRequest();
|
|
2834
|
+
},
|
|
2835
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
2836
|
+
return new CairoFelt252(val).toApiRequest();
|
|
2837
|
+
},
|
|
2838
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
2839
|
+
return new CairoUint256(val).toApiRequest();
|
|
2840
|
+
},
|
|
2841
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
2842
|
+
return new CairoUint512(val).toApiRequest();
|
|
2843
|
+
},
|
|
2844
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
2845
|
+
return new CairoUint8(val).toApiRequest();
|
|
2846
|
+
},
|
|
2847
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
2848
|
+
return new CairoUint16(val).toApiRequest();
|
|
2849
|
+
},
|
|
2850
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
2851
|
+
return new CairoUint64(val).toApiRequest();
|
|
2852
|
+
},
|
|
2853
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
2854
|
+
return new CairoUint96(val).toApiRequest();
|
|
2855
|
+
},
|
|
2856
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
2857
|
+
return new CairoUint128(val).toApiRequest();
|
|
2858
|
+
},
|
|
2859
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
2860
|
+
return new CairoInt8(val).toApiRequest();
|
|
2861
|
+
},
|
|
2862
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
2863
|
+
return new CairoInt16(val).toApiRequest();
|
|
2864
|
+
},
|
|
2865
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
2866
|
+
return new CairoInt32(val).toApiRequest();
|
|
2867
|
+
},
|
|
2868
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
2869
|
+
return new CairoInt64(val).toApiRequest();
|
|
2870
|
+
},
|
|
2871
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
2872
|
+
return new CairoInt128(val).toApiRequest();
|
|
2873
|
+
}
|
|
2874
|
+
},
|
|
2875
|
+
response: {
|
|
2876
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
2877
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
2878
|
+
},
|
|
2879
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
2880
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
2881
|
+
},
|
|
2882
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
2883
|
+
return CairoFelt252.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2884
|
+
},
|
|
2885
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
2886
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2887
|
+
},
|
|
2888
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
2889
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2890
|
+
},
|
|
2891
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
2892
|
+
return CairoUint8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2893
|
+
},
|
|
2894
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
2895
|
+
return CairoUint16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2896
|
+
},
|
|
2897
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
2898
|
+
return CairoUint64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2899
|
+
},
|
|
2900
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
2901
|
+
return CairoUint96.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2902
|
+
},
|
|
2903
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
2904
|
+
return CairoUint128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2905
|
+
},
|
|
2906
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
2907
|
+
return CairoInt8.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2908
|
+
},
|
|
2909
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
2910
|
+
return CairoInt16.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2911
|
+
},
|
|
2912
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
2913
|
+
return CairoInt32.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2914
|
+
},
|
|
2915
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
2916
|
+
return CairoInt64.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2917
|
+
},
|
|
2918
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
2919
|
+
return CairoInt128.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
2923
|
+
var fastParsingStrategy = {
|
|
2924
|
+
request: {
|
|
2925
|
+
[CairoBytes31.abiSelector]: (val) => {
|
|
2926
|
+
return new CairoBytes31(val).toApiRequest();
|
|
2927
|
+
},
|
|
2928
|
+
[CairoByteArray.abiSelector]: (val) => {
|
|
2929
|
+
return new CairoByteArray(val).toApiRequest();
|
|
2930
|
+
},
|
|
2931
|
+
[CairoFelt252.abiSelector]: (val) => {
|
|
2932
|
+
return felt(val);
|
|
2933
|
+
},
|
|
2934
|
+
[CairoUint256.abiSelector]: (val) => {
|
|
2935
|
+
return new CairoUint256(val).toApiRequest();
|
|
2936
|
+
},
|
|
2937
|
+
[CairoUint512.abiSelector]: (val) => {
|
|
2938
|
+
return new CairoUint512(val).toApiRequest();
|
|
2939
|
+
},
|
|
2940
|
+
[CairoUint8.abiSelector]: (val) => {
|
|
2941
|
+
return felt(val);
|
|
2942
|
+
},
|
|
2943
|
+
[CairoUint16.abiSelector]: (val) => {
|
|
2944
|
+
return felt(val);
|
|
2945
|
+
},
|
|
2946
|
+
[CairoUint64.abiSelector]: (val) => {
|
|
2947
|
+
return felt(val);
|
|
2948
|
+
},
|
|
2949
|
+
[CairoUint96.abiSelector]: (val) => {
|
|
2950
|
+
return felt(val);
|
|
2951
|
+
},
|
|
2952
|
+
[CairoUint128.abiSelector]: (val) => {
|
|
2953
|
+
return felt(val);
|
|
2954
|
+
},
|
|
2955
|
+
[CairoInt8.abiSelector]: (val) => {
|
|
2956
|
+
return new CairoInt8(val).toApiRequest();
|
|
2957
|
+
},
|
|
2958
|
+
[CairoInt16.abiSelector]: (val) => {
|
|
2959
|
+
return new CairoInt16(val).toApiRequest();
|
|
2960
|
+
},
|
|
2961
|
+
[CairoInt32.abiSelector]: (val) => {
|
|
2962
|
+
return new CairoInt32(val).toApiRequest();
|
|
2963
|
+
},
|
|
2964
|
+
[CairoInt64.abiSelector]: (val) => {
|
|
2965
|
+
return new CairoInt64(val).toApiRequest();
|
|
2966
|
+
},
|
|
2967
|
+
[CairoInt128.abiSelector]: (val) => {
|
|
2968
|
+
return new CairoInt128(val).toApiRequest();
|
|
2969
|
+
}
|
|
2970
|
+
},
|
|
2971
|
+
response: {
|
|
2972
|
+
[CairoBytes31.abiSelector]: (responseIterator) => {
|
|
2973
|
+
return CairoBytes31.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
2974
|
+
},
|
|
2975
|
+
[CairoByteArray.abiSelector]: (responseIterator) => {
|
|
2976
|
+
return CairoByteArray.factoryFromApiResponse(responseIterator).decodeUtf8();
|
|
2977
|
+
},
|
|
2978
|
+
[CairoFelt252.abiSelector]: (responseIterator) => {
|
|
2979
|
+
return BigInt(getNext(responseIterator));
|
|
2980
|
+
},
|
|
2981
|
+
[CairoUint256.abiSelector]: (responseIterator) => {
|
|
2982
|
+
return CairoUint256.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2983
|
+
},
|
|
2984
|
+
[CairoUint512.abiSelector]: (responseIterator) => {
|
|
2985
|
+
return CairoUint512.factoryFromApiResponse(responseIterator).toBigInt();
|
|
2986
|
+
},
|
|
2987
|
+
[CairoUint8.abiSelector]: (responseIterator) => {
|
|
2988
|
+
return BigInt(getNext(responseIterator));
|
|
2989
|
+
},
|
|
2990
|
+
[CairoUint16.abiSelector]: (responseIterator) => {
|
|
2991
|
+
return BigInt(getNext(responseIterator));
|
|
2992
|
+
},
|
|
2993
|
+
[CairoUint64.abiSelector]: (responseIterator) => {
|
|
2994
|
+
return BigInt(getNext(responseIterator));
|
|
2995
|
+
},
|
|
2996
|
+
[CairoUint96.abiSelector]: (responseIterator) => {
|
|
2997
|
+
return BigInt(getNext(responseIterator));
|
|
2998
|
+
},
|
|
2999
|
+
[CairoUint128.abiSelector]: (responseIterator) => {
|
|
3000
|
+
return BigInt(getNext(responseIterator));
|
|
3001
|
+
},
|
|
3002
|
+
[CairoInt8.abiSelector]: (responseIterator) => {
|
|
3003
|
+
return BigInt(getNext(responseIterator));
|
|
3004
|
+
},
|
|
3005
|
+
[CairoInt16.abiSelector]: (responseIterator) => {
|
|
3006
|
+
return BigInt(getNext(responseIterator));
|
|
3007
|
+
},
|
|
3008
|
+
[CairoInt32.abiSelector]: (responseIterator) => {
|
|
3009
|
+
return BigInt(getNext(responseIterator));
|
|
3010
|
+
},
|
|
3011
|
+
[CairoInt64.abiSelector]: (responseIterator) => {
|
|
3012
|
+
return BigInt(getNext(responseIterator));
|
|
3013
|
+
},
|
|
3014
|
+
[CairoInt128.abiSelector]: (responseIterator) => {
|
|
3015
|
+
return BigInt(getNext(responseIterator));
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
1484
3019
|
|
|
1485
3020
|
// src/utils/calldata/parser/parser-0-1.1.0.ts
|
|
1486
3021
|
var AbiParser1 = class {
|
|
1487
3022
|
abi;
|
|
1488
|
-
|
|
3023
|
+
parsingStrategy;
|
|
3024
|
+
constructor(abi, parsingStrategy) {
|
|
1489
3025
|
this.abi = abi;
|
|
3026
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
3027
|
+
}
|
|
3028
|
+
getRequestParser(abiType) {
|
|
3029
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
3030
|
+
return this.parsingStrategy.request[abiType];
|
|
3031
|
+
}
|
|
3032
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
3033
|
+
}
|
|
3034
|
+
getResponseParser(abiType) {
|
|
3035
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
3036
|
+
return this.parsingStrategy.response[abiType];
|
|
3037
|
+
}
|
|
3038
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
1490
3039
|
}
|
|
1491
3040
|
/**
|
|
1492
3041
|
* abi method inputs length without '_len' inputs
|
|
@@ -1517,8 +3066,22 @@ var AbiParser1 = class {
|
|
|
1517
3066
|
// src/utils/calldata/parser/parser-2.0.0.ts
|
|
1518
3067
|
var AbiParser2 = class {
|
|
1519
3068
|
abi;
|
|
1520
|
-
|
|
3069
|
+
parsingStrategy;
|
|
3070
|
+
constructor(abi, parsingStrategy) {
|
|
1521
3071
|
this.abi = abi;
|
|
3072
|
+
this.parsingStrategy = parsingStrategy || fastParsingStrategy;
|
|
3073
|
+
}
|
|
3074
|
+
getRequestParser(abiType) {
|
|
3075
|
+
if (this.parsingStrategy.request[abiType]) {
|
|
3076
|
+
return this.parsingStrategy.request[abiType];
|
|
3077
|
+
}
|
|
3078
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
3079
|
+
}
|
|
3080
|
+
getResponseParser(abiType) {
|
|
3081
|
+
if (this.parsingStrategy.response[abiType]) {
|
|
3082
|
+
return this.parsingStrategy.response[abiType];
|
|
3083
|
+
}
|
|
3084
|
+
throw new Error(`Parser for ${abiType} not found`);
|
|
1522
3085
|
}
|
|
1523
3086
|
/**
|
|
1524
3087
|
* abi method inputs length
|
|
@@ -1551,13 +3114,13 @@ var AbiParser2 = class {
|
|
|
1551
3114
|
};
|
|
1552
3115
|
|
|
1553
3116
|
// src/utils/calldata/parser/index.ts
|
|
1554
|
-
function createAbiParser(abi) {
|
|
3117
|
+
function createAbiParser(abi, parsingStrategy) {
|
|
1555
3118
|
const version = getAbiVersion(abi);
|
|
1556
3119
|
if (version === 0 || version === 1) {
|
|
1557
|
-
return new AbiParser1(abi);
|
|
3120
|
+
return new AbiParser1(abi, parsingStrategy);
|
|
1558
3121
|
}
|
|
1559
3122
|
if (version === 2) {
|
|
1560
|
-
return new AbiParser2(abi);
|
|
3123
|
+
return new AbiParser2(abi, parsingStrategy);
|
|
1561
3124
|
}
|
|
1562
3125
|
throw Error(`Unsupported ABI version ${version}`);
|
|
1563
3126
|
}
|
|
@@ -1684,16 +3247,17 @@ var CairoFixedArray = class _CairoFixedArray {
|
|
|
1684
3247
|
`The type ${arrayType} do not includes any content type. Needs [type; length].`
|
|
1685
3248
|
);
|
|
1686
3249
|
}
|
|
3250
|
+
let arraySize;
|
|
1687
3251
|
try {
|
|
1688
|
-
_CairoFixedArray.getFixedArraySize(arrayType);
|
|
3252
|
+
arraySize = _CairoFixedArray.getFixedArraySize(arrayType);
|
|
1689
3253
|
} catch {
|
|
1690
3254
|
throw new Error(
|
|
1691
3255
|
`The type ${arrayType} type do not includes any length. Needs [type; length].`
|
|
1692
3256
|
);
|
|
1693
3257
|
}
|
|
1694
3258
|
assert(
|
|
1695
|
-
|
|
1696
|
-
`The ABI type ${arrayType} is expecting ${
|
|
3259
|
+
arraySize === content.length,
|
|
3260
|
+
`The ABI type ${arrayType} is expecting ${arraySize} items. ${content.length} items provided.`
|
|
1697
3261
|
);
|
|
1698
3262
|
this.content = content;
|
|
1699
3263
|
this.arrayType = arrayType;
|
|
@@ -1790,6 +3354,7 @@ var CairoFixedArray = class _CairoFixedArray {
|
|
|
1790
3354
|
}
|
|
1791
3355
|
/**
|
|
1792
3356
|
* Checks if the given Cairo type is a fixed-array type.
|
|
3357
|
+
* structure: [string; number]
|
|
1793
3358
|
*
|
|
1794
3359
|
* @param {string} type - The type to check.
|
|
1795
3360
|
* @returns - `true` if the type is a fixed array type, `false` otherwise.
|
|
@@ -1834,7 +3399,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1834
3399
|
if (isTypeNonZero(abiType)) {
|
|
1835
3400
|
return unorderedItem;
|
|
1836
3401
|
}
|
|
1837
|
-
if (
|
|
3402
|
+
if (CairoByteArray.isAbiType(abiType)) {
|
|
1838
3403
|
return unorderedItem;
|
|
1839
3404
|
}
|
|
1840
3405
|
if (isTypeU96(abiType)) {
|
|
@@ -1992,14 +3557,38 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
1992
3557
|
}
|
|
1993
3558
|
|
|
1994
3559
|
// src/utils/calldata/requestParser.ts
|
|
1995
|
-
function parseBaseTypes(
|
|
3560
|
+
function parseBaseTypes({
|
|
3561
|
+
type,
|
|
3562
|
+
val,
|
|
3563
|
+
parser
|
|
3564
|
+
}) {
|
|
1996
3565
|
switch (true) {
|
|
1997
3566
|
case CairoUint256.isAbiType(type):
|
|
1998
|
-
return
|
|
3567
|
+
return parser.getRequestParser(type)(val);
|
|
1999
3568
|
case CairoUint512.isAbiType(type):
|
|
2000
|
-
return
|
|
2001
|
-
case
|
|
2002
|
-
return
|
|
3569
|
+
return parser.getRequestParser(type)(val);
|
|
3570
|
+
case CairoUint8.isAbiType(type):
|
|
3571
|
+
return parser.getRequestParser(type)(val);
|
|
3572
|
+
case CairoUint16.isAbiType(type):
|
|
3573
|
+
return parser.getRequestParser(type)(val);
|
|
3574
|
+
case CairoUint64.isAbiType(type):
|
|
3575
|
+
return parser.getRequestParser(type)(val);
|
|
3576
|
+
case CairoUint96.isAbiType(type):
|
|
3577
|
+
return parser.getRequestParser(type)(val);
|
|
3578
|
+
case CairoUint128.isAbiType(type):
|
|
3579
|
+
return parser.getRequestParser(type)(val);
|
|
3580
|
+
case CairoInt8.isAbiType(type):
|
|
3581
|
+
return parser.getRequestParser(type)(val);
|
|
3582
|
+
case CairoInt16.isAbiType(type):
|
|
3583
|
+
return parser.getRequestParser(type)(val);
|
|
3584
|
+
case CairoInt32.isAbiType(type):
|
|
3585
|
+
return parser.getRequestParser(type)(val);
|
|
3586
|
+
case CairoInt64.isAbiType(type):
|
|
3587
|
+
return parser.getRequestParser(type)(val);
|
|
3588
|
+
case CairoInt128.isAbiType(type):
|
|
3589
|
+
return parser.getRequestParser(type)(val);
|
|
3590
|
+
case CairoBytes31.isAbiType(type):
|
|
3591
|
+
return parser.getRequestParser(type)(val);
|
|
2003
3592
|
case isTypeSecp256k1Point(type): {
|
|
2004
3593
|
const pubKeyETH = removeHexPrefix(toHex(val)).padStart(128, "0");
|
|
2005
3594
|
const pubKeyETHy = uint256(addHexPrefix(pubKeyETH.slice(-64)));
|
|
@@ -2012,7 +3601,7 @@ function parseBaseTypes(type, val) {
|
|
|
2012
3601
|
];
|
|
2013
3602
|
}
|
|
2014
3603
|
default:
|
|
2015
|
-
return
|
|
3604
|
+
return parser.getRequestParser(CairoFelt252.abiSelector)(val);
|
|
2016
3605
|
}
|
|
2017
3606
|
}
|
|
2018
3607
|
function parseTuple(element, typeStr) {
|
|
@@ -2032,16 +3621,13 @@ function parseTuple(element, typeStr) {
|
|
|
2032
3621
|
};
|
|
2033
3622
|
});
|
|
2034
3623
|
}
|
|
2035
|
-
function
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
];
|
|
2043
|
-
}
|
|
2044
|
-
function parseCalldataValue(element, type, structs, enums) {
|
|
3624
|
+
function parseCalldataValue({
|
|
3625
|
+
element,
|
|
3626
|
+
type,
|
|
3627
|
+
structs,
|
|
3628
|
+
enums,
|
|
3629
|
+
parser
|
|
3630
|
+
}) {
|
|
2045
3631
|
if (element === void 0) {
|
|
2046
3632
|
throw Error(`Missing parameter for type ${type}`);
|
|
2047
3633
|
}
|
|
@@ -2061,7 +3647,9 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2061
3647
|
throw new Error(`ABI type ${type}: not an Array representing a cairo.fixedArray() provided.`);
|
|
2062
3648
|
}
|
|
2063
3649
|
return values.reduce((acc, it) => {
|
|
2064
|
-
return acc.concat(
|
|
3650
|
+
return acc.concat(
|
|
3651
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
3652
|
+
);
|
|
2065
3653
|
}, []);
|
|
2066
3654
|
}
|
|
2067
3655
|
if (Array.isArray(element)) {
|
|
@@ -2069,37 +3657,51 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2069
3657
|
result.push(felt(element.length));
|
|
2070
3658
|
const arrayType = getArrayType(type);
|
|
2071
3659
|
return element.reduce((acc, it) => {
|
|
2072
|
-
return acc.concat(
|
|
3660
|
+
return acc.concat(
|
|
3661
|
+
parseCalldataValue({ element: it, type: arrayType, structs, enums, parser })
|
|
3662
|
+
);
|
|
2073
3663
|
}, result);
|
|
2074
3664
|
}
|
|
3665
|
+
if (CairoUint256.isAbiType(type)) {
|
|
3666
|
+
return parser.getRequestParser(type)(element);
|
|
3667
|
+
}
|
|
3668
|
+
if (CairoUint512.isAbiType(type)) {
|
|
3669
|
+
return parser.getRequestParser(type)(element);
|
|
3670
|
+
}
|
|
2075
3671
|
if (structs[type] && structs[type].members.length) {
|
|
2076
|
-
if (
|
|
2077
|
-
return
|
|
3672
|
+
if (isTypeEthAddress(type)) {
|
|
3673
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
2078
3674
|
}
|
|
2079
|
-
if (
|
|
2080
|
-
return
|
|
3675
|
+
if (CairoByteArray.isAbiType(type)) {
|
|
3676
|
+
return parser.getRequestParser(type)(element);
|
|
2081
3677
|
}
|
|
2082
|
-
if (isTypeEthAddress(type)) return parseBaseTypes(type, element);
|
|
2083
|
-
if (isTypeByteArray(type)) return parseByteArray(element);
|
|
2084
3678
|
const { members } = structs[type];
|
|
2085
3679
|
const subElement = element;
|
|
2086
3680
|
return members.reduce((acc, it) => {
|
|
2087
|
-
return acc.concat(
|
|
3681
|
+
return acc.concat(
|
|
3682
|
+
parseCalldataValue({
|
|
3683
|
+
element: subElement[it.name],
|
|
3684
|
+
type: it.type,
|
|
3685
|
+
structs,
|
|
3686
|
+
enums,
|
|
3687
|
+
parser
|
|
3688
|
+
})
|
|
3689
|
+
);
|
|
2088
3690
|
}, []);
|
|
2089
3691
|
}
|
|
2090
3692
|
if (isTypeTuple(type)) {
|
|
2091
3693
|
const tupled = parseTuple(element, type);
|
|
2092
3694
|
return tupled.reduce((acc, it) => {
|
|
2093
|
-
const parsedData = parseCalldataValue(
|
|
3695
|
+
const parsedData = parseCalldataValue({
|
|
3696
|
+
element: it.element,
|
|
3697
|
+
type: it.type,
|
|
3698
|
+
structs,
|
|
3699
|
+
enums,
|
|
3700
|
+
parser
|
|
3701
|
+
});
|
|
2094
3702
|
return acc.concat(parsedData);
|
|
2095
3703
|
}, []);
|
|
2096
3704
|
}
|
|
2097
|
-
if (CairoUint256.isAbiType(type)) {
|
|
2098
|
-
return new CairoUint256(element).toApiRequest();
|
|
2099
|
-
}
|
|
2100
|
-
if (CairoUint512.isAbiType(type)) {
|
|
2101
|
-
return new CairoUint512(element).toApiRequest();
|
|
2102
|
-
}
|
|
2103
3705
|
if (isTypeEnum(type, enums)) {
|
|
2104
3706
|
const { variants } = enums[type];
|
|
2105
3707
|
if (isTypeOption(type)) {
|
|
@@ -2113,12 +3715,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2113
3715
|
if (typeVariantSome === "()") {
|
|
2114
3716
|
return CairoOptionVariant.Some.toString();
|
|
2115
3717
|
}
|
|
2116
|
-
const parsedParameter2 = parseCalldataValue(
|
|
2117
|
-
myOption.unwrap(),
|
|
2118
|
-
typeVariantSome,
|
|
3718
|
+
const parsedParameter2 = parseCalldataValue({
|
|
3719
|
+
element: myOption.unwrap(),
|
|
3720
|
+
type: typeVariantSome,
|
|
2119
3721
|
structs,
|
|
2120
|
-
enums
|
|
2121
|
-
|
|
3722
|
+
enums,
|
|
3723
|
+
parser
|
|
3724
|
+
});
|
|
2122
3725
|
if (Array.isArray(parsedParameter2)) {
|
|
2123
3726
|
return [CairoOptionVariant.Some.toString(), ...parsedParameter2];
|
|
2124
3727
|
}
|
|
@@ -2137,12 +3740,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2137
3740
|
if (typeVariantOk === "()") {
|
|
2138
3741
|
return CairoResultVariant.Ok.toString();
|
|
2139
3742
|
}
|
|
2140
|
-
const parsedParameter3 = parseCalldataValue(
|
|
2141
|
-
myResult.unwrap(),
|
|
2142
|
-
typeVariantOk,
|
|
3743
|
+
const parsedParameter3 = parseCalldataValue({
|
|
3744
|
+
element: myResult.unwrap(),
|
|
3745
|
+
type: typeVariantOk,
|
|
2143
3746
|
structs,
|
|
2144
|
-
enums
|
|
2145
|
-
|
|
3747
|
+
enums,
|
|
3748
|
+
parser
|
|
3749
|
+
});
|
|
2146
3750
|
if (Array.isArray(parsedParameter3)) {
|
|
2147
3751
|
return [CairoResultVariant.Ok.toString(), ...parsedParameter3];
|
|
2148
3752
|
}
|
|
@@ -2156,7 +3760,13 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2156
3760
|
if (typeVariantErr === "()") {
|
|
2157
3761
|
return CairoResultVariant.Err.toString();
|
|
2158
3762
|
}
|
|
2159
|
-
const parsedParameter2 = parseCalldataValue(
|
|
3763
|
+
const parsedParameter2 = parseCalldataValue({
|
|
3764
|
+
element: myResult.unwrap(),
|
|
3765
|
+
type: typeVariantErr,
|
|
3766
|
+
structs,
|
|
3767
|
+
enums,
|
|
3768
|
+
parser
|
|
3769
|
+
});
|
|
2160
3770
|
if (Array.isArray(parsedParameter2)) {
|
|
2161
3771
|
return [CairoResultVariant.Err.toString(), ...parsedParameter2];
|
|
2162
3772
|
}
|
|
@@ -2173,21 +3783,33 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
2173
3783
|
if (typeActiveVariant === "()") {
|
|
2174
3784
|
return numActiveVariant.toString();
|
|
2175
3785
|
}
|
|
2176
|
-
const parsedParameter = parseCalldataValue(
|
|
3786
|
+
const parsedParameter = parseCalldataValue({
|
|
3787
|
+
element: myEnum.unwrap(),
|
|
3788
|
+
type: typeActiveVariant,
|
|
3789
|
+
structs,
|
|
3790
|
+
enums,
|
|
3791
|
+
parser
|
|
3792
|
+
});
|
|
2177
3793
|
if (Array.isArray(parsedParameter)) {
|
|
2178
3794
|
return [numActiveVariant.toString(), ...parsedParameter];
|
|
2179
3795
|
}
|
|
2180
3796
|
return [numActiveVariant.toString(), parsedParameter];
|
|
2181
3797
|
}
|
|
2182
3798
|
if (isTypeNonZero(type)) {
|
|
2183
|
-
return parseBaseTypes(getArrayType(type), element);
|
|
3799
|
+
return parseBaseTypes({ type: getArrayType(type), val: element, parser });
|
|
2184
3800
|
}
|
|
2185
3801
|
if (typeof element === "object") {
|
|
2186
3802
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
2187
3803
|
}
|
|
2188
|
-
return parseBaseTypes(type, element);
|
|
3804
|
+
return parseBaseTypes({ type, val: element, parser });
|
|
2189
3805
|
}
|
|
2190
|
-
function parseCalldataField(
|
|
3806
|
+
function parseCalldataField({
|
|
3807
|
+
argsIterator,
|
|
3808
|
+
input,
|
|
3809
|
+
structs,
|
|
3810
|
+
enums,
|
|
3811
|
+
parser
|
|
3812
|
+
}) {
|
|
2191
3813
|
const { name, type } = input;
|
|
2192
3814
|
let { value } = argsIterator.next();
|
|
2193
3815
|
switch (true) {
|
|
@@ -2196,7 +3818,7 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
2196
3818
|
if (!Array.isArray(value) && !(typeof value === "object")) {
|
|
2197
3819
|
throw Error(`ABI expected parameter ${name} to be an array or an object, got ${value}`);
|
|
2198
3820
|
}
|
|
2199
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
3821
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
2200
3822
|
// Normal Array
|
|
2201
3823
|
case isTypeArray(type):
|
|
2202
3824
|
if (!Array.isArray(value) && !isText(value)) {
|
|
@@ -2205,51 +3827,71 @@ function parseCalldataField(argsIterator, input, structs, enums) {
|
|
|
2205
3827
|
if (isString(value)) {
|
|
2206
3828
|
value = splitLongString(value);
|
|
2207
3829
|
}
|
|
2208
|
-
return parseCalldataValue(value, input.type, structs, enums);
|
|
3830
|
+
return parseCalldataValue({ element: value, type: input.type, structs, enums, parser });
|
|
2209
3831
|
case isTypeNonZero(type):
|
|
2210
|
-
return parseBaseTypes(getArrayType(type), value);
|
|
3832
|
+
return parseBaseTypes({ type: getArrayType(type), val: value, parser });
|
|
2211
3833
|
case isTypeEthAddress(type):
|
|
2212
|
-
return parseBaseTypes(type, value);
|
|
3834
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
2213
3835
|
// Struct or Tuple
|
|
2214
3836
|
case (isTypeStruct(type, structs) || isTypeTuple(type) || CairoUint256.isAbiType(type)):
|
|
2215
|
-
return parseCalldataValue(
|
|
3837
|
+
return parseCalldataValue({
|
|
3838
|
+
element: value,
|
|
3839
|
+
type,
|
|
3840
|
+
structs,
|
|
3841
|
+
enums,
|
|
3842
|
+
parser
|
|
3843
|
+
});
|
|
2216
3844
|
// Enums
|
|
2217
3845
|
case isTypeEnum(type, enums):
|
|
2218
|
-
return parseCalldataValue(
|
|
2219
|
-
value,
|
|
3846
|
+
return parseCalldataValue({
|
|
3847
|
+
element: value,
|
|
2220
3848
|
type,
|
|
2221
3849
|
structs,
|
|
2222
|
-
enums
|
|
2223
|
-
|
|
3850
|
+
enums,
|
|
3851
|
+
parser
|
|
3852
|
+
});
|
|
2224
3853
|
// Felt or unhandled
|
|
2225
3854
|
default:
|
|
2226
|
-
return parseBaseTypes(type, value);
|
|
3855
|
+
return parseBaseTypes({ type, val: value, parser });
|
|
2227
3856
|
}
|
|
2228
3857
|
}
|
|
2229
3858
|
|
|
2230
3859
|
// src/utils/calldata/responseParser.ts
|
|
2231
|
-
function parseBaseTypes2(type, it) {
|
|
3860
|
+
function parseBaseTypes2(type, it, parser) {
|
|
2232
3861
|
let temp;
|
|
2233
3862
|
switch (true) {
|
|
2234
3863
|
case isTypeBool(type):
|
|
2235
3864
|
temp = it.next().value;
|
|
2236
3865
|
return Boolean(BigInt(temp));
|
|
2237
3866
|
case CairoUint256.isAbiType(type):
|
|
2238
|
-
|
|
2239
|
-
const high = it.next().value;
|
|
2240
|
-
return new CairoUint256(low, high).toBigInt();
|
|
3867
|
+
return parser.getResponseParser(type)(it);
|
|
2241
3868
|
case CairoUint512.isAbiType(type):
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
return
|
|
3869
|
+
return parser.getResponseParser(type)(it);
|
|
3870
|
+
case CairoUint8.isAbiType(type):
|
|
3871
|
+
return parser.getResponseParser(type)(it);
|
|
3872
|
+
case CairoUint16.isAbiType(type):
|
|
3873
|
+
return parser.getResponseParser(type)(it);
|
|
3874
|
+
case CairoUint64.isAbiType(type):
|
|
3875
|
+
return parser.getResponseParser(type)(it);
|
|
3876
|
+
case CairoUint96.isAbiType(type):
|
|
3877
|
+
return parser.getResponseParser(type)(it);
|
|
3878
|
+
case CairoUint128.isAbiType(type):
|
|
3879
|
+
return parser.getResponseParser(type)(it);
|
|
3880
|
+
case CairoInt8.isAbiType(type):
|
|
3881
|
+
return parser.getResponseParser(type)(it);
|
|
3882
|
+
case CairoInt16.isAbiType(type):
|
|
3883
|
+
return parser.getResponseParser(type)(it);
|
|
3884
|
+
case CairoInt32.isAbiType(type):
|
|
3885
|
+
return parser.getResponseParser(type)(it);
|
|
3886
|
+
case CairoInt64.isAbiType(type):
|
|
3887
|
+
return parser.getResponseParser(type)(it);
|
|
3888
|
+
case CairoInt128.isAbiType(type):
|
|
3889
|
+
return parser.getResponseParser(type)(it);
|
|
2247
3890
|
case isTypeEthAddress(type):
|
|
2248
3891
|
temp = it.next().value;
|
|
2249
3892
|
return BigInt(temp);
|
|
2250
|
-
case
|
|
2251
|
-
|
|
2252
|
-
return decodeShortString(temp);
|
|
3893
|
+
case CairoBytes31.isAbiType(type):
|
|
3894
|
+
return parser.getResponseParser(type)(it);
|
|
2253
3895
|
case isTypeSecp256k1Point(type):
|
|
2254
3896
|
const xLow = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
2255
3897
|
const xHigh = removeHexPrefix(it.next().value).padStart(32, "0");
|
|
@@ -2258,47 +3900,28 @@ function parseBaseTypes2(type, it) {
|
|
|
2258
3900
|
const pubK = BigInt(addHexPrefix(xHigh + xLow + yHigh + yLow));
|
|
2259
3901
|
return pubK;
|
|
2260
3902
|
default:
|
|
2261
|
-
|
|
2262
|
-
return BigInt(temp);
|
|
3903
|
+
return parser.getResponseParser(CairoFelt252.abiSelector)(it);
|
|
2263
3904
|
}
|
|
2264
3905
|
}
|
|
2265
|
-
function parseResponseValue(responseIterator, element, structs, enums) {
|
|
3906
|
+
function parseResponseValue(responseIterator, element, parser, structs, enums) {
|
|
2266
3907
|
if (element.type === "()") {
|
|
2267
3908
|
return {};
|
|
2268
3909
|
}
|
|
2269
3910
|
if (CairoUint256.isAbiType(element.type)) {
|
|
2270
|
-
|
|
2271
|
-
const high = responseIterator.next().value;
|
|
2272
|
-
return new CairoUint256(low, high).toBigInt();
|
|
3911
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
2273
3912
|
}
|
|
2274
3913
|
if (CairoUint512.isAbiType(element.type)) {
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
return new CairoUint512(limb0, limb1, limb2, limb3).toBigInt();
|
|
2280
|
-
}
|
|
2281
|
-
if (isTypeByteArray(element.type)) {
|
|
2282
|
-
const parsedBytes31Arr = [];
|
|
2283
|
-
const bytes31ArrLen = BigInt(responseIterator.next().value);
|
|
2284
|
-
while (parsedBytes31Arr.length < bytes31ArrLen) {
|
|
2285
|
-
parsedBytes31Arr.push(toHex(responseIterator.next().value));
|
|
2286
|
-
}
|
|
2287
|
-
const pending_word = toHex(responseIterator.next().value);
|
|
2288
|
-
const pending_word_len = BigInt(responseIterator.next().value);
|
|
2289
|
-
const myByteArray = {
|
|
2290
|
-
data: parsedBytes31Arr,
|
|
2291
|
-
pending_word,
|
|
2292
|
-
pending_word_len
|
|
2293
|
-
};
|
|
2294
|
-
return stringFromByteArray(myByteArray);
|
|
3914
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
3915
|
+
}
|
|
3916
|
+
if (CairoByteArray.isAbiType(element.type)) {
|
|
3917
|
+
return parser.getResponseParser(element.type)(responseIterator);
|
|
2295
3918
|
}
|
|
2296
3919
|
if (CairoFixedArray.isTypeFixedArray(element.type)) {
|
|
2297
3920
|
const parsedDataArr = [];
|
|
2298
3921
|
const el = { name: "", type: CairoFixedArray.getFixedArrayType(element.type) };
|
|
2299
3922
|
const arraySize = CairoFixedArray.getFixedArraySize(element.type);
|
|
2300
3923
|
while (parsedDataArr.length < arraySize) {
|
|
2301
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
3924
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2302
3925
|
}
|
|
2303
3926
|
return parsedDataArr;
|
|
2304
3927
|
}
|
|
@@ -2307,20 +3930,20 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2307
3930
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2308
3931
|
const len = BigInt(responseIterator.next().value);
|
|
2309
3932
|
while (parsedDataArr.length < len) {
|
|
2310
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
3933
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2311
3934
|
}
|
|
2312
3935
|
return parsedDataArr;
|
|
2313
3936
|
}
|
|
2314
3937
|
if (isTypeNonZero(element.type)) {
|
|
2315
3938
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2316
|
-
return parseResponseValue(responseIterator, el, structs, enums);
|
|
3939
|
+
return parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2317
3940
|
}
|
|
2318
3941
|
if (structs && element.type in structs && structs[element.type]) {
|
|
2319
3942
|
if (isTypeEthAddress(element.type)) {
|
|
2320
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
3943
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
2321
3944
|
}
|
|
2322
3945
|
return structs[element.type].members.reduce((acc, el) => {
|
|
2323
|
-
acc[el.name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
3946
|
+
acc[el.name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2324
3947
|
return acc;
|
|
2325
3948
|
}, {});
|
|
2326
3949
|
}
|
|
@@ -2331,6 +3954,7 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2331
3954
|
acc[variant.name] = parseResponseValue(
|
|
2332
3955
|
responseIterator,
|
|
2333
3956
|
{ name: "", type: variant.type },
|
|
3957
|
+
parser,
|
|
2334
3958
|
structs,
|
|
2335
3959
|
enums
|
|
2336
3960
|
);
|
|
@@ -2361,7 +3985,7 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2361
3985
|
const name = it?.name ? it.name : idx;
|
|
2362
3986
|
const type = it?.type ? it.type : it;
|
|
2363
3987
|
const el = { name, type };
|
|
2364
|
-
acc[name] = parseResponseValue(responseIterator, el, structs, enums);
|
|
3988
|
+
acc[name] = parseResponseValue(responseIterator, el, parser, structs, enums);
|
|
2365
3989
|
return acc;
|
|
2366
3990
|
}, {});
|
|
2367
3991
|
}
|
|
@@ -2370,13 +3994,20 @@ function parseResponseValue(responseIterator, element, structs, enums) {
|
|
|
2370
3994
|
const el = { name: "", type: getArrayType(element.type) };
|
|
2371
3995
|
const len = BigInt(responseIterator.next().value);
|
|
2372
3996
|
while (parsedDataArr.length < len) {
|
|
2373
|
-
parsedDataArr.push(parseResponseValue(responseIterator, el, structs, enums));
|
|
3997
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, parser, structs, enums));
|
|
2374
3998
|
}
|
|
2375
3999
|
return parsedDataArr;
|
|
2376
4000
|
}
|
|
2377
|
-
return parseBaseTypes2(element.type, responseIterator);
|
|
4001
|
+
return parseBaseTypes2(element.type, responseIterator, parser);
|
|
2378
4002
|
}
|
|
2379
|
-
function responseParser(
|
|
4003
|
+
function responseParser({
|
|
4004
|
+
responseIterator,
|
|
4005
|
+
output,
|
|
4006
|
+
structs,
|
|
4007
|
+
enums,
|
|
4008
|
+
parsedResult,
|
|
4009
|
+
parser
|
|
4010
|
+
}) {
|
|
2380
4011
|
const { name, type } = output;
|
|
2381
4012
|
let temp;
|
|
2382
4013
|
switch (true) {
|
|
@@ -2384,14 +4015,14 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2384
4015
|
temp = responseIterator.next().value;
|
|
2385
4016
|
return BigInt(temp);
|
|
2386
4017
|
case (structs && type in structs || isTypeTuple(type)):
|
|
2387
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4018
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2388
4019
|
case (enums && isTypeEnum(type, enums)):
|
|
2389
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4020
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2390
4021
|
case CairoFixedArray.isTypeFixedArray(type):
|
|
2391
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4022
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2392
4023
|
case isTypeArray(type):
|
|
2393
4024
|
if (isCairo1Type(type)) {
|
|
2394
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4025
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2395
4026
|
}
|
|
2396
4027
|
const parsedDataArr = [];
|
|
2397
4028
|
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
@@ -2401,6 +4032,7 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2401
4032
|
parseResponseValue(
|
|
2402
4033
|
responseIterator,
|
|
2403
4034
|
{ name, type: output.type.replace("*", "") },
|
|
4035
|
+
parser,
|
|
2404
4036
|
structs,
|
|
2405
4037
|
enums
|
|
2406
4038
|
)
|
|
@@ -2409,9 +4041,9 @@ function responseParser(responseIterator, output, structs, enums, parsedResult)
|
|
|
2409
4041
|
}
|
|
2410
4042
|
return parsedDataArr;
|
|
2411
4043
|
case isTypeNonZero(type):
|
|
2412
|
-
return parseResponseValue(responseIterator, output, structs, enums);
|
|
4044
|
+
return parseResponseValue(responseIterator, output, parser, structs, enums);
|
|
2413
4045
|
default:
|
|
2414
|
-
return parseBaseTypes2(type, responseIterator);
|
|
4046
|
+
return parseBaseTypes2(type, responseIterator, parser);
|
|
2415
4047
|
}
|
|
2416
4048
|
}
|
|
2417
4049
|
|
|
@@ -2429,16 +4061,6 @@ var validateFelt = (parameter, input) => {
|
|
|
2429
4061
|
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
2430
4062
|
);
|
|
2431
4063
|
};
|
|
2432
|
-
var validateBytes31 = (parameter, input) => {
|
|
2433
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
2434
|
-
assert(
|
|
2435
|
-
parameter.length < 32,
|
|
2436
|
-
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
2437
|
-
);
|
|
2438
|
-
};
|
|
2439
|
-
var validateByteArray = (parameter, input) => {
|
|
2440
|
-
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
2441
|
-
};
|
|
2442
4064
|
var validateUint = (parameter, input) => {
|
|
2443
4065
|
if (isNumber(parameter)) {
|
|
2444
4066
|
assert(
|
|
@@ -2690,8 +4312,8 @@ function validateFields(abiMethod, args, structs, enums) {
|
|
|
2690
4312
|
case isTypeFelt(input.type):
|
|
2691
4313
|
validateFelt(parameter, input);
|
|
2692
4314
|
break;
|
|
2693
|
-
case
|
|
2694
|
-
|
|
4315
|
+
case CairoBytes31.isAbiType(input.type):
|
|
4316
|
+
CairoBytes31.validate(parameter);
|
|
2695
4317
|
break;
|
|
2696
4318
|
case (isTypeUint(input.type) || isTypeLiteral(input.type)):
|
|
2697
4319
|
validateUint(parameter, input);
|
|
@@ -2699,8 +4321,23 @@ function validateFields(abiMethod, args, structs, enums) {
|
|
|
2699
4321
|
case isTypeBool(input.type):
|
|
2700
4322
|
validateBool(parameter, input);
|
|
2701
4323
|
break;
|
|
2702
|
-
case
|
|
2703
|
-
|
|
4324
|
+
case CairoByteArray.isAbiType(input.type):
|
|
4325
|
+
CairoByteArray.validate(parameter);
|
|
4326
|
+
break;
|
|
4327
|
+
case CairoInt8.isAbiType(input.type):
|
|
4328
|
+
CairoInt8.validate(parameter);
|
|
4329
|
+
break;
|
|
4330
|
+
case CairoInt16.isAbiType(input.type):
|
|
4331
|
+
CairoInt16.validate(parameter);
|
|
4332
|
+
break;
|
|
4333
|
+
case CairoInt32.isAbiType(input.type):
|
|
4334
|
+
CairoInt32.validate(parameter);
|
|
4335
|
+
break;
|
|
4336
|
+
case CairoInt64.isAbiType(input.type):
|
|
4337
|
+
CairoInt64.validate(parameter);
|
|
4338
|
+
break;
|
|
4339
|
+
case CairoInt128.isAbiType(input.type):
|
|
4340
|
+
CairoInt128.validate(parameter);
|
|
2704
4341
|
break;
|
|
2705
4342
|
case (isTypeArray(input.type) || CairoFixedArray.isTypeFixedArray(input.type)):
|
|
2706
4343
|
validateArray(parameter, input, structs, enums);
|
|
@@ -2732,10 +4369,10 @@ var CallData = class _CallData {
|
|
|
2732
4369
|
parser;
|
|
2733
4370
|
structs;
|
|
2734
4371
|
enums;
|
|
2735
|
-
constructor(abi) {
|
|
4372
|
+
constructor(abi, parsingStrategy) {
|
|
2736
4373
|
this.structs = _CallData.getAbiStruct(abi);
|
|
2737
4374
|
this.enums = _CallData.getAbiEnum(abi);
|
|
2738
|
-
this.parser = createAbiParser(abi);
|
|
4375
|
+
this.parser = createAbiParser(abi, parsingStrategy);
|
|
2739
4376
|
this.abi = this.parser.getLegacyFormat();
|
|
2740
4377
|
}
|
|
2741
4378
|
/**
|
|
@@ -2804,7 +4441,15 @@ var CallData = class _CallData {
|
|
|
2804
4441
|
}
|
|
2805
4442
|
const argsIterator = args[Symbol.iterator]();
|
|
2806
4443
|
const callArray = abiMethod.inputs.reduce(
|
|
2807
|
-
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
4444
|
+
(acc, input) => isLen(input.name) && !isCairo1Type(input.type) ? acc : acc.concat(
|
|
4445
|
+
parseCalldataField({
|
|
4446
|
+
argsIterator,
|
|
4447
|
+
input,
|
|
4448
|
+
structs: this.structs,
|
|
4449
|
+
enums: this.enums,
|
|
4450
|
+
parser: this.parser
|
|
4451
|
+
})
|
|
4452
|
+
),
|
|
2808
4453
|
[]
|
|
2809
4454
|
);
|
|
2810
4455
|
Object.defineProperty(callArray, "__compiled__", {
|
|
@@ -2891,7 +4536,14 @@ var CallData = class _CallData {
|
|
|
2891
4536
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
2892
4537
|
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
2893
4538
|
const propName = output.name ?? idx;
|
|
2894
|
-
acc[propName] = responseParser(
|
|
4539
|
+
acc[propName] = responseParser({
|
|
4540
|
+
responseIterator,
|
|
4541
|
+
output,
|
|
4542
|
+
structs: this.structs,
|
|
4543
|
+
enums: this.enums,
|
|
4544
|
+
parsedResult: acc,
|
|
4545
|
+
parser: this.parser
|
|
4546
|
+
});
|
|
2895
4547
|
if (acc[propName] && acc[`${propName}_len`]) {
|
|
2896
4548
|
delete acc[`${propName}_len`];
|
|
2897
4549
|
}
|
|
@@ -2971,12 +4623,13 @@ var CallData = class _CallData {
|
|
|
2971
4623
|
const typeCairoArray = Array.isArray(typeCairo) ? typeCairo : [typeCairo];
|
|
2972
4624
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
2973
4625
|
const decodedArray = typeCairoArray.map(
|
|
2974
|
-
(typeParam) => responseParser(
|
|
4626
|
+
(typeParam) => responseParser({
|
|
2975
4627
|
responseIterator,
|
|
2976
|
-
{ name: "", type: typeParam },
|
|
2977
|
-
this.
|
|
2978
|
-
this.
|
|
2979
|
-
|
|
4628
|
+
output: { name: "", type: typeParam },
|
|
4629
|
+
parser: this.parser,
|
|
4630
|
+
structs: this.structs,
|
|
4631
|
+
enums: this.enums
|
|
4632
|
+
})
|
|
2980
4633
|
);
|
|
2981
4634
|
return decodedArray.length === 1 ? decodedArray[0] : decodedArray;
|
|
2982
4635
|
}
|
|
@@ -3661,114 +5314,6 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
|
3661
5314
|
return { ...contract, program: decompressProgram(contract.program) };
|
|
3662
5315
|
}
|
|
3663
5316
|
|
|
3664
|
-
// src/utils/errors/rpc.ts
|
|
3665
|
-
var errorCodes = {
|
|
3666
|
-
FAILED_TO_RECEIVE_TXN: 1,
|
|
3667
|
-
NO_TRACE_AVAILABLE: 10,
|
|
3668
|
-
CONTRACT_NOT_FOUND: 20,
|
|
3669
|
-
ENTRYPOINT_NOT_FOUND: 21,
|
|
3670
|
-
BLOCK_NOT_FOUND: 24,
|
|
3671
|
-
INVALID_TXN_INDEX: 27,
|
|
3672
|
-
CLASS_HASH_NOT_FOUND: 28,
|
|
3673
|
-
TXN_HASH_NOT_FOUND: 29,
|
|
3674
|
-
PAGE_SIZE_TOO_BIG: 31,
|
|
3675
|
-
NO_BLOCKS: 32,
|
|
3676
|
-
INVALID_CONTINUATION_TOKEN: 33,
|
|
3677
|
-
TOO_MANY_KEYS_IN_FILTER: 34,
|
|
3678
|
-
CONTRACT_ERROR: 40,
|
|
3679
|
-
TRANSACTION_EXECUTION_ERROR: 41,
|
|
3680
|
-
STORAGE_PROOF_NOT_SUPPORTED: 42,
|
|
3681
|
-
CLASS_ALREADY_DECLARED: 51,
|
|
3682
|
-
INVALID_TRANSACTION_NONCE: 52,
|
|
3683
|
-
INSUFFICIENT_RESOURCES_FOR_VALIDATE: 53,
|
|
3684
|
-
INSUFFICIENT_ACCOUNT_BALANCE: 54,
|
|
3685
|
-
VALIDATION_FAILURE: 55,
|
|
3686
|
-
COMPILATION_FAILED: 56,
|
|
3687
|
-
CONTRACT_CLASS_SIZE_IS_TOO_LARGE: 57,
|
|
3688
|
-
NON_ACCOUNT: 58,
|
|
3689
|
-
DUPLICATE_TX: 59,
|
|
3690
|
-
COMPILED_CLASS_HASH_MISMATCH: 60,
|
|
3691
|
-
UNSUPPORTED_TX_VERSION: 61,
|
|
3692
|
-
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
3693
|
-
UNEXPECTED_ERROR: 63,
|
|
3694
|
-
INVALID_SUBSCRIPTION_ID: 66,
|
|
3695
|
-
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
3696
|
-
TOO_MANY_BLOCKS_BACK: 68,
|
|
3697
|
-
COMPILATION_ERROR: 100,
|
|
3698
|
-
INVALID_ADDRESS: 150,
|
|
3699
|
-
TOKEN_NOT_SUPPORTED: 151,
|
|
3700
|
-
INVALID_SIGNATURE: 153,
|
|
3701
|
-
MAX_AMOUNT_TOO_LOW: 154,
|
|
3702
|
-
CLASS_HASH_NOT_SUPPORTED: 155,
|
|
3703
|
-
PAYMASTER_TRANSACTION_EXECUTION_ERROR: 156,
|
|
3704
|
-
INVALID_TIME_BOUNDS: 157,
|
|
3705
|
-
INVALID_DEPLOYMENT_DATA: 158,
|
|
3706
|
-
INVALID_CLASS_HASH: 159,
|
|
3707
|
-
INVALID_ID: 160,
|
|
3708
|
-
UNKNOWN_ERROR: 163
|
|
3709
|
-
};
|
|
3710
|
-
var rpc_default = errorCodes;
|
|
3711
|
-
|
|
3712
|
-
// src/utils/errors/index.ts
|
|
3713
|
-
function fixStack(target, fn = target.constructor) {
|
|
3714
|
-
const { captureStackTrace } = Error;
|
|
3715
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
3716
|
-
}
|
|
3717
|
-
function fixProto(target, prototype) {
|
|
3718
|
-
const { setPrototypeOf } = Object;
|
|
3719
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3720
|
-
}
|
|
3721
|
-
var CustomError = class extends Error {
|
|
3722
|
-
name;
|
|
3723
|
-
constructor(message) {
|
|
3724
|
-
super(message);
|
|
3725
|
-
Object.defineProperty(this, "name", {
|
|
3726
|
-
value: new.target.name,
|
|
3727
|
-
enumerable: false,
|
|
3728
|
-
configurable: true
|
|
3729
|
-
});
|
|
3730
|
-
fixProto(this, new.target.prototype);
|
|
3731
|
-
fixStack(this);
|
|
3732
|
-
}
|
|
3733
|
-
};
|
|
3734
|
-
var LibraryError = class extends CustomError {
|
|
3735
|
-
};
|
|
3736
|
-
var RpcError = class extends LibraryError {
|
|
3737
|
-
constructor(baseError, method, params) {
|
|
3738
|
-
super(`RPC: ${method} with params ${stringify2(params, null, 2)}
|
|
3739
|
-
|
|
3740
|
-
${baseError.code}: ${baseError.message}: ${stringify2(baseError.data)}`);
|
|
3741
|
-
this.baseError = baseError;
|
|
3742
|
-
this.request = { method, params };
|
|
3743
|
-
}
|
|
3744
|
-
request;
|
|
3745
|
-
get code() {
|
|
3746
|
-
return this.baseError.code;
|
|
3747
|
-
}
|
|
3748
|
-
/**
|
|
3749
|
-
* Verifies the underlying RPC error, also serves as a type guard for the _baseError_ property
|
|
3750
|
-
* @example
|
|
3751
|
-
* ```typescript
|
|
3752
|
-
* SomeError.isType('UNEXPECTED_ERROR');
|
|
3753
|
-
* ```
|
|
3754
|
-
*/
|
|
3755
|
-
isType(typeName) {
|
|
3756
|
-
return rpc_default[typeName] === this.code;
|
|
3757
|
-
}
|
|
3758
|
-
};
|
|
3759
|
-
var TimeoutError = class extends LibraryError {
|
|
3760
|
-
constructor(message) {
|
|
3761
|
-
super(message);
|
|
3762
|
-
this.name = "TimeoutError";
|
|
3763
|
-
}
|
|
3764
|
-
};
|
|
3765
|
-
var WebSocketNotConnectedError = class extends LibraryError {
|
|
3766
|
-
constructor(message) {
|
|
3767
|
-
super(message);
|
|
3768
|
-
this.name = "WebSocketNotConnectedError";
|
|
3769
|
-
}
|
|
3770
|
-
};
|
|
3771
|
-
|
|
3772
5317
|
// src/utils/eth.ts
|
|
3773
5318
|
var eth_exports = {};
|
|
3774
5319
|
__export(eth_exports, {
|
|
@@ -3907,7 +5452,7 @@ var Block = class {
|
|
|
3907
5452
|
tag = null;
|
|
3908
5453
|
setIdentifier(__identifier) {
|
|
3909
5454
|
if (isString(__identifier)) {
|
|
3910
|
-
if (
|
|
5455
|
+
if (isDecimalString2(__identifier)) {
|
|
3911
5456
|
this.number = parseInt(__identifier, 10);
|
|
3912
5457
|
} else if (isHex(__identifier)) {
|
|
3913
5458
|
this.hash = __identifier;
|
|
@@ -4356,11 +5901,13 @@ var RpcChannel = class {
|
|
|
4356
5901
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L2,
|
|
4357
5902
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L1
|
|
4358
5903
|
];
|
|
5904
|
+
const txLife = [];
|
|
4359
5905
|
let txStatus;
|
|
4360
5906
|
while (!onchain) {
|
|
4361
5907
|
await wait(retryInterval);
|
|
4362
5908
|
try {
|
|
4363
5909
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
5910
|
+
txLife.push(txStatus.finality_status);
|
|
4364
5911
|
const executionStatus = txStatus.execution_status;
|
|
4365
5912
|
const finalityStatus = txStatus.finality_status;
|
|
4366
5913
|
if (!finalityStatus) {
|
|
@@ -4380,6 +5927,18 @@ var RpcChannel = class {
|
|
|
4380
5927
|
if (error instanceof Error && isErrorState) {
|
|
4381
5928
|
throw error;
|
|
4382
5929
|
}
|
|
5930
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
5931
|
+
logger.info("txLife: ", txLife);
|
|
5932
|
+
const errorMessages = {
|
|
5933
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
5934
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
5935
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
5936
|
+
};
|
|
5937
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
5938
|
+
if (errorMessage) {
|
|
5939
|
+
throw new Error(errorMessage);
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
4383
5942
|
if (retries <= 0) {
|
|
4384
5943
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
4385
5944
|
}
|
|
@@ -4929,11 +6488,13 @@ var RpcChannel2 = class {
|
|
|
4929
6488
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
4930
6489
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1
|
|
4931
6490
|
];
|
|
6491
|
+
const txLife = [];
|
|
4932
6492
|
let txStatus;
|
|
4933
6493
|
while (!onchain) {
|
|
4934
6494
|
await wait(retryInterval);
|
|
4935
6495
|
try {
|
|
4936
6496
|
txStatus = await this.getTransactionStatus(transactionHash);
|
|
6497
|
+
txLife.push(txStatus.finality_status);
|
|
4937
6498
|
const executionStatus = txStatus.execution_status;
|
|
4938
6499
|
const finalityStatus = txStatus.finality_status;
|
|
4939
6500
|
if (!finalityStatus) {
|
|
@@ -4953,6 +6514,18 @@ var RpcChannel2 = class {
|
|
|
4953
6514
|
if (error instanceof Error && isErrorState) {
|
|
4954
6515
|
throw error;
|
|
4955
6516
|
}
|
|
6517
|
+
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
6518
|
+
logger.info("txLife: ", txLife);
|
|
6519
|
+
const errorMessages = {
|
|
6520
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
6521
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
6522
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
6523
|
+
};
|
|
6524
|
+
const errorMessage = errorMessages[txLife.at(-1)];
|
|
6525
|
+
if (errorMessage) {
|
|
6526
|
+
throw new Error(errorMessage);
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
4956
6529
|
if (retries <= 0) {
|
|
4957
6530
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
4958
6531
|
}
|
|
@@ -5998,56 +7571,123 @@ var ReceiptTx = class _ReceiptTx {
|
|
|
5998
7571
|
statusReceipt;
|
|
5999
7572
|
value;
|
|
6000
7573
|
constructor(receipt) {
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
}
|
|
6007
|
-
for (const [key, value] of Object.entries(receipt)) {
|
|
6008
|
-
Object.defineProperty(this, key, {
|
|
6009
|
-
enumerable: true,
|
|
7574
|
+
Object.assign(this, receipt);
|
|
7575
|
+
const [statusReceipt, value] = _ReceiptTx.isSuccess(receipt) ? ["SUCCEEDED", receipt] : _ReceiptTx.isReverted(receipt) ? ["REVERTED", receipt] : ["ERROR", new Error("Unknown response type")];
|
|
7576
|
+
Object.defineProperties(this, {
|
|
7577
|
+
statusReceipt: {
|
|
7578
|
+
value: statusReceipt,
|
|
6010
7579
|
writable: false,
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
7580
|
+
enumerable: false,
|
|
7581
|
+
configurable: false
|
|
7582
|
+
},
|
|
7583
|
+
value: {
|
|
7584
|
+
value,
|
|
7585
|
+
writable: false,
|
|
7586
|
+
enumerable: false,
|
|
7587
|
+
configurable: false
|
|
7588
|
+
},
|
|
7589
|
+
match: {
|
|
7590
|
+
value(callbacks) {
|
|
7591
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
7592
|
+
},
|
|
7593
|
+
writable: false,
|
|
7594
|
+
enumerable: false,
|
|
7595
|
+
configurable: false
|
|
7596
|
+
},
|
|
7597
|
+
isSuccess: {
|
|
7598
|
+
value: () => statusReceipt === "SUCCEEDED",
|
|
7599
|
+
writable: false,
|
|
7600
|
+
enumerable: false,
|
|
7601
|
+
configurable: false
|
|
7602
|
+
},
|
|
7603
|
+
isReverted: {
|
|
7604
|
+
value: () => statusReceipt === "REVERTED",
|
|
7605
|
+
writable: false,
|
|
7606
|
+
enumerable: false,
|
|
7607
|
+
configurable: false
|
|
7608
|
+
},
|
|
7609
|
+
isError: {
|
|
7610
|
+
value: () => statusReceipt === "ERROR",
|
|
7611
|
+
writable: false,
|
|
7612
|
+
enumerable: false,
|
|
7613
|
+
configurable: false
|
|
7614
|
+
}
|
|
7615
|
+
});
|
|
6034
7616
|
}
|
|
7617
|
+
match;
|
|
7618
|
+
isSuccess;
|
|
7619
|
+
isReverted;
|
|
7620
|
+
isError;
|
|
6035
7621
|
static isSuccess(transactionReceipt) {
|
|
6036
7622
|
return transactionReceipt.execution_status === TransactionExecutionStatus.SUCCEEDED;
|
|
6037
7623
|
}
|
|
6038
7624
|
static isReverted(transactionReceipt) {
|
|
6039
7625
|
return transactionReceipt.execution_status === TransactionExecutionStatus.REVERTED;
|
|
6040
7626
|
}
|
|
6041
|
-
// Status do not exist on receipts
|
|
6042
|
-
/* static isRejected(
|
|
6043
|
-
transactionReceipt: GetTxReceiptResponseWithoutHelper
|
|
6044
|
-
): transactionReceipt is RejectedTransactionReceiptResponse {
|
|
6045
|
-
return (
|
|
6046
|
-
(transactionReceipt as RejectedTransactionReceiptResponse).status ===
|
|
6047
|
-
TransactionExecutionStatus.REJECTED
|
|
6048
|
-
);
|
|
6049
|
-
} */
|
|
6050
7627
|
};
|
|
7628
|
+
var RECEIPT_CONFIG = {
|
|
7629
|
+
[TransactionExecutionStatus.SUCCEEDED]: {
|
|
7630
|
+
statusReceipt: "SUCCEEDED",
|
|
7631
|
+
getBaseData: (receipt) => receipt,
|
|
7632
|
+
getValue: (receipt) => receipt
|
|
7633
|
+
},
|
|
7634
|
+
[TransactionExecutionStatus.REVERTED]: {
|
|
7635
|
+
statusReceipt: "REVERTED",
|
|
7636
|
+
getBaseData: (receipt) => receipt,
|
|
7637
|
+
getValue: (receipt) => receipt
|
|
7638
|
+
}
|
|
7639
|
+
};
|
|
7640
|
+
function createTransactionReceipt(receipt) {
|
|
7641
|
+
const config2 = RECEIPT_CONFIG[receipt.execution_status];
|
|
7642
|
+
let obj;
|
|
7643
|
+
if (config2) {
|
|
7644
|
+
const { statusReceipt, getBaseData, getValue } = config2;
|
|
7645
|
+
const value = getValue(receipt);
|
|
7646
|
+
obj = {
|
|
7647
|
+
...getBaseData(receipt),
|
|
7648
|
+
statusReceipt,
|
|
7649
|
+
value,
|
|
7650
|
+
match(callbacks) {
|
|
7651
|
+
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
7652
|
+
},
|
|
7653
|
+
isSuccess() {
|
|
7654
|
+
return statusReceipt === "SUCCEEDED";
|
|
7655
|
+
},
|
|
7656
|
+
isReverted() {
|
|
7657
|
+
return statusReceipt === "REVERTED";
|
|
7658
|
+
},
|
|
7659
|
+
isError() {
|
|
7660
|
+
return false;
|
|
7661
|
+
}
|
|
7662
|
+
};
|
|
7663
|
+
} else {
|
|
7664
|
+
const errorValue = new Error("Unknown response type");
|
|
7665
|
+
obj = {
|
|
7666
|
+
statusReceipt: "ERROR",
|
|
7667
|
+
value: errorValue,
|
|
7668
|
+
match(callbacks) {
|
|
7669
|
+
return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
|
|
7670
|
+
},
|
|
7671
|
+
isSuccess() {
|
|
7672
|
+
return false;
|
|
7673
|
+
},
|
|
7674
|
+
isReverted() {
|
|
7675
|
+
return false;
|
|
7676
|
+
},
|
|
7677
|
+
isError() {
|
|
7678
|
+
return true;
|
|
7679
|
+
}
|
|
7680
|
+
};
|
|
7681
|
+
}
|
|
7682
|
+
Object.setPrototypeOf(obj, ReceiptTx.prototype);
|
|
7683
|
+
Object.defineProperty(obj, "constructor", {
|
|
7684
|
+
value: ReceiptTx,
|
|
7685
|
+
writable: false,
|
|
7686
|
+
enumerable: false,
|
|
7687
|
+
configurable: false
|
|
7688
|
+
});
|
|
7689
|
+
return obj;
|
|
7690
|
+
}
|
|
6051
7691
|
|
|
6052
7692
|
// src/utils/typedData.ts
|
|
6053
7693
|
var typedData_exports = {};
|
|
@@ -6716,7 +8356,7 @@ var RpcProvider = class {
|
|
|
6716
8356
|
async getTransactionReceipt(txHash) {
|
|
6717
8357
|
const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
|
|
6718
8358
|
const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
|
|
6719
|
-
return
|
|
8359
|
+
return createTransactionReceipt(txReceiptWoHelperModified);
|
|
6720
8360
|
}
|
|
6721
8361
|
async getTransactionTrace(txHash) {
|
|
6722
8362
|
return this.channel.getTransactionTrace(txHash);
|
|
@@ -6732,7 +8372,7 @@ var RpcProvider = class {
|
|
|
6732
8372
|
txHash,
|
|
6733
8373
|
options
|
|
6734
8374
|
);
|
|
6735
|
-
return
|
|
8375
|
+
return createTransactionReceipt(receiptWoHelper);
|
|
6736
8376
|
}
|
|
6737
8377
|
async getStorageAt(contractAddress, key, blockIdentifier) {
|
|
6738
8378
|
return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
|
|
@@ -7739,12 +9379,12 @@ var LedgerSigner111 = class {
|
|
|
7739
9379
|
*/
|
|
7740
9380
|
async signRaw(msgHash) {
|
|
7741
9381
|
addHexPrefix(
|
|
7742
|
-
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0,
|
|
9382
|
+
buf2hex(await this._transporter.send(Number("0x5a"), 2, 0, 0, buffer_default.from(this.pathBuffer)))
|
|
7743
9383
|
);
|
|
7744
9384
|
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
7745
9385
|
const buff2 = hexToBytes(shiftedHash);
|
|
7746
9386
|
const respSign2 = Uint8Array.from(
|
|
7747
|
-
await this._transporter.send(Number("0x5a"), 2, 1, 0,
|
|
9387
|
+
await this._transporter.send(Number("0x5a"), 2, 1, 0, buffer_default.from(buff2))
|
|
7748
9388
|
);
|
|
7749
9389
|
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
7750
9390
|
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
@@ -7757,7 +9397,7 @@ var LedgerSigner111 = class {
|
|
|
7757
9397
|
async getPublicKeys() {
|
|
7758
9398
|
const pathBuff = this.pathBuffer;
|
|
7759
9399
|
const respGetPublic = Uint8Array.from(
|
|
7760
|
-
await this._transporter.send(Number("0x5a"), 1, 0, 0,
|
|
9400
|
+
await this._transporter.send(Number("0x5a"), 1, 0, 0, buffer_default.from(pathBuff))
|
|
7761
9401
|
);
|
|
7762
9402
|
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
7763
9403
|
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
@@ -8013,7 +9653,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8013
9653
|
txDetails.accountDeploymentData.length <= 7,
|
|
8014
9654
|
"accountDeploymentData includes more than 7 items"
|
|
8015
9655
|
);
|
|
8016
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
9656
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8017
9657
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
8018
9658
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8019
9659
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
@@ -8035,30 +9675,30 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8035
9675
|
nonceBuf,
|
|
8036
9676
|
dAModeHashBuf
|
|
8037
9677
|
]);
|
|
8038
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
9678
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
8039
9679
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8040
9680
|
txDetails.paymasterData.map((value) => {
|
|
8041
9681
|
const a = this.convertBnToLedger(value);
|
|
8042
9682
|
return a;
|
|
8043
9683
|
})
|
|
8044
9684
|
);
|
|
8045
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
9685
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(paymasterBuf));
|
|
8046
9686
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
8047
9687
|
txDetails.paymasterData.map((value) => {
|
|
8048
9688
|
const a = this.convertBnToLedger(value);
|
|
8049
9689
|
return a;
|
|
8050
9690
|
})
|
|
8051
9691
|
);
|
|
8052
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
9692
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(accountDeployDataBuf));
|
|
8053
9693
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8054
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
9694
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(nbCallsBuf));
|
|
8055
9695
|
let respSign = new Uint8Array(0);
|
|
8056
9696
|
for (const call of calls) {
|
|
8057
9697
|
const calldatas = this.encodeCall(call);
|
|
8058
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
9698
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(calldatas[0]));
|
|
8059
9699
|
if (calldatas.length > 1) {
|
|
8060
9700
|
calldatas.slice(1).forEach(async (part) => {
|
|
8061
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 1,
|
|
9701
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 1, buffer_default.from(part));
|
|
8062
9702
|
});
|
|
8063
9703
|
}
|
|
8064
9704
|
respSign = await this._transporter.send(Number("0x5a"), 3, 5, 2);
|
|
@@ -8095,7 +9735,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8095
9735
|
* ```
|
|
8096
9736
|
*/
|
|
8097
9737
|
async signDeployAccountV3(deployAccountDetail) {
|
|
8098
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
9738
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8099
9739
|
const accountAddressBuf = this.convertBnToLedger(
|
|
8100
9740
|
deployAccountDetail.contractAddress
|
|
8101
9741
|
);
|
|
@@ -8117,7 +9757,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8117
9757
|
classHashBuf,
|
|
8118
9758
|
saltBuf
|
|
8119
9759
|
]);
|
|
8120
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
9760
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
8121
9761
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8122
9762
|
const l1_gasBuf = this.convertBnToLedger(
|
|
8123
9763
|
encodeResourceBoundsL1(deployAccountDetail.resourceBounds)
|
|
@@ -8126,17 +9766,17 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8126
9766
|
encodeResourceBoundsL2(deployAccountDetail.resourceBounds)
|
|
8127
9767
|
);
|
|
8128
9768
|
const feeBuf = concatenateArrayBuffer([tipBuf, l1_gasBuf, l2_gasBuf]);
|
|
8129
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
9769
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
8130
9770
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8131
9771
|
deployAccountDetail.paymasterData.map((value) => {
|
|
8132
9772
|
const a = this.convertBnToLedger(value);
|
|
8133
9773
|
return a;
|
|
8134
9774
|
})
|
|
8135
9775
|
);
|
|
8136
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
9776
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
8137
9777
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8138
9778
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8139
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
9779
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
8140
9780
|
const constructorBuf = concatenateArrayBuffer(
|
|
8141
9781
|
compiledConstructor.map((parameter) => {
|
|
8142
9782
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -8149,7 +9789,7 @@ var LedgerSigner221 = class extends LedgerSigner111 {
|
|
|
8149
9789
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8150
9790
|
let respSign = new Uint8Array(0);
|
|
8151
9791
|
for (const chunk of constructorChunks) {
|
|
8152
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
9792
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
8153
9793
|
}
|
|
8154
9794
|
return this.decodeSignatureLedger(respSign);
|
|
8155
9795
|
}
|
|
@@ -8239,7 +9879,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8239
9879
|
txDetails.accountDeploymentData.length <= 7,
|
|
8240
9880
|
"accountDeploymentData includes more than 7 items"
|
|
8241
9881
|
);
|
|
8242
|
-
await this._transporter.send(Number("0x5a"), 3, 0, 0,
|
|
9882
|
+
await this._transporter.send(Number("0x5a"), 3, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8243
9883
|
const accountAddressBuf = this.convertBnToLedger(txDetails.walletAddress);
|
|
8244
9884
|
const chainIdBuf = this.convertBnToLedger(txDetails.chainId);
|
|
8245
9885
|
const nonceBuf = this.convertBnToLedger(txDetails.nonce);
|
|
@@ -8255,7 +9895,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8255
9895
|
nonceBuf,
|
|
8256
9896
|
dAModeHashBuf
|
|
8257
9897
|
]);
|
|
8258
|
-
await this._transporter.send(Number("0x5a"), 3, 1, 0,
|
|
9898
|
+
await this._transporter.send(Number("0x5a"), 3, 1, 0, buffer_default.from(dataBuf));
|
|
8259
9899
|
if (isRPC08Plus_ResourceBoundsBN(txDetails.resourceBounds)) {
|
|
8260
9900
|
const tipBuf = this.convertBnToLedger(txDetails.tip);
|
|
8261
9901
|
const l1_gasBuf = this.convertBnToLedger(encodeResourceBoundsL1(txDetails.resourceBounds));
|
|
@@ -8269,7 +9909,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8269
9909
|
l2_gasBuf,
|
|
8270
9910
|
l1_data_gasBuf
|
|
8271
9911
|
]);
|
|
8272
|
-
await this._transporter.send(Number("0x5a"), 3, 2, 0,
|
|
9912
|
+
await this._transporter.send(Number("0x5a"), 3, 2, 0, buffer_default.from(feeBuf));
|
|
8273
9913
|
}
|
|
8274
9914
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8275
9915
|
txDetails.paymasterData.map((value) => {
|
|
@@ -8277,23 +9917,23 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8277
9917
|
return a;
|
|
8278
9918
|
})
|
|
8279
9919
|
);
|
|
8280
|
-
await this._transporter.send(Number("0x5a"), 3, 3, 0,
|
|
9920
|
+
await this._transporter.send(Number("0x5a"), 3, 3, 0, buffer_default.from(paymasterBuf));
|
|
8281
9921
|
const accountDeployDataBuf = concatenateArrayBuffer(
|
|
8282
9922
|
txDetails.paymasterData.map((value) => {
|
|
8283
9923
|
const a = this.convertBnToLedger(value);
|
|
8284
9924
|
return a;
|
|
8285
9925
|
})
|
|
8286
9926
|
);
|
|
8287
|
-
await this._transporter.send(Number("0x5a"), 3, 4, 0,
|
|
9927
|
+
await this._transporter.send(Number("0x5a"), 3, 4, 0, buffer_default.from(accountDeployDataBuf));
|
|
8288
9928
|
const nbCallsBuf = this.convertBnToLedger(calls.length);
|
|
8289
|
-
await this._transporter.send(Number("0x5a"), 3, 5, 0,
|
|
9929
|
+
await this._transporter.send(Number("0x5a"), 3, 5, 0, buffer_default.from(nbCallsBuf));
|
|
8290
9930
|
let respSign = new Uint8Array(0);
|
|
8291
9931
|
for (const call of calls) {
|
|
8292
9932
|
const calldatas = this.encodeCall(call);
|
|
8293
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0,
|
|
9933
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 0, buffer_default.from(calldatas[0]));
|
|
8294
9934
|
if (calldatas.length > 1) {
|
|
8295
9935
|
calldatas.slice(1).forEach(async (part) => {
|
|
8296
|
-
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1,
|
|
9936
|
+
respSign = await this._transporter.send(Number("0x5a"), 3, 6, 1, buffer_default.from(part));
|
|
8297
9937
|
});
|
|
8298
9938
|
}
|
|
8299
9939
|
}
|
|
@@ -8329,7 +9969,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8329
9969
|
* ```
|
|
8330
9970
|
*/
|
|
8331
9971
|
async signDeployAccountV3(deployAccountDetail) {
|
|
8332
|
-
await this._transporter.send(Number("0x5a"), 5, 0, 0,
|
|
9972
|
+
await this._transporter.send(Number("0x5a"), 5, 0, 0, buffer_default.from(this.pathBuffer));
|
|
8333
9973
|
const accountAddressBuf = this.convertBnToLedger(
|
|
8334
9974
|
deployAccountDetail.contractAddress
|
|
8335
9975
|
);
|
|
@@ -8351,7 +9991,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8351
9991
|
classHashBuf,
|
|
8352
9992
|
saltBuf
|
|
8353
9993
|
]);
|
|
8354
|
-
await this._transporter.send(Number("0x5a"), 5, 1, 0,
|
|
9994
|
+
await this._transporter.send(Number("0x5a"), 5, 1, 0, buffer_default.from(dataBuf));
|
|
8355
9995
|
if (isRPC08Plus_ResourceBoundsBN(deployAccountDetail.resourceBounds)) {
|
|
8356
9996
|
const tipBuf = this.convertBnToLedger(deployAccountDetail.tip);
|
|
8357
9997
|
const l1_gasBuf = this.convertBnToLedger(
|
|
@@ -8369,7 +10009,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8369
10009
|
l2_gasBuf,
|
|
8370
10010
|
l1_data_gasBuf
|
|
8371
10011
|
]);
|
|
8372
|
-
await this._transporter.send(Number("0x5a"), 5, 2, 0,
|
|
10012
|
+
await this._transporter.send(Number("0x5a"), 5, 2, 0, buffer_default.from(feeBuf));
|
|
8373
10013
|
}
|
|
8374
10014
|
const paymasterBuf = concatenateArrayBuffer(
|
|
8375
10015
|
deployAccountDetail.paymasterData.map((value) => {
|
|
@@ -8377,10 +10017,10 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8377
10017
|
return a;
|
|
8378
10018
|
})
|
|
8379
10019
|
);
|
|
8380
|
-
await this._transporter.send(Number("0x5a"), 5, 3, 0,
|
|
10020
|
+
await this._transporter.send(Number("0x5a"), 5, 3, 0, buffer_default.from(paymasterBuf));
|
|
8381
10021
|
const compiledConstructor = CallData.compile(deployAccountDetail.constructorCalldata);
|
|
8382
10022
|
const constructorLengthBuf = this.convertBnToLedger(compiledConstructor.length);
|
|
8383
|
-
await this._transporter.send(Number("0x5a"), 5, 4, 0,
|
|
10023
|
+
await this._transporter.send(Number("0x5a"), 5, 4, 0, buffer_default.from(constructorLengthBuf));
|
|
8384
10024
|
const constructorBuf = concatenateArrayBuffer(
|
|
8385
10025
|
compiledConstructor.map((parameter) => {
|
|
8386
10026
|
const a = this.convertBnToLedger(parameter);
|
|
@@ -8393,7 +10033,7 @@ var LedgerSigner231 = class extends LedgerSigner221 {
|
|
|
8393
10033
|
constructorChunks.push(constructorBuf.subarray(i, i + chunkSize));
|
|
8394
10034
|
let respSign = new Uint8Array(0);
|
|
8395
10035
|
for (const chunk of constructorChunks) {
|
|
8396
|
-
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0,
|
|
10036
|
+
respSign = await this._transporter.send(Number("0x5a"), 5, 5, 0, buffer_default.from(chunk));
|
|
8397
10037
|
}
|
|
8398
10038
|
return this.decodeSignatureLedger(respSign);
|
|
8399
10039
|
}
|
|
@@ -9921,7 +11561,11 @@ function mergeAbiEvents(target, source) {
|
|
|
9921
11561
|
Object.keys(source).forEach((key) => {
|
|
9922
11562
|
if (isObject(source[key])) {
|
|
9923
11563
|
if (!(key in target)) Object.assign(output, { [key]: source[key] });
|
|
9924
|
-
else
|
|
11564
|
+
else
|
|
11565
|
+
output[key] = mergeAbiEvents(
|
|
11566
|
+
target[key],
|
|
11567
|
+
source[key]
|
|
11568
|
+
);
|
|
9925
11569
|
} else {
|
|
9926
11570
|
Object.assign(output, { [key]: source[key] });
|
|
9927
11571
|
}
|
|
@@ -9929,7 +11573,7 @@ function mergeAbiEvents(target, source) {
|
|
|
9929
11573
|
}
|
|
9930
11574
|
return output;
|
|
9931
11575
|
}
|
|
9932
|
-
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
|
|
11576
|
+
function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums, parser) {
|
|
9933
11577
|
const ret = providerReceivedEvents.flat().reduce((acc, recEvent) => {
|
|
9934
11578
|
const currentEvent = JSON.parse(JSON.stringify(recEvent));
|
|
9935
11579
|
let abiEvent = abiEvents[currentEvent.keys.shift() ?? 0];
|
|
@@ -9948,22 +11592,24 @@ function parseEvents(providerReceivedEvents, abiEvents, abiStructs, abiEnums) {
|
|
|
9948
11592
|
const abiEventKeys = abiEvent.members?.filter((it) => it.kind === "key") || abiEvent.keys;
|
|
9949
11593
|
const abiEventData = abiEvent.members?.filter((it) => it.kind === "data") || abiEvent.data;
|
|
9950
11594
|
abiEventKeys.forEach((key) => {
|
|
9951
|
-
parsedEvent[abiEvent.name][key.name] = responseParser(
|
|
9952
|
-
keysIter,
|
|
9953
|
-
key,
|
|
9954
|
-
abiStructs,
|
|
9955
|
-
abiEnums,
|
|
9956
|
-
|
|
9957
|
-
|
|
11595
|
+
parsedEvent[abiEvent.name][key.name] = responseParser({
|
|
11596
|
+
responseIterator: keysIter,
|
|
11597
|
+
output: key,
|
|
11598
|
+
structs: abiStructs,
|
|
11599
|
+
enums: abiEnums,
|
|
11600
|
+
parser,
|
|
11601
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
11602
|
+
});
|
|
9958
11603
|
});
|
|
9959
11604
|
abiEventData.forEach((data) => {
|
|
9960
|
-
parsedEvent[abiEvent.name][data.name] = responseParser(
|
|
9961
|
-
dataIter,
|
|
9962
|
-
data,
|
|
9963
|
-
abiStructs,
|
|
9964
|
-
abiEnums,
|
|
9965
|
-
|
|
9966
|
-
|
|
11605
|
+
parsedEvent[abiEvent.name][data.name] = responseParser({
|
|
11606
|
+
responseIterator: dataIter,
|
|
11607
|
+
output: data,
|
|
11608
|
+
structs: abiStructs,
|
|
11609
|
+
enums: abiEnums,
|
|
11610
|
+
parser,
|
|
11611
|
+
parsedResult: parsedEvent[abiEvent.name]
|
|
11612
|
+
});
|
|
9967
11613
|
});
|
|
9968
11614
|
if ("block_hash" in currentEvent) parsedEvent.block_hash = currentEvent.block_hash;
|
|
9969
11615
|
if ("block_number" in currentEvent) parsedEvent.block_number = currentEvent.block_number;
|
|
@@ -9981,8 +11627,8 @@ function buildCall(contract, functionAbi) {
|
|
|
9981
11627
|
const options = { ...contract.withOptionsProps };
|
|
9982
11628
|
contract.withOptionsProps = void 0;
|
|
9983
11629
|
return contract.call(functionAbi.name, args, {
|
|
9984
|
-
parseRequest:
|
|
9985
|
-
parseResponse:
|
|
11630
|
+
parseRequest: contract.parseRequest,
|
|
11631
|
+
parseResponse: contract.parseResponse,
|
|
9986
11632
|
...options
|
|
9987
11633
|
});
|
|
9988
11634
|
};
|
|
@@ -9992,7 +11638,7 @@ function buildInvoke(contract, functionAbi) {
|
|
|
9992
11638
|
const options = { ...contract.withOptionsProps };
|
|
9993
11639
|
contract.withOptionsProps = void 0;
|
|
9994
11640
|
return contract.invoke(functionAbi.name, args, {
|
|
9995
|
-
parseRequest:
|
|
11641
|
+
parseRequest: contract.parseRequest,
|
|
9996
11642
|
...options
|
|
9997
11643
|
});
|
|
9998
11644
|
};
|
|
@@ -10020,6 +11666,8 @@ var Contract = class _Contract {
|
|
|
10020
11666
|
address;
|
|
10021
11667
|
providerOrAccount;
|
|
10022
11668
|
classHash;
|
|
11669
|
+
parseRequest;
|
|
11670
|
+
parseResponse;
|
|
10023
11671
|
structs;
|
|
10024
11672
|
events;
|
|
10025
11673
|
functions;
|
|
@@ -10028,6 +11676,7 @@ var Contract = class _Contract {
|
|
|
10028
11676
|
estimateFee;
|
|
10029
11677
|
callData;
|
|
10030
11678
|
withOptionsProps;
|
|
11679
|
+
parsingStrategy;
|
|
10031
11680
|
/**
|
|
10032
11681
|
* @param options
|
|
10033
11682
|
* - abi: Abi of the contract object (required)
|
|
@@ -10035,14 +11684,18 @@ var Contract = class _Contract {
|
|
|
10035
11684
|
* - providerOrAccount?: Provider or Account to attach to (fallback to defaultProvider)
|
|
10036
11685
|
* - parseRequest?: compile and validate arguments (optional, default true)
|
|
10037
11686
|
* - parseResponse?: Parse elements of the response array and structuring them into response object (optional, default true)
|
|
11687
|
+
* - parser?: Abi parser (optional, default createAbiParser(options.abi))
|
|
10038
11688
|
*/
|
|
10039
11689
|
constructor(options) {
|
|
10040
|
-
|
|
10041
|
-
|
|
11690
|
+
this.parsingStrategy = options.parsingStrategy;
|
|
11691
|
+
const parser = createAbiParser(options.abi, options.parsingStrategy);
|
|
10042
11692
|
this.abi = parser.getLegacyFormat();
|
|
11693
|
+
this.address = options.address && options.address.toLowerCase();
|
|
10043
11694
|
this.providerOrAccount = options.providerOrAccount ?? defaultProvider;
|
|
11695
|
+
this.parseRequest = options.parseRequest ?? true;
|
|
11696
|
+
this.parseResponse = options.parseResponse ?? true;
|
|
10044
11697
|
this.classHash = options.classHash;
|
|
10045
|
-
this.callData = new CallData(options.abi);
|
|
11698
|
+
this.callData = new CallData(options.abi, options.parsingStrategy);
|
|
10046
11699
|
this.structs = CallData.getAbiStruct(options.abi);
|
|
10047
11700
|
this.events = getAbiEvents(options.abi);
|
|
10048
11701
|
const methodTypes = { enumerable: true, value: {}, writable: false };
|
|
@@ -10094,8 +11747,9 @@ var Contract = class _Contract {
|
|
|
10094
11747
|
attach(address, abi) {
|
|
10095
11748
|
this.address = address;
|
|
10096
11749
|
if (abi) {
|
|
10097
|
-
|
|
10098
|
-
this.
|
|
11750
|
+
const parser = createAbiParser(abi, this.parsingStrategy);
|
|
11751
|
+
this.abi = parser.getLegacyFormat();
|
|
11752
|
+
this.callData = new CallData(abi, this.parsingStrategy);
|
|
10099
11753
|
this.structs = CallData.getAbiStruct(abi);
|
|
10100
11754
|
this.events = getAbiEvents(abi);
|
|
10101
11755
|
}
|
|
@@ -10141,7 +11795,8 @@ var Contract = class _Contract {
|
|
|
10141
11795
|
return this.callData.parse(method, it);
|
|
10142
11796
|
});
|
|
10143
11797
|
}
|
|
10144
|
-
invoke(method, args = [],
|
|
11798
|
+
async invoke(method, args = [], options = {}) {
|
|
11799
|
+
const { parseRequest = true, signature, waitForTransaction, ...RestInvokeOptions } = options;
|
|
10145
11800
|
assert(this.address !== null, "contract is not connected to an address");
|
|
10146
11801
|
const calldata = getCompiledCalldata(args, () => {
|
|
10147
11802
|
if (parseRequest) {
|
|
@@ -10157,9 +11812,17 @@ var Contract = class _Contract {
|
|
|
10157
11812
|
entrypoint: method
|
|
10158
11813
|
};
|
|
10159
11814
|
if (isAccount(this.providerOrAccount)) {
|
|
10160
|
-
|
|
11815
|
+
const result = await this.providerOrAccount.execute(invocation, {
|
|
10161
11816
|
...RestInvokeOptions
|
|
10162
11817
|
});
|
|
11818
|
+
if (waitForTransaction) {
|
|
11819
|
+
const result2 = await this.providerOrAccount.waitForTransaction(result.transaction_hash);
|
|
11820
|
+
if (result2.isSuccess()) {
|
|
11821
|
+
return result2;
|
|
11822
|
+
}
|
|
11823
|
+
throw new Error("Transaction failed", { cause: result2 });
|
|
11824
|
+
}
|
|
11825
|
+
return result;
|
|
10163
11826
|
}
|
|
10164
11827
|
if (!RestInvokeOptions.nonce)
|
|
10165
11828
|
throw new Error(`Manual nonce is required when invoking a function without an account`);
|
|
@@ -10197,9 +11860,9 @@ var Contract = class _Contract {
|
|
|
10197
11860
|
// TODO: Demistify what is going on here ???
|
|
10198
11861
|
// TODO: receipt status filtering test and fix this do not look right
|
|
10199
11862
|
parseEvents(receipt) {
|
|
10200
|
-
let parsed;
|
|
11863
|
+
let parsed = [];
|
|
10201
11864
|
receipt.match({
|
|
10202
|
-
|
|
11865
|
+
SUCCEEDED: (txR) => {
|
|
10203
11866
|
const emittedEvents = txR.events?.map((event) => {
|
|
10204
11867
|
return {
|
|
10205
11868
|
// TODO: this do not check that block is production and block_hash and block_number actually exists
|
|
@@ -10212,16 +11875,26 @@ var Contract = class _Contract {
|
|
|
10212
11875
|
}).filter((event) => cleanHex(event.from_address) === cleanHex(this.address), []) || [];
|
|
10213
11876
|
parsed = parseEvents(
|
|
10214
11877
|
emittedEvents,
|
|
10215
|
-
// TODO: any temp hotfix, fix this
|
|
10216
11878
|
this.events,
|
|
10217
11879
|
this.structs,
|
|
10218
|
-
CallData.getAbiEnum(this.abi)
|
|
11880
|
+
CallData.getAbiEnum(this.abi),
|
|
11881
|
+
this.callData.parser
|
|
10219
11882
|
);
|
|
10220
11883
|
},
|
|
10221
11884
|
_: () => {
|
|
10222
11885
|
throw Error("This transaction was not successful.");
|
|
10223
11886
|
}
|
|
10224
11887
|
});
|
|
11888
|
+
Object.defineProperty(parsed, "getByPath", {
|
|
11889
|
+
value: (path) => {
|
|
11890
|
+
const event = parsed.find((ev) => Object.keys(ev).some((key) => key.includes(path)));
|
|
11891
|
+
const eventKey = Object.keys(event || {}).find((key) => key.includes(path));
|
|
11892
|
+
return eventKey && event ? event[eventKey] : null;
|
|
11893
|
+
},
|
|
11894
|
+
writable: false,
|
|
11895
|
+
enumerable: false,
|
|
11896
|
+
configurable: false
|
|
11897
|
+
});
|
|
10225
11898
|
return parsed;
|
|
10226
11899
|
}
|
|
10227
11900
|
isCairo1() {
|
|
@@ -10338,7 +12011,10 @@ var Contract = class _Contract {
|
|
|
10338
12011
|
abi,
|
|
10339
12012
|
address: contract_address,
|
|
10340
12013
|
providerOrAccount: account,
|
|
10341
|
-
classHash
|
|
12014
|
+
classHash,
|
|
12015
|
+
parseRequest: params.parseRequest,
|
|
12016
|
+
parseResponse: params.parseResponse,
|
|
12017
|
+
parsingStrategy: params.parsingStrategy
|
|
10342
12018
|
});
|
|
10343
12019
|
}
|
|
10344
12020
|
};
|
|
@@ -10394,19 +12070,33 @@ function units(amount, simbol = "fri") {
|
|
|
10394
12070
|
}
|
|
10395
12071
|
var export_TypedDataRevision = api_exports.TypedDataRevision;
|
|
10396
12072
|
export {
|
|
12073
|
+
AbiParser1,
|
|
12074
|
+
AbiParser2,
|
|
12075
|
+
AbiParserInterface,
|
|
10397
12076
|
Account,
|
|
10398
12077
|
AccountInterface,
|
|
10399
12078
|
BatchClient,
|
|
10400
12079
|
BlockStatus,
|
|
10401
12080
|
BlockTag,
|
|
12081
|
+
CairoByteArray,
|
|
10402
12082
|
CairoCustomEnum,
|
|
10403
12083
|
CairoFixedArray,
|
|
12084
|
+
CairoInt128,
|
|
12085
|
+
CairoInt16,
|
|
12086
|
+
CairoInt32,
|
|
12087
|
+
CairoInt64,
|
|
12088
|
+
CairoInt8,
|
|
10404
12089
|
CairoOption,
|
|
10405
12090
|
CairoOptionVariant,
|
|
10406
12091
|
CairoResult,
|
|
10407
12092
|
CairoResultVariant,
|
|
12093
|
+
CairoUint128,
|
|
12094
|
+
CairoUint16,
|
|
10408
12095
|
CairoUint256,
|
|
10409
12096
|
CairoUint512,
|
|
12097
|
+
CairoUint64,
|
|
12098
|
+
CairoUint8,
|
|
12099
|
+
CairoUint96,
|
|
10410
12100
|
CallData,
|
|
10411
12101
|
Contract,
|
|
10412
12102
|
ContractInterface,
|
|
@@ -10422,6 +12112,7 @@ export {
|
|
|
10422
12112
|
ETransactionVersion3,
|
|
10423
12113
|
EntryPointType,
|
|
10424
12114
|
EthSigner,
|
|
12115
|
+
Int,
|
|
10425
12116
|
LedgerSigner111 as LedgerSigner,
|
|
10426
12117
|
LedgerSigner111,
|
|
10427
12118
|
LedgerSigner221,
|
|
@@ -10475,6 +12166,8 @@ export {
|
|
|
10475
12166
|
config,
|
|
10476
12167
|
constants_exports as constants,
|
|
10477
12168
|
contractClassResponseToLegacyCompiledContract,
|
|
12169
|
+
createAbiParser,
|
|
12170
|
+
createTransactionReceipt,
|
|
10478
12171
|
defaultDeployer,
|
|
10479
12172
|
defaultPaymaster,
|
|
10480
12173
|
defaultProvider,
|
|
@@ -10483,6 +12176,8 @@ export {
|
|
|
10483
12176
|
eth_exports as eth,
|
|
10484
12177
|
events_exports as events,
|
|
10485
12178
|
extractContractHashes,
|
|
12179
|
+
fastParsingStrategy,
|
|
12180
|
+
getAbiVersion,
|
|
10486
12181
|
getChecksumAddress,
|
|
10487
12182
|
getGasPrices,
|
|
10488
12183
|
getLedgerPathBuffer111 as getLedgerPathBuffer,
|
|
@@ -10490,7 +12185,9 @@ export {
|
|
|
10490
12185
|
getLedgerPathBuffer221,
|
|
10491
12186
|
getTipStatsFromBlocks,
|
|
10492
12187
|
hash_exports as hash,
|
|
12188
|
+
hdParsingStrategy,
|
|
10493
12189
|
isAccount,
|
|
12190
|
+
isNoConstructorValid,
|
|
10494
12191
|
isPendingBlock,
|
|
10495
12192
|
isPendingStateUpdate,
|
|
10496
12193
|
isPendingTransaction,
|