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,375 @@
1
+ 'use strict';
2
+
3
+ var BN = require('../../../../BN/bn');
4
+ var elliptic = require('../../elliptic');
5
+ var utils = elliptic.utils;
6
+ var getNAF = utils.getNAF;
7
+ var getJSF = utils.getJSF;
8
+ var assert = utils.assert;
9
+
10
+ function BaseCurve(type, conf) {
11
+ this.type = type;
12
+ this.p = new BN(conf.p, 16);
13
+
14
+ // Use Montgomery, when there is no fast reduction for the prime
15
+ this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
16
+
17
+ // Useful for many curves
18
+ this.zero = new BN(0).toRed(this.red);
19
+ this.one = new BN(1).toRed(this.red);
20
+ this.two = new BN(2).toRed(this.red);
21
+
22
+ // Curve configuration, optional
23
+ this.n = conf.n && new BN(conf.n, 16);
24
+ this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
25
+
26
+ // Temporary arrays
27
+ this._wnafT1 = new Array(4);
28
+ this._wnafT2 = new Array(4);
29
+ this._wnafT3 = new Array(4);
30
+ this._wnafT4 = new Array(4);
31
+
32
+ // Generalized Greg Maxwell's trick
33
+ var adjustCount = this.n && this.p.div(this.n);
34
+ if (!adjustCount || adjustCount.cmpn(100) > 0) {
35
+ this.redN = null;
36
+ } else {
37
+ this._maxwellTrick = true;
38
+ this.redN = this.n.toRed(this.red);
39
+ }
40
+ }
41
+ module.exports = BaseCurve;
42
+
43
+ BaseCurve.prototype.point = function point() {
44
+ throw new Error('Not implemented');
45
+ };
46
+
47
+ BaseCurve.prototype.validate = function validate() {
48
+ throw new Error('Not implemented');
49
+ };
50
+
51
+ BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
52
+ assert(p.precomputed);
53
+ var doubles = p._getDoubles();
54
+
55
+ var naf = getNAF(k, 1);
56
+ var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
57
+ I /= 3;
58
+
59
+ // Translate into more windowed form
60
+ var repr = [];
61
+ for (var j = 0; j < naf.length; j += doubles.step) {
62
+ var nafW = 0;
63
+ for (var k = j + doubles.step - 1; k >= j; k--)
64
+ nafW = (nafW << 1) + naf[k];
65
+ repr.push(nafW);
66
+ }
67
+
68
+ var a = this.jpoint(null, null, null);
69
+ var b = this.jpoint(null, null, null);
70
+ for (var i = I; i > 0; i--) {
71
+ for (var j = 0; j < repr.length; j++) {
72
+ var nafW = repr[j];
73
+ if (nafW === i)
74
+ b = b.mixedAdd(doubles.points[j]);
75
+ else if (nafW === -i)
76
+ b = b.mixedAdd(doubles.points[j].neg());
77
+ }
78
+ a = a.add(b);
79
+ }
80
+ return a.toP();
81
+ };
82
+
83
+ BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
84
+ var w = 4;
85
+
86
+ // Precompute window
87
+ var nafPoints = p._getNAFPoints(w);
88
+ w = nafPoints.wnd;
89
+ var wnd = nafPoints.points;
90
+
91
+ // Get NAF form
92
+ var naf = getNAF(k, w);
93
+
94
+ // Add `this`*(N+1) for every w-NAF index
95
+ var acc = this.jpoint(null, null, null);
96
+ for (var i = naf.length - 1; i >= 0; i--) {
97
+ // Count zeroes
98
+ for (var k = 0; i >= 0 && naf[i] === 0; i--)
99
+ k++;
100
+ if (i >= 0)
101
+ k++;
102
+ acc = acc.dblp(k);
103
+
104
+ if (i < 0)
105
+ break;
106
+ var z = naf[i];
107
+ assert(z !== 0);
108
+ if (p.type === 'affine') {
109
+ // J +- P
110
+ if (z > 0)
111
+ acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
112
+ else
113
+ acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
114
+ } else {
115
+ // J +- J
116
+ if (z > 0)
117
+ acc = acc.add(wnd[(z - 1) >> 1]);
118
+ else
119
+ acc = acc.add(wnd[(-z - 1) >> 1].neg());
120
+ }
121
+ }
122
+ return p.type === 'affine' ? acc.toP() : acc;
123
+ };
124
+
125
+ BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
126
+ points,
127
+ coeffs,
128
+ len,
129
+ jacobianResult) {
130
+ var wndWidth = this._wnafT1;
131
+ var wnd = this._wnafT2;
132
+ var naf = this._wnafT3;
133
+
134
+ // Fill all arrays
135
+ var max = 0;
136
+ for (var i = 0; i < len; i++) {
137
+ var p = points[i];
138
+ var nafPoints = p._getNAFPoints(defW);
139
+ wndWidth[i] = nafPoints.wnd;
140
+ wnd[i] = nafPoints.points;
141
+ }
142
+
143
+ // Comb small window NAFs
144
+ for (var i = len - 1; i >= 1; i -= 2) {
145
+ var a = i - 1;
146
+ var b = i;
147
+ if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
148
+ naf[a] = getNAF(coeffs[a], wndWidth[a]);
149
+ naf[b] = getNAF(coeffs[b], wndWidth[b]);
150
+ max = Math.max(naf[a].length, max);
151
+ max = Math.max(naf[b].length, max);
152
+ continue;
153
+ }
154
+
155
+ var comb = [
156
+ points[a], /* 1 */
157
+ null, /* 3 */
158
+ null, /* 5 */
159
+ points[b] /* 7 */
160
+ ];
161
+
162
+ // Try to avoid Projective points, if possible
163
+ if (points[a].y.cmp(points[b].y) === 0) {
164
+ comb[1] = points[a].add(points[b]);
165
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
166
+ } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
167
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
168
+ comb[2] = points[a].add(points[b].neg());
169
+ } else {
170
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
171
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
172
+ }
173
+
174
+ var index = [
175
+ -3, /* -1 -1 */
176
+ -1, /* -1 0 */
177
+ -5, /* -1 1 */
178
+ -7, /* 0 -1 */
179
+ 0, /* 0 0 */
180
+ 7, /* 0 1 */
181
+ 5, /* 1 -1 */
182
+ 1, /* 1 0 */
183
+ 3 /* 1 1 */
184
+ ];
185
+
186
+ var jsf = getJSF(coeffs[a], coeffs[b]);
187
+ max = Math.max(jsf[0].length, max);
188
+ naf[a] = new Array(max);
189
+ naf[b] = new Array(max);
190
+ for (var j = 0; j < max; j++) {
191
+ var ja = jsf[0][j] | 0;
192
+ var jb = jsf[1][j] | 0;
193
+
194
+ naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
195
+ naf[b][j] = 0;
196
+ wnd[a] = comb;
197
+ }
198
+ }
199
+
200
+ var acc = this.jpoint(null, null, null);
201
+ var tmp = this._wnafT4;
202
+ for (var i = max; i >= 0; i--) {
203
+ var k = 0;
204
+
205
+ while (i >= 0) {
206
+ var zero = true;
207
+ for (var j = 0; j < len; j++) {
208
+ tmp[j] = naf[j][i] | 0;
209
+ if (tmp[j] !== 0)
210
+ zero = false;
211
+ }
212
+ if (!zero)
213
+ break;
214
+ k++;
215
+ i--;
216
+ }
217
+ if (i >= 0)
218
+ k++;
219
+ acc = acc.dblp(k);
220
+ if (i < 0)
221
+ break;
222
+
223
+ for (var j = 0; j < len; j++) {
224
+ var z = tmp[j];
225
+ var p;
226
+ if (z === 0)
227
+ continue;
228
+ else if (z > 0)
229
+ p = wnd[j][(z - 1) >> 1];
230
+ else if (z < 0)
231
+ p = wnd[j][(-z - 1) >> 1].neg();
232
+
233
+ if (p.type === 'affine')
234
+ acc = acc.mixedAdd(p);
235
+ else
236
+ acc = acc.add(p);
237
+ }
238
+ }
239
+ // Zeroify references
240
+ for (var i = 0; i < len; i++)
241
+ wnd[i] = null;
242
+
243
+ if (jacobianResult)
244
+ return acc;
245
+ else
246
+ return acc.toP();
247
+ };
248
+
249
+ function BasePoint(curve, type) {
250
+ this.curve = curve;
251
+ this.type = type;
252
+ this.precomputed = null;
253
+ }
254
+ BaseCurve.BasePoint = BasePoint;
255
+
256
+ BasePoint.prototype.eq = function eq(/*other*/) {
257
+ throw new Error('Not implemented');
258
+ };
259
+
260
+ BasePoint.prototype.validate = function validate() {
261
+ return this.curve.validate(this);
262
+ };
263
+
264
+ BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
265
+ bytes = utils.toArray(bytes, enc);
266
+
267
+ var len = this.p.byteLength();
268
+
269
+ // uncompressed, hybrid-odd, hybrid-even
270
+ if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
271
+ bytes.length - 1 === 2 * len) {
272
+ if (bytes[0] === 0x06)
273
+ assert(bytes[bytes.length - 1] % 2 === 0);
274
+ else if (bytes[0] === 0x07)
275
+ assert(bytes[bytes.length - 1] % 2 === 1);
276
+
277
+ var res = this.point(bytes.slice(1, 1 + len),
278
+ bytes.slice(1 + len, 1 + 2 * len));
279
+
280
+ return res;
281
+ } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
282
+ bytes.length - 1 === len) {
283
+ return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
284
+ }
285
+ throw new Error('Unknown point format');
286
+ };
287
+
288
+ BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
289
+ return this.encode(enc, true);
290
+ };
291
+
292
+ BasePoint.prototype._encode = function _encode(compact) {
293
+ var len = this.curve.p.byteLength();
294
+ var x = this.getX().toArray('be', len);
295
+
296
+ if (compact)
297
+ return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
298
+
299
+ return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
300
+ };
301
+
302
+ BasePoint.prototype.encode = function encode(enc, compact) {
303
+ return utils.encode(this._encode(compact), enc);
304
+ };
305
+
306
+ BasePoint.prototype.precompute = function precompute(power) {
307
+ if (this.precomputed)
308
+ return this;
309
+
310
+ var precomputed = {
311
+ doubles: null,
312
+ naf: null,
313
+ beta: null
314
+ };
315
+ precomputed.naf = this._getNAFPoints(8);
316
+ precomputed.doubles = this._getDoubles(4, power);
317
+ precomputed.beta = this._getBeta();
318
+ this.precomputed = precomputed;
319
+
320
+ return this;
321
+ };
322
+
323
+ BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
324
+ if (!this.precomputed)
325
+ return false;
326
+
327
+ var doubles = this.precomputed.doubles;
328
+ if (!doubles)
329
+ return false;
330
+
331
+ return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
332
+ };
333
+
334
+ BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
335
+ if (this.precomputed && this.precomputed.doubles)
336
+ return this.precomputed.doubles;
337
+
338
+ var doubles = [ this ];
339
+ var acc = this;
340
+ for (var i = 0; i < power; i += step) {
341
+ for (var j = 0; j < step; j++)
342
+ acc = acc.dbl();
343
+ doubles.push(acc);
344
+ }
345
+ return {
346
+ step: step,
347
+ points: doubles
348
+ };
349
+ };
350
+
351
+ BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
352
+ if (this.precomputed && this.precomputed.naf)
353
+ return this.precomputed.naf;
354
+
355
+ var res = [ this ];
356
+ var max = (1 << wnd) - 1;
357
+ var dbl = max === 1 ? null : this.dbl();
358
+ for (var i = 1; i < max; i++)
359
+ res[i] = res[i - 1].add(dbl);
360
+ return {
361
+ wnd: wnd,
362
+ points: res
363
+ };
364
+ };
365
+
366
+ BasePoint.prototype._getBeta = function _getBeta() {
367
+ return null;
368
+ };
369
+
370
+ BasePoint.prototype.dblp = function dblp(k) {
371
+ var r = this;
372
+ for (var i = 0; i < k; i++)
373
+ r = r.dbl();
374
+ return r;
375
+ };