ccxt 4.5.60 → 4.5.62

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 (521) hide show
  1. package/README.md +56 -54
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +6 -2
  4. package/dist/cjs/src/aftermath.js +1 -1
  5. package/dist/cjs/src/apex.js +2 -2
  6. package/dist/cjs/src/ascendex.js +1 -1
  7. package/dist/cjs/src/aster.js +3 -4
  8. package/dist/cjs/src/backpack.js +1 -1
  9. package/dist/cjs/src/base/Exchange.js +6 -38
  10. package/dist/cjs/src/base/functions/crypto.js +72 -15
  11. package/dist/cjs/src/base/functions/rsa.js +25 -10
  12. package/dist/cjs/src/base/functions.js +1 -0
  13. package/dist/cjs/src/bequant.js +1 -1
  14. package/dist/cjs/src/bigone.js +1 -1
  15. package/dist/cjs/src/binance.js +1 -1
  16. package/dist/cjs/src/bingx.js +4 -4
  17. package/dist/cjs/src/bit2c.js +1 -1
  18. package/dist/cjs/src/bitbank.js +1 -1
  19. package/dist/cjs/src/bitbns.js +1 -1
  20. package/dist/cjs/src/bitfinex.js +5 -5
  21. package/dist/cjs/src/bitflyer.js +1 -1
  22. package/dist/cjs/src/bitget.js +2 -2
  23. package/dist/cjs/src/bithumb.js +1 -1
  24. package/dist/cjs/src/bitmart.js +2 -2
  25. package/dist/cjs/src/bitmex.js +3 -3
  26. package/dist/cjs/src/bitopro.js +1 -1
  27. package/dist/cjs/src/bitrue.js +1 -1
  28. package/dist/cjs/src/bitso.js +2 -2
  29. package/dist/cjs/src/bitstamp.js +1 -1
  30. package/dist/cjs/src/bittrade.js +2 -2
  31. package/dist/cjs/src/bitvavo.js +2 -2
  32. package/dist/cjs/src/blockchaincom.js +1 -1
  33. package/dist/cjs/src/blofin.js +3 -4
  34. package/dist/cjs/src/btcbox.js +1 -1
  35. package/dist/cjs/src/btcmarkets.js +1 -1
  36. package/dist/cjs/src/btcturk.js +2 -2
  37. package/dist/cjs/src/bullish.js +1 -1
  38. package/dist/cjs/src/bybit.js +1 -1
  39. package/dist/cjs/src/bydfi.js +1 -1
  40. package/dist/cjs/src/cex.js +2 -2
  41. package/dist/cjs/src/coinbase.js +1 -1
  42. package/dist/cjs/src/coinbaseexchange.js +2 -2
  43. package/dist/cjs/src/coincheck.js +2 -2
  44. package/dist/cjs/src/coinex.js +1 -1
  45. package/dist/cjs/src/coinmate.js +1 -1
  46. package/dist/cjs/src/coinmetro.js +1 -1
  47. package/dist/cjs/src/coinone.js +1 -1
  48. package/dist/cjs/src/coinsph.js +1 -1
  49. package/dist/cjs/src/coinspot.js +1 -1
  50. package/dist/cjs/src/cryptocom.js +1 -1
  51. package/dist/cjs/src/cryptomus.js +2 -2
  52. package/dist/cjs/src/deepcoin.js +1 -1
  53. package/dist/cjs/src/delta.js +1 -1
  54. package/dist/cjs/src/deribit.js +1 -1
  55. package/dist/cjs/src/derive.js +2 -3
  56. package/dist/cjs/src/digifinex.js +1 -1
  57. package/dist/cjs/src/dydx.js +2 -2
  58. package/dist/cjs/src/exmo.js +1 -1
  59. package/dist/cjs/src/extended.js +5 -5
  60. package/dist/cjs/src/foxbit.js +1 -1
  61. package/dist/cjs/src/gate.js +3 -3
  62. package/dist/cjs/src/gateeu.js +60 -0
  63. package/dist/cjs/src/gemini.js +1 -1
  64. package/dist/cjs/src/grvt.js +1 -1
  65. package/dist/cjs/src/hashkey.js +2 -2
  66. package/dist/cjs/src/hibachi.js +1 -1
  67. package/dist/cjs/src/hitbtc.js +1 -1
  68. package/dist/cjs/src/hollaex.js +1 -1
  69. package/dist/cjs/src/htx.js +1 -1
  70. package/dist/cjs/src/hyperliquid.js +1 -1
  71. package/dist/cjs/src/independentreserve.js +1 -1
  72. package/dist/cjs/src/indodax.js +1 -1
  73. package/dist/cjs/src/kraken.js +1 -1
  74. package/dist/cjs/src/kucoin.js +1 -1
  75. package/dist/cjs/src/latoken.js +1 -1
  76. package/dist/cjs/src/lbank.js +1 -1
  77. package/dist/cjs/src/lighter.js +1 -1
  78. package/dist/cjs/src/luno.js +2 -2
  79. package/dist/cjs/src/mercado.js +1 -1
  80. package/dist/cjs/src/mexc.js +1 -1
  81. package/dist/cjs/src/modetrade.js +3 -5
  82. package/dist/cjs/src/ndax.js +1 -1
  83. package/dist/cjs/src/novadax.js +1 -1
  84. package/dist/cjs/src/okx.js +1 -1
  85. package/dist/cjs/src/onetrading.js +2 -2
  86. package/dist/cjs/src/p2b.js +2 -3
  87. package/dist/cjs/src/pacifica.js +2 -2
  88. package/dist/cjs/src/paradex.js +1 -1
  89. package/dist/cjs/src/paymium.js +1 -1
  90. package/dist/cjs/src/phemex.js +1 -1
  91. package/dist/cjs/src/poloniex.js +1 -1
  92. package/dist/cjs/src/pro/aftermath.js +1 -1
  93. package/dist/cjs/src/pro/alpaca.js +1 -1
  94. package/dist/cjs/src/pro/apex.js +2 -2
  95. package/dist/cjs/src/pro/ascendex.js +1 -1
  96. package/dist/cjs/src/pro/aster.js +4 -4
  97. package/dist/cjs/src/pro/backpack.js +4 -4
  98. package/dist/cjs/src/pro/binance.js +5 -5
  99. package/dist/cjs/src/pro/bingx.js +2 -2
  100. package/dist/cjs/src/pro/bitfinex.js +1 -1
  101. package/dist/cjs/src/pro/bitget.js +4 -4
  102. package/dist/cjs/src/pro/bitmart.js +4 -4
  103. package/dist/cjs/src/pro/bitmex.js +2 -2
  104. package/dist/cjs/src/pro/bitopro.js +1 -1
  105. package/dist/cjs/src/pro/bitstamp.js +1 -1
  106. package/dist/cjs/src/pro/bittrade.js +1 -1
  107. package/dist/cjs/src/pro/bitvavo.js +1 -1
  108. package/dist/cjs/src/pro/blockchaincom.js +1 -1
  109. package/dist/cjs/src/pro/blofin.js +2 -2
  110. package/dist/cjs/src/pro/bullish.js +1 -1
  111. package/dist/cjs/src/pro/bybit.js +4 -4
  112. package/dist/cjs/src/pro/bydfi.js +4 -4
  113. package/dist/cjs/src/pro/cex.js +1 -1
  114. package/dist/cjs/src/pro/coinbase.js +3 -3
  115. package/dist/cjs/src/pro/coinbaseexchange.js +2 -2
  116. package/dist/cjs/src/pro/coinbaseinternational.js +2 -2
  117. package/dist/cjs/src/pro/coincheck.js +1 -1
  118. package/dist/cjs/src/pro/coinex.js +2 -2
  119. package/dist/cjs/src/pro/coinone.js +1 -1
  120. package/dist/cjs/src/pro/cryptocom.js +4 -4
  121. package/dist/cjs/src/pro/deepcoin.js +2 -2
  122. package/dist/cjs/src/pro/deribit.js +2 -2
  123. package/dist/cjs/src/pro/derive.js +2 -2
  124. package/dist/cjs/src/pro/dydx.js +2 -2
  125. package/dist/cjs/src/pro/exmo.js +1 -1
  126. package/dist/cjs/src/pro/extended.js +1 -1
  127. package/dist/cjs/src/pro/gate.js +46 -15
  128. package/dist/cjs/src/pro/gateeu.js +32 -0
  129. package/dist/cjs/src/pro/gemini.js +2 -3
  130. package/dist/cjs/src/pro/grvt.js +2 -2
  131. package/dist/cjs/src/pro/hashkey.js +1 -1
  132. package/dist/cjs/src/pro/hitbtc.js +1 -1
  133. package/dist/cjs/src/pro/hollaex.js +1 -1
  134. package/dist/cjs/src/pro/htx.js +440 -102
  135. package/dist/cjs/src/pro/hyperliquid.js +2 -2
  136. package/dist/cjs/src/pro/independentreserve.js +1 -1
  137. package/dist/cjs/src/pro/kraken.js +2 -2
  138. package/dist/cjs/src/pro/krakenfutures.js +2 -2
  139. package/dist/cjs/src/pro/kucoin.js +4 -4
  140. package/dist/cjs/src/pro/lighter.js +2 -2
  141. package/dist/cjs/src/pro/luno.js +1 -1
  142. package/dist/cjs/src/pro/mexc.js +2 -2
  143. package/dist/cjs/src/pro/modetrade.js +1 -1
  144. package/dist/cjs/src/pro/ndax.js +1 -1
  145. package/dist/cjs/src/pro/okx.js +4 -4
  146. package/dist/cjs/src/pro/onetrading.js +1 -1
  147. package/dist/cjs/src/pro/p2b.js +1 -1
  148. package/dist/cjs/src/pro/pacifica.js +2 -2
  149. package/dist/cjs/src/pro/paradex.js +1 -1
  150. package/dist/cjs/src/pro/phemex.js +1 -1
  151. package/dist/cjs/src/pro/poloniex.js +1 -1
  152. package/dist/cjs/src/pro/toobit.js +2 -2
  153. package/dist/cjs/src/pro/upbit.js +1 -1
  154. package/dist/cjs/src/pro/weex.js +4 -4
  155. package/dist/cjs/src/pro/whitebit.js +1 -1
  156. package/dist/cjs/src/pro/woo.js +2 -2
  157. package/dist/cjs/src/pro/woofipro.js +1 -1
  158. package/dist/cjs/src/tokocrypto.js +1 -1
  159. package/dist/cjs/src/toobit.js +2 -2
  160. package/dist/cjs/src/upbit.js +1 -1
  161. package/dist/cjs/src/weex.js +2 -2
  162. package/dist/cjs/src/whitebit.js +1 -1
  163. package/dist/cjs/src/woo.js +1 -1
  164. package/dist/cjs/src/woofipro.js +2 -4
  165. package/dist/cjs/src/xt.js +1 -1
  166. package/dist/cjs/src/zaif.js +2 -2
  167. package/dist/cjs/src/zebpay.js +2 -2
  168. package/js/ccxt.d.ts +8 -2
  169. package/js/ccxt.js +6 -3
  170. package/js/src/abstract/gateeu.d.ts +346 -0
  171. package/js/src/{static_dependencies/jsencrypt/index.js → abstract/gateeu.js} +5 -3
  172. package/js/src/aftermath.d.ts +1 -1
  173. package/js/src/aftermath.js +1 -1
  174. package/js/src/apex.d.ts +1 -1
  175. package/js/src/apex.js +2 -2
  176. package/js/src/ascendex.d.ts +1 -1
  177. package/js/src/ascendex.js +1 -1
  178. package/js/src/aster.d.ts +1 -1
  179. package/js/src/aster.js +3 -4
  180. package/js/src/backpack.js +1 -1
  181. package/js/src/base/Exchange.d.ts +1 -1
  182. package/js/src/base/Exchange.js +6 -38
  183. package/js/src/base/functions/crypto.d.ts +2 -1
  184. package/js/src/base/functions/crypto.js +72 -16
  185. package/js/src/base/functions/rsa.js +18 -7
  186. package/js/src/bequant.js +1 -1
  187. package/js/src/bigone.d.ts +1 -1
  188. package/js/src/bigone.js +1 -1
  189. package/js/src/binance.d.ts +1 -1
  190. package/js/src/binance.js +1 -1
  191. package/js/src/bingx.d.ts +1 -1
  192. package/js/src/bingx.js +4 -4
  193. package/js/src/bit2c.d.ts +1 -1
  194. package/js/src/bit2c.js +1 -1
  195. package/js/src/bitbank.d.ts +1 -1
  196. package/js/src/bitbank.js +1 -1
  197. package/js/src/bitbns.d.ts +1 -1
  198. package/js/src/bitbns.js +1 -1
  199. package/js/src/bitfinex.d.ts +1 -1
  200. package/js/src/bitfinex.js +5 -5
  201. package/js/src/bitflyer.d.ts +1 -1
  202. package/js/src/bitflyer.js +1 -1
  203. package/js/src/bitget.d.ts +1 -1
  204. package/js/src/bitget.js +2 -2
  205. package/js/src/bithumb.d.ts +1 -1
  206. package/js/src/bithumb.js +1 -1
  207. package/js/src/bitmart.d.ts +1 -1
  208. package/js/src/bitmart.js +2 -2
  209. package/js/src/bitmex.d.ts +1 -1
  210. package/js/src/bitmex.js +3 -3
  211. package/js/src/bitopro.d.ts +1 -1
  212. package/js/src/bitopro.js +1 -1
  213. package/js/src/bitrue.d.ts +1 -1
  214. package/js/src/bitrue.js +1 -1
  215. package/js/src/bitso.d.ts +1 -1
  216. package/js/src/bitso.js +2 -2
  217. package/js/src/bitstamp.d.ts +1 -1
  218. package/js/src/bitstamp.js +1 -1
  219. package/js/src/bittrade.d.ts +1 -1
  220. package/js/src/bittrade.js +2 -2
  221. package/js/src/bitvavo.d.ts +1 -1
  222. package/js/src/bitvavo.js +2 -2
  223. package/js/src/blockchaincom.d.ts +1 -1
  224. package/js/src/blockchaincom.js +1 -1
  225. package/js/src/blofin.d.ts +1 -1
  226. package/js/src/blofin.js +3 -4
  227. package/js/src/btcbox.d.ts +1 -1
  228. package/js/src/btcbox.js +1 -1
  229. package/js/src/btcmarkets.d.ts +1 -1
  230. package/js/src/btcmarkets.js +1 -1
  231. package/js/src/btcturk.d.ts +1 -1
  232. package/js/src/btcturk.js +2 -2
  233. package/js/src/bullish.d.ts +1 -1
  234. package/js/src/bullish.js +1 -1
  235. package/js/src/bybit.d.ts +1 -1
  236. package/js/src/bybit.js +1 -1
  237. package/js/src/bydfi.js +1 -1
  238. package/js/src/cex.d.ts +1 -1
  239. package/js/src/cex.js +2 -2
  240. package/js/src/coinbase.d.ts +1 -1
  241. package/js/src/coinbase.js +1 -1
  242. package/js/src/coinbaseexchange.d.ts +1 -1
  243. package/js/src/coinbaseexchange.js +2 -2
  244. package/js/src/coincheck.d.ts +1 -1
  245. package/js/src/coincheck.js +2 -2
  246. package/js/src/coinex.d.ts +1 -1
  247. package/js/src/coinex.js +1 -1
  248. package/js/src/coinmate.d.ts +1 -1
  249. package/js/src/coinmate.js +1 -1
  250. package/js/src/coinmetro.d.ts +1 -1
  251. package/js/src/coinmetro.js +1 -1
  252. package/js/src/coinone.d.ts +1 -1
  253. package/js/src/coinone.js +1 -1
  254. package/js/src/coinsph.d.ts +1 -1
  255. package/js/src/coinsph.js +1 -1
  256. package/js/src/coinspot.d.ts +1 -1
  257. package/js/src/coinspot.js +1 -1
  258. package/js/src/cryptocom.d.ts +1 -1
  259. package/js/src/cryptocom.js +1 -1
  260. package/js/src/cryptomus.d.ts +1 -1
  261. package/js/src/cryptomus.js +2 -2
  262. package/js/src/deepcoin.d.ts +1 -1
  263. package/js/src/deepcoin.js +1 -1
  264. package/js/src/delta.d.ts +1 -1
  265. package/js/src/delta.js +1 -1
  266. package/js/src/deribit.d.ts +1 -1
  267. package/js/src/deribit.js +1 -1
  268. package/js/src/derive.js +2 -3
  269. package/js/src/digifinex.d.ts +1 -1
  270. package/js/src/digifinex.js +1 -1
  271. package/js/src/dydx.d.ts +1 -1
  272. package/js/src/dydx.js +2 -2
  273. package/js/src/exmo.d.ts +1 -1
  274. package/js/src/exmo.js +1 -1
  275. package/js/src/extended.d.ts +1 -1
  276. package/js/src/extended.js +5 -5
  277. package/js/src/foxbit.d.ts +1 -1
  278. package/js/src/foxbit.js +1 -1
  279. package/js/src/gate.d.ts +1 -1
  280. package/js/src/gate.js +3 -3
  281. package/js/src/gateeu.d.ts +4 -0
  282. package/js/src/gateeu.js +59 -0
  283. package/js/src/gemini.d.ts +1 -1
  284. package/js/src/gemini.js +1 -1
  285. package/js/src/grvt.js +1 -1
  286. package/js/src/hashkey.d.ts +1 -1
  287. package/js/src/hashkey.js +2 -2
  288. package/js/src/hibachi.js +1 -1
  289. package/js/src/hitbtc.d.ts +1 -1
  290. package/js/src/hitbtc.js +1 -1
  291. package/js/src/hollaex.d.ts +1 -1
  292. package/js/src/hollaex.js +1 -1
  293. package/js/src/htx.d.ts +1 -1
  294. package/js/src/htx.js +1 -1
  295. package/js/src/hyperliquid.d.ts +1 -1
  296. package/js/src/hyperliquid.js +1 -1
  297. package/js/src/independentreserve.d.ts +1 -1
  298. package/js/src/independentreserve.js +1 -1
  299. package/js/src/indodax.d.ts +1 -1
  300. package/js/src/indodax.js +1 -1
  301. package/js/src/kraken.d.ts +1 -1
  302. package/js/src/kraken.js +1 -1
  303. package/js/src/kucoin.d.ts +1 -1
  304. package/js/src/kucoin.js +1 -1
  305. package/js/src/latoken.d.ts +1 -1
  306. package/js/src/latoken.js +1 -1
  307. package/js/src/lbank.d.ts +1 -1
  308. package/js/src/lbank.js +1 -1
  309. package/js/src/lighter.d.ts +1 -1
  310. package/js/src/lighter.js +1 -1
  311. package/js/src/luno.d.ts +1 -1
  312. package/js/src/luno.js +2 -2
  313. package/js/src/mercado.d.ts +1 -1
  314. package/js/src/mercado.js +1 -1
  315. package/js/src/mexc.d.ts +1 -1
  316. package/js/src/mexc.js +1 -1
  317. package/js/src/modetrade.d.ts +1 -1
  318. package/js/src/modetrade.js +3 -5
  319. package/js/src/ndax.d.ts +1 -1
  320. package/js/src/ndax.js +1 -1
  321. package/js/src/novadax.d.ts +1 -1
  322. package/js/src/novadax.js +1 -1
  323. package/js/src/okx.d.ts +1 -1
  324. package/js/src/okx.js +1 -1
  325. package/js/src/onetrading.d.ts +1 -1
  326. package/js/src/onetrading.js +2 -2
  327. package/js/src/p2b.d.ts +1 -1
  328. package/js/src/p2b.js +2 -3
  329. package/js/src/pacifica.d.ts +1 -1
  330. package/js/src/pacifica.js +2 -2
  331. package/js/src/paradex.d.ts +1 -1
  332. package/js/src/paradex.js +1 -1
  333. package/js/src/paymium.d.ts +1 -1
  334. package/js/src/paymium.js +1 -1
  335. package/js/src/phemex.d.ts +1 -1
  336. package/js/src/phemex.js +1 -1
  337. package/js/src/poloniex.d.ts +1 -1
  338. package/js/src/poloniex.js +1 -1
  339. package/js/src/pro/aftermath.d.ts +1 -1
  340. package/js/src/pro/aftermath.js +1 -1
  341. package/js/src/pro/alpaca.d.ts +1 -1
  342. package/js/src/pro/alpaca.js +1 -1
  343. package/js/src/pro/apex.d.ts +2 -2
  344. package/js/src/pro/apex.js +2 -2
  345. package/js/src/pro/ascendex.d.ts +1 -1
  346. package/js/src/pro/ascendex.js +1 -1
  347. package/js/src/pro/aster.d.ts +4 -4
  348. package/js/src/pro/aster.js +4 -4
  349. package/js/src/pro/backpack.d.ts +4 -4
  350. package/js/src/pro/backpack.js +4 -4
  351. package/js/src/pro/binance.d.ts +5 -5
  352. package/js/src/pro/binance.js +5 -5
  353. package/js/src/pro/bingx.d.ts +2 -2
  354. package/js/src/pro/bingx.js +2 -2
  355. package/js/src/pro/bitfinex.d.ts +1 -1
  356. package/js/src/pro/bitfinex.js +1 -1
  357. package/js/src/pro/bitget.d.ts +4 -4
  358. package/js/src/pro/bitget.js +4 -4
  359. package/js/src/pro/bitmart.d.ts +4 -4
  360. package/js/src/pro/bitmart.js +4 -4
  361. package/js/src/pro/bitmex.d.ts +2 -2
  362. package/js/src/pro/bitmex.js +2 -2
  363. package/js/src/pro/bitopro.d.ts +1 -1
  364. package/js/src/pro/bitopro.js +1 -1
  365. package/js/src/pro/bitstamp.d.ts +1 -1
  366. package/js/src/pro/bitstamp.js +1 -1
  367. package/js/src/pro/bittrade.d.ts +1 -1
  368. package/js/src/pro/bittrade.js +1 -1
  369. package/js/src/pro/bitvavo.d.ts +1 -1
  370. package/js/src/pro/bitvavo.js +1 -1
  371. package/js/src/pro/blockchaincom.d.ts +1 -1
  372. package/js/src/pro/blockchaincom.js +1 -1
  373. package/js/src/pro/blofin.d.ts +2 -2
  374. package/js/src/pro/blofin.js +2 -2
  375. package/js/src/pro/bullish.d.ts +1 -1
  376. package/js/src/pro/bullish.js +1 -1
  377. package/js/src/pro/bybit.d.ts +4 -4
  378. package/js/src/pro/bybit.js +4 -4
  379. package/js/src/pro/bydfi.d.ts +4 -4
  380. package/js/src/pro/bydfi.js +4 -4
  381. package/js/src/pro/cex.d.ts +1 -1
  382. package/js/src/pro/cex.js +1 -1
  383. package/js/src/pro/coinbase.d.ts +3 -3
  384. package/js/src/pro/coinbase.js +3 -3
  385. package/js/src/pro/coinbaseexchange.d.ts +2 -2
  386. package/js/src/pro/coinbaseexchange.js +2 -2
  387. package/js/src/pro/coinbaseinternational.d.ts +2 -2
  388. package/js/src/pro/coinbaseinternational.js +2 -2
  389. package/js/src/pro/coincheck.d.ts +1 -1
  390. package/js/src/pro/coincheck.js +1 -1
  391. package/js/src/pro/coinex.d.ts +2 -2
  392. package/js/src/pro/coinex.js +2 -2
  393. package/js/src/pro/coinone.d.ts +1 -1
  394. package/js/src/pro/coinone.js +1 -1
  395. package/js/src/pro/cryptocom.d.ts +4 -4
  396. package/js/src/pro/cryptocom.js +4 -4
  397. package/js/src/pro/deepcoin.d.ts +2 -2
  398. package/js/src/pro/deepcoin.js +2 -2
  399. package/js/src/pro/deribit.d.ts +2 -2
  400. package/js/src/pro/deribit.js +2 -2
  401. package/js/src/pro/derive.d.ts +2 -2
  402. package/js/src/pro/derive.js +2 -2
  403. package/js/src/pro/dydx.d.ts +2 -2
  404. package/js/src/pro/dydx.js +2 -2
  405. package/js/src/pro/exmo.d.ts +1 -1
  406. package/js/src/pro/exmo.js +1 -1
  407. package/js/src/pro/extended.d.ts +1 -1
  408. package/js/src/pro/extended.js +1 -1
  409. package/js/src/pro/gate.d.ts +3 -2
  410. package/js/src/pro/gate.js +46 -15
  411. package/js/src/pro/gateeu.d.ts +4 -0
  412. package/js/src/pro/gateeu.js +31 -0
  413. package/js/src/pro/gemini.d.ts +2 -2
  414. package/js/src/pro/gemini.js +2 -3
  415. package/js/src/pro/grvt.d.ts +2 -2
  416. package/js/src/pro/grvt.js +2 -2
  417. package/js/src/pro/hashkey.d.ts +1 -1
  418. package/js/src/pro/hashkey.js +1 -1
  419. package/js/src/pro/hitbtc.d.ts +1 -1
  420. package/js/src/pro/hitbtc.js +1 -1
  421. package/js/src/pro/hollaex.d.ts +1 -1
  422. package/js/src/pro/hollaex.js +1 -1
  423. package/js/src/pro/htx.d.ts +9 -8
  424. package/js/src/pro/htx.js +440 -100
  425. package/js/src/pro/hyperliquid.d.ts +2 -2
  426. package/js/src/pro/hyperliquid.js +2 -2
  427. package/js/src/pro/independentreserve.d.ts +1 -1
  428. package/js/src/pro/independentreserve.js +1 -1
  429. package/js/src/pro/kraken.d.ts +2 -2
  430. package/js/src/pro/kraken.js +2 -2
  431. package/js/src/pro/krakenfutures.d.ts +2 -2
  432. package/js/src/pro/krakenfutures.js +2 -2
  433. package/js/src/pro/kucoin.d.ts +4 -4
  434. package/js/src/pro/kucoin.js +4 -4
  435. package/js/src/pro/lighter.d.ts +2 -2
  436. package/js/src/pro/lighter.js +2 -2
  437. package/js/src/pro/luno.d.ts +1 -1
  438. package/js/src/pro/luno.js +1 -1
  439. package/js/src/pro/mexc.d.ts +2 -2
  440. package/js/src/pro/mexc.js +2 -2
  441. package/js/src/pro/modetrade.d.ts +1 -1
  442. package/js/src/pro/modetrade.js +1 -1
  443. package/js/src/pro/ndax.d.ts +1 -1
  444. package/js/src/pro/ndax.js +1 -1
  445. package/js/src/pro/okx.d.ts +4 -4
  446. package/js/src/pro/okx.js +4 -4
  447. package/js/src/pro/onetrading.d.ts +1 -1
  448. package/js/src/pro/onetrading.js +1 -1
  449. package/js/src/pro/p2b.d.ts +1 -1
  450. package/js/src/pro/p2b.js +1 -1
  451. package/js/src/pro/pacifica.d.ts +2 -2
  452. package/js/src/pro/pacifica.js +2 -2
  453. package/js/src/pro/paradex.d.ts +1 -1
  454. package/js/src/pro/paradex.js +1 -1
  455. package/js/src/pro/phemex.d.ts +1 -1
  456. package/js/src/pro/phemex.js +1 -1
  457. package/js/src/pro/poloniex.d.ts +1 -1
  458. package/js/src/pro/poloniex.js +1 -1
  459. package/js/src/pro/toobit.d.ts +2 -2
  460. package/js/src/pro/toobit.js +2 -2
  461. package/js/src/pro/upbit.d.ts +1 -1
  462. package/js/src/pro/upbit.js +1 -1
  463. package/js/src/pro/weex.d.ts +4 -4
  464. package/js/src/pro/weex.js +4 -4
  465. package/js/src/pro/whitebit.d.ts +1 -1
  466. package/js/src/pro/whitebit.js +1 -1
  467. package/js/src/pro/woo.d.ts +2 -2
  468. package/js/src/pro/woo.js +2 -2
  469. package/js/src/pro/woofipro.d.ts +1 -1
  470. package/js/src/pro/woofipro.js +1 -1
  471. package/js/src/tokocrypto.d.ts +1 -1
  472. package/js/src/tokocrypto.js +1 -1
  473. package/js/src/toobit.d.ts +1 -1
  474. package/js/src/toobit.js +2 -2
  475. package/js/src/upbit.d.ts +1 -1
  476. package/js/src/upbit.js +1 -1
  477. package/js/src/weex.d.ts +1 -1
  478. package/js/src/weex.js +2 -2
  479. package/js/src/whitebit.d.ts +1 -1
  480. package/js/src/whitebit.js +1 -1
  481. package/js/src/woo.d.ts +1 -1
  482. package/js/src/woo.js +1 -1
  483. package/js/src/woofipro.d.ts +1 -1
  484. package/js/src/woofipro.js +2 -4
  485. package/js/src/xt.js +1 -1
  486. package/js/src/zaif.d.ts +1 -1
  487. package/js/src/zaif.js +2 -2
  488. package/js/src/zebpay.d.ts +1 -1
  489. package/js/src/zebpay.js +2 -2
  490. package/package.json +18 -8
  491. package/js/src/static_dependencies/jsencrypt/JSEncrypt.d.ts +0 -116
  492. package/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -194
  493. package/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.d.ts +0 -142
  494. package/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -307
  495. package/js/src/static_dependencies/jsencrypt/index.d.ts +0 -3
  496. package/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.d.ts +0 -51
  497. package/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -565
  498. package/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.d.ts +0 -5
  499. package/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  500. package/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.d.ts +0 -3
  501. package/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  502. package/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.d.ts +0 -9
  503. package/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  504. package/js/src/static_dependencies/jsencrypt/lib/asn1js/oids.d.ts +0 -9778
  505. package/js/src/static_dependencies/jsencrypt/lib/asn1js/oids.js +0 -1968
  506. package/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.d.ts +0 -3
  507. package/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -25
  508. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +0 -101
  509. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1757
  510. package/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.d.ts +0 -10
  511. package/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -50
  512. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.d.ts +0 -3
  513. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -80
  514. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.d.ts +0 -23
  515. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -377
  516. package/js/src/static_dependencies/jsencrypt/lib/jsbn/util.d.ts +0 -7
  517. package/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -64
  518. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.d.ts +0 -24
  519. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1627
  520. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.d.ts +0 -5
  521. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -75
@@ -1,1757 +0,0 @@
1
- // ----------------------------------------------------------------------------
2
-
3
- // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
- // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
- // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
-
7
- // Copyright (c) 2005 Tom Wu
8
- // All Rights Reserved.
9
- // See "LICENSE" for details.
10
- // Basic JavaScript BN library - subset useful for RSA encryption.
11
- import { cbit, int2char, lbit, op_and, op_andnot, op_or, op_xor } from "./util.js";
12
- // Bits per digit
13
- let dbits;
14
- // JavaScript engine analysis
15
- const canary = 0xdeadbeefcafe;
16
- const j_lm = ((canary & 0xffffff) == 0xefcafe);
17
- //#region
18
- const lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
19
- const lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
20
- //#endregion
21
- // (public) Constructor
22
- /**
23
- * @type Class
24
- */
25
- export class BigInteger {
26
- constructor(a, b, c) {
27
- if (a != null) {
28
- if ("number" == typeof a) {
29
- this.fromNumber(a, b, c);
30
- }
31
- else if (b == null && "string" != typeof a) {
32
- this.fromString(a, 256);
33
- }
34
- else {
35
- this.fromString(a, b);
36
- }
37
- }
38
- }
39
- //#region PUBLIC
40
- // BigInteger.prototype.toString = bnToString;
41
- // (public) return string representation in given radix
42
- toString(b) {
43
- if (this.s < 0) {
44
- return "-" + this.negate().toString(b);
45
- }
46
- let k;
47
- if (b == 16) {
48
- k = 4;
49
- }
50
- else if (b == 8) {
51
- k = 3;
52
- }
53
- else if (b == 2) {
54
- k = 1;
55
- }
56
- else if (b == 32) {
57
- k = 5;
58
- }
59
- else if (b == 4) {
60
- k = 2;
61
- }
62
- else {
63
- return this.toRadix(b);
64
- }
65
- const km = (1 << k) - 1;
66
- let d;
67
- let m = false;
68
- let r = "";
69
- let i = this.t;
70
- let p = this.DB - (i * this.DB) % k;
71
- if (i-- > 0) {
72
- if (p < this.DB && (d = this[i] >> p) > 0) {
73
- m = true;
74
- r = int2char(d);
75
- }
76
- while (i >= 0) {
77
- if (p < k) {
78
- d = (this[i] & ((1 << p) - 1)) << (k - p);
79
- d |= this[--i] >> (p += this.DB - k);
80
- }
81
- else {
82
- d = (this[i] >> (p -= k)) & km;
83
- if (p <= 0) {
84
- p += this.DB;
85
- --i;
86
- }
87
- }
88
- if (d > 0) {
89
- m = true;
90
- }
91
- if (m) {
92
- r += int2char(d);
93
- }
94
- }
95
- }
96
- return m ? r : "0";
97
- }
98
- // BigInteger.prototype.negate = bnNegate;
99
- // (public) -this
100
- negate() {
101
- const r = nbi();
102
- BigInteger.ZERO.subTo(this, r);
103
- return r;
104
- }
105
- // BigInteger.prototype.abs = bnAbs;
106
- // (public) |this|
107
- abs() {
108
- return (this.s < 0) ? this.negate() : this;
109
- }
110
- // BigInteger.prototype.compareTo = bnCompareTo;
111
- // (public) return + if this > a, - if this < a, 0 if equal
112
- compareTo(a) {
113
- let r = this.s - a.s;
114
- if (r != 0) {
115
- return r;
116
- }
117
- let i = this.t;
118
- r = i - a.t;
119
- if (r != 0) {
120
- return (this.s < 0) ? -r : r;
121
- }
122
- while (--i >= 0) {
123
- if ((r = this[i] - a[i]) != 0) {
124
- return r;
125
- }
126
- }
127
- return 0;
128
- }
129
- // BigInteger.prototype.bitLength = bnBitLength;
130
- // (public) return the number of bits in "this"
131
- bitLength() {
132
- if (this.t <= 0) {
133
- return 0;
134
- }
135
- return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
136
- }
137
- // BigInteger.prototype.mod = bnMod;
138
- // (public) this mod a
139
- mod(a) {
140
- const r = nbi();
141
- this.abs().divRemTo(a, null, r);
142
- if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
143
- a.subTo(r, r);
144
- }
145
- return r;
146
- }
147
- // BigInteger.prototype.modPowInt = bnModPowInt;
148
- // (public) this^e % m, 0 <= e < 2^32
149
- modPowInt(e, m) {
150
- let z;
151
- if (e < 256 || m.isEven()) {
152
- z = new Classic(m);
153
- }
154
- else {
155
- z = new Montgomery(m);
156
- }
157
- return this.exp(e, z);
158
- }
159
- // BigInteger.prototype.clone = bnClone;
160
- // (public)
161
- clone() {
162
- const r = nbi();
163
- this.copyTo(r);
164
- return r;
165
- }
166
- // BigInteger.prototype.intValue = bnIntValue;
167
- // (public) return value as integer
168
- intValue() {
169
- if (this.s < 0) {
170
- if (this.t == 1) {
171
- return this[0] - this.DV;
172
- }
173
- else if (this.t == 0) {
174
- return -1;
175
- }
176
- }
177
- else if (this.t == 1) {
178
- return this[0];
179
- }
180
- else if (this.t == 0) {
181
- return 0;
182
- }
183
- // assumes 16 < DB < 32
184
- return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
185
- }
186
- // BigInteger.prototype.byteValue = bnByteValue;
187
- // (public) return value as byte
188
- byteValue() {
189
- return (this.t == 0) ? this.s : (this[0] << 24) >> 24;
190
- }
191
- // BigInteger.prototype.shortValue = bnShortValue;
192
- // (public) return value as short (assumes DB>=16)
193
- shortValue() {
194
- return (this.t == 0) ? this.s : (this[0] << 16) >> 16;
195
- }
196
- // BigInteger.prototype.signum = bnSigNum;
197
- // (public) 0 if this == 0, 1 if this > 0
198
- signum() {
199
- if (this.s < 0) {
200
- return -1;
201
- }
202
- else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) {
203
- return 0;
204
- }
205
- else {
206
- return 1;
207
- }
208
- }
209
- // BigInteger.prototype.toByteArray = bnToByteArray;
210
- // (public) convert to bigendian byte array
211
- toByteArray() {
212
- let i = this.t;
213
- const r = [];
214
- r[0] = this.s;
215
- let p = this.DB - (i * this.DB) % 8;
216
- let d;
217
- let k = 0;
218
- if (i-- > 0) {
219
- if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
220
- r[k++] = d | (this.s << (this.DB - p));
221
- }
222
- while (i >= 0) {
223
- if (p < 8) {
224
- d = (this[i] & ((1 << p) - 1)) << (8 - p);
225
- d |= this[--i] >> (p += this.DB - 8);
226
- }
227
- else {
228
- d = (this[i] >> (p -= 8)) & 0xff;
229
- if (p <= 0) {
230
- p += this.DB;
231
- --i;
232
- }
233
- }
234
- if ((d & 0x80) != 0) {
235
- d |= -256;
236
- }
237
- if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
238
- ++k;
239
- }
240
- if (k > 0 || d != this.s) {
241
- r[k++] = d;
242
- }
243
- }
244
- }
245
- return r;
246
- }
247
- // BigInteger.prototype.equals = bnEquals;
248
- equals(a) {
249
- return (this.compareTo(a) == 0);
250
- }
251
- // BigInteger.prototype.min = bnMin;
252
- min(a) {
253
- return (this.compareTo(a) < 0) ? this : a;
254
- }
255
- // BigInteger.prototype.max = bnMax;
256
- max(a) {
257
- return (this.compareTo(a) > 0) ? this : a;
258
- }
259
- // BigInteger.prototype.and = bnAnd;
260
- and(a) {
261
- const r = nbi();
262
- this.bitwiseTo(a, op_and, r);
263
- return r;
264
- }
265
- // BigInteger.prototype.or = bnOr;
266
- or(a) {
267
- const r = nbi();
268
- this.bitwiseTo(a, op_or, r);
269
- return r;
270
- }
271
- // BigInteger.prototype.xor = bnXor;
272
- xor(a) {
273
- const r = nbi();
274
- this.bitwiseTo(a, op_xor, r);
275
- return r;
276
- }
277
- // BigInteger.prototype.andNot = bnAndNot;
278
- andNot(a) {
279
- const r = nbi();
280
- this.bitwiseTo(a, op_andnot, r);
281
- return r;
282
- }
283
- // BigInteger.prototype.not = bnNot;
284
- // (public) ~this
285
- not() {
286
- const r = nbi();
287
- for (let i = 0; i < this.t; ++i) {
288
- r[i] = this.DM & ~this[i];
289
- }
290
- r.t = this.t;
291
- r.s = ~this.s;
292
- return r;
293
- }
294
- // BigInteger.prototype.shiftLeft = bnShiftLeft;
295
- // (public) this << n
296
- shiftLeft(n) {
297
- const r = nbi();
298
- if (n < 0) {
299
- this.rShiftTo(-n, r);
300
- }
301
- else {
302
- this.lShiftTo(n, r);
303
- }
304
- return r;
305
- }
306
- // BigInteger.prototype.shiftRight = bnShiftRight;
307
- // (public) this >> n
308
- shiftRight(n) {
309
- const r = nbi();
310
- if (n < 0) {
311
- this.lShiftTo(-n, r);
312
- }
313
- else {
314
- this.rShiftTo(n, r);
315
- }
316
- return r;
317
- }
318
- // BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
319
- // (public) returns index of lowest 1-bit (or -1 if none)
320
- getLowestSetBit() {
321
- for (let i = 0; i < this.t; ++i) {
322
- if (this[i] != 0) {
323
- return i * this.DB + lbit(this[i]);
324
- }
325
- }
326
- if (this.s < 0) {
327
- return this.t * this.DB;
328
- }
329
- return -1;
330
- }
331
- // BigInteger.prototype.bitCount = bnBitCount;
332
- // (public) return number of set bits
333
- bitCount() {
334
- let r = 0;
335
- const x = this.s & this.DM;
336
- for (let i = 0; i < this.t; ++i) {
337
- r += cbit(this[i] ^ x);
338
- }
339
- return r;
340
- }
341
- // BigInteger.prototype.testBit = bnTestBit;
342
- // (public) true iff nth bit is set
343
- testBit(n) {
344
- const j = Math.floor(n / this.DB);
345
- if (j >= this.t) {
346
- return (this.s != 0);
347
- }
348
- return ((this[j] & (1 << (n % this.DB))) != 0);
349
- }
350
- // BigInteger.prototype.setBit = bnSetBit;
351
- // (public) this | (1<<n)
352
- setBit(n) {
353
- return this.changeBit(n, op_or);
354
- }
355
- // BigInteger.prototype.clearBit = bnClearBit;
356
- // (public) this & ~(1<<n)
357
- clearBit(n) {
358
- return this.changeBit(n, op_andnot);
359
- }
360
- // BigInteger.prototype.flipBit = bnFlipBit;
361
- // (public) this ^ (1<<n)
362
- flipBit(n) {
363
- return this.changeBit(n, op_xor);
364
- }
365
- // BigInteger.prototype.add = bnAdd;
366
- // (public) this + a
367
- add(a) {
368
- const r = nbi();
369
- this.addTo(a, r);
370
- return r;
371
- }
372
- // BigInteger.prototype.subtract = bnSubtract;
373
- // (public) this - a
374
- subtract(a) {
375
- const r = nbi();
376
- this.subTo(a, r);
377
- return r;
378
- }
379
- // BigInteger.prototype.multiply = bnMultiply;
380
- // (public) this * a
381
- multiply(a) {
382
- const r = nbi();
383
- this.multiplyTo(a, r);
384
- return r;
385
- }
386
- // BigInteger.prototype.divide = bnDivide;
387
- // (public) this / a
388
- divide(a) {
389
- const r = nbi();
390
- this.divRemTo(a, r, null);
391
- return r;
392
- }
393
- // BigInteger.prototype.remainder = bnRemainder;
394
- // (public) this % a
395
- remainder(a) {
396
- const r = nbi();
397
- this.divRemTo(a, null, r);
398
- return r;
399
- }
400
- // BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
401
- // (public) [this/a,this%a]
402
- divideAndRemainder(a) {
403
- const q = nbi();
404
- const r = nbi();
405
- this.divRemTo(a, q, r);
406
- return [q, r];
407
- }
408
- // BigInteger.prototype.modPow = bnModPow;
409
- // (public) this^e % m (HAC 14.85)
410
- modPow(e, m) {
411
- let i = e.bitLength();
412
- let k;
413
- let r = nbv(1);
414
- let z;
415
- if (i <= 0) {
416
- return r;
417
- }
418
- else if (i < 18) {
419
- k = 1;
420
- }
421
- else if (i < 48) {
422
- k = 3;
423
- }
424
- else if (i < 144) {
425
- k = 4;
426
- }
427
- else if (i < 768) {
428
- k = 5;
429
- }
430
- else {
431
- k = 6;
432
- }
433
- if (i < 8) {
434
- z = new Classic(m);
435
- }
436
- else if (m.isEven()) {
437
- z = new Barrett(m);
438
- }
439
- else {
440
- z = new Montgomery(m);
441
- }
442
- // precomputation
443
- const g = [];
444
- let n = 3;
445
- const k1 = k - 1;
446
- const km = (1 << k) - 1;
447
- g[1] = z.convert(this);
448
- if (k > 1) {
449
- const g2 = nbi();
450
- z.sqrTo(g[1], g2);
451
- while (n <= km) {
452
- g[n] = nbi();
453
- z.mulTo(g2, g[n - 2], g[n]);
454
- n += 2;
455
- }
456
- }
457
- let j = e.t - 1;
458
- let w;
459
- let is1 = true;
460
- let r2 = nbi();
461
- let t;
462
- i = nbits(e[j]) - 1;
463
- while (j >= 0) {
464
- if (i >= k1) {
465
- w = (e[j] >> (i - k1)) & km;
466
- }
467
- else {
468
- w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i);
469
- if (j > 0) {
470
- w |= e[j - 1] >> (this.DB + i - k1);
471
- }
472
- }
473
- n = k;
474
- while ((w & 1) == 0) {
475
- w >>= 1;
476
- --n;
477
- }
478
- if ((i -= n) < 0) {
479
- i += this.DB;
480
- --j;
481
- }
482
- if (is1) { // ret == 1, don't bother squaring or multiplying it
483
- g[w].copyTo(r);
484
- is1 = false;
485
- }
486
- else {
487
- while (n > 1) {
488
- z.sqrTo(r, r2);
489
- z.sqrTo(r2, r);
490
- n -= 2;
491
- }
492
- if (n > 0) {
493
- z.sqrTo(r, r2);
494
- }
495
- else {
496
- t = r;
497
- r = r2;
498
- r2 = t;
499
- }
500
- z.mulTo(r2, g[w], r);
501
- }
502
- while (j >= 0 && (e[j] & (1 << i)) == 0) {
503
- z.sqrTo(r, r2);
504
- t = r;
505
- r = r2;
506
- r2 = t;
507
- if (--i < 0) {
508
- i = this.DB - 1;
509
- --j;
510
- }
511
- }
512
- }
513
- return z.revert(r);
514
- }
515
- // BigInteger.prototype.modInverse = bnModInverse;
516
- // (public) 1/this % m (HAC 14.61)
517
- modInverse(m) {
518
- const ac = m.isEven();
519
- if ((this.isEven() && ac) || m.signum() == 0) {
520
- return BigInteger.ZERO;
521
- }
522
- const u = m.clone();
523
- const v = this.clone();
524
- const a = nbv(1);
525
- const b = nbv(0);
526
- const c = nbv(0);
527
- const d = nbv(1);
528
- while (u.signum() != 0) {
529
- while (u.isEven()) {
530
- u.rShiftTo(1, u);
531
- if (ac) {
532
- if (!a.isEven() || !b.isEven()) {
533
- a.addTo(this, a);
534
- b.subTo(m, b);
535
- }
536
- a.rShiftTo(1, a);
537
- }
538
- else if (!b.isEven()) {
539
- b.subTo(m, b);
540
- }
541
- b.rShiftTo(1, b);
542
- }
543
- while (v.isEven()) {
544
- v.rShiftTo(1, v);
545
- if (ac) {
546
- if (!c.isEven() || !d.isEven()) {
547
- c.addTo(this, c);
548
- d.subTo(m, d);
549
- }
550
- c.rShiftTo(1, c);
551
- }
552
- else if (!d.isEven()) {
553
- d.subTo(m, d);
554
- }
555
- d.rShiftTo(1, d);
556
- }
557
- if (u.compareTo(v) >= 0) {
558
- u.subTo(v, u);
559
- if (ac) {
560
- a.subTo(c, a);
561
- }
562
- b.subTo(d, b);
563
- }
564
- else {
565
- v.subTo(u, v);
566
- if (ac) {
567
- c.subTo(a, c);
568
- }
569
- d.subTo(b, d);
570
- }
571
- }
572
- if (v.compareTo(BigInteger.ONE) != 0) {
573
- return BigInteger.ZERO;
574
- }
575
- if (d.compareTo(m) >= 0) {
576
- return d.subtract(m);
577
- }
578
- if (d.signum() < 0) {
579
- d.addTo(m, d);
580
- }
581
- else {
582
- return d;
583
- }
584
- if (d.signum() < 0) {
585
- return d.add(m);
586
- }
587
- else {
588
- return d;
589
- }
590
- }
591
- // BigInteger.prototype.pow = bnPow;
592
- // (public) this^e
593
- pow(e) {
594
- return this.exp(e, new NullExp());
595
- }
596
- // BigInteger.prototype.gcd = bnGCD;
597
- // (public) gcd(this,a) (HAC 14.54)
598
- gcd(a) {
599
- let x = (this.s < 0) ? this.negate() : this.clone();
600
- let y = (a.s < 0) ? a.negate() : a.clone();
601
- if (x.compareTo(y) < 0) {
602
- const t = x;
603
- x = y;
604
- y = t;
605
- }
606
- let i = x.getLowestSetBit();
607
- let g = y.getLowestSetBit();
608
- if (g < 0) {
609
- return x;
610
- }
611
- if (i < g) {
612
- g = i;
613
- }
614
- if (g > 0) {
615
- x.rShiftTo(g, x);
616
- y.rShiftTo(g, y);
617
- }
618
- while (x.signum() > 0) {
619
- if ((i = x.getLowestSetBit()) > 0) {
620
- x.rShiftTo(i, x);
621
- }
622
- if ((i = y.getLowestSetBit()) > 0) {
623
- y.rShiftTo(i, y);
624
- }
625
- if (x.compareTo(y) >= 0) {
626
- x.subTo(y, x);
627
- x.rShiftTo(1, x);
628
- }
629
- else {
630
- y.subTo(x, y);
631
- y.rShiftTo(1, y);
632
- }
633
- }
634
- if (g > 0) {
635
- y.lShiftTo(g, y);
636
- }
637
- return y;
638
- }
639
- // BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
640
- // (public) test primality with certainty >= 1-.5^t
641
- isProbablePrime(t) {
642
- let i;
643
- const x = this.abs();
644
- if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
645
- for (i = 0; i < lowprimes.length; ++i) {
646
- if (x[0] == lowprimes[i]) {
647
- return true;
648
- }
649
- }
650
- return false;
651
- }
652
- if (x.isEven()) {
653
- return false;
654
- }
655
- i = 1;
656
- while (i < lowprimes.length) {
657
- let m = lowprimes[i];
658
- let j = i + 1;
659
- while (j < lowprimes.length && m < lplim) {
660
- m *= lowprimes[j++];
661
- }
662
- m = x.modInt(m);
663
- while (i < j) {
664
- if (m % lowprimes[i++] == 0) {
665
- return false;
666
- }
667
- }
668
- }
669
- return x.millerRabin(t);
670
- }
671
- //#endregion PUBLIC
672
- //#region PROTECTED
673
- // BigInteger.prototype.copyTo = bnpCopyTo;
674
- // (protected) copy this to r
675
- copyTo(r) {
676
- for (let i = this.t - 1; i >= 0; --i) {
677
- r[i] = this[i];
678
- }
679
- r.t = this.t;
680
- r.s = this.s;
681
- }
682
- // BigInteger.prototype.fromInt = bnpFromInt;
683
- // (protected) set from integer value x, -DV <= x < DV
684
- fromInt(x) {
685
- this.t = 1;
686
- this.s = (x < 0) ? -1 : 0;
687
- if (x > 0) {
688
- this[0] = x;
689
- }
690
- else if (x < -1) {
691
- this[0] = x + this.DV;
692
- }
693
- else {
694
- this.t = 0;
695
- }
696
- }
697
- // BigInteger.prototype.fromString = bnpFromString;
698
- // (protected) set from string and radix
699
- fromString(s, b) {
700
- let k;
701
- if (b == 16) {
702
- k = 4;
703
- }
704
- else if (b == 8) {
705
- k = 3;
706
- }
707
- else if (b == 256) {
708
- k = 8;
709
- /* byte array */
710
- }
711
- else if (b == 2) {
712
- k = 1;
713
- }
714
- else if (b == 32) {
715
- k = 5;
716
- }
717
- else if (b == 4) {
718
- k = 2;
719
- }
720
- else {
721
- this.fromRadix(s, b);
722
- return;
723
- }
724
- this.t = 0;
725
- this.s = 0;
726
- let i = s.length;
727
- let mi = false;
728
- let sh = 0;
729
- while (--i >= 0) {
730
- const x = (k == 8) ? (+s[i]) & 0xff : intAt(s, i);
731
- if (x < 0) {
732
- if (s.charAt(i) == "-") {
733
- mi = true;
734
- }
735
- continue;
736
- }
737
- mi = false;
738
- if (sh == 0) {
739
- this[this.t++] = x;
740
- }
741
- else if (sh + k > this.DB) {
742
- this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
743
- this[this.t++] = (x >> (this.DB - sh));
744
- }
745
- else {
746
- this[this.t - 1] |= x << sh;
747
- }
748
- sh += k;
749
- if (sh >= this.DB) {
750
- sh -= this.DB;
751
- }
752
- }
753
- if (k == 8 && ((+s[0]) & 0x80) != 0) {
754
- this.s = -1;
755
- if (sh > 0) {
756
- this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
757
- }
758
- }
759
- this.clamp();
760
- if (mi) {
761
- BigInteger.ZERO.subTo(this, this);
762
- }
763
- }
764
- // BigInteger.prototype.clamp = bnpClamp;
765
- // (protected) clamp off excess high words
766
- clamp() {
767
- const c = this.s & this.DM;
768
- while (this.t > 0 && this[this.t - 1] == c) {
769
- --this.t;
770
- }
771
- }
772
- // BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
773
- // (protected) r = this << n*DB
774
- dlShiftTo(n, r) {
775
- let i;
776
- for (i = this.t - 1; i >= 0; --i) {
777
- r[i + n] = this[i];
778
- }
779
- for (i = n - 1; i >= 0; --i) {
780
- r[i] = 0;
781
- }
782
- r.t = this.t + n;
783
- r.s = this.s;
784
- }
785
- // BigInteger.prototype.drShiftTo = bnpDRShiftTo;
786
- // (protected) r = this >> n*DB
787
- drShiftTo(n, r) {
788
- for (let i = n; i < this.t; ++i) {
789
- r[i - n] = this[i];
790
- }
791
- r.t = Math.max(this.t - n, 0);
792
- r.s = this.s;
793
- }
794
- // BigInteger.prototype.lShiftTo = bnpLShiftTo;
795
- // (protected) r = this << n
796
- lShiftTo(n, r) {
797
- const bs = n % this.DB;
798
- const cbs = this.DB - bs;
799
- const bm = (1 << cbs) - 1;
800
- const ds = Math.floor(n / this.DB);
801
- let c = (this.s << bs) & this.DM;
802
- for (let i = this.t - 1; i >= 0; --i) {
803
- r[i + ds + 1] = (this[i] >> cbs) | c;
804
- c = (this[i] & bm) << bs;
805
- }
806
- for (let i = ds - 1; i >= 0; --i) {
807
- r[i] = 0;
808
- }
809
- r[ds] = c;
810
- r.t = this.t + ds + 1;
811
- r.s = this.s;
812
- r.clamp();
813
- }
814
- // BigInteger.prototype.rShiftTo = bnpRShiftTo;
815
- // (protected) r = this >> n
816
- rShiftTo(n, r) {
817
- r.s = this.s;
818
- const ds = Math.floor(n / this.DB);
819
- if (ds >= this.t) {
820
- r.t = 0;
821
- return;
822
- }
823
- const bs = n % this.DB;
824
- const cbs = this.DB - bs;
825
- const bm = (1 << bs) - 1;
826
- r[0] = this[ds] >> bs;
827
- for (let i = ds + 1; i < this.t; ++i) {
828
- r[i - ds - 1] |= (this[i] & bm) << cbs;
829
- r[i - ds] = this[i] >> bs;
830
- }
831
- if (bs > 0) {
832
- r[this.t - ds - 1] |= (this.s & bm) << cbs;
833
- }
834
- r.t = this.t - ds;
835
- r.clamp();
836
- }
837
- // BigInteger.prototype.subTo = bnpSubTo;
838
- // (protected) r = this - a
839
- subTo(a, r) {
840
- let i = 0;
841
- let c = 0;
842
- const m = Math.min(a.t, this.t);
843
- while (i < m) {
844
- c += this[i] - a[i];
845
- r[i++] = c & this.DM;
846
- c >>= this.DB;
847
- }
848
- if (a.t < this.t) {
849
- c -= a.s;
850
- while (i < this.t) {
851
- c += this[i];
852
- r[i++] = c & this.DM;
853
- c >>= this.DB;
854
- }
855
- c += this.s;
856
- }
857
- else {
858
- c += this.s;
859
- while (i < a.t) {
860
- c -= a[i];
861
- r[i++] = c & this.DM;
862
- c >>= this.DB;
863
- }
864
- c -= a.s;
865
- }
866
- r.s = (c < 0) ? -1 : 0;
867
- if (c < -1) {
868
- r[i++] = this.DV + c;
869
- }
870
- else if (c > 0) {
871
- r[i++] = c;
872
- }
873
- r.t = i;
874
- r.clamp();
875
- }
876
- // BigInteger.prototype.multiplyTo = bnpMultiplyTo;
877
- // (protected) r = this * a, r != this,a (HAC 14.12)
878
- // "this" should be the larger one if appropriate.
879
- multiplyTo(a, r) {
880
- const x = this.abs();
881
- const y = a.abs();
882
- let i = x.t;
883
- r.t = i + y.t;
884
- while (--i >= 0) {
885
- r[i] = 0;
886
- }
887
- for (i = 0; i < y.t; ++i) {
888
- r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
889
- }
890
- r.s = 0;
891
- r.clamp();
892
- if (this.s != a.s) {
893
- BigInteger.ZERO.subTo(r, r);
894
- }
895
- }
896
- // BigInteger.prototype.squareTo = bnpSquareTo;
897
- // (protected) r = this^2, r != this (HAC 14.16)
898
- squareTo(r) {
899
- const x = this.abs();
900
- let i = r.t = 2 * x.t;
901
- while (--i >= 0) {
902
- r[i] = 0;
903
- }
904
- for (i = 0; i < x.t - 1; ++i) {
905
- const c = x.am(i, x[i], r, 2 * i, 0, 1);
906
- if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
907
- r[i + x.t] -= x.DV;
908
- r[i + x.t + 1] = 1;
909
- }
910
- }
911
- if (r.t > 0) {
912
- r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
913
- }
914
- r.s = 0;
915
- r.clamp();
916
- }
917
- // BigInteger.prototype.divRemTo = bnpDivRemTo;
918
- // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
919
- // r != q, this != m. q or r may be null.
920
- divRemTo(m, q, r) {
921
- const pm = m.abs();
922
- if (pm.t <= 0) {
923
- return;
924
- }
925
- const pt = this.abs();
926
- if (pt.t < pm.t) {
927
- if (q != null) {
928
- q.fromInt(0);
929
- }
930
- if (r != null) {
931
- this.copyTo(r);
932
- }
933
- return;
934
- }
935
- if (r == null) {
936
- r = nbi();
937
- }
938
- const y = nbi();
939
- const ts = this.s;
940
- const ms = m.s;
941
- const nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
942
- if (nsh > 0) {
943
- pm.lShiftTo(nsh, y);
944
- pt.lShiftTo(nsh, r);
945
- }
946
- else {
947
- pm.copyTo(y);
948
- pt.copyTo(r);
949
- }
950
- const ys = y.t;
951
- const y0 = y[ys - 1];
952
- if (y0 == 0) {
953
- return;
954
- }
955
- const yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
956
- const d1 = this.FV / yt;
957
- const d2 = (1 << this.F1) / yt;
958
- const e = 1 << this.F2;
959
- let i = r.t;
960
- let j = i - ys;
961
- const t = (q == null) ? nbi() : q;
962
- y.dlShiftTo(j, t);
963
- if (r.compareTo(t) >= 0) {
964
- r[r.t++] = 1;
965
- r.subTo(t, r);
966
- }
967
- BigInteger.ONE.dlShiftTo(ys, t);
968
- t.subTo(y, y); // "negative" y so we can replace sub with am later
969
- while (y.t < ys) {
970
- y[y.t++] = 0;
971
- }
972
- while (--j >= 0) {
973
- // Estimate quotient digit
974
- let qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
975
- if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
976
- y.dlShiftTo(j, t);
977
- r.subTo(t, r);
978
- while (r[i] < --qd) {
979
- r.subTo(t, r);
980
- }
981
- }
982
- }
983
- if (q != null) {
984
- r.drShiftTo(ys, q);
985
- if (ts != ms) {
986
- BigInteger.ZERO.subTo(q, q);
987
- }
988
- }
989
- r.t = ys;
990
- r.clamp();
991
- if (nsh > 0) {
992
- r.rShiftTo(nsh, r);
993
- } // Denormalize remainder
994
- if (ts < 0) {
995
- BigInteger.ZERO.subTo(r, r);
996
- }
997
- }
998
- // BigInteger.prototype.invDigit = bnpInvDigit;
999
- // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
1000
- // justification:
1001
- // xy == 1 (mod m)
1002
- // xy = 1+km
1003
- // xy(2-xy) = (1+km)(1-km)
1004
- // x[y(2-xy)] = 1-k^2m^2
1005
- // x[y(2-xy)] == 1 (mod m^2)
1006
- // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
1007
- // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
1008
- // JS multiply "overflows" differently from C/C++, so care is needed here.
1009
- invDigit() {
1010
- if (this.t < 1) {
1011
- return 0;
1012
- }
1013
- const x = this[0];
1014
- if ((x & 1) == 0) {
1015
- return 0;
1016
- }
1017
- let y = x & 3; // y == 1/x mod 2^2
1018
- y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
1019
- y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
1020
- y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
1021
- // last step - calculate inverse mod DV directly;
1022
- // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
1023
- y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
1024
- // we really want the negative inverse, and -DV < y < DV
1025
- return (y > 0) ? this.DV - y : -y;
1026
- }
1027
- // BigInteger.prototype.isEven = bnpIsEven;
1028
- // (protected) true iff this is even
1029
- isEven() {
1030
- return ((this.t > 0) ? (this[0] & 1) : this.s) == 0;
1031
- }
1032
- // BigInteger.prototype.exp = bnpExp;
1033
- // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
1034
- exp(e, z) {
1035
- if (e > 0xffffffff || e < 1) {
1036
- return BigInteger.ONE;
1037
- }
1038
- let r = nbi();
1039
- let r2 = nbi();
1040
- const g = z.convert(this);
1041
- let i = nbits(e) - 1;
1042
- g.copyTo(r);
1043
- while (--i >= 0) {
1044
- z.sqrTo(r, r2);
1045
- if ((e & (1 << i)) > 0) {
1046
- z.mulTo(r2, g, r);
1047
- }
1048
- else {
1049
- const t = r;
1050
- r = r2;
1051
- r2 = t;
1052
- }
1053
- }
1054
- return z.revert(r);
1055
- }
1056
- // BigInteger.prototype.chunkSize = bnpChunkSize;
1057
- // (protected) return x s.t. r^x < DV
1058
- chunkSize(r) {
1059
- return Math.floor(Math.LN2 * this.DB / Math.log(r));
1060
- }
1061
- // BigInteger.prototype.toRadix = bnpToRadix;
1062
- // (protected) convert to radix string
1063
- toRadix(b) {
1064
- if (b == null) {
1065
- b = 10;
1066
- }
1067
- if (this.signum() == 0 || b < 2 || b > 36) {
1068
- return "0";
1069
- }
1070
- const cs = this.chunkSize(b);
1071
- const a = Math.pow(b, cs);
1072
- const d = nbv(a);
1073
- const y = nbi();
1074
- const z = nbi();
1075
- let r = "";
1076
- this.divRemTo(d, y, z);
1077
- while (y.signum() > 0) {
1078
- r = (a + z.intValue()).toString(b).substr(1) + r;
1079
- y.divRemTo(d, y, z);
1080
- }
1081
- return z.intValue().toString(b) + r;
1082
- }
1083
- // BigInteger.prototype.fromRadix = bnpFromRadix;
1084
- // (protected) convert from radix string
1085
- fromRadix(s, b) {
1086
- this.fromInt(0);
1087
- if (b == null) {
1088
- b = 10;
1089
- }
1090
- const cs = this.chunkSize(b);
1091
- const d = Math.pow(b, cs);
1092
- let mi = false;
1093
- let j = 0;
1094
- let w = 0;
1095
- for (let i = 0; i < s.length; ++i) {
1096
- const x = intAt(s, i);
1097
- if (x < 0) {
1098
- if (s.charAt(i) == "-" && this.signum() == 0) {
1099
- mi = true;
1100
- }
1101
- continue;
1102
- }
1103
- w = b * w + x;
1104
- if (++j >= cs) {
1105
- this.dMultiply(d);
1106
- this.dAddOffset(w, 0);
1107
- j = 0;
1108
- w = 0;
1109
- }
1110
- }
1111
- if (j > 0) {
1112
- this.dMultiply(Math.pow(b, j));
1113
- this.dAddOffset(w, 0);
1114
- }
1115
- if (mi) {
1116
- BigInteger.ZERO.subTo(this, this);
1117
- }
1118
- }
1119
- // BigInteger.prototype.fromNumber = bnpFromNumber;
1120
- // (protected) alternate constructor
1121
- fromNumber(a, b, c) {
1122
- if ("number" == typeof b) {
1123
- // new BigInteger(int,int,RNG)
1124
- if (a < 2) {
1125
- this.fromInt(1);
1126
- }
1127
- else {
1128
- this.fromNumber(a, c);
1129
- if (!this.testBit(a - 1)) {
1130
- // force MSB set
1131
- this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1132
- }
1133
- if (this.isEven()) {
1134
- this.dAddOffset(1, 0);
1135
- } // force odd
1136
- while (!this.isProbablePrime(b)) {
1137
- this.dAddOffset(2, 0);
1138
- if (this.bitLength() > a) {
1139
- this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
1140
- }
1141
- }
1142
- }
1143
- }
1144
- else {
1145
- // new BigInteger(int,RNG)
1146
- const x = [];
1147
- const t = a & 7;
1148
- x.length = (a >> 3) + 1;
1149
- b.nextBytes(x);
1150
- if (t > 0) {
1151
- x[0] &= ((1 << t) - 1);
1152
- }
1153
- else {
1154
- x[0] = 0;
1155
- }
1156
- this.fromString(x, 256);
1157
- }
1158
- }
1159
- // BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
1160
- // (protected) r = this op a (bitwise)
1161
- bitwiseTo(a, op, r) {
1162
- let i;
1163
- let f;
1164
- const m = Math.min(a.t, this.t);
1165
- for (i = 0; i < m; ++i) {
1166
- r[i] = op(this[i], a[i]);
1167
- }
1168
- if (a.t < this.t) {
1169
- f = a.s & this.DM;
1170
- for (i = m; i < this.t; ++i) {
1171
- r[i] = op(this[i], f);
1172
- }
1173
- r.t = this.t;
1174
- }
1175
- else {
1176
- f = this.s & this.DM;
1177
- for (i = m; i < a.t; ++i) {
1178
- r[i] = op(f, a[i]);
1179
- }
1180
- r.t = a.t;
1181
- }
1182
- r.s = op(this.s, a.s);
1183
- r.clamp();
1184
- }
1185
- // BigInteger.prototype.changeBit = bnpChangeBit;
1186
- // (protected) this op (1<<n)
1187
- changeBit(n, op) {
1188
- const r = BigInteger.ONE.shiftLeft(n);
1189
- this.bitwiseTo(r, op, r);
1190
- return r;
1191
- }
1192
- // BigInteger.prototype.addTo = bnpAddTo;
1193
- // (protected) r = this + a
1194
- addTo(a, r) {
1195
- let i = 0;
1196
- let c = 0;
1197
- const m = Math.min(a.t, this.t);
1198
- while (i < m) {
1199
- c += this[i] + a[i];
1200
- r[i++] = c & this.DM;
1201
- c >>= this.DB;
1202
- }
1203
- if (a.t < this.t) {
1204
- c += a.s;
1205
- while (i < this.t) {
1206
- c += this[i];
1207
- r[i++] = c & this.DM;
1208
- c >>= this.DB;
1209
- }
1210
- c += this.s;
1211
- }
1212
- else {
1213
- c += this.s;
1214
- while (i < a.t) {
1215
- c += a[i];
1216
- r[i++] = c & this.DM;
1217
- c >>= this.DB;
1218
- }
1219
- c += a.s;
1220
- }
1221
- r.s = (c < 0) ? -1 : 0;
1222
- if (c > 0) {
1223
- r[i++] = c;
1224
- }
1225
- else if (c < -1) {
1226
- r[i++] = this.DV + c;
1227
- }
1228
- r.t = i;
1229
- r.clamp();
1230
- }
1231
- // BigInteger.prototype.dMultiply = bnpDMultiply;
1232
- // (protected) this *= n, this >= 0, 1 < n < DV
1233
- dMultiply(n) {
1234
- this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
1235
- ++this.t;
1236
- this.clamp();
1237
- }
1238
- // BigInteger.prototype.dAddOffset = bnpDAddOffset;
1239
- // (protected) this += n << w words, this >= 0
1240
- dAddOffset(n, w) {
1241
- if (n == 0) {
1242
- return;
1243
- }
1244
- while (this.t <= w) {
1245
- this[this.t++] = 0;
1246
- }
1247
- this[w] += n;
1248
- while (this[w] >= this.DV) {
1249
- this[w] -= this.DV;
1250
- if (++w >= this.t) {
1251
- this[this.t++] = 0;
1252
- }
1253
- ++this[w];
1254
- }
1255
- }
1256
- // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
1257
- // (protected) r = lower n words of "this * a", a.t <= n
1258
- // "this" should be the larger one if appropriate.
1259
- multiplyLowerTo(a, n, r) {
1260
- let i = Math.min(this.t + a.t, n);
1261
- r.s = 0; // assumes a,this >= 0
1262
- r.t = i;
1263
- while (i > 0) {
1264
- r[--i] = 0;
1265
- }
1266
- for (const j = r.t - this.t; i < j; ++i) {
1267
- r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
1268
- }
1269
- for (const j = Math.min(a.t, n); i < j; ++i) {
1270
- this.am(0, a[i], r, i, 0, n - i);
1271
- }
1272
- r.clamp();
1273
- }
1274
- // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
1275
- // (protected) r = "this * a" without lower n words, n > 0
1276
- // "this" should be the larger one if appropriate.
1277
- multiplyUpperTo(a, n, r) {
1278
- --n;
1279
- let i = r.t = this.t + a.t - n;
1280
- r.s = 0; // assumes a,this >= 0
1281
- while (--i >= 0) {
1282
- r[i] = 0;
1283
- }
1284
- for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
1285
- r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
1286
- }
1287
- r.clamp();
1288
- r.drShiftTo(1, r);
1289
- }
1290
- // BigInteger.prototype.modInt = bnpModInt;
1291
- // (protected) this % n, n < 2^26
1292
- modInt(n) {
1293
- if (n <= 0) {
1294
- return 0;
1295
- }
1296
- const d = this.DV % n;
1297
- let r = (this.s < 0) ? n - 1 : 0;
1298
- if (this.t > 0) {
1299
- if (d == 0) {
1300
- r = this[0] % n;
1301
- }
1302
- else {
1303
- for (let i = this.t - 1; i >= 0; --i) {
1304
- r = (d * r + this[i]) % n;
1305
- }
1306
- }
1307
- }
1308
- return r;
1309
- }
1310
- // BigInteger.prototype.millerRabin = bnpMillerRabin;
1311
- // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1312
- millerRabin(t) {
1313
- const n1 = this.subtract(BigInteger.ONE);
1314
- const k = n1.getLowestSetBit();
1315
- if (k <= 0) {
1316
- return false;
1317
- }
1318
- const r = n1.shiftRight(k);
1319
- t = (t + 1) >> 1;
1320
- if (t > lowprimes.length) {
1321
- t = lowprimes.length;
1322
- }
1323
- const a = nbi();
1324
- for (let i = 0; i < t; ++i) {
1325
- // Pick bases at random, instead of starting at 2
1326
- a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
1327
- let y = a.modPow(r, this);
1328
- if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1329
- let j = 1;
1330
- while (j++ < k && y.compareTo(n1) != 0) {
1331
- y = y.modPowInt(2, this);
1332
- if (y.compareTo(BigInteger.ONE) == 0) {
1333
- return false;
1334
- }
1335
- }
1336
- if (y.compareTo(n1) != 0) {
1337
- return false;
1338
- }
1339
- }
1340
- }
1341
- return true;
1342
- }
1343
- // BigInteger.prototype.square = bnSquare;
1344
- // (public) this^2
1345
- square() {
1346
- const r = nbi();
1347
- this.squareTo(r);
1348
- return r;
1349
- }
1350
- //#region ASYNC
1351
- // Public API method
1352
- gcda(a, callback) {
1353
- let x = (this.s < 0) ? this.negate() : this.clone();
1354
- let y = (a.s < 0) ? a.negate() : a.clone();
1355
- if (x.compareTo(y) < 0) {
1356
- const t = x;
1357
- x = y;
1358
- y = t;
1359
- }
1360
- let i = x.getLowestSetBit();
1361
- let g = y.getLowestSetBit();
1362
- if (g < 0) {
1363
- callback(x);
1364
- return;
1365
- }
1366
- if (i < g) {
1367
- g = i;
1368
- }
1369
- if (g > 0) {
1370
- x.rShiftTo(g, x);
1371
- y.rShiftTo(g, y);
1372
- }
1373
- // Workhorse of the algorithm, gets called 200 - 800 times per 512 bit keygen.
1374
- const gcda1 = function () {
1375
- if ((i = x.getLowestSetBit()) > 0) {
1376
- x.rShiftTo(i, x);
1377
- }
1378
- if ((i = y.getLowestSetBit()) > 0) {
1379
- y.rShiftTo(i, y);
1380
- }
1381
- if (x.compareTo(y) >= 0) {
1382
- x.subTo(y, x);
1383
- x.rShiftTo(1, x);
1384
- }
1385
- else {
1386
- y.subTo(x, y);
1387
- y.rShiftTo(1, y);
1388
- }
1389
- if (!(x.signum() > 0)) {
1390
- if (g > 0) {
1391
- y.lShiftTo(g, y);
1392
- }
1393
- setTimeout(function () { callback(y); }, 0); // escape
1394
- }
1395
- else {
1396
- setTimeout(gcda1, 0);
1397
- }
1398
- };
1399
- setTimeout(gcda1, 10);
1400
- }
1401
- // (protected) alternate constructor
1402
- fromNumberAsync(a, b, c, callback) {
1403
- if ("number" == typeof b) {
1404
- if (a < 2) {
1405
- this.fromInt(1);
1406
- }
1407
- else {
1408
- this.fromNumber(a, c);
1409
- if (!this.testBit(a - 1)) {
1410
- this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1411
- }
1412
- if (this.isEven()) {
1413
- this.dAddOffset(1, 0);
1414
- }
1415
- const bnp = this;
1416
- const bnpfn1 = function () {
1417
- bnp.dAddOffset(2, 0);
1418
- if (bnp.bitLength() > a) {
1419
- bnp.subTo(BigInteger.ONE.shiftLeft(a - 1), bnp);
1420
- }
1421
- if (bnp.isProbablePrime(b)) {
1422
- setTimeout(function () { callback(); }, 0); // escape
1423
- }
1424
- else {
1425
- setTimeout(bnpfn1, 0);
1426
- }
1427
- };
1428
- setTimeout(bnpfn1, 0);
1429
- }
1430
- }
1431
- else {
1432
- const x = [];
1433
- const t = a & 7;
1434
- x.length = (a >> 3) + 1;
1435
- b.nextBytes(x);
1436
- if (t > 0) {
1437
- x[0] &= ((1 << t) - 1);
1438
- }
1439
- else {
1440
- x[0] = 0;
1441
- }
1442
- this.fromString(x, 256);
1443
- }
1444
- }
1445
- }
1446
- //#region REDUCERS
1447
- //#region NullExp
1448
- class NullExp {
1449
- constructor() {
1450
- }
1451
- // NullExp.prototype.convert = nNop;
1452
- convert(x) {
1453
- return x;
1454
- }
1455
- // NullExp.prototype.revert = nNop;
1456
- revert(x) {
1457
- return x;
1458
- }
1459
- // NullExp.prototype.mulTo = nMulTo;
1460
- mulTo(x, y, r) {
1461
- x.multiplyTo(y, r);
1462
- }
1463
- // NullExp.prototype.sqrTo = nSqrTo;
1464
- sqrTo(x, r) {
1465
- x.squareTo(r);
1466
- }
1467
- }
1468
- // Modular reduction using "classic" algorithm
1469
- class Classic {
1470
- constructor(m) {
1471
- this.m = m;
1472
- }
1473
- // Classic.prototype.convert = cConvert;
1474
- convert(x) {
1475
- if (x.s < 0 || x.compareTo(this.m) >= 0) {
1476
- return x.mod(this.m);
1477
- }
1478
- else {
1479
- return x;
1480
- }
1481
- }
1482
- // Classic.prototype.revert = cRevert;
1483
- revert(x) {
1484
- return x;
1485
- }
1486
- // Classic.prototype.reduce = cReduce;
1487
- reduce(x) {
1488
- x.divRemTo(this.m, null, x);
1489
- }
1490
- // Classic.prototype.mulTo = cMulTo;
1491
- mulTo(x, y, r) {
1492
- x.multiplyTo(y, r);
1493
- this.reduce(r);
1494
- }
1495
- // Classic.prototype.sqrTo = cSqrTo;
1496
- sqrTo(x, r) {
1497
- x.squareTo(r);
1498
- this.reduce(r);
1499
- }
1500
- }
1501
- //#endregion
1502
- //#region Montgomery
1503
- // Montgomery reduction
1504
- class Montgomery {
1505
- constructor(m) {
1506
- this.m = m;
1507
- this.mp = m.invDigit();
1508
- this.mpl = this.mp & 0x7fff;
1509
- this.mph = this.mp >> 15;
1510
- this.um = (1 << (m.DB - 15)) - 1;
1511
- this.mt2 = 2 * m.t;
1512
- }
1513
- // Montgomery.prototype.convert = montConvert;
1514
- // xR mod m
1515
- convert(x) {
1516
- const r = nbi();
1517
- x.abs().dlShiftTo(this.m.t, r);
1518
- r.divRemTo(this.m, null, r);
1519
- if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
1520
- this.m.subTo(r, r);
1521
- }
1522
- return r;
1523
- }
1524
- // Montgomery.prototype.revert = montRevert;
1525
- // x/R mod m
1526
- revert(x) {
1527
- const r = nbi();
1528
- x.copyTo(r);
1529
- this.reduce(r);
1530
- return r;
1531
- }
1532
- // Montgomery.prototype.reduce = montReduce;
1533
- // x = x/R mod m (HAC 14.32)
1534
- reduce(x) {
1535
- while (x.t <= this.mt2) {
1536
- // pad x so am has enough room later
1537
- x[x.t++] = 0;
1538
- }
1539
- for (let i = 0; i < this.m.t; ++i) {
1540
- // faster way of calculating u0 = x[i]*mp mod DV
1541
- let j = x[i] & 0x7fff;
1542
- const u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
1543
- // use am to combine the multiply-shift-add into one call
1544
- j = i + this.m.t;
1545
- x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
1546
- // propagate carry
1547
- while (x[j] >= x.DV) {
1548
- x[j] -= x.DV;
1549
- x[++j]++;
1550
- }
1551
- }
1552
- x.clamp();
1553
- x.drShiftTo(this.m.t, x);
1554
- if (x.compareTo(this.m) >= 0) {
1555
- x.subTo(this.m, x);
1556
- }
1557
- }
1558
- // Montgomery.prototype.mulTo = montMulTo;
1559
- // r = "xy/R mod m"; x,y != r
1560
- mulTo(x, y, r) {
1561
- x.multiplyTo(y, r);
1562
- this.reduce(r);
1563
- }
1564
- // Montgomery.prototype.sqrTo = montSqrTo;
1565
- // r = "x^2/R mod m"; x != r
1566
- sqrTo(x, r) {
1567
- x.squareTo(r);
1568
- this.reduce(r);
1569
- }
1570
- }
1571
- //#endregion Montgomery
1572
- //#region Barrett
1573
- // Barrett modular reduction
1574
- class Barrett {
1575
- constructor(m) {
1576
- this.m = m;
1577
- // setup Barrett
1578
- this.r2 = nbi();
1579
- this.q3 = nbi();
1580
- BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
1581
- this.mu = this.r2.divide(m);
1582
- }
1583
- // Barrett.prototype.convert = barrettConvert;
1584
- convert(x) {
1585
- if (x.s < 0 || x.t > 2 * this.m.t) {
1586
- return x.mod(this.m);
1587
- }
1588
- else if (x.compareTo(this.m) < 0) {
1589
- return x;
1590
- }
1591
- else {
1592
- const r = nbi();
1593
- x.copyTo(r);
1594
- this.reduce(r);
1595
- return r;
1596
- }
1597
- }
1598
- // Barrett.prototype.revert = barrettRevert;
1599
- revert(x) {
1600
- return x;
1601
- }
1602
- // Barrett.prototype.reduce = barrettReduce;
1603
- // x = x mod m (HAC 14.42)
1604
- reduce(x) {
1605
- x.drShiftTo(this.m.t - 1, this.r2);
1606
- if (x.t > this.m.t + 1) {
1607
- x.t = this.m.t + 1;
1608
- x.clamp();
1609
- }
1610
- this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
1611
- this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
1612
- while (x.compareTo(this.r2) < 0) {
1613
- x.dAddOffset(1, this.m.t + 1);
1614
- }
1615
- x.subTo(this.r2, x);
1616
- while (x.compareTo(this.m) >= 0) {
1617
- x.subTo(this.m, x);
1618
- }
1619
- }
1620
- // Barrett.prototype.mulTo = barrettMulTo;
1621
- // r = x*y mod m; x,y != r
1622
- mulTo(x, y, r) {
1623
- x.multiplyTo(y, r);
1624
- this.reduce(r);
1625
- }
1626
- // Barrett.prototype.sqrTo = barrettSqrTo;
1627
- // r = x^2 mod m; x != r
1628
- sqrTo(x, r) {
1629
- x.squareTo(r);
1630
- this.reduce(r);
1631
- }
1632
- }
1633
- //#endregion
1634
- //#endregion REDUCERS
1635
- // return new, unset BigInteger
1636
- export function nbi() { return new BigInteger(null); }
1637
- export function parseBigInt(str, r) {
1638
- return new BigInteger(str, r);
1639
- }
1640
- // am: Compute w_j += (x*this_i), propagate carries,
1641
- // c is initial carry, returns final carry.
1642
- // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
1643
- // We need to select the fastest one that works in this environment.
1644
- const inBrowser = typeof navigator !== "undefined";
1645
- if (inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
1646
- // am2 avoids a big mult-and-extract completely.
1647
- // Max digit bits should be <= 30 because we do bitwise ops
1648
- // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
1649
- BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
1650
- const xl = x & 0x7fff;
1651
- const xh = x >> 15;
1652
- while (--n >= 0) {
1653
- let l = this[i] & 0x7fff;
1654
- const h = this[i++] >> 15;
1655
- const m = xh * l + h * xl;
1656
- l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
1657
- c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
1658
- w[j++] = l & 0x3fffffff;
1659
- }
1660
- return c;
1661
- };
1662
- dbits = 30;
1663
- }
1664
- else if (inBrowser && j_lm && (navigator.appName != "Netscape")) {
1665
- // am1: use a single mult and divide to get the high bits,
1666
- // max digit bits should be 26 because
1667
- // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
1668
- BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
1669
- while (--n >= 0) {
1670
- const v = x * this[i++] + w[j] + c;
1671
- c = Math.floor(v / 0x4000000);
1672
- w[j++] = v & 0x3ffffff;
1673
- }
1674
- return c;
1675
- };
1676
- dbits = 26;
1677
- }
1678
- else { // Mozilla/Netscape seems to prefer am3
1679
- // Alternately, set max digit bits to 28 since some
1680
- // browsers slow down when dealing with 32-bit numbers.
1681
- BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
1682
- const xl = x & 0x3fff;
1683
- const xh = x >> 14;
1684
- while (--n >= 0) {
1685
- let l = this[i] & 0x3fff;
1686
- const h = this[i++] >> 14;
1687
- const m = xh * l + h * xl;
1688
- l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
1689
- c = (l >> 28) + (m >> 14) + xh * h;
1690
- w[j++] = l & 0xfffffff;
1691
- }
1692
- return c;
1693
- };
1694
- dbits = 28;
1695
- }
1696
- BigInteger.prototype.DB = dbits;
1697
- BigInteger.prototype.DM = ((1 << dbits) - 1);
1698
- BigInteger.prototype.DV = (1 << dbits);
1699
- const BI_FP = 52;
1700
- BigInteger.prototype.FV = Math.pow(2, BI_FP);
1701
- BigInteger.prototype.F1 = BI_FP - dbits;
1702
- BigInteger.prototype.F2 = 2 * dbits - BI_FP;
1703
- // Digit conversions
1704
- const BI_RC = [];
1705
- let rr;
1706
- let vv;
1707
- rr = "0".charCodeAt(0);
1708
- for (vv = 0; vv <= 9; ++vv) {
1709
- BI_RC[rr++] = vv;
1710
- }
1711
- rr = "a".charCodeAt(0);
1712
- for (vv = 10; vv < 36; ++vv) {
1713
- BI_RC[rr++] = vv;
1714
- }
1715
- rr = "A".charCodeAt(0);
1716
- for (vv = 10; vv < 36; ++vv) {
1717
- BI_RC[rr++] = vv;
1718
- }
1719
- export function intAt(s, i) {
1720
- const c = BI_RC[s.charCodeAt(i)];
1721
- return (c == null) ? -1 : c;
1722
- }
1723
- // return bigint initialized to value
1724
- export function nbv(i) {
1725
- const r = nbi();
1726
- r.fromInt(i);
1727
- return r;
1728
- }
1729
- // returns bit length of the integer x
1730
- export function nbits(x) {
1731
- let r = 1;
1732
- let t;
1733
- if ((t = x >>> 16) != 0) {
1734
- x = t;
1735
- r += 16;
1736
- }
1737
- if ((t = x >> 8) != 0) {
1738
- x = t;
1739
- r += 8;
1740
- }
1741
- if ((t = x >> 4) != 0) {
1742
- x = t;
1743
- r += 4;
1744
- }
1745
- if ((t = x >> 2) != 0) {
1746
- x = t;
1747
- r += 2;
1748
- }
1749
- if ((t = x >> 1) != 0) {
1750
- x = t;
1751
- r += 1;
1752
- }
1753
- return r;
1754
- }
1755
- // "constants"
1756
- BigInteger.ZERO = nbv(0);
1757
- BigInteger.ONE = nbv(1);