starknet 5.11.1 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +779 -513
- package/dist/index.global.js +3860 -3850
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +802 -795
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +802 -796
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -73,79 +73,35 @@ __export(src_exports, {
|
|
|
73
73
|
starknetId: () => starknetId_exports,
|
|
74
74
|
transaction: () => transaction_exports,
|
|
75
75
|
typedData: () => typedData_exports,
|
|
76
|
+
types: () => types_exports,
|
|
76
77
|
uint256: () => uint256_exports,
|
|
77
78
|
validateAndParseAddress: () => validateAndParseAddress,
|
|
78
79
|
validateChecksumAddress: () => validateChecksumAddress
|
|
79
80
|
});
|
|
80
81
|
module.exports = __toCommonJS(src_exports);
|
|
81
82
|
|
|
82
|
-
// src/
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
TransactionType2["DEPLOY"] = "DEPLOY";
|
|
104
|
-
TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
105
|
-
return TransactionType2;
|
|
106
|
-
})(TransactionType || {});
|
|
107
|
-
|
|
108
|
-
// src/types/api/rpc.ts
|
|
109
|
-
var RPC;
|
|
110
|
-
((RPC2) => {
|
|
111
|
-
let TransactionType2;
|
|
112
|
-
((TransactionType3) => {
|
|
113
|
-
TransactionType3["DECLARE"] = "DECLARE";
|
|
114
|
-
TransactionType3["DEPLOY"] = "DEPLOY";
|
|
115
|
-
TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
116
|
-
TransactionType3["INVOKE"] = "INVOKE";
|
|
117
|
-
TransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
118
|
-
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
119
|
-
})(RPC || (RPC = {}));
|
|
120
|
-
|
|
121
|
-
// src/utils/assert.ts
|
|
122
|
-
function assert(condition, message) {
|
|
123
|
-
if (!condition) {
|
|
124
|
-
throw new Error(message || "Assertion failure");
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/utils/num.ts
|
|
129
|
-
var num_exports = {};
|
|
130
|
-
__export(num_exports, {
|
|
131
|
-
assertInRange: () => assertInRange,
|
|
132
|
-
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
133
|
-
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
134
|
-
cleanHex: () => cleanHex,
|
|
135
|
-
getDecimalString: () => getDecimalString,
|
|
136
|
-
getHexString: () => getHexString,
|
|
137
|
-
getHexStringArray: () => getHexStringArray,
|
|
138
|
-
hexToBytes: () => hexToBytes,
|
|
139
|
-
hexToDecimalString: () => hexToDecimalString,
|
|
140
|
-
isBigInt: () => isBigInt,
|
|
141
|
-
isHex: () => isHex,
|
|
142
|
-
isStringWholeNumber: () => isStringWholeNumber,
|
|
143
|
-
toBigInt: () => toBigInt,
|
|
144
|
-
toCairoBool: () => toCairoBool,
|
|
145
|
-
toHex: () => toHex,
|
|
146
|
-
toHexString: () => toHexString
|
|
83
|
+
// src/constants.ts
|
|
84
|
+
var constants_exports = {};
|
|
85
|
+
__export(constants_exports, {
|
|
86
|
+
ALPHA: () => ALPHA,
|
|
87
|
+
API_VERSION: () => API_VERSION,
|
|
88
|
+
BETA: () => BETA,
|
|
89
|
+
BaseUrl: () => BaseUrl,
|
|
90
|
+
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
91
|
+
EC_ORDER: () => EC_ORDER,
|
|
92
|
+
FIELD_GEN: () => FIELD_GEN,
|
|
93
|
+
FIELD_PRIME: () => FIELD_PRIME,
|
|
94
|
+
FIELD_SIZE: () => FIELD_SIZE,
|
|
95
|
+
IS_BROWSER: () => IS_BROWSER,
|
|
96
|
+
MASK_250: () => MASK_250,
|
|
97
|
+
MASK_251: () => MASK_251,
|
|
98
|
+
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
99
|
+
NetworkName: () => NetworkName,
|
|
100
|
+
StarknetChainId: () => StarknetChainId,
|
|
101
|
+
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
102
|
+
UDC: () => UDC,
|
|
103
|
+
ZERO: () => ZERO
|
|
147
104
|
});
|
|
148
|
-
var import_utils = require("@noble/curves/abstract/utils");
|
|
149
105
|
|
|
150
106
|
// src/utils/encode.ts
|
|
151
107
|
var encode_exports = {};
|
|
@@ -210,98 +166,7 @@ function utf8ToArray(str) {
|
|
|
210
166
|
return new TextEncoder().encode(str);
|
|
211
167
|
}
|
|
212
168
|
|
|
213
|
-
// src/utils/num.ts
|
|
214
|
-
function isHex(hex) {
|
|
215
|
-
return /^0x[0-9a-f]*$/i.test(hex);
|
|
216
|
-
}
|
|
217
|
-
function toBigInt(value) {
|
|
218
|
-
return BigInt(value);
|
|
219
|
-
}
|
|
220
|
-
function isBigInt(value) {
|
|
221
|
-
return typeof value === "bigint";
|
|
222
|
-
}
|
|
223
|
-
function toHex(number2) {
|
|
224
|
-
return addHexPrefix(toBigInt(number2).toString(16));
|
|
225
|
-
}
|
|
226
|
-
function hexToDecimalString(hex) {
|
|
227
|
-
return BigInt(addHexPrefix(hex)).toString(10);
|
|
228
|
-
}
|
|
229
|
-
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
230
|
-
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
231
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
232
|
-
const inputBigInt = BigInt(input);
|
|
233
|
-
const lowerBoundBigInt = BigInt(lowerBound);
|
|
234
|
-
const upperBoundBigInt = BigInt(upperBound);
|
|
235
|
-
assert(
|
|
236
|
-
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
237
|
-
`Message not signable, ${messageSuffix}.`
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
241
|
-
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
242
|
-
}
|
|
243
|
-
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
244
|
-
return rawCalldata.map((x) => toHex(x));
|
|
245
|
-
}
|
|
246
|
-
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
247
|
-
var toHexString = (value) => toHex(value);
|
|
248
|
-
function getDecimalString(value) {
|
|
249
|
-
if (isHex(value)) {
|
|
250
|
-
return hexToDecimalString(value);
|
|
251
|
-
}
|
|
252
|
-
if (isStringWholeNumber(value)) {
|
|
253
|
-
return value;
|
|
254
|
-
}
|
|
255
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
256
|
-
}
|
|
257
|
-
function getHexString(value) {
|
|
258
|
-
if (isHex(value)) {
|
|
259
|
-
return value;
|
|
260
|
-
}
|
|
261
|
-
if (isStringWholeNumber(value)) {
|
|
262
|
-
return toHexString(value);
|
|
263
|
-
}
|
|
264
|
-
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
265
|
-
}
|
|
266
|
-
function getHexStringArray(value) {
|
|
267
|
-
return value.map((el) => getHexString(el));
|
|
268
|
-
}
|
|
269
|
-
var toCairoBool = (value) => (+value).toString();
|
|
270
|
-
function hexToBytes(value) {
|
|
271
|
-
if (!isHex(value))
|
|
272
|
-
throw new Error(`${value} need to be a hex-string`);
|
|
273
|
-
let adaptedValue = removeHexPrefix(value);
|
|
274
|
-
if (adaptedValue.length % 2 !== 0) {
|
|
275
|
-
adaptedValue = `0${adaptedValue}`;
|
|
276
|
-
}
|
|
277
|
-
return (0, import_utils.hexToBytes)(adaptedValue);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// src/utils/selector.ts
|
|
281
|
-
var import_micro_starknet = require("micro-starknet");
|
|
282
|
-
|
|
283
169
|
// src/constants.ts
|
|
284
|
-
var constants_exports = {};
|
|
285
|
-
__export(constants_exports, {
|
|
286
|
-
ALPHA: () => ALPHA,
|
|
287
|
-
API_VERSION: () => API_VERSION,
|
|
288
|
-
BETA: () => BETA,
|
|
289
|
-
BaseUrl: () => BaseUrl,
|
|
290
|
-
CONSTANT_POINTS: () => CONSTANT_POINTS,
|
|
291
|
-
EC_ORDER: () => EC_ORDER,
|
|
292
|
-
FIELD_GEN: () => FIELD_GEN,
|
|
293
|
-
FIELD_PRIME: () => FIELD_PRIME,
|
|
294
|
-
FIELD_SIZE: () => FIELD_SIZE,
|
|
295
|
-
IS_BROWSER: () => IS_BROWSER,
|
|
296
|
-
MASK_250: () => MASK_250,
|
|
297
|
-
MASK_251: () => MASK_251,
|
|
298
|
-
MAX_ECDSA_VAL: () => MAX_ECDSA_VAL,
|
|
299
|
-
NetworkName: () => NetworkName,
|
|
300
|
-
StarknetChainId: () => StarknetChainId,
|
|
301
|
-
TransactionHashPrefix: () => TransactionHashPrefix,
|
|
302
|
-
UDC: () => UDC,
|
|
303
|
-
ZERO: () => ZERO
|
|
304
|
-
});
|
|
305
170
|
var ZERO = 0n;
|
|
306
171
|
var MASK_250 = 2n ** 250n - 1n;
|
|
307
172
|
var MASK_251 = 2n ** 251n;
|
|
@@ -2370,39 +2235,182 @@ var CONSTANT_POINTS = [
|
|
|
2370
2235
|
]
|
|
2371
2236
|
];
|
|
2372
2237
|
|
|
2373
|
-
// src/
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
return
|
|
2388
|
-
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2238
|
+
// src/types/index.ts
|
|
2239
|
+
var types_exports = {};
|
|
2240
|
+
__export(types_exports, {
|
|
2241
|
+
EntryPointType: () => EntryPointType,
|
|
2242
|
+
RPC: () => RPC,
|
|
2243
|
+
TransactionStatus: () => TransactionStatus,
|
|
2244
|
+
TransactionType: () => TransactionType
|
|
2245
|
+
});
|
|
2246
|
+
|
|
2247
|
+
// src/types/lib/contract/index.ts
|
|
2248
|
+
var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
|
|
2249
|
+
EntryPointType2["EXTERNAL"] = "EXTERNAL";
|
|
2250
|
+
EntryPointType2["L1_HANDLER"] = "L1_HANDLER";
|
|
2251
|
+
EntryPointType2["CONSTRUCTOR"] = "CONSTRUCTOR";
|
|
2252
|
+
return EntryPointType2;
|
|
2253
|
+
})(EntryPointType || {});
|
|
2254
|
+
|
|
2255
|
+
// src/types/lib/index.ts
|
|
2256
|
+
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
2257
|
+
TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
|
|
2258
|
+
TransactionStatus2["RECEIVED"] = "RECEIVED";
|
|
2259
|
+
TransactionStatus2["PENDING"] = "PENDING";
|
|
2260
|
+
TransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
|
|
2261
|
+
TransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
|
|
2262
|
+
TransactionStatus2["REJECTED"] = "REJECTED";
|
|
2263
|
+
return TransactionStatus2;
|
|
2264
|
+
})(TransactionStatus || {});
|
|
2265
|
+
var TransactionType = /* @__PURE__ */ ((TransactionType2) => {
|
|
2266
|
+
TransactionType2["INVOKE"] = "INVOKE_FUNCTION";
|
|
2267
|
+
TransactionType2["DECLARE"] = "DECLARE";
|
|
2268
|
+
TransactionType2["DEPLOY"] = "DEPLOY";
|
|
2269
|
+
TransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
2270
|
+
return TransactionType2;
|
|
2271
|
+
})(TransactionType || {});
|
|
2272
|
+
|
|
2273
|
+
// src/types/api/rpc.ts
|
|
2274
|
+
var RPC;
|
|
2275
|
+
((RPC2) => {
|
|
2276
|
+
let TransactionType2;
|
|
2277
|
+
((TransactionType3) => {
|
|
2278
|
+
TransactionType3["DECLARE"] = "DECLARE";
|
|
2279
|
+
TransactionType3["DEPLOY"] = "DEPLOY";
|
|
2280
|
+
TransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
|
|
2281
|
+
TransactionType3["INVOKE"] = "INVOKE";
|
|
2282
|
+
TransactionType3["L1_HANDLER"] = "L1_HANDLER";
|
|
2283
|
+
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
2284
|
+
})(RPC || (RPC = {}));
|
|
2285
|
+
|
|
2286
|
+
// src/utils/assert.ts
|
|
2287
|
+
function assert(condition, message) {
|
|
2288
|
+
if (!condition) {
|
|
2289
|
+
throw new Error(message || "Assertion failure");
|
|
2395
2290
|
}
|
|
2396
|
-
return getSelectorFromName(value);
|
|
2397
2291
|
}
|
|
2398
2292
|
|
|
2399
|
-
// src/utils/
|
|
2400
|
-
var
|
|
2401
|
-
__export(
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2293
|
+
// src/utils/num.ts
|
|
2294
|
+
var num_exports = {};
|
|
2295
|
+
__export(num_exports, {
|
|
2296
|
+
assertInRange: () => assertInRange,
|
|
2297
|
+
bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
|
|
2298
|
+
bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
|
|
2299
|
+
cleanHex: () => cleanHex,
|
|
2300
|
+
getDecimalString: () => getDecimalString,
|
|
2301
|
+
getHexString: () => getHexString,
|
|
2302
|
+
getHexStringArray: () => getHexStringArray,
|
|
2303
|
+
hexToBytes: () => hexToBytes,
|
|
2304
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
2305
|
+
isBigInt: () => isBigInt,
|
|
2306
|
+
isHex: () => isHex,
|
|
2307
|
+
isStringWholeNumber: () => isStringWholeNumber,
|
|
2308
|
+
toBigInt: () => toBigInt,
|
|
2309
|
+
toCairoBool: () => toCairoBool,
|
|
2310
|
+
toHex: () => toHex,
|
|
2311
|
+
toHexString: () => toHexString
|
|
2312
|
+
});
|
|
2313
|
+
var import_utils = require("@noble/curves/abstract/utils");
|
|
2314
|
+
function isHex(hex) {
|
|
2315
|
+
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2316
|
+
}
|
|
2317
|
+
function toBigInt(value) {
|
|
2318
|
+
return BigInt(value);
|
|
2319
|
+
}
|
|
2320
|
+
function isBigInt(value) {
|
|
2321
|
+
return typeof value === "bigint";
|
|
2322
|
+
}
|
|
2323
|
+
function toHex(number2) {
|
|
2324
|
+
return addHexPrefix(toBigInt(number2).toString(16));
|
|
2325
|
+
}
|
|
2326
|
+
function hexToDecimalString(hex) {
|
|
2327
|
+
return BigInt(addHexPrefix(hex)).toString(10);
|
|
2328
|
+
}
|
|
2329
|
+
var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
|
|
2330
|
+
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
2331
|
+
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
2332
|
+
const inputBigInt = BigInt(input);
|
|
2333
|
+
const lowerBoundBigInt = BigInt(lowerBound);
|
|
2334
|
+
const upperBoundBigInt = BigInt(upperBound);
|
|
2335
|
+
assert(
|
|
2336
|
+
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
2337
|
+
`Message not signable, ${messageSuffix}.`
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
function bigNumberishArrayToDecimalStringArray(rawCalldata) {
|
|
2341
|
+
return rawCalldata.map((x) => toBigInt(x).toString(10));
|
|
2342
|
+
}
|
|
2343
|
+
function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
|
|
2344
|
+
return rawCalldata.map((x) => toHex(x));
|
|
2345
|
+
}
|
|
2346
|
+
var isStringWholeNumber = (value) => /^\d+$/.test(value);
|
|
2347
|
+
var toHexString = (value) => toHex(value);
|
|
2348
|
+
function getDecimalString(value) {
|
|
2349
|
+
if (isHex(value)) {
|
|
2350
|
+
return hexToDecimalString(value);
|
|
2351
|
+
}
|
|
2352
|
+
if (isStringWholeNumber(value)) {
|
|
2353
|
+
return value;
|
|
2354
|
+
}
|
|
2355
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2356
|
+
}
|
|
2357
|
+
function getHexString(value) {
|
|
2358
|
+
if (isHex(value)) {
|
|
2359
|
+
return value;
|
|
2360
|
+
}
|
|
2361
|
+
if (isStringWholeNumber(value)) {
|
|
2362
|
+
return toHexString(value);
|
|
2363
|
+
}
|
|
2364
|
+
throw new Error(`${value} need to be hex-string or whole-number-string`);
|
|
2365
|
+
}
|
|
2366
|
+
function getHexStringArray(value) {
|
|
2367
|
+
return value.map((el) => getHexString(el));
|
|
2368
|
+
}
|
|
2369
|
+
var toCairoBool = (value) => (+value).toString();
|
|
2370
|
+
function hexToBytes(value) {
|
|
2371
|
+
if (!isHex(value))
|
|
2372
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
2373
|
+
let adaptedValue = removeHexPrefix(value);
|
|
2374
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
2375
|
+
adaptedValue = `0${adaptedValue}`;
|
|
2376
|
+
}
|
|
2377
|
+
return (0, import_utils.hexToBytes)(adaptedValue);
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
// src/utils/selector.ts
|
|
2381
|
+
var import_micro_starknet = require("micro-starknet");
|
|
2382
|
+
function keccakBn(value) {
|
|
2383
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
2384
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
2385
|
+
return addHexPrefix((0, import_micro_starknet.keccak)(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
2386
|
+
}
|
|
2387
|
+
function keccakHex(value) {
|
|
2388
|
+
return addHexPrefix((0, import_micro_starknet.keccak)(utf8ToArray(value)).toString(16));
|
|
2389
|
+
}
|
|
2390
|
+
function starknetKeccak(value) {
|
|
2391
|
+
const hash = BigInt(keccakHex(value));
|
|
2392
|
+
return hash & MASK_250;
|
|
2393
|
+
}
|
|
2394
|
+
function getSelectorFromName(funcName) {
|
|
2395
|
+
return toHex(starknetKeccak(funcName));
|
|
2396
|
+
}
|
|
2397
|
+
function getSelector(value) {
|
|
2398
|
+
if (isHex(value)) {
|
|
2399
|
+
return value;
|
|
2400
|
+
}
|
|
2401
|
+
if (isStringWholeNumber(value)) {
|
|
2402
|
+
return toHexString(value);
|
|
2403
|
+
}
|
|
2404
|
+
return getSelectorFromName(value);
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
// src/utils/shortString.ts
|
|
2408
|
+
var shortString_exports = {};
|
|
2409
|
+
__export(shortString_exports, {
|
|
2410
|
+
decodeShortString: () => decodeShortString,
|
|
2411
|
+
encodeShortString: () => encodeShortString,
|
|
2412
|
+
isASCII: () => isASCII,
|
|
2413
|
+
isDecimalString: () => isDecimalString,
|
|
2406
2414
|
isLongText: () => isLongText,
|
|
2407
2415
|
isShortString: () => isShortString,
|
|
2408
2416
|
isShortText: () => isShortText,
|
|
@@ -5031,463 +5039,169 @@ var Provider = class {
|
|
|
5031
5039
|
}
|
|
5032
5040
|
};
|
|
5033
5041
|
|
|
5034
|
-
// src/
|
|
5035
|
-
var
|
|
5042
|
+
// src/signer/interface.ts
|
|
5043
|
+
var SignerInterface = class {
|
|
5036
5044
|
};
|
|
5037
5045
|
|
|
5038
|
-
// src/
|
|
5039
|
-
var
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
};
|
|
5059
|
-
function buildCall(contract, functionAbi) {
|
|
5060
|
-
return async function(...args) {
|
|
5061
|
-
const params = splitArgsAndOptions(args);
|
|
5062
|
-
return contract.call(functionAbi.name, params.args, {
|
|
5063
|
-
parseRequest: true,
|
|
5064
|
-
parseResponse: true,
|
|
5065
|
-
...params.options
|
|
5066
|
-
});
|
|
5067
|
-
};
|
|
5068
|
-
}
|
|
5069
|
-
function buildInvoke(contract, functionAbi) {
|
|
5070
|
-
return async function(...args) {
|
|
5071
|
-
const params = splitArgsAndOptions(args);
|
|
5072
|
-
return contract.invoke(functionAbi.name, params.args, {
|
|
5073
|
-
parseRequest: true,
|
|
5074
|
-
...params.options
|
|
5046
|
+
// src/utils/transaction.ts
|
|
5047
|
+
var transaction_exports = {};
|
|
5048
|
+
__export(transaction_exports, {
|
|
5049
|
+
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
5050
|
+
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
5051
|
+
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
5052
|
+
getExecuteCalldata: () => getExecuteCalldata,
|
|
5053
|
+
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
5054
|
+
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
5055
|
+
});
|
|
5056
|
+
var transformCallsToMulticallArrays = (calls) => {
|
|
5057
|
+
const callArray = [];
|
|
5058
|
+
const calldata = [];
|
|
5059
|
+
calls.forEach((call) => {
|
|
5060
|
+
const data = CallData.compile(call.calldata || []);
|
|
5061
|
+
callArray.push({
|
|
5062
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
5063
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5064
|
+
data_offset: calldata.length.toString(),
|
|
5065
|
+
data_len: data.length.toString()
|
|
5075
5066
|
});
|
|
5067
|
+
calldata.push(...data);
|
|
5068
|
+
});
|
|
5069
|
+
return {
|
|
5070
|
+
callArray,
|
|
5071
|
+
calldata: CallData.compile({ calldata })
|
|
5076
5072
|
};
|
|
5077
|
-
}
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5073
|
+
};
|
|
5074
|
+
var fromCallsToExecuteCalldata = (calls) => {
|
|
5075
|
+
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5076
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
5077
|
+
return [...compiledCalls, ...calldata];
|
|
5078
|
+
};
|
|
5079
|
+
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5080
|
+
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
5081
|
+
};
|
|
5082
|
+
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
5083
|
+
const callArray = calls.map((call) => ({
|
|
5084
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
5085
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5086
|
+
calldata: CallData.compile(call.calldata || [])
|
|
5087
|
+
}));
|
|
5088
|
+
return callArray;
|
|
5089
|
+
};
|
|
5090
|
+
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5091
|
+
const orderCalls = calls.map((call) => ({
|
|
5092
|
+
contractAddress: call.contractAddress,
|
|
5093
|
+
entrypoint: call.entrypoint,
|
|
5094
|
+
calldata: call.calldata
|
|
5095
|
+
}));
|
|
5096
|
+
return CallData.compile({ orderCalls });
|
|
5097
|
+
};
|
|
5098
|
+
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5099
|
+
if (cairoVersion === "1") {
|
|
5100
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
5081
5101
|
}
|
|
5082
|
-
return
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
}
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
this.address = address && address.toLowerCase();
|
|
5111
|
-
this.providerOrAccount = providerOrAccount;
|
|
5112
|
-
this.callData = new CallData(abi);
|
|
5113
|
-
this.structs = CallData.getAbiStruct(abi);
|
|
5114
|
-
this.abi = abi;
|
|
5115
|
-
const options = { enumerable: true, value: {}, writable: false };
|
|
5116
|
-
Object.defineProperties(this, {
|
|
5117
|
-
functions: { enumerable: true, value: {}, writable: false },
|
|
5118
|
-
callStatic: { enumerable: true, value: {}, writable: false },
|
|
5119
|
-
populateTransaction: { enumerable: true, value: {}, writable: false },
|
|
5120
|
-
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
5121
|
-
});
|
|
5122
|
-
this.abi.forEach((abiElement) => {
|
|
5123
|
-
if (abiElement.type !== "function")
|
|
5124
|
-
return;
|
|
5125
|
-
const signature = abiElement.name;
|
|
5126
|
-
if (!this[signature]) {
|
|
5127
|
-
Object.defineProperty(this, signature, {
|
|
5128
|
-
...options,
|
|
5129
|
-
value: buildDefault(this, abiElement)
|
|
5130
|
-
});
|
|
5131
|
-
}
|
|
5132
|
-
if (!this.functions[signature]) {
|
|
5133
|
-
Object.defineProperty(this.functions, signature, {
|
|
5134
|
-
...options,
|
|
5135
|
-
value: buildDefault(this, abiElement)
|
|
5136
|
-
});
|
|
5137
|
-
}
|
|
5138
|
-
if (!this.callStatic[signature]) {
|
|
5139
|
-
Object.defineProperty(this.callStatic, signature, {
|
|
5140
|
-
...options,
|
|
5141
|
-
value: buildCall(this, abiElement)
|
|
5142
|
-
});
|
|
5143
|
-
}
|
|
5144
|
-
if (!this.populateTransaction[signature]) {
|
|
5145
|
-
Object.defineProperty(this.populateTransaction, signature, {
|
|
5146
|
-
...options,
|
|
5147
|
-
value: buildPopulate(this, abiElement)
|
|
5148
|
-
});
|
|
5149
|
-
}
|
|
5150
|
-
if (!this.estimateFee[signature]) {
|
|
5151
|
-
Object.defineProperty(this.estimateFee, signature, {
|
|
5152
|
-
...options,
|
|
5153
|
-
value: buildEstimate(this, abiElement)
|
|
5154
|
-
});
|
|
5155
|
-
}
|
|
5156
|
-
});
|
|
5157
|
-
}
|
|
5158
|
-
attach(address) {
|
|
5159
|
-
this.address = address;
|
|
5160
|
-
}
|
|
5161
|
-
connect(providerOrAccount) {
|
|
5162
|
-
this.providerOrAccount = providerOrAccount;
|
|
5102
|
+
return fromCallsToExecuteCalldata(calls);
|
|
5103
|
+
};
|
|
5104
|
+
|
|
5105
|
+
// src/utils/typedData.ts
|
|
5106
|
+
var typedData_exports = {};
|
|
5107
|
+
__export(typedData_exports, {
|
|
5108
|
+
encodeData: () => encodeData,
|
|
5109
|
+
encodeType: () => encodeType,
|
|
5110
|
+
encodeValue: () => encodeValue,
|
|
5111
|
+
getDependencies: () => getDependencies,
|
|
5112
|
+
getMessageHash: () => getMessageHash,
|
|
5113
|
+
getStructHash: () => getStructHash,
|
|
5114
|
+
getTypeHash: () => getTypeHash,
|
|
5115
|
+
isMerkleTreeType: () => isMerkleTreeType,
|
|
5116
|
+
prepareSelector: () => prepareSelector
|
|
5117
|
+
});
|
|
5118
|
+
|
|
5119
|
+
// src/utils/merkle.ts
|
|
5120
|
+
var merkle_exports = {};
|
|
5121
|
+
__export(merkle_exports, {
|
|
5122
|
+
MerkleTree: () => MerkleTree,
|
|
5123
|
+
proofMerklePath: () => proofMerklePath
|
|
5124
|
+
});
|
|
5125
|
+
var MerkleTree = class {
|
|
5126
|
+
constructor(leafHashes) {
|
|
5127
|
+
this.branches = [];
|
|
5128
|
+
this.leaves = leafHashes;
|
|
5129
|
+
this.root = this.build(leafHashes);
|
|
5163
5130
|
}
|
|
5164
|
-
|
|
5165
|
-
if (
|
|
5166
|
-
|
|
5167
|
-
this.deployTransactionHash = void 0;
|
|
5131
|
+
build(leaves) {
|
|
5132
|
+
if (leaves.length === 1) {
|
|
5133
|
+
return leaves[0];
|
|
5168
5134
|
}
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
async call(method, args = [], {
|
|
5172
|
-
parseRequest = true,
|
|
5173
|
-
parseResponse = true,
|
|
5174
|
-
formatResponse = void 0,
|
|
5175
|
-
blockIdentifier = void 0
|
|
5176
|
-
} = {}) {
|
|
5177
|
-
assert(this.address !== null, "contract is not connected to an address");
|
|
5178
|
-
const calldata = getCalldata(args, () => {
|
|
5179
|
-
if (parseRequest) {
|
|
5180
|
-
this.callData.validate("CALL", method, args);
|
|
5181
|
-
return this.callData.compile(method, args);
|
|
5182
|
-
}
|
|
5183
|
-
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
5184
|
-
return args;
|
|
5185
|
-
});
|
|
5186
|
-
return this.providerOrAccount.callContract(
|
|
5187
|
-
{
|
|
5188
|
-
contractAddress: this.address,
|
|
5189
|
-
calldata,
|
|
5190
|
-
entrypoint: method
|
|
5191
|
-
},
|
|
5192
|
-
blockIdentifier
|
|
5193
|
-
).then((x) => {
|
|
5194
|
-
if (!parseResponse) {
|
|
5195
|
-
return x.result;
|
|
5196
|
-
}
|
|
5197
|
-
if (formatResponse) {
|
|
5198
|
-
return this.callData.format(method, x.result, formatResponse);
|
|
5199
|
-
}
|
|
5200
|
-
return this.callData.parse(method, x.result);
|
|
5201
|
-
});
|
|
5202
|
-
}
|
|
5203
|
-
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
5204
|
-
assert(this.address !== null, "contract is not connected to an address");
|
|
5205
|
-
const calldata = getCalldata(args, () => {
|
|
5206
|
-
if (parseRequest) {
|
|
5207
|
-
this.callData.validate("INVOKE", method, args);
|
|
5208
|
-
return this.callData.compile(method, args);
|
|
5209
|
-
}
|
|
5210
|
-
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
5211
|
-
return args;
|
|
5212
|
-
});
|
|
5213
|
-
const invocation = {
|
|
5214
|
-
contractAddress: this.address,
|
|
5215
|
-
calldata,
|
|
5216
|
-
entrypoint: method
|
|
5217
|
-
};
|
|
5218
|
-
if ("execute" in this.providerOrAccount) {
|
|
5219
|
-
return this.providerOrAccount.execute(invocation, void 0, {
|
|
5220
|
-
maxFee,
|
|
5221
|
-
nonce
|
|
5222
|
-
});
|
|
5135
|
+
if (leaves.length !== this.leaves.length) {
|
|
5136
|
+
this.branches.push(leaves);
|
|
5223
5137
|
}
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
{
|
|
5229
|
-
|
|
5230
|
-
signature
|
|
5231
|
-
},
|
|
5232
|
-
{
|
|
5233
|
-
nonce
|
|
5138
|
+
const newLeaves = [];
|
|
5139
|
+
for (let i = 0; i < leaves.length; i += 2) {
|
|
5140
|
+
if (i + 1 === leaves.length) {
|
|
5141
|
+
newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
|
|
5142
|
+
} else {
|
|
5143
|
+
newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
|
|
5234
5144
|
}
|
|
5235
|
-
|
|
5145
|
+
}
|
|
5146
|
+
return this.build(newLeaves);
|
|
5236
5147
|
}
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5148
|
+
static hash(a, b) {
|
|
5149
|
+
const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
|
|
5150
|
+
return starkCurve.pedersen(aSorted, bSorted);
|
|
5151
|
+
}
|
|
5152
|
+
getProof(leaf, branch = this.leaves, hashPath = []) {
|
|
5153
|
+
const index = branch.indexOf(leaf);
|
|
5154
|
+
if (index === -1) {
|
|
5155
|
+
throw new Error("leaf not found");
|
|
5241
5156
|
}
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
5157
|
+
if (branch.length === 1) {
|
|
5158
|
+
return hashPath;
|
|
5245
5159
|
}
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
const
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5160
|
+
const isLeft = index % 2 === 0;
|
|
5161
|
+
const neededBranch = (isLeft ? branch[index + 1] : branch[index - 1]) ?? "0x0";
|
|
5162
|
+
const newHashPath = [...hashPath, neededBranch];
|
|
5163
|
+
const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
|
|
5164
|
+
const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
|
|
5165
|
+
return this.getProof(
|
|
5166
|
+
MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
5167
|
+
nextBranch,
|
|
5168
|
+
newHashPath
|
|
5169
|
+
);
|
|
5255
5170
|
}
|
|
5256
5171
|
};
|
|
5172
|
+
function proofMerklePath(root, leaf, path) {
|
|
5173
|
+
if (path.length === 0) {
|
|
5174
|
+
return root === leaf;
|
|
5175
|
+
}
|
|
5176
|
+
const [next, ...rest] = path;
|
|
5177
|
+
return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
|
|
5178
|
+
}
|
|
5257
5179
|
|
|
5258
|
-
// src/
|
|
5259
|
-
|
|
5180
|
+
// src/utils/typedData.ts
|
|
5181
|
+
function getHex(value) {
|
|
5182
|
+
try {
|
|
5183
|
+
return toHex(value);
|
|
5184
|
+
} catch (e) {
|
|
5185
|
+
if (typeof value === "string") {
|
|
5186
|
+
return toHex(encodeShortString(value));
|
|
5187
|
+
}
|
|
5188
|
+
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
5189
|
+
}
|
|
5190
|
+
}
|
|
5191
|
+
var validateTypedData = (data) => {
|
|
5192
|
+
const typedData = data;
|
|
5193
|
+
const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
|
|
5194
|
+
return valid;
|
|
5260
5195
|
};
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
}
|
|
5271
|
-
/**
|
|
5272
|
-
* Deploys contract and returns new instance of the Contract
|
|
5273
|
-
*
|
|
5274
|
-
* @param args - Array of the constructor arguments for deployment
|
|
5275
|
-
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
5276
|
-
* @returns deployed Contract
|
|
5277
|
-
*/
|
|
5278
|
-
async deploy(...args) {
|
|
5279
|
-
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
5280
|
-
const constructorCalldata = getCalldata(param, () => {
|
|
5281
|
-
if (options.parseRequest) {
|
|
5282
|
-
this.CallData.validate("DEPLOY", "constructor", param);
|
|
5283
|
-
return this.CallData.compile("constructor", param);
|
|
5284
|
-
}
|
|
5285
|
-
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
5286
|
-
return param;
|
|
5287
|
-
});
|
|
5288
|
-
const {
|
|
5289
|
-
deploy: { contract_address, transaction_hash }
|
|
5290
|
-
} = await this.account.declareAndDeploy({
|
|
5291
|
-
contract: this.compiledContract,
|
|
5292
|
-
constructorCalldata,
|
|
5293
|
-
salt: options.addressSalt
|
|
5294
|
-
});
|
|
5295
|
-
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
5296
|
-
const contractInstance = new Contract(
|
|
5297
|
-
this.compiledContract.abi,
|
|
5298
|
-
contract_address,
|
|
5299
|
-
this.account
|
|
5300
|
-
);
|
|
5301
|
-
contractInstance.deployTransactionHash = transaction_hash;
|
|
5302
|
-
return contractInstance;
|
|
5303
|
-
}
|
|
5304
|
-
/**
|
|
5305
|
-
* Attaches to new Account
|
|
5306
|
-
*
|
|
5307
|
-
* @param account - new Provider or Account to attach to
|
|
5308
|
-
* @returns ContractFactory
|
|
5309
|
-
*/
|
|
5310
|
-
connect(account) {
|
|
5311
|
-
this.account = account;
|
|
5312
|
-
return this;
|
|
5313
|
-
}
|
|
5314
|
-
/**
|
|
5315
|
-
* Attaches current abi and account to the new address
|
|
5316
|
-
*
|
|
5317
|
-
* @param address - Contract address
|
|
5318
|
-
* @returns Contract
|
|
5319
|
-
*/
|
|
5320
|
-
attach(address) {
|
|
5321
|
-
return new Contract(this.abi, address, this.account);
|
|
5322
|
-
}
|
|
5323
|
-
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
5324
|
-
};
|
|
5325
|
-
|
|
5326
|
-
// src/signer/interface.ts
|
|
5327
|
-
var SignerInterface = class {
|
|
5328
|
-
};
|
|
5329
|
-
|
|
5330
|
-
// src/utils/transaction.ts
|
|
5331
|
-
var transaction_exports = {};
|
|
5332
|
-
__export(transaction_exports, {
|
|
5333
|
-
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
5334
|
-
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
5335
|
-
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
5336
|
-
getExecuteCalldata: () => getExecuteCalldata,
|
|
5337
|
-
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
5338
|
-
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
5339
|
-
});
|
|
5340
|
-
var transformCallsToMulticallArrays = (calls) => {
|
|
5341
|
-
const callArray = [];
|
|
5342
|
-
const calldata = [];
|
|
5343
|
-
calls.forEach((call) => {
|
|
5344
|
-
const data = CallData.compile(call.calldata || []);
|
|
5345
|
-
callArray.push({
|
|
5346
|
-
to: toBigInt(call.contractAddress).toString(10),
|
|
5347
|
-
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5348
|
-
data_offset: calldata.length.toString(),
|
|
5349
|
-
data_len: data.length.toString()
|
|
5350
|
-
});
|
|
5351
|
-
calldata.push(...data);
|
|
5352
|
-
});
|
|
5353
|
-
return {
|
|
5354
|
-
callArray,
|
|
5355
|
-
calldata: CallData.compile({ calldata })
|
|
5356
|
-
};
|
|
5357
|
-
};
|
|
5358
|
-
var fromCallsToExecuteCalldata = (calls) => {
|
|
5359
|
-
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5360
|
-
const compiledCalls = CallData.compile({ callArray });
|
|
5361
|
-
return [...compiledCalls, ...calldata];
|
|
5362
|
-
};
|
|
5363
|
-
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5364
|
-
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
5365
|
-
};
|
|
5366
|
-
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
5367
|
-
const callArray = calls.map((call) => ({
|
|
5368
|
-
to: toBigInt(call.contractAddress).toString(10),
|
|
5369
|
-
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5370
|
-
calldata: CallData.compile(call.calldata || [])
|
|
5371
|
-
}));
|
|
5372
|
-
return callArray;
|
|
5373
|
-
};
|
|
5374
|
-
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5375
|
-
const orderCalls = calls.map((call) => ({
|
|
5376
|
-
contractAddress: call.contractAddress,
|
|
5377
|
-
entrypoint: call.entrypoint,
|
|
5378
|
-
calldata: call.calldata
|
|
5379
|
-
}));
|
|
5380
|
-
return CallData.compile({ orderCalls });
|
|
5381
|
-
};
|
|
5382
|
-
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5383
|
-
if (cairoVersion === "1") {
|
|
5384
|
-
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
5385
|
-
}
|
|
5386
|
-
return fromCallsToExecuteCalldata(calls);
|
|
5387
|
-
};
|
|
5388
|
-
|
|
5389
|
-
// src/utils/typedData/index.ts
|
|
5390
|
-
var typedData_exports = {};
|
|
5391
|
-
__export(typedData_exports, {
|
|
5392
|
-
encodeData: () => encodeData,
|
|
5393
|
-
encodeType: () => encodeType,
|
|
5394
|
-
encodeValue: () => encodeValue,
|
|
5395
|
-
getDependencies: () => getDependencies,
|
|
5396
|
-
getMessageHash: () => getMessageHash,
|
|
5397
|
-
getStructHash: () => getStructHash,
|
|
5398
|
-
getTypeHash: () => getTypeHash,
|
|
5399
|
-
isMerkleTreeType: () => isMerkleTreeType,
|
|
5400
|
-
prepareSelector: () => prepareSelector
|
|
5401
|
-
});
|
|
5402
|
-
|
|
5403
|
-
// src/utils/merkle.ts
|
|
5404
|
-
var merkle_exports = {};
|
|
5405
|
-
__export(merkle_exports, {
|
|
5406
|
-
MerkleTree: () => MerkleTree,
|
|
5407
|
-
proofMerklePath: () => proofMerklePath
|
|
5408
|
-
});
|
|
5409
|
-
var MerkleTree = class {
|
|
5410
|
-
constructor(leafHashes) {
|
|
5411
|
-
this.branches = [];
|
|
5412
|
-
this.leaves = leafHashes;
|
|
5413
|
-
this.root = this.build(leafHashes);
|
|
5414
|
-
}
|
|
5415
|
-
build(leaves) {
|
|
5416
|
-
if (leaves.length === 1) {
|
|
5417
|
-
return leaves[0];
|
|
5418
|
-
}
|
|
5419
|
-
if (leaves.length !== this.leaves.length) {
|
|
5420
|
-
this.branches.push(leaves);
|
|
5421
|
-
}
|
|
5422
|
-
const newLeaves = [];
|
|
5423
|
-
for (let i = 0; i < leaves.length; i += 2) {
|
|
5424
|
-
if (i + 1 === leaves.length) {
|
|
5425
|
-
newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
|
|
5426
|
-
} else {
|
|
5427
|
-
newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
|
|
5428
|
-
}
|
|
5429
|
-
}
|
|
5430
|
-
return this.build(newLeaves);
|
|
5431
|
-
}
|
|
5432
|
-
static hash(a, b) {
|
|
5433
|
-
const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
|
|
5434
|
-
return starkCurve.pedersen(aSorted, bSorted);
|
|
5435
|
-
}
|
|
5436
|
-
getProof(leaf, branch = this.leaves, hashPath = []) {
|
|
5437
|
-
const index = branch.indexOf(leaf);
|
|
5438
|
-
if (index === -1) {
|
|
5439
|
-
throw new Error("leaf not found");
|
|
5440
|
-
}
|
|
5441
|
-
if (branch.length === 1) {
|
|
5442
|
-
return hashPath;
|
|
5443
|
-
}
|
|
5444
|
-
const isLeft = index % 2 === 0;
|
|
5445
|
-
const neededBranch = (isLeft ? branch[index + 1] : branch[index - 1]) ?? "0x0";
|
|
5446
|
-
const newHashPath = [...hashPath, neededBranch];
|
|
5447
|
-
const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
|
|
5448
|
-
const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
|
|
5449
|
-
return this.getProof(
|
|
5450
|
-
MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
|
|
5451
|
-
nextBranch,
|
|
5452
|
-
newHashPath
|
|
5453
|
-
);
|
|
5454
|
-
}
|
|
5455
|
-
};
|
|
5456
|
-
function proofMerklePath(root, leaf, path) {
|
|
5457
|
-
if (path.length === 0) {
|
|
5458
|
-
return root === leaf;
|
|
5459
|
-
}
|
|
5460
|
-
const [next, ...rest] = path;
|
|
5461
|
-
return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
|
|
5462
|
-
}
|
|
5463
|
-
|
|
5464
|
-
// src/utils/typedData/utils.ts
|
|
5465
|
-
var validateTypedData = (data) => {
|
|
5466
|
-
const typedData = data;
|
|
5467
|
-
const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
|
|
5468
|
-
return valid;
|
|
5469
|
-
};
|
|
5470
|
-
|
|
5471
|
-
// src/utils/typedData/index.ts
|
|
5472
|
-
function getHex(value) {
|
|
5473
|
-
try {
|
|
5474
|
-
return toHex(value);
|
|
5475
|
-
} catch (e) {
|
|
5476
|
-
if (typeof value === "string") {
|
|
5477
|
-
return toHex(encodeShortString(value));
|
|
5478
|
-
}
|
|
5479
|
-
throw new Error(`Invalid BigNumberish: ${value}`);
|
|
5480
|
-
}
|
|
5481
|
-
}
|
|
5482
|
-
function prepareSelector(selector) {
|
|
5483
|
-
return isHex(selector) ? selector : getSelectorFromName(selector);
|
|
5484
|
-
}
|
|
5485
|
-
function isMerkleTreeType(type) {
|
|
5486
|
-
return type.type === "merkletree";
|
|
5487
|
-
}
|
|
5488
|
-
var getDependencies = (types, type, dependencies = []) => {
|
|
5489
|
-
if (type[type.length - 1] === "*") {
|
|
5490
|
-
type = type.slice(0, -1);
|
|
5196
|
+
function prepareSelector(selector) {
|
|
5197
|
+
return isHex(selector) ? selector : getSelectorFromName(selector);
|
|
5198
|
+
}
|
|
5199
|
+
function isMerkleTreeType(type) {
|
|
5200
|
+
return type.type === "merkletree";
|
|
5201
|
+
}
|
|
5202
|
+
var getDependencies = (types, type, dependencies = []) => {
|
|
5203
|
+
if (type[type.length - 1] === "*") {
|
|
5204
|
+
type = type.slice(0, -1);
|
|
5491
5205
|
}
|
|
5492
5206
|
if (dependencies.includes(type)) {
|
|
5493
5207
|
return dependencies;
|
|
@@ -6012,191 +5726,483 @@ var Account = class extends Provider {
|
|
|
6012
5726
|
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
6013
5727
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
6014
5728
|
{
|
|
6015
|
-
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
6016
|
-
payload: {
|
|
6017
|
-
classHash,
|
|
6018
|
-
constructorCalldata: compiledCalldata,
|
|
6019
|
-
addressSalt,
|
|
6020
|
-
contractAddress
|
|
6021
|
-
}
|
|
5729
|
+
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
5730
|
+
payload: {
|
|
5731
|
+
classHash,
|
|
5732
|
+
constructorCalldata: compiledCalldata,
|
|
5733
|
+
addressSalt,
|
|
5734
|
+
contractAddress
|
|
5735
|
+
}
|
|
5736
|
+
},
|
|
5737
|
+
transactionsDetail
|
|
5738
|
+
);
|
|
5739
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
5740
|
+
classHash,
|
|
5741
|
+
constructorCalldata: compiledCalldata,
|
|
5742
|
+
contractAddress,
|
|
5743
|
+
addressSalt,
|
|
5744
|
+
chainId,
|
|
5745
|
+
maxFee,
|
|
5746
|
+
version,
|
|
5747
|
+
nonce
|
|
5748
|
+
});
|
|
5749
|
+
return this.deployAccountContract(
|
|
5750
|
+
{ classHash, addressSalt, constructorCalldata, signature },
|
|
5751
|
+
{
|
|
5752
|
+
nonce,
|
|
5753
|
+
maxFee,
|
|
5754
|
+
version
|
|
5755
|
+
}
|
|
5756
|
+
);
|
|
5757
|
+
}
|
|
5758
|
+
async signMessage(typedData) {
|
|
5759
|
+
return this.signer.signMessage(typedData, this.address);
|
|
5760
|
+
}
|
|
5761
|
+
async hashMessage(typedData) {
|
|
5762
|
+
return getMessageHash(typedData, this.address);
|
|
5763
|
+
}
|
|
5764
|
+
async verifyMessageHash(hash, signature) {
|
|
5765
|
+
try {
|
|
5766
|
+
await this.callContract({
|
|
5767
|
+
contractAddress: this.address,
|
|
5768
|
+
entrypoint: "isValidSignature",
|
|
5769
|
+
calldata: CallData.compile({
|
|
5770
|
+
hash: toBigInt(hash).toString(),
|
|
5771
|
+
signature: formatSignature(signature)
|
|
5772
|
+
})
|
|
5773
|
+
});
|
|
5774
|
+
return true;
|
|
5775
|
+
} catch {
|
|
5776
|
+
return false;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
async verifyMessage(typedData, signature) {
|
|
5780
|
+
const hash = await this.hashMessage(typedData);
|
|
5781
|
+
return this.verifyMessageHash(hash, signature);
|
|
5782
|
+
}
|
|
5783
|
+
async getSuggestedMaxFee({ type, payload }, details) {
|
|
5784
|
+
let feeEstimate;
|
|
5785
|
+
switch (type) {
|
|
5786
|
+
case "INVOKE_FUNCTION" /* INVOKE */:
|
|
5787
|
+
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
5788
|
+
break;
|
|
5789
|
+
case "DECLARE" /* DECLARE */:
|
|
5790
|
+
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
5791
|
+
break;
|
|
5792
|
+
case "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */:
|
|
5793
|
+
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
5794
|
+
break;
|
|
5795
|
+
case "DEPLOY" /* DEPLOY */:
|
|
5796
|
+
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
5797
|
+
break;
|
|
5798
|
+
default:
|
|
5799
|
+
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
5800
|
+
break;
|
|
5801
|
+
}
|
|
5802
|
+
return feeEstimate.suggestedMaxFee;
|
|
5803
|
+
}
|
|
5804
|
+
/**
|
|
5805
|
+
* will be renamed to buildDeclareContractTransaction
|
|
5806
|
+
*/
|
|
5807
|
+
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
5808
|
+
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
5809
|
+
const contractDefinition = parseContract(contract);
|
|
5810
|
+
const signature = await this.signer.signDeclareTransaction({
|
|
5811
|
+
classHash,
|
|
5812
|
+
compiledClassHash,
|
|
5813
|
+
senderAddress: walletAddress,
|
|
5814
|
+
chainId,
|
|
5815
|
+
maxFee,
|
|
5816
|
+
version,
|
|
5817
|
+
nonce
|
|
5818
|
+
});
|
|
5819
|
+
return {
|
|
5820
|
+
senderAddress: walletAddress,
|
|
5821
|
+
signature,
|
|
5822
|
+
contractDefinition,
|
|
5823
|
+
compiledClassHash
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
async buildAccountDeployPayload({
|
|
5827
|
+
classHash,
|
|
5828
|
+
addressSalt = 0,
|
|
5829
|
+
constructorCalldata = [],
|
|
5830
|
+
contractAddress: providedContractAddress
|
|
5831
|
+
}, { nonce, chainId, version, maxFee }) {
|
|
5832
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5833
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5834
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
5835
|
+
classHash,
|
|
5836
|
+
contractAddress,
|
|
5837
|
+
chainId,
|
|
5838
|
+
maxFee,
|
|
5839
|
+
version,
|
|
5840
|
+
nonce,
|
|
5841
|
+
addressSalt,
|
|
5842
|
+
constructorCalldata: compiledCalldata
|
|
5843
|
+
});
|
|
5844
|
+
return {
|
|
5845
|
+
classHash,
|
|
5846
|
+
addressSalt,
|
|
5847
|
+
constructorCalldata: compiledCalldata,
|
|
5848
|
+
signature
|
|
5849
|
+
};
|
|
5850
|
+
}
|
|
5851
|
+
buildUDCContractPayload(payload) {
|
|
5852
|
+
const calls = [].concat(payload).map((it) => {
|
|
5853
|
+
const {
|
|
5854
|
+
classHash,
|
|
5855
|
+
salt = "0",
|
|
5856
|
+
unique = true,
|
|
5857
|
+
constructorCalldata = []
|
|
5858
|
+
} = it;
|
|
5859
|
+
const compiledConstructorCallData = CallData.compile(constructorCalldata);
|
|
5860
|
+
return {
|
|
5861
|
+
contractAddress: UDC.ADDRESS,
|
|
5862
|
+
entrypoint: UDC.ENTRYPOINT,
|
|
5863
|
+
calldata: [
|
|
5864
|
+
classHash,
|
|
5865
|
+
salt,
|
|
5866
|
+
toCairoBool(unique),
|
|
5867
|
+
compiledConstructorCallData.length,
|
|
5868
|
+
...compiledConstructorCallData
|
|
5869
|
+
]
|
|
5870
|
+
};
|
|
5871
|
+
});
|
|
5872
|
+
return calls;
|
|
5873
|
+
}
|
|
5874
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
|
|
5875
|
+
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
5876
|
+
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
5877
|
+
const version = toBigInt(feeTransactionVersion);
|
|
5878
|
+
const chainId = await this.getChainId();
|
|
5879
|
+
const signerDetails = {
|
|
5880
|
+
walletAddress: this.address,
|
|
5881
|
+
nonce,
|
|
5882
|
+
maxFee: ZERO,
|
|
5883
|
+
version,
|
|
5884
|
+
chainId,
|
|
5885
|
+
cairoVersion: this.cairoVersion
|
|
5886
|
+
};
|
|
5887
|
+
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
5888
|
+
const response = await super.getSimulateTransaction(
|
|
5889
|
+
invocation,
|
|
5890
|
+
{ version, nonce },
|
|
5891
|
+
blockIdentifier,
|
|
5892
|
+
skipValidate
|
|
5893
|
+
);
|
|
5894
|
+
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
5895
|
+
return {
|
|
5896
|
+
...response,
|
|
5897
|
+
fee_estimation: {
|
|
5898
|
+
...response.fee_estimation,
|
|
5899
|
+
suggestedMaxFee
|
|
5900
|
+
}
|
|
5901
|
+
};
|
|
5902
|
+
}
|
|
5903
|
+
async getStarkName(address = this.address, StarknetIdContract2) {
|
|
5904
|
+
return super.getStarkName(address, StarknetIdContract2);
|
|
5905
|
+
}
|
|
5906
|
+
};
|
|
5907
|
+
|
|
5908
|
+
// src/provider/interface.ts
|
|
5909
|
+
var ProviderInterface = class {
|
|
5910
|
+
};
|
|
5911
|
+
|
|
5912
|
+
// src/provider/index.ts
|
|
5913
|
+
var defaultProvider = new Provider();
|
|
5914
|
+
|
|
5915
|
+
// src/account/interface.ts
|
|
5916
|
+
var AccountInterface = class extends ProviderInterface {
|
|
5917
|
+
};
|
|
5918
|
+
|
|
5919
|
+
// src/contract/default.ts
|
|
5920
|
+
var splitArgsAndOptions = (args) => {
|
|
5921
|
+
const options = [
|
|
5922
|
+
"blockIdentifier",
|
|
5923
|
+
"parseRequest",
|
|
5924
|
+
"parseResponse",
|
|
5925
|
+
"formatResponse",
|
|
5926
|
+
"maxFee",
|
|
5927
|
+
"nonce",
|
|
5928
|
+
"signature",
|
|
5929
|
+
"addressSalt"
|
|
5930
|
+
];
|
|
5931
|
+
const lastArg = args[args.length - 1];
|
|
5932
|
+
if (typeof lastArg === "object" && options.some((x) => x in lastArg)) {
|
|
5933
|
+
return { args, options: args.pop() };
|
|
5934
|
+
}
|
|
5935
|
+
return { args };
|
|
5936
|
+
};
|
|
5937
|
+
function buildCall(contract, functionAbi) {
|
|
5938
|
+
return async function(...args) {
|
|
5939
|
+
const params = splitArgsAndOptions(args);
|
|
5940
|
+
return contract.call(functionAbi.name, params.args, {
|
|
5941
|
+
parseRequest: true,
|
|
5942
|
+
parseResponse: true,
|
|
5943
|
+
...params.options
|
|
5944
|
+
});
|
|
5945
|
+
};
|
|
5946
|
+
}
|
|
5947
|
+
function buildInvoke(contract, functionAbi) {
|
|
5948
|
+
return async function(...args) {
|
|
5949
|
+
const params = splitArgsAndOptions(args);
|
|
5950
|
+
return contract.invoke(functionAbi.name, params.args, {
|
|
5951
|
+
parseRequest: true,
|
|
5952
|
+
...params.options
|
|
5953
|
+
});
|
|
5954
|
+
};
|
|
5955
|
+
}
|
|
5956
|
+
function buildDefault(contract, functionAbi) {
|
|
5957
|
+
if (functionAbi.stateMutability === "view" || functionAbi.state_mutability === "view") {
|
|
5958
|
+
return buildCall(contract, functionAbi);
|
|
5959
|
+
}
|
|
5960
|
+
return buildInvoke(contract, functionAbi);
|
|
5961
|
+
}
|
|
5962
|
+
function buildPopulate(contract, functionAbi) {
|
|
5963
|
+
return function(...args) {
|
|
5964
|
+
return contract.populate(functionAbi.name, args);
|
|
5965
|
+
};
|
|
5966
|
+
}
|
|
5967
|
+
function buildEstimate(contract, functionAbi) {
|
|
5968
|
+
return function(...args) {
|
|
5969
|
+
return contract.estimate(functionAbi.name, args);
|
|
5970
|
+
};
|
|
5971
|
+
}
|
|
5972
|
+
function getCalldata(args, callback) {
|
|
5973
|
+
if (Array.isArray(args) && "__compiled__" in args)
|
|
5974
|
+
return args;
|
|
5975
|
+
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
5976
|
+
return args[0];
|
|
5977
|
+
return callback();
|
|
5978
|
+
}
|
|
5979
|
+
var Contract = class {
|
|
5980
|
+
/**
|
|
5981
|
+
* Contract class to handle contract methods
|
|
5982
|
+
*
|
|
5983
|
+
* @param abi - Abi of the contract object
|
|
5984
|
+
* @param address (optional) - address to connect to
|
|
5985
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
5986
|
+
*/
|
|
5987
|
+
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
5988
|
+
this.address = address && address.toLowerCase();
|
|
5989
|
+
this.providerOrAccount = providerOrAccount;
|
|
5990
|
+
this.callData = new CallData(abi);
|
|
5991
|
+
this.structs = CallData.getAbiStruct(abi);
|
|
5992
|
+
this.abi = abi;
|
|
5993
|
+
const options = { enumerable: true, value: {}, writable: false };
|
|
5994
|
+
Object.defineProperties(this, {
|
|
5995
|
+
functions: { enumerable: true, value: {}, writable: false },
|
|
5996
|
+
callStatic: { enumerable: true, value: {}, writable: false },
|
|
5997
|
+
populateTransaction: { enumerable: true, value: {}, writable: false },
|
|
5998
|
+
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
5999
|
+
});
|
|
6000
|
+
this.abi.forEach((abiElement) => {
|
|
6001
|
+
if (abiElement.type !== "function")
|
|
6002
|
+
return;
|
|
6003
|
+
const signature = abiElement.name;
|
|
6004
|
+
if (!this[signature]) {
|
|
6005
|
+
Object.defineProperty(this, signature, {
|
|
6006
|
+
...options,
|
|
6007
|
+
value: buildDefault(this, abiElement)
|
|
6008
|
+
});
|
|
6009
|
+
}
|
|
6010
|
+
if (!this.functions[signature]) {
|
|
6011
|
+
Object.defineProperty(this.functions, signature, {
|
|
6012
|
+
...options,
|
|
6013
|
+
value: buildDefault(this, abiElement)
|
|
6014
|
+
});
|
|
6015
|
+
}
|
|
6016
|
+
if (!this.callStatic[signature]) {
|
|
6017
|
+
Object.defineProperty(this.callStatic, signature, {
|
|
6018
|
+
...options,
|
|
6019
|
+
value: buildCall(this, abiElement)
|
|
6020
|
+
});
|
|
6021
|
+
}
|
|
6022
|
+
if (!this.populateTransaction[signature]) {
|
|
6023
|
+
Object.defineProperty(this.populateTransaction, signature, {
|
|
6024
|
+
...options,
|
|
6025
|
+
value: buildPopulate(this, abiElement)
|
|
6026
|
+
});
|
|
6027
|
+
}
|
|
6028
|
+
if (!this.estimateFee[signature]) {
|
|
6029
|
+
Object.defineProperty(this.estimateFee, signature, {
|
|
6030
|
+
...options,
|
|
6031
|
+
value: buildEstimate(this, abiElement)
|
|
6032
|
+
});
|
|
6033
|
+
}
|
|
6034
|
+
});
|
|
6035
|
+
}
|
|
6036
|
+
attach(address) {
|
|
6037
|
+
this.address = address;
|
|
6038
|
+
}
|
|
6039
|
+
connect(providerOrAccount) {
|
|
6040
|
+
this.providerOrAccount = providerOrAccount;
|
|
6041
|
+
}
|
|
6042
|
+
async deployed() {
|
|
6043
|
+
if (this.deployTransactionHash) {
|
|
6044
|
+
await this.providerOrAccount.waitForTransaction(this.deployTransactionHash);
|
|
6045
|
+
this.deployTransactionHash = void 0;
|
|
6046
|
+
}
|
|
6047
|
+
return this;
|
|
6048
|
+
}
|
|
6049
|
+
async call(method, args = [], {
|
|
6050
|
+
parseRequest = true,
|
|
6051
|
+
parseResponse = true,
|
|
6052
|
+
formatResponse = void 0,
|
|
6053
|
+
blockIdentifier = void 0
|
|
6054
|
+
} = {}) {
|
|
6055
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
6056
|
+
const calldata = getCalldata(args, () => {
|
|
6057
|
+
if (parseRequest) {
|
|
6058
|
+
this.callData.validate("CALL", method, args);
|
|
6059
|
+
return this.callData.compile(method, args);
|
|
6060
|
+
}
|
|
6061
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
6062
|
+
return args;
|
|
6063
|
+
});
|
|
6064
|
+
return this.providerOrAccount.callContract(
|
|
6065
|
+
{
|
|
6066
|
+
contractAddress: this.address,
|
|
6067
|
+
calldata,
|
|
6068
|
+
entrypoint: method
|
|
6069
|
+
},
|
|
6070
|
+
blockIdentifier
|
|
6071
|
+
).then((x) => {
|
|
6072
|
+
if (!parseResponse) {
|
|
6073
|
+
return x.result;
|
|
6074
|
+
}
|
|
6075
|
+
if (formatResponse) {
|
|
6076
|
+
return this.callData.format(method, x.result, formatResponse);
|
|
6077
|
+
}
|
|
6078
|
+
return this.callData.parse(method, x.result);
|
|
6079
|
+
});
|
|
6080
|
+
}
|
|
6081
|
+
invoke(method, args = [], { parseRequest = true, maxFee, nonce, signature } = {}) {
|
|
6082
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
6083
|
+
const calldata = getCalldata(args, () => {
|
|
6084
|
+
if (parseRequest) {
|
|
6085
|
+
this.callData.validate("INVOKE", method, args);
|
|
6086
|
+
return this.callData.compile(method, args);
|
|
6087
|
+
}
|
|
6088
|
+
console.warn("Invoke skipped parsing but provided rawArgs, possible malfunction request");
|
|
6089
|
+
return args;
|
|
6090
|
+
});
|
|
6091
|
+
const invocation = {
|
|
6092
|
+
contractAddress: this.address,
|
|
6093
|
+
calldata,
|
|
6094
|
+
entrypoint: method
|
|
6095
|
+
};
|
|
6096
|
+
if ("execute" in this.providerOrAccount) {
|
|
6097
|
+
return this.providerOrAccount.execute(invocation, void 0, {
|
|
6098
|
+
maxFee,
|
|
6099
|
+
nonce
|
|
6100
|
+
});
|
|
6101
|
+
}
|
|
6102
|
+
if (!nonce)
|
|
6103
|
+
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
6104
|
+
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
6105
|
+
return this.providerOrAccount.invokeFunction(
|
|
6106
|
+
{
|
|
6107
|
+
...invocation,
|
|
6108
|
+
signature
|
|
6022
6109
|
},
|
|
6023
|
-
transactionsDetail
|
|
6024
|
-
);
|
|
6025
|
-
const signature = await this.signer.signDeployAccountTransaction({
|
|
6026
|
-
classHash,
|
|
6027
|
-
constructorCalldata: compiledCalldata,
|
|
6028
|
-
contractAddress,
|
|
6029
|
-
addressSalt,
|
|
6030
|
-
chainId,
|
|
6031
|
-
maxFee,
|
|
6032
|
-
version,
|
|
6033
|
-
nonce
|
|
6034
|
-
});
|
|
6035
|
-
return this.deployAccountContract(
|
|
6036
|
-
{ classHash, addressSalt, constructorCalldata, signature },
|
|
6037
6110
|
{
|
|
6038
|
-
nonce
|
|
6039
|
-
maxFee,
|
|
6040
|
-
version
|
|
6111
|
+
nonce
|
|
6041
6112
|
}
|
|
6042
6113
|
);
|
|
6043
6114
|
}
|
|
6044
|
-
async
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
return getMessageHash(typedData, this.address);
|
|
6049
|
-
}
|
|
6050
|
-
async verifyMessageHash(hash, signature) {
|
|
6051
|
-
try {
|
|
6052
|
-
await this.callContract({
|
|
6053
|
-
contractAddress: this.address,
|
|
6054
|
-
entrypoint: "isValidSignature",
|
|
6055
|
-
calldata: CallData.compile({
|
|
6056
|
-
hash: toBigInt(hash).toString(),
|
|
6057
|
-
signature: formatSignature(signature)
|
|
6058
|
-
})
|
|
6059
|
-
});
|
|
6060
|
-
return true;
|
|
6061
|
-
} catch {
|
|
6062
|
-
return false;
|
|
6115
|
+
async estimate(method, args = []) {
|
|
6116
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
6117
|
+
if (!getCalldata(args, () => false)) {
|
|
6118
|
+
this.callData.validate("INVOKE", method, args);
|
|
6063
6119
|
}
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
return this.verifyMessageHash(hash, signature);
|
|
6068
|
-
}
|
|
6069
|
-
async getSuggestedMaxFee({ type, payload }, details) {
|
|
6070
|
-
let feeEstimate;
|
|
6071
|
-
switch (type) {
|
|
6072
|
-
case "INVOKE_FUNCTION" /* INVOKE */:
|
|
6073
|
-
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
6074
|
-
break;
|
|
6075
|
-
case "DECLARE" /* DECLARE */:
|
|
6076
|
-
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
6077
|
-
break;
|
|
6078
|
-
case "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */:
|
|
6079
|
-
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
6080
|
-
break;
|
|
6081
|
-
case "DEPLOY" /* DEPLOY */:
|
|
6082
|
-
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
6083
|
-
break;
|
|
6084
|
-
default:
|
|
6085
|
-
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
6086
|
-
break;
|
|
6120
|
+
const invocation = this.populate(method, args);
|
|
6121
|
+
if ("estimateInvokeFee" in this.providerOrAccount) {
|
|
6122
|
+
return this.providerOrAccount.estimateInvokeFee(invocation);
|
|
6087
6123
|
}
|
|
6088
|
-
|
|
6124
|
+
throw Error("Contract must be connected to the account contract to estimate");
|
|
6089
6125
|
}
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
*/
|
|
6093
|
-
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
6094
|
-
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
6095
|
-
const contractDefinition = parseContract(contract);
|
|
6096
|
-
const signature = await this.signer.signDeclareTransaction({
|
|
6097
|
-
classHash,
|
|
6098
|
-
compiledClassHash,
|
|
6099
|
-
senderAddress: walletAddress,
|
|
6100
|
-
chainId,
|
|
6101
|
-
maxFee,
|
|
6102
|
-
version,
|
|
6103
|
-
nonce
|
|
6104
|
-
});
|
|
6126
|
+
populate(method, args = []) {
|
|
6127
|
+
const calldata = getCalldata(args, () => this.callData.compile(method, args));
|
|
6105
6128
|
return {
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
compiledClassHash
|
|
6129
|
+
contractAddress: this.address,
|
|
6130
|
+
entrypoint: method,
|
|
6131
|
+
calldata
|
|
6110
6132
|
};
|
|
6111
6133
|
}
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
nonce,
|
|
6127
|
-
addressSalt,
|
|
6128
|
-
constructorCalldata: compiledCalldata
|
|
6129
|
-
});
|
|
6130
|
-
return {
|
|
6131
|
-
classHash,
|
|
6132
|
-
addressSalt,
|
|
6133
|
-
constructorCalldata: compiledCalldata,
|
|
6134
|
-
signature
|
|
6135
|
-
};
|
|
6134
|
+
};
|
|
6135
|
+
|
|
6136
|
+
// src/contract/interface.ts
|
|
6137
|
+
var ContractInterface = class {
|
|
6138
|
+
};
|
|
6139
|
+
|
|
6140
|
+
// src/contract/contractFactory.ts
|
|
6141
|
+
var ContractFactory = class {
|
|
6142
|
+
constructor(compiledContract, classHash, account, abi = compiledContract.abi) {
|
|
6143
|
+
this.abi = abi;
|
|
6144
|
+
this.compiledContract = compiledContract;
|
|
6145
|
+
this.account = account;
|
|
6146
|
+
this.classHash = classHash;
|
|
6147
|
+
this.CallData = new CallData(abi);
|
|
6136
6148
|
}
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
compiledConstructorCallData.length,
|
|
6154
|
-
...compiledConstructorCallData
|
|
6155
|
-
]
|
|
6156
|
-
};
|
|
6149
|
+
/**
|
|
6150
|
+
* Deploys contract and returns new instance of the Contract
|
|
6151
|
+
*
|
|
6152
|
+
* @param args - Array of the constructor arguments for deployment
|
|
6153
|
+
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
6154
|
+
* @returns deployed Contract
|
|
6155
|
+
*/
|
|
6156
|
+
async deploy(...args) {
|
|
6157
|
+
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
6158
|
+
const constructorCalldata = getCalldata(param, () => {
|
|
6159
|
+
if (options.parseRequest) {
|
|
6160
|
+
this.CallData.validate("DEPLOY", "constructor", param);
|
|
6161
|
+
return this.CallData.compile("constructor", param);
|
|
6162
|
+
}
|
|
6163
|
+
console.warn("Call skipped parsing but provided rawArgs, possible malfunction request");
|
|
6164
|
+
return param;
|
|
6157
6165
|
});
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
chainId,
|
|
6171
|
-
cairoVersion: this.cairoVersion
|
|
6172
|
-
};
|
|
6173
|
-
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
6174
|
-
const response = await super.getSimulateTransaction(
|
|
6175
|
-
invocation,
|
|
6176
|
-
{ version, nonce },
|
|
6177
|
-
blockIdentifier,
|
|
6178
|
-
skipValidate
|
|
6166
|
+
const {
|
|
6167
|
+
deploy: { contract_address, transaction_hash }
|
|
6168
|
+
} = await this.account.declareAndDeploy({
|
|
6169
|
+
contract: this.compiledContract,
|
|
6170
|
+
constructorCalldata,
|
|
6171
|
+
salt: options.addressSalt
|
|
6172
|
+
});
|
|
6173
|
+
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
6174
|
+
const contractInstance = new Contract(
|
|
6175
|
+
this.compiledContract.abi,
|
|
6176
|
+
contract_address,
|
|
6177
|
+
this.account
|
|
6179
6178
|
);
|
|
6180
|
-
|
|
6181
|
-
return
|
|
6182
|
-
...response,
|
|
6183
|
-
fee_estimation: {
|
|
6184
|
-
...response.fee_estimation,
|
|
6185
|
-
suggestedMaxFee
|
|
6186
|
-
}
|
|
6187
|
-
};
|
|
6179
|
+
contractInstance.deployTransactionHash = transaction_hash;
|
|
6180
|
+
return contractInstance;
|
|
6188
6181
|
}
|
|
6189
|
-
|
|
6190
|
-
|
|
6182
|
+
/**
|
|
6183
|
+
* Attaches to new Account
|
|
6184
|
+
*
|
|
6185
|
+
* @param account - new Provider or Account to attach to
|
|
6186
|
+
* @returns ContractFactory
|
|
6187
|
+
*/
|
|
6188
|
+
connect(account) {
|
|
6189
|
+
this.account = account;
|
|
6190
|
+
return this;
|
|
6191
6191
|
}
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6192
|
+
/**
|
|
6193
|
+
* Attaches current abi and account to the new address
|
|
6194
|
+
*
|
|
6195
|
+
* @param address - Contract address
|
|
6196
|
+
* @returns Contract
|
|
6197
|
+
*/
|
|
6198
|
+
attach(address) {
|
|
6199
|
+
return new Contract(this.abi, address, this.account);
|
|
6200
|
+
}
|
|
6201
|
+
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
6196
6202
|
};
|
|
6197
6203
|
|
|
6198
6204
|
// src/utils/address.ts
|
|
6199
|
-
var
|
|
6205
|
+
var import_utils4 = require("@noble/curves/abstract/utils");
|
|
6200
6206
|
function addAddressPadding(address) {
|
|
6201
6207
|
return addHexPrefix(removeHexPrefix(toHex(address)).padStart(64, "0"));
|
|
6202
6208
|
}
|
|
@@ -6211,7 +6217,7 @@ function validateAndParseAddress(address) {
|
|
|
6211
6217
|
function getChecksumAddress(address) {
|
|
6212
6218
|
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
6213
6219
|
const hex = removeHexPrefix(keccakBn(address));
|
|
6214
|
-
const hashed = (0,
|
|
6220
|
+
const hashed = (0, import_utils4.hexToBytes)(hex.padStart(64, "0"));
|
|
6215
6221
|
for (let i = 0; i < chars.length; i += 2) {
|
|
6216
6222
|
if (hashed[i >> 1] >> 4 >= 8) {
|
|
6217
6223
|
chars[i] = chars[i].toUpperCase();
|
|
@@ -6273,6 +6279,7 @@ var number = num_exports;
|
|
|
6273
6279
|
starknetId,
|
|
6274
6280
|
transaction,
|
|
6275
6281
|
typedData,
|
|
6282
|
+
types,
|
|
6276
6283
|
uint256,
|
|
6277
6284
|
validateAndParseAddress,
|
|
6278
6285
|
validateChecksumAddress
|