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.
Files changed (264) hide show
  1. package/.cache/eslintcache +1 -0
  2. package/.dockerignore +6 -0
  3. package/.eslintignore +1 -0
  4. package/.gitattributes +5 -0
  5. package/.readthedocs.yaml +16 -0
  6. package/CONTRIBUTING.md +1049 -0
  7. package/LICENSE.txt +21 -0
  8. package/README.md +537 -0
  9. package/SECURITY.md +5 -0
  10. package/build/cleanup-old-tags.js +94 -0
  11. package/build/countries.js +256 -0
  12. package/build/export-exchanges.js +520 -0
  13. package/build/fs.js +51 -0
  14. package/build/transpile.js +1772 -0
  15. package/build/vss.js +78 -0
  16. package/ccxt.browser.js +7 -0
  17. package/ccxt.d.ts +692 -0
  18. package/ccxt.js +171 -0
  19. package/cleanup.sh +2 -0
  20. package/composer-install.sh +20 -0
  21. package/dist/ccxt.browser.js +208383 -0
  22. package/gource.sh +3 -0
  23. package/index.html +7 -0
  24. package/js/.eslintrc +87 -0
  25. package/js/aax.js +2686 -0
  26. package/js/ascendex.js +2584 -0
  27. package/js/base/.eslintrc.js +43 -0
  28. package/js/base/Exchange.js +2371 -0
  29. package/js/base/Precise.js +283 -0
  30. package/js/base/errorHierarchy.js +47 -0
  31. package/js/base/errors.js +55 -0
  32. package/js/base/functions/crypto.js +158 -0
  33. package/js/base/functions/encode.js +118 -0
  34. package/js/base/functions/generic.js +270 -0
  35. package/js/base/functions/misc.js +138 -0
  36. package/js/base/functions/number.js +329 -0
  37. package/js/base/functions/platform.js +38 -0
  38. package/js/base/functions/string.js +21 -0
  39. package/js/base/functions/throttle.js +79 -0
  40. package/js/base/functions/time.js +210 -0
  41. package/js/base/functions/type.js +66 -0
  42. package/js/base/functions.js +28 -0
  43. package/js/bequant.js +32 -0
  44. package/js/bibox.js +1407 -0
  45. package/js/bigone.js +1366 -0
  46. package/js/binance.js +5652 -0
  47. package/js/binancecoinm.js +46 -0
  48. package/js/binanceus.js +46 -0
  49. package/js/binanceusdm.js +49 -0
  50. package/js/bit2c.js +535 -0
  51. package/js/bitbank.js +842 -0
  52. package/js/bitbay.js +16 -0
  53. package/js/bitbns.js +1073 -0
  54. package/js/bitcoincom.js +15 -0
  55. package/js/bitfinex.js +1433 -0
  56. package/js/bitfinex2.js +2025 -0
  57. package/js/bitflyer.js +840 -0
  58. package/js/bitforex.js +614 -0
  59. package/js/bitget.js +2397 -0
  60. package/js/bithumb.js +980 -0
  61. package/js/bitmart.js +2516 -0
  62. package/js/bitmex.js +1809 -0
  63. package/js/bitopro.js +1443 -0
  64. package/js/bitpanda.js +1782 -0
  65. package/js/bitrue.js +1747 -0
  66. package/js/bitso.js +1062 -0
  67. package/js/bitstamp.js +1757 -0
  68. package/js/bitstamp1.js +343 -0
  69. package/js/bittrex.js +1876 -0
  70. package/js/bitvavo.js +1579 -0
  71. package/js/bkex.js +1233 -0
  72. package/js/bl3p.js +346 -0
  73. package/js/blockchaincom.js +969 -0
  74. package/js/btcalpha.js +680 -0
  75. package/js/btcbox.js +477 -0
  76. package/js/btcmarkets.js +1022 -0
  77. package/js/btctradeua.js +466 -0
  78. package/js/btcturk.js +734 -0
  79. package/js/buda.js +946 -0
  80. package/js/bw.js +1265 -0
  81. package/js/bybit.js +3372 -0
  82. package/js/bytetrade.js +1336 -0
  83. package/js/cdax.js +1646 -0
  84. package/js/cex.js +1410 -0
  85. package/js/coinbase.js +1342 -0
  86. package/js/coinbaseprime.js +31 -0
  87. package/js/coinbasepro.js +1466 -0
  88. package/js/coincheck.js +755 -0
  89. package/js/coinex.js +3400 -0
  90. package/js/coinfalcon.js +880 -0
  91. package/js/coinmate.js +794 -0
  92. package/js/coinone.js +816 -0
  93. package/js/coinspot.js +345 -0
  94. package/js/crex24.js +1636 -0
  95. package/js/cryptocom.js +1832 -0
  96. package/js/currencycom.js +1748 -0
  97. package/js/delta.js +1547 -0
  98. package/js/deribit.js +2148 -0
  99. package/js/digifinex.js +1585 -0
  100. package/js/eqonex.js +1660 -0
  101. package/js/exmo.js +1670 -0
  102. package/js/fairdesk.js +1231 -0
  103. package/js/flowbtc.js +35 -0
  104. package/js/fmfwio.js +34 -0
  105. package/js/ftx.js +2751 -0
  106. package/js/ftxus.js +38 -0
  107. package/js/gateio.js +4174 -0
  108. package/js/gemini.js +1397 -0
  109. package/js/hitbtc.js +1343 -0
  110. package/js/hitbtc3.js +2329 -0
  111. package/js/hollaex.js +1486 -0
  112. package/js/huobi.js +5706 -0
  113. package/js/huobijp.js +1710 -0
  114. package/js/huobipro.js +18 -0
  115. package/js/idex.js +1439 -0
  116. package/js/independentreserve.js +649 -0
  117. package/js/indodax.js +742 -0
  118. package/js/itbit.js +722 -0
  119. package/js/kraken.js +2179 -0
  120. package/js/kucoin.js +2571 -0
  121. package/js/kucoinfutures.js +1771 -0
  122. package/js/kuna.js +809 -0
  123. package/js/latoken.js +1445 -0
  124. package/js/lbank.js +760 -0
  125. package/js/liquid.js +1432 -0
  126. package/js/luno.js +873 -0
  127. package/js/lykke.js +1147 -0
  128. package/js/mercado.js +771 -0
  129. package/js/mexc.js +3151 -0
  130. package/js/ndax.js +2233 -0
  131. package/js/novadax.js +1318 -0
  132. package/js/oceanex.js +816 -0
  133. package/js/okcoin.js +3841 -0
  134. package/js/okex.js +16 -0
  135. package/js/okex5.js +16 -0
  136. package/js/okx.js +4795 -0
  137. package/js/paymium.js +498 -0
  138. package/js/phemex.js +2957 -0
  139. package/js/poloniex.js +1674 -0
  140. package/js/probit.js +1346 -0
  141. package/js/qtrade.js +1588 -0
  142. package/js/ripio.js +1061 -0
  143. package/js/static_dependencies/BN/bn.js +3526 -0
  144. package/js/static_dependencies/README.md +1 -0
  145. package/js/static_dependencies/crypto-js/crypto-js.js +5988 -0
  146. package/js/static_dependencies/elliptic/lib/elliptic/curve/base.js +375 -0
  147. package/js/static_dependencies/elliptic/lib/elliptic/curve/edwards.js +433 -0
  148. package/js/static_dependencies/elliptic/lib/elliptic/curve/index.js +8 -0
  149. package/js/static_dependencies/elliptic/lib/elliptic/curve/mont.js +180 -0
  150. package/js/static_dependencies/elliptic/lib/elliptic/curve/short.js +938 -0
  151. package/js/static_dependencies/elliptic/lib/elliptic/curves.js +204 -0
  152. package/js/static_dependencies/elliptic/lib/elliptic/ec/index.js +240 -0
  153. package/js/static_dependencies/elliptic/lib/elliptic/ec/key.js +119 -0
  154. package/js/static_dependencies/elliptic/lib/elliptic/ec/signature.js +24 -0
  155. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/index.js +145 -0
  156. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/key.js +100 -0
  157. package/js/static_dependencies/elliptic/lib/elliptic/eddsa/signature.js +65 -0
  158. package/js/static_dependencies/elliptic/lib/elliptic/precomputed/secp256k1.js +780 -0
  159. package/js/static_dependencies/elliptic/lib/elliptic/utils.js +214 -0
  160. package/js/static_dependencies/elliptic/lib/elliptic.js +22 -0
  161. package/js/static_dependencies/elliptic/lib/hmac-drbg/hmac-drbg.js +114 -0
  162. package/js/static_dependencies/fetch-ponyfill/fetch-node.js +39 -0
  163. package/js/static_dependencies/node-fetch/index.js +1564 -0
  164. package/js/static_dependencies/node-rsa/NodeRSA.js +223 -0
  165. package/js/static_dependencies/node-rsa/asn1/ber/errors.js +13 -0
  166. package/js/static_dependencies/node-rsa/asn1/ber/index.js +21 -0
  167. package/js/static_dependencies/node-rsa/asn1/ber/reader.js +262 -0
  168. package/js/static_dependencies/node-rsa/asn1/ber/types.js +36 -0
  169. package/js/static_dependencies/node-rsa/asn1/index.js +17 -0
  170. package/js/static_dependencies/node-rsa/encryptEngines/js.js +34 -0
  171. package/js/static_dependencies/node-rsa/formats/components.js +71 -0
  172. package/js/static_dependencies/node-rsa/formats/formats.js +31 -0
  173. package/js/static_dependencies/node-rsa/formats/pkcs1.js +148 -0
  174. package/js/static_dependencies/node-rsa/formats/pkcs8.js +187 -0
  175. package/js/static_dependencies/node-rsa/libs/jsbn.js +1252 -0
  176. package/js/static_dependencies/node-rsa/libs/rsa.js +147 -0
  177. package/js/static_dependencies/node-rsa/schemes/pkcs1.js +176 -0
  178. package/js/static_dependencies/node-rsa/schemes/schemes.js +21 -0
  179. package/js/static_dependencies/node-rsa/utils.js +98 -0
  180. package/js/static_dependencies/qs/formats.js +18 -0
  181. package/js/static_dependencies/qs/index.js +11 -0
  182. package/js/static_dependencies/qs/parse.js +242 -0
  183. package/js/static_dependencies/qs/stringify.js +269 -0
  184. package/js/static_dependencies/qs/utils.js +230 -0
  185. package/js/stex.js +1925 -0
  186. package/js/test/.eslintrc.js +42 -0
  187. package/js/test/Exchange/test.balance.js +61 -0
  188. package/js/test/Exchange/test.borrowRate.js +32 -0
  189. package/js/test/Exchange/test.currency.js +52 -0
  190. package/js/test/Exchange/test.fetchBalance.js +23 -0
  191. package/js/test/Exchange/test.fetchBorrowInterest.js +59 -0
  192. package/js/test/Exchange/test.fetchBorrowRate.js +32 -0
  193. package/js/test/Exchange/test.fetchBorrowRates.js +28 -0
  194. package/js/test/Exchange/test.fetchClosedOrders.js +32 -0
  195. package/js/test/Exchange/test.fetchCurrencies.js +35 -0
  196. package/js/test/Exchange/test.fetchDeposits.js +31 -0
  197. package/js/test/Exchange/test.fetchFundingFees.js +19 -0
  198. package/js/test/Exchange/test.fetchFundingRateHistory.js +40 -0
  199. package/js/test/Exchange/test.fetchL2OrderBook.js +23 -0
  200. package/js/test/Exchange/test.fetchLedger.js +42 -0
  201. package/js/test/Exchange/test.fetchLeverageTiers.js +33 -0
  202. package/js/test/Exchange/test.fetchMarketLeverageTiers.js +22 -0
  203. package/js/test/Exchange/test.fetchMarkets.js +33 -0
  204. package/js/test/Exchange/test.fetchMyTrades.js +42 -0
  205. package/js/test/Exchange/test.fetchOHLCV.js +46 -0
  206. package/js/test/Exchange/test.fetchOpenOrders.js +36 -0
  207. package/js/test/Exchange/test.fetchOrderBook.js +25 -0
  208. package/js/test/Exchange/test.fetchOrderBooks.js +35 -0
  209. package/js/test/Exchange/test.fetchOrders.js +41 -0
  210. package/js/test/Exchange/test.fetchPositions.js +47 -0
  211. package/js/test/Exchange/test.fetchStatus.js +35 -0
  212. package/js/test/Exchange/test.fetchTicker.js +38 -0
  213. package/js/test/Exchange/test.fetchTickers.js +49 -0
  214. package/js/test/Exchange/test.fetchTrades.js +39 -0
  215. package/js/test/Exchange/test.fetchTradingFee.js +18 -0
  216. package/js/test/Exchange/test.fetchTradingFees.js +22 -0
  217. package/js/test/Exchange/test.fetchTransactions.js +31 -0
  218. package/js/test/Exchange/test.fetchWithdrawals.js +31 -0
  219. package/js/test/Exchange/test.ledgerItem.js +46 -0
  220. package/js/test/Exchange/test.leverageTier.js +33 -0
  221. package/js/test/Exchange/test.loadMarkets.js +35 -0
  222. package/js/test/Exchange/test.market.js +129 -0
  223. package/js/test/Exchange/test.ohlcv.js +33 -0
  224. package/js/test/Exchange/test.order.js +62 -0
  225. package/js/test/Exchange/test.orderbook.js +61 -0
  226. package/js/test/Exchange/test.position.js +21 -0
  227. package/js/test/Exchange/test.throttle.js +94 -0
  228. package/js/test/Exchange/test.ticker.js +95 -0
  229. package/js/test/Exchange/test.trade.js +68 -0
  230. package/js/test/Exchange/test.tradingFee.js +34 -0
  231. package/js/test/Exchange/test.transaction.js +35 -0
  232. package/js/test/base/.eslintrc +38 -0
  233. package/js/test/base/functions/test.crypto.js +110 -0
  234. package/js/test/base/functions/test.datetime.js +62 -0
  235. package/js/test/base/functions/test.generic.js +152 -0
  236. package/js/test/base/functions/test.number.js +362 -0
  237. package/js/test/base/functions/test.time.js +56 -0
  238. package/js/test/base/functions/test.type.js +53 -0
  239. package/js/test/base/test.base.js +193 -0
  240. package/js/test/errors/test.InsufficientFunds.js +86 -0
  241. package/js/test/errors/test.InvalidNonce.js +64 -0
  242. package/js/test/errors/test.InvalidOrder.js +35 -0
  243. package/js/test/errors/test.OrderNotFound.js +39 -0
  244. package/js/test/test.js +426 -0
  245. package/js/test/test.timeout_hang.js +12 -0
  246. package/js/therock.js +1431 -0
  247. package/js/tidebit.js +632 -0
  248. package/js/tidex.js +939 -0
  249. package/js/timex.js +1283 -0
  250. package/js/upbit.js +1622 -0
  251. package/js/vcc.js +1353 -0
  252. package/js/wavesexchange.js +2185 -0
  253. package/js/wazirx.js +732 -0
  254. package/js/whitebit.js +1352 -0
  255. package/js/woo.js +1577 -0
  256. package/js/xena.js +1948 -0
  257. package/js/yobit.js +1129 -0
  258. package/js/zaif.js +647 -0
  259. package/js/zb.js +4088 -0
  260. package/js/zipmex.js +40 -0
  261. package/js/zonda.js +1497 -0
  262. package/multilang.sh +159 -0
  263. package/package.json +591 -0
  264. package/postinstall.js +103 -0
@@ -0,0 +1,147 @@
1
+ /*
2
+ * RSA Encryption / Decryption with PKCS1 v2 Padding.
3
+ *
4
+ * ~MIT License~
5
+ * Contributors:
6
+ * Tom Wu, rzcoder, frosty00
7
+ */
8
+
9
+ var _ = require('../utils')._;
10
+ var BigInteger = require('./jsbn.js');
11
+ var utils = require('../utils.js');
12
+ var schemes = require('../schemes/schemes.js');
13
+
14
+ //exports.BigInteger = BigInteger;
15
+ module.exports.Key = (function () {
16
+ /**
17
+ * RSA key constructor
18
+ *
19
+ * n - modulus
20
+ * e - publicExponent
21
+ * d - privateExponent
22
+ * p - prime1
23
+ * q - prime2
24
+ * dmp1 - exponent1 -- d mod (p1)
25
+ * dmq1 - exponent2 -- d mod (q-1)
26
+ * coeff - coefficient -- (inverse of q) mod p
27
+ */
28
+ function RSAKey() {
29
+ this.n = null;
30
+ this.e = 0;
31
+ this.d = null;
32
+ this.p = null;
33
+ this.q = null;
34
+ this.dmp1 = null;
35
+ this.dmq1 = null;
36
+ this.coeff = null;
37
+ }
38
+
39
+ RSAKey.prototype.setOptions = function (options) {
40
+ var signingSchemeProvider = schemes[options.signingScheme];
41
+ var encryptionSchemeProvider = schemes[options.encryptionScheme];
42
+
43
+ if (signingSchemeProvider === encryptionSchemeProvider) {
44
+ this.signingScheme = this.encryptionScheme = encryptionSchemeProvider.makeScheme(this, options);
45
+ } else {
46
+ this.encryptionScheme = encryptionSchemeProvider.makeScheme(this, options);
47
+ this.signingScheme = signingSchemeProvider.makeScheme(this, options);
48
+ }
49
+
50
+ };
51
+ /**
52
+ * Set the private key fields N, e, d and CRT params from buffers
53
+ *
54
+ * @param N
55
+ * @param E
56
+ * @param D
57
+ * @param P
58
+ * @param Q
59
+ * @param DP
60
+ * @param DQ
61
+ * @param C
62
+ */
63
+ RSAKey.prototype.setPrivate = function (N, E, D, P, Q, DP, DQ, C) {
64
+ if (N && E && D && N.length > 0 && (_.isNumber(E) || E.length > 0) && D.length > 0) {
65
+ this.n = new BigInteger(N);
66
+ this.e = _.isNumber(E) ? E : utils.get32IntFromBuffer(E, 0);
67
+ this.d = new BigInteger(D);
68
+
69
+ if (P && Q && DP && DQ && C) {
70
+ this.p = new BigInteger(P);
71
+ this.q = new BigInteger(Q);
72
+ this.dmp1 = new BigInteger(DP);
73
+ this.dmq1 = new BigInteger(DQ);
74
+ this.coeff = new BigInteger(C);
75
+ } else {
76
+ // TODO: re-calculate any missing CRT params
77
+ }
78
+ this.$$recalculateCache();
79
+ } else {
80
+ throw Error("Invalid RSA private key");
81
+ }
82
+ };
83
+
84
+ /**
85
+ * private
86
+ * Perform raw private operation on "x": return x^d (mod n)
87
+ *
88
+ * @param x
89
+ * @returns {*}
90
+ */
91
+ RSAKey.prototype.$doPrivate = function (x) {
92
+ if (this.p || this.q) {
93
+ return x.modPow(this.d, this.n);
94
+ }
95
+
96
+ // TODO: re-calculate any missing CRT params
97
+ var xp = x.mod(this.p).modPow(this.dmp1, this.p);
98
+ var xq = x.mod(this.q).modPow(this.dmq1, this.q);
99
+
100
+ while (xp.compareTo(xq) < 0) {
101
+ xp = xp.add(this.p);
102
+ }
103
+ return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
104
+ };
105
+
106
+ RSAKey.prototype.sign = function (buffer) {
107
+ return this.signingScheme.sign.apply(this.signingScheme, arguments);
108
+ };
109
+
110
+ /**
111
+ * Check if key pair contains private key
112
+ */
113
+ RSAKey.prototype.isPrivate = function () {
114
+ return this.n && this.e && this.d || false;
115
+ };
116
+
117
+ Object.defineProperty(RSAKey.prototype, 'keySize', {
118
+ get: function () {
119
+ return this.cache.keyBitLength;
120
+ }
121
+ });
122
+
123
+ Object.defineProperty(RSAKey.prototype, 'encryptedDataLength', {
124
+ get: function () {
125
+ return this.cache.keyByteLength;
126
+ }
127
+ });
128
+
129
+ Object.defineProperty(RSAKey.prototype, 'maxMessageLength', {
130
+ get: function () {
131
+ return this.encryptionScheme.maxMessageLength();
132
+ }
133
+ });
134
+
135
+ /**
136
+ * Caching key data
137
+ */
138
+ RSAKey.prototype.$$recalculateCache = function () {
139
+ this.cache = this.cache || {};
140
+ // Bit & byte length
141
+ this.cache.keyBitLength = this.n.bitLength();
142
+ this.cache.keyByteLength = (this.cache.keyBitLength + 6) >> 3;
143
+ };
144
+
145
+ return RSAKey;
146
+ })();
147
+
@@ -0,0 +1,176 @@
1
+ /**
2
+ * PKCS1 padding and signature scheme
3
+ */
4
+
5
+ var BigInteger = require('../libs/jsbn');
6
+ var CryptoJS = require('../../crypto-js/crypto-js');
7
+ var constants = { RSA_NO_PADDING: 3 }
8
+ require('constants');
9
+ var SIGN_INFO_HEAD = {
10
+ md2: Buffer.from('3020300c06082a864886f70d020205000410', 'hex'),
11
+ md5: Buffer.from('3020300c06082a864886f70d020505000410', 'hex'),
12
+ sha1: Buffer.from('3021300906052b0e03021a05000414', 'hex'),
13
+ sha224: Buffer.from('302d300d06096086480165030402040500041c', 'hex'),
14
+ sha256: Buffer.from('3031300d060960864801650304020105000420', 'hex'),
15
+ sha384: Buffer.from('3041300d060960864801650304020205000430', 'hex'),
16
+ sha512: Buffer.from('3051300d060960864801650304020305000440', 'hex'),
17
+ ripemd160: Buffer.from('3021300906052b2403020105000414', 'hex'),
18
+ rmd160: Buffer.from('3021300906052b2403020105000414', 'hex')
19
+ };
20
+
21
+ var SIGN_ALG_TO_HASH_ALIASES = {
22
+ 'ripemd160': 'rmd160'
23
+ };
24
+
25
+ var DEFAULT_HASH_FUNCTION = 'sha256';
26
+
27
+ module.exports = {
28
+ isEncryption: true,
29
+ isSignature: true
30
+ };
31
+
32
+ module.exports.makeScheme = function (key, options) {
33
+ function Scheme(key, options) {
34
+ this.key = key;
35
+ this.options = options;
36
+ }
37
+
38
+ Scheme.prototype.maxMessageLength = function () {
39
+ if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) {
40
+ return this.key.encryptedDataLength;
41
+ }
42
+ return this.key.encryptedDataLength - 11;
43
+ };
44
+
45
+ /**
46
+ * Unpad input Buffer and, if valid, return the Buffer object
47
+ * alg: PKCS#1 (type 2, random)
48
+ * @param buffer
49
+ * @returns {Buffer}
50
+ */
51
+ Scheme.prototype.encUnPad = function (buffer, options) {
52
+ options = options || {};
53
+ var i = 0;
54
+
55
+ if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == constants.RSA_NO_PADDING) {
56
+ //RSA_NO_PADDING treated like JAVA left pad with zero character
57
+ var unPad;
58
+ if (typeof buffer.lastIndexOf == "function") { //patch for old node version
59
+ unPad = buffer.slice(buffer.lastIndexOf('\0') + 1, buffer.length);
60
+ } else {
61
+ unPad = buffer.slice(String.prototype.lastIndexOf.call(buffer, '\0') + 1, buffer.length);
62
+ }
63
+ return unPad;
64
+ }
65
+
66
+ if (buffer.length < 4) {
67
+ return null;
68
+ }
69
+
70
+ /* Type 1: zeros padding for private key decrypt */
71
+ if (options.type === 1) {
72
+ if (buffer[0] !== 0 && buffer[1] !== 1) {
73
+ return null;
74
+ }
75
+ i = 3;
76
+ while (buffer[i] !== 0) {
77
+ if (buffer[i] != 0xFF || ++i >= buffer.length) {
78
+ return null;
79
+ }
80
+ }
81
+ } else {
82
+ /* random padding for public key decrypt */
83
+ if (buffer[0] !== 0 && buffer[1] !== 2) {
84
+ return null;
85
+ }
86
+ i = 3;
87
+ while (buffer[i] !== 0) {
88
+ if (++i >= buffer.length) {
89
+ return null;
90
+ }
91
+ }
92
+ }
93
+ return buffer.slice(i + 1, buffer.length);
94
+ };
95
+
96
+ Scheme.prototype.sign = function (buffer) {
97
+ var hashAlgorithm = this.options.signingSchemeOptions.hash || DEFAULT_HASH_FUNCTION;
98
+ if (this.options.environment === 'browser') {
99
+ hashAlgorithm = SIGN_ALG_TO_HASH_ALIASES[hashAlgorithm] || hashAlgorithm;
100
+ var hasher = CryptoJS[hashAlgorithm.toUpperCase()] (buffer.toString());
101
+ var asBuffer = wordArrayToBuffer(hasher)
102
+ var paddedHash = this.pkcs1pad(asBuffer, hashAlgorithm);
103
+ var res = this.key.$doPrivate(new BigInteger(paddedHash)).toBuffer(this.key.encryptedDataLength);
104
+ return res;
105
+ } else {
106
+ throw new Error ('CCXT only supports browser mode :P');
107
+ }
108
+ };
109
+
110
+ /**
111
+ * PKCS#1 pad input buffer to max data length
112
+ * @param hashBuf
113
+ * @param hashAlgorithm
114
+ * @returns {*}
115
+ */
116
+ Scheme.prototype.pkcs1pad = function (hashBuf, hashAlgorithm) {
117
+ var digest = SIGN_INFO_HEAD[hashAlgorithm];
118
+ if (!digest) {
119
+ throw Error('Unsupported hash algorithm');
120
+ }
121
+
122
+ var data = Buffer.concat([digest, hashBuf]);
123
+
124
+ if (data.length + 10 > this.key.encryptedDataLength) {
125
+ throw Error('Key is too short for signing algorithm (' + hashAlgorithm + ')');
126
+ }
127
+
128
+ var filled = Buffer.alloc(this.key.encryptedDataLength - data.length - 1);
129
+ filled.fill(0xff, 0, filled.length - 1);
130
+ filled[0] = 1;
131
+ filled[filled.length - 1] = 0;
132
+
133
+ var res = Buffer.concat([filled, data]);
134
+
135
+ return res;
136
+ };
137
+
138
+ return new Scheme(key, options);
139
+ };
140
+
141
+ // used to convert `CryptoJS` wordArrays into `crypto` hex buffers
142
+ function wordToByteArray(word, length) {
143
+ var ba = [],
144
+ xFF = 0xFF;
145
+ if (length > 0)
146
+ ba.push(word >>> 24);
147
+ if (length > 1)
148
+ ba.push((word >>> 16) & xFF);
149
+ if (length > 2)
150
+ ba.push((word >>> 8) & xFF);
151
+ if (length > 3)
152
+ ba.push(word & xFF);
153
+
154
+ return ba;
155
+ }
156
+
157
+ function wordArrayToBuffer(wordArray) {
158
+ let length = undefined;
159
+ if (wordArray.hasOwnProperty("sigBytes") && wordArray.hasOwnProperty("words")) {
160
+ length = wordArray.sigBytes;
161
+ wordArray = wordArray.words;
162
+ } else {
163
+ throw Error('Argument not a wordArray')
164
+ }
165
+
166
+ const result = []
167
+ let bytes = []
168
+ let i = 0;
169
+ while (length > 0) {
170
+ bytes = wordToByteArray(wordArray[i], Math.min(4, length));
171
+ length -= bytes.length;
172
+ result.push(bytes);
173
+ i++;
174
+ }
175
+ return new Buffer.from([].concat.apply([], result), 'hex');
176
+ }
@@ -0,0 +1,21 @@
1
+ module.exports = {
2
+ pkcs1: require('./pkcs1'),
3
+
4
+ /**
5
+ * Check if scheme has padding methods
6
+ * @param scheme {string}
7
+ * @returns {Boolean}
8
+ */
9
+ isEncryption: function (scheme) {
10
+ return module.exports[scheme] && module.exports[scheme].isEncryption;
11
+ },
12
+
13
+ /**
14
+ * Check if scheme has sign/verify methods
15
+ * @param scheme {string}
16
+ * @returns {Boolean}
17
+ */
18
+ isSignature: function (scheme) {
19
+ return module.exports[scheme] && module.exports[scheme].isSignature;
20
+ }
21
+ };
@@ -0,0 +1,98 @@
1
+ /*
2
+ * Utils functions
3
+ *
4
+ */
5
+
6
+ /**
7
+ * Break string str each maxLen symbols
8
+ * @param str
9
+ * @param maxLen
10
+ * @returns {string}
11
+ */
12
+ module.exports.linebrk = function (str, maxLen) {
13
+ var res = '';
14
+ var i = 0;
15
+ while (i + maxLen < str.length) {
16
+ res += str.substring(i, i + maxLen) + "\n";
17
+ i += maxLen;
18
+ }
19
+ return res + str.substring(i, str.length);
20
+ };
21
+
22
+ /**
23
+ * Trying get a 32-bit unsigned integer from the partial buffer
24
+ * @param buffer
25
+ * @param offset
26
+ * @returns {Number}
27
+ */
28
+ module.exports.get32IntFromBuffer = function (buffer, offset) {
29
+ offset = offset || 0;
30
+ var size = 0;
31
+ if ((size = buffer.length - offset) > 0) {
32
+ if (size >= 4) {
33
+ return buffer.readUInt32BE(offset);
34
+ } else {
35
+ var res = 0;
36
+ for (var i = offset + size, d = 0; i > offset; i--, d += 2) {
37
+ res += buffer[i - 1] * Math.pow(16, d);
38
+ }
39
+ return res;
40
+ }
41
+ } else {
42
+ return NaN;
43
+ }
44
+ };
45
+
46
+ module.exports._ = {
47
+ isObject: function (value) {
48
+ var type = typeof value;
49
+ return !!value && (type == 'object' || type == 'function');
50
+ },
51
+
52
+ isString: function (value) {
53
+ return typeof value == 'string' || value instanceof String;
54
+ },
55
+
56
+ isNumber: function (value) {
57
+ return typeof value == 'number' || !isNaN(parseFloat(value)) && isFinite(value);
58
+ },
59
+
60
+ /**
61
+ * Returns copy of `obj` without `removeProp` field.
62
+ * @param obj
63
+ * @param removeProp
64
+ * @returns Object
65
+ */
66
+ omit: function (obj, removeProp) {
67
+ var newObj = {};
68
+ for (var prop in obj) {
69
+ if (!obj.hasOwnProperty(prop) || prop === removeProp) {
70
+ continue;
71
+ }
72
+ newObj[prop] = obj[prop];
73
+ }
74
+
75
+ return newObj;
76
+ }
77
+ };
78
+
79
+ /**
80
+ * Strips everything around the opening and closing lines, including the lines
81
+ * themselves.
82
+ */
83
+ module.exports.trimSurroundingText = function (data, opening, closing) {
84
+ var trimStartIndex = 0;
85
+ var trimEndIndex = data.length;
86
+
87
+ var openingBoundaryIndex = data.indexOf(opening);
88
+ if (openingBoundaryIndex >= 0) {
89
+ trimStartIndex = openingBoundaryIndex + opening.length;
90
+ }
91
+
92
+ var closingBoundaryIndex = data.indexOf(closing, openingBoundaryIndex);
93
+ if (closingBoundaryIndex >= 0) {
94
+ trimEndIndex = closingBoundaryIndex;
95
+ }
96
+
97
+ return data.substring(trimStartIndex, trimEndIndex);
98
+ }
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var replace = String.prototype.replace;
4
+ var percentTwenties = /%20/g;
5
+
6
+ module.exports = {
7
+ 'default': 'RFC3986',
8
+ formatters: {
9
+ RFC1738: function (value) {
10
+ return replace.call(value, percentTwenties, '+');
11
+ },
12
+ RFC3986: function (value) {
13
+ return value;
14
+ }
15
+ },
16
+ RFC1738: 'RFC1738',
17
+ RFC3986: 'RFC3986'
18
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var stringify = require('./stringify');
4
+ var parse = require('./parse');
5
+ var formats = require('./formats');
6
+
7
+ module.exports = {
8
+ formats: formats,
9
+ parse: parse,
10
+ stringify: stringify
11
+ };