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.js
CHANGED
|
@@ -51,6 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
EthSigner: () => EthSigner,
|
|
52
52
|
GatewayError: () => GatewayError,
|
|
53
53
|
HttpError: () => HttpError,
|
|
54
|
+
LedgerSigner: () => LedgerSigner,
|
|
54
55
|
LibraryError: () => LibraryError,
|
|
55
56
|
Literal: () => Literal,
|
|
56
57
|
Provider: () => RpcProvider2,
|
|
@@ -99,6 +100,7 @@ __export(src_exports, {
|
|
|
99
100
|
fixStack: () => fixStack,
|
|
100
101
|
getCalldata: () => getCalldata,
|
|
101
102
|
getChecksumAddress: () => getChecksumAddress,
|
|
103
|
+
getLedgerPathBuffer: () => getLedgerPathBuffer,
|
|
102
104
|
hash: () => hash_exports,
|
|
103
105
|
isSierra: () => isSierra,
|
|
104
106
|
isUrl: () => isUrl,
|
|
@@ -134,6 +136,7 @@ __export(constants_exports, {
|
|
|
134
136
|
FeeMarginPercentage: () => FeeMarginPercentage,
|
|
135
137
|
IS_BROWSER: () => IS_BROWSER,
|
|
136
138
|
MASK_250: () => MASK_250,
|
|
139
|
+
MASK_31: () => MASK_31,
|
|
137
140
|
MAX_STORAGE_ITEM_SIZE: () => MAX_STORAGE_ITEM_SIZE,
|
|
138
141
|
NetworkName: () => NetworkName,
|
|
139
142
|
PRIME: () => PRIME,
|
|
@@ -251,10 +254,10 @@ var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion25) => {
|
|
|
251
254
|
ETransactionVersion25["F2"] = "0x100000000000000000000000000000002";
|
|
252
255
|
return ETransactionVersion25;
|
|
253
256
|
})(ETransactionVersion2 || {});
|
|
254
|
-
var ETransactionVersion3 = /* @__PURE__ */ ((
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return
|
|
257
|
+
var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion37) => {
|
|
258
|
+
ETransactionVersion37["V3"] = "0x3";
|
|
259
|
+
ETransactionVersion37["F3"] = "0x100000000000000000000000000000003";
|
|
260
|
+
return ETransactionVersion37;
|
|
258
261
|
})(ETransactionVersion3 || {});
|
|
259
262
|
|
|
260
263
|
// src/types/api/index.ts
|
|
@@ -271,6 +274,7 @@ __export(encode_exports, {
|
|
|
271
274
|
btoaUniversal: () => btoaUniversal,
|
|
272
275
|
buf2hex: () => buf2hex,
|
|
273
276
|
calcByteLength: () => calcByteLength,
|
|
277
|
+
concatenateArrayBuffer: () => concatenateArrayBuffer,
|
|
274
278
|
padLeft: () => padLeft,
|
|
275
279
|
pascalToSnake: () => pascalToSnake,
|
|
276
280
|
removeHexPrefix: () => removeHexPrefix,
|
|
@@ -335,11 +339,22 @@ function sanitizeHex(hex) {
|
|
|
335
339
|
return hex;
|
|
336
340
|
}
|
|
337
341
|
var pascalToSnake = (text) => /[a-z]/.test(text) ? text.split(/(?=[A-Z])/).join("_").toUpperCase() : text;
|
|
342
|
+
function concatenateArrayBuffer(uint8arrays) {
|
|
343
|
+
const totalLength = uint8arrays.reduce((total, uint8array) => total + uint8array.byteLength, 0);
|
|
344
|
+
const result = new Uint8Array(totalLength);
|
|
345
|
+
let offset = 0;
|
|
346
|
+
uint8arrays.forEach((uint8array) => {
|
|
347
|
+
result.set(uint8array, offset);
|
|
348
|
+
offset += uint8array.byteLength;
|
|
349
|
+
});
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
338
352
|
|
|
339
353
|
// src/constants.ts
|
|
340
354
|
var TEXT_TO_FELT_MAX_LEN = 31;
|
|
341
355
|
var ZERO = 0n;
|
|
342
356
|
var MASK_250 = 2n ** 250n - 1n;
|
|
357
|
+
var MASK_31 = 2n ** 31n - 1n;
|
|
343
358
|
var API_VERSION = ZERO;
|
|
344
359
|
var PRIME = 2n ** 251n + 17n * 2n ** 192n + 1n;
|
|
345
360
|
var MAX_STORAGE_ITEM_SIZE = 256n;
|
|
@@ -393,10 +408,6 @@ var RPC_NODES = {
|
|
|
393
408
|
]
|
|
394
409
|
};
|
|
395
410
|
|
|
396
|
-
// src/provider/rpc.ts
|
|
397
|
-
var import_utils2 = require("@noble/curves/abstract/utils");
|
|
398
|
-
var import_sha3 = require("@noble/hashes/sha3");
|
|
399
|
-
|
|
400
411
|
// src/channel/rpc_0_6.ts
|
|
401
412
|
var rpc_0_6_exports = {};
|
|
402
413
|
__export(rpc_0_6_exports, {
|
|
@@ -535,6 +546,104 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
|
|
|
535
546
|
// src/types/typedData.ts
|
|
536
547
|
var import_starknet_types_07 = require("starknet-types-07");
|
|
537
548
|
|
|
549
|
+
// src/utils/json.ts
|
|
550
|
+
var json_exports = {};
|
|
551
|
+
__export(json_exports, {
|
|
552
|
+
parse: () => parse2,
|
|
553
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
554
|
+
stringify: () => stringify2,
|
|
555
|
+
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
556
|
+
});
|
|
557
|
+
var json = __toESM(require("lossless-json"));
|
|
558
|
+
var parseIntAsNumberOrBigInt = (str) => {
|
|
559
|
+
if (!json.isInteger(str)) return parseFloat(str);
|
|
560
|
+
const num = parseInt(str, 10);
|
|
561
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
562
|
+
};
|
|
563
|
+
var parse2 = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
564
|
+
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
565
|
+
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
566
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
567
|
+
|
|
568
|
+
// src/utils/batch/index.ts
|
|
569
|
+
var BatchClient = class {
|
|
570
|
+
nodeUrl;
|
|
571
|
+
headers;
|
|
572
|
+
interval;
|
|
573
|
+
requestId = 0;
|
|
574
|
+
pendingRequests = {};
|
|
575
|
+
batchPromises = {};
|
|
576
|
+
delayTimer;
|
|
577
|
+
delayPromise;
|
|
578
|
+
delayPromiseResolve;
|
|
579
|
+
constructor(options) {
|
|
580
|
+
this.nodeUrl = options.nodeUrl;
|
|
581
|
+
this.headers = options.headers;
|
|
582
|
+
this.interval = options.interval;
|
|
583
|
+
}
|
|
584
|
+
async wait() {
|
|
585
|
+
if (!this.delayPromise || !this.delayPromiseResolve) {
|
|
586
|
+
this.delayPromise = new Promise((resolve) => {
|
|
587
|
+
this.delayPromiseResolve = resolve;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
if (this.delayTimer) {
|
|
591
|
+
clearTimeout(this.delayTimer);
|
|
592
|
+
this.delayTimer = void 0;
|
|
593
|
+
}
|
|
594
|
+
this.delayTimer = setTimeout(() => {
|
|
595
|
+
if (this.delayPromiseResolve) {
|
|
596
|
+
this.delayPromiseResolve();
|
|
597
|
+
this.delayPromise = void 0;
|
|
598
|
+
this.delayPromiseResolve = void 0;
|
|
599
|
+
}
|
|
600
|
+
}, this.interval);
|
|
601
|
+
return this.delayPromise;
|
|
602
|
+
}
|
|
603
|
+
addPendingRequest(method, params, id) {
|
|
604
|
+
const request = {
|
|
605
|
+
id: id ?? `batched_${this.requestId += 1}`,
|
|
606
|
+
jsonrpc: "2.0",
|
|
607
|
+
method,
|
|
608
|
+
params: params ?? void 0
|
|
609
|
+
};
|
|
610
|
+
this.pendingRequests[request.id] = request;
|
|
611
|
+
return request.id;
|
|
612
|
+
}
|
|
613
|
+
async sendBatch(requests) {
|
|
614
|
+
const raw = await fetch(this.nodeUrl, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
body: stringify2(requests),
|
|
617
|
+
headers: this.headers
|
|
618
|
+
});
|
|
619
|
+
return raw.json();
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Automatically batches and fetches JSON-RPC calls in a single request.
|
|
623
|
+
* @param method Method to call
|
|
624
|
+
* @param params Method parameters
|
|
625
|
+
* @param id JSON-RPC Request ID
|
|
626
|
+
* @returns JSON-RPC Response
|
|
627
|
+
*/
|
|
628
|
+
async fetch(method, params, id) {
|
|
629
|
+
const requestId = this.addPendingRequest(method, params, id);
|
|
630
|
+
await this.wait();
|
|
631
|
+
const requests = this.pendingRequests;
|
|
632
|
+
this.pendingRequests = {};
|
|
633
|
+
if (!this.batchPromises[requestId]) {
|
|
634
|
+
const promise = this.sendBatch(Object.values(requests));
|
|
635
|
+
Object.keys(requests).forEach((key) => {
|
|
636
|
+
this.batchPromises[key] = promise;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
const results = await this.batchPromises[requestId];
|
|
640
|
+
delete this.batchPromises[requestId];
|
|
641
|
+
const result = results.find((res) => res.id === requestId);
|
|
642
|
+
if (!result) throw new Error(`Couldn't find the result for the request. Method: ${method}`);
|
|
643
|
+
return result;
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
538
647
|
// src/utils/assert.ts
|
|
539
648
|
function assert(condition, message) {
|
|
540
649
|
if (!condition) {
|
|
@@ -560,6 +669,7 @@ __export(num_exports, {
|
|
|
560
669
|
isHex: () => isHex,
|
|
561
670
|
isNumber: () => isNumber,
|
|
562
671
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
672
|
+
stringToSha256ToArrayBuff4: () => stringToSha256ToArrayBuff4,
|
|
563
673
|
toBigInt: () => toBigInt,
|
|
564
674
|
toCairoBool: () => toCairoBool,
|
|
565
675
|
toHex: () => toHex,
|
|
@@ -567,6 +677,7 @@ __export(num_exports, {
|
|
|
567
677
|
toStorageKey: () => toStorageKey
|
|
568
678
|
});
|
|
569
679
|
var import_utils = require("@noble/curves/abstract/utils");
|
|
680
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
570
681
|
function isHex(hex) {
|
|
571
682
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
572
683
|
}
|
|
@@ -633,8 +744,7 @@ function toCairoBool(value) {
|
|
|
633
744
|
return (+value).toString();
|
|
634
745
|
}
|
|
635
746
|
function hexToBytes(str) {
|
|
636
|
-
if (!isHex(str))
|
|
637
|
-
throw new Error(`${str} needs to be a hex-string`);
|
|
747
|
+
if (!isHex(str)) throw new Error(`${str} needs to be a hex-string`);
|
|
638
748
|
let adaptedValue = removeHexPrefix(str);
|
|
639
749
|
if (adaptedValue.length % 2 !== 0) {
|
|
640
750
|
adaptedValue = `0${adaptedValue}`;
|
|
@@ -651,16 +761,25 @@ function isNumber(value) {
|
|
|
651
761
|
function isBoolean(value) {
|
|
652
762
|
return typeof value === "boolean";
|
|
653
763
|
}
|
|
764
|
+
function stringToSha256ToArrayBuff4(str) {
|
|
765
|
+
const int31 = (n) => Number(n & MASK_31);
|
|
766
|
+
const result = int31(BigInt(addHexPrefix(buf2hex((0, import_sha256.sha256)(str)))));
|
|
767
|
+
return hexToBytes(toHex(result));
|
|
768
|
+
}
|
|
654
769
|
|
|
655
770
|
// src/utils/hash/selector.ts
|
|
656
771
|
var selector_exports = {};
|
|
657
772
|
__export(selector_exports, {
|
|
773
|
+
getL2MessageHash: () => getL2MessageHash,
|
|
658
774
|
getSelector: () => getSelector,
|
|
659
775
|
getSelectorFromName: () => getSelectorFromName,
|
|
660
776
|
keccakBn: () => keccakBn,
|
|
777
|
+
solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
|
|
661
778
|
starknetKeccak: () => starknetKeccak
|
|
662
779
|
});
|
|
663
780
|
var import_starknet = require("@scure/starknet");
|
|
781
|
+
var import_sha3 = require("@noble/hashes/sha3");
|
|
782
|
+
var import_utils2 = require("@noble/curves/abstract/utils");
|
|
664
783
|
function keccakBn(value) {
|
|
665
784
|
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
666
785
|
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
@@ -677,14 +796,30 @@ function getSelectorFromName(funcName) {
|
|
|
677
796
|
return toHex(starknetKeccak(funcName));
|
|
678
797
|
}
|
|
679
798
|
function getSelector(value) {
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
if (isStringWholeNumber(value)) {
|
|
684
|
-
return toHexString(value);
|
|
685
|
-
}
|
|
799
|
+
if (isNumber(value) || isBigInt(value)) return toHex(value);
|
|
800
|
+
if (isHex(value)) return value;
|
|
801
|
+
if (isStringWholeNumber(value)) return toHex(value);
|
|
686
802
|
return getSelectorFromName(value);
|
|
687
803
|
}
|
|
804
|
+
function solidityUint256PackedKeccak256(params) {
|
|
805
|
+
const myEncode = addHexPrefix(
|
|
806
|
+
params.reduce(
|
|
807
|
+
(res, par) => res + removeHexPrefix(toHex(par)).padStart(64, "0"),
|
|
808
|
+
""
|
|
809
|
+
)
|
|
810
|
+
);
|
|
811
|
+
return addHexPrefix((0, import_utils2.bytesToHex)((0, import_sha3.keccak_256)(hexToBytes(myEncode))));
|
|
812
|
+
}
|
|
813
|
+
function getL2MessageHash(l1FromAddress, l2ToAddress, l2Selector, l2Calldata, l1Nonce) {
|
|
814
|
+
return solidityUint256PackedKeccak256([
|
|
815
|
+
l1FromAddress,
|
|
816
|
+
l2ToAddress,
|
|
817
|
+
l1Nonce,
|
|
818
|
+
l2Selector,
|
|
819
|
+
l2Calldata.length,
|
|
820
|
+
...l2Calldata
|
|
821
|
+
]);
|
|
822
|
+
}
|
|
688
823
|
|
|
689
824
|
// src/utils/shortString.ts
|
|
690
825
|
var shortString_exports = {};
|
|
@@ -722,15 +857,12 @@ function splitLongString(longStr) {
|
|
|
722
857
|
return longStr.match(regex) || [];
|
|
723
858
|
}
|
|
724
859
|
function encodeShortString(str) {
|
|
725
|
-
if (!isASCII(str))
|
|
726
|
-
|
|
727
|
-
if (!isShortString(str))
|
|
728
|
-
throw new Error(`${str} is too long`);
|
|
860
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
861
|
+
if (!isShortString(str)) throw new Error(`${str} is too long`);
|
|
729
862
|
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
730
863
|
}
|
|
731
864
|
function decodeShortString(str) {
|
|
732
|
-
if (!isASCII(str))
|
|
733
|
-
throw new Error(`${str} is not an ASCII string`);
|
|
865
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
734
866
|
if (isHex(str)) {
|
|
735
867
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
736
868
|
}
|
|
@@ -858,10 +990,8 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
858
990
|
*/
|
|
859
991
|
static validate(bigNumberish) {
|
|
860
992
|
const bigInt = BigInt(bigNumberish);
|
|
861
|
-
if (bigInt < UINT_256_MIN)
|
|
862
|
-
|
|
863
|
-
if (bigInt > UINT_256_MAX)
|
|
864
|
-
throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
993
|
+
if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
|
|
994
|
+
if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
865
995
|
return bigInt;
|
|
866
996
|
}
|
|
867
997
|
/**
|
|
@@ -972,10 +1102,8 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
972
1102
|
*/
|
|
973
1103
|
static validate(bigNumberish) {
|
|
974
1104
|
const bigInt = BigInt(bigNumberish);
|
|
975
|
-
if (bigInt < UINT_512_MIN)
|
|
976
|
-
|
|
977
|
-
if (bigInt > UINT_512_MAX)
|
|
978
|
-
throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
1105
|
+
if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
1106
|
+
if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
979
1107
|
return bigInt;
|
|
980
1108
|
}
|
|
981
1109
|
/**
|
|
@@ -1412,10 +1540,8 @@ function createAbiParser(abi) {
|
|
|
1412
1540
|
throw Error(`Unsupported ABI version ${version}`);
|
|
1413
1541
|
}
|
|
1414
1542
|
function getAbiVersion(abi) {
|
|
1415
|
-
if (abi.find((it) => it.type === "interface"))
|
|
1416
|
-
|
|
1417
|
-
if (isCairo1Abi(abi))
|
|
1418
|
-
return 1;
|
|
1543
|
+
if (abi.find((it) => it.type === "interface")) return 2;
|
|
1544
|
+
if (isCairo1Abi(abi)) return 1;
|
|
1419
1545
|
return 0;
|
|
1420
1546
|
}
|
|
1421
1547
|
function isNoConstructorValid(method, argsCalldata, abiMethod) {
|
|
@@ -1429,8 +1555,7 @@ function parseNamedTuple(namedTuple) {
|
|
|
1429
1555
|
return { name, type };
|
|
1430
1556
|
}
|
|
1431
1557
|
function parseSubTuple(s) {
|
|
1432
|
-
if (!s.includes("("))
|
|
1433
|
-
return { subTuple: [], result: s };
|
|
1558
|
+
if (!s.includes("(")) return { subTuple: [], result: s };
|
|
1434
1559
|
const subTuple = [];
|
|
1435
1560
|
let result = "";
|
|
1436
1561
|
let i = 0;
|
|
@@ -1440,10 +1565,8 @@ function parseSubTuple(s) {
|
|
|
1440
1565
|
const lBracket = i;
|
|
1441
1566
|
i++;
|
|
1442
1567
|
while (counter) {
|
|
1443
|
-
if (s[i] === ")")
|
|
1444
|
-
|
|
1445
|
-
if (s[i] === "(")
|
|
1446
|
-
counter++;
|
|
1568
|
+
if (s[i] === ")") counter--;
|
|
1569
|
+
if (s[i] === "(") counter++;
|
|
1447
1570
|
i++;
|
|
1448
1571
|
}
|
|
1449
1572
|
subTuple.push(s.substring(lBracket, i));
|
|
@@ -1750,8 +1873,7 @@ function parseCalldataValue(element, type, structs, enums) {
|
|
|
1750
1873
|
}
|
|
1751
1874
|
if (type === "core::starknet::eth_address::EthAddress")
|
|
1752
1875
|
return parseBaseTypes(type, element);
|
|
1753
|
-
if (type === "core::byte_array::ByteArray")
|
|
1754
|
-
return parseByteArray(element);
|
|
1876
|
+
if (type === "core::byte_array::ByteArray") return parseByteArray(element);
|
|
1755
1877
|
const { members } = structs[type];
|
|
1756
1878
|
const subElement = element;
|
|
1757
1879
|
return members.reduce((acc, it) => {
|
|
@@ -2071,8 +2193,7 @@ var validateFelt = (parameter, input) => {
|
|
|
2071
2193
|
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
2072
2194
|
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
2073
2195
|
);
|
|
2074
|
-
if (isString(parameter) && !isHex(parameter))
|
|
2075
|
-
return;
|
|
2196
|
+
if (isString(parameter) && !isHex(parameter)) return;
|
|
2076
2197
|
const param = BigInt(parameter.toString(10));
|
|
2077
2198
|
assert(
|
|
2078
2199
|
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1266
|
|
@@ -2378,8 +2499,7 @@ var CallData = class _CallData {
|
|
|
2378
2499
|
validate(type, method, args = []) {
|
|
2379
2500
|
if (type !== "DEPLOY" /* DEPLOY */) {
|
|
2380
2501
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
2381
|
-
if (abi.type !== "function")
|
|
2382
|
-
return false;
|
|
2502
|
+
if (abi.type !== "function") return false;
|
|
2383
2503
|
const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
|
|
2384
2504
|
return type === "INVOKE" /* INVOKE */ ? !isView : isView;
|
|
2385
2505
|
}).map((abi) => abi.name);
|
|
@@ -2457,13 +2577,10 @@ var CallData = class _CallData {
|
|
|
2457
2577
|
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
|
|
2458
2578
|
return Object.entries(oe).flatMap(([k, v]) => {
|
|
2459
2579
|
let value = v;
|
|
2460
|
-
if (k === "entrypoint")
|
|
2461
|
-
|
|
2462
|
-
else if (isLongText(value))
|
|
2463
|
-
value = byteArrayFromString(value);
|
|
2580
|
+
if (k === "entrypoint") value = getSelectorFromName(value);
|
|
2581
|
+
else if (isLongText(value)) value = byteArrayFromString(value);
|
|
2464
2582
|
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
2465
|
-
if (isBigInt(value))
|
|
2466
|
-
return [[`${prefix}${kk}`, felt(value)]];
|
|
2583
|
+
if (isBigInt(value)) return [[`${prefix}${kk}`, felt(value)]];
|
|
2467
2584
|
if (Object(value) === value) {
|
|
2468
2585
|
const methodsKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(value));
|
|
2469
2586
|
const keys = [...Object.getOwnPropertyNames(value), ...methodsKeys];
|
|
@@ -2624,6 +2741,7 @@ __export(hash_exports, {
|
|
|
2624
2741
|
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash3,
|
|
2625
2742
|
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash3,
|
|
2626
2743
|
calculateInvokeTransactionHash: () => calculateInvokeTransactionHash2,
|
|
2744
|
+
calculateL2MessageTxHash: () => calculateL2MessageTxHash,
|
|
2627
2745
|
computeCompiledClassHash: () => computeCompiledClassHash,
|
|
2628
2746
|
computeContractClassHash: () => computeContractClassHash,
|
|
2629
2747
|
computeHashOnElements: () => computeHashOnElements2,
|
|
@@ -2635,11 +2753,13 @@ __export(hash_exports, {
|
|
|
2635
2753
|
computePoseidonHashOnElements: () => computePoseidonHashOnElements,
|
|
2636
2754
|
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
2637
2755
|
formatSpaces: () => formatSpaces,
|
|
2756
|
+
getL2MessageHash: () => getL2MessageHash,
|
|
2638
2757
|
getSelector: () => getSelector,
|
|
2639
2758
|
getSelectorFromName: () => getSelectorFromName,
|
|
2640
2759
|
hashByteCodeSegments: () => hashByteCodeSegments,
|
|
2641
2760
|
keccakBn: () => keccakBn,
|
|
2642
2761
|
poseidon: () => poseidon,
|
|
2762
|
+
solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
|
|
2643
2763
|
starknetKeccak: () => starknetKeccak
|
|
2644
2764
|
});
|
|
2645
2765
|
var poseidon = __toESM(require("@noble/curves/abstract/poseidon"));
|
|
@@ -2649,6 +2769,7 @@ var v2_exports = {};
|
|
|
2649
2769
|
__export(v2_exports, {
|
|
2650
2770
|
calculateDeclareTransactionHash: () => calculateDeclareTransactionHash,
|
|
2651
2771
|
calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash,
|
|
2772
|
+
calculateL2MessageTxHash: () => calculateL2MessageTxHash,
|
|
2652
2773
|
calculateTransactionHash: () => calculateTransactionHash,
|
|
2653
2774
|
calculateTransactionHashCommon: () => calculateTransactionHashCommon,
|
|
2654
2775
|
computeHashOnElements: () => computeHashOnElements
|
|
@@ -2718,6 +2839,19 @@ function calculateTransactionHash(contractAddress, version, calldata, maxFee, ch
|
|
|
2718
2839
|
[nonce]
|
|
2719
2840
|
);
|
|
2720
2841
|
}
|
|
2842
|
+
function calculateL2MessageTxHash(l1FromAddress, l2ToAddress, l2Selector, l2Calldata, l2ChainId, l1Nonce) {
|
|
2843
|
+
const payload = [l1FromAddress, ...l2Calldata];
|
|
2844
|
+
return calculateTransactionHashCommon(
|
|
2845
|
+
"0x6c315f68616e646c6572" /* L1_HANDLER */,
|
|
2846
|
+
0,
|
|
2847
|
+
l2ToAddress,
|
|
2848
|
+
getSelector(l2Selector),
|
|
2849
|
+
payload,
|
|
2850
|
+
0,
|
|
2851
|
+
l2ChainId,
|
|
2852
|
+
[l1Nonce]
|
|
2853
|
+
);
|
|
2854
|
+
}
|
|
2721
2855
|
|
|
2722
2856
|
// src/utils/hash/transactionHash/v3.ts
|
|
2723
2857
|
var v3_exports = {};
|
|
@@ -2900,28 +3034,6 @@ function calculateDeployAccountTransactionHash3(args) {
|
|
|
2900
3034
|
|
|
2901
3035
|
// src/utils/hash/classHash.ts
|
|
2902
3036
|
var import_starknet3 = require("@scure/starknet");
|
|
2903
|
-
|
|
2904
|
-
// src/utils/json.ts
|
|
2905
|
-
var json_exports = {};
|
|
2906
|
-
__export(json_exports, {
|
|
2907
|
-
parse: () => parse2,
|
|
2908
|
-
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
2909
|
-
stringify: () => stringify2,
|
|
2910
|
-
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
2911
|
-
});
|
|
2912
|
-
var json = __toESM(require("lossless-json"));
|
|
2913
|
-
var parseIntAsNumberOrBigInt = (str) => {
|
|
2914
|
-
if (!json.isInteger(str))
|
|
2915
|
-
return parseFloat(str);
|
|
2916
|
-
const num = parseInt(str, 10);
|
|
2917
|
-
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
2918
|
-
};
|
|
2919
|
-
var parse2 = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
2920
|
-
var parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
2921
|
-
var stringify2 = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
2922
|
-
var stringifyAlwaysAsBig = stringify2;
|
|
2923
|
-
|
|
2924
|
-
// src/utils/hash/classHash.ts
|
|
2925
3037
|
function computePedersenHash(a, b) {
|
|
2926
3038
|
return starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
2927
3039
|
}
|
|
@@ -3108,8 +3220,7 @@ function compressProgram(jsonProgram) {
|
|
|
3108
3220
|
return btoaUniversal(compressedProgram);
|
|
3109
3221
|
}
|
|
3110
3222
|
function decompressProgram(base642) {
|
|
3111
|
-
if (Array.isArray(base642))
|
|
3112
|
-
return base642;
|
|
3223
|
+
if (Array.isArray(base642)) return base642;
|
|
3113
3224
|
const decompressed = arrayBufferToString((0, import_pako.ungzip)(atobUniversal(base642)));
|
|
3114
3225
|
return parse2(decompressed);
|
|
3115
3226
|
}
|
|
@@ -3121,8 +3232,7 @@ function makeAddress(input) {
|
|
|
3121
3232
|
return addHexPrefix(input).toLowerCase();
|
|
3122
3233
|
}
|
|
3123
3234
|
function formatSignature(sig) {
|
|
3124
|
-
if (!sig)
|
|
3125
|
-
throw Error("formatSignature: provided signature is undefined");
|
|
3235
|
+
if (!sig) throw Error("formatSignature: provided signature is undefined");
|
|
3126
3236
|
if (Array.isArray(sig)) {
|
|
3127
3237
|
return sig.map((it) => toHex(it));
|
|
3128
3238
|
}
|
|
@@ -3160,10 +3270,8 @@ function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUN
|
|
|
3160
3270
|
};
|
|
3161
3271
|
}
|
|
3162
3272
|
function intDAM(dam) {
|
|
3163
|
-
if (dam === api_exports.EDataAvailabilityMode.L1)
|
|
3164
|
-
|
|
3165
|
-
if (dam === api_exports.EDataAvailabilityMode.L2)
|
|
3166
|
-
return api_exports.EDAMode.L2;
|
|
3273
|
+
if (dam === api_exports.EDataAvailabilityMode.L1) return api_exports.EDAMode.L1;
|
|
3274
|
+
if (dam === api_exports.EDataAvailabilityMode.L2) return api_exports.EDAMode.L2;
|
|
3167
3275
|
throw Error("EDAM conversion");
|
|
3168
3276
|
}
|
|
3169
3277
|
function toTransactionVersion(defaultVersion, providedVersion) {
|
|
@@ -3178,17 +3286,12 @@ function toTransactionVersion(defaultVersion, providedVersion) {
|
|
|
3178
3286
|
return providedVersion ? providedVersion0xs : defaultVersion0xs;
|
|
3179
3287
|
}
|
|
3180
3288
|
function toFeeVersion(providedVersion) {
|
|
3181
|
-
if (!providedVersion)
|
|
3182
|
-
return void 0;
|
|
3289
|
+
if (!providedVersion) return void 0;
|
|
3183
3290
|
const version = toHex(providedVersion);
|
|
3184
|
-
if (version === api_exports.ETransactionVersion.V0)
|
|
3185
|
-
|
|
3186
|
-
if (version === api_exports.ETransactionVersion.
|
|
3187
|
-
|
|
3188
|
-
if (version === api_exports.ETransactionVersion.V2)
|
|
3189
|
-
return api_exports.ETransactionVersion.F2;
|
|
3190
|
-
if (version === api_exports.ETransactionVersion.V3)
|
|
3191
|
-
return api_exports.ETransactionVersion.F3;
|
|
3291
|
+
if (version === api_exports.ETransactionVersion.V0) return api_exports.ETransactionVersion.F0;
|
|
3292
|
+
if (version === api_exports.ETransactionVersion.V1) return api_exports.ETransactionVersion.F1;
|
|
3293
|
+
if (version === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.F2;
|
|
3294
|
+
if (version === api_exports.ETransactionVersion.V3) return api_exports.ETransactionVersion.F3;
|
|
3192
3295
|
throw Error(`toFeeVersion: ${version} is not supported`);
|
|
3193
3296
|
}
|
|
3194
3297
|
function v3Details(details) {
|
|
@@ -3202,10 +3305,8 @@ function v3Details(details) {
|
|
|
3202
3305
|
};
|
|
3203
3306
|
}
|
|
3204
3307
|
function reduceV2(providedVersion) {
|
|
3205
|
-
if (providedVersion === api_exports.ETransactionVersion.F2)
|
|
3206
|
-
|
|
3207
|
-
if (providedVersion === api_exports.ETransactionVersion.V2)
|
|
3208
|
-
return api_exports.ETransactionVersion.V1;
|
|
3308
|
+
if (providedVersion === api_exports.ETransactionVersion.F2) return api_exports.ETransactionVersion.F1;
|
|
3309
|
+
if (providedVersion === api_exports.ETransactionVersion.V2) return api_exports.ETransactionVersion.V1;
|
|
3209
3310
|
return providedVersion;
|
|
3210
3311
|
}
|
|
3211
3312
|
|
|
@@ -3545,8 +3646,9 @@ var RpcChannel = class {
|
|
|
3545
3646
|
specVersion;
|
|
3546
3647
|
waitMode;
|
|
3547
3648
|
// behave like web2 rpc and return when tx is processed
|
|
3649
|
+
batchClient;
|
|
3548
3650
|
constructor(optionsOrProvider) {
|
|
3549
|
-
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
|
|
3651
|
+
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode, batch } = optionsOrProvider || {};
|
|
3550
3652
|
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
3551
3653
|
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
3552
3654
|
} else if (nodeUrl) {
|
|
@@ -3561,6 +3663,13 @@ var RpcChannel = class {
|
|
|
3561
3663
|
this.specVersion = specVersion;
|
|
3562
3664
|
this.waitMode = waitMode || false;
|
|
3563
3665
|
this.requestId = 0;
|
|
3666
|
+
if (typeof batch === "number") {
|
|
3667
|
+
this.batchClient = new BatchClient({
|
|
3668
|
+
nodeUrl: this.nodeUrl,
|
|
3669
|
+
headers: this.headers,
|
|
3670
|
+
interval: batch
|
|
3671
|
+
});
|
|
3672
|
+
}
|
|
3564
3673
|
}
|
|
3565
3674
|
setChainId(chainId) {
|
|
3566
3675
|
this.chainId = chainId;
|
|
@@ -3596,6 +3705,15 @@ var RpcChannel = class {
|
|
|
3596
3705
|
}
|
|
3597
3706
|
async fetchEndpoint(method, params) {
|
|
3598
3707
|
try {
|
|
3708
|
+
if (this.batchClient) {
|
|
3709
|
+
const { error: error2, result: result2 } = await this.batchClient.fetch(
|
|
3710
|
+
method,
|
|
3711
|
+
params,
|
|
3712
|
+
this.requestId += 1
|
|
3713
|
+
);
|
|
3714
|
+
this.errorHandler(method, params, error2);
|
|
3715
|
+
return result2;
|
|
3716
|
+
}
|
|
3599
3717
|
const rawResult = await this.fetch(method, params, this.requestId += 1);
|
|
3600
3718
|
const { error, result } = await rawResult.json();
|
|
3601
3719
|
this.errorHandler(method, params, error);
|
|
@@ -3695,10 +3813,8 @@ var RpcChannel = class {
|
|
|
3695
3813
|
} = simulateTransactionOptions;
|
|
3696
3814
|
const block_id = new Block(blockIdentifier).identifier;
|
|
3697
3815
|
const simulationFlags = [];
|
|
3698
|
-
if (skipValidate)
|
|
3699
|
-
|
|
3700
|
-
if (skipFeeCharge)
|
|
3701
|
-
simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3816
|
+
if (skipValidate) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
|
|
3817
|
+
if (skipFeeCharge) simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
3702
3818
|
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
3703
3819
|
block_id,
|
|
3704
3820
|
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
@@ -4080,6 +4196,7 @@ var RpcChannel2 = class {
|
|
|
4080
4196
|
transactionRetryIntervalFallback;
|
|
4081
4197
|
waitMode;
|
|
4082
4198
|
// behave like web2 rpc and return when tx is processed
|
|
4199
|
+
batchClient;
|
|
4083
4200
|
constructor(optionsOrProvider) {
|
|
4084
4201
|
const {
|
|
4085
4202
|
nodeUrl,
|
|
@@ -4089,7 +4206,8 @@ var RpcChannel2 = class {
|
|
|
4089
4206
|
chainId,
|
|
4090
4207
|
specVersion,
|
|
4091
4208
|
waitMode,
|
|
4092
|
-
transactionRetryIntervalFallback
|
|
4209
|
+
transactionRetryIntervalFallback,
|
|
4210
|
+
batch
|
|
4093
4211
|
} = optionsOrProvider || {};
|
|
4094
4212
|
if (Object.values(NetworkName).includes(nodeUrl)) {
|
|
4095
4213
|
this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
|
|
@@ -4106,6 +4224,13 @@ var RpcChannel2 = class {
|
|
|
4106
4224
|
this.waitMode = waitMode || false;
|
|
4107
4225
|
this.requestId = 0;
|
|
4108
4226
|
this.transactionRetryIntervalFallback = transactionRetryIntervalFallback;
|
|
4227
|
+
if (typeof batch === "number") {
|
|
4228
|
+
this.batchClient = new BatchClient({
|
|
4229
|
+
nodeUrl: this.nodeUrl,
|
|
4230
|
+
headers: this.headers,
|
|
4231
|
+
interval: batch
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4109
4234
|
}
|
|
4110
4235
|
get transactionRetryIntervalDefault() {
|
|
4111
4236
|
return this.transactionRetryIntervalFallback ?? 5e3;
|
|
@@ -4144,6 +4269,15 @@ var RpcChannel2 = class {
|
|
|
4144
4269
|
}
|
|
4145
4270
|
async fetchEndpoint(method, params) {
|
|
4146
4271
|
try {
|
|
4272
|
+
if (this.batchClient) {
|
|
4273
|
+
const { error: error2, result: result2 } = await this.batchClient.fetch(
|
|
4274
|
+
method,
|
|
4275
|
+
params,
|
|
4276
|
+
this.requestId += 1
|
|
4277
|
+
);
|
|
4278
|
+
this.errorHandler(method, params, error2);
|
|
4279
|
+
return result2;
|
|
4280
|
+
}
|
|
4147
4281
|
const rawResult = await this.fetch(method, params, this.requestId += 1);
|
|
4148
4282
|
const { error, result } = await rawResult.json();
|
|
4149
4283
|
this.errorHandler(method, params, error);
|
|
@@ -4247,10 +4381,8 @@ var RpcChannel2 = class {
|
|
|
4247
4381
|
} = simulateTransactionOptions;
|
|
4248
4382
|
const block_id = new Block(blockIdentifier).identifier;
|
|
4249
4383
|
const simulationFlags = [];
|
|
4250
|
-
if (skipValidate)
|
|
4251
|
-
|
|
4252
|
-
if (skipFeeCharge)
|
|
4253
|
-
simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
4384
|
+
if (skipValidate) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_VALIDATE);
|
|
4385
|
+
if (skipFeeCharge) simulationFlags.push(RPCSPEC07.ESimulationFlag.SKIP_FEE_CHARGE);
|
|
4254
4386
|
return this.fetchEndpoint("starknet_simulateTransactions", {
|
|
4255
4387
|
block_id,
|
|
4256
4388
|
transactions: invocations.map((it) => this.buildTransaction(it)),
|
|
@@ -4785,7 +4917,7 @@ var RpcProvider = class {
|
|
|
4785
4917
|
}
|
|
4786
4918
|
/**
|
|
4787
4919
|
* Pause the execution of the script until a specified block is created.
|
|
4788
|
-
* @param {BlockIdentifier} blockIdentifier bloc number (
|
|
4920
|
+
* @param {BlockIdentifier} blockIdentifier bloc number (BigNumberish) or 'pending' or 'latest'.
|
|
4789
4921
|
* Use of 'latest" or of a block already created will generate no pause.
|
|
4790
4922
|
* @param {number} [retryInterval] number of milliseconds between 2 requests to the node
|
|
4791
4923
|
* @example
|
|
@@ -4795,12 +4927,10 @@ var RpcProvider = class {
|
|
|
4795
4927
|
* ```
|
|
4796
4928
|
*/
|
|
4797
4929
|
async waitForBlock(blockIdentifier = "pending", retryInterval = 5e3) {
|
|
4798
|
-
if (blockIdentifier === "latest" /* LATEST */)
|
|
4799
|
-
return;
|
|
4930
|
+
if (blockIdentifier === "latest" /* LATEST */) return;
|
|
4800
4931
|
const currentBlock = await this.getBlockNumber();
|
|
4801
4932
|
const targetBlock = blockIdentifier === "pending" /* PENDING */ ? currentBlock + 1 : Number(toHex(blockIdentifier));
|
|
4802
|
-
if (targetBlock <= currentBlock)
|
|
4803
|
-
return;
|
|
4933
|
+
if (targetBlock <= currentBlock) return;
|
|
4804
4934
|
const { retries } = this.channel;
|
|
4805
4935
|
let retriesCount = retries;
|
|
4806
4936
|
let isTargetBlock = false;
|
|
@@ -4832,13 +4962,7 @@ var RpcProvider = class {
|
|
|
4832
4962
|
calldata.length - 1,
|
|
4833
4963
|
...calldata.slice(1)
|
|
4834
4964
|
];
|
|
4835
|
-
|
|
4836
|
-
params.reduce(
|
|
4837
|
-
(res, par) => res + removeHexPrefix(toHex(par)).padStart(64, "0"),
|
|
4838
|
-
""
|
|
4839
|
-
)
|
|
4840
|
-
);
|
|
4841
|
-
return addHexPrefix((0, import_utils2.bytesToHex)((0, import_sha3.keccak_256)(hexToBytes(myEncode))));
|
|
4965
|
+
return solidityUint256PackedKeccak256(params);
|
|
4842
4966
|
}
|
|
4843
4967
|
async getBlockWithReceipts(blockIdentifier) {
|
|
4844
4968
|
if (this.channel instanceof rpc_0_6_exports.RpcChannel)
|
|
@@ -5074,17 +5198,14 @@ function useDecoded(encoded) {
|
|
|
5074
5198
|
if (nextSubdomain === ZERO) {
|
|
5075
5199
|
const code2 = subdomain % bigAlphabetSizePlusOne;
|
|
5076
5200
|
subdomain = nextSubdomain;
|
|
5077
|
-
if (code2 === ZERO)
|
|
5078
|
-
|
|
5079
|
-
else
|
|
5080
|
-
decoded += bigAlphabet[Number(code2) - 1];
|
|
5201
|
+
if (code2 === ZERO) decoded += basicAlphabet[0];
|
|
5202
|
+
else decoded += bigAlphabet[Number(code2) - 1];
|
|
5081
5203
|
} else {
|
|
5082
5204
|
const code2 = subdomain % bigAlphabetSize;
|
|
5083
5205
|
decoded += bigAlphabet[Number(code2)];
|
|
5084
5206
|
subdomain /= bigAlphabetSize;
|
|
5085
5207
|
}
|
|
5086
|
-
} else
|
|
5087
|
-
decoded += basicAlphabet[Number(code)];
|
|
5208
|
+
} else decoded += basicAlphabet[Number(code)];
|
|
5088
5209
|
}
|
|
5089
5210
|
const [str, k] = extractStars(decoded);
|
|
5090
5211
|
if (k)
|
|
@@ -5104,8 +5225,7 @@ function useEncoded(decoded) {
|
|
|
5104
5225
|
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
5105
5226
|
} else {
|
|
5106
5227
|
const [str, k] = extractStars(decoded);
|
|
5107
|
-
if (k)
|
|
5108
|
-
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
5228
|
+
if (k) decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
5109
5229
|
}
|
|
5110
5230
|
for (let i = 0; i < decoded.length; i += 1) {
|
|
5111
5231
|
const char = decoded[i];
|
|
@@ -5760,8 +5880,7 @@ function encodeValue(types, type, data, ctx = {}, revision = import_starknet_typ
|
|
|
5760
5880
|
const variantType = enumType.find((t) => t.name === variantKey);
|
|
5761
5881
|
const variantIndex = enumType.indexOf(variantType);
|
|
5762
5882
|
const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
|
|
5763
|
-
if (!subtype)
|
|
5764
|
-
return subtype;
|
|
5883
|
+
if (!subtype) return subtype;
|
|
5765
5884
|
const subtypeData = variantData[index];
|
|
5766
5885
|
return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
|
|
5767
5886
|
});
|
|
@@ -6119,6 +6238,195 @@ var EthSigner = class {
|
|
|
6119
6238
|
}
|
|
6120
6239
|
};
|
|
6121
6240
|
|
|
6241
|
+
// src/signer/ledgerSigner.ts
|
|
6242
|
+
var LedgerSigner = class {
|
|
6243
|
+
transporter;
|
|
6244
|
+
accountID;
|
|
6245
|
+
eip2645applicationName;
|
|
6246
|
+
pathBuffer;
|
|
6247
|
+
appVersion;
|
|
6248
|
+
pubKey;
|
|
6249
|
+
fullPubKey;
|
|
6250
|
+
/**
|
|
6251
|
+
* constructor of the LedgerSigner class.
|
|
6252
|
+
* @param {Transport} transport 5 transports are available to handle USB, bluetooth, Node, Web, Mobile.
|
|
6253
|
+
* See Guides for more details.
|
|
6254
|
+
* @param {number} accountID ID of Ledger Nano (can handle 2**31 accounts).
|
|
6255
|
+
* @param {string} [eip2645application='LedgerW'] A wallet is defined by an ERC2645 derivation path (6 items).
|
|
6256
|
+
* One item is the `application`. Default value is `LedgerW`.
|
|
6257
|
+
* @example
|
|
6258
|
+
* ```typescript
|
|
6259
|
+
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
|
|
6260
|
+
* const myNodeTransport = await TransportNodeHid.create();
|
|
6261
|
+
* const myLedgerSigner = new LedgerSigner(myNodeTransport, 0);
|
|
6262
|
+
* ```
|
|
6263
|
+
*/
|
|
6264
|
+
constructor(transport, accountID, eip2645application = "LedgerW") {
|
|
6265
|
+
assert(accountID >= 0, "Ledger account ID shall not be a negative number.");
|
|
6266
|
+
assert(accountID <= MASK_31, "Ledger account ID shall be < 2**31.");
|
|
6267
|
+
assert(!!eip2645application, "Ledger application name shall not be empty.");
|
|
6268
|
+
this.transporter = transport;
|
|
6269
|
+
this.accountID = accountID;
|
|
6270
|
+
this.pubKey = "";
|
|
6271
|
+
this.fullPubKey = "";
|
|
6272
|
+
this.eip2645applicationName = eip2645application;
|
|
6273
|
+
this.appVersion = "";
|
|
6274
|
+
this.pathBuffer = getLedgerPathBuffer(this.accountID, this.eip2645applicationName);
|
|
6275
|
+
}
|
|
6276
|
+
/**
|
|
6277
|
+
* provides the Starknet public key
|
|
6278
|
+
* @returns an hex string : 64 characters are Point X coordinate.
|
|
6279
|
+
*/
|
|
6280
|
+
async getPubKey() {
|
|
6281
|
+
if (!this.pubKey) await this.getPublicKeys();
|
|
6282
|
+
return this.pubKey;
|
|
6283
|
+
}
|
|
6284
|
+
/**
|
|
6285
|
+
* provides the full public key (with parity prefix)
|
|
6286
|
+
* @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.
|
|
6287
|
+
*/
|
|
6288
|
+
async getFullPubKey() {
|
|
6289
|
+
if (!this.fullPubKey) await this.getPublicKeys();
|
|
6290
|
+
return this.fullPubKey;
|
|
6291
|
+
}
|
|
6292
|
+
/**
|
|
6293
|
+
* Returns the version of the Starknet APP implemented in the Ledger.
|
|
6294
|
+
* @returns {string} version.
|
|
6295
|
+
* @example
|
|
6296
|
+
* ```typescript
|
|
6297
|
+
* const result = await myLedgerSigner.getAppVersion();
|
|
6298
|
+
* // result= "1.1.1"
|
|
6299
|
+
* ```
|
|
6300
|
+
*/
|
|
6301
|
+
async getAppVersion() {
|
|
6302
|
+
if (!this.appVersion) {
|
|
6303
|
+
const resp = await this.transporter.send(Number("0x5a"), 0, 0, 0);
|
|
6304
|
+
this.appVersion = `${resp[0]}.${resp[1]}.${resp[2]}`;
|
|
6305
|
+
}
|
|
6306
|
+
return this.appVersion;
|
|
6307
|
+
}
|
|
6308
|
+
async signMessage(typedDataToHash, accountAddress) {
|
|
6309
|
+
const msgHash = getMessageHash(typedDataToHash, accountAddress);
|
|
6310
|
+
return this.signRaw(msgHash);
|
|
6311
|
+
}
|
|
6312
|
+
async signTransaction(transactions, transactionsDetail) {
|
|
6313
|
+
const compiledCalldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
6314
|
+
let msgHash;
|
|
6315
|
+
if (Object.values(ETransactionVersion2).includes(transactionsDetail.version)) {
|
|
6316
|
+
const det = transactionsDetail;
|
|
6317
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
6318
|
+
...det,
|
|
6319
|
+
senderAddress: det.walletAddress,
|
|
6320
|
+
compiledCalldata,
|
|
6321
|
+
version: det.version
|
|
6322
|
+
});
|
|
6323
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(transactionsDetail.version)) {
|
|
6324
|
+
const det = transactionsDetail;
|
|
6325
|
+
msgHash = calculateInvokeTransactionHash2({
|
|
6326
|
+
...det,
|
|
6327
|
+
senderAddress: det.walletAddress,
|
|
6328
|
+
compiledCalldata,
|
|
6329
|
+
version: det.version,
|
|
6330
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6331
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6332
|
+
});
|
|
6333
|
+
} else {
|
|
6334
|
+
throw Error("unsupported signTransaction version");
|
|
6335
|
+
}
|
|
6336
|
+
return this.signRaw(msgHash);
|
|
6337
|
+
}
|
|
6338
|
+
async signDeployAccountTransaction(details) {
|
|
6339
|
+
const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
|
|
6340
|
+
let msgHash;
|
|
6341
|
+
if (Object.values(ETransactionVersion2).includes(details.version)) {
|
|
6342
|
+
const det = details;
|
|
6343
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
6344
|
+
...det,
|
|
6345
|
+
salt: det.addressSalt,
|
|
6346
|
+
constructorCalldata: compiledConstructorCalldata,
|
|
6347
|
+
version: det.version
|
|
6348
|
+
});
|
|
6349
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(details.version)) {
|
|
6350
|
+
const det = details;
|
|
6351
|
+
msgHash = calculateDeployAccountTransactionHash3({
|
|
6352
|
+
...det,
|
|
6353
|
+
salt: det.addressSalt,
|
|
6354
|
+
compiledConstructorCalldata,
|
|
6355
|
+
version: det.version,
|
|
6356
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6357
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6358
|
+
});
|
|
6359
|
+
} else {
|
|
6360
|
+
throw Error("unsupported signDeployAccountTransaction version");
|
|
6361
|
+
}
|
|
6362
|
+
return this.signRaw(msgHash);
|
|
6363
|
+
}
|
|
6364
|
+
async signDeclareTransaction(details) {
|
|
6365
|
+
let msgHash;
|
|
6366
|
+
if (Object.values(ETransactionVersion2).includes(details.version)) {
|
|
6367
|
+
const det = details;
|
|
6368
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
6369
|
+
...det,
|
|
6370
|
+
version: det.version
|
|
6371
|
+
});
|
|
6372
|
+
} else if (Object.values(api_exports.ETransactionVersion3).includes(details.version)) {
|
|
6373
|
+
const det = details;
|
|
6374
|
+
msgHash = calculateDeclareTransactionHash3({
|
|
6375
|
+
...det,
|
|
6376
|
+
version: det.version,
|
|
6377
|
+
nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
|
|
6378
|
+
feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
|
|
6379
|
+
});
|
|
6380
|
+
} else {
|
|
6381
|
+
throw Error("unsupported signDeclareTransaction version");
|
|
6382
|
+
}
|
|
6383
|
+
return this.signRaw(msgHash);
|
|
6384
|
+
}
|
|
6385
|
+
async signRaw(msgHash) {
|
|
6386
|
+
addHexPrefix(
|
|
6387
|
+
buf2hex(await this.transporter.send(Number("0x5a"), 2, 0, 0, Buffer.from(this.pathBuffer)))
|
|
6388
|
+
);
|
|
6389
|
+
const shiftedHash = toHex(BigInt(msgHash) << 4n);
|
|
6390
|
+
const buff2 = hexToBytes(shiftedHash);
|
|
6391
|
+
const respSign2 = Uint8Array.from(
|
|
6392
|
+
await this.transporter.send(Number("0x5a"), 2, 1, 0, Buffer.from(buff2))
|
|
6393
|
+
);
|
|
6394
|
+
const r = BigInt(addHexPrefix(buf2hex(respSign2.subarray(1, 33))));
|
|
6395
|
+
const s = BigInt(addHexPrefix(buf2hex(respSign2.subarray(33, 65))));
|
|
6396
|
+
const v = respSign2[65];
|
|
6397
|
+
const sign0 = new starkCurve.Signature(r, s);
|
|
6398
|
+
const sign1 = sign0.addRecoveryBit(v);
|
|
6399
|
+
return sign1;
|
|
6400
|
+
}
|
|
6401
|
+
async getPublicKeys() {
|
|
6402
|
+
const pathBuff = this.pathBuffer;
|
|
6403
|
+
const respGetPublic = Uint8Array.from(
|
|
6404
|
+
await this.transporter.send(Number("0x5a"), 1, 0, 0, Buffer.from(pathBuff))
|
|
6405
|
+
);
|
|
6406
|
+
this.pubKey = addHexPrefix(buf2hex(respGetPublic.subarray(1, 33)));
|
|
6407
|
+
this.fullPubKey = addHexPrefix(buf2hex(respGetPublic.subarray(0, 65)));
|
|
6408
|
+
}
|
|
6409
|
+
};
|
|
6410
|
+
function getLedgerPathBuffer(accountId, applicationName) {
|
|
6411
|
+
const path0buff = new Uint8Array([128, 0, 10, 85]);
|
|
6412
|
+
const path1buff = new Uint8Array([71, 65, 233, 201]);
|
|
6413
|
+
const path2buff = applicationName === "LedgerW" ? new Uint8Array([43, 206, 231, 219]) : stringToSha256ToArrayBuff4(applicationName);
|
|
6414
|
+
const path3buff = new Uint8Array([0, 0, 0, 0]);
|
|
6415
|
+
const hex = toHex(accountId);
|
|
6416
|
+
const padded = addHexPrefix(removeHexPrefix(hex).padStart(8, "0"));
|
|
6417
|
+
const path4buff = hexToBytes(padded);
|
|
6418
|
+
const path5buff = new Uint8Array([0, 0, 0, 0]);
|
|
6419
|
+
const pathBuff = concatenateArrayBuffer([
|
|
6420
|
+
path0buff,
|
|
6421
|
+
path1buff,
|
|
6422
|
+
path2buff,
|
|
6423
|
+
path3buff,
|
|
6424
|
+
path4buff,
|
|
6425
|
+
path5buff
|
|
6426
|
+
]);
|
|
6427
|
+
return pathBuff;
|
|
6428
|
+
}
|
|
6429
|
+
|
|
6122
6430
|
// src/utils/events/index.ts
|
|
6123
6431
|
var events_exports = {};
|
|
6124
6432
|
__export(events_exports, {
|
|
@@ -6152,19 +6460,16 @@ function getCairo1AbiEvents(abi) {
|
|
|
6152
6460
|
const findName = (variant) => variant.type === name;
|
|
6153
6461
|
while (true) {
|
|
6154
6462
|
const eventEnum = abiEventsEnums.find((eventE) => eventE.variants.some(findName));
|
|
6155
|
-
if (typeof eventEnum === "undefined")
|
|
6156
|
-
break;
|
|
6463
|
+
if (typeof eventEnum === "undefined") break;
|
|
6157
6464
|
const variant = eventEnum.variants.find(findName);
|
|
6158
6465
|
nameList.unshift(variant.name);
|
|
6159
|
-
if (variant.kind === "flat")
|
|
6160
|
-
flat = true;
|
|
6466
|
+
if (variant.kind === "flat") flat = true;
|
|
6161
6467
|
name = eventEnum.name;
|
|
6162
6468
|
}
|
|
6163
6469
|
if (nameList.length === 0) {
|
|
6164
6470
|
throw new Error("inconsistency in ABI events definition.");
|
|
6165
6471
|
}
|
|
6166
|
-
if (flat)
|
|
6167
|
-
nameList = [nameList[nameList.length - 1]];
|
|
6472
|
+
if (flat) nameList = [nameList[nameList.length - 1]];
|
|
6168
6473
|
const final = nameList.pop();
|
|
6169
6474
|
let result = {
|
|
6170
6475
|
[addHexPrefix(starkCurve.keccak(utf8ToArray(final)).toString(16))]: event
|
|
@@ -6190,10 +6495,8 @@ function mergeAbiEvents(target, source) {
|
|
|
6190
6495
|
if (isObject(target) && isObject(source)) {
|
|
6191
6496
|
Object.keys(source).forEach((key) => {
|
|
6192
6497
|
if (isObject(source[key])) {
|
|
6193
|
-
if (!(key in target))
|
|
6194
|
-
|
|
6195
|
-
else
|
|
6196
|
-
output[key] = mergeAbiEvents(target[key], source[key]);
|
|
6498
|
+
if (!(key in target)) Object.assign(output, { [key]: source[key] });
|
|
6499
|
+
else output[key] = mergeAbiEvents(target[key], source[key]);
|
|
6197
6500
|
} else {
|
|
6198
6501
|
Object.assign(output, { [key]: source[key] });
|
|
6199
6502
|
}
|
|
@@ -6280,10 +6583,8 @@ var Account = class extends RpcProvider2 {
|
|
|
6280
6583
|
}
|
|
6281
6584
|
// provided version or contract based preferred transactionVersion
|
|
6282
6585
|
getPreferredVersion(type12, type3) {
|
|
6283
|
-
if (this.transactionVersion === api_exports.ETransactionVersion.V3)
|
|
6284
|
-
|
|
6285
|
-
if (this.transactionVersion === api_exports.ETransactionVersion.V2)
|
|
6286
|
-
return type12;
|
|
6586
|
+
if (this.transactionVersion === api_exports.ETransactionVersion.V3) return type3;
|
|
6587
|
+
if (this.transactionVersion === api_exports.ETransactionVersion.V2) return type12;
|
|
6287
6588
|
return api_exports.ETransactionVersion.V3;
|
|
6288
6589
|
}
|
|
6289
6590
|
async getNonce(blockIdentifier) {
|
|
@@ -6989,13 +7290,11 @@ var WalletAccount = class extends Account {
|
|
|
6989
7290
|
super(providerOrOptions, "", "", cairoVersion);
|
|
6990
7291
|
this.walletProvider = walletProvider;
|
|
6991
7292
|
this.walletProvider.on("accountsChanged", (res) => {
|
|
6992
|
-
if (!res)
|
|
6993
|
-
return;
|
|
7293
|
+
if (!res) return;
|
|
6994
7294
|
this.address = res[0].toLowerCase();
|
|
6995
7295
|
});
|
|
6996
7296
|
this.walletProvider.on("networkChanged", (res) => {
|
|
6997
|
-
if (!res)
|
|
6998
|
-
return;
|
|
7297
|
+
if (!res) return;
|
|
6999
7298
|
this.channel.setChainId(res);
|
|
7000
7299
|
});
|
|
7001
7300
|
walletProvider.request({
|
|
@@ -7135,8 +7434,7 @@ function buildEstimate(contract, functionAbi) {
|
|
|
7135
7434
|
};
|
|
7136
7435
|
}
|
|
7137
7436
|
function getCalldata(args, callback) {
|
|
7138
|
-
if (Array.isArray(args) && "__compiled__" in args)
|
|
7139
|
-
return args;
|
|
7437
|
+
if (Array.isArray(args) && "__compiled__" in args) return args;
|
|
7140
7438
|
if (Array.isArray(args) && Array.isArray(args[0]) && "__compiled__" in args[0])
|
|
7141
7439
|
return args[0];
|
|
7142
7440
|
return callback();
|
|
@@ -7176,8 +7474,7 @@ var Contract = class {
|
|
|
7176
7474
|
estimateFee: { enumerable: true, value: {}, writable: false }
|
|
7177
7475
|
});
|
|
7178
7476
|
this.abi.forEach((abiElement) => {
|
|
7179
|
-
if (abiElement.type !== "function")
|
|
7180
|
-
return;
|
|
7477
|
+
if (abiElement.type !== "function") return;
|
|
7181
7478
|
const signature = abiElement.name;
|
|
7182
7479
|
if (!this[signature]) {
|
|
7183
7480
|
Object.defineProperty(this, signature, {
|
|
@@ -7277,8 +7574,7 @@ var Contract = class {
|
|
|
7277
7574
|
nonce
|
|
7278
7575
|
});
|
|
7279
7576
|
}
|
|
7280
|
-
if (!nonce)
|
|
7281
|
-
throw new Error(`Nonce is required when invoking a function without an account`);
|
|
7577
|
+
if (!nonce) throw new Error(`Nonce is required when invoking a function without an account`);
|
|
7282
7578
|
console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
|
|
7283
7579
|
return this.providerOrAccount.invokeFunction(
|
|
7284
7580
|
{
|
|
@@ -7508,6 +7804,7 @@ var number = num_exports;
|
|
|
7508
7804
|
EthSigner,
|
|
7509
7805
|
GatewayError,
|
|
7510
7806
|
HttpError,
|
|
7807
|
+
LedgerSigner,
|
|
7511
7808
|
LibraryError,
|
|
7512
7809
|
Literal,
|
|
7513
7810
|
Provider,
|
|
@@ -7556,6 +7853,7 @@ var number = num_exports;
|
|
|
7556
7853
|
fixStack,
|
|
7557
7854
|
getCalldata,
|
|
7558
7855
|
getChecksumAddress,
|
|
7856
|
+
getLedgerPathBuffer,
|
|
7559
7857
|
hash,
|
|
7560
7858
|
isSierra,
|
|
7561
7859
|
isUrl,
|