From bde1cc356485e3edb023190829b6b391baca629b Mon Sep 17 00:00:00 2001 From: dpronin Date: Tue, 19 Dec 2017 12:50:59 +0300 Subject: [PATCH] jsbn.ts no style errors --- lib/asn1js/asn1.ts | 2 +- lib/jsbn/jsbn.ts | 1242 ++++++++++++++++++++++++++------------------ tslint.json | 1 + 3 files changed, 748 insertions(+), 497 deletions(-) diff --git a/lib/asn1js/asn1.ts b/lib/asn1js/asn1.ts index 5880579..7a5dfc8 100644 --- a/lib/asn1js/asn1.ts +++ b/lib/asn1js/asn1.ts @@ -41,7 +41,7 @@ export class Stream { } } - private enc:string; + private enc:string|number[]; public pos:number; public get(pos?:number) { diff --git a/lib/jsbn/jsbn.ts b/lib/jsbn/jsbn.ts index 7539d4d..a8c51c3 100644 --- a/lib/jsbn/jsbn.ts +++ b/lib/jsbn/jsbn.ts @@ -5,6 +5,7 @@ // Basic JavaScript BN library - subset useful for RSA encryption. import {cbit, int2char, lbit, op_and, op_andnot, op_or, op_xor} from "./util"; +import {SecureRandom} from "./rng"; // Bits per digit let dbits; @@ -20,14 +21,14 @@ const lplim = (1 << 26) / lowprimes[lowprimes.length - 1]; // (public) Constructor export class BigInteger { - constructor(a, b?, c?) { + constructor(a:number|number[]|string, b?:number|SecureRandom, c?:number|SecureRandom) { if (a != null) { if ("number" == typeof a) { this.fromNumber(a, b, c); } else if (b == null && "string" != typeof a) { this.fromString(a, 256); } else { - this.fromString(a, b); + this.fromString(a, b as number); } } } @@ -99,14 +100,14 @@ export class BigInteger { // BigInteger.prototype.abs = bnAbs; // (public) |this| - protected abs() { + public abs() { return (this.s < 0) ? this.negate() : this; } // BigInteger.prototype.compareTo = bnCompareTo; // (public) return + if this > a, - if this < a, 0 if equal - public compareTo(a) { + public compareTo(a:BigInteger):number { let r = this.s - a.s; if (r != 0) { return r; @@ -255,25 +256,25 @@ export class BigInteger { // BigInteger.prototype.equals = bnEquals; - protected equals(a) { + protected equals(a:BigInteger):boolean { return (this.compareTo(a) == 0); } // BigInteger.prototype.min = bnMin; - protected min(a) { + protected min(a:BigInteger):BigInteger { return (this.compareTo(a) < 0) ? this : a; } // BigInteger.prototype.max = bnMax; - protected max(a) { + protected max(a:BigInteger):BigInteger { return (this.compareTo(a) > 0) ? this : a; } // BigInteger.prototype.and = bnAnd; - protected and(a) { + protected and(a:BigInteger):BigInteger { const r = nbi(); this.bitwiseTo(a, op_and, r); return r; @@ -281,7 +282,7 @@ export class BigInteger { // BigInteger.prototype.or = bnOr; - protected or(a) { + protected or(a:BigInteger):BigInteger { const r = nbi(); this.bitwiseTo(a, op_or, r); return r; @@ -289,7 +290,7 @@ export class BigInteger { // BigInteger.prototype.xor = bnXor; - protected xor(a) { + protected xor(a:BigInteger):BigInteger { const r = nbi(); this.bitwiseTo(a, op_xor, r); return r; @@ -297,7 +298,7 @@ export class BigInteger { // BigInteger.prototype.andNot = bnAndNot; - protected andNot(a) { + protected andNot(a:BigInteger):BigInteger { const r = nbi(); this.bitwiseTo(a, op_andnot, r); return r; @@ -306,7 +307,7 @@ export class BigInteger { // BigInteger.prototype.not = bnNot; // (public) ~this - protected not() { + protected not():BigInteger { const r = nbi(); for (let i = 0; i < this.t; ++i) { r[i] = this.DM & ~this[i]; @@ -383,29 +384,29 @@ export class BigInteger { // BigInteger.prototype.setBit = bnSetBit; // (public) this | (1<= 0) { - u.subTo(v,u); - if(ac) a.subTo(c,a); - b.subTo(d,b); - } - else { - v.subTo(u,v); - if(ac) c.subTo(a,c); - d.subTo(b,d); + if (u.compareTo(v) >= 0) { + u.subTo(v, u); + if (ac) { + a.subTo(c, a); + } + b.subTo(d, b); + } else { + v.subTo(u, v); + if (ac) { c.subTo(a, c); } + d.subTo(b, d); } } - if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO; - if(d.compareTo(m) >= 0) return d.subtract(m); - if(d.signum() < 0) d.addTo(m,d); else return d; - if(d.signum() < 0) return d.add(m); else return d; + if (v.compareTo(BigInteger.ONE) != 0) { + return BigInteger.ZERO; + } + if (d.compareTo(m) >= 0) { + return d.subtract(m); + } + if (d.signum() < 0) { + d.addTo(m, d); + } else { + return d; + } + if (d.signum() < 0) { + return d.add(m); + } else { + return d; + } } // BigInteger.prototype.pow = bnPow; // (public) this^e - protected pow(e) { return this.exp(e,new NullExp()); } + protected pow(e:number) { + return this.exp(e, new NullExp()); + } // BigInteger.prototype.gcd = bnGCD; // (public) gcd(this,a) (HAC 14.54) - public gcd(a) { - var x = (this.s<0)?this.negate():this.clone(); - var y = (a.s<0)?a.negate():a.clone(); - if(x.compareTo(y) < 0) { var t = x; x = y; y = t; } - var i = x.getLowestSetBit(), g = y.getLowestSetBit(); - if(g < 0) { return x; } - if(i < g) { g = i; } - if(g > 0) { - x.rShiftTo(g,x); - y.rShiftTo(g,y); - } - while(x.signum() > 0) { - if((i = x.getLowestSetBit()) > 0) { x.rShiftTo(i,x); } - if((i = y.getLowestSetBit()) > 0) { y.rShiftTo(i,y); } - if(x.compareTo(y) >= 0) { - x.subTo(y,x); - x.rShiftTo(1,x); + public gcd(a:BigInteger) { + let x = (this.s < 0) ? this.negate() : this.clone(); + let y = (a.s < 0) ? a.negate() : a.clone(); + if (x.compareTo(y) < 0) { + const t = x; + x = y; + y = t; + } + let i = x.getLowestSetBit(); + let g = y.getLowestSetBit(); + if (g < 0) { + return x; + } + if (i < g) { + g = i; + } + if (g > 0) { + x.rShiftTo(g, x); + y.rShiftTo(g, y); + } + while (x.signum() > 0) { + if ((i = x.getLowestSetBit()) > 0) { + x.rShiftTo(i, x); + } + if ((i = y.getLowestSetBit()) > 0) { + y.rShiftTo(i, y); + } + if (x.compareTo(y) >= 0) { + x.subTo(y, x); + x.rShiftTo(1, x); } else { - y.subTo(x,y); - y.rShiftTo(1,y); + y.subTo(x, y); + y.rShiftTo(1, y); } } - if(g > 0) { y.lShiftTo(g,y); } + if (g > 0) { + y.lShiftTo(g, y); + } return y; } @@ -663,15 +717,16 @@ export class BigInteger { } - //#endregion PUBLIC //#region PROTECTED // BigInteger.prototype.copyTo = bnpCopyTo; // (protected) copy this to r - protected copyTo(r) { - for(var i = this.t-1; i >= 0; --i) r[i] = this[i]; + public copyTo(r:BigInteger) { + for (let i = this.t - 1; i >= 0; --i) { + r[i] = this[i]; + } r.t = this.t; r.s = this.s; } @@ -679,98 +734,134 @@ export class BigInteger { // BigInteger.prototype.fromInt = bnpFromInt; // (protected) set from integer value x, -DV <= x < DV - public fromInt(x) { + public fromInt(x:number) { this.t = 1; - this.s = (x<0)?-1:0; - if(x > 0) this[0] = x; - else if(x < -1) this[0] = x+this.DV; - else this.t = 0; + this.s = (x < 0) ? -1 : 0; + if (x > 0) { + this[0] = x; + } else if (x < -1) { + this[0] = x + this.DV; + } else { + this.t = 0; + } } // BigInteger.prototype.fromString = bnpFromString; // (protected) set from string and radix - protected fromString(s,b) { - var k; - if(b == 16) k = 4; - else if(b == 8) k = 3; - else if(b == 256) k = 8; // byte array - else if(b == 2) k = 1; - else if(b == 32) k = 5; - else if(b == 4) k = 2; - else { this.fromRadix(s,b); return; } + protected fromString(s:string|number[], b:number) { + let k; + if (b == 16) { + k = 4; + } else if (b == 8) { + k = 3; + } else if (b == 256) { + k = 8; + /* byte array */ + } else if (b == 2) { + k = 1; + } else if (b == 32) { + k = 5; + } else if (b == 4) { + k = 2; + } else { + this.fromRadix(s as string, b); + return; + } this.t = 0; this.s = 0; - var i = s.length, mi = false, sh = 0; - while(--i >= 0) { - var x = (k==8)?s[i]&0xff:intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-") mi = true; + let i = s.length; + let mi = false; + let sh = 0; + while (--i >= 0) { + const x = (k == 8) ? (+s[i]) & 0xff : intAt(s as string, i); + if (x < 0) { + if ((s as string).charAt(i) == "-") { + mi = true; + } continue; } mi = false; - if(sh == 0) + if (sh == 0) { this[this.t++] = x; - else if(sh+k > this.DB) { - this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<>(this.DB-sh)); + } else if (sh + k > this.DB) { + this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh; + this[this.t++] = (x >> (this.DB - sh)); + } else { + this[this.t - 1] |= x << sh; } - else - this[this.t-1] |= x<= this.DB) sh -= this.DB; + if (sh >= this.DB) { + sh -= this.DB; + } } - if(k == 8 && (s[0]&0x80) != 0) { + if (k == 8 && ((+s[0]) & 0x80) != 0) { this.s = -1; - if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)< 0) { + this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh; + } } this.clamp(); - if(mi) BigInteger.ZERO.subTo(this,this); + if (mi) { + BigInteger.ZERO.subTo(this, this); + } } // BigInteger.prototype.clamp = bnpClamp; // (protected) clamp off excess high words - protected clamp() { - var c = this.s&this.DM; - while(this.t > 0 && this[this.t-1] == c) --this.t; + public clamp() { + const c = this.s & this.DM; + while (this.t > 0 && this[this.t - 1] == c) { + --this.t; + } } // BigInteger.prototype.dlShiftTo = bnpDLShiftTo; // (protected) r = this << n*DB - public dlShiftTo(n,r) { - var i; - for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; - for(i = n-1; i >= 0; --i) r[i] = 0; - r.t = this.t+n; + public dlShiftTo(n:number, r:BigInteger) { + let i; + for (i = this.t - 1; i >= 0; --i) { + r[i + n] = this[i]; + } + for (i = n - 1; i >= 0; --i) { + r[i] = 0; + } + r.t = this.t + n; r.s = this.s; } // BigInteger.prototype.drShiftTo = bnpDRShiftTo; // (protected) r = this >> n*DB - protected drShiftTo(n,r) { - for(var i = n; i < this.t; ++i) r[i-n] = this[i]; - r.t = Math.max(this.t-n,0); + public drShiftTo(n:number, r:BigInteger) { + for (let i = n; i < this.t; ++i) { + r[i - n] = this[i]; + } + r.t = Math.max(this.t - n, 0); r.s = this.s; } // BigInteger.prototype.lShiftTo = bnpLShiftTo; // (protected) r = this << n - protected lShiftTo(n,r) { - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<= 0; --i) { - r[i+ds+1] = (this[i]>>cbs)|c; - c = (this[i]&bm)<= 0; --i) r[i] = 0; + protected lShiftTo(n:number, r:BigInteger) { + const bs = n % this.DB; + const cbs = this.DB - bs; + const bm = (1 << cbs) - 1; + const ds = Math.floor(n / this.DB); + let c = (this.s << bs) & this.DM; + + for (let i = this.t - 1; i >= 0; --i) { + r[i + ds + 1] = (this[i] >> cbs) | c; + c = (this[i] & bm) << bs; + } + for (let i = ds - 1; i >= 0; --i) { + r[i] = 0; + } r[ds] = c; - r.t = this.t+ds+1; + r.t = this.t + ds + 1; r.s = this.s; r.clamp(); } @@ -778,54 +869,63 @@ export class BigInteger { // BigInteger.prototype.rShiftTo = bnpRShiftTo; // (protected) r = this >> n - protected rShiftTo(n,r) { + protected rShiftTo(n:number, r:BigInteger) { r.s = this.s; - var ds = Math.floor(n/this.DB); - if(ds >= this.t) { r.t = 0; return; } - var bs = n%this.DB; - var cbs = this.DB-bs; - var bm = (1<>bs; - for(var i = ds+1; i < this.t; ++i) { - r[i-ds-1] |= (this[i]&bm)<>bs; - } - if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<= this.t) { + r.t = 0; + return; + } + const bs = n % this.DB; + const cbs = this.DB - bs; + const bm = (1 << bs) - 1; + r[0] = this[ds] >> bs; + for (let i = ds + 1; i < this.t; ++i) { + r[i - ds - 1] |= (this[i] & bm) << cbs; + r[i - ds] = this[i] >> bs; + } + if (bs > 0) { + r[this.t - ds - 1] |= (this.s & bm) << cbs; + } + r.t = this.t - ds; r.clamp(); } // BigInteger.prototype.subTo = bnpSubTo; // (protected) r = this - a - public subTo(a,r) { - var i = 0, c = 0, m = Math.min(a.t,this.t); - while(i < m) { - c += this[i]-a[i]; - r[i++] = c&this.DM; + public subTo(a:BigInteger, r:BigInteger) { + let i = 0; + let c = 0; + const m = Math.min(a.t, this.t); + while (i < m) { + c += this[i] - a[i]; + r[i++] = c & this.DM; c >>= this.DB; } - if(a.t < this.t) { + if (a.t < this.t) { c -= a.s; - while(i < this.t) { + while (i < this.t) { c += this[i]; - r[i++] = c&this.DM; + r[i++] = c & this.DM; c >>= this.DB; } c += this.s; - } - else { + } else { c += this.s; - while(i < a.t) { + while (i < a.t) { c -= a[i]; - r[i++] = c&this.DM; + r[i++] = c & this.DM; c >>= this.DB; } c -= a.s; } - r.s = (c<0)?-1:0; - if(c < -1) r[i++] = this.DV+c; - else if(c > 0) r[i++] = c; + r.s = (c < 0) ? -1 : 0; + if (c < -1) { + r[i++] = this.DV + c; + } else if (c > 0) { + r[i++] = c; + } r.t = i; r.clamp(); } @@ -834,32 +934,43 @@ export class BigInteger { // BigInteger.prototype.multiplyTo = bnpMultiplyTo; // (protected) r = this * a, r != this,a (HAC 14.12) // "this" should be the larger one if appropriate. - public multiplyTo(a,r) { - var x = this.abs(), y = a.abs(); - var i = x.t; - r.t = i+y.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); + public multiplyTo(a:BigInteger, r:BigInteger) { + const x = this.abs(); + const y = a.abs(); + let i = x.t; + r.t = i + y.t; + while (--i >= 0) { + r[i] = 0; + } + for (i = 0; i < y.t; ++i) { + r[i + x.t] = x.am(0, y[i], r, i, 0, x.t); + } r.s = 0; r.clamp(); - if(this.s != a.s) BigInteger.ZERO.subTo(r,r); + if (this.s != a.s) { + BigInteger.ZERO.subTo(r, r); + } } // BigInteger.prototype.squareTo = bnpSquareTo; // (protected) r = this^2, r != this (HAC 14.16) - public squareTo(r) { - var x = this.abs(); - var i = r.t = 2*x.t; - while(--i >= 0) r[i] = 0; - for(i = 0; i < x.t-1; ++i) { - var c = x.am(i,x[i],r,2*i,0,1); - if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { - r[i+x.t] -= x.DV; - r[i+x.t+1] = 1; + public squareTo(r:BigInteger) { + const x = this.abs(); + let i = r.t = 2 * x.t; + while (--i >= 0) { + r[i] = 0; + } + for (i = 0; i < x.t - 1; ++i) { + const c = x.am(i, x[i], r, 2 * i, 0, 1); + if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { + r[i + x.t] -= x.DV; + r[i + x.t + 1] = 1; } } - if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); + if (r.t > 0) { + r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1); + } r.s = 0; r.clamp(); } @@ -868,51 +979,82 @@ export class BigInteger { // BigInteger.prototype.divRemTo = bnpDivRemTo; // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20) // r != q, this != m. q or r may be null. - public divRemTo(m,q,r) { - var pm = m.abs(); - if(pm.t <= 0) return; - var pt = this.abs(); - if(pt.t < pm.t) { - if(q != null) q.fromInt(0); - if(r != null) this.copyTo(r); + public divRemTo(m:BigInteger, q:BigInteger, r:BigInteger) { + const pm = m.abs(); + if (pm.t <= 0) { + return; + } + const pt = this.abs(); + if (pt.t < pm.t) { + if (q != null) { + q.fromInt(0); + } + if (r != null) { + this.copyTo(r); + } + return; + } + if (r == null) { + r = nbi(); + } + const y = nbi(); + const ts = this.s; + const ms = m.s; + const nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus + if (nsh > 0) { + pm.lShiftTo(nsh, y); + pt.lShiftTo(nsh, r); + } else { + pm.copyTo(y); + pt.copyTo(r); + } + const ys = y.t; + const y0 = y[ys - 1]; + if (y0 == 0) { return; } - if(r == null) r = nbi(); - var y = nbi(), ts = this.s, ms = m.s; - var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus - if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } - else { pm.copyTo(y); pt.copyTo(r); } - var ys = y.t; - var y0 = y[ys-1]; - if(y0 == 0) return; - var yt = y0*(1<1)?y[ys-2]>>this.F2:0); - var d1 = this.FV/yt, d2 = (1<= 0) { + const yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0); + const d1 = this.FV / yt; + const d2 = (1 << this.F1) / yt; + const e = 1 << this.F2; + let i = r.t; + let j = i - ys; + const t = (q == null) ? nbi() : q; + y.dlShiftTo(j, t); + if (r.compareTo(t) >= 0) { r[r.t++] = 1; - r.subTo(t,r); + r.subTo(t, r); + } + BigInteger.ONE.dlShiftTo(ys, t); + t.subTo(y, y); // "negative" y so we can replace sub with am later + while (y.t < ys) { + y[y.t++] = 0; } - BigInteger.ONE.dlShiftTo(ys,t); - t.subTo(y,y); // "negative" y so we can replace sub with am later - while(y.t < ys) y[y.t++] = 0; - while(--j >= 0) { + while (--j >= 0) { // Estimate quotient digit - var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2); - if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out - y.dlShiftTo(j,t); - r.subTo(t,r); - while(r[i] < --qd) r.subTo(t,r); + let qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2); + if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out + y.dlShiftTo(j, t); + r.subTo(t, r); + while (r[i] < --qd) { + r.subTo(t, r); + } } } - if(q != null) { - r.drShiftTo(ys,q); - if(ts != ms) BigInteger.ZERO.subTo(q,q); + if (q != null) { + r.drShiftTo(ys, q); + if (ts != ms) { + BigInteger.ZERO.subTo(q, q); + } } r.t = ys; r.clamp(); - if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder - if(ts < 0) BigInteger.ZERO.subTo(r,r); + if (nsh > 0) { + r.rShiftTo(nsh, r); + } // Denormalize remainder + if (ts < 0) { + BigInteger.ZERO.subTo(r, r); + } } @@ -928,36 +1070,52 @@ export class BigInteger { // should reduce x and y(2-xy) by m^2 at each step to keep size bounded. // JS multiply "overflows" differently from C/C++, so care is needed here. public invDigit():number { - if(this.t < 1) return 0; - var x = this[0]; - if((x&1) == 0) return 0; - var y = x&3; // y == 1/x mod 2^2 - y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4 - y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8 - y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16 + if (this.t < 1) { + return 0; + } + const x = this[0]; + if ((x & 1) == 0) { + return 0; + } + let y = x & 3; // y == 1/x mod 2^2 + y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 + y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 + y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16 // last step - calculate inverse mod DV directly; // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints - y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits + y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits // we really want the negative inverse, and -DV < y < DV - return (y>0)?this.DV-y:-y; + return (y > 0) ? this.DV - y : -y; } // BigInteger.prototype.isEven = bnpIsEven; // (protected) true iff this is even - protected isEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; } + protected isEven() { + return ((this.t > 0) ? (this[0] & 1) : this.s) == 0; + } // BigInteger.prototype.exp = bnpExp; // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79) - protected exp(e,z) { - if(e > 0xffffffff || e < 1) return BigInteger.ONE; - var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; + protected exp(e:number, z:IReduction) { + if (e > 0xffffffff || e < 1) { + return BigInteger.ONE; + } + let r = nbi(); + let r2 = nbi(); + const g = z.convert(this); + let i = nbits(e) - 1; g.copyTo(r); - while(--i >= 0) { - z.sqrTo(r,r2); - if((e&(1< 0) z.mulTo(r2,g,r); - else { var t = r; r = r2; r2 = t; } + while (--i >= 0) { + z.sqrTo(r, r2); + if ((e & (1 << i)) > 0) { + z.mulTo(r2, g, r); + } else { + const t = r; + r = r2; + r2 = t; + } } return z.revert(r); } @@ -965,21 +1123,30 @@ export class BigInteger { // BigInteger.prototype.chunkSize = bnpChunkSize; // (protected) return x s.t. r^x < DV - protected chunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); } + protected chunkSize(r:number) { + return Math.floor(Math.LN2 * this.DB / Math.log(r)); + } // BigInteger.prototype.toRadix = bnpToRadix; // (protected) convert to radix string - protected toRadix(b) { - if(b == null) b = 10; - if(this.signum() == 0 || b < 2 || b > 36) return "0"; - var cs = this.chunkSize(b); - var a = Math.pow(b,cs); - var d = nbv(a), y = nbi(), z = nbi(), r = ""; - this.divRemTo(d,y,z); - while(y.signum() > 0) { - r = (a+z.intValue()).toString(b).substr(1) + r; - y.divRemTo(d,y,z); + protected toRadix(b:number) { + if (b == null) { + b = 10; + } + if (this.signum() == 0 || b < 2 || b > 36) { + return "0"; + } + const cs = this.chunkSize(b); + const a = Math.pow(b, cs); + const d = nbv(a); + const y = nbi(); + const z = nbi(); + let r = ""; + this.divRemTo(d, y, z); + while (y.signum() > 0) { + r = (a + z.intValue()).toString(b).substr(1) + r; + y.divRemTo(d, y, z); } return z.intValue().toString(b) + r; } @@ -987,64 +1154,84 @@ export class BigInteger { // BigInteger.prototype.fromRadix = bnpFromRadix; // (protected) convert from radix string - public fromRadix(s,b) { + public fromRadix(s:string, b:number) { this.fromInt(0); - if(b == null) b = 10; - var cs = this.chunkSize(b); - var d = Math.pow(b,cs), mi = false, j = 0, w = 0; - for(var i = 0; i < s.length; ++i) { - var x = intAt(s,i); - if(x < 0) { - if(s.charAt(i) == "-" && this.signum() == 0) mi = true; + if (b == null) { + b = 10; + } + const cs = this.chunkSize(b); + const d = Math.pow(b, cs); + let mi = false; + let j = 0; + let w = 0; + for (let i = 0; i < s.length; ++i) { + const x = intAt(s, i); + if (x < 0) { + if (s.charAt(i) == "-" && this.signum() == 0) { + mi = true; + } continue; } - w = b*w+x; - if(++j >= cs) { + w = b * w + x; + if (++j >= cs) { this.dMultiply(d); - this.dAddOffset(w,0); + this.dAddOffset(w, 0); j = 0; w = 0; } } - if(j > 0) { - this.dMultiply(Math.pow(b,j)); - this.dAddOffset(w,0); + if (j > 0) { + this.dMultiply(Math.pow(b, j)); + this.dAddOffset(w, 0); + } + if (mi) { + BigInteger.ZERO.subTo(this, this); } - if(mi) BigInteger.ZERO.subTo(this,this); } // BigInteger.prototype.fromNumber = bnpFromNumber; // (protected) alternate constructor - protected fromNumber(a,b,c?) { - if("number" == typeof b) { + protected fromNumber(a:number, b:number|SecureRandom, c?:number|SecureRandom) { + if ("number" == typeof b) { // new BigInteger(int,int,RNG) - if(a < 2) this.fromInt(1); - else { - this.fromNumber(a,c); - if(!this.testBit(a-1)) // force MSB set - this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this); - if(this.isEven()) this.dAddOffset(1,0); // force odd - while(!this.isProbablePrime(b)) { - this.dAddOffset(2,0); - if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this); + if (a < 2) { + this.fromInt(1); + } else { + this.fromNumber(a, c); + if (!this.testBit(a - 1)) { + // force MSB set + this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this); + } + if (this.isEven()) { + this.dAddOffset(1, 0); + } // force odd + while (!this.isProbablePrime(b)) { + this.dAddOffset(2, 0); + if (this.bitLength() > a) { + this.subTo(BigInteger.ONE.shiftLeft(a - 1), this); + } } } - } - else { + } else { // new BigInteger(int,RNG) - var x = new Array(), t = a&7; - x.length = (a>>3)+1; + const x:number[] = []; + const t = a & 7; + x.length = (a >> 3) + 1; b.nextBytes(x); - if(t > 0) x[0] &= ((1< 0) { + x[0] &= ((1 << t) - 1); + } else { + x[0] = 0; + } + this.fromString(x, 256); } } // BigInteger.prototype.bitwiseTo = bnpBitwiseTo; // (protected) r = this op a (bitwise) - protected bitwiseTo(a:BigInteger, op:(a:number, b:number) => number, r) { + protected bitwiseTo(a:BigInteger, op:(a:number, b:number) => number, r:BigInteger) { let i; let f; const m = Math.min(a.t, this.t); @@ -1071,7 +1258,7 @@ export class BigInteger { // BigInteger.prototype.changeBit = bnpChangeBit; // (protected) this op (1< number) { + protected changeBit(n:number, op:(a:number, b:number) => number) { const r = BigInteger.ONE.shiftLeft(n); this.bitwiseTo(r, op, r); return r; @@ -1080,34 +1267,38 @@ export class BigInteger { // BigInteger.prototype.addTo = bnpAddTo; // (protected) r = this + a - protected addTo(a,r) { - var i = 0, c = 0, m = Math.min(a.t,this.t); - while(i < m) { - c += this[i]+a[i]; - r[i++] = c&this.DM; + protected addTo(a:BigInteger, r:BigInteger) { + let i = 0; + let c = 0; + const m = Math.min(a.t, this.t); + while (i < m) { + c += this[i] + a[i]; + r[i++] = c & this.DM; c >>= this.DB; } - if(a.t < this.t) { + if (a.t < this.t) { c += a.s; - while(i < this.t) { + while (i < this.t) { c += this[i]; - r[i++] = c&this.DM; + r[i++] = c & this.DM; c >>= this.DB; } c += this.s; - } - else { + } else { c += this.s; - while(i < a.t) { + while (i < a.t) { c += a[i]; - r[i++] = c&this.DM; + r[i++] = c & this.DM; c >>= this.DB; } c += a.s; } - r.s = (c<0)?-1:0; - if(c > 0) r[i++] = c; - else if(c < -1) r[i++] = this.DV+c; + r.s = (c < 0) ? -1 : 0; + if (c > 0) { + r[i++] = c; + } else if (c < -1) { + r[i++] = this.DV + c; + } r.t = i; r.clamp(); } @@ -1115,8 +1306,8 @@ export class BigInteger { // BigInteger.prototype.dMultiply = bnpDMultiply; // (protected) this *= n, this >= 0, 1 < n < DV - protected dMultiply(n) { - this[this.t] = this.am(0,n-1,this,0,0,this.t); + protected dMultiply(n:number) { + this[this.t] = this.am(0, n - 1, this, 0, 0, this.t); ++this.t; this.clamp(); } @@ -1124,13 +1315,19 @@ export class BigInteger { // BigInteger.prototype.dAddOffset = bnpDAddOffset; // (protected) this += n << w words, this >= 0 - protected dAddOffset(n,w) { - if(n == 0) return; - while(this.t <= w) this[this.t++] = 0; + public dAddOffset(n:number, w:number) { + if (n == 0) { + return; + } + while (this.t <= w) { + this[this.t++] = 0; + } this[w] += n; - while(this[w] >= this.DV) { + while (this[w] >= this.DV) { this[w] -= this.DV; - if(++w >= this.t) this[this.t++] = 0; + if (++w >= this.t) { + this[this.t++] = 0; + } ++this[w]; } } @@ -1139,14 +1336,19 @@ export class BigInteger { // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; // (protected) r = lower n words of "this * a", a.t <= n // "this" should be the larger one if appropriate. - public multiplyLowerTo(a,n,r) { - var i = Math.min(this.t+a.t,n); + public multiplyLowerTo(a:BigInteger, n:number, r:BigInteger) { + let i = Math.min(this.t + a.t, n); r.s = 0; // assumes a,this >= 0 r.t = i; - while(i > 0) r[--i] = 0; - var j; - for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t); - for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i); + while (i > 0) { + r[--i] = 0; + } + for (const j = r.t - this.t; i < j; ++i) { + r[i + this.t] = this.am(0, a[i], r, i, 0, this.t); + } + for (const j = Math.min(a.t, n); i < j; ++i) { + this.am(0, a[i], r, i, 0, n - i); + } r.clamp(); } @@ -1154,59 +1356,83 @@ export class BigInteger { // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; // (protected) r = "this * a" without lower n words, n > 0 // "this" should be the larger one if appropriate. - public multiplyUpperTo(a,n,r) { + public multiplyUpperTo(a:BigInteger, n:number, r:BigInteger) { --n; - var i = r.t = this.t+a.t-n; + let i = r.t = this.t + a.t - n; r.s = 0; // assumes a,this >= 0 - while(--i >= 0) r[i] = 0; - for(i = Math.max(n-this.t,0); i < a.t; ++i) - r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n); + while (--i >= 0) { + r[i] = 0; + } + for (i = Math.max(n - this.t, 0); i < a.t; ++i) { + r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n); + } r.clamp(); - r.drShiftTo(1,r); + r.drShiftTo(1, r); } // BigInteger.prototype.modInt = bnpModInt; // (protected) this % n, n < 2^26 - protected modInt(n) { - if(n <= 0) return 0; - var d = this.DV%n, r = (this.s<0)?n-1:0; - if(this.t > 0) - if(d == 0) r = this[0]%n; - else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n; + protected modInt(n:number) { + if (n <= 0) { + return 0; + } + const d = this.DV % n; + let r = (this.s < 0) ? n - 1 : 0; + if (this.t > 0) { + if (d == 0) { + r = this[0] % n; + } else { + for (let i = this.t - 1; i >= 0; --i) { + r = (d * r + this[i]) % n; + } + } + } return r; } // BigInteger.prototype.millerRabin = bnpMillerRabin; // (protected) true if probably prime (HAC 4.24, Miller-Rabin) - protected millerRabin(t) { - var n1 = this.subtract(BigInteger.ONE); - var k = n1.getLowestSetBit(); - if(k <= 0) return false; - var r = n1.shiftRight(k); - t = (t+1)>>1; - if(t > lowprimes.length) t = lowprimes.length; - var a = nbi(); - for(var i = 0; i < t; ++i) { - //Pick bases at random, instead of starting at 2 - a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]); - var y = a.modPow(r,this); - if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { - var j = 1; - while(j++ < k && y.compareTo(n1) != 0) { - y = y.modPowInt(2,this); - if(y.compareTo(BigInteger.ONE) == 0) return false; + protected millerRabin(t:number) { + const n1 = this.subtract(BigInteger.ONE); + const k = n1.getLowestSetBit(); + if (k <= 0) { + return false; + } + const r = n1.shiftRight(k); + t = (t + 1) >> 1; + if (t > lowprimes.length) { + t = lowprimes.length; + } + const a = nbi(); + for (let i = 0; i < t; ++i) { + // Pick bases at random, instead of starting at 2 + a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]); + let y = a.modPow(r, this); + if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { + let j = 1; + while (j++ < k && y.compareTo(n1) != 0) { + y = y.modPowInt(2, this); + if (y.compareTo(BigInteger.ONE) == 0) { + return false; + } + } + if (y.compareTo(n1) != 0) { + return false; } - if(y.compareTo(n1) != 0) return false; } } return true; } - //BigInteger.prototype.square = bnSquare; + // BigInteger.prototype.square = bnSquare; // (public) this^2 - protected square() { var r = nbi(); this.squareTo(r); return r; } + protected square() { + const r = nbi(); + this.squareTo(r); + return r; + } //#endregion PROTECTED @@ -1225,7 +1451,7 @@ export class BigInteger { public F1:number; public F2:number; - public am:(i,x,w,j,c,n) => number; + public am:(i:number, x:number, w:BigInteger, j:number, c:number, n:number) => number; [index:number]:number; @@ -1243,20 +1469,29 @@ class NullExp { constructor() { } + // NullExp.prototype.convert = nNop; - public convert(x:BigInteger) { return x; } + public convert(x:BigInteger) { + return x; + } // NullExp.prototype.revert = nNop; - public revert(x:BigInteger) { return x; } + public revert(x:BigInteger) { + return x; + } // NullExp.prototype.mulTo = nMulTo; - public mulTo(x:BigInteger,y:BigInteger,r:BigInteger) { x.multiplyTo(y,r); } + public mulTo(x:BigInteger, y:BigInteger, r:BigInteger) { + x.multiplyTo(y, r); + } // NullExp.prototype.sqrTo = nSqrTo; - public nSqrTo(x:BigInteger,r:BigInteger) { x.squareTo(r); } + public sqrTo(x:BigInteger, r:BigInteger) { + x.squareTo(r); + } } //#endregion NullExp @@ -1268,7 +1503,7 @@ interface IReduction { revert(x:BigInteger):BigInteger; - reduce(x:BigInteger):void; + // reduce?(x:BigInteger):void; mulTo(x:BigInteger, y:BigInteger, r:BigInteger):void; @@ -1282,8 +1517,11 @@ export class Classic implements IReduction { // Classic.prototype.convert = cConvert; public convert(x:BigInteger) { - if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); - else return x; + if (x.s < 0 || x.compareTo(this.m) >= 0) { + return x.mod(this.m); + } else { + return x; + } } @@ -1335,18 +1573,20 @@ export class Montgomery implements IReduction { // Montgomery.prototype.convert = montConvert; // xR mod m - public convert(x) { - var r = nbi(); - x.abs().dlShiftTo(this.m.t,r); - r.divRemTo(this.m,null,r); - if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); + public convert(x:BigInteger) { + const r = nbi(); + x.abs().dlShiftTo(this.m.t, r); + r.divRemTo(this.m, null, r); + if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) { + this.m.subTo(r, r); + } return r; } // Montgomery.prototype.revert = montRevert; // x/R mod m - public revert(x) { - var r = nbi(); + public revert(x:BigInteger) { + const r = nbi(); x.copyTo(r); this.reduce(r); return r; @@ -1354,33 +1594,46 @@ export class Montgomery implements IReduction { // Montgomery.prototype.reduce = montReduce; // x = x/R mod m (HAC 14.32) - public reduce(x) { - while(x.t <= this.mt2) // pad x so am has enough room later + public reduce(x:BigInteger) { + while (x.t <= this.mt2) { + // pad x so am has enough room later x[x.t++] = 0; - for(var i = 0; i < this.m.t; ++i) { + } + for (let i = 0; i < this.m.t; ++i) { // faster way of calculating u0 = x[i]*mp mod DV - var j = x[i]&0x7fff; - var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM; + let j = x[i] & 0x7fff; + const u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM; // use am to combine the multiply-shift-add into one call - j = i+this.m.t; - x[j] += this.m.am(0,u0,x,i,0,this.m.t); + j = i + this.m.t; + x[j] += this.m.am(0, u0, x, i, 0, this.m.t); // propagate carry - while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } + while (x[j] >= x.DV) { + x[j] -= x.DV; + x[++j]++; + } } x.clamp(); - x.drShiftTo(this.m.t,x); - if(x.compareTo(this.m) >= 0) x.subTo(this.m,x); + x.drShiftTo(this.m.t, x); + if (x.compareTo(this.m) >= 0) { + x.subTo(this.m, x); + } } // Montgomery.prototype.mulTo = montMulTo; // r = "xy/R mod m"; x,y != r - public mulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } + public mulTo(x:BigInteger, y:BigInteger, r:BigInteger) { + x.multiplyTo(y, r); + this.reduce(r); + } // Montgomery.prototype.sqrTo = montSqrTo; // r = "x^2/R mod m"; x != r - public sqrTo(x,r) { x.squareTo(r); this.reduce(r); } + public sqrTo(x:BigInteger, r:BigInteger) { + x.squareTo(r); + this.reduce(r); + } } @@ -1404,36 +1657,58 @@ class Barrett implements IReduction { protected mu:BigInteger; // Barrett.prototype.convert = barrettConvert; - public convert(x) { - if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m); - else if(x.compareTo(this.m) < 0) return x; - else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; } + public convert(x:BigInteger) { + if (x.s < 0 || x.t > 2 * this.m.t) { + return x.mod(this.m); + } else if (x.compareTo(this.m) < 0) { + return x; + } else { + const r = nbi(); + x.copyTo(r); + this.reduce(r); + return r; + } } // Barrett.prototype.revert = barrettRevert; - public revert(x) { return x; } + public revert(x:BigInteger) { + return x; + } // Barrett.prototype.reduce = barrettReduce; // x = x mod m (HAC 14.42) - public reduce(x) { - x.drShiftTo(this.m.t-1,this.r2); - if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); } - this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3); - this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2); - while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1); - x.subTo(this.r2,x); - while(x.compareTo(this.m) >= 0) x.subTo(this.m,x); + public reduce(x:BigInteger) { + x.drShiftTo(this.m.t - 1, this.r2); + if (x.t > this.m.t + 1) { + x.t = this.m.t + 1; + x.clamp(); + } + this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3); + this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); + while (x.compareTo(this.r2) < 0) { + x.dAddOffset(1, this.m.t + 1); + } + x.subTo(this.r2, x); + while (x.compareTo(this.m) >= 0) { + x.subTo(this.m, x); + } } // Barrett.prototype.mulTo = barrettMulTo; // r = x*y mod m; x,y != r - public mulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); } + public mulTo(x:BigInteger, y:BigInteger, r:BigInteger) { + x.multiplyTo(y, r); + this.reduce(r); + } // Barrett.prototype.sqrTo = barrettSqrTo; // r = x^2 mod m; x != r - public sqrTo(x,r) { x.squareTo(r); this.reduce(r); } + public sqrTo(x:BigInteger, r:BigInteger) { + x.squareTo(r); + this.reduce(r); + } } //#endregion @@ -1444,7 +1719,7 @@ class Barrett implements IReduction { export function nbi() { return new BigInteger(null); } export function parseBigInt(str:string, r:number) { - return new BigInteger(str,r); + return new BigInteger(str, r); } // am: Compute w_j += (x*this_i), propagate carries, @@ -1455,149 +1730,124 @@ export function parseBigInt(str:string, r:number) { // am1: use a single mult and divide to get the high bits, // max digit bits should be 26 because // max internal value = 2*dvalue^2-2*dvalue (< 2^53) -function am1(i,x,w,j,c,n) { - while(--n >= 0) { - var v = x*this[i++]+w[j]+c; - c = Math.floor(v/0x4000000); - w[j++] = v&0x3ffffff; - } - return c; +function am1(i:number, x:number, w:BigInteger, j:number, c:number, n:number) { + while (--n >= 0) { + const v = x * this[i++] + w[j] + c; + c = Math.floor(v / 0x4000000); + w[j++] = v & 0x3ffffff; + } + return c; } // am2 avoids a big mult-and-extract completely. // Max digit bits should be <= 30 because we do bitwise ops // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31) -function am2(i,x,w,j,c,n) { - var xl = x&0x7fff, xh = x>>15; - while(--n >= 0) { - var l = this[i]&0x7fff; - var h = this[i++]>>15; - var m = xh*l+h*xl; - l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff); - c = (l>>>30)+(m>>>15)+xh*h+(c>>>30); - w[j++] = l&0x3fffffff; - } - return c; +function am2(i:number, x:number, w:BigInteger, j:number, c:number, n:number) { + const xl = x & 0x7fff; + const xh = x >> 15; + while (--n >= 0) { + let l = this[i] & 0x7fff; + const h = this[i++] >> 15; + const m = xh * l + h * xl; + l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff); + c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30); + w[j++] = l & 0x3fffffff; + } + return c; } // Alternately, set max digit bits to 28 since some // browsers slow down when dealing with 32-bit numbers. -function am3(i,x,w,j,c,n) { - var xl = x&0x3fff, xh = x>>14; - while(--n >= 0) { - var l = this[i]&0x3fff; - var h = this[i++]>>14; - var m = xh*l+h*xl; - l = xl*l+((m&0x3fff)<<14)+w[j]+c; - c = (l>>28)+(m>>14)+xh*h; - w[j++] = l&0xfffffff; - } - return c; -} -if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { - BigInteger.prototype.am = am2; - dbits = 30; -} -else if(j_lm && (navigator.appName != "Netscape")) { - BigInteger.prototype.am = am1; - dbits = 26; +function am3(i:number, x:number, w:BigInteger, j:number, c:number, n:number) { + const xl = x & 0x3fff; + const xh = x >> 14; + while (--n >= 0) { + let l = this[i] & 0x3fff; + const h = this[i++] >> 14; + const m = xh * l + h * xl; + l = xl * l + ((m & 0x3fff) << 14) + w[j] + c; + c = (l >> 28) + (m >> 14) + xh * h; + w[j++] = l & 0xfffffff; + } + return c; } -else { // Mozilla/Netscape seems to prefer am3 - BigInteger.prototype.am = am3; - dbits = 28; + +if (j_lm && (navigator.appName == "Microsoft Internet Explorer")) { + BigInteger.prototype.am = am2; + dbits = 30; +} else if (j_lm && (navigator.appName != "Netscape")) { + BigInteger.prototype.am = am1; + dbits = 26; +} else { // Mozilla/Netscape seems to prefer am3 + BigInteger.prototype.am = am3; + dbits = 28; } BigInteger.prototype.DB = dbits; -BigInteger.prototype.DM = ((1<>>16) != 0) { x = t; r += 16; } - if((t=x>>8) != 0) { x = t; r += 8; } - if((t=x>>4) != 0) { x = t; r += 4; } - if((t=x>>2) != 0) { x = t; r += 2; } - if((t=x>>1) != 0) { x = t; r += 1; } - return r; +export function nbits(x:number) { + let r = 1; + let t; + if ((t = x >>> 16) != 0) { + x = t; + r += 16; + } + if ((t = x >> 8) != 0) { + x = t; + r += 8; + } + if ((t = x >> 4) != 0) { + x = t; + r += 4; + } + if ((t = x >> 2) != 0) { + x = t; + r += 2; + } + if ((t = x >> 1) != 0) { + x = t; + r += 1; + } + return r; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// protected - - -// public - - // "constants" BigInteger.ZERO = nbv(0); BigInteger.ONE = nbv(1); diff --git a/tslint.json b/tslint.json index a843357..23080fa 100644 --- a/tslint.json +++ b/tslint.json @@ -10,6 +10,7 @@ "triple-equals": false, "no-empty": false, "no-console": false, + "no-conditional-assignment": false, "typedef-whitespace": { "options": [ {