starknet 5.2.0 → 5.4.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 +23 -0
- package/README.md +2 -5
- package/dist/index.d.ts +1187 -1010
- package/dist/index.global.js +1132 -2840
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +326 -204
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +324 -204
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -5
package/dist/index.global.js
CHANGED
|
@@ -540,2521 +540,105 @@ var starknet = (() => {
|
|
|
540
540
|
}
|
|
541
541
|
});
|
|
542
542
|
|
|
543
|
-
// node_modules
|
|
544
|
-
var
|
|
545
|
-
"node_modules
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
if (typeof hash3 !== "function" || typeof hash3.create !== "function")
|
|
568
|
-
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
569
|
-
number3(hash3.outputLen);
|
|
570
|
-
number3(hash3.blockLen);
|
|
571
|
-
}
|
|
572
|
-
exports.hash = hash2;
|
|
573
|
-
function exists2(instance, checkFinished = true) {
|
|
574
|
-
if (instance.destroyed)
|
|
575
|
-
throw new Error("Hash instance has been destroyed");
|
|
576
|
-
if (checkFinished && instance.finished)
|
|
577
|
-
throw new Error("Hash#digest() has already been called");
|
|
578
|
-
}
|
|
579
|
-
exports.exists = exists2;
|
|
580
|
-
function output2(out, instance) {
|
|
581
|
-
bytes2(out);
|
|
582
|
-
const min = instance.outputLen;
|
|
583
|
-
if (out.length < min) {
|
|
584
|
-
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
exports.output = output2;
|
|
588
|
-
var assert3 = {
|
|
589
|
-
number: number3,
|
|
590
|
-
bool: bool2,
|
|
591
|
-
bytes: bytes2,
|
|
592
|
-
hash: hash2,
|
|
593
|
-
exists: exists2,
|
|
594
|
-
output: output2
|
|
595
|
-
};
|
|
596
|
-
exports.default = assert3;
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
// node_modules/@noble/hashes/_u64.js
|
|
601
|
-
var require_u64 = __commonJS({
|
|
602
|
-
"node_modules/@noble/hashes/_u64.js"(exports) {
|
|
603
|
-
"use strict";
|
|
604
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
605
|
-
exports.add = exports.toBig = exports.split = exports.fromBig = void 0;
|
|
606
|
-
var U32_MASK642 = BigInt(2 ** 32 - 1);
|
|
607
|
-
var _32n2 = BigInt(32);
|
|
608
|
-
function fromBig2(n, le = false) {
|
|
609
|
-
if (le)
|
|
610
|
-
return { h: Number(n & U32_MASK642), l: Number(n >> _32n2 & U32_MASK642) };
|
|
611
|
-
return { h: Number(n >> _32n2 & U32_MASK642) | 0, l: Number(n & U32_MASK642) | 0 };
|
|
612
|
-
}
|
|
613
|
-
exports.fromBig = fromBig2;
|
|
614
|
-
function split2(lst, le = false) {
|
|
615
|
-
let Ah = new Uint32Array(lst.length);
|
|
616
|
-
let Al = new Uint32Array(lst.length);
|
|
617
|
-
for (let i = 0; i < lst.length; i++) {
|
|
618
|
-
const { h, l } = fromBig2(lst[i], le);
|
|
619
|
-
[Ah[i], Al[i]] = [h, l];
|
|
620
|
-
}
|
|
621
|
-
return [Ah, Al];
|
|
622
|
-
}
|
|
623
|
-
exports.split = split2;
|
|
624
|
-
var toBig2 = (h, l) => BigInt(h >>> 0) << _32n2 | BigInt(l >>> 0);
|
|
625
|
-
exports.toBig = toBig2;
|
|
626
|
-
var shrSH2 = (h, l, s) => h >>> s;
|
|
627
|
-
var shrSL2 = (h, l, s) => h << 32 - s | l >>> s;
|
|
628
|
-
var rotrSH2 = (h, l, s) => h >>> s | l << 32 - s;
|
|
629
|
-
var rotrSL2 = (h, l, s) => h << 32 - s | l >>> s;
|
|
630
|
-
var rotrBH2 = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
631
|
-
var rotrBL2 = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
632
|
-
var rotr32H2 = (h, l) => l;
|
|
633
|
-
var rotr32L2 = (h, l) => h;
|
|
634
|
-
var rotlSH2 = (h, l, s) => h << s | l >>> 32 - s;
|
|
635
|
-
var rotlSL2 = (h, l, s) => l << s | h >>> 32 - s;
|
|
636
|
-
var rotlBH2 = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
637
|
-
var rotlBL2 = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
638
|
-
function add2(Ah, Al, Bh, Bl) {
|
|
639
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
640
|
-
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
641
|
-
}
|
|
642
|
-
exports.add = add2;
|
|
643
|
-
var add3L2 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
644
|
-
var add3H2 = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
645
|
-
var add4L2 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
646
|
-
var add4H2 = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
647
|
-
var add5L2 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
648
|
-
var add5H2 = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
649
|
-
var u642 = {
|
|
650
|
-
fromBig: fromBig2,
|
|
651
|
-
split: split2,
|
|
652
|
-
toBig: exports.toBig,
|
|
653
|
-
shrSH: shrSH2,
|
|
654
|
-
shrSL: shrSL2,
|
|
655
|
-
rotrSH: rotrSH2,
|
|
656
|
-
rotrSL: rotrSL2,
|
|
657
|
-
rotrBH: rotrBH2,
|
|
658
|
-
rotrBL: rotrBL2,
|
|
659
|
-
rotr32H: rotr32H2,
|
|
660
|
-
rotr32L: rotr32L2,
|
|
661
|
-
rotlSH: rotlSH2,
|
|
662
|
-
rotlSL: rotlSL2,
|
|
663
|
-
rotlBH: rotlBH2,
|
|
664
|
-
rotlBL: rotlBL2,
|
|
665
|
-
add: add2,
|
|
666
|
-
add3L: add3L2,
|
|
667
|
-
add3H: add3H2,
|
|
668
|
-
add4L: add4L2,
|
|
669
|
-
add4H: add4H2,
|
|
670
|
-
add5H: add5H2,
|
|
671
|
-
add5L: add5L2
|
|
672
|
-
};
|
|
673
|
-
exports.default = u642;
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// node_modules/@noble/hashes/cryptoBrowser.js
|
|
678
|
-
var require_cryptoBrowser = __commonJS({
|
|
679
|
-
"node_modules/@noble/hashes/cryptoBrowser.js"(exports) {
|
|
680
|
-
"use strict";
|
|
681
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
682
|
-
exports.crypto = void 0;
|
|
683
|
-
exports.crypto = {
|
|
684
|
-
node: void 0,
|
|
685
|
-
web: typeof self === "object" && "crypto" in self ? self.crypto : void 0
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
// node_modules/@noble/hashes/utils.js
|
|
691
|
-
var require_utils = __commonJS({
|
|
692
|
-
"node_modules/@noble/hashes/utils.js"(exports) {
|
|
693
|
-
"use strict";
|
|
694
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
695
|
-
exports.randomBytes = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.utf8ToBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
|
|
696
|
-
var crypto_1 = require_cryptoBrowser();
|
|
697
|
-
var u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
698
|
-
exports.u8 = u8;
|
|
699
|
-
var u322 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
700
|
-
exports.u32 = u322;
|
|
701
|
-
var createView2 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
702
|
-
exports.createView = createView2;
|
|
703
|
-
var rotr2 = (word, shift) => word << 32 - shift | word >>> shift;
|
|
704
|
-
exports.rotr = rotr2;
|
|
705
|
-
exports.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
706
|
-
if (!exports.isLE)
|
|
707
|
-
throw new Error("Non little-endian hardware is not supported");
|
|
708
|
-
var hexes3 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, "0"));
|
|
709
|
-
function bytesToHex2(uint8a) {
|
|
710
|
-
if (!(uint8a instanceof Uint8Array))
|
|
711
|
-
throw new Error("Uint8Array expected");
|
|
712
|
-
let hex = "";
|
|
713
|
-
for (let i = 0; i < uint8a.length; i++) {
|
|
714
|
-
hex += hexes3[uint8a[i]];
|
|
715
|
-
}
|
|
716
|
-
return hex;
|
|
717
|
-
}
|
|
718
|
-
exports.bytesToHex = bytesToHex2;
|
|
719
|
-
function hexToBytes3(hex) {
|
|
720
|
-
if (typeof hex !== "string") {
|
|
721
|
-
throw new TypeError("hexToBytes: expected string, got " + typeof hex);
|
|
722
|
-
}
|
|
723
|
-
if (hex.length % 2)
|
|
724
|
-
throw new Error("hexToBytes: received invalid unpadded hex");
|
|
725
|
-
const array = new Uint8Array(hex.length / 2);
|
|
726
|
-
for (let i = 0; i < array.length; i++) {
|
|
727
|
-
const j = i * 2;
|
|
728
|
-
const hexByte = hex.slice(j, j + 2);
|
|
729
|
-
const byte = Number.parseInt(hexByte, 16);
|
|
730
|
-
if (Number.isNaN(byte) || byte < 0)
|
|
731
|
-
throw new Error("Invalid byte sequence");
|
|
732
|
-
array[i] = byte;
|
|
733
|
-
}
|
|
734
|
-
return array;
|
|
735
|
-
}
|
|
736
|
-
exports.hexToBytes = hexToBytes3;
|
|
737
|
-
var nextTick = async () => {
|
|
738
|
-
};
|
|
739
|
-
exports.nextTick = nextTick;
|
|
740
|
-
async function asyncLoop(iters, tick, cb) {
|
|
741
|
-
let ts = Date.now();
|
|
742
|
-
for (let i = 0; i < iters; i++) {
|
|
743
|
-
cb(i);
|
|
744
|
-
const diff = Date.now() - ts;
|
|
745
|
-
if (diff >= 0 && diff < tick)
|
|
746
|
-
continue;
|
|
747
|
-
await (0, exports.nextTick)();
|
|
748
|
-
ts += diff;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
exports.asyncLoop = asyncLoop;
|
|
752
|
-
function utf8ToBytes3(str) {
|
|
753
|
-
if (typeof str !== "string") {
|
|
754
|
-
throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
|
|
755
|
-
}
|
|
756
|
-
return new TextEncoder().encode(str);
|
|
757
|
-
}
|
|
758
|
-
exports.utf8ToBytes = utf8ToBytes3;
|
|
759
|
-
function toBytes2(data) {
|
|
760
|
-
if (typeof data === "string")
|
|
761
|
-
data = utf8ToBytes3(data);
|
|
762
|
-
if (!(data instanceof Uint8Array))
|
|
763
|
-
throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
|
|
764
|
-
return data;
|
|
765
|
-
}
|
|
766
|
-
exports.toBytes = toBytes2;
|
|
767
|
-
function concatBytes3(...arrays) {
|
|
768
|
-
if (!arrays.every((a) => a instanceof Uint8Array))
|
|
769
|
-
throw new Error("Uint8Array list expected");
|
|
770
|
-
if (arrays.length === 1)
|
|
771
|
-
return arrays[0];
|
|
772
|
-
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
773
|
-
const result = new Uint8Array(length);
|
|
774
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
775
|
-
const arr = arrays[i];
|
|
776
|
-
result.set(arr, pad);
|
|
777
|
-
pad += arr.length;
|
|
778
|
-
}
|
|
779
|
-
return result;
|
|
780
|
-
}
|
|
781
|
-
exports.concatBytes = concatBytes3;
|
|
782
|
-
var Hash2 = class {
|
|
783
|
-
clone() {
|
|
784
|
-
return this._cloneInto();
|
|
785
|
-
}
|
|
786
|
-
};
|
|
787
|
-
exports.Hash = Hash2;
|
|
788
|
-
var isPlainObject = (obj) => Object.prototype.toString.call(obj) === "[object Object]" && obj.constructor === Object;
|
|
789
|
-
function checkOpts(defaults, opts) {
|
|
790
|
-
if (opts !== void 0 && (typeof opts !== "object" || !isPlainObject(opts)))
|
|
791
|
-
throw new TypeError("Options should be object or undefined");
|
|
792
|
-
const merged = Object.assign(defaults, opts);
|
|
793
|
-
return merged;
|
|
794
|
-
}
|
|
795
|
-
exports.checkOpts = checkOpts;
|
|
796
|
-
function wrapConstructor2(hashConstructor) {
|
|
797
|
-
const hashC = (message) => hashConstructor().update(toBytes2(message)).digest();
|
|
798
|
-
const tmp = hashConstructor();
|
|
799
|
-
hashC.outputLen = tmp.outputLen;
|
|
800
|
-
hashC.blockLen = tmp.blockLen;
|
|
801
|
-
hashC.create = () => hashConstructor();
|
|
802
|
-
return hashC;
|
|
803
|
-
}
|
|
804
|
-
exports.wrapConstructor = wrapConstructor2;
|
|
805
|
-
function wrapConstructorWithOpts2(hashCons) {
|
|
806
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes2(msg)).digest();
|
|
807
|
-
const tmp = hashCons({});
|
|
808
|
-
hashC.outputLen = tmp.outputLen;
|
|
809
|
-
hashC.blockLen = tmp.blockLen;
|
|
810
|
-
hashC.create = (opts) => hashCons(opts);
|
|
811
|
-
return hashC;
|
|
812
|
-
}
|
|
813
|
-
exports.wrapConstructorWithOpts = wrapConstructorWithOpts2;
|
|
814
|
-
function randomBytes2(bytesLength = 32) {
|
|
815
|
-
if (crypto_1.crypto.web) {
|
|
816
|
-
return crypto_1.crypto.web.getRandomValues(new Uint8Array(bytesLength));
|
|
817
|
-
} else if (crypto_1.crypto.node) {
|
|
818
|
-
return new Uint8Array(crypto_1.crypto.node.randomBytes(bytesLength).buffer);
|
|
819
|
-
} else {
|
|
820
|
-
throw new Error("The environment doesn't have randomBytes function");
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
exports.randomBytes = randomBytes2;
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
// node_modules/@noble/hashes/sha3.js
|
|
828
|
-
var require_sha3 = __commonJS({
|
|
829
|
-
"node_modules/@noble/hashes/sha3.js"(exports) {
|
|
830
|
-
"use strict";
|
|
831
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
832
|
-
exports.shake256 = exports.shake128 = exports.keccak_512 = exports.keccak_384 = exports.keccak_256 = exports.keccak_224 = exports.sha3_512 = exports.sha3_384 = exports.sha3_256 = exports.sha3_224 = exports.Keccak = exports.keccakP = void 0;
|
|
833
|
-
var _assert_js_1 = require_assert();
|
|
834
|
-
var _u64_js_1 = require_u64();
|
|
835
|
-
var utils_js_1 = require_utils();
|
|
836
|
-
var [SHA3_PI2, SHA3_ROTL2, _SHA3_IOTA2] = [[], [], []];
|
|
837
|
-
var _0n6 = BigInt(0);
|
|
838
|
-
var _1n6 = BigInt(1);
|
|
839
|
-
var _2n4 = BigInt(2);
|
|
840
|
-
var _7n2 = BigInt(7);
|
|
841
|
-
var _256n2 = BigInt(256);
|
|
842
|
-
var _0x71n2 = BigInt(113);
|
|
843
|
-
for (let round = 0, R = _1n6, x = 1, y = 0; round < 24; round++) {
|
|
844
|
-
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
845
|
-
SHA3_PI2.push(2 * (5 * y + x));
|
|
846
|
-
SHA3_ROTL2.push((round + 1) * (round + 2) / 2 % 64);
|
|
847
|
-
let t = _0n6;
|
|
848
|
-
for (let j = 0; j < 7; j++) {
|
|
849
|
-
R = (R << _1n6 ^ (R >> _7n2) * _0x71n2) % _256n2;
|
|
850
|
-
if (R & _2n4)
|
|
851
|
-
t ^= _1n6 << (_1n6 << BigInt(j)) - _1n6;
|
|
852
|
-
}
|
|
853
|
-
_SHA3_IOTA2.push(t);
|
|
854
|
-
}
|
|
855
|
-
var [SHA3_IOTA_H2, SHA3_IOTA_L2] = _u64_js_1.default.split(_SHA3_IOTA2, true);
|
|
856
|
-
var rotlH2 = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBH(h, l, s) : _u64_js_1.default.rotlSH(h, l, s);
|
|
857
|
-
var rotlL2 = (h, l, s) => s > 32 ? _u64_js_1.default.rotlBL(h, l, s) : _u64_js_1.default.rotlSL(h, l, s);
|
|
858
|
-
function keccakP2(s, rounds = 24) {
|
|
859
|
-
const B = new Uint32Array(5 * 2);
|
|
860
|
-
for (let round = 24 - rounds; round < 24; round++) {
|
|
861
|
-
for (let x = 0; x < 10; x++)
|
|
862
|
-
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
863
|
-
for (let x = 0; x < 10; x += 2) {
|
|
864
|
-
const idx1 = (x + 8) % 10;
|
|
865
|
-
const idx0 = (x + 2) % 10;
|
|
866
|
-
const B0 = B[idx0];
|
|
867
|
-
const B1 = B[idx0 + 1];
|
|
868
|
-
const Th = rotlH2(B0, B1, 1) ^ B[idx1];
|
|
869
|
-
const Tl = rotlL2(B0, B1, 1) ^ B[idx1 + 1];
|
|
870
|
-
for (let y = 0; y < 50; y += 10) {
|
|
871
|
-
s[x + y] ^= Th;
|
|
872
|
-
s[x + y + 1] ^= Tl;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
let curH = s[2];
|
|
876
|
-
let curL = s[3];
|
|
877
|
-
for (let t = 0; t < 24; t++) {
|
|
878
|
-
const shift = SHA3_ROTL2[t];
|
|
879
|
-
const Th = rotlH2(curH, curL, shift);
|
|
880
|
-
const Tl = rotlL2(curH, curL, shift);
|
|
881
|
-
const PI = SHA3_PI2[t];
|
|
882
|
-
curH = s[PI];
|
|
883
|
-
curL = s[PI + 1];
|
|
884
|
-
s[PI] = Th;
|
|
885
|
-
s[PI + 1] = Tl;
|
|
886
|
-
}
|
|
887
|
-
for (let y = 0; y < 50; y += 10) {
|
|
888
|
-
for (let x = 0; x < 10; x++)
|
|
889
|
-
B[x] = s[y + x];
|
|
890
|
-
for (let x = 0; x < 10; x++)
|
|
891
|
-
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
892
|
-
}
|
|
893
|
-
s[0] ^= SHA3_IOTA_H2[round];
|
|
894
|
-
s[1] ^= SHA3_IOTA_L2[round];
|
|
895
|
-
}
|
|
896
|
-
B.fill(0);
|
|
897
|
-
}
|
|
898
|
-
exports.keccakP = keccakP2;
|
|
899
|
-
var Keccak2 = class extends utils_js_1.Hash {
|
|
900
|
-
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
901
|
-
super();
|
|
902
|
-
this.blockLen = blockLen;
|
|
903
|
-
this.suffix = suffix;
|
|
904
|
-
this.outputLen = outputLen;
|
|
905
|
-
this.enableXOF = enableXOF;
|
|
906
|
-
this.rounds = rounds;
|
|
907
|
-
this.pos = 0;
|
|
908
|
-
this.posOut = 0;
|
|
909
|
-
this.finished = false;
|
|
910
|
-
this.destroyed = false;
|
|
911
|
-
_assert_js_1.default.number(outputLen);
|
|
912
|
-
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
913
|
-
throw new Error("Sha3 supports only keccak-f1600 function");
|
|
914
|
-
this.state = new Uint8Array(200);
|
|
915
|
-
this.state32 = (0, utils_js_1.u32)(this.state);
|
|
916
|
-
}
|
|
917
|
-
keccak() {
|
|
918
|
-
keccakP2(this.state32, this.rounds);
|
|
919
|
-
this.posOut = 0;
|
|
920
|
-
this.pos = 0;
|
|
921
|
-
}
|
|
922
|
-
update(data) {
|
|
923
|
-
_assert_js_1.default.exists(this);
|
|
924
|
-
const { blockLen, state } = this;
|
|
925
|
-
data = (0, utils_js_1.toBytes)(data);
|
|
926
|
-
const len = data.length;
|
|
927
|
-
for (let pos = 0; pos < len; ) {
|
|
928
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
929
|
-
for (let i = 0; i < take; i++)
|
|
930
|
-
state[this.pos++] ^= data[pos++];
|
|
931
|
-
if (this.pos === blockLen)
|
|
932
|
-
this.keccak();
|
|
933
|
-
}
|
|
934
|
-
return this;
|
|
935
|
-
}
|
|
936
|
-
finish() {
|
|
937
|
-
if (this.finished)
|
|
938
|
-
return;
|
|
939
|
-
this.finished = true;
|
|
940
|
-
const { state, suffix, pos, blockLen } = this;
|
|
941
|
-
state[pos] ^= suffix;
|
|
942
|
-
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
943
|
-
this.keccak();
|
|
944
|
-
state[blockLen - 1] ^= 128;
|
|
945
|
-
this.keccak();
|
|
946
|
-
}
|
|
947
|
-
writeInto(out) {
|
|
948
|
-
_assert_js_1.default.exists(this, false);
|
|
949
|
-
_assert_js_1.default.bytes(out);
|
|
950
|
-
this.finish();
|
|
951
|
-
const bufferOut = this.state;
|
|
952
|
-
const { blockLen } = this;
|
|
953
|
-
for (let pos = 0, len = out.length; pos < len; ) {
|
|
954
|
-
if (this.posOut >= blockLen)
|
|
955
|
-
this.keccak();
|
|
956
|
-
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
957
|
-
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
958
|
-
this.posOut += take;
|
|
959
|
-
pos += take;
|
|
960
|
-
}
|
|
961
|
-
return out;
|
|
962
|
-
}
|
|
963
|
-
xofInto(out) {
|
|
964
|
-
if (!this.enableXOF)
|
|
965
|
-
throw new Error("XOF is not possible for this instance");
|
|
966
|
-
return this.writeInto(out);
|
|
967
|
-
}
|
|
968
|
-
xof(bytes2) {
|
|
969
|
-
_assert_js_1.default.number(bytes2);
|
|
970
|
-
return this.xofInto(new Uint8Array(bytes2));
|
|
971
|
-
}
|
|
972
|
-
digestInto(out) {
|
|
973
|
-
_assert_js_1.default.output(out, this);
|
|
974
|
-
if (this.finished)
|
|
975
|
-
throw new Error("digest() was already called");
|
|
976
|
-
this.writeInto(out);
|
|
977
|
-
this.destroy();
|
|
978
|
-
return out;
|
|
979
|
-
}
|
|
980
|
-
digest() {
|
|
981
|
-
return this.digestInto(new Uint8Array(this.outputLen));
|
|
982
|
-
}
|
|
983
|
-
destroy() {
|
|
984
|
-
this.destroyed = true;
|
|
985
|
-
this.state.fill(0);
|
|
986
|
-
}
|
|
987
|
-
_cloneInto(to) {
|
|
988
|
-
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
989
|
-
to || (to = new Keccak2(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
990
|
-
to.state32.set(this.state32);
|
|
991
|
-
to.pos = this.pos;
|
|
992
|
-
to.posOut = this.posOut;
|
|
993
|
-
to.finished = this.finished;
|
|
994
|
-
to.rounds = rounds;
|
|
995
|
-
to.suffix = suffix;
|
|
996
|
-
to.outputLen = outputLen;
|
|
997
|
-
to.enableXOF = enableXOF;
|
|
998
|
-
to.destroyed = this.destroyed;
|
|
999
|
-
return to;
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
exports.Keccak = Keccak2;
|
|
1003
|
-
var gen2 = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapConstructor)(() => new Keccak2(blockLen, suffix, outputLen));
|
|
1004
|
-
exports.sha3_224 = gen2(6, 144, 224 / 8);
|
|
1005
|
-
exports.sha3_256 = gen2(6, 136, 256 / 8);
|
|
1006
|
-
exports.sha3_384 = gen2(6, 104, 384 / 8);
|
|
1007
|
-
exports.sha3_512 = gen2(6, 72, 512 / 8);
|
|
1008
|
-
exports.keccak_224 = gen2(1, 144, 224 / 8);
|
|
1009
|
-
exports.keccak_256 = gen2(1, 136, 256 / 8);
|
|
1010
|
-
exports.keccak_384 = gen2(1, 104, 384 / 8);
|
|
1011
|
-
exports.keccak_512 = gen2(1, 72, 512 / 8);
|
|
1012
|
-
var genShake2 = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapConstructorWithOpts)((opts = {}) => new Keccak2(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
|
|
1013
|
-
exports.shake128 = genShake2(31, 168, 128 / 8);
|
|
1014
|
-
exports.shake256 = genShake2(31, 136, 256 / 8);
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
|
-
|
|
1018
|
-
// node_modules/ethereum-cryptography/utils.js
|
|
1019
|
-
var require_utils2 = __commonJS({
|
|
1020
|
-
"node_modules/ethereum-cryptography/utils.js"(exports, module) {
|
|
1021
|
-
"use strict";
|
|
1022
|
-
var __importDefault = exports && exports.__importDefault || function(mod2) {
|
|
1023
|
-
return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
|
|
1024
|
-
};
|
|
1025
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1026
|
-
exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = void 0;
|
|
1027
|
-
var _assert_1 = __importDefault(require_assert());
|
|
1028
|
-
var utils_1 = require_utils();
|
|
1029
|
-
var assertBool = _assert_1.default.bool;
|
|
1030
|
-
exports.assertBool = assertBool;
|
|
1031
|
-
var assertBytes = _assert_1.default.bytes;
|
|
1032
|
-
exports.assertBytes = assertBytes;
|
|
1033
|
-
var utils_2 = require_utils();
|
|
1034
|
-
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function() {
|
|
1035
|
-
return utils_2.bytesToHex;
|
|
1036
|
-
} });
|
|
1037
|
-
Object.defineProperty(exports, "toHex", { enumerable: true, get: function() {
|
|
1038
|
-
return utils_2.bytesToHex;
|
|
1039
|
-
} });
|
|
1040
|
-
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function() {
|
|
1041
|
-
return utils_2.concatBytes;
|
|
1042
|
-
} });
|
|
1043
|
-
Object.defineProperty(exports, "createView", { enumerable: true, get: function() {
|
|
1044
|
-
return utils_2.createView;
|
|
1045
|
-
} });
|
|
1046
|
-
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function() {
|
|
1047
|
-
return utils_2.utf8ToBytes;
|
|
1048
|
-
} });
|
|
1049
|
-
function bytesToUtf8(data) {
|
|
1050
|
-
if (!(data instanceof Uint8Array)) {
|
|
1051
|
-
throw new TypeError(`bytesToUtf8 expected Uint8Array, got ${typeof data}`);
|
|
1052
|
-
}
|
|
1053
|
-
return new TextDecoder().decode(data);
|
|
1054
|
-
}
|
|
1055
|
-
exports.bytesToUtf8 = bytesToUtf8;
|
|
1056
|
-
function hexToBytes3(data) {
|
|
1057
|
-
const sliced = data.startsWith("0x") ? data.substring(2) : data;
|
|
1058
|
-
return (0, utils_1.hexToBytes)(sliced);
|
|
1059
|
-
}
|
|
1060
|
-
exports.hexToBytes = hexToBytes3;
|
|
1061
|
-
function equalsBytes(a, b) {
|
|
1062
|
-
if (a.length !== b.length) {
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
1065
|
-
for (let i = 0; i < a.length; i++) {
|
|
1066
|
-
if (a[i] !== b[i]) {
|
|
1067
|
-
return false;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
return true;
|
|
1071
|
-
}
|
|
1072
|
-
exports.equalsBytes = equalsBytes;
|
|
1073
|
-
function wrapHash(hash2) {
|
|
1074
|
-
return (msg) => {
|
|
1075
|
-
_assert_1.default.bytes(msg);
|
|
1076
|
-
return hash2(msg);
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
exports.wrapHash = wrapHash;
|
|
1080
|
-
exports.crypto = (() => {
|
|
1081
|
-
const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : void 0;
|
|
1082
|
-
const nodeRequire = typeof module !== "undefined" && typeof module.require === "function" && module.require.bind(module);
|
|
1083
|
-
return {
|
|
1084
|
-
node: nodeRequire && !webCrypto ? nodeRequire("crypto") : void 0,
|
|
1085
|
-
web: webCrypto
|
|
1086
|
-
};
|
|
1087
|
-
})();
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
// node_modules/ethereum-cryptography/keccak.js
|
|
1092
|
-
var require_keccak = __commonJS({
|
|
1093
|
-
"node_modules/ethereum-cryptography/keccak.js"(exports) {
|
|
1094
|
-
"use strict";
|
|
1095
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1096
|
-
exports.keccak512 = exports.keccak384 = exports.keccak256 = exports.keccak224 = void 0;
|
|
1097
|
-
var sha3_1 = require_sha3();
|
|
1098
|
-
var utils_1 = require_utils2();
|
|
1099
|
-
exports.keccak224 = (0, utils_1.wrapHash)(sha3_1.keccak_224);
|
|
1100
|
-
exports.keccak256 = (() => {
|
|
1101
|
-
const k = (0, utils_1.wrapHash)(sha3_1.keccak_256);
|
|
1102
|
-
k.create = sha3_1.keccak_256.create;
|
|
1103
|
-
return k;
|
|
1104
|
-
})();
|
|
1105
|
-
exports.keccak384 = (0, utils_1.wrapHash)(sha3_1.keccak_384);
|
|
1106
|
-
exports.keccak512 = (0, utils_1.wrapHash)(sha3_1.keccak_512);
|
|
1107
|
-
}
|
|
1108
|
-
});
|
|
1109
|
-
|
|
1110
|
-
// node_modules/json-keys-sort/index.js
|
|
1111
|
-
var require_json_keys_sort = __commonJS({
|
|
1112
|
-
"node_modules/json-keys-sort/index.js"(exports) {
|
|
1113
|
-
var typeOf = function(data) {
|
|
1114
|
-
const objectConstructor = {}.constructor;
|
|
1115
|
-
const arrayConstructor = [].constructor;
|
|
1116
|
-
const stringConstructor = "test".constructor;
|
|
1117
|
-
if (data && data !== null && data.constructor === objectConstructor) {
|
|
1118
|
-
return "OBJECT";
|
|
1119
|
-
} else if (data && data !== null && data.constructor === arrayConstructor) {
|
|
1120
|
-
return "ARRAY";
|
|
1121
|
-
} else if (data && data !== null && data.constructor === stringConstructor) {
|
|
1122
|
-
return "STRING";
|
|
1123
|
-
} else {
|
|
1124
|
-
return "";
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
function jsonSort(data, sort2) {
|
|
1128
|
-
if (typeOf(data) === "ARRAY") {
|
|
1129
|
-
let newData = [];
|
|
1130
|
-
for (let w = 0; w < data.length; w++) {
|
|
1131
|
-
let d = data[w];
|
|
1132
|
-
if (typeOf(d) === "OBJECT" || typeOf(d) === "ARRAY")
|
|
1133
|
-
newData.push(jsonSort(d, sort2));
|
|
1134
|
-
else {
|
|
1135
|
-
newData.push(d);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
return newData;
|
|
1139
|
-
} else if (typeOf(data) === "OBJECT") {
|
|
1140
|
-
let newKeys = [], keys, newData = {};
|
|
1141
|
-
if (sort2 === void 0)
|
|
1142
|
-
sort2 = true;
|
|
1143
|
-
keys = Object.keys(data).sort();
|
|
1144
|
-
if (!sort2) {
|
|
1145
|
-
for (let i = keys.length - 1; i >= 0; i--)
|
|
1146
|
-
newKeys.push(keys[i]);
|
|
1147
|
-
keys = newKeys;
|
|
1148
|
-
}
|
|
1149
|
-
for (let j = 0; j < keys.length; j++) {
|
|
1150
|
-
let key = keys[j];
|
|
1151
|
-
if (typeOf(data[key]) === "OBJECT")
|
|
1152
|
-
newData[key] = jsonSort(data[key], sort2);
|
|
1153
|
-
else if (typeOf(data[key]) === "ARRAY") {
|
|
1154
|
-
newData[key] = [];
|
|
1155
|
-
for (let k = 0; k < data[key].length; k++) {
|
|
1156
|
-
let d = data[key][k];
|
|
1157
|
-
if (typeOf(d) === "OBJECT" || typeOf(d) === "ARRAY")
|
|
1158
|
-
newData[key].push(jsonSort(data[key][k], sort2));
|
|
1159
|
-
else
|
|
1160
|
-
newData[key].push(data[key][k]);
|
|
1161
|
-
}
|
|
1162
|
-
} else
|
|
1163
|
-
newData[key] = data[key];
|
|
1164
|
-
}
|
|
1165
|
-
return newData;
|
|
1166
|
-
} else
|
|
1167
|
-
throw new Error("must be an object/array");
|
|
1168
|
-
}
|
|
1169
|
-
async function jsonSortAsync(data, sort2) {
|
|
1170
|
-
return new Promise((resolve, reject) => {
|
|
1171
|
-
try {
|
|
1172
|
-
const response = jsonSort(data, sort2);
|
|
1173
|
-
resolve(response);
|
|
1174
|
-
} catch (e) {
|
|
1175
|
-
reject(e);
|
|
1176
|
-
}
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
exports.sort = jsonSort;
|
|
1180
|
-
exports.sortAsync = jsonSortAsync;
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
|
|
1184
|
-
// node_modules/bignumber.js/bignumber.js
|
|
1185
|
-
var require_bignumber = __commonJS({
|
|
1186
|
-
"node_modules/bignumber.js/bignumber.js"(exports, module) {
|
|
1187
|
-
(function(globalObject) {
|
|
1188
|
-
"use strict";
|
|
1189
|
-
var BigNumber, isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, mathceil = Math.ceil, mathfloor = Math.floor, bignumberError = "[BigNumber Error] ", tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ", BASE = 1e14, LOG_BASE = 14, MAX_SAFE_INTEGER = 9007199254740991, POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13], SQRT_BASE = 1e7, MAX = 1e9;
|
|
1190
|
-
function clone(configObject) {
|
|
1191
|
-
var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
1192
|
-
prefix: "",
|
|
1193
|
-
groupSize: 3,
|
|
1194
|
-
secondaryGroupSize: 0,
|
|
1195
|
-
groupSeparator: ",",
|
|
1196
|
-
decimalSeparator: ".",
|
|
1197
|
-
fractionGroupSize: 0,
|
|
1198
|
-
fractionGroupSeparator: "\xA0",
|
|
1199
|
-
suffix: ""
|
|
1200
|
-
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
1201
|
-
function BigNumber2(v, b) {
|
|
1202
|
-
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
1203
|
-
if (!(x instanceof BigNumber2))
|
|
1204
|
-
return new BigNumber2(v, b);
|
|
1205
|
-
if (b == null) {
|
|
1206
|
-
if (v && v._isBigNumber === true) {
|
|
1207
|
-
x.s = v.s;
|
|
1208
|
-
if (!v.c || v.e > MAX_EXP) {
|
|
1209
|
-
x.c = x.e = null;
|
|
1210
|
-
} else if (v.e < MIN_EXP) {
|
|
1211
|
-
x.c = [x.e = 0];
|
|
1212
|
-
} else {
|
|
1213
|
-
x.e = v.e;
|
|
1214
|
-
x.c = v.c.slice();
|
|
1215
|
-
}
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
1219
|
-
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
1220
|
-
if (v === ~~v) {
|
|
1221
|
-
for (e = 0, i = v; i >= 10; i /= 10, e++)
|
|
1222
|
-
;
|
|
1223
|
-
if (e > MAX_EXP) {
|
|
1224
|
-
x.c = x.e = null;
|
|
1225
|
-
} else {
|
|
1226
|
-
x.e = e;
|
|
1227
|
-
x.c = [v];
|
|
1228
|
-
}
|
|
1229
|
-
return;
|
|
1230
|
-
}
|
|
1231
|
-
str = String(v);
|
|
1232
|
-
} else {
|
|
1233
|
-
if (!isNumeric.test(str = String(v)))
|
|
1234
|
-
return parseNumeric(x, str, isNum);
|
|
1235
|
-
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
1236
|
-
}
|
|
1237
|
-
if ((e = str.indexOf(".")) > -1)
|
|
1238
|
-
str = str.replace(".", "");
|
|
1239
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
1240
|
-
if (e < 0)
|
|
1241
|
-
e = i;
|
|
1242
|
-
e += +str.slice(i + 1);
|
|
1243
|
-
str = str.substring(0, i);
|
|
1244
|
-
} else if (e < 0) {
|
|
1245
|
-
e = str.length;
|
|
1246
|
-
}
|
|
1247
|
-
} else {
|
|
1248
|
-
intCheck(b, 2, ALPHABET.length, "Base");
|
|
1249
|
-
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
1250
|
-
x = new BigNumber2(v);
|
|
1251
|
-
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
1252
|
-
}
|
|
1253
|
-
str = String(v);
|
|
1254
|
-
if (isNum = typeof v == "number") {
|
|
1255
|
-
if (v * 0 != 0)
|
|
1256
|
-
return parseNumeric(x, str, isNum, b);
|
|
1257
|
-
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
1258
|
-
if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
|
|
1259
|
-
throw Error(tooManyDigits + v);
|
|
1260
|
-
}
|
|
1261
|
-
} else {
|
|
1262
|
-
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
1263
|
-
}
|
|
1264
|
-
alphabet = ALPHABET.slice(0, b);
|
|
1265
|
-
e = i = 0;
|
|
1266
|
-
for (len = str.length; i < len; i++) {
|
|
1267
|
-
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
1268
|
-
if (c == ".") {
|
|
1269
|
-
if (i > e) {
|
|
1270
|
-
e = len;
|
|
1271
|
-
continue;
|
|
1272
|
-
}
|
|
1273
|
-
} else if (!caseChanged) {
|
|
1274
|
-
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
1275
|
-
caseChanged = true;
|
|
1276
|
-
i = -1;
|
|
1277
|
-
e = 0;
|
|
1278
|
-
continue;
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
return parseNumeric(x, String(v), isNum, b);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
isNum = false;
|
|
1285
|
-
str = convertBase(str, b, 10, x.s);
|
|
1286
|
-
if ((e = str.indexOf(".")) > -1)
|
|
1287
|
-
str = str.replace(".", "");
|
|
1288
|
-
else
|
|
1289
|
-
e = str.length;
|
|
1290
|
-
}
|
|
1291
|
-
for (i = 0; str.charCodeAt(i) === 48; i++)
|
|
1292
|
-
;
|
|
1293
|
-
for (len = str.length; str.charCodeAt(--len) === 48; )
|
|
1294
|
-
;
|
|
1295
|
-
if (str = str.slice(i, ++len)) {
|
|
1296
|
-
len -= i;
|
|
1297
|
-
if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
1298
|
-
throw Error(tooManyDigits + x.s * v);
|
|
1299
|
-
}
|
|
1300
|
-
if ((e = e - i - 1) > MAX_EXP) {
|
|
1301
|
-
x.c = x.e = null;
|
|
1302
|
-
} else if (e < MIN_EXP) {
|
|
1303
|
-
x.c = [x.e = 0];
|
|
1304
|
-
} else {
|
|
1305
|
-
x.e = e;
|
|
1306
|
-
x.c = [];
|
|
1307
|
-
i = (e + 1) % LOG_BASE;
|
|
1308
|
-
if (e < 0)
|
|
1309
|
-
i += LOG_BASE;
|
|
1310
|
-
if (i < len) {
|
|
1311
|
-
if (i)
|
|
1312
|
-
x.c.push(+str.slice(0, i));
|
|
1313
|
-
for (len -= LOG_BASE; i < len; ) {
|
|
1314
|
-
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
1315
|
-
}
|
|
1316
|
-
i = LOG_BASE - (str = str.slice(i)).length;
|
|
1317
|
-
} else {
|
|
1318
|
-
i -= len;
|
|
1319
|
-
}
|
|
1320
|
-
for (; i--; str += "0")
|
|
1321
|
-
;
|
|
1322
|
-
x.c.push(+str);
|
|
1323
|
-
}
|
|
1324
|
-
} else {
|
|
1325
|
-
x.c = [x.e = 0];
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
BigNumber2.clone = clone;
|
|
1329
|
-
BigNumber2.ROUND_UP = 0;
|
|
1330
|
-
BigNumber2.ROUND_DOWN = 1;
|
|
1331
|
-
BigNumber2.ROUND_CEIL = 2;
|
|
1332
|
-
BigNumber2.ROUND_FLOOR = 3;
|
|
1333
|
-
BigNumber2.ROUND_HALF_UP = 4;
|
|
1334
|
-
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
1335
|
-
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
1336
|
-
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
1337
|
-
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
1338
|
-
BigNumber2.EUCLID = 9;
|
|
1339
|
-
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
1340
|
-
var p, v;
|
|
1341
|
-
if (obj != null) {
|
|
1342
|
-
if (typeof obj == "object") {
|
|
1343
|
-
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
1344
|
-
v = obj[p];
|
|
1345
|
-
intCheck(v, 0, MAX, p);
|
|
1346
|
-
DECIMAL_PLACES = v;
|
|
1347
|
-
}
|
|
1348
|
-
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
1349
|
-
v = obj[p];
|
|
1350
|
-
intCheck(v, 0, 8, p);
|
|
1351
|
-
ROUNDING_MODE = v;
|
|
1352
|
-
}
|
|
1353
|
-
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
1354
|
-
v = obj[p];
|
|
1355
|
-
if (v && v.pop) {
|
|
1356
|
-
intCheck(v[0], -MAX, 0, p);
|
|
1357
|
-
intCheck(v[1], 0, MAX, p);
|
|
1358
|
-
TO_EXP_NEG = v[0];
|
|
1359
|
-
TO_EXP_POS = v[1];
|
|
1360
|
-
} else {
|
|
1361
|
-
intCheck(v, -MAX, MAX, p);
|
|
1362
|
-
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
1366
|
-
v = obj[p];
|
|
1367
|
-
if (v && v.pop) {
|
|
1368
|
-
intCheck(v[0], -MAX, -1, p);
|
|
1369
|
-
intCheck(v[1], 1, MAX, p);
|
|
1370
|
-
MIN_EXP = v[0];
|
|
1371
|
-
MAX_EXP = v[1];
|
|
1372
|
-
} else {
|
|
1373
|
-
intCheck(v, -MAX, MAX, p);
|
|
1374
|
-
if (v) {
|
|
1375
|
-
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
1376
|
-
} else {
|
|
1377
|
-
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
1382
|
-
v = obj[p];
|
|
1383
|
-
if (v === !!v) {
|
|
1384
|
-
if (v) {
|
|
1385
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
1386
|
-
CRYPTO = v;
|
|
1387
|
-
} else {
|
|
1388
|
-
CRYPTO = !v;
|
|
1389
|
-
throw Error(bignumberError + "crypto unavailable");
|
|
1390
|
-
}
|
|
1391
|
-
} else {
|
|
1392
|
-
CRYPTO = v;
|
|
1393
|
-
}
|
|
1394
|
-
} else {
|
|
1395
|
-
throw Error(bignumberError + p + " not true or false: " + v);
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
1399
|
-
v = obj[p];
|
|
1400
|
-
intCheck(v, 0, 9, p);
|
|
1401
|
-
MODULO_MODE = v;
|
|
1402
|
-
}
|
|
1403
|
-
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
1404
|
-
v = obj[p];
|
|
1405
|
-
intCheck(v, 0, MAX, p);
|
|
1406
|
-
POW_PRECISION = v;
|
|
1407
|
-
}
|
|
1408
|
-
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
1409
|
-
v = obj[p];
|
|
1410
|
-
if (typeof v == "object")
|
|
1411
|
-
FORMAT = v;
|
|
1412
|
-
else
|
|
1413
|
-
throw Error(bignumberError + p + " not an object: " + v);
|
|
1414
|
-
}
|
|
1415
|
-
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
1416
|
-
v = obj[p];
|
|
1417
|
-
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
1418
|
-
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
1419
|
-
ALPHABET = v;
|
|
1420
|
-
} else {
|
|
1421
|
-
throw Error(bignumberError + p + " invalid: " + v);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
} else {
|
|
1425
|
-
throw Error(bignumberError + "Object expected: " + obj);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
return {
|
|
1429
|
-
DECIMAL_PLACES,
|
|
1430
|
-
ROUNDING_MODE,
|
|
1431
|
-
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
1432
|
-
RANGE: [MIN_EXP, MAX_EXP],
|
|
1433
|
-
CRYPTO,
|
|
1434
|
-
MODULO_MODE,
|
|
1435
|
-
POW_PRECISION,
|
|
1436
|
-
FORMAT,
|
|
1437
|
-
ALPHABET
|
|
1438
|
-
};
|
|
1439
|
-
};
|
|
1440
|
-
BigNumber2.isBigNumber = function(v) {
|
|
1441
|
-
if (!v || v._isBigNumber !== true)
|
|
1442
|
-
return false;
|
|
1443
|
-
if (!BigNumber2.DEBUG)
|
|
1444
|
-
return true;
|
|
1445
|
-
var i, n, c = v.c, e = v.e, s = v.s;
|
|
1446
|
-
out:
|
|
1447
|
-
if ({}.toString.call(c) == "[object Array]") {
|
|
1448
|
-
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
1449
|
-
if (c[0] === 0) {
|
|
1450
|
-
if (e === 0 && c.length === 1)
|
|
1451
|
-
return true;
|
|
1452
|
-
break out;
|
|
1453
|
-
}
|
|
1454
|
-
i = (e + 1) % LOG_BASE;
|
|
1455
|
-
if (i < 1)
|
|
1456
|
-
i += LOG_BASE;
|
|
1457
|
-
if (String(c[0]).length == i) {
|
|
1458
|
-
for (i = 0; i < c.length; i++) {
|
|
1459
|
-
n = c[i];
|
|
1460
|
-
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
1461
|
-
break out;
|
|
1462
|
-
}
|
|
1463
|
-
if (n !== 0)
|
|
1464
|
-
return true;
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
1468
|
-
return true;
|
|
1469
|
-
}
|
|
1470
|
-
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
1471
|
-
};
|
|
1472
|
-
BigNumber2.maximum = BigNumber2.max = function() {
|
|
1473
|
-
return maxOrMin(arguments, P.lt);
|
|
1474
|
-
};
|
|
1475
|
-
BigNumber2.minimum = BigNumber2.min = function() {
|
|
1476
|
-
return maxOrMin(arguments, P.gt);
|
|
1477
|
-
};
|
|
1478
|
-
BigNumber2.random = function() {
|
|
1479
|
-
var pow2_53 = 9007199254740992;
|
|
1480
|
-
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
1481
|
-
return mathfloor(Math.random() * pow2_53);
|
|
1482
|
-
} : function() {
|
|
1483
|
-
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
1484
|
-
};
|
|
1485
|
-
return function(dp) {
|
|
1486
|
-
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
1487
|
-
if (dp == null)
|
|
1488
|
-
dp = DECIMAL_PLACES;
|
|
1489
|
-
else
|
|
1490
|
-
intCheck(dp, 0, MAX);
|
|
1491
|
-
k = mathceil(dp / LOG_BASE);
|
|
1492
|
-
if (CRYPTO) {
|
|
1493
|
-
if (crypto.getRandomValues) {
|
|
1494
|
-
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
1495
|
-
for (; i < k; ) {
|
|
1496
|
-
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
1497
|
-
if (v >= 9e15) {
|
|
1498
|
-
b = crypto.getRandomValues(new Uint32Array(2));
|
|
1499
|
-
a[i] = b[0];
|
|
1500
|
-
a[i + 1] = b[1];
|
|
1501
|
-
} else {
|
|
1502
|
-
c.push(v % 1e14);
|
|
1503
|
-
i += 2;
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
i = k / 2;
|
|
1507
|
-
} else if (crypto.randomBytes) {
|
|
1508
|
-
a = crypto.randomBytes(k *= 7);
|
|
1509
|
-
for (; i < k; ) {
|
|
1510
|
-
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
1511
|
-
if (v >= 9e15) {
|
|
1512
|
-
crypto.randomBytes(7).copy(a, i);
|
|
1513
|
-
} else {
|
|
1514
|
-
c.push(v % 1e14);
|
|
1515
|
-
i += 7;
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
i = k / 7;
|
|
1519
|
-
} else {
|
|
1520
|
-
CRYPTO = false;
|
|
1521
|
-
throw Error(bignumberError + "crypto unavailable");
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
if (!CRYPTO) {
|
|
1525
|
-
for (; i < k; ) {
|
|
1526
|
-
v = random53bitInt();
|
|
1527
|
-
if (v < 9e15)
|
|
1528
|
-
c[i++] = v % 1e14;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
k = c[--i];
|
|
1532
|
-
dp %= LOG_BASE;
|
|
1533
|
-
if (k && dp) {
|
|
1534
|
-
v = POWS_TEN[LOG_BASE - dp];
|
|
1535
|
-
c[i] = mathfloor(k / v) * v;
|
|
1536
|
-
}
|
|
1537
|
-
for (; c[i] === 0; c.pop(), i--)
|
|
1538
|
-
;
|
|
1539
|
-
if (i < 0) {
|
|
1540
|
-
c = [e = 0];
|
|
1541
|
-
} else {
|
|
1542
|
-
for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
1543
|
-
;
|
|
1544
|
-
for (i = 1, v = c[0]; v >= 10; v /= 10, i++)
|
|
1545
|
-
;
|
|
1546
|
-
if (i < LOG_BASE)
|
|
1547
|
-
e -= LOG_BASE - i;
|
|
1548
|
-
}
|
|
1549
|
-
rand.e = e;
|
|
1550
|
-
rand.c = c;
|
|
1551
|
-
return rand;
|
|
1552
|
-
};
|
|
1553
|
-
}();
|
|
1554
|
-
BigNumber2.sum = function() {
|
|
1555
|
-
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
1556
|
-
for (; i < args.length; )
|
|
1557
|
-
sum = sum.plus(args[i++]);
|
|
1558
|
-
return sum;
|
|
1559
|
-
};
|
|
1560
|
-
convertBase = function() {
|
|
1561
|
-
var decimal = "0123456789";
|
|
1562
|
-
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
1563
|
-
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
1564
|
-
for (; i < len; ) {
|
|
1565
|
-
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn)
|
|
1566
|
-
;
|
|
1567
|
-
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
1568
|
-
for (j = 0; j < arr.length; j++) {
|
|
1569
|
-
if (arr[j] > baseOut - 1) {
|
|
1570
|
-
if (arr[j + 1] == null)
|
|
1571
|
-
arr[j + 1] = 0;
|
|
1572
|
-
arr[j + 1] += arr[j] / baseOut | 0;
|
|
1573
|
-
arr[j] %= baseOut;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
}
|
|
1577
|
-
return arr.reverse();
|
|
1578
|
-
}
|
|
1579
|
-
return function(str, baseIn, baseOut, sign2, callerIsToString) {
|
|
1580
|
-
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
1581
|
-
if (i >= 0) {
|
|
1582
|
-
k = POW_PRECISION;
|
|
1583
|
-
POW_PRECISION = 0;
|
|
1584
|
-
str = str.replace(".", "");
|
|
1585
|
-
y = new BigNumber2(baseIn);
|
|
1586
|
-
x = y.pow(str.length - i);
|
|
1587
|
-
POW_PRECISION = k;
|
|
1588
|
-
y.c = toBaseOut(
|
|
1589
|
-
toFixedPoint(coeffToString(x.c), x.e, "0"),
|
|
1590
|
-
10,
|
|
1591
|
-
baseOut,
|
|
1592
|
-
decimal
|
|
1593
|
-
);
|
|
1594
|
-
y.e = y.c.length;
|
|
1595
|
-
}
|
|
1596
|
-
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
1597
|
-
e = k = xc.length;
|
|
1598
|
-
for (; xc[--k] == 0; xc.pop())
|
|
1599
|
-
;
|
|
1600
|
-
if (!xc[0])
|
|
1601
|
-
return alphabet.charAt(0);
|
|
1602
|
-
if (i < 0) {
|
|
1603
|
-
--e;
|
|
1604
|
-
} else {
|
|
1605
|
-
x.c = xc;
|
|
1606
|
-
x.e = e;
|
|
1607
|
-
x.s = sign2;
|
|
1608
|
-
x = div(x, y, dp, rm, baseOut);
|
|
1609
|
-
xc = x.c;
|
|
1610
|
-
r = x.r;
|
|
1611
|
-
e = x.e;
|
|
1612
|
-
}
|
|
1613
|
-
d = e + dp + 1;
|
|
1614
|
-
i = xc[d];
|
|
1615
|
-
k = baseOut / 2;
|
|
1616
|
-
r = r || d < 0 || xc[d + 1] != null;
|
|
1617
|
-
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
1618
|
-
if (d < 1 || !xc[0]) {
|
|
1619
|
-
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
1620
|
-
} else {
|
|
1621
|
-
xc.length = d;
|
|
1622
|
-
if (r) {
|
|
1623
|
-
for (--baseOut; ++xc[--d] > baseOut; ) {
|
|
1624
|
-
xc[d] = 0;
|
|
1625
|
-
if (!d) {
|
|
1626
|
-
++e;
|
|
1627
|
-
xc = [1].concat(xc);
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
for (k = xc.length; !xc[--k]; )
|
|
1632
|
-
;
|
|
1633
|
-
for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]))
|
|
1634
|
-
;
|
|
1635
|
-
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
1636
|
-
}
|
|
1637
|
-
return str;
|
|
1638
|
-
};
|
|
1639
|
-
}();
|
|
1640
|
-
div = function() {
|
|
1641
|
-
function multiply(x, k, base) {
|
|
1642
|
-
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
1643
|
-
for (x = x.slice(); i--; ) {
|
|
1644
|
-
xlo = x[i] % SQRT_BASE;
|
|
1645
|
-
xhi = x[i] / SQRT_BASE | 0;
|
|
1646
|
-
m = khi * xlo + xhi * klo;
|
|
1647
|
-
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
1648
|
-
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
1649
|
-
x[i] = temp % base;
|
|
1650
|
-
}
|
|
1651
|
-
if (carry)
|
|
1652
|
-
x = [carry].concat(x);
|
|
1653
|
-
return x;
|
|
1654
|
-
}
|
|
1655
|
-
function compare2(a, b, aL, bL) {
|
|
1656
|
-
var i, cmp;
|
|
1657
|
-
if (aL != bL) {
|
|
1658
|
-
cmp = aL > bL ? 1 : -1;
|
|
1659
|
-
} else {
|
|
1660
|
-
for (i = cmp = 0; i < aL; i++) {
|
|
1661
|
-
if (a[i] != b[i]) {
|
|
1662
|
-
cmp = a[i] > b[i] ? 1 : -1;
|
|
1663
|
-
break;
|
|
1664
|
-
}
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
return cmp;
|
|
1668
|
-
}
|
|
1669
|
-
function subtract(a, b, aL, base) {
|
|
1670
|
-
var i = 0;
|
|
1671
|
-
for (; aL--; ) {
|
|
1672
|
-
a[aL] -= i;
|
|
1673
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
1674
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
1675
|
-
}
|
|
1676
|
-
for (; !a[0] && a.length > 1; a.splice(0, 1))
|
|
1677
|
-
;
|
|
1678
|
-
}
|
|
1679
|
-
return function(x, y, dp, rm, base) {
|
|
1680
|
-
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
|
|
1681
|
-
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
1682
|
-
return new BigNumber2(
|
|
1683
|
-
!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
q = new BigNumber2(s);
|
|
1687
|
-
qc = q.c = [];
|
|
1688
|
-
e = x.e - y.e;
|
|
1689
|
-
s = dp + e + 1;
|
|
1690
|
-
if (!base) {
|
|
1691
|
-
base = BASE;
|
|
1692
|
-
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
1693
|
-
s = s / LOG_BASE | 0;
|
|
1694
|
-
}
|
|
1695
|
-
for (i = 0; yc[i] == (xc[i] || 0); i++)
|
|
1696
|
-
;
|
|
1697
|
-
if (yc[i] > (xc[i] || 0))
|
|
1698
|
-
e--;
|
|
1699
|
-
if (s < 0) {
|
|
1700
|
-
qc.push(1);
|
|
1701
|
-
more = true;
|
|
1702
|
-
} else {
|
|
1703
|
-
xL = xc.length;
|
|
1704
|
-
yL = yc.length;
|
|
1705
|
-
i = 0;
|
|
1706
|
-
s += 2;
|
|
1707
|
-
n = mathfloor(base / (yc[0] + 1));
|
|
1708
|
-
if (n > 1) {
|
|
1709
|
-
yc = multiply(yc, n, base);
|
|
1710
|
-
xc = multiply(xc, n, base);
|
|
1711
|
-
yL = yc.length;
|
|
1712
|
-
xL = xc.length;
|
|
1713
|
-
}
|
|
1714
|
-
xi = yL;
|
|
1715
|
-
rem = xc.slice(0, yL);
|
|
1716
|
-
remL = rem.length;
|
|
1717
|
-
for (; remL < yL; rem[remL++] = 0)
|
|
1718
|
-
;
|
|
1719
|
-
yz = yc.slice();
|
|
1720
|
-
yz = [0].concat(yz);
|
|
1721
|
-
yc0 = yc[0];
|
|
1722
|
-
if (yc[1] >= base / 2)
|
|
1723
|
-
yc0++;
|
|
1724
|
-
do {
|
|
1725
|
-
n = 0;
|
|
1726
|
-
cmp = compare2(yc, rem, yL, remL);
|
|
1727
|
-
if (cmp < 0) {
|
|
1728
|
-
rem0 = rem[0];
|
|
1729
|
-
if (yL != remL)
|
|
1730
|
-
rem0 = rem0 * base + (rem[1] || 0);
|
|
1731
|
-
n = mathfloor(rem0 / yc0);
|
|
1732
|
-
if (n > 1) {
|
|
1733
|
-
if (n >= base)
|
|
1734
|
-
n = base - 1;
|
|
1735
|
-
prod = multiply(yc, n, base);
|
|
1736
|
-
prodL = prod.length;
|
|
1737
|
-
remL = rem.length;
|
|
1738
|
-
while (compare2(prod, rem, prodL, remL) == 1) {
|
|
1739
|
-
n--;
|
|
1740
|
-
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
1741
|
-
prodL = prod.length;
|
|
1742
|
-
cmp = 1;
|
|
1743
|
-
}
|
|
1744
|
-
} else {
|
|
1745
|
-
if (n == 0) {
|
|
1746
|
-
cmp = n = 1;
|
|
1747
|
-
}
|
|
1748
|
-
prod = yc.slice();
|
|
1749
|
-
prodL = prod.length;
|
|
1750
|
-
}
|
|
1751
|
-
if (prodL < remL)
|
|
1752
|
-
prod = [0].concat(prod);
|
|
1753
|
-
subtract(rem, prod, remL, base);
|
|
1754
|
-
remL = rem.length;
|
|
1755
|
-
if (cmp == -1) {
|
|
1756
|
-
while (compare2(yc, rem, yL, remL) < 1) {
|
|
1757
|
-
n++;
|
|
1758
|
-
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
1759
|
-
remL = rem.length;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
} else if (cmp === 0) {
|
|
1763
|
-
n++;
|
|
1764
|
-
rem = [0];
|
|
1765
|
-
}
|
|
1766
|
-
qc[i++] = n;
|
|
1767
|
-
if (rem[0]) {
|
|
1768
|
-
rem[remL++] = xc[xi] || 0;
|
|
1769
|
-
} else {
|
|
1770
|
-
rem = [xc[xi]];
|
|
1771
|
-
remL = 1;
|
|
1772
|
-
}
|
|
1773
|
-
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
1774
|
-
more = rem[0] != null;
|
|
1775
|
-
if (!qc[0])
|
|
1776
|
-
qc.splice(0, 1);
|
|
1777
|
-
}
|
|
1778
|
-
if (base == BASE) {
|
|
1779
|
-
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++)
|
|
1780
|
-
;
|
|
1781
|
-
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
1782
|
-
} else {
|
|
1783
|
-
q.e = e;
|
|
1784
|
-
q.r = +more;
|
|
1785
|
-
}
|
|
1786
|
-
return q;
|
|
1787
|
-
};
|
|
1788
|
-
}();
|
|
1789
|
-
function format(n, i, rm, id) {
|
|
1790
|
-
var c0, e, ne, len, str;
|
|
1791
|
-
if (rm == null)
|
|
1792
|
-
rm = ROUNDING_MODE;
|
|
1793
|
-
else
|
|
1794
|
-
intCheck(rm, 0, 8);
|
|
1795
|
-
if (!n.c)
|
|
1796
|
-
return n.toString();
|
|
1797
|
-
c0 = n.c[0];
|
|
1798
|
-
ne = n.e;
|
|
1799
|
-
if (i == null) {
|
|
1800
|
-
str = coeffToString(n.c);
|
|
1801
|
-
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
1802
|
-
} else {
|
|
1803
|
-
n = round(new BigNumber2(n), i, rm);
|
|
1804
|
-
e = n.e;
|
|
1805
|
-
str = coeffToString(n.c);
|
|
1806
|
-
len = str.length;
|
|
1807
|
-
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
1808
|
-
for (; len < i; str += "0", len++)
|
|
1809
|
-
;
|
|
1810
|
-
str = toExponential(str, e);
|
|
1811
|
-
} else {
|
|
1812
|
-
i -= ne;
|
|
1813
|
-
str = toFixedPoint(str, e, "0");
|
|
1814
|
-
if (e + 1 > len) {
|
|
1815
|
-
if (--i > 0)
|
|
1816
|
-
for (str += "."; i--; str += "0")
|
|
1817
|
-
;
|
|
1818
|
-
} else {
|
|
1819
|
-
i += e - len;
|
|
1820
|
-
if (i > 0) {
|
|
1821
|
-
if (e + 1 == len)
|
|
1822
|
-
str += ".";
|
|
1823
|
-
for (; i--; str += "0")
|
|
1824
|
-
;
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
return n.s < 0 && c0 ? "-" + str : str;
|
|
1830
|
-
}
|
|
1831
|
-
function maxOrMin(args, method) {
|
|
1832
|
-
var n, i = 1, m = new BigNumber2(args[0]);
|
|
1833
|
-
for (; i < args.length; i++) {
|
|
1834
|
-
n = new BigNumber2(args[i]);
|
|
1835
|
-
if (!n.s) {
|
|
1836
|
-
m = n;
|
|
1837
|
-
break;
|
|
1838
|
-
} else if (method.call(m, n)) {
|
|
1839
|
-
m = n;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
return m;
|
|
1843
|
-
}
|
|
1844
|
-
function normalise(n, c, e) {
|
|
1845
|
-
var i = 1, j = c.length;
|
|
1846
|
-
for (; !c[--j]; c.pop())
|
|
1847
|
-
;
|
|
1848
|
-
for (j = c[0]; j >= 10; j /= 10, i++)
|
|
1849
|
-
;
|
|
1850
|
-
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
1851
|
-
n.c = n.e = null;
|
|
1852
|
-
} else if (e < MIN_EXP) {
|
|
1853
|
-
n.c = [n.e = 0];
|
|
1854
|
-
} else {
|
|
1855
|
-
n.e = e;
|
|
1856
|
-
n.c = c;
|
|
1857
|
-
}
|
|
1858
|
-
return n;
|
|
1859
|
-
}
|
|
1860
|
-
parseNumeric = function() {
|
|
1861
|
-
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
1862
|
-
return function(x, str, isNum, b) {
|
|
1863
|
-
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
1864
|
-
if (isInfinityOrNaN.test(s)) {
|
|
1865
|
-
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
1866
|
-
} else {
|
|
1867
|
-
if (!isNum) {
|
|
1868
|
-
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
1869
|
-
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
1870
|
-
return !b || b == base ? p1 : m;
|
|
1871
|
-
});
|
|
1872
|
-
if (b) {
|
|
1873
|
-
base = b;
|
|
1874
|
-
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
1875
|
-
}
|
|
1876
|
-
if (str != s)
|
|
1877
|
-
return new BigNumber2(s, base);
|
|
1878
|
-
}
|
|
1879
|
-
if (BigNumber2.DEBUG) {
|
|
1880
|
-
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
1881
|
-
}
|
|
1882
|
-
x.s = null;
|
|
1883
|
-
}
|
|
1884
|
-
x.c = x.e = null;
|
|
1885
|
-
};
|
|
1886
|
-
}();
|
|
1887
|
-
function round(x, sd, rm, r) {
|
|
1888
|
-
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
1889
|
-
if (xc) {
|
|
1890
|
-
out: {
|
|
1891
|
-
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++)
|
|
1892
|
-
;
|
|
1893
|
-
i = sd - d;
|
|
1894
|
-
if (i < 0) {
|
|
1895
|
-
i += LOG_BASE;
|
|
1896
|
-
j = sd;
|
|
1897
|
-
n = xc[ni = 0];
|
|
1898
|
-
rd = n / pows10[d - j - 1] % 10 | 0;
|
|
1899
|
-
} else {
|
|
1900
|
-
ni = mathceil((i + 1) / LOG_BASE);
|
|
1901
|
-
if (ni >= xc.length) {
|
|
1902
|
-
if (r) {
|
|
1903
|
-
for (; xc.length <= ni; xc.push(0))
|
|
1904
|
-
;
|
|
1905
|
-
n = rd = 0;
|
|
1906
|
-
d = 1;
|
|
1907
|
-
i %= LOG_BASE;
|
|
1908
|
-
j = i - LOG_BASE + 1;
|
|
1909
|
-
} else {
|
|
1910
|
-
break out;
|
|
1911
|
-
}
|
|
1912
|
-
} else {
|
|
1913
|
-
n = k = xc[ni];
|
|
1914
|
-
for (d = 1; k >= 10; k /= 10, d++)
|
|
1915
|
-
;
|
|
1916
|
-
i %= LOG_BASE;
|
|
1917
|
-
j = i - LOG_BASE + d;
|
|
1918
|
-
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
1922
|
-
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
1923
|
-
if (sd < 1 || !xc[0]) {
|
|
1924
|
-
xc.length = 0;
|
|
1925
|
-
if (r) {
|
|
1926
|
-
sd -= x.e + 1;
|
|
1927
|
-
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
1928
|
-
x.e = -sd || 0;
|
|
1929
|
-
} else {
|
|
1930
|
-
xc[0] = x.e = 0;
|
|
1931
|
-
}
|
|
1932
|
-
return x;
|
|
1933
|
-
}
|
|
1934
|
-
if (i == 0) {
|
|
1935
|
-
xc.length = ni;
|
|
1936
|
-
k = 1;
|
|
1937
|
-
ni--;
|
|
1938
|
-
} else {
|
|
1939
|
-
xc.length = ni + 1;
|
|
1940
|
-
k = pows10[LOG_BASE - i];
|
|
1941
|
-
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
1942
|
-
}
|
|
1943
|
-
if (r) {
|
|
1944
|
-
for (; ; ) {
|
|
1945
|
-
if (ni == 0) {
|
|
1946
|
-
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++)
|
|
1947
|
-
;
|
|
1948
|
-
j = xc[0] += k;
|
|
1949
|
-
for (k = 1; j >= 10; j /= 10, k++)
|
|
1950
|
-
;
|
|
1951
|
-
if (i != k) {
|
|
1952
|
-
x.e++;
|
|
1953
|
-
if (xc[0] == BASE)
|
|
1954
|
-
xc[0] = 1;
|
|
1955
|
-
}
|
|
1956
|
-
break;
|
|
1957
|
-
} else {
|
|
1958
|
-
xc[ni] += k;
|
|
1959
|
-
if (xc[ni] != BASE)
|
|
1960
|
-
break;
|
|
1961
|
-
xc[ni--] = 0;
|
|
1962
|
-
k = 1;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
for (i = xc.length; xc[--i] === 0; xc.pop())
|
|
1967
|
-
;
|
|
1968
|
-
}
|
|
1969
|
-
if (x.e > MAX_EXP) {
|
|
1970
|
-
x.c = x.e = null;
|
|
1971
|
-
} else if (x.e < MIN_EXP) {
|
|
1972
|
-
x.c = [x.e = 0];
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
return x;
|
|
1976
|
-
}
|
|
1977
|
-
function valueOf(n) {
|
|
1978
|
-
var str, e = n.e;
|
|
1979
|
-
if (e === null)
|
|
1980
|
-
return n.toString();
|
|
1981
|
-
str = coeffToString(n.c);
|
|
1982
|
-
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
1983
|
-
return n.s < 0 ? "-" + str : str;
|
|
1984
|
-
}
|
|
1985
|
-
P.absoluteValue = P.abs = function() {
|
|
1986
|
-
var x = new BigNumber2(this);
|
|
1987
|
-
if (x.s < 0)
|
|
1988
|
-
x.s = 1;
|
|
1989
|
-
return x;
|
|
1990
|
-
};
|
|
1991
|
-
P.comparedTo = function(y, b) {
|
|
1992
|
-
return compare(this, new BigNumber2(y, b));
|
|
1993
|
-
};
|
|
1994
|
-
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
1995
|
-
var c, n, v, x = this;
|
|
1996
|
-
if (dp != null) {
|
|
1997
|
-
intCheck(dp, 0, MAX);
|
|
1998
|
-
if (rm == null)
|
|
1999
|
-
rm = ROUNDING_MODE;
|
|
2000
|
-
else
|
|
2001
|
-
intCheck(rm, 0, 8);
|
|
2002
|
-
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
2003
|
-
}
|
|
2004
|
-
if (!(c = x.c))
|
|
2005
|
-
return null;
|
|
2006
|
-
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
2007
|
-
if (v = c[v])
|
|
2008
|
-
for (; v % 10 == 0; v /= 10, n--)
|
|
2009
|
-
;
|
|
2010
|
-
if (n < 0)
|
|
2011
|
-
n = 0;
|
|
2012
|
-
return n;
|
|
2013
|
-
};
|
|
2014
|
-
P.dividedBy = P.div = function(y, b) {
|
|
2015
|
-
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
2016
|
-
};
|
|
2017
|
-
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
2018
|
-
return div(this, new BigNumber2(y, b), 0, 1);
|
|
2019
|
-
};
|
|
2020
|
-
P.exponentiatedBy = P.pow = function(n, m) {
|
|
2021
|
-
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
2022
|
-
n = new BigNumber2(n);
|
|
2023
|
-
if (n.c && !n.isInteger()) {
|
|
2024
|
-
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
2025
|
-
}
|
|
2026
|
-
if (m != null)
|
|
2027
|
-
m = new BigNumber2(m);
|
|
2028
|
-
nIsBig = n.e > 14;
|
|
2029
|
-
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
2030
|
-
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
2031
|
-
return m ? y.mod(m) : y;
|
|
2032
|
-
}
|
|
2033
|
-
nIsNeg = n.s < 0;
|
|
2034
|
-
if (m) {
|
|
2035
|
-
if (m.c ? !m.c[0] : !m.s)
|
|
2036
|
-
return new BigNumber2(NaN);
|
|
2037
|
-
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
2038
|
-
if (isModExp)
|
|
2039
|
-
x = x.mod(m);
|
|
2040
|
-
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
|
2041
|
-
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
2042
|
-
if (x.e > -1)
|
|
2043
|
-
k = 1 / k;
|
|
2044
|
-
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
2045
|
-
} else if (POW_PRECISION) {
|
|
2046
|
-
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
2047
|
-
}
|
|
2048
|
-
if (nIsBig) {
|
|
2049
|
-
half = new BigNumber2(0.5);
|
|
2050
|
-
if (nIsNeg)
|
|
2051
|
-
n.s = 1;
|
|
2052
|
-
nIsOdd = isOdd(n);
|
|
2053
|
-
} else {
|
|
2054
|
-
i = Math.abs(+valueOf(n));
|
|
2055
|
-
nIsOdd = i % 2;
|
|
2056
|
-
}
|
|
2057
|
-
y = new BigNumber2(ONE);
|
|
2058
|
-
for (; ; ) {
|
|
2059
|
-
if (nIsOdd) {
|
|
2060
|
-
y = y.times(x);
|
|
2061
|
-
if (!y.c)
|
|
2062
|
-
break;
|
|
2063
|
-
if (k) {
|
|
2064
|
-
if (y.c.length > k)
|
|
2065
|
-
y.c.length = k;
|
|
2066
|
-
} else if (isModExp) {
|
|
2067
|
-
y = y.mod(m);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
if (i) {
|
|
2071
|
-
i = mathfloor(i / 2);
|
|
2072
|
-
if (i === 0)
|
|
2073
|
-
break;
|
|
2074
|
-
nIsOdd = i % 2;
|
|
2075
|
-
} else {
|
|
2076
|
-
n = n.times(half);
|
|
2077
|
-
round(n, n.e + 1, 1);
|
|
2078
|
-
if (n.e > 14) {
|
|
2079
|
-
nIsOdd = isOdd(n);
|
|
2080
|
-
} else {
|
|
2081
|
-
i = +valueOf(n);
|
|
2082
|
-
if (i === 0)
|
|
2083
|
-
break;
|
|
2084
|
-
nIsOdd = i % 2;
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
x = x.times(x);
|
|
2088
|
-
if (k) {
|
|
2089
|
-
if (x.c && x.c.length > k)
|
|
2090
|
-
x.c.length = k;
|
|
2091
|
-
} else if (isModExp) {
|
|
2092
|
-
x = x.mod(m);
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
if (isModExp)
|
|
2096
|
-
return y;
|
|
2097
|
-
if (nIsNeg)
|
|
2098
|
-
y = ONE.div(y);
|
|
2099
|
-
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
2100
|
-
};
|
|
2101
|
-
P.integerValue = function(rm) {
|
|
2102
|
-
var n = new BigNumber2(this);
|
|
2103
|
-
if (rm == null)
|
|
2104
|
-
rm = ROUNDING_MODE;
|
|
2105
|
-
else
|
|
2106
|
-
intCheck(rm, 0, 8);
|
|
2107
|
-
return round(n, n.e + 1, rm);
|
|
2108
|
-
};
|
|
2109
|
-
P.isEqualTo = P.eq = function(y, b) {
|
|
2110
|
-
return compare(this, new BigNumber2(y, b)) === 0;
|
|
2111
|
-
};
|
|
2112
|
-
P.isFinite = function() {
|
|
2113
|
-
return !!this.c;
|
|
2114
|
-
};
|
|
2115
|
-
P.isGreaterThan = P.gt = function(y, b) {
|
|
2116
|
-
return compare(this, new BigNumber2(y, b)) > 0;
|
|
2117
|
-
};
|
|
2118
|
-
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
2119
|
-
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
2120
|
-
};
|
|
2121
|
-
P.isInteger = function() {
|
|
2122
|
-
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
2123
|
-
};
|
|
2124
|
-
P.isLessThan = P.lt = function(y, b) {
|
|
2125
|
-
return compare(this, new BigNumber2(y, b)) < 0;
|
|
2126
|
-
};
|
|
2127
|
-
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
2128
|
-
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
2129
|
-
};
|
|
2130
|
-
P.isNaN = function() {
|
|
2131
|
-
return !this.s;
|
|
2132
|
-
};
|
|
2133
|
-
P.isNegative = function() {
|
|
2134
|
-
return this.s < 0;
|
|
2135
|
-
};
|
|
2136
|
-
P.isPositive = function() {
|
|
2137
|
-
return this.s > 0;
|
|
2138
|
-
};
|
|
2139
|
-
P.isZero = function() {
|
|
2140
|
-
return !!this.c && this.c[0] == 0;
|
|
2141
|
-
};
|
|
2142
|
-
P.minus = function(y, b) {
|
|
2143
|
-
var i, j, t, xLTy, x = this, a = x.s;
|
|
2144
|
-
y = new BigNumber2(y, b);
|
|
2145
|
-
b = y.s;
|
|
2146
|
-
if (!a || !b)
|
|
2147
|
-
return new BigNumber2(NaN);
|
|
2148
|
-
if (a != b) {
|
|
2149
|
-
y.s = -b;
|
|
2150
|
-
return x.plus(y);
|
|
2151
|
-
}
|
|
2152
|
-
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
2153
|
-
if (!xe || !ye) {
|
|
2154
|
-
if (!xc || !yc)
|
|
2155
|
-
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
2156
|
-
if (!xc[0] || !yc[0]) {
|
|
2157
|
-
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
xe = bitFloor(xe);
|
|
2161
|
-
ye = bitFloor(ye);
|
|
2162
|
-
xc = xc.slice();
|
|
2163
|
-
if (a = xe - ye) {
|
|
2164
|
-
if (xLTy = a < 0) {
|
|
2165
|
-
a = -a;
|
|
2166
|
-
t = xc;
|
|
2167
|
-
} else {
|
|
2168
|
-
ye = xe;
|
|
2169
|
-
t = yc;
|
|
2170
|
-
}
|
|
2171
|
-
t.reverse();
|
|
2172
|
-
for (b = a; b--; t.push(0))
|
|
2173
|
-
;
|
|
2174
|
-
t.reverse();
|
|
2175
|
-
} else {
|
|
2176
|
-
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
2177
|
-
for (a = b = 0; b < j; b++) {
|
|
2178
|
-
if (xc[b] != yc[b]) {
|
|
2179
|
-
xLTy = xc[b] < yc[b];
|
|
2180
|
-
break;
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
if (xLTy) {
|
|
2185
|
-
t = xc;
|
|
2186
|
-
xc = yc;
|
|
2187
|
-
yc = t;
|
|
2188
|
-
y.s = -y.s;
|
|
2189
|
-
}
|
|
2190
|
-
b = (j = yc.length) - (i = xc.length);
|
|
2191
|
-
if (b > 0)
|
|
2192
|
-
for (; b--; xc[i++] = 0)
|
|
2193
|
-
;
|
|
2194
|
-
b = BASE - 1;
|
|
2195
|
-
for (; j > a; ) {
|
|
2196
|
-
if (xc[--j] < yc[j]) {
|
|
2197
|
-
for (i = j; i && !xc[--i]; xc[i] = b)
|
|
2198
|
-
;
|
|
2199
|
-
--xc[i];
|
|
2200
|
-
xc[j] += BASE;
|
|
2201
|
-
}
|
|
2202
|
-
xc[j] -= yc[j];
|
|
2203
|
-
}
|
|
2204
|
-
for (; xc[0] == 0; xc.splice(0, 1), --ye)
|
|
2205
|
-
;
|
|
2206
|
-
if (!xc[0]) {
|
|
2207
|
-
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
2208
|
-
y.c = [y.e = 0];
|
|
2209
|
-
return y;
|
|
2210
|
-
}
|
|
2211
|
-
return normalise(y, xc, ye);
|
|
2212
|
-
};
|
|
2213
|
-
P.modulo = P.mod = function(y, b) {
|
|
2214
|
-
var q, s, x = this;
|
|
2215
|
-
y = new BigNumber2(y, b);
|
|
2216
|
-
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
2217
|
-
return new BigNumber2(NaN);
|
|
2218
|
-
} else if (!y.c || x.c && !x.c[0]) {
|
|
2219
|
-
return new BigNumber2(x);
|
|
2220
|
-
}
|
|
2221
|
-
if (MODULO_MODE == 9) {
|
|
2222
|
-
s = y.s;
|
|
2223
|
-
y.s = 1;
|
|
2224
|
-
q = div(x, y, 0, 3);
|
|
2225
|
-
y.s = s;
|
|
2226
|
-
q.s *= s;
|
|
2227
|
-
} else {
|
|
2228
|
-
q = div(x, y, 0, MODULO_MODE);
|
|
2229
|
-
}
|
|
2230
|
-
y = x.minus(q.times(y));
|
|
2231
|
-
if (!y.c[0] && MODULO_MODE == 1)
|
|
2232
|
-
y.s = x.s;
|
|
2233
|
-
return y;
|
|
2234
|
-
};
|
|
2235
|
-
P.multipliedBy = P.times = function(y, b) {
|
|
2236
|
-
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
|
|
2237
|
-
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
2238
|
-
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
2239
|
-
y.c = y.e = y.s = null;
|
|
2240
|
-
} else {
|
|
2241
|
-
y.s *= x.s;
|
|
2242
|
-
if (!xc || !yc) {
|
|
2243
|
-
y.c = y.e = null;
|
|
2244
|
-
} else {
|
|
2245
|
-
y.c = [0];
|
|
2246
|
-
y.e = 0;
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
return y;
|
|
2250
|
-
}
|
|
2251
|
-
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
2252
|
-
y.s *= x.s;
|
|
2253
|
-
xcL = xc.length;
|
|
2254
|
-
ycL = yc.length;
|
|
2255
|
-
if (xcL < ycL) {
|
|
2256
|
-
zc = xc;
|
|
2257
|
-
xc = yc;
|
|
2258
|
-
yc = zc;
|
|
2259
|
-
i = xcL;
|
|
2260
|
-
xcL = ycL;
|
|
2261
|
-
ycL = i;
|
|
2262
|
-
}
|
|
2263
|
-
for (i = xcL + ycL, zc = []; i--; zc.push(0))
|
|
2264
|
-
;
|
|
2265
|
-
base = BASE;
|
|
2266
|
-
sqrtBase = SQRT_BASE;
|
|
2267
|
-
for (i = ycL; --i >= 0; ) {
|
|
2268
|
-
c = 0;
|
|
2269
|
-
ylo = yc[i] % sqrtBase;
|
|
2270
|
-
yhi = yc[i] / sqrtBase | 0;
|
|
2271
|
-
for (k = xcL, j = i + k; j > i; ) {
|
|
2272
|
-
xlo = xc[--k] % sqrtBase;
|
|
2273
|
-
xhi = xc[k] / sqrtBase | 0;
|
|
2274
|
-
m = yhi * xlo + xhi * ylo;
|
|
2275
|
-
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
2276
|
-
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
2277
|
-
zc[j--] = xlo % base;
|
|
2278
|
-
}
|
|
2279
|
-
zc[j] = c;
|
|
2280
|
-
}
|
|
2281
|
-
if (c) {
|
|
2282
|
-
++e;
|
|
2283
|
-
} else {
|
|
2284
|
-
zc.splice(0, 1);
|
|
2285
|
-
}
|
|
2286
|
-
return normalise(y, zc, e);
|
|
2287
|
-
};
|
|
2288
|
-
P.negated = function() {
|
|
2289
|
-
var x = new BigNumber2(this);
|
|
2290
|
-
x.s = -x.s || null;
|
|
2291
|
-
return x;
|
|
2292
|
-
};
|
|
2293
|
-
P.plus = function(y, b) {
|
|
2294
|
-
var t, x = this, a = x.s;
|
|
2295
|
-
y = new BigNumber2(y, b);
|
|
2296
|
-
b = y.s;
|
|
2297
|
-
if (!a || !b)
|
|
2298
|
-
return new BigNumber2(NaN);
|
|
2299
|
-
if (a != b) {
|
|
2300
|
-
y.s = -b;
|
|
2301
|
-
return x.minus(y);
|
|
2302
|
-
}
|
|
2303
|
-
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
2304
|
-
if (!xe || !ye) {
|
|
2305
|
-
if (!xc || !yc)
|
|
2306
|
-
return new BigNumber2(a / 0);
|
|
2307
|
-
if (!xc[0] || !yc[0])
|
|
2308
|
-
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
2309
|
-
}
|
|
2310
|
-
xe = bitFloor(xe);
|
|
2311
|
-
ye = bitFloor(ye);
|
|
2312
|
-
xc = xc.slice();
|
|
2313
|
-
if (a = xe - ye) {
|
|
2314
|
-
if (a > 0) {
|
|
2315
|
-
ye = xe;
|
|
2316
|
-
t = yc;
|
|
2317
|
-
} else {
|
|
2318
|
-
a = -a;
|
|
2319
|
-
t = xc;
|
|
2320
|
-
}
|
|
2321
|
-
t.reverse();
|
|
2322
|
-
for (; a--; t.push(0))
|
|
2323
|
-
;
|
|
2324
|
-
t.reverse();
|
|
2325
|
-
}
|
|
2326
|
-
a = xc.length;
|
|
2327
|
-
b = yc.length;
|
|
2328
|
-
if (a - b < 0) {
|
|
2329
|
-
t = yc;
|
|
2330
|
-
yc = xc;
|
|
2331
|
-
xc = t;
|
|
2332
|
-
b = a;
|
|
2333
|
-
}
|
|
2334
|
-
for (a = 0; b; ) {
|
|
2335
|
-
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
2336
|
-
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
2337
|
-
}
|
|
2338
|
-
if (a) {
|
|
2339
|
-
xc = [a].concat(xc);
|
|
2340
|
-
++ye;
|
|
2341
|
-
}
|
|
2342
|
-
return normalise(y, xc, ye);
|
|
2343
|
-
};
|
|
2344
|
-
P.precision = P.sd = function(sd, rm) {
|
|
2345
|
-
var c, n, v, x = this;
|
|
2346
|
-
if (sd != null && sd !== !!sd) {
|
|
2347
|
-
intCheck(sd, 1, MAX);
|
|
2348
|
-
if (rm == null)
|
|
2349
|
-
rm = ROUNDING_MODE;
|
|
2350
|
-
else
|
|
2351
|
-
intCheck(rm, 0, 8);
|
|
2352
|
-
return round(new BigNumber2(x), sd, rm);
|
|
2353
|
-
}
|
|
2354
|
-
if (!(c = x.c))
|
|
2355
|
-
return null;
|
|
2356
|
-
v = c.length - 1;
|
|
2357
|
-
n = v * LOG_BASE + 1;
|
|
2358
|
-
if (v = c[v]) {
|
|
2359
|
-
for (; v % 10 == 0; v /= 10, n--)
|
|
2360
|
-
;
|
|
2361
|
-
for (v = c[0]; v >= 10; v /= 10, n++)
|
|
2362
|
-
;
|
|
2363
|
-
}
|
|
2364
|
-
if (sd && x.e + 1 > n)
|
|
2365
|
-
n = x.e + 1;
|
|
2366
|
-
return n;
|
|
2367
|
-
};
|
|
2368
|
-
P.shiftedBy = function(k) {
|
|
2369
|
-
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
2370
|
-
return this.times("1e" + k);
|
|
2371
|
-
};
|
|
2372
|
-
P.squareRoot = P.sqrt = function() {
|
|
2373
|
-
var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
|
|
2374
|
-
if (s !== 1 || !c || !c[0]) {
|
|
2375
|
-
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
2376
|
-
}
|
|
2377
|
-
s = Math.sqrt(+valueOf(x));
|
|
2378
|
-
if (s == 0 || s == 1 / 0) {
|
|
2379
|
-
n = coeffToString(c);
|
|
2380
|
-
if ((n.length + e) % 2 == 0)
|
|
2381
|
-
n += "0";
|
|
2382
|
-
s = Math.sqrt(+n);
|
|
2383
|
-
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
2384
|
-
if (s == 1 / 0) {
|
|
2385
|
-
n = "5e" + e;
|
|
2386
|
-
} else {
|
|
2387
|
-
n = s.toExponential();
|
|
2388
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
2389
|
-
}
|
|
2390
|
-
r = new BigNumber2(n);
|
|
2391
|
-
} else {
|
|
2392
|
-
r = new BigNumber2(s + "");
|
|
2393
|
-
}
|
|
2394
|
-
if (r.c[0]) {
|
|
2395
|
-
e = r.e;
|
|
2396
|
-
s = e + dp;
|
|
2397
|
-
if (s < 3)
|
|
2398
|
-
s = 0;
|
|
2399
|
-
for (; ; ) {
|
|
2400
|
-
t = r;
|
|
2401
|
-
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
2402
|
-
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
2403
|
-
if (r.e < e)
|
|
2404
|
-
--s;
|
|
2405
|
-
n = n.slice(s - 3, s + 1);
|
|
2406
|
-
if (n == "9999" || !rep && n == "4999") {
|
|
2407
|
-
if (!rep) {
|
|
2408
|
-
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
2409
|
-
if (t.times(t).eq(x)) {
|
|
2410
|
-
r = t;
|
|
2411
|
-
break;
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
dp += 4;
|
|
2415
|
-
s += 4;
|
|
2416
|
-
rep = 1;
|
|
2417
|
-
} else {
|
|
2418
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
2419
|
-
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
2420
|
-
m = !r.times(r).eq(x);
|
|
2421
|
-
}
|
|
2422
|
-
break;
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
2428
|
-
};
|
|
2429
|
-
P.toExponential = function(dp, rm) {
|
|
2430
|
-
if (dp != null) {
|
|
2431
|
-
intCheck(dp, 0, MAX);
|
|
2432
|
-
dp++;
|
|
2433
|
-
}
|
|
2434
|
-
return format(this, dp, rm, 1);
|
|
2435
|
-
};
|
|
2436
|
-
P.toFixed = function(dp, rm) {
|
|
2437
|
-
if (dp != null) {
|
|
2438
|
-
intCheck(dp, 0, MAX);
|
|
2439
|
-
dp = dp + this.e + 1;
|
|
2440
|
-
}
|
|
2441
|
-
return format(this, dp, rm);
|
|
2442
|
-
};
|
|
2443
|
-
P.toFormat = function(dp, rm, format2) {
|
|
2444
|
-
var str, x = this;
|
|
2445
|
-
if (format2 == null) {
|
|
2446
|
-
if (dp != null && rm && typeof rm == "object") {
|
|
2447
|
-
format2 = rm;
|
|
2448
|
-
rm = null;
|
|
2449
|
-
} else if (dp && typeof dp == "object") {
|
|
2450
|
-
format2 = dp;
|
|
2451
|
-
dp = rm = null;
|
|
2452
|
-
} else {
|
|
2453
|
-
format2 = FORMAT;
|
|
2454
|
-
}
|
|
2455
|
-
} else if (typeof format2 != "object") {
|
|
2456
|
-
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
2457
|
-
}
|
|
2458
|
-
str = x.toFixed(dp, rm);
|
|
2459
|
-
if (x.c) {
|
|
2460
|
-
var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
2461
|
-
if (g2) {
|
|
2462
|
-
i = g1;
|
|
2463
|
-
g1 = g2;
|
|
2464
|
-
g2 = i;
|
|
2465
|
-
len -= i;
|
|
2466
|
-
}
|
|
2467
|
-
if (g1 > 0 && len > 0) {
|
|
2468
|
-
i = len % g1 || g1;
|
|
2469
|
-
intPart = intDigits.substr(0, i);
|
|
2470
|
-
for (; i < len; i += g1)
|
|
2471
|
-
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
2472
|
-
if (g2 > 0)
|
|
2473
|
-
intPart += groupSeparator + intDigits.slice(i);
|
|
2474
|
-
if (isNeg)
|
|
2475
|
-
intPart = "-" + intPart;
|
|
2476
|
-
}
|
|
2477
|
-
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
|
|
2478
|
-
new RegExp("\\d{" + g2 + "}\\B", "g"),
|
|
2479
|
-
"$&" + (format2.fractionGroupSeparator || "")
|
|
2480
|
-
) : fractionPart) : intPart;
|
|
2481
|
-
}
|
|
2482
|
-
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
2483
|
-
};
|
|
2484
|
-
P.toFraction = function(md) {
|
|
2485
|
-
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
2486
|
-
if (md != null) {
|
|
2487
|
-
n = new BigNumber2(md);
|
|
2488
|
-
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
2489
|
-
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
if (!xc)
|
|
2493
|
-
return new BigNumber2(x);
|
|
2494
|
-
d = new BigNumber2(ONE);
|
|
2495
|
-
n1 = d0 = new BigNumber2(ONE);
|
|
2496
|
-
d1 = n0 = new BigNumber2(ONE);
|
|
2497
|
-
s = coeffToString(xc);
|
|
2498
|
-
e = d.e = s.length - x.e - 1;
|
|
2499
|
-
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
2500
|
-
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
2501
|
-
exp = MAX_EXP;
|
|
2502
|
-
MAX_EXP = 1 / 0;
|
|
2503
|
-
n = new BigNumber2(s);
|
|
2504
|
-
n0.c[0] = 0;
|
|
2505
|
-
for (; ; ) {
|
|
2506
|
-
q = div(n, d, 0, 1);
|
|
2507
|
-
d2 = d0.plus(q.times(d1));
|
|
2508
|
-
if (d2.comparedTo(md) == 1)
|
|
2509
|
-
break;
|
|
2510
|
-
d0 = d1;
|
|
2511
|
-
d1 = d2;
|
|
2512
|
-
n1 = n0.plus(q.times(d2 = n1));
|
|
2513
|
-
n0 = d2;
|
|
2514
|
-
d = n.minus(q.times(d2 = d));
|
|
2515
|
-
n = d2;
|
|
2516
|
-
}
|
|
2517
|
-
d2 = div(md.minus(d0), d1, 0, 1);
|
|
2518
|
-
n0 = n0.plus(d2.times(n1));
|
|
2519
|
-
d0 = d0.plus(d2.times(d1));
|
|
2520
|
-
n0.s = n1.s = x.s;
|
|
2521
|
-
e = e * 2;
|
|
2522
|
-
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
|
|
2523
|
-
div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
|
|
2524
|
-
) < 1 ? [n1, d1] : [n0, d0];
|
|
2525
|
-
MAX_EXP = exp;
|
|
2526
|
-
return r;
|
|
2527
|
-
};
|
|
2528
|
-
P.toNumber = function() {
|
|
2529
|
-
return +valueOf(this);
|
|
2530
|
-
};
|
|
2531
|
-
P.toPrecision = function(sd, rm) {
|
|
2532
|
-
if (sd != null)
|
|
2533
|
-
intCheck(sd, 1, MAX);
|
|
2534
|
-
return format(this, sd, rm, 2);
|
|
2535
|
-
};
|
|
2536
|
-
P.toString = function(b) {
|
|
2537
|
-
var str, n = this, s = n.s, e = n.e;
|
|
2538
|
-
if (e === null) {
|
|
2539
|
-
if (s) {
|
|
2540
|
-
str = "Infinity";
|
|
2541
|
-
if (s < 0)
|
|
2542
|
-
str = "-" + str;
|
|
2543
|
-
} else {
|
|
2544
|
-
str = "NaN";
|
|
2545
|
-
}
|
|
2546
|
-
} else {
|
|
2547
|
-
if (b == null) {
|
|
2548
|
-
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
2549
|
-
} else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
2550
|
-
n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
2551
|
-
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
2552
|
-
} else {
|
|
2553
|
-
intCheck(b, 2, ALPHABET.length, "Base");
|
|
2554
|
-
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
2555
|
-
}
|
|
2556
|
-
if (s < 0 && n.c[0])
|
|
2557
|
-
str = "-" + str;
|
|
2558
|
-
}
|
|
2559
|
-
return str;
|
|
2560
|
-
};
|
|
2561
|
-
P.valueOf = P.toJSON = function() {
|
|
2562
|
-
return valueOf(this);
|
|
2563
|
-
};
|
|
2564
|
-
P._isBigNumber = true;
|
|
2565
|
-
if (configObject != null)
|
|
2566
|
-
BigNumber2.set(configObject);
|
|
2567
|
-
return BigNumber2;
|
|
2568
|
-
}
|
|
2569
|
-
function bitFloor(n) {
|
|
2570
|
-
var i = n | 0;
|
|
2571
|
-
return n > 0 || n === i ? i : i - 1;
|
|
2572
|
-
}
|
|
2573
|
-
function coeffToString(a) {
|
|
2574
|
-
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
2575
|
-
for (; i < j; ) {
|
|
2576
|
-
s = a[i++] + "";
|
|
2577
|
-
z = LOG_BASE - s.length;
|
|
2578
|
-
for (; z--; s = "0" + s)
|
|
2579
|
-
;
|
|
2580
|
-
r += s;
|
|
2581
|
-
}
|
|
2582
|
-
for (j = r.length; r.charCodeAt(--j) === 48; )
|
|
2583
|
-
;
|
|
2584
|
-
return r.slice(0, j + 1 || 1);
|
|
2585
|
-
}
|
|
2586
|
-
function compare(x, y) {
|
|
2587
|
-
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
2588
|
-
if (!i || !j)
|
|
2589
|
-
return null;
|
|
2590
|
-
a = xc && !xc[0];
|
|
2591
|
-
b = yc && !yc[0];
|
|
2592
|
-
if (a || b)
|
|
2593
|
-
return a ? b ? 0 : -j : i;
|
|
2594
|
-
if (i != j)
|
|
2595
|
-
return i;
|
|
2596
|
-
a = i < 0;
|
|
2597
|
-
b = k == l;
|
|
2598
|
-
if (!xc || !yc)
|
|
2599
|
-
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
2600
|
-
if (!b)
|
|
2601
|
-
return k > l ^ a ? 1 : -1;
|
|
2602
|
-
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
2603
|
-
for (i = 0; i < j; i++)
|
|
2604
|
-
if (xc[i] != yc[i])
|
|
2605
|
-
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
2606
|
-
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
2607
|
-
}
|
|
2608
|
-
function intCheck(n, min, max, name) {
|
|
2609
|
-
if (n < min || n > max || n !== mathfloor(n)) {
|
|
2610
|
-
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
function isOdd(n) {
|
|
2614
|
-
var k = n.c.length - 1;
|
|
2615
|
-
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
2616
|
-
}
|
|
2617
|
-
function toExponential(str, e) {
|
|
2618
|
-
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
2619
|
-
}
|
|
2620
|
-
function toFixedPoint(str, e, z) {
|
|
2621
|
-
var len, zs;
|
|
2622
|
-
if (e < 0) {
|
|
2623
|
-
for (zs = z + "."; ++e; zs += z)
|
|
2624
|
-
;
|
|
2625
|
-
str = zs + str;
|
|
2626
|
-
} else {
|
|
2627
|
-
len = str.length;
|
|
2628
|
-
if (++e > len) {
|
|
2629
|
-
for (zs = z, e -= len; --e; zs += z)
|
|
2630
|
-
;
|
|
2631
|
-
str += zs;
|
|
2632
|
-
} else if (e < len) {
|
|
2633
|
-
str = str.slice(0, e) + "." + str.slice(e);
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
return str;
|
|
2637
|
-
}
|
|
2638
|
-
BigNumber = clone();
|
|
2639
|
-
BigNumber["default"] = BigNumber.BigNumber = BigNumber;
|
|
2640
|
-
if (typeof define == "function" && define.amd) {
|
|
2641
|
-
define(function() {
|
|
2642
|
-
return BigNumber;
|
|
2643
|
-
});
|
|
2644
|
-
} else if (typeof module != "undefined" && module.exports) {
|
|
2645
|
-
module.exports = BigNumber;
|
|
2646
|
-
} else {
|
|
2647
|
-
if (!globalObject) {
|
|
2648
|
-
globalObject = typeof self != "undefined" && self ? self : window;
|
|
2649
|
-
}
|
|
2650
|
-
globalObject.BigNumber = BigNumber;
|
|
2651
|
-
}
|
|
2652
|
-
})(exports);
|
|
2653
|
-
}
|
|
2654
|
-
});
|
|
2655
|
-
|
|
2656
|
-
// node_modules/json-bigint/lib/stringify.js
|
|
2657
|
-
var require_stringify = __commonJS({
|
|
2658
|
-
"node_modules/json-bigint/lib/stringify.js"(exports, module) {
|
|
2659
|
-
var BigNumber = require_bignumber();
|
|
2660
|
-
var JSON2 = module.exports;
|
|
2661
|
-
(function() {
|
|
2662
|
-
"use strict";
|
|
2663
|
-
function f(n) {
|
|
2664
|
-
return n < 10 ? "0" + n : n;
|
|
2665
|
-
}
|
|
2666
|
-
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {
|
|
2667
|
-
"\b": "\\b",
|
|
2668
|
-
" ": "\\t",
|
|
2669
|
-
"\n": "\\n",
|
|
2670
|
-
"\f": "\\f",
|
|
2671
|
-
"\r": "\\r",
|
|
2672
|
-
'"': '\\"',
|
|
2673
|
-
"\\": "\\\\"
|
|
2674
|
-
}, rep;
|
|
2675
|
-
function quote(string) {
|
|
2676
|
-
escapable.lastIndex = 0;
|
|
2677
|
-
return escapable.test(string) ? '"' + string.replace(escapable, function(a) {
|
|
2678
|
-
var c = meta[a];
|
|
2679
|
-
return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
2680
|
-
}) + '"' : '"' + string + '"';
|
|
2681
|
-
}
|
|
2682
|
-
function str(key, holder) {
|
|
2683
|
-
var i, k, v, length, mind = gap, partial, value = holder[key], isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));
|
|
2684
|
-
if (value && typeof value === "object" && typeof value.toJSON === "function") {
|
|
2685
|
-
value = value.toJSON(key);
|
|
2686
|
-
}
|
|
2687
|
-
if (typeof rep === "function") {
|
|
2688
|
-
value = rep.call(holder, key, value);
|
|
2689
|
-
}
|
|
2690
|
-
switch (typeof value) {
|
|
2691
|
-
case "string":
|
|
2692
|
-
if (isBigNumber) {
|
|
2693
|
-
return value;
|
|
2694
|
-
} else {
|
|
2695
|
-
return quote(value);
|
|
2696
|
-
}
|
|
2697
|
-
case "number":
|
|
2698
|
-
return isFinite(value) ? String(value) : "null";
|
|
2699
|
-
case "boolean":
|
|
2700
|
-
case "null":
|
|
2701
|
-
case "bigint":
|
|
2702
|
-
return String(value);
|
|
2703
|
-
case "object":
|
|
2704
|
-
if (!value) {
|
|
2705
|
-
return "null";
|
|
2706
|
-
}
|
|
2707
|
-
gap += indent;
|
|
2708
|
-
partial = [];
|
|
2709
|
-
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
2710
|
-
length = value.length;
|
|
2711
|
-
for (i = 0; i < length; i += 1) {
|
|
2712
|
-
partial[i] = str(i, value) || "null";
|
|
2713
|
-
}
|
|
2714
|
-
v = partial.length === 0 ? "[]" : gap ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]" : "[" + partial.join(",") + "]";
|
|
2715
|
-
gap = mind;
|
|
2716
|
-
return v;
|
|
2717
|
-
}
|
|
2718
|
-
if (rep && typeof rep === "object") {
|
|
2719
|
-
length = rep.length;
|
|
2720
|
-
for (i = 0; i < length; i += 1) {
|
|
2721
|
-
if (typeof rep[i] === "string") {
|
|
2722
|
-
k = rep[i];
|
|
2723
|
-
v = str(k, value);
|
|
2724
|
-
if (v) {
|
|
2725
|
-
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
} else {
|
|
2730
|
-
Object.keys(value).forEach(function(k2) {
|
|
2731
|
-
var v2 = str(k2, value);
|
|
2732
|
-
if (v2) {
|
|
2733
|
-
partial.push(quote(k2) + (gap ? ": " : ":") + v2);
|
|
2734
|
-
}
|
|
2735
|
-
});
|
|
2736
|
-
}
|
|
2737
|
-
v = partial.length === 0 ? "{}" : gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" : "{" + partial.join(",") + "}";
|
|
2738
|
-
gap = mind;
|
|
2739
|
-
return v;
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
if (typeof JSON2.stringify !== "function") {
|
|
2743
|
-
JSON2.stringify = function(value, replacer, space) {
|
|
2744
|
-
var i;
|
|
2745
|
-
gap = "";
|
|
2746
|
-
indent = "";
|
|
2747
|
-
if (typeof space === "number") {
|
|
2748
|
-
for (i = 0; i < space; i += 1) {
|
|
2749
|
-
indent += " ";
|
|
2750
|
-
}
|
|
2751
|
-
} else if (typeof space === "string") {
|
|
2752
|
-
indent = space;
|
|
2753
|
-
}
|
|
2754
|
-
rep = replacer;
|
|
2755
|
-
if (replacer && typeof replacer !== "function" && (typeof replacer !== "object" || typeof replacer.length !== "number")) {
|
|
2756
|
-
throw new Error("JSON.stringify");
|
|
2757
|
-
}
|
|
2758
|
-
return str("", { "": value });
|
|
2759
|
-
};
|
|
2760
|
-
}
|
|
2761
|
-
})();
|
|
2762
|
-
}
|
|
2763
|
-
});
|
|
2764
|
-
|
|
2765
|
-
// node_modules/json-bigint/lib/parse.js
|
|
2766
|
-
var require_parse = __commonJS({
|
|
2767
|
-
"node_modules/json-bigint/lib/parse.js"(exports, module) {
|
|
2768
|
-
var BigNumber = null;
|
|
2769
|
-
var suspectProtoRx = /(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/;
|
|
2770
|
-
var suspectConstructorRx = /(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/;
|
|
2771
|
-
var json_parse = function(options) {
|
|
2772
|
-
"use strict";
|
|
2773
|
-
var _options = {
|
|
2774
|
-
strict: false,
|
|
2775
|
-
storeAsString: false,
|
|
2776
|
-
alwaysParseAsBig: false,
|
|
2777
|
-
useNativeBigInt: false,
|
|
2778
|
-
protoAction: "error",
|
|
2779
|
-
constructorAction: "error"
|
|
2780
|
-
};
|
|
2781
|
-
if (options !== void 0 && options !== null) {
|
|
2782
|
-
if (options.strict === true) {
|
|
2783
|
-
_options.strict = true;
|
|
2784
|
-
}
|
|
2785
|
-
if (options.storeAsString === true) {
|
|
2786
|
-
_options.storeAsString = true;
|
|
2787
|
-
}
|
|
2788
|
-
_options.alwaysParseAsBig = options.alwaysParseAsBig === true ? options.alwaysParseAsBig : false;
|
|
2789
|
-
_options.useNativeBigInt = options.useNativeBigInt === true ? options.useNativeBigInt : false;
|
|
2790
|
-
if (typeof options.constructorAction !== "undefined") {
|
|
2791
|
-
if (options.constructorAction === "error" || options.constructorAction === "ignore" || options.constructorAction === "preserve") {
|
|
2792
|
-
_options.constructorAction = options.constructorAction;
|
|
2793
|
-
} else {
|
|
2794
|
-
throw new Error(
|
|
2795
|
-
`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${options.constructorAction}`
|
|
2796
|
-
);
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
if (typeof options.protoAction !== "undefined") {
|
|
2800
|
-
if (options.protoAction === "error" || options.protoAction === "ignore" || options.protoAction === "preserve") {
|
|
2801
|
-
_options.protoAction = options.protoAction;
|
|
2802
|
-
} else {
|
|
2803
|
-
throw new Error(
|
|
2804
|
-
`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${options.protoAction}`
|
|
2805
|
-
);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
var at, ch, escapee = {
|
|
2810
|
-
'"': '"',
|
|
2811
|
-
"\\": "\\",
|
|
2812
|
-
"/": "/",
|
|
2813
|
-
b: "\b",
|
|
2814
|
-
f: "\f",
|
|
2815
|
-
n: "\n",
|
|
2816
|
-
r: "\r",
|
|
2817
|
-
t: " "
|
|
2818
|
-
}, text, error = function(m) {
|
|
2819
|
-
throw {
|
|
2820
|
-
name: "SyntaxError",
|
|
2821
|
-
message: m,
|
|
2822
|
-
at,
|
|
2823
|
-
text
|
|
2824
|
-
};
|
|
2825
|
-
}, next = function(c) {
|
|
2826
|
-
if (c && c !== ch) {
|
|
2827
|
-
error("Expected '" + c + "' instead of '" + ch + "'");
|
|
2828
|
-
}
|
|
2829
|
-
ch = text.charAt(at);
|
|
2830
|
-
at += 1;
|
|
2831
|
-
return ch;
|
|
2832
|
-
}, number3 = function() {
|
|
2833
|
-
var number4, string2 = "";
|
|
2834
|
-
if (ch === "-") {
|
|
2835
|
-
string2 = "-";
|
|
2836
|
-
next("-");
|
|
2837
|
-
}
|
|
2838
|
-
while (ch >= "0" && ch <= "9") {
|
|
2839
|
-
string2 += ch;
|
|
2840
|
-
next();
|
|
2841
|
-
}
|
|
2842
|
-
if (ch === ".") {
|
|
2843
|
-
string2 += ".";
|
|
2844
|
-
while (next() && ch >= "0" && ch <= "9") {
|
|
2845
|
-
string2 += ch;
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
if (ch === "e" || ch === "E") {
|
|
2849
|
-
string2 += ch;
|
|
2850
|
-
next();
|
|
2851
|
-
if (ch === "-" || ch === "+") {
|
|
2852
|
-
string2 += ch;
|
|
2853
|
-
next();
|
|
543
|
+
// node_modules/ts-custom-error/dist/custom-error.js
|
|
544
|
+
var require_custom_error = __commonJS({
|
|
545
|
+
"node_modules/ts-custom-error/dist/custom-error.js"(exports) {
|
|
546
|
+
function fixProto(target, prototype) {
|
|
547
|
+
var setPrototypeOf = Object.setPrototypeOf;
|
|
548
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
549
|
+
}
|
|
550
|
+
function fixStack(target, fn) {
|
|
551
|
+
if (fn === void 0) {
|
|
552
|
+
fn = target.constructor;
|
|
553
|
+
}
|
|
554
|
+
var captureStackTrace = Error.captureStackTrace;
|
|
555
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
556
|
+
}
|
|
557
|
+
var __extends = function() {
|
|
558
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
559
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
560
|
+
__proto__: []
|
|
561
|
+
} instanceof Array && function(d2, b2) {
|
|
562
|
+
d2.__proto__ = b2;
|
|
563
|
+
} || function(d2, b2) {
|
|
564
|
+
for (var p in b2) {
|
|
565
|
+
if (Object.prototype.hasOwnProperty.call(b2, p))
|
|
566
|
+
d2[p] = b2[p];
|
|
2854
567
|
}
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
if (BigNumber == null)
|
|
2865
|
-
BigNumber = require_bignumber();
|
|
2866
|
-
if (string2.length > 15)
|
|
2867
|
-
return _options.storeAsString ? string2 : _options.useNativeBigInt ? BigInt(string2) : new BigNumber(string2);
|
|
2868
|
-
else
|
|
2869
|
-
return !_options.alwaysParseAsBig ? number4 : _options.useNativeBigInt ? BigInt(number4) : new BigNumber(number4);
|
|
568
|
+
};
|
|
569
|
+
return _extendStatics(d, b);
|
|
570
|
+
};
|
|
571
|
+
return function(d, b) {
|
|
572
|
+
if (typeof b !== "function" && b !== null)
|
|
573
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
574
|
+
_extendStatics(d, b);
|
|
575
|
+
function __() {
|
|
576
|
+
this.constructor = d;
|
|
2870
577
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
string2 += escapee[ch];
|
|
2898
|
-
} else {
|
|
2899
|
-
break;
|
|
2900
|
-
}
|
|
2901
|
-
startAt = at;
|
|
2902
|
-
}
|
|
578
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
579
|
+
};
|
|
580
|
+
}();
|
|
581
|
+
var CustomError2 = function(_super) {
|
|
582
|
+
__extends(CustomError3, _super);
|
|
583
|
+
function CustomError3(message, options) {
|
|
584
|
+
var _newTarget = this.constructor;
|
|
585
|
+
var _this = _super.call(this, message, options) || this;
|
|
586
|
+
Object.defineProperty(_this, "name", {
|
|
587
|
+
value: _newTarget.name,
|
|
588
|
+
enumerable: false,
|
|
589
|
+
configurable: true
|
|
590
|
+
});
|
|
591
|
+
fixProto(_this, _newTarget.prototype);
|
|
592
|
+
fixStack(_this);
|
|
593
|
+
return _this;
|
|
594
|
+
}
|
|
595
|
+
return CustomError3;
|
|
596
|
+
}(Error);
|
|
597
|
+
var __spreadArray = function(to, from, pack) {
|
|
598
|
+
if (pack || arguments.length === 2)
|
|
599
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
600
|
+
if (ar || !(i in from)) {
|
|
601
|
+
if (!ar)
|
|
602
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
603
|
+
ar[i] = from[i];
|
|
2903
604
|
}
|
|
2904
605
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
next("u");
|
|
2916
|
-
next("e");
|
|
2917
|
-
return true;
|
|
2918
|
-
case "f":
|
|
2919
|
-
next("f");
|
|
2920
|
-
next("a");
|
|
2921
|
-
next("l");
|
|
2922
|
-
next("s");
|
|
2923
|
-
next("e");
|
|
2924
|
-
return false;
|
|
2925
|
-
case "n":
|
|
2926
|
-
next("n");
|
|
2927
|
-
next("u");
|
|
2928
|
-
next("l");
|
|
2929
|
-
next("l");
|
|
2930
|
-
return null;
|
|
2931
|
-
}
|
|
2932
|
-
error("Unexpected '" + ch + "'");
|
|
2933
|
-
}, value, array = function() {
|
|
2934
|
-
var array2 = [];
|
|
2935
|
-
if (ch === "[") {
|
|
2936
|
-
next("[");
|
|
2937
|
-
white();
|
|
2938
|
-
if (ch === "]") {
|
|
2939
|
-
next("]");
|
|
2940
|
-
return array2;
|
|
2941
|
-
}
|
|
2942
|
-
while (ch) {
|
|
2943
|
-
array2.push(value());
|
|
2944
|
-
white();
|
|
2945
|
-
if (ch === "]") {
|
|
2946
|
-
next("]");
|
|
2947
|
-
return array2;
|
|
2948
|
-
}
|
|
2949
|
-
next(",");
|
|
2950
|
-
white();
|
|
2951
|
-
}
|
|
606
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
607
|
+
};
|
|
608
|
+
function customErrorFactory(fn, parent) {
|
|
609
|
+
if (parent === void 0) {
|
|
610
|
+
parent = Error;
|
|
611
|
+
}
|
|
612
|
+
function CustomError3() {
|
|
613
|
+
var args = [];
|
|
614
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
615
|
+
args[_i] = arguments[_i];
|
|
2952
616
|
}
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
if (_options.protoAction === "error") {
|
|
2972
|
-
error("Object contains forbidden prototype property");
|
|
2973
|
-
} else if (_options.protoAction === "ignore") {
|
|
2974
|
-
value();
|
|
2975
|
-
} else {
|
|
2976
|
-
object2[key] = value();
|
|
2977
|
-
}
|
|
2978
|
-
} else if (suspectConstructorRx.test(key) === true) {
|
|
2979
|
-
if (_options.constructorAction === "error") {
|
|
2980
|
-
error("Object contains forbidden constructor property");
|
|
2981
|
-
} else if (_options.constructorAction === "ignore") {
|
|
2982
|
-
value();
|
|
2983
|
-
} else {
|
|
2984
|
-
object2[key] = value();
|
|
2985
|
-
}
|
|
2986
|
-
} else {
|
|
2987
|
-
object2[key] = value();
|
|
2988
|
-
}
|
|
2989
|
-
white();
|
|
2990
|
-
if (ch === "}") {
|
|
2991
|
-
next("}");
|
|
2992
|
-
return object2;
|
|
617
|
+
if (!(this instanceof CustomError3))
|
|
618
|
+
return new (CustomError3.bind.apply(CustomError3, __spreadArray([void 0], args, false)))();
|
|
619
|
+
parent.apply(this, args);
|
|
620
|
+
Object.defineProperty(this, "name", {
|
|
621
|
+
value: fn.name || parent.name,
|
|
622
|
+
enumerable: false,
|
|
623
|
+
configurable: true
|
|
624
|
+
});
|
|
625
|
+
fn.apply(this, args);
|
|
626
|
+
fixStack(this, CustomError3);
|
|
627
|
+
}
|
|
628
|
+
return Object.defineProperties(CustomError3, {
|
|
629
|
+
prototype: {
|
|
630
|
+
value: Object.create(parent.prototype, {
|
|
631
|
+
constructor: {
|
|
632
|
+
value: CustomError3,
|
|
633
|
+
writable: true,
|
|
634
|
+
configurable: true
|
|
2993
635
|
}
|
|
2994
|
-
|
|
2995
|
-
white();
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
error("Bad object");
|
|
2999
|
-
};
|
|
3000
|
-
value = function() {
|
|
3001
|
-
white();
|
|
3002
|
-
switch (ch) {
|
|
3003
|
-
case "{":
|
|
3004
|
-
return object();
|
|
3005
|
-
case "[":
|
|
3006
|
-
return array();
|
|
3007
|
-
case '"':
|
|
3008
|
-
return string();
|
|
3009
|
-
case "-":
|
|
3010
|
-
return number3();
|
|
3011
|
-
default:
|
|
3012
|
-
return ch >= "0" && ch <= "9" ? number3() : word();
|
|
3013
|
-
}
|
|
3014
|
-
};
|
|
3015
|
-
return function(source, reviver) {
|
|
3016
|
-
var result;
|
|
3017
|
-
text = source + "";
|
|
3018
|
-
at = 0;
|
|
3019
|
-
ch = " ";
|
|
3020
|
-
result = value();
|
|
3021
|
-
white();
|
|
3022
|
-
if (ch) {
|
|
3023
|
-
error("Syntax error");
|
|
636
|
+
})
|
|
3024
637
|
}
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
v = walk(value2, k2);
|
|
3030
|
-
if (v !== void 0) {
|
|
3031
|
-
value2[k2] = v;
|
|
3032
|
-
} else {
|
|
3033
|
-
delete value2[k2];
|
|
3034
|
-
}
|
|
3035
|
-
});
|
|
3036
|
-
}
|
|
3037
|
-
return reviver.call(holder, key, value2);
|
|
3038
|
-
}({ "": result }, "") : result;
|
|
3039
|
-
};
|
|
3040
|
-
};
|
|
3041
|
-
module.exports = json_parse;
|
|
3042
|
-
}
|
|
3043
|
-
});
|
|
3044
|
-
|
|
3045
|
-
// node_modules/json-bigint/index.js
|
|
3046
|
-
var require_json_bigint = __commonJS({
|
|
3047
|
-
"node_modules/json-bigint/index.js"(exports, module) {
|
|
3048
|
-
var json_stringify = require_stringify().stringify;
|
|
3049
|
-
var json_parse = require_parse();
|
|
3050
|
-
module.exports = function(options) {
|
|
3051
|
-
return {
|
|
3052
|
-
parse: json_parse(options),
|
|
3053
|
-
stringify: json_stringify
|
|
3054
|
-
};
|
|
3055
|
-
};
|
|
3056
|
-
module.exports.parse = json_parse();
|
|
3057
|
-
module.exports.stringify = json_stringify;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
exports.CustomError = CustomError2;
|
|
641
|
+
exports.customErrorFactory = customErrorFactory;
|
|
3058
642
|
}
|
|
3059
643
|
});
|
|
3060
644
|
|
|
@@ -3128,9 +712,11 @@ var starknet = (() => {
|
|
|
3128
712
|
__export(src_exports, {
|
|
3129
713
|
Account: () => Account,
|
|
3130
714
|
AccountInterface: () => AccountInterface,
|
|
715
|
+
CallData: () => CallData,
|
|
3131
716
|
Contract: () => Contract,
|
|
3132
717
|
ContractFactory: () => ContractFactory,
|
|
3133
718
|
ContractInterface: () => ContractInterface,
|
|
719
|
+
EntryPointType: () => EntryPointType,
|
|
3134
720
|
GatewayError: () => GatewayError,
|
|
3135
721
|
HttpError: () => HttpError,
|
|
3136
722
|
LibraryError: () => LibraryError,
|
|
@@ -3165,7 +751,15 @@ var starknet = (() => {
|
|
|
3165
751
|
validateChecksumAddress: () => validateChecksumAddress
|
|
3166
752
|
});
|
|
3167
753
|
|
|
3168
|
-
// src/types/lib.ts
|
|
754
|
+
// src/types/lib/contract/index.ts
|
|
755
|
+
var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
|
|
756
|
+
EntryPointType2["EXTERNAL"] = "EXTERNAL";
|
|
757
|
+
EntryPointType2["L1_HANDLER"] = "L1_HANDLER";
|
|
758
|
+
EntryPointType2["CONSTRUCTOR"] = "CONSTRUCTOR";
|
|
759
|
+
return EntryPointType2;
|
|
760
|
+
})(EntryPointType || {});
|
|
761
|
+
|
|
762
|
+
// src/types/lib/index.ts
|
|
3169
763
|
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
3170
764
|
TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
|
|
3171
765
|
TransactionStatus2["RECEIVED"] = "RECEIVED";
|
|
@@ -3213,19 +807,18 @@ var starknet = (() => {
|
|
|
3213
807
|
computeContractClassHash: () => computeContractClassHash,
|
|
3214
808
|
computeHashOnElements: () => computeHashOnElements2,
|
|
3215
809
|
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
3216
|
-
|
|
810
|
+
computeSierraContractClassHash: () => computeSierraContractClassHash,
|
|
3217
811
|
default: () => computeHintedClassHash,
|
|
3218
812
|
feeTransactionVersion: () => feeTransactionVersion,
|
|
813
|
+
formatSpaces: () => formatSpaces,
|
|
3219
814
|
getSelector: () => getSelector,
|
|
3220
815
|
getSelectorFromName: () => getSelectorFromName,
|
|
3221
816
|
keccakBn: () => keccakBn,
|
|
3222
817
|
poseidon: () => poseidon_exports,
|
|
3223
818
|
starknetKeccak: () => starknetKeccak,
|
|
3224
|
-
transactionVersion: () => transactionVersion
|
|
819
|
+
transactionVersion: () => transactionVersion,
|
|
820
|
+
transactionVersion_2: () => transactionVersion_2
|
|
3225
821
|
});
|
|
3226
|
-
var import_keccak = __toESM(require_keccak());
|
|
3227
|
-
var import_utils10 = __toESM(require_utils2());
|
|
3228
|
-
var import_json_keys_sort = __toESM(require_json_keys_sort());
|
|
3229
822
|
|
|
3230
823
|
// node_modules/micro-starknet/lib/esm/index.js
|
|
3231
824
|
var esm_exports = {};
|
|
@@ -3369,11 +962,8 @@ var starknet = (() => {
|
|
|
3369
962
|
};
|
|
3370
963
|
var u64_default = u64;
|
|
3371
964
|
|
|
3372
|
-
// node_modules/@noble/hashes/esm/
|
|
3373
|
-
var
|
|
3374
|
-
node: void 0,
|
|
3375
|
-
web: typeof self === "object" && "crypto" in self ? self.crypto : void 0
|
|
3376
|
-
};
|
|
965
|
+
// node_modules/@noble/hashes/esm/crypto.js
|
|
966
|
+
var crypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
3377
967
|
|
|
3378
968
|
// node_modules/@noble/hashes/esm/utils.js
|
|
3379
969
|
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
@@ -3432,13 +1022,10 @@ var starknet = (() => {
|
|
|
3432
1022
|
return hashC;
|
|
3433
1023
|
}
|
|
3434
1024
|
function randomBytes(bytesLength = 32) {
|
|
3435
|
-
if (
|
|
3436
|
-
return
|
|
3437
|
-
} else if (crypto2.node) {
|
|
3438
|
-
return new Uint8Array(crypto2.node.randomBytes(bytesLength).buffer);
|
|
3439
|
-
} else {
|
|
3440
|
-
throw new Error("The environment doesn't have randomBytes function");
|
|
1025
|
+
if (crypto && typeof crypto.getRandomValues === "function") {
|
|
1026
|
+
return crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
3441
1027
|
}
|
|
1028
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
3442
1029
|
}
|
|
3443
1030
|
|
|
3444
1031
|
// node_modules/@noble/hashes/esm/sha3.js
|
|
@@ -7831,6 +5418,7 @@ var starknet = (() => {
|
|
|
7831
5418
|
getDecimalString: () => getDecimalString,
|
|
7832
5419
|
getHexString: () => getHexString,
|
|
7833
5420
|
getHexStringArray: () => getHexStringArray,
|
|
5421
|
+
hexToBytes: () => hexToBytes2,
|
|
7834
5422
|
hexToDecimalString: () => hexToDecimalString,
|
|
7835
5423
|
isBigInt: () => isBigInt,
|
|
7836
5424
|
isHex: () => isHex,
|
|
@@ -7905,6 +5493,15 @@ var starknet = (() => {
|
|
|
7905
5493
|
return value.map((el) => getHexString(el));
|
|
7906
5494
|
}
|
|
7907
5495
|
var toCairoBool = (value) => (+value).toString();
|
|
5496
|
+
function hexToBytes2(value) {
|
|
5497
|
+
if (!isHex(value))
|
|
5498
|
+
throw new Error(`${value} need to be a hex-string`);
|
|
5499
|
+
let adaptedValue = removeHexPrefix(value);
|
|
5500
|
+
if (adaptedValue.length % 2 !== 0) {
|
|
5501
|
+
adaptedValue = `0${adaptedValue}`;
|
|
5502
|
+
}
|
|
5503
|
+
return hexToBytes(adaptedValue);
|
|
5504
|
+
}
|
|
7908
5505
|
|
|
7909
5506
|
// src/utils/shortString.ts
|
|
7910
5507
|
var shortString_exports = {};
|
|
@@ -7951,107 +5548,753 @@ var starknet = (() => {
|
|
|
7951
5548
|
if (isHex(str)) {
|
|
7952
5549
|
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
7953
5550
|
}
|
|
7954
|
-
if (isDecimalString(str)) {
|
|
7955
|
-
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
5551
|
+
if (isDecimalString(str)) {
|
|
5552
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
5553
|
+
}
|
|
5554
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
5555
|
+
}
|
|
5556
|
+
|
|
5557
|
+
// src/utils/uint256.ts
|
|
5558
|
+
var uint256_exports = {};
|
|
5559
|
+
__export(uint256_exports, {
|
|
5560
|
+
UINT_128_MAX: () => UINT_128_MAX,
|
|
5561
|
+
UINT_256_MAX: () => UINT_256_MAX,
|
|
5562
|
+
bnToUint256: () => bnToUint256,
|
|
5563
|
+
isUint256: () => isUint256,
|
|
5564
|
+
uint256ToBN: () => uint256ToBN
|
|
5565
|
+
});
|
|
5566
|
+
function uint256ToBN(uint256) {
|
|
5567
|
+
return (toBigInt(uint256.high) << 128n) + toBigInt(uint256.low);
|
|
5568
|
+
}
|
|
5569
|
+
var UINT_128_MAX = (1n << 128n) - 1n;
|
|
5570
|
+
var UINT_256_MAX = (1n << 256n) - 1n;
|
|
5571
|
+
function isUint256(bn) {
|
|
5572
|
+
return toBigInt(bn) <= UINT_256_MAX;
|
|
5573
|
+
}
|
|
5574
|
+
function bnToUint256(bignumber) {
|
|
5575
|
+
const bn = toBigInt(bignumber);
|
|
5576
|
+
if (!isUint256(bn))
|
|
5577
|
+
throw new Error("Number is too large");
|
|
5578
|
+
return {
|
|
5579
|
+
low: addHexPrefix((bn & UINT_128_MAX).toString(16)),
|
|
5580
|
+
high: addHexPrefix((bn >> 128n).toString(16))
|
|
5581
|
+
};
|
|
5582
|
+
}
|
|
5583
|
+
|
|
5584
|
+
// src/utils/calldata/cairo.ts
|
|
5585
|
+
var isLen = (name) => /_len$/.test(name);
|
|
5586
|
+
var isTypeFelt = (type) => type === "felt";
|
|
5587
|
+
var isTypeFeltArray = (type) => type === "felt*";
|
|
5588
|
+
var isTypeArray = (type) => /\*/.test(type);
|
|
5589
|
+
var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
|
|
5590
|
+
var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
|
|
5591
|
+
var isTypeStruct = (type, structs) => type in structs;
|
|
5592
|
+
function felt(it) {
|
|
5593
|
+
if (isBigInt(it) || typeof it === "number" && Number.isInteger(it)) {
|
|
5594
|
+
return it.toString();
|
|
5595
|
+
}
|
|
5596
|
+
if (isText(it)) {
|
|
5597
|
+
if (!isShortString(it))
|
|
5598
|
+
throw new Error(
|
|
5599
|
+
`${it} is a long string > 31 chars, felt can store short strings, split it to array of short strings`
|
|
5600
|
+
);
|
|
5601
|
+
const encoded = encodeShortString(it);
|
|
5602
|
+
return BigInt(encoded).toString();
|
|
5603
|
+
}
|
|
5604
|
+
if (typeof it === "string" && isHex(it)) {
|
|
5605
|
+
return BigInt(it).toString();
|
|
5606
|
+
}
|
|
5607
|
+
if (typeof it === "string" && isStringWholeNumber(it)) {
|
|
5608
|
+
return it;
|
|
5609
|
+
}
|
|
5610
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
5611
|
+
}
|
|
5612
|
+
|
|
5613
|
+
// src/utils/ec.ts
|
|
5614
|
+
var ec_exports = {};
|
|
5615
|
+
__export(ec_exports, {
|
|
5616
|
+
starkCurve: () => esm_exports,
|
|
5617
|
+
weierstrass: () => weierstrass_exports
|
|
5618
|
+
});
|
|
5619
|
+
|
|
5620
|
+
// src/utils/json.ts
|
|
5621
|
+
var json_exports = {};
|
|
5622
|
+
__export(json_exports, {
|
|
5623
|
+
parse: () => parse2,
|
|
5624
|
+
parseAlwaysAsBig: () => parseAlwaysAsBig,
|
|
5625
|
+
stringify: () => stringify2,
|
|
5626
|
+
stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
|
|
5627
|
+
});
|
|
5628
|
+
|
|
5629
|
+
// node_modules/lossless-json/lib/esm/utils.js
|
|
5630
|
+
function isInteger(value) {
|
|
5631
|
+
return INTEGER_REGEX.test(value);
|
|
5632
|
+
}
|
|
5633
|
+
var INTEGER_REGEX = /^-?[0-9]+$/;
|
|
5634
|
+
function isNumber(value) {
|
|
5635
|
+
return NUMBER_REGEX.test(value);
|
|
5636
|
+
}
|
|
5637
|
+
var NUMBER_REGEX = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
|
|
5638
|
+
function isSafeNumber(value, config) {
|
|
5639
|
+
var num = parseFloat(value);
|
|
5640
|
+
var str = String(num);
|
|
5641
|
+
var v = extractSignificantDigits(value);
|
|
5642
|
+
var s = extractSignificantDigits(str);
|
|
5643
|
+
if (v === s) {
|
|
5644
|
+
return true;
|
|
5645
|
+
}
|
|
5646
|
+
if ((config === null || config === void 0 ? void 0 : config.approx) === true) {
|
|
5647
|
+
var requiredDigits = 14;
|
|
5648
|
+
if (!isInteger(value) && s.length >= requiredDigits && v.startsWith(s.substring(0, requiredDigits))) {
|
|
5649
|
+
return true;
|
|
5650
|
+
}
|
|
5651
|
+
}
|
|
5652
|
+
return false;
|
|
5653
|
+
}
|
|
5654
|
+
var UnsafeNumberReason;
|
|
5655
|
+
(function(UnsafeNumberReason2) {
|
|
5656
|
+
UnsafeNumberReason2["underflow"] = "underflow";
|
|
5657
|
+
UnsafeNumberReason2["overflow"] = "overflow";
|
|
5658
|
+
UnsafeNumberReason2["truncate_integer"] = "truncate_integer";
|
|
5659
|
+
UnsafeNumberReason2["truncate_float"] = "truncate_float";
|
|
5660
|
+
})(UnsafeNumberReason || (UnsafeNumberReason = {}));
|
|
5661
|
+
function getUnsafeNumberReason(value) {
|
|
5662
|
+
if (isSafeNumber(value, {
|
|
5663
|
+
approx: false
|
|
5664
|
+
})) {
|
|
5665
|
+
return void 0;
|
|
5666
|
+
}
|
|
5667
|
+
if (isInteger(value)) {
|
|
5668
|
+
return UnsafeNumberReason.truncate_integer;
|
|
5669
|
+
}
|
|
5670
|
+
var num = parseFloat(value);
|
|
5671
|
+
if (!isFinite(num)) {
|
|
5672
|
+
return UnsafeNumberReason.overflow;
|
|
5673
|
+
}
|
|
5674
|
+
if (num === 0) {
|
|
5675
|
+
return UnsafeNumberReason.underflow;
|
|
5676
|
+
}
|
|
5677
|
+
return UnsafeNumberReason.truncate_float;
|
|
5678
|
+
}
|
|
5679
|
+
function extractSignificantDigits(value) {
|
|
5680
|
+
return value.replace(EXPONENTIAL_PART_REGEX, "").replace(DOT_REGEX, "").replace(TRAILING_ZEROS_REGEX, "").replace(LEADING_MINUS_AND_ZEROS_REGEX, "");
|
|
5681
|
+
}
|
|
5682
|
+
var EXPONENTIAL_PART_REGEX = /[eE][+-]?\d+$/;
|
|
5683
|
+
var LEADING_MINUS_AND_ZEROS_REGEX = /^-?(0*)?/;
|
|
5684
|
+
var DOT_REGEX = /\./;
|
|
5685
|
+
var TRAILING_ZEROS_REGEX = /0+$/;
|
|
5686
|
+
|
|
5687
|
+
// node_modules/lossless-json/lib/esm/LosslessNumber.js
|
|
5688
|
+
function _typeof(obj) {
|
|
5689
|
+
"@babel/helpers - typeof";
|
|
5690
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
5691
|
+
return typeof obj2;
|
|
5692
|
+
} : function(obj2) {
|
|
5693
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
5694
|
+
}, _typeof(obj);
|
|
5695
|
+
}
|
|
5696
|
+
function _classCallCheck(instance, Constructor) {
|
|
5697
|
+
if (!(instance instanceof Constructor)) {
|
|
5698
|
+
throw new TypeError("Cannot call a class as a function");
|
|
5699
|
+
}
|
|
5700
|
+
}
|
|
5701
|
+
function _defineProperties(target, props) {
|
|
5702
|
+
for (var i = 0; i < props.length; i++) {
|
|
5703
|
+
var descriptor = props[i];
|
|
5704
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
5705
|
+
descriptor.configurable = true;
|
|
5706
|
+
if ("value" in descriptor)
|
|
5707
|
+
descriptor.writable = true;
|
|
5708
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
5709
|
+
}
|
|
5710
|
+
}
|
|
5711
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
5712
|
+
if (protoProps)
|
|
5713
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
5714
|
+
if (staticProps)
|
|
5715
|
+
_defineProperties(Constructor, staticProps);
|
|
5716
|
+
Object.defineProperty(Constructor, "prototype", { writable: false });
|
|
5717
|
+
return Constructor;
|
|
5718
|
+
}
|
|
5719
|
+
function _defineProperty(obj, key, value) {
|
|
5720
|
+
key = _toPropertyKey(key);
|
|
5721
|
+
if (key in obj) {
|
|
5722
|
+
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
5723
|
+
} else {
|
|
5724
|
+
obj[key] = value;
|
|
5725
|
+
}
|
|
5726
|
+
return obj;
|
|
5727
|
+
}
|
|
5728
|
+
function _toPropertyKey(arg) {
|
|
5729
|
+
var key = _toPrimitive(arg, "string");
|
|
5730
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
5731
|
+
}
|
|
5732
|
+
function _toPrimitive(input, hint) {
|
|
5733
|
+
if (_typeof(input) !== "object" || input === null)
|
|
5734
|
+
return input;
|
|
5735
|
+
var prim = input[Symbol.toPrimitive];
|
|
5736
|
+
if (prim !== void 0) {
|
|
5737
|
+
var res = prim.call(input, hint || "default");
|
|
5738
|
+
if (_typeof(res) !== "object")
|
|
5739
|
+
return res;
|
|
5740
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
5741
|
+
}
|
|
5742
|
+
return (hint === "string" ? String : Number)(input);
|
|
5743
|
+
}
|
|
5744
|
+
var LosslessNumber = /* @__PURE__ */ function() {
|
|
5745
|
+
function LosslessNumber2(value) {
|
|
5746
|
+
_classCallCheck(this, LosslessNumber2);
|
|
5747
|
+
_defineProperty(this, "isLosslessNumber", true);
|
|
5748
|
+
if (!isNumber(value)) {
|
|
5749
|
+
throw new Error('Invalid number (value: "' + value + '")');
|
|
5750
|
+
}
|
|
5751
|
+
this.value = value;
|
|
5752
|
+
}
|
|
5753
|
+
_createClass(LosslessNumber2, [{
|
|
5754
|
+
key: "valueOf",
|
|
5755
|
+
value: function valueOf() {
|
|
5756
|
+
var unsafeReason = getUnsafeNumberReason(this.value);
|
|
5757
|
+
if (unsafeReason === void 0 || unsafeReason === UnsafeNumberReason.truncate_float) {
|
|
5758
|
+
return parseFloat(this.value);
|
|
5759
|
+
}
|
|
5760
|
+
if (isInteger(this.value)) {
|
|
5761
|
+
return BigInt(this.value);
|
|
5762
|
+
}
|
|
5763
|
+
throw new Error("Cannot safely convert to number: " + "the value '".concat(this.value, "' would ").concat(unsafeReason, " and become ").concat(parseFloat(this.value)));
|
|
5764
|
+
}
|
|
5765
|
+
}, {
|
|
5766
|
+
key: "toString",
|
|
5767
|
+
value: function toString2() {
|
|
5768
|
+
return this.value;
|
|
5769
|
+
}
|
|
5770
|
+
}]);
|
|
5771
|
+
return LosslessNumber2;
|
|
5772
|
+
}();
|
|
5773
|
+
function isLosslessNumber(value) {
|
|
5774
|
+
return value && _typeof(value) === "object" && value.isLosslessNumber === true || false;
|
|
5775
|
+
}
|
|
5776
|
+
|
|
5777
|
+
// node_modules/lossless-json/lib/esm/numberParsers.js
|
|
5778
|
+
function parseLosslessNumber(value) {
|
|
5779
|
+
return new LosslessNumber(value);
|
|
5780
|
+
}
|
|
5781
|
+
function parseNumberAndBigInt(value) {
|
|
5782
|
+
return isInteger(value) ? BigInt(value) : parseFloat(value);
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5785
|
+
// node_modules/lossless-json/lib/esm/revive.js
|
|
5786
|
+
function _typeof2(obj) {
|
|
5787
|
+
"@babel/helpers - typeof";
|
|
5788
|
+
return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
5789
|
+
return typeof obj2;
|
|
5790
|
+
} : function(obj2) {
|
|
5791
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
5792
|
+
}, _typeof2(obj);
|
|
5793
|
+
}
|
|
5794
|
+
function revive(json, reviver) {
|
|
5795
|
+
return reviveValue({
|
|
5796
|
+
"": json
|
|
5797
|
+
}, "", json, reviver);
|
|
5798
|
+
}
|
|
5799
|
+
function reviveValue(context, key, value, reviver) {
|
|
5800
|
+
if (Array.isArray(value)) {
|
|
5801
|
+
return reviver.call(context, key, reviveArray(value, reviver));
|
|
5802
|
+
} else if (value && _typeof2(value) === "object" && !isLosslessNumber(value)) {
|
|
5803
|
+
return reviver.call(context, key, reviveObject(value, reviver));
|
|
5804
|
+
} else {
|
|
5805
|
+
return reviver.call(context, key, value);
|
|
5806
|
+
}
|
|
5807
|
+
}
|
|
5808
|
+
function reviveObject(object, reviver) {
|
|
5809
|
+
Object.keys(object).forEach(function(key) {
|
|
5810
|
+
var value = reviveValue(object, key, object[key], reviver);
|
|
5811
|
+
if (value !== void 0) {
|
|
5812
|
+
object[key] = value;
|
|
5813
|
+
} else {
|
|
5814
|
+
delete object[key];
|
|
5815
|
+
}
|
|
5816
|
+
});
|
|
5817
|
+
return object;
|
|
5818
|
+
}
|
|
5819
|
+
function reviveArray(array, reviver) {
|
|
5820
|
+
for (var i = 0; i < array.length; i++) {
|
|
5821
|
+
array[i] = reviveValue(array, i + "", array[i], reviver);
|
|
5822
|
+
}
|
|
5823
|
+
return array;
|
|
5824
|
+
}
|
|
5825
|
+
|
|
5826
|
+
// node_modules/lossless-json/lib/esm/parse.js
|
|
5827
|
+
function _typeof3(obj) {
|
|
5828
|
+
"@babel/helpers - typeof";
|
|
5829
|
+
return _typeof3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
5830
|
+
return typeof obj2;
|
|
5831
|
+
} : function(obj2) {
|
|
5832
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
5833
|
+
}, _typeof3(obj);
|
|
5834
|
+
}
|
|
5835
|
+
function _toConsumableArray(arr) {
|
|
5836
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
5837
|
+
}
|
|
5838
|
+
function _nonIterableSpread() {
|
|
5839
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
5840
|
+
}
|
|
5841
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
5842
|
+
if (!o)
|
|
5843
|
+
return;
|
|
5844
|
+
if (typeof o === "string")
|
|
5845
|
+
return _arrayLikeToArray(o, minLen);
|
|
5846
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
5847
|
+
if (n === "Object" && o.constructor)
|
|
5848
|
+
n = o.constructor.name;
|
|
5849
|
+
if (n === "Map" || n === "Set")
|
|
5850
|
+
return Array.from(o);
|
|
5851
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
5852
|
+
return _arrayLikeToArray(o, minLen);
|
|
5853
|
+
}
|
|
5854
|
+
function _iterableToArray(iter) {
|
|
5855
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
5856
|
+
return Array.from(iter);
|
|
5857
|
+
}
|
|
5858
|
+
function _arrayWithoutHoles(arr) {
|
|
5859
|
+
if (Array.isArray(arr))
|
|
5860
|
+
return _arrayLikeToArray(arr);
|
|
5861
|
+
}
|
|
5862
|
+
function _arrayLikeToArray(arr, len) {
|
|
5863
|
+
if (len == null || len > arr.length)
|
|
5864
|
+
len = arr.length;
|
|
5865
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
5866
|
+
arr2[i] = arr[i];
|
|
5867
|
+
}
|
|
5868
|
+
return arr2;
|
|
5869
|
+
}
|
|
5870
|
+
function parse(text, reviver) {
|
|
5871
|
+
var parseNumber = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : parseLosslessNumber;
|
|
5872
|
+
var i = 0;
|
|
5873
|
+
var value = parseValue();
|
|
5874
|
+
expectValue(value);
|
|
5875
|
+
expectEndOfInput();
|
|
5876
|
+
return reviver ? revive(value, reviver) : value;
|
|
5877
|
+
function parseObject() {
|
|
5878
|
+
if (text.charCodeAt(i) === codeOpeningBrace) {
|
|
5879
|
+
i++;
|
|
5880
|
+
skipWhitespace();
|
|
5881
|
+
var object = {};
|
|
5882
|
+
var initial = true;
|
|
5883
|
+
while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
|
|
5884
|
+
if (!initial) {
|
|
5885
|
+
eatComma();
|
|
5886
|
+
skipWhitespace();
|
|
5887
|
+
} else {
|
|
5888
|
+
initial = false;
|
|
5889
|
+
}
|
|
5890
|
+
var start = i;
|
|
5891
|
+
var key = parseString();
|
|
5892
|
+
if (key === void 0) {
|
|
5893
|
+
throwObjectKeyExpected();
|
|
5894
|
+
}
|
|
5895
|
+
skipWhitespace();
|
|
5896
|
+
eatColon();
|
|
5897
|
+
var _value = parseValue();
|
|
5898
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && !isDeepEqual(_value, object[key])) {
|
|
5899
|
+
throwDuplicateKey(key, start + 1);
|
|
5900
|
+
}
|
|
5901
|
+
object[key] = _value;
|
|
5902
|
+
}
|
|
5903
|
+
if (text.charCodeAt(i) !== codeClosingBrace) {
|
|
5904
|
+
throwObjectKeyOrEndExpected();
|
|
5905
|
+
}
|
|
5906
|
+
i++;
|
|
5907
|
+
return object;
|
|
5908
|
+
}
|
|
5909
|
+
}
|
|
5910
|
+
function parseArray() {
|
|
5911
|
+
if (text.charCodeAt(i) === codeOpeningBracket) {
|
|
5912
|
+
i++;
|
|
5913
|
+
skipWhitespace();
|
|
5914
|
+
var array = [];
|
|
5915
|
+
var initial = true;
|
|
5916
|
+
while (i < text.length && text.charCodeAt(i) !== codeClosingBracket) {
|
|
5917
|
+
if (!initial) {
|
|
5918
|
+
eatComma();
|
|
5919
|
+
} else {
|
|
5920
|
+
initial = false;
|
|
5921
|
+
}
|
|
5922
|
+
var _value2 = parseValue();
|
|
5923
|
+
expectArrayItem(_value2);
|
|
5924
|
+
array.push(_value2);
|
|
5925
|
+
}
|
|
5926
|
+
if (text.charCodeAt(i) !== codeClosingBracket) {
|
|
5927
|
+
throwArrayItemOrEndExpected();
|
|
5928
|
+
}
|
|
5929
|
+
i++;
|
|
5930
|
+
return array;
|
|
5931
|
+
}
|
|
5932
|
+
}
|
|
5933
|
+
function parseValue() {
|
|
5934
|
+
var _ref, _ref2, _ref3, _ref4, _ref5, _parseString;
|
|
5935
|
+
skipWhitespace();
|
|
5936
|
+
var value2 = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_parseString = parseString()) !== null && _parseString !== void 0 ? _parseString : parseNumeric()) !== null && _ref5 !== void 0 ? _ref5 : parseObject()) !== null && _ref4 !== void 0 ? _ref4 : parseArray()) !== null && _ref3 !== void 0 ? _ref3 : parseKeyword("true", true)) !== null && _ref2 !== void 0 ? _ref2 : parseKeyword("false", false)) !== null && _ref !== void 0 ? _ref : parseKeyword("null", null);
|
|
5937
|
+
skipWhitespace();
|
|
5938
|
+
return value2;
|
|
5939
|
+
}
|
|
5940
|
+
function parseKeyword(name, value2) {
|
|
5941
|
+
if (text.slice(i, i + name.length) === name) {
|
|
5942
|
+
i += name.length;
|
|
5943
|
+
return value2;
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
function skipWhitespace() {
|
|
5947
|
+
while (isWhitespace(text.charCodeAt(i))) {
|
|
5948
|
+
i++;
|
|
5949
|
+
}
|
|
5950
|
+
}
|
|
5951
|
+
function parseString() {
|
|
5952
|
+
if (text.charCodeAt(i) === codeDoubleQuote) {
|
|
5953
|
+
i++;
|
|
5954
|
+
var result = "";
|
|
5955
|
+
while (i < text.length && text.charCodeAt(i) !== codeDoubleQuote) {
|
|
5956
|
+
if (text.charCodeAt(i) === codeBackslash) {
|
|
5957
|
+
var char = text[i + 1];
|
|
5958
|
+
var escapeChar = escapeCharacters[char];
|
|
5959
|
+
if (escapeChar !== void 0) {
|
|
5960
|
+
result += escapeChar;
|
|
5961
|
+
i++;
|
|
5962
|
+
} else if (char === "u") {
|
|
5963
|
+
if (isHex2(text.charCodeAt(i + 2)) && isHex2(text.charCodeAt(i + 3)) && isHex2(text.charCodeAt(i + 4)) && isHex2(text.charCodeAt(i + 5))) {
|
|
5964
|
+
result += String.fromCharCode(parseInt(text.slice(i + 2, i + 6), 16));
|
|
5965
|
+
i += 5;
|
|
5966
|
+
} else {
|
|
5967
|
+
throwInvalidUnicodeCharacter(i);
|
|
5968
|
+
}
|
|
5969
|
+
} else {
|
|
5970
|
+
throwInvalidEscapeCharacter(i);
|
|
5971
|
+
}
|
|
5972
|
+
} else {
|
|
5973
|
+
if (isValidStringCharacter(text.charCodeAt(i))) {
|
|
5974
|
+
result += text[i];
|
|
5975
|
+
} else {
|
|
5976
|
+
throwInvalidCharacter(text[i]);
|
|
5977
|
+
}
|
|
5978
|
+
}
|
|
5979
|
+
i++;
|
|
5980
|
+
}
|
|
5981
|
+
expectEndOfString();
|
|
5982
|
+
i++;
|
|
5983
|
+
return result;
|
|
5984
|
+
}
|
|
5985
|
+
}
|
|
5986
|
+
function parseNumeric() {
|
|
5987
|
+
var start = i;
|
|
5988
|
+
if (text.charCodeAt(i) === codeMinus) {
|
|
5989
|
+
i++;
|
|
5990
|
+
expectDigit(start);
|
|
5991
|
+
}
|
|
5992
|
+
if (text.charCodeAt(i) === codeZero) {
|
|
5993
|
+
i++;
|
|
5994
|
+
} else if (isNonZeroDigit(text.charCodeAt(i))) {
|
|
5995
|
+
i++;
|
|
5996
|
+
while (isDigit(text.charCodeAt(i))) {
|
|
5997
|
+
i++;
|
|
5998
|
+
}
|
|
5999
|
+
}
|
|
6000
|
+
if (text.charCodeAt(i) === codeDot) {
|
|
6001
|
+
i++;
|
|
6002
|
+
expectDigit(start);
|
|
6003
|
+
while (isDigit(text.charCodeAt(i))) {
|
|
6004
|
+
i++;
|
|
6005
|
+
}
|
|
6006
|
+
}
|
|
6007
|
+
if (text.charCodeAt(i) === codeLowercaseE || text.charCodeAt(i) === codeUppercaseE) {
|
|
6008
|
+
i++;
|
|
6009
|
+
if (text.charCodeAt(i) === codeMinus || text.charCodeAt(i) === codePlus) {
|
|
6010
|
+
i++;
|
|
6011
|
+
}
|
|
6012
|
+
expectDigit(start);
|
|
6013
|
+
while (isDigit(text.charCodeAt(i))) {
|
|
6014
|
+
i++;
|
|
6015
|
+
}
|
|
6016
|
+
}
|
|
6017
|
+
if (i > start) {
|
|
6018
|
+
return parseNumber(text.slice(start, i));
|
|
6019
|
+
}
|
|
6020
|
+
}
|
|
6021
|
+
function eatComma() {
|
|
6022
|
+
if (text.charCodeAt(i) !== codeComma) {
|
|
6023
|
+
throw new SyntaxError("Comma ',' expected after value ".concat(gotAt()));
|
|
6024
|
+
}
|
|
6025
|
+
i++;
|
|
6026
|
+
}
|
|
6027
|
+
function eatColon() {
|
|
6028
|
+
if (text.charCodeAt(i) !== codeColon) {
|
|
6029
|
+
throw new SyntaxError("Colon ':' expected after property name ".concat(gotAt()));
|
|
6030
|
+
}
|
|
6031
|
+
i++;
|
|
6032
|
+
}
|
|
6033
|
+
function expectValue(value2) {
|
|
6034
|
+
if (value2 === void 0) {
|
|
6035
|
+
throw new SyntaxError("JSON value expected ".concat(gotAt()));
|
|
6036
|
+
}
|
|
6037
|
+
}
|
|
6038
|
+
function expectArrayItem(value2) {
|
|
6039
|
+
if (value2 === void 0) {
|
|
6040
|
+
throw new SyntaxError("Array item expected ".concat(gotAt()));
|
|
6041
|
+
}
|
|
6042
|
+
}
|
|
6043
|
+
function expectEndOfInput() {
|
|
6044
|
+
if (i < text.length) {
|
|
6045
|
+
throw new SyntaxError("Expected end of input ".concat(gotAt()));
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
6048
|
+
function expectDigit(start) {
|
|
6049
|
+
if (!isDigit(text.charCodeAt(i))) {
|
|
6050
|
+
var numSoFar = text.slice(start, i);
|
|
6051
|
+
throw new SyntaxError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(gotAt()));
|
|
6052
|
+
}
|
|
6053
|
+
}
|
|
6054
|
+
function expectEndOfString() {
|
|
6055
|
+
if (text.charCodeAt(i) !== codeDoubleQuote) {
|
|
6056
|
+
throw new SyntaxError(`End of string '"' expected `.concat(gotAt()));
|
|
6057
|
+
}
|
|
6058
|
+
}
|
|
6059
|
+
function throwObjectKeyExpected() {
|
|
6060
|
+
throw new SyntaxError("Quoted object key expected ".concat(gotAt()));
|
|
6061
|
+
}
|
|
6062
|
+
function throwDuplicateKey(key, pos2) {
|
|
6063
|
+
throw new SyntaxError("Duplicate key '".concat(key, "' encountered at position ").concat(pos2));
|
|
6064
|
+
}
|
|
6065
|
+
function throwObjectKeyOrEndExpected() {
|
|
6066
|
+
throw new SyntaxError("Quoted object key or end of object '}' expected ".concat(gotAt()));
|
|
6067
|
+
}
|
|
6068
|
+
function throwArrayItemOrEndExpected() {
|
|
6069
|
+
throw new SyntaxError("Array item or end of array ']' expected ".concat(gotAt()));
|
|
6070
|
+
}
|
|
6071
|
+
function throwInvalidCharacter(char) {
|
|
6072
|
+
throw new SyntaxError("Invalid character '".concat(char, "' ").concat(pos()));
|
|
6073
|
+
}
|
|
6074
|
+
function throwInvalidEscapeCharacter(start) {
|
|
6075
|
+
var chars = text.slice(start, start + 2);
|
|
6076
|
+
throw new SyntaxError("Invalid escape character '".concat(chars, "' ").concat(pos()));
|
|
6077
|
+
}
|
|
6078
|
+
function throwInvalidUnicodeCharacter(start) {
|
|
6079
|
+
var end = start + 2;
|
|
6080
|
+
while (/\w/.test(text[end])) {
|
|
6081
|
+
end++;
|
|
6082
|
+
}
|
|
6083
|
+
var chars = text.slice(start, end);
|
|
6084
|
+
throw new SyntaxError("Invalid unicode character '".concat(chars, "' ").concat(pos()));
|
|
6085
|
+
}
|
|
6086
|
+
function pos() {
|
|
6087
|
+
return "at position ".concat(i);
|
|
6088
|
+
}
|
|
6089
|
+
function got() {
|
|
6090
|
+
return i < text.length ? "but got '".concat(text[i], "'") : "but reached end of input";
|
|
6091
|
+
}
|
|
6092
|
+
function gotAt() {
|
|
6093
|
+
return got() + " " + pos();
|
|
7956
6094
|
}
|
|
7957
|
-
throw new Error(`${str} is not Hex or decimal`);
|
|
7958
6095
|
}
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
var uint256_exports = {};
|
|
7962
|
-
__export(uint256_exports, {
|
|
7963
|
-
UINT_128_MAX: () => UINT_128_MAX,
|
|
7964
|
-
UINT_256_MAX: () => UINT_256_MAX,
|
|
7965
|
-
bnToUint256: () => bnToUint256,
|
|
7966
|
-
isUint256: () => isUint256,
|
|
7967
|
-
uint256ToBN: () => uint256ToBN
|
|
7968
|
-
});
|
|
7969
|
-
function uint256ToBN(uint256) {
|
|
7970
|
-
return (toBigInt(uint256.high) << 128n) + toBigInt(uint256.low);
|
|
6096
|
+
function isWhitespace(code) {
|
|
6097
|
+
return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
|
|
7971
6098
|
}
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
function isUint256(bn) {
|
|
7975
|
-
return toBigInt(bn) <= UINT_256_MAX;
|
|
6099
|
+
function isHex2(code) {
|
|
6100
|
+
return code >= codeZero && code <= codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF;
|
|
7976
6101
|
}
|
|
7977
|
-
function
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
return
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
6102
|
+
function isDigit(code) {
|
|
6103
|
+
return code >= codeZero && code <= codeNine;
|
|
6104
|
+
}
|
|
6105
|
+
function isNonZeroDigit(code) {
|
|
6106
|
+
return code >= codeOne && code <= codeNine;
|
|
6107
|
+
}
|
|
6108
|
+
function isValidStringCharacter(code) {
|
|
6109
|
+
return code >= 32 && code <= 1114111;
|
|
6110
|
+
}
|
|
6111
|
+
function isDeepEqual(a, b) {
|
|
6112
|
+
if (a === b) {
|
|
6113
|
+
return true;
|
|
6114
|
+
}
|
|
6115
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
6116
|
+
return a.length === b.length && a.every(function(item, index) {
|
|
6117
|
+
return isDeepEqual(item, b[index]);
|
|
6118
|
+
});
|
|
6119
|
+
}
|
|
6120
|
+
if (isObject(a) && isObject(b)) {
|
|
6121
|
+
var keys = _toConsumableArray(new Set([].concat(_toConsumableArray(Object.keys(a)), _toConsumableArray(Object.keys(b)))));
|
|
6122
|
+
return keys.every(function(key) {
|
|
6123
|
+
return isDeepEqual(a[key], b[key]);
|
|
6124
|
+
});
|
|
6125
|
+
}
|
|
6126
|
+
return false;
|
|
7985
6127
|
}
|
|
6128
|
+
function isObject(value) {
|
|
6129
|
+
return _typeof3(value) === "object" && value !== null;
|
|
6130
|
+
}
|
|
6131
|
+
var escapeCharacters = {
|
|
6132
|
+
'"': '"',
|
|
6133
|
+
"\\": "\\",
|
|
6134
|
+
"/": "/",
|
|
6135
|
+
b: "\b",
|
|
6136
|
+
f: "\f",
|
|
6137
|
+
n: "\n",
|
|
6138
|
+
r: "\r",
|
|
6139
|
+
t: " "
|
|
6140
|
+
};
|
|
6141
|
+
var codeBackslash = 92;
|
|
6142
|
+
var codeOpeningBrace = 123;
|
|
6143
|
+
var codeClosingBrace = 125;
|
|
6144
|
+
var codeOpeningBracket = 91;
|
|
6145
|
+
var codeClosingBracket = 93;
|
|
6146
|
+
var codeSpace = 32;
|
|
6147
|
+
var codeNewline = 10;
|
|
6148
|
+
var codeTab = 9;
|
|
6149
|
+
var codeReturn = 13;
|
|
6150
|
+
var codeDoubleQuote = 34;
|
|
6151
|
+
var codePlus = 43;
|
|
6152
|
+
var codeMinus = 45;
|
|
6153
|
+
var codeZero = 48;
|
|
6154
|
+
var codeOne = 49;
|
|
6155
|
+
var codeNine = 57;
|
|
6156
|
+
var codeComma = 44;
|
|
6157
|
+
var codeDot = 46;
|
|
6158
|
+
var codeColon = 58;
|
|
6159
|
+
var codeUppercaseA = 65;
|
|
6160
|
+
var codeLowercaseA = 97;
|
|
6161
|
+
var codeUppercaseE = 69;
|
|
6162
|
+
var codeLowercaseE = 101;
|
|
6163
|
+
var codeUppercaseF = 70;
|
|
6164
|
+
var codeLowercaseF = 102;
|
|
7986
6165
|
|
|
7987
|
-
//
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
6166
|
+
// node_modules/lossless-json/lib/esm/stringify.js
|
|
6167
|
+
function _typeof4(obj) {
|
|
6168
|
+
"@babel/helpers - typeof";
|
|
6169
|
+
return _typeof4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
6170
|
+
return typeof obj2;
|
|
6171
|
+
} : function(obj2) {
|
|
6172
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
6173
|
+
}, _typeof4(obj);
|
|
6174
|
+
}
|
|
6175
|
+
function stringify(value, replacer, space, numberStringifiers) {
|
|
6176
|
+
var resolvedSpace = resolveSpace(space);
|
|
6177
|
+
var replacedValue = typeof replacer === "function" ? replacer.call({
|
|
6178
|
+
"": value
|
|
6179
|
+
}, "", value) : value;
|
|
6180
|
+
return stringifyValue(replacedValue, "");
|
|
6181
|
+
function stringifyValue(value2, indent) {
|
|
6182
|
+
if (Array.isArray(numberStringifiers)) {
|
|
6183
|
+
var stringifier = numberStringifiers.find(function(item) {
|
|
6184
|
+
return item.test(value2);
|
|
6185
|
+
});
|
|
6186
|
+
if (stringifier) {
|
|
6187
|
+
var str = stringifier.stringify(value2);
|
|
6188
|
+
if (typeof str !== "string" || !isNumber(str)) {
|
|
6189
|
+
throw new Error("Invalid JSON number: output of a number stringifier must be a string containing a JSON number " + "(output: ".concat(str, ")"));
|
|
6190
|
+
}
|
|
6191
|
+
return str;
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
if (typeof value2 === "boolean" || typeof value2 === "number" || typeof value2 === "string" || value2 === null || value2 instanceof Date || value2 instanceof Boolean || value2 instanceof Number || value2 instanceof String) {
|
|
6195
|
+
return JSON.stringify(value2);
|
|
6196
|
+
}
|
|
6197
|
+
if (value2 && value2.isLosslessNumber) {
|
|
6198
|
+
return value2.toString();
|
|
6199
|
+
}
|
|
6200
|
+
if (typeof value2 === "bigint") {
|
|
6201
|
+
return value2.toString();
|
|
6202
|
+
}
|
|
6203
|
+
if (Array.isArray(value2)) {
|
|
6204
|
+
return stringifyArray(value2, indent);
|
|
6205
|
+
}
|
|
6206
|
+
if (value2 && _typeof4(value2) === "object") {
|
|
6207
|
+
return stringifyObject(value2, indent);
|
|
6208
|
+
}
|
|
6209
|
+
return void 0;
|
|
7998
6210
|
}
|
|
7999
|
-
|
|
8000
|
-
if (
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
6211
|
+
function stringifyArray(array, indent) {
|
|
6212
|
+
if (array.length === 0) {
|
|
6213
|
+
return "[]";
|
|
6214
|
+
}
|
|
6215
|
+
var childIndent = resolvedSpace ? indent + resolvedSpace : void 0;
|
|
6216
|
+
var str = resolvedSpace ? "[\n" : "[";
|
|
6217
|
+
for (var i = 0; i < array.length; i++) {
|
|
6218
|
+
var item = typeof replacer === "function" ? replacer.call(array, String(i), array[i]) : array[i];
|
|
6219
|
+
if (resolvedSpace) {
|
|
6220
|
+
str += childIndent;
|
|
6221
|
+
}
|
|
6222
|
+
if (typeof item !== "undefined" && typeof item !== "function") {
|
|
6223
|
+
str += stringifyValue(item, childIndent);
|
|
6224
|
+
} else {
|
|
6225
|
+
str += "null";
|
|
6226
|
+
}
|
|
6227
|
+
if (i < array.length - 1) {
|
|
6228
|
+
str += resolvedSpace ? ",\n" : ",";
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
str += resolvedSpace ? "\n" + indent + "]" : "]";
|
|
6232
|
+
return str;
|
|
8006
6233
|
}
|
|
8007
|
-
|
|
8008
|
-
|
|
6234
|
+
function stringifyObject(object, indent) {
|
|
6235
|
+
if (typeof object.toJSON === "function") {
|
|
6236
|
+
return stringify(object.toJSON(), replacer, space, void 0);
|
|
6237
|
+
}
|
|
6238
|
+
var keys = Array.isArray(replacer) ? replacer.map(String) : Object.keys(object);
|
|
6239
|
+
if (keys.length === 0) {
|
|
6240
|
+
return "{}";
|
|
6241
|
+
}
|
|
6242
|
+
var childIndent = resolvedSpace ? indent + resolvedSpace : void 0;
|
|
6243
|
+
var first = true;
|
|
6244
|
+
var str = resolvedSpace ? "{\n" : "{";
|
|
6245
|
+
keys.forEach(function(key) {
|
|
6246
|
+
var value2 = typeof replacer === "function" ? replacer.call(object, key, object[key]) : object[key];
|
|
6247
|
+
if (includeProperty(key, value2)) {
|
|
6248
|
+
if (first) {
|
|
6249
|
+
first = false;
|
|
6250
|
+
} else {
|
|
6251
|
+
str += resolvedSpace ? ",\n" : ",";
|
|
6252
|
+
}
|
|
6253
|
+
var keyStr = JSON.stringify(key);
|
|
6254
|
+
str += resolvedSpace ? childIndent + keyStr + ": " : keyStr + ":";
|
|
6255
|
+
str += stringifyValue(value2, childIndent);
|
|
6256
|
+
}
|
|
6257
|
+
});
|
|
6258
|
+
str += resolvedSpace ? "\n" + indent + "}" : "}";
|
|
6259
|
+
return str;
|
|
8009
6260
|
}
|
|
8010
|
-
|
|
8011
|
-
return
|
|
6261
|
+
function includeProperty(key, value2) {
|
|
6262
|
+
return typeof value2 !== "undefined" && typeof value2 !== "function" && _typeof4(value2) !== "symbol";
|
|
8012
6263
|
}
|
|
8013
|
-
throw new Error(`${it} can't be computed by felt()`);
|
|
8014
6264
|
}
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
6265
|
+
function resolveSpace(space) {
|
|
6266
|
+
if (typeof space === "number") {
|
|
6267
|
+
return " ".repeat(space);
|
|
6268
|
+
}
|
|
6269
|
+
if (typeof space === "string" && space !== "") {
|
|
6270
|
+
return space;
|
|
6271
|
+
}
|
|
6272
|
+
return void 0;
|
|
6273
|
+
}
|
|
8022
6274
|
|
|
8023
6275
|
// src/utils/json.ts
|
|
8024
|
-
var
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
|
|
8030
|
-
|
|
8031
|
-
|
|
8032
|
-
var
|
|
8033
|
-
var
|
|
8034
|
-
return (0, import_json_bigint.default)({
|
|
8035
|
-
alwaysParseAsBig,
|
|
8036
|
-
useNativeBigInt: true,
|
|
8037
|
-
protoAction: "preserve",
|
|
8038
|
-
constructorAction: "preserve"
|
|
8039
|
-
});
|
|
8040
|
-
};
|
|
8041
|
-
var { parse, stringify } = json(false);
|
|
8042
|
-
var { parse: parseAlwaysAsBig, stringify: stringifyAlwaysAsBig } = json(true);
|
|
8043
|
-
var json_default = { parse, stringify };
|
|
6276
|
+
var parseIntAsNumberOrBigInt = (x) => {
|
|
6277
|
+
if (!isInteger(x))
|
|
6278
|
+
return parseFloat(x);
|
|
6279
|
+
const v = parseInt(x, 10);
|
|
6280
|
+
return Number.isSafeInteger(v) ? v : BigInt(x);
|
|
6281
|
+
};
|
|
6282
|
+
var parse2 = (x) => parse(String(x), null, parseIntAsNumberOrBigInt);
|
|
6283
|
+
var parseAlwaysAsBig = (x) => parse(String(x), null, parseNumberAndBigInt);
|
|
6284
|
+
var stringify2 = (...p) => stringify(...p);
|
|
6285
|
+
var stringifyAlwaysAsBig = stringify2;
|
|
8044
6286
|
|
|
8045
6287
|
// src/utils/hash.ts
|
|
8046
6288
|
var transactionVersion = 1n;
|
|
6289
|
+
var transactionVersion_2 = 2n;
|
|
8047
6290
|
var feeTransactionVersion = 2n ** 128n + transactionVersion;
|
|
8048
6291
|
function keccakBn(value) {
|
|
8049
6292
|
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
8050
6293
|
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
8051
|
-
return addHexPrefix(
|
|
6294
|
+
return addHexPrefix(keccak(hexToBytes2(addHexPrefix(evenHex))).toString(16));
|
|
8052
6295
|
}
|
|
8053
6296
|
function keccakHex(value) {
|
|
8054
|
-
return addHexPrefix(
|
|
6297
|
+
return addHexPrefix(keccak(utf8ToArray(value)).toString(16));
|
|
8055
6298
|
}
|
|
8056
6299
|
function starknetKeccak(value) {
|
|
8057
6300
|
const hash2 = BigInt(keccakHex(value));
|
|
@@ -8097,7 +6340,7 @@ var starknet = (() => {
|
|
|
8097
6340
|
chainId
|
|
8098
6341
|
);
|
|
8099
6342
|
}
|
|
8100
|
-
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce) {
|
|
6343
|
+
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
8101
6344
|
return calculateTransactionHashCommon(
|
|
8102
6345
|
"0x6465636c617265" /* DECLARE */,
|
|
8103
6346
|
version,
|
|
@@ -8106,7 +6349,7 @@ var starknet = (() => {
|
|
|
8106
6349
|
[classHash],
|
|
8107
6350
|
maxFee,
|
|
8108
6351
|
chainId,
|
|
8109
|
-
[nonce]
|
|
6352
|
+
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
8110
6353
|
);
|
|
8111
6354
|
}
|
|
8112
6355
|
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
@@ -8154,10 +6397,10 @@ var starknet = (() => {
|
|
|
8154
6397
|
}
|
|
8155
6398
|
return value === null ? void 0 : value;
|
|
8156
6399
|
}
|
|
8157
|
-
function formatSpaces(
|
|
6400
|
+
function formatSpaces(json) {
|
|
8158
6401
|
let insideQuotes = false;
|
|
8159
6402
|
let newString = "";
|
|
8160
|
-
for (const char of
|
|
6403
|
+
for (const char of json) {
|
|
8161
6404
|
if (char === '"' && newString.endsWith("\\") === false) {
|
|
8162
6405
|
insideQuotes = !insideQuotes;
|
|
8163
6406
|
}
|
|
@@ -8172,11 +6415,11 @@ var starknet = (() => {
|
|
|
8172
6415
|
function computeHintedClassHash(compiledContract) {
|
|
8173
6416
|
const { abi, program } = compiledContract;
|
|
8174
6417
|
const contractClass = { abi, program };
|
|
8175
|
-
const serializedJson = formatSpaces(
|
|
6418
|
+
const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
|
|
8176
6419
|
return addHexPrefix(esm_exports.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
8177
6420
|
}
|
|
8178
6421
|
function computeLegacyContractClassHash(contract) {
|
|
8179
|
-
const compiledContract = typeof contract === "string" ?
|
|
6422
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
8180
6423
|
const apiVersion = toHex(API_VERSION);
|
|
8181
6424
|
const externalEntryPointsHash = computeHashOnElements2(
|
|
8182
6425
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
@@ -8215,36 +6458,12 @@ var starknet = (() => {
|
|
|
8215
6458
|
});
|
|
8216
6459
|
return poseidonHashMany(base);
|
|
8217
6460
|
}
|
|
8218
|
-
function parseHints(hints) {
|
|
8219
|
-
return hints.reduce((cum, [hint_id, hint_codes]) => {
|
|
8220
|
-
cum[hint_id] = hint_codes.map((it) => ({
|
|
8221
|
-
code: it,
|
|
8222
|
-
accessible_scopes: [],
|
|
8223
|
-
flow_tracking_data: { ap_tracking: { group: 0, offset: 0 }, reference_ids: {} }
|
|
8224
|
-
}));
|
|
8225
|
-
return cum;
|
|
8226
|
-
}, {});
|
|
8227
|
-
}
|
|
8228
|
-
function hintedProgram(casm) {
|
|
8229
|
-
const sortedHintedProgram = (0, import_json_keys_sort.sort)({
|
|
8230
|
-
program: {
|
|
8231
|
-
prime: casm.prime,
|
|
8232
|
-
data: casm.bytecode,
|
|
8233
|
-
builtins: [],
|
|
8234
|
-
hints: parseHints(casm.hints),
|
|
8235
|
-
compiler_version: casm.compiler_version
|
|
8236
|
-
}
|
|
8237
|
-
});
|
|
8238
|
-
const serialized = formatSpaces(stringify(sortedHintedProgram));
|
|
8239
|
-
return BigInt(addHexPrefix(esm_exports.keccak(utf8ToArray(serialized)).toString(16)));
|
|
8240
|
-
}
|
|
8241
6461
|
function computeCompiledClassHash(casm) {
|
|
8242
6462
|
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
8243
6463
|
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
8244
6464
|
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
8245
6465
|
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
8246
6466
|
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
8247
|
-
const hintedCompiledClassHash = hintedProgram(casm);
|
|
8248
6467
|
const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
8249
6468
|
return toHex(
|
|
8250
6469
|
poseidonHashMany([
|
|
@@ -8252,29 +6471,28 @@ var starknet = (() => {
|
|
|
8252
6471
|
externalEntryPointsHash,
|
|
8253
6472
|
l1Handlers,
|
|
8254
6473
|
constructor,
|
|
8255
|
-
hintedCompiledClassHash,
|
|
8256
6474
|
bytecode
|
|
8257
6475
|
])
|
|
8258
6476
|
);
|
|
8259
6477
|
}
|
|
8260
|
-
function
|
|
6478
|
+
function hashEntryPointSierra(data) {
|
|
8261
6479
|
const base = data.flatMap((it) => {
|
|
8262
6480
|
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
8263
6481
|
});
|
|
8264
6482
|
return poseidonHashMany(base);
|
|
8265
6483
|
}
|
|
8266
|
-
function hashAbi(
|
|
8267
|
-
const indentString =
|
|
6484
|
+
function hashAbi(sierra) {
|
|
6485
|
+
const indentString = formatSpaces(stringify2(sierra.abi, null));
|
|
8268
6486
|
return BigInt(addHexPrefix(esm_exports.keccak(utf8ToArray(indentString)).toString(16)));
|
|
8269
6487
|
}
|
|
8270
|
-
function
|
|
6488
|
+
function computeSierraContractClassHash(sierra) {
|
|
8271
6489
|
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
8272
6490
|
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
8273
|
-
const externalEntryPointsHash =
|
|
8274
|
-
const l1Handlers =
|
|
8275
|
-
const constructor =
|
|
8276
|
-
const abiHash = hashAbi(
|
|
8277
|
-
const
|
|
6491
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
6492
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
6493
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
6494
|
+
const abiHash = hashAbi(sierra);
|
|
6495
|
+
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
8278
6496
|
return toHex(
|
|
8279
6497
|
poseidonHashMany([
|
|
8280
6498
|
compiledClassVersion,
|
|
@@ -8282,18 +6500,40 @@ var starknet = (() => {
|
|
|
8282
6500
|
l1Handlers,
|
|
8283
6501
|
constructor,
|
|
8284
6502
|
abiHash,
|
|
8285
|
-
|
|
6503
|
+
sierraProgram
|
|
8286
6504
|
])
|
|
8287
6505
|
);
|
|
8288
6506
|
}
|
|
8289
6507
|
function computeContractClassHash(contract) {
|
|
8290
|
-
const compiledContract = typeof contract === "string" ?
|
|
6508
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
8291
6509
|
if ("sierra_program" in compiledContract) {
|
|
8292
|
-
return
|
|
6510
|
+
return computeSierraContractClassHash(compiledContract);
|
|
8293
6511
|
}
|
|
8294
6512
|
return computeLegacyContractClassHash(compiledContract);
|
|
8295
6513
|
}
|
|
8296
6514
|
|
|
6515
|
+
// src/utils/contract.ts
|
|
6516
|
+
function isSierra(contract) {
|
|
6517
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
6518
|
+
return "sierra_program" in compiledContract;
|
|
6519
|
+
}
|
|
6520
|
+
function extractContractHashes(payload) {
|
|
6521
|
+
const response = { ...payload };
|
|
6522
|
+
if (isSierra(payload.contract)) {
|
|
6523
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
6524
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
6525
|
+
}
|
|
6526
|
+
if (!response.compiledClassHash)
|
|
6527
|
+
throw new Error(
|
|
6528
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
6529
|
+
);
|
|
6530
|
+
}
|
|
6531
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
6532
|
+
if (!response.classHash)
|
|
6533
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
6534
|
+
return response;
|
|
6535
|
+
}
|
|
6536
|
+
|
|
8297
6537
|
// src/utils/stark.ts
|
|
8298
6538
|
var stark_exports = {};
|
|
8299
6539
|
__export(stark_exports, {
|
|
@@ -12384,7 +10624,7 @@ var starknet = (() => {
|
|
|
12384
10624
|
|
|
12385
10625
|
// src/utils/stark.ts
|
|
12386
10626
|
function compressProgram(jsonProgram) {
|
|
12387
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram :
|
|
10627
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
12388
10628
|
const compressedProgram = gzip_1(stringified);
|
|
12389
10629
|
return btoaUniversal(compressedProgram);
|
|
12390
10630
|
}
|
|
@@ -12451,12 +10691,23 @@ var starknet = (() => {
|
|
|
12451
10691
|
return toHex(data);
|
|
12452
10692
|
});
|
|
12453
10693
|
}
|
|
10694
|
+
function createSierraContractClass(contract) {
|
|
10695
|
+
const result = { ...contract };
|
|
10696
|
+
delete result.sierra_program_debug_info;
|
|
10697
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
10698
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
10699
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
10700
|
+
return result;
|
|
10701
|
+
}
|
|
12454
10702
|
function parseContract(contract) {
|
|
12455
|
-
const parsedContract = typeof contract === "string" ?
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
10703
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
10704
|
+
if (!isSierra(contract)) {
|
|
10705
|
+
return {
|
|
10706
|
+
...parsedContract,
|
|
10707
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
10708
|
+
};
|
|
10709
|
+
}
|
|
10710
|
+
return createSierraContractClass(parsedContract);
|
|
12460
10711
|
}
|
|
12461
10712
|
|
|
12462
10713
|
// src/utils/responseParser/rpc.ts
|
|
@@ -12476,6 +10727,7 @@ var starknet = (() => {
|
|
|
12476
10727
|
return {
|
|
12477
10728
|
calldata: res.calldata || [],
|
|
12478
10729
|
contract_address: res.contract_address,
|
|
10730
|
+
sender_address: res.contract_address,
|
|
12479
10731
|
max_fee: res.max_fee,
|
|
12480
10732
|
nonce: res.nonce,
|
|
12481
10733
|
signature: res.signature || [],
|
|
@@ -12497,61 +10749,9 @@ var starknet = (() => {
|
|
|
12497
10749
|
}
|
|
12498
10750
|
};
|
|
12499
10751
|
|
|
12500
|
-
// node_modules/ts-custom-error/dist/custom-error.mjs
|
|
12501
|
-
function fixProto(target, prototype) {
|
|
12502
|
-
var setPrototypeOf = Object.setPrototypeOf;
|
|
12503
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
12504
|
-
}
|
|
12505
|
-
function fixStack(target, fn) {
|
|
12506
|
-
if (fn === void 0) {
|
|
12507
|
-
fn = target.constructor;
|
|
12508
|
-
}
|
|
12509
|
-
var captureStackTrace = Error.captureStackTrace;
|
|
12510
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
12511
|
-
}
|
|
12512
|
-
var __extends = function() {
|
|
12513
|
-
var _extendStatics = function extendStatics(d, b) {
|
|
12514
|
-
_extendStatics = Object.setPrototypeOf || {
|
|
12515
|
-
__proto__: []
|
|
12516
|
-
} instanceof Array && function(d2, b2) {
|
|
12517
|
-
d2.__proto__ = b2;
|
|
12518
|
-
} || function(d2, b2) {
|
|
12519
|
-
for (var p in b2) {
|
|
12520
|
-
if (Object.prototype.hasOwnProperty.call(b2, p))
|
|
12521
|
-
d2[p] = b2[p];
|
|
12522
|
-
}
|
|
12523
|
-
};
|
|
12524
|
-
return _extendStatics(d, b);
|
|
12525
|
-
};
|
|
12526
|
-
return function(d, b) {
|
|
12527
|
-
if (typeof b !== "function" && b !== null)
|
|
12528
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12529
|
-
_extendStatics(d, b);
|
|
12530
|
-
function __() {
|
|
12531
|
-
this.constructor = d;
|
|
12532
|
-
}
|
|
12533
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12534
|
-
};
|
|
12535
|
-
}();
|
|
12536
|
-
var CustomError = function(_super) {
|
|
12537
|
-
__extends(CustomError2, _super);
|
|
12538
|
-
function CustomError2(message, options) {
|
|
12539
|
-
var _newTarget = this.constructor;
|
|
12540
|
-
var _this = _super.call(this, message, options) || this;
|
|
12541
|
-
Object.defineProperty(_this, "name", {
|
|
12542
|
-
value: _newTarget.name,
|
|
12543
|
-
enumerable: false,
|
|
12544
|
-
configurable: true
|
|
12545
|
-
});
|
|
12546
|
-
fixProto(_this, _newTarget.prototype);
|
|
12547
|
-
fixStack(_this);
|
|
12548
|
-
return _this;
|
|
12549
|
-
}
|
|
12550
|
-
return CustomError2;
|
|
12551
|
-
}(Error);
|
|
12552
|
-
|
|
12553
10752
|
// src/provider/errors.ts
|
|
12554
|
-
var
|
|
10753
|
+
var import_custom_error = __toESM(require_custom_error());
|
|
10754
|
+
var LibraryError = class extends import_custom_error.CustomError {
|
|
12555
10755
|
};
|
|
12556
10756
|
var GatewayError = class extends LibraryError {
|
|
12557
10757
|
constructor(message, errorCode) {
|
|
@@ -12772,7 +10972,7 @@ var starknet = (() => {
|
|
|
12772
10972
|
fetch(method, params) {
|
|
12773
10973
|
return fetchPonyfill_default(this.nodeUrl, {
|
|
12774
10974
|
method: "POST",
|
|
12775
|
-
body:
|
|
10975
|
+
body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
|
|
12776
10976
|
headers: this.headers
|
|
12777
10977
|
});
|
|
12778
10978
|
}
|
|
@@ -12897,22 +11097,25 @@ var starknet = (() => {
|
|
|
12897
11097
|
}
|
|
12898
11098
|
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
12899
11099
|
const block_id = new Block(blockIdentifier).identifier;
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
11100
|
+
if ("program" in contractDefinition) {
|
|
11101
|
+
return this.fetchEndpoint("starknet_estimateFee", {
|
|
11102
|
+
request: {
|
|
11103
|
+
type: RPC.TransactionType.DECLARE,
|
|
11104
|
+
contract_class: {
|
|
11105
|
+
program: contractDefinition.program,
|
|
11106
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
11107
|
+
abi: contractDefinition.abi
|
|
11108
|
+
},
|
|
11109
|
+
sender_address: senderAddress,
|
|
11110
|
+
signature: signatureToHexArray(signature),
|
|
11111
|
+
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
11112
|
+
nonce: toHex(details.nonce),
|
|
11113
|
+
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
12907
11114
|
},
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
|
|
12913
|
-
},
|
|
12914
|
-
block_id
|
|
12915
|
-
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
11115
|
+
block_id
|
|
11116
|
+
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
11117
|
+
}
|
|
11118
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
12916
11119
|
}
|
|
12917
11120
|
async getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
12918
11121
|
const block_id = new Block(blockIdentifier).identifier;
|
|
@@ -12934,21 +11137,24 @@ var starknet = (() => {
|
|
|
12934
11137
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
12935
11138
|
}
|
|
12936
11139
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
11140
|
+
if ("program" in contractDefinition) {
|
|
11141
|
+
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
11142
|
+
declare_transaction: {
|
|
11143
|
+
contract_class: {
|
|
11144
|
+
program: contractDefinition.program,
|
|
11145
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
11146
|
+
abi: contractDefinition.abi
|
|
11147
|
+
},
|
|
11148
|
+
type: RPC.TransactionType.DECLARE,
|
|
11149
|
+
version: "0x1",
|
|
11150
|
+
max_fee: toHex(details.maxFee || 0),
|
|
11151
|
+
signature: signatureToHexArray(signature),
|
|
11152
|
+
sender_address: senderAddress,
|
|
11153
|
+
nonce: toHex(details.nonce)
|
|
11154
|
+
}
|
|
11155
|
+
});
|
|
11156
|
+
}
|
|
11157
|
+
throw new Error("RPC do not support Sierra Contracts yet");
|
|
12952
11158
|
}
|
|
12953
11159
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
12954
11160
|
return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
|
|
@@ -12971,7 +11177,7 @@ var starknet = (() => {
|
|
|
12971
11177
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
12972
11178
|
type: RPC.TransactionType.INVOKE,
|
|
12973
11179
|
max_fee: toHex(details.maxFee || 0),
|
|
12974
|
-
version:
|
|
11180
|
+
version: "0x1",
|
|
12975
11181
|
signature: signatureToHexArray(functionInvocation.signature),
|
|
12976
11182
|
nonce: toHex(details.nonce)
|
|
12977
11183
|
}
|
|
@@ -13080,7 +11286,6 @@ var starknet = (() => {
|
|
|
13080
11286
|
return {
|
|
13081
11287
|
...res,
|
|
13082
11288
|
calldata: "calldata" in res.transaction ? res.transaction.calldata : [],
|
|
13083
|
-
contract_address: "contract_address" in res.transaction ? res.transaction.contract_address : void 0,
|
|
13084
11289
|
contract_class: "contract_class" in res.transaction ? res.transaction.contract_class : void 0,
|
|
13085
11290
|
entry_point_selector: "entry_point_selector" in res.transaction ? res.transaction.entry_point_selector : void 0,
|
|
13086
11291
|
max_fee: "max_fee" in res.transaction ? res.transaction.max_fee : void 0,
|
|
@@ -13198,24 +11403,18 @@ var starknet = (() => {
|
|
|
13198
11403
|
};
|
|
13199
11404
|
}
|
|
13200
11405
|
parseGetStateUpdateResponse(res) {
|
|
13201
|
-
const nonces =
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
return {
|
|
13209
|
-
address,
|
|
13210
|
-
storage_entries
|
|
13211
|
-
};
|
|
13212
|
-
});
|
|
11406
|
+
const nonces = Object.entries(res.state_diff.nonces).map(([contract_address, nonce]) => ({
|
|
11407
|
+
contract_address,
|
|
11408
|
+
nonce
|
|
11409
|
+
}));
|
|
11410
|
+
const storage_diffs = Object.entries(res.state_diff.storage_diffs).map(
|
|
11411
|
+
([address, storage_entries]) => ({ address, storage_entries })
|
|
11412
|
+
);
|
|
13213
11413
|
return {
|
|
13214
11414
|
...res,
|
|
13215
11415
|
state_diff: {
|
|
11416
|
+
...res.state_diff,
|
|
13216
11417
|
storage_diffs,
|
|
13217
|
-
declared_contract_hashes: res.state_diff.declared_contract_hashes,
|
|
13218
|
-
deployed_contracts: res.state_diff.deployed_contracts,
|
|
13219
11418
|
nonces
|
|
13220
11419
|
}
|
|
13221
11420
|
};
|
|
@@ -13360,20 +11559,20 @@ var starknet = (() => {
|
|
|
13360
11559
|
try {
|
|
13361
11560
|
const response = await fetchPonyfill_default(url, {
|
|
13362
11561
|
method,
|
|
13363
|
-
body:
|
|
11562
|
+
body: stringify2(options == null ? void 0 : options.body),
|
|
13364
11563
|
headers
|
|
13365
11564
|
});
|
|
13366
11565
|
const textResponse = await response.text();
|
|
13367
11566
|
if (!response.ok) {
|
|
13368
11567
|
let responseBody;
|
|
13369
11568
|
try {
|
|
13370
|
-
responseBody =
|
|
11569
|
+
responseBody = parse2(textResponse);
|
|
13371
11570
|
} catch {
|
|
13372
11571
|
throw new HttpError(response.statusText, response.status);
|
|
13373
11572
|
}
|
|
13374
11573
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
13375
11574
|
}
|
|
13376
|
-
const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig :
|
|
11575
|
+
const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse2;
|
|
13377
11576
|
return parseChoice(textResponse);
|
|
13378
11577
|
} catch (error) {
|
|
13379
11578
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -13389,7 +11588,6 @@ var starknet = (() => {
|
|
|
13389
11588
|
"call_contract",
|
|
13390
11589
|
{ blockIdentifier },
|
|
13391
11590
|
{
|
|
13392
|
-
signature: [],
|
|
13393
11591
|
contract_address: contractAddress,
|
|
13394
11592
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
13395
11593
|
calldata
|
|
@@ -13434,18 +11632,23 @@ var starknet = (() => {
|
|
|
13434
11632
|
async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
|
|
13435
11633
|
return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
|
|
13436
11634
|
}
|
|
13437
|
-
async getClassByHash(classHash) {
|
|
13438
|
-
return this.fetchEndpoint("get_class_by_hash", { classHash }).then(
|
|
11635
|
+
async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
|
|
11636
|
+
return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
|
|
11637
|
+
parseContract
|
|
11638
|
+
);
|
|
11639
|
+
}
|
|
11640
|
+
async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
|
|
11641
|
+
return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });
|
|
13439
11642
|
}
|
|
13440
11643
|
async invokeFunction(functionInvocation, details) {
|
|
13441
11644
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
13442
11645
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
13443
|
-
|
|
11646
|
+
sender_address: functionInvocation.contractAddress,
|
|
13444
11647
|
calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
|
|
13445
11648
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
13446
11649
|
nonce: toHex(details.nonce),
|
|
13447
11650
|
max_fee: toHex(details.maxFee || 0),
|
|
13448
|
-
version:
|
|
11651
|
+
version: "0x1"
|
|
13449
11652
|
}).then(this.responseParser.parseInvokeFunctionResponse);
|
|
13450
11653
|
}
|
|
13451
11654
|
async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
|
|
@@ -13460,27 +11663,39 @@ var starknet = (() => {
|
|
|
13460
11663
|
signature: signatureToDecimalArray(signature)
|
|
13461
11664
|
}).then(this.responseParser.parseDeployContractResponse);
|
|
13462
11665
|
}
|
|
13463
|
-
async declareContract({ senderAddress, contractDefinition, signature }, details) {
|
|
11666
|
+
async declareContract({ senderAddress, contractDefinition, signature, compiledClassHash }, details) {
|
|
11667
|
+
if (!isSierra(contractDefinition)) {
|
|
11668
|
+
return this.fetchEndpoint("add_transaction", void 0, {
|
|
11669
|
+
type: "DECLARE" /* DECLARE */,
|
|
11670
|
+
contract_class: contractDefinition,
|
|
11671
|
+
nonce: toHex(details.nonce),
|
|
11672
|
+
signature: signatureToDecimalArray(signature),
|
|
11673
|
+
sender_address: senderAddress,
|
|
11674
|
+
max_fee: toHex(details.maxFee || 0),
|
|
11675
|
+
version: "0x1"
|
|
11676
|
+
}).then(this.responseParser.parseDeclareContractResponse);
|
|
11677
|
+
}
|
|
13464
11678
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
13465
11679
|
type: "DECLARE" /* DECLARE */,
|
|
11680
|
+
sender_address: senderAddress,
|
|
11681
|
+
compiled_class_hash: compiledClassHash,
|
|
13466
11682
|
contract_class: contractDefinition,
|
|
13467
11683
|
nonce: toHex(details.nonce),
|
|
13468
11684
|
signature: signatureToDecimalArray(signature),
|
|
13469
|
-
sender_address: senderAddress,
|
|
13470
11685
|
max_fee: toHex(details.maxFee || 0),
|
|
13471
|
-
version:
|
|
11686
|
+
version: "0x2"
|
|
13472
11687
|
}).then(this.responseParser.parseDeclareContractResponse);
|
|
13473
11688
|
}
|
|
13474
|
-
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
13475
|
-
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
|
|
11689
|
+
async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
11690
|
+
return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
|
|
13476
11691
|
}
|
|
13477
|
-
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
11692
|
+
async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
13478
11693
|
return this.fetchEndpoint(
|
|
13479
11694
|
"estimate_fee",
|
|
13480
|
-
{ blockIdentifier },
|
|
11695
|
+
{ blockIdentifier, skipValidate },
|
|
13481
11696
|
{
|
|
13482
11697
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
13483
|
-
|
|
11698
|
+
sender_address: invocation.contractAddress,
|
|
13484
11699
|
calldata: invocation.calldata ?? [],
|
|
13485
11700
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13486
11701
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
@@ -13488,24 +11703,39 @@ var starknet = (() => {
|
|
|
13488
11703
|
}
|
|
13489
11704
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
13490
11705
|
}
|
|
13491
|
-
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
11706
|
+
async getDeclareEstimateFee({ senderAddress, contractDefinition, signature, compiledClassHash }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
11707
|
+
if (!isSierra(contractDefinition)) {
|
|
11708
|
+
return this.fetchEndpoint(
|
|
11709
|
+
"estimate_fee",
|
|
11710
|
+
{ blockIdentifier, skipValidate },
|
|
11711
|
+
{
|
|
11712
|
+
type: "DECLARE" /* DECLARE */,
|
|
11713
|
+
sender_address: senderAddress,
|
|
11714
|
+
contract_class: contractDefinition,
|
|
11715
|
+
signature: signatureToDecimalArray(signature),
|
|
11716
|
+
version: toHex((details == null ? void 0 : details.version) || toBigInt(feeTransactionVersion)),
|
|
11717
|
+
nonce: toHex(details.nonce)
|
|
11718
|
+
}
|
|
11719
|
+
).then(this.responseParser.parseFeeEstimateResponse);
|
|
11720
|
+
}
|
|
13492
11721
|
return this.fetchEndpoint(
|
|
13493
11722
|
"estimate_fee",
|
|
13494
|
-
{ blockIdentifier },
|
|
11723
|
+
{ blockIdentifier, skipValidate },
|
|
13495
11724
|
{
|
|
13496
11725
|
type: "DECLARE" /* DECLARE */,
|
|
13497
11726
|
sender_address: senderAddress,
|
|
11727
|
+
compiled_class_hash: compiledClassHash,
|
|
13498
11728
|
contract_class: contractDefinition,
|
|
11729
|
+
nonce: toHex(details.nonce),
|
|
13499
11730
|
signature: signatureToDecimalArray(signature),
|
|
13500
|
-
version:
|
|
13501
|
-
nonce: toHex(details.nonce)
|
|
11731
|
+
version: "0x2"
|
|
13502
11732
|
}
|
|
13503
11733
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
13504
11734
|
}
|
|
13505
|
-
async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier) {
|
|
11735
|
+
async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
13506
11736
|
return this.fetchEndpoint(
|
|
13507
11737
|
"estimate_fee",
|
|
13508
|
-
{ blockIdentifier },
|
|
11738
|
+
{ blockIdentifier, skipValidate },
|
|
13509
11739
|
{
|
|
13510
11740
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
13511
11741
|
class_hash: toHex(classHash),
|
|
@@ -13523,7 +11753,7 @@ var starknet = (() => {
|
|
|
13523
11753
|
if (invocation.type === "INVOKE_FUNCTION") {
|
|
13524
11754
|
res = {
|
|
13525
11755
|
type: invocation.type,
|
|
13526
|
-
|
|
11756
|
+
sender_address: invocation.contractAddress,
|
|
13527
11757
|
calldata: invocation.calldata ?? []
|
|
13528
11758
|
};
|
|
13529
11759
|
} else if (invocation.type === "DECLARE") {
|
|
@@ -13602,13 +11832,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13602
11832
|
};
|
|
13603
11833
|
return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
|
|
13604
11834
|
}
|
|
13605
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
|
|
11835
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
|
|
13606
11836
|
return this.fetchEndpoint(
|
|
13607
11837
|
"simulate_transaction",
|
|
13608
|
-
{ blockIdentifier },
|
|
11838
|
+
{ blockIdentifier, skipValidate },
|
|
13609
11839
|
{
|
|
13610
11840
|
type: "INVOKE_FUNCTION",
|
|
13611
|
-
|
|
11841
|
+
sender_address: invocation.contractAddress,
|
|
13612
11842
|
calldata: invocation.calldata ?? [],
|
|
13613
11843
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13614
11844
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
|
|
@@ -13668,11 +11898,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13668
11898
|
async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
13669
11899
|
return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
|
|
13670
11900
|
}
|
|
13671
|
-
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
|
|
11901
|
+
async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
|
|
13672
11902
|
return this.provider.getInvokeEstimateFee(
|
|
13673
11903
|
invocationWithTxType,
|
|
13674
11904
|
invocationDetails,
|
|
13675
|
-
blockIdentifier
|
|
11905
|
+
blockIdentifier,
|
|
11906
|
+
skipValidate
|
|
13676
11907
|
);
|
|
13677
11908
|
}
|
|
13678
11909
|
async getEstimateFeeBulk(invocations, blockIdentifier) {
|
|
@@ -13702,11 +11933,16 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13702
11933
|
async declareContract(transaction, details) {
|
|
13703
11934
|
return this.provider.declareContract(transaction, details);
|
|
13704
11935
|
}
|
|
13705
|
-
async getDeclareEstimateFee(transaction, details, blockIdentifier) {
|
|
13706
|
-
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier);
|
|
11936
|
+
async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
11937
|
+
return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
|
|
13707
11938
|
}
|
|
13708
|
-
getDeployAccountEstimateFee(transaction, details, blockIdentifier) {
|
|
13709
|
-
return this.provider.getDeployAccountEstimateFee(
|
|
11939
|
+
getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
|
|
11940
|
+
return this.provider.getDeployAccountEstimateFee(
|
|
11941
|
+
transaction,
|
|
11942
|
+
details,
|
|
11943
|
+
blockIdentifier,
|
|
11944
|
+
skipValidate
|
|
11945
|
+
);
|
|
13710
11946
|
}
|
|
13711
11947
|
async getCode(contractAddress, blockIdentifier) {
|
|
13712
11948
|
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
@@ -13714,8 +11950,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13714
11950
|
async waitForTransaction(txHash, options) {
|
|
13715
11951
|
return this.provider.waitForTransaction(txHash, options);
|
|
13716
11952
|
}
|
|
13717
|
-
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
|
|
13718
|
-
return this.provider.getSimulateTransaction(
|
|
11953
|
+
async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
|
|
11954
|
+
return this.provider.getSimulateTransaction(
|
|
11955
|
+
invocation,
|
|
11956
|
+
invocationDetails,
|
|
11957
|
+
blockIdentifier,
|
|
11958
|
+
skipValidate
|
|
11959
|
+
);
|
|
13719
11960
|
}
|
|
13720
11961
|
async getStateUpdate(blockIdentifier) {
|
|
13721
11962
|
return this.provider.getStateUpdate(blockIdentifier);
|
|
@@ -14400,7 +12641,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14400
12641
|
__export(transaction_exports, {
|
|
14401
12642
|
fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
|
|
14402
12643
|
fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
|
|
14403
|
-
|
|
12644
|
+
fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
|
|
12645
|
+
getExecuteCalldata: () => getExecuteCalldata,
|
|
12646
|
+
transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
|
|
12647
|
+
transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
|
|
14404
12648
|
});
|
|
14405
12649
|
var transformCallsToMulticallArrays = (calls) => {
|
|
14406
12650
|
const callArray = [];
|
|
@@ -14434,6 +12678,27 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14434
12678
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
14435
12679
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
14436
12680
|
};
|
|
12681
|
+
var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
12682
|
+
const callArray = calls.map((call) => ({
|
|
12683
|
+
to: toBigInt(call.contractAddress).toString(10),
|
|
12684
|
+
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
12685
|
+
calldata: bigNumberishArrayToDecimalStringArray(call.calldata || [])
|
|
12686
|
+
}));
|
|
12687
|
+
return callArray;
|
|
12688
|
+
};
|
|
12689
|
+
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
12690
|
+
const callArray = transformCallsToMulticallArrays_cairo1(calls);
|
|
12691
|
+
return [
|
|
12692
|
+
callArray.length.toString(),
|
|
12693
|
+
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
12694
|
+
];
|
|
12695
|
+
};
|
|
12696
|
+
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
12697
|
+
if (cairoVersion === "1") {
|
|
12698
|
+
return fromCallsToExecuteCalldata_cairo1(calls);
|
|
12699
|
+
}
|
|
12700
|
+
return fromCallsToExecuteCalldata(calls);
|
|
12701
|
+
};
|
|
14437
12702
|
|
|
14438
12703
|
// src/utils/typedData/index.ts
|
|
14439
12704
|
var typedData_exports = {};
|
|
@@ -14660,7 +12925,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14660
12925
|
if (abis && abis.length !== transactions.length) {
|
|
14661
12926
|
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
14662
12927
|
}
|
|
14663
|
-
const calldata =
|
|
12928
|
+
const calldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
|
|
14664
12929
|
const msgHash = calculateTransactionHash(
|
|
14665
12930
|
transactionsDetail.walletAddress,
|
|
14666
12931
|
transactionsDetail.version,
|
|
@@ -14693,14 +12958,23 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14693
12958
|
);
|
|
14694
12959
|
return esm_exports.sign(msgHash, this.pk);
|
|
14695
12960
|
}
|
|
14696
|
-
async signDeclareTransaction({
|
|
12961
|
+
async signDeclareTransaction({
|
|
12962
|
+
classHash,
|
|
12963
|
+
senderAddress,
|
|
12964
|
+
chainId,
|
|
12965
|
+
maxFee,
|
|
12966
|
+
version,
|
|
12967
|
+
nonce,
|
|
12968
|
+
compiledClassHash
|
|
12969
|
+
}) {
|
|
14697
12970
|
const msgHash = calculateDeclareTransactionHash(
|
|
14698
12971
|
classHash,
|
|
14699
12972
|
senderAddress,
|
|
14700
12973
|
version,
|
|
14701
12974
|
maxFee,
|
|
14702
12975
|
chainId,
|
|
14703
|
-
nonce
|
|
12976
|
+
nonce,
|
|
12977
|
+
compiledClassHash
|
|
14704
12978
|
);
|
|
14705
12979
|
return esm_exports.sign(msgHash, this.pk);
|
|
14706
12980
|
}
|
|
@@ -14742,7 +13016,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14742
13016
|
async estimateFee(calls, estimateFeeDetails) {
|
|
14743
13017
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
14744
13018
|
}
|
|
14745
|
-
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
13019
|
+
async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
14746
13020
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
14747
13021
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14748
13022
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -14752,13 +13026,15 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14752
13026
|
nonce,
|
|
14753
13027
|
maxFee: ZERO,
|
|
14754
13028
|
version,
|
|
14755
|
-
chainId
|
|
13029
|
+
chainId,
|
|
13030
|
+
cairoVersion: cairoVersion ?? "0"
|
|
14756
13031
|
};
|
|
14757
13032
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
14758
13033
|
const response = await super.getInvokeEstimateFee(
|
|
14759
13034
|
{ ...invocation },
|
|
14760
13035
|
{ version, nonce },
|
|
14761
|
-
blockIdentifier
|
|
13036
|
+
blockIdentifier,
|
|
13037
|
+
skipValidate
|
|
14762
13038
|
);
|
|
14763
13039
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
14764
13040
|
return {
|
|
@@ -14766,18 +13042,26 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14766
13042
|
suggestedMaxFee
|
|
14767
13043
|
};
|
|
14768
13044
|
}
|
|
14769
|
-
async estimateDeclareFee({ contract, classHash: providedClassHash }, { blockIdentifier, nonce: providedNonce } = {}) {
|
|
13045
|
+
async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate, cairoVersion } = {}) {
|
|
14770
13046
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14771
|
-
const version = toBigInt(feeTransactionVersion);
|
|
13047
|
+
const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
|
|
14772
13048
|
const chainId = await this.getChainId();
|
|
14773
|
-
const
|
|
14774
|
-
{ classHash: providedClassHash, contract },
|
|
14775
|
-
{
|
|
13049
|
+
const declareContractTransaction = await this.buildDeclarePayload(
|
|
13050
|
+
{ classHash: providedClassHash, contract, casm, compiledClassHash },
|
|
13051
|
+
{
|
|
13052
|
+
nonce,
|
|
13053
|
+
chainId,
|
|
13054
|
+
version,
|
|
13055
|
+
walletAddress: this.address,
|
|
13056
|
+
maxFee: ZERO,
|
|
13057
|
+
cairoVersion: cairoVersion ?? "0"
|
|
13058
|
+
}
|
|
14776
13059
|
);
|
|
14777
13060
|
const response = await super.getDeclareEstimateFee(
|
|
14778
|
-
|
|
13061
|
+
declareContractTransaction,
|
|
14779
13062
|
{ version, nonce },
|
|
14780
|
-
blockIdentifier
|
|
13063
|
+
blockIdentifier,
|
|
13064
|
+
skipValidate
|
|
14781
13065
|
);
|
|
14782
13066
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
14783
13067
|
return {
|
|
@@ -14790,18 +13074,26 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14790
13074
|
addressSalt = 0,
|
|
14791
13075
|
constructorCalldata = [],
|
|
14792
13076
|
contractAddress: providedContractAddress
|
|
14793
|
-
}, { blockIdentifier } = {}) {
|
|
13077
|
+
}, { blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
14794
13078
|
const version = toBigInt(feeTransactionVersion);
|
|
14795
13079
|
const nonce = ZERO;
|
|
14796
13080
|
const chainId = await this.getChainId();
|
|
14797
13081
|
const payload = await this.buildAccountDeployPayload(
|
|
14798
13082
|
{ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress },
|
|
14799
|
-
{
|
|
13083
|
+
{
|
|
13084
|
+
nonce,
|
|
13085
|
+
chainId,
|
|
13086
|
+
version,
|
|
13087
|
+
walletAddress: this.address,
|
|
13088
|
+
maxFee: ZERO,
|
|
13089
|
+
cairoVersion: cairoVersion ?? "0"
|
|
13090
|
+
}
|
|
14800
13091
|
);
|
|
14801
13092
|
const response = await super.getDeployAccountEstimateFee(
|
|
14802
13093
|
{ ...payload },
|
|
14803
13094
|
{ version, nonce },
|
|
14804
|
-
blockIdentifier
|
|
13095
|
+
blockIdentifier,
|
|
13096
|
+
skipValidate
|
|
14805
13097
|
);
|
|
14806
13098
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
|
|
14807
13099
|
return {
|
|
@@ -14813,7 +13105,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14813
13105
|
const calls = this.buildUDCContractPayload(payload);
|
|
14814
13106
|
return this.estimateInvokeFee(calls, transactionsDetail);
|
|
14815
13107
|
}
|
|
14816
|
-
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
13108
|
+
async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier, cairoVersion } = {}) {
|
|
14817
13109
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
14818
13110
|
const version = toBigInt(feeTransactionVersion);
|
|
14819
13111
|
const chainId = await this.getChainId();
|
|
@@ -14824,7 +13116,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14824
13116
|
nonce: toBigInt(Number(nonce) + index),
|
|
14825
13117
|
maxFee: ZERO,
|
|
14826
13118
|
version,
|
|
14827
|
-
chainId
|
|
13119
|
+
chainId,
|
|
13120
|
+
cairoVersion: cairoVersion ?? "0"
|
|
14828
13121
|
};
|
|
14829
13122
|
const txPayload = transaction.payload;
|
|
14830
13123
|
let res;
|
|
@@ -14882,7 +13175,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14882
13175
|
});
|
|
14883
13176
|
}
|
|
14884
13177
|
async buildInvocation(call, signerDetails) {
|
|
14885
|
-
const calldata =
|
|
13178
|
+
const calldata = getExecuteCalldata(call, signerDetails.cairoVersion);
|
|
14886
13179
|
const signature = await this.signer.signTransaction(call, signerDetails);
|
|
14887
13180
|
return {
|
|
14888
13181
|
contractAddress: this.address,
|
|
@@ -14899,15 +13192,17 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14899
13192
|
);
|
|
14900
13193
|
const version = toBigInt(transactionVersion);
|
|
14901
13194
|
const chainId = await this.getChainId();
|
|
13195
|
+
const cairoVersion = transactionsDetail.cairoVersion ?? "0";
|
|
14902
13196
|
const signerDetails = {
|
|
14903
13197
|
walletAddress: this.address,
|
|
14904
13198
|
nonce,
|
|
14905
13199
|
maxFee,
|
|
14906
13200
|
version,
|
|
14907
|
-
chainId
|
|
13201
|
+
chainId,
|
|
13202
|
+
cairoVersion
|
|
14908
13203
|
};
|
|
14909
13204
|
const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
|
|
14910
|
-
const calldata =
|
|
13205
|
+
const calldata = getExecuteCalldata(transactions, cairoVersion);
|
|
14911
13206
|
return this.invokeFunction(
|
|
14912
13207
|
{ contractAddress: this.address, calldata, signature },
|
|
14913
13208
|
{
|
|
@@ -14917,32 +13212,25 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14917
13212
|
}
|
|
14918
13213
|
);
|
|
14919
13214
|
}
|
|
14920
|
-
async declare(
|
|
14921
|
-
const
|
|
14922
|
-
const
|
|
14923
|
-
|
|
14924
|
-
|
|
13215
|
+
async declare(payload, transactionsDetail = {}) {
|
|
13216
|
+
const declareContractPayload = extractContractHashes(payload);
|
|
13217
|
+
const details = {};
|
|
13218
|
+
details.nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
|
|
13219
|
+
details.maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
13220
|
+
{
|
|
13221
|
+
type: "DECLARE" /* DECLARE */,
|
|
13222
|
+
payload: declareContractPayload
|
|
13223
|
+
},
|
|
14925
13224
|
transactionsDetail
|
|
14926
13225
|
);
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
const
|
|
14930
|
-
|
|
14931
|
-
|
|
14932
|
-
|
|
14933
|
-
maxFee,
|
|
14934
|
-
version,
|
|
14935
|
-
nonce
|
|
13226
|
+
details.version = !isSierra(payload.contract) ? transactionVersion : transactionVersion_2;
|
|
13227
|
+
details.chainId = await this.getChainId();
|
|
13228
|
+
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
|
|
13229
|
+
...details,
|
|
13230
|
+
walletAddress: this.address,
|
|
13231
|
+
cairoVersion: transactionsDetail.cairoVersion ?? "0"
|
|
14936
13232
|
});
|
|
14937
|
-
|
|
14938
|
-
return this.declareContract(
|
|
14939
|
-
{ contractDefinition, senderAddress: this.address, signature },
|
|
14940
|
-
{
|
|
14941
|
-
nonce,
|
|
14942
|
-
maxFee,
|
|
14943
|
-
version
|
|
14944
|
-
}
|
|
14945
|
-
);
|
|
13233
|
+
return this.declareContract(declareContractTransaction, details);
|
|
14946
13234
|
}
|
|
14947
13235
|
async deploy(payload, details) {
|
|
14948
13236
|
const params = [].concat(payload).map((it) => {
|
|
@@ -15081,13 +13369,14 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
15081
13369
|
feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
|
|
15082
13370
|
break;
|
|
15083
13371
|
}
|
|
15084
|
-
return feeEstimate.suggestedMaxFee
|
|
13372
|
+
return feeEstimate.suggestedMaxFee;
|
|
15085
13373
|
}
|
|
15086
|
-
async buildDeclarePayload(
|
|
13374
|
+
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
13375
|
+
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
15087
13376
|
const contractDefinition = parseContract(contract);
|
|
15088
|
-
const classHash = providedClassHash ?? computeContractClassHash(contract);
|
|
15089
13377
|
const signature = await this.signer.signDeclareTransaction({
|
|
15090
13378
|
classHash,
|
|
13379
|
+
compiledClassHash,
|
|
15091
13380
|
senderAddress: walletAddress,
|
|
15092
13381
|
chainId,
|
|
15093
13382
|
maxFee,
|
|
@@ -15097,7 +13386,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
15097
13386
|
return {
|
|
15098
13387
|
senderAddress: walletAddress,
|
|
15099
13388
|
signature,
|
|
15100
|
-
contractDefinition
|
|
13389
|
+
contractDefinition,
|
|
13390
|
+
compiledClassHash
|
|
15101
13391
|
};
|
|
15102
13392
|
}
|
|
15103
13393
|
async buildAccountDeployPayload({
|
|
@@ -15147,7 +13437,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
15147
13437
|
});
|
|
15148
13438
|
return calls;
|
|
15149
13439
|
}
|
|
15150
|
-
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
|
|
13440
|
+
async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
|
|
15151
13441
|
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
15152
13442
|
const nonce = toBigInt(providedNonce ?? await this.getNonce());
|
|
15153
13443
|
const version = toBigInt(feeTransactionVersion);
|
|
@@ -15157,13 +13447,15 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
15157
13447
|
nonce,
|
|
15158
13448
|
maxFee: ZERO,
|
|
15159
13449
|
version,
|
|
15160
|
-
chainId
|
|
13450
|
+
chainId,
|
|
13451
|
+
cairoVersion: cairoVersion ?? "0"
|
|
15161
13452
|
};
|
|
15162
13453
|
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
15163
13454
|
const response = await super.getSimulateTransaction(
|
|
15164
13455
|
invocation,
|
|
15165
13456
|
{ version, nonce },
|
|
15166
|
-
blockIdentifier
|
|
13457
|
+
blockIdentifier,
|
|
13458
|
+
skipValidate
|
|
15167
13459
|
);
|
|
15168
13460
|
const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
|
|
15169
13461
|
return {
|