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,214 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = exports;
|
4
|
+
var BN = require('../../../BN/bn');
|
5
|
+
|
6
|
+
utils.assert = function (condition, errorMessage) {
|
7
|
+
if (!condition) {
|
8
|
+
throw new Error(errorMessage)
|
9
|
+
}
|
10
|
+
};
|
11
|
+
|
12
|
+
// Represent num in a w-NAF form
|
13
|
+
function getNAF(num, w) {
|
14
|
+
var naf = [];
|
15
|
+
var ws = 1 << (w + 1);
|
16
|
+
var k = num.clone();
|
17
|
+
while (k.cmpn(1) >= 0) {
|
18
|
+
var z;
|
19
|
+
if (k.isOdd()) {
|
20
|
+
var mod = k.andln(ws - 1);
|
21
|
+
if (mod > (ws >> 1) - 1)
|
22
|
+
z = (ws >> 1) - mod;
|
23
|
+
else
|
24
|
+
z = mod;
|
25
|
+
k.isubn(z);
|
26
|
+
} else {
|
27
|
+
z = 0;
|
28
|
+
}
|
29
|
+
naf.push(z);
|
30
|
+
|
31
|
+
// Optimization, shift by word if possible
|
32
|
+
var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
|
33
|
+
for (var i = 1; i < shift; i++)
|
34
|
+
naf.push(0);
|
35
|
+
k.iushrn(shift);
|
36
|
+
}
|
37
|
+
|
38
|
+
return naf;
|
39
|
+
}
|
40
|
+
utils.getNAF = getNAF;
|
41
|
+
|
42
|
+
// Represent k1, k2 in a Joint Sparse Form
|
43
|
+
function getJSF(k1, k2) {
|
44
|
+
var jsf = [
|
45
|
+
[],
|
46
|
+
[]
|
47
|
+
];
|
48
|
+
|
49
|
+
k1 = k1.clone();
|
50
|
+
k2 = k2.clone();
|
51
|
+
var d1 = 0;
|
52
|
+
var d2 = 0;
|
53
|
+
while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
|
54
|
+
|
55
|
+
// First phase
|
56
|
+
var m14 = (k1.andln(3) + d1) & 3;
|
57
|
+
var m24 = (k2.andln(3) + d2) & 3;
|
58
|
+
if (m14 === 3)
|
59
|
+
m14 = -1;
|
60
|
+
if (m24 === 3)
|
61
|
+
m24 = -1;
|
62
|
+
var u1;
|
63
|
+
if ((m14 & 1) === 0) {
|
64
|
+
u1 = 0;
|
65
|
+
} else {
|
66
|
+
var m8 = (k1.andln(7) + d1) & 7;
|
67
|
+
if ((m8 === 3 || m8 === 5) && m24 === 2)
|
68
|
+
u1 = -m14;
|
69
|
+
else
|
70
|
+
u1 = m14;
|
71
|
+
}
|
72
|
+
jsf[0].push(u1);
|
73
|
+
|
74
|
+
var u2;
|
75
|
+
if ((m24 & 1) === 0) {
|
76
|
+
u2 = 0;
|
77
|
+
} else {
|
78
|
+
var m8 = (k2.andln(7) + d2) & 7;
|
79
|
+
if ((m8 === 3 || m8 === 5) && m14 === 2)
|
80
|
+
u2 = -m24;
|
81
|
+
else
|
82
|
+
u2 = m24;
|
83
|
+
}
|
84
|
+
jsf[1].push(u2);
|
85
|
+
|
86
|
+
// Second phase
|
87
|
+
if (2 * d1 === u1 + 1)
|
88
|
+
d1 = 1 - d1;
|
89
|
+
if (2 * d2 === u2 + 1)
|
90
|
+
d2 = 1 - d2;
|
91
|
+
k1.iushrn(1);
|
92
|
+
k2.iushrn(1);
|
93
|
+
}
|
94
|
+
|
95
|
+
return jsf;
|
96
|
+
}
|
97
|
+
utils.getJSF = getJSF;
|
98
|
+
|
99
|
+
function cachedProperty(obj, name, computer) {
|
100
|
+
var key = '_' + name;
|
101
|
+
obj.prototype[name] = function cachedProperty() {
|
102
|
+
return this[key] !== undefined ? this[key] :
|
103
|
+
this[key] = computer.call(this);
|
104
|
+
};
|
105
|
+
}
|
106
|
+
utils.cachedProperty = cachedProperty;
|
107
|
+
|
108
|
+
function parseBytes(bytes) {
|
109
|
+
return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
|
110
|
+
bytes;
|
111
|
+
}
|
112
|
+
utils.parseBytes = parseBytes;
|
113
|
+
|
114
|
+
function intFromLE(bytes) {
|
115
|
+
return new BN(bytes, 'hex', 'le');
|
116
|
+
}
|
117
|
+
utils.intFromLE = intFromLE;
|
118
|
+
|
119
|
+
// used to convert `CryptoJS` wordArrays into `crypto` hex buffers
|
120
|
+
function wordToByteArray(word, length) {
|
121
|
+
var ba = [],
|
122
|
+
xFF = 0xFF;
|
123
|
+
if (length > 0)
|
124
|
+
ba.push(word >>> 24);
|
125
|
+
if (length > 1)
|
126
|
+
ba.push((word >>> 16) & xFF);
|
127
|
+
if (length > 2)
|
128
|
+
ba.push((word >>> 8) & xFF);
|
129
|
+
if (length > 3)
|
130
|
+
ba.push(word & xFF);
|
131
|
+
|
132
|
+
return ba;
|
133
|
+
}
|
134
|
+
|
135
|
+
function wordArrayToBuffer(wordArray) {
|
136
|
+
let length = undefined;
|
137
|
+
if (wordArray.hasOwnProperty("sigBytes") && wordArray.hasOwnProperty("words")) {
|
138
|
+
length = wordArray.sigBytes;
|
139
|
+
wordArray = wordArray.words;
|
140
|
+
} else {
|
141
|
+
throw Error('Argument not a wordArray')
|
142
|
+
}
|
143
|
+
|
144
|
+
const result = []
|
145
|
+
let bytes = []
|
146
|
+
let i = 0;
|
147
|
+
while (length > 0) {
|
148
|
+
bytes = wordToByteArray(wordArray[i], Math.min(4, length));
|
149
|
+
length -= bytes.length;
|
150
|
+
result.push(bytes);
|
151
|
+
i++;
|
152
|
+
}
|
153
|
+
return [].concat.apply([], result)
|
154
|
+
}
|
155
|
+
|
156
|
+
utils.wordArrayToBuffer = wordArrayToBuffer;
|
157
|
+
|
158
|
+
// https://github.com/indutny/minimalistic-crypto-utils/blob/master/lib/utils.js
|
159
|
+
// moved here to remove the dep
|
160
|
+
|
161
|
+
function toArray(msg, enc) {
|
162
|
+
if (Array.isArray(msg))
|
163
|
+
return msg.slice();
|
164
|
+
if (!msg)
|
165
|
+
return [];
|
166
|
+
var res = [];
|
167
|
+
if (typeof msg !== 'string') {
|
168
|
+
for (var i = 0; i < msg.length; i++)
|
169
|
+
res[i] = msg[i] | 0;
|
170
|
+
return res;
|
171
|
+
}
|
172
|
+
if (enc === 'hex') {
|
173
|
+
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
174
|
+
if (msg.length % 2 !== 0)
|
175
|
+
msg = '0' + msg;
|
176
|
+
for (var i = 0; i < msg.length; i += 2)
|
177
|
+
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
178
|
+
} else {
|
179
|
+
for (var i = 0; i < msg.length; i++) {
|
180
|
+
var c = msg.charCodeAt(i);
|
181
|
+
var hi = c >> 8;
|
182
|
+
var lo = c & 0xff;
|
183
|
+
if (hi)
|
184
|
+
res.push(hi, lo);
|
185
|
+
else
|
186
|
+
res.push(lo);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
return res;
|
190
|
+
}
|
191
|
+
utils.toArray = toArray;
|
192
|
+
|
193
|
+
function zero2(word) {
|
194
|
+
if (word.length === 1)
|
195
|
+
return '0' + word;
|
196
|
+
else
|
197
|
+
return word;
|
198
|
+
}
|
199
|
+
utils.zero2 = zero2;
|
200
|
+
|
201
|
+
function toHex(msg) {
|
202
|
+
var res = '';
|
203
|
+
for (var i = 0; i < msg.length; i++)
|
204
|
+
res += zero2(msg[i].toString(16));
|
205
|
+
return res;
|
206
|
+
}
|
207
|
+
utils.toHex = toHex;
|
208
|
+
|
209
|
+
utils.encode = function encode(arr, enc) {
|
210
|
+
if (enc === 'hex')
|
211
|
+
return toHex(arr);
|
212
|
+
else
|
213
|
+
return arr;
|
214
|
+
};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var elliptic = exports;
|
4
|
+
|
5
|
+
// hello ladies ;)
|
6
|
+
function inherits (ctor, superCtor) {
|
7
|
+
ctor.super_ = superCtor;
|
8
|
+
var TempCtor = function () {};
|
9
|
+
TempCtor.prototype = superCtor.prototype;
|
10
|
+
ctor.prototype = new TempCtor();
|
11
|
+
ctor.prototype.constructor = ctor;
|
12
|
+
}
|
13
|
+
|
14
|
+
elliptic.inherits = inherits
|
15
|
+
elliptic.version = '6.5.0';
|
16
|
+
elliptic.utils = require('./elliptic/utils');
|
17
|
+
elliptic.curve = require('./elliptic/curve');
|
18
|
+
elliptic.curves = require('./elliptic/curves');
|
19
|
+
|
20
|
+
// Protocols
|
21
|
+
elliptic.ec = require('./elliptic/ec');
|
22
|
+
elliptic.eddsa = require('./elliptic/eddsa');
|
@@ -0,0 +1,114 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var CryptoJS = require('../../../crypto-js/crypto-js');
|
4
|
+
var assert = require('../elliptic/utils').assert;
|
5
|
+
var utils = require ('../elliptic/utils')
|
6
|
+
var { byteArrayToWordArray } = require('../../../../base/functions/encode');
|
7
|
+
|
8
|
+
// some static stuff
|
9
|
+
const ONE = CryptoJS.enc.Utf8.parse ('\x01')
|
10
|
+
const ZERO = CryptoJS.enc.Utf8.parse ('\x00')
|
11
|
+
|
12
|
+
function HmacDRBG(options) {
|
13
|
+
if (!(this instanceof HmacDRBG))
|
14
|
+
return new HmacDRBG(options);
|
15
|
+
this.hash = options.hash
|
16
|
+
this.predResist = !!options.predResist;
|
17
|
+
|
18
|
+
this.outLen = this.hash.slice (3, 6); // only support SHAXXX hashes
|
19
|
+
this.minEntropy = options.minEntropy || 192;
|
20
|
+
|
21
|
+
this._reseed = null;
|
22
|
+
this.reseedInterval = null;
|
23
|
+
this.K = null;
|
24
|
+
this.V = null;
|
25
|
+
|
26
|
+
var entropy = options.entropy
|
27
|
+
var nonce = options.nonce
|
28
|
+
var pers = []
|
29
|
+
assert(entropy.length >= (this.minEntropy / 8),
|
30
|
+
'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
31
|
+
this._init(entropy, nonce, pers);
|
32
|
+
}
|
33
|
+
module.exports = HmacDRBG;
|
34
|
+
|
35
|
+
HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
|
36
|
+
var seed = entropy.concat(nonce).concat(pers);
|
37
|
+
|
38
|
+
this.K = new CryptoJS.lib.WordArray.init ()
|
39
|
+
this.V = new CryptoJS.lib.WordArray.init ()
|
40
|
+
const magicNumber = (1 << 24) + (1 << 16) + (1 << 8) + 1
|
41
|
+
this.V.words = Array (this.outLen / 32).fill (magicNumber)
|
42
|
+
this.V.sigBytes = 32
|
43
|
+
this._update(seed);
|
44
|
+
this._reseed = 1;
|
45
|
+
this.reseedInterval = 0x1000000000000; // 2^48
|
46
|
+
};
|
47
|
+
|
48
|
+
HmacDRBG.prototype._hmac = function hmac() {
|
49
|
+
return new CryptoJS.lib.WordArray.init ();
|
50
|
+
};
|
51
|
+
|
52
|
+
HmacDRBG.prototype._update = function update(seed) {
|
53
|
+
var kmac = this._hmac ()
|
54
|
+
kmac.concat (this.V)
|
55
|
+
kmac.concat (ZERO)
|
56
|
+
if (seed)
|
57
|
+
kmac.concat (byteArrayToWordArray (seed));
|
58
|
+
this.K = CryptoJS['Hmac' + this.hash] (kmac, this.K)
|
59
|
+
this.V = CryptoJS['Hmac' + this.hash] (this.V, this.K)
|
60
|
+
if (!seed)
|
61
|
+
return;
|
62
|
+
|
63
|
+
kmac = this._hmac ()
|
64
|
+
kmac.concat (this.V)
|
65
|
+
kmac.concat (ONE)
|
66
|
+
kmac.concat (byteArrayToWordArray (seed))
|
67
|
+
this.K = CryptoJS['Hmac' + this.hash] (kmac, this.K)
|
68
|
+
this.V = CryptoJS['Hmac' + this.hash] (this.V, this.K)
|
69
|
+
};
|
70
|
+
|
71
|
+
HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
|
72
|
+
// Optional entropy enc
|
73
|
+
if (typeof entropyEnc !== 'string') {
|
74
|
+
addEnc = add;
|
75
|
+
add = entropyEnc;
|
76
|
+
entropyEnc = null;
|
77
|
+
}
|
78
|
+
|
79
|
+
//entropy = utils.toArray(entropy, entropyEnc);
|
80
|
+
//add = utils.toArray(add, addEnc);
|
81
|
+
|
82
|
+
assert(entropy.length >= (this.minEntropy / 8),
|
83
|
+
'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
84
|
+
|
85
|
+
this._update(entropy.concat(add || []));
|
86
|
+
this._reseed = 1;
|
87
|
+
};
|
88
|
+
|
89
|
+
HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
|
90
|
+
if (this._reseed > this.reseedInterval)
|
91
|
+
throw new Error ('Reseed is required');
|
92
|
+
|
93
|
+
// Optional encoding
|
94
|
+
if (typeof enc !== 'string') {
|
95
|
+
addEnc = add;
|
96
|
+
add = enc;
|
97
|
+
enc = null;
|
98
|
+
}
|
99
|
+
|
100
|
+
// Optional additional data
|
101
|
+
if (add) {
|
102
|
+
add = CryptoJS.enc.Utf8.parse (add);
|
103
|
+
this._update (add);
|
104
|
+
}
|
105
|
+
|
106
|
+
var res = new CryptoJS.lib.WordArray.init ();
|
107
|
+
while (res.sigBytes < len) {
|
108
|
+
this.V = CryptoJS['Hmac' + this.hash] (this.V, this.K)
|
109
|
+
res.concat (this.V);
|
110
|
+
}
|
111
|
+
this._update (add);
|
112
|
+
this._reseed++;
|
113
|
+
return utils.wordArrayToBuffer(res);
|
114
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var fetch = require('../node-fetch/index');
|
4
|
+
|
5
|
+
function wrapFetchForNode(fetch) {
|
6
|
+
// Support schemaless URIs on the server for parity with the browser.
|
7
|
+
// https://github.com/matthew-andrews/isomorphic-fetch/pull/10
|
8
|
+
const f = function (u, options) {
|
9
|
+
if (typeof u === 'string' && u.slice(0, 2) === '//') {
|
10
|
+
return fetch('https:' + u, options);
|
11
|
+
}
|
12
|
+
|
13
|
+
return fetch(u, options);
|
14
|
+
};
|
15
|
+
// Igor Kroitor 2019 Dec 30
|
16
|
+
// expose http and https
|
17
|
+
// https://github.com/ccxt/ccxt/issues/6327
|
18
|
+
f.http = fetch.http;
|
19
|
+
f.https = fetch.https;
|
20
|
+
return f;
|
21
|
+
}
|
22
|
+
|
23
|
+
module.exports = function (context) {
|
24
|
+
// This modifies the global `node-fetch` object, which isn't great, since
|
25
|
+
// different callers to `fetch-ponyfill` which pass a different Promise
|
26
|
+
// implementation would each expect to have their implementation used. But,
|
27
|
+
// given the way `node-fetch` is implemented, this is the only way to make
|
28
|
+
// it work at all.
|
29
|
+
if (context && context.Promise) {
|
30
|
+
fetch.Promise = context.Promise;
|
31
|
+
}
|
32
|
+
|
33
|
+
return {
|
34
|
+
fetch: wrapFetchForNode(fetch),
|
35
|
+
Headers: fetch.Headers,
|
36
|
+
Request: fetch.Request,
|
37
|
+
Response: fetch.Response
|
38
|
+
};
|
39
|
+
};
|