starknet 4.13.2 → 4.14.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/CODE_OF_CONDUCT.md +128 -0
  3. package/README.md +2 -2
  4. package/__tests__/account.test.ts +38 -14
  5. package/__tests__/contract.test.ts +70 -57
  6. package/__tests__/defaultProvider.test.ts +14 -13
  7. package/__tests__/fixtures.ts +26 -27
  8. package/__tests__/rpcProvider.test.ts +19 -16
  9. package/__tests__/sequencerProvider.test.ts +47 -55
  10. package/__tests__/utils/utils.test.ts +10 -0
  11. package/dist/index.d.ts +112 -28
  12. package/dist/index.global.js +511 -453
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +107 -49
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +107 -49
  17. package/dist/index.mjs.map +1 -1
  18. package/index.d.ts +112 -28
  19. package/index.global.js +511 -453
  20. package/index.global.js.map +1 -1
  21. package/index.js +107 -49
  22. package/index.js.map +1 -1
  23. package/index.mjs +107 -49
  24. package/index.mjs.map +1 -1
  25. package/package.json +2 -2
  26. package/src/account/default.ts +29 -7
  27. package/src/account/interface.ts +71 -5
  28. package/src/contract/contractFactory.ts +20 -13
  29. package/src/contract/default.ts +10 -1
  30. package/src/provider/default.ts +26 -11
  31. package/src/provider/interface.ts +9 -3
  32. package/src/provider/rpc.ts +15 -11
  33. package/src/provider/sequencer.ts +11 -6
  34. package/src/provider/utils.ts +19 -11
  35. package/src/types/account.ts +21 -1
  36. package/src/types/lib.ts +5 -2
  37. package/src/types/provider.ts +0 -5
  38. package/src/utils/events.ts +32 -0
  39. package/src/utils/number.ts +6 -0
  40. package/www/docs/API/account.md +156 -2
  41. package/www/docs/API/contractFactory.md +7 -11
  42. package/www/docs/API/provider.md +5 -9
  43. package/www/docs/API/utils.md +8 -0
  44. package/www/guides/account.md +89 -38
  45. package/www/guides/erc20.md +115 -59
  46. package/www/guides/intro.md +11 -4
@@ -53,8 +53,8 @@ var starknet = (() => {
53
53
  ctor.prototype = new TempCtor();
54
54
  ctor.prototype.constructor = ctor;
55
55
  }
56
- function BN3(number, base, endian) {
57
- if (BN3.isBN(number)) {
56
+ function BN4(number, base, endian) {
57
+ if (BN4.isBN(number)) {
58
58
  return number;
59
59
  }
60
60
  this.negative = 0;
@@ -70,12 +70,12 @@ var starknet = (() => {
70
70
  }
71
71
  }
72
72
  if (typeof module2 === "object") {
73
- module2.exports = BN3;
73
+ module2.exports = BN4;
74
74
  } else {
75
- exports2.BN = BN3;
75
+ exports2.BN = BN4;
76
76
  }
77
- BN3.BN = BN3;
78
- BN3.wordSize = 26;
77
+ BN4.BN = BN4;
78
+ BN4.wordSize = 26;
79
79
  var Buffer2;
80
80
  try {
81
81
  if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
@@ -85,23 +85,23 @@ var starknet = (() => {
85
85
  }
86
86
  } catch (e) {
87
87
  }
88
- BN3.isBN = function isBN(num) {
89
- if (num instanceof BN3) {
88
+ BN4.isBN = function isBN(num) {
89
+ if (num instanceof BN4) {
90
90
  return true;
91
91
  }
92
- return num !== null && typeof num === "object" && num.constructor.wordSize === BN3.wordSize && Array.isArray(num.words);
92
+ return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
93
93
  };
94
- BN3.max = function max(left, right) {
94
+ BN4.max = function max(left, right) {
95
95
  if (left.cmp(right) > 0)
96
96
  return left;
97
97
  return right;
98
98
  };
99
- BN3.min = function min(left, right) {
99
+ BN4.min = function min(left, right) {
100
100
  if (left.cmp(right) < 0)
101
101
  return left;
102
102
  return right;
103
103
  };
104
- BN3.prototype._init = function init(number, base, endian) {
104
+ BN4.prototype._init = function init(number, base, endian) {
105
105
  if (typeof number === "number") {
106
106
  return this._initNumber(number, base, endian);
107
107
  }
@@ -129,7 +129,7 @@ var starknet = (() => {
129
129
  }
130
130
  }
131
131
  };
132
- BN3.prototype._initNumber = function _initNumber(number, base, endian) {
132
+ BN4.prototype._initNumber = function _initNumber(number, base, endian) {
133
133
  if (number < 0) {
134
134
  this.negative = 1;
135
135
  number = -number;
@@ -156,7 +156,7 @@ var starknet = (() => {
156
156
  return;
157
157
  this._initArray(this.toArray(), base, endian);
158
158
  };
159
- BN3.prototype._initArray = function _initArray(number, base, endian) {
159
+ BN4.prototype._initArray = function _initArray(number, base, endian) {
160
160
  assert6(typeof number.length === "number");
161
161
  if (number.length <= 0) {
162
162
  this.words = [0];
@@ -214,7 +214,7 @@ var starknet = (() => {
214
214
  }
215
215
  return r;
216
216
  }
217
- BN3.prototype._parseHex = function _parseHex(number, start, endian) {
217
+ BN4.prototype._parseHex = function _parseHex(number, start, endian) {
218
218
  this.length = Math.ceil((number.length - start) / 6);
219
219
  this.words = new Array(this.length);
220
220
  for (var i = 0; i < this.length; i++) {
@@ -270,7 +270,7 @@ var starknet = (() => {
270
270
  }
271
271
  return r;
272
272
  }
273
- BN3.prototype._parseBase = function _parseBase(number, base, start) {
273
+ BN4.prototype._parseBase = function _parseBase(number, base, start) {
274
274
  this.words = [0];
275
275
  this.length = 1;
276
276
  for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
@@ -306,7 +306,7 @@ var starknet = (() => {
306
306
  }
307
307
  this._strip();
308
308
  };
309
- BN3.prototype.copy = function copy(dest) {
309
+ BN4.prototype.copy = function copy(dest) {
310
310
  dest.words = new Array(this.length);
311
311
  for (var i = 0; i < this.length; i++) {
312
312
  dest.words[i] = this.words[i];
@@ -321,27 +321,27 @@ var starknet = (() => {
321
321
  dest.negative = src.negative;
322
322
  dest.red = src.red;
323
323
  }
324
- BN3.prototype._move = function _move(dest) {
324
+ BN4.prototype._move = function _move(dest) {
325
325
  move(dest, this);
326
326
  };
327
- BN3.prototype.clone = function clone() {
328
- var r = new BN3(null);
327
+ BN4.prototype.clone = function clone() {
328
+ var r = new BN4(null);
329
329
  this.copy(r);
330
330
  return r;
331
331
  };
332
- BN3.prototype._expand = function _expand(size) {
332
+ BN4.prototype._expand = function _expand(size) {
333
333
  while (this.length < size) {
334
334
  this.words[this.length++] = 0;
335
335
  }
336
336
  return this;
337
337
  };
338
- BN3.prototype._strip = function strip() {
338
+ BN4.prototype._strip = function strip() {
339
339
  while (this.length > 1 && this.words[this.length - 1] === 0) {
340
340
  this.length--;
341
341
  }
342
342
  return this._normSign();
343
343
  };
344
- BN3.prototype._normSign = function _normSign() {
344
+ BN4.prototype._normSign = function _normSign() {
345
345
  if (this.length === 1 && this.words[0] === 0) {
346
346
  this.negative = 0;
347
347
  }
@@ -349,12 +349,12 @@ var starknet = (() => {
349
349
  };
350
350
  if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
351
351
  try {
352
- BN3.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
352
+ BN4.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
353
353
  } catch (e) {
354
- BN3.prototype.inspect = inspect;
354
+ BN4.prototype.inspect = inspect;
355
355
  }
356
356
  } else {
357
- BN3.prototype.inspect = inspect;
357
+ BN4.prototype.inspect = inspect;
358
358
  }
359
359
  function inspect() {
360
360
  return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
@@ -465,7 +465,7 @@ var starknet = (() => {
465
465
  52521875,
466
466
  60466176
467
467
  ];
468
- BN3.prototype.toString = function toString2(base, padding) {
468
+ BN4.prototype.toString = function toString2(base, padding) {
469
469
  base = base || 10;
470
470
  padding = padding | 0 || 1;
471
471
  var out;
@@ -527,7 +527,7 @@ var starknet = (() => {
527
527
  }
528
528
  assert6(false, "Base should be between 2 and 36");
529
529
  };
530
- BN3.prototype.toNumber = function toNumber() {
530
+ BN4.prototype.toNumber = function toNumber() {
531
531
  var ret = this.words[0];
532
532
  if (this.length === 2) {
533
533
  ret += this.words[1] * 67108864;
@@ -538,15 +538,15 @@ var starknet = (() => {
538
538
  }
539
539
  return this.negative !== 0 ? -ret : ret;
540
540
  };
541
- BN3.prototype.toJSON = function toJSON() {
541
+ BN4.prototype.toJSON = function toJSON() {
542
542
  return this.toString(16, 2);
543
543
  };
544
544
  if (Buffer2) {
545
- BN3.prototype.toBuffer = function toBuffer(endian, length) {
545
+ BN4.prototype.toBuffer = function toBuffer(endian, length) {
546
546
  return this.toArrayLike(Buffer2, endian, length);
547
547
  };
548
548
  }
549
- BN3.prototype.toArray = function toArray(endian, length) {
549
+ BN4.prototype.toArray = function toArray(endian, length) {
550
550
  return this.toArrayLike(Array, endian, length);
551
551
  };
552
552
  var allocate = function allocate2(ArrayType, size) {
@@ -555,7 +555,7 @@ var starknet = (() => {
555
555
  }
556
556
  return new ArrayType(size);
557
557
  };
558
- BN3.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
558
+ BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
559
559
  this._strip();
560
560
  var byteLength = this.byteLength();
561
561
  var reqLength = length || Math.max(1, byteLength);
@@ -566,7 +566,7 @@ var starknet = (() => {
566
566
  this["_toArrayLike" + postfix](res, byteLength);
567
567
  return res;
568
568
  };
569
- BN3.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
569
+ BN4.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
570
570
  var position = 0;
571
571
  var carry = 0;
572
572
  for (var i = 0, shift = 0; i < this.length; i++) {
@@ -596,7 +596,7 @@ var starknet = (() => {
596
596
  }
597
597
  }
598
598
  };
599
- BN3.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
599
+ BN4.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
600
600
  var position = res.length - 1;
601
601
  var carry = 0;
602
602
  for (var i = 0, shift = 0; i < this.length; i++) {
@@ -627,11 +627,11 @@ var starknet = (() => {
627
627
  }
628
628
  };
629
629
  if (Math.clz32) {
630
- BN3.prototype._countBits = function _countBits(w) {
630
+ BN4.prototype._countBits = function _countBits(w) {
631
631
  return 32 - Math.clz32(w);
632
632
  };
633
633
  } else {
634
- BN3.prototype._countBits = function _countBits(w) {
634
+ BN4.prototype._countBits = function _countBits(w) {
635
635
  var t = w;
636
636
  var r = 0;
637
637
  if (t >= 4096) {
@@ -653,7 +653,7 @@ var starknet = (() => {
653
653
  return r + t;
654
654
  };
655
655
  }
656
- BN3.prototype._zeroBits = function _zeroBits(w) {
656
+ BN4.prototype._zeroBits = function _zeroBits(w) {
657
657
  if (w === 0)
658
658
  return 26;
659
659
  var t = w;
@@ -679,7 +679,7 @@ var starknet = (() => {
679
679
  }
680
680
  return r;
681
681
  };
682
- BN3.prototype.bitLength = function bitLength() {
682
+ BN4.prototype.bitLength = function bitLength() {
683
683
  var w = this.words[this.length - 1];
684
684
  var hi = this._countBits(w);
685
685
  return (this.length - 1) * 26 + hi;
@@ -693,7 +693,7 @@ var starknet = (() => {
693
693
  }
694
694
  return w;
695
695
  }
696
- BN3.prototype.zeroBits = function zeroBits() {
696
+ BN4.prototype.zeroBits = function zeroBits() {
697
697
  if (this.isZero())
698
698
  return 0;
699
699
  var r = 0;
@@ -705,34 +705,34 @@ var starknet = (() => {
705
705
  }
706
706
  return r;
707
707
  };
708
- BN3.prototype.byteLength = function byteLength() {
708
+ BN4.prototype.byteLength = function byteLength() {
709
709
  return Math.ceil(this.bitLength() / 8);
710
710
  };
711
- BN3.prototype.toTwos = function toTwos(width) {
711
+ BN4.prototype.toTwos = function toTwos(width) {
712
712
  if (this.negative !== 0) {
713
713
  return this.abs().inotn(width).iaddn(1);
714
714
  }
715
715
  return this.clone();
716
716
  };
717
- BN3.prototype.fromTwos = function fromTwos(width) {
717
+ BN4.prototype.fromTwos = function fromTwos(width) {
718
718
  if (this.testn(width - 1)) {
719
719
  return this.notn(width).iaddn(1).ineg();
720
720
  }
721
721
  return this.clone();
722
722
  };
723
- BN3.prototype.isNeg = function isNeg() {
723
+ BN4.prototype.isNeg = function isNeg() {
724
724
  return this.negative !== 0;
725
725
  };
726
- BN3.prototype.neg = function neg() {
726
+ BN4.prototype.neg = function neg() {
727
727
  return this.clone().ineg();
728
728
  };
729
- BN3.prototype.ineg = function ineg() {
729
+ BN4.prototype.ineg = function ineg() {
730
730
  if (!this.isZero()) {
731
731
  this.negative ^= 1;
732
732
  }
733
733
  return this;
734
734
  };
735
- BN3.prototype.iuor = function iuor(num) {
735
+ BN4.prototype.iuor = function iuor(num) {
736
736
  while (this.length < num.length) {
737
737
  this.words[this.length++] = 0;
738
738
  }
@@ -741,21 +741,21 @@ var starknet = (() => {
741
741
  }
742
742
  return this._strip();
743
743
  };
744
- BN3.prototype.ior = function ior(num) {
744
+ BN4.prototype.ior = function ior(num) {
745
745
  assert6((this.negative | num.negative) === 0);
746
746
  return this.iuor(num);
747
747
  };
748
- BN3.prototype.or = function or(num) {
748
+ BN4.prototype.or = function or(num) {
749
749
  if (this.length > num.length)
750
750
  return this.clone().ior(num);
751
751
  return num.clone().ior(this);
752
752
  };
753
- BN3.prototype.uor = function uor(num) {
753
+ BN4.prototype.uor = function uor(num) {
754
754
  if (this.length > num.length)
755
755
  return this.clone().iuor(num);
756
756
  return num.clone().iuor(this);
757
757
  };
758
- BN3.prototype.iuand = function iuand(num) {
758
+ BN4.prototype.iuand = function iuand(num) {
759
759
  var b;
760
760
  if (this.length > num.length) {
761
761
  b = num;
@@ -768,21 +768,21 @@ var starknet = (() => {
768
768
  this.length = b.length;
769
769
  return this._strip();
770
770
  };
771
- BN3.prototype.iand = function iand(num) {
771
+ BN4.prototype.iand = function iand(num) {
772
772
  assert6((this.negative | num.negative) === 0);
773
773
  return this.iuand(num);
774
774
  };
775
- BN3.prototype.and = function and(num) {
775
+ BN4.prototype.and = function and(num) {
776
776
  if (this.length > num.length)
777
777
  return this.clone().iand(num);
778
778
  return num.clone().iand(this);
779
779
  };
780
- BN3.prototype.uand = function uand(num) {
780
+ BN4.prototype.uand = function uand(num) {
781
781
  if (this.length > num.length)
782
782
  return this.clone().iuand(num);
783
783
  return num.clone().iuand(this);
784
784
  };
785
- BN3.prototype.iuxor = function iuxor(num) {
785
+ BN4.prototype.iuxor = function iuxor(num) {
786
786
  var a;
787
787
  var b;
788
788
  if (this.length > num.length) {
@@ -803,21 +803,21 @@ var starknet = (() => {
803
803
  this.length = a.length;
804
804
  return this._strip();
805
805
  };
806
- BN3.prototype.ixor = function ixor(num) {
806
+ BN4.prototype.ixor = function ixor(num) {
807
807
  assert6((this.negative | num.negative) === 0);
808
808
  return this.iuxor(num);
809
809
  };
810
- BN3.prototype.xor = function xor(num) {
810
+ BN4.prototype.xor = function xor(num) {
811
811
  if (this.length > num.length)
812
812
  return this.clone().ixor(num);
813
813
  return num.clone().ixor(this);
814
814
  };
815
- BN3.prototype.uxor = function uxor(num) {
815
+ BN4.prototype.uxor = function uxor(num) {
816
816
  if (this.length > num.length)
817
817
  return this.clone().iuxor(num);
818
818
  return num.clone().iuxor(this);
819
819
  };
820
- BN3.prototype.inotn = function inotn(width) {
820
+ BN4.prototype.inotn = function inotn(width) {
821
821
  assert6(typeof width === "number" && width >= 0);
822
822
  var bytesNeeded = Math.ceil(width / 26) | 0;
823
823
  var bitsLeft = width % 26;
@@ -833,10 +833,10 @@ var starknet = (() => {
833
833
  }
834
834
  return this._strip();
835
835
  };
836
- BN3.prototype.notn = function notn(width) {
836
+ BN4.prototype.notn = function notn(width) {
837
837
  return this.clone().inotn(width);
838
838
  };
839
- BN3.prototype.setn = function setn(bit, val) {
839
+ BN4.prototype.setn = function setn(bit, val) {
840
840
  assert6(typeof bit === "number" && bit >= 0);
841
841
  var off = bit / 26 | 0;
842
842
  var wbit = bit % 26;
@@ -848,7 +848,7 @@ var starknet = (() => {
848
848
  }
849
849
  return this._strip();
850
850
  };
851
- BN3.prototype.iadd = function iadd(num) {
851
+ BN4.prototype.iadd = function iadd(num) {
852
852
  var r;
853
853
  if (this.negative !== 0 && num.negative === 0) {
854
854
  this.negative = 0;
@@ -891,7 +891,7 @@ var starknet = (() => {
891
891
  }
892
892
  return this;
893
893
  };
894
- BN3.prototype.add = function add(num) {
894
+ BN4.prototype.add = function add(num) {
895
895
  var res;
896
896
  if (num.negative !== 0 && this.negative === 0) {
897
897
  num.negative = 0;
@@ -908,7 +908,7 @@ var starknet = (() => {
908
908
  return this.clone().iadd(num);
909
909
  return num.clone().iadd(this);
910
910
  };
911
- BN3.prototype.isub = function isub(num) {
911
+ BN4.prototype.isub = function isub(num) {
912
912
  if (num.negative !== 0) {
913
913
  num.negative = 0;
914
914
  var r = this.iadd(num);
@@ -957,7 +957,7 @@ var starknet = (() => {
957
957
  }
958
958
  return this._strip();
959
959
  };
960
- BN3.prototype.sub = function sub(num) {
960
+ BN4.prototype.sub = function sub(num) {
961
961
  return this.clone().isub(num);
962
962
  };
963
963
  function smallMulTo(self2, num, out) {
@@ -1585,7 +1585,7 @@ var starknet = (() => {
1585
1585
  function jumboMulTo(self2, num, out) {
1586
1586
  return bigMulTo(self2, num, out);
1587
1587
  }
1588
- BN3.prototype.mulTo = function mulTo(num, out) {
1588
+ BN4.prototype.mulTo = function mulTo(num, out) {
1589
1589
  var res;
1590
1590
  var len = this.length + num.length;
1591
1591
  if (this.length === 10 && num.length === 10) {
@@ -1605,7 +1605,7 @@ var starknet = (() => {
1605
1605
  }
1606
1606
  FFTM.prototype.makeRBT = function makeRBT(N) {
1607
1607
  var t = new Array(N);
1608
- var l = BN3.prototype._countBits(N) - 1;
1608
+ var l = BN4.prototype._countBits(N) - 1;
1609
1609
  for (var i = 0; i < N; i++) {
1610
1610
  t[i] = this.revBin(i, l, N);
1611
1611
  }
@@ -1742,20 +1742,20 @@ var starknet = (() => {
1742
1742
  out.length = x.length + y.length;
1743
1743
  return out._strip();
1744
1744
  };
1745
- BN3.prototype.mul = function mul(num) {
1746
- var out = new BN3(null);
1745
+ BN4.prototype.mul = function mul(num) {
1746
+ var out = new BN4(null);
1747
1747
  out.words = new Array(this.length + num.length);
1748
1748
  return this.mulTo(num, out);
1749
1749
  };
1750
- BN3.prototype.mulf = function mulf(num) {
1751
- var out = new BN3(null);
1750
+ BN4.prototype.mulf = function mulf(num) {
1751
+ var out = new BN4(null);
1752
1752
  out.words = new Array(this.length + num.length);
1753
1753
  return jumboMulTo(this, num, out);
1754
1754
  };
1755
- BN3.prototype.imul = function imul(num) {
1755
+ BN4.prototype.imul = function imul(num) {
1756
1756
  return this.clone().mulTo(num, this);
1757
1757
  };
1758
- BN3.prototype.imuln = function imuln(num) {
1758
+ BN4.prototype.imuln = function imuln(num) {
1759
1759
  var isNegNum = num < 0;
1760
1760
  if (isNegNum)
1761
1761
  num = -num;
@@ -1776,19 +1776,19 @@ var starknet = (() => {
1776
1776
  }
1777
1777
  return isNegNum ? this.ineg() : this;
1778
1778
  };
1779
- BN3.prototype.muln = function muln(num) {
1779
+ BN4.prototype.muln = function muln(num) {
1780
1780
  return this.clone().imuln(num);
1781
1781
  };
1782
- BN3.prototype.sqr = function sqr() {
1782
+ BN4.prototype.sqr = function sqr() {
1783
1783
  return this.mul(this);
1784
1784
  };
1785
- BN3.prototype.isqr = function isqr() {
1785
+ BN4.prototype.isqr = function isqr() {
1786
1786
  return this.imul(this.clone());
1787
1787
  };
1788
- BN3.prototype.pow = function pow(num) {
1788
+ BN4.prototype.pow = function pow(num) {
1789
1789
  var w = toBitArray(num);
1790
1790
  if (w.length === 0)
1791
- return new BN3(1);
1791
+ return new BN4(1);
1792
1792
  var res = this;
1793
1793
  for (var i = 0; i < w.length; i++, res = res.sqr()) {
1794
1794
  if (w[i] !== 0)
@@ -1803,7 +1803,7 @@ var starknet = (() => {
1803
1803
  }
1804
1804
  return res;
1805
1805
  };
1806
- BN3.prototype.iushln = function iushln(bits) {
1806
+ BN4.prototype.iushln = function iushln(bits) {
1807
1807
  assert6(typeof bits === "number" && bits >= 0);
1808
1808
  var r = bits % 26;
1809
1809
  var s = (bits - r) / 26;
@@ -1833,11 +1833,11 @@ var starknet = (() => {
1833
1833
  }
1834
1834
  return this._strip();
1835
1835
  };
1836
- BN3.prototype.ishln = function ishln(bits) {
1836
+ BN4.prototype.ishln = function ishln(bits) {
1837
1837
  assert6(this.negative === 0);
1838
1838
  return this.iushln(bits);
1839
1839
  };
1840
- BN3.prototype.iushrn = function iushrn(bits, hint, extended) {
1840
+ BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
1841
1841
  assert6(typeof bits === "number" && bits >= 0);
1842
1842
  var h;
1843
1843
  if (hint) {
@@ -1882,23 +1882,23 @@ var starknet = (() => {
1882
1882
  }
1883
1883
  return this._strip();
1884
1884
  };
1885
- BN3.prototype.ishrn = function ishrn(bits, hint, extended) {
1885
+ BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
1886
1886
  assert6(this.negative === 0);
1887
1887
  return this.iushrn(bits, hint, extended);
1888
1888
  };
1889
- BN3.prototype.shln = function shln(bits) {
1889
+ BN4.prototype.shln = function shln(bits) {
1890
1890
  return this.clone().ishln(bits);
1891
1891
  };
1892
- BN3.prototype.ushln = function ushln(bits) {
1892
+ BN4.prototype.ushln = function ushln(bits) {
1893
1893
  return this.clone().iushln(bits);
1894
1894
  };
1895
- BN3.prototype.shrn = function shrn(bits) {
1895
+ BN4.prototype.shrn = function shrn(bits) {
1896
1896
  return this.clone().ishrn(bits);
1897
1897
  };
1898
- BN3.prototype.ushrn = function ushrn(bits) {
1898
+ BN4.prototype.ushrn = function ushrn(bits) {
1899
1899
  return this.clone().iushrn(bits);
1900
1900
  };
1901
- BN3.prototype.testn = function testn(bit) {
1901
+ BN4.prototype.testn = function testn(bit) {
1902
1902
  assert6(typeof bit === "number" && bit >= 0);
1903
1903
  var r = bit % 26;
1904
1904
  var s = (bit - r) / 26;
@@ -1908,7 +1908,7 @@ var starknet = (() => {
1908
1908
  var w = this.words[s];
1909
1909
  return !!(w & q);
1910
1910
  };
1911
- BN3.prototype.imaskn = function imaskn(bits) {
1911
+ BN4.prototype.imaskn = function imaskn(bits) {
1912
1912
  assert6(typeof bits === "number" && bits >= 0);
1913
1913
  var r = bits % 26;
1914
1914
  var s = (bits - r) / 26;
@@ -1926,10 +1926,10 @@ var starknet = (() => {
1926
1926
  }
1927
1927
  return this._strip();
1928
1928
  };
1929
- BN3.prototype.maskn = function maskn(bits) {
1929
+ BN4.prototype.maskn = function maskn(bits) {
1930
1930
  return this.clone().imaskn(bits);
1931
1931
  };
1932
- BN3.prototype.iaddn = function iaddn(num) {
1932
+ BN4.prototype.iaddn = function iaddn(num) {
1933
1933
  assert6(typeof num === "number");
1934
1934
  assert6(num < 67108864);
1935
1935
  if (num < 0)
@@ -1947,7 +1947,7 @@ var starknet = (() => {
1947
1947
  }
1948
1948
  return this._iaddn(num);
1949
1949
  };
1950
- BN3.prototype._iaddn = function _iaddn(num) {
1950
+ BN4.prototype._iaddn = function _iaddn(num) {
1951
1951
  this.words[0] += num;
1952
1952
  for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
1953
1953
  this.words[i] -= 67108864;
@@ -1960,7 +1960,7 @@ var starknet = (() => {
1960
1960
  this.length = Math.max(this.length, i + 1);
1961
1961
  return this;
1962
1962
  };
1963
- BN3.prototype.isubn = function isubn(num) {
1963
+ BN4.prototype.isubn = function isubn(num) {
1964
1964
  assert6(typeof num === "number");
1965
1965
  assert6(num < 67108864);
1966
1966
  if (num < 0)
@@ -1983,20 +1983,20 @@ var starknet = (() => {
1983
1983
  }
1984
1984
  return this._strip();
1985
1985
  };
1986
- BN3.prototype.addn = function addn(num) {
1986
+ BN4.prototype.addn = function addn(num) {
1987
1987
  return this.clone().iaddn(num);
1988
1988
  };
1989
- BN3.prototype.subn = function subn(num) {
1989
+ BN4.prototype.subn = function subn(num) {
1990
1990
  return this.clone().isubn(num);
1991
1991
  };
1992
- BN3.prototype.iabs = function iabs() {
1992
+ BN4.prototype.iabs = function iabs() {
1993
1993
  this.negative = 0;
1994
1994
  return this;
1995
1995
  };
1996
- BN3.prototype.abs = function abs() {
1996
+ BN4.prototype.abs = function abs() {
1997
1997
  return this.clone().iabs();
1998
1998
  };
1999
- BN3.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
1999
+ BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
2000
2000
  var len = num.length + shift;
2001
2001
  var i;
2002
2002
  this._expand(len);
@@ -2026,7 +2026,7 @@ var starknet = (() => {
2026
2026
  this.negative = 1;
2027
2027
  return this._strip();
2028
2028
  };
2029
- BN3.prototype._wordDiv = function _wordDiv(num, mode) {
2029
+ BN4.prototype._wordDiv = function _wordDiv(num, mode) {
2030
2030
  var shift = this.length - num.length;
2031
2031
  var a = this.clone();
2032
2032
  var b = num;
@@ -2041,7 +2041,7 @@ var starknet = (() => {
2041
2041
  var m = a.length - b.length;
2042
2042
  var q;
2043
2043
  if (mode !== "mod") {
2044
- q = new BN3(null);
2044
+ q = new BN4(null);
2045
2045
  q.length = m + 1;
2046
2046
  q.words = new Array(q.length);
2047
2047
  for (var i = 0; i < q.length; i++) {
@@ -2083,12 +2083,12 @@ var starknet = (() => {
2083
2083
  mod: a
2084
2084
  };
2085
2085
  };
2086
- BN3.prototype.divmod = function divmod(num, mode, positive) {
2086
+ BN4.prototype.divmod = function divmod(num, mode, positive) {
2087
2087
  assert6(!num.isZero());
2088
2088
  if (this.isZero()) {
2089
2089
  return {
2090
- div: new BN3(0),
2091
- mod: new BN3(0)
2090
+ div: new BN4(0),
2091
+ mod: new BN4(0)
2092
2092
  };
2093
2093
  }
2094
2094
  var div, mod, res;
@@ -2133,7 +2133,7 @@ var starknet = (() => {
2133
2133
  }
2134
2134
  if (num.length > this.length || this.cmp(num) < 0) {
2135
2135
  return {
2136
- div: new BN3(0),
2136
+ div: new BN4(0),
2137
2137
  mod: this
2138
2138
  };
2139
2139
  }
@@ -2147,26 +2147,26 @@ var starknet = (() => {
2147
2147
  if (mode === "mod") {
2148
2148
  return {
2149
2149
  div: null,
2150
- mod: new BN3(this.modrn(num.words[0]))
2150
+ mod: new BN4(this.modrn(num.words[0]))
2151
2151
  };
2152
2152
  }
2153
2153
  return {
2154
2154
  div: this.divn(num.words[0]),
2155
- mod: new BN3(this.modrn(num.words[0]))
2155
+ mod: new BN4(this.modrn(num.words[0]))
2156
2156
  };
2157
2157
  }
2158
2158
  return this._wordDiv(num, mode);
2159
2159
  };
2160
- BN3.prototype.div = function div(num) {
2160
+ BN4.prototype.div = function div(num) {
2161
2161
  return this.divmod(num, "div", false).div;
2162
2162
  };
2163
- BN3.prototype.mod = function mod(num) {
2163
+ BN4.prototype.mod = function mod(num) {
2164
2164
  return this.divmod(num, "mod", false).mod;
2165
2165
  };
2166
- BN3.prototype.umod = function umod(num) {
2166
+ BN4.prototype.umod = function umod(num) {
2167
2167
  return this.divmod(num, "mod", true).mod;
2168
2168
  };
2169
- BN3.prototype.divRound = function divRound(num) {
2169
+ BN4.prototype.divRound = function divRound(num) {
2170
2170
  var dm = this.divmod(num);
2171
2171
  if (dm.mod.isZero())
2172
2172
  return dm.div;
@@ -2178,7 +2178,7 @@ var starknet = (() => {
2178
2178
  return dm.div;
2179
2179
  return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
2180
2180
  };
2181
- BN3.prototype.modrn = function modrn(num) {
2181
+ BN4.prototype.modrn = function modrn(num) {
2182
2182
  var isNegNum = num < 0;
2183
2183
  if (isNegNum)
2184
2184
  num = -num;
@@ -2190,10 +2190,10 @@ var starknet = (() => {
2190
2190
  }
2191
2191
  return isNegNum ? -acc : acc;
2192
2192
  };
2193
- BN3.prototype.modn = function modn(num) {
2193
+ BN4.prototype.modn = function modn(num) {
2194
2194
  return this.modrn(num);
2195
2195
  };
2196
- BN3.prototype.idivn = function idivn(num) {
2196
+ BN4.prototype.idivn = function idivn(num) {
2197
2197
  var isNegNum = num < 0;
2198
2198
  if (isNegNum)
2199
2199
  num = -num;
@@ -2207,10 +2207,10 @@ var starknet = (() => {
2207
2207
  this._strip();
2208
2208
  return isNegNum ? this.ineg() : this;
2209
2209
  };
2210
- BN3.prototype.divn = function divn(num) {
2210
+ BN4.prototype.divn = function divn(num) {
2211
2211
  return this.clone().idivn(num);
2212
2212
  };
2213
- BN3.prototype.egcd = function egcd(p) {
2213
+ BN4.prototype.egcd = function egcd(p) {
2214
2214
  assert6(p.negative === 0);
2215
2215
  assert6(!p.isZero());
2216
2216
  var x = this;
@@ -2220,10 +2220,10 @@ var starknet = (() => {
2220
2220
  } else {
2221
2221
  x = x.clone();
2222
2222
  }
2223
- var A = new BN3(1);
2224
- var B = new BN3(0);
2225
- var C = new BN3(0);
2226
- var D = new BN3(1);
2223
+ var A = new BN4(1);
2224
+ var B = new BN4(0);
2225
+ var C = new BN4(0);
2226
+ var D = new BN4(1);
2227
2227
  var g = 0;
2228
2228
  while (x.isEven() && y.isEven()) {
2229
2229
  x.iushrn(1);
@@ -2275,7 +2275,7 @@ var starknet = (() => {
2275
2275
  gcd: y.iushln(g)
2276
2276
  };
2277
2277
  };
2278
- BN3.prototype._invmp = function _invmp(p) {
2278
+ BN4.prototype._invmp = function _invmp(p) {
2279
2279
  assert6(p.negative === 0);
2280
2280
  assert6(!p.isZero());
2281
2281
  var a = this;
@@ -2285,8 +2285,8 @@ var starknet = (() => {
2285
2285
  } else {
2286
2286
  a = a.clone();
2287
2287
  }
2288
- var x1 = new BN3(1);
2289
- var x2 = new BN3(0);
2288
+ var x1 = new BN4(1);
2289
+ var x2 = new BN4(0);
2290
2290
  var delta = b.clone();
2291
2291
  while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
2292
2292
  for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1)
@@ -2330,7 +2330,7 @@ var starknet = (() => {
2330
2330
  }
2331
2331
  return res;
2332
2332
  };
2333
- BN3.prototype.gcd = function gcd(num) {
2333
+ BN4.prototype.gcd = function gcd(num) {
2334
2334
  if (this.isZero())
2335
2335
  return num.abs();
2336
2336
  if (num.isZero())
@@ -2362,19 +2362,19 @@ var starknet = (() => {
2362
2362
  } while (true);
2363
2363
  return b.iushln(shift);
2364
2364
  };
2365
- BN3.prototype.invm = function invm(num) {
2365
+ BN4.prototype.invm = function invm(num) {
2366
2366
  return this.egcd(num).a.umod(num);
2367
2367
  };
2368
- BN3.prototype.isEven = function isEven() {
2368
+ BN4.prototype.isEven = function isEven() {
2369
2369
  return (this.words[0] & 1) === 0;
2370
2370
  };
2371
- BN3.prototype.isOdd = function isOdd() {
2371
+ BN4.prototype.isOdd = function isOdd() {
2372
2372
  return (this.words[0] & 1) === 1;
2373
2373
  };
2374
- BN3.prototype.andln = function andln(num) {
2374
+ BN4.prototype.andln = function andln(num) {
2375
2375
  return this.words[0] & num;
2376
2376
  };
2377
- BN3.prototype.bincn = function bincn(bit) {
2377
+ BN4.prototype.bincn = function bincn(bit) {
2378
2378
  assert6(typeof bit === "number");
2379
2379
  var r = bit % 26;
2380
2380
  var s = (bit - r) / 26;
@@ -2398,10 +2398,10 @@ var starknet = (() => {
2398
2398
  }
2399
2399
  return this;
2400
2400
  };
2401
- BN3.prototype.isZero = function isZero() {
2401
+ BN4.prototype.isZero = function isZero() {
2402
2402
  return this.length === 1 && this.words[0] === 0;
2403
2403
  };
2404
- BN3.prototype.cmpn = function cmpn(num) {
2404
+ BN4.prototype.cmpn = function cmpn(num) {
2405
2405
  var negative = num < 0;
2406
2406
  if (this.negative !== 0 && !negative)
2407
2407
  return -1;
@@ -2423,7 +2423,7 @@ var starknet = (() => {
2423
2423
  return -res | 0;
2424
2424
  return res;
2425
2425
  };
2426
- BN3.prototype.cmp = function cmp(num) {
2426
+ BN4.prototype.cmp = function cmp(num) {
2427
2427
  if (this.negative !== 0 && num.negative === 0)
2428
2428
  return -1;
2429
2429
  if (this.negative === 0 && num.negative !== 0)
@@ -2433,7 +2433,7 @@ var starknet = (() => {
2433
2433
  return -res | 0;
2434
2434
  return res;
2435
2435
  };
2436
- BN3.prototype.ucmp = function ucmp(num) {
2436
+ BN4.prototype.ucmp = function ucmp(num) {
2437
2437
  if (this.length > num.length)
2438
2438
  return 1;
2439
2439
  if (this.length < num.length)
@@ -2453,112 +2453,112 @@ var starknet = (() => {
2453
2453
  }
2454
2454
  return res;
2455
2455
  };
2456
- BN3.prototype.gtn = function gtn(num) {
2456
+ BN4.prototype.gtn = function gtn(num) {
2457
2457
  return this.cmpn(num) === 1;
2458
2458
  };
2459
- BN3.prototype.gt = function gt(num) {
2459
+ BN4.prototype.gt = function gt(num) {
2460
2460
  return this.cmp(num) === 1;
2461
2461
  };
2462
- BN3.prototype.gten = function gten(num) {
2462
+ BN4.prototype.gten = function gten(num) {
2463
2463
  return this.cmpn(num) >= 0;
2464
2464
  };
2465
- BN3.prototype.gte = function gte(num) {
2465
+ BN4.prototype.gte = function gte(num) {
2466
2466
  return this.cmp(num) >= 0;
2467
2467
  };
2468
- BN3.prototype.ltn = function ltn(num) {
2468
+ BN4.prototype.ltn = function ltn(num) {
2469
2469
  return this.cmpn(num) === -1;
2470
2470
  };
2471
- BN3.prototype.lt = function lt(num) {
2471
+ BN4.prototype.lt = function lt(num) {
2472
2472
  return this.cmp(num) === -1;
2473
2473
  };
2474
- BN3.prototype.lten = function lten(num) {
2474
+ BN4.prototype.lten = function lten(num) {
2475
2475
  return this.cmpn(num) <= 0;
2476
2476
  };
2477
- BN3.prototype.lte = function lte(num) {
2477
+ BN4.prototype.lte = function lte(num) {
2478
2478
  return this.cmp(num) <= 0;
2479
2479
  };
2480
- BN3.prototype.eqn = function eqn(num) {
2480
+ BN4.prototype.eqn = function eqn(num) {
2481
2481
  return this.cmpn(num) === 0;
2482
2482
  };
2483
- BN3.prototype.eq = function eq(num) {
2483
+ BN4.prototype.eq = function eq(num) {
2484
2484
  return this.cmp(num) === 0;
2485
2485
  };
2486
- BN3.red = function red(num) {
2486
+ BN4.red = function red(num) {
2487
2487
  return new Red(num);
2488
2488
  };
2489
- BN3.prototype.toRed = function toRed(ctx) {
2489
+ BN4.prototype.toRed = function toRed(ctx) {
2490
2490
  assert6(!this.red, "Already a number in reduction context");
2491
2491
  assert6(this.negative === 0, "red works only with positives");
2492
2492
  return ctx.convertTo(this)._forceRed(ctx);
2493
2493
  };
2494
- BN3.prototype.fromRed = function fromRed() {
2494
+ BN4.prototype.fromRed = function fromRed() {
2495
2495
  assert6(this.red, "fromRed works only with numbers in reduction context");
2496
2496
  return this.red.convertFrom(this);
2497
2497
  };
2498
- BN3.prototype._forceRed = function _forceRed(ctx) {
2498
+ BN4.prototype._forceRed = function _forceRed(ctx) {
2499
2499
  this.red = ctx;
2500
2500
  return this;
2501
2501
  };
2502
- BN3.prototype.forceRed = function forceRed(ctx) {
2502
+ BN4.prototype.forceRed = function forceRed(ctx) {
2503
2503
  assert6(!this.red, "Already a number in reduction context");
2504
2504
  return this._forceRed(ctx);
2505
2505
  };
2506
- BN3.prototype.redAdd = function redAdd(num) {
2506
+ BN4.prototype.redAdd = function redAdd(num) {
2507
2507
  assert6(this.red, "redAdd works only with red numbers");
2508
2508
  return this.red.add(this, num);
2509
2509
  };
2510
- BN3.prototype.redIAdd = function redIAdd(num) {
2510
+ BN4.prototype.redIAdd = function redIAdd(num) {
2511
2511
  assert6(this.red, "redIAdd works only with red numbers");
2512
2512
  return this.red.iadd(this, num);
2513
2513
  };
2514
- BN3.prototype.redSub = function redSub(num) {
2514
+ BN4.prototype.redSub = function redSub(num) {
2515
2515
  assert6(this.red, "redSub works only with red numbers");
2516
2516
  return this.red.sub(this, num);
2517
2517
  };
2518
- BN3.prototype.redISub = function redISub(num) {
2518
+ BN4.prototype.redISub = function redISub(num) {
2519
2519
  assert6(this.red, "redISub works only with red numbers");
2520
2520
  return this.red.isub(this, num);
2521
2521
  };
2522
- BN3.prototype.redShl = function redShl(num) {
2522
+ BN4.prototype.redShl = function redShl(num) {
2523
2523
  assert6(this.red, "redShl works only with red numbers");
2524
2524
  return this.red.shl(this, num);
2525
2525
  };
2526
- BN3.prototype.redMul = function redMul(num) {
2526
+ BN4.prototype.redMul = function redMul(num) {
2527
2527
  assert6(this.red, "redMul works only with red numbers");
2528
2528
  this.red._verify2(this, num);
2529
2529
  return this.red.mul(this, num);
2530
2530
  };
2531
- BN3.prototype.redIMul = function redIMul(num) {
2531
+ BN4.prototype.redIMul = function redIMul(num) {
2532
2532
  assert6(this.red, "redMul works only with red numbers");
2533
2533
  this.red._verify2(this, num);
2534
2534
  return this.red.imul(this, num);
2535
2535
  };
2536
- BN3.prototype.redSqr = function redSqr() {
2536
+ BN4.prototype.redSqr = function redSqr() {
2537
2537
  assert6(this.red, "redSqr works only with red numbers");
2538
2538
  this.red._verify1(this);
2539
2539
  return this.red.sqr(this);
2540
2540
  };
2541
- BN3.prototype.redISqr = function redISqr() {
2541
+ BN4.prototype.redISqr = function redISqr() {
2542
2542
  assert6(this.red, "redISqr works only with red numbers");
2543
2543
  this.red._verify1(this);
2544
2544
  return this.red.isqr(this);
2545
2545
  };
2546
- BN3.prototype.redSqrt = function redSqrt() {
2546
+ BN4.prototype.redSqrt = function redSqrt() {
2547
2547
  assert6(this.red, "redSqrt works only with red numbers");
2548
2548
  this.red._verify1(this);
2549
2549
  return this.red.sqrt(this);
2550
2550
  };
2551
- BN3.prototype.redInvm = function redInvm() {
2551
+ BN4.prototype.redInvm = function redInvm() {
2552
2552
  assert6(this.red, "redInvm works only with red numbers");
2553
2553
  this.red._verify1(this);
2554
2554
  return this.red.invm(this);
2555
2555
  };
2556
- BN3.prototype.redNeg = function redNeg() {
2556
+ BN4.prototype.redNeg = function redNeg() {
2557
2557
  assert6(this.red, "redNeg works only with red numbers");
2558
2558
  this.red._verify1(this);
2559
2559
  return this.red.neg(this);
2560
2560
  };
2561
- BN3.prototype.redPow = function redPow(num) {
2561
+ BN4.prototype.redPow = function redPow(num) {
2562
2562
  assert6(this.red && !num.red, "redPow(normalNum)");
2563
2563
  this.red._verify1(this);
2564
2564
  return this.red.pow(this, num);
@@ -2571,13 +2571,13 @@ var starknet = (() => {
2571
2571
  };
2572
2572
  function MPrime(name, p) {
2573
2573
  this.name = name;
2574
- this.p = new BN3(p, 16);
2574
+ this.p = new BN4(p, 16);
2575
2575
  this.n = this.p.bitLength();
2576
- this.k = new BN3(1).iushln(this.n).isub(this.p);
2576
+ this.k = new BN4(1).iushln(this.n).isub(this.p);
2577
2577
  this.tmp = this._tmp();
2578
2578
  }
2579
2579
  MPrime.prototype._tmp = function _tmp() {
2580
- var tmp = new BN3(null);
2580
+ var tmp = new BN4(null);
2581
2581
  tmp.words = new Array(Math.ceil(this.n / 13));
2582
2582
  return tmp;
2583
2583
  };
@@ -2703,7 +2703,7 @@ var starknet = (() => {
2703
2703
  }
2704
2704
  return num;
2705
2705
  };
2706
- BN3._prime = function prime(name) {
2706
+ BN4._prime = function prime(name) {
2707
2707
  if (primes[name])
2708
2708
  return primes[name];
2709
2709
  var prime2;
@@ -2723,7 +2723,7 @@ var starknet = (() => {
2723
2723
  };
2724
2724
  function Red(m) {
2725
2725
  if (typeof m === "string") {
2726
- var prime = BN3._prime(m);
2726
+ var prime = BN4._prime(m);
2727
2727
  this.m = prime.p;
2728
2728
  this.prime = prime;
2729
2729
  } else {
@@ -2811,7 +2811,7 @@ var starknet = (() => {
2811
2811
  var mod3 = this.m.andln(3);
2812
2812
  assert6(mod3 % 2 === 1);
2813
2813
  if (mod3 === 3) {
2814
- var pow = this.m.add(new BN3(1)).iushrn(2);
2814
+ var pow = this.m.add(new BN4(1)).iushrn(2);
2815
2815
  return this.pow(a, pow);
2816
2816
  }
2817
2817
  var q = this.m.subn(1);
@@ -2821,11 +2821,11 @@ var starknet = (() => {
2821
2821
  q.iushrn(1);
2822
2822
  }
2823
2823
  assert6(!q.isZero());
2824
- var one = new BN3(1).toRed(this);
2824
+ var one = new BN4(1).toRed(this);
2825
2825
  var nOne = one.redNeg();
2826
2826
  var lpow = this.m.subn(1).iushrn(1);
2827
2827
  var z = this.m.bitLength();
2828
- z = new BN3(2 * z * z).toRed(this);
2828
+ z = new BN4(2 * z * z).toRed(this);
2829
2829
  while (this.pow(z, lpow).cmp(nOne) !== 0) {
2830
2830
  z.redIAdd(nOne);
2831
2831
  }
@@ -2839,7 +2839,7 @@ var starknet = (() => {
2839
2839
  tmp = tmp.redSqr();
2840
2840
  }
2841
2841
  assert6(i < m);
2842
- var b = this.pow(c, new BN3(1).iushln(m - i - 1));
2842
+ var b = this.pow(c, new BN4(1).iushln(m - i - 1));
2843
2843
  r = r.redMul(b);
2844
2844
  c = b.redSqr();
2845
2845
  t = t.redMul(c);
@@ -2858,12 +2858,12 @@ var starknet = (() => {
2858
2858
  };
2859
2859
  Red.prototype.pow = function pow(a, num) {
2860
2860
  if (num.isZero())
2861
- return new BN3(1).toRed(this);
2861
+ return new BN4(1).toRed(this);
2862
2862
  if (num.cmpn(1) === 0)
2863
2863
  return a.clone();
2864
2864
  var windowSize = 4;
2865
2865
  var wnd = new Array(1 << windowSize);
2866
- wnd[0] = new BN3(1).toRed(this);
2866
+ wnd[0] = new BN4(1).toRed(this);
2867
2867
  wnd[1] = a;
2868
2868
  for (var i = 2; i < wnd.length; i++) {
2869
2869
  wnd[i] = this.mul(wnd[i - 1], a);
@@ -2908,7 +2908,7 @@ var starknet = (() => {
2908
2908
  res.red = null;
2909
2909
  return res;
2910
2910
  };
2911
- BN3.mont = function mont(num) {
2911
+ BN4.mont = function mont(num) {
2912
2912
  return new Mont(num);
2913
2913
  };
2914
2914
  function Mont(m) {
@@ -2917,7 +2917,7 @@ var starknet = (() => {
2917
2917
  if (this.shift % 26 !== 0) {
2918
2918
  this.shift += 26 - this.shift % 26;
2919
2919
  }
2920
- this.r = new BN3(1).iushln(this.shift);
2920
+ this.r = new BN4(1).iushln(this.shift);
2921
2921
  this.r2 = this.imod(this.r.sqr());
2922
2922
  this.rinv = this.r._invmp(this.m);
2923
2923
  this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
@@ -2952,7 +2952,7 @@ var starknet = (() => {
2952
2952
  };
2953
2953
  Mont.prototype.mul = function mul(a, b) {
2954
2954
  if (a.isZero() || b.isZero())
2955
- return new BN3(0)._forceRed(this);
2955
+ return new BN4(0)._forceRed(this);
2956
2956
  var t = a.mul(b);
2957
2957
  var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
2958
2958
  var u = t.isub(c).iushrn(this.shift);
@@ -4143,8 +4143,8 @@ var starknet = (() => {
4143
4143
  ctor.prototype = new TempCtor();
4144
4144
  ctor.prototype.constructor = ctor;
4145
4145
  }
4146
- function BN3(number, base, endian) {
4147
- if (BN3.isBN(number)) {
4146
+ function BN4(number, base, endian) {
4147
+ if (BN4.isBN(number)) {
4148
4148
  return number;
4149
4149
  }
4150
4150
  this.negative = 0;
@@ -4160,12 +4160,12 @@ var starknet = (() => {
4160
4160
  }
4161
4161
  }
4162
4162
  if (typeof module2 === "object") {
4163
- module2.exports = BN3;
4163
+ module2.exports = BN4;
4164
4164
  } else {
4165
- exports2.BN = BN3;
4165
+ exports2.BN = BN4;
4166
4166
  }
4167
- BN3.BN = BN3;
4168
- BN3.wordSize = 26;
4167
+ BN4.BN = BN4;
4168
+ BN4.wordSize = 26;
4169
4169
  var Buffer2;
4170
4170
  try {
4171
4171
  if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
@@ -4175,23 +4175,23 @@ var starknet = (() => {
4175
4175
  }
4176
4176
  } catch (e) {
4177
4177
  }
4178
- BN3.isBN = function isBN(num) {
4179
- if (num instanceof BN3) {
4178
+ BN4.isBN = function isBN(num) {
4179
+ if (num instanceof BN4) {
4180
4180
  return true;
4181
4181
  }
4182
- return num !== null && typeof num === "object" && num.constructor.wordSize === BN3.wordSize && Array.isArray(num.words);
4182
+ return num !== null && typeof num === "object" && num.constructor.wordSize === BN4.wordSize && Array.isArray(num.words);
4183
4183
  };
4184
- BN3.max = function max(left, right) {
4184
+ BN4.max = function max(left, right) {
4185
4185
  if (left.cmp(right) > 0)
4186
4186
  return left;
4187
4187
  return right;
4188
4188
  };
4189
- BN3.min = function min(left, right) {
4189
+ BN4.min = function min(left, right) {
4190
4190
  if (left.cmp(right) < 0)
4191
4191
  return left;
4192
4192
  return right;
4193
4193
  };
4194
- BN3.prototype._init = function init(number, base, endian) {
4194
+ BN4.prototype._init = function init(number, base, endian) {
4195
4195
  if (typeof number === "number") {
4196
4196
  return this._initNumber(number, base, endian);
4197
4197
  }
@@ -4219,7 +4219,7 @@ var starknet = (() => {
4219
4219
  }
4220
4220
  }
4221
4221
  };
4222
- BN3.prototype._initNumber = function _initNumber(number, base, endian) {
4222
+ BN4.prototype._initNumber = function _initNumber(number, base, endian) {
4223
4223
  if (number < 0) {
4224
4224
  this.negative = 1;
4225
4225
  number = -number;
@@ -4246,7 +4246,7 @@ var starknet = (() => {
4246
4246
  return;
4247
4247
  this._initArray(this.toArray(), base, endian);
4248
4248
  };
4249
- BN3.prototype._initArray = function _initArray(number, base, endian) {
4249
+ BN4.prototype._initArray = function _initArray(number, base, endian) {
4250
4250
  assert6(typeof number.length === "number");
4251
4251
  if (number.length <= 0) {
4252
4252
  this.words = [0];
@@ -4302,7 +4302,7 @@ var starknet = (() => {
4302
4302
  }
4303
4303
  return r;
4304
4304
  }
4305
- BN3.prototype._parseHex = function _parseHex(number, start, endian) {
4305
+ BN4.prototype._parseHex = function _parseHex(number, start, endian) {
4306
4306
  this.length = Math.ceil((number.length - start) / 6);
4307
4307
  this.words = new Array(this.length);
4308
4308
  for (var i = 0; i < this.length; i++) {
@@ -4355,7 +4355,7 @@ var starknet = (() => {
4355
4355
  }
4356
4356
  return r;
4357
4357
  }
4358
- BN3.prototype._parseBase = function _parseBase(number, base, start) {
4358
+ BN4.prototype._parseBase = function _parseBase(number, base, start) {
4359
4359
  this.words = [0];
4360
4360
  this.length = 1;
4361
4361
  for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
@@ -4391,7 +4391,7 @@ var starknet = (() => {
4391
4391
  }
4392
4392
  this.strip();
4393
4393
  };
4394
- BN3.prototype.copy = function copy(dest) {
4394
+ BN4.prototype.copy = function copy(dest) {
4395
4395
  dest.words = new Array(this.length);
4396
4396
  for (var i = 0; i < this.length; i++) {
4397
4397
  dest.words[i] = this.words[i];
@@ -4400,30 +4400,30 @@ var starknet = (() => {
4400
4400
  dest.negative = this.negative;
4401
4401
  dest.red = this.red;
4402
4402
  };
4403
- BN3.prototype.clone = function clone() {
4404
- var r = new BN3(null);
4403
+ BN4.prototype.clone = function clone() {
4404
+ var r = new BN4(null);
4405
4405
  this.copy(r);
4406
4406
  return r;
4407
4407
  };
4408
- BN3.prototype._expand = function _expand(size) {
4408
+ BN4.prototype._expand = function _expand(size) {
4409
4409
  while (this.length < size) {
4410
4410
  this.words[this.length++] = 0;
4411
4411
  }
4412
4412
  return this;
4413
4413
  };
4414
- BN3.prototype.strip = function strip() {
4414
+ BN4.prototype.strip = function strip() {
4415
4415
  while (this.length > 1 && this.words[this.length - 1] === 0) {
4416
4416
  this.length--;
4417
4417
  }
4418
4418
  return this._normSign();
4419
4419
  };
4420
- BN3.prototype._normSign = function _normSign() {
4420
+ BN4.prototype._normSign = function _normSign() {
4421
4421
  if (this.length === 1 && this.words[0] === 0) {
4422
4422
  this.negative = 0;
4423
4423
  }
4424
4424
  return this;
4425
4425
  };
4426
- BN3.prototype.inspect = function inspect() {
4426
+ BN4.prototype.inspect = function inspect() {
4427
4427
  return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
4428
4428
  };
4429
4429
  var zeros = [
@@ -4532,7 +4532,7 @@ var starknet = (() => {
4532
4532
  52521875,
4533
4533
  60466176
4534
4534
  ];
4535
- BN3.prototype.toString = function toString2(base, padding) {
4535
+ BN4.prototype.toString = function toString2(base, padding) {
4536
4536
  base = base || 10;
4537
4537
  padding = padding | 0 || 1;
4538
4538
  var out;
@@ -4594,7 +4594,7 @@ var starknet = (() => {
4594
4594
  }
4595
4595
  assert6(false, "Base should be between 2 and 36");
4596
4596
  };
4597
- BN3.prototype.toNumber = function toNumber() {
4597
+ BN4.prototype.toNumber = function toNumber() {
4598
4598
  var ret = this.words[0];
4599
4599
  if (this.length === 2) {
4600
4600
  ret += this.words[1] * 67108864;
@@ -4605,17 +4605,17 @@ var starknet = (() => {
4605
4605
  }
4606
4606
  return this.negative !== 0 ? -ret : ret;
4607
4607
  };
4608
- BN3.prototype.toJSON = function toJSON() {
4608
+ BN4.prototype.toJSON = function toJSON() {
4609
4609
  return this.toString(16);
4610
4610
  };
4611
- BN3.prototype.toBuffer = function toBuffer(endian, length) {
4611
+ BN4.prototype.toBuffer = function toBuffer(endian, length) {
4612
4612
  assert6(typeof Buffer2 !== "undefined");
4613
4613
  return this.toArrayLike(Buffer2, endian, length);
4614
4614
  };
4615
- BN3.prototype.toArray = function toArray(endian, length) {
4615
+ BN4.prototype.toArray = function toArray(endian, length) {
4616
4616
  return this.toArrayLike(Array, endian, length);
4617
4617
  };
4618
- BN3.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
4618
+ BN4.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
4619
4619
  var byteLength = this.byteLength();
4620
4620
  var reqLength = length || Math.max(1, byteLength);
4621
4621
  assert6(byteLength <= reqLength, "byte array longer than desired length");
@@ -4647,11 +4647,11 @@ var starknet = (() => {
4647
4647
  return res;
4648
4648
  };
4649
4649
  if (Math.clz32) {
4650
- BN3.prototype._countBits = function _countBits(w) {
4650
+ BN4.prototype._countBits = function _countBits(w) {
4651
4651
  return 32 - Math.clz32(w);
4652
4652
  };
4653
4653
  } else {
4654
- BN3.prototype._countBits = function _countBits(w) {
4654
+ BN4.prototype._countBits = function _countBits(w) {
4655
4655
  var t = w;
4656
4656
  var r = 0;
4657
4657
  if (t >= 4096) {
@@ -4673,7 +4673,7 @@ var starknet = (() => {
4673
4673
  return r + t;
4674
4674
  };
4675
4675
  }
4676
- BN3.prototype._zeroBits = function _zeroBits(w) {
4676
+ BN4.prototype._zeroBits = function _zeroBits(w) {
4677
4677
  if (w === 0)
4678
4678
  return 26;
4679
4679
  var t = w;
@@ -4699,7 +4699,7 @@ var starknet = (() => {
4699
4699
  }
4700
4700
  return r;
4701
4701
  };
4702
- BN3.prototype.bitLength = function bitLength() {
4702
+ BN4.prototype.bitLength = function bitLength() {
4703
4703
  var w = this.words[this.length - 1];
4704
4704
  var hi = this._countBits(w);
4705
4705
  return (this.length - 1) * 26 + hi;
@@ -4713,7 +4713,7 @@ var starknet = (() => {
4713
4713
  }
4714
4714
  return w;
4715
4715
  }
4716
- BN3.prototype.zeroBits = function zeroBits() {
4716
+ BN4.prototype.zeroBits = function zeroBits() {
4717
4717
  if (this.isZero())
4718
4718
  return 0;
4719
4719
  var r = 0;
@@ -4725,34 +4725,34 @@ var starknet = (() => {
4725
4725
  }
4726
4726
  return r;
4727
4727
  };
4728
- BN3.prototype.byteLength = function byteLength() {
4728
+ BN4.prototype.byteLength = function byteLength() {
4729
4729
  return Math.ceil(this.bitLength() / 8);
4730
4730
  };
4731
- BN3.prototype.toTwos = function toTwos(width) {
4731
+ BN4.prototype.toTwos = function toTwos(width) {
4732
4732
  if (this.negative !== 0) {
4733
4733
  return this.abs().inotn(width).iaddn(1);
4734
4734
  }
4735
4735
  return this.clone();
4736
4736
  };
4737
- BN3.prototype.fromTwos = function fromTwos(width) {
4737
+ BN4.prototype.fromTwos = function fromTwos(width) {
4738
4738
  if (this.testn(width - 1)) {
4739
4739
  return this.notn(width).iaddn(1).ineg();
4740
4740
  }
4741
4741
  return this.clone();
4742
4742
  };
4743
- BN3.prototype.isNeg = function isNeg() {
4743
+ BN4.prototype.isNeg = function isNeg() {
4744
4744
  return this.negative !== 0;
4745
4745
  };
4746
- BN3.prototype.neg = function neg() {
4746
+ BN4.prototype.neg = function neg() {
4747
4747
  return this.clone().ineg();
4748
4748
  };
4749
- BN3.prototype.ineg = function ineg() {
4749
+ BN4.prototype.ineg = function ineg() {
4750
4750
  if (!this.isZero()) {
4751
4751
  this.negative ^= 1;
4752
4752
  }
4753
4753
  return this;
4754
4754
  };
4755
- BN3.prototype.iuor = function iuor(num) {
4755
+ BN4.prototype.iuor = function iuor(num) {
4756
4756
  while (this.length < num.length) {
4757
4757
  this.words[this.length++] = 0;
4758
4758
  }
@@ -4761,21 +4761,21 @@ var starknet = (() => {
4761
4761
  }
4762
4762
  return this.strip();
4763
4763
  };
4764
- BN3.prototype.ior = function ior(num) {
4764
+ BN4.prototype.ior = function ior(num) {
4765
4765
  assert6((this.negative | num.negative) === 0);
4766
4766
  return this.iuor(num);
4767
4767
  };
4768
- BN3.prototype.or = function or(num) {
4768
+ BN4.prototype.or = function or(num) {
4769
4769
  if (this.length > num.length)
4770
4770
  return this.clone().ior(num);
4771
4771
  return num.clone().ior(this);
4772
4772
  };
4773
- BN3.prototype.uor = function uor(num) {
4773
+ BN4.prototype.uor = function uor(num) {
4774
4774
  if (this.length > num.length)
4775
4775
  return this.clone().iuor(num);
4776
4776
  return num.clone().iuor(this);
4777
4777
  };
4778
- BN3.prototype.iuand = function iuand(num) {
4778
+ BN4.prototype.iuand = function iuand(num) {
4779
4779
  var b;
4780
4780
  if (this.length > num.length) {
4781
4781
  b = num;
@@ -4788,21 +4788,21 @@ var starknet = (() => {
4788
4788
  this.length = b.length;
4789
4789
  return this.strip();
4790
4790
  };
4791
- BN3.prototype.iand = function iand(num) {
4791
+ BN4.prototype.iand = function iand(num) {
4792
4792
  assert6((this.negative | num.negative) === 0);
4793
4793
  return this.iuand(num);
4794
4794
  };
4795
- BN3.prototype.and = function and(num) {
4795
+ BN4.prototype.and = function and(num) {
4796
4796
  if (this.length > num.length)
4797
4797
  return this.clone().iand(num);
4798
4798
  return num.clone().iand(this);
4799
4799
  };
4800
- BN3.prototype.uand = function uand(num) {
4800
+ BN4.prototype.uand = function uand(num) {
4801
4801
  if (this.length > num.length)
4802
4802
  return this.clone().iuand(num);
4803
4803
  return num.clone().iuand(this);
4804
4804
  };
4805
- BN3.prototype.iuxor = function iuxor(num) {
4805
+ BN4.prototype.iuxor = function iuxor(num) {
4806
4806
  var a;
4807
4807
  var b;
4808
4808
  if (this.length > num.length) {
@@ -4823,21 +4823,21 @@ var starknet = (() => {
4823
4823
  this.length = a.length;
4824
4824
  return this.strip();
4825
4825
  };
4826
- BN3.prototype.ixor = function ixor(num) {
4826
+ BN4.prototype.ixor = function ixor(num) {
4827
4827
  assert6((this.negative | num.negative) === 0);
4828
4828
  return this.iuxor(num);
4829
4829
  };
4830
- BN3.prototype.xor = function xor(num) {
4830
+ BN4.prototype.xor = function xor(num) {
4831
4831
  if (this.length > num.length)
4832
4832
  return this.clone().ixor(num);
4833
4833
  return num.clone().ixor(this);
4834
4834
  };
4835
- BN3.prototype.uxor = function uxor(num) {
4835
+ BN4.prototype.uxor = function uxor(num) {
4836
4836
  if (this.length > num.length)
4837
4837
  return this.clone().iuxor(num);
4838
4838
  return num.clone().iuxor(this);
4839
4839
  };
4840
- BN3.prototype.inotn = function inotn(width) {
4840
+ BN4.prototype.inotn = function inotn(width) {
4841
4841
  assert6(typeof width === "number" && width >= 0);
4842
4842
  var bytesNeeded = Math.ceil(width / 26) | 0;
4843
4843
  var bitsLeft = width % 26;
@@ -4853,10 +4853,10 @@ var starknet = (() => {
4853
4853
  }
4854
4854
  return this.strip();
4855
4855
  };
4856
- BN3.prototype.notn = function notn(width) {
4856
+ BN4.prototype.notn = function notn(width) {
4857
4857
  return this.clone().inotn(width);
4858
4858
  };
4859
- BN3.prototype.setn = function setn(bit, val) {
4859
+ BN4.prototype.setn = function setn(bit, val) {
4860
4860
  assert6(typeof bit === "number" && bit >= 0);
4861
4861
  var off = bit / 26 | 0;
4862
4862
  var wbit = bit % 26;
@@ -4868,7 +4868,7 @@ var starknet = (() => {
4868
4868
  }
4869
4869
  return this.strip();
4870
4870
  };
4871
- BN3.prototype.iadd = function iadd(num) {
4871
+ BN4.prototype.iadd = function iadd(num) {
4872
4872
  var r;
4873
4873
  if (this.negative !== 0 && num.negative === 0) {
4874
4874
  this.negative = 0;
@@ -4911,7 +4911,7 @@ var starknet = (() => {
4911
4911
  }
4912
4912
  return this;
4913
4913
  };
4914
- BN3.prototype.add = function add(num) {
4914
+ BN4.prototype.add = function add(num) {
4915
4915
  var res;
4916
4916
  if (num.negative !== 0 && this.negative === 0) {
4917
4917
  num.negative = 0;
@@ -4928,7 +4928,7 @@ var starknet = (() => {
4928
4928
  return this.clone().iadd(num);
4929
4929
  return num.clone().iadd(this);
4930
4930
  };
4931
- BN3.prototype.isub = function isub(num) {
4931
+ BN4.prototype.isub = function isub(num) {
4932
4932
  if (num.negative !== 0) {
4933
4933
  num.negative = 0;
4934
4934
  var r = this.iadd(num);
@@ -4977,7 +4977,7 @@ var starknet = (() => {
4977
4977
  }
4978
4978
  return this.strip();
4979
4979
  };
4980
- BN3.prototype.sub = function sub(num) {
4980
+ BN4.prototype.sub = function sub(num) {
4981
4981
  return this.clone().isub(num);
4982
4982
  };
4983
4983
  function smallMulTo(self2, num, out) {
@@ -5606,7 +5606,7 @@ var starknet = (() => {
5606
5606
  var fftm = new FFTM();
5607
5607
  return fftm.mulp(self2, num, out);
5608
5608
  }
5609
- BN3.prototype.mulTo = function mulTo(num, out) {
5609
+ BN4.prototype.mulTo = function mulTo(num, out) {
5610
5610
  var res;
5611
5611
  var len = this.length + num.length;
5612
5612
  if (this.length === 10 && num.length === 10) {
@@ -5626,7 +5626,7 @@ var starknet = (() => {
5626
5626
  }
5627
5627
  FFTM.prototype.makeRBT = function makeRBT(N) {
5628
5628
  var t = new Array(N);
5629
- var l = BN3.prototype._countBits(N) - 1;
5629
+ var l = BN4.prototype._countBits(N) - 1;
5630
5630
  for (var i = 0; i < N; i++) {
5631
5631
  t[i] = this.revBin(i, l, N);
5632
5632
  }
@@ -5763,20 +5763,20 @@ var starknet = (() => {
5763
5763
  out.length = x.length + y.length;
5764
5764
  return out.strip();
5765
5765
  };
5766
- BN3.prototype.mul = function mul(num) {
5767
- var out = new BN3(null);
5766
+ BN4.prototype.mul = function mul(num) {
5767
+ var out = new BN4(null);
5768
5768
  out.words = new Array(this.length + num.length);
5769
5769
  return this.mulTo(num, out);
5770
5770
  };
5771
- BN3.prototype.mulf = function mulf(num) {
5772
- var out = new BN3(null);
5771
+ BN4.prototype.mulf = function mulf(num) {
5772
+ var out = new BN4(null);
5773
5773
  out.words = new Array(this.length + num.length);
5774
5774
  return jumboMulTo(this, num, out);
5775
5775
  };
5776
- BN3.prototype.imul = function imul(num) {
5776
+ BN4.prototype.imul = function imul(num) {
5777
5777
  return this.clone().mulTo(num, this);
5778
5778
  };
5779
- BN3.prototype.imuln = function imuln(num) {
5779
+ BN4.prototype.imuln = function imuln(num) {
5780
5780
  assert6(typeof num === "number");
5781
5781
  assert6(num < 67108864);
5782
5782
  var carry = 0;
@@ -5794,19 +5794,19 @@ var starknet = (() => {
5794
5794
  }
5795
5795
  return this;
5796
5796
  };
5797
- BN3.prototype.muln = function muln(num) {
5797
+ BN4.prototype.muln = function muln(num) {
5798
5798
  return this.clone().imuln(num);
5799
5799
  };
5800
- BN3.prototype.sqr = function sqr() {
5800
+ BN4.prototype.sqr = function sqr() {
5801
5801
  return this.mul(this);
5802
5802
  };
5803
- BN3.prototype.isqr = function isqr() {
5803
+ BN4.prototype.isqr = function isqr() {
5804
5804
  return this.imul(this.clone());
5805
5805
  };
5806
- BN3.prototype.pow = function pow(num) {
5806
+ BN4.prototype.pow = function pow(num) {
5807
5807
  var w = toBitArray(num);
5808
5808
  if (w.length === 0)
5809
- return new BN3(1);
5809
+ return new BN4(1);
5810
5810
  var res = this;
5811
5811
  for (var i = 0; i < w.length; i++, res = res.sqr()) {
5812
5812
  if (w[i] !== 0)
@@ -5821,7 +5821,7 @@ var starknet = (() => {
5821
5821
  }
5822
5822
  return res;
5823
5823
  };
5824
- BN3.prototype.iushln = function iushln(bits) {
5824
+ BN4.prototype.iushln = function iushln(bits) {
5825
5825
  assert6(typeof bits === "number" && bits >= 0);
5826
5826
  var r = bits % 26;
5827
5827
  var s = (bits - r) / 26;
@@ -5851,11 +5851,11 @@ var starknet = (() => {
5851
5851
  }
5852
5852
  return this.strip();
5853
5853
  };
5854
- BN3.prototype.ishln = function ishln(bits) {
5854
+ BN4.prototype.ishln = function ishln(bits) {
5855
5855
  assert6(this.negative === 0);
5856
5856
  return this.iushln(bits);
5857
5857
  };
5858
- BN3.prototype.iushrn = function iushrn(bits, hint, extended) {
5858
+ BN4.prototype.iushrn = function iushrn(bits, hint, extended) {
5859
5859
  assert6(typeof bits === "number" && bits >= 0);
5860
5860
  var h;
5861
5861
  if (hint) {
@@ -5900,23 +5900,23 @@ var starknet = (() => {
5900
5900
  }
5901
5901
  return this.strip();
5902
5902
  };
5903
- BN3.prototype.ishrn = function ishrn(bits, hint, extended) {
5903
+ BN4.prototype.ishrn = function ishrn(bits, hint, extended) {
5904
5904
  assert6(this.negative === 0);
5905
5905
  return this.iushrn(bits, hint, extended);
5906
5906
  };
5907
- BN3.prototype.shln = function shln(bits) {
5907
+ BN4.prototype.shln = function shln(bits) {
5908
5908
  return this.clone().ishln(bits);
5909
5909
  };
5910
- BN3.prototype.ushln = function ushln(bits) {
5910
+ BN4.prototype.ushln = function ushln(bits) {
5911
5911
  return this.clone().iushln(bits);
5912
5912
  };
5913
- BN3.prototype.shrn = function shrn(bits) {
5913
+ BN4.prototype.shrn = function shrn(bits) {
5914
5914
  return this.clone().ishrn(bits);
5915
5915
  };
5916
- BN3.prototype.ushrn = function ushrn(bits) {
5916
+ BN4.prototype.ushrn = function ushrn(bits) {
5917
5917
  return this.clone().iushrn(bits);
5918
5918
  };
5919
- BN3.prototype.testn = function testn(bit) {
5919
+ BN4.prototype.testn = function testn(bit) {
5920
5920
  assert6(typeof bit === "number" && bit >= 0);
5921
5921
  var r = bit % 26;
5922
5922
  var s = (bit - r) / 26;
@@ -5926,7 +5926,7 @@ var starknet = (() => {
5926
5926
  var w = this.words[s];
5927
5927
  return !!(w & q);
5928
5928
  };
5929
- BN3.prototype.imaskn = function imaskn(bits) {
5929
+ BN4.prototype.imaskn = function imaskn(bits) {
5930
5930
  assert6(typeof bits === "number" && bits >= 0);
5931
5931
  var r = bits % 26;
5932
5932
  var s = (bits - r) / 26;
@@ -5944,10 +5944,10 @@ var starknet = (() => {
5944
5944
  }
5945
5945
  return this.strip();
5946
5946
  };
5947
- BN3.prototype.maskn = function maskn(bits) {
5947
+ BN4.prototype.maskn = function maskn(bits) {
5948
5948
  return this.clone().imaskn(bits);
5949
5949
  };
5950
- BN3.prototype.iaddn = function iaddn(num) {
5950
+ BN4.prototype.iaddn = function iaddn(num) {
5951
5951
  assert6(typeof num === "number");
5952
5952
  assert6(num < 67108864);
5953
5953
  if (num < 0)
@@ -5965,7 +5965,7 @@ var starknet = (() => {
5965
5965
  }
5966
5966
  return this._iaddn(num);
5967
5967
  };
5968
- BN3.prototype._iaddn = function _iaddn(num) {
5968
+ BN4.prototype._iaddn = function _iaddn(num) {
5969
5969
  this.words[0] += num;
5970
5970
  for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
5971
5971
  this.words[i] -= 67108864;
@@ -5978,7 +5978,7 @@ var starknet = (() => {
5978
5978
  this.length = Math.max(this.length, i + 1);
5979
5979
  return this;
5980
5980
  };
5981
- BN3.prototype.isubn = function isubn(num) {
5981
+ BN4.prototype.isubn = function isubn(num) {
5982
5982
  assert6(typeof num === "number");
5983
5983
  assert6(num < 67108864);
5984
5984
  if (num < 0)
@@ -6001,20 +6001,20 @@ var starknet = (() => {
6001
6001
  }
6002
6002
  return this.strip();
6003
6003
  };
6004
- BN3.prototype.addn = function addn(num) {
6004
+ BN4.prototype.addn = function addn(num) {
6005
6005
  return this.clone().iaddn(num);
6006
6006
  };
6007
- BN3.prototype.subn = function subn(num) {
6007
+ BN4.prototype.subn = function subn(num) {
6008
6008
  return this.clone().isubn(num);
6009
6009
  };
6010
- BN3.prototype.iabs = function iabs() {
6010
+ BN4.prototype.iabs = function iabs() {
6011
6011
  this.negative = 0;
6012
6012
  return this;
6013
6013
  };
6014
- BN3.prototype.abs = function abs() {
6014
+ BN4.prototype.abs = function abs() {
6015
6015
  return this.clone().iabs();
6016
6016
  };
6017
- BN3.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
6017
+ BN4.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
6018
6018
  var len = num.length + shift;
6019
6019
  var i;
6020
6020
  this._expand(len);
@@ -6044,7 +6044,7 @@ var starknet = (() => {
6044
6044
  this.negative = 1;
6045
6045
  return this.strip();
6046
6046
  };
6047
- BN3.prototype._wordDiv = function _wordDiv(num, mode) {
6047
+ BN4.prototype._wordDiv = function _wordDiv(num, mode) {
6048
6048
  var shift = this.length - num.length;
6049
6049
  var a = this.clone();
6050
6050
  var b = num;
@@ -6059,7 +6059,7 @@ var starknet = (() => {
6059
6059
  var m = a.length - b.length;
6060
6060
  var q;
6061
6061
  if (mode !== "mod") {
6062
- q = new BN3(null);
6062
+ q = new BN4(null);
6063
6063
  q.length = m + 1;
6064
6064
  q.words = new Array(q.length);
6065
6065
  for (var i = 0; i < q.length; i++) {
@@ -6101,12 +6101,12 @@ var starknet = (() => {
6101
6101
  mod: a
6102
6102
  };
6103
6103
  };
6104
- BN3.prototype.divmod = function divmod(num, mode, positive) {
6104
+ BN4.prototype.divmod = function divmod(num, mode, positive) {
6105
6105
  assert6(!num.isZero());
6106
6106
  if (this.isZero()) {
6107
6107
  return {
6108
- div: new BN3(0),
6109
- mod: new BN3(0)
6108
+ div: new BN4(0),
6109
+ mod: new BN4(0)
6110
6110
  };
6111
6111
  }
6112
6112
  var div, mod, res;
@@ -6151,7 +6151,7 @@ var starknet = (() => {
6151
6151
  }
6152
6152
  if (num.length > this.length || this.cmp(num) < 0) {
6153
6153
  return {
6154
- div: new BN3(0),
6154
+ div: new BN4(0),
6155
6155
  mod: this
6156
6156
  };
6157
6157
  }
@@ -6165,26 +6165,26 @@ var starknet = (() => {
6165
6165
  if (mode === "mod") {
6166
6166
  return {
6167
6167
  div: null,
6168
- mod: new BN3(this.modn(num.words[0]))
6168
+ mod: new BN4(this.modn(num.words[0]))
6169
6169
  };
6170
6170
  }
6171
6171
  return {
6172
6172
  div: this.divn(num.words[0]),
6173
- mod: new BN3(this.modn(num.words[0]))
6173
+ mod: new BN4(this.modn(num.words[0]))
6174
6174
  };
6175
6175
  }
6176
6176
  return this._wordDiv(num, mode);
6177
6177
  };
6178
- BN3.prototype.div = function div(num) {
6178
+ BN4.prototype.div = function div(num) {
6179
6179
  return this.divmod(num, "div", false).div;
6180
6180
  };
6181
- BN3.prototype.mod = function mod(num) {
6181
+ BN4.prototype.mod = function mod(num) {
6182
6182
  return this.divmod(num, "mod", false).mod;
6183
6183
  };
6184
- BN3.prototype.umod = function umod(num) {
6184
+ BN4.prototype.umod = function umod(num) {
6185
6185
  return this.divmod(num, "mod", true).mod;
6186
6186
  };
6187
- BN3.prototype.divRound = function divRound(num) {
6187
+ BN4.prototype.divRound = function divRound(num) {
6188
6188
  var dm = this.divmod(num);
6189
6189
  if (dm.mod.isZero())
6190
6190
  return dm.div;
@@ -6196,7 +6196,7 @@ var starknet = (() => {
6196
6196
  return dm.div;
6197
6197
  return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
6198
6198
  };
6199
- BN3.prototype.modn = function modn(num) {
6199
+ BN4.prototype.modn = function modn(num) {
6200
6200
  assert6(num <= 67108863);
6201
6201
  var p = (1 << 26) % num;
6202
6202
  var acc = 0;
@@ -6205,7 +6205,7 @@ var starknet = (() => {
6205
6205
  }
6206
6206
  return acc;
6207
6207
  };
6208
- BN3.prototype.idivn = function idivn(num) {
6208
+ BN4.prototype.idivn = function idivn(num) {
6209
6209
  assert6(num <= 67108863);
6210
6210
  var carry = 0;
6211
6211
  for (var i = this.length - 1; i >= 0; i--) {
@@ -6215,10 +6215,10 @@ var starknet = (() => {
6215
6215
  }
6216
6216
  return this.strip();
6217
6217
  };
6218
- BN3.prototype.divn = function divn(num) {
6218
+ BN4.prototype.divn = function divn(num) {
6219
6219
  return this.clone().idivn(num);
6220
6220
  };
6221
- BN3.prototype.egcd = function egcd(p) {
6221
+ BN4.prototype.egcd = function egcd(p) {
6222
6222
  assert6(p.negative === 0);
6223
6223
  assert6(!p.isZero());
6224
6224
  var x = this;
@@ -6228,10 +6228,10 @@ var starknet = (() => {
6228
6228
  } else {
6229
6229
  x = x.clone();
6230
6230
  }
6231
- var A = new BN3(1);
6232
- var B = new BN3(0);
6233
- var C = new BN3(0);
6234
- var D = new BN3(1);
6231
+ var A = new BN4(1);
6232
+ var B = new BN4(0);
6233
+ var C = new BN4(0);
6234
+ var D = new BN4(1);
6235
6235
  var g = 0;
6236
6236
  while (x.isEven() && y.isEven()) {
6237
6237
  x.iushrn(1);
@@ -6283,7 +6283,7 @@ var starknet = (() => {
6283
6283
  gcd: y.iushln(g)
6284
6284
  };
6285
6285
  };
6286
- BN3.prototype._invmp = function _invmp(p) {
6286
+ BN4.prototype._invmp = function _invmp(p) {
6287
6287
  assert6(p.negative === 0);
6288
6288
  assert6(!p.isZero());
6289
6289
  var a = this;
@@ -6293,8 +6293,8 @@ var starknet = (() => {
6293
6293
  } else {
6294
6294
  a = a.clone();
6295
6295
  }
6296
- var x1 = new BN3(1);
6297
- var x2 = new BN3(0);
6296
+ var x1 = new BN4(1);
6297
+ var x2 = new BN4(0);
6298
6298
  var delta = b.clone();
6299
6299
  while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
6300
6300
  for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1)
@@ -6338,7 +6338,7 @@ var starknet = (() => {
6338
6338
  }
6339
6339
  return res;
6340
6340
  };
6341
- BN3.prototype.gcd = function gcd(num) {
6341
+ BN4.prototype.gcd = function gcd(num) {
6342
6342
  if (this.isZero())
6343
6343
  return num.abs();
6344
6344
  if (num.isZero())
@@ -6370,19 +6370,19 @@ var starknet = (() => {
6370
6370
  } while (true);
6371
6371
  return b.iushln(shift);
6372
6372
  };
6373
- BN3.prototype.invm = function invm(num) {
6373
+ BN4.prototype.invm = function invm(num) {
6374
6374
  return this.egcd(num).a.umod(num);
6375
6375
  };
6376
- BN3.prototype.isEven = function isEven() {
6376
+ BN4.prototype.isEven = function isEven() {
6377
6377
  return (this.words[0] & 1) === 0;
6378
6378
  };
6379
- BN3.prototype.isOdd = function isOdd() {
6379
+ BN4.prototype.isOdd = function isOdd() {
6380
6380
  return (this.words[0] & 1) === 1;
6381
6381
  };
6382
- BN3.prototype.andln = function andln(num) {
6382
+ BN4.prototype.andln = function andln(num) {
6383
6383
  return this.words[0] & num;
6384
6384
  };
6385
- BN3.prototype.bincn = function bincn(bit) {
6385
+ BN4.prototype.bincn = function bincn(bit) {
6386
6386
  assert6(typeof bit === "number");
6387
6387
  var r = bit % 26;
6388
6388
  var s = (bit - r) / 26;
@@ -6406,10 +6406,10 @@ var starknet = (() => {
6406
6406
  }
6407
6407
  return this;
6408
6408
  };
6409
- BN3.prototype.isZero = function isZero() {
6409
+ BN4.prototype.isZero = function isZero() {
6410
6410
  return this.length === 1 && this.words[0] === 0;
6411
6411
  };
6412
- BN3.prototype.cmpn = function cmpn(num) {
6412
+ BN4.prototype.cmpn = function cmpn(num) {
6413
6413
  var negative = num < 0;
6414
6414
  if (this.negative !== 0 && !negative)
6415
6415
  return -1;
@@ -6431,7 +6431,7 @@ var starknet = (() => {
6431
6431
  return -res | 0;
6432
6432
  return res;
6433
6433
  };
6434
- BN3.prototype.cmp = function cmp(num) {
6434
+ BN4.prototype.cmp = function cmp(num) {
6435
6435
  if (this.negative !== 0 && num.negative === 0)
6436
6436
  return -1;
6437
6437
  if (this.negative === 0 && num.negative !== 0)
@@ -6441,7 +6441,7 @@ var starknet = (() => {
6441
6441
  return -res | 0;
6442
6442
  return res;
6443
6443
  };
6444
- BN3.prototype.ucmp = function ucmp(num) {
6444
+ BN4.prototype.ucmp = function ucmp(num) {
6445
6445
  if (this.length > num.length)
6446
6446
  return 1;
6447
6447
  if (this.length < num.length)
@@ -6461,112 +6461,112 @@ var starknet = (() => {
6461
6461
  }
6462
6462
  return res;
6463
6463
  };
6464
- BN3.prototype.gtn = function gtn(num) {
6464
+ BN4.prototype.gtn = function gtn(num) {
6465
6465
  return this.cmpn(num) === 1;
6466
6466
  };
6467
- BN3.prototype.gt = function gt(num) {
6467
+ BN4.prototype.gt = function gt(num) {
6468
6468
  return this.cmp(num) === 1;
6469
6469
  };
6470
- BN3.prototype.gten = function gten(num) {
6470
+ BN4.prototype.gten = function gten(num) {
6471
6471
  return this.cmpn(num) >= 0;
6472
6472
  };
6473
- BN3.prototype.gte = function gte(num) {
6473
+ BN4.prototype.gte = function gte(num) {
6474
6474
  return this.cmp(num) >= 0;
6475
6475
  };
6476
- BN3.prototype.ltn = function ltn(num) {
6476
+ BN4.prototype.ltn = function ltn(num) {
6477
6477
  return this.cmpn(num) === -1;
6478
6478
  };
6479
- BN3.prototype.lt = function lt(num) {
6479
+ BN4.prototype.lt = function lt(num) {
6480
6480
  return this.cmp(num) === -1;
6481
6481
  };
6482
- BN3.prototype.lten = function lten(num) {
6482
+ BN4.prototype.lten = function lten(num) {
6483
6483
  return this.cmpn(num) <= 0;
6484
6484
  };
6485
- BN3.prototype.lte = function lte(num) {
6485
+ BN4.prototype.lte = function lte(num) {
6486
6486
  return this.cmp(num) <= 0;
6487
6487
  };
6488
- BN3.prototype.eqn = function eqn(num) {
6488
+ BN4.prototype.eqn = function eqn(num) {
6489
6489
  return this.cmpn(num) === 0;
6490
6490
  };
6491
- BN3.prototype.eq = function eq(num) {
6491
+ BN4.prototype.eq = function eq(num) {
6492
6492
  return this.cmp(num) === 0;
6493
6493
  };
6494
- BN3.red = function red(num) {
6494
+ BN4.red = function red(num) {
6495
6495
  return new Red(num);
6496
6496
  };
6497
- BN3.prototype.toRed = function toRed(ctx) {
6497
+ BN4.prototype.toRed = function toRed(ctx) {
6498
6498
  assert6(!this.red, "Already a number in reduction context");
6499
6499
  assert6(this.negative === 0, "red works only with positives");
6500
6500
  return ctx.convertTo(this)._forceRed(ctx);
6501
6501
  };
6502
- BN3.prototype.fromRed = function fromRed() {
6502
+ BN4.prototype.fromRed = function fromRed() {
6503
6503
  assert6(this.red, "fromRed works only with numbers in reduction context");
6504
6504
  return this.red.convertFrom(this);
6505
6505
  };
6506
- BN3.prototype._forceRed = function _forceRed(ctx) {
6506
+ BN4.prototype._forceRed = function _forceRed(ctx) {
6507
6507
  this.red = ctx;
6508
6508
  return this;
6509
6509
  };
6510
- BN3.prototype.forceRed = function forceRed(ctx) {
6510
+ BN4.prototype.forceRed = function forceRed(ctx) {
6511
6511
  assert6(!this.red, "Already a number in reduction context");
6512
6512
  return this._forceRed(ctx);
6513
6513
  };
6514
- BN3.prototype.redAdd = function redAdd(num) {
6514
+ BN4.prototype.redAdd = function redAdd(num) {
6515
6515
  assert6(this.red, "redAdd works only with red numbers");
6516
6516
  return this.red.add(this, num);
6517
6517
  };
6518
- BN3.prototype.redIAdd = function redIAdd(num) {
6518
+ BN4.prototype.redIAdd = function redIAdd(num) {
6519
6519
  assert6(this.red, "redIAdd works only with red numbers");
6520
6520
  return this.red.iadd(this, num);
6521
6521
  };
6522
- BN3.prototype.redSub = function redSub(num) {
6522
+ BN4.prototype.redSub = function redSub(num) {
6523
6523
  assert6(this.red, "redSub works only with red numbers");
6524
6524
  return this.red.sub(this, num);
6525
6525
  };
6526
- BN3.prototype.redISub = function redISub(num) {
6526
+ BN4.prototype.redISub = function redISub(num) {
6527
6527
  assert6(this.red, "redISub works only with red numbers");
6528
6528
  return this.red.isub(this, num);
6529
6529
  };
6530
- BN3.prototype.redShl = function redShl(num) {
6530
+ BN4.prototype.redShl = function redShl(num) {
6531
6531
  assert6(this.red, "redShl works only with red numbers");
6532
6532
  return this.red.shl(this, num);
6533
6533
  };
6534
- BN3.prototype.redMul = function redMul(num) {
6534
+ BN4.prototype.redMul = function redMul(num) {
6535
6535
  assert6(this.red, "redMul works only with red numbers");
6536
6536
  this.red._verify2(this, num);
6537
6537
  return this.red.mul(this, num);
6538
6538
  };
6539
- BN3.prototype.redIMul = function redIMul(num) {
6539
+ BN4.prototype.redIMul = function redIMul(num) {
6540
6540
  assert6(this.red, "redMul works only with red numbers");
6541
6541
  this.red._verify2(this, num);
6542
6542
  return this.red.imul(this, num);
6543
6543
  };
6544
- BN3.prototype.redSqr = function redSqr() {
6544
+ BN4.prototype.redSqr = function redSqr() {
6545
6545
  assert6(this.red, "redSqr works only with red numbers");
6546
6546
  this.red._verify1(this);
6547
6547
  return this.red.sqr(this);
6548
6548
  };
6549
- BN3.prototype.redISqr = function redISqr() {
6549
+ BN4.prototype.redISqr = function redISqr() {
6550
6550
  assert6(this.red, "redISqr works only with red numbers");
6551
6551
  this.red._verify1(this);
6552
6552
  return this.red.isqr(this);
6553
6553
  };
6554
- BN3.prototype.redSqrt = function redSqrt() {
6554
+ BN4.prototype.redSqrt = function redSqrt() {
6555
6555
  assert6(this.red, "redSqrt works only with red numbers");
6556
6556
  this.red._verify1(this);
6557
6557
  return this.red.sqrt(this);
6558
6558
  };
6559
- BN3.prototype.redInvm = function redInvm() {
6559
+ BN4.prototype.redInvm = function redInvm() {
6560
6560
  assert6(this.red, "redInvm works only with red numbers");
6561
6561
  this.red._verify1(this);
6562
6562
  return this.red.invm(this);
6563
6563
  };
6564
- BN3.prototype.redNeg = function redNeg() {
6564
+ BN4.prototype.redNeg = function redNeg() {
6565
6565
  assert6(this.red, "redNeg works only with red numbers");
6566
6566
  this.red._verify1(this);
6567
6567
  return this.red.neg(this);
6568
6568
  };
6569
- BN3.prototype.redPow = function redPow(num) {
6569
+ BN4.prototype.redPow = function redPow(num) {
6570
6570
  assert6(this.red && !num.red, "redPow(normalNum)");
6571
6571
  this.red._verify1(this);
6572
6572
  return this.red.pow(this, num);
@@ -6579,13 +6579,13 @@ var starknet = (() => {
6579
6579
  };
6580
6580
  function MPrime(name, p) {
6581
6581
  this.name = name;
6582
- this.p = new BN3(p, 16);
6582
+ this.p = new BN4(p, 16);
6583
6583
  this.n = this.p.bitLength();
6584
- this.k = new BN3(1).iushln(this.n).isub(this.p);
6584
+ this.k = new BN4(1).iushln(this.n).isub(this.p);
6585
6585
  this.tmp = this._tmp();
6586
6586
  }
6587
6587
  MPrime.prototype._tmp = function _tmp() {
6588
- var tmp = new BN3(null);
6588
+ var tmp = new BN4(null);
6589
6589
  tmp.words = new Array(Math.ceil(this.n / 13));
6590
6590
  return tmp;
6591
6591
  };
@@ -6711,7 +6711,7 @@ var starknet = (() => {
6711
6711
  }
6712
6712
  return num;
6713
6713
  };
6714
- BN3._prime = function prime(name) {
6714
+ BN4._prime = function prime(name) {
6715
6715
  if (primes[name])
6716
6716
  return primes[name];
6717
6717
  var prime2;
@@ -6731,7 +6731,7 @@ var starknet = (() => {
6731
6731
  };
6732
6732
  function Red(m) {
6733
6733
  if (typeof m === "string") {
6734
- var prime = BN3._prime(m);
6734
+ var prime = BN4._prime(m);
6735
6735
  this.m = prime.p;
6736
6736
  this.prime = prime;
6737
6737
  } else {
@@ -6818,7 +6818,7 @@ var starknet = (() => {
6818
6818
  var mod3 = this.m.andln(3);
6819
6819
  assert6(mod3 % 2 === 1);
6820
6820
  if (mod3 === 3) {
6821
- var pow = this.m.add(new BN3(1)).iushrn(2);
6821
+ var pow = this.m.add(new BN4(1)).iushrn(2);
6822
6822
  return this.pow(a, pow);
6823
6823
  }
6824
6824
  var q = this.m.subn(1);
@@ -6828,11 +6828,11 @@ var starknet = (() => {
6828
6828
  q.iushrn(1);
6829
6829
  }
6830
6830
  assert6(!q.isZero());
6831
- var one = new BN3(1).toRed(this);
6831
+ var one = new BN4(1).toRed(this);
6832
6832
  var nOne = one.redNeg();
6833
6833
  var lpow = this.m.subn(1).iushrn(1);
6834
6834
  var z = this.m.bitLength();
6835
- z = new BN3(2 * z * z).toRed(this);
6835
+ z = new BN4(2 * z * z).toRed(this);
6836
6836
  while (this.pow(z, lpow).cmp(nOne) !== 0) {
6837
6837
  z.redIAdd(nOne);
6838
6838
  }
@@ -6846,7 +6846,7 @@ var starknet = (() => {
6846
6846
  tmp = tmp.redSqr();
6847
6847
  }
6848
6848
  assert6(i < m);
6849
- var b = this.pow(c, new BN3(1).iushln(m - i - 1));
6849
+ var b = this.pow(c, new BN4(1).iushln(m - i - 1));
6850
6850
  r = r.redMul(b);
6851
6851
  c = b.redSqr();
6852
6852
  t = t.redMul(c);
@@ -6865,12 +6865,12 @@ var starknet = (() => {
6865
6865
  };
6866
6866
  Red.prototype.pow = function pow(a, num) {
6867
6867
  if (num.isZero())
6868
- return new BN3(1).toRed(this);
6868
+ return new BN4(1).toRed(this);
6869
6869
  if (num.cmpn(1) === 0)
6870
6870
  return a.clone();
6871
6871
  var windowSize = 4;
6872
6872
  var wnd = new Array(1 << windowSize);
6873
- wnd[0] = new BN3(1).toRed(this);
6873
+ wnd[0] = new BN4(1).toRed(this);
6874
6874
  wnd[1] = a;
6875
6875
  for (var i = 2; i < wnd.length; i++) {
6876
6876
  wnd[i] = this.mul(wnd[i - 1], a);
@@ -6915,7 +6915,7 @@ var starknet = (() => {
6915
6915
  res.red = null;
6916
6916
  return res;
6917
6917
  };
6918
- BN3.mont = function mont(num) {
6918
+ BN4.mont = function mont(num) {
6919
6919
  return new Mont(num);
6920
6920
  };
6921
6921
  function Mont(m) {
@@ -6924,7 +6924,7 @@ var starknet = (() => {
6924
6924
  if (this.shift % 26 !== 0) {
6925
6925
  this.shift += 26 - this.shift % 26;
6926
6926
  }
6927
- this.r = new BN3(1).iushln(this.shift);
6927
+ this.r = new BN4(1).iushln(this.shift);
6928
6928
  this.r2 = this.imod(this.r.sqr());
6929
6929
  this.rinv = this.r._invmp(this.m);
6930
6930
  this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
@@ -6959,7 +6959,7 @@ var starknet = (() => {
6959
6959
  };
6960
6960
  Mont.prototype.mul = function mul(a, b) {
6961
6961
  if (a.isZero() || b.isZero())
6962
- return new BN3(0)._forceRed(this);
6962
+ return new BN4(0)._forceRed(this);
6963
6963
  var t = a.mul(b);
6964
6964
  var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
6965
6965
  var u = t.isub(c).iushrn(this.shift);
@@ -7043,7 +7043,7 @@ var starknet = (() => {
7043
7043
  "node_modules/elliptic/lib/elliptic/utils.js"(exports) {
7044
7044
  "use strict";
7045
7045
  var utils = exports;
7046
- var BN3 = require_bn2();
7046
+ var BN4 = require_bn2();
7047
7047
  var minAssert = require_minimalistic_assert();
7048
7048
  var minUtils = require_utils3();
7049
7049
  utils.assert = minAssert;
@@ -7135,7 +7135,7 @@ var starknet = (() => {
7135
7135
  }
7136
7136
  utils.parseBytes = parseBytes;
7137
7137
  function intFromLE(bytes) {
7138
- return new BN3(bytes, "hex", "le");
7138
+ return new BN4(bytes, "hex", "le");
7139
7139
  }
7140
7140
  utils.intFromLE = intFromLE;
7141
7141
  }
@@ -7208,19 +7208,19 @@ var starknet = (() => {
7208
7208
  var require_base = __commonJS({
7209
7209
  "node_modules/elliptic/lib/elliptic/curve/base.js"(exports, module) {
7210
7210
  "use strict";
7211
- var BN3 = require_bn2();
7211
+ var BN4 = require_bn2();
7212
7212
  var utils = require_utils4();
7213
7213
  var getNAF = utils.getNAF;
7214
7214
  var getJSF = utils.getJSF;
7215
7215
  var assert6 = utils.assert;
7216
7216
  function BaseCurve(type, conf) {
7217
7217
  this.type = type;
7218
- this.p = new BN3(conf.p, 16);
7219
- this.red = conf.prime ? BN3.red(conf.prime) : BN3.mont(this.p);
7220
- this.zero = new BN3(0).toRed(this.red);
7221
- this.one = new BN3(1).toRed(this.red);
7222
- this.two = new BN3(2).toRed(this.red);
7223
- this.n = conf.n && new BN3(conf.n, 16);
7218
+ this.p = new BN4(conf.p, 16);
7219
+ this.red = conf.prime ? BN4.red(conf.prime) : BN4.mont(this.p);
7220
+ this.zero = new BN4(0).toRed(this.red);
7221
+ this.one = new BN4(1).toRed(this.red);
7222
+ this.two = new BN4(2).toRed(this.red);
7223
+ this.n = conf.n && new BN4(conf.n, 16);
7224
7224
  this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
7225
7225
  this._wnafT1 = new Array(4);
7226
7226
  this._wnafT2 = new Array(4);
@@ -7550,14 +7550,14 @@ var starknet = (() => {
7550
7550
  "node_modules/elliptic/lib/elliptic/curve/short.js"(exports, module) {
7551
7551
  "use strict";
7552
7552
  var utils = require_utils4();
7553
- var BN3 = require_bn2();
7553
+ var BN4 = require_bn2();
7554
7554
  var inherits = require_inherits_browser();
7555
7555
  var Base = require_base();
7556
7556
  var assert6 = utils.assert;
7557
7557
  function ShortCurve(conf) {
7558
7558
  Base.call(this, "short", conf);
7559
- this.a = new BN3(conf.a, 16).toRed(this.red);
7560
- this.b = new BN3(conf.b, 16).toRed(this.red);
7559
+ this.a = new BN4(conf.a, 16).toRed(this.red);
7560
+ this.b = new BN4(conf.b, 16).toRed(this.red);
7561
7561
  this.tinv = this.two.redInvm();
7562
7562
  this.zeroA = this.a.fromRed().cmpn(0) === 0;
7563
7563
  this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
@@ -7573,14 +7573,14 @@ var starknet = (() => {
7573
7573
  var beta;
7574
7574
  var lambda;
7575
7575
  if (conf.beta) {
7576
- beta = new BN3(conf.beta, 16).toRed(this.red);
7576
+ beta = new BN4(conf.beta, 16).toRed(this.red);
7577
7577
  } else {
7578
7578
  var betas = this._getEndoRoots(this.p);
7579
7579
  beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
7580
7580
  beta = beta.toRed(this.red);
7581
7581
  }
7582
7582
  if (conf.lambda) {
7583
- lambda = new BN3(conf.lambda, 16);
7583
+ lambda = new BN4(conf.lambda, 16);
7584
7584
  } else {
7585
7585
  var lambdas = this._getEndoRoots(this.n);
7586
7586
  if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
@@ -7594,8 +7594,8 @@ var starknet = (() => {
7594
7594
  if (conf.basis) {
7595
7595
  basis = conf.basis.map(function(vec) {
7596
7596
  return {
7597
- a: new BN3(vec.a, 16),
7598
- b: new BN3(vec.b, 16)
7597
+ a: new BN4(vec.a, 16),
7598
+ b: new BN4(vec.b, 16)
7599
7599
  };
7600
7600
  });
7601
7601
  } else {
@@ -7608,10 +7608,10 @@ var starknet = (() => {
7608
7608
  };
7609
7609
  };
7610
7610
  ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
7611
- var red = num === this.p ? this.red : BN3.mont(num);
7612
- var tinv = new BN3(2).toRed(red).redInvm();
7611
+ var red = num === this.p ? this.red : BN4.mont(num);
7612
+ var tinv = new BN4(2).toRed(red).redInvm();
7613
7613
  var ntinv = tinv.redNeg();
7614
- var s = new BN3(3).toRed(red).redNeg().redSqrt().redMul(tinv);
7614
+ var s = new BN4(3).toRed(red).redNeg().redSqrt().redMul(tinv);
7615
7615
  var l1 = ntinv.redAdd(s).fromRed();
7616
7616
  var l2 = ntinv.redSub(s).fromRed();
7617
7617
  return [l1, l2];
@@ -7620,10 +7620,10 @@ var starknet = (() => {
7620
7620
  var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
7621
7621
  var u = lambda;
7622
7622
  var v = this.n.clone();
7623
- var x1 = new BN3(1);
7624
- var y1 = new BN3(0);
7625
- var x2 = new BN3(0);
7626
- var y2 = new BN3(1);
7623
+ var x1 = new BN4(1);
7624
+ var y1 = new BN4(0);
7625
+ var x2 = new BN4(0);
7626
+ var y2 = new BN4(1);
7627
7627
  var a0;
7628
7628
  var b0;
7629
7629
  var a1;
@@ -7691,7 +7691,7 @@ var starknet = (() => {
7691
7691
  return { k1, k2 };
7692
7692
  };
7693
7693
  ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
7694
- x = new BN3(x, 16);
7694
+ x = new BN4(x, 16);
7695
7695
  if (!x.red)
7696
7696
  x = x.toRed(this.red);
7697
7697
  var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
@@ -7746,8 +7746,8 @@ var starknet = (() => {
7746
7746
  this.y = null;
7747
7747
  this.inf = true;
7748
7748
  } else {
7749
- this.x = new BN3(x, 16);
7750
- this.y = new BN3(y, 16);
7749
+ this.x = new BN4(x, 16);
7750
+ this.y = new BN4(y, 16);
7751
7751
  if (isRed) {
7752
7752
  this.x.forceRed(this.curve.red);
7753
7753
  this.y.forceRed(this.curve.red);
@@ -7877,7 +7877,7 @@ var starknet = (() => {
7877
7877
  return this.y.fromRed();
7878
7878
  };
7879
7879
  Point.prototype.mul = function mul(k) {
7880
- k = new BN3(k, 16);
7880
+ k = new BN4(k, 16);
7881
7881
  if (this.isInfinity())
7882
7882
  return this;
7883
7883
  else if (this._hasDoubles(k))
@@ -7939,11 +7939,11 @@ var starknet = (() => {
7939
7939
  if (x === null && y === null && z === null) {
7940
7940
  this.x = this.curve.one;
7941
7941
  this.y = this.curve.one;
7942
- this.z = new BN3(0);
7942
+ this.z = new BN4(0);
7943
7943
  } else {
7944
- this.x = new BN3(x, 16);
7945
- this.y = new BN3(y, 16);
7946
- this.z = new BN3(z, 16);
7944
+ this.x = new BN4(x, 16);
7945
+ this.y = new BN4(y, 16);
7946
+ this.z = new BN4(z, 16);
7947
7947
  }
7948
7948
  if (!this.x.red)
7949
7949
  this.x = this.x.toRed(this.curve.red);
@@ -8200,7 +8200,7 @@ var starknet = (() => {
8200
8200
  return this.curve.jpoint(nx, ny, nz);
8201
8201
  };
8202
8202
  JPoint.prototype.mul = function mul(k, kbase) {
8203
- k = new BN3(k, kbase);
8203
+ k = new BN4(k, kbase);
8204
8204
  return this.curve._wnafMul(this, k);
8205
8205
  };
8206
8206
  JPoint.prototype.eq = function eq(p) {
@@ -8247,16 +8247,16 @@ var starknet = (() => {
8247
8247
  var require_mont = __commonJS({
8248
8248
  "node_modules/elliptic/lib/elliptic/curve/mont.js"(exports, module) {
8249
8249
  "use strict";
8250
- var BN3 = require_bn2();
8250
+ var BN4 = require_bn2();
8251
8251
  var inherits = require_inherits_browser();
8252
8252
  var Base = require_base();
8253
8253
  var utils = require_utils4();
8254
8254
  function MontCurve(conf) {
8255
8255
  Base.call(this, "mont", conf);
8256
- this.a = new BN3(conf.a, 16).toRed(this.red);
8257
- this.b = new BN3(conf.b, 16).toRed(this.red);
8258
- this.i4 = new BN3(4).toRed(this.red).redInvm();
8259
- this.two = new BN3(2).toRed(this.red);
8256
+ this.a = new BN4(conf.a, 16).toRed(this.red);
8257
+ this.b = new BN4(conf.b, 16).toRed(this.red);
8258
+ this.i4 = new BN4(4).toRed(this.red).redInvm();
8259
+ this.two = new BN4(2).toRed(this.red);
8260
8260
  this.a24 = this.i4.redMul(this.a.redAdd(this.two));
8261
8261
  }
8262
8262
  inherits(MontCurve, Base);
@@ -8274,8 +8274,8 @@ var starknet = (() => {
8274
8274
  this.x = this.curve.one;
8275
8275
  this.z = this.curve.zero;
8276
8276
  } else {
8277
- this.x = new BN3(x, 16);
8278
- this.z = new BN3(z, 16);
8277
+ this.x = new BN4(x, 16);
8278
+ this.z = new BN4(z, 16);
8279
8279
  if (!this.x.red)
8280
8280
  this.x = this.x.toRed(this.curve.red);
8281
8281
  if (!this.z.red)
@@ -8376,7 +8376,7 @@ var starknet = (() => {
8376
8376
  "node_modules/elliptic/lib/elliptic/curve/edwards.js"(exports, module) {
8377
8377
  "use strict";
8378
8378
  var utils = require_utils4();
8379
- var BN3 = require_bn2();
8379
+ var BN4 = require_bn2();
8380
8380
  var inherits = require_inherits_browser();
8381
8381
  var Base = require_base();
8382
8382
  var assert6 = utils.assert;
@@ -8385,11 +8385,11 @@ var starknet = (() => {
8385
8385
  this.mOneA = this.twisted && (conf.a | 0) === -1;
8386
8386
  this.extended = this.mOneA;
8387
8387
  Base.call(this, "edwards", conf);
8388
- this.a = new BN3(conf.a, 16).umod(this.red.m);
8388
+ this.a = new BN4(conf.a, 16).umod(this.red.m);
8389
8389
  this.a = this.a.toRed(this.red);
8390
- this.c = new BN3(conf.c, 16).toRed(this.red);
8390
+ this.c = new BN4(conf.c, 16).toRed(this.red);
8391
8391
  this.c2 = this.c.redSqr();
8392
- this.d = new BN3(conf.d, 16).toRed(this.red);
8392
+ this.d = new BN4(conf.d, 16).toRed(this.red);
8393
8393
  this.dd = this.d.redAdd(this.d);
8394
8394
  assert6(!this.twisted || this.c.fromRed().cmpn(1) === 0);
8395
8395
  this.oneC = (conf.c | 0) === 1;
@@ -8412,7 +8412,7 @@ var starknet = (() => {
8412
8412
  return this.point(x, y, z, t);
8413
8413
  };
8414
8414
  EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
8415
- x = new BN3(x, 16);
8415
+ x = new BN4(x, 16);
8416
8416
  if (!x.red)
8417
8417
  x = x.toRed(this.red);
8418
8418
  var x2 = x.redSqr();
@@ -8428,7 +8428,7 @@ var starknet = (() => {
8428
8428
  return this.point(x, y);
8429
8429
  };
8430
8430
  EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
8431
- y = new BN3(y, 16);
8431
+ y = new BN4(y, 16);
8432
8432
  if (!y.red)
8433
8433
  y = y.toRed(this.red);
8434
8434
  var y2 = y.redSqr();
@@ -8467,10 +8467,10 @@ var starknet = (() => {
8467
8467
  this.t = this.curve.zero;
8468
8468
  this.zOne = true;
8469
8469
  } else {
8470
- this.x = new BN3(x, 16);
8471
- this.y = new BN3(y, 16);
8472
- this.z = z ? new BN3(z, 16) : this.curve.one;
8473
- this.t = t && new BN3(t, 16);
8470
+ this.x = new BN4(x, 16);
8471
+ this.y = new BN4(y, 16);
8472
+ this.z = z ? new BN4(z, 16) : this.curve.one;
8473
+ this.t = t && new BN4(t, 16);
8474
8474
  if (!this.x.red)
8475
8475
  this.x = this.x.toRed(this.curve.red);
8476
8476
  if (!this.y.red)
@@ -11366,7 +11366,7 @@ var starknet = (() => {
11366
11366
  var require_key = __commonJS({
11367
11367
  "node_modules/elliptic/lib/elliptic/ec/key.js"(exports, module) {
11368
11368
  "use strict";
11369
- var BN3 = require_bn2();
11369
+ var BN4 = require_bn2();
11370
11370
  var utils = require_utils4();
11371
11371
  var assert6 = utils.assert;
11372
11372
  function KeyPair(ec2, options) {
@@ -11423,7 +11423,7 @@ var starknet = (() => {
11423
11423
  return this.priv;
11424
11424
  };
11425
11425
  KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
11426
- this.priv = new BN3(key, enc || 16);
11426
+ this.priv = new BN4(key, enc || 16);
11427
11427
  this.priv = this.priv.umod(this.ec.curve.n);
11428
11428
  };
11429
11429
  KeyPair.prototype._importPublic = function _importPublic(key, enc) {
@@ -11460,7 +11460,7 @@ var starknet = (() => {
11460
11460
  var require_signature = __commonJS({
11461
11461
  "node_modules/elliptic/lib/elliptic/ec/signature.js"(exports, module) {
11462
11462
  "use strict";
11463
- var BN3 = require_bn2();
11463
+ var BN4 = require_bn2();
11464
11464
  var utils = require_utils4();
11465
11465
  var assert6 = utils.assert;
11466
11466
  function Signature(options, enc) {
@@ -11469,8 +11469,8 @@ var starknet = (() => {
11469
11469
  if (this._importDER(options, enc))
11470
11470
  return;
11471
11471
  assert6(options.r && options.s, "Signature without r or s");
11472
- this.r = new BN3(options.r, 16);
11473
- this.s = new BN3(options.s, 16);
11472
+ this.r = new BN4(options.r, 16);
11473
+ this.s = new BN4(options.s, 16);
11474
11474
  if (options.recoveryParam === void 0)
11475
11475
  this.recoveryParam = null;
11476
11476
  else
@@ -11559,8 +11559,8 @@ var starknet = (() => {
11559
11559
  return false;
11560
11560
  }
11561
11561
  }
11562
- this.r = new BN3(r);
11563
- this.s = new BN3(s);
11562
+ this.r = new BN4(r);
11563
+ this.s = new BN4(s);
11564
11564
  this.recoveryParam = null;
11565
11565
  return true;
11566
11566
  };
@@ -11606,7 +11606,7 @@ var starknet = (() => {
11606
11606
  var require_ec = __commonJS({
11607
11607
  "node_modules/elliptic/lib/elliptic/ec/index.js"(exports, module) {
11608
11608
  "use strict";
11609
- var BN3 = require_bn2();
11609
+ var BN4 = require_bn2();
11610
11610
  var HmacDRBG = require_hmac_drbg();
11611
11611
  var utils = require_utils4();
11612
11612
  var curves2 = require_curves();
@@ -11656,9 +11656,9 @@ var starknet = (() => {
11656
11656
  nonce: this.n.toArray()
11657
11657
  });
11658
11658
  var bytes = this.n.byteLength();
11659
- var ns2 = this.n.sub(new BN3(2));
11659
+ var ns2 = this.n.sub(new BN4(2));
11660
11660
  for (; ; ) {
11661
- var priv = new BN3(drbg.generate(bytes));
11661
+ var priv = new BN4(drbg.generate(bytes));
11662
11662
  if (priv.cmp(ns2) > 0)
11663
11663
  continue;
11664
11664
  priv.iaddn(1);
@@ -11682,7 +11682,7 @@ var starknet = (() => {
11682
11682
  if (!options)
11683
11683
  options = {};
11684
11684
  key = this.keyFromPrivate(key, enc);
11685
- msg = this._truncateToN(new BN3(msg, 16));
11685
+ msg = this._truncateToN(new BN4(msg, 16));
11686
11686
  var bytes = this.n.byteLength();
11687
11687
  var bkey = key.getPrivate().toArray("be", bytes);
11688
11688
  var nonce = msg.toArray("be", bytes);
@@ -11693,9 +11693,9 @@ var starknet = (() => {
11693
11693
  pers: options.pers,
11694
11694
  persEnc: options.persEnc || "utf8"
11695
11695
  });
11696
- var ns1 = this.n.sub(new BN3(1));
11696
+ var ns1 = this.n.sub(new BN4(1));
11697
11697
  for (var iter = 0; ; iter++) {
11698
- var k = options.k ? options.k(iter) : new BN3(drbg.generate(this.n.byteLength()));
11698
+ var k = options.k ? options.k(iter) : new BN4(drbg.generate(this.n.byteLength()));
11699
11699
  k = this._truncateToN(k, true);
11700
11700
  if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
11701
11701
  continue;
@@ -11719,7 +11719,7 @@ var starknet = (() => {
11719
11719
  }
11720
11720
  };
11721
11721
  EC2.prototype.verify = function verify2(msg, signature, key, enc) {
11722
- msg = this._truncateToN(new BN3(msg, 16));
11722
+ msg = this._truncateToN(new BN4(msg, 16));
11723
11723
  key = this.keyFromPublic(key, enc);
11724
11724
  signature = new Signature(signature, "hex");
11725
11725
  var r = signature.r;
@@ -11747,7 +11747,7 @@ var starknet = (() => {
11747
11747
  assert6((3 & j) === j, "The recovery param is more than two bits");
11748
11748
  signature = new Signature(signature, enc);
11749
11749
  var n = this.n;
11750
- var e = new BN3(msg);
11750
+ var e = new BN4(msg);
11751
11751
  var r = signature.r;
11752
11752
  var s = signature.s;
11753
11753
  var isYOdd = j & 1;
@@ -11860,7 +11860,7 @@ var starknet = (() => {
11860
11860
  var require_signature2 = __commonJS({
11861
11861
  "node_modules/elliptic/lib/elliptic/eddsa/signature.js"(exports, module) {
11862
11862
  "use strict";
11863
- var BN3 = require_bn2();
11863
+ var BN4 = require_bn2();
11864
11864
  var utils = require_utils4();
11865
11865
  var assert6 = utils.assert;
11866
11866
  var cachedProperty = utils.cachedProperty;
@@ -11878,7 +11878,7 @@ var starknet = (() => {
11878
11878
  assert6(sig.R && sig.S, "Signature without R or S");
11879
11879
  if (eddsa.isPoint(sig.R))
11880
11880
  this._R = sig.R;
11881
- if (sig.S instanceof BN3)
11881
+ if (sig.S instanceof BN4)
11882
11882
  this._S = sig.S;
11883
11883
  this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
11884
11884
  this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
@@ -13967,7 +13967,7 @@ var starknet = (() => {
13967
13967
  });
13968
13968
 
13969
13969
  // src/contract/default.ts
13970
- var import_bn2 = __toESM(require_bn());
13970
+ var import_bn3 = __toESM(require_bn());
13971
13971
  var import_minimalistic_assert4 = __toESM(require_minimalistic_assert());
13972
13972
 
13973
13973
  // src/utils/fetchPonyfill.ts
@@ -14024,6 +14024,7 @@ var starknet = (() => {
14024
14024
  assertInRange: () => assertInRange,
14025
14025
  bigNumberishArrayToDecimalStringArray: () => bigNumberishArrayToDecimalStringArray,
14026
14026
  bigNumberishArrayToHexadecimalStringArray: () => bigNumberishArrayToHexadecimalStringArray,
14027
+ cleanHex: () => cleanHex,
14027
14028
  getDecimalString: () => getDecimalString,
14028
14029
  getHexString: () => getHexString,
14029
14030
  getHexStringArray: () => getHexStringArray,
@@ -14126,6 +14127,7 @@ var starknet = (() => {
14126
14127
  }
14127
14128
  return toBN(num).toString();
14128
14129
  }
14130
+ var cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, "$1");
14129
14131
  function assertInRange(input, lowerBound, upperBound, inputName = "") {
14130
14132
  const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
14131
14133
  const inputBn = toBN(input);
@@ -20528,6 +20530,8 @@ var starknet = (() => {
20528
20530
  };
20529
20531
 
20530
20532
  // src/provider/utils.ts
20533
+ var import_bn2 = __toESM(require_bn());
20534
+ var validBlockTags = ["latest", "pending"];
20531
20535
  var Block = class {
20532
20536
  constructor(_identifier) {
20533
20537
  this.hash = null;
@@ -20535,17 +20539,21 @@ var starknet = (() => {
20535
20539
  this.tag = null;
20536
20540
  this.valueOf = () => this.number;
20537
20541
  this.toString = () => this.hash;
20538
- this.setIdentifier = function(__identifier) {
20539
- if (typeof __identifier === "string" && isHex(__identifier)) {
20540
- this.hash = __identifier;
20541
- } else if (typeof __identifier === "number") {
20542
- this.number = __identifier;
20543
- } else {
20544
- this.tag = __identifier;
20545
- }
20546
- };
20547
20542
  this.setIdentifier(_identifier);
20548
20543
  }
20544
+ setIdentifier(__identifier) {
20545
+ if (typeof __identifier === "string" && isHex(__identifier)) {
20546
+ this.hash = __identifier;
20547
+ } else if (import_bn2.BN.isBN(__identifier)) {
20548
+ this.hash = toHex(__identifier);
20549
+ } else if (typeof __identifier === "number") {
20550
+ this.number = __identifier;
20551
+ } else if (typeof __identifier === "string" && validBlockTags.includes(__identifier)) {
20552
+ this.tag = __identifier;
20553
+ } else {
20554
+ this.tag = "pending";
20555
+ }
20556
+ }
20549
20557
  get queryIdentifier() {
20550
20558
  if (this.number !== null) {
20551
20559
  return `blockNumber=${this.number}`;
@@ -20632,7 +20640,7 @@ var starknet = (() => {
20632
20640
  contract_address: contractAddress
20633
20641
  });
20634
20642
  }
20635
- async getNonce(contractAddress, blockIdentifier = "pending") {
20643
+ async getNonceForAddress(contractAddress, blockIdentifier = "pending") {
20636
20644
  const block_id = new Block(blockIdentifier).identifier;
20637
20645
  return this.fetchEndpoint("starknet_getNonce", {
20638
20646
  contract_address: contractAddress,
@@ -20817,25 +20825,25 @@ var starknet = (() => {
20817
20825
  async traceBlockTransactions(blockHash) {
20818
20826
  return this.fetchEndpoint("starknet_traceBlockTransactions", { block_hash: blockHash });
20819
20827
  }
20820
- async waitForTransaction(txHash, retryInterval = 8e3) {
20828
+ async waitForTransaction(txHash, successStates = ["ACCEPTED_ON_L1", "ACCEPTED_ON_L2", "PENDING"], retryInterval = 8e3) {
20829
+ const errorStates = ["REJECTED", "NOT_RECEIVED"];
20821
20830
  let { retries } = this;
20822
20831
  let onchain = false;
20832
+ let txReceipt = {};
20823
20833
  while (!onchain) {
20824
- const successStates = ["ACCEPTED_ON_L1", "ACCEPTED_ON_L2", "PENDING"];
20825
- const errorStates = ["REJECTED", "NOT_RECEIVED"];
20826
20834
  await wait(retryInterval);
20827
20835
  try {
20828
- const res = await this.getTransactionReceipt(txHash);
20829
- if (!("status" in res)) {
20836
+ txReceipt = await this.getTransactionReceipt(txHash);
20837
+ if (!("status" in txReceipt)) {
20830
20838
  const error = new Error("pending transaction");
20831
20839
  throw error;
20832
20840
  }
20833
- if (res.status && successStates.includes(res.status)) {
20841
+ if (txReceipt.status && successStates.includes(txReceipt.status)) {
20834
20842
  onchain = true;
20835
- } else if (res.status && errorStates.includes(res.status)) {
20836
- const message = res.status;
20843
+ } else if (txReceipt.status && errorStates.includes(txReceipt.status)) {
20844
+ const message = txReceipt.status;
20837
20845
  const error = new Error(message);
20838
- error.response = res;
20846
+ error.response = txReceipt;
20839
20847
  throw error;
20840
20848
  }
20841
20849
  } catch (error) {
@@ -20849,6 +20857,7 @@ var starknet = (() => {
20849
20857
  retries -= 1;
20850
20858
  }
20851
20859
  await wait(retryInterval);
20860
+ return txReceipt;
20852
20861
  }
20853
20862
  async getTransactionCount(blockIdentifier = "pending") {
20854
20863
  const block_id = new Block(blockIdentifier).identifier;
@@ -21198,7 +21207,7 @@ var starknet = (() => {
21198
21207
  this.responseParser.parseGetBlockResponse
21199
21208
  );
21200
21209
  }
21201
- async getNonce(contractAddress, blockIdentifier = "pending") {
21210
+ async getNonceForAddress(contractAddress, blockIdentifier = "pending") {
21202
21211
  return this.fetchEndpoint("get_nonce", { contractAddress, blockIdentifier });
21203
21212
  }
21204
21213
  async getStorageAt(contractAddress, key, blockIdentifier = "pending") {
@@ -21328,13 +21337,13 @@ var starknet = (() => {
21328
21337
  async getCode(contractAddress, blockIdentifier = "pending") {
21329
21338
  return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
21330
21339
  }
21331
- async waitForTransaction(txHash, retryInterval = 8e3) {
21340
+ async waitForTransaction(txHash, successStates = ["ACCEPTED_ON_L1", "ACCEPTED_ON_L2", "PENDING"], retryInterval = 8e3) {
21341
+ const errorStates = ["REJECTED", "NOT_RECEIVED"];
21332
21342
  let onchain = false;
21343
+ let res;
21333
21344
  while (!onchain) {
21334
21345
  await wait(retryInterval);
21335
- const res = await this.getTransactionStatus(txHash);
21336
- const successStates = ["ACCEPTED_ON_L1", "ACCEPTED_ON_L2", "PENDING"];
21337
- const errorStates = ["REJECTED", "NOT_RECEIVED"];
21346
+ res = await this.getTransactionStatus(txHash);
21338
21347
  if (successStates.includes(res.tx_status)) {
21339
21348
  onchain = true;
21340
21349
  } else if (errorStates.includes(res.tx_status)) {
@@ -21345,6 +21354,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21345
21354
  throw error;
21346
21355
  }
21347
21356
  }
21357
+ const txReceipt = await this.getTransactionReceipt(txHash);
21358
+ return txReceipt;
21348
21359
  }
21349
21360
  async getTransactionStatus(txHash) {
21350
21361
  const txHashHex = toHex(toBN(txHash));
@@ -21371,11 +21382,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21371
21382
  // src/provider/default.ts
21372
21383
  var Provider = class {
21373
21384
  constructor(providerOrOptions) {
21374
- if (providerOrOptions && "chainId" in providerOrOptions) {
21385
+ if (providerOrOptions instanceof Provider) {
21386
+ this.provider = providerOrOptions.provider;
21387
+ } else if (providerOrOptions instanceof RpcProvider || providerOrOptions instanceof SequencerProvider) {
21375
21388
  this.provider = providerOrOptions;
21376
- } else if (providerOrOptions == null ? void 0 : providerOrOptions.rpc) {
21389
+ } else if (providerOrOptions && "rpc" in providerOrOptions) {
21377
21390
  this.provider = new RpcProvider(providerOrOptions.rpc);
21378
- } else if (providerOrOptions == null ? void 0 : providerOrOptions.sequencer) {
21391
+ } else if (providerOrOptions && "sequencer" in providerOrOptions) {
21379
21392
  this.provider = new SequencerProvider(providerOrOptions.sequencer);
21380
21393
  } else {
21381
21394
  this.provider = new SequencerProvider();
@@ -21409,8 +21422,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21409
21422
  blockIdentifier
21410
21423
  );
21411
21424
  }
21412
- async getNonce(contractAddress, blockIdentifier) {
21413
- return this.provider.getNonce(contractAddress, blockIdentifier);
21425
+ async getNonceForAddress(contractAddress, blockIdentifier) {
21426
+ return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
21414
21427
  }
21415
21428
  async getStorageAt(contractAddress, key, blockIdentifier = "pending") {
21416
21429
  return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
@@ -21445,8 +21458,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21445
21458
  async getCode(contractAddress, blockIdentifier) {
21446
21459
  return this.provider.getCode(contractAddress, blockIdentifier);
21447
21460
  }
21448
- async waitForTransaction(txHash, retryInterval) {
21449
- return this.provider.waitForTransaction(txHash, retryInterval);
21461
+ async waitForTransaction(txHash, successStates, retryInterval) {
21462
+ return this.provider.waitForTransaction(txHash, successStates, retryInterval);
21450
21463
  }
21451
21464
  };
21452
21465
 
@@ -21467,7 +21480,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21467
21480
  }
21468
21481
  function buildCall(contract, functionAbi) {
21469
21482
  return async function(...args) {
21470
- return contract.call(functionAbi.name, args);
21483
+ let blockIdentifier = null;
21484
+ args.forEach((arg) => {
21485
+ if (arg.blockIdentifier) {
21486
+ blockIdentifier = arg.blockIdentifier;
21487
+ }
21488
+ });
21489
+ return contract.call(functionAbi.name, args, { blockIdentifier });
21471
21490
  };
21472
21491
  }
21473
21492
  function buildInvoke(contract, functionAbi) {
@@ -21692,7 +21711,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21692
21711
  }
21693
21712
  if (input.type === "felt") {
21694
21713
  (0, import_minimalistic_assert4.default)(
21695
- typeof args[argPosition] === "string" || typeof args[argPosition] === "number" || args[argPosition] instanceof import_bn2.default,
21714
+ typeof args[argPosition] === "string" || typeof args[argPosition] === "number" || args[argPosition] instanceof import_bn3.default,
21696
21715
  `arg ${input.name} should be a felt (string, number, BigNumber)`
21697
21716
  );
21698
21717
  argPosition += 1;
@@ -21717,7 +21736,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21717
21736
  if (input.type === "felt*") {
21718
21737
  args[argPosition].forEach((felt) => {
21719
21738
  (0, import_minimalistic_assert4.default)(
21720
- typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn2.default,
21739
+ typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn3.default,
21721
21740
  `arg ${input.name} should be an array of string, number or BigNumber`
21722
21741
  );
21723
21742
  });
@@ -21730,7 +21749,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21730
21749
  );
21731
21750
  args[argPosition].forEach((felt) => {
21732
21751
  (0, import_minimalistic_assert4.default)(
21733
- typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn2.default,
21752
+ typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn3.default,
21734
21753
  `arg ${input.name} should be an array of string, number or BigNumber`
21735
21754
  );
21736
21755
  });
@@ -21887,32 +21906,36 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21887
21906
  // src/contract/contractFactory.ts
21888
21907
  var import_minimalistic_assert5 = __toESM(require_minimalistic_assert());
21889
21908
  var ContractFactory = class {
21890
- constructor(compiledContract, providerOrAccount = defaultProvider, abi = compiledContract.abi) {
21909
+ constructor(compiledContract, classHash, account, abi = compiledContract.abi) {
21891
21910
  this.abi = abi;
21892
21911
  this.compiledContract = compiledContract;
21893
- this.providerOrAccount = providerOrAccount;
21912
+ this.account = account;
21913
+ this.classHash = classHash;
21894
21914
  }
21895
21915
  async deploy(constructorCalldata, addressSalt) {
21896
- const { contract_address, transaction_hash } = await this.providerOrAccount.deployContract({
21916
+ const {
21917
+ deploy: { contract_address, transaction_hash }
21918
+ } = await this.account.declareDeploy({
21897
21919
  contract: this.compiledContract,
21920
+ classHash: this.classHash,
21898
21921
  constructorCalldata,
21899
- addressSalt
21922
+ salt: addressSalt
21900
21923
  });
21901
21924
  (0, import_minimalistic_assert5.default)(Boolean(contract_address), "Deployment of the contract failed");
21902
21925
  const contractInstance = new Contract(
21903
21926
  this.compiledContract.abi,
21904
21927
  contract_address,
21905
- this.providerOrAccount
21928
+ this.account
21906
21929
  );
21907
21930
  contractInstance.deployTransactionHash = transaction_hash;
21908
21931
  return contractInstance;
21909
21932
  }
21910
- connect(providerOrAccount) {
21911
- this.providerOrAccount = providerOrAccount;
21933
+ connect(account) {
21934
+ this.account = account;
21912
21935
  return this;
21913
21936
  }
21914
21937
  attach(address) {
21915
- return new Contract(this.abi, address, this.providerOrAccount);
21938
+ return new Contract(this.abi, address, this.account);
21916
21939
  }
21917
21940
  };
21918
21941
 
@@ -22256,6 +22279,29 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22256
22279
  }
22257
22280
  };
22258
22281
 
22282
+ // src/utils/events.ts
22283
+ function parseUDCEvent(txReceipt) {
22284
+ if (!txReceipt.events) {
22285
+ throw new Error("UDC emited event is empty");
22286
+ }
22287
+ const event = txReceipt.events.find(
22288
+ (it) => cleanHex(it.from_address) === cleanHex(UDC.ADDRESS)
22289
+ ) || {
22290
+ data: []
22291
+ };
22292
+ return {
22293
+ transaction_hash: txReceipt.transaction_hash,
22294
+ contract_address: event.data[0],
22295
+ address: event.data[0],
22296
+ deployer: event.data[1],
22297
+ unique: event.data[2],
22298
+ classHash: event.data[3],
22299
+ calldata_len: event.data[4],
22300
+ calldata: event.data.slice(5, 5 + parseInt(event.data[4], 16)),
22301
+ salt: event.data[event.data.length - 1]
22302
+ };
22303
+ }
22304
+
22259
22305
  // src/account/default.ts
22260
22306
  var Account = class extends Provider {
22261
22307
  constructor(providerOrOptions, address, keyPairOrSigner) {
@@ -22264,7 +22310,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22264
22310
  this.signer = "getPubKey" in keyPairOrSigner ? keyPairOrSigner : new Signer(keyPairOrSigner);
22265
22311
  }
22266
22312
  async getNonce(blockIdentifier) {
22267
- return super.getNonce(this.address, blockIdentifier);
22313
+ return super.getNonceForAddress(this.address, blockIdentifier);
22268
22314
  }
22269
22315
  async estimateFee(calls, estimateFeeDetails) {
22270
22316
  return this.estimateInvokeFee(calls, estimateFeeDetails);
@@ -22351,7 +22397,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22351
22397
  }
22352
22398
  async estimateDeployFee({
22353
22399
  classHash,
22354
- salt,
22400
+ salt = "0",
22355
22401
  unique = true,
22356
22402
  constructorCalldata = [],
22357
22403
  additionalCalls = []
@@ -22432,9 +22478,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22432
22478
  unique = true,
22433
22479
  constructorCalldata = [],
22434
22480
  additionalCalls = []
22435
- }, transactionsDetail = {}) {
22481
+ }, invocationsDetails = {}) {
22436
22482
  const compiledConstructorCallData = compileCalldata(constructorCalldata);
22437
22483
  const callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls];
22484
+ const deploySalt = salt ?? randomAddress();
22438
22485
  return this.execute(
22439
22486
  [
22440
22487
  {
@@ -22442,7 +22489,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22442
22489
  entrypoint: UDC.ENTRYPOINT,
22443
22490
  calldata: [
22444
22491
  classHash,
22445
- salt,
22492
+ deploySalt,
22446
22493
  toCairoBool(unique),
22447
22494
  compiledConstructorCallData.length,
22448
22495
  ...compiledConstructorCallData
@@ -22451,9 +22498,20 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22451
22498
  ...callsArray
22452
22499
  ],
22453
22500
  void 0,
22454
- transactionsDetail
22501
+ invocationsDetails
22455
22502
  );
22456
22503
  }
22504
+ async deployContract(payload, details = {}) {
22505
+ const deployTx = await this.deploy(payload, details);
22506
+ const txReceipt = await this.waitForTransaction(deployTx.transaction_hash, ["ACCEPTED_ON_L2"]);
22507
+ return parseUDCEvent(txReceipt);
22508
+ }
22509
+ async declareDeploy({ classHash, contract, constructorCalldata }, details) {
22510
+ const { transaction_hash } = await this.declare({ contract, classHash }, details);
22511
+ const declare = await this.waitForTransaction(transaction_hash, ["ACCEPTED_ON_L2"]);
22512
+ const deploy = await this.deployContract({ classHash, constructorCalldata }, details);
22513
+ return { declare: { ...declare, class_hash: classHash }, deploy };
22514
+ }
22457
22515
  async deployAccount({
22458
22516
  classHash,
22459
22517
  constructorCalldata = [],