starknet 6.11.0 → 6.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 +118 -0
- package/README.md +1 -1
- package/dist/index.d.ts +393 -64
- package/dist/index.global.js +7701 -7440
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +450 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +448 -152
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(constants_exports, {
|
|
|
25
25
|
FeeMarginPercentage: () => FeeMarginPercentage,
|
|
26
26
|
IS_BROWSER: () => IS_BROWSER,
|
|
27
27
|
MASK_250: () => MASK_250,
|
|
28
|
+
MASK_31: () => MASK_31,
|
|
28
29
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
29
30
|
NetworkName: () => NetworkName,
|
|
30
31
|
PRIME: () => PRIME,
|
|
@@ -142,10 +143,10 @@ var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion25) => {
|
|
|
142
143
|
ETransactionVersion25["F2"] = "0x100000000000000000000000000000002";
|
|
143
144
|
return ETransactionVersion25;
|
|
144
145
|
})(ETransactionVersion2 || {});
|
|
145
|
-
var ETransactionVersion3 = /* @__PURE__ */ ((
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
146
|
+
var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion37) => {
|
|
147
|
+
ETransactionVersion37["V3"] = "0x3";
|
|
148
|
+
ETransactionVersion37["F3"] = "0x100000000000000000000000000000003";
|
|
149
|
+
return ETransactionVersion37;
|
|
149
150
|
})(ETransactionVersion3 || {});
|
|
150
151
|
|
|
151
152
|
// src/types/api/index.ts
|
|
@@ -163,6 +164,7 @@ __export(encode_exports, {
|
|
|
163
164
|
btoaUniversal: () => btoaUniversal,
|
|
164
165
|
buf2hex: () => buf2hex,
|
|
165
166
|
calcByteLength: () => calcByteLength,
|
|
167
|
+
concatenateArrayBuffer: () => concatenateArrayBuffer,
|
|
166
168
|
padLeft: () => padLeft,
|
|
167
169
|
pascalToSnake: () => pascalToSnake,
|
|
168
170
|
removeHexPrefix: () => removeHexPrefix,
|
|
@@ -227,11 +229,22 @@ function sanitizeHex(hex) {
|
|
|
227
229
|
return hex;
|
|
228
230
|
}
|
|
229
231
|
var pascalToSnake = (text) => /[a-z]/.test(text) ? text.split(/(?=[A-Z])/).join("_").toUpperCase() : text;
|
|
232
|
+
function concatenateArrayBuffer(uint8arrays) {
|
|
233
|
+
const totalLength = uint8arrays.reduce((total, uint8array) => total + uint8array.byteLength, 0);
|
|
234
|
+
const result = new Uint8Array(totalLength);
|
|
235
|
+
let offset = 0;
|
|
236
|
+
uint8arrays.forEach((uint8array) => {
|
|
237
|
+
result.set(uint8array, offset);
|
|
238
|
+
offset += uint8array.byteLength;
|
|
239
|
+
});
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
230
242
|
|
|
231
243
|
// src/constants.ts
|
|
232
244
|
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
233
245
|
var ZERO = 0n;
|
|
234
246
|
var MASK_250 = 2n ** 250n - 1n;
|
|
247
|
+
var MASK_31 = 2n ** 31n - 1n;
|
|
235
248
|
var API_VERSION = ZERO;
|
|
236
249
|
var PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
237
250
|
var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
@@ -285,10 +298,6 @@ var RPC_NODES = {
|
|
|
285
298
|
]
|
|
286
299
|
};
|
|
287
300
|
|
|
288
|
-
// src/provider/rpc.ts
|
|
289
|
-
import { bytesToHex } from "@noble/curves/abstract/utils";
|
|
290
|
-
import { keccak_256 } from "@noble/hashes/sha3";
|
|
291
|
-
|
|
292
301
|
// src/channel/rpc_0_6.ts
|
|
293
302
|
var rpc_0_6_exports = {};
|
|
294
303
|
__export(rpc_0_6_exports, {
|
|
@@ -429,6 +438,104 @@ import {
|
|
|
429
438
|
TypedDataRevision
|
|
430
439
|
} from "starknet-types-07";
|
|
431
440
|
|
|
441
|
+
// src/utils/json.ts
|
|
442
|
+
var json_exports = {};
|
|
443
|
+
__export(json_exports, {
|
|
444
|
+
parse: () => parse2,
|
|
445
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
446
|
+
stringify: () => stringify2,
|
|
447
|
+
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
448
|
+
});
|
|
449
|
+
import * as json from "lossless-json";
|
|
450
|
+
var parseIntAsNumberOrBigInt = (str) => {
|
|
451
|
+
if (!json.isInteger(str)) return parseFloat(str);
|
|
452
|
+
const num = parseInt(str, 10);
|
|
453
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
454
|
+
};
|
|
455
|
+
var parse2 = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
456
|
+
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
457
|
+
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
458
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
459
|
+
|
|
460
|
+
// src/utils/batch/index.ts
|
|
461
|
+
var BatchClient = class {
|
|
462
|
+
nodeUrl;
|
|
463
|
+
headers;
|
|
464
|
+
interval;
|
|
465
|
+
requestId = 0;
|
|
466
|
+
pendingRequests = {};
|
|
467
|
+
batchPromises = {};
|
|
468
|
+
delayTimer;
|
|
469
|
+
delayPromise;
|
|
470
|
+
delayPromiseResolve;
|
|
471
|
+
constructor(options) {
|
|
472
|
+
this.nodeUrl = options.nodeUrl;
|
|
473
|
+
this.headers = options.headers;
|
|
474
|
+
this.interval = options.interval;
|
|
475
|
+
}
|
|
476
|
+
async wait() {
|
|
477
|
+
if (!this.delayPromise || !this.delayPromiseResolve) {
|
|
478
|
+
this.delayPromise = new Promise((resolve) => {
|
|
479
|
+
this.delayPromiseResolve = resolve;
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (this.delayTimer) {
|
|
483
|
+
clearTimeout(this.delayTimer);
|
|
484
|
+
this.delayTimer = void 0;
|
|
485
|
+
}
|
|
486
|
+
this.delayTimer = setTimeout(() => {
|
|
487
|
+
if (this.delayPromiseResolve) {
|
|
488
|
+
this.delayPromiseResolve();
|
|
489
|
+
this.delayPromise = void 0;
|
|
490
|
+
this.delayPromiseResolve = void 0;
|
|
491
|
+
}
|
|
492
|
+
}, this.interval);
|
|
493
|
+
return this.delayPromise;
|
|
494
|
+
}
|
|
495
|
+
addPendingRequest(method, params, id) {
|
|
496
|
+
const request = {
|
|
497
|
+
id: id ?? `batched_${this.requestId += 1}`,
|
|
498
|
+
jsonrpc: "2.0",
|
|
499
|
+
method,
|
|
500
|
+
params: params ?? void 0
|
|
501
|
+
};
|
|
502
|
+
this.pendingRequests[request.id] = request;
|
|
503
|
+
return request.id;
|
|
504
|
+
}
|
|
505
|
+
async sendBatch(requests) {
|
|
506
|
+
const raw = await fetch(this.nodeUrl, {
|
|
507
|
+
method: "POST",
|
|
508
|
+
body: stringify2(requests),
|
|
509
|
+
headers: this.headers
|
|
510
|
+
});
|
|
511
|
+
return raw.json();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Automatically batches and fetches JSON-RPC calls in a single request.
|
|
515
|
+
* @param method Method to call
|
|
516
|
+
* @param params Method parameters
|
|
517
|
+
* @param id JSON-RPC Request ID
|
|
518
|
+
* @returns JSON-RPC Response
|
|
519
|
+
*/
|
|
520
|
+
async fetch(method, params, id) {
|
|
521
|
+
const requestId = this.addPendingRequest(method, params, id);
|
|
522
|
+
await this.wait();
|
|
523
|
+
const requests = this.pendingRequests;
|
|
524
|
+
this.pendingRequests = {};
|
|
525
|
+
if (!this.batchPromises[requestId]) {
|
|
526
|
+
const promise = this.sendBatch(Object.values(requests));
|
|
527
|
+
Object.keys(requests).forEach((key) => {
|
|
528
|
+
this.batchPromises[key] = promise;
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
const results = await this.batchPromises[requestId];
|
|
532
|
+
delete this.batchPromises[requestId];
|
|
533
|
+
const result = results.find((res) => res.id === requestId);
|
|
534
|
+
if (!result) throw new Error(`Couldn't find the result for the request. Method: ${method}`);
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
|
|
432
539
|
// src/utils/assert.ts
|
|
433
540
|
function assert(condition, message) {
|
|
434
541
|
if (!condition) {
|
|
@@ -454,6 +561,7 @@ __export(num_exports, {
|
|
|
454
561
|
isHex: () => isHex,
|
|
455
562
|
isNumber: () => isNumber,
|
|
456
563
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
564
|
+
stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
|
|
457
565
|
toBigInt: () => toBigInt,
|
|
458
566
|
toCairoBool: () => toCairoBool,
|
|
459
567
|
toHex: () => toHex,
|
|
@@ -461,6 +569,7 @@ __export(num_exports, {
|
|
|
461
569
|
toStorageKey: () => toStorageKey
|
|
462
570
|
});
|
|
463
571
|
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
572
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
464
573
|
function isHex(hex) {
|
|
465
574
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
466
575
|
}
|
|
@@ -527,8 +636,7 @@ function toCairoBool(value) {
|
|
|
527
636
|
return (+value).toString();
|
|
528
637
|
}
|
|
529
638
|
function hexToBytes(str) {
|
|
530
|
-
if (!isHex(str))
|
|
531
|
-
throw new Error(`${str} needs to be a hex-string`);
|
|
639
|
+
if (!isHex(str)) throw new Error(`${str} needs to be a hex-string`);
|
|
532
640
|
let adaptedValue = removeHexPrefix(str);
|
|
533
641
|
if (adaptedValue.length % 2 !== 0) {
|
|
534
642
|
adaptedValue = `0${adaptedValue}`;
|
|
@@ -545,16 +653,25 @@ function isNumber(value) {
|
|
|
545
653
|
function isBoolean(value) {
|
|
546
654
|
return typeof value === "boolean";
|
|
547
655
|
}
|
|
656
|
+
function stringToSha256ToArrayBuff4(str) {
|
|
657
|
+
const int31 = (n) => Number(n & MASK_31);
|
|
658
|
+
const result = int31(BigInt(addHexPrefix(buf2hex(sha256(str)))));
|
|
659
|
+
return hexToBytes(toHex(result));
|
|
660
|
+
}
|
|
548
661
|
|
|
549
662
|
// src/utils/hash/selector.ts
|
|
550
663
|
var selector_exports = {};
|
|
551
664
|
__export(selector_exports, {
|
|
665
|
+
getL2MessageHash: () => getL2MessageHash,
|
|
552
666
|
getSelector: () => getSelector,
|
|
553
667
|
getSelectorFromName: () => getSelectorFromName,
|
|
554
668
|
keccakBn: () => keccakBn,
|
|
669
|
+
solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
|
|
555
670
|
starknetKeccak: () => starknetKeccak
|
|
556
671
|
});
|
|
557
672
|
import { keccak } from "@scure/starknet";
|
|
673
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
674
|
+
import { bytesToHex } from "@noble/curves/abstract/utils";
|
|
558
675
|
function keccakBn(value) {
|
|
559
676
|
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
560
677
|
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
@@ -571,14 +688,30 @@ function getSelectorFromName(funcName) {
|
|
|
571
688
|
return toHex(starknetKeccak(funcName));
|
|
572
689
|
}
|
|
573
690
|
function getSelector(value) {
|
|
574
|
-
if (
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (isStringWholeNumber(value)) {
|
|
578
|
-
return toHexString(value);
|
|
579
|
-
}
|
|
691
|
+
if (isNumber(value) || isBigInt(value)) return toHex(value);
|
|
692
|
+
if (isHex(value)) return value;
|
|
693
|
+
if (isStringWholeNumber(value)) return toHex(value);
|
|
580
694
|
return getSelectorFromName(value);
|
|
581
695
|
}
|
|
696
|
+
function solidityUint256PackedKeccak256(params) {
|
|
697
|
+
const myEncode = addHexPrefix(
|
|
698
|
+
params.reduce(
|
|
699
|
+
(res, par) => res + removeHexPrefix(toHex(par)).padStart(64, "0"),
|
|
700
|
+
""
|
|
701
|
+
)
|
|
702
|
+
);
|
|
703
|
+
return addHexPrefix(bytesToHex(keccak_256(hexToBytes(myEncode))));
|
|
704
|
+
}
|
|
705
|
+
function getL2MessageHash(l1FromAddress, l2ToAddress, l2Selector, l2Calldata, l1Nonce) {
|
|
706
|
+
return solidityUint256PackedKeccak256([
|
|
707
|
+
l1FromAddress,
|
|
708
|
+
l2ToAddress,
|
|
709
|
+
l1Nonce,
|
|
710
|
+
l2Selector,
|
|
711
|
+
l2Calldata.length,
|
|
712
|
+
...l2Calldata
|
|
713
|
+
]);
|
|
714
|
+
}
|
|
582
715
|
|
|
583
716
|
// src/utils/shortString.ts
|
|
584
717
|
var shortString_exports = {};
|
|
@@ -616,15 +749,12 @@ function splitLongString(longStr) {
|
|
|
616
749
|
return longStr.match(regex) || [];
|
|
617
750
|
}
|
|
618
751
|
function encodeShortString(str) {
|
|
619
|
-
if (!isASCII(str))
|
|
620
|
-
|
|
621
|
-
if (!isShortString(str))
|
|
622
|
-
throw new Error(`${str} is too long`);
|
|
752
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
753
|
+
if (!isShortString(str)) throw new Error(`${str} is too long`);
|
|
623
754
|
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
624
755
|
}
|
|
625
756
|
function decodeShortString(str) {
|
|
626
|
-
if (!isASCII(str))
|
|
627
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
757
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
628
758
|
if (isHex(str)) {
|
|
629
759
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
630
760
|
}
|
|
@@ -752,10 +882,8 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
752
882
|
*/
|
|
753
883
|
static validate(bigNumberish) {
|
|
754
884
|
const bigInt = BigInt(bigNumberish);
|
|
755
|
-
if (bigInt < UINT_256_MIN)
|
|
756
|
-
|
|
757
|
-
if (bigInt > UINT_256_MAX)
|
|
758
|
-
throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
885
|
+
if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
|
|
886
|
+
if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
759
887
|
return bigInt;
|
|
760
888
|
}
|
|
761
889
|
/**
|
|
@@ -866,10 +994,8 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
866
994
|
*/
|
|
867
995
|
static validate(bigNumberish) {
|
|
868
996
|
const bigInt = BigInt(bigNumberish);
|
|
869
|
-
if (bigInt < UINT_512_MIN)
|
|
870
|
-
|
|
871
|
-
if (bigInt > UINT_512_MAX)
|
|
872
|
-
throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
997
|
+
if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
998
|
+
if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
873
999
|
return bigInt;
|
|
874
1000
|
}
|
|
875
1001
|
/**
|
|
@@ -1306,10 +1432,8 @@ function createAbiParser(abi) {
|
|
|
1306
1432
|
throw Error(`Unsupported ABI version ${version}`);
|
|
1307
1433
|
}
|
|
1308
1434
|
function getAbiVersion(abi) {
|
|
1309
|
-
if (abi.find((it) => it.type === "interface"))
|
|
1310
|
-
|
|
1311
|
-
if (isCairo1Abi(abi))
|
|
1312
|
-
return 1;
|
|
1435
|
+
if (abi.find((it) => it.type === "interface")) return 2;
|
|
1436
|
+
if (isCairo1Abi(abi)) return 1;
|
|
1313
1437
|
return 0;
|
|
1314
1438
|
}
|
|
1315
1439
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
@@ -1323,8 +1447,7 @@ function parseNamedTuple(namedTuple) {
|
|
|
1323
1447
|
return { name, type };
|
|
1324
1448
|
}
|
|
1325
1449
|
function parseSubTuple(s) {
|
|
1326
|
-
if (!s.includes("("))
|
|
1327
|
-
return { subTuple: [], result: s };
|
|
1450
|
+
if (!s.includes("(")) return { subTuple: [], result: s };
|
|
1328
1451
|
const subTuple = [];
|
|
1329
1452
|
let result = "";
|
|
1330
1453
|
let i = 0;
|
|
@@ -1334,10 +1457,8 @@ function parseSubTuple(s) {
|
|
|
1334
1457
|
const lBracket = i;
|
|
1335
1458
|
i++;
|
|
1336
1459
|
while (counter) {
|
|
1337
|
-
if (s[i] === ")")
|
|
1338
|
-
|
|
1339
|
-
if (s[i] === "(")
|
|
1340
|
-
counter++;
|
|
1460
|
+
if (s[i] === ")") counter--;
|
|
1461
|
+
if (s[i] === "(") counter++;
|
|
1341
1462
|
i++;
|
|
1342
1463
|
}
|
|
1343
1464
|
subTuple.push(s.substring(lBracket, i));
|
|
@@ -1644,8 +1765,7 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1644
1765
|
}
|
|
1645
1766
|
if (type === "core::starknet::eth_address::EthAddress")
|
|
1646
1767
|
return parseBaseTypes(type, element);
|
|
1647
|
-
if (type === "core::byte_array::ByteArray")
|
|
1648
|
-
return parseByteArray(element);
|
|
1768
|
+
if (type === "core::byte_array::ByteArray") return parseByteArray(element);
|
|
1649
1769
|
const { members } = structs[type];
|
|
1650
1770
|
const subElement = element;
|
|
1651
1771
|
return members.reduce((acc, it) => {
|
|
@@ -1965,8 +2085,7 @@ var validateFelt = (parameter, input) => {
|
|
|
1965
2085
|
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
1966
2086
|
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
1967
2087
|
);
|
|
1968
|
-
if (isString(parameter) && !isHex(parameter))
|
|
1969
|
-
return;
|
|
2088
|
+
if (isString(parameter) && !isHex(parameter)) return;
|
|
1970
2089
|
const param = BigInt(parameter.toString(10));
|
|
1971
2090
|
assert(
|
|
1972
2091
|
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1266
|
|
@@ -2272,8 +2391,7 @@ var CallData = class _CallData {
|
|
|
2272
2391
|
validate(type, method, args = []) {
|
|
2273
2392
|
if (type !== "DEPLOY" /* DEPLOY */) {
|
|
2274
2393
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
2275
|
-
if (abi.type !== "function")
|
|
2276
|
-
return false;
|
|
2394
|
+
if (abi.type !== "function") return false;
|
|
2277
2395
|
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
2278
2396
|
return type === "INVOKE" /* INVOKE */ ? !isView : isView;
|
|
2279
2397
|
}).map((abi) => abi.name);
|
|
@@ -2351,13 +2469,10 @@ var CallData = class _CallData {
|
|
|
2351
2469
|
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
2352
2470
|
return Object.entries(oe).flatMap(([k, v]) => {
|
|
2353
2471
|
let value = v;
|
|
2354
|
-
if (k === "entrypoint")
|
|
2355
|
-
|
|
2356
|
-
else if (isLongText(value))
|
|
2357
|
-
value = byteArrayFromString(value);
|
|
2472
|
+
if (k === "entrypoint") value = getSelectorFromName(value);
|
|
2473
|
+
else if (isLongText(value)) value = byteArrayFromString(value);
|
|
2358
2474
|
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
2359
|
-
if (isBigInt(value))
|
|
2360
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
2475
|
+
if (isBigInt(value)) return [[`${prefix}${kk}`, felt(value)]];
|
|
2361
2476
|
if (Object(value) === value) {
|
|
2362
2477
|
const methodsKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(value));
|
|
2363
2478
|
const keys = [...Object.getOwnPropertyNames(value), ...methodsKeys];
|
|
@@ -2518,6 +2633,7 @@ __export(hash_exports, {
|
|
|
2518
2633
|
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash3,
|
|
2519
2634
|
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash3,
|
|
2520
2635
|
calculateInvokeTransactionHash: () => calculateInvokeTransactionHash2,
|
|
2636
|
+
calculateL2MessageTxHash: () => calculateL2MessageTxHash,
|
|
2521
2637
|
computeCompiledClassHash: () => computeCompiledClassHash,
|
|
2522
2638
|
computeContractClassHash: () => computeContractClassHash,
|
|
2523
2639
|
computeHashOnElements: () => computeHashOnElements2,
|
|
@@ -2529,11 +2645,13 @@ __export(hash_exports, {
|
|
|
2529
2645
|
computePoseidonHashOnElements: () => computePoseidonHashOnElements,
|
|
2530
2646
|
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
2531
2647
|
formatSpaces: () => formatSpaces,
|
|
2648
|
+
getL2MessageHash: () => getL2MessageHash,
|
|
2532
2649
|
getSelector: () => getSelector,
|
|
2533
2650
|
getSelectorFromName: () => getSelectorFromName,
|
|
2534
2651
|
hashByteCodeSegments: () => hashByteCodeSegments,
|
|
2535
2652
|
keccakBn: () => keccakBn,
|
|
2536
2653
|
poseidon: () => poseidon,
|
|
2654
|
+
solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
|
|
2537
2655
|
starknetKeccak: () => starknetKeccak
|
|
2538
2656
|
});
|
|
2539
2657
|
import * as poseidon from "@noble/curves/abstract/poseidon";
|
|
@@ -2543,6 +2661,7 @@ var v2_exports = {};
|
|
|
2543
2661
|
__export(v2_exports, {
|
|
2544
2662
|
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash,
|
|
2545
2663
|
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash,
|
|
2664
|
+
calculateL2MessageTxHash: () => calculateL2MessageTxHash,
|
|
2546
2665
|
calculateTransactionHash: () => calculateTransactionHash,
|
|
2547
2666
|
calculateTransactionHashCommon: () => calculateTransactionHashCommon,
|
|
2548
2667
|
computeHashOnElements: () => computeHashOnElements
|
|
@@ -2612,6 +2731,19 @@ function calculateTransactionHash(contractAddress, version, calldata, maxFee, ch
|
|
|
2612
2731
|
[nonce]
|
|
2613
2732
|
);
|
|
2614
2733
|
}
|
|
2734
|
+
function calculateL2MessageTxHash(l1FromAddress, l2ToAddress, l2Selector, l2Calldata, l2ChainId, l1Nonce) {
|
|
2735
|
+
const payload = [l1FromAddress, ...l2Calldata];
|
|
2736
|
+
return calculateTransactionHashCommon(
|
|
2737
|
+
"0x6c315f68616e646c6572" /* L1_HANDLER */,
|
|
2738
|
+
0,
|
|
2739
|
+
l2ToAddress,
|
|
2740
|
+
getSelector(l2Selector),
|
|
2741
|
+
payload,
|
|
2742
|
+
0,
|
|
2743
|
+
l2ChainId,
|
|
2744
|
+
[l1Nonce]
|
|
2745
|
+
);
|
|
2746
|
+
}
|
|
2615
2747
|
|
|
2616
2748
|
// src/utils/hash/transactionHash/v3.ts
|
|
2617
2749
|
var v3_exports = {};
|
|
@@ -2794,28 +2926,6 @@ function calculateDeployAccountTransactionHash3(args) {
|
|
|
2794
2926
|
|
|
2795
2927
|
// src/utils/hash/classHash.ts
|
|
2796
2928
|
import { poseidonHashMany as poseidonHashMany2 } from "@scure/starknet";
|
|
2797
|
-
|
|
2798
|
-
// src/utils/json.ts
|
|
2799
|
-
var json_exports = {};
|
|
2800
|
-
__export(json_exports, {
|
|
2801
|
-
parse: () => parse2,
|
|
2802
|
-
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
2803
|
-
stringify: () => stringify2,
|
|
2804
|
-
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
2805
|
-
});
|
|
2806
|
-
import * as json from "lossless-json";
|
|
2807
|
-
var parseIntAsNumberOrBigInt = (str) => {
|
|
2808
|
-
if (!json.isInteger(str))
|
|
2809
|
-
return parseFloat(str);
|
|
2810
|
-
const num = parseInt(str, 10);
|
|
2811
|
-
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
2812
|
-
};
|
|
2813
|
-
var parse2 = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
2814
|
-
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
2815
|
-
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
2816
|
-
var stringifyAlwaysAsBig = stringify2;
|
|
2817
|
-
|
|
2818
|
-
// src/utils/hash/classHash.ts
|
|
2819
2929
|
function computePedersenHash(a, b) {
|
|
2820
2930
|
return starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
2821
2931
|
}
|
|
@@ -3002,8 +3112,7 @@ function compressProgram(jsonProgram) {
|
|
|
3002
3112
|
return btoaUniversal(compressedProgram);
|
|
3003
3113
|
}
|
|
3004
3114
|
function decompressProgram(base642) {
|
|
3005
|
-
if (Array.isArray(base642))
|
|
3006
|
-
return base642;
|
|
3115
|
+
if (Array.isArray(base642)) return base642;
|
|
3007
3116
|
const decompressed = arrayBufferToString(ungzip(atobUniversal(base642)));
|
|
3008
3117
|
return parse2(decompressed);
|
|
3009
3118
|
}
|
|
@@ -3015,8 +3124,7 @@ function makeAddress(input) {
|
|
|
3015
3124
|
return addHexPrefix(input).toLowerCase();
|
|
3016
3125
|
}
|
|
3017
3126
|
function formatSignature(sig) {
|
|
3018
|
-
if (!sig)
|
|
3019
|
-
throw Error("formatSignature: provided signature is undefined");
|
|
3127
|
+
if (!sig) throw Error("formatSignature: provided signature is undefined");
|
|
3020
3128
|
if (Array.isArray(sig)) {
|
|
3021
3129
|
return sig.map((it) => toHex(it));
|
|
3022
3130
|
}
|
|
@@ -3054,10 +3162,8 @@ function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUN
|
|
|
3054
3162
|
};
|
|
3055
3163
|
}
|
|
3056
3164
|
function intDAM(dam) {
|
|
3057
|
-
if (dam === api_exports.EDataAvailabilityMode.L1)
|
|
3058
|
-
|
|
3059
|
-
if (dam === api_exports.EDataAvailabilityMode.L2)
|
|
3060
|
-
return api_exports.EDAMode.L2;
|
|
3165
|
+
if (dam === api_exports.EDataAvailabilityMode.L1) return api_exports.EDAMode.L1;
|
|
3166
|
+
if (dam === api_exports.EDataAvailabilityMode.L2) return api_exports.EDAMode.L2;
|
|
3061
3167
|
throw Error("EDAM conversion");
|
|
3062
3168
|
}
|
|
3063
3169
|
function toTransactionVersion(defaultVersion, providedVersion) {
|
|
@@ -3072,17 +3178,12 @@ function toTransactionVersion(defaultVersion, providedVersion) {
|
|
|
3072
3178
|
return providedVersion ? providedVersion0xs : defaultVersion0xs;
|
|
3073
3179
|
}
|
|
3074
3180
|
function toFeeVersion(providedVersion) {
|
|
3075
|
-
if (!providedVersion)
|
|
3076
|
-
return void 0;
|
|
3181
|
+
if (!providedVersion) return void 0;
|
|
3077
3182
|
const version = toHex(providedVersion);
|
|
3078
|
-
if (version === api_exports.ETransactionVersion.V0)
|
|
3079
|
-
|
|
3080
|
-
if (version === api_exports.ETransactionVersion.
|
|
3081
|
-
|
|
3082
|
-
if (version === api_exports.ETransactionVersion.V2)
|
|
3083
|
-
return api_exports.ETransactionVersion.F2;
|
|
3084
|
-
if (version === api_exports.ETransactionVersion.V3)
|
|
3085
|
-
return api_exports.ETransactionVersion.F3;
|
|
3183
|
+
if (version === api_exports.ETransactionVersion.V0) return api_exports.ETransactionVersion.F0;
|
|
3184
|
+
if (version === api_exports.ETransactionVersion.V1) return api_exports.ETransactionVersion.F1;
|
|
3185
|
+
if (version === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.F2;
|
|
3186
|
+
if (version === api_exports.ETransactionVersion.V3) return api_exports.ETransactionVersion.F3;
|
|
3086
3187
|
throw Error(`toFeeVersion: ${version} is not supported`);
|
|
3087
3188
|
}
|
|
3088
3189
|
function v3Details(details) {
|
|
@@ -3096,10 +3197,8 @@ function v3Details(details) {
|
|
|
3096
3197
|
};
|
|
3097
3198
|
}
|
|
3098
3199
|
function reduceV2(providedVersion) {
|
|
3099
|
-
if (providedVersion === api_exports.ETransactionVersion.F2)
|
|
3100
|
-
|
|
3101
|
-
if (providedVersion === api_exports.ETransactionVersion.V2)
|
|
3102
|
-
return api_exports.ETransactionVersion.V1;
|
|
3200
|
+
if (providedVersion === api_exports.ETransactionVersion.F2) return api_exports.ETransactionVersion.F1;
|
|
3201
|
+
if (providedVersion === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.V1;
|
|
3103
3202
|
return providedVersion;
|
|
3104
3203
|
}
|
|
3105
3204
|
|
|
@@ -3439,8 +3538,9 @@ var RpcChannel = class {
|
|
|
3439
3538
|
specVersion;
|
|
3440
3539
|
waitMode;
|
|
3441
3540
|
// behave like web2 rpc and return when tx is processed
|
|
3541
|
+
batchClient;
|
|
3442
3542
|
constructor(optionsOrProvider) {
|
|
3443
|
-
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
|
|
3543
|
+
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode, batch } = optionsOrProvider || {};
|
|
3444
3544
|
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
3445
3545
|
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
3446
3546
|
} else if (nodeUrl) {
|
|
@@ -3455,6 +3555,13 @@ var RpcChannel = class {
|
|
|
3455
3555
|
this.specVersion = specVersion;
|
|
3456
3556
|
this.waitMode = waitMode || false;
|
|
3457
3557
|
this.requestId = 0;
|
|
3558
|
+
if (typeof batch === "number") {
|
|
3559
|
+
this.batchClient = new BatchClient({
|
|
3560
|
+
nodeUrl: this.nodeUrl,
|
|
3561
|
+
headers: this.headers,
|
|
3562
|
+
interval: batch
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3458
3565
|
}
|
|
3459
3566
|
setChainId(chainId) {
|
|
3460
3567
|
this.chainId = chainId;
|
|
@@ -3490,6 +3597,15 @@ var RpcChannel = class {
|
|
|
3490
3597
|
}
|
|
3491
3598
|
async fetchEndpoint(method, params) {
|
|
3492
3599
|
try {
|
|
3600
|
+
if (this.batchClient) {
|
|
3601
|
+
const { error: error2, result: result2 } = await this.batchClient.fetch(
|
|
3602
|
+
method,
|
|
3603
|
+
params,
|
|
3604
|
+
this.requestId += 1
|
|
3605
|
+
);
|
|
3606
|
+
this.errorHandler(method, params, error2);
|
|
3607
|
+
return result2;
|
|
3608
|
+
}
|
|
3493
3609
|
const rawResult = await this.fetch(method, params, this.requestId += 1);
|
|
3494
3610
|
const { error, result } = await rawResult.json();
|
|
3495
3611
|
this.errorHandler(method, params, error);
|
|
@@ -3589,10 +3705,8 @@ var RpcChannel = class {
|
|
|
3589
3705
|
} = simulateTransactionOptions;
|
|
3590
3706
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3591
3707
|
const simulationFlags = [];
|
|
3592
|
-
if (skipValidate)
|
|
3593
|
-
|
|
3594
|
-
if (skipFeeCharge)
|
|
3595
|
-
simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3708
|
+
if (skipValidate) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
|
|
3709
|
+
if (skipFeeCharge) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3596
3710
|
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
3597
3711
|
block_id,
|
|
3598
3712
|
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
@@ -3974,6 +4088,7 @@ var RpcChannel2 = class {
|
|
|
3974
4088
|
transactionRetryIntervalFallback;
|
|
3975
4089
|
waitMode;
|
|
3976
4090
|
// behave like web2 rpc and return when tx is processed
|
|
4091
|
+
batchClient;
|
|
3977
4092
|
constructor(optionsOrProvider) {
|
|
3978
4093
|
const {
|
|
3979
4094
|
nodeUrl,
|
|
@@ -3983,7 +4098,8 @@ var RpcChannel2 = class {
|
|
|
3983
4098
|
chainId,
|
|
3984
4099
|
specVersion,
|
|
3985
4100
|
waitMode,
|
|
3986
|
-
transactionRetryIntervalFallback
|
|
4101
|
+
transactionRetryIntervalFallback,
|
|
4102
|
+
batch
|
|
3987
4103
|
} = optionsOrProvider || {};
|
|
3988
4104
|
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
3989
4105
|
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
@@ -4000,6 +4116,13 @@ var RpcChannel2 = class {
|
|
|
4000
4116
|
this.waitMode = waitMode || false;
|
|
4001
4117
|
this.requestId = 0;
|
|
4002
4118
|
this.transactionRetryIntervalFallback = transactionRetryIntervalFallback;
|
|
4119
|
+
if (typeof batch === "number") {
|
|
4120
|
+
this.batchClient = new BatchClient({
|
|
4121
|
+
nodeUrl: this.nodeUrl,
|
|
4122
|
+
headers: this.headers,
|
|
4123
|
+
interval: batch
|
|
4124
|
+
});
|
|
4125
|
+
}
|
|
4003
4126
|
}
|
|
4004
4127
|
get transactionRetryIntervalDefault() {
|
|
4005
4128
|
return this.transactionRetryIntervalFallback ?? 5e3;
|
|
@@ -4038,6 +4161,15 @@ var RpcChannel2 = class {
|
|
|
4038
4161
|
}
|
|
4039
4162
|
async fetchEndpoint(method, params) {
|
|
4040
4163
|
try {
|
|
4164
|
+
if (this.batchClient) {
|
|
4165
|
+
const { error: error2, result: result2 } = await this.batchClient.fetch(
|
|
4166
|
+
method,
|
|
4167
|
+
params,
|
|
4168
|
+
this.requestId += 1
|
|
4169
|
+
);
|
|
4170
|
+
this.errorHandler(method, params, error2);
|
|
4171
|
+
return result2;
|
|
4172
|
+
}
|
|
4041
4173
|
const rawResult = await this.fetch(method, params, this.requestId += 1);
|
|
4042
4174
|
const { error, result } = await rawResult.json();
|
|
4043
4175
|
this.errorHandler(method, params, error);
|
|
@@ -4141,10 +4273,8 @@ var RpcChannel2 = class {
|
|
|
4141
4273
|
} = simulateTransactionOptions;
|
|
4142
4274
|
const block_id = new Block(blockIdentifier).identifier;
|
|
4143
4275
|
const simulationFlags = [];
|
|
4144
|
-
if (skipValidate)
|
|
4145
|
-
|
|
4146
|
-
if (skipFeeCharge)
|
|
4147
|
-
simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
4276
|
+
if (skipValidate) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_VALIDATE);
|
|
4277
|
+
if (skipFeeCharge) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
4148
4278
|
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
4149
4279
|
block_id,
|
|
4150
4280
|
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
@@ -4679,7 +4809,7 @@ var RpcProvider = class {
|
|
|
4679
4809
|
}
|
|
4680
4810
|
/**
|
|
4681
4811
|
* Pause the execution of the script until a specified block is created.
|
|
4682
|
-
* @param {BlockIdentifier} blockIdentifier bloc number (
|
|
4812
|
+
* @param {BlockIdentifier} blockIdentifier bloc number (BigNumberish) or 'pending' or 'latest'.
|
|
4683
4813
|
* Use of 'latest" or of a block already created will generate no pause.
|
|
4684
4814
|
* @param {number} [retryInterval] number of milliseconds between 2 requests to the node
|
|
4685
4815
|
* @example
|
|
@@ -4689,12 +4819,10 @@ var RpcProvider = class {
|
|
|
4689
4819
|
* ```
|
|
4690
4820
|
*/
|
|
4691
4821
|
async waitForBlock(blockIdentifier = "pending", retryInterval = 5e3) {
|
|
4692
|
-
if (blockIdentifier === "latest" /* LATEST */)
|
|
4693
|
-
return;
|
|
4822
|
+
if (blockIdentifier === "latest" /* LATEST */) return;
|
|
4694
4823
|
const currentBlock = await this.getBlockNumber();
|
|
4695
4824
|
const targetBlock = blockIdentifier === "pending" /* PENDING */ ? currentBlock + 1 : Number(toHex(blockIdentifier));
|
|
4696
|
-
if (targetBlock <= currentBlock)
|
|
4697
|
-
return;
|
|
4825
|
+
if (targetBlock <= currentBlock) return;
|
|
4698
4826
|
const { retries } = this.channel;
|
|
4699
4827
|
let retriesCount = retries;
|
|
4700
4828
|
let isTargetBlock = false;
|
|
@@ -4726,13 +4854,7 @@ var RpcProvider = class {
|
|
|
4726
4854
|
calldata.length - 1,
|
|
4727
4855
|
...calldata.slice(1)
|
|
4728
4856
|
];
|
|
4729
|
-
|
|
4730
|
-
params.reduce(
|
|
4731
|
-
(res, par) => res + removeHexPrefix(toHex(par)).padStart(64, "0"),
|
|
4732
|
-
""
|
|
4733
|
-
)
|
|
4734
|
-
);
|
|
4735
|
-
return addHexPrefix(bytesToHex(keccak_256(hexToBytes(myEncode))));
|
|
4857
|
+
return solidityUint256PackedKeccak256(params);
|
|
4736
4858
|
}
|
|
4737
4859
|
async getBlockWithReceipts(blockIdentifier) {
|
|
4738
4860
|
if (this.channel instanceof rpc_0_6_exports.RpcChannel)
|
|
@@ -4968,17 +5090,14 @@ function useDecoded(encoded) {
|
|
|
4968
5090
|
if (nextSubdomain === ZERO) {
|
|
4969
5091
|
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
4970
5092
|
subdomain = nextSubdomain;
|
|
4971
|
-
if (code2 === ZERO)
|
|
4972
|
-
|
|
4973
|
-
else
|
|
4974
|
-
decoded += bigAlphabet[Number(code2) - 1];
|
|
5093
|
+
if (code2 === ZERO) decoded += basicAlphabet[0];
|
|
5094
|
+
else decoded += bigAlphabet[Number(code2) - 1];
|
|
4975
5095
|
} else {
|
|
4976
5096
|
const code2 = subdomain % bigAlphabetSize;
|
|
4977
5097
|
decoded += bigAlphabet[Number(code2)];
|
|
4978
5098
|
subdomain /= bigAlphabetSize;
|
|
4979
5099
|
}
|
|
4980
|
-
} else
|
|
4981
|
-
decoded += basicAlphabet[Number(code)];
|
|
5100
|
+
} else decoded += basicAlphabet[Number(code)];
|
|
4982
5101
|
}
|
|
4983
5102
|
const [str, k] = extractStars(decoded);
|
|
4984
5103
|
if (k)
|
|
@@ -4998,8 +5117,7 @@ function useEncoded(decoded) {
|
|
|
4998
5117
|
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
4999
5118
|
} else {
|
|
5000
5119
|
const [str, k] = extractStars(decoded);
|
|
5001
|
-
if (k)
|
|
5002
|
-
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
5120
|
+
if (k) decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
5003
5121
|
}
|
|
5004
5122
|
for (let i = 0; i < decoded.length; i += 1) {
|
|
5005
5123
|
const char = decoded[i];
|
|
@@ -5654,8 +5772,7 @@ function encodeValue(types, type, data, ctx = {}, revision = TypedDataRevision.L
|
|
|
5654
5772
|
const variantType = enumType.find((t) => t.name === variantKey);
|
|
5655
5773
|
const variantIndex = enumType.indexOf(variantType);
|
|
5656
5774
|
const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
|
|
5657
|
-
if (!subtype)
|
|
5658
|
-
return subtype;
|
|
5775
|
+
if (!subtype) return subtype;
|
|
5659
5776
|
const subtypeData = variantData[index];
|
|
5660
5777
|
return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
|
|
5661
5778
|
});
|
|
@@ -6013,6 +6130,195 @@ var EthSigner = class {
|
|
|
6013
6130
|
}
|
|
6014
6131
|
};
|
|
6015
6132
|
|
|
6133
|
+
// src/signer/ledgerSigner.ts
|
|
6134
|
+
var LedgerSigner = class {
|
|
6135
|
+
transporter;
|
|
6136
|
+
accountID;
|
|
6137
|
+
eip2645applicationName;
|
|
6138
|
+
pathBuffer;
|
|
6139
|
+
appVersion;
|
|
6140
|
+
pubKey;
|
|
6141
|
+
fullPubKey;
|
|
6142
|
+
/**
|
|
6143
|
+
* constructor of the LedgerSigner class.
|
|
6144
|
+
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
6145
|
+
* See Guides for more details.
|
|
6146
|
+
* @param {number} accountID ID of Ledger Nano (can handle 2**31 accounts).
|
|
6147
|
+
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
6148
|
+
* One item is the `application`. Default value is `LedgerW`.
|
|
6149
|
+
* @example
|
|
6150
|
+
* ```typescript
|
|
6151
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
6152
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
6153
|
+
* const myLedgerSigner = new LedgerSigner(myNodeTransport, 0);
|
|
6154
|
+
* ```
|
|
6155
|
+
*/
|
|
6156
|
+
constructor(transport, accountID, eip2645application = "LedgerW") {
|
|
6157
|
+
assert(accountID >= 0, "Ledger account ID shall not be a negative number.");
|
|
6158
|
+
assert(accountID <= MASK_31, "Ledger account ID shall be < 2**31.");
|
|
6159
|
+
assert(!!eip2645application, "Ledger application name shall not be empty.");
|
|
6160
|
+
this.transporter = transport;
|
|
6161
|
+
this.accountID = accountID;
|
|
6162
|
+
this.pubKey = "";
|
|
6163
|
+
this.fullPubKey = "";
|
|
6164
|
+
this.eip2645applicationName = eip2645application;
|
|
6165
|
+
this.appVersion = "";
|
|
6166
|
+
this.pathBuffer = getLedgerPathBuffer(this.accountID, this.eip2645applicationName);
|
|
6167
|
+
}
|
|
6168
|
+
/**
|
|
6169
|
+
* provides the Starknet public key
|
|
6170
|
+
* @returns an hex string : 64 characters are Point X coordinate.
|
|
6171
|
+
*/
|
|
6172
|
+
async getPubKey() {
|
|
6173
|
+
if (!this.pubKey) await this.getPublicKeys();
|
|
6174
|
+
return this.pubKey;
|
|
6175
|
+
}
|
|
6176
|
+
/**
|
|
6177
|
+
* provides the full public key (with parity prefix)
|
|
6178
|
+
* @returns an hex string : 2 first characters are the parity, the 64 following characters are Point X coordinate. 64 last characters are Point Y coordinate.
|
|
6179
|
+
*/
|
|
6180
|
+
async getFullPubKey() {
|
|
6181
|
+
if (!this.fullPubKey) await this.getPublicKeys();
|
|
6182
|
+
return this.fullPubKey;
|
|
6183
|
+
}
|
|
6184
|
+
/**
|
|
6185
|
+
* Returns the version of the Starknet APP implemented in the Ledger.
|
|
6186
|
+
* @returns {string} version.
|
|
6187
|
+
* @example
|
|
6188
|
+
* ```typescript
|
|
6189
|
+
* const result = await myLedgerSigner.getAppVersion();
|
|
6190
|
+
* // result= "1.1.1"
|
|
6191
|
+
* ```
|
|
6192
|
+
*/
|
|
6193
|
+
async getAppVersion() {
|
|
6194
|
+
if (!this.appVersion) {
|
|
6195
|
+
const resp = await this.transporter.send(Number("0x5a"), 0, 0, 0);
|
|
6196
|
+
this.appVersion = `${resp[0]}.${resp[1]}.${resp[2]}`;
|
|
6197
|
+
}
|
|
6198
|
+
return this.appVersion;
|
|
6199
|
+
}
|
|
6200
|
+
async signMessage(typedDataToHash, accountAddress) {
|
|
6201
|
+
const msgHash = getMessageHash(typedDataToHash, accountAddress);
|
|
6202
|
+
return this.signRaw(msgHash);
|
|
6203
|
+
}
|
|
6204
|
+
async signTransaction(transactions, transactionsDetail) {
|
|
6205
|
+
const compiledCalldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
6206
|
+
let msgHash;
|
|
6207
|
+
if (Object.values(ETransactionVersion2).includes(transactionsDetail.version)) {
|
|
6208
|
+
const det = transactionsDetail;
|
|
6209
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
6210
|
+
...det,
|
|
6211
|
+
senderAddress: det.walletAddress,
|
|
6212
|
+
compiledCalldata,
|
|
6213
|
+
version: det.version
|
|
6214
|
+
});
|
|
6215
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(transactionsDetail.version)) {
|
|
6216
|
+
const det = transactionsDetail;
|
|
6217
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
6218
|
+
...det,
|
|
6219
|
+
senderAddress: det.walletAddress,
|
|
6220
|
+
compiledCalldata,
|
|
6221
|
+
version: det.version,
|
|
6222
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6223
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6224
|
+
});
|
|
6225
|
+
} else {
|
|
6226
|
+
throw Error("unsupported signTransaction version");
|
|
6227
|
+
}
|
|
6228
|
+
return this.signRaw(msgHash);
|
|
6229
|
+
}
|
|
6230
|
+
async signDeployAccountTransaction(details) {
|
|
6231
|
+
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
6232
|
+
let msgHash;
|
|
6233
|
+
if (Object.values(ETransactionVersion2).includes(details.version)) {
|
|
6234
|
+
const det = details;
|
|
6235
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
6236
|
+
...det,
|
|
6237
|
+
salt: det.addressSalt,
|
|
6238
|
+
constructorCalldata: compiledConstructorCalldata,
|
|
6239
|
+
version: det.version
|
|
6240
|
+
});
|
|
6241
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(details.version)) {
|
|
6242
|
+
const det = details;
|
|
6243
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
6244
|
+
...det,
|
|
6245
|
+
salt: det.addressSalt,
|
|
6246
|
+
compiledConstructorCalldata,
|
|
6247
|
+
version: det.version,
|
|
6248
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6249
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6250
|
+
});
|
|
6251
|
+
} else {
|
|
6252
|
+
throw Error("unsupported signDeployAccountTransaction version");
|
|
6253
|
+
}
|
|
6254
|
+
return this.signRaw(msgHash);
|
|
6255
|
+
}
|
|
6256
|
+
async signDeclareTransaction(details) {
|
|
6257
|
+
let msgHash;
|
|
6258
|
+
if (Object.values(ETransactionVersion2).includes(details.version)) {
|
|
6259
|
+
const det = details;
|
|
6260
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
6261
|
+
...det,
|
|
6262
|
+
version: det.version
|
|
6263
|
+
});
|
|
6264
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(details.version)) {
|
|
6265
|
+
const det = details;
|
|
6266
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
6267
|
+
...det,
|
|
6268
|
+
version: det.version,
|
|
6269
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6270
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6271
|
+
});
|
|
6272
|
+
} else {
|
|
6273
|
+
throw Error("unsupported signDeclareTransaction version");
|
|
6274
|
+
}
|
|
6275
|
+
return this.signRaw(msgHash);
|
|
6276
|
+
}
|
|
6277
|
+
async signRaw(msgHash) {
|
|
6278
|
+
addHexPrefix(
|
|
6279
|
+
buf2hex(await this.transporter.send(Number("0x5a"), 2, 0, 0, Buffer.from(this.pathBuffer)))
|
|
6280
|
+
);
|
|
6281
|
+
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
6282
|
+
const buff2 = hexToBytes(shiftedHash);
|
|
6283
|
+
const respSign2 = Uint8Array.from(
|
|
6284
|
+
await this.transporter.send(Number("0x5a"), 2, 1, 0, Buffer.from(buff2))
|
|
6285
|
+
);
|
|
6286
|
+
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
6287
|
+
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
6288
|
+
const v = respSign2[65];
|
|
6289
|
+
const sign0 = new starkCurve.Signature(r, s);
|
|
6290
|
+
const sign1 = sign0.addRecoveryBit(v);
|
|
6291
|
+
return sign1;
|
|
6292
|
+
}
|
|
6293
|
+
async getPublicKeys() {
|
|
6294
|
+
const pathBuff = this.pathBuffer;
|
|
6295
|
+
const respGetPublic = Uint8Array.from(
|
|
6296
|
+
await this.transporter.send(Number("0x5a"), 1, 0, 0, Buffer.from(pathBuff))
|
|
6297
|
+
);
|
|
6298
|
+
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
6299
|
+
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
6300
|
+
}
|
|
6301
|
+
};
|
|
6302
|
+
function getLedgerPathBuffer(accountId, applicationName) {
|
|
6303
|
+
const path0buff = new Uint8Array([128, 0, 10, 85]);
|
|
6304
|
+
const path1buff = new Uint8Array([71, 65, 233, 201]);
|
|
6305
|
+
const path2buff = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
6306
|
+
const path3buff = new Uint8Array([0, 0, 0, 0]);
|
|
6307
|
+
const hex = toHex(accountId);
|
|
6308
|
+
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
6309
|
+
const path4buff = hexToBytes(padded);
|
|
6310
|
+
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
6311
|
+
const pathBuff = concatenateArrayBuffer([
|
|
6312
|
+
path0buff,
|
|
6313
|
+
path1buff,
|
|
6314
|
+
path2buff,
|
|
6315
|
+
path3buff,
|
|
6316
|
+
path4buff,
|
|
6317
|
+
path5buff
|
|
6318
|
+
]);
|
|
6319
|
+
return pathBuff;
|
|
6320
|
+
}
|
|
6321
|
+
|
|
6016
6322
|
// src/utils/events/index.ts
|
|
6017
6323
|
var events_exports = {};
|
|
6018
6324
|
__export(events_exports, {
|
|
@@ -6046,19 +6352,16 @@ function getCairo1AbiEvents(abi) {
|
|
|
6046
6352
|
const findName = (variant) => variant.type === name;
|
|
6047
6353
|
while (true) {
|
|
6048
6354
|
const eventEnum = abiEventsEnums.find((eventE) => eventE.variants.some(findName));
|
|
6049
|
-
if (typeof eventEnum === "undefined")
|
|
6050
|
-
break;
|
|
6355
|
+
if (typeof eventEnum === "undefined") break;
|
|
6051
6356
|
const variant = eventEnum.variants.find(findName);
|
|
6052
6357
|
nameList.unshift(variant.name);
|
|
6053
|
-
if (variant.kind === "flat")
|
|
6054
|
-
flat = true;
|
|
6358
|
+
if (variant.kind === "flat") flat = true;
|
|
6055
6359
|
name = eventEnum.name;
|
|
6056
6360
|
}
|
|
6057
6361
|
if (nameList.length === 0) {
|
|
6058
6362
|
throw new Error("inconsistency in ABI events definition.");
|
|
6059
6363
|
}
|
|
6060
|
-
if (flat)
|
|
6061
|
-
nameList = [nameList[nameList.length - 1]];
|
|
6364
|
+
if (flat) nameList = [nameList[nameList.length - 1]];
|
|
6062
6365
|
const final = nameList.pop();
|
|
6063
6366
|
let result = {
|
|
6064
6367
|
[addHexPrefix(starkCurve.keccak(utf8ToArray(final)).toString(16))]: event
|
|
@@ -6084,10 +6387,8 @@ function mergeAbiEvents(target, source) {
|
|
|
6084
6387
|
if (isObject(target) && isObject(source)) {
|
|
6085
6388
|
Object.keys(source).forEach((key) => {
|
|
6086
6389
|
if (isObject(source[key])) {
|
|
6087
|
-
if (!(key in target))
|
|
6088
|
-
|
|
6089
|
-
else
|
|
6090
|
-
output[key] = mergeAbiEvents(target[key], source[key]);
|
|
6390
|
+
if (!(key in target)) Object.assign(output, { [key]: source[key] });
|
|
6391
|
+
else output[key] = mergeAbiEvents(target[key], source[key]);
|
|
6091
6392
|
} else {
|
|
6092
6393
|
Object.assign(output, { [key]: source[key] });
|
|
6093
6394
|
}
|
|
@@ -6174,10 +6475,8 @@ var Account = class extends RpcProvider2 {
|
|
|
6174
6475
|
}
|
|
6175
6476
|
// provided version or contract based preferred transactionVersion
|
|
6176
6477
|
getPreferredVersion(type12, type3) {
|
|
6177
|
-
if (this.transactionVersion === api_exports.ETransactionVersion.V3)
|
|
6178
|
-
|
|
6179
|
-
if (this.transactionVersion === api_exports.ETransactionVersion.V2)
|
|
6180
|
-
return type12;
|
|
6478
|
+
if (this.transactionVersion === api_exports.ETransactionVersion.V3) return type3;
|
|
6479
|
+
if (this.transactionVersion === api_exports.ETransactionVersion.V2) return type12;
|
|
6181
6480
|
return api_exports.ETransactionVersion.V3;
|
|
6182
6481
|
}
|
|
6183
6482
|
async getNonce(blockIdentifier) {
|
|
@@ -6883,13 +7182,11 @@ var WalletAccount = class extends Account {
|
|
|
6883
7182
|
super(providerOrOptions, "", "", cairoVersion);
|
|
6884
7183
|
this.walletProvider = walletProvider;
|
|
6885
7184
|
this.walletProvider.on("accountsChanged", (res) => {
|
|
6886
|
-
if (!res)
|
|
6887
|
-
return;
|
|
7185
|
+
if (!res) return;
|
|
6888
7186
|
this.address = res[0].toLowerCase();
|
|
6889
7187
|
});
|
|
6890
7188
|
this.walletProvider.on("networkChanged", (res) => {
|
|
6891
|
-
if (!res)
|
|
6892
|
-
return;
|
|
7189
|
+
if (!res) return;
|
|
6893
7190
|
this.channel.setChainId(res);
|
|
6894
7191
|
});
|
|
6895
7192
|
walletProvider.request({
|
|
@@ -7029,8 +7326,7 @@ function buildEstimate(contract, functionAbi) {
|
|
|
7029
7326
|
};
|
|
7030
7327
|
}
|
|
7031
7328
|
function getCalldata(args, callback) {
|
|
7032
|
-
if (Array.isArray(args) && "__compiled__" in args)
|
|
7033
|
-
return args;
|
|
7329
|
+
if (Array.isArray(args) && "__compiled__" in args) return args;
|
|
7034
7330
|
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
7035
7331
|
return args[0];
|
|
7036
7332
|
return callback();
|
|
@@ -7070,8 +7366,7 @@ var Contract = class {
|
|
|
7070
7366
|
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
7071
7367
|
});
|
|
7072
7368
|
this.abi.forEach((abiElement) => {
|
|
7073
|
-
if (abiElement.type !== "function")
|
|
7074
|
-
return;
|
|
7369
|
+
if (abiElement.type !== "function") return;
|
|
7075
7370
|
const signature = abiElement.name;
|
|
7076
7371
|
if (!this[signature]) {
|
|
7077
7372
|
Object.defineProperty(this, signature, {
|
|
@@ -7171,8 +7466,7 @@ var Contract = class {
|
|
|
7171
7466
|
nonce
|
|
7172
7467
|
});
|
|
7173
7468
|
}
|
|
7174
|
-
if (!nonce)
|
|
7175
|
-
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
7469
|
+
if (!nonce) throw new Error(`Nonce is required when invoking a function without an account`);
|
|
7176
7470
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
7177
7471
|
return this.providerOrAccount.invokeFunction(
|
|
7178
7472
|
{
|
|
@@ -7401,6 +7695,7 @@ export {
|
|
|
7401
7695
|
EthSigner,
|
|
7402
7696
|
GatewayError,
|
|
7403
7697
|
HttpError,
|
|
7698
|
+
LedgerSigner,
|
|
7404
7699
|
LibraryError,
|
|
7405
7700
|
Literal,
|
|
7406
7701
|
RpcProvider2 as Provider,
|
|
@@ -7449,6 +7744,7 @@ export {
|
|
|
7449
7744
|
fixStack,
|
|
7450
7745
|
getCalldata,
|
|
7451
7746
|
getChecksumAddress,
|
|
7747
|
+
getLedgerPathBuffer,
|
|
7452
7748
|
hash_exports as hash,
|
|
7453
7749
|
isSierra,
|
|
7454
7750
|
isUrl,
|