ccxt-look 1.81.50
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/.cache/eslintcache +1 -0
- package/.dockerignore +6 -0
- package/.eslintignore +1 -0
- package/.gitattributes +5 -0
- package/.readthedocs.yaml +16 -0
- package/CONTRIBUTING.md +1049 -0
- package/LICENSE.txt +21 -0
- package/README.md +537 -0
- package/SECURITY.md +5 -0
- package/build/cleanup-old-tags.js +94 -0
- package/build/countries.js +256 -0
- package/build/export-exchanges.js +520 -0
- package/build/fs.js +51 -0
- package/build/transpile.js +1772 -0
- package/build/vss.js +78 -0
- package/ccxt.browser.js +7 -0
- package/ccxt.d.ts +692 -0
- package/ccxt.js +171 -0
- package/cleanup.sh +2 -0
- package/composer-install.sh +20 -0
- package/dist/ccxt.browser.js +208383 -0
- package/gource.sh +3 -0
- package/index.html +7 -0
- package/js/.eslintrc +87 -0
- package/js/aax.js +2686 -0
- package/js/ascendex.js +2584 -0
- package/js/base/.eslintrc.js +43 -0
- package/js/base/Exchange.js +2371 -0
- package/js/base/Precise.js +283 -0
- package/js/base/errorHierarchy.js +47 -0
- package/js/base/errors.js +55 -0
- package/js/base/functions/crypto.js +158 -0
- package/js/base/functions/encode.js +118 -0
- package/js/base/functions/generic.js +270 -0
- package/js/base/functions/misc.js +138 -0
- package/js/base/functions/number.js +329 -0
- package/js/base/functions/platform.js +38 -0
- package/js/base/functions/string.js +21 -0
- package/js/base/functions/throttle.js +79 -0
- package/js/base/functions/time.js +210 -0
- package/js/base/functions/type.js +66 -0
- package/js/base/functions.js +28 -0
- package/js/bequant.js +32 -0
- package/js/bibox.js +1407 -0
- package/js/bigone.js +1366 -0
- package/js/binance.js +5652 -0
- package/js/binancecoinm.js +46 -0
- package/js/binanceus.js +46 -0
- package/js/binanceusdm.js +49 -0
- package/js/bit2c.js +535 -0
- package/js/bitbank.js +842 -0
- package/js/bitbay.js +16 -0
- package/js/bitbns.js +1073 -0
- package/js/bitcoincom.js +15 -0
- package/js/bitfinex.js +1433 -0
- package/js/bitfinex2.js +2025 -0
- package/js/bitflyer.js +840 -0
- package/js/bitforex.js +614 -0
- package/js/bitget.js +2397 -0
- package/js/bithumb.js +980 -0
- package/js/bitmart.js +2516 -0
- package/js/bitmex.js +1809 -0
- package/js/bitopro.js +1443 -0
- package/js/bitpanda.js +1782 -0
- package/js/bitrue.js +1747 -0
- package/js/bitso.js +1062 -0
- package/js/bitstamp.js +1757 -0
- package/js/bitstamp1.js +343 -0
- package/js/bittrex.js +1876 -0
- package/js/bitvavo.js +1579 -0
- package/js/bkex.js +1233 -0
- package/js/bl3p.js +346 -0
- package/js/blockchaincom.js +969 -0
- package/js/btcalpha.js +680 -0
- package/js/btcbox.js +477 -0
- package/js/btcmarkets.js +1022 -0
- package/js/btctradeua.js +466 -0
- package/js/btcturk.js +734 -0
- package/js/buda.js +946 -0
- package/js/bw.js +1265 -0
- package/js/bybit.js +3372 -0
- package/js/bytetrade.js +1336 -0
- package/js/cdax.js +1646 -0
- package/js/cex.js +1410 -0
- package/js/coinbase.js +1342 -0
- package/js/coinbaseprime.js +31 -0
- package/js/coinbasepro.js +1466 -0
- package/js/coincheck.js +755 -0
- package/js/coinex.js +3400 -0
- package/js/coinfalcon.js +880 -0
- package/js/coinmate.js +794 -0
- package/js/coinone.js +816 -0
- package/js/coinspot.js +345 -0
- package/js/crex24.js +1636 -0
- package/js/cryptocom.js +1832 -0
- package/js/currencycom.js +1748 -0
- package/js/delta.js +1547 -0
- package/js/deribit.js +2148 -0
- package/js/digifinex.js +1585 -0
- package/js/eqonex.js +1660 -0
- package/js/exmo.js +1670 -0
- package/js/fairdesk.js +1231 -0
- package/js/flowbtc.js +35 -0
- package/js/fmfwio.js +34 -0
- package/js/ftx.js +2751 -0
- package/js/ftxus.js +38 -0
- package/js/gateio.js +4174 -0
- package/js/gemini.js +1397 -0
- package/js/hitbtc.js +1343 -0
- package/js/hitbtc3.js +2329 -0
- package/js/hollaex.js +1486 -0
- package/js/huobi.js +5706 -0
- package/js/huobijp.js +1710 -0
- package/js/huobipro.js +18 -0
- package/js/idex.js +1439 -0
- package/js/independentreserve.js +649 -0
- package/js/indodax.js +742 -0
- package/js/itbit.js +722 -0
- package/js/kraken.js +2179 -0
- package/js/kucoin.js +2571 -0
- package/js/kucoinfutures.js +1771 -0
- package/js/kuna.js +809 -0
- package/js/latoken.js +1445 -0
- package/js/lbank.js +760 -0
- package/js/liquid.js +1432 -0
- package/js/luno.js +873 -0
- package/js/lykke.js +1147 -0
- package/js/mercado.js +771 -0
- package/js/mexc.js +3151 -0
- package/js/ndax.js +2233 -0
- package/js/novadax.js +1318 -0
- package/js/oceanex.js +816 -0
- package/js/okcoin.js +3841 -0
- package/js/okex.js +16 -0
- package/js/okex5.js +16 -0
- package/js/okx.js +4795 -0
- package/js/paymium.js +498 -0
- package/js/phemex.js +2957 -0
- package/js/poloniex.js +1674 -0
- package/js/probit.js +1346 -0
- package/js/qtrade.js +1588 -0
- package/js/ripio.js +1061 -0
- package/js/static_dependencies/BN/bn.js +3526 -0
- package/js/static_dependencies/README.md +1 -0
- package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
- package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
- package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
- package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
- package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
- package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
- package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
- package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
- package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
- package/js/static_dependencies/node-fetch/index.js +1564 -0
- package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
- package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
- package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
- package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
- package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
- package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
- package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
- package/js/static_dependencies/node-rsa/formats/components.js +71 -0
- package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
- package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
- package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
- package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
- package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
- package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
- package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
- package/js/static_dependencies/node-rsa/utils.js +98 -0
- package/js/static_dependencies/qs/formats.js +18 -0
- package/js/static_dependencies/qs/index.js +11 -0
- package/js/static_dependencies/qs/parse.js +242 -0
- package/js/static_dependencies/qs/stringify.js +269 -0
- package/js/static_dependencies/qs/utils.js +230 -0
- package/js/stex.js +1925 -0
- package/js/test/.eslintrc.js +42 -0
- package/js/test/Exchange/test.balance.js +61 -0
- package/js/test/Exchange/test.borrowRate.js +32 -0
- package/js/test/Exchange/test.currency.js +52 -0
- package/js/test/Exchange/test.fetchBalance.js +23 -0
- package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
- package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
- package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
- package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
- package/js/test/Exchange/test.fetchCurrencies.js +35 -0
- package/js/test/Exchange/test.fetchDeposits.js +31 -0
- package/js/test/Exchange/test.fetchFundingFees.js +19 -0
- package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
- package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
- package/js/test/Exchange/test.fetchLedger.js +42 -0
- package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
- package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
- package/js/test/Exchange/test.fetchMarkets.js +33 -0
- package/js/test/Exchange/test.fetchMyTrades.js +42 -0
- package/js/test/Exchange/test.fetchOHLCV.js +46 -0
- package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
- package/js/test/Exchange/test.fetchOrderBook.js +25 -0
- package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
- package/js/test/Exchange/test.fetchOrders.js +41 -0
- package/js/test/Exchange/test.fetchPositions.js +47 -0
- package/js/test/Exchange/test.fetchStatus.js +35 -0
- package/js/test/Exchange/test.fetchTicker.js +38 -0
- package/js/test/Exchange/test.fetchTickers.js +49 -0
- package/js/test/Exchange/test.fetchTrades.js +39 -0
- package/js/test/Exchange/test.fetchTradingFee.js +18 -0
- package/js/test/Exchange/test.fetchTradingFees.js +22 -0
- package/js/test/Exchange/test.fetchTransactions.js +31 -0
- package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
- package/js/test/Exchange/test.ledgerItem.js +46 -0
- package/js/test/Exchange/test.leverageTier.js +33 -0
- package/js/test/Exchange/test.loadMarkets.js +35 -0
- package/js/test/Exchange/test.market.js +129 -0
- package/js/test/Exchange/test.ohlcv.js +33 -0
- package/js/test/Exchange/test.order.js +62 -0
- package/js/test/Exchange/test.orderbook.js +61 -0
- package/js/test/Exchange/test.position.js +21 -0
- package/js/test/Exchange/test.throttle.js +94 -0
- package/js/test/Exchange/test.ticker.js +95 -0
- package/js/test/Exchange/test.trade.js +68 -0
- package/js/test/Exchange/test.tradingFee.js +34 -0
- package/js/test/Exchange/test.transaction.js +35 -0
- package/js/test/base/.eslintrc +38 -0
- package/js/test/base/functions/test.crypto.js +110 -0
- package/js/test/base/functions/test.datetime.js +62 -0
- package/js/test/base/functions/test.generic.js +152 -0
- package/js/test/base/functions/test.number.js +362 -0
- package/js/test/base/functions/test.time.js +56 -0
- package/js/test/base/functions/test.type.js +53 -0
- package/js/test/base/test.base.js +193 -0
- package/js/test/errors/test.InsufficientFunds.js +86 -0
- package/js/test/errors/test.InvalidNonce.js +64 -0
- package/js/test/errors/test.InvalidOrder.js +35 -0
- package/js/test/errors/test.OrderNotFound.js +39 -0
- package/js/test/test.js +426 -0
- package/js/test/test.timeout_hang.js +12 -0
- package/js/therock.js +1431 -0
- package/js/tidebit.js +632 -0
- package/js/tidex.js +939 -0
- package/js/timex.js +1283 -0
- package/js/upbit.js +1622 -0
- package/js/vcc.js +1353 -0
- package/js/wavesexchange.js +2185 -0
- package/js/wazirx.js +732 -0
- package/js/whitebit.js +1352 -0
- package/js/woo.js +1577 -0
- package/js/xena.js +1948 -0
- package/js/yobit.js +1129 -0
- package/js/zaif.js +647 -0
- package/js/zb.js +4088 -0
- package/js/zipmex.js +40 -0
- package/js/zonda.js +1497 -0
- package/multilang.sh +159 -0
- package/package.json +591 -0
- package/postinstall.js +103 -0
@@ -0,0 +1,1252 @@
|
|
1
|
+
/*
|
2
|
+
* Basic JavaScript BN library - subset useful for RSA encryption.
|
3
|
+
*
|
4
|
+
* Copyright (c) 2003-2005 Tom Wu
|
5
|
+
* ~BSD license~
|
6
|
+
*
|
7
|
+
* Added Node.js Buffers support
|
8
|
+
* 2014 rzcoder
|
9
|
+
*
|
10
|
+
* Deleted some stuff to save bytes
|
11
|
+
* frosty00
|
12
|
+
*/
|
13
|
+
|
14
|
+
var _ = require('../utils')._;
|
15
|
+
|
16
|
+
// Bits per digit
|
17
|
+
var dbits;
|
18
|
+
|
19
|
+
// (public) Constructor
|
20
|
+
function BigInteger(a, b) {
|
21
|
+
if (a != null) {
|
22
|
+
if ("number" == typeof a) {
|
23
|
+
this.fromNumber(a, b);
|
24
|
+
} else if (Buffer.isBuffer(a)) {
|
25
|
+
this.fromBuffer(a);
|
26
|
+
} else if (b == null && "string" != typeof a) {
|
27
|
+
this.fromByteArray(a);
|
28
|
+
} else {
|
29
|
+
this.fromString(a, b);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
// return new, unset BigInteger
|
35
|
+
function nbi() {
|
36
|
+
return new BigInteger(null);
|
37
|
+
}
|
38
|
+
|
39
|
+
// am: Compute w_j += (x*this_i), propagate carries,
|
40
|
+
// c is initial carry, returns final carry.
|
41
|
+
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
42
|
+
// We need to select the fastest one that works in this environment.
|
43
|
+
|
44
|
+
// Alternately, set max digit bits to 28 since some
|
45
|
+
// browsers slow down when dealing with 32-bit numbers.
|
46
|
+
function am3(i, x, w, j, c, n) {
|
47
|
+
var xl = x & 0x3fff, xh = x >> 14;
|
48
|
+
while (--n >= 0) {
|
49
|
+
var l = this[i] & 0x3fff;
|
50
|
+
var h = this[i++] >> 14;
|
51
|
+
var m = xh * l + h * xl;
|
52
|
+
l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
|
53
|
+
c = (l >> 28) + (m >> 14) + xh * h;
|
54
|
+
w[j++] = l & 0xfffffff;
|
55
|
+
}
|
56
|
+
return c;
|
57
|
+
}
|
58
|
+
|
59
|
+
// We need to select the fastest one that works in this environment.
|
60
|
+
//if (j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
61
|
+
// BigInteger.prototype.am = am2;
|
62
|
+
// dbits = 30;
|
63
|
+
//} else if (j_lm && (navigator.appName != "Netscape")) {
|
64
|
+
// BigInteger.prototype.am = am1;
|
65
|
+
// dbits = 26;
|
66
|
+
//} else { // Mozilla/Netscape seems to prefer am3
|
67
|
+
// BigInteger.prototype.am = am3;
|
68
|
+
// dbits = 28;
|
69
|
+
//}
|
70
|
+
|
71
|
+
// For node.js, we pick am3 with max dbits to 28.
|
72
|
+
BigInteger.prototype.am = am3;
|
73
|
+
dbits = 28;
|
74
|
+
|
75
|
+
BigInteger.prototype.DB = dbits;
|
76
|
+
BigInteger.prototype.DM = ((1 << dbits) - 1);
|
77
|
+
BigInteger.prototype.DV = (1 << dbits);
|
78
|
+
|
79
|
+
var BI_FP = 52;
|
80
|
+
BigInteger.prototype.FV = Math.pow(2, BI_FP);
|
81
|
+
BigInteger.prototype.F1 = BI_FP - dbits;
|
82
|
+
BigInteger.prototype.F2 = 2 * dbits - BI_FP;
|
83
|
+
|
84
|
+
// Digit conversions
|
85
|
+
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
86
|
+
var BI_RC = new Array();
|
87
|
+
var rr, vv;
|
88
|
+
rr = "0".charCodeAt(0);
|
89
|
+
for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
90
|
+
rr = "a".charCodeAt(0);
|
91
|
+
for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
92
|
+
rr = "A".charCodeAt(0);
|
93
|
+
for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
94
|
+
|
95
|
+
function int2char(n) {
|
96
|
+
return BI_RM.charAt(n);
|
97
|
+
}
|
98
|
+
function intAt(s, i) {
|
99
|
+
var c = BI_RC[s.charCodeAt(i)];
|
100
|
+
return (c == null) ? -1 : c;
|
101
|
+
}
|
102
|
+
|
103
|
+
// (protected) copy this to r
|
104
|
+
function bnpCopyTo(r) {
|
105
|
+
for (var i = this.t - 1; i >= 0; --i) r[i] = this[i];
|
106
|
+
r.t = this.t;
|
107
|
+
r.s = this.s;
|
108
|
+
}
|
109
|
+
|
110
|
+
// (protected) set from integer value x, -DV <= x < DV
|
111
|
+
function bnpFromInt(x) {
|
112
|
+
this.t = 1;
|
113
|
+
this.s = (x < 0) ? -1 : 0;
|
114
|
+
if (x > 0) this[0] = x;
|
115
|
+
else if (x < -1) this[0] = x + DV;
|
116
|
+
else this.t = 0;
|
117
|
+
}
|
118
|
+
|
119
|
+
// return bigint initialized to value
|
120
|
+
function nbv(i) {
|
121
|
+
var r = nbi();
|
122
|
+
r.fromInt(i);
|
123
|
+
return r;
|
124
|
+
}
|
125
|
+
|
126
|
+
// (protected) set from string and radix
|
127
|
+
function bnpFromString(data, radix, unsigned) {
|
128
|
+
var k;
|
129
|
+
switch (radix) {
|
130
|
+
case 2:
|
131
|
+
k = 1;
|
132
|
+
break;
|
133
|
+
case 4:
|
134
|
+
k = 2;
|
135
|
+
break;
|
136
|
+
case 8:
|
137
|
+
k = 3;
|
138
|
+
break;
|
139
|
+
case 16:
|
140
|
+
k = 4;
|
141
|
+
break;
|
142
|
+
case 32:
|
143
|
+
k = 5;
|
144
|
+
break;
|
145
|
+
case 256:
|
146
|
+
k = 8;
|
147
|
+
break;
|
148
|
+
default:
|
149
|
+
this.fromRadix(data, radix);
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
|
153
|
+
this.t = 0;
|
154
|
+
this.s = 0;
|
155
|
+
|
156
|
+
var i = data.length;
|
157
|
+
var mi = false;
|
158
|
+
var sh = 0;
|
159
|
+
|
160
|
+
while (--i >= 0) {
|
161
|
+
var x = (k == 8) ? data[i] & 0xff : intAt(data, i);
|
162
|
+
if (x < 0) {
|
163
|
+
if (data.charAt(i) == "-") mi = true;
|
164
|
+
continue;
|
165
|
+
}
|
166
|
+
mi = false;
|
167
|
+
if (sh === 0)
|
168
|
+
this[this.t++] = x;
|
169
|
+
else if (sh + k > this.DB) {
|
170
|
+
this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
|
171
|
+
this[this.t++] = (x >> (this.DB - sh));
|
172
|
+
}
|
173
|
+
else
|
174
|
+
this[this.t - 1] |= x << sh;
|
175
|
+
sh += k;
|
176
|
+
if (sh >= this.DB) sh -= this.DB;
|
177
|
+
}
|
178
|
+
if ((!unsigned) && k == 8 && (data[0] & 0x80) != 0) {
|
179
|
+
this.s = -1;
|
180
|
+
if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
|
181
|
+
}
|
182
|
+
this.clamp();
|
183
|
+
if (mi) BigInteger.ZERO.subTo(this, this);
|
184
|
+
}
|
185
|
+
|
186
|
+
function bnpFromByteArray(a, unsigned) {
|
187
|
+
this.fromString(a, 256, unsigned)
|
188
|
+
}
|
189
|
+
|
190
|
+
function bnpFromBuffer(a) {
|
191
|
+
this.fromString(a, 256, true)
|
192
|
+
}
|
193
|
+
|
194
|
+
// (protected) clamp off excess high words
|
195
|
+
function bnpClamp() {
|
196
|
+
var c = this.s & this.DM;
|
197
|
+
while (this.t > 0 && this[this.t - 1] == c) --this.t;
|
198
|
+
}
|
199
|
+
|
200
|
+
// (public) return string representation in given radix
|
201
|
+
function bnToString(b) {
|
202
|
+
if (this.s < 0) return "-" + this.negate().toString(b);
|
203
|
+
var k;
|
204
|
+
if (b == 16) k = 4;
|
205
|
+
else if (b == 8) k = 3;
|
206
|
+
else if (b == 2) k = 1;
|
207
|
+
else if (b == 32) k = 5;
|
208
|
+
else if (b == 4) k = 2;
|
209
|
+
else return this.toRadix(b);
|
210
|
+
var km = (1 << k) - 1, d, m = false, r = "", i = this.t;
|
211
|
+
var p = this.DB - (i * this.DB) % k;
|
212
|
+
if (i-- > 0) {
|
213
|
+
if (p < this.DB && (d = this[i] >> p) > 0) {
|
214
|
+
m = true;
|
215
|
+
r = int2char(d);
|
216
|
+
}
|
217
|
+
while (i >= 0) {
|
218
|
+
if (p < k) {
|
219
|
+
d = (this[i] & ((1 << p) - 1)) << (k - p);
|
220
|
+
d |= this[--i] >> (p += this.DB - k);
|
221
|
+
}
|
222
|
+
else {
|
223
|
+
d = (this[i] >> (p -= k)) & km;
|
224
|
+
if (p <= 0) {
|
225
|
+
p += this.DB;
|
226
|
+
--i;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
if (d > 0) m = true;
|
230
|
+
if (m) r += int2char(d);
|
231
|
+
}
|
232
|
+
}
|
233
|
+
return m ? r : "0";
|
234
|
+
}
|
235
|
+
|
236
|
+
// (public) -this
|
237
|
+
function bnNegate() {
|
238
|
+
var r = nbi();
|
239
|
+
BigInteger.ZERO.subTo(this, r);
|
240
|
+
return r;
|
241
|
+
}
|
242
|
+
|
243
|
+
// (public) |this|
|
244
|
+
function bnAbs() {
|
245
|
+
return (this.s < 0) ? this.negate() : this;
|
246
|
+
}
|
247
|
+
|
248
|
+
// (public) return + if this > a, - if this < a, 0 if equal
|
249
|
+
function bnCompareTo(a) {
|
250
|
+
var r = this.s - a.s;
|
251
|
+
if (r != 0) return r;
|
252
|
+
var i = this.t;
|
253
|
+
r = i - a.t;
|
254
|
+
if (r != 0) return (this.s < 0) ? -r : r;
|
255
|
+
while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r;
|
256
|
+
return 0;
|
257
|
+
}
|
258
|
+
|
259
|
+
// returns bit length of the integer x
|
260
|
+
function nbits(x) {
|
261
|
+
var r = 1, t;
|
262
|
+
if ((t = x >>> 16) != 0) {
|
263
|
+
x = t;
|
264
|
+
r += 16;
|
265
|
+
}
|
266
|
+
if ((t = x >> 8) != 0) {
|
267
|
+
x = t;
|
268
|
+
r += 8;
|
269
|
+
}
|
270
|
+
if ((t = x >> 4) != 0) {
|
271
|
+
x = t;
|
272
|
+
r += 4;
|
273
|
+
}
|
274
|
+
if ((t = x >> 2) != 0) {
|
275
|
+
x = t;
|
276
|
+
r += 2;
|
277
|
+
}
|
278
|
+
if ((t = x >> 1) != 0) {
|
279
|
+
x = t;
|
280
|
+
r += 1;
|
281
|
+
}
|
282
|
+
return r;
|
283
|
+
}
|
284
|
+
|
285
|
+
// (public) return the number of bits in "this"
|
286
|
+
function bnBitLength() {
|
287
|
+
if (this.t <= 0) return 0;
|
288
|
+
return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
|
289
|
+
}
|
290
|
+
|
291
|
+
// (protected) r = this << n*DB
|
292
|
+
function bnpDLShiftTo(n, r) {
|
293
|
+
var i;
|
294
|
+
for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i];
|
295
|
+
for (i = n - 1; i >= 0; --i) r[i] = 0;
|
296
|
+
r.t = this.t + n;
|
297
|
+
r.s = this.s;
|
298
|
+
}
|
299
|
+
|
300
|
+
// (protected) r = this >> n*DB
|
301
|
+
function bnpDRShiftTo(n, r) {
|
302
|
+
for (var i = n; i < this.t; ++i) r[i - n] = this[i];
|
303
|
+
r.t = Math.max(this.t - n, 0);
|
304
|
+
r.s = this.s;
|
305
|
+
}
|
306
|
+
|
307
|
+
// (protected) r = this << n
|
308
|
+
function bnpLShiftTo(n, r) {
|
309
|
+
var bs = n % this.DB;
|
310
|
+
var cbs = this.DB - bs;
|
311
|
+
var bm = (1 << cbs) - 1;
|
312
|
+
var ds = Math.floor(n / this.DB), c = (this.s << bs) & this.DM, i;
|
313
|
+
for (i = this.t - 1; i >= 0; --i) {
|
314
|
+
r[i + ds + 1] = (this[i] >> cbs) | c;
|
315
|
+
c = (this[i] & bm) << bs;
|
316
|
+
}
|
317
|
+
for (i = ds - 1; i >= 0; --i) r[i] = 0;
|
318
|
+
r[ds] = c;
|
319
|
+
r.t = this.t + ds + 1;
|
320
|
+
r.s = this.s;
|
321
|
+
r.clamp();
|
322
|
+
}
|
323
|
+
|
324
|
+
// (protected) r = this >> n
|
325
|
+
function bnpRShiftTo(n, r) {
|
326
|
+
r.s = this.s;
|
327
|
+
var ds = Math.floor(n / this.DB);
|
328
|
+
if (ds >= this.t) {
|
329
|
+
r.t = 0;
|
330
|
+
return;
|
331
|
+
}
|
332
|
+
var bs = n % this.DB;
|
333
|
+
var cbs = this.DB - bs;
|
334
|
+
var bm = (1 << bs) - 1;
|
335
|
+
r[0] = this[ds] >> bs;
|
336
|
+
for (var i = ds + 1; i < this.t; ++i) {
|
337
|
+
r[i - ds - 1] |= (this[i] & bm) << cbs;
|
338
|
+
r[i - ds] = this[i] >> bs;
|
339
|
+
}
|
340
|
+
if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs;
|
341
|
+
r.t = this.t - ds;
|
342
|
+
r.clamp();
|
343
|
+
}
|
344
|
+
|
345
|
+
// (protected) r = this - a
|
346
|
+
function bnpSubTo(a, r) {
|
347
|
+
var i = 0, c = 0, m = Math.min(a.t, this.t);
|
348
|
+
while (i < m) {
|
349
|
+
c += this[i] - a[i];
|
350
|
+
r[i++] = c & this.DM;
|
351
|
+
c >>= this.DB;
|
352
|
+
}
|
353
|
+
if (a.t < this.t) {
|
354
|
+
c -= a.s;
|
355
|
+
while (i < this.t) {
|
356
|
+
c += this[i];
|
357
|
+
r[i++] = c & this.DM;
|
358
|
+
c >>= this.DB;
|
359
|
+
}
|
360
|
+
c += this.s;
|
361
|
+
}
|
362
|
+
else {
|
363
|
+
c += this.s;
|
364
|
+
while (i < a.t) {
|
365
|
+
c -= a[i];
|
366
|
+
r[i++] = c & this.DM;
|
367
|
+
c >>= this.DB;
|
368
|
+
}
|
369
|
+
c -= a.s;
|
370
|
+
}
|
371
|
+
r.s = (c < 0) ? -1 : 0;
|
372
|
+
if (c < -1) r[i++] = this.DV + c;
|
373
|
+
else if (c > 0) r[i++] = c;
|
374
|
+
r.t = i;
|
375
|
+
r.clamp();
|
376
|
+
}
|
377
|
+
|
378
|
+
// (protected) r = this * a, r != this,a (HAC 14.12)
|
379
|
+
// "this" should be the larger one if appropriate.
|
380
|
+
function bnpMultiplyTo(a, r) {
|
381
|
+
var x = this.abs(), y = a.abs();
|
382
|
+
var i = x.t;
|
383
|
+
r.t = i + y.t;
|
384
|
+
while (--i >= 0) r[i] = 0;
|
385
|
+
for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
|
386
|
+
r.s = 0;
|
387
|
+
r.clamp();
|
388
|
+
if (this.s != a.s) BigInteger.ZERO.subTo(r, r);
|
389
|
+
}
|
390
|
+
|
391
|
+
// (protected) r = this^2, r != this (HAC 14.16)
|
392
|
+
function bnpSquareTo(r) {
|
393
|
+
var x = this.abs();
|
394
|
+
var i = r.t = 2 * x.t;
|
395
|
+
while (--i >= 0) r[i] = 0;
|
396
|
+
for (i = 0; i < x.t - 1; ++i) {
|
397
|
+
var c = x.am(i, x[i], r, 2 * i, 0, 1);
|
398
|
+
if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
|
399
|
+
r[i + x.t] -= x.DV;
|
400
|
+
r[i + x.t + 1] = 1;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
|
404
|
+
r.s = 0;
|
405
|
+
r.clamp();
|
406
|
+
}
|
407
|
+
|
408
|
+
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
409
|
+
// r != q, this != m. q or r may be null.
|
410
|
+
function bnpDivRemTo(m, q, r) {
|
411
|
+
var pm = m.abs();
|
412
|
+
if (pm.t <= 0) return;
|
413
|
+
var pt = this.abs();
|
414
|
+
if (pt.t < pm.t) {
|
415
|
+
if (q != null) q.fromInt(0);
|
416
|
+
if (r != null) this.copyTo(r);
|
417
|
+
return;
|
418
|
+
}
|
419
|
+
if (r == null) r = nbi();
|
420
|
+
var y = nbi(), ts = this.s, ms = m.s;
|
421
|
+
var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
|
422
|
+
if (nsh > 0) {
|
423
|
+
pm.lShiftTo(nsh, y);
|
424
|
+
pt.lShiftTo(nsh, r);
|
425
|
+
}
|
426
|
+
else {
|
427
|
+
pm.copyTo(y);
|
428
|
+
pt.copyTo(r);
|
429
|
+
}
|
430
|
+
var ys = y.t;
|
431
|
+
var y0 = y[ys - 1];
|
432
|
+
if (y0 === 0) return;
|
433
|
+
var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
|
434
|
+
var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2;
|
435
|
+
var i = r.t, j = i - ys, t = (q == null) ? nbi() : q;
|
436
|
+
y.dlShiftTo(j, t);
|
437
|
+
if (r.compareTo(t) >= 0) {
|
438
|
+
r[r.t++] = 1;
|
439
|
+
r.subTo(t, r);
|
440
|
+
}
|
441
|
+
BigInteger.ONE.dlShiftTo(ys, t);
|
442
|
+
t.subTo(y, y); // "negative" y so we can replace sub with am later
|
443
|
+
while (y.t < ys) y[y.t++] = 0;
|
444
|
+
while (--j >= 0) {
|
445
|
+
// Estimate quotient digit
|
446
|
+
var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
|
447
|
+
if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
|
448
|
+
y.dlShiftTo(j, t);
|
449
|
+
r.subTo(t, r);
|
450
|
+
while (r[i] < --qd) r.subTo(t, r);
|
451
|
+
}
|
452
|
+
}
|
453
|
+
if (q != null) {
|
454
|
+
r.drShiftTo(ys, q);
|
455
|
+
if (ts != ms) BigInteger.ZERO.subTo(q, q);
|
456
|
+
}
|
457
|
+
r.t = ys;
|
458
|
+
r.clamp();
|
459
|
+
if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
|
460
|
+
if (ts < 0) BigInteger.ZERO.subTo(r, r);
|
461
|
+
}
|
462
|
+
|
463
|
+
// (public) this mod a
|
464
|
+
function bnMod(a) {
|
465
|
+
var r = nbi();
|
466
|
+
this.abs().divRemTo(a, null, r);
|
467
|
+
if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r);
|
468
|
+
return r;
|
469
|
+
}
|
470
|
+
|
471
|
+
// Modular reduction using "classic" algorithm
|
472
|
+
function Classic(m) {
|
473
|
+
this.m = m;
|
474
|
+
}
|
475
|
+
function cConvert(x) {
|
476
|
+
if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
477
|
+
else return x;
|
478
|
+
}
|
479
|
+
function cRevert(x) {
|
480
|
+
return x;
|
481
|
+
}
|
482
|
+
function cReduce(x) {
|
483
|
+
x.divRemTo(this.m, null, x);
|
484
|
+
}
|
485
|
+
function cMulTo(x, y, r) {
|
486
|
+
x.multiplyTo(y, r);
|
487
|
+
this.reduce(r);
|
488
|
+
}
|
489
|
+
function cSqrTo(x, r) {
|
490
|
+
x.squareTo(r);
|
491
|
+
this.reduce(r);
|
492
|
+
}
|
493
|
+
|
494
|
+
Classic.prototype.convert = cConvert;
|
495
|
+
Classic.prototype.revert = cRevert;
|
496
|
+
Classic.prototype.reduce = cReduce;
|
497
|
+
Classic.prototype.mulTo = cMulTo;
|
498
|
+
Classic.prototype.sqrTo = cSqrTo;
|
499
|
+
|
500
|
+
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
501
|
+
// justification:
|
502
|
+
// xy == 1 (mod m)
|
503
|
+
// xy = 1+km
|
504
|
+
// xy(2-xy) = (1+km)(1-km)
|
505
|
+
// x[y(2-xy)] = 1-k^2m^2
|
506
|
+
// x[y(2-xy)] == 1 (mod m^2)
|
507
|
+
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
508
|
+
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
509
|
+
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
510
|
+
function bnpInvDigit() {
|
511
|
+
if (this.t < 1) return 0;
|
512
|
+
var x = this[0];
|
513
|
+
if ((x & 1) === 0) return 0;
|
514
|
+
var y = x & 3; // y == 1/x mod 2^2
|
515
|
+
y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
|
516
|
+
y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
|
517
|
+
y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
|
518
|
+
// last step - calculate inverse mod DV directly;
|
519
|
+
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
520
|
+
y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
|
521
|
+
// we really want the negative inverse, and -DV < y < DV
|
522
|
+
return (y > 0) ? this.DV - y : -y;
|
523
|
+
}
|
524
|
+
|
525
|
+
// Montgomery reduction
|
526
|
+
function Montgomery(m) {
|
527
|
+
this.m = m;
|
528
|
+
this.mp = m.invDigit();
|
529
|
+
this.mpl = this.mp & 0x7fff;
|
530
|
+
this.mph = this.mp >> 15;
|
531
|
+
this.um = (1 << (m.DB - 15)) - 1;
|
532
|
+
this.mt2 = 2 * m.t;
|
533
|
+
}
|
534
|
+
|
535
|
+
// xR mod m
|
536
|
+
function montConvert(x) {
|
537
|
+
var r = nbi();
|
538
|
+
x.abs().dlShiftTo(this.m.t, r);
|
539
|
+
r.divRemTo(this.m, null, r);
|
540
|
+
if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r);
|
541
|
+
return r;
|
542
|
+
}
|
543
|
+
|
544
|
+
// x/R mod m
|
545
|
+
function montRevert(x) {
|
546
|
+
var r = nbi();
|
547
|
+
x.copyTo(r);
|
548
|
+
this.reduce(r);
|
549
|
+
return r;
|
550
|
+
}
|
551
|
+
|
552
|
+
// x = x/R mod m (HAC 14.32)
|
553
|
+
function montReduce(x) {
|
554
|
+
while (x.t <= this.mt2) // pad x so am has enough room later
|
555
|
+
x[x.t++] = 0;
|
556
|
+
for (var i = 0; i < this.m.t; ++i) {
|
557
|
+
// faster way of calculating u0 = x[i]*mp mod DV
|
558
|
+
var j = x[i] & 0x7fff;
|
559
|
+
var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
|
560
|
+
// use am to combine the multiply-shift-add into one call
|
561
|
+
j = i + this.m.t;
|
562
|
+
x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
|
563
|
+
// propagate carry
|
564
|
+
while (x[j] >= x.DV) {
|
565
|
+
x[j] -= x.DV;
|
566
|
+
x[++j]++;
|
567
|
+
}
|
568
|
+
}
|
569
|
+
x.clamp();
|
570
|
+
x.drShiftTo(this.m.t, x);
|
571
|
+
if (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
|
572
|
+
}
|
573
|
+
|
574
|
+
// r = "x^2/R mod m"; x != r
|
575
|
+
function montSqrTo(x, r) {
|
576
|
+
x.squareTo(r);
|
577
|
+
this.reduce(r);
|
578
|
+
}
|
579
|
+
|
580
|
+
// r = "xy/R mod m"; x,y != r
|
581
|
+
function montMulTo(x, y, r) {
|
582
|
+
x.multiplyTo(y, r);
|
583
|
+
this.reduce(r);
|
584
|
+
}
|
585
|
+
|
586
|
+
Montgomery.prototype.convert = montConvert;
|
587
|
+
Montgomery.prototype.revert = montRevert;
|
588
|
+
Montgomery.prototype.reduce = montReduce;
|
589
|
+
Montgomery.prototype.mulTo = montMulTo;
|
590
|
+
Montgomery.prototype.sqrTo = montSqrTo;
|
591
|
+
|
592
|
+
// (protected) true iff this is even
|
593
|
+
function bnpIsEven() {
|
594
|
+
return ((this.t > 0) ? (this[0] & 1) : this.s) === 0;
|
595
|
+
}
|
596
|
+
|
597
|
+
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
598
|
+
function bnpExp(e, z) {
|
599
|
+
if (e > 0xffffffff || e < 1) return BigInteger.ONE;
|
600
|
+
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e) - 1;
|
601
|
+
g.copyTo(r);
|
602
|
+
while (--i >= 0) {
|
603
|
+
z.sqrTo(r, r2);
|
604
|
+
if ((e & (1 << i)) > 0) z.mulTo(r2, g, r);
|
605
|
+
else {
|
606
|
+
var t = r;
|
607
|
+
r = r2;
|
608
|
+
r2 = t;
|
609
|
+
}
|
610
|
+
}
|
611
|
+
return z.revert(r);
|
612
|
+
}
|
613
|
+
|
614
|
+
// Copyright (c) 2005-2009 Tom Wu
|
615
|
+
// All Rights Reserved.
|
616
|
+
// See "LICENSE" for details.
|
617
|
+
|
618
|
+
// Extended JavaScript BN functions, required for RSA private ops.
|
619
|
+
|
620
|
+
// Version 1.1: new BigInteger("0", 10) returns "proper" zero
|
621
|
+
// Version 1.2: square() API, isProbablePrime fix
|
622
|
+
|
623
|
+
//(public)
|
624
|
+
function bnClone() {
|
625
|
+
var r = nbi();
|
626
|
+
this.copyTo(r);
|
627
|
+
return r;
|
628
|
+
}
|
629
|
+
|
630
|
+
//(public) return value as integer
|
631
|
+
function bnIntValue() {
|
632
|
+
if (this.s < 0) {
|
633
|
+
if (this.t == 1) return this[0] - this.DV;
|
634
|
+
else if (this.t === 0) return -1;
|
635
|
+
}
|
636
|
+
else if (this.t == 1) return this[0];
|
637
|
+
else if (this.t === 0) return 0;
|
638
|
+
// assumes 16 < DB < 32
|
639
|
+
return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
|
640
|
+
}
|
641
|
+
|
642
|
+
//(protected) return x s.t. r^x < DV
|
643
|
+
function bnpChunkSize(r) {
|
644
|
+
return Math.floor(Math.LN2 * this.DB / Math.log(r));
|
645
|
+
}
|
646
|
+
|
647
|
+
//(public) 0 if this === 0, 1 if this > 0
|
648
|
+
function bnSigNum() {
|
649
|
+
if (this.s < 0) return -1;
|
650
|
+
else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
|
651
|
+
else return 1;
|
652
|
+
}
|
653
|
+
|
654
|
+
//(protected) convert to radix string
|
655
|
+
function bnpToRadix(b) {
|
656
|
+
if (b == null) b = 10;
|
657
|
+
if (this.signum() === 0 || b < 2 || b > 36) return "0";
|
658
|
+
var cs = this.chunkSize(b);
|
659
|
+
var a = Math.pow(b, cs);
|
660
|
+
var d = nbv(a), y = nbi(), z = nbi(), r = "";
|
661
|
+
this.divRemTo(d, y, z);
|
662
|
+
while (y.signum() > 0) {
|
663
|
+
r = (a + z.intValue()).toString(b).substr(1) + r;
|
664
|
+
y.divRemTo(d, y, z);
|
665
|
+
}
|
666
|
+
return z.intValue().toString(b) + r;
|
667
|
+
}
|
668
|
+
|
669
|
+
//(protected) convert from radix string
|
670
|
+
function bnpFromRadix(s, b) {
|
671
|
+
this.fromInt(0);
|
672
|
+
if (b == null) b = 10;
|
673
|
+
var cs = this.chunkSize(b);
|
674
|
+
var d = Math.pow(b, cs), mi = false, j = 0, w = 0;
|
675
|
+
for (var i = 0; i < s.length; ++i) {
|
676
|
+
var x = intAt(s, i);
|
677
|
+
if (x < 0) {
|
678
|
+
if (s.charAt(i) == "-" && this.signum() === 0) mi = true;
|
679
|
+
continue;
|
680
|
+
}
|
681
|
+
w = b * w + x;
|
682
|
+
if (++j >= cs) {
|
683
|
+
this.dMultiply(d);
|
684
|
+
this.dAddOffset(w, 0);
|
685
|
+
j = 0;
|
686
|
+
w = 0;
|
687
|
+
}
|
688
|
+
}
|
689
|
+
if (j > 0) {
|
690
|
+
this.dMultiply(Math.pow(b, j));
|
691
|
+
this.dAddOffset(w, 0);
|
692
|
+
}
|
693
|
+
if (mi) BigInteger.ZERO.subTo(this, this);
|
694
|
+
}
|
695
|
+
|
696
|
+
//(public) convert to bigendian byte array
|
697
|
+
function bnToByteArray() {
|
698
|
+
var i = this.t, r = new Array();
|
699
|
+
r[0] = this.s;
|
700
|
+
var p = this.DB - (i * this.DB) % 8, d, k = 0;
|
701
|
+
if (i-- > 0) {
|
702
|
+
if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p)
|
703
|
+
r[k++] = d | (this.s << (this.DB - p));
|
704
|
+
while (i >= 0) {
|
705
|
+
if (p < 8) {
|
706
|
+
d = (this[i] & ((1 << p) - 1)) << (8 - p);
|
707
|
+
d |= this[--i] >> (p += this.DB - 8);
|
708
|
+
}
|
709
|
+
else {
|
710
|
+
d = (this[i] >> (p -= 8)) & 0xff;
|
711
|
+
if (p <= 0) {
|
712
|
+
p += this.DB;
|
713
|
+
--i;
|
714
|
+
}
|
715
|
+
}
|
716
|
+
if ((d & 0x80) != 0) d |= -256;
|
717
|
+
if (k === 0 && (this.s & 0x80) != (d & 0x80)) ++k;
|
718
|
+
if (k > 0 || d != this.s) r[k++] = d;
|
719
|
+
}
|
720
|
+
}
|
721
|
+
return r;
|
722
|
+
}
|
723
|
+
|
724
|
+
/**
|
725
|
+
* return Buffer object
|
726
|
+
* @param trim {boolean} slice buffer if first element == 0
|
727
|
+
* @returns {Buffer}
|
728
|
+
*/
|
729
|
+
function bnToBuffer(trimOrSize) {
|
730
|
+
var res = Buffer.from(this.toByteArray());
|
731
|
+
if (trimOrSize === true && res[0] === 0) {
|
732
|
+
res = res.slice(1);
|
733
|
+
} else if (_.isNumber(trimOrSize)) {
|
734
|
+
if (res.length > trimOrSize) {
|
735
|
+
for (var i = 0; i < res.length - trimOrSize; i++) {
|
736
|
+
if (res[i] !== 0) {
|
737
|
+
return null;
|
738
|
+
}
|
739
|
+
}
|
740
|
+
return res.slice(res.length - trimOrSize);
|
741
|
+
} else if (res.length < trimOrSize) {
|
742
|
+
var padded = Buffer.alloc(trimOrSize);
|
743
|
+
padded.fill(0, 0, trimOrSize - res.length);
|
744
|
+
res.copy(padded, trimOrSize - res.length);
|
745
|
+
return padded;
|
746
|
+
}
|
747
|
+
}
|
748
|
+
return res;
|
749
|
+
}
|
750
|
+
|
751
|
+
function bnEquals(a) {
|
752
|
+
return (this.compareTo(a) == 0);
|
753
|
+
}
|
754
|
+
function bnMin(a) {
|
755
|
+
return (this.compareTo(a) < 0) ? this : a;
|
756
|
+
}
|
757
|
+
function bnMax(a) {
|
758
|
+
return (this.compareTo(a) > 0) ? this : a;
|
759
|
+
}
|
760
|
+
|
761
|
+
//(protected) r = this op a (bitwise)
|
762
|
+
function bnpBitwiseTo(a, op, r) {
|
763
|
+
var i, f, m = Math.min(a.t, this.t);
|
764
|
+
for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]);
|
765
|
+
if (a.t < this.t) {
|
766
|
+
f = a.s & this.DM;
|
767
|
+
for (i = m; i < this.t; ++i) r[i] = op(this[i], f);
|
768
|
+
r.t = this.t;
|
769
|
+
}
|
770
|
+
else {
|
771
|
+
f = this.s & this.DM;
|
772
|
+
for (i = m; i < a.t; ++i) r[i] = op(f, a[i]);
|
773
|
+
r.t = a.t;
|
774
|
+
}
|
775
|
+
r.s = op(this.s, a.s);
|
776
|
+
r.clamp();
|
777
|
+
}
|
778
|
+
|
779
|
+
//(public) this & a
|
780
|
+
function op_and(x, y) {
|
781
|
+
return x & y;
|
782
|
+
}
|
783
|
+
function bnAnd(a) {
|
784
|
+
var r = nbi();
|
785
|
+
this.bitwiseTo(a, op_and, r);
|
786
|
+
return r;
|
787
|
+
}
|
788
|
+
|
789
|
+
//(public) this | a
|
790
|
+
function op_or(x, y) {
|
791
|
+
return x | y;
|
792
|
+
}
|
793
|
+
function bnOr(a) {
|
794
|
+
var r = nbi();
|
795
|
+
this.bitwiseTo(a, op_or, r);
|
796
|
+
return r;
|
797
|
+
}
|
798
|
+
|
799
|
+
//(public) this ^ a
|
800
|
+
function op_xor(x, y) {
|
801
|
+
return x ^ y;
|
802
|
+
}
|
803
|
+
function bnXor(a) {
|
804
|
+
var r = nbi();
|
805
|
+
this.bitwiseTo(a, op_xor, r);
|
806
|
+
return r;
|
807
|
+
}
|
808
|
+
|
809
|
+
//(public) this & ~a
|
810
|
+
function op_andnot(x, y) {
|
811
|
+
return x & ~y;
|
812
|
+
}
|
813
|
+
|
814
|
+
//(public) ~this
|
815
|
+
function bnNot() {
|
816
|
+
var r = nbi();
|
817
|
+
for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i];
|
818
|
+
r.t = this.t;
|
819
|
+
r.s = ~this.s;
|
820
|
+
return r;
|
821
|
+
}
|
822
|
+
|
823
|
+
//return index of lowest 1-bit in x, x < 2^31
|
824
|
+
function lbit(x) {
|
825
|
+
if (x === 0) return -1;
|
826
|
+
var r = 0;
|
827
|
+
if ((x & 0xffff) === 0) {
|
828
|
+
x >>= 16;
|
829
|
+
r += 16;
|
830
|
+
}
|
831
|
+
if ((x & 0xff) === 0) {
|
832
|
+
x >>= 8;
|
833
|
+
r += 8;
|
834
|
+
}
|
835
|
+
if ((x & 0xf) === 0) {
|
836
|
+
x >>= 4;
|
837
|
+
r += 4;
|
838
|
+
}
|
839
|
+
if ((x & 3) === 0) {
|
840
|
+
x >>= 2;
|
841
|
+
r += 2;
|
842
|
+
}
|
843
|
+
if ((x & 1) === 0) ++r;
|
844
|
+
return r;
|
845
|
+
}
|
846
|
+
|
847
|
+
//(public) returns index of lowest 1-bit (or -1 if none)
|
848
|
+
function bnGetLowestSetBit() {
|
849
|
+
for (var i = 0; i < this.t; ++i)
|
850
|
+
if (this[i] != 0) return i * this.DB + lbit(this[i]);
|
851
|
+
if (this.s < 0) return this.t * this.DB;
|
852
|
+
return -1;
|
853
|
+
}
|
854
|
+
|
855
|
+
//return number of 1 bits in x
|
856
|
+
function cbit(x) {
|
857
|
+
var r = 0;
|
858
|
+
while (x != 0) {
|
859
|
+
x &= x - 1;
|
860
|
+
++r;
|
861
|
+
}
|
862
|
+
return r;
|
863
|
+
}
|
864
|
+
|
865
|
+
//(protected) r = this + a
|
866
|
+
function bnpAddTo(a, r) {
|
867
|
+
var i = 0, c = 0, m = Math.min(a.t, this.t);
|
868
|
+
while (i < m) {
|
869
|
+
c += this[i] + a[i];
|
870
|
+
r[i++] = c & this.DM;
|
871
|
+
c >>= this.DB;
|
872
|
+
}
|
873
|
+
if (a.t < this.t) {
|
874
|
+
c += a.s;
|
875
|
+
while (i < this.t) {
|
876
|
+
c += this[i];
|
877
|
+
r[i++] = c & this.DM;
|
878
|
+
c >>= this.DB;
|
879
|
+
}
|
880
|
+
c += this.s;
|
881
|
+
}
|
882
|
+
else {
|
883
|
+
c += this.s;
|
884
|
+
while (i < a.t) {
|
885
|
+
c += a[i];
|
886
|
+
r[i++] = c & this.DM;
|
887
|
+
c >>= this.DB;
|
888
|
+
}
|
889
|
+
c += a.s;
|
890
|
+
}
|
891
|
+
r.s = (c < 0) ? -1 : 0;
|
892
|
+
if (c > 0) r[i++] = c;
|
893
|
+
else if (c < -1) r[i++] = this.DV + c;
|
894
|
+
r.t = i;
|
895
|
+
r.clamp();
|
896
|
+
}
|
897
|
+
|
898
|
+
//(public) this + a
|
899
|
+
function bnAdd(a) {
|
900
|
+
var r = nbi();
|
901
|
+
this.addTo(a, r);
|
902
|
+
return r;
|
903
|
+
}
|
904
|
+
|
905
|
+
//(public) this - a
|
906
|
+
function bnSubtract(a) {
|
907
|
+
var r = nbi();
|
908
|
+
this.subTo(a, r);
|
909
|
+
return r;
|
910
|
+
}
|
911
|
+
|
912
|
+
//(public) this * a
|
913
|
+
function bnMultiply(a) {
|
914
|
+
var r = nbi();
|
915
|
+
this.multiplyTo(a, r);
|
916
|
+
return r;
|
917
|
+
}
|
918
|
+
|
919
|
+
// (public) this^2
|
920
|
+
function bnSquare() {
|
921
|
+
var r = nbi();
|
922
|
+
this.squareTo(r);
|
923
|
+
return r;
|
924
|
+
}
|
925
|
+
|
926
|
+
//(public) this / a
|
927
|
+
function bnDivide(a) {
|
928
|
+
var r = nbi();
|
929
|
+
this.divRemTo(a, r, null);
|
930
|
+
return r;
|
931
|
+
}
|
932
|
+
|
933
|
+
//(public) this % a
|
934
|
+
function bnRemainder(a) {
|
935
|
+
var r = nbi();
|
936
|
+
this.divRemTo(a, null, r);
|
937
|
+
return r;
|
938
|
+
}
|
939
|
+
|
940
|
+
//(protected) this *= n, this >= 0, 1 < n < DV
|
941
|
+
function bnpDMultiply(n) {
|
942
|
+
this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
|
943
|
+
++this.t;
|
944
|
+
this.clamp();
|
945
|
+
}
|
946
|
+
|
947
|
+
//(protected) this += n << w words, this >= 0
|
948
|
+
function bnpDAddOffset(n, w) {
|
949
|
+
if (n === 0) return;
|
950
|
+
while (this.t <= w) this[this.t++] = 0;
|
951
|
+
this[w] += n;
|
952
|
+
while (this[w] >= this.DV) {
|
953
|
+
this[w] -= this.DV;
|
954
|
+
if (++w >= this.t) this[this.t++] = 0;
|
955
|
+
++this[w];
|
956
|
+
}
|
957
|
+
}
|
958
|
+
|
959
|
+
//A "null" reducer
|
960
|
+
function NullExp() {
|
961
|
+
}
|
962
|
+
function nNop(x) {
|
963
|
+
return x;
|
964
|
+
}
|
965
|
+
function nMulTo(x, y, r) {
|
966
|
+
x.multiplyTo(y, r);
|
967
|
+
}
|
968
|
+
function nSqrTo(x, r) {
|
969
|
+
x.squareTo(r);
|
970
|
+
}
|
971
|
+
|
972
|
+
NullExp.prototype.convert = nNop;
|
973
|
+
NullExp.prototype.revert = nNop;
|
974
|
+
NullExp.prototype.mulTo = nMulTo;
|
975
|
+
NullExp.prototype.sqrTo = nSqrTo;
|
976
|
+
|
977
|
+
//(public) this^e
|
978
|
+
function bnPow(e) {
|
979
|
+
return this.exp(e, new NullExp());
|
980
|
+
}
|
981
|
+
|
982
|
+
//(protected) r = lower n words of "this * a", a.t <= n
|
983
|
+
//"this" should be the larger one if appropriate.
|
984
|
+
function bnpMultiplyLowerTo(a, n, r) {
|
985
|
+
var i = Math.min(this.t + a.t, n);
|
986
|
+
r.s = 0; // assumes a,this >= 0
|
987
|
+
r.t = i;
|
988
|
+
while (i > 0) r[--i] = 0;
|
989
|
+
var j;
|
990
|
+
for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
|
991
|
+
for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i);
|
992
|
+
r.clamp();
|
993
|
+
}
|
994
|
+
|
995
|
+
//(protected) r = "this * a" without lower n words, n > 0
|
996
|
+
//"this" should be the larger one if appropriate.
|
997
|
+
function bnpMultiplyUpperTo(a, n, r) {
|
998
|
+
--n;
|
999
|
+
var i = r.t = this.t + a.t - n;
|
1000
|
+
r.s = 0; // assumes a,this >= 0
|
1001
|
+
while (--i >= 0) r[i] = 0;
|
1002
|
+
for (i = Math.max(n - this.t, 0); i < a.t; ++i)
|
1003
|
+
r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
|
1004
|
+
r.clamp();
|
1005
|
+
r.drShiftTo(1, r);
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
//Barrett modular reduction
|
1009
|
+
function Barrett(m) {
|
1010
|
+
// setup Barrett
|
1011
|
+
this.r2 = nbi();
|
1012
|
+
this.q3 = nbi();
|
1013
|
+
BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
|
1014
|
+
this.mu = this.r2.divide(m);
|
1015
|
+
this.m = m;
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
function barrettConvert(x) {
|
1019
|
+
if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m);
|
1020
|
+
else if (x.compareTo(this.m) < 0) return x;
|
1021
|
+
else {
|
1022
|
+
var r = nbi();
|
1023
|
+
x.copyTo(r);
|
1024
|
+
this.reduce(r);
|
1025
|
+
return r;
|
1026
|
+
}
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
function barrettRevert(x) {
|
1030
|
+
return x;
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
//x = x mod m (HAC 14.42)
|
1034
|
+
function barrettReduce(x) {
|
1035
|
+
x.drShiftTo(this.m.t - 1, this.r2);
|
1036
|
+
if (x.t > this.m.t + 1) {
|
1037
|
+
x.t = this.m.t + 1;
|
1038
|
+
x.clamp();
|
1039
|
+
}
|
1040
|
+
this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
|
1041
|
+
this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
|
1042
|
+
while (x.compareTo(this.r2) < 0) x.dAddOffset(1, this.m.t + 1);
|
1043
|
+
x.subTo(this.r2, x);
|
1044
|
+
while (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
//r = x^2 mod m; x != r
|
1048
|
+
function barrettSqrTo(x, r) {
|
1049
|
+
x.squareTo(r);
|
1050
|
+
this.reduce(r);
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
//r = x*y mod m; x,y != r
|
1054
|
+
function barrettMulTo(x, y, r) {
|
1055
|
+
x.multiplyTo(y, r);
|
1056
|
+
this.reduce(r);
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
Barrett.prototype.convert = barrettConvert;
|
1060
|
+
Barrett.prototype.revert = barrettRevert;
|
1061
|
+
Barrett.prototype.reduce = barrettReduce;
|
1062
|
+
Barrett.prototype.mulTo = barrettMulTo;
|
1063
|
+
Barrett.prototype.sqrTo = barrettSqrTo;
|
1064
|
+
|
1065
|
+
//(public) this^e % m (HAC 14.85)
|
1066
|
+
function bnModPow(e, m) {
|
1067
|
+
var i = e.bitLength(), k, r = nbv(1), z;
|
1068
|
+
if (i <= 0) return r;
|
1069
|
+
else if (i < 18) k = 1;
|
1070
|
+
else if (i < 48) k = 3;
|
1071
|
+
else if (i < 144) k = 4;
|
1072
|
+
else if (i < 768) k = 5;
|
1073
|
+
else k = 6;
|
1074
|
+
if (i < 8)
|
1075
|
+
z = new Classic(m);
|
1076
|
+
else if (m.isEven())
|
1077
|
+
z = new Barrett(m);
|
1078
|
+
else
|
1079
|
+
z = new Montgomery(m);
|
1080
|
+
|
1081
|
+
// precomputation
|
1082
|
+
var g = new Array(), n = 3, k1 = k - 1, km = (1 << k) - 1;
|
1083
|
+
g[1] = z.convert(this);
|
1084
|
+
if (k > 1) {
|
1085
|
+
var g2 = nbi();
|
1086
|
+
z.sqrTo(g[1], g2);
|
1087
|
+
while (n <= km) {
|
1088
|
+
g[n] = nbi();
|
1089
|
+
z.mulTo(g2, g[n - 2], g[n]);
|
1090
|
+
n += 2;
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
var j = e.t - 1, w, is1 = true, r2 = nbi(), t;
|
1095
|
+
i = nbits(e[j]) - 1;
|
1096
|
+
while (j >= 0) {
|
1097
|
+
if (i >= k1) w = (e[j] >> (i - k1)) & km;
|
1098
|
+
else {
|
1099
|
+
w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i);
|
1100
|
+
if (j > 0) w |= e[j - 1] >> (this.DB + i - k1);
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
n = k;
|
1104
|
+
while ((w & 1) === 0) {
|
1105
|
+
w >>= 1;
|
1106
|
+
--n;
|
1107
|
+
}
|
1108
|
+
if ((i -= n) < 0) {
|
1109
|
+
i += this.DB;
|
1110
|
+
--j;
|
1111
|
+
}
|
1112
|
+
if (is1) { // ret == 1, don't bother squaring or multiplying it
|
1113
|
+
g[w].copyTo(r);
|
1114
|
+
is1 = false;
|
1115
|
+
}
|
1116
|
+
else {
|
1117
|
+
while (n > 1) {
|
1118
|
+
z.sqrTo(r, r2);
|
1119
|
+
z.sqrTo(r2, r);
|
1120
|
+
n -= 2;
|
1121
|
+
}
|
1122
|
+
if (n > 0) z.sqrTo(r, r2); else {
|
1123
|
+
t = r;
|
1124
|
+
r = r2;
|
1125
|
+
r2 = t;
|
1126
|
+
}
|
1127
|
+
z.mulTo(r2, g[w], r);
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
while (j >= 0 && (e[j] & (1 << i)) === 0) {
|
1131
|
+
z.sqrTo(r, r2);
|
1132
|
+
t = r;
|
1133
|
+
r = r2;
|
1134
|
+
r2 = t;
|
1135
|
+
if (--i < 0) {
|
1136
|
+
i = this.DB - 1;
|
1137
|
+
--j;
|
1138
|
+
}
|
1139
|
+
}
|
1140
|
+
}
|
1141
|
+
return z.revert(r);
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
//(public) gcd(this,a) (HAC 14.54)
|
1145
|
+
function bnGCD(a) {
|
1146
|
+
var x = (this.s < 0) ? this.negate() : this.clone();
|
1147
|
+
var y = (a.s < 0) ? a.negate() : a.clone();
|
1148
|
+
if (x.compareTo(y) < 0) {
|
1149
|
+
var t = x;
|
1150
|
+
x = y;
|
1151
|
+
y = t;
|
1152
|
+
}
|
1153
|
+
var i = x.getLowestSetBit(), g = y.getLowestSetBit();
|
1154
|
+
if (g < 0) return x;
|
1155
|
+
if (i < g) g = i;
|
1156
|
+
if (g > 0) {
|
1157
|
+
x.rShiftTo(g, x);
|
1158
|
+
y.rShiftTo(g, y);
|
1159
|
+
}
|
1160
|
+
while (x.signum() > 0) {
|
1161
|
+
if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x);
|
1162
|
+
if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y);
|
1163
|
+
if (x.compareTo(y) >= 0) {
|
1164
|
+
x.subTo(y, x);
|
1165
|
+
x.rShiftTo(1, x);
|
1166
|
+
}
|
1167
|
+
else {
|
1168
|
+
y.subTo(x, y);
|
1169
|
+
y.rShiftTo(1, y);
|
1170
|
+
}
|
1171
|
+
}
|
1172
|
+
if (g > 0) y.lShiftTo(g, y);
|
1173
|
+
return y;
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
// protected
|
1177
|
+
BigInteger.prototype.copyTo = bnpCopyTo;
|
1178
|
+
BigInteger.prototype.fromInt = bnpFromInt;
|
1179
|
+
BigInteger.prototype.fromString = bnpFromString;
|
1180
|
+
BigInteger.prototype.fromByteArray = bnpFromByteArray;
|
1181
|
+
BigInteger.prototype.fromBuffer = bnpFromBuffer;
|
1182
|
+
BigInteger.prototype.clamp = bnpClamp;
|
1183
|
+
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
1184
|
+
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
1185
|
+
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
1186
|
+
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
1187
|
+
BigInteger.prototype.subTo = bnpSubTo;
|
1188
|
+
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
1189
|
+
BigInteger.prototype.squareTo = bnpSquareTo;
|
1190
|
+
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
1191
|
+
BigInteger.prototype.invDigit = bnpInvDigit;
|
1192
|
+
BigInteger.prototype.isEven = bnpIsEven;
|
1193
|
+
BigInteger.prototype.exp = bnpExp;
|
1194
|
+
|
1195
|
+
BigInteger.prototype.chunkSize = bnpChunkSize;
|
1196
|
+
BigInteger.prototype.toRadix = bnpToRadix;
|
1197
|
+
BigInteger.prototype.fromRadix = bnpFromRadix;
|
1198
|
+
BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
|
1199
|
+
BigInteger.prototype.addTo = bnpAddTo;
|
1200
|
+
BigInteger.prototype.dMultiply = bnpDMultiply;
|
1201
|
+
BigInteger.prototype.dAddOffset = bnpDAddOffset;
|
1202
|
+
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
|
1203
|
+
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
|
1204
|
+
|
1205
|
+
// public
|
1206
|
+
BigInteger.prototype.toString = bnToString;
|
1207
|
+
BigInteger.prototype.negate = bnNegate;
|
1208
|
+
BigInteger.prototype.abs = bnAbs;
|
1209
|
+
BigInteger.prototype.compareTo = bnCompareTo;
|
1210
|
+
BigInteger.prototype.bitLength = bnBitLength;
|
1211
|
+
BigInteger.prototype.mod = bnMod;
|
1212
|
+
|
1213
|
+
BigInteger.prototype.clone = bnClone;
|
1214
|
+
BigInteger.prototype.intValue = bnIntValue;
|
1215
|
+
BigInteger.prototype.signum = bnSigNum;
|
1216
|
+
BigInteger.prototype.toByteArray = bnToByteArray;
|
1217
|
+
BigInteger.prototype.toBuffer = bnToBuffer;
|
1218
|
+
BigInteger.prototype.equals = bnEquals;
|
1219
|
+
BigInteger.prototype.min = bnMin;
|
1220
|
+
BigInteger.prototype.max = bnMax;
|
1221
|
+
BigInteger.prototype.and = bnAnd;
|
1222
|
+
BigInteger.prototype.or = bnOr;
|
1223
|
+
BigInteger.prototype.xor = bnXor;
|
1224
|
+
BigInteger.prototype.not = bnNot;
|
1225
|
+
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
|
1226
|
+
BigInteger.prototype.add = bnAdd;
|
1227
|
+
BigInteger.prototype.subtract = bnSubtract;
|
1228
|
+
BigInteger.prototype.multiply = bnMultiply;
|
1229
|
+
BigInteger.prototype.divide = bnDivide;
|
1230
|
+
BigInteger.prototype.remainder = bnRemainder;
|
1231
|
+
BigInteger.prototype.modPow = bnModPow;
|
1232
|
+
BigInteger.prototype.pow = bnPow;
|
1233
|
+
BigInteger.prototype.gcd = bnGCD;
|
1234
|
+
BigInteger.int2char = int2char;
|
1235
|
+
|
1236
|
+
// "constants"
|
1237
|
+
BigInteger.ZERO = nbv(0);
|
1238
|
+
BigInteger.ONE = nbv(1);
|
1239
|
+
|
1240
|
+
// JSBN-specific extension
|
1241
|
+
BigInteger.prototype.square = bnSquare;
|
1242
|
+
|
1243
|
+
//BigInteger interfaces not implemented in jsbn:
|
1244
|
+
|
1245
|
+
//BigInteger(int signum, byte[] magnitude)
|
1246
|
+
//double doubleValue()
|
1247
|
+
//float floatValue()
|
1248
|
+
//int hashCode()
|
1249
|
+
//long longValue()
|
1250
|
+
//static BigInteger valueOf(long val)
|
1251
|
+
|
1252
|
+
module.exports = BigInteger;
|