@grapenpm/gpass-sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -4
- package/dist/index.d.mts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +221 -187
- package/dist/index.mjs +221 -187
- package/package.json +3 -5
- package/src/client.ts +44 -20
- package/src/index.ts +1 -1
- package/src/types/index.ts +39 -6
- package/src/bn-js.d.ts +0 -18
package/dist/index.mjs
CHANGED
|
@@ -47,8 +47,8 @@ var require_bn = __commonJS({
|
|
|
47
47
|
ctor.prototype = new TempCtor();
|
|
48
48
|
ctor.prototype.constructor = ctor;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
if (
|
|
50
|
+
function BN2(number, base, endian) {
|
|
51
|
+
if (BN2.isBN(number)) {
|
|
52
52
|
return number;
|
|
53
53
|
}
|
|
54
54
|
this.negative = 0;
|
|
@@ -64,12 +64,12 @@ var require_bn = __commonJS({
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
if (typeof module2 === "object") {
|
|
67
|
-
module2.exports =
|
|
67
|
+
module2.exports = BN2;
|
|
68
68
|
} else {
|
|
69
|
-
exports2.BN =
|
|
69
|
+
exports2.BN = BN2;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
BN2.BN = BN2;
|
|
72
|
+
BN2.wordSize = 26;
|
|
73
73
|
var Buffer2;
|
|
74
74
|
try {
|
|
75
75
|
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
|
|
@@ -79,21 +79,21 @@ var require_bn = __commonJS({
|
|
|
79
79
|
}
|
|
80
80
|
} catch (e) {
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
if (num instanceof
|
|
82
|
+
BN2.isBN = function isBN(num) {
|
|
83
|
+
if (num instanceof BN2) {
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
86
|
-
return num !== null && typeof num === "object" && num.constructor.wordSize ===
|
|
86
|
+
return num !== null && typeof num === "object" && num.constructor.wordSize === BN2.wordSize && Array.isArray(num.words);
|
|
87
87
|
};
|
|
88
|
-
|
|
88
|
+
BN2.max = function max(left, right) {
|
|
89
89
|
if (left.cmp(right) > 0) return left;
|
|
90
90
|
return right;
|
|
91
91
|
};
|
|
92
|
-
|
|
92
|
+
BN2.min = function min(left, right) {
|
|
93
93
|
if (left.cmp(right) < 0) return left;
|
|
94
94
|
return right;
|
|
95
95
|
};
|
|
96
|
-
|
|
96
|
+
BN2.prototype._init = function init(number, base, endian) {
|
|
97
97
|
if (typeof number === "number") {
|
|
98
98
|
return this._initNumber(number, base, endian);
|
|
99
99
|
}
|
|
@@ -121,7 +121,7 @@ var require_bn = __commonJS({
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
-
|
|
124
|
+
BN2.prototype._initNumber = function _initNumber(number, base, endian) {
|
|
125
125
|
if (number < 0) {
|
|
126
126
|
this.negative = 1;
|
|
127
127
|
number = -number;
|
|
@@ -147,7 +147,7 @@ var require_bn = __commonJS({
|
|
|
147
147
|
if (endian !== "le") return;
|
|
148
148
|
this._initArray(this.toArray(), base, endian);
|
|
149
149
|
};
|
|
150
|
-
|
|
150
|
+
BN2.prototype._initArray = function _initArray(number, base, endian) {
|
|
151
151
|
assert(typeof number.length === "number");
|
|
152
152
|
if (number.length <= 0) {
|
|
153
153
|
this.words = [0];
|
|
@@ -205,7 +205,7 @@ var require_bn = __commonJS({
|
|
|
205
205
|
}
|
|
206
206
|
return r;
|
|
207
207
|
}
|
|
208
|
-
|
|
208
|
+
BN2.prototype._parseHex = function _parseHex(number, start, endian) {
|
|
209
209
|
this.length = Math.ceil((number.length - start) / 6);
|
|
210
210
|
this.words = new Array(this.length);
|
|
211
211
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -261,7 +261,7 @@ var require_bn = __commonJS({
|
|
|
261
261
|
}
|
|
262
262
|
return r;
|
|
263
263
|
}
|
|
264
|
-
|
|
264
|
+
BN2.prototype._parseBase = function _parseBase(number, base, start) {
|
|
265
265
|
this.words = [0];
|
|
266
266
|
this.length = 1;
|
|
267
267
|
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
|
|
@@ -297,7 +297,7 @@ var require_bn = __commonJS({
|
|
|
297
297
|
}
|
|
298
298
|
this._strip();
|
|
299
299
|
};
|
|
300
|
-
|
|
300
|
+
BN2.prototype.copy = function copy(dest) {
|
|
301
301
|
dest.words = new Array(this.length);
|
|
302
302
|
for (var i = 0; i < this.length; i++) {
|
|
303
303
|
dest.words[i] = this.words[i];
|
|
@@ -312,27 +312,27 @@ var require_bn = __commonJS({
|
|
|
312
312
|
dest.negative = src.negative;
|
|
313
313
|
dest.red = src.red;
|
|
314
314
|
}
|
|
315
|
-
|
|
315
|
+
BN2.prototype._move = function _move(dest) {
|
|
316
316
|
move(dest, this);
|
|
317
317
|
};
|
|
318
|
-
|
|
319
|
-
var r = new
|
|
318
|
+
BN2.prototype.clone = function clone() {
|
|
319
|
+
var r = new BN2(null);
|
|
320
320
|
this.copy(r);
|
|
321
321
|
return r;
|
|
322
322
|
};
|
|
323
|
-
|
|
323
|
+
BN2.prototype._expand = function _expand(size) {
|
|
324
324
|
while (this.length < size) {
|
|
325
325
|
this.words[this.length++] = 0;
|
|
326
326
|
}
|
|
327
327
|
return this;
|
|
328
328
|
};
|
|
329
|
-
|
|
329
|
+
BN2.prototype._strip = function strip() {
|
|
330
330
|
while (this.length > 1 && this.words[this.length - 1] === 0) {
|
|
331
331
|
this.length--;
|
|
332
332
|
}
|
|
333
333
|
return this._normSign();
|
|
334
334
|
};
|
|
335
|
-
|
|
335
|
+
BN2.prototype._normSign = function _normSign() {
|
|
336
336
|
if (this.length === 1 && this.words[0] === 0) {
|
|
337
337
|
this.negative = 0;
|
|
338
338
|
}
|
|
@@ -340,12 +340,12 @@ var require_bn = __commonJS({
|
|
|
340
340
|
};
|
|
341
341
|
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
|
|
342
342
|
try {
|
|
343
|
-
|
|
343
|
+
BN2.prototype[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = inspect;
|
|
344
344
|
} catch (e) {
|
|
345
|
-
|
|
345
|
+
BN2.prototype.inspect = inspect;
|
|
346
346
|
}
|
|
347
347
|
} else {
|
|
348
|
-
|
|
348
|
+
BN2.prototype.inspect = inspect;
|
|
349
349
|
}
|
|
350
350
|
function inspect() {
|
|
351
351
|
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
|
|
@@ -456,7 +456,7 @@ var require_bn = __commonJS({
|
|
|
456
456
|
52521875,
|
|
457
457
|
60466176
|
|
458
458
|
];
|
|
459
|
-
|
|
459
|
+
BN2.prototype.toString = function toString(base, padding) {
|
|
460
460
|
base = base || 10;
|
|
461
461
|
padding = padding | 0 || 1;
|
|
462
462
|
var out;
|
|
@@ -518,7 +518,7 @@ var require_bn = __commonJS({
|
|
|
518
518
|
}
|
|
519
519
|
assert(false, "Base should be between 2 and 36");
|
|
520
520
|
};
|
|
521
|
-
|
|
521
|
+
BN2.prototype.toNumber = function toNumber() {
|
|
522
522
|
var ret = this.words[0];
|
|
523
523
|
if (this.length === 2) {
|
|
524
524
|
ret += this.words[1] * 67108864;
|
|
@@ -529,15 +529,15 @@ var require_bn = __commonJS({
|
|
|
529
529
|
}
|
|
530
530
|
return this.negative !== 0 ? -ret : ret;
|
|
531
531
|
};
|
|
532
|
-
|
|
532
|
+
BN2.prototype.toJSON = function toJSON() {
|
|
533
533
|
return this.toString(16, 2);
|
|
534
534
|
};
|
|
535
535
|
if (Buffer2) {
|
|
536
|
-
|
|
536
|
+
BN2.prototype.toBuffer = function toBuffer(endian, length) {
|
|
537
537
|
return this.toArrayLike(Buffer2, endian, length);
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
|
-
|
|
540
|
+
BN2.prototype.toArray = function toArray(endian, length) {
|
|
541
541
|
return this.toArrayLike(Array, endian, length);
|
|
542
542
|
};
|
|
543
543
|
var allocate = function allocate2(ArrayType, size) {
|
|
@@ -546,7 +546,7 @@ var require_bn = __commonJS({
|
|
|
546
546
|
}
|
|
547
547
|
return new ArrayType(size);
|
|
548
548
|
};
|
|
549
|
-
|
|
549
|
+
BN2.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
|
|
550
550
|
this._strip();
|
|
551
551
|
var byteLength = this.byteLength();
|
|
552
552
|
var reqLength = length || Math.max(1, byteLength);
|
|
@@ -557,7 +557,7 @@ var require_bn = __commonJS({
|
|
|
557
557
|
this["_toArrayLike" + postfix](res, byteLength);
|
|
558
558
|
return res;
|
|
559
559
|
};
|
|
560
|
-
|
|
560
|
+
BN2.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
|
|
561
561
|
var position = 0;
|
|
562
562
|
var carry = 0;
|
|
563
563
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -587,7 +587,7 @@ var require_bn = __commonJS({
|
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
};
|
|
590
|
-
|
|
590
|
+
BN2.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
|
|
591
591
|
var position = res.length - 1;
|
|
592
592
|
var carry = 0;
|
|
593
593
|
for (var i = 0, shift = 0; i < this.length; i++) {
|
|
@@ -618,11 +618,11 @@ var require_bn = __commonJS({
|
|
|
618
618
|
}
|
|
619
619
|
};
|
|
620
620
|
if (Math.clz32) {
|
|
621
|
-
|
|
621
|
+
BN2.prototype._countBits = function _countBits(w) {
|
|
622
622
|
return 32 - Math.clz32(w);
|
|
623
623
|
};
|
|
624
624
|
} else {
|
|
625
|
-
|
|
625
|
+
BN2.prototype._countBits = function _countBits(w) {
|
|
626
626
|
var t = w;
|
|
627
627
|
var r = 0;
|
|
628
628
|
if (t >= 4096) {
|
|
@@ -644,7 +644,7 @@ var require_bn = __commonJS({
|
|
|
644
644
|
return r + t;
|
|
645
645
|
};
|
|
646
646
|
}
|
|
647
|
-
|
|
647
|
+
BN2.prototype._zeroBits = function _zeroBits(w) {
|
|
648
648
|
if (w === 0) return 26;
|
|
649
649
|
var t = w;
|
|
650
650
|
var r = 0;
|
|
@@ -669,7 +669,7 @@ var require_bn = __commonJS({
|
|
|
669
669
|
}
|
|
670
670
|
return r;
|
|
671
671
|
};
|
|
672
|
-
|
|
672
|
+
BN2.prototype.bitLength = function bitLength() {
|
|
673
673
|
var w = this.words[this.length - 1];
|
|
674
674
|
var hi = this._countBits(w);
|
|
675
675
|
return (this.length - 1) * 26 + hi;
|
|
@@ -683,7 +683,7 @@ var require_bn = __commonJS({
|
|
|
683
683
|
}
|
|
684
684
|
return w;
|
|
685
685
|
}
|
|
686
|
-
|
|
686
|
+
BN2.prototype.zeroBits = function zeroBits() {
|
|
687
687
|
if (this.isZero()) return 0;
|
|
688
688
|
var r = 0;
|
|
689
689
|
for (var i = 0; i < this.length; i++) {
|
|
@@ -693,34 +693,34 @@ var require_bn = __commonJS({
|
|
|
693
693
|
}
|
|
694
694
|
return r;
|
|
695
695
|
};
|
|
696
|
-
|
|
696
|
+
BN2.prototype.byteLength = function byteLength() {
|
|
697
697
|
return Math.ceil(this.bitLength() / 8);
|
|
698
698
|
};
|
|
699
|
-
|
|
699
|
+
BN2.prototype.toTwos = function toTwos(width) {
|
|
700
700
|
if (this.negative !== 0) {
|
|
701
701
|
return this.abs().inotn(width).iaddn(1);
|
|
702
702
|
}
|
|
703
703
|
return this.clone();
|
|
704
704
|
};
|
|
705
|
-
|
|
705
|
+
BN2.prototype.fromTwos = function fromTwos(width) {
|
|
706
706
|
if (this.testn(width - 1)) {
|
|
707
707
|
return this.notn(width).iaddn(1).ineg();
|
|
708
708
|
}
|
|
709
709
|
return this.clone();
|
|
710
710
|
};
|
|
711
|
-
|
|
711
|
+
BN2.prototype.isNeg = function isNeg() {
|
|
712
712
|
return this.negative !== 0;
|
|
713
713
|
};
|
|
714
|
-
|
|
714
|
+
BN2.prototype.neg = function neg() {
|
|
715
715
|
return this.clone().ineg();
|
|
716
716
|
};
|
|
717
|
-
|
|
717
|
+
BN2.prototype.ineg = function ineg() {
|
|
718
718
|
if (!this.isZero()) {
|
|
719
719
|
this.negative ^= 1;
|
|
720
720
|
}
|
|
721
721
|
return this;
|
|
722
722
|
};
|
|
723
|
-
|
|
723
|
+
BN2.prototype.iuor = function iuor(num) {
|
|
724
724
|
while (this.length < num.length) {
|
|
725
725
|
this.words[this.length++] = 0;
|
|
726
726
|
}
|
|
@@ -729,19 +729,19 @@ var require_bn = __commonJS({
|
|
|
729
729
|
}
|
|
730
730
|
return this._strip();
|
|
731
731
|
};
|
|
732
|
-
|
|
732
|
+
BN2.prototype.ior = function ior(num) {
|
|
733
733
|
assert((this.negative | num.negative) === 0);
|
|
734
734
|
return this.iuor(num);
|
|
735
735
|
};
|
|
736
|
-
|
|
736
|
+
BN2.prototype.or = function or(num) {
|
|
737
737
|
if (this.length > num.length) return this.clone().ior(num);
|
|
738
738
|
return num.clone().ior(this);
|
|
739
739
|
};
|
|
740
|
-
|
|
740
|
+
BN2.prototype.uor = function uor(num) {
|
|
741
741
|
if (this.length > num.length) return this.clone().iuor(num);
|
|
742
742
|
return num.clone().iuor(this);
|
|
743
743
|
};
|
|
744
|
-
|
|
744
|
+
BN2.prototype.iuand = function iuand(num) {
|
|
745
745
|
var b;
|
|
746
746
|
if (this.length > num.length) {
|
|
747
747
|
b = num;
|
|
@@ -754,19 +754,19 @@ var require_bn = __commonJS({
|
|
|
754
754
|
this.length = b.length;
|
|
755
755
|
return this._strip();
|
|
756
756
|
};
|
|
757
|
-
|
|
757
|
+
BN2.prototype.iand = function iand(num) {
|
|
758
758
|
assert((this.negative | num.negative) === 0);
|
|
759
759
|
return this.iuand(num);
|
|
760
760
|
};
|
|
761
|
-
|
|
761
|
+
BN2.prototype.and = function and(num) {
|
|
762
762
|
if (this.length > num.length) return this.clone().iand(num);
|
|
763
763
|
return num.clone().iand(this);
|
|
764
764
|
};
|
|
765
|
-
|
|
765
|
+
BN2.prototype.uand = function uand(num) {
|
|
766
766
|
if (this.length > num.length) return this.clone().iuand(num);
|
|
767
767
|
return num.clone().iuand(this);
|
|
768
768
|
};
|
|
769
|
-
|
|
769
|
+
BN2.prototype.iuxor = function iuxor(num) {
|
|
770
770
|
var a;
|
|
771
771
|
var b;
|
|
772
772
|
if (this.length > num.length) {
|
|
@@ -787,19 +787,19 @@ var require_bn = __commonJS({
|
|
|
787
787
|
this.length = a.length;
|
|
788
788
|
return this._strip();
|
|
789
789
|
};
|
|
790
|
-
|
|
790
|
+
BN2.prototype.ixor = function ixor(num) {
|
|
791
791
|
assert((this.negative | num.negative) === 0);
|
|
792
792
|
return this.iuxor(num);
|
|
793
793
|
};
|
|
794
|
-
|
|
794
|
+
BN2.prototype.xor = function xor(num) {
|
|
795
795
|
if (this.length > num.length) return this.clone().ixor(num);
|
|
796
796
|
return num.clone().ixor(this);
|
|
797
797
|
};
|
|
798
|
-
|
|
798
|
+
BN2.prototype.uxor = function uxor(num) {
|
|
799
799
|
if (this.length > num.length) return this.clone().iuxor(num);
|
|
800
800
|
return num.clone().iuxor(this);
|
|
801
801
|
};
|
|
802
|
-
|
|
802
|
+
BN2.prototype.inotn = function inotn(width) {
|
|
803
803
|
assert(typeof width === "number" && width >= 0);
|
|
804
804
|
var bytesNeeded = Math.ceil(width / 26) | 0;
|
|
805
805
|
var bitsLeft = width % 26;
|
|
@@ -815,10 +815,10 @@ var require_bn = __commonJS({
|
|
|
815
815
|
}
|
|
816
816
|
return this._strip();
|
|
817
817
|
};
|
|
818
|
-
|
|
818
|
+
BN2.prototype.notn = function notn(width) {
|
|
819
819
|
return this.clone().inotn(width);
|
|
820
820
|
};
|
|
821
|
-
|
|
821
|
+
BN2.prototype.setn = function setn(bit, val) {
|
|
822
822
|
assert(typeof bit === "number" && bit >= 0);
|
|
823
823
|
var off = bit / 26 | 0;
|
|
824
824
|
var wbit = bit % 26;
|
|
@@ -830,7 +830,7 @@ var require_bn = __commonJS({
|
|
|
830
830
|
}
|
|
831
831
|
return this._strip();
|
|
832
832
|
};
|
|
833
|
-
|
|
833
|
+
BN2.prototype.iadd = function iadd(num) {
|
|
834
834
|
var r;
|
|
835
835
|
if (this.negative !== 0 && num.negative === 0) {
|
|
836
836
|
this.negative = 0;
|
|
@@ -873,7 +873,7 @@ var require_bn = __commonJS({
|
|
|
873
873
|
}
|
|
874
874
|
return this;
|
|
875
875
|
};
|
|
876
|
-
|
|
876
|
+
BN2.prototype.add = function add(num) {
|
|
877
877
|
var res;
|
|
878
878
|
if (num.negative !== 0 && this.negative === 0) {
|
|
879
879
|
num.negative = 0;
|
|
@@ -889,7 +889,7 @@ var require_bn = __commonJS({
|
|
|
889
889
|
if (this.length > num.length) return this.clone().iadd(num);
|
|
890
890
|
return num.clone().iadd(this);
|
|
891
891
|
};
|
|
892
|
-
|
|
892
|
+
BN2.prototype.isub = function isub(num) {
|
|
893
893
|
if (num.negative !== 0) {
|
|
894
894
|
num.negative = 0;
|
|
895
895
|
var r = this.iadd(num);
|
|
@@ -938,7 +938,7 @@ var require_bn = __commonJS({
|
|
|
938
938
|
}
|
|
939
939
|
return this._strip();
|
|
940
940
|
};
|
|
941
|
-
|
|
941
|
+
BN2.prototype.sub = function sub(num) {
|
|
942
942
|
return this.clone().isub(num);
|
|
943
943
|
};
|
|
944
944
|
function smallMulTo(self, num, out) {
|
|
@@ -1566,7 +1566,7 @@ var require_bn = __commonJS({
|
|
|
1566
1566
|
function jumboMulTo(self, num, out) {
|
|
1567
1567
|
return bigMulTo(self, num, out);
|
|
1568
1568
|
}
|
|
1569
|
-
|
|
1569
|
+
BN2.prototype.mulTo = function mulTo(num, out) {
|
|
1570
1570
|
var res;
|
|
1571
1571
|
var len = this.length + num.length;
|
|
1572
1572
|
if (this.length === 10 && num.length === 10) {
|
|
@@ -1586,7 +1586,7 @@ var require_bn = __commonJS({
|
|
|
1586
1586
|
}
|
|
1587
1587
|
FFTM.prototype.makeRBT = function makeRBT(N) {
|
|
1588
1588
|
var t = new Array(N);
|
|
1589
|
-
var l =
|
|
1589
|
+
var l = BN2.prototype._countBits(N) - 1;
|
|
1590
1590
|
for (var i = 0; i < N; i++) {
|
|
1591
1591
|
t[i] = this.revBin(i, l, N);
|
|
1592
1592
|
}
|
|
@@ -1721,20 +1721,20 @@ var require_bn = __commonJS({
|
|
|
1721
1721
|
out.length = x.length + y.length;
|
|
1722
1722
|
return out._strip();
|
|
1723
1723
|
};
|
|
1724
|
-
|
|
1725
|
-
var out = new
|
|
1724
|
+
BN2.prototype.mul = function mul(num) {
|
|
1725
|
+
var out = new BN2(null);
|
|
1726
1726
|
out.words = new Array(this.length + num.length);
|
|
1727
1727
|
return this.mulTo(num, out);
|
|
1728
1728
|
};
|
|
1729
|
-
|
|
1730
|
-
var out = new
|
|
1729
|
+
BN2.prototype.mulf = function mulf(num) {
|
|
1730
|
+
var out = new BN2(null);
|
|
1731
1731
|
out.words = new Array(this.length + num.length);
|
|
1732
1732
|
return jumboMulTo(this, num, out);
|
|
1733
1733
|
};
|
|
1734
|
-
|
|
1734
|
+
BN2.prototype.imul = function imul(num) {
|
|
1735
1735
|
return this.clone().mulTo(num, this);
|
|
1736
1736
|
};
|
|
1737
|
-
|
|
1737
|
+
BN2.prototype.imuln = function imuln(num) {
|
|
1738
1738
|
var isNegNum = num < 0;
|
|
1739
1739
|
if (isNegNum) num = -num;
|
|
1740
1740
|
assert(typeof num === "number");
|
|
@@ -1755,18 +1755,18 @@ var require_bn = __commonJS({
|
|
|
1755
1755
|
this.length = num === 0 ? 1 : this.length;
|
|
1756
1756
|
return isNegNum ? this.ineg() : this;
|
|
1757
1757
|
};
|
|
1758
|
-
|
|
1758
|
+
BN2.prototype.muln = function muln(num) {
|
|
1759
1759
|
return this.clone().imuln(num);
|
|
1760
1760
|
};
|
|
1761
|
-
|
|
1761
|
+
BN2.prototype.sqr = function sqr() {
|
|
1762
1762
|
return this.mul(this);
|
|
1763
1763
|
};
|
|
1764
|
-
|
|
1764
|
+
BN2.prototype.isqr = function isqr() {
|
|
1765
1765
|
return this.imul(this.clone());
|
|
1766
1766
|
};
|
|
1767
|
-
|
|
1767
|
+
BN2.prototype.pow = function pow(num) {
|
|
1768
1768
|
var w = toBitArray(num);
|
|
1769
|
-
if (w.length === 0) return new
|
|
1769
|
+
if (w.length === 0) return new BN2(1);
|
|
1770
1770
|
var res = this;
|
|
1771
1771
|
for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
|
1772
1772
|
if (w[i] !== 0) break;
|
|
@@ -1779,7 +1779,7 @@ var require_bn = __commonJS({
|
|
|
1779
1779
|
}
|
|
1780
1780
|
return res;
|
|
1781
1781
|
};
|
|
1782
|
-
|
|
1782
|
+
BN2.prototype.iushln = function iushln(bits) {
|
|
1783
1783
|
assert(typeof bits === "number" && bits >= 0);
|
|
1784
1784
|
var r = bits % 26;
|
|
1785
1785
|
var s = (bits - r) / 26;
|
|
@@ -1809,11 +1809,11 @@ var require_bn = __commonJS({
|
|
|
1809
1809
|
}
|
|
1810
1810
|
return this._strip();
|
|
1811
1811
|
};
|
|
1812
|
-
|
|
1812
|
+
BN2.prototype.ishln = function ishln(bits) {
|
|
1813
1813
|
assert(this.negative === 0);
|
|
1814
1814
|
return this.iushln(bits);
|
|
1815
1815
|
};
|
|
1816
|
-
|
|
1816
|
+
BN2.prototype.iushrn = function iushrn(bits, hint, extended) {
|
|
1817
1817
|
assert(typeof bits === "number" && bits >= 0);
|
|
1818
1818
|
var h;
|
|
1819
1819
|
if (hint) {
|
|
@@ -1858,23 +1858,23 @@ var require_bn = __commonJS({
|
|
|
1858
1858
|
}
|
|
1859
1859
|
return this._strip();
|
|
1860
1860
|
};
|
|
1861
|
-
|
|
1861
|
+
BN2.prototype.ishrn = function ishrn(bits, hint, extended) {
|
|
1862
1862
|
assert(this.negative === 0);
|
|
1863
1863
|
return this.iushrn(bits, hint, extended);
|
|
1864
1864
|
};
|
|
1865
|
-
|
|
1865
|
+
BN2.prototype.shln = function shln(bits) {
|
|
1866
1866
|
return this.clone().ishln(bits);
|
|
1867
1867
|
};
|
|
1868
|
-
|
|
1868
|
+
BN2.prototype.ushln = function ushln(bits) {
|
|
1869
1869
|
return this.clone().iushln(bits);
|
|
1870
1870
|
};
|
|
1871
|
-
|
|
1871
|
+
BN2.prototype.shrn = function shrn(bits) {
|
|
1872
1872
|
return this.clone().ishrn(bits);
|
|
1873
1873
|
};
|
|
1874
|
-
|
|
1874
|
+
BN2.prototype.ushrn = function ushrn(bits) {
|
|
1875
1875
|
return this.clone().iushrn(bits);
|
|
1876
1876
|
};
|
|
1877
|
-
|
|
1877
|
+
BN2.prototype.testn = function testn(bit) {
|
|
1878
1878
|
assert(typeof bit === "number" && bit >= 0);
|
|
1879
1879
|
var r = bit % 26;
|
|
1880
1880
|
var s = (bit - r) / 26;
|
|
@@ -1883,7 +1883,7 @@ var require_bn = __commonJS({
|
|
|
1883
1883
|
var w = this.words[s];
|
|
1884
1884
|
return !!(w & q);
|
|
1885
1885
|
};
|
|
1886
|
-
|
|
1886
|
+
BN2.prototype.imaskn = function imaskn(bits) {
|
|
1887
1887
|
assert(typeof bits === "number" && bits >= 0);
|
|
1888
1888
|
var r = bits % 26;
|
|
1889
1889
|
var s = (bits - r) / 26;
|
|
@@ -1899,12 +1899,16 @@ var require_bn = __commonJS({
|
|
|
1899
1899
|
var mask = 67108863 ^ 67108863 >>> r << r;
|
|
1900
1900
|
this.words[this.length - 1] &= mask;
|
|
1901
1901
|
}
|
|
1902
|
+
if (this.length === 0) {
|
|
1903
|
+
this.words[0] = 0;
|
|
1904
|
+
this.length = 1;
|
|
1905
|
+
}
|
|
1902
1906
|
return this._strip();
|
|
1903
1907
|
};
|
|
1904
|
-
|
|
1908
|
+
BN2.prototype.maskn = function maskn(bits) {
|
|
1905
1909
|
return this.clone().imaskn(bits);
|
|
1906
1910
|
};
|
|
1907
|
-
|
|
1911
|
+
BN2.prototype.iaddn = function iaddn(num) {
|
|
1908
1912
|
assert(typeof num === "number");
|
|
1909
1913
|
assert(num < 67108864);
|
|
1910
1914
|
if (num < 0) return this.isubn(-num);
|
|
@@ -1921,7 +1925,7 @@ var require_bn = __commonJS({
|
|
|
1921
1925
|
}
|
|
1922
1926
|
return this._iaddn(num);
|
|
1923
1927
|
};
|
|
1924
|
-
|
|
1928
|
+
BN2.prototype._iaddn = function _iaddn(num) {
|
|
1925
1929
|
this.words[0] += num;
|
|
1926
1930
|
for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
|
|
1927
1931
|
this.words[i] -= 67108864;
|
|
@@ -1934,7 +1938,7 @@ var require_bn = __commonJS({
|
|
|
1934
1938
|
this.length = Math.max(this.length, i + 1);
|
|
1935
1939
|
return this;
|
|
1936
1940
|
};
|
|
1937
|
-
|
|
1941
|
+
BN2.prototype.isubn = function isubn(num) {
|
|
1938
1942
|
assert(typeof num === "number");
|
|
1939
1943
|
assert(num < 67108864);
|
|
1940
1944
|
if (num < 0) return this.iaddn(-num);
|
|
@@ -1956,20 +1960,20 @@ var require_bn = __commonJS({
|
|
|
1956
1960
|
}
|
|
1957
1961
|
return this._strip();
|
|
1958
1962
|
};
|
|
1959
|
-
|
|
1963
|
+
BN2.prototype.addn = function addn(num) {
|
|
1960
1964
|
return this.clone().iaddn(num);
|
|
1961
1965
|
};
|
|
1962
|
-
|
|
1966
|
+
BN2.prototype.subn = function subn(num) {
|
|
1963
1967
|
return this.clone().isubn(num);
|
|
1964
1968
|
};
|
|
1965
|
-
|
|
1969
|
+
BN2.prototype.iabs = function iabs() {
|
|
1966
1970
|
this.negative = 0;
|
|
1967
1971
|
return this;
|
|
1968
1972
|
};
|
|
1969
|
-
|
|
1973
|
+
BN2.prototype.abs = function abs() {
|
|
1970
1974
|
return this.clone().iabs();
|
|
1971
1975
|
};
|
|
1972
|
-
|
|
1976
|
+
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
|
|
1973
1977
|
var len = num.length + shift;
|
|
1974
1978
|
var i;
|
|
1975
1979
|
this._expand(len);
|
|
@@ -1998,7 +2002,7 @@ var require_bn = __commonJS({
|
|
|
1998
2002
|
this.negative = 1;
|
|
1999
2003
|
return this._strip();
|
|
2000
2004
|
};
|
|
2001
|
-
|
|
2005
|
+
BN2.prototype._wordDiv = function _wordDiv(num, mode) {
|
|
2002
2006
|
var shift = this.length - num.length;
|
|
2003
2007
|
var a = this.clone();
|
|
2004
2008
|
var b = num;
|
|
@@ -2013,7 +2017,7 @@ var require_bn = __commonJS({
|
|
|
2013
2017
|
var m = a.length - b.length;
|
|
2014
2018
|
var q;
|
|
2015
2019
|
if (mode !== "mod") {
|
|
2016
|
-
q = new
|
|
2020
|
+
q = new BN2(null);
|
|
2017
2021
|
q.length = m + 1;
|
|
2018
2022
|
q.words = new Array(q.length);
|
|
2019
2023
|
for (var i = 0; i < q.length; i++) {
|
|
@@ -2055,12 +2059,12 @@ var require_bn = __commonJS({
|
|
|
2055
2059
|
mod: a
|
|
2056
2060
|
};
|
|
2057
2061
|
};
|
|
2058
|
-
|
|
2062
|
+
BN2.prototype.divmod = function divmod(num, mode, positive) {
|
|
2059
2063
|
assert(!num.isZero());
|
|
2060
2064
|
if (this.isZero()) {
|
|
2061
2065
|
return {
|
|
2062
|
-
div: new
|
|
2063
|
-
mod: new
|
|
2066
|
+
div: new BN2(0),
|
|
2067
|
+
mod: new BN2(0)
|
|
2064
2068
|
};
|
|
2065
2069
|
}
|
|
2066
2070
|
var div, mod, res;
|
|
@@ -2105,7 +2109,7 @@ var require_bn = __commonJS({
|
|
|
2105
2109
|
}
|
|
2106
2110
|
if (num.length > this.length || this.cmp(num) < 0) {
|
|
2107
2111
|
return {
|
|
2108
|
-
div: new
|
|
2112
|
+
div: new BN2(0),
|
|
2109
2113
|
mod: this
|
|
2110
2114
|
};
|
|
2111
2115
|
}
|
|
@@ -2119,26 +2123,26 @@ var require_bn = __commonJS({
|
|
|
2119
2123
|
if (mode === "mod") {
|
|
2120
2124
|
return {
|
|
2121
2125
|
div: null,
|
|
2122
|
-
mod: new
|
|
2126
|
+
mod: new BN2(this.modrn(num.words[0]))
|
|
2123
2127
|
};
|
|
2124
2128
|
}
|
|
2125
2129
|
return {
|
|
2126
2130
|
div: this.divn(num.words[0]),
|
|
2127
|
-
mod: new
|
|
2131
|
+
mod: new BN2(this.modrn(num.words[0]))
|
|
2128
2132
|
};
|
|
2129
2133
|
}
|
|
2130
2134
|
return this._wordDiv(num, mode);
|
|
2131
2135
|
};
|
|
2132
|
-
|
|
2136
|
+
BN2.prototype.div = function div(num) {
|
|
2133
2137
|
return this.divmod(num, "div", false).div;
|
|
2134
2138
|
};
|
|
2135
|
-
|
|
2139
|
+
BN2.prototype.mod = function mod(num) {
|
|
2136
2140
|
return this.divmod(num, "mod", false).mod;
|
|
2137
2141
|
};
|
|
2138
|
-
|
|
2142
|
+
BN2.prototype.umod = function umod(num) {
|
|
2139
2143
|
return this.divmod(num, "mod", true).mod;
|
|
2140
2144
|
};
|
|
2141
|
-
|
|
2145
|
+
BN2.prototype.divRound = function divRound(num) {
|
|
2142
2146
|
var dm = this.divmod(num);
|
|
2143
2147
|
if (dm.mod.isZero()) return dm.div;
|
|
2144
2148
|
var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
|
@@ -2148,7 +2152,7 @@ var require_bn = __commonJS({
|
|
|
2148
2152
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
2149
2153
|
return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
|
2150
2154
|
};
|
|
2151
|
-
|
|
2155
|
+
BN2.prototype.modrn = function modrn(num) {
|
|
2152
2156
|
var isNegNum = num < 0;
|
|
2153
2157
|
if (isNegNum) num = -num;
|
|
2154
2158
|
assert(num <= 67108863);
|
|
@@ -2159,10 +2163,10 @@ var require_bn = __commonJS({
|
|
|
2159
2163
|
}
|
|
2160
2164
|
return isNegNum ? -acc : acc;
|
|
2161
2165
|
};
|
|
2162
|
-
|
|
2166
|
+
BN2.prototype.modn = function modn(num) {
|
|
2163
2167
|
return this.modrn(num);
|
|
2164
2168
|
};
|
|
2165
|
-
|
|
2169
|
+
BN2.prototype.idivn = function idivn(num) {
|
|
2166
2170
|
var isNegNum = num < 0;
|
|
2167
2171
|
if (isNegNum) num = -num;
|
|
2168
2172
|
assert(num <= 67108863);
|
|
@@ -2175,10 +2179,10 @@ var require_bn = __commonJS({
|
|
|
2175
2179
|
this._strip();
|
|
2176
2180
|
return isNegNum ? this.ineg() : this;
|
|
2177
2181
|
};
|
|
2178
|
-
|
|
2182
|
+
BN2.prototype.divn = function divn(num) {
|
|
2179
2183
|
return this.clone().idivn(num);
|
|
2180
2184
|
};
|
|
2181
|
-
|
|
2185
|
+
BN2.prototype.egcd = function egcd(p) {
|
|
2182
2186
|
assert(p.negative === 0);
|
|
2183
2187
|
assert(!p.isZero());
|
|
2184
2188
|
var x = this;
|
|
@@ -2188,10 +2192,10 @@ var require_bn = __commonJS({
|
|
|
2188
2192
|
} else {
|
|
2189
2193
|
x = x.clone();
|
|
2190
2194
|
}
|
|
2191
|
-
var A = new
|
|
2192
|
-
var B = new
|
|
2193
|
-
var C = new
|
|
2194
|
-
var D = new
|
|
2195
|
+
var A = new BN2(1);
|
|
2196
|
+
var B = new BN2(0);
|
|
2197
|
+
var C = new BN2(0);
|
|
2198
|
+
var D = new BN2(1);
|
|
2195
2199
|
var g = 0;
|
|
2196
2200
|
while (x.isEven() && y.isEven()) {
|
|
2197
2201
|
x.iushrn(1);
|
|
@@ -2241,7 +2245,7 @@ var require_bn = __commonJS({
|
|
|
2241
2245
|
gcd: y.iushln(g)
|
|
2242
2246
|
};
|
|
2243
2247
|
};
|
|
2244
|
-
|
|
2248
|
+
BN2.prototype._invmp = function _invmp(p) {
|
|
2245
2249
|
assert(p.negative === 0);
|
|
2246
2250
|
assert(!p.isZero());
|
|
2247
2251
|
var a = this;
|
|
@@ -2251,8 +2255,8 @@ var require_bn = __commonJS({
|
|
|
2251
2255
|
} else {
|
|
2252
2256
|
a = a.clone();
|
|
2253
2257
|
}
|
|
2254
|
-
var x1 = new
|
|
2255
|
-
var x2 = new
|
|
2258
|
+
var x1 = new BN2(1);
|
|
2259
|
+
var x2 = new BN2(0);
|
|
2256
2260
|
var delta = b.clone();
|
|
2257
2261
|
while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
|
2258
2262
|
for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
|
|
@@ -2294,7 +2298,7 @@ var require_bn = __commonJS({
|
|
|
2294
2298
|
}
|
|
2295
2299
|
return res;
|
|
2296
2300
|
};
|
|
2297
|
-
|
|
2301
|
+
BN2.prototype.gcd = function gcd(num) {
|
|
2298
2302
|
if (this.isZero()) return num.abs();
|
|
2299
2303
|
if (num.isZero()) return this.abs();
|
|
2300
2304
|
var a = this.clone();
|
|
@@ -2324,19 +2328,19 @@ var require_bn = __commonJS({
|
|
|
2324
2328
|
} while (true);
|
|
2325
2329
|
return b.iushln(shift);
|
|
2326
2330
|
};
|
|
2327
|
-
|
|
2331
|
+
BN2.prototype.invm = function invm(num) {
|
|
2328
2332
|
return this.egcd(num).a.umod(num);
|
|
2329
2333
|
};
|
|
2330
|
-
|
|
2334
|
+
BN2.prototype.isEven = function isEven() {
|
|
2331
2335
|
return (this.words[0] & 1) === 0;
|
|
2332
2336
|
};
|
|
2333
|
-
|
|
2337
|
+
BN2.prototype.isOdd = function isOdd() {
|
|
2334
2338
|
return (this.words[0] & 1) === 1;
|
|
2335
2339
|
};
|
|
2336
|
-
|
|
2340
|
+
BN2.prototype.andln = function andln(num) {
|
|
2337
2341
|
return this.words[0] & num;
|
|
2338
2342
|
};
|
|
2339
|
-
|
|
2343
|
+
BN2.prototype.bincn = function bincn(bit) {
|
|
2340
2344
|
assert(typeof bit === "number");
|
|
2341
2345
|
var r = bit % 26;
|
|
2342
2346
|
var s = (bit - r) / 26;
|
|
@@ -2360,10 +2364,10 @@ var require_bn = __commonJS({
|
|
|
2360
2364
|
}
|
|
2361
2365
|
return this;
|
|
2362
2366
|
};
|
|
2363
|
-
|
|
2367
|
+
BN2.prototype.isZero = function isZero() {
|
|
2364
2368
|
return this.length === 1 && this.words[0] === 0;
|
|
2365
2369
|
};
|
|
2366
|
-
|
|
2370
|
+
BN2.prototype.cmpn = function cmpn(num) {
|
|
2367
2371
|
var negative = num < 0;
|
|
2368
2372
|
if (this.negative !== 0 && !negative) return -1;
|
|
2369
2373
|
if (this.negative === 0 && negative) return 1;
|
|
@@ -2382,14 +2386,14 @@ var require_bn = __commonJS({
|
|
|
2382
2386
|
if (this.negative !== 0) return -res | 0;
|
|
2383
2387
|
return res;
|
|
2384
2388
|
};
|
|
2385
|
-
|
|
2389
|
+
BN2.prototype.cmp = function cmp(num) {
|
|
2386
2390
|
if (this.negative !== 0 && num.negative === 0) return -1;
|
|
2387
2391
|
if (this.negative === 0 && num.negative !== 0) return 1;
|
|
2388
2392
|
var res = this.ucmp(num);
|
|
2389
2393
|
if (this.negative !== 0) return -res | 0;
|
|
2390
2394
|
return res;
|
|
2391
2395
|
};
|
|
2392
|
-
|
|
2396
|
+
BN2.prototype.ucmp = function ucmp(num) {
|
|
2393
2397
|
if (this.length > num.length) return 1;
|
|
2394
2398
|
if (this.length < num.length) return -1;
|
|
2395
2399
|
var res = 0;
|
|
@@ -2406,112 +2410,112 @@ var require_bn = __commonJS({
|
|
|
2406
2410
|
}
|
|
2407
2411
|
return res;
|
|
2408
2412
|
};
|
|
2409
|
-
|
|
2413
|
+
BN2.prototype.gtn = function gtn(num) {
|
|
2410
2414
|
return this.cmpn(num) === 1;
|
|
2411
2415
|
};
|
|
2412
|
-
|
|
2416
|
+
BN2.prototype.gt = function gt(num) {
|
|
2413
2417
|
return this.cmp(num) === 1;
|
|
2414
2418
|
};
|
|
2415
|
-
|
|
2419
|
+
BN2.prototype.gten = function gten(num) {
|
|
2416
2420
|
return this.cmpn(num) >= 0;
|
|
2417
2421
|
};
|
|
2418
|
-
|
|
2422
|
+
BN2.prototype.gte = function gte(num) {
|
|
2419
2423
|
return this.cmp(num) >= 0;
|
|
2420
2424
|
};
|
|
2421
|
-
|
|
2425
|
+
BN2.prototype.ltn = function ltn(num) {
|
|
2422
2426
|
return this.cmpn(num) === -1;
|
|
2423
2427
|
};
|
|
2424
|
-
|
|
2428
|
+
BN2.prototype.lt = function lt(num) {
|
|
2425
2429
|
return this.cmp(num) === -1;
|
|
2426
2430
|
};
|
|
2427
|
-
|
|
2431
|
+
BN2.prototype.lten = function lten(num) {
|
|
2428
2432
|
return this.cmpn(num) <= 0;
|
|
2429
2433
|
};
|
|
2430
|
-
|
|
2434
|
+
BN2.prototype.lte = function lte(num) {
|
|
2431
2435
|
return this.cmp(num) <= 0;
|
|
2432
2436
|
};
|
|
2433
|
-
|
|
2437
|
+
BN2.prototype.eqn = function eqn(num) {
|
|
2434
2438
|
return this.cmpn(num) === 0;
|
|
2435
2439
|
};
|
|
2436
|
-
|
|
2440
|
+
BN2.prototype.eq = function eq(num) {
|
|
2437
2441
|
return this.cmp(num) === 0;
|
|
2438
2442
|
};
|
|
2439
|
-
|
|
2443
|
+
BN2.red = function red(num) {
|
|
2440
2444
|
return new Red(num);
|
|
2441
2445
|
};
|
|
2442
|
-
|
|
2446
|
+
BN2.prototype.toRed = function toRed(ctx) {
|
|
2443
2447
|
assert(!this.red, "Already a number in reduction context");
|
|
2444
2448
|
assert(this.negative === 0, "red works only with positives");
|
|
2445
2449
|
return ctx.convertTo(this)._forceRed(ctx);
|
|
2446
2450
|
};
|
|
2447
|
-
|
|
2451
|
+
BN2.prototype.fromRed = function fromRed() {
|
|
2448
2452
|
assert(this.red, "fromRed works only with numbers in reduction context");
|
|
2449
2453
|
return this.red.convertFrom(this);
|
|
2450
2454
|
};
|
|
2451
|
-
|
|
2455
|
+
BN2.prototype._forceRed = function _forceRed(ctx) {
|
|
2452
2456
|
this.red = ctx;
|
|
2453
2457
|
return this;
|
|
2454
2458
|
};
|
|
2455
|
-
|
|
2459
|
+
BN2.prototype.forceRed = function forceRed(ctx) {
|
|
2456
2460
|
assert(!this.red, "Already a number in reduction context");
|
|
2457
2461
|
return this._forceRed(ctx);
|
|
2458
2462
|
};
|
|
2459
|
-
|
|
2463
|
+
BN2.prototype.redAdd = function redAdd(num) {
|
|
2460
2464
|
assert(this.red, "redAdd works only with red numbers");
|
|
2461
2465
|
return this.red.add(this, num);
|
|
2462
2466
|
};
|
|
2463
|
-
|
|
2467
|
+
BN2.prototype.redIAdd = function redIAdd(num) {
|
|
2464
2468
|
assert(this.red, "redIAdd works only with red numbers");
|
|
2465
2469
|
return this.red.iadd(this, num);
|
|
2466
2470
|
};
|
|
2467
|
-
|
|
2471
|
+
BN2.prototype.redSub = function redSub(num) {
|
|
2468
2472
|
assert(this.red, "redSub works only with red numbers");
|
|
2469
2473
|
return this.red.sub(this, num);
|
|
2470
2474
|
};
|
|
2471
|
-
|
|
2475
|
+
BN2.prototype.redISub = function redISub(num) {
|
|
2472
2476
|
assert(this.red, "redISub works only with red numbers");
|
|
2473
2477
|
return this.red.isub(this, num);
|
|
2474
2478
|
};
|
|
2475
|
-
|
|
2479
|
+
BN2.prototype.redShl = function redShl(num) {
|
|
2476
2480
|
assert(this.red, "redShl works only with red numbers");
|
|
2477
2481
|
return this.red.shl(this, num);
|
|
2478
2482
|
};
|
|
2479
|
-
|
|
2483
|
+
BN2.prototype.redMul = function redMul(num) {
|
|
2480
2484
|
assert(this.red, "redMul works only with red numbers");
|
|
2481
2485
|
this.red._verify2(this, num);
|
|
2482
2486
|
return this.red.mul(this, num);
|
|
2483
2487
|
};
|
|
2484
|
-
|
|
2488
|
+
BN2.prototype.redIMul = function redIMul(num) {
|
|
2485
2489
|
assert(this.red, "redMul works only with red numbers");
|
|
2486
2490
|
this.red._verify2(this, num);
|
|
2487
2491
|
return this.red.imul(this, num);
|
|
2488
2492
|
};
|
|
2489
|
-
|
|
2493
|
+
BN2.prototype.redSqr = function redSqr() {
|
|
2490
2494
|
assert(this.red, "redSqr works only with red numbers");
|
|
2491
2495
|
this.red._verify1(this);
|
|
2492
2496
|
return this.red.sqr(this);
|
|
2493
2497
|
};
|
|
2494
|
-
|
|
2498
|
+
BN2.prototype.redISqr = function redISqr() {
|
|
2495
2499
|
assert(this.red, "redISqr works only with red numbers");
|
|
2496
2500
|
this.red._verify1(this);
|
|
2497
2501
|
return this.red.isqr(this);
|
|
2498
2502
|
};
|
|
2499
|
-
|
|
2503
|
+
BN2.prototype.redSqrt = function redSqrt() {
|
|
2500
2504
|
assert(this.red, "redSqrt works only with red numbers");
|
|
2501
2505
|
this.red._verify1(this);
|
|
2502
2506
|
return this.red.sqrt(this);
|
|
2503
2507
|
};
|
|
2504
|
-
|
|
2508
|
+
BN2.prototype.redInvm = function redInvm() {
|
|
2505
2509
|
assert(this.red, "redInvm works only with red numbers");
|
|
2506
2510
|
this.red._verify1(this);
|
|
2507
2511
|
return this.red.invm(this);
|
|
2508
2512
|
};
|
|
2509
|
-
|
|
2513
|
+
BN2.prototype.redNeg = function redNeg() {
|
|
2510
2514
|
assert(this.red, "redNeg works only with red numbers");
|
|
2511
2515
|
this.red._verify1(this);
|
|
2512
2516
|
return this.red.neg(this);
|
|
2513
2517
|
};
|
|
2514
|
-
|
|
2518
|
+
BN2.prototype.redPow = function redPow(num) {
|
|
2515
2519
|
assert(this.red && !num.red, "redPow(normalNum)");
|
|
2516
2520
|
this.red._verify1(this);
|
|
2517
2521
|
return this.red.pow(this, num);
|
|
@@ -2524,13 +2528,13 @@ var require_bn = __commonJS({
|
|
|
2524
2528
|
};
|
|
2525
2529
|
function MPrime(name, p) {
|
|
2526
2530
|
this.name = name;
|
|
2527
|
-
this.p = new
|
|
2531
|
+
this.p = new BN2(p, 16);
|
|
2528
2532
|
this.n = this.p.bitLength();
|
|
2529
|
-
this.k = new
|
|
2533
|
+
this.k = new BN2(1).iushln(this.n).isub(this.p);
|
|
2530
2534
|
this.tmp = this._tmp();
|
|
2531
2535
|
}
|
|
2532
2536
|
MPrime.prototype._tmp = function _tmp() {
|
|
2533
|
-
var tmp = new
|
|
2537
|
+
var tmp = new BN2(null);
|
|
2534
2538
|
tmp.words = new Array(Math.ceil(this.n / 13));
|
|
2535
2539
|
return tmp;
|
|
2536
2540
|
};
|
|
@@ -2656,7 +2660,7 @@ var require_bn = __commonJS({
|
|
|
2656
2660
|
}
|
|
2657
2661
|
return num;
|
|
2658
2662
|
};
|
|
2659
|
-
|
|
2663
|
+
BN2._prime = function prime(name) {
|
|
2660
2664
|
if (primes[name]) return primes[name];
|
|
2661
2665
|
var prime2;
|
|
2662
2666
|
if (name === "k256") {
|
|
@@ -2675,7 +2679,7 @@ var require_bn = __commonJS({
|
|
|
2675
2679
|
};
|
|
2676
2680
|
function Red(m) {
|
|
2677
2681
|
if (typeof m === "string") {
|
|
2678
|
-
var prime =
|
|
2682
|
+
var prime = BN2._prime(m);
|
|
2679
2683
|
this.m = prime.p;
|
|
2680
2684
|
this.prime = prime;
|
|
2681
2685
|
} else {
|
|
@@ -2761,7 +2765,7 @@ var require_bn = __commonJS({
|
|
|
2761
2765
|
var mod3 = this.m.andln(3);
|
|
2762
2766
|
assert(mod3 % 2 === 1);
|
|
2763
2767
|
if (mod3 === 3) {
|
|
2764
|
-
var pow = this.m.add(new
|
|
2768
|
+
var pow = this.m.add(new BN2(1)).iushrn(2);
|
|
2765
2769
|
return this.pow(a, pow);
|
|
2766
2770
|
}
|
|
2767
2771
|
var q = this.m.subn(1);
|
|
@@ -2771,11 +2775,11 @@ var require_bn = __commonJS({
|
|
|
2771
2775
|
q.iushrn(1);
|
|
2772
2776
|
}
|
|
2773
2777
|
assert(!q.isZero());
|
|
2774
|
-
var one = new
|
|
2778
|
+
var one = new BN2(1).toRed(this);
|
|
2775
2779
|
var nOne = one.redNeg();
|
|
2776
2780
|
var lpow = this.m.subn(1).iushrn(1);
|
|
2777
2781
|
var z = this.m.bitLength();
|
|
2778
|
-
z = new
|
|
2782
|
+
z = new BN2(2 * z * z).toRed(this);
|
|
2779
2783
|
while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
|
2780
2784
|
z.redIAdd(nOne);
|
|
2781
2785
|
}
|
|
@@ -2789,7 +2793,7 @@ var require_bn = __commonJS({
|
|
|
2789
2793
|
tmp = tmp.redSqr();
|
|
2790
2794
|
}
|
|
2791
2795
|
assert(i < m);
|
|
2792
|
-
var b = this.pow(c, new
|
|
2796
|
+
var b = this.pow(c, new BN2(1).iushln(m - i - 1));
|
|
2793
2797
|
r = r.redMul(b);
|
|
2794
2798
|
c = b.redSqr();
|
|
2795
2799
|
t = t.redMul(c);
|
|
@@ -2807,11 +2811,11 @@ var require_bn = __commonJS({
|
|
|
2807
2811
|
}
|
|
2808
2812
|
};
|
|
2809
2813
|
Red.prototype.pow = function pow(a, num) {
|
|
2810
|
-
if (num.isZero()) return new
|
|
2814
|
+
if (num.isZero()) return new BN2(1).toRed(this);
|
|
2811
2815
|
if (num.cmpn(1) === 0) return a.clone();
|
|
2812
2816
|
var windowSize = 4;
|
|
2813
2817
|
var wnd = new Array(1 << windowSize);
|
|
2814
|
-
wnd[0] = new
|
|
2818
|
+
wnd[0] = new BN2(1).toRed(this);
|
|
2815
2819
|
wnd[1] = a;
|
|
2816
2820
|
for (var i = 2; i < wnd.length; i++) {
|
|
2817
2821
|
wnd[i] = this.mul(wnd[i - 1], a);
|
|
@@ -2855,7 +2859,7 @@ var require_bn = __commonJS({
|
|
|
2855
2859
|
res.red = null;
|
|
2856
2860
|
return res;
|
|
2857
2861
|
};
|
|
2858
|
-
|
|
2862
|
+
BN2.mont = function mont(num) {
|
|
2859
2863
|
return new Mont(num);
|
|
2860
2864
|
};
|
|
2861
2865
|
function Mont(m) {
|
|
@@ -2864,7 +2868,7 @@ var require_bn = __commonJS({
|
|
|
2864
2868
|
if (this.shift % 26 !== 0) {
|
|
2865
2869
|
this.shift += 26 - this.shift % 26;
|
|
2866
2870
|
}
|
|
2867
|
-
this.r = new
|
|
2871
|
+
this.r = new BN2(1).iushln(this.shift);
|
|
2868
2872
|
this.r2 = this.imod(this.r.sqr());
|
|
2869
2873
|
this.rinv = this.r._invmp(this.m);
|
|
2870
2874
|
this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
|
@@ -2898,7 +2902,7 @@ var require_bn = __commonJS({
|
|
|
2898
2902
|
return res._forceRed(this);
|
|
2899
2903
|
};
|
|
2900
2904
|
Mont.prototype.mul = function mul(a, b) {
|
|
2901
|
-
if (a.isZero() || b.isZero()) return new
|
|
2905
|
+
if (a.isZero() || b.isZero()) return new BN2(0)._forceRed(this);
|
|
2902
2906
|
var t = a.mul(b);
|
|
2903
2907
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
2904
2908
|
var u = t.isub(c).iushrn(this.shift);
|
|
@@ -3281,10 +3285,19 @@ var GateCriteriaFactory = {
|
|
|
3281
3285
|
}
|
|
3282
3286
|
}),
|
|
3283
3287
|
customProgram: (params) => ({
|
|
3284
|
-
customProgram: {
|
|
3285
|
-
|
|
3286
|
-
instructionData
|
|
3287
|
-
|
|
3288
|
+
customProgram: (() => {
|
|
3289
|
+
const rawHash = params.instructionDataHash ?? params.instructionData ?? Buffer.alloc(32);
|
|
3290
|
+
const instructionData = Buffer.isBuffer(rawHash) ? rawHash : Buffer.from(rawHash);
|
|
3291
|
+
if (instructionData.length !== 32) {
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
"GateCriteriaFactory.customProgram requires a 32-byte instruction hash"
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
return {
|
|
3297
|
+
programId: params.programId,
|
|
3298
|
+
instructionData
|
|
3299
|
+
};
|
|
3300
|
+
})()
|
|
3288
3301
|
})
|
|
3289
3302
|
};
|
|
3290
3303
|
|
|
@@ -3369,12 +3382,21 @@ var GpassClient = class {
|
|
|
3369
3382
|
async initializeGate(params) {
|
|
3370
3383
|
const authority = params.authority ?? this.provider.wallet.publicKey;
|
|
3371
3384
|
const [gatePda] = await findGatePda(params.gateId);
|
|
3372
|
-
|
|
3385
|
+
if (!authority.equals(this.provider.wallet.publicKey) && !params.authoritySigner) {
|
|
3386
|
+
throw new Error(
|
|
3387
|
+
"authoritySigner is required when initializeGate authority is not the provider wallet"
|
|
3388
|
+
);
|
|
3389
|
+
}
|
|
3390
|
+
const method = this.program.methods.initializeGate(params.gateId, params.criteria, params.gateType).accounts({
|
|
3373
3391
|
gate: gatePda,
|
|
3374
3392
|
authority,
|
|
3375
3393
|
payer: this.provider.wallet.publicKey,
|
|
3376
3394
|
systemProgram: SystemProgram.programId
|
|
3377
|
-
})
|
|
3395
|
+
});
|
|
3396
|
+
if (params.authoritySigner) {
|
|
3397
|
+
method.signers([params.authoritySigner]);
|
|
3398
|
+
}
|
|
3399
|
+
const tx = await method.rpc();
|
|
3378
3400
|
return { tx, gate: gatePda };
|
|
3379
3401
|
}
|
|
3380
3402
|
// ─────────────────────────────────────────────────────
|
|
@@ -3396,7 +3418,7 @@ var GpassClient = class {
|
|
|
3396
3418
|
async checkGate(params) {
|
|
3397
3419
|
const [gatePda] = await findGatePda(params.gateId);
|
|
3398
3420
|
const [checkRecordPda] = params.storeRecord ? await findCheckRecordPda(gatePda, params.user) : [null];
|
|
3399
|
-
const
|
|
3421
|
+
const method = this.program.methods.checkGate(params.gateId).accounts({
|
|
3400
3422
|
gate: gatePda,
|
|
3401
3423
|
user: params.user,
|
|
3402
3424
|
reputationAccount: params.reputationAccount ?? null,
|
|
@@ -3406,7 +3428,11 @@ var GpassClient = class {
|
|
|
3406
3428
|
checkRecord: checkRecordPda ?? null,
|
|
3407
3429
|
payer: this.provider.wallet.publicKey,
|
|
3408
3430
|
systemProgram: SystemProgram.programId
|
|
3409
|
-
})
|
|
3431
|
+
});
|
|
3432
|
+
if (params.remainingAccounts?.length) {
|
|
3433
|
+
method.remainingAccounts(params.remainingAccounts);
|
|
3434
|
+
}
|
|
3435
|
+
const tx = await method.rpc();
|
|
3410
3436
|
return tx;
|
|
3411
3437
|
}
|
|
3412
3438
|
/**
|
|
@@ -3418,7 +3444,7 @@ var GpassClient = class {
|
|
|
3418
3444
|
try {
|
|
3419
3445
|
const [gatePda] = await findGatePda(params.gateId);
|
|
3420
3446
|
const [checkRecordPda] = params.storeRecord ? await findCheckRecordPda(gatePda, params.user) : [null];
|
|
3421
|
-
|
|
3447
|
+
const method = this.program.methods.checkGate(params.gateId).accounts({
|
|
3422
3448
|
gate: gatePda,
|
|
3423
3449
|
user: params.user,
|
|
3424
3450
|
reputationAccount: params.reputationAccount ?? null,
|
|
@@ -3428,7 +3454,11 @@ var GpassClient = class {
|
|
|
3428
3454
|
checkRecord: checkRecordPda ?? null,
|
|
3429
3455
|
payer: this.provider.wallet.publicKey,
|
|
3430
3456
|
systemProgram: SystemProgram.programId
|
|
3431
|
-
})
|
|
3457
|
+
});
|
|
3458
|
+
if (params.remainingAccounts?.length) {
|
|
3459
|
+
method.remainingAccounts(params.remainingAccounts);
|
|
3460
|
+
}
|
|
3461
|
+
await method.simulate();
|
|
3432
3462
|
return true;
|
|
3433
3463
|
} catch {
|
|
3434
3464
|
return false;
|
|
@@ -3506,7 +3536,7 @@ var GpassClient = class {
|
|
|
3506
3536
|
async fetchGate(gateId) {
|
|
3507
3537
|
const [gatePda] = await findGatePda(gateId);
|
|
3508
3538
|
try {
|
|
3509
|
-
return await this.program.account.
|
|
3539
|
+
return await this.program.account.gate.fetch(gatePda);
|
|
3510
3540
|
} catch {
|
|
3511
3541
|
return null;
|
|
3512
3542
|
}
|
|
@@ -3518,7 +3548,7 @@ var GpassClient = class {
|
|
|
3518
3548
|
const [gatePda] = await findGatePda(gateId);
|
|
3519
3549
|
const [checkRecordPda] = await findCheckRecordPda(gatePda, user);
|
|
3520
3550
|
try {
|
|
3521
|
-
return await this.program.account.
|
|
3551
|
+
return await this.program.account.gateCheckRecord.fetch(
|
|
3522
3552
|
checkRecordPda
|
|
3523
3553
|
);
|
|
3524
3554
|
} catch {
|
|
@@ -3529,7 +3559,7 @@ var GpassClient = class {
|
|
|
3529
3559
|
* Fetch all gates owned by a specific authority.
|
|
3530
3560
|
*/
|
|
3531
3561
|
async fetchGatesByAuthority(authority) {
|
|
3532
|
-
const accounts = await this.program.account.
|
|
3562
|
+
const accounts = await this.program.account.gate.all([
|
|
3533
3563
|
{
|
|
3534
3564
|
memcmp: {
|
|
3535
3565
|
offset: 8 + 1 + 32,
|
|
@@ -3550,7 +3580,7 @@ var GpassClient = class {
|
|
|
3550
3580
|
async buildCheckGateInstruction(params) {
|
|
3551
3581
|
const [gatePda] = await findGatePda(params.gateId);
|
|
3552
3582
|
const [checkRecordPda] = params.storeRecord ? await findCheckRecordPda(gatePda, params.user) : [null];
|
|
3553
|
-
|
|
3583
|
+
const method = this.program.methods.checkGate(params.gateId).accounts({
|
|
3554
3584
|
gate: gatePda,
|
|
3555
3585
|
user: params.user,
|
|
3556
3586
|
reputationAccount: params.reputationAccount ?? null,
|
|
@@ -3560,7 +3590,11 @@ var GpassClient = class {
|
|
|
3560
3590
|
checkRecord: checkRecordPda ?? null,
|
|
3561
3591
|
payer: this.provider.wallet.publicKey,
|
|
3562
3592
|
systemProgram: SystemProgram.programId
|
|
3563
|
-
})
|
|
3593
|
+
});
|
|
3594
|
+
if (params.remainingAccounts?.length) {
|
|
3595
|
+
method.remainingAccounts(params.remainingAccounts);
|
|
3596
|
+
}
|
|
3597
|
+
return method.instruction();
|
|
3564
3598
|
}
|
|
3565
3599
|
/**
|
|
3566
3600
|
* Build a full transaction that checks a gate and then executes
|