@bitpay-labs/bitcore-wallet-service 11.5.2

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 (949) hide show
  1. package/.coveralls.yml +1 -0
  2. package/.travis.yml +27 -0
  3. package/DKG-flow.png +0 -0
  4. package/DSG-flow.png +0 -0
  5. package/Dockerfile +18 -0
  6. package/Installation.md +138 -0
  7. package/LICENCE +22 -0
  8. package/Makefile +5 -0
  9. package/README.md +429 -0
  10. package/TSS.md +136 -0
  11. package/bws.example.config.js +451 -0
  12. package/package.json +119 -0
  13. package/scripts/checkCopayerIds.js +118 -0
  14. package/scripts/clean_db.mongodb +5 -0
  15. package/scripts/deleteDupAddresses.mongo +6 -0
  16. package/scripts/deleteWallet.mongo +18 -0
  17. package/scripts/delme.ts +468 -0
  18. package/scripts/findEmail.js +32 -0
  19. package/scripts/fixAddressType.js +98 -0
  20. package/scripts/getSolStats2.js +81 -0
  21. package/scripts/migrateToNamedTestnets.js +191 -0
  22. package/scripts/migrateWalletsNetwork.js +204 -0
  23. package/scripts/preview-email.js +359 -0
  24. package/scripts/purgeNotifications.js +107 -0
  25. package/scripts/resetV8registration.mongo +21 -0
  26. package/scripts/v8tool-list.ts +93 -0
  27. package/scripts/v8tool.ts +82 -0
  28. package/scripts/walletStats.js +290 -0
  29. package/src/app.ts +28 -0
  30. package/src/bcmonitor/bcmonitor.ts +11 -0
  31. package/src/bws.ts +85 -0
  32. package/src/cleanfiatrates/cleanfiatrates.ts +9 -0
  33. package/src/config.ts +540 -0
  34. package/src/db/.empty +0 -0
  35. package/src/deprecated-serverMessages.ts +15 -0
  36. package/src/emailservice/emailservice.ts +11 -0
  37. package/src/externalservices/banxa.ts +261 -0
  38. package/src/externalservices/changelly.ts +371 -0
  39. package/src/externalservices/coingecko.ts +453 -0
  40. package/src/externalservices/moonpay.ts +435 -0
  41. package/src/externalservices/oneInch.ts +169 -0
  42. package/src/externalservices/ramp.ts +259 -0
  43. package/src/externalservices/sardine.ts +237 -0
  44. package/src/externalservices/simplex.ts +281 -0
  45. package/src/externalservices/thorswap.ts +197 -0
  46. package/src/externalservices/transak.ts +320 -0
  47. package/src/externalservices/wyre.ts +131 -0
  48. package/src/fiatrateservice/fiatrateservice.ts +15 -0
  49. package/src/index.ts +9 -0
  50. package/src/lib/bchaddresstranslator.ts +59 -0
  51. package/src/lib/blockchainexplorer.ts +84 -0
  52. package/src/lib/blockchainexplorers/v8/client.ts +177 -0
  53. package/src/lib/blockchainexplorers/v8.ts +730 -0
  54. package/src/lib/blockchainmonitor.ts +423 -0
  55. package/src/lib/chain/arb/index.ts +8 -0
  56. package/src/lib/chain/base/index.ts +8 -0
  57. package/src/lib/chain/bch/index.ts +40 -0
  58. package/src/lib/chain/btc/index.ts +991 -0
  59. package/src/lib/chain/doge/index.ts +387 -0
  60. package/src/lib/chain/eth/abi-erc20.ts +222 -0
  61. package/src/lib/chain/eth/abi-invoice.ts +277 -0
  62. package/src/lib/chain/eth/index.ts +657 -0
  63. package/src/lib/chain/index.ts +178 -0
  64. package/src/lib/chain/ltc/index.ts +9 -0
  65. package/src/lib/chain/matic/index.ts +8 -0
  66. package/src/lib/chain/op/index.ts +8 -0
  67. package/src/lib/chain/sol/index.ts +349 -0
  68. package/src/lib/chain/xrp/index.ts +338 -0
  69. package/src/lib/cleanfiatrates.ts +160 -0
  70. package/src/lib/common/constants.ts +231 -0
  71. package/src/lib/common/defaults.ts +436 -0
  72. package/src/lib/common/index.ts +11 -0
  73. package/src/lib/common/services.ts +43 -0
  74. package/src/lib/common/utils.ts +506 -0
  75. package/src/lib/emailservice.ts +741 -0
  76. package/src/lib/errors/clienterror.ts +44 -0
  77. package/src/lib/errors/errordefinitions.ts +158 -0
  78. package/src/lib/expressapp.ts +2415 -0
  79. package/src/lib/fiatrateproviders/bitpay.ts +20 -0
  80. package/src/lib/fiatrateproviders/bitstamp.ts +16 -0
  81. package/src/lib/fiatrateproviders/index.ts +8 -0
  82. package/src/lib/fiatrateproviders/provider.d.ts +10 -0
  83. package/src/lib/fiatrateservice.ts +338 -0
  84. package/src/lib/iconsconfig.ts +31 -0
  85. package/src/lib/index.ts +0 -0
  86. package/src/lib/lock.ts +112 -0
  87. package/src/lib/logger.ts +77 -0
  88. package/src/lib/messagebroker.ts +42 -0
  89. package/src/lib/model/address.ts +226 -0
  90. package/src/lib/model/addressmanager.ts +138 -0
  91. package/src/lib/model/advertisement.ts +84 -0
  92. package/src/lib/model/copayer.ts +162 -0
  93. package/src/lib/model/email.ts +103 -0
  94. package/src/lib/model/index.ts +12 -0
  95. package/src/lib/model/notification.ts +77 -0
  96. package/src/lib/model/preferences.ts +79 -0
  97. package/src/lib/model/pushnotificationsub.ts +50 -0
  98. package/src/lib/model/session.ts +65 -0
  99. package/src/lib/model/tsskeygen.ts +154 -0
  100. package/src/lib/model/tsssign.ts +136 -0
  101. package/src/lib/model/txconfirmationsub.ts +50 -0
  102. package/src/lib/model/txnote.ts +60 -0
  103. package/src/lib/model/txproposal.ts +561 -0
  104. package/src/lib/model/txproposal_legacy.ts +236 -0
  105. package/src/lib/model/txproposalaction.ts +48 -0
  106. package/src/lib/model/wallet.ts +359 -0
  107. package/src/lib/notificationbroadcaster.ts +17 -0
  108. package/src/lib/pushnotificationsservice.ts +802 -0
  109. package/src/lib/routes/helpers/error.ts +51 -0
  110. package/src/lib/routes/helpers/index.ts +1 -0
  111. package/src/lib/routes/middleware/authRequest.ts +117 -0
  112. package/src/lib/routes/middleware/authTssRequest.ts +66 -0
  113. package/src/lib/routes/middleware/createWalletLimiter.ts +21 -0
  114. package/src/lib/routes/middleware/log.ts +63 -0
  115. package/src/lib/routes/middleware/verifyTssMessage.ts +37 -0
  116. package/src/lib/routes/tss.ts +123 -0
  117. package/src/lib/server.ts +5342 -0
  118. package/src/lib/stats.ts +174 -0
  119. package/src/lib/storage.ts +1919 -0
  120. package/src/lib/tss.ts +446 -0
  121. package/src/lib/updatestats.ts +291 -0
  122. package/src/messagebroker/messagebroker.ts +18 -0
  123. package/src/pushnotificationsservice/pushnotificationsservice.ts +11 -0
  124. package/src/serverMessages.ts +30 -0
  125. package/src/types/chain.d.ts +62 -0
  126. package/src/types/emailservice.d.ts +11 -0
  127. package/src/types/expressapp.d.ts +15 -0
  128. package/src/types/externalservices.d.ts +41 -0
  129. package/src/types/notifications.d.ts +8 -0
  130. package/src/types/pushnotificationservice.d.ts +51 -0
  131. package/src/types/server.d.ts +24 -0
  132. package/src/updatestats/updatestats.ts +10 -0
  133. package/start-docker.sh +18 -0
  134. package/start.sh +38 -0
  135. package/static/images/down-arrow-green.png +0 -0
  136. package/static/images/failed-icon.png +0 -0
  137. package/static/images/green-check.png +0 -0
  138. package/static/images/person-plus.png +0 -0
  139. package/static/images/up-arrow-gray.png +0 -0
  140. package/static/images/writing-gray.png +0 -0
  141. package/stop.sh +19 -0
  142. package/templates/en/new_copayer.html +13 -0
  143. package/templates/en/new_copayer.plain +2 -0
  144. package/templates/en/new_incoming_tx.html +11 -0
  145. package/templates/en/new_incoming_tx.plain +2 -0
  146. package/templates/en/new_incoming_tx_testnet.html +13 -0
  147. package/templates/en/new_incoming_tx_testnet.plain +2 -0
  148. package/templates/en/new_outgoing_tx.html +11 -0
  149. package/templates/en/new_outgoing_tx.plain +2 -0
  150. package/templates/en/new_tx_proposal.html +13 -0
  151. package/templates/en/new_tx_proposal.plain +2 -0
  152. package/templates/en/new_zero_outgoing_tx.html +13 -0
  153. package/templates/en/new_zero_outgoing_tx.plain +2 -0
  154. package/templates/en/tx_confirmation.html +13 -0
  155. package/templates/en/tx_confirmation.plain +2 -0
  156. package/templates/en/tx_confirmation_receiver.html +13 -0
  157. package/templates/en/tx_confirmation_receiver.plain +2 -0
  158. package/templates/en/tx_confirmation_sender.html +13 -0
  159. package/templates/en/tx_confirmation_sender.plain +2 -0
  160. package/templates/en/txp_finally_rejected.html +13 -0
  161. package/templates/en/txp_finally_rejected.plain +2 -0
  162. package/templates/en/wallet_complete.html +13 -0
  163. package/templates/en/wallet_complete.plain +2 -0
  164. package/templates/es/new_copayer.html +13 -0
  165. package/templates/es/new_copayer.plain +2 -0
  166. package/templates/es/new_incoming_tx.html +11 -0
  167. package/templates/es/new_incoming_tx.plain +2 -0
  168. package/templates/es/new_incoming_tx_testnet.html +13 -0
  169. package/templates/es/new_incoming_tx_testnet.plain +2 -0
  170. package/templates/es/new_outgoing_tx.html +11 -0
  171. package/templates/es/new_outgoing_tx.plain +2 -0
  172. package/templates/es/new_tx_proposal.html +13 -0
  173. package/templates/es/new_tx_proposal.plain +2 -0
  174. package/templates/es/new_zero_outgoing_tx.html +13 -0
  175. package/templates/es/new_zero_outgoing_tx.plain +2 -0
  176. package/templates/es/tx_confirmation.html +13 -0
  177. package/templates/es/tx_confirmation.plain +2 -0
  178. package/templates/es/tx_confirmation_receiver.html +13 -0
  179. package/templates/es/tx_confirmation_receiver.plain +2 -0
  180. package/templates/es/tx_confirmation_sender.html +13 -0
  181. package/templates/es/tx_confirmation_sender.plain +2 -0
  182. package/templates/es/txp_finally_rejected.html +13 -0
  183. package/templates/es/txp_finally_rejected.plain +2 -0
  184. package/templates/es/wallet_complete.html +13 -0
  185. package/templates/es/wallet_complete.plain +2 -0
  186. package/templates/fr/new_copayer.html +13 -0
  187. package/templates/fr/new_copayer.plain +2 -0
  188. package/templates/fr/new_incoming_tx.html +11 -0
  189. package/templates/fr/new_incoming_tx.plain +2 -0
  190. package/templates/fr/new_incoming_tx_testnet.html +13 -0
  191. package/templates/fr/new_incoming_tx_testnet.plain +2 -0
  192. package/templates/fr/new_outgoing_tx.html +11 -0
  193. package/templates/fr/new_outgoing_tx.plain +2 -0
  194. package/templates/fr/new_tx_proposal.html +13 -0
  195. package/templates/fr/new_tx_proposal.plain +2 -0
  196. package/templates/fr/new_zero_outgoing_tx.html +13 -0
  197. package/templates/fr/new_zero_outgoing_tx.plain +2 -0
  198. package/templates/fr/tx_confirmation.html +13 -0
  199. package/templates/fr/tx_confirmation.plain +2 -0
  200. package/templates/fr/tx_confirmation_receiver.html +13 -0
  201. package/templates/fr/tx_confirmation_receiver.plain +2 -0
  202. package/templates/fr/tx_confirmation_sender.html +13 -0
  203. package/templates/fr/tx_confirmation_sender.plain +2 -0
  204. package/templates/fr/txp_finally_rejected.html +13 -0
  205. package/templates/fr/txp_finally_rejected.plain +2 -0
  206. package/templates/fr/wallet_complete.html +13 -0
  207. package/templates/fr/wallet_complete.plain +2 -0
  208. package/templates/ja/new_copayer.html +13 -0
  209. package/templates/ja/new_copayer.plain +2 -0
  210. package/templates/ja/new_incoming_tx.html +11 -0
  211. package/templates/ja/new_incoming_tx.plain +2 -0
  212. package/templates/ja/new_incoming_tx_testnet.html +13 -0
  213. package/templates/ja/new_incoming_tx_testnet.plain +2 -0
  214. package/templates/ja/new_outgoing_tx.html +11 -0
  215. package/templates/ja/new_outgoing_tx.plain +2 -0
  216. package/templates/ja/new_tx_proposal.html +13 -0
  217. package/templates/ja/new_tx_proposal.plain +2 -0
  218. package/templates/ja/new_zero_outgoing_tx.html +13 -0
  219. package/templates/ja/new_zero_outgoing_tx.plain +2 -0
  220. package/templates/ja/tx_confirmation.html +13 -0
  221. package/templates/ja/tx_confirmation.plain +2 -0
  222. package/templates/ja/tx_confirmation_receiver.html +13 -0
  223. package/templates/ja/tx_confirmation_receiver.plain +2 -0
  224. package/templates/ja/tx_confirmation_sender.html +13 -0
  225. package/templates/ja/tx_confirmation_sender.plain +2 -0
  226. package/templates/ja/txp_finally_rejected.html +13 -0
  227. package/templates/ja/txp_finally_rejected.plain +2 -0
  228. package/templates/ja/wallet_complete.html +13 -0
  229. package/templates/ja/wallet_complete.plain +2 -0
  230. package/templates/master-template.html +494 -0
  231. package/test/bchaddresstranslator.test.ts +50 -0
  232. package/test/blockchainexplorer.test.ts +66 -0
  233. package/test/chain/bch.test.ts +115 -0
  234. package/test/chain/btc.test.ts +331 -0
  235. package/test/chain/doge.test.ts +347 -0
  236. package/test/chain/eth.test.ts +21 -0
  237. package/test/chain/ltc.test.ts +328 -0
  238. package/test/chain/matic.test.ts +21 -0
  239. package/test/chain/xrp.test.ts +206 -0
  240. package/test/expressapp.test.ts +513 -0
  241. package/test/integration/bcmonitor.test.ts +381 -0
  242. package/test/integration/cashAddrMigration.test.ts +127 -0
  243. package/test/integration/data/tss/2of3/index.ts +3 -0
  244. package/test/integration/data/tss/2of3/party0.key.ts +5 -0
  245. package/test/integration/data/tss/2of3/party1.key.ts +5 -0
  246. package/test/integration/data/tss/2of3/party2.key.ts +5 -0
  247. package/test/integration/emailnotifications.test.ts +864 -0
  248. package/test/integration/externalservices/banxa.test.ts +373 -0
  249. package/test/integration/externalservices/changelly.test.ts +515 -0
  250. package/test/integration/externalservices/coinGecko.test.ts +284 -0
  251. package/test/integration/externalservices/moonpay.test.ts +569 -0
  252. package/test/integration/externalservices/oneInch.test.ts +162 -0
  253. package/test/integration/externalservices/ramp.test.ts +475 -0
  254. package/test/integration/externalservices/sardine.test.ts +352 -0
  255. package/test/integration/externalservices/simplex.test.ts +384 -0
  256. package/test/integration/externalservices/thorswap.test.ts +309 -0
  257. package/test/integration/externalservices/transak.test.ts +410 -0
  258. package/test/integration/externalservices/wyre.test.ts +270 -0
  259. package/test/integration/fiatrateservice.test.ts +979 -0
  260. package/test/integration/helpers.ts +694 -0
  261. package/test/integration/history.test.ts +1142 -0
  262. package/test/integration/hugetx.ts +6986 -0
  263. package/test/integration/pushNotifications.test.ts +1523 -0
  264. package/test/integration/server.test.ts +10740 -0
  265. package/test/integration/tss.test.ts +340 -0
  266. package/test/lock.test.ts +224 -0
  267. package/test/model/address.test.ts +187 -0
  268. package/test/model/addressmanager.test.ts +146 -0
  269. package/test/model/advertisement.test.ts +31 -0
  270. package/test/model/copayer.test.ts +131 -0
  271. package/test/model/txproposal.test.ts +185 -0
  272. package/test/model/wallet.test.ts +191 -0
  273. package/test/storage.test.ts +430 -0
  274. package/test/test-config.ts +12 -0
  275. package/test/testdata.ts +388 -0
  276. package/test/utils.test.ts +457 -0
  277. package/test/v8.test.ts +332 -0
  278. package/ts_build/package.json +119 -0
  279. package/ts_build/scripts/delme.d.ts +2 -0
  280. package/ts_build/scripts/delme.d.ts.map +1 -0
  281. package/ts_build/scripts/delme.js +453 -0
  282. package/ts_build/scripts/delme.js.map +1 -0
  283. package/ts_build/scripts/v8tool-list.d.ts +3 -0
  284. package/ts_build/scripts/v8tool-list.d.ts.map +1 -0
  285. package/ts_build/scripts/v8tool-list.js +80 -0
  286. package/ts_build/scripts/v8tool-list.js.map +1 -0
  287. package/ts_build/scripts/v8tool.d.ts +3 -0
  288. package/ts_build/scripts/v8tool.d.ts.map +1 -0
  289. package/ts_build/scripts/v8tool.js +69 -0
  290. package/ts_build/scripts/v8tool.js.map +1 -0
  291. package/ts_build/src/app.d.ts +3 -0
  292. package/ts_build/src/app.d.ts.map +1 -0
  293. package/ts_build/src/app.js +29 -0
  294. package/ts_build/src/app.js.map +1 -0
  295. package/ts_build/src/bcmonitor/bcmonitor.d.ts +3 -0
  296. package/ts_build/src/bcmonitor/bcmonitor.d.ts.map +1 -0
  297. package/ts_build/src/bcmonitor/bcmonitor.js +16 -0
  298. package/ts_build/src/bcmonitor/bcmonitor.js.map +1 -0
  299. package/ts_build/src/bws.d.ts +3 -0
  300. package/ts_build/src/bws.d.ts.map +1 -0
  301. package/ts_build/src/bws.js +98 -0
  302. package/ts_build/src/bws.js.map +1 -0
  303. package/ts_build/src/cleanfiatrates/cleanfiatrates.d.ts +3 -0
  304. package/ts_build/src/cleanfiatrates/cleanfiatrates.d.ts.map +1 -0
  305. package/ts_build/src/cleanfiatrates/cleanfiatrates.js +11 -0
  306. package/ts_build/src/cleanfiatrates/cleanfiatrates.js.map +1 -0
  307. package/ts_build/src/config.d.ts +3 -0
  308. package/ts_build/src/config.d.ts.map +1 -0
  309. package/ts_build/src/config.js +256 -0
  310. package/ts_build/src/config.js.map +1 -0
  311. package/ts_build/src/deprecated-serverMessages.d.ts +10 -0
  312. package/ts_build/src/deprecated-serverMessages.d.ts.map +1 -0
  313. package/ts_build/src/deprecated-serverMessages.js +20 -0
  314. package/ts_build/src/deprecated-serverMessages.js.map +1 -0
  315. package/ts_build/src/emailservice/emailservice.d.ts +3 -0
  316. package/ts_build/src/emailservice/emailservice.d.ts.map +1 -0
  317. package/ts_build/src/emailservice/emailservice.js +16 -0
  318. package/ts_build/src/emailservice/emailservice.js.map +1 -0
  319. package/ts_build/src/externalservices/banxa.d.ts +11 -0
  320. package/ts_build/src/externalservices/banxa.d.ts.map +1 -0
  321. package/ts_build/src/externalservices/banxa.js +254 -0
  322. package/ts_build/src/externalservices/banxa.js.map +1 -0
  323. package/ts_build/src/externalservices/changelly.d.ts +18 -0
  324. package/ts_build/src/externalservices/changelly.d.ts.map +1 -0
  325. package/ts_build/src/externalservices/changelly.js +356 -0
  326. package/ts_build/src/externalservices/changelly.js.map +1 -0
  327. package/ts_build/src/externalservices/coingecko.d.ts +43 -0
  328. package/ts_build/src/externalservices/coingecko.d.ts.map +1 -0
  329. package/ts_build/src/externalservices/coingecko.js +416 -0
  330. package/ts_build/src/externalservices/coingecko.js.map +1 -0
  331. package/ts_build/src/externalservices/moonpay.d.ts +19 -0
  332. package/ts_build/src/externalservices/moonpay.d.ts.map +1 -0
  333. package/ts_build/src/externalservices/moonpay.js +397 -0
  334. package/ts_build/src/externalservices/moonpay.js.map +1 -0
  335. package/ts_build/src/externalservices/oneInch.d.ts +11 -0
  336. package/ts_build/src/externalservices/oneInch.d.ts.map +1 -0
  337. package/ts_build/src/externalservices/oneInch.js +179 -0
  338. package/ts_build/src/externalservices/oneInch.js.map +1 -0
  339. package/ts_build/src/externalservices/ramp.d.ts +12 -0
  340. package/ts_build/src/externalservices/ramp.d.ts.map +1 -0
  341. package/ts_build/src/externalservices/ramp.js +256 -0
  342. package/ts_build/src/externalservices/ramp.js.map +1 -0
  343. package/ts_build/src/externalservices/sardine.d.ts +10 -0
  344. package/ts_build/src/externalservices/sardine.d.ts.map +1 -0
  345. package/ts_build/src/externalservices/sardine.js +232 -0
  346. package/ts_build/src/externalservices/sardine.js.map +1 -0
  347. package/ts_build/src/externalservices/simplex.d.ts +11 -0
  348. package/ts_build/src/externalservices/simplex.d.ts.map +1 -0
  349. package/ts_build/src/externalservices/simplex.js +261 -0
  350. package/ts_build/src/externalservices/simplex.js.map +1 -0
  351. package/ts_build/src/externalservices/thorswap.d.ts +9 -0
  352. package/ts_build/src/externalservices/thorswap.d.ts.map +1 -0
  353. package/ts_build/src/externalservices/thorswap.js +206 -0
  354. package/ts_build/src/externalservices/thorswap.js.map +1 -0
  355. package/ts_build/src/externalservices/transak.d.ts +13 -0
  356. package/ts_build/src/externalservices/transak.d.ts.map +1 -0
  357. package/ts_build/src/externalservices/transak.js +311 -0
  358. package/ts_build/src/externalservices/transak.js.map +1 -0
  359. package/ts_build/src/externalservices/wyre.d.ts +7 -0
  360. package/ts_build/src/externalservices/wyre.d.ts.map +1 -0
  361. package/ts_build/src/externalservices/wyre.js +144 -0
  362. package/ts_build/src/externalservices/wyre.js.map +1 -0
  363. package/ts_build/src/fiatrateservice/fiatrateservice.d.ts +3 -0
  364. package/ts_build/src/fiatrateservice/fiatrateservice.d.ts.map +1 -0
  365. package/ts_build/src/fiatrateservice/fiatrateservice.js +20 -0
  366. package/ts_build/src/fiatrateservice/fiatrateservice.js.map +1 -0
  367. package/ts_build/src/index.d.ts +8 -0
  368. package/ts_build/src/index.d.ts.map +1 -0
  369. package/ts_build/src/index.js +11 -0
  370. package/ts_build/src/index.js.map +1 -0
  371. package/ts_build/src/lib/bchaddresstranslator.d.ts +5 -0
  372. package/ts_build/src/lib/bchaddresstranslator.d.ts.map +1 -0
  373. package/ts_build/src/lib/bchaddresstranslator.js +66 -0
  374. package/ts_build/src/lib/bchaddresstranslator.js.map +1 -0
  375. package/ts_build/src/lib/blockchainexplorer.d.ts +3 -0
  376. package/ts_build/src/lib/blockchainexplorer.d.ts.map +1 -0
  377. package/ts_build/src/lib/blockchainexplorer.js +87 -0
  378. package/ts_build/src/lib/blockchainexplorer.js.map +1 -0
  379. package/ts_build/src/lib/blockchainexplorers/v8/client.d.ts +31 -0
  380. package/ts_build/src/lib/blockchainexplorers/v8/client.d.ts.map +1 -0
  381. package/ts_build/src/lib/blockchainexplorers/v8/client.js +191 -0
  382. package/ts_build/src/lib/blockchainexplorers/v8/client.js.map +1 -0
  383. package/ts_build/src/lib/blockchainexplorers/v8.d.ts +91 -0
  384. package/ts_build/src/lib/blockchainexplorers/v8.d.ts.map +1 -0
  385. package/ts_build/src/lib/blockchainexplorers/v8.js +662 -0
  386. package/ts_build/src/lib/blockchainexplorers/v8.js.map +1 -0
  387. package/ts_build/src/lib/blockchainmonitor.d.ts +32 -0
  388. package/ts_build/src/lib/blockchainmonitor.d.ts.map +1 -0
  389. package/ts_build/src/lib/blockchainmonitor.js +413 -0
  390. package/ts_build/src/lib/blockchainmonitor.js.map +1 -0
  391. package/ts_build/src/lib/chain/arb/index.d.ts +5 -0
  392. package/ts_build/src/lib/chain/arb/index.d.ts.map +1 -0
  393. package/ts_build/src/lib/chain/arb/index.js +12 -0
  394. package/ts_build/src/lib/chain/arb/index.js.map +1 -0
  395. package/ts_build/src/lib/chain/base/index.d.ts +5 -0
  396. package/ts_build/src/lib/chain/base/index.d.ts.map +1 -0
  397. package/ts_build/src/lib/chain/base/index.js +12 -0
  398. package/ts_build/src/lib/chain/base/index.js.map +1 -0
  399. package/ts_build/src/lib/chain/bch/index.d.ts +9 -0
  400. package/ts_build/src/lib/chain/bch/index.d.ts.map +1 -0
  401. package/ts_build/src/lib/chain/bch/index.js +43 -0
  402. package/ts_build/src/lib/chain/bch/index.js.map +1 -0
  403. package/ts_build/src/lib/chain/btc/index.d.ts +65 -0
  404. package/ts_build/src/lib/chain/btc/index.d.ts.map +1 -0
  405. package/ts_build/src/lib/chain/btc/index.js +829 -0
  406. package/ts_build/src/lib/chain/btc/index.js.map +1 -0
  407. package/ts_build/src/lib/chain/doge/index.d.ts +9 -0
  408. package/ts_build/src/lib/chain/doge/index.d.ts.map +1 -0
  409. package/ts_build/src/lib/chain/doge/index.js +338 -0
  410. package/ts_build/src/lib/chain/doge/index.js.map +1 -0
  411. package/ts_build/src/lib/chain/eth/abi-erc20.d.ts +39 -0
  412. package/ts_build/src/lib/chain/eth/abi-erc20.d.ts.map +1 -0
  413. package/ts_build/src/lib/chain/eth/abi-erc20.js +226 -0
  414. package/ts_build/src/lib/chain/eth/abi-erc20.js.map +1 -0
  415. package/ts_build/src/lib/chain/eth/abi-invoice.d.ts +42 -0
  416. package/ts_build/src/lib/chain/eth/abi-invoice.d.ts.map +1 -0
  417. package/ts_build/src/lib/chain/eth/abi-invoice.js +281 -0
  418. package/ts_build/src/lib/chain/eth/abi-invoice.js.map +1 -0
  419. package/ts_build/src/lib/chain/eth/index.d.ts +66 -0
  420. package/ts_build/src/lib/chain/eth/index.d.ts.map +1 -0
  421. package/ts_build/src/lib/chain/eth/index.js +516 -0
  422. package/ts_build/src/lib/chain/eth/index.js.map +1 -0
  423. package/ts_build/src/lib/chain/index.d.ts +40 -0
  424. package/ts_build/src/lib/chain/index.d.ts.map +1 -0
  425. package/ts_build/src/lib/chain/index.js +143 -0
  426. package/ts_build/src/lib/chain/index.js.map +1 -0
  427. package/ts_build/src/lib/chain/ltc/index.d.ts +6 -0
  428. package/ts_build/src/lib/chain/ltc/index.d.ts.map +1 -0
  429. package/ts_build/src/lib/chain/ltc/index.js +12 -0
  430. package/ts_build/src/lib/chain/ltc/index.js.map +1 -0
  431. package/ts_build/src/lib/chain/matic/index.d.ts +5 -0
  432. package/ts_build/src/lib/chain/matic/index.d.ts.map +1 -0
  433. package/ts_build/src/lib/chain/matic/index.js +12 -0
  434. package/ts_build/src/lib/chain/matic/index.js.map +1 -0
  435. package/ts_build/src/lib/chain/op/index.d.ts +5 -0
  436. package/ts_build/src/lib/chain/op/index.d.ts.map +1 -0
  437. package/ts_build/src/lib/chain/op/index.js +12 -0
  438. package/ts_build/src/lib/chain/op/index.js.map +1 -0
  439. package/ts_build/src/lib/chain/sol/index.d.ts +52 -0
  440. package/ts_build/src/lib/chain/sol/index.d.ts.map +1 -0
  441. package/ts_build/src/lib/chain/sol/index.js +305 -0
  442. package/ts_build/src/lib/chain/sol/index.js.map +1 -0
  443. package/ts_build/src/lib/chain/xrp/index.d.ts +46 -0
  444. package/ts_build/src/lib/chain/xrp/index.d.ts.map +1 -0
  445. package/ts_build/src/lib/chain/xrp/index.js +300 -0
  446. package/ts_build/src/lib/chain/xrp/index.js.map +1 -0
  447. package/ts_build/src/lib/cleanfiatrates.d.ts +13 -0
  448. package/ts_build/src/lib/cleanfiatrates.d.ts.map +1 -0
  449. package/ts_build/src/lib/cleanfiatrates.js +176 -0
  450. package/ts_build/src/lib/cleanfiatrates.js.map +1 -0
  451. package/ts_build/src/lib/common/constants.d.ts +387 -0
  452. package/ts_build/src/lib/common/constants.d.ts.map +1 -0
  453. package/ts_build/src/lib/common/constants.js +234 -0
  454. package/ts_build/src/lib/common/constants.js.map +1 -0
  455. package/ts_build/src/lib/common/defaults.d.ts +326 -0
  456. package/ts_build/src/lib/common/defaults.d.ts.map +1 -0
  457. package/ts_build/src/lib/common/defaults.js +356 -0
  458. package/ts_build/src/lib/common/defaults.js.map +1 -0
  459. package/ts_build/src/lib/common/index.d.ts +793 -0
  460. package/ts_build/src/lib/common/index.d.ts.map +1 -0
  461. package/ts_build/src/lib/common/index.js +14 -0
  462. package/ts_build/src/lib/common/index.js.map +1 -0
  463. package/ts_build/src/lib/common/services.d.ts +34 -0
  464. package/ts_build/src/lib/common/services.d.ts.map +1 -0
  465. package/ts_build/src/lib/common/services.js +44 -0
  466. package/ts_build/src/lib/common/services.js.map +1 -0
  467. package/ts_build/src/lib/common/utils.d.ts +47 -0
  468. package/ts_build/src/lib/common/utils.d.ts.map +1 -0
  469. package/ts_build/src/lib/common/utils.js +385 -0
  470. package/ts_build/src/lib/common/utils.js.map +1 -0
  471. package/ts_build/src/lib/emailservice.d.ts +62 -0
  472. package/ts_build/src/lib/emailservice.d.ts.map +1 -0
  473. package/ts_build/src/lib/emailservice.js +727 -0
  474. package/ts_build/src/lib/emailservice.js.map +1 -0
  475. package/ts_build/src/lib/errors/clienterror.d.ts +11 -0
  476. package/ts_build/src/lib/errors/clienterror.d.ts.map +1 -0
  477. package/ts_build/src/lib/errors/clienterror.js +46 -0
  478. package/ts_build/src/lib/errors/clienterror.js.map +1 -0
  479. package/ts_build/src/lib/errors/errordefinitions.d.ts +76 -0
  480. package/ts_build/src/lib/errors/errordefinitions.d.ts.map +1 -0
  481. package/ts_build/src/lib/errors/errordefinitions.js +82 -0
  482. package/ts_build/src/lib/errors/errordefinitions.js.map +1 -0
  483. package/ts_build/src/lib/expressapp.d.ts +8 -0
  484. package/ts_build/src/lib/expressapp.d.ts.map +1 -0
  485. package/ts_build/src/lib/expressapp.js +2221 -0
  486. package/ts_build/src/lib/expressapp.js.map +1 -0
  487. package/ts_build/src/lib/fiatrateproviders/bitpay.d.ts +3 -0
  488. package/ts_build/src/lib/fiatrateproviders/bitpay.d.ts.map +1 -0
  489. package/ts_build/src/lib/fiatrateproviders/bitpay.js +22 -0
  490. package/ts_build/src/lib/fiatrateproviders/bitpay.js.map +1 -0
  491. package/ts_build/src/lib/fiatrateproviders/bitstamp.d.ts +3 -0
  492. package/ts_build/src/lib/fiatrateproviders/bitstamp.d.ts.map +1 -0
  493. package/ts_build/src/lib/fiatrateproviders/bitstamp.js +18 -0
  494. package/ts_build/src/lib/fiatrateproviders/bitstamp.js.map +1 -0
  495. package/ts_build/src/lib/fiatrateproviders/index.d.ts +3 -0
  496. package/ts_build/src/lib/fiatrateproviders/index.d.ts.map +1 -0
  497. package/ts_build/src/lib/fiatrateproviders/index.js +8 -0
  498. package/ts_build/src/lib/fiatrateproviders/index.js.map +1 -0
  499. package/ts_build/src/lib/fiatrateservice.d.ts +18 -0
  500. package/ts_build/src/lib/fiatrateservice.d.ts.map +1 -0
  501. package/ts_build/src/lib/fiatrateservice.js +313 -0
  502. package/ts_build/src/lib/fiatrateservice.js.map +1 -0
  503. package/ts_build/src/lib/iconsconfig.d.ts +2 -0
  504. package/ts_build/src/lib/iconsconfig.d.ts.map +1 -0
  505. package/ts_build/src/lib/iconsconfig.js +31 -0
  506. package/ts_build/src/lib/iconsconfig.js.map +1 -0
  507. package/ts_build/src/lib/index.d.ts +1 -0
  508. package/ts_build/src/lib/index.d.ts.map +1 -0
  509. package/ts_build/src/lib/index.js +1 -0
  510. package/ts_build/src/lib/index.js.map +1 -0
  511. package/ts_build/src/lib/lock.d.ts +14 -0
  512. package/ts_build/src/lib/lock.d.ts.map +1 -0
  513. package/ts_build/src/lib/lock.js +55 -0
  514. package/ts_build/src/lib/lock.js.map +1 -0
  515. package/ts_build/src/lib/logger.d.ts +7 -0
  516. package/ts_build/src/lib/logger.d.ts.map +1 -0
  517. package/ts_build/src/lib/logger.js +95 -0
  518. package/ts_build/src/lib/logger.js.map +1 -0
  519. package/ts_build/src/lib/messagebroker.d.ts +11 -0
  520. package/ts_build/src/lib/messagebroker.d.ts.map +1 -0
  521. package/ts_build/src/lib/messagebroker.js +77 -0
  522. package/ts_build/src/lib/messagebroker.js.map +1 -0
  523. package/ts_build/src/lib/model/address.d.ts +47 -0
  524. package/ts_build/src/lib/model/address.d.ts.map +1 -0
  525. package/ts_build/src/lib/model/address.js +158 -0
  526. package/ts_build/src/lib/model/address.js.map +1 -0
  527. package/ts_build/src/lib/model/addressmanager.d.ts +41 -0
  528. package/ts_build/src/lib/model/addressmanager.d.ts.map +1 -0
  529. package/ts_build/src/lib/model/addressmanager.js +103 -0
  530. package/ts_build/src/lib/model/addressmanager.js.map +1 -0
  531. package/ts_build/src/lib/model/advertisement.d.ts +38 -0
  532. package/ts_build/src/lib/model/advertisement.d.ts.map +1 -0
  533. package/ts_build/src/lib/model/advertisement.js +68 -0
  534. package/ts_build/src/lib/model/advertisement.js.map +1 -0
  535. package/ts_build/src/lib/model/copayer.d.ts +48 -0
  536. package/ts_build/src/lib/model/copayer.d.ts.map +1 -0
  537. package/ts_build/src/lib/model/copayer.js +116 -0
  538. package/ts_build/src/lib/model/copayer.js.map +1 -0
  539. package/ts_build/src/lib/model/email.d.ts +23 -0
  540. package/ts_build/src/lib/model/email.d.ts.map +1 -0
  541. package/ts_build/src/lib/model/email.js +84 -0
  542. package/ts_build/src/lib/model/email.js.map +1 -0
  543. package/ts_build/src/lib/model/index.d.ts +13 -0
  544. package/ts_build/src/lib/model/index.d.ts.map +1 -0
  545. package/ts_build/src/lib/model/index.js +28 -0
  546. package/ts_build/src/lib/model/index.js.map +1 -0
  547. package/ts_build/src/lib/model/notification.d.ts +23 -0
  548. package/ts_build/src/lib/model/notification.d.ts.map +1 -0
  549. package/ts_build/src/lib/model/notification.js +40 -0
  550. package/ts_build/src/lib/model/notification.js.map +1 -0
  551. package/ts_build/src/lib/model/preferences.d.ts +37 -0
  552. package/ts_build/src/lib/model/preferences.d.ts.map +1 -0
  553. package/ts_build/src/lib/model/preferences.js +61 -0
  554. package/ts_build/src/lib/model/preferences.js.map +1 -0
  555. package/ts_build/src/lib/model/pushnotificationsub.d.ts +23 -0
  556. package/ts_build/src/lib/model/pushnotificationsub.d.ts.map +1 -0
  557. package/ts_build/src/lib/model/pushnotificationsub.js +40 -0
  558. package/ts_build/src/lib/model/pushnotificationsub.js.map +1 -0
  559. package/ts_build/src/lib/model/session.d.ts +22 -0
  560. package/ts_build/src/lib/model/session.d.ts.map +1 -0
  561. package/ts_build/src/lib/model/session.js +52 -0
  562. package/ts_build/src/lib/model/session.js.map +1 -0
  563. package/ts_build/src/lib/model/tsskeygen.d.ts +67 -0
  564. package/ts_build/src/lib/model/tsskeygen.d.ts.map +1 -0
  565. package/ts_build/src/lib/model/tsskeygen.js +69 -0
  566. package/ts_build/src/lib/model/tsskeygen.js.map +1 -0
  567. package/ts_build/src/lib/model/tsssign.d.ts +70 -0
  568. package/ts_build/src/lib/model/tsssign.d.ts.map +1 -0
  569. package/ts_build/src/lib/model/tsssign.js +54 -0
  570. package/ts_build/src/lib/model/tsssign.js.map +1 -0
  571. package/ts_build/src/lib/model/txconfirmationsub.d.ts +23 -0
  572. package/ts_build/src/lib/model/txconfirmationsub.d.ts.map +1 -0
  573. package/ts_build/src/lib/model/txconfirmationsub.js +40 -0
  574. package/ts_build/src/lib/model/txconfirmationsub.js.map +1 -0
  575. package/ts_build/src/lib/model/txnote.d.ts +23 -0
  576. package/ts_build/src/lib/model/txnote.d.ts.map +1 -0
  577. package/ts_build/src/lib/model/txnote.js +46 -0
  578. package/ts_build/src/lib/model/txnote.js.map +1 -0
  579. package/ts_build/src/lib/model/txproposal.d.ts +196 -0
  580. package/ts_build/src/lib/model/txproposal.d.ts.map +1 -0
  581. package/ts_build/src/lib/model/txproposal.js +382 -0
  582. package/ts_build/src/lib/model/txproposal.js.map +1 -0
  583. package/ts_build/src/lib/model/txproposal_legacy.d.ts +93 -0
  584. package/ts_build/src/lib/model/txproposal_legacy.d.ts.map +1 -0
  585. package/ts_build/src/lib/model/txproposal_legacy.js +185 -0
  586. package/ts_build/src/lib/model/txproposal_legacy.js.map +1 -0
  587. package/ts_build/src/lib/model/txproposalaction.d.ts +21 -0
  588. package/ts_build/src/lib/model/txproposalaction.d.ts.map +1 -0
  589. package/ts_build/src/lib/model/txproposalaction.js +37 -0
  590. package/ts_build/src/lib/model/txproposalaction.js.map +1 -0
  591. package/ts_build/src/lib/model/wallet.d.ts +110 -0
  592. package/ts_build/src/lib/model/wallet.d.ts.map +1 -0
  593. package/ts_build/src/lib/model/wallet.js +224 -0
  594. package/ts_build/src/lib/model/wallet.js.map +1 -0
  595. package/ts_build/src/lib/notificationbroadcaster.d.ts +6 -0
  596. package/ts_build/src/lib/notificationbroadcaster.d.ts.map +1 -0
  597. package/ts_build/src/lib/notificationbroadcaster.js +19 -0
  598. package/ts_build/src/lib/notificationbroadcaster.js.map +1 -0
  599. package/ts_build/src/lib/pushnotificationsservice.d.ts +56 -0
  600. package/ts_build/src/lib/pushnotificationsservice.d.ts.map +1 -0
  601. package/ts_build/src/lib/pushnotificationsservice.js +721 -0
  602. package/ts_build/src/lib/pushnotificationsservice.js.map +1 -0
  603. package/ts_build/src/lib/routes/helpers/error.d.ts +10 -0
  604. package/ts_build/src/lib/routes/helpers/error.d.ts.map +1 -0
  605. package/ts_build/src/lib/routes/helpers/error.js +54 -0
  606. package/ts_build/src/lib/routes/helpers/error.js.map +1 -0
  607. package/ts_build/src/lib/routes/helpers/index.d.ts +2 -0
  608. package/ts_build/src/lib/routes/helpers/index.d.ts.map +1 -0
  609. package/ts_build/src/lib/routes/helpers/index.js +18 -0
  610. package/ts_build/src/lib/routes/helpers/index.js.map +1 -0
  611. package/ts_build/src/lib/routes/middleware/authRequest.d.ts +6 -0
  612. package/ts_build/src/lib/routes/middleware/authRequest.d.ts.map +1 -0
  613. package/ts_build/src/lib/routes/middleware/authRequest.js +106 -0
  614. package/ts_build/src/lib/routes/middleware/authRequest.js.map +1 -0
  615. package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts +3 -0
  616. package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts.map +1 -0
  617. package/ts_build/src/lib/routes/middleware/authTssRequest.js +56 -0
  618. package/ts_build/src/lib/routes/middleware/authTssRequest.js.map +1 -0
  619. package/ts_build/src/lib/routes/middleware/createWalletLimiter.d.ts +4 -0
  620. package/ts_build/src/lib/routes/middleware/createWalletLimiter.d.ts.map +1 -0
  621. package/ts_build/src/lib/routes/middleware/createWalletLimiter.js +28 -0
  622. package/ts_build/src/lib/routes/middleware/createWalletLimiter.js.map +1 -0
  623. package/ts_build/src/lib/routes/middleware/log.d.ts +9 -0
  624. package/ts_build/src/lib/routes/middleware/log.d.ts.map +1 -0
  625. package/ts_build/src/lib/routes/middleware/log.js +52 -0
  626. package/ts_build/src/lib/routes/middleware/log.js.map +1 -0
  627. package/ts_build/src/lib/routes/middleware/verifyTssMessage.d.ts +2 -0
  628. package/ts_build/src/lib/routes/middleware/verifyTssMessage.d.ts.map +1 -0
  629. package/ts_build/src/lib/routes/middleware/verifyTssMessage.js +34 -0
  630. package/ts_build/src/lib/routes/middleware/verifyTssMessage.js.map +1 -0
  631. package/ts_build/src/lib/routes/tss.d.ts +14 -0
  632. package/ts_build/src/lib/routes/tss.d.ts.map +1 -0
  633. package/ts_build/src/lib/routes/tss.js +120 -0
  634. package/ts_build/src/lib/routes/tss.js.map +1 -0
  635. package/ts_build/src/lib/server.d.ts +250 -0
  636. package/ts_build/src/lib/server.d.ts.map +1 -0
  637. package/ts_build/src/lib/server.js +4115 -0
  638. package/ts_build/src/lib/server.js.map +1 -0
  639. package/ts_build/src/lib/stats.d.ts +17 -0
  640. package/ts_build/src/lib/stats.d.ts.map +1 -0
  641. package/ts_build/src/lib/stats.js +203 -0
  642. package/ts_build/src/lib/stats.js.map +1 -0
  643. package/ts_build/src/lib/storage.d.ts +163 -0
  644. package/ts_build/src/lib/storage.d.ts.map +1 -0
  645. package/ts_build/src/lib/storage.js +1513 -0
  646. package/ts_build/src/lib/storage.js.map +1 -0
  647. package/ts_build/src/lib/tss.d.ts +70 -0
  648. package/ts_build/src/lib/tss.d.ts.map +1 -0
  649. package/ts_build/src/lib/tss.js +379 -0
  650. package/ts_build/src/lib/tss.js.map +1 -0
  651. package/ts_build/src/lib/updatestats.d.ts +16 -0
  652. package/ts_build/src/lib/updatestats.d.ts.map +1 -0
  653. package/ts_build/src/lib/updatestats.js +308 -0
  654. package/ts_build/src/lib/updatestats.js.map +1 -0
  655. package/ts_build/src/messagebroker/messagebroker.d.ts +3 -0
  656. package/ts_build/src/messagebroker/messagebroker.d.ts.map +1 -0
  657. package/ts_build/src/messagebroker/messagebroker.js +20 -0
  658. package/ts_build/src/messagebroker/messagebroker.js.map +1 -0
  659. package/ts_build/src/pushnotificationsservice/pushnotificationsservice.d.ts +3 -0
  660. package/ts_build/src/pushnotificationsservice/pushnotificationsservice.d.ts.map +1 -0
  661. package/ts_build/src/pushnotificationsservice/pushnotificationsservice.js +16 -0
  662. package/ts_build/src/pushnotificationsservice/pushnotificationsservice.js.map +1 -0
  663. package/ts_build/src/serverMessages.d.ts +2 -0
  664. package/ts_build/src/serverMessages.d.ts.map +1 -0
  665. package/ts_build/src/serverMessages.js +35 -0
  666. package/ts_build/src/serverMessages.js.map +1 -0
  667. package/ts_build/src/updatestats/updatestats.d.ts +3 -0
  668. package/ts_build/src/updatestats/updatestats.d.ts.map +1 -0
  669. package/ts_build/src/updatestats/updatestats.js +15 -0
  670. package/ts_build/src/updatestats/updatestats.js.map +1 -0
  671. package/ts_build/templates/en/new_copayer.html +13 -0
  672. package/ts_build/templates/en/new_copayer.plain +2 -0
  673. package/ts_build/templates/en/new_incoming_tx.html +11 -0
  674. package/ts_build/templates/en/new_incoming_tx.plain +2 -0
  675. package/ts_build/templates/en/new_incoming_tx_testnet.html +13 -0
  676. package/ts_build/templates/en/new_incoming_tx_testnet.plain +2 -0
  677. package/ts_build/templates/en/new_outgoing_tx.html +11 -0
  678. package/ts_build/templates/en/new_outgoing_tx.plain +2 -0
  679. package/ts_build/templates/en/new_tx_proposal.html +13 -0
  680. package/ts_build/templates/en/new_tx_proposal.plain +2 -0
  681. package/ts_build/templates/en/new_zero_outgoing_tx.html +13 -0
  682. package/ts_build/templates/en/new_zero_outgoing_tx.plain +2 -0
  683. package/ts_build/templates/en/tx_confirmation.html +13 -0
  684. package/ts_build/templates/en/tx_confirmation.plain +2 -0
  685. package/ts_build/templates/en/tx_confirmation_receiver.html +13 -0
  686. package/ts_build/templates/en/tx_confirmation_receiver.plain +2 -0
  687. package/ts_build/templates/en/tx_confirmation_sender.html +13 -0
  688. package/ts_build/templates/en/tx_confirmation_sender.plain +2 -0
  689. package/ts_build/templates/en/txp_finally_rejected.html +13 -0
  690. package/ts_build/templates/en/txp_finally_rejected.plain +2 -0
  691. package/ts_build/templates/en/wallet_complete.html +13 -0
  692. package/ts_build/templates/en/wallet_complete.plain +2 -0
  693. package/ts_build/templates/es/new_copayer.html +13 -0
  694. package/ts_build/templates/es/new_copayer.plain +2 -0
  695. package/ts_build/templates/es/new_incoming_tx.html +11 -0
  696. package/ts_build/templates/es/new_incoming_tx.plain +2 -0
  697. package/ts_build/templates/es/new_incoming_tx_testnet.html +13 -0
  698. package/ts_build/templates/es/new_incoming_tx_testnet.plain +2 -0
  699. package/ts_build/templates/es/new_outgoing_tx.html +11 -0
  700. package/ts_build/templates/es/new_outgoing_tx.plain +2 -0
  701. package/ts_build/templates/es/new_tx_proposal.html +13 -0
  702. package/ts_build/templates/es/new_tx_proposal.plain +2 -0
  703. package/ts_build/templates/es/new_zero_outgoing_tx.html +13 -0
  704. package/ts_build/templates/es/new_zero_outgoing_tx.plain +2 -0
  705. package/ts_build/templates/es/tx_confirmation.html +13 -0
  706. package/ts_build/templates/es/tx_confirmation.plain +2 -0
  707. package/ts_build/templates/es/tx_confirmation_receiver.html +13 -0
  708. package/ts_build/templates/es/tx_confirmation_receiver.plain +2 -0
  709. package/ts_build/templates/es/tx_confirmation_sender.html +13 -0
  710. package/ts_build/templates/es/tx_confirmation_sender.plain +2 -0
  711. package/ts_build/templates/es/txp_finally_rejected.html +13 -0
  712. package/ts_build/templates/es/txp_finally_rejected.plain +2 -0
  713. package/ts_build/templates/es/wallet_complete.html +13 -0
  714. package/ts_build/templates/es/wallet_complete.plain +2 -0
  715. package/ts_build/templates/fr/new_copayer.html +13 -0
  716. package/ts_build/templates/fr/new_copayer.plain +2 -0
  717. package/ts_build/templates/fr/new_incoming_tx.html +11 -0
  718. package/ts_build/templates/fr/new_incoming_tx.plain +2 -0
  719. package/ts_build/templates/fr/new_incoming_tx_testnet.html +13 -0
  720. package/ts_build/templates/fr/new_incoming_tx_testnet.plain +2 -0
  721. package/ts_build/templates/fr/new_outgoing_tx.html +11 -0
  722. package/ts_build/templates/fr/new_outgoing_tx.plain +2 -0
  723. package/ts_build/templates/fr/new_tx_proposal.html +13 -0
  724. package/ts_build/templates/fr/new_tx_proposal.plain +2 -0
  725. package/ts_build/templates/fr/new_zero_outgoing_tx.html +13 -0
  726. package/ts_build/templates/fr/new_zero_outgoing_tx.plain +2 -0
  727. package/ts_build/templates/fr/tx_confirmation.html +13 -0
  728. package/ts_build/templates/fr/tx_confirmation.plain +2 -0
  729. package/ts_build/templates/fr/tx_confirmation_receiver.html +13 -0
  730. package/ts_build/templates/fr/tx_confirmation_receiver.plain +2 -0
  731. package/ts_build/templates/fr/tx_confirmation_sender.html +13 -0
  732. package/ts_build/templates/fr/tx_confirmation_sender.plain +2 -0
  733. package/ts_build/templates/fr/txp_finally_rejected.html +13 -0
  734. package/ts_build/templates/fr/txp_finally_rejected.plain +2 -0
  735. package/ts_build/templates/fr/wallet_complete.html +13 -0
  736. package/ts_build/templates/fr/wallet_complete.plain +2 -0
  737. package/ts_build/templates/ja/new_copayer.html +13 -0
  738. package/ts_build/templates/ja/new_copayer.plain +2 -0
  739. package/ts_build/templates/ja/new_incoming_tx.html +11 -0
  740. package/ts_build/templates/ja/new_incoming_tx.plain +2 -0
  741. package/ts_build/templates/ja/new_incoming_tx_testnet.html +13 -0
  742. package/ts_build/templates/ja/new_incoming_tx_testnet.plain +2 -0
  743. package/ts_build/templates/ja/new_outgoing_tx.html +11 -0
  744. package/ts_build/templates/ja/new_outgoing_tx.plain +2 -0
  745. package/ts_build/templates/ja/new_tx_proposal.html +13 -0
  746. package/ts_build/templates/ja/new_tx_proposal.plain +2 -0
  747. package/ts_build/templates/ja/new_zero_outgoing_tx.html +13 -0
  748. package/ts_build/templates/ja/new_zero_outgoing_tx.plain +2 -0
  749. package/ts_build/templates/ja/tx_confirmation.html +13 -0
  750. package/ts_build/templates/ja/tx_confirmation.plain +2 -0
  751. package/ts_build/templates/ja/tx_confirmation_receiver.html +13 -0
  752. package/ts_build/templates/ja/tx_confirmation_receiver.plain +2 -0
  753. package/ts_build/templates/ja/tx_confirmation_sender.html +13 -0
  754. package/ts_build/templates/ja/tx_confirmation_sender.plain +2 -0
  755. package/ts_build/templates/ja/txp_finally_rejected.html +13 -0
  756. package/ts_build/templates/ja/txp_finally_rejected.plain +2 -0
  757. package/ts_build/templates/ja/wallet_complete.html +13 -0
  758. package/ts_build/templates/ja/wallet_complete.plain +2 -0
  759. package/ts_build/templates/master-template.html +494 -0
  760. package/ts_build/test/bchaddresstranslator.test.d.ts +2 -0
  761. package/ts_build/test/bchaddresstranslator.test.d.ts.map +1 -0
  762. package/ts_build/test/bchaddresstranslator.test.js +76 -0
  763. package/ts_build/test/bchaddresstranslator.test.js.map +1 -0
  764. package/ts_build/test/blockchainexplorer.test.d.ts +2 -0
  765. package/ts_build/test/blockchainexplorer.test.d.ts.map +1 -0
  766. package/ts_build/test/blockchainexplorer.test.js +98 -0
  767. package/ts_build/test/blockchainexplorer.test.js.map +1 -0
  768. package/ts_build/test/chain/bch.test.d.ts +2 -0
  769. package/ts_build/test/chain/bch.test.d.ts.map +1 -0
  770. package/ts_build/test/chain/bch.test.js +135 -0
  771. package/ts_build/test/chain/bch.test.js.map +1 -0
  772. package/ts_build/test/chain/btc.test.d.ts +2 -0
  773. package/ts_build/test/chain/btc.test.d.ts.map +1 -0
  774. package/ts_build/test/chain/btc.test.js +310 -0
  775. package/ts_build/test/chain/btc.test.js.map +1 -0
  776. package/ts_build/test/chain/doge.test.d.ts +2 -0
  777. package/ts_build/test/chain/doge.test.d.ts.map +1 -0
  778. package/ts_build/test/chain/doge.test.js +343 -0
  779. package/ts_build/test/chain/doge.test.js.map +1 -0
  780. package/ts_build/test/chain/eth.test.d.ts +2 -0
  781. package/ts_build/test/chain/eth.test.d.ts.map +1 -0
  782. package/ts_build/test/chain/eth.test.js +51 -0
  783. package/ts_build/test/chain/eth.test.js.map +1 -0
  784. package/ts_build/test/chain/ltc.test.d.ts +2 -0
  785. package/ts_build/test/chain/ltc.test.d.ts.map +1 -0
  786. package/ts_build/test/chain/ltc.test.js +323 -0
  787. package/ts_build/test/chain/ltc.test.js.map +1 -0
  788. package/ts_build/test/chain/matic.test.d.ts +2 -0
  789. package/ts_build/test/chain/matic.test.d.ts.map +1 -0
  790. package/ts_build/test/chain/matic.test.js +51 -0
  791. package/ts_build/test/chain/matic.test.js.map +1 -0
  792. package/ts_build/test/chain/xrp.test.d.ts +2 -0
  793. package/ts_build/test/chain/xrp.test.d.ts.map +1 -0
  794. package/ts_build/test/chain/xrp.test.js +228 -0
  795. package/ts_build/test/chain/xrp.test.js.map +1 -0
  796. package/ts_build/test/expressapp.test.d.ts +2 -0
  797. package/ts_build/test/expressapp.test.d.ts.map +1 -0
  798. package/ts_build/test/expressapp.test.js +523 -0
  799. package/ts_build/test/expressapp.test.js.map +1 -0
  800. package/ts_build/test/integration/bcmonitor.test.d.ts +2 -0
  801. package/ts_build/test/integration/bcmonitor.test.d.ts.map +1 -0
  802. package/ts_build/test/integration/bcmonitor.test.js +375 -0
  803. package/ts_build/test/integration/bcmonitor.test.js.map +1 -0
  804. package/ts_build/test/integration/cashAddrMigration.test.d.ts +2 -0
  805. package/ts_build/test/integration/cashAddrMigration.test.d.ts.map +1 -0
  806. package/ts_build/test/integration/cashAddrMigration.test.js +147 -0
  807. package/ts_build/test/integration/cashAddrMigration.test.js.map +1 -0
  808. package/ts_build/test/integration/data/tss/2of3/index.d.ts +4 -0
  809. package/ts_build/test/integration/data/tss/2of3/index.d.ts.map +1 -0
  810. package/ts_build/test/integration/data/tss/2of3/index.js +20 -0
  811. package/ts_build/test/integration/data/tss/2of3/index.js.map +1 -0
  812. package/ts_build/test/integration/data/tss/2of3/party0.key.d.ts +6 -0
  813. package/ts_build/test/integration/data/tss/2of3/party0.key.d.ts.map +1 -0
  814. package/ts_build/test/integration/data/tss/2of3/party0.key.js +9 -0
  815. package/ts_build/test/integration/data/tss/2of3/party0.key.js.map +1 -0
  816. package/ts_build/test/integration/data/tss/2of3/party1.key.d.ts +6 -0
  817. package/ts_build/test/integration/data/tss/2of3/party1.key.d.ts.map +1 -0
  818. package/ts_build/test/integration/data/tss/2of3/party1.key.js +9 -0
  819. package/ts_build/test/integration/data/tss/2of3/party1.key.js.map +1 -0
  820. package/ts_build/test/integration/data/tss/2of3/party2.key.d.ts +6 -0
  821. package/ts_build/test/integration/data/tss/2of3/party2.key.d.ts.map +1 -0
  822. package/ts_build/test/integration/data/tss/2of3/party2.key.js +9 -0
  823. package/ts_build/test/integration/data/tss/2of3/party2.key.js.map +1 -0
  824. package/ts_build/test/integration/emailnotifications.test.d.ts +2 -0
  825. package/ts_build/test/integration/emailnotifications.test.d.ts.map +1 -0
  826. package/ts_build/test/integration/emailnotifications.test.js +805 -0
  827. package/ts_build/test/integration/emailnotifications.test.js.map +1 -0
  828. package/ts_build/test/integration/externalservices/banxa.test.d.ts +2 -0
  829. package/ts_build/test/integration/externalservices/banxa.test.d.ts.map +1 -0
  830. package/ts_build/test/integration/externalservices/banxa.test.js +382 -0
  831. package/ts_build/test/integration/externalservices/banxa.test.js.map +1 -0
  832. package/ts_build/test/integration/externalservices/changelly.test.d.ts +2 -0
  833. package/ts_build/test/integration/externalservices/changelly.test.d.ts.map +1 -0
  834. package/ts_build/test/integration/externalservices/changelly.test.js +509 -0
  835. package/ts_build/test/integration/externalservices/changelly.test.js.map +1 -0
  836. package/ts_build/test/integration/externalservices/coinGecko.test.d.ts +2 -0
  837. package/ts_build/test/integration/externalservices/coinGecko.test.d.ts.map +1 -0
  838. package/ts_build/test/integration/externalservices/coinGecko.test.js +295 -0
  839. package/ts_build/test/integration/externalservices/coinGecko.test.js.map +1 -0
  840. package/ts_build/test/integration/externalservices/moonpay.test.d.ts +2 -0
  841. package/ts_build/test/integration/externalservices/moonpay.test.d.ts.map +1 -0
  842. package/ts_build/test/integration/externalservices/moonpay.test.js +567 -0
  843. package/ts_build/test/integration/externalservices/moonpay.test.js.map +1 -0
  844. package/ts_build/test/integration/externalservices/oneInch.test.d.ts +2 -0
  845. package/ts_build/test/integration/externalservices/oneInch.test.d.ts.map +1 -0
  846. package/ts_build/test/integration/externalservices/oneInch.test.js +182 -0
  847. package/ts_build/test/integration/externalservices/oneInch.test.js.map +1 -0
  848. package/ts_build/test/integration/externalservices/ramp.test.d.ts +2 -0
  849. package/ts_build/test/integration/externalservices/ramp.test.d.ts.map +1 -0
  850. package/ts_build/test/integration/externalservices/ramp.test.js +459 -0
  851. package/ts_build/test/integration/externalservices/ramp.test.js.map +1 -0
  852. package/ts_build/test/integration/externalservices/sardine.test.d.ts +2 -0
  853. package/ts_build/test/integration/externalservices/sardine.test.d.ts.map +1 -0
  854. package/ts_build/test/integration/externalservices/sardine.test.js +364 -0
  855. package/ts_build/test/integration/externalservices/sardine.test.js.map +1 -0
  856. package/ts_build/test/integration/externalservices/simplex.test.d.ts +2 -0
  857. package/ts_build/test/integration/externalservices/simplex.test.d.ts.map +1 -0
  858. package/ts_build/test/integration/externalservices/simplex.test.js +383 -0
  859. package/ts_build/test/integration/externalservices/simplex.test.js.map +1 -0
  860. package/ts_build/test/integration/externalservices/thorswap.test.d.ts +2 -0
  861. package/ts_build/test/integration/externalservices/thorswap.test.d.ts.map +1 -0
  862. package/ts_build/test/integration/externalservices/thorswap.test.js +316 -0
  863. package/ts_build/test/integration/externalservices/thorswap.test.js.map +1 -0
  864. package/ts_build/test/integration/externalservices/transak.test.d.ts +2 -0
  865. package/ts_build/test/integration/externalservices/transak.test.d.ts.map +1 -0
  866. package/ts_build/test/integration/externalservices/transak.test.js +409 -0
  867. package/ts_build/test/integration/externalservices/transak.test.js.map +1 -0
  868. package/ts_build/test/integration/externalservices/wyre.test.d.ts +2 -0
  869. package/ts_build/test/integration/externalservices/wyre.test.d.ts.map +1 -0
  870. package/ts_build/test/integration/externalservices/wyre.test.js +281 -0
  871. package/ts_build/test/integration/externalservices/wyre.test.js.map +1 -0
  872. package/ts_build/test/integration/fiatrateservice.test.d.ts +2 -0
  873. package/ts_build/test/integration/fiatrateservice.test.d.ts.map +1 -0
  874. package/ts_build/test/integration/fiatrateservice.test.js +838 -0
  875. package/ts_build/test/integration/fiatrateservice.test.js.map +1 -0
  876. package/ts_build/test/integration/helpers.d.ts +57 -0
  877. package/ts_build/test/integration/helpers.d.ts.map +1 -0
  878. package/ts_build/test/integration/helpers.js +633 -0
  879. package/ts_build/test/integration/helpers.js.map +1 -0
  880. package/ts_build/test/integration/history.test.d.ts +2 -0
  881. package/ts_build/test/integration/history.test.d.ts.map +1 -0
  882. package/ts_build/test/integration/history.test.js +1064 -0
  883. package/ts_build/test/integration/history.test.js.map +1 -0
  884. package/ts_build/test/integration/hugetx.d.ts +46 -0
  885. package/ts_build/test/integration/hugetx.d.ts.map +1 -0
  886. package/ts_build/test/integration/hugetx.js +6459 -0
  887. package/ts_build/test/integration/hugetx.js.map +1 -0
  888. package/ts_build/test/integration/pushNotifications.test.d.ts +2 -0
  889. package/ts_build/test/integration/pushNotifications.test.d.ts.map +1 -0
  890. package/ts_build/test/integration/pushNotifications.test.js +1379 -0
  891. package/ts_build/test/integration/pushNotifications.test.js.map +1 -0
  892. package/ts_build/test/integration/server.test.d.ts +2 -0
  893. package/ts_build/test/integration/server.test.d.ts.map +1 -0
  894. package/ts_build/test/integration/server.test.js +9980 -0
  895. package/ts_build/test/integration/server.test.js.map +1 -0
  896. package/ts_build/test/integration/tss.test.d.ts +2 -0
  897. package/ts_build/test/integration/tss.test.d.ts.map +1 -0
  898. package/ts_build/test/integration/tss.test.js +360 -0
  899. package/ts_build/test/integration/tss.test.js.map +1 -0
  900. package/ts_build/test/lock.test.d.ts +2 -0
  901. package/ts_build/test/lock.test.d.ts.map +1 -0
  902. package/ts_build/test/lock.test.js +226 -0
  903. package/ts_build/test/lock.test.js.map +1 -0
  904. package/ts_build/test/model/address.test.d.ts +2 -0
  905. package/ts_build/test/model/address.test.d.ts.map +1 -0
  906. package/ts_build/test/model/address.test.js +209 -0
  907. package/ts_build/test/model/address.test.js.map +1 -0
  908. package/ts_build/test/model/addressmanager.test.d.ts +2 -0
  909. package/ts_build/test/model/addressmanager.test.d.ts.map +1 -0
  910. package/ts_build/test/model/addressmanager.test.js +178 -0
  911. package/ts_build/test/model/addressmanager.test.js.map +1 -0
  912. package/ts_build/test/model/advertisement.test.d.ts +2 -0
  913. package/ts_build/test/model/advertisement.test.d.ts.map +1 -0
  914. package/ts_build/test/model/advertisement.test.js +61 -0
  915. package/ts_build/test/model/advertisement.test.js.map +1 -0
  916. package/ts_build/test/model/copayer.test.d.ts +2 -0
  917. package/ts_build/test/model/copayer.test.d.ts.map +1 -0
  918. package/ts_build/test/model/copayer.test.js +161 -0
  919. package/ts_build/test/model/copayer.test.js.map +1 -0
  920. package/ts_build/test/model/txproposal.test.d.ts +2 -0
  921. package/ts_build/test/model/txproposal.test.d.ts.map +1 -0
  922. package/ts_build/test/model/txproposal.test.js +198 -0
  923. package/ts_build/test/model/txproposal.test.js.map +1 -0
  924. package/ts_build/test/model/wallet.test.d.ts +2 -0
  925. package/ts_build/test/model/wallet.test.d.ts.map +1 -0
  926. package/ts_build/test/model/wallet.test.js +215 -0
  927. package/ts_build/test/model/wallet.test.js.map +1 -0
  928. package/ts_build/test/storage.test.d.ts +2 -0
  929. package/ts_build/test/storage.test.d.ts.map +1 -0
  930. package/ts_build/test/storage.test.js +433 -0
  931. package/ts_build/test/storage.test.js.map +1 -0
  932. package/ts_build/test/test-config.d.ts +8 -0
  933. package/ts_build/test/test-config.d.ts.map +1 -0
  934. package/ts_build/test/test-config.js +14 -0
  935. package/ts_build/test/test-config.js.map +1 -0
  936. package/ts_build/test/testdata.d.ts +91 -0
  937. package/ts_build/test/testdata.d.ts.map +1 -0
  938. package/ts_build/test/testdata.js +304 -0
  939. package/ts_build/test/testdata.js.map +1 -0
  940. package/ts_build/test/utils.test.d.ts +2 -0
  941. package/ts_build/test/utils.test.d.ts.map +1 -0
  942. package/ts_build/test/utils.test.js +450 -0
  943. package/ts_build/test/utils.test.js.map +1 -0
  944. package/ts_build/test/v8.test.d.ts +2 -0
  945. package/ts_build/test/v8.test.d.ts.map +1 -0
  946. package/ts_build/test/v8.test.js +341 -0
  947. package/ts_build/test/v8.test.js.map +1 -0
  948. package/tsconfig.json +43 -0
  949. package/tsconfig.prod.json +6 -0
@@ -0,0 +1,1919 @@
1
+ import * as async from 'async';
2
+ import _ from 'lodash';
3
+ import { Db } from 'mongodb';
4
+ import * as mongodb from 'mongodb';
5
+ import preconditions from 'preconditions';
6
+ import { BCHAddressTranslator } from './bchaddresstranslator'; // only for migration
7
+ import { Common } from './common';
8
+ import logger from './logger';
9
+ import {
10
+ Address,
11
+ Advertisement,
12
+ Copayer,
13
+ Email,
14
+ Notification,
15
+ Preferences,
16
+ PushNotificationSub,
17
+ Session,
18
+ TxNote,
19
+ TxProposal,
20
+ Wallet
21
+ } from './model';
22
+ import { ITssKeyMessageObject, TssKeyGenModel } from './model/tsskeygen';
23
+ import { ITssSigMessageObject, TssSigGenModel } from './model/tsssign';
24
+
25
+ const $ = preconditions.singleton();
26
+
27
+ const collections = {
28
+ // Duplciated in helpers.. TODO
29
+ WALLETS: 'wallets',
30
+ TXS: 'txs',
31
+ ADDRESSES: 'addresses',
32
+ ADVERTISEMENTS: 'advertisements',
33
+ NOTIFICATIONS: 'notifications',
34
+ COPAYERS_LOOKUP: 'copayers_lookup',
35
+ PREFERENCES: 'preferences',
36
+ EMAIL_QUEUE: 'email_queue',
37
+ CACHE: 'cache',
38
+ FIAT_RATES2: 'fiat_rates2',
39
+ TX_NOTES: 'tx_notes',
40
+ SESSIONS: 'sessions',
41
+ PUSH_NOTIFICATION_SUBS: 'push_notification_subs',
42
+ TX_CONFIRMATION_SUBS: 'tx_confirmation_subs',
43
+ LOCKS: 'locks',
44
+ TSS_KEYGEN: 'tss_keygen',
45
+ TSS_SIGN: 'tss_sign'
46
+ };
47
+
48
+ const Defaults = Common.Defaults;
49
+ const Utils = Common.Utils;
50
+
51
+ const ObjectID = mongodb.ObjectID;
52
+
53
+ const objectIdDate = function(date) {
54
+ return Math.floor(date / 1000).toString(16) + '0000000000000000';
55
+ };
56
+ export class Storage {
57
+ static BCHEIGHT_KEY = 'bcheight';
58
+ static collections = collections;
59
+ db: Db;
60
+ client: any;
61
+
62
+ constructor(opts: { db?: Db } = {}) {
63
+ opts = opts || {};
64
+ this.db = opts.db;
65
+ }
66
+
67
+ static createIndexes(db) {
68
+ logger.info('Creating DB indexes');
69
+ if (!db.collection) {
70
+ logger.error('DB not ready: [storage.ts] no db.collection');
71
+ return;
72
+ }
73
+ db.collection(collections.WALLETS).createIndex({
74
+ id: 1
75
+ });
76
+ db.collection(collections.COPAYERS_LOOKUP).createIndex({
77
+ copayerId: 1
78
+ });
79
+ db.collection(collections.COPAYERS_LOOKUP).createIndex({
80
+ walletId: 1
81
+ });
82
+ db.collection(collections.TXS).createIndex({
83
+ walletId: 1,
84
+ id: 1
85
+ });
86
+ db.collection(collections.TXS).createIndex({
87
+ walletId: 1,
88
+ isPending: 1,
89
+ txid: 1
90
+ });
91
+ db.collection(collections.TXS).createIndex({
92
+ walletId: 1,
93
+ createdOn: -1
94
+ });
95
+ db.collection(collections.TXS).createIndex({
96
+ txid: 1
97
+ });
98
+ db.collection(collections.NOTIFICATIONS).createIndex({
99
+ walletId: 1,
100
+ id: 1
101
+ });
102
+ db.collection(collections.ADVERTISEMENTS).createIndex(
103
+ {
104
+ advertisementId: 1,
105
+ title: 1
106
+ },
107
+ { unique: true }
108
+ );
109
+ db.collection(collections.ADDRESSES).createIndex({
110
+ walletId: 1,
111
+ createdOn: 1
112
+ });
113
+ db.collection(collections.ADDRESSES).createIndex(
114
+ {
115
+ address: 1,
116
+ coin: 1
117
+ },
118
+ { unique: true }
119
+ );
120
+ db.collection(collections.ADDRESSES).createIndex({
121
+ address: 1,
122
+ beRegistered: 1
123
+ });
124
+ db.collection(collections.ADDRESSES).createIndex({
125
+ walletId: 1,
126
+ address: 1
127
+ });
128
+ db.collection(collections.EMAIL_QUEUE).createIndex({
129
+ id: 1
130
+ });
131
+ db.collection(collections.EMAIL_QUEUE).createIndex({
132
+ notificationId: 1
133
+ });
134
+ db.collection(collections.CACHE).createIndex({
135
+ walletId: 1,
136
+ type: 1,
137
+ key: 1
138
+ });
139
+ db.collection(collections.TX_NOTES).createIndex({
140
+ walletId: 1,
141
+ txid: 1
142
+ });
143
+ db.collection(collections.PREFERENCES).createIndex({
144
+ walletId: 1
145
+ });
146
+ db.collection(collections.FIAT_RATES2).createIndex({
147
+ coin: 1,
148
+ code: 1,
149
+ ts: 1
150
+ });
151
+ db.collection(collections.PUSH_NOTIFICATION_SUBS).createIndex({
152
+ copayerId: 1
153
+ });
154
+ db.collection(collections.TX_CONFIRMATION_SUBS).createIndex({
155
+ copayerId: 1,
156
+ txid: 1
157
+ });
158
+ db.collection(collections.TX_CONFIRMATION_SUBS).createIndex({
159
+ isActive: 1,
160
+ txid: 1,
161
+ copayerId: 1
162
+ });
163
+ db.collection(collections.SESSIONS).createIndex({
164
+ copayerId: 1
165
+ });
166
+ db.collection(collections.TSS_KEYGEN).createIndex({
167
+ id: 1
168
+ }, { unique: true });
169
+ }
170
+
171
+ connect(opts, cb) {
172
+ opts = opts || {};
173
+ if (this.db) return cb();
174
+ const config = opts.mongoDb || {};
175
+
176
+ if (opts.secondaryPreferred) {
177
+ if (config.uri.indexOf('?') > 0) {
178
+ config.uri = config.uri + '&';
179
+ } else {
180
+ config.uri = config.uri + '?';
181
+ }
182
+ config.uri = config.uri + 'readPreference=secondaryPreferred';
183
+ logger.info('Read operations set to secondaryPreferred');
184
+ }
185
+
186
+ if (!config.dbname) {
187
+ logger.error('No dbname at config.');
188
+ return cb(new Error('No dbname at config.'));
189
+ }
190
+
191
+ mongodb.MongoClient.connect(config.uri, { useUnifiedTopology: true }, (err, client) => {
192
+ if (err) {
193
+ logger.error('Unable to connect to the mongoDB. Check the credentials.');
194
+ return cb(err);
195
+ }
196
+ this.db = client.db(config.dbname);
197
+ this.client = client;
198
+
199
+ logger.info(`Connection established to db: ${config.uri}`);
200
+
201
+ Storage.createIndexes(this.db);
202
+ return cb();
203
+ });
204
+ }
205
+
206
+ disconnect(cb) {
207
+ if (this.client) {
208
+ this.client.close(err => {
209
+ if (err) return cb(err);
210
+ this.db = null;
211
+ this.client = null;
212
+ return cb();
213
+ });
214
+ } else {
215
+ return cb();
216
+ }
217
+ }
218
+
219
+ fetchWallet(id, cb: (err?: any, wallet?: Wallet) => void) {
220
+ if (!this.db) return cb('not ready');
221
+
222
+ this.db.collection(collections.WALLETS).findOne(
223
+ {
224
+ id
225
+ },
226
+ (err, result) => {
227
+ if (err) return cb(err);
228
+ if (!result) return cb();
229
+ return cb(null, Wallet.fromObj(result));
230
+ }
231
+ );
232
+ }
233
+
234
+ storeWallet(wallet, cb) {
235
+ this.db.collection(collections.WALLETS).replaceOne(
236
+ {
237
+ id: wallet.id
238
+ },
239
+ wallet.toObject(),
240
+ {
241
+ w: 1,
242
+ upsert: true
243
+ },
244
+ cb
245
+ );
246
+ }
247
+
248
+ storeWalletAndUpdateCopayersLookup(wallet, cb) {
249
+ const copayerLookups = (wallet.copayers || []).map(copayer => {
250
+ try {
251
+ $.checkState(copayer.requestPubKeys, 'Failed state: copayer.requestPubkeys undefined at <storeWalletAndUpdateCopayersLookup()>');
252
+ } catch (e) {
253
+ return cb(e);
254
+ }
255
+
256
+ return {
257
+ copayerId: copayer.id,
258
+ walletId: wallet.id,
259
+ requestPubKeys: copayer.requestPubKeys
260
+ };
261
+ });
262
+
263
+ this.db.collection(collections.COPAYERS_LOOKUP).deleteMany(
264
+ {
265
+ walletId: wallet.id
266
+ },
267
+ {
268
+ w: 1
269
+ },
270
+ err => {
271
+ if (err) return cb(err);
272
+ this.db.collection(collections.COPAYERS_LOOKUP).insertMany(
273
+ copayerLookups,
274
+ {
275
+ w: 1
276
+ },
277
+ err => {
278
+ if (err) return cb(err);
279
+ return this.storeWallet(wallet, cb);
280
+ }
281
+ );
282
+ }
283
+ );
284
+ }
285
+
286
+ fetchCopayerLookup(copayerId: string, cb: (err?: any, copayer?: Copayer) => void) {
287
+ this.db.collection(collections.COPAYERS_LOOKUP).findOne(
288
+ {
289
+ copayerId
290
+ },
291
+ (err, result) => {
292
+ if (err) return cb(err);
293
+ if (!result) return cb();
294
+
295
+ if (!result.requestPubKeys) {
296
+ result.requestPubKeys = [
297
+ {
298
+ key: result.requestPubKey,
299
+ signature: result.signature
300
+ }
301
+ ];
302
+ }
303
+
304
+ return cb(null, Copayer.fromObj(result));
305
+ }
306
+ );
307
+ }
308
+
309
+ // TODO: should be done client-side
310
+ _completeTxData(walletId, txs, cb) {
311
+ this.fetchWallet(walletId, (err, wallet) => {
312
+ if (err) return cb(err);
313
+ _.each([].concat(txs), tx => {
314
+ tx.derivationStrategy = wallet.derivationStrategy || 'BIP45';
315
+ tx.creatorName = wallet.getCopayer(tx.creatorId).name;
316
+ _.each(tx.actions, action => {
317
+ action.copayerName = wallet.getCopayer(action.copayerId).name;
318
+ });
319
+
320
+ if (tx.status == 'accepted') tx.raw = tx.getRawTx();
321
+ });
322
+ return cb(null, txs);
323
+ });
324
+ }
325
+
326
+ // TODO: remove walletId from signature
327
+ fetchTx(walletId, txProposalId, cb) {
328
+ if (!this.db) return cb();
329
+
330
+ this.db.collection(collections.TXS).findOne(
331
+ {
332
+ id: txProposalId,
333
+ walletId
334
+ },
335
+ (err, result) => {
336
+ if (err) return cb(err);
337
+ if (!result) return cb();
338
+ return this._completeTxData(walletId, TxProposal.fromObj(result), cb);
339
+ }
340
+ );
341
+ }
342
+
343
+ fetchTxByHash(hash, cb) {
344
+ if (!this.db) return cb();
345
+
346
+ this.db.collection(collections.TXS).findOne(
347
+ {
348
+ txid: hash
349
+ },
350
+ (err, result) => {
351
+ if (err) return cb(err);
352
+ if (!result) return cb();
353
+
354
+ return this._completeTxData(result.walletId, TxProposal.fromObj(result), cb);
355
+ }
356
+ );
357
+ }
358
+
359
+ fetchLastTxs(walletId, creatorId, limit, cb) {
360
+ this.db
361
+ .collection(collections.TXS)
362
+ .find(
363
+ {
364
+ walletId,
365
+ creatorId
366
+ },
367
+ {
368
+ limit: limit || 5
369
+ }
370
+ )
371
+ .sort({
372
+ createdOn: -1
373
+ })
374
+ .toArray((err, result) => {
375
+ if (err) return cb(err);
376
+ if (!result) return cb();
377
+ const txs = _.map(result, tx => {
378
+ return TxProposal.fromObj(tx);
379
+ });
380
+ return cb(null, txs);
381
+ });
382
+ }
383
+
384
+ fetchEthPendingTxs(multisigTxpsInfo) {
385
+ return new Promise((resolve, reject) => {
386
+ this.db
387
+ .collection(collections.TXS)
388
+ .find({
389
+ txid: { $in: multisigTxpsInfo.map(txpInfo => txpInfo.transactionHash) }
390
+ })
391
+ .sort({
392
+ createdOn: -1
393
+ })
394
+ .toArray(async (err, result) => {
395
+ if (err) return reject(err);
396
+ if (!result) return reject();
397
+ const multisigTxpsInfoByTransactionHash: any = _.groupBy(multisigTxpsInfo, 'transactionHash');
398
+ const actionsById = {};
399
+ const txs = _.compact(
400
+ _.map(result, tx => {
401
+ if (!tx.multisigContractAddress) {
402
+ return undefined;
403
+ }
404
+ tx.status = 'pending';
405
+ tx.multisigTxId = multisigTxpsInfoByTransactionHash[tx.txid][0].transactionId;
406
+ for (const action of tx.actions) {
407
+ if (_.some(multisigTxpsInfoByTransactionHash[tx.txid], { event: 'ExecutionFailure' })) {
408
+ action.type = 'failed';
409
+ }
410
+ }
411
+ if (tx.amount === 0) {
412
+ actionsById[tx.multisigTxId] = [...tx.actions, ...(actionsById[tx.multisigTxId] || [])];
413
+ return undefined;
414
+ }
415
+ return TxProposal.fromObj(tx);
416
+ })
417
+ );
418
+
419
+ for (const tx of txs as TxProposal[]) {
420
+ if (actionsById[tx.multisigTxId]) {
421
+ tx.actions = [...tx.actions, ...(actionsById[tx.multisigTxId] || [])];
422
+ }
423
+ }
424
+
425
+ return resolve(txs);
426
+ });
427
+ });
428
+ }
429
+
430
+ fetchPendingTxs(walletId, cb) {
431
+ this.db
432
+ .collection(collections.TXS)
433
+ .find({
434
+ walletId,
435
+ isPending: true
436
+ })
437
+ .sort({
438
+ createdOn: -1
439
+ })
440
+ .toArray((err, result) => {
441
+ if (err) return cb(err);
442
+ if (!result) return cb();
443
+ const txs = _.map(result, tx => {
444
+ return TxProposal.fromObj(tx);
445
+ });
446
+ return this._completeTxData(walletId, txs, cb);
447
+ });
448
+ }
449
+
450
+ /**
451
+ * fetchTxs. Times are in UNIX EPOCH (seconds)
452
+ *
453
+ * @param walletId
454
+ * @param opts.minTs
455
+ * @param opts.maxTs
456
+ * @param opts.limit
457
+ */
458
+ fetchTxs(walletId, opts, cb) {
459
+ opts = opts || {};
460
+
461
+ const tsFilter: { $gte?: number; $lte?: number } = {};
462
+ if (_.isNumber(opts.minTs)) tsFilter.$gte = opts.minTs;
463
+ if (_.isNumber(opts.maxTs)) tsFilter.$lte = opts.maxTs;
464
+
465
+ const filter: { walletId: string; createdOn?: typeof tsFilter } = {
466
+ walletId
467
+ };
468
+ if (!_.isEmpty(tsFilter)) filter.createdOn = tsFilter;
469
+
470
+ const mods: { limit?: number } = {};
471
+ if (_.isNumber(opts.limit)) mods.limit = opts.limit;
472
+
473
+ this.db
474
+ .collection(collections.TXS)
475
+ .find(filter, mods)
476
+ .sort({
477
+ createdOn: -1
478
+ })
479
+ .toArray((err, result) => {
480
+ if (err) return cb(err);
481
+ if (!result) return cb();
482
+ const txs = _.map(result, tx => {
483
+ return TxProposal.fromObj(tx);
484
+ });
485
+ return this._completeTxData(walletId, txs, cb);
486
+ });
487
+ }
488
+
489
+ /**
490
+ * fetchBroadcastedTxs. Times are in UNIX EPOCH (seconds)
491
+ *
492
+ * @param walletId
493
+ * @param opts.minTs
494
+ * @param opts.maxTs
495
+ * @param opts.limit
496
+ */
497
+ fetchBroadcastedTxs(walletId, opts, cb) {
498
+ opts = opts || {};
499
+
500
+ const tsFilter: { $gte?: number; $lte?: number } = {};
501
+ if (_.isNumber(opts.minTs)) tsFilter.$gte = opts.minTs;
502
+ if (_.isNumber(opts.maxTs)) tsFilter.$lte = opts.maxTs;
503
+
504
+ const filter: {
505
+ walletId: string;
506
+ status: string;
507
+ broadcastedOn?: typeof tsFilter;
508
+ } = {
509
+ walletId,
510
+ status: 'broadcasted'
511
+ };
512
+ if (!_.isEmpty(tsFilter)) filter.broadcastedOn = tsFilter;
513
+
514
+ const mods: { limit?: number } = {};
515
+ if (_.isNumber(opts.limit)) mods.limit = opts.limit;
516
+
517
+ this.db
518
+ .collection(collections.TXS)
519
+ .find(filter, mods)
520
+ .sort({
521
+ createdOn: -1
522
+ })
523
+ .toArray((err, result) => {
524
+ if (err) return cb(err);
525
+ if (!result) return cb();
526
+ const txs = _.map(result, tx => {
527
+ return TxProposal.fromObj(tx);
528
+ });
529
+ return this._completeTxData(walletId, txs, cb);
530
+ });
531
+ }
532
+
533
+ /**
534
+ * Retrieves notifications after a specific id or from a given ts (whichever is more recent).
535
+ *
536
+ * @param {String} notificationId
537
+ * @param {Number} minTs
538
+ * @returns {Notification[]} Notifications
539
+ */
540
+ fetchNotifications(walletId, notificationId, minTs, cb) {
541
+ function makeId(timestamp) {
542
+ return _.padStart(timestamp, 14, '0') + _.repeat('0', 4);
543
+ }
544
+ let minId = makeId(minTs);
545
+ if (notificationId) {
546
+ minId = notificationId > minId ? notificationId : minId;
547
+ }
548
+
549
+ this.db
550
+ .collection(collections.NOTIFICATIONS)
551
+ .find({
552
+ walletId,
553
+ id: {
554
+ $gt: minId
555
+ }
556
+ })
557
+ .sort({
558
+ id: 1
559
+ })
560
+ .toArray((err, result) => {
561
+ if (err) return cb(err);
562
+ if (!result) return cb();
563
+ const notifications = _.map(result, notification => {
564
+ return Notification.fromObj(notification);
565
+ });
566
+ return cb(null, notifications);
567
+ });
568
+ }
569
+
570
+ // TODO: remove walletId from signature
571
+ storeNotification(walletId, notification, cb) {
572
+ // This should only happens in certain tests.
573
+ if (!this.db) {
574
+ logger.warn('Trying to store a notification with close DB %o', notification);
575
+ return;
576
+ }
577
+
578
+ this.db.collection(collections.NOTIFICATIONS).insertOne(
579
+ notification,
580
+ {
581
+ w: 1
582
+ },
583
+ cb
584
+ );
585
+ }
586
+
587
+ // TODO: remove walletId from signature
588
+ storeTx(walletId, txp, cb) {
589
+ this.db.collection(collections.TXS).replaceOne(
590
+ {
591
+ id: txp.id,
592
+ walletId
593
+ },
594
+ txp.toObject(),
595
+ {
596
+ w: 1,
597
+ upsert: true
598
+ },
599
+ cb
600
+ );
601
+ }
602
+
603
+ removeTx(walletId, txProposalId, cb) {
604
+ this.db.collection(collections.TXS).deleteOne(
605
+ {
606
+ id: txProposalId,
607
+ walletId
608
+ },
609
+ {
610
+ w: 1
611
+ },
612
+ cb
613
+ );
614
+ }
615
+
616
+ removeWallet(walletId, cb) {
617
+ async.parallel(
618
+ [
619
+ next => {
620
+ this.db.collection(collections.WALLETS).deleteOne(
621
+ {
622
+ id: walletId
623
+ },
624
+ next
625
+ );
626
+ },
627
+ next => {
628
+ const otherCollections: string[] = _.without(_.values(collections), collections.WALLETS);
629
+ async.each(
630
+ otherCollections,
631
+ (col, next) => {
632
+ this.db.collection(col).deleteMany(
633
+ {
634
+ walletId
635
+ },
636
+ next
637
+ );
638
+ },
639
+ next
640
+ );
641
+ }
642
+ ],
643
+ cb
644
+ );
645
+ }
646
+
647
+ fetchAddresses(walletId, cb) {
648
+ this.db
649
+ .collection(collections.ADDRESSES)
650
+ .find({
651
+ walletId
652
+ })
653
+ .sort({
654
+ createdOn: 1
655
+ })
656
+ .toArray((err, result) => {
657
+ if (err) return cb(err);
658
+ if (!result) return cb();
659
+
660
+ return cb(null, Utils.sortAsc(result.map(Address.fromObj), 'createdOn', 'path'));
661
+ });
662
+ }
663
+
664
+ migrateToCashAddr(walletId, cb) {
665
+ const cursor = this.db.collection(collections.ADDRESSES).find({
666
+ walletId
667
+ });
668
+
669
+ cursor.on('end', () => {
670
+ console.log(`Migration to cash address of ${walletId} Finished`);
671
+ return this.clearWalletCache(walletId, cb);
672
+ });
673
+
674
+ cursor.on('err', err => {
675
+ return cb(err);
676
+ });
677
+
678
+ cursor.on('data', doc => {
679
+ cursor.pause();
680
+ let x;
681
+ try {
682
+ x = BCHAddressTranslator.translate(doc.address, 'cashaddr');
683
+ } catch (e) {
684
+ return cb(e);
685
+ }
686
+
687
+ this.db.collection(collections.ADDRESSES).updateMany({ _id: doc._id }, { $set: { address: x } });
688
+ cursor.resume();
689
+ });
690
+ }
691
+
692
+ fetchUnsyncAddresses(walletId, cb) {
693
+ this.db
694
+ .collection(collections.ADDRESSES)
695
+ .find({
696
+ walletId,
697
+ beRegistered: null
698
+ })
699
+ .toArray((err, result) => {
700
+ if (err) return cb(err);
701
+ if (!result) return cb();
702
+ return cb(null, result);
703
+ });
704
+ }
705
+
706
+ fetchNewAddresses(walletId, fromTs, cb) {
707
+ this.db
708
+ .collection(collections.ADDRESSES)
709
+ .find({
710
+ walletId,
711
+ createdOn: {
712
+ $gte: fromTs
713
+ }
714
+ })
715
+ .sort({
716
+ createdOn: 1
717
+ })
718
+ .toArray((err, result) => {
719
+ if (err) return cb(err);
720
+ if (!result) return cb();
721
+ return cb(null, result.map(Address.fromObj));
722
+ });
723
+ }
724
+
725
+ storeAddress(address, cb) {
726
+ this.db.collection(collections.ADDRESSES).replaceOne(
727
+ {
728
+ walletId: address.walletId,
729
+ address: address.address
730
+ },
731
+ address,
732
+ {
733
+ w: 1,
734
+ upsert: false
735
+ },
736
+ cb
737
+ );
738
+ }
739
+
740
+ markSyncedAddresses(addresses, cb) {
741
+ this.db.collection(collections.ADDRESSES).updateMany(
742
+ {
743
+ address: { $in: addresses }
744
+ },
745
+ { $set: { beRegistered: true } },
746
+ {
747
+ w: 1,
748
+ upsert: false
749
+ },
750
+ cb
751
+ );
752
+ }
753
+
754
+ deregisterWallet(walletId, cb) {
755
+ this.db.collection(collections.WALLETS).updateOne(
756
+ {
757
+ id: walletId
758
+ },
759
+ { $set: { beRegistered: null } },
760
+ {
761
+ w: 1,
762
+ upsert: false
763
+ },
764
+ () => {
765
+ this.db.collection(collections.ADDRESSES).updateMany(
766
+ {
767
+ walletId
768
+ },
769
+ { $set: { beRegistered: null } },
770
+ {
771
+ w: 1,
772
+ upsert: false
773
+ },
774
+ () => {
775
+ this.clearWalletCache(walletId, cb);
776
+ }
777
+ );
778
+ }
779
+ );
780
+ }
781
+
782
+ storeAddressAndWallet(wallet, addresses, cb) {
783
+ const clonedAddresses = [].concat(addresses);
784
+ if (!addresses || !clonedAddresses.length) return cb();
785
+ let duplicate;
786
+
787
+ this.db.collection(collections.ADDRESSES).insertMany(
788
+ clonedAddresses,
789
+ {
790
+ w: 1
791
+ },
792
+ err => {
793
+ // duplicate address?
794
+ if (err) {
795
+ if (!err.toString().match(/E11000/)) {
796
+ return cb(err);
797
+ } else {
798
+ // just return it
799
+ duplicate = true;
800
+ logger.warn('Found duplicate address: ' + clonedAddresses.map(a => a.address).join(','));
801
+ }
802
+ }
803
+ this.storeWallet(wallet, err => {
804
+ return cb(err, duplicate);
805
+ });
806
+ }
807
+ );
808
+ }
809
+
810
+ fetchAddressByWalletId(walletId, address, cb) {
811
+ this.db.collection(collections.ADDRESSES).findOne(
812
+ {
813
+ walletId,
814
+ address
815
+ },
816
+ (err, result) => {
817
+ if (err) return cb(err);
818
+ if (!result) return cb();
819
+
820
+ return cb(null, Address.fromObj(result));
821
+ }
822
+ );
823
+ }
824
+
825
+ fetchAddressesByWalletId(walletId, addresses, cb) {
826
+ this.db
827
+ .collection(collections.ADDRESSES)
828
+ .find(
829
+ {
830
+ walletId,
831
+ address: { $in: addresses }
832
+ },
833
+ {}
834
+ )
835
+ .toArray((err, result) => {
836
+ if (err) return cb(err);
837
+ if (!result) return cb();
838
+ return cb(null, result);
839
+ });
840
+ }
841
+
842
+ fetchAddressByChain(chain, address, cb) {
843
+ if (!this.db) return cb();
844
+
845
+ this.db
846
+ .collection(collections.ADDRESSES)
847
+ .find({
848
+ address
849
+ })
850
+ .toArray((err, result) => {
851
+ if (err) return cb(err);
852
+ if (!result || _.isEmpty(result)) return cb();
853
+ if (result.length > 1) {
854
+ result = _.find(result, address => {
855
+ return chain == (address.chain || address.coin || 'btc');
856
+ });
857
+ } else {
858
+ result = _.head(result);
859
+ }
860
+ if (!result) return cb();
861
+
862
+ return cb(null, Address.fromObj(result));
863
+ });
864
+ }
865
+
866
+ fetchPreferences<T extends Preferences | Preferences[]>(walletId: string, copayerId: string | null, cb: (err?: any, preferences?: T) => void) {
867
+ this.db
868
+ .collection(collections.PREFERENCES)
869
+ .find({
870
+ walletId
871
+ })
872
+ .toArray((err, result) => {
873
+ if (err) return cb(err);
874
+
875
+ if (copayerId) {
876
+ result = _.find(result, {
877
+ copayerId
878
+ });
879
+ }
880
+ if (!result) return cb();
881
+
882
+ const preferences = _.map([].concat(result), r => {
883
+ return Preferences.fromObj(r);
884
+ });
885
+ if (copayerId) {
886
+ return cb(null, preferences[0] as T);
887
+ } else {
888
+ return cb(null, preferences as T);
889
+ }
890
+ });
891
+ }
892
+
893
+ storePreferences(preferences, cb) {
894
+ this.db.collection(collections.PREFERENCES).replaceOne(
895
+ {
896
+ walletId: preferences.walletId,
897
+ copayerId: preferences.copayerId
898
+ },
899
+ preferences,
900
+ {
901
+ w: 1,
902
+ upsert: true
903
+ },
904
+ cb
905
+ );
906
+ }
907
+
908
+ storeEmail(email, cb) {
909
+ this.db.collection(collections.EMAIL_QUEUE).replaceOne(
910
+ {
911
+ id: email.id
912
+ },
913
+ email,
914
+ {
915
+ w: 1,
916
+ upsert: true
917
+ },
918
+ cb
919
+ );
920
+ }
921
+
922
+ fetchUnsentEmails(cb) {
923
+ this.db
924
+ .collection(collections.EMAIL_QUEUE)
925
+ .find({
926
+ status: 'fail'
927
+ })
928
+ .toArray((err, result) => {
929
+ if (err) return cb(err);
930
+ if (!result || _.isEmpty(result)) return cb(null, []);
931
+
932
+ const emails = _.map(result, x => {
933
+ return Email.fromObj(x);
934
+ });
935
+
936
+ return cb(null, emails);
937
+ });
938
+ }
939
+
940
+ fetchEmailByNotification(notificationId: string | number, cb: (err?: any, email?: Email) => void) {
941
+ this.db.collection(collections.EMAIL_QUEUE).findOne(
942
+ {
943
+ notificationId
944
+ },
945
+ (err, result) => {
946
+ if (err) return cb(err);
947
+ if (!result) return cb();
948
+
949
+ return cb(null, Email.fromObj(result));
950
+ }
951
+ );
952
+ }
953
+
954
+ getTxHistoryCacheStatusV8(walletId, cb) {
955
+ this.db.collection(collections.CACHE).findOne(
956
+ {
957
+ walletId,
958
+ type: 'historyCacheStatusV8',
959
+ key: null
960
+ },
961
+ (err, result) => {
962
+ if (err) return cb(err);
963
+ if (!result)
964
+ return cb(null, {
965
+ tipId: null,
966
+ tipIndex: null
967
+ });
968
+
969
+ return cb(null, {
970
+ updatedOn: result.updatedOn,
971
+ updatedHeight: result.updatedHeight,
972
+ tipIndex: result.tipIndex,
973
+ tipTxId: result.tipTxId,
974
+ tipHeight: result.tipHeight
975
+ });
976
+ }
977
+ );
978
+ }
979
+
980
+ getWalletAddressChecked(walletId, cb) {
981
+ this.db.collection(collections.CACHE).findOne(
982
+ {
983
+ walletId,
984
+ type: 'addressChecked',
985
+ key: null
986
+ },
987
+ (err, result) => {
988
+ if (err || !result) return cb(err);
989
+ return cb(null, result.totalAddresses);
990
+ }
991
+ );
992
+ }
993
+
994
+ setWalletAddressChecked(walletId, totalAddresses, cb) {
995
+ this.db.collection(collections.CACHE).replaceOne(
996
+ {
997
+ walletId,
998
+ type: 'addressChecked',
999
+ key: null
1000
+ },
1001
+ {
1002
+ walletId,
1003
+ type: 'addressChecked',
1004
+ key: null,
1005
+ totalAddresses
1006
+ },
1007
+ {
1008
+ w: 1,
1009
+ upsert: true
1010
+ },
1011
+ cb
1012
+ );
1013
+ }
1014
+
1015
+ // Since cache TX are "hard confirmed" skip, and limit
1016
+ // should be reliable to query the database.
1017
+ //
1018
+ //
1019
+ // skip=0 -> Latest TX of the wallet. (heights heigth, -1 doest not count because this
1020
+ // are confirmed TXs).
1021
+ //
1022
+ // In a query, tipIndex - skip - limit would be the oldest tx to be queried.
1023
+
1024
+ getTxHistoryCacheV8(walletId, skip, limit, cb) {
1025
+ $.checkArgument(skip >= 0);
1026
+ $.checkArgument(limit >= 0);
1027
+
1028
+ this.getTxHistoryCacheStatusV8(walletId, (err, cacheStatus) => {
1029
+ if (err) return cb(err);
1030
+
1031
+ if (_.isNull(cacheStatus.tipId)) return cb(null, []);
1032
+ // console.log('Cache status in GET:', cacheStatus); //TODO
1033
+
1034
+ let firstPosition = cacheStatus.tipIndex - skip - limit + 1;
1035
+ const lastPosition = cacheStatus.tipIndex - skip + 1;
1036
+
1037
+ if (firstPosition < 0) firstPosition = 0;
1038
+ if (lastPosition <= 0) return cb(null, []);
1039
+
1040
+ // console.log('[storage.js.750:first/lastPosition:]',firstPosition + '/'+lastPosition); //TODO
1041
+
1042
+ this.db
1043
+ .collection(collections.CACHE)
1044
+ .find({
1045
+ walletId,
1046
+ type: 'historyCacheV8',
1047
+ key: {
1048
+ $gte: firstPosition,
1049
+ $lt: lastPosition
1050
+ }
1051
+ })
1052
+ .sort({
1053
+ key: -1
1054
+ })
1055
+ .toArray((err, result) => {
1056
+ if (err) return cb(err);
1057
+ if (!result) return cb();
1058
+ const txs = _.map(result, 'tx');
1059
+ return cb(null, txs);
1060
+ });
1061
+ });
1062
+ }
1063
+
1064
+ clearWalletCache(walletId, cb) {
1065
+ this.db.collection(collections.CACHE).deleteMany(
1066
+ {
1067
+ walletId
1068
+ },
1069
+ {},
1070
+ cb
1071
+ );
1072
+ }
1073
+
1074
+ /*
1075
+ * This represent a ongoing query stream from a Wallet client
1076
+ */
1077
+ storeTxHistoryStreamV8(walletId, streamKey, items, cb) {
1078
+ // only 1 per wallet is allowed
1079
+ this.db.collection(collections.CACHE).replaceOne(
1080
+ {
1081
+ walletId,
1082
+ type: 'historyStream',
1083
+ key: null
1084
+ },
1085
+ {
1086
+ walletId,
1087
+ type: 'historyStream',
1088
+ key: null,
1089
+ streamKey,
1090
+ items
1091
+ },
1092
+ {
1093
+ w: 1,
1094
+ upsert: true
1095
+ },
1096
+ cb
1097
+ );
1098
+ }
1099
+
1100
+ clearTxHistoryStreamV8(walletId, cb) {
1101
+ this.db.collection(collections.CACHE).deleteMany(
1102
+ {
1103
+ walletId,
1104
+ type: 'historyStream',
1105
+ key: null
1106
+ },
1107
+ {},
1108
+ cb
1109
+ );
1110
+ }
1111
+
1112
+ getTxHistoryStreamV8(walletId, cb) {
1113
+ this.db.collection(collections.CACHE).findOne(
1114
+ {
1115
+ walletId,
1116
+ type: 'historyStream',
1117
+ key: null
1118
+ },
1119
+ (err, result) => {
1120
+ if (err || !result) return cb(err);
1121
+ return cb(null, result);
1122
+ }
1123
+ );
1124
+ }
1125
+
1126
+ /*
1127
+ * @param {string} [opts.walletId] - The wallet id to use as current wallet
1128
+ * @param {tipIndex} [integer] - Last tx index of the current cache
1129
+ * @param {array} [items] - The items (transactions) to store
1130
+ * @param {updateHeight} [integer] - The blockchain height up to which the transactions where queried, with CONFIRMATIONS_TO_START_CACHING subtracted.
1131
+ *
1132
+ *
1133
+ */
1134
+ storeTxHistoryCacheV8(walletId, tipIndex, items, updateHeight, cb) {
1135
+ let index = _.isNull(tipIndex) ? 0 : tipIndex + 1;
1136
+ let pos;
1137
+
1138
+ // `items` must be ordeder: first item [0]: most recent.
1139
+ //
1140
+ // In cache:
1141
+ // pos = 0; oldest one.
1142
+ // pos = tipIndex (item[0] => most recent).
1143
+
1144
+ _.each(items.reverse(), item => {
1145
+ item.position = index++;
1146
+ });
1147
+ async.each(
1148
+ items,
1149
+ (item: { position: number; code: string; value: string }, next) => {
1150
+ pos = item.position;
1151
+ delete item.position;
1152
+ // console.log('STORING [storage.js.804:at:]',pos, item.blockheight);
1153
+ this.db.collection(collections.CACHE).insertOne(
1154
+ {
1155
+ walletId,
1156
+ type: 'historyCacheV8',
1157
+ key: pos,
1158
+ tx: item
1159
+ },
1160
+ next
1161
+ );
1162
+ },
1163
+ err => {
1164
+ if (err) return cb(err);
1165
+
1166
+ interface CacheItem {
1167
+ txid?: string;
1168
+ blockheight?: number;
1169
+ }
1170
+ const first: CacheItem = _.first(items);
1171
+ const last: CacheItem = _.last(items);
1172
+
1173
+ try {
1174
+ $.checkState(last.txid, 'Failed state: missing txid in tx to be cached at <storeHistoryCacheV8()>');
1175
+ $.checkState(
1176
+ last.blockheight,
1177
+ 'Failed state: missing blockheight in tx to be cached at <storeHistoryCacheV8()>'
1178
+ );
1179
+ $.checkState(
1180
+ first.blockheight,
1181
+ 'Failed state: missing blockheight in tx to be cached at <storeHistoryCacheV8()>'
1182
+ );
1183
+ $.checkState(
1184
+ last.blockheight >= 0,
1185
+ 'Failed state: blockheight <=0 om tx to be cached at <storeHistoryCacheV8()>'
1186
+ );
1187
+
1188
+ // note there is a .reverse before.
1189
+ $.checkState(
1190
+ first.blockheight <= last.blockheight,
1191
+ 'Failed state: tx to be cached are in wrong order (lastest should be first)'
1192
+ );
1193
+ } catch (e) {
1194
+ return cb(e);
1195
+ }
1196
+
1197
+ logger.debug(`Cache Last Item: ${last.txid} blockh: ${last.blockheight} updatedh: ${updateHeight}`);
1198
+ this.db.collection(collections.CACHE).replaceOne(
1199
+ {
1200
+ walletId,
1201
+ type: 'historyCacheStatusV8',
1202
+ key: null
1203
+ },
1204
+ {
1205
+ walletId,
1206
+ type: 'historyCacheStatusV8',
1207
+ key: null,
1208
+ updatedOn: Date.now(),
1209
+ updatedHeight: updateHeight,
1210
+ tipIndex: pos,
1211
+ tipTxId: last.txid,
1212
+ tipHeight: last.blockheight
1213
+ },
1214
+ {
1215
+ w: 1,
1216
+ upsert: true
1217
+ },
1218
+ cb
1219
+ );
1220
+ }
1221
+ );
1222
+ }
1223
+
1224
+ storeFiatRate(coin, rates, cb) {
1225
+ const now = Date.now();
1226
+ async.each(
1227
+ rates,
1228
+ (rate: { code: string; value: string }, next) => {
1229
+ const i = {
1230
+ ts: now,
1231
+ coin,
1232
+ code: rate.code,
1233
+ value: rate.value
1234
+ };
1235
+ this.db.collection(collections.FIAT_RATES2).insertOne(
1236
+ i,
1237
+ {
1238
+ w: 1
1239
+ },
1240
+ next
1241
+ );
1242
+ },
1243
+ cb
1244
+ );
1245
+ }
1246
+
1247
+ fetchFiatRate(coin, code, ts, cb) {
1248
+ this.db
1249
+ .collection(collections.FIAT_RATES2)
1250
+ .find({
1251
+ coin,
1252
+ code,
1253
+ ts: {
1254
+ $lte: ts
1255
+ }
1256
+ })
1257
+ .sort({
1258
+ ts: -1
1259
+ })
1260
+ .limit(1)
1261
+ .toArray((err, result) => {
1262
+ if (err || _.isEmpty(result)) return cb(err);
1263
+ return cb(null, result[0]);
1264
+ });
1265
+ }
1266
+
1267
+ fetchHistoricalRates(coin, code, ts, cb) {
1268
+ this.db
1269
+ .collection(collections.FIAT_RATES2)
1270
+ .find({
1271
+ coin,
1272
+ code,
1273
+ ts: {
1274
+ $gte: ts
1275
+ }
1276
+ })
1277
+ .sort({
1278
+ ts: -1
1279
+ })
1280
+ .toArray((err, result) => {
1281
+ if (err || _.isEmpty(result)) return cb(err);
1282
+ return cb(null, result);
1283
+ });
1284
+ }
1285
+
1286
+ fetchTxNote(walletId, txid, cb) {
1287
+ this.db.collection(collections.TX_NOTES).findOne(
1288
+ {
1289
+ walletId,
1290
+ txid
1291
+ },
1292
+ (err, result) => {
1293
+ if (err) return cb(err);
1294
+ if (!result) return cb();
1295
+ return this._completeTxNotesData(walletId, TxNote.fromObj(result), cb);
1296
+ }
1297
+ );
1298
+ }
1299
+
1300
+ // TODO: should be done client-side
1301
+ _completeTxNotesData(walletId, notes, cb) {
1302
+ this.fetchWallet(walletId, (err, wallet) => {
1303
+ if (err) return cb(err);
1304
+ _.each([].concat(notes), note => {
1305
+ note.editedByName = wallet.getCopayer(note.editedBy).name;
1306
+ });
1307
+ return cb(null, notes);
1308
+ });
1309
+ }
1310
+
1311
+ /**
1312
+ * fetchTxNotes. Times are in UNIX EPOCH (seconds)
1313
+ *
1314
+ * @param walletId
1315
+ * @param opts.minTs
1316
+ */
1317
+ fetchTxNotes(walletId, opts, cb) {
1318
+ const filter: { walletId: string; editedOn?: { $gte: number } } = {
1319
+ walletId
1320
+ };
1321
+ if (_.isNumber(opts.minTs))
1322
+ filter.editedOn = {
1323
+ $gte: opts.minTs
1324
+ };
1325
+ this.db
1326
+ .collection(collections.TX_NOTES)
1327
+ .find(filter)
1328
+ .toArray((err, result) => {
1329
+ if (err) return cb(err);
1330
+ const notes = _.compact(
1331
+ _.map(result, note => {
1332
+ return TxNote.fromObj(note);
1333
+ })
1334
+ );
1335
+ return this._completeTxNotesData(walletId, notes, cb);
1336
+ });
1337
+ }
1338
+
1339
+ storeTxNote(txNote, cb) {
1340
+ this.db.collection(collections.TX_NOTES).replaceOne(
1341
+ {
1342
+ txid: txNote.txid,
1343
+ walletId: txNote.walletId
1344
+ },
1345
+ txNote.toObject(),
1346
+ {
1347
+ w: 1,
1348
+ upsert: true
1349
+ },
1350
+ cb
1351
+ );
1352
+ }
1353
+
1354
+ getSession(copayerId, cb) {
1355
+ this.db.collection(collections.SESSIONS).findOne(
1356
+ {
1357
+ copayerId
1358
+ },
1359
+ (err, result) => {
1360
+ if (err || !result) return cb(err);
1361
+ return cb(null, Session.fromObj(result));
1362
+ }
1363
+ );
1364
+ }
1365
+
1366
+ storeSession(session, cb) {
1367
+ this.db.collection(collections.SESSIONS).replaceOne(
1368
+ {
1369
+ copayerId: session.copayerId
1370
+ },
1371
+ session.toObject(),
1372
+ {
1373
+ w: 1,
1374
+ upsert: true
1375
+ },
1376
+ cb
1377
+ );
1378
+ }
1379
+
1380
+ fetchPushNotificationSubs(copayerId, cb) {
1381
+ this.db
1382
+ .collection(collections.PUSH_NOTIFICATION_SUBS)
1383
+ .find({
1384
+ copayerId
1385
+ })
1386
+ .toArray((err, result) => {
1387
+ if (err) return cb(err);
1388
+
1389
+ if (!result) return cb();
1390
+
1391
+ const tokens = _.map([].concat(result), r => {
1392
+ return PushNotificationSub.fromObj(r);
1393
+ });
1394
+ return cb(null, tokens);
1395
+ });
1396
+ }
1397
+
1398
+ fetchLatestPushNotificationSubs(cb) {
1399
+ const fromDate = new Date().getTime() - Defaults.PUSH_NOTIFICATION_SUBS_TIME;
1400
+ this.db
1401
+ .collection(collections.PUSH_NOTIFICATION_SUBS)
1402
+ .find({
1403
+ _id: {
1404
+ $gte: new ObjectID(objectIdDate(fromDate))
1405
+ }
1406
+ })
1407
+ .sort({ _id: -1 })
1408
+ .toArray((err, result) => {
1409
+ if (err) return cb(err);
1410
+
1411
+ if (!result) return cb();
1412
+
1413
+ const tokens = _.map([].concat(result), r => {
1414
+ return PushNotificationSub.fromObj(r);
1415
+ });
1416
+ return cb(null, tokens);
1417
+ });
1418
+ }
1419
+
1420
+ storePushNotificationSub(pushNotificationSub, cb) {
1421
+ this.db.collection(collections.PUSH_NOTIFICATION_SUBS).replaceOne(
1422
+ {
1423
+ copayerId: pushNotificationSub.copayerId,
1424
+ token: pushNotificationSub.token
1425
+ },
1426
+ pushNotificationSub,
1427
+ {
1428
+ w: 1,
1429
+ upsert: true
1430
+ },
1431
+ cb
1432
+ );
1433
+ }
1434
+
1435
+ removePushNotificationSub(copayerId, token, cb) {
1436
+ this.db.collection(collections.PUSH_NOTIFICATION_SUBS).deleteMany(
1437
+ {
1438
+ copayerId,
1439
+ token
1440
+ },
1441
+ {
1442
+ w: 1
1443
+ },
1444
+ cb
1445
+ );
1446
+ }
1447
+
1448
+ storePushNotificationBrazeSub(pushNotificationSub, cb) {
1449
+ this.db.collection(collections.PUSH_NOTIFICATION_SUBS).replaceOne(
1450
+ {
1451
+ copayerId: pushNotificationSub.copayerId,
1452
+ externalUserId: pushNotificationSub.externalUserId
1453
+ },
1454
+ pushNotificationSub,
1455
+ {
1456
+ w: 1,
1457
+ upsert: true
1458
+ },
1459
+ cb
1460
+ );
1461
+ }
1462
+
1463
+ removePushNotificationBrazeSub(copayerId, externalUserId, cb) {
1464
+ this.db.collection(collections.PUSH_NOTIFICATION_SUBS).deleteMany(
1465
+ {
1466
+ copayerId,
1467
+ externalUserId
1468
+ },
1469
+ {
1470
+ w: 1
1471
+ },
1472
+ cb
1473
+ );
1474
+ }
1475
+
1476
+ streamActiveTxConfirmationSubs(copayerId: string, txids: string[]) {
1477
+ // This should only happens in certain tests.
1478
+ if (!this.db) {
1479
+ logger.warn('Trying to fetch notifications with closed DB');
1480
+ return;
1481
+ }
1482
+
1483
+ const filter: { isActive: boolean; txid: { $in: string[] }; copayerId?: string } = {
1484
+ isActive: true,
1485
+ txid: { $in: txids }
1486
+ };
1487
+
1488
+ if (copayerId) filter.copayerId = copayerId;
1489
+
1490
+ return this.db
1491
+ .collection(collections.TX_CONFIRMATION_SUBS)
1492
+ .find(filter)
1493
+ .addCursorFlag('noCursorTimeout', true);
1494
+ }
1495
+
1496
+ storeTxConfirmationSub(txConfirmationSub, cb) {
1497
+ this.db.collection(collections.TX_CONFIRMATION_SUBS).replaceOne(
1498
+ {
1499
+ copayerId: txConfirmationSub.copayerId,
1500
+ txid: txConfirmationSub.txid
1501
+ },
1502
+ txConfirmationSub,
1503
+ {
1504
+ w: 1,
1505
+ upsert: true
1506
+ },
1507
+ cb
1508
+ );
1509
+ }
1510
+
1511
+ removeTxConfirmationSub(copayerId, txid, cb) {
1512
+ this.db.collection(collections.TX_CONFIRMATION_SUBS).deleteMany(
1513
+ {
1514
+ copayerId,
1515
+ txid
1516
+ },
1517
+ {
1518
+ w: 1
1519
+ },
1520
+ cb
1521
+ );
1522
+ }
1523
+
1524
+ _dump(cb, fn) {
1525
+ fn = fn || console.log;
1526
+ cb = cb || function() {};
1527
+
1528
+ this.db.collections((err, collections) => {
1529
+ if (err) return cb(err);
1530
+ async.eachSeries(
1531
+ collections,
1532
+ (col: any, next) => {
1533
+ col.find().toArray((err, items) => {
1534
+ fn('--------', col.s.name);
1535
+ fn(items);
1536
+ fn('------------------------------------------------------------------\n\n');
1537
+ next(err);
1538
+ });
1539
+ },
1540
+ cb
1541
+ );
1542
+ });
1543
+ }
1544
+
1545
+ // key: 'feeLevel' + JSON.stringify(opts);
1546
+ // duration: FEE_LEVEL_DURATION
1547
+ //
1548
+
1549
+ checkAndUseGlobalCache(key, duration, cb) {
1550
+ const now = Date.now();
1551
+ this.db.collection(collections.CACHE).findOne(
1552
+ {
1553
+ key,
1554
+ walletId: null,
1555
+ type: null
1556
+ },
1557
+ (err, ret) => {
1558
+ if (err) return cb(err);
1559
+ if (!ret) return cb();
1560
+ const validFor = ret.ts + duration - now;
1561
+
1562
+ // always return the value as a 3 param anyways.
1563
+ return cb(null, validFor > 0 ? ret.result : null, ret.result);
1564
+ }
1565
+ );
1566
+ }
1567
+
1568
+ storeGlobalCache(key, values, cb) {
1569
+ const now = Date.now();
1570
+ this.db.collection(collections.CACHE).updateOne(
1571
+ {
1572
+ key,
1573
+ walletId: null,
1574
+ type: null
1575
+ },
1576
+ {
1577
+ $set: {
1578
+ ts: now,
1579
+ result: values
1580
+ }
1581
+ },
1582
+ {
1583
+ w: 1,
1584
+ upsert: true
1585
+ },
1586
+ cb
1587
+ );
1588
+ }
1589
+
1590
+ clearGlobalCache(key, cb) {
1591
+ this.db.collection(collections.CACHE).deleteMany(
1592
+ {
1593
+ key,
1594
+ walletId: null,
1595
+ type: null
1596
+ },
1597
+ {
1598
+ w: 1
1599
+ },
1600
+ cb
1601
+ );
1602
+ }
1603
+
1604
+ walletCheck = async params => {
1605
+ const { walletId } = params;
1606
+
1607
+ return new Promise(resolve => {
1608
+ const addressStream = this.db.collection(collections.ADDRESSES).find({ walletId });
1609
+ let sum = 0;
1610
+ let lastAddress;
1611
+ addressStream.on('data', walletAddress => {
1612
+ if (walletAddress.address) {
1613
+ lastAddress = walletAddress.address.replace(/:.*$/, '');
1614
+ const addressSum = Buffer.from(lastAddress).reduce((tot, cur) => (tot + cur) % Number.MAX_SAFE_INTEGER);
1615
+ sum = (sum + addressSum) % Number.MAX_SAFE_INTEGER;
1616
+ }
1617
+ });
1618
+ addressStream.on('end', () => {
1619
+ resolve({ lastAddress, sum });
1620
+ });
1621
+ });
1622
+ };
1623
+
1624
+ acquireLock(key, expireTs, cb) {
1625
+ this.db.collection(collections.LOCKS).insertOne(
1626
+ {
1627
+ _id: key,
1628
+ expireOn: expireTs
1629
+ },
1630
+ {},
1631
+ cb
1632
+ );
1633
+ }
1634
+
1635
+ releaseLock(key, cb) {
1636
+ this.db.collection(collections.LOCKS).deleteMany(
1637
+ {
1638
+ _id: key
1639
+ },
1640
+ {},
1641
+ cb
1642
+ );
1643
+ }
1644
+
1645
+ clearExpiredLock(key, cb) {
1646
+ this.db.collection(collections.LOCKS).findOne(
1647
+ {
1648
+ _id: key
1649
+ },
1650
+ (err, ret) => {
1651
+ if (err || !ret) return;
1652
+
1653
+ if (ret.expireOn < Date.now()) {
1654
+ logger.info('Releasing expired lock : ' + key);
1655
+ return this.releaseLock(key, cb);
1656
+ }
1657
+ return cb();
1658
+ }
1659
+ );
1660
+ }
1661
+
1662
+ fetchTestingAdverts(cb) {
1663
+ this.db
1664
+ .collection(collections.ADVERTISEMENTS)
1665
+ .find({
1666
+ isTesting: true
1667
+ })
1668
+ .toArray((err, result) => {
1669
+ if (err) return cb(err);
1670
+ if (!result) return cb();
1671
+ return cb(null, result.map(Advertisement.fromObj));
1672
+ });
1673
+ }
1674
+
1675
+ fetchActiveAdverts(cb) {
1676
+ this.db
1677
+ .collection(collections.ADVERTISEMENTS)
1678
+ .find({
1679
+ isAdActive: true
1680
+ })
1681
+ .toArray((err, result) => {
1682
+ if (err) return cb(err);
1683
+ if (!result) return cb();
1684
+ return cb(null, result.map(Advertisement.fromObj));
1685
+ });
1686
+ }
1687
+
1688
+ fetchAdvertsByCountry(country, cb) {
1689
+ this.db
1690
+ .collection(collections.ADVERTISEMENTS)
1691
+ .find({
1692
+ country
1693
+ })
1694
+ .toArray((err, result) => {
1695
+ if (err) return cb(err);
1696
+ if (!result) return cb();
1697
+ return cb(null, result.map(Advertisement.fromObj));
1698
+ });
1699
+ }
1700
+
1701
+ fetchAllAdverts(_cb) {
1702
+ this.db.collection(collections.ADVERTISEMENTS).find({});
1703
+ }
1704
+
1705
+ removeAdvert(adId, cb) {
1706
+ this.db.collection(collections.ADVERTISEMENTS).deleteOne(
1707
+ {
1708
+ advertisementId: adId
1709
+ },
1710
+ {
1711
+ w: 1
1712
+ },
1713
+ cb
1714
+ );
1715
+ }
1716
+
1717
+ storeAdvert(advert, cb) {
1718
+ this.db.collection(collections.ADVERTISEMENTS).updateOne(
1719
+ {
1720
+ advertisementId: advert.advertisementId
1721
+ },
1722
+ { $set: advert },
1723
+ {
1724
+ upsert: true
1725
+ },
1726
+ cb
1727
+ );
1728
+ }
1729
+
1730
+ fetchAdvert(adId, cb) {
1731
+ this.db.collection(collections.ADVERTISEMENTS).findOne(
1732
+ {
1733
+ advertisementId: adId
1734
+ },
1735
+ (err, result) => {
1736
+ if (err) return cb(err);
1737
+ if (!result) return cb();
1738
+
1739
+ return cb(null, Advertisement.fromObj(result));
1740
+ }
1741
+ );
1742
+ }
1743
+
1744
+ activateAdvert(adId, cb) {
1745
+ this.db.collection(collections.ADVERTISEMENTS).updateOne(
1746
+ {
1747
+ advertisementId: adId
1748
+ },
1749
+ { $set: { isAdActive: true, isTesting: false } },
1750
+ {
1751
+ upsert: true
1752
+ },
1753
+ cb
1754
+ );
1755
+ }
1756
+
1757
+ deactivateAdvert(adId, cb) {
1758
+ this.db.collection(collections.ADVERTISEMENTS).updateOne(
1759
+ {
1760
+ advertisementId: adId
1761
+ },
1762
+ {
1763
+ $set: { isAdActive: false, isTesting: true }
1764
+ },
1765
+ {
1766
+ upsert: true
1767
+ },
1768
+ cb
1769
+ );
1770
+ }
1771
+
1772
+ async fetchTssKeyGenSession({ id }: { id: string }) {
1773
+ const doc = await this.db.collection(collections.TSS_KEYGEN).findOne({ id });
1774
+ if (!doc) {
1775
+ return null;
1776
+ }
1777
+ return TssKeyGenModel.fromObj(doc);
1778
+ }
1779
+
1780
+ async storeTssKeyGenSession({ doc }: { doc: TssKeyGenModel }) {
1781
+ return this.db.collection(collections.TSS_KEYGEN).insertOne(doc);
1782
+ }
1783
+
1784
+ async storeTssKeyGenParticipant({ id, partyId, copayerId }: { id: string; partyId: number; copayerId: string }) {
1785
+ return this.db.collection(collections.TSS_KEYGEN).updateOne(
1786
+ { id },
1787
+ {
1788
+ $set: {
1789
+ [`participants.${partyId}`]: copayerId
1790
+ }
1791
+ },
1792
+ { upsert: false }
1793
+ );
1794
+ }
1795
+
1796
+ async storeTssKeyGenMessage({ id, message, __v }: { id: string; message: ITssKeyMessageObject; __v: number }) {
1797
+ const result = await this.db.collection(collections.TSS_KEYGEN).updateOne(
1798
+ { id, __v },
1799
+ {
1800
+ $push: {
1801
+ [`rounds.${message.round}`]: {
1802
+ fromPartyId: message.partyId,
1803
+ messages: message
1804
+ }
1805
+ },
1806
+ $inc: {
1807
+ __v: 1
1808
+ }
1809
+ },
1810
+ { upsert: false }
1811
+ );
1812
+ if (!result.matchedCount) {
1813
+ throw new Error('MONGO_DOC_OUTDATED: No document found for version ' + __v);
1814
+ }
1815
+ return result;
1816
+ }
1817
+
1818
+ async storeTssKeySharedPubKey({ id, publicKey }: { id: string; publicKey: string }) {
1819
+ return this.db.collection(collections.TSS_KEYGEN).updateOne(
1820
+ { id },
1821
+ {
1822
+ $set: {
1823
+ sharedPublicKey: publicKey
1824
+ }
1825
+ },
1826
+ { upsert: false }
1827
+ );
1828
+ }
1829
+
1830
+ async storeTssKeyShare({ id, partyId, encryptedKeyChain }: { id: string; partyId: number; encryptedKeyChain: string }) {
1831
+ return this.db.collection(collections.TSS_KEYGEN).updateOne(
1832
+ { id },
1833
+ {
1834
+ $set: {
1835
+ [`keyShares.${partyId}`]: encryptedKeyChain
1836
+ }
1837
+ },
1838
+ { upsert: false }
1839
+ );
1840
+ }
1841
+
1842
+ async storeTssKeyBwsJoinSecret({ id, secret }: { id: string; secret: string }) {
1843
+ return this.db.collection(collections.TSS_KEYGEN).updateOne({
1844
+ id
1845
+ },
1846
+ {
1847
+ $set: {
1848
+ bwsJoinSecret: secret
1849
+ }
1850
+ },
1851
+ { upsert: false });
1852
+ }
1853
+
1854
+ async fetchTssSigSession({ id }: { id: string }) {
1855
+ const doc = await this.db.collection(collections.TSS_SIGN).findOne({ id });
1856
+ if (!doc) {
1857
+ return null;
1858
+ }
1859
+ return TssSigGenModel.fromObj(doc);
1860
+ }
1861
+
1862
+ async storeTssSigSession({ doc }: { doc: TssSigGenModel }) {
1863
+ return this.db.collection(collections.TSS_SIGN).insertOne(doc);
1864
+ }
1865
+
1866
+ async storeTssSigParticipant({ id, partyId, copayerId, __v }: { id: string; partyId: number; copayerId: string; __v: number }) {
1867
+ const result = await this.db.collection(collections.TSS_SIGN).updateOne(
1868
+ { id, __v },
1869
+ {
1870
+ $push: {
1871
+ participants: {
1872
+ partyId,
1873
+ copayerId
1874
+ }
1875
+ }
1876
+ },
1877
+ { upsert: false }
1878
+ );
1879
+ if (!result.matchedCount) {
1880
+ throw new Error('MONGO_DOC_OUTDATED: No document found for version ' + __v);
1881
+ }
1882
+ return result;
1883
+ }
1884
+
1885
+ async storeTssSigMessage({ id, message, __v }: { id: string; message: ITssSigMessageObject; __v: number }) {
1886
+ const result = await this.db.collection(collections.TSS_SIGN).updateOne(
1887
+ { id, __v },
1888
+ {
1889
+ $push: {
1890
+ [`rounds.${message.round}`]: {
1891
+ fromPartyId: message.partyId,
1892
+ messages: message
1893
+ }
1894
+ },
1895
+ $inc: {
1896
+ __v: 1
1897
+ }
1898
+ },
1899
+ { upsert: false }
1900
+ );
1901
+ if (!result.matchedCount) {
1902
+ throw new Error('MONGO_DOC_OUTDATED: No document found for version ' + __v);
1903
+ }
1904
+ return result;
1905
+ }
1906
+
1907
+ async storeTssSignature({ id, signature }: { id: string; signature: ITssSigMessageObject['signature'] }) {
1908
+ return this.db.collection(collections.TSS_SIGN).updateOne(
1909
+ { id },
1910
+ {
1911
+ $set: {
1912
+ signature
1913
+ }
1914
+ },
1915
+ { upsert: false }
1916
+ );
1917
+ }
1918
+
1919
+ }