starknet 5.9.2 → 5.10.1
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 +20 -0
- package/dist/index.d.ts +92 -71
- package/dist/index.global.js +1872 -1839
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +679 -641
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +671 -633
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -50,55 +50,27 @@ function assert(condition, message) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// src/utils/
|
|
54
|
-
var
|
|
55
|
-
__export(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
keccakBn: () => keccakBn,
|
|
73
|
-
poseidon: () => poseidon,
|
|
74
|
-
starknetKeccak: () => starknetKeccak,
|
|
75
|
-
transactionVersion: () => transactionVersion,
|
|
76
|
-
transactionVersion_2: () => transactionVersion_2
|
|
77
|
-
});
|
|
78
|
-
import { keccak, poseidonHashMany } from "micro-starknet";
|
|
79
|
-
|
|
80
|
-
// src/constants.ts
|
|
81
|
-
var constants_exports = {};
|
|
82
|
-
__export(constants_exports, {
|
|
83
|
-
ALPHA: () => ALPHA,
|
|
84
|
-
API_VERSION: () => API_VERSION,
|
|
85
|
-
BETA: () => BETA,
|
|
86
|
-
BaseUrl: () => BaseUrl,
|
|
87
|
-
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
88
|
-
EC_ORDER: () => EC_ORDER,
|
|
89
|
-
FIELD_GEN: () => FIELD_GEN,
|
|
90
|
-
FIELD_PRIME: () => FIELD_PRIME,
|
|
91
|
-
FIELD_SIZE: () => FIELD_SIZE,
|
|
92
|
-
IS_BROWSER: () => IS_BROWSER,
|
|
93
|
-
MASK_250: () => MASK_250,
|
|
94
|
-
MASK_251: () => MASK_251,
|
|
95
|
-
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
96
|
-
NetworkName: () => NetworkName,
|
|
97
|
-
StarknetChainId: () => StarknetChainId,
|
|
98
|
-
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
99
|
-
UDC: () => UDC,
|
|
100
|
-
ZERO: () => ZERO
|
|
53
|
+
// src/utils/num.ts
|
|
54
|
+
var num_exports = {};
|
|
55
|
+
__export(num_exports, {
|
|
56
|
+
assertInRange: () => assertInRange,
|
|
57
|
+
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
58
|
+
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
59
|
+
cleanHex: () => cleanHex,
|
|
60
|
+
getDecimalString: () => getDecimalString,
|
|
61
|
+
getHexString: () => getHexString,
|
|
62
|
+
getHexStringArray: () => getHexStringArray,
|
|
63
|
+
hexToBytes: () => hexToBytes,
|
|
64
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
65
|
+
isBigInt: () => isBigInt,
|
|
66
|
+
isHex: () => isHex,
|
|
67
|
+
isStringWholeNumber: () => isStringWholeNumber,
|
|
68
|
+
toBigInt: () => toBigInt,
|
|
69
|
+
toCairoBool: () => toCairoBool,
|
|
70
|
+
toHex: () => toHex,
|
|
71
|
+
toHexString: () => toHexString
|
|
101
72
|
});
|
|
73
|
+
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
102
74
|
|
|
103
75
|
// src/utils/encode.ts
|
|
104
76
|
var encode_exports = {};
|
|
@@ -163,7 +135,98 @@ function utf8ToArray(str) {
|
|
|
163
135
|
return new TextEncoder().encode(str);
|
|
164
136
|
}
|
|
165
137
|
|
|
138
|
+
// src/utils/num.ts
|
|
139
|
+
function isHex(hex) {
|
|
140
|
+
return /^0x[0-9a-f]*$/i.test(hex);
|
|
141
|
+
}
|
|
142
|
+
function toBigInt(value) {
|
|
143
|
+
return BigInt(value);
|
|
144
|
+
}
|
|
145
|
+
function isBigInt(value) {
|
|
146
|
+
return typeof value === "bigint";
|
|
147
|
+
}
|
|
148
|
+
function toHex(number2) {
|
|
149
|
+
return addHexPrefix(toBigInt(number2).toString(16));
|
|
150
|
+
}
|
|
151
|
+
function hexToDecimalString(hex) {
|
|
152
|
+
return BigInt(addHexPrefix(hex)).toString(10);
|
|
153
|
+
}
|
|
154
|
+
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
155
|
+
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
156
|
+
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
157
|
+
const inputBigInt = BigInt(input);
|
|
158
|
+
const lowerBoundBigInt = BigInt(lowerBound);
|
|
159
|
+
const upperBoundBigInt = BigInt(upperBound);
|
|
160
|
+
assert(
|
|
161
|
+
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
162
|
+
`Message not signable, ${messageSuffix}.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
166
|
+
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
167
|
+
}
|
|
168
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
169
|
+
return rawCalldata.map((x) => toHex(x));
|
|
170
|
+
}
|
|
171
|
+
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
172
|
+
var toHexString = (value) => toHex(value);
|
|
173
|
+
function getDecimalString(value) {
|
|
174
|
+
if (isHex(value)) {
|
|
175
|
+
return hexToDecimalString(value);
|
|
176
|
+
}
|
|
177
|
+
if (isStringWholeNumber(value)) {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
181
|
+
}
|
|
182
|
+
function getHexString(value) {
|
|
183
|
+
if (isHex(value)) {
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
if (isStringWholeNumber(value)) {
|
|
187
|
+
return toHexString(value);
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
190
|
+
}
|
|
191
|
+
function getHexStringArray(value) {
|
|
192
|
+
return value.map((el) => getHexString(el));
|
|
193
|
+
}
|
|
194
|
+
var toCairoBool = (value) => (+value).toString();
|
|
195
|
+
function hexToBytes(value) {
|
|
196
|
+
if (!isHex(value))
|
|
197
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
198
|
+
let adaptedValue = removeHexPrefix(value);
|
|
199
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
200
|
+
adaptedValue = `0${adaptedValue}`;
|
|
201
|
+
}
|
|
202
|
+
return hexToBytesNoble(adaptedValue);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/utils/selector.ts
|
|
206
|
+
import { keccak } from "micro-starknet";
|
|
207
|
+
|
|
166
208
|
// src/constants.ts
|
|
209
|
+
var constants_exports = {};
|
|
210
|
+
__export(constants_exports, {
|
|
211
|
+
ALPHA: () => ALPHA,
|
|
212
|
+
API_VERSION: () => API_VERSION,
|
|
213
|
+
BETA: () => BETA,
|
|
214
|
+
BaseUrl: () => BaseUrl,
|
|
215
|
+
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
216
|
+
EC_ORDER: () => EC_ORDER,
|
|
217
|
+
FIELD_GEN: () => FIELD_GEN,
|
|
218
|
+
FIELD_PRIME: () => FIELD_PRIME,
|
|
219
|
+
FIELD_SIZE: () => FIELD_SIZE,
|
|
220
|
+
IS_BROWSER: () => IS_BROWSER,
|
|
221
|
+
MASK_250: () => MASK_250,
|
|
222
|
+
MASK_251: () => MASK_251,
|
|
223
|
+
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
224
|
+
NetworkName: () => NetworkName,
|
|
225
|
+
StarknetChainId: () => StarknetChainId,
|
|
226
|
+
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
227
|
+
UDC: () => UDC,
|
|
228
|
+
ZERO: () => ZERO
|
|
229
|
+
});
|
|
167
230
|
var ZERO = 0n;
|
|
168
231
|
var MASK_250 = 2n ** 250n - 1n;
|
|
169
232
|
var MASK_251 = 2n ** 251n;
|
|
@@ -2232,6 +2295,83 @@ var CONSTANT_POINTS = [
|
|
|
2232
2295
|
]
|
|
2233
2296
|
];
|
|
2234
2297
|
|
|
2298
|
+
// src/utils/selector.ts
|
|
2299
|
+
function keccakBn(value) {
|
|
2300
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2301
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2302
|
+
return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2303
|
+
}
|
|
2304
|
+
function keccakHex(value) {
|
|
2305
|
+
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
2306
|
+
}
|
|
2307
|
+
function starknetKeccak(value) {
|
|
2308
|
+
const hash = BigInt(keccakHex(value));
|
|
2309
|
+
return hash & MASK_250;
|
|
2310
|
+
}
|
|
2311
|
+
function getSelectorFromName(funcName) {
|
|
2312
|
+
return toHex(starknetKeccak(funcName));
|
|
2313
|
+
}
|
|
2314
|
+
function getSelector(value) {
|
|
2315
|
+
if (isHex(value)) {
|
|
2316
|
+
return value;
|
|
2317
|
+
}
|
|
2318
|
+
if (isStringWholeNumber(value)) {
|
|
2319
|
+
return toHexString(value);
|
|
2320
|
+
}
|
|
2321
|
+
return getSelectorFromName(value);
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
// src/utils/shortString.ts
|
|
2325
|
+
var shortString_exports = {};
|
|
2326
|
+
__export(shortString_exports, {
|
|
2327
|
+
decodeShortString: () => decodeShortString,
|
|
2328
|
+
encodeShortString: () => encodeShortString,
|
|
2329
|
+
isASCII: () => isASCII,
|
|
2330
|
+
isDecimalString: () => isDecimalString,
|
|
2331
|
+
isLongText: () => isLongText,
|
|
2332
|
+
isShortString: () => isShortString,
|
|
2333
|
+
isShortText: () => isShortText,
|
|
2334
|
+
isText: () => isText,
|
|
2335
|
+
splitLongString: () => splitLongString
|
|
2336
|
+
});
|
|
2337
|
+
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
2338
|
+
function isASCII(str) {
|
|
2339
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
2340
|
+
}
|
|
2341
|
+
function isShortString(str) {
|
|
2342
|
+
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
2343
|
+
}
|
|
2344
|
+
function isDecimalString(decim) {
|
|
2345
|
+
return /^[0-9]*$/i.test(decim);
|
|
2346
|
+
}
|
|
2347
|
+
function isText(val) {
|
|
2348
|
+
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
2349
|
+
}
|
|
2350
|
+
var isShortText = (val) => isText(val) && isShortString(val);
|
|
2351
|
+
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
2352
|
+
function splitLongString(longStr) {
|
|
2353
|
+
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
2354
|
+
return longStr.match(regex) || [];
|
|
2355
|
+
}
|
|
2356
|
+
function encodeShortString(str) {
|
|
2357
|
+
if (!isASCII(str))
|
|
2358
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
2359
|
+
if (!isShortString(str))
|
|
2360
|
+
throw new Error(`${str} is too long`);
|
|
2361
|
+
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
2362
|
+
}
|
|
2363
|
+
function decodeShortString(str) {
|
|
2364
|
+
if (!isASCII(str))
|
|
2365
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
2366
|
+
if (isHex(str)) {
|
|
2367
|
+
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
2368
|
+
}
|
|
2369
|
+
if (isDecimalString(str)) {
|
|
2370
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
2371
|
+
}
|
|
2372
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2235
2375
|
// src/utils/calldata/cairo.ts
|
|
2236
2376
|
var cairo_exports = {};
|
|
2237
2377
|
__export(cairo_exports, {
|
|
@@ -2253,144 +2393,6 @@ __export(cairo_exports, {
|
|
|
2253
2393
|
uint256: () => uint256
|
|
2254
2394
|
});
|
|
2255
2395
|
|
|
2256
|
-
// src/utils/num.ts
|
|
2257
|
-
var num_exports = {};
|
|
2258
|
-
__export(num_exports, {
|
|
2259
|
-
assertInRange: () => assertInRange,
|
|
2260
|
-
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
2261
|
-
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
2262
|
-
cleanHex: () => cleanHex,
|
|
2263
|
-
getDecimalString: () => getDecimalString,
|
|
2264
|
-
getHexString: () => getHexString,
|
|
2265
|
-
getHexStringArray: () => getHexStringArray,
|
|
2266
|
-
hexToBytes: () => hexToBytes,
|
|
2267
|
-
hexToDecimalString: () => hexToDecimalString,
|
|
2268
|
-
isBigInt: () => isBigInt,
|
|
2269
|
-
isHex: () => isHex,
|
|
2270
|
-
isStringWholeNumber: () => isStringWholeNumber,
|
|
2271
|
-
toBigInt: () => toBigInt,
|
|
2272
|
-
toCairoBool: () => toCairoBool,
|
|
2273
|
-
toHex: () => toHex,
|
|
2274
|
-
toHexString: () => toHexString
|
|
2275
|
-
});
|
|
2276
|
-
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
2277
|
-
function isHex(hex) {
|
|
2278
|
-
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2279
|
-
}
|
|
2280
|
-
function toBigInt(value) {
|
|
2281
|
-
return BigInt(value);
|
|
2282
|
-
}
|
|
2283
|
-
function isBigInt(value) {
|
|
2284
|
-
return typeof value === "bigint";
|
|
2285
|
-
}
|
|
2286
|
-
function toHex(number2) {
|
|
2287
|
-
return addHexPrefix(toBigInt(number2).toString(16));
|
|
2288
|
-
}
|
|
2289
|
-
function hexToDecimalString(hex) {
|
|
2290
|
-
return BigInt(addHexPrefix(hex)).toString(10);
|
|
2291
|
-
}
|
|
2292
|
-
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
2293
|
-
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
2294
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
2295
|
-
const inputBigInt = BigInt(input);
|
|
2296
|
-
const lowerBoundBigInt = BigInt(lowerBound);
|
|
2297
|
-
const upperBoundBigInt = BigInt(upperBound);
|
|
2298
|
-
assert(
|
|
2299
|
-
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
2300
|
-
`Message not signable, ${messageSuffix}.`
|
|
2301
|
-
);
|
|
2302
|
-
}
|
|
2303
|
-
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
2304
|
-
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
2305
|
-
}
|
|
2306
|
-
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
2307
|
-
return rawCalldata.map((x) => toHex(x));
|
|
2308
|
-
}
|
|
2309
|
-
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
2310
|
-
var toHexString = (value) => toHex(value);
|
|
2311
|
-
function getDecimalString(value) {
|
|
2312
|
-
if (isHex(value)) {
|
|
2313
|
-
return hexToDecimalString(value);
|
|
2314
|
-
}
|
|
2315
|
-
if (isStringWholeNumber(value)) {
|
|
2316
|
-
return value;
|
|
2317
|
-
}
|
|
2318
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2319
|
-
}
|
|
2320
|
-
function getHexString(value) {
|
|
2321
|
-
if (isHex(value)) {
|
|
2322
|
-
return value;
|
|
2323
|
-
}
|
|
2324
|
-
if (isStringWholeNumber(value)) {
|
|
2325
|
-
return toHexString(value);
|
|
2326
|
-
}
|
|
2327
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2328
|
-
}
|
|
2329
|
-
function getHexStringArray(value) {
|
|
2330
|
-
return value.map((el) => getHexString(el));
|
|
2331
|
-
}
|
|
2332
|
-
var toCairoBool = (value) => (+value).toString();
|
|
2333
|
-
function hexToBytes(value) {
|
|
2334
|
-
if (!isHex(value))
|
|
2335
|
-
throw new Error(`${value} need to be a hex-string`);
|
|
2336
|
-
let adaptedValue = removeHexPrefix(value);
|
|
2337
|
-
if (adaptedValue.length % 2 !== 0) {
|
|
2338
|
-
adaptedValue = `0${adaptedValue}`;
|
|
2339
|
-
}
|
|
2340
|
-
return hexToBytesNoble(adaptedValue);
|
|
2341
|
-
}
|
|
2342
|
-
|
|
2343
|
-
// src/utils/shortString.ts
|
|
2344
|
-
var shortString_exports = {};
|
|
2345
|
-
__export(shortString_exports, {
|
|
2346
|
-
decodeShortString: () => decodeShortString,
|
|
2347
|
-
encodeShortString: () => encodeShortString,
|
|
2348
|
-
isASCII: () => isASCII,
|
|
2349
|
-
isDecimalString: () => isDecimalString,
|
|
2350
|
-
isLongText: () => isLongText,
|
|
2351
|
-
isShortString: () => isShortString,
|
|
2352
|
-
isShortText: () => isShortText,
|
|
2353
|
-
isText: () => isText,
|
|
2354
|
-
splitLongString: () => splitLongString
|
|
2355
|
-
});
|
|
2356
|
-
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
2357
|
-
function isASCII(str) {
|
|
2358
|
-
return /^[\x00-\x7F]*$/.test(str);
|
|
2359
|
-
}
|
|
2360
|
-
function isShortString(str) {
|
|
2361
|
-
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
2362
|
-
}
|
|
2363
|
-
function isDecimalString(decim) {
|
|
2364
|
-
return /^[0-9]*$/i.test(decim);
|
|
2365
|
-
}
|
|
2366
|
-
function isText(val) {
|
|
2367
|
-
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
2368
|
-
}
|
|
2369
|
-
var isShortText = (val) => isText(val) && isShortString(val);
|
|
2370
|
-
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
2371
|
-
function splitLongString(longStr) {
|
|
2372
|
-
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
2373
|
-
return longStr.match(regex) || [];
|
|
2374
|
-
}
|
|
2375
|
-
function encodeShortString(str) {
|
|
2376
|
-
if (!isASCII(str))
|
|
2377
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
2378
|
-
if (!isShortString(str))
|
|
2379
|
-
throw new Error(`${str} is too long`);
|
|
2380
|
-
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
2381
|
-
}
|
|
2382
|
-
function decodeShortString(str) {
|
|
2383
|
-
if (!isASCII(str))
|
|
2384
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
2385
|
-
if (isHex(str)) {
|
|
2386
|
-
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
2387
|
-
}
|
|
2388
|
-
if (isDecimalString(str)) {
|
|
2389
|
-
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
2390
|
-
}
|
|
2391
|
-
throw new Error(`${str} is not Hex or decimal`);
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
2396
|
// src/utils/uint256.ts
|
|
2395
2397
|
var uint256_exports = {};
|
|
2396
2398
|
__export(uint256_exports, {
|
|
@@ -2430,7 +2432,7 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
|
|
|
2430
2432
|
})(Uint || {});
|
|
2431
2433
|
var isLen = (name) => /_len$/.test(name);
|
|
2432
2434
|
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
2433
|
-
var isTypeArray = (type) => /\*/.test(type) || type.
|
|
2435
|
+
var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::");
|
|
2434
2436
|
var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
|
|
2435
2437
|
var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
|
|
2436
2438
|
var isTypeStruct = (type, structs) => type in structs;
|
|
@@ -2441,7 +2443,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
|
|
|
2441
2443
|
var isCairo1Type = (type) => type.includes("core::");
|
|
2442
2444
|
var getArrayType = (type) => {
|
|
2443
2445
|
if (isCairo1Type(type)) {
|
|
2444
|
-
return type.substring(type.indexOf("<") + 1, type.
|
|
2446
|
+
return type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
|
|
2445
2447
|
}
|
|
2446
2448
|
return type.replace("*", "");
|
|
2447
2449
|
};
|
|
@@ -2470,271 +2472,13 @@ function felt(it) {
|
|
|
2470
2472
|
if (typeof it === "string" && isHex(it)) {
|
|
2471
2473
|
return BigInt(it).toString();
|
|
2472
2474
|
}
|
|
2473
|
-
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2474
|
-
return it;
|
|
2475
|
-
}
|
|
2476
|
-
if (typeof it === "boolean") {
|
|
2477
|
-
return `${+it}`;
|
|
2478
|
-
}
|
|
2479
|
-
throw new Error(`${it} can't be computed by felt()`);
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
// src/utils/ec.ts
|
|
2483
|
-
var ec_exports = {};
|
|
2484
|
-
__export(ec_exports, {
|
|
2485
|
-
starkCurve: () => starkCurve,
|
|
2486
|
-
weierstrass: () => weierstrass
|
|
2487
|
-
});
|
|
2488
|
-
import * as starkCurve from "micro-starknet";
|
|
2489
|
-
import * as weierstrass from "@noble/curves/abstract/weierstrass";
|
|
2490
|
-
|
|
2491
|
-
// src/utils/json.ts
|
|
2492
|
-
var json_exports = {};
|
|
2493
|
-
__export(json_exports, {
|
|
2494
|
-
parse: () => parse2,
|
|
2495
|
-
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
2496
|
-
stringify: () => stringify2,
|
|
2497
|
-
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
2498
|
-
});
|
|
2499
|
-
import * as json from "lossless-json";
|
|
2500
|
-
var parseIntAsNumberOrBigInt = (x) => {
|
|
2501
|
-
if (!json.isInteger(x))
|
|
2502
|
-
return parseFloat(x);
|
|
2503
|
-
const v = parseInt(x, 10);
|
|
2504
|
-
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
2505
|
-
};
|
|
2506
|
-
var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
2507
|
-
var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
|
|
2508
|
-
var stringify2 = (...p) => json.stringify(...p);
|
|
2509
|
-
var stringifyAlwaysAsBig = stringify2;
|
|
2510
|
-
|
|
2511
|
-
// src/utils/hash.ts
|
|
2512
|
-
import * as poseidon from "@noble/curves/abstract/poseidon";
|
|
2513
|
-
var transactionVersion = 1n;
|
|
2514
|
-
var transactionVersion_2 = 2n;
|
|
2515
|
-
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
2516
|
-
function keccakBn(value) {
|
|
2517
|
-
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2518
|
-
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2519
|
-
return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2520
|
-
}
|
|
2521
|
-
function keccakHex(value) {
|
|
2522
|
-
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
2523
|
-
}
|
|
2524
|
-
function starknetKeccak(value) {
|
|
2525
|
-
const hash = BigInt(keccakHex(value));
|
|
2526
|
-
return hash & MASK_250;
|
|
2527
|
-
}
|
|
2528
|
-
function getSelectorFromName(funcName) {
|
|
2529
|
-
return toHex(starknetKeccak(funcName));
|
|
2530
|
-
}
|
|
2531
|
-
function getSelector(value) {
|
|
2532
|
-
if (isHex(value)) {
|
|
2533
|
-
return value;
|
|
2534
|
-
}
|
|
2535
|
-
if (isStringWholeNumber(value)) {
|
|
2536
|
-
return toHexString(value);
|
|
2537
|
-
}
|
|
2538
|
-
return getSelectorFromName(value);
|
|
2539
|
-
}
|
|
2540
|
-
function computeHashOnElements(data) {
|
|
2541
|
-
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
2542
|
-
}
|
|
2543
|
-
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
2544
|
-
const calldataHash = computeHashOnElements(calldata);
|
|
2545
|
-
const dataToHash = [
|
|
2546
|
-
txHashPrefix,
|
|
2547
|
-
version,
|
|
2548
|
-
contractAddress,
|
|
2549
|
-
entryPointSelector,
|
|
2550
|
-
calldataHash,
|
|
2551
|
-
maxFee,
|
|
2552
|
-
chainId,
|
|
2553
|
-
...additionalData
|
|
2554
|
-
];
|
|
2555
|
-
return computeHashOnElements(dataToHash);
|
|
2556
|
-
}
|
|
2557
|
-
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
2558
|
-
return calculateTransactionHashCommon(
|
|
2559
|
-
"0x6465706c6f79" /* DEPLOY */,
|
|
2560
|
-
version,
|
|
2561
|
-
contractAddress,
|
|
2562
|
-
getSelectorFromName("constructor"),
|
|
2563
|
-
constructorCalldata,
|
|
2564
|
-
0,
|
|
2565
|
-
chainId
|
|
2566
|
-
);
|
|
2567
|
-
}
|
|
2568
|
-
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
2569
|
-
return calculateTransactionHashCommon(
|
|
2570
|
-
"0x6465636c617265" /* DECLARE */,
|
|
2571
|
-
version,
|
|
2572
|
-
senderAddress,
|
|
2573
|
-
0,
|
|
2574
|
-
[classHash],
|
|
2575
|
-
maxFee,
|
|
2576
|
-
chainId,
|
|
2577
|
-
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
2578
|
-
);
|
|
2579
|
-
}
|
|
2580
|
-
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
2581
|
-
const calldata = [classHash, salt, ...constructorCalldata];
|
|
2582
|
-
return calculateTransactionHashCommon(
|
|
2583
|
-
"0x6465706c6f795f6163636f756e74" /* DEPLOY_ACCOUNT */,
|
|
2584
|
-
version,
|
|
2585
|
-
contractAddress,
|
|
2586
|
-
0,
|
|
2587
|
-
calldata,
|
|
2588
|
-
maxFee,
|
|
2589
|
-
chainId,
|
|
2590
|
-
[nonce]
|
|
2591
|
-
);
|
|
2592
|
-
}
|
|
2593
|
-
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
2594
|
-
return calculateTransactionHashCommon(
|
|
2595
|
-
"0x696e766f6b65" /* INVOKE */,
|
|
2596
|
-
version,
|
|
2597
|
-
contractAddress,
|
|
2598
|
-
0,
|
|
2599
|
-
calldata,
|
|
2600
|
-
maxFee,
|
|
2601
|
-
chainId,
|
|
2602
|
-
[nonce]
|
|
2603
|
-
);
|
|
2604
|
-
}
|
|
2605
|
-
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
2606
|
-
const constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
2607
|
-
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
2608
|
-
return computeHashOnElements([
|
|
2609
|
-
CONTRACT_ADDRESS_PREFIX,
|
|
2610
|
-
deployerAddress,
|
|
2611
|
-
salt,
|
|
2612
|
-
classHash,
|
|
2613
|
-
constructorCalldataHash
|
|
2614
|
-
]);
|
|
2615
|
-
}
|
|
2616
|
-
function nullSkipReplacer(key, value) {
|
|
2617
|
-
if (key === "attributes" || key === "accessible_scopes") {
|
|
2618
|
-
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
2619
|
-
}
|
|
2620
|
-
if (key === "debug_info") {
|
|
2621
|
-
return null;
|
|
2622
|
-
}
|
|
2623
|
-
return value === null ? void 0 : value;
|
|
2624
|
-
}
|
|
2625
|
-
function formatSpaces(json2) {
|
|
2626
|
-
let insideQuotes = false;
|
|
2627
|
-
let newString = "";
|
|
2628
|
-
for (const char of json2) {
|
|
2629
|
-
if (char === '"' && newString.endsWith("\\") === false) {
|
|
2630
|
-
insideQuotes = !insideQuotes;
|
|
2631
|
-
}
|
|
2632
|
-
if (insideQuotes) {
|
|
2633
|
-
newString += char;
|
|
2634
|
-
} else {
|
|
2635
|
-
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
return newString;
|
|
2639
|
-
}
|
|
2640
|
-
function computeHintedClassHash(compiledContract) {
|
|
2641
|
-
const { abi, program } = compiledContract;
|
|
2642
|
-
const contractClass = { abi, program };
|
|
2643
|
-
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
2644
|
-
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2645
|
-
}
|
|
2646
|
-
function computeLegacyContractClassHash(contract) {
|
|
2647
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2648
|
-
const apiVersion = toHex(API_VERSION);
|
|
2649
|
-
const externalEntryPointsHash = computeHashOnElements(
|
|
2650
|
-
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
2651
|
-
);
|
|
2652
|
-
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
2653
|
-
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
2654
|
-
);
|
|
2655
|
-
const constructorEntryPointHash = computeHashOnElements(
|
|
2656
|
-
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
2657
|
-
);
|
|
2658
|
-
const builtinsHash = computeHashOnElements(
|
|
2659
|
-
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
2660
|
-
);
|
|
2661
|
-
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
2662
|
-
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
2663
|
-
return computeHashOnElements([
|
|
2664
|
-
apiVersion,
|
|
2665
|
-
externalEntryPointsHash,
|
|
2666
|
-
l1HandlerEntryPointsHash,
|
|
2667
|
-
constructorEntryPointHash,
|
|
2668
|
-
builtinsHash,
|
|
2669
|
-
hintedClassHash,
|
|
2670
|
-
dataHash
|
|
2671
|
-
]);
|
|
2672
|
-
}
|
|
2673
|
-
function hashBuiltins(builtins) {
|
|
2674
|
-
return poseidonHashMany(
|
|
2675
|
-
builtins.flatMap((it) => {
|
|
2676
|
-
return BigInt(encodeShortString(it));
|
|
2677
|
-
})
|
|
2678
|
-
);
|
|
2679
|
-
}
|
|
2680
|
-
function hashEntryPoint(data) {
|
|
2681
|
-
const base = data.flatMap((it) => {
|
|
2682
|
-
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
2683
|
-
});
|
|
2684
|
-
return poseidonHashMany(base);
|
|
2685
|
-
}
|
|
2686
|
-
function computeCompiledClassHash(casm) {
|
|
2687
|
-
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
2688
|
-
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
2689
|
-
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
2690
|
-
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
2691
|
-
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
2692
|
-
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
2693
|
-
return toHex(
|
|
2694
|
-
poseidonHashMany([
|
|
2695
|
-
compiledClassVersion,
|
|
2696
|
-
externalEntryPointsHash,
|
|
2697
|
-
l1Handlers,
|
|
2698
|
-
constructor,
|
|
2699
|
-
bytecode
|
|
2700
|
-
])
|
|
2701
|
-
);
|
|
2702
|
-
}
|
|
2703
|
-
function hashEntryPointSierra(data) {
|
|
2704
|
-
const base = data.flatMap((it) => {
|
|
2705
|
-
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
2706
|
-
});
|
|
2707
|
-
return poseidonHashMany(base);
|
|
2708
|
-
}
|
|
2709
|
-
function hashAbi(sierra) {
|
|
2710
|
-
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
2711
|
-
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
2712
|
-
}
|
|
2713
|
-
function computeSierraContractClassHash(sierra) {
|
|
2714
|
-
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
2715
|
-
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
2716
|
-
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
2717
|
-
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
2718
|
-
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
2719
|
-
const abiHash = hashAbi(sierra);
|
|
2720
|
-
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
2721
|
-
return toHex(
|
|
2722
|
-
poseidonHashMany([
|
|
2723
|
-
compiledClassVersion,
|
|
2724
|
-
externalEntryPointsHash,
|
|
2725
|
-
l1Handlers,
|
|
2726
|
-
constructor,
|
|
2727
|
-
abiHash,
|
|
2728
|
-
sierraProgram
|
|
2729
|
-
])
|
|
2730
|
-
);
|
|
2731
|
-
}
|
|
2732
|
-
function computeContractClassHash(contract) {
|
|
2733
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2734
|
-
if ("sierra_program" in compiledContract) {
|
|
2735
|
-
return computeSierraContractClassHash(compiledContract);
|
|
2736
|
-
}
|
|
2737
|
-
return computeLegacyContractClassHash(compiledContract);
|
|
2475
|
+
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2476
|
+
return it;
|
|
2477
|
+
}
|
|
2478
|
+
if (typeof it === "boolean") {
|
|
2479
|
+
return `${+it}`;
|
|
2480
|
+
}
|
|
2481
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
2738
2482
|
}
|
|
2739
2483
|
|
|
2740
2484
|
// src/utils/calldata/formatter.ts
|
|
@@ -2885,7 +2629,12 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2885
2629
|
throw Error(`Missing parameter for type ${type}`);
|
|
2886
2630
|
}
|
|
2887
2631
|
if (Array.isArray(element)) {
|
|
2888
|
-
|
|
2632
|
+
const result = [];
|
|
2633
|
+
result.push(felt(element.length));
|
|
2634
|
+
const arrayType = getArrayType(type);
|
|
2635
|
+
return element.reduce((acc, it) => {
|
|
2636
|
+
return acc.concat(parseCalldataValue(it, arrayType, structs));
|
|
2637
|
+
}, result);
|
|
2889
2638
|
}
|
|
2890
2639
|
if (structs[type] && structs[type].members.length) {
|
|
2891
2640
|
const { members } = structs[type];
|
|
@@ -2917,17 +2666,7 @@ function parseCalldataField(argsIterator, input, structs) {
|
|
|
2917
2666
|
if (typeof value === "string") {
|
|
2918
2667
|
value = splitLongString(value);
|
|
2919
2668
|
}
|
|
2920
|
-
|
|
2921
|
-
result.push(felt(value.length));
|
|
2922
|
-
const arrayType = getArrayType(input.type);
|
|
2923
|
-
return value.reduce((acc, el) => {
|
|
2924
|
-
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
2925
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
2926
|
-
} else {
|
|
2927
|
-
return acc.concat(parseBaseTypes(arrayType, el));
|
|
2928
|
-
}
|
|
2929
|
-
return acc;
|
|
2930
|
-
}, result);
|
|
2669
|
+
return parseCalldataValue(value, input.type, structs);
|
|
2931
2670
|
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
2932
2671
|
return parseCalldataValue(value, type, structs);
|
|
2933
2672
|
case isTypeUint256(type):
|
|
@@ -2957,23 +2696,33 @@ function parseBaseTypes2(type, it) {
|
|
|
2957
2696
|
return BigInt(temp);
|
|
2958
2697
|
}
|
|
2959
2698
|
}
|
|
2960
|
-
function
|
|
2961
|
-
if (type in structs && structs[type]) {
|
|
2962
|
-
return structs[type].members.reduce((acc, el) => {
|
|
2963
|
-
acc[el.name] =
|
|
2699
|
+
function parseResponseValue(responseIterator, element, structs) {
|
|
2700
|
+
if (element.type in structs && structs[element.type]) {
|
|
2701
|
+
return structs[element.type].members.reduce((acc, el) => {
|
|
2702
|
+
acc[el.name] = parseResponseValue(responseIterator, el, structs);
|
|
2964
2703
|
return acc;
|
|
2965
2704
|
}, {});
|
|
2966
2705
|
}
|
|
2967
|
-
if (isTypeTuple(type)) {
|
|
2968
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
2706
|
+
if (isTypeTuple(element.type)) {
|
|
2707
|
+
const memberTypes = extractTupleMemberTypes(element.type);
|
|
2969
2708
|
return memberTypes.reduce((acc, it, idx) => {
|
|
2970
|
-
const
|
|
2971
|
-
const
|
|
2972
|
-
|
|
2709
|
+
const name = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
2710
|
+
const type = (it == null ? void 0 : it.type) ? it.type : it;
|
|
2711
|
+
const el = { name, type };
|
|
2712
|
+
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
2973
2713
|
return acc;
|
|
2974
2714
|
}, {});
|
|
2975
2715
|
}
|
|
2976
|
-
|
|
2716
|
+
if (isTypeArray(element.type)) {
|
|
2717
|
+
const parsedDataArr = [];
|
|
2718
|
+
const el = { name: "", type: getArrayType(element.type) };
|
|
2719
|
+
const len = BigInt(responseIterator.next().value);
|
|
2720
|
+
while (parsedDataArr.length < len) {
|
|
2721
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, structs));
|
|
2722
|
+
}
|
|
2723
|
+
return parsedDataArr;
|
|
2724
|
+
}
|
|
2725
|
+
return parseBaseTypes2(element.type, responseIterator);
|
|
2977
2726
|
}
|
|
2978
2727
|
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
2979
2728
|
const { name, type } = output;
|
|
@@ -2982,27 +2731,26 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
2982
2731
|
case isLen(name):
|
|
2983
2732
|
temp = responseIterator.next().value;
|
|
2984
2733
|
return BigInt(temp);
|
|
2734
|
+
case (type in structs || isTypeTuple(type)):
|
|
2735
|
+
return parseResponseValue(responseIterator, output, structs);
|
|
2985
2736
|
case isTypeArray(type):
|
|
2986
|
-
const parsedDataArr = [];
|
|
2987
2737
|
if (isCairo1Type(type)) {
|
|
2988
|
-
|
|
2989
|
-
const len = BigInt(responseIterator.next().value);
|
|
2990
|
-
while (parsedDataArr.length < len) {
|
|
2991
|
-
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
2992
|
-
}
|
|
2993
|
-
return parsedDataArr;
|
|
2738
|
+
return parseResponseValue(responseIterator, output, structs);
|
|
2994
2739
|
}
|
|
2740
|
+
const parsedDataArr = [];
|
|
2995
2741
|
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
2996
2742
|
const arrLen = parsedResult[`${name}_len`];
|
|
2997
2743
|
while (parsedDataArr.length < arrLen) {
|
|
2998
2744
|
parsedDataArr.push(
|
|
2999
|
-
|
|
2745
|
+
parseResponseValue(
|
|
2746
|
+
responseIterator,
|
|
2747
|
+
{ name, type: output.type.replace("*", "") },
|
|
2748
|
+
structs
|
|
2749
|
+
)
|
|
3000
2750
|
);
|
|
3001
2751
|
}
|
|
3002
2752
|
}
|
|
3003
2753
|
return parsedDataArr;
|
|
3004
|
-
case (type in structs || isTypeTuple(type)):
|
|
3005
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
3006
2754
|
default:
|
|
3007
2755
|
return parseBaseTypes2(type, responseIterator);
|
|
3008
2756
|
}
|
|
@@ -3115,6 +2863,11 @@ var validateArray = (parameter, input, structs) => {
|
|
|
3115
2863
|
case isTypeBool(baseType):
|
|
3116
2864
|
parameter.forEach((param) => validateBool(param, input));
|
|
3117
2865
|
break;
|
|
2866
|
+
case isTypeArray(baseType):
|
|
2867
|
+
parameter.forEach(
|
|
2868
|
+
(param) => validateArray(param, { name: "", type: baseType }, structs)
|
|
2869
|
+
);
|
|
2870
|
+
break;
|
|
3118
2871
|
default:
|
|
3119
2872
|
throw new Error(
|
|
3120
2873
|
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
@@ -3155,120 +2908,382 @@ function validateFields(abiMethod, args, structs) {
|
|
|
3155
2908
|
return acc + 1;
|
|
3156
2909
|
}, 0);
|
|
3157
2910
|
}
|
|
3158
|
-
|
|
3159
|
-
// src/utils/calldata/index.ts
|
|
3160
|
-
var CallData = class {
|
|
3161
|
-
constructor(abi) {
|
|
3162
|
-
this.abi = abi;
|
|
3163
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
3164
|
-
}
|
|
3165
|
-
validate(type, method, args = []) {
|
|
3166
|
-
if (type !== "DEPLOY") {
|
|
3167
|
-
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3168
|
-
if (abi.type !== "function")
|
|
3169
|
-
return false;
|
|
3170
|
-
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3171
|
-
return type === "INVOKE" ? !isView : isView;
|
|
3172
|
-
}).map((abi) => abi.name);
|
|
3173
|
-
assert(
|
|
3174
|
-
invocableFunctionNames.includes(method),
|
|
3175
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3176
|
-
);
|
|
3177
|
-
}
|
|
3178
|
-
const abiMethod = this.abi.find(
|
|
3179
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3180
|
-
);
|
|
3181
|
-
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3182
|
-
if (args.length !== inputsLength) {
|
|
3183
|
-
throw Error(
|
|
3184
|
-
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3185
|
-
);
|
|
3186
|
-
}
|
|
3187
|
-
validateFields(abiMethod, args, this.structs);
|
|
2911
|
+
|
|
2912
|
+
// src/utils/calldata/index.ts
|
|
2913
|
+
var CallData = class {
|
|
2914
|
+
constructor(abi) {
|
|
2915
|
+
this.abi = abi;
|
|
2916
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
2917
|
+
}
|
|
2918
|
+
validate(type, method, args = []) {
|
|
2919
|
+
if (type !== "DEPLOY") {
|
|
2920
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
2921
|
+
if (abi.type !== "function")
|
|
2922
|
+
return false;
|
|
2923
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
2924
|
+
return type === "INVOKE" ? !isView : isView;
|
|
2925
|
+
}).map((abi) => abi.name);
|
|
2926
|
+
assert(
|
|
2927
|
+
invocableFunctionNames.includes(method),
|
|
2928
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
const abiMethod = this.abi.find(
|
|
2932
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
2933
|
+
);
|
|
2934
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
2935
|
+
if (args.length !== inputsLength) {
|
|
2936
|
+
throw Error(
|
|
2937
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
2938
|
+
);
|
|
2939
|
+
}
|
|
2940
|
+
validateFields(abiMethod, args, this.structs);
|
|
2941
|
+
}
|
|
2942
|
+
compile(method, args) {
|
|
2943
|
+
const argsIterator = args[Symbol.iterator]();
|
|
2944
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
2945
|
+
return inputs.reduce(
|
|
2946
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
2947
|
+
[]
|
|
2948
|
+
);
|
|
2949
|
+
}
|
|
2950
|
+
static compile(rawArgs) {
|
|
2951
|
+
const createTree = (obj) => {
|
|
2952
|
+
const getEntries = (o, prefix = "") => {
|
|
2953
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
2954
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
2955
|
+
let value = v;
|
|
2956
|
+
if (isLongText(value))
|
|
2957
|
+
value = splitLongString(value);
|
|
2958
|
+
if (k === "entrypoint")
|
|
2959
|
+
value = getSelectorFromName(value);
|
|
2960
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
2961
|
+
if (isBigInt(value))
|
|
2962
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
2963
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
2964
|
+
});
|
|
2965
|
+
};
|
|
2966
|
+
return Object.fromEntries(getEntries(obj));
|
|
2967
|
+
};
|
|
2968
|
+
let callTreeArray;
|
|
2969
|
+
if (!Array.isArray(rawArgs)) {
|
|
2970
|
+
const callTree = createTree(rawArgs);
|
|
2971
|
+
callTreeArray = Object.values(callTree);
|
|
2972
|
+
} else {
|
|
2973
|
+
const callObj = { ...rawArgs };
|
|
2974
|
+
const callTree = createTree(callObj);
|
|
2975
|
+
callTreeArray = Object.values(callTree);
|
|
2976
|
+
}
|
|
2977
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
2978
|
+
enumerable: false,
|
|
2979
|
+
writable: false,
|
|
2980
|
+
value: true
|
|
2981
|
+
});
|
|
2982
|
+
return callTreeArray;
|
|
2983
|
+
}
|
|
2984
|
+
parse(method, response) {
|
|
2985
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
2986
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
2987
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
2988
|
+
const propName = output.name ?? idx;
|
|
2989
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
2990
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
2991
|
+
delete acc[`${propName}_len`];
|
|
2992
|
+
}
|
|
2993
|
+
return acc;
|
|
2994
|
+
}, {});
|
|
2995
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
2996
|
+
}
|
|
2997
|
+
format(method, response, format) {
|
|
2998
|
+
const parsed = this.parse(method, response);
|
|
2999
|
+
return formatter(parsed, format);
|
|
3000
|
+
}
|
|
3001
|
+
static abiInputsLength(inputs) {
|
|
3002
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3003
|
+
}
|
|
3004
|
+
static getAbiStruct(abi) {
|
|
3005
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3006
|
+
(acc, abiEntry) => ({
|
|
3007
|
+
...acc,
|
|
3008
|
+
[abiEntry.name]: abiEntry
|
|
3009
|
+
}),
|
|
3010
|
+
{}
|
|
3011
|
+
);
|
|
3012
|
+
}
|
|
3013
|
+
static toCalldata(rawCalldata = []) {
|
|
3014
|
+
return CallData.compile(rawCalldata);
|
|
3015
|
+
}
|
|
3016
|
+
static toHex(raw = []) {
|
|
3017
|
+
const calldata = CallData.compile(raw);
|
|
3018
|
+
return calldata.map((it) => toHex(it));
|
|
3019
|
+
}
|
|
3020
|
+
};
|
|
3021
|
+
|
|
3022
|
+
// src/utils/fetchPonyfill.ts
|
|
3023
|
+
import isomorphicFetch from "isomorphic-fetch";
|
|
3024
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
|
|
3025
|
+
|
|
3026
|
+
// src/utils/hash.ts
|
|
3027
|
+
var hash_exports = {};
|
|
3028
|
+
__export(hash_exports, {
|
|
3029
|
+
calculateContractAddressFromHash: () => calculateContractAddressFromHash,
|
|
3030
|
+
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash,
|
|
3031
|
+
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash,
|
|
3032
|
+
calculateDeployTransactionHash: () => calculateDeployTransactionHash,
|
|
3033
|
+
calculateTransactionHash: () => calculateTransactionHash,
|
|
3034
|
+
calculateTransactionHashCommon: () => calculateTransactionHashCommon,
|
|
3035
|
+
computeCompiledClassHash: () => computeCompiledClassHash,
|
|
3036
|
+
computeContractClassHash: () => computeContractClassHash,
|
|
3037
|
+
computeHashOnElements: () => computeHashOnElements,
|
|
3038
|
+
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
3039
|
+
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
3040
|
+
default: () => computeHintedClassHash,
|
|
3041
|
+
feeTransactionVersion: () => feeTransactionVersion,
|
|
3042
|
+
formatSpaces: () => formatSpaces,
|
|
3043
|
+
getSelector: () => getSelector,
|
|
3044
|
+
getSelectorFromName: () => getSelectorFromName,
|
|
3045
|
+
keccakBn: () => keccakBn,
|
|
3046
|
+
poseidon: () => poseidon,
|
|
3047
|
+
starknetKeccak: () => starknetKeccak,
|
|
3048
|
+
transactionVersion: () => transactionVersion,
|
|
3049
|
+
transactionVersion_2: () => transactionVersion_2
|
|
3050
|
+
});
|
|
3051
|
+
import { poseidonHashMany } from "micro-starknet";
|
|
3052
|
+
|
|
3053
|
+
// src/utils/ec.ts
|
|
3054
|
+
var ec_exports = {};
|
|
3055
|
+
__export(ec_exports, {
|
|
3056
|
+
starkCurve: () => starkCurve,
|
|
3057
|
+
weierstrass: () => weierstrass
|
|
3058
|
+
});
|
|
3059
|
+
import * as starkCurve from "micro-starknet";
|
|
3060
|
+
import * as weierstrass from "@noble/curves/abstract/weierstrass";
|
|
3061
|
+
|
|
3062
|
+
// src/utils/json.ts
|
|
3063
|
+
var json_exports = {};
|
|
3064
|
+
__export(json_exports, {
|
|
3065
|
+
parse: () => parse2,
|
|
3066
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
3067
|
+
stringify: () => stringify2,
|
|
3068
|
+
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
3069
|
+
});
|
|
3070
|
+
import * as json from "lossless-json";
|
|
3071
|
+
var parseIntAsNumberOrBigInt = (x) => {
|
|
3072
|
+
if (!json.isInteger(x))
|
|
3073
|
+
return parseFloat(x);
|
|
3074
|
+
const v = parseInt(x, 10);
|
|
3075
|
+
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
3076
|
+
};
|
|
3077
|
+
var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
3078
|
+
var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
|
|
3079
|
+
var stringify2 = (...p) => json.stringify(...p);
|
|
3080
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
3081
|
+
|
|
3082
|
+
// src/utils/hash.ts
|
|
3083
|
+
import * as poseidon from "@noble/curves/abstract/poseidon";
|
|
3084
|
+
var transactionVersion = 1n;
|
|
3085
|
+
var transactionVersion_2 = 2n;
|
|
3086
|
+
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
3087
|
+
function computeHashOnElements(data) {
|
|
3088
|
+
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
3089
|
+
}
|
|
3090
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
3091
|
+
const calldataHash = computeHashOnElements(calldata);
|
|
3092
|
+
const dataToHash = [
|
|
3093
|
+
txHashPrefix,
|
|
3094
|
+
version,
|
|
3095
|
+
contractAddress,
|
|
3096
|
+
entryPointSelector,
|
|
3097
|
+
calldataHash,
|
|
3098
|
+
maxFee,
|
|
3099
|
+
chainId,
|
|
3100
|
+
...additionalData
|
|
3101
|
+
];
|
|
3102
|
+
return computeHashOnElements(dataToHash);
|
|
3103
|
+
}
|
|
3104
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
3105
|
+
return calculateTransactionHashCommon(
|
|
3106
|
+
"0x6465706c6f79" /* DEPLOY */,
|
|
3107
|
+
version,
|
|
3108
|
+
contractAddress,
|
|
3109
|
+
getSelectorFromName("constructor"),
|
|
3110
|
+
constructorCalldata,
|
|
3111
|
+
0,
|
|
3112
|
+
chainId
|
|
3113
|
+
);
|
|
3114
|
+
}
|
|
3115
|
+
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
3116
|
+
return calculateTransactionHashCommon(
|
|
3117
|
+
"0x6465636c617265" /* DECLARE */,
|
|
3118
|
+
version,
|
|
3119
|
+
senderAddress,
|
|
3120
|
+
0,
|
|
3121
|
+
[classHash],
|
|
3122
|
+
maxFee,
|
|
3123
|
+
chainId,
|
|
3124
|
+
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
3125
|
+
);
|
|
3126
|
+
}
|
|
3127
|
+
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
3128
|
+
const calldata = [classHash, salt, ...constructorCalldata];
|
|
3129
|
+
return calculateTransactionHashCommon(
|
|
3130
|
+
"0x6465706c6f795f6163636f756e74" /* DEPLOY_ACCOUNT */,
|
|
3131
|
+
version,
|
|
3132
|
+
contractAddress,
|
|
3133
|
+
0,
|
|
3134
|
+
calldata,
|
|
3135
|
+
maxFee,
|
|
3136
|
+
chainId,
|
|
3137
|
+
[nonce]
|
|
3138
|
+
);
|
|
3139
|
+
}
|
|
3140
|
+
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
3141
|
+
return calculateTransactionHashCommon(
|
|
3142
|
+
"0x696e766f6b65" /* INVOKE */,
|
|
3143
|
+
version,
|
|
3144
|
+
contractAddress,
|
|
3145
|
+
0,
|
|
3146
|
+
calldata,
|
|
3147
|
+
maxFee,
|
|
3148
|
+
chainId,
|
|
3149
|
+
[nonce]
|
|
3150
|
+
);
|
|
3151
|
+
}
|
|
3152
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
3153
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
3154
|
+
const constructorCalldataHash = computeHashOnElements(compiledCalldata);
|
|
3155
|
+
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
3156
|
+
return computeHashOnElements([
|
|
3157
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
3158
|
+
deployerAddress,
|
|
3159
|
+
salt,
|
|
3160
|
+
classHash,
|
|
3161
|
+
constructorCalldataHash
|
|
3162
|
+
]);
|
|
3163
|
+
}
|
|
3164
|
+
function nullSkipReplacer(key, value) {
|
|
3165
|
+
if (key === "attributes" || key === "accessible_scopes") {
|
|
3166
|
+
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
3188
3167
|
}
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3192
|
-
return inputs.reduce(
|
|
3193
|
-
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3194
|
-
[]
|
|
3195
|
-
);
|
|
3168
|
+
if (key === "debug_info") {
|
|
3169
|
+
return null;
|
|
3196
3170
|
}
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
if (isBigInt(value))
|
|
3209
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
3210
|
-
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3211
|
-
});
|
|
3212
|
-
};
|
|
3213
|
-
return Object.fromEntries(getEntries(obj));
|
|
3214
|
-
};
|
|
3215
|
-
let callTreeArray;
|
|
3216
|
-
if (!Array.isArray(rawArgs)) {
|
|
3217
|
-
const callTree = createTree(rawArgs);
|
|
3218
|
-
callTreeArray = Object.values(callTree);
|
|
3171
|
+
return value === null ? void 0 : value;
|
|
3172
|
+
}
|
|
3173
|
+
function formatSpaces(json2) {
|
|
3174
|
+
let insideQuotes = false;
|
|
3175
|
+
let newString = "";
|
|
3176
|
+
for (const char of json2) {
|
|
3177
|
+
if (char === '"' && newString.endsWith("\\") === false) {
|
|
3178
|
+
insideQuotes = !insideQuotes;
|
|
3179
|
+
}
|
|
3180
|
+
if (insideQuotes) {
|
|
3181
|
+
newString += char;
|
|
3219
3182
|
} else {
|
|
3220
|
-
|
|
3221
|
-
const callTree = createTree(callObj);
|
|
3222
|
-
callTreeArray = Object.values(callTree);
|
|
3183
|
+
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
3223
3184
|
}
|
|
3224
|
-
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3225
|
-
enumerable: false,
|
|
3226
|
-
writable: false,
|
|
3227
|
-
value: true
|
|
3228
|
-
});
|
|
3229
|
-
return callTreeArray;
|
|
3230
|
-
}
|
|
3231
|
-
parse(method, response) {
|
|
3232
|
-
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3233
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3234
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3235
|
-
const propName = output.name ?? idx;
|
|
3236
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3237
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3238
|
-
delete acc[`${propName}_len`];
|
|
3239
|
-
}
|
|
3240
|
-
return acc;
|
|
3241
|
-
}, {});
|
|
3242
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3243
|
-
}
|
|
3244
|
-
format(method, response, format) {
|
|
3245
|
-
const parsed = this.parse(method, response);
|
|
3246
|
-
return formatter(parsed, format);
|
|
3247
|
-
}
|
|
3248
|
-
static abiInputsLength(inputs) {
|
|
3249
|
-
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3250
|
-
}
|
|
3251
|
-
static getAbiStruct(abi) {
|
|
3252
|
-
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3253
|
-
(acc, abiEntry) => ({
|
|
3254
|
-
...acc,
|
|
3255
|
-
[abiEntry.name]: abiEntry
|
|
3256
|
-
}),
|
|
3257
|
-
{}
|
|
3258
|
-
);
|
|
3259
3185
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3186
|
+
return newString;
|
|
3187
|
+
}
|
|
3188
|
+
function computeHintedClassHash(compiledContract) {
|
|
3189
|
+
const { abi, program } = compiledContract;
|
|
3190
|
+
const contractClass = { abi, program };
|
|
3191
|
+
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
3192
|
+
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
3193
|
+
}
|
|
3194
|
+
function computeLegacyContractClassHash(contract) {
|
|
3195
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3196
|
+
const apiVersion = toHex(API_VERSION);
|
|
3197
|
+
const externalEntryPointsHash = computeHashOnElements(
|
|
3198
|
+
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
3199
|
+
);
|
|
3200
|
+
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
3201
|
+
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
3202
|
+
);
|
|
3203
|
+
const constructorEntryPointHash = computeHashOnElements(
|
|
3204
|
+
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
3205
|
+
);
|
|
3206
|
+
const builtinsHash = computeHashOnElements(
|
|
3207
|
+
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
3208
|
+
);
|
|
3209
|
+
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
3210
|
+
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
3211
|
+
return computeHashOnElements([
|
|
3212
|
+
apiVersion,
|
|
3213
|
+
externalEntryPointsHash,
|
|
3214
|
+
l1HandlerEntryPointsHash,
|
|
3215
|
+
constructorEntryPointHash,
|
|
3216
|
+
builtinsHash,
|
|
3217
|
+
hintedClassHash,
|
|
3218
|
+
dataHash
|
|
3219
|
+
]);
|
|
3220
|
+
}
|
|
3221
|
+
function hashBuiltins(builtins) {
|
|
3222
|
+
return poseidonHashMany(
|
|
3223
|
+
builtins.flatMap((it) => {
|
|
3224
|
+
return BigInt(encodeShortString(it));
|
|
3225
|
+
})
|
|
3226
|
+
);
|
|
3227
|
+
}
|
|
3228
|
+
function hashEntryPoint(data) {
|
|
3229
|
+
const base = data.flatMap((it) => {
|
|
3230
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
3231
|
+
});
|
|
3232
|
+
return poseidonHashMany(base);
|
|
3233
|
+
}
|
|
3234
|
+
function computeCompiledClassHash(casm) {
|
|
3235
|
+
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
3236
|
+
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
3237
|
+
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
3238
|
+
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
3239
|
+
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
3240
|
+
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
3241
|
+
return toHex(
|
|
3242
|
+
poseidonHashMany([
|
|
3243
|
+
compiledClassVersion,
|
|
3244
|
+
externalEntryPointsHash,
|
|
3245
|
+
l1Handlers,
|
|
3246
|
+
constructor,
|
|
3247
|
+
bytecode
|
|
3248
|
+
])
|
|
3249
|
+
);
|
|
3250
|
+
}
|
|
3251
|
+
function hashEntryPointSierra(data) {
|
|
3252
|
+
const base = data.flatMap((it) => {
|
|
3253
|
+
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
3254
|
+
});
|
|
3255
|
+
return poseidonHashMany(base);
|
|
3256
|
+
}
|
|
3257
|
+
function hashAbi(sierra) {
|
|
3258
|
+
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
3259
|
+
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
3260
|
+
}
|
|
3261
|
+
function computeSierraContractClassHash(sierra) {
|
|
3262
|
+
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
3263
|
+
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
3264
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
3265
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
3266
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
3267
|
+
const abiHash = hashAbi(sierra);
|
|
3268
|
+
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
3269
|
+
return toHex(
|
|
3270
|
+
poseidonHashMany([
|
|
3271
|
+
compiledClassVersion,
|
|
3272
|
+
externalEntryPointsHash,
|
|
3273
|
+
l1Handlers,
|
|
3274
|
+
constructor,
|
|
3275
|
+
abiHash,
|
|
3276
|
+
sierraProgram
|
|
3277
|
+
])
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
function computeContractClassHash(contract) {
|
|
3281
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3282
|
+
if ("sierra_program" in compiledContract) {
|
|
3283
|
+
return computeSierraContractClassHash(compiledContract);
|
|
3266
3284
|
}
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
// src/utils/fetchPonyfill.ts
|
|
3270
|
-
import isomorphicFetch from "isomorphic-fetch";
|
|
3271
|
-
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
|
|
3285
|
+
return computeLegacyContractClassHash(compiledContract);
|
|
3286
|
+
}
|
|
3272
3287
|
|
|
3273
3288
|
// src/utils/contract.ts
|
|
3274
3289
|
function isSierra(contract) {
|
|
@@ -3807,7 +3822,7 @@ var RpcProvider = class {
|
|
|
3807
3822
|
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3808
3823
|
request: {
|
|
3809
3824
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
3810
|
-
constructor_calldata:
|
|
3825
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
3811
3826
|
class_hash: toHex(classHash),
|
|
3812
3827
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3813
3828
|
signature: signatureToHexArray(signature),
|
|
@@ -3844,7 +3859,7 @@ var RpcProvider = class {
|
|
|
3844
3859
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
3845
3860
|
return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
3846
3861
|
deploy_account_transaction: {
|
|
3847
|
-
constructor_calldata:
|
|
3862
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
3848
3863
|
class_hash: toHex(classHash),
|
|
3849
3864
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3850
3865
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
@@ -4282,7 +4297,7 @@ var SequencerProvider = class {
|
|
|
4282
4297
|
{
|
|
4283
4298
|
contract_address: contractAddress,
|
|
4284
4299
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
4285
|
-
calldata
|
|
4300
|
+
calldata: CallData.compile(calldata)
|
|
4286
4301
|
}
|
|
4287
4302
|
).then(this.responseParser.parseCallContractResponse);
|
|
4288
4303
|
}
|
|
@@ -4396,7 +4411,7 @@ var SequencerProvider = class {
|
|
|
4396
4411
|
{
|
|
4397
4412
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
4398
4413
|
sender_address: invocation.contractAddress,
|
|
4399
|
-
calldata: invocation.calldata ?? [],
|
|
4414
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4400
4415
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4401
4416
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4402
4417
|
nonce: toHex(invocationDetails.nonce)
|
|
@@ -4454,7 +4469,7 @@ var SequencerProvider = class {
|
|
|
4454
4469
|
res = {
|
|
4455
4470
|
type: invocation.type,
|
|
4456
4471
|
sender_address: invocation.contractAddress,
|
|
4457
|
-
calldata: invocation.calldata ?? []
|
|
4472
|
+
calldata: CallData.compile(invocation.calldata ?? [])
|
|
4458
4473
|
};
|
|
4459
4474
|
} else if (invocation.type === "DECLARE") {
|
|
4460
4475
|
res = {
|
|
@@ -4537,7 +4552,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4537
4552
|
{
|
|
4538
4553
|
type: "INVOKE_FUNCTION",
|
|
4539
4554
|
sender_address: invocation.contractAddress,
|
|
4540
|
-
calldata: invocation.calldata ?? [],
|
|
4555
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4541
4556
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4542
4557
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4543
4558
|
nonce: toHex(invocationDetails.nonce),
|
|
@@ -4950,7 +4965,7 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
4950
4965
|
const callArray = [];
|
|
4951
4966
|
const calldata = [];
|
|
4952
4967
|
calls.forEach((call) => {
|
|
4953
|
-
const data = call.calldata || [];
|
|
4968
|
+
const data = CallData.compile(call.calldata || []);
|
|
4954
4969
|
callArray.push({
|
|
4955
4970
|
to: toBigInt(call.contractAddress).toString(10),
|
|
4956
4971
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
@@ -4981,11 +4996,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
4981
4996
|
return callArray;
|
|
4982
4997
|
};
|
|
4983
4998
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
4984
|
-
|
|
4999
|
+
const orderCalls = calls.map((call) => ({
|
|
5000
|
+
contractAddress: call.contractAddress,
|
|
5001
|
+
entrypoint: call.entrypoint,
|
|
5002
|
+
calldata: call.calldata
|
|
5003
|
+
}));
|
|
5004
|
+
return CallData.compile({ orderCalls });
|
|
4985
5005
|
};
|
|
4986
5006
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
4987
5007
|
if (cairoVersion === "1") {
|
|
4988
|
-
return
|
|
5008
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
4989
5009
|
}
|
|
4990
5010
|
return fromCallsToExecuteCalldata(calls);
|
|
4991
5011
|
};
|
|
@@ -5239,7 +5259,7 @@ var Signer = class {
|
|
|
5239
5259
|
const msgHash = calculateDeployAccountTransactionHash(
|
|
5240
5260
|
contractAddress,
|
|
5241
5261
|
classHash,
|
|
5242
|
-
constructorCalldata,
|
|
5262
|
+
CallData.compile(constructorCalldata),
|
|
5243
5263
|
addressSalt,
|
|
5244
5264
|
version,
|
|
5245
5265
|
maxFee,
|
|
@@ -5295,10 +5315,12 @@ function parseUDCEvent(txReceipt) {
|
|
|
5295
5315
|
|
|
5296
5316
|
// src/account/default.ts
|
|
5297
5317
|
var Account = class extends Provider {
|
|
5298
|
-
constructor(providerOrOptions, address, pkOrSigner) {
|
|
5318
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion = "0") {
|
|
5299
5319
|
super(providerOrOptions);
|
|
5320
|
+
this.deploySelf = this.deployAccount;
|
|
5300
5321
|
this.address = address.toLowerCase();
|
|
5301
5322
|
this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
5323
|
+
this.cairoVersion = cairoVersion;
|
|
5302
5324
|
}
|
|
5303
5325
|
async getNonce(blockIdentifier) {
|
|
5304
5326
|
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
@@ -5306,7 +5328,7 @@ var Account = class extends Provider {
|
|
|
5306
5328
|
async estimateFee(calls, estimateFeeDetails) {
|
|
5307
5329
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
5308
5330
|
}
|
|
5309
|
-
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
5331
|
+
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5310
5332
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5311
5333
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5312
5334
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5317,7 +5339,7 @@ var Account = class extends Provider {
|
|
|
5317
5339
|
maxFee: ZERO,
|
|
5318
5340
|
version,
|
|
5319
5341
|
chainId,
|
|
5320
|
-
cairoVersion: cairoVersion
|
|
5342
|
+
cairoVersion: this.cairoVersion
|
|
5321
5343
|
};
|
|
5322
5344
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5323
5345
|
const response = await super.getInvokeEstimateFee(
|
|
@@ -5332,7 +5354,7 @@ var Account = class extends Provider {
|
|
|
5332
5354
|
suggestedMaxFee
|
|
5333
5355
|
};
|
|
5334
5356
|
}
|
|
5335
|
-
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate
|
|
5357
|
+
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate } = {}) {
|
|
5336
5358
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5337
5359
|
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
|
|
5338
5360
|
const chainId = await this.getChainId();
|
|
@@ -5344,7 +5366,7 @@ var Account = class extends Provider {
|
|
|
5344
5366
|
version,
|
|
5345
5367
|
walletAddress: this.address,
|
|
5346
5368
|
maxFee: ZERO,
|
|
5347
|
-
cairoVersion: cairoVersion
|
|
5369
|
+
cairoVersion: this.cairoVersion
|
|
5348
5370
|
}
|
|
5349
5371
|
);
|
|
5350
5372
|
const response = await super.getDeclareEstimateFee(
|
|
@@ -5364,7 +5386,7 @@ var Account = class extends Provider {
|
|
|
5364
5386
|
addressSalt = 0,
|
|
5365
5387
|
constructorCalldata = [],
|
|
5366
5388
|
contractAddress: providedContractAddress
|
|
5367
|
-
}, { blockIdentifier, skipValidate
|
|
5389
|
+
}, { blockIdentifier, skipValidate } = {}) {
|
|
5368
5390
|
const version = toBigInt(feeTransactionVersion);
|
|
5369
5391
|
const nonce = ZERO;
|
|
5370
5392
|
const chainId = await this.getChainId();
|
|
@@ -5376,7 +5398,7 @@ var Account = class extends Provider {
|
|
|
5376
5398
|
version,
|
|
5377
5399
|
walletAddress: this.address,
|
|
5378
5400
|
maxFee: ZERO,
|
|
5379
|
-
cairoVersion: cairoVersion
|
|
5401
|
+
cairoVersion: this.cairoVersion
|
|
5380
5402
|
}
|
|
5381
5403
|
);
|
|
5382
5404
|
const response = await super.getDeployAccountEstimateFee(
|
|
@@ -5395,7 +5417,7 @@ var Account = class extends Provider {
|
|
|
5395
5417
|
const calls = this.buildUDCContractPayload(payload);
|
|
5396
5418
|
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
5397
5419
|
}
|
|
5398
|
-
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier
|
|
5420
|
+
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5399
5421
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5400
5422
|
const version = toBigInt(feeTransactionVersion);
|
|
5401
5423
|
const chainId = await this.getChainId();
|
|
@@ -5407,7 +5429,7 @@ var Account = class extends Provider {
|
|
|
5407
5429
|
maxFee: ZERO,
|
|
5408
5430
|
version,
|
|
5409
5431
|
chainId,
|
|
5410
|
-
cairoVersion: cairoVersion
|
|
5432
|
+
cairoVersion: this.cairoVersion
|
|
5411
5433
|
};
|
|
5412
5434
|
const txPayload = transaction.payload;
|
|
5413
5435
|
let res;
|
|
@@ -5465,7 +5487,7 @@ var Account = class extends Provider {
|
|
|
5465
5487
|
});
|
|
5466
5488
|
}
|
|
5467
5489
|
async buildInvocation(call, signerDetails) {
|
|
5468
|
-
const calldata = getExecuteCalldata(call,
|
|
5490
|
+
const calldata = getExecuteCalldata(call, this.cairoVersion);
|
|
5469
5491
|
const signature = await this.signer.signTransaction(call, signerDetails);
|
|
5470
5492
|
return {
|
|
5471
5493
|
contractAddress: this.address,
|
|
@@ -5482,17 +5504,16 @@ var Account = class extends Provider {
|
|
|
5482
5504
|
);
|
|
5483
5505
|
const version = toBigInt(transactionVersion);
|
|
5484
5506
|
const chainId = await this.getChainId();
|
|
5485
|
-
const cairoVersion = transactionsDetail.cairoVersion ?? "0";
|
|
5486
5507
|
const signerDetails = {
|
|
5487
5508
|
walletAddress: this.address,
|
|
5488
5509
|
nonce,
|
|
5489
5510
|
maxFee,
|
|
5490
5511
|
version,
|
|
5491
5512
|
chainId,
|
|
5492
|
-
cairoVersion
|
|
5513
|
+
cairoVersion: this.cairoVersion
|
|
5493
5514
|
};
|
|
5494
5515
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
5495
|
-
const calldata = getExecuteCalldata(transactions, cairoVersion);
|
|
5516
|
+
const calldata = getExecuteCalldata(transactions, this.cairoVersion);
|
|
5496
5517
|
return this.invokeFunction(
|
|
5497
5518
|
{ contractAddress: this.address, calldata, signature },
|
|
5498
5519
|
{
|
|
@@ -5502,6 +5523,18 @@ var Account = class extends Provider {
|
|
|
5502
5523
|
}
|
|
5503
5524
|
);
|
|
5504
5525
|
}
|
|
5526
|
+
async declareIfNot(payload, transactionsDetail = {}) {
|
|
5527
|
+
const declareContractPayload = extractContractHashes(payload);
|
|
5528
|
+
try {
|
|
5529
|
+
await this.getClassByHash(declareContractPayload.classHash);
|
|
5530
|
+
} catch (error) {
|
|
5531
|
+
return this.declare(payload, transactionsDetail);
|
|
5532
|
+
}
|
|
5533
|
+
return {
|
|
5534
|
+
transaction_hash: "",
|
|
5535
|
+
class_hash: declareContractPayload.classHash
|
|
5536
|
+
};
|
|
5537
|
+
}
|
|
5505
5538
|
async declare(payload, transactionsDetail = {}) {
|
|
5506
5539
|
const declareContractPayload = extractContractHashes(payload);
|
|
5507
5540
|
const details = {};
|
|
@@ -5518,7 +5551,7 @@ var Account = class extends Provider {
|
|
|
5518
5551
|
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
|
|
5519
5552
|
...details,
|
|
5520
5553
|
walletAddress: this.address,
|
|
5521
|
-
cairoVersion:
|
|
5554
|
+
cairoVersion: this.cairoVersion
|
|
5522
5555
|
});
|
|
5523
5556
|
return this.declareContract(declareContractTransaction, details);
|
|
5524
5557
|
}
|
|
@@ -5554,10 +5587,7 @@ var Account = class extends Provider {
|
|
|
5554
5587
|
});
|
|
5555
5588
|
const calls = params.map((it) => it.call);
|
|
5556
5589
|
const addresses = params.map((it) => it.address);
|
|
5557
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5558
|
-
...details,
|
|
5559
|
-
cairoVersion: "0"
|
|
5560
|
-
});
|
|
5590
|
+
const invokeResponse = await this.execute(calls, void 0, details);
|
|
5561
5591
|
return {
|
|
5562
5592
|
...invokeResponse,
|
|
5563
5593
|
contract_address: addresses
|
|
@@ -5572,15 +5602,18 @@ var Account = class extends Provider {
|
|
|
5572
5602
|
}
|
|
5573
5603
|
async declareAndDeploy(payload, details) {
|
|
5574
5604
|
const { constructorCalldata, salt, unique } = payload;
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5605
|
+
let declare = await this.declareIfNot(payload, details);
|
|
5606
|
+
if (declare.transaction_hash !== "") {
|
|
5607
|
+
const tx = await this.waitForTransaction(declare.transaction_hash, {
|
|
5608
|
+
successStates: ["ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */]
|
|
5609
|
+
});
|
|
5610
|
+
declare = { ...declare, ...tx };
|
|
5611
|
+
}
|
|
5579
5612
|
const deploy = await this.deployContract(
|
|
5580
|
-
{ classHash: class_hash, salt, unique, constructorCalldata },
|
|
5613
|
+
{ classHash: declare.class_hash, salt, unique, constructorCalldata },
|
|
5581
5614
|
details
|
|
5582
5615
|
);
|
|
5583
|
-
return { declare: { ...declare
|
|
5616
|
+
return { declare: { ...declare }, deploy };
|
|
5584
5617
|
}
|
|
5585
5618
|
async deployAccount({
|
|
5586
5619
|
classHash,
|
|
@@ -5596,13 +5629,18 @@ var Account = class extends Provider {
|
|
|
5596
5629
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5597
5630
|
{
|
|
5598
5631
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
5599
|
-
payload: {
|
|
5632
|
+
payload: {
|
|
5633
|
+
classHash,
|
|
5634
|
+
constructorCalldata: compiledCalldata,
|
|
5635
|
+
addressSalt,
|
|
5636
|
+
contractAddress
|
|
5637
|
+
}
|
|
5600
5638
|
},
|
|
5601
5639
|
transactionsDetail
|
|
5602
5640
|
);
|
|
5603
5641
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5604
5642
|
classHash,
|
|
5605
|
-
constructorCalldata,
|
|
5643
|
+
constructorCalldata: compiledCalldata,
|
|
5606
5644
|
contractAddress,
|
|
5607
5645
|
addressSalt,
|
|
5608
5646
|
chainId,
|
|
@@ -5700,12 +5738,12 @@ var Account = class extends Provider {
|
|
|
5700
5738
|
version,
|
|
5701
5739
|
nonce,
|
|
5702
5740
|
addressSalt,
|
|
5703
|
-
constructorCalldata
|
|
5741
|
+
constructorCalldata: compiledCalldata
|
|
5704
5742
|
});
|
|
5705
5743
|
return {
|
|
5706
5744
|
classHash,
|
|
5707
5745
|
addressSalt,
|
|
5708
|
-
constructorCalldata,
|
|
5746
|
+
constructorCalldata: compiledCalldata,
|
|
5709
5747
|
signature
|
|
5710
5748
|
};
|
|
5711
5749
|
}
|
|
@@ -5732,7 +5770,7 @@ var Account = class extends Provider {
|
|
|
5732
5770
|
});
|
|
5733
5771
|
return calls;
|
|
5734
5772
|
}
|
|
5735
|
-
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
5773
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5736
5774
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5737
5775
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5738
5776
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5743,7 +5781,7 @@ var Account = class extends Provider {
|
|
|
5743
5781
|
maxFee: ZERO,
|
|
5744
5782
|
version,
|
|
5745
5783
|
chainId,
|
|
5746
|
-
cairoVersion: cairoVersion
|
|
5784
|
+
cairoVersion: this.cairoVersion
|
|
5747
5785
|
};
|
|
5748
5786
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5749
5787
|
const response = await super.getSimulateTransaction(
|