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.js
CHANGED
|
@@ -121,55 +121,27 @@ function assert(condition, message) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
// src/utils/
|
|
125
|
-
var
|
|
126
|
-
__export(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
keccakBn: () => keccakBn,
|
|
144
|
-
poseidon: () => poseidon,
|
|
145
|
-
starknetKeccak: () => starknetKeccak,
|
|
146
|
-
transactionVersion: () => transactionVersion,
|
|
147
|
-
transactionVersion_2: () => transactionVersion_2
|
|
148
|
-
});
|
|
149
|
-
var import_micro_starknet = require("micro-starknet");
|
|
150
|
-
|
|
151
|
-
// src/constants.ts
|
|
152
|
-
var constants_exports = {};
|
|
153
|
-
__export(constants_exports, {
|
|
154
|
-
ALPHA: () => ALPHA,
|
|
155
|
-
API_VERSION: () => API_VERSION,
|
|
156
|
-
BETA: () => BETA,
|
|
157
|
-
BaseUrl: () => BaseUrl,
|
|
158
|
-
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
159
|
-
EC_ORDER: () => EC_ORDER,
|
|
160
|
-
FIELD_GEN: () => FIELD_GEN,
|
|
161
|
-
FIELD_PRIME: () => FIELD_PRIME,
|
|
162
|
-
FIELD_SIZE: () => FIELD_SIZE,
|
|
163
|
-
IS_BROWSER: () => IS_BROWSER,
|
|
164
|
-
MASK_250: () => MASK_250,
|
|
165
|
-
MASK_251: () => MASK_251,
|
|
166
|
-
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
167
|
-
NetworkName: () => NetworkName,
|
|
168
|
-
StarknetChainId: () => StarknetChainId,
|
|
169
|
-
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
170
|
-
UDC: () => UDC,
|
|
171
|
-
ZERO: () => ZERO
|
|
124
|
+
// src/utils/num.ts
|
|
125
|
+
var num_exports = {};
|
|
126
|
+
__export(num_exports, {
|
|
127
|
+
assertInRange: () => assertInRange,
|
|
128
|
+
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
129
|
+
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
130
|
+
cleanHex: () => cleanHex,
|
|
131
|
+
getDecimalString: () => getDecimalString,
|
|
132
|
+
getHexString: () => getHexString,
|
|
133
|
+
getHexStringArray: () => getHexStringArray,
|
|
134
|
+
hexToBytes: () => hexToBytes,
|
|
135
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
136
|
+
isBigInt: () => isBigInt,
|
|
137
|
+
isHex: () => isHex,
|
|
138
|
+
isStringWholeNumber: () => isStringWholeNumber,
|
|
139
|
+
toBigInt: () => toBigInt,
|
|
140
|
+
toCairoBool: () => toCairoBool,
|
|
141
|
+
toHex: () => toHex,
|
|
142
|
+
toHexString: () => toHexString
|
|
172
143
|
});
|
|
144
|
+
var import_utils = require("@noble/curves/abstract/utils");
|
|
173
145
|
|
|
174
146
|
// src/utils/encode.ts
|
|
175
147
|
var encode_exports = {};
|
|
@@ -234,7 +206,98 @@ function utf8ToArray(str) {
|
|
|
234
206
|
return new TextEncoder().encode(str);
|
|
235
207
|
}
|
|
236
208
|
|
|
209
|
+
// src/utils/num.ts
|
|
210
|
+
function isHex(hex) {
|
|
211
|
+
return /^0x[0-9a-f]*$/i.test(hex);
|
|
212
|
+
}
|
|
213
|
+
function toBigInt(value) {
|
|
214
|
+
return BigInt(value);
|
|
215
|
+
}
|
|
216
|
+
function isBigInt(value) {
|
|
217
|
+
return typeof value === "bigint";
|
|
218
|
+
}
|
|
219
|
+
function toHex(number2) {
|
|
220
|
+
return addHexPrefix(toBigInt(number2).toString(16));
|
|
221
|
+
}
|
|
222
|
+
function hexToDecimalString(hex) {
|
|
223
|
+
return BigInt(addHexPrefix(hex)).toString(10);
|
|
224
|
+
}
|
|
225
|
+
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
226
|
+
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
227
|
+
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
228
|
+
const inputBigInt = BigInt(input);
|
|
229
|
+
const lowerBoundBigInt = BigInt(lowerBound);
|
|
230
|
+
const upperBoundBigInt = BigInt(upperBound);
|
|
231
|
+
assert(
|
|
232
|
+
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
233
|
+
`Message not signable, ${messageSuffix}.`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
237
|
+
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
238
|
+
}
|
|
239
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
240
|
+
return rawCalldata.map((x) => toHex(x));
|
|
241
|
+
}
|
|
242
|
+
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
243
|
+
var toHexString = (value) => toHex(value);
|
|
244
|
+
function getDecimalString(value) {
|
|
245
|
+
if (isHex(value)) {
|
|
246
|
+
return hexToDecimalString(value);
|
|
247
|
+
}
|
|
248
|
+
if (isStringWholeNumber(value)) {
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
252
|
+
}
|
|
253
|
+
function getHexString(value) {
|
|
254
|
+
if (isHex(value)) {
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
if (isStringWholeNumber(value)) {
|
|
258
|
+
return toHexString(value);
|
|
259
|
+
}
|
|
260
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
261
|
+
}
|
|
262
|
+
function getHexStringArray(value) {
|
|
263
|
+
return value.map((el) => getHexString(el));
|
|
264
|
+
}
|
|
265
|
+
var toCairoBool = (value) => (+value).toString();
|
|
266
|
+
function hexToBytes(value) {
|
|
267
|
+
if (!isHex(value))
|
|
268
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
269
|
+
let adaptedValue = removeHexPrefix(value);
|
|
270
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
271
|
+
adaptedValue = `0${adaptedValue}`;
|
|
272
|
+
}
|
|
273
|
+
return (0, import_utils.hexToBytes)(adaptedValue);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/utils/selector.ts
|
|
277
|
+
var import_micro_starknet = require("micro-starknet");
|
|
278
|
+
|
|
237
279
|
// src/constants.ts
|
|
280
|
+
var constants_exports = {};
|
|
281
|
+
__export(constants_exports, {
|
|
282
|
+
ALPHA: () => ALPHA,
|
|
283
|
+
API_VERSION: () => API_VERSION,
|
|
284
|
+
BETA: () => BETA,
|
|
285
|
+
BaseUrl: () => BaseUrl,
|
|
286
|
+
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
287
|
+
EC_ORDER: () => EC_ORDER,
|
|
288
|
+
FIELD_GEN: () => FIELD_GEN,
|
|
289
|
+
FIELD_PRIME: () => FIELD_PRIME,
|
|
290
|
+
FIELD_SIZE: () => FIELD_SIZE,
|
|
291
|
+
IS_BROWSER: () => IS_BROWSER,
|
|
292
|
+
MASK_250: () => MASK_250,
|
|
293
|
+
MASK_251: () => MASK_251,
|
|
294
|
+
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
295
|
+
NetworkName: () => NetworkName,
|
|
296
|
+
StarknetChainId: () => StarknetChainId,
|
|
297
|
+
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
298
|
+
UDC: () => UDC,
|
|
299
|
+
ZERO: () => ZERO
|
|
300
|
+
});
|
|
238
301
|
var ZERO = 0n;
|
|
239
302
|
var MASK_250 = 2n ** 250n - 1n;
|
|
240
303
|
var MASK_251 = 2n ** 251n;
|
|
@@ -2303,6 +2366,83 @@ var CONSTANT_POINTS = [
|
|
|
2303
2366
|
]
|
|
2304
2367
|
];
|
|
2305
2368
|
|
|
2369
|
+
// src/utils/selector.ts
|
|
2370
|
+
function keccakBn(value) {
|
|
2371
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2372
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2373
|
+
return addHexPrefix((0, import_micro_starknet.keccak)(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2374
|
+
}
|
|
2375
|
+
function keccakHex(value) {
|
|
2376
|
+
return addHexPrefix((0, import_micro_starknet.keccak)(utf8ToArray(value)).toString(16));
|
|
2377
|
+
}
|
|
2378
|
+
function starknetKeccak(value) {
|
|
2379
|
+
const hash = BigInt(keccakHex(value));
|
|
2380
|
+
return hash & MASK_250;
|
|
2381
|
+
}
|
|
2382
|
+
function getSelectorFromName(funcName) {
|
|
2383
|
+
return toHex(starknetKeccak(funcName));
|
|
2384
|
+
}
|
|
2385
|
+
function getSelector(value) {
|
|
2386
|
+
if (isHex(value)) {
|
|
2387
|
+
return value;
|
|
2388
|
+
}
|
|
2389
|
+
if (isStringWholeNumber(value)) {
|
|
2390
|
+
return toHexString(value);
|
|
2391
|
+
}
|
|
2392
|
+
return getSelectorFromName(value);
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// src/utils/shortString.ts
|
|
2396
|
+
var shortString_exports = {};
|
|
2397
|
+
__export(shortString_exports, {
|
|
2398
|
+
decodeShortString: () => decodeShortString,
|
|
2399
|
+
encodeShortString: () => encodeShortString,
|
|
2400
|
+
isASCII: () => isASCII,
|
|
2401
|
+
isDecimalString: () => isDecimalString,
|
|
2402
|
+
isLongText: () => isLongText,
|
|
2403
|
+
isShortString: () => isShortString,
|
|
2404
|
+
isShortText: () => isShortText,
|
|
2405
|
+
isText: () => isText,
|
|
2406
|
+
splitLongString: () => splitLongString
|
|
2407
|
+
});
|
|
2408
|
+
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
2409
|
+
function isASCII(str) {
|
|
2410
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
2411
|
+
}
|
|
2412
|
+
function isShortString(str) {
|
|
2413
|
+
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
2414
|
+
}
|
|
2415
|
+
function isDecimalString(decim) {
|
|
2416
|
+
return /^[0-9]*$/i.test(decim);
|
|
2417
|
+
}
|
|
2418
|
+
function isText(val) {
|
|
2419
|
+
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
2420
|
+
}
|
|
2421
|
+
var isShortText = (val) => isText(val) && isShortString(val);
|
|
2422
|
+
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
2423
|
+
function splitLongString(longStr) {
|
|
2424
|
+
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
2425
|
+
return longStr.match(regex) || [];
|
|
2426
|
+
}
|
|
2427
|
+
function encodeShortString(str) {
|
|
2428
|
+
if (!isASCII(str))
|
|
2429
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
2430
|
+
if (!isShortString(str))
|
|
2431
|
+
throw new Error(`${str} is too long`);
|
|
2432
|
+
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
2433
|
+
}
|
|
2434
|
+
function decodeShortString(str) {
|
|
2435
|
+
if (!isASCII(str))
|
|
2436
|
+
throw new Error(`${str} is not an ASCII string`);
|
|
2437
|
+
if (isHex(str)) {
|
|
2438
|
+
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
2439
|
+
}
|
|
2440
|
+
if (isDecimalString(str)) {
|
|
2441
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
2442
|
+
}
|
|
2443
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2306
2446
|
// src/utils/calldata/cairo.ts
|
|
2307
2447
|
var cairo_exports = {};
|
|
2308
2448
|
__export(cairo_exports, {
|
|
@@ -2324,144 +2464,6 @@ __export(cairo_exports, {
|
|
|
2324
2464
|
uint256: () => uint256
|
|
2325
2465
|
});
|
|
2326
2466
|
|
|
2327
|
-
// src/utils/num.ts
|
|
2328
|
-
var num_exports = {};
|
|
2329
|
-
__export(num_exports, {
|
|
2330
|
-
assertInRange: () => assertInRange,
|
|
2331
|
-
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
2332
|
-
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
2333
|
-
cleanHex: () => cleanHex,
|
|
2334
|
-
getDecimalString: () => getDecimalString,
|
|
2335
|
-
getHexString: () => getHexString,
|
|
2336
|
-
getHexStringArray: () => getHexStringArray,
|
|
2337
|
-
hexToBytes: () => hexToBytes,
|
|
2338
|
-
hexToDecimalString: () => hexToDecimalString,
|
|
2339
|
-
isBigInt: () => isBigInt,
|
|
2340
|
-
isHex: () => isHex,
|
|
2341
|
-
isStringWholeNumber: () => isStringWholeNumber,
|
|
2342
|
-
toBigInt: () => toBigInt,
|
|
2343
|
-
toCairoBool: () => toCairoBool,
|
|
2344
|
-
toHex: () => toHex,
|
|
2345
|
-
toHexString: () => toHexString
|
|
2346
|
-
});
|
|
2347
|
-
var import_utils = require("@noble/curves/abstract/utils");
|
|
2348
|
-
function isHex(hex) {
|
|
2349
|
-
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2350
|
-
}
|
|
2351
|
-
function toBigInt(value) {
|
|
2352
|
-
return BigInt(value);
|
|
2353
|
-
}
|
|
2354
|
-
function isBigInt(value) {
|
|
2355
|
-
return typeof value === "bigint";
|
|
2356
|
-
}
|
|
2357
|
-
function toHex(number2) {
|
|
2358
|
-
return addHexPrefix(toBigInt(number2).toString(16));
|
|
2359
|
-
}
|
|
2360
|
-
function hexToDecimalString(hex) {
|
|
2361
|
-
return BigInt(addHexPrefix(hex)).toString(10);
|
|
2362
|
-
}
|
|
2363
|
-
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
2364
|
-
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
2365
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
2366
|
-
const inputBigInt = BigInt(input);
|
|
2367
|
-
const lowerBoundBigInt = BigInt(lowerBound);
|
|
2368
|
-
const upperBoundBigInt = BigInt(upperBound);
|
|
2369
|
-
assert(
|
|
2370
|
-
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
2371
|
-
`Message not signable, ${messageSuffix}.`
|
|
2372
|
-
);
|
|
2373
|
-
}
|
|
2374
|
-
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
2375
|
-
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
2376
|
-
}
|
|
2377
|
-
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
2378
|
-
return rawCalldata.map((x) => toHex(x));
|
|
2379
|
-
}
|
|
2380
|
-
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
2381
|
-
var toHexString = (value) => toHex(value);
|
|
2382
|
-
function getDecimalString(value) {
|
|
2383
|
-
if (isHex(value)) {
|
|
2384
|
-
return hexToDecimalString(value);
|
|
2385
|
-
}
|
|
2386
|
-
if (isStringWholeNumber(value)) {
|
|
2387
|
-
return value;
|
|
2388
|
-
}
|
|
2389
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2390
|
-
}
|
|
2391
|
-
function getHexString(value) {
|
|
2392
|
-
if (isHex(value)) {
|
|
2393
|
-
return value;
|
|
2394
|
-
}
|
|
2395
|
-
if (isStringWholeNumber(value)) {
|
|
2396
|
-
return toHexString(value);
|
|
2397
|
-
}
|
|
2398
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2399
|
-
}
|
|
2400
|
-
function getHexStringArray(value) {
|
|
2401
|
-
return value.map((el) => getHexString(el));
|
|
2402
|
-
}
|
|
2403
|
-
var toCairoBool = (value) => (+value).toString();
|
|
2404
|
-
function hexToBytes(value) {
|
|
2405
|
-
if (!isHex(value))
|
|
2406
|
-
throw new Error(`${value} need to be a hex-string`);
|
|
2407
|
-
let adaptedValue = removeHexPrefix(value);
|
|
2408
|
-
if (adaptedValue.length % 2 !== 0) {
|
|
2409
|
-
adaptedValue = `0${adaptedValue}`;
|
|
2410
|
-
}
|
|
2411
|
-
return (0, import_utils.hexToBytes)(adaptedValue);
|
|
2412
|
-
}
|
|
2413
|
-
|
|
2414
|
-
// src/utils/shortString.ts
|
|
2415
|
-
var shortString_exports = {};
|
|
2416
|
-
__export(shortString_exports, {
|
|
2417
|
-
decodeShortString: () => decodeShortString,
|
|
2418
|
-
encodeShortString: () => encodeShortString,
|
|
2419
|
-
isASCII: () => isASCII,
|
|
2420
|
-
isDecimalString: () => isDecimalString,
|
|
2421
|
-
isLongText: () => isLongText,
|
|
2422
|
-
isShortString: () => isShortString,
|
|
2423
|
-
isShortText: () => isShortText,
|
|
2424
|
-
isText: () => isText,
|
|
2425
|
-
splitLongString: () => splitLongString
|
|
2426
|
-
});
|
|
2427
|
-
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
2428
|
-
function isASCII(str) {
|
|
2429
|
-
return /^[\x00-\x7F]*$/.test(str);
|
|
2430
|
-
}
|
|
2431
|
-
function isShortString(str) {
|
|
2432
|
-
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
2433
|
-
}
|
|
2434
|
-
function isDecimalString(decim) {
|
|
2435
|
-
return /^[0-9]*$/i.test(decim);
|
|
2436
|
-
}
|
|
2437
|
-
function isText(val) {
|
|
2438
|
-
return typeof val === "string" && !isHex(val) && !isStringWholeNumber(val);
|
|
2439
|
-
}
|
|
2440
|
-
var isShortText = (val) => isText(val) && isShortString(val);
|
|
2441
|
-
var isLongText = (val) => isText(val) && !isShortString(val);
|
|
2442
|
-
function splitLongString(longStr) {
|
|
2443
|
-
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
2444
|
-
return longStr.match(regex) || [];
|
|
2445
|
-
}
|
|
2446
|
-
function encodeShortString(str) {
|
|
2447
|
-
if (!isASCII(str))
|
|
2448
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
2449
|
-
if (!isShortString(str))
|
|
2450
|
-
throw new Error(`${str} is too long`);
|
|
2451
|
-
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
2452
|
-
}
|
|
2453
|
-
function decodeShortString(str) {
|
|
2454
|
-
if (!isASCII(str))
|
|
2455
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
2456
|
-
if (isHex(str)) {
|
|
2457
|
-
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
2458
|
-
}
|
|
2459
|
-
if (isDecimalString(str)) {
|
|
2460
|
-
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
2461
|
-
}
|
|
2462
|
-
throw new Error(`${str} is not Hex or decimal`);
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
2467
|
// src/utils/uint256.ts
|
|
2466
2468
|
var uint256_exports = {};
|
|
2467
2469
|
__export(uint256_exports, {
|
|
@@ -2501,7 +2503,7 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
|
|
|
2501
2503
|
})(Uint || {});
|
|
2502
2504
|
var isLen = (name) => /_len$/.test(name);
|
|
2503
2505
|
var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
2504
|
-
var isTypeArray = (type) => /\*/.test(type) || type.
|
|
2506
|
+
var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::");
|
|
2505
2507
|
var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
|
|
2506
2508
|
var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
|
|
2507
2509
|
var isTypeStruct = (type, structs) => type in structs;
|
|
@@ -2512,7 +2514,7 @@ var isTypeContractAddress = (type) => type === "core::starknet::contract_address
|
|
|
2512
2514
|
var isCairo1Type = (type) => type.includes("core::");
|
|
2513
2515
|
var getArrayType = (type) => {
|
|
2514
2516
|
if (isCairo1Type(type)) {
|
|
2515
|
-
return type.substring(type.indexOf("<") + 1, type.
|
|
2517
|
+
return type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
|
|
2516
2518
|
}
|
|
2517
2519
|
return type.replace("*", "");
|
|
2518
2520
|
};
|
|
@@ -2535,277 +2537,19 @@ function felt(it) {
|
|
|
2535
2537
|
throw new Error(
|
|
2536
2538
|
`${it} is a long string > 31 chars, felt can store short strings, split it to array of short strings`
|
|
2537
2539
|
);
|
|
2538
|
-
const encoded = encodeShortString(it);
|
|
2539
|
-
return BigInt(encoded).toString();
|
|
2540
|
-
}
|
|
2541
|
-
if (typeof it === "string" && isHex(it)) {
|
|
2542
|
-
return BigInt(it).toString();
|
|
2543
|
-
}
|
|
2544
|
-
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2545
|
-
return it;
|
|
2546
|
-
}
|
|
2547
|
-
if (typeof it === "boolean") {
|
|
2548
|
-
return `${+it}`;
|
|
2549
|
-
}
|
|
2550
|
-
throw new Error(`${it} can't be computed by felt()`);
|
|
2551
|
-
}
|
|
2552
|
-
|
|
2553
|
-
// src/utils/ec.ts
|
|
2554
|
-
var ec_exports = {};
|
|
2555
|
-
__export(ec_exports, {
|
|
2556
|
-
starkCurve: () => starkCurve,
|
|
2557
|
-
weierstrass: () => weierstrass
|
|
2558
|
-
});
|
|
2559
|
-
var starkCurve = __toESM(require("micro-starknet"));
|
|
2560
|
-
var weierstrass = __toESM(require("@noble/curves/abstract/weierstrass"));
|
|
2561
|
-
|
|
2562
|
-
// src/utils/json.ts
|
|
2563
|
-
var json_exports = {};
|
|
2564
|
-
__export(json_exports, {
|
|
2565
|
-
parse: () => parse2,
|
|
2566
|
-
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
2567
|
-
stringify: () => stringify2,
|
|
2568
|
-
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
2569
|
-
});
|
|
2570
|
-
var json = __toESM(require("lossless-json"));
|
|
2571
|
-
var parseIntAsNumberOrBigInt = (x) => {
|
|
2572
|
-
if (!json.isInteger(x))
|
|
2573
|
-
return parseFloat(x);
|
|
2574
|
-
const v = parseInt(x, 10);
|
|
2575
|
-
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
2576
|
-
};
|
|
2577
|
-
var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
2578
|
-
var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
|
|
2579
|
-
var stringify2 = (...p) => json.stringify(...p);
|
|
2580
|
-
var stringifyAlwaysAsBig = stringify2;
|
|
2581
|
-
|
|
2582
|
-
// src/utils/hash.ts
|
|
2583
|
-
var poseidon = __toESM(require("@noble/curves/abstract/poseidon"));
|
|
2584
|
-
var transactionVersion = 1n;
|
|
2585
|
-
var transactionVersion_2 = 2n;
|
|
2586
|
-
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
2587
|
-
function keccakBn(value) {
|
|
2588
|
-
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2589
|
-
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2590
|
-
return addHexPrefix((0, import_micro_starknet.keccak)(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2591
|
-
}
|
|
2592
|
-
function keccakHex(value) {
|
|
2593
|
-
return addHexPrefix((0, import_micro_starknet.keccak)(utf8ToArray(value)).toString(16));
|
|
2594
|
-
}
|
|
2595
|
-
function starknetKeccak(value) {
|
|
2596
|
-
const hash = BigInt(keccakHex(value));
|
|
2597
|
-
return hash & MASK_250;
|
|
2598
|
-
}
|
|
2599
|
-
function getSelectorFromName(funcName) {
|
|
2600
|
-
return toHex(starknetKeccak(funcName));
|
|
2601
|
-
}
|
|
2602
|
-
function getSelector(value) {
|
|
2603
|
-
if (isHex(value)) {
|
|
2604
|
-
return value;
|
|
2605
|
-
}
|
|
2606
|
-
if (isStringWholeNumber(value)) {
|
|
2607
|
-
return toHexString(value);
|
|
2608
|
-
}
|
|
2609
|
-
return getSelectorFromName(value);
|
|
2610
|
-
}
|
|
2611
|
-
function computeHashOnElements(data) {
|
|
2612
|
-
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
2613
|
-
}
|
|
2614
|
-
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
2615
|
-
const calldataHash = computeHashOnElements(calldata);
|
|
2616
|
-
const dataToHash = [
|
|
2617
|
-
txHashPrefix,
|
|
2618
|
-
version,
|
|
2619
|
-
contractAddress,
|
|
2620
|
-
entryPointSelector,
|
|
2621
|
-
calldataHash,
|
|
2622
|
-
maxFee,
|
|
2623
|
-
chainId,
|
|
2624
|
-
...additionalData
|
|
2625
|
-
];
|
|
2626
|
-
return computeHashOnElements(dataToHash);
|
|
2627
|
-
}
|
|
2628
|
-
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
2629
|
-
return calculateTransactionHashCommon(
|
|
2630
|
-
"0x6465706c6f79" /* DEPLOY */,
|
|
2631
|
-
version,
|
|
2632
|
-
contractAddress,
|
|
2633
|
-
getSelectorFromName("constructor"),
|
|
2634
|
-
constructorCalldata,
|
|
2635
|
-
0,
|
|
2636
|
-
chainId
|
|
2637
|
-
);
|
|
2638
|
-
}
|
|
2639
|
-
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
2640
|
-
return calculateTransactionHashCommon(
|
|
2641
|
-
"0x6465636c617265" /* DECLARE */,
|
|
2642
|
-
version,
|
|
2643
|
-
senderAddress,
|
|
2644
|
-
0,
|
|
2645
|
-
[classHash],
|
|
2646
|
-
maxFee,
|
|
2647
|
-
chainId,
|
|
2648
|
-
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
2649
|
-
);
|
|
2650
|
-
}
|
|
2651
|
-
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
2652
|
-
const calldata = [classHash, salt, ...constructorCalldata];
|
|
2653
|
-
return calculateTransactionHashCommon(
|
|
2654
|
-
"0x6465706c6f795f6163636f756e74" /* DEPLOY_ACCOUNT */,
|
|
2655
|
-
version,
|
|
2656
|
-
contractAddress,
|
|
2657
|
-
0,
|
|
2658
|
-
calldata,
|
|
2659
|
-
maxFee,
|
|
2660
|
-
chainId,
|
|
2661
|
-
[nonce]
|
|
2662
|
-
);
|
|
2663
|
-
}
|
|
2664
|
-
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
2665
|
-
return calculateTransactionHashCommon(
|
|
2666
|
-
"0x696e766f6b65" /* INVOKE */,
|
|
2667
|
-
version,
|
|
2668
|
-
contractAddress,
|
|
2669
|
-
0,
|
|
2670
|
-
calldata,
|
|
2671
|
-
maxFee,
|
|
2672
|
-
chainId,
|
|
2673
|
-
[nonce]
|
|
2674
|
-
);
|
|
2675
|
-
}
|
|
2676
|
-
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
2677
|
-
const constructorCalldataHash = computeHashOnElements(constructorCalldata);
|
|
2678
|
-
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
2679
|
-
return computeHashOnElements([
|
|
2680
|
-
CONTRACT_ADDRESS_PREFIX,
|
|
2681
|
-
deployerAddress,
|
|
2682
|
-
salt,
|
|
2683
|
-
classHash,
|
|
2684
|
-
constructorCalldataHash
|
|
2685
|
-
]);
|
|
2686
|
-
}
|
|
2687
|
-
function nullSkipReplacer(key, value) {
|
|
2688
|
-
if (key === "attributes" || key === "accessible_scopes") {
|
|
2689
|
-
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
2690
|
-
}
|
|
2691
|
-
if (key === "debug_info") {
|
|
2692
|
-
return null;
|
|
2693
|
-
}
|
|
2694
|
-
return value === null ? void 0 : value;
|
|
2695
|
-
}
|
|
2696
|
-
function formatSpaces(json2) {
|
|
2697
|
-
let insideQuotes = false;
|
|
2698
|
-
let newString = "";
|
|
2699
|
-
for (const char of json2) {
|
|
2700
|
-
if (char === '"' && newString.endsWith("\\") === false) {
|
|
2701
|
-
insideQuotes = !insideQuotes;
|
|
2702
|
-
}
|
|
2703
|
-
if (insideQuotes) {
|
|
2704
|
-
newString += char;
|
|
2705
|
-
} else {
|
|
2706
|
-
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
return newString;
|
|
2710
|
-
}
|
|
2711
|
-
function computeHintedClassHash(compiledContract) {
|
|
2712
|
-
const { abi, program } = compiledContract;
|
|
2713
|
-
const contractClass = { abi, program };
|
|
2714
|
-
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
2715
|
-
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
2716
|
-
}
|
|
2717
|
-
function computeLegacyContractClassHash(contract) {
|
|
2718
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2719
|
-
const apiVersion = toHex(API_VERSION);
|
|
2720
|
-
const externalEntryPointsHash = computeHashOnElements(
|
|
2721
|
-
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
2722
|
-
);
|
|
2723
|
-
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
2724
|
-
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
2725
|
-
);
|
|
2726
|
-
const constructorEntryPointHash = computeHashOnElements(
|
|
2727
|
-
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
2728
|
-
);
|
|
2729
|
-
const builtinsHash = computeHashOnElements(
|
|
2730
|
-
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
2731
|
-
);
|
|
2732
|
-
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
2733
|
-
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
2734
|
-
return computeHashOnElements([
|
|
2735
|
-
apiVersion,
|
|
2736
|
-
externalEntryPointsHash,
|
|
2737
|
-
l1HandlerEntryPointsHash,
|
|
2738
|
-
constructorEntryPointHash,
|
|
2739
|
-
builtinsHash,
|
|
2740
|
-
hintedClassHash,
|
|
2741
|
-
dataHash
|
|
2742
|
-
]);
|
|
2743
|
-
}
|
|
2744
|
-
function hashBuiltins(builtins) {
|
|
2745
|
-
return (0, import_micro_starknet.poseidonHashMany)(
|
|
2746
|
-
builtins.flatMap((it) => {
|
|
2747
|
-
return BigInt(encodeShortString(it));
|
|
2748
|
-
})
|
|
2749
|
-
);
|
|
2750
|
-
}
|
|
2751
|
-
function hashEntryPoint(data) {
|
|
2752
|
-
const base = data.flatMap((it) => {
|
|
2753
|
-
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
2754
|
-
});
|
|
2755
|
-
return (0, import_micro_starknet.poseidonHashMany)(base);
|
|
2756
|
-
}
|
|
2757
|
-
function computeCompiledClassHash(casm) {
|
|
2758
|
-
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
2759
|
-
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
2760
|
-
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
2761
|
-
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
2762
|
-
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
2763
|
-
const bytecode = (0, import_micro_starknet.poseidonHashMany)(casm.bytecode.map((it) => BigInt(it)));
|
|
2764
|
-
return toHex(
|
|
2765
|
-
(0, import_micro_starknet.poseidonHashMany)([
|
|
2766
|
-
compiledClassVersion,
|
|
2767
|
-
externalEntryPointsHash,
|
|
2768
|
-
l1Handlers,
|
|
2769
|
-
constructor,
|
|
2770
|
-
bytecode
|
|
2771
|
-
])
|
|
2772
|
-
);
|
|
2773
|
-
}
|
|
2774
|
-
function hashEntryPointSierra(data) {
|
|
2775
|
-
const base = data.flatMap((it) => {
|
|
2776
|
-
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
2777
|
-
});
|
|
2778
|
-
return (0, import_micro_starknet.poseidonHashMany)(base);
|
|
2779
|
-
}
|
|
2780
|
-
function hashAbi(sierra) {
|
|
2781
|
-
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
2782
|
-
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
2783
|
-
}
|
|
2784
|
-
function computeSierraContractClassHash(sierra) {
|
|
2785
|
-
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
2786
|
-
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
2787
|
-
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
2788
|
-
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
2789
|
-
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
2790
|
-
const abiHash = hashAbi(sierra);
|
|
2791
|
-
const sierraProgram = (0, import_micro_starknet.poseidonHashMany)(sierra.sierra_program.map((it) => BigInt(it)));
|
|
2792
|
-
return toHex(
|
|
2793
|
-
(0, import_micro_starknet.poseidonHashMany)([
|
|
2794
|
-
compiledClassVersion,
|
|
2795
|
-
externalEntryPointsHash,
|
|
2796
|
-
l1Handlers,
|
|
2797
|
-
constructor,
|
|
2798
|
-
abiHash,
|
|
2799
|
-
sierraProgram
|
|
2800
|
-
])
|
|
2801
|
-
);
|
|
2802
|
-
}
|
|
2803
|
-
function computeContractClassHash(contract) {
|
|
2804
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2805
|
-
if ("sierra_program" in compiledContract) {
|
|
2806
|
-
return computeSierraContractClassHash(compiledContract);
|
|
2540
|
+
const encoded = encodeShortString(it);
|
|
2541
|
+
return BigInt(encoded).toString();
|
|
2807
2542
|
}
|
|
2808
|
-
|
|
2543
|
+
if (typeof it === "string" && isHex(it)) {
|
|
2544
|
+
return BigInt(it).toString();
|
|
2545
|
+
}
|
|
2546
|
+
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
2547
|
+
return it;
|
|
2548
|
+
}
|
|
2549
|
+
if (typeof it === "boolean") {
|
|
2550
|
+
return `${+it}`;
|
|
2551
|
+
}
|
|
2552
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
2809
2553
|
}
|
|
2810
2554
|
|
|
2811
2555
|
// src/utils/calldata/formatter.ts
|
|
@@ -2956,7 +2700,12 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2956
2700
|
throw Error(`Missing parameter for type ${type}`);
|
|
2957
2701
|
}
|
|
2958
2702
|
if (Array.isArray(element)) {
|
|
2959
|
-
|
|
2703
|
+
const result = [];
|
|
2704
|
+
result.push(felt(element.length));
|
|
2705
|
+
const arrayType = getArrayType(type);
|
|
2706
|
+
return element.reduce((acc, it) => {
|
|
2707
|
+
return acc.concat(parseCalldataValue(it, arrayType, structs));
|
|
2708
|
+
}, result);
|
|
2960
2709
|
}
|
|
2961
2710
|
if (structs[type] && structs[type].members.length) {
|
|
2962
2711
|
const { members } = structs[type];
|
|
@@ -2988,17 +2737,7 @@ function parseCalldataField(argsIterator, input, structs) {
|
|
|
2988
2737
|
if (typeof value === "string") {
|
|
2989
2738
|
value = splitLongString(value);
|
|
2990
2739
|
}
|
|
2991
|
-
|
|
2992
|
-
result.push(felt(value.length));
|
|
2993
|
-
const arrayType = getArrayType(input.type);
|
|
2994
|
-
return value.reduce((acc, el) => {
|
|
2995
|
-
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
2996
|
-
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
2997
|
-
} else {
|
|
2998
|
-
return acc.concat(parseBaseTypes(arrayType, el));
|
|
2999
|
-
}
|
|
3000
|
-
return acc;
|
|
3001
|
-
}, result);
|
|
2740
|
+
return parseCalldataValue(value, input.type, structs);
|
|
3002
2741
|
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
3003
2742
|
return parseCalldataValue(value, type, structs);
|
|
3004
2743
|
case isTypeUint256(type):
|
|
@@ -3028,23 +2767,33 @@ function parseBaseTypes2(type, it) {
|
|
|
3028
2767
|
return BigInt(temp);
|
|
3029
2768
|
}
|
|
3030
2769
|
}
|
|
3031
|
-
function
|
|
3032
|
-
if (type in structs && structs[type]) {
|
|
3033
|
-
return structs[type].members.reduce((acc, el) => {
|
|
3034
|
-
acc[el.name] =
|
|
2770
|
+
function parseResponseValue(responseIterator, element, structs) {
|
|
2771
|
+
if (element.type in structs && structs[element.type]) {
|
|
2772
|
+
return structs[element.type].members.reduce((acc, el) => {
|
|
2773
|
+
acc[el.name] = parseResponseValue(responseIterator, el, structs);
|
|
3035
2774
|
return acc;
|
|
3036
2775
|
}, {});
|
|
3037
2776
|
}
|
|
3038
|
-
if (isTypeTuple(type)) {
|
|
3039
|
-
const memberTypes = extractTupleMemberTypes(type);
|
|
2777
|
+
if (isTypeTuple(element.type)) {
|
|
2778
|
+
const memberTypes = extractTupleMemberTypes(element.type);
|
|
3040
2779
|
return memberTypes.reduce((acc, it, idx) => {
|
|
3041
|
-
const
|
|
3042
|
-
const
|
|
3043
|
-
|
|
2780
|
+
const name = (it == null ? void 0 : it.name) ? it.name : idx;
|
|
2781
|
+
const type = (it == null ? void 0 : it.type) ? it.type : it;
|
|
2782
|
+
const el = { name, type };
|
|
2783
|
+
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
3044
2784
|
return acc;
|
|
3045
2785
|
}, {});
|
|
3046
2786
|
}
|
|
3047
|
-
|
|
2787
|
+
if (isTypeArray(element.type)) {
|
|
2788
|
+
const parsedDataArr = [];
|
|
2789
|
+
const el = { name: "", type: getArrayType(element.type) };
|
|
2790
|
+
const len = BigInt(responseIterator.next().value);
|
|
2791
|
+
while (parsedDataArr.length < len) {
|
|
2792
|
+
parsedDataArr.push(parseResponseValue(responseIterator, el, structs));
|
|
2793
|
+
}
|
|
2794
|
+
return parsedDataArr;
|
|
2795
|
+
}
|
|
2796
|
+
return parseBaseTypes2(element.type, responseIterator);
|
|
3048
2797
|
}
|
|
3049
2798
|
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3050
2799
|
const { name, type } = output;
|
|
@@ -3053,27 +2802,26 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
3053
2802
|
case isLen(name):
|
|
3054
2803
|
temp = responseIterator.next().value;
|
|
3055
2804
|
return BigInt(temp);
|
|
2805
|
+
case (type in structs || isTypeTuple(type)):
|
|
2806
|
+
return parseResponseValue(responseIterator, output, structs);
|
|
3056
2807
|
case isTypeArray(type):
|
|
3057
|
-
const parsedDataArr = [];
|
|
3058
2808
|
if (isCairo1Type(type)) {
|
|
3059
|
-
|
|
3060
|
-
const len = BigInt(responseIterator.next().value);
|
|
3061
|
-
while (parsedDataArr.length < len) {
|
|
3062
|
-
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
3063
|
-
}
|
|
3064
|
-
return parsedDataArr;
|
|
2809
|
+
return parseResponseValue(responseIterator, output, structs);
|
|
3065
2810
|
}
|
|
2811
|
+
const parsedDataArr = [];
|
|
3066
2812
|
if (parsedResult && parsedResult[`${name}_len`]) {
|
|
3067
2813
|
const arrLen = parsedResult[`${name}_len`];
|
|
3068
2814
|
while (parsedDataArr.length < arrLen) {
|
|
3069
2815
|
parsedDataArr.push(
|
|
3070
|
-
|
|
2816
|
+
parseResponseValue(
|
|
2817
|
+
responseIterator,
|
|
2818
|
+
{ name, type: output.type.replace("*", "") },
|
|
2819
|
+
structs
|
|
2820
|
+
)
|
|
3071
2821
|
);
|
|
3072
2822
|
}
|
|
3073
2823
|
}
|
|
3074
2824
|
return parsedDataArr;
|
|
3075
|
-
case (type in structs || isTypeTuple(type)):
|
|
3076
|
-
return parseResponseStruct(responseIterator, type, structs);
|
|
3077
2825
|
default:
|
|
3078
2826
|
return parseBaseTypes2(type, responseIterator);
|
|
3079
2827
|
}
|
|
@@ -3186,6 +2934,11 @@ var validateArray = (parameter, input, structs) => {
|
|
|
3186
2934
|
case isTypeBool(baseType):
|
|
3187
2935
|
parameter.forEach((param) => validateBool(param, input));
|
|
3188
2936
|
break;
|
|
2937
|
+
case isTypeArray(baseType):
|
|
2938
|
+
parameter.forEach(
|
|
2939
|
+
(param) => validateArray(param, { name: "", type: baseType }, structs)
|
|
2940
|
+
);
|
|
2941
|
+
break;
|
|
3189
2942
|
default:
|
|
3190
2943
|
throw new Error(
|
|
3191
2944
|
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
@@ -3226,120 +2979,382 @@ function validateFields(abiMethod, args, structs) {
|
|
|
3226
2979
|
return acc + 1;
|
|
3227
2980
|
}, 0);
|
|
3228
2981
|
}
|
|
3229
|
-
|
|
3230
|
-
// src/utils/calldata/index.ts
|
|
3231
|
-
var CallData = class {
|
|
3232
|
-
constructor(abi) {
|
|
3233
|
-
this.abi = abi;
|
|
3234
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
3235
|
-
}
|
|
3236
|
-
validate(type, method, args = []) {
|
|
3237
|
-
if (type !== "DEPLOY") {
|
|
3238
|
-
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
3239
|
-
if (abi.type !== "function")
|
|
3240
|
-
return false;
|
|
3241
|
-
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
3242
|
-
return type === "INVOKE" ? !isView : isView;
|
|
3243
|
-
}).map((abi) => abi.name);
|
|
3244
|
-
assert(
|
|
3245
|
-
invocableFunctionNames.includes(method),
|
|
3246
|
-
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3247
|
-
);
|
|
3248
|
-
}
|
|
3249
|
-
const abiMethod = this.abi.find(
|
|
3250
|
-
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3251
|
-
);
|
|
3252
|
-
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3253
|
-
if (args.length !== inputsLength) {
|
|
3254
|
-
throw Error(
|
|
3255
|
-
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3256
|
-
);
|
|
3257
|
-
}
|
|
3258
|
-
validateFields(abiMethod, args, this.structs);
|
|
2982
|
+
|
|
2983
|
+
// src/utils/calldata/index.ts
|
|
2984
|
+
var CallData = class {
|
|
2985
|
+
constructor(abi) {
|
|
2986
|
+
this.abi = abi;
|
|
2987
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
2988
|
+
}
|
|
2989
|
+
validate(type, method, args = []) {
|
|
2990
|
+
if (type !== "DEPLOY") {
|
|
2991
|
+
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
2992
|
+
if (abi.type !== "function")
|
|
2993
|
+
return false;
|
|
2994
|
+
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
2995
|
+
return type === "INVOKE" ? !isView : isView;
|
|
2996
|
+
}).map((abi) => abi.name);
|
|
2997
|
+
assert(
|
|
2998
|
+
invocableFunctionNames.includes(method),
|
|
2999
|
+
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
const abiMethod = this.abi.find(
|
|
3003
|
+
(abi) => type === "DEPLOY" ? abi.name === method && abi.type === method : abi.name === method && abi.type === "function"
|
|
3004
|
+
);
|
|
3005
|
+
const inputsLength = CallData.abiInputsLength(abiMethod.inputs);
|
|
3006
|
+
if (args.length !== inputsLength) {
|
|
3007
|
+
throw Error(
|
|
3008
|
+
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
3011
|
+
validateFields(abiMethod, args, this.structs);
|
|
3012
|
+
}
|
|
3013
|
+
compile(method, args) {
|
|
3014
|
+
const argsIterator = args[Symbol.iterator]();
|
|
3015
|
+
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3016
|
+
return inputs.reduce(
|
|
3017
|
+
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3018
|
+
[]
|
|
3019
|
+
);
|
|
3020
|
+
}
|
|
3021
|
+
static compile(rawArgs) {
|
|
3022
|
+
const createTree = (obj) => {
|
|
3023
|
+
const getEntries = (o, prefix = "") => {
|
|
3024
|
+
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
3025
|
+
return Object.entries(oe).flatMap(([k, v]) => {
|
|
3026
|
+
let value = v;
|
|
3027
|
+
if (isLongText(value))
|
|
3028
|
+
value = splitLongString(value);
|
|
3029
|
+
if (k === "entrypoint")
|
|
3030
|
+
value = getSelectorFromName(value);
|
|
3031
|
+
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3032
|
+
if (isBigInt(value))
|
|
3033
|
+
return [[`${prefix}${kk}`, felt(value)]];
|
|
3034
|
+
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3035
|
+
});
|
|
3036
|
+
};
|
|
3037
|
+
return Object.fromEntries(getEntries(obj));
|
|
3038
|
+
};
|
|
3039
|
+
let callTreeArray;
|
|
3040
|
+
if (!Array.isArray(rawArgs)) {
|
|
3041
|
+
const callTree = createTree(rawArgs);
|
|
3042
|
+
callTreeArray = Object.values(callTree);
|
|
3043
|
+
} else {
|
|
3044
|
+
const callObj = { ...rawArgs };
|
|
3045
|
+
const callTree = createTree(callObj);
|
|
3046
|
+
callTreeArray = Object.values(callTree);
|
|
3047
|
+
}
|
|
3048
|
+
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3049
|
+
enumerable: false,
|
|
3050
|
+
writable: false,
|
|
3051
|
+
value: true
|
|
3052
|
+
});
|
|
3053
|
+
return callTreeArray;
|
|
3054
|
+
}
|
|
3055
|
+
parse(method, response) {
|
|
3056
|
+
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3057
|
+
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3058
|
+
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3059
|
+
const propName = output.name ?? idx;
|
|
3060
|
+
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3061
|
+
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3062
|
+
delete acc[`${propName}_len`];
|
|
3063
|
+
}
|
|
3064
|
+
return acc;
|
|
3065
|
+
}, {});
|
|
3066
|
+
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3067
|
+
}
|
|
3068
|
+
format(method, response, format) {
|
|
3069
|
+
const parsed = this.parse(method, response);
|
|
3070
|
+
return formatter(parsed, format);
|
|
3071
|
+
}
|
|
3072
|
+
static abiInputsLength(inputs) {
|
|
3073
|
+
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3074
|
+
}
|
|
3075
|
+
static getAbiStruct(abi) {
|
|
3076
|
+
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3077
|
+
(acc, abiEntry) => ({
|
|
3078
|
+
...acc,
|
|
3079
|
+
[abiEntry.name]: abiEntry
|
|
3080
|
+
}),
|
|
3081
|
+
{}
|
|
3082
|
+
);
|
|
3083
|
+
}
|
|
3084
|
+
static toCalldata(rawCalldata = []) {
|
|
3085
|
+
return CallData.compile(rawCalldata);
|
|
3086
|
+
}
|
|
3087
|
+
static toHex(raw = []) {
|
|
3088
|
+
const calldata = CallData.compile(raw);
|
|
3089
|
+
return calldata.map((it) => toHex(it));
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
|
|
3093
|
+
// src/utils/fetchPonyfill.ts
|
|
3094
|
+
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
3095
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
3096
|
+
|
|
3097
|
+
// src/utils/hash.ts
|
|
3098
|
+
var hash_exports = {};
|
|
3099
|
+
__export(hash_exports, {
|
|
3100
|
+
calculateContractAddressFromHash: () => calculateContractAddressFromHash,
|
|
3101
|
+
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash,
|
|
3102
|
+
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash,
|
|
3103
|
+
calculateDeployTransactionHash: () => calculateDeployTransactionHash,
|
|
3104
|
+
calculateTransactionHash: () => calculateTransactionHash,
|
|
3105
|
+
calculateTransactionHashCommon: () => calculateTransactionHashCommon,
|
|
3106
|
+
computeCompiledClassHash: () => computeCompiledClassHash,
|
|
3107
|
+
computeContractClassHash: () => computeContractClassHash,
|
|
3108
|
+
computeHashOnElements: () => computeHashOnElements,
|
|
3109
|
+
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
3110
|
+
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
3111
|
+
default: () => computeHintedClassHash,
|
|
3112
|
+
feeTransactionVersion: () => feeTransactionVersion,
|
|
3113
|
+
formatSpaces: () => formatSpaces,
|
|
3114
|
+
getSelector: () => getSelector,
|
|
3115
|
+
getSelectorFromName: () => getSelectorFromName,
|
|
3116
|
+
keccakBn: () => keccakBn,
|
|
3117
|
+
poseidon: () => poseidon,
|
|
3118
|
+
starknetKeccak: () => starknetKeccak,
|
|
3119
|
+
transactionVersion: () => transactionVersion,
|
|
3120
|
+
transactionVersion_2: () => transactionVersion_2
|
|
3121
|
+
});
|
|
3122
|
+
var import_micro_starknet2 = require("micro-starknet");
|
|
3123
|
+
|
|
3124
|
+
// src/utils/ec.ts
|
|
3125
|
+
var ec_exports = {};
|
|
3126
|
+
__export(ec_exports, {
|
|
3127
|
+
starkCurve: () => starkCurve,
|
|
3128
|
+
weierstrass: () => weierstrass
|
|
3129
|
+
});
|
|
3130
|
+
var starkCurve = __toESM(require("micro-starknet"));
|
|
3131
|
+
var weierstrass = __toESM(require("@noble/curves/abstract/weierstrass"));
|
|
3132
|
+
|
|
3133
|
+
// src/utils/json.ts
|
|
3134
|
+
var json_exports = {};
|
|
3135
|
+
__export(json_exports, {
|
|
3136
|
+
parse: () => parse2,
|
|
3137
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
3138
|
+
stringify: () => stringify2,
|
|
3139
|
+
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
3140
|
+
});
|
|
3141
|
+
var json = __toESM(require("lossless-json"));
|
|
3142
|
+
var parseIntAsNumberOrBigInt = (x) => {
|
|
3143
|
+
if (!json.isInteger(x))
|
|
3144
|
+
return parseFloat(x);
|
|
3145
|
+
const v = parseInt(x, 10);
|
|
3146
|
+
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
3147
|
+
};
|
|
3148
|
+
var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
3149
|
+
var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
|
|
3150
|
+
var stringify2 = (...p) => json.stringify(...p);
|
|
3151
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
3152
|
+
|
|
3153
|
+
// src/utils/hash.ts
|
|
3154
|
+
var poseidon = __toESM(require("@noble/curves/abstract/poseidon"));
|
|
3155
|
+
var transactionVersion = 1n;
|
|
3156
|
+
var transactionVersion_2 = 2n;
|
|
3157
|
+
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
3158
|
+
function computeHashOnElements(data) {
|
|
3159
|
+
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
3160
|
+
}
|
|
3161
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
3162
|
+
const calldataHash = computeHashOnElements(calldata);
|
|
3163
|
+
const dataToHash = [
|
|
3164
|
+
txHashPrefix,
|
|
3165
|
+
version,
|
|
3166
|
+
contractAddress,
|
|
3167
|
+
entryPointSelector,
|
|
3168
|
+
calldataHash,
|
|
3169
|
+
maxFee,
|
|
3170
|
+
chainId,
|
|
3171
|
+
...additionalData
|
|
3172
|
+
];
|
|
3173
|
+
return computeHashOnElements(dataToHash);
|
|
3174
|
+
}
|
|
3175
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
3176
|
+
return calculateTransactionHashCommon(
|
|
3177
|
+
"0x6465706c6f79" /* DEPLOY */,
|
|
3178
|
+
version,
|
|
3179
|
+
contractAddress,
|
|
3180
|
+
getSelectorFromName("constructor"),
|
|
3181
|
+
constructorCalldata,
|
|
3182
|
+
0,
|
|
3183
|
+
chainId
|
|
3184
|
+
);
|
|
3185
|
+
}
|
|
3186
|
+
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
3187
|
+
return calculateTransactionHashCommon(
|
|
3188
|
+
"0x6465636c617265" /* DECLARE */,
|
|
3189
|
+
version,
|
|
3190
|
+
senderAddress,
|
|
3191
|
+
0,
|
|
3192
|
+
[classHash],
|
|
3193
|
+
maxFee,
|
|
3194
|
+
chainId,
|
|
3195
|
+
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
3196
|
+
);
|
|
3197
|
+
}
|
|
3198
|
+
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
3199
|
+
const calldata = [classHash, salt, ...constructorCalldata];
|
|
3200
|
+
return calculateTransactionHashCommon(
|
|
3201
|
+
"0x6465706c6f795f6163636f756e74" /* DEPLOY_ACCOUNT */,
|
|
3202
|
+
version,
|
|
3203
|
+
contractAddress,
|
|
3204
|
+
0,
|
|
3205
|
+
calldata,
|
|
3206
|
+
maxFee,
|
|
3207
|
+
chainId,
|
|
3208
|
+
[nonce]
|
|
3209
|
+
);
|
|
3210
|
+
}
|
|
3211
|
+
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
3212
|
+
return calculateTransactionHashCommon(
|
|
3213
|
+
"0x696e766f6b65" /* INVOKE */,
|
|
3214
|
+
version,
|
|
3215
|
+
contractAddress,
|
|
3216
|
+
0,
|
|
3217
|
+
calldata,
|
|
3218
|
+
maxFee,
|
|
3219
|
+
chainId,
|
|
3220
|
+
[nonce]
|
|
3221
|
+
);
|
|
3222
|
+
}
|
|
3223
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
3224
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
3225
|
+
const constructorCalldataHash = computeHashOnElements(compiledCalldata);
|
|
3226
|
+
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
3227
|
+
return computeHashOnElements([
|
|
3228
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
3229
|
+
deployerAddress,
|
|
3230
|
+
salt,
|
|
3231
|
+
classHash,
|
|
3232
|
+
constructorCalldataHash
|
|
3233
|
+
]);
|
|
3234
|
+
}
|
|
3235
|
+
function nullSkipReplacer(key, value) {
|
|
3236
|
+
if (key === "attributes" || key === "accessible_scopes") {
|
|
3237
|
+
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
3259
3238
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
3263
|
-
return inputs.reduce(
|
|
3264
|
-
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
3265
|
-
[]
|
|
3266
|
-
);
|
|
3239
|
+
if (key === "debug_info") {
|
|
3240
|
+
return null;
|
|
3267
3241
|
}
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
if (isBigInt(value))
|
|
3280
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
3281
|
-
return Object(value) === value ? getEntries(value, `${prefix}${kk}.`) : [[`${prefix}${kk}`, felt(value)]];
|
|
3282
|
-
});
|
|
3283
|
-
};
|
|
3284
|
-
return Object.fromEntries(getEntries(obj));
|
|
3285
|
-
};
|
|
3286
|
-
let callTreeArray;
|
|
3287
|
-
if (!Array.isArray(rawArgs)) {
|
|
3288
|
-
const callTree = createTree(rawArgs);
|
|
3289
|
-
callTreeArray = Object.values(callTree);
|
|
3242
|
+
return value === null ? void 0 : value;
|
|
3243
|
+
}
|
|
3244
|
+
function formatSpaces(json2) {
|
|
3245
|
+
let insideQuotes = false;
|
|
3246
|
+
let newString = "";
|
|
3247
|
+
for (const char of json2) {
|
|
3248
|
+
if (char === '"' && newString.endsWith("\\") === false) {
|
|
3249
|
+
insideQuotes = !insideQuotes;
|
|
3250
|
+
}
|
|
3251
|
+
if (insideQuotes) {
|
|
3252
|
+
newString += char;
|
|
3290
3253
|
} else {
|
|
3291
|
-
|
|
3292
|
-
const callTree = createTree(callObj);
|
|
3293
|
-
callTreeArray = Object.values(callTree);
|
|
3254
|
+
newString += char === ":" ? ": " : char === "," ? ", " : char;
|
|
3294
3255
|
}
|
|
3295
|
-
Object.defineProperty(callTreeArray, "__compiled__", {
|
|
3296
|
-
enumerable: false,
|
|
3297
|
-
writable: false,
|
|
3298
|
-
value: true
|
|
3299
|
-
});
|
|
3300
|
-
return callTreeArray;
|
|
3301
|
-
}
|
|
3302
|
-
parse(method, response) {
|
|
3303
|
-
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
3304
|
-
const responseIterator = response.flat()[Symbol.iterator]();
|
|
3305
|
-
const parsed = outputs.flat().reduce((acc, output, idx) => {
|
|
3306
|
-
const propName = output.name ?? idx;
|
|
3307
|
-
acc[propName] = responseParser(responseIterator, output, this.structs, acc);
|
|
3308
|
-
if (acc[propName] && acc[`${propName}_len`]) {
|
|
3309
|
-
delete acc[`${propName}_len`];
|
|
3310
|
-
}
|
|
3311
|
-
return acc;
|
|
3312
|
-
}, {});
|
|
3313
|
-
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
3314
|
-
}
|
|
3315
|
-
format(method, response, format) {
|
|
3316
|
-
const parsed = this.parse(method, response);
|
|
3317
|
-
return formatter(parsed, format);
|
|
3318
|
-
}
|
|
3319
|
-
static abiInputsLength(inputs) {
|
|
3320
|
-
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3321
|
-
}
|
|
3322
|
-
static getAbiStruct(abi) {
|
|
3323
|
-
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
3324
|
-
(acc, abiEntry) => ({
|
|
3325
|
-
...acc,
|
|
3326
|
-
[abiEntry.name]: abiEntry
|
|
3327
|
-
}),
|
|
3328
|
-
{}
|
|
3329
|
-
);
|
|
3330
|
-
}
|
|
3331
|
-
static toCalldata(rawCalldata = []) {
|
|
3332
|
-
return CallData.compile(rawCalldata);
|
|
3333
3256
|
}
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3257
|
+
return newString;
|
|
3258
|
+
}
|
|
3259
|
+
function computeHintedClassHash(compiledContract) {
|
|
3260
|
+
const { abi, program } = compiledContract;
|
|
3261
|
+
const contractClass = { abi, program };
|
|
3262
|
+
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
3263
|
+
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
3264
|
+
}
|
|
3265
|
+
function computeLegacyContractClassHash(contract) {
|
|
3266
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3267
|
+
const apiVersion = toHex(API_VERSION);
|
|
3268
|
+
const externalEntryPointsHash = computeHashOnElements(
|
|
3269
|
+
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
3270
|
+
);
|
|
3271
|
+
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
3272
|
+
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
3273
|
+
);
|
|
3274
|
+
const constructorEntryPointHash = computeHashOnElements(
|
|
3275
|
+
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
3276
|
+
);
|
|
3277
|
+
const builtinsHash = computeHashOnElements(
|
|
3278
|
+
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
3279
|
+
);
|
|
3280
|
+
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
3281
|
+
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
3282
|
+
return computeHashOnElements([
|
|
3283
|
+
apiVersion,
|
|
3284
|
+
externalEntryPointsHash,
|
|
3285
|
+
l1HandlerEntryPointsHash,
|
|
3286
|
+
constructorEntryPointHash,
|
|
3287
|
+
builtinsHash,
|
|
3288
|
+
hintedClassHash,
|
|
3289
|
+
dataHash
|
|
3290
|
+
]);
|
|
3291
|
+
}
|
|
3292
|
+
function hashBuiltins(builtins) {
|
|
3293
|
+
return (0, import_micro_starknet2.poseidonHashMany)(
|
|
3294
|
+
builtins.flatMap((it) => {
|
|
3295
|
+
return BigInt(encodeShortString(it));
|
|
3296
|
+
})
|
|
3297
|
+
);
|
|
3298
|
+
}
|
|
3299
|
+
function hashEntryPoint(data) {
|
|
3300
|
+
const base = data.flatMap((it) => {
|
|
3301
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
3302
|
+
});
|
|
3303
|
+
return (0, import_micro_starknet2.poseidonHashMany)(base);
|
|
3304
|
+
}
|
|
3305
|
+
function computeCompiledClassHash(casm) {
|
|
3306
|
+
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
3307
|
+
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
3308
|
+
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
3309
|
+
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
3310
|
+
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
3311
|
+
const bytecode = (0, import_micro_starknet2.poseidonHashMany)(casm.bytecode.map((it) => BigInt(it)));
|
|
3312
|
+
return toHex(
|
|
3313
|
+
(0, import_micro_starknet2.poseidonHashMany)([
|
|
3314
|
+
compiledClassVersion,
|
|
3315
|
+
externalEntryPointsHash,
|
|
3316
|
+
l1Handlers,
|
|
3317
|
+
constructor,
|
|
3318
|
+
bytecode
|
|
3319
|
+
])
|
|
3320
|
+
);
|
|
3321
|
+
}
|
|
3322
|
+
function hashEntryPointSierra(data) {
|
|
3323
|
+
const base = data.flatMap((it) => {
|
|
3324
|
+
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
3325
|
+
});
|
|
3326
|
+
return (0, import_micro_starknet2.poseidonHashMany)(base);
|
|
3327
|
+
}
|
|
3328
|
+
function hashAbi(sierra) {
|
|
3329
|
+
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
3330
|
+
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
3331
|
+
}
|
|
3332
|
+
function computeSierraContractClassHash(sierra) {
|
|
3333
|
+
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
3334
|
+
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
3335
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
3336
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
3337
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
3338
|
+
const abiHash = hashAbi(sierra);
|
|
3339
|
+
const sierraProgram = (0, import_micro_starknet2.poseidonHashMany)(sierra.sierra_program.map((it) => BigInt(it)));
|
|
3340
|
+
return toHex(
|
|
3341
|
+
(0, import_micro_starknet2.poseidonHashMany)([
|
|
3342
|
+
compiledClassVersion,
|
|
3343
|
+
externalEntryPointsHash,
|
|
3344
|
+
l1Handlers,
|
|
3345
|
+
constructor,
|
|
3346
|
+
abiHash,
|
|
3347
|
+
sierraProgram
|
|
3348
|
+
])
|
|
3349
|
+
);
|
|
3350
|
+
}
|
|
3351
|
+
function computeContractClassHash(contract) {
|
|
3352
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3353
|
+
if ("sierra_program" in compiledContract) {
|
|
3354
|
+
return computeSierraContractClassHash(compiledContract);
|
|
3337
3355
|
}
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
// src/utils/fetchPonyfill.ts
|
|
3341
|
-
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
3342
|
-
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
3356
|
+
return computeLegacyContractClassHash(compiledContract);
|
|
3357
|
+
}
|
|
3343
3358
|
|
|
3344
3359
|
// src/utils/contract.ts
|
|
3345
3360
|
function isSierra(contract) {
|
|
@@ -3374,7 +3389,7 @@ __export(stark_exports, {
|
|
|
3374
3389
|
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
3375
3390
|
signatureToHexArray: () => signatureToHexArray
|
|
3376
3391
|
});
|
|
3377
|
-
var
|
|
3392
|
+
var import_micro_starknet3 = require("micro-starknet");
|
|
3378
3393
|
var import_pako = require("pako");
|
|
3379
3394
|
function compressProgram(jsonProgram) {
|
|
3380
3395
|
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
@@ -3382,8 +3397,8 @@ function compressProgram(jsonProgram) {
|
|
|
3382
3397
|
return btoaUniversal(compressedProgram);
|
|
3383
3398
|
}
|
|
3384
3399
|
function randomAddress() {
|
|
3385
|
-
const randomKeyPair =
|
|
3386
|
-
return (0,
|
|
3400
|
+
const randomKeyPair = import_micro_starknet3.utils.randomPrivateKey();
|
|
3401
|
+
return (0, import_micro_starknet3.getStarkKey)(randomKeyPair);
|
|
3387
3402
|
}
|
|
3388
3403
|
function makeAddress(input) {
|
|
3389
3404
|
return addHexPrefix(input).toLowerCase();
|
|
@@ -3878,7 +3893,7 @@ var RpcProvider = class {
|
|
|
3878
3893
|
return this.fetchEndpoint("starknet_estimateFee", {
|
|
3879
3894
|
request: {
|
|
3880
3895
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
3881
|
-
constructor_calldata:
|
|
3896
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
3882
3897
|
class_hash: toHex(classHash),
|
|
3883
3898
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3884
3899
|
signature: signatureToHexArray(signature),
|
|
@@ -3915,7 +3930,7 @@ var RpcProvider = class {
|
|
|
3915
3930
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
3916
3931
|
return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
3917
3932
|
deploy_account_transaction: {
|
|
3918
|
-
constructor_calldata:
|
|
3933
|
+
constructor_calldata: CallData.toHex(constructorCalldata || []),
|
|
3919
3934
|
class_hash: toHex(classHash),
|
|
3920
3935
|
contract_address_salt: toHex(addressSalt || 0),
|
|
3921
3936
|
type: RPC.TransactionType.DEPLOY_ACCOUNT,
|
|
@@ -4353,7 +4368,7 @@ var SequencerProvider = class {
|
|
|
4353
4368
|
{
|
|
4354
4369
|
contract_address: contractAddress,
|
|
4355
4370
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
4356
|
-
calldata
|
|
4371
|
+
calldata: CallData.compile(calldata)
|
|
4357
4372
|
}
|
|
4358
4373
|
).then(this.responseParser.parseCallContractResponse);
|
|
4359
4374
|
}
|
|
@@ -4467,7 +4482,7 @@ var SequencerProvider = class {
|
|
|
4467
4482
|
{
|
|
4468
4483
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
4469
4484
|
sender_address: invocation.contractAddress,
|
|
4470
|
-
calldata: invocation.calldata ?? [],
|
|
4485
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4471
4486
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4472
4487
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4473
4488
|
nonce: toHex(invocationDetails.nonce)
|
|
@@ -4525,7 +4540,7 @@ var SequencerProvider = class {
|
|
|
4525
4540
|
res = {
|
|
4526
4541
|
type: invocation.type,
|
|
4527
4542
|
sender_address: invocation.contractAddress,
|
|
4528
|
-
calldata: invocation.calldata ?? []
|
|
4543
|
+
calldata: CallData.compile(invocation.calldata ?? [])
|
|
4529
4544
|
};
|
|
4530
4545
|
} else if (invocation.type === "DECLARE") {
|
|
4531
4546
|
res = {
|
|
@@ -4608,7 +4623,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
4608
4623
|
{
|
|
4609
4624
|
type: "INVOKE_FUNCTION",
|
|
4610
4625
|
sender_address: invocation.contractAddress,
|
|
4611
|
-
calldata: invocation.calldata ?? [],
|
|
4626
|
+
calldata: CallData.compile(invocation.calldata ?? []),
|
|
4612
4627
|
signature: signatureToDecimalArray(invocation.signature),
|
|
4613
4628
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
4614
4629
|
nonce: toHex(invocationDetails.nonce),
|
|
@@ -5021,7 +5036,7 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
5021
5036
|
const callArray = [];
|
|
5022
5037
|
const calldata = [];
|
|
5023
5038
|
calls.forEach((call) => {
|
|
5024
|
-
const data = call.calldata || [];
|
|
5039
|
+
const data = CallData.compile(call.calldata || []);
|
|
5025
5040
|
callArray.push({
|
|
5026
5041
|
to: toBigInt(call.contractAddress).toString(10),
|
|
5027
5042
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
@@ -5052,11 +5067,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
5052
5067
|
return callArray;
|
|
5053
5068
|
};
|
|
5054
5069
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5055
|
-
|
|
5070
|
+
const orderCalls = calls.map((call) => ({
|
|
5071
|
+
contractAddress: call.contractAddress,
|
|
5072
|
+
entrypoint: call.entrypoint,
|
|
5073
|
+
calldata: call.calldata
|
|
5074
|
+
}));
|
|
5075
|
+
return CallData.compile({ orderCalls });
|
|
5056
5076
|
};
|
|
5057
5077
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5058
5078
|
if (cairoVersion === "1") {
|
|
5059
|
-
return
|
|
5079
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
5060
5080
|
}
|
|
5061
5081
|
return fromCallsToExecuteCalldata(calls);
|
|
5062
5082
|
};
|
|
@@ -5310,7 +5330,7 @@ var Signer = class {
|
|
|
5310
5330
|
const msgHash = calculateDeployAccountTransactionHash(
|
|
5311
5331
|
contractAddress,
|
|
5312
5332
|
classHash,
|
|
5313
|
-
constructorCalldata,
|
|
5333
|
+
CallData.compile(constructorCalldata),
|
|
5314
5334
|
addressSalt,
|
|
5315
5335
|
version,
|
|
5316
5336
|
maxFee,
|
|
@@ -5366,10 +5386,12 @@ function parseUDCEvent(txReceipt) {
|
|
|
5366
5386
|
|
|
5367
5387
|
// src/account/default.ts
|
|
5368
5388
|
var Account = class extends Provider {
|
|
5369
|
-
constructor(providerOrOptions, address, pkOrSigner) {
|
|
5389
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion = "0") {
|
|
5370
5390
|
super(providerOrOptions);
|
|
5391
|
+
this.deploySelf = this.deployAccount;
|
|
5371
5392
|
this.address = address.toLowerCase();
|
|
5372
5393
|
this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
|
|
5394
|
+
this.cairoVersion = cairoVersion;
|
|
5373
5395
|
}
|
|
5374
5396
|
async getNonce(blockIdentifier) {
|
|
5375
5397
|
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
@@ -5377,7 +5399,7 @@ var Account = class extends Provider {
|
|
|
5377
5399
|
async estimateFee(calls, estimateFeeDetails) {
|
|
5378
5400
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
5379
5401
|
}
|
|
5380
|
-
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
5402
|
+
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5381
5403
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5382
5404
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5383
5405
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5388,7 +5410,7 @@ var Account = class extends Provider {
|
|
|
5388
5410
|
maxFee: ZERO,
|
|
5389
5411
|
version,
|
|
5390
5412
|
chainId,
|
|
5391
|
-
cairoVersion: cairoVersion
|
|
5413
|
+
cairoVersion: this.cairoVersion
|
|
5392
5414
|
};
|
|
5393
5415
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5394
5416
|
const response = await super.getInvokeEstimateFee(
|
|
@@ -5403,7 +5425,7 @@ var Account = class extends Provider {
|
|
|
5403
5425
|
suggestedMaxFee
|
|
5404
5426
|
};
|
|
5405
5427
|
}
|
|
5406
|
-
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate
|
|
5428
|
+
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate } = {}) {
|
|
5407
5429
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5408
5430
|
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
|
|
5409
5431
|
const chainId = await this.getChainId();
|
|
@@ -5415,7 +5437,7 @@ var Account = class extends Provider {
|
|
|
5415
5437
|
version,
|
|
5416
5438
|
walletAddress: this.address,
|
|
5417
5439
|
maxFee: ZERO,
|
|
5418
|
-
cairoVersion: cairoVersion
|
|
5440
|
+
cairoVersion: this.cairoVersion
|
|
5419
5441
|
}
|
|
5420
5442
|
);
|
|
5421
5443
|
const response = await super.getDeclareEstimateFee(
|
|
@@ -5435,7 +5457,7 @@ var Account = class extends Provider {
|
|
|
5435
5457
|
addressSalt = 0,
|
|
5436
5458
|
constructorCalldata = [],
|
|
5437
5459
|
contractAddress: providedContractAddress
|
|
5438
|
-
}, { blockIdentifier, skipValidate
|
|
5460
|
+
}, { blockIdentifier, skipValidate } = {}) {
|
|
5439
5461
|
const version = toBigInt(feeTransactionVersion);
|
|
5440
5462
|
const nonce = ZERO;
|
|
5441
5463
|
const chainId = await this.getChainId();
|
|
@@ -5447,7 +5469,7 @@ var Account = class extends Provider {
|
|
|
5447
5469
|
version,
|
|
5448
5470
|
walletAddress: this.address,
|
|
5449
5471
|
maxFee: ZERO,
|
|
5450
|
-
cairoVersion: cairoVersion
|
|
5472
|
+
cairoVersion: this.cairoVersion
|
|
5451
5473
|
}
|
|
5452
5474
|
);
|
|
5453
5475
|
const response = await super.getDeployAccountEstimateFee(
|
|
@@ -5466,7 +5488,7 @@ var Account = class extends Provider {
|
|
|
5466
5488
|
const calls = this.buildUDCContractPayload(payload);
|
|
5467
5489
|
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
5468
5490
|
}
|
|
5469
|
-
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier
|
|
5491
|
+
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
5470
5492
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5471
5493
|
const version = toBigInt(feeTransactionVersion);
|
|
5472
5494
|
const chainId = await this.getChainId();
|
|
@@ -5478,7 +5500,7 @@ var Account = class extends Provider {
|
|
|
5478
5500
|
maxFee: ZERO,
|
|
5479
5501
|
version,
|
|
5480
5502
|
chainId,
|
|
5481
|
-
cairoVersion: cairoVersion
|
|
5503
|
+
cairoVersion: this.cairoVersion
|
|
5482
5504
|
};
|
|
5483
5505
|
const txPayload = transaction.payload;
|
|
5484
5506
|
let res;
|
|
@@ -5536,7 +5558,7 @@ var Account = class extends Provider {
|
|
|
5536
5558
|
});
|
|
5537
5559
|
}
|
|
5538
5560
|
async buildInvocation(call, signerDetails) {
|
|
5539
|
-
const calldata = getExecuteCalldata(call,
|
|
5561
|
+
const calldata = getExecuteCalldata(call, this.cairoVersion);
|
|
5540
5562
|
const signature = await this.signer.signTransaction(call, signerDetails);
|
|
5541
5563
|
return {
|
|
5542
5564
|
contractAddress: this.address,
|
|
@@ -5553,17 +5575,16 @@ var Account = class extends Provider {
|
|
|
5553
5575
|
);
|
|
5554
5576
|
const version = toBigInt(transactionVersion);
|
|
5555
5577
|
const chainId = await this.getChainId();
|
|
5556
|
-
const cairoVersion = transactionsDetail.cairoVersion ?? "0";
|
|
5557
5578
|
const signerDetails = {
|
|
5558
5579
|
walletAddress: this.address,
|
|
5559
5580
|
nonce,
|
|
5560
5581
|
maxFee,
|
|
5561
5582
|
version,
|
|
5562
5583
|
chainId,
|
|
5563
|
-
cairoVersion
|
|
5584
|
+
cairoVersion: this.cairoVersion
|
|
5564
5585
|
};
|
|
5565
5586
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
5566
|
-
const calldata = getExecuteCalldata(transactions, cairoVersion);
|
|
5587
|
+
const calldata = getExecuteCalldata(transactions, this.cairoVersion);
|
|
5567
5588
|
return this.invokeFunction(
|
|
5568
5589
|
{ contractAddress: this.address, calldata, signature },
|
|
5569
5590
|
{
|
|
@@ -5573,6 +5594,18 @@ var Account = class extends Provider {
|
|
|
5573
5594
|
}
|
|
5574
5595
|
);
|
|
5575
5596
|
}
|
|
5597
|
+
async declareIfNot(payload, transactionsDetail = {}) {
|
|
5598
|
+
const declareContractPayload = extractContractHashes(payload);
|
|
5599
|
+
try {
|
|
5600
|
+
await this.getClassByHash(declareContractPayload.classHash);
|
|
5601
|
+
} catch (error) {
|
|
5602
|
+
return this.declare(payload, transactionsDetail);
|
|
5603
|
+
}
|
|
5604
|
+
return {
|
|
5605
|
+
transaction_hash: "",
|
|
5606
|
+
class_hash: declareContractPayload.classHash
|
|
5607
|
+
};
|
|
5608
|
+
}
|
|
5576
5609
|
async declare(payload, transactionsDetail = {}) {
|
|
5577
5610
|
const declareContractPayload = extractContractHashes(payload);
|
|
5578
5611
|
const details = {};
|
|
@@ -5589,7 +5622,7 @@ var Account = class extends Provider {
|
|
|
5589
5622
|
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
|
|
5590
5623
|
...details,
|
|
5591
5624
|
walletAddress: this.address,
|
|
5592
|
-
cairoVersion:
|
|
5625
|
+
cairoVersion: this.cairoVersion
|
|
5593
5626
|
});
|
|
5594
5627
|
return this.declareContract(declareContractTransaction, details);
|
|
5595
5628
|
}
|
|
@@ -5625,10 +5658,7 @@ var Account = class extends Provider {
|
|
|
5625
5658
|
});
|
|
5626
5659
|
const calls = params.map((it) => it.call);
|
|
5627
5660
|
const addresses = params.map((it) => it.address);
|
|
5628
|
-
const invokeResponse = await this.execute(calls, void 0,
|
|
5629
|
-
...details,
|
|
5630
|
-
cairoVersion: "0"
|
|
5631
|
-
});
|
|
5661
|
+
const invokeResponse = await this.execute(calls, void 0, details);
|
|
5632
5662
|
return {
|
|
5633
5663
|
...invokeResponse,
|
|
5634
5664
|
contract_address: addresses
|
|
@@ -5643,15 +5673,18 @@ var Account = class extends Provider {
|
|
|
5643
5673
|
}
|
|
5644
5674
|
async declareAndDeploy(payload, details) {
|
|
5645
5675
|
const { constructorCalldata, salt, unique } = payload;
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5676
|
+
let declare = await this.declareIfNot(payload, details);
|
|
5677
|
+
if (declare.transaction_hash !== "") {
|
|
5678
|
+
const tx = await this.waitForTransaction(declare.transaction_hash, {
|
|
5679
|
+
successStates: ["ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */]
|
|
5680
|
+
});
|
|
5681
|
+
declare = { ...declare, ...tx };
|
|
5682
|
+
}
|
|
5650
5683
|
const deploy = await this.deployContract(
|
|
5651
|
-
{ classHash: class_hash, salt, unique, constructorCalldata },
|
|
5684
|
+
{ classHash: declare.class_hash, salt, unique, constructorCalldata },
|
|
5652
5685
|
details
|
|
5653
5686
|
);
|
|
5654
|
-
return { declare: { ...declare
|
|
5687
|
+
return { declare: { ...declare }, deploy };
|
|
5655
5688
|
}
|
|
5656
5689
|
async deployAccount({
|
|
5657
5690
|
classHash,
|
|
@@ -5667,13 +5700,18 @@ var Account = class extends Provider {
|
|
|
5667
5700
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5668
5701
|
{
|
|
5669
5702
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
5670
|
-
payload: {
|
|
5703
|
+
payload: {
|
|
5704
|
+
classHash,
|
|
5705
|
+
constructorCalldata: compiledCalldata,
|
|
5706
|
+
addressSalt,
|
|
5707
|
+
contractAddress
|
|
5708
|
+
}
|
|
5671
5709
|
},
|
|
5672
5710
|
transactionsDetail
|
|
5673
5711
|
);
|
|
5674
5712
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5675
5713
|
classHash,
|
|
5676
|
-
constructorCalldata,
|
|
5714
|
+
constructorCalldata: compiledCalldata,
|
|
5677
5715
|
contractAddress,
|
|
5678
5716
|
addressSalt,
|
|
5679
5717
|
chainId,
|
|
@@ -5771,12 +5809,12 @@ var Account = class extends Provider {
|
|
|
5771
5809
|
version,
|
|
5772
5810
|
nonce,
|
|
5773
5811
|
addressSalt,
|
|
5774
|
-
constructorCalldata
|
|
5812
|
+
constructorCalldata: compiledCalldata
|
|
5775
5813
|
});
|
|
5776
5814
|
return {
|
|
5777
5815
|
classHash,
|
|
5778
5816
|
addressSalt,
|
|
5779
|
-
constructorCalldata,
|
|
5817
|
+
constructorCalldata: compiledCalldata,
|
|
5780
5818
|
signature
|
|
5781
5819
|
};
|
|
5782
5820
|
}
|
|
@@ -5803,7 +5841,7 @@ var Account = class extends Provider {
|
|
|
5803
5841
|
});
|
|
5804
5842
|
return calls;
|
|
5805
5843
|
}
|
|
5806
|
-
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate
|
|
5844
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5807
5845
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5808
5846
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5809
5847
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -5814,7 +5852,7 @@ var Account = class extends Provider {
|
|
|
5814
5852
|
maxFee: ZERO,
|
|
5815
5853
|
version,
|
|
5816
5854
|
chainId,
|
|
5817
|
-
cairoVersion: cairoVersion
|
|
5855
|
+
cairoVersion: this.cairoVersion
|
|
5818
5856
|
};
|
|
5819
5857
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5820
5858
|
const response = await super.getSimulateTransaction(
|