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,283 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const zero = BigInt (0)
|
4
|
+
const minusOne = BigInt (-1)
|
5
|
+
const base = BigInt (10)
|
6
|
+
|
7
|
+
class Precise {
|
8
|
+
constructor (number, decimals = undefined) {
|
9
|
+
if (decimals === undefined) {
|
10
|
+
let modifier = 0
|
11
|
+
number = number.toLowerCase ()
|
12
|
+
if (number.indexOf ('e') > -1) {
|
13
|
+
[ number, modifier ] = number.split ('e')
|
14
|
+
modifier = parseInt (modifier)
|
15
|
+
}
|
16
|
+
const decimalIndex = number.indexOf ('.')
|
17
|
+
this.decimals = (decimalIndex > -1) ? number.length - decimalIndex - 1 : 0
|
18
|
+
const integerString = number.replace ('.', '')
|
19
|
+
this.integer = BigInt (integerString)
|
20
|
+
this.decimals = this.decimals - modifier
|
21
|
+
} else {
|
22
|
+
this.integer = number
|
23
|
+
this.decimals = decimals
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
mul (other) {
|
28
|
+
// other must be another instance of Precise
|
29
|
+
const integerResult = this.integer * other.integer
|
30
|
+
return new Precise (integerResult, this.decimals + other.decimals)
|
31
|
+
}
|
32
|
+
|
33
|
+
div (other, precision = 18) {
|
34
|
+
const distance = precision - this.decimals + other.decimals
|
35
|
+
let numerator
|
36
|
+
if (distance === 0) {
|
37
|
+
numerator = this.integer
|
38
|
+
} else if (distance < 0) {
|
39
|
+
const exponent = base ** BigInt (-distance)
|
40
|
+
numerator = this.integer / exponent
|
41
|
+
} else {
|
42
|
+
const exponent = base ** BigInt (distance)
|
43
|
+
numerator = this.integer * exponent
|
44
|
+
}
|
45
|
+
const result = numerator / other.integer
|
46
|
+
return new Precise (result, precision)
|
47
|
+
}
|
48
|
+
|
49
|
+
add (other) {
|
50
|
+
if (this.decimals === other.decimals) {
|
51
|
+
const integerResult = this.integer + other.integer
|
52
|
+
return new Precise (integerResult, this.decimals)
|
53
|
+
} else {
|
54
|
+
const [ smaller, bigger ] =
|
55
|
+
(this.decimals > other.decimals) ? [ other, this ] : [ this, other ]
|
56
|
+
const exponent = bigger.decimals - smaller.decimals
|
57
|
+
const normalised = smaller.integer * (base ** BigInt (exponent))
|
58
|
+
const result = normalised + bigger.integer
|
59
|
+
return new Precise (result, bigger.decimals)
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
mod (other) {
|
64
|
+
const rationizerNumerator = Math.max (-this.decimals + other.decimals, 0)
|
65
|
+
const numerator = this.integer * (base ** BigInt (rationizerNumerator))
|
66
|
+
const rationizerDenominator = Math.max (-other.decimals + this.decimals, 0)
|
67
|
+
const denominator = other.integer * (base ** BigInt (rationizerDenominator))
|
68
|
+
const result = numerator % denominator
|
69
|
+
return new Precise (result, rationizerDenominator + other.decimals)
|
70
|
+
}
|
71
|
+
|
72
|
+
sub (other) {
|
73
|
+
const negative = new Precise (-other.integer, other.decimals)
|
74
|
+
return this.add (negative)
|
75
|
+
}
|
76
|
+
|
77
|
+
abs () {
|
78
|
+
return new Precise (this.integer < 0 ? this.integer * minusOne : this.integer, this.decimals)
|
79
|
+
}
|
80
|
+
|
81
|
+
neg () {
|
82
|
+
return new Precise (-this.integer, this.decimals)
|
83
|
+
}
|
84
|
+
|
85
|
+
min (other) {
|
86
|
+
return this.lt (other) ? this : other
|
87
|
+
}
|
88
|
+
|
89
|
+
max (other) {
|
90
|
+
return this.gt (other) ? this : other
|
91
|
+
}
|
92
|
+
|
93
|
+
gt (other) {
|
94
|
+
const sum = this.sub (other)
|
95
|
+
return sum.integer > 0
|
96
|
+
}
|
97
|
+
|
98
|
+
ge (other) {
|
99
|
+
const sum = this.sub (other)
|
100
|
+
return sum.integer >= 0
|
101
|
+
}
|
102
|
+
|
103
|
+
lt (other) {
|
104
|
+
return other.gt (this)
|
105
|
+
}
|
106
|
+
|
107
|
+
le (other) {
|
108
|
+
return other.ge (this)
|
109
|
+
}
|
110
|
+
|
111
|
+
reduce () {
|
112
|
+
const string = this.integer.toString ()
|
113
|
+
const start = string.length - 1
|
114
|
+
if (start === 0) {
|
115
|
+
if (string === '0') {
|
116
|
+
this.decimals = 0
|
117
|
+
}
|
118
|
+
return this
|
119
|
+
}
|
120
|
+
let i
|
121
|
+
for (i = start; i >= 0; i--) {
|
122
|
+
if (string.charAt (i) !== '0') {
|
123
|
+
break
|
124
|
+
}
|
125
|
+
}
|
126
|
+
const difference = start - i
|
127
|
+
if (difference === 0) {
|
128
|
+
return this
|
129
|
+
}
|
130
|
+
this.decimals -= difference
|
131
|
+
this.integer = BigInt (string.slice (0, i + 1))
|
132
|
+
}
|
133
|
+
|
134
|
+
equals (other) {
|
135
|
+
this.reduce ()
|
136
|
+
other.reduce ()
|
137
|
+
return (this.decimals === other.decimals) && (this.integer === other.integer)
|
138
|
+
}
|
139
|
+
|
140
|
+
toString () {
|
141
|
+
this.reduce ()
|
142
|
+
let sign
|
143
|
+
let abs
|
144
|
+
if (this.integer < 0) {
|
145
|
+
sign = '-'
|
146
|
+
abs = -this.integer
|
147
|
+
} else {
|
148
|
+
sign = ''
|
149
|
+
abs = this.integer
|
150
|
+
}
|
151
|
+
const integerArray = Array.from (abs.toString (this.base).padStart (this.decimals, '0'))
|
152
|
+
const index = integerArray.length - this.decimals
|
153
|
+
let item
|
154
|
+
if (index === 0) {
|
155
|
+
// if we are adding to the front
|
156
|
+
item = '0.'
|
157
|
+
} else if (this.decimals < 0) {
|
158
|
+
item = '0'.repeat (-this.decimals)
|
159
|
+
} else if (this.decimals === 0) {
|
160
|
+
item = ''
|
161
|
+
} else {
|
162
|
+
item = '.'
|
163
|
+
}
|
164
|
+
integerArray.splice (index, 0, item)
|
165
|
+
return sign + integerArray.join ('')
|
166
|
+
}
|
167
|
+
|
168
|
+
static stringMul (string1, string2) {
|
169
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
170
|
+
return undefined
|
171
|
+
}
|
172
|
+
return (new Precise (string1)).mul (new Precise (string2)).toString ()
|
173
|
+
}
|
174
|
+
|
175
|
+
static stringDiv (string1, string2, precision = 18) {
|
176
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
177
|
+
return undefined
|
178
|
+
}
|
179
|
+
const string2Precise = new Precise (string2)
|
180
|
+
if (string2Precise.integer === zero) {
|
181
|
+
return undefined
|
182
|
+
}
|
183
|
+
return (new Precise (string1)).div (string2Precise, precision).toString ()
|
184
|
+
}
|
185
|
+
|
186
|
+
static stringAdd (string1, string2) {
|
187
|
+
if ((string1 === undefined) && (string2 === undefined)) {
|
188
|
+
return undefined
|
189
|
+
}
|
190
|
+
if (string1 === undefined) {
|
191
|
+
return string2
|
192
|
+
} else if (string2 === undefined) {
|
193
|
+
return string1
|
194
|
+
}
|
195
|
+
return (new Precise (string1)).add (new Precise (string2)).toString ()
|
196
|
+
}
|
197
|
+
|
198
|
+
static stringSub (string1, string2) {
|
199
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
200
|
+
return undefined
|
201
|
+
}
|
202
|
+
return (new Precise (string1)).sub (new Precise (string2)).toString ()
|
203
|
+
}
|
204
|
+
|
205
|
+
static stringAbs (string) {
|
206
|
+
if (string === undefined) {
|
207
|
+
return undefined
|
208
|
+
}
|
209
|
+
return (new Precise (string)).abs ().toString ()
|
210
|
+
}
|
211
|
+
|
212
|
+
static stringNeg (string) {
|
213
|
+
if (string === undefined) {
|
214
|
+
return undefined
|
215
|
+
}
|
216
|
+
return (new Precise (string)).neg ().toString ()
|
217
|
+
}
|
218
|
+
|
219
|
+
static stringMod (string1, string2) {
|
220
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
221
|
+
return undefined
|
222
|
+
}
|
223
|
+
return (new Precise (string1)).mod (new Precise (string2)).toString ()
|
224
|
+
}
|
225
|
+
|
226
|
+
static stringEquals (string1, string2) {
|
227
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
228
|
+
return undefined
|
229
|
+
}
|
230
|
+
return (new Precise (string1)).equals (new Precise (string2))
|
231
|
+
}
|
232
|
+
|
233
|
+
static stringEq (string1, string2) {
|
234
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
235
|
+
return undefined
|
236
|
+
}
|
237
|
+
return (new Precise (string1)).equals (new Precise (string2))
|
238
|
+
}
|
239
|
+
|
240
|
+
static stringMin (string1, string2) {
|
241
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
242
|
+
return undefined
|
243
|
+
}
|
244
|
+
return (new Precise (string1)).min (new Precise (string2)).toString ()
|
245
|
+
}
|
246
|
+
|
247
|
+
static stringMax (string1, string2) {
|
248
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
249
|
+
return undefined
|
250
|
+
}
|
251
|
+
return (new Precise (string1)).max (new Precise (string2)).toString ()
|
252
|
+
}
|
253
|
+
|
254
|
+
static stringGt (string1, string2) {
|
255
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
256
|
+
return undefined
|
257
|
+
}
|
258
|
+
return (new Precise (string1)).gt (new Precise (string2))
|
259
|
+
}
|
260
|
+
|
261
|
+
static stringGe (string1, string2) {
|
262
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
263
|
+
return undefined
|
264
|
+
}
|
265
|
+
return (new Precise (string1)).ge (new Precise (string2))
|
266
|
+
}
|
267
|
+
|
268
|
+
static stringLt (string1, string2) {
|
269
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
270
|
+
return undefined
|
271
|
+
}
|
272
|
+
return (new Precise (string1)).lt (new Precise (string2))
|
273
|
+
}
|
274
|
+
|
275
|
+
static stringLe (string1, string2) {
|
276
|
+
if ((string1 === undefined) || (string2 === undefined)) {
|
277
|
+
return undefined
|
278
|
+
}
|
279
|
+
return (new Precise (string1)).le (new Precise (string2))
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
module.exports = Precise;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const errorHierarchy = {
|
4
|
+
'BaseError': {
|
5
|
+
'ExchangeError': {
|
6
|
+
'AuthenticationError': {
|
7
|
+
'PermissionDenied': {
|
8
|
+
'AccountNotEnabled': {},
|
9
|
+
},
|
10
|
+
'AccountSuspended': {},
|
11
|
+
},
|
12
|
+
'ArgumentsRequired': {},
|
13
|
+
'BadRequest': {
|
14
|
+
'BadSymbol': {},
|
15
|
+
'MarginModeAlreadySet': {},
|
16
|
+
},
|
17
|
+
'BadResponse': {
|
18
|
+
'NullResponse': {},
|
19
|
+
},
|
20
|
+
'InsufficientFunds': {},
|
21
|
+
'InvalidAddress': {
|
22
|
+
'AddressPending': {},
|
23
|
+
},
|
24
|
+
'InvalidOrder': {
|
25
|
+
'OrderNotFound': {},
|
26
|
+
'OrderNotCached': {},
|
27
|
+
'CancelPending': {},
|
28
|
+
'OrderImmediatelyFillable': {},
|
29
|
+
'OrderNotFillable': {},
|
30
|
+
'DuplicateOrderId': {},
|
31
|
+
},
|
32
|
+
'NotSupported': {},
|
33
|
+
},
|
34
|
+
'NetworkError': {
|
35
|
+
'DDoSProtection': {
|
36
|
+
'RateLimitExceeded': {},
|
37
|
+
},
|
38
|
+
'ExchangeNotAvailable': {
|
39
|
+
'OnMaintenance': {},
|
40
|
+
},
|
41
|
+
'InvalidNonce': {},
|
42
|
+
'RequestTimeout': {},
|
43
|
+
},
|
44
|
+
},
|
45
|
+
};
|
46
|
+
|
47
|
+
module.exports = errorHierarchy;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const errorHierarchy = require ('./errorHierarchy.js')
|
4
|
+
|
5
|
+
/* ------------------------------------------------------------------------ */
|
6
|
+
|
7
|
+
function subclass (BaseClass, classes, namespace = {}) {
|
8
|
+
|
9
|
+
for (const [className, subclasses] of Object.entries (classes)) {
|
10
|
+
|
11
|
+
const Class = Object.assign (namespace, {
|
12
|
+
|
13
|
+
/* By creating a named property, we trick compiler to assign our class constructor function a name.
|
14
|
+
Otherwise, all our error constructors would be shown as [Function: Error] in the debugger! And
|
15
|
+
the super-useful `e.constructor.name` magic wouldn't work — we then would have no chance to
|
16
|
+
obtain a error type string from an error instance programmatically! */
|
17
|
+
|
18
|
+
[className]: class extends BaseClass {
|
19
|
+
|
20
|
+
constructor (message) {
|
21
|
+
|
22
|
+
super (message)
|
23
|
+
|
24
|
+
/* A workaround to make `instanceof` work on custom Error classes in transpiled ES5.
|
25
|
+
See my blog post for the explanation of this hack:
|
26
|
+
|
27
|
+
https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801 */
|
28
|
+
|
29
|
+
this.constructor = Class
|
30
|
+
this.__proto__ = Class.prototype
|
31
|
+
this.name = className
|
32
|
+
this.message = message
|
33
|
+
|
34
|
+
// https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work
|
35
|
+
|
36
|
+
Object.setPrototypeOf (this, Class.prototype)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
})[className]
|
41
|
+
|
42
|
+
subclass (Class, subclasses, namespace)
|
43
|
+
}
|
44
|
+
|
45
|
+
return namespace
|
46
|
+
}
|
47
|
+
|
48
|
+
/* ------------------------------------------------------------------------ */
|
49
|
+
|
50
|
+
module.exports = subclass (
|
51
|
+
// Root class
|
52
|
+
Error,
|
53
|
+
// Derived class hierarchy
|
54
|
+
errorHierarchy
|
55
|
+
)
|
@@ -0,0 +1,158 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
/* ------------------------------------------------------------------------ */
|
4
|
+
|
5
|
+
const CryptoJS = require ('../../static_dependencies/crypto-js/crypto-js')
|
6
|
+
const { capitalize } = require ('./string')
|
7
|
+
const { stringToBase64, urlencodeBase64 } = require ('./encode')
|
8
|
+
const NodeRSA = require ('./../../static_dependencies/node-rsa/NodeRSA')
|
9
|
+
const { binaryToBase58, byteArrayToWordArray } = require ('./encode')
|
10
|
+
const elliptic = require ('./../../static_dependencies/elliptic/lib/elliptic')
|
11
|
+
const EC = elliptic.ec
|
12
|
+
const EDDSA = elliptic.eddsa
|
13
|
+
const { ArgumentsRequired } = require ('./../errors')
|
14
|
+
const BN = require ('../../static_dependencies/BN/bn.js')
|
15
|
+
|
16
|
+
/* ------------------------------------------------------------------------ */
|
17
|
+
|
18
|
+
const hash = (request, hash = 'md5', digest = 'hex') => {
|
19
|
+
const options = {}
|
20
|
+
if (hash === 'keccak') {
|
21
|
+
hash = 'SHA3'
|
22
|
+
options['outputLength'] = 256
|
23
|
+
}
|
24
|
+
const result = CryptoJS[hash.toUpperCase ()] (request, options)
|
25
|
+
return (digest === 'binary') ? result : result.toString (CryptoJS.enc[capitalize (digest)])
|
26
|
+
}
|
27
|
+
|
28
|
+
/* ............................................. */
|
29
|
+
|
30
|
+
const hmac = (request, secret, hash = 'sha256', digest = 'hex') => {
|
31
|
+
const result = CryptoJS['Hmac' + hash.toUpperCase ()] (request, secret)
|
32
|
+
if (digest) {
|
33
|
+
const encoding = (digest === 'binary') ? 'Latin1' : capitalize (digest)
|
34
|
+
return result.toString (CryptoJS.enc[capitalize (encoding)])
|
35
|
+
}
|
36
|
+
return result
|
37
|
+
}
|
38
|
+
|
39
|
+
/* ............................................. */
|
40
|
+
|
41
|
+
function rsa (request, secret, alg = 'RS256') {
|
42
|
+
const algos = {
|
43
|
+
'RS256': 'pkcs1-sha256',
|
44
|
+
'RS512': 'pkcs1-sha512',
|
45
|
+
}
|
46
|
+
if (!(alg in algos)) {
|
47
|
+
throw new ExchangeError (alg + ' is not a supported rsa signing algorithm.')
|
48
|
+
}
|
49
|
+
const algorithm = algos[alg]
|
50
|
+
let key = new NodeRSA (secret, {
|
51
|
+
'environment': 'browser',
|
52
|
+
'signingScheme': algorithm,
|
53
|
+
})
|
54
|
+
return key.sign (request, 'base64', 'binary')
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @return {string}
|
60
|
+
*/
|
61
|
+
function jwt (request, secret, alg = 'HS256') {
|
62
|
+
const algos = {
|
63
|
+
'HS256': 'sha256',
|
64
|
+
'HS384': 'sha384',
|
65
|
+
'HS512': 'sha512',
|
66
|
+
};
|
67
|
+
const encodedHeader = urlencodeBase64 (stringToBase64 (JSON.stringify ({ 'alg': alg, 'typ': 'JWT' })))
|
68
|
+
const encodedData = urlencodeBase64 (stringToBase64 (JSON.stringify (request)))
|
69
|
+
const token = [ encodedHeader, encodedData ].join ('.')
|
70
|
+
const algoType = alg.slice (0, 2);
|
71
|
+
const algorithm = algos[alg]
|
72
|
+
let signature = undefined
|
73
|
+
if (algoType === 'HS') {
|
74
|
+
signature = urlencodeBase64 (hmac (token, secret, algorithm, 'base64'))
|
75
|
+
} else if (algoType === 'RS') {
|
76
|
+
signature = urlencodeBase64 (rsa (token, secret, alg))
|
77
|
+
}
|
78
|
+
return [ token, signature ].join ('.')
|
79
|
+
}
|
80
|
+
|
81
|
+
function ecdsa (request, secret, algorithm = 'p256', hashFunction = undefined, fixedLength = false) {
|
82
|
+
let digest = request
|
83
|
+
if (hashFunction !== undefined) {
|
84
|
+
digest = hash (request, hashFunction, 'hex')
|
85
|
+
}
|
86
|
+
const curve = new EC (algorithm)
|
87
|
+
let signature = curve.sign (digest, secret, 'hex', { 'canonical': true })
|
88
|
+
let counter = new BN ('0')
|
89
|
+
const minimum_size = new BN ('1').shln (8 * 31).sub (new BN ('1'))
|
90
|
+
while (fixedLength && (signature.r.gt (curve.nh) || signature.r.lte (minimum_size) || signature.s.lte (minimum_size))) {
|
91
|
+
signature = curve.sign (digest, secret, 'hex', { 'canonical': true, 'extraEntropy': counter.toArray ('le', 32)})
|
92
|
+
counter = counter.add (new BN ('1'))
|
93
|
+
}
|
94
|
+
return {
|
95
|
+
'r': signature.r.toString (16).padStart (64, '0'),
|
96
|
+
's': signature.s.toString (16).padStart (64, '0'),
|
97
|
+
'v': signature.recoveryParam,
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
function eddsa (request, secret, algorithm = 'ed25519') {
|
103
|
+
// used for waves.exchange (that's why the output is base58)
|
104
|
+
const curve = new EDDSA (algorithm)
|
105
|
+
const signature = curve.signModified (request, secret)
|
106
|
+
return binaryToBase58 (byteArrayToWordArray (signature.toBytes ()))
|
107
|
+
}
|
108
|
+
|
109
|
+
/* ------------------------------------------------------------------------ */
|
110
|
+
|
111
|
+
const totp = (secret) => {
|
112
|
+
|
113
|
+
const dec2hex = s => ((s < 15.5 ? '0' : '') + Math.round (s).toString (16))
|
114
|
+
, hex2dec = s => parseInt (s, 16)
|
115
|
+
, leftpad = (s, p) => (p + s).slice (-p.length) // both s and p are short strings
|
116
|
+
|
117
|
+
const base32tohex = (base32) => {
|
118
|
+
let base32chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
|
119
|
+
let bits = ''
|
120
|
+
let hex = ''
|
121
|
+
for (let i = 0; i < base32.length; i++) {
|
122
|
+
let val = base32chars.indexOf (base32.charAt (i).toUpperCase ())
|
123
|
+
bits += leftpad (val.toString (2), '00000')
|
124
|
+
}
|
125
|
+
for (let i = 0; i + 4 <= bits.length; i += 4) {
|
126
|
+
let chunk = bits.substr (i, 4)
|
127
|
+
hex = hex + parseInt (chunk, 2).toString (16)
|
128
|
+
}
|
129
|
+
return hex
|
130
|
+
}
|
131
|
+
|
132
|
+
const getOTP = (secret) => {
|
133
|
+
secret = secret.replace (' ', '') // support 2fa-secrets with spaces like "4TDV WOGO" → "4TDVWOGO"
|
134
|
+
let epoch = Math.round (new Date ().getTime () / 1000.0)
|
135
|
+
let time = leftpad (dec2hex (Math.floor (epoch / 30)), '0000000000000000')
|
136
|
+
let hmacRes = hmac (CryptoJS.enc.Hex.parse (time), CryptoJS.enc.Hex.parse (base32tohex (secret)), 'sha1', 'hex')
|
137
|
+
let offset = hex2dec (hmacRes.substring (hmacRes.length - 1))
|
138
|
+
let otp = (hex2dec (hmacRes.substr (offset * 2, 8)) & hex2dec ('7fffffff')) + ''
|
139
|
+
otp = (otp).substr (otp.length - 6, 6)
|
140
|
+
return otp
|
141
|
+
}
|
142
|
+
|
143
|
+
return getOTP (secret)
|
144
|
+
}
|
145
|
+
|
146
|
+
/* ------------------------------------------------------------------------ */
|
147
|
+
|
148
|
+
module.exports = {
|
149
|
+
hash,
|
150
|
+
hmac,
|
151
|
+
jwt,
|
152
|
+
totp,
|
153
|
+
rsa,
|
154
|
+
ecdsa,
|
155
|
+
eddsa,
|
156
|
+
}
|
157
|
+
|
158
|
+
/* ------------------------------------------------------------------------ */
|
@@ -0,0 +1,118 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
/* ------------------------------------------------------------------------ */
|
4
|
+
|
5
|
+
const CryptoJS = require ('../../static_dependencies/crypto-js/crypto-js')
|
6
|
+
const qs = require ('../../static_dependencies/qs/index')
|
7
|
+
const BN = require ('../../static_dependencies/BN/bn')
|
8
|
+
|
9
|
+
|
10
|
+
/* ------------------------------------------------------------------------ */
|
11
|
+
|
12
|
+
// global vars for base58 encoding
|
13
|
+
const base58Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
14
|
+
let base58Decoder = null
|
15
|
+
let base58Encoder = null
|
16
|
+
|
17
|
+
/* ------------------------------------------------------------------------ */
|
18
|
+
|
19
|
+
module.exports =
|
20
|
+
|
21
|
+
{ json: (data, params = undefined) => JSON.stringify (data)
|
22
|
+
|
23
|
+
, isJsonEncodedObject: object => (
|
24
|
+
(typeof object === 'string') &&
|
25
|
+
(object.length >= 2) &&
|
26
|
+
((object[0] === '{') || (object[0] === '['))
|
27
|
+
)
|
28
|
+
|
29
|
+
, stringToBinary: string => CryptoJS.enc.Latin1.parse (string)
|
30
|
+
, stringToBase64: string => CryptoJS.enc.Latin1.parse (string).toString (CryptoJS.enc.Base64)
|
31
|
+
, base64ToBinary: string => CryptoJS.enc.Base64.parse (string)
|
32
|
+
, base64ToString: string => CryptoJS.enc.Base64.parse (string).toString (CryptoJS.enc.Utf8)
|
33
|
+
, binaryToBase64: binary => binary.toString (CryptoJS.enc.Base64)
|
34
|
+
, base16ToBinary: string => CryptoJS.enc.Hex.parse (string)
|
35
|
+
, binaryToBase16: binary => binary.toString (CryptoJS.enc.Hex)
|
36
|
+
, binaryConcat: (...args) => args.reduce ((a, b) => a.concat (b))
|
37
|
+
, binaryConcatArray: (arr) => arr.reduce ((a, b) => a.concat (b))
|
38
|
+
|
39
|
+
, urlencode: object => qs.stringify (object)
|
40
|
+
, urlencodeNested: object => qs.stringify (object) // implemented only in python
|
41
|
+
, urlencodeWithArrayRepeat: object => qs.stringify (object, { arrayFormat: 'repeat' })
|
42
|
+
, rawencode: object => qs.stringify (object, { encode: false })
|
43
|
+
, encode: x => x
|
44
|
+
, decode: x => x
|
45
|
+
|
46
|
+
// Url-safe-base64 without equals signs, with + replaced by - and slashes replaced by underscores
|
47
|
+
|
48
|
+
, urlencodeBase64: base64string => base64string.replace (/[=]+$/, '')
|
49
|
+
.replace (/\+/g, '-')
|
50
|
+
.replace (/\//g, '_')
|
51
|
+
|
52
|
+
, numberToLE: (n, padding) => {
|
53
|
+
const hexArray = new BN (n).toArray ('le', padding)
|
54
|
+
return byteArrayToWordArray (hexArray)
|
55
|
+
}
|
56
|
+
|
57
|
+
, numberToBE: (n, padding) => {
|
58
|
+
const hexArray = new BN (n).toArray ('be', padding)
|
59
|
+
return byteArrayToWordArray (hexArray)
|
60
|
+
}
|
61
|
+
|
62
|
+
, base58ToBinary: (string) => {
|
63
|
+
if (!base58Decoder) {
|
64
|
+
base58Decoder = {}
|
65
|
+
base58Encoder = {}
|
66
|
+
for (let i = 0; i < 58; i++) {
|
67
|
+
const c = base58Alphabet[i]
|
68
|
+
const bigNum = new BN (i)
|
69
|
+
base58Decoder[c] = bigNum
|
70
|
+
base58Encoder[bigNum] = c
|
71
|
+
}
|
72
|
+
}
|
73
|
+
let result = new BN (0)
|
74
|
+
const base = new BN (58)
|
75
|
+
for (let i = 0; i < string.length; i++) {
|
76
|
+
const character = string[i]
|
77
|
+
result.imul (base)
|
78
|
+
result.iadd (base58Decoder[character])
|
79
|
+
}
|
80
|
+
return byteArrayToWordArray (result.toArray ('be'))
|
81
|
+
}
|
82
|
+
|
83
|
+
, binaryToBase58: (wordArray) => {
|
84
|
+
if (!base58Encoder) {
|
85
|
+
base58Decoder = {}
|
86
|
+
base58Encoder = {}
|
87
|
+
for (let i = 0; i < 58; i++) {
|
88
|
+
const c = base58Alphabet[i]
|
89
|
+
const bigNum = new BN (i)
|
90
|
+
base58Decoder[c] = bigNum
|
91
|
+
base58Encoder[bigNum] = c
|
92
|
+
}
|
93
|
+
}
|
94
|
+
const base = new BN (58)
|
95
|
+
// hex is only compatible encoding between cryptojs and BN
|
96
|
+
const hexString = wordArray.toString (CryptoJS.enc.Hex)
|
97
|
+
let result = new BN (hexString, 16)
|
98
|
+
let string = []
|
99
|
+
while (!result.isZero ()) {
|
100
|
+
const { div, mod } = result.divmod (base)
|
101
|
+
result = div
|
102
|
+
string.push (base58Encoder[mod])
|
103
|
+
}
|
104
|
+
return string.reverse ().join ('')
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
function byteArrayToWordArray (ba) {
|
109
|
+
const wa = []
|
110
|
+
for (let i = 0; i < ba.length; i++) {
|
111
|
+
wa[(i / 4) | 0] |= ba[i] << (24 - 8 * i)
|
112
|
+
}
|
113
|
+
return CryptoJS.lib.WordArray.create (wa, ba.length)
|
114
|
+
}
|
115
|
+
|
116
|
+
module.exports['byteArrayToWordArray'] = byteArrayToWordArray
|
117
|
+
|
118
|
+
/* ------------------------------------------------------------------------ */
|