@ledgerhq/coin-framework 0.0.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 (471) hide show
  1. package/lib/account/accountId.d.ts +16 -0
  2. package/lib/account/accountId.d.ts.map +1 -0
  3. package/lib/account/accountId.js +85 -0
  4. package/lib/account/accountId.js.map +1 -0
  5. package/lib/account/accountName.d.ts +14 -0
  6. package/lib/account/accountName.d.ts.map +1 -0
  7. package/lib/account/accountName.js +17 -0
  8. package/lib/account/accountName.js.map +1 -0
  9. package/lib/account/addAccounts.d.ts +35 -0
  10. package/lib/account/addAccounts.d.ts.map +1 -0
  11. package/lib/account/addAccounts.js +209 -0
  12. package/lib/account/addAccounts.js.map +1 -0
  13. package/lib/account/balanceHistoryCache.d.ts +25 -0
  14. package/lib/account/balanceHistoryCache.d.ts.map +1 -0
  15. package/lib/account/balanceHistoryCache.js +115 -0
  16. package/lib/account/balanceHistoryCache.js.map +1 -0
  17. package/lib/account/groupOperations.d.ts +17 -0
  18. package/lib/account/groupOperations.d.ts.map +1 -0
  19. package/lib/account/groupOperations.js +127 -0
  20. package/lib/account/groupOperations.js.map +1 -0
  21. package/lib/account/helpers.d.ts +44 -0
  22. package/lib/account/helpers.d.ts.map +1 -0
  23. package/lib/account/helpers.js +333 -0
  24. package/lib/account/helpers.js.map +1 -0
  25. package/lib/account/helpers.test.d.ts +2 -0
  26. package/lib/account/helpers.test.d.ts.map +1 -0
  27. package/lib/account/helpers.test.js +366 -0
  28. package/lib/account/helpers.test.js.map +1 -0
  29. package/lib/account/index.d.ts +11 -0
  30. package/lib/account/index.d.ts.map +1 -0
  31. package/lib/account/index.js +27 -0
  32. package/lib/account/index.js.map +1 -0
  33. package/lib/account/ordering.d.ts +10 -0
  34. package/lib/account/ordering.d.ts.map +1 -0
  35. package/lib/account/ordering.js +110 -0
  36. package/lib/account/ordering.js.map +1 -0
  37. package/lib/account/pending.d.ts +33 -0
  38. package/lib/account/pending.d.ts.map +1 -0
  39. package/lib/account/pending.js +64 -0
  40. package/lib/account/pending.js.map +1 -0
  41. package/lib/account/serialization.d.ts +6 -0
  42. package/lib/account/serialization.d.ts.map +1 -0
  43. package/lib/account/serialization.js +118 -0
  44. package/lib/account/serialization.js.map +1 -0
  45. package/lib/account/support.d.ts +9 -0
  46. package/lib/account/support.d.ts.map +1 -0
  47. package/lib/account/support.js +72 -0
  48. package/lib/account/support.js.map +1 -0
  49. package/lib/account.test.d.ts +2 -0
  50. package/lib/account.test.d.ts.map +1 -0
  51. package/lib/account.test.js +257 -0
  52. package/lib/account.test.js.map +1 -0
  53. package/lib/bot/bot-test-context.d.ts +3 -0
  54. package/lib/bot/bot-test-context.d.ts.map +1 -0
  55. package/lib/bot/bot-test-context.js +26 -0
  56. package/lib/bot/bot-test-context.js.map +1 -0
  57. package/lib/bot/bot-test-context.test.d.ts +2 -0
  58. package/lib/bot/bot-test-context.test.d.ts.map +1 -0
  59. package/lib/bot/bot-test-context.test.js +41 -0
  60. package/lib/bot/bot-test-context.test.js.map +1 -0
  61. package/lib/bot/formatters.d.ts +2 -0
  62. package/lib/bot/formatters.d.ts.map +1 -0
  63. package/lib/bot/formatters.js +31 -0
  64. package/lib/bot/formatters.js.map +1 -0
  65. package/lib/bot/specs.d.ts +50 -0
  66. package/lib/bot/specs.d.ts.map +1 -0
  67. package/lib/bot/specs.js +204 -0
  68. package/lib/bot/specs.js.map +1 -0
  69. package/lib/bot/types.d.ts +178 -0
  70. package/lib/bot/types.d.ts.map +1 -0
  71. package/lib/bot/types.js +3 -0
  72. package/lib/bot/types.js.map +1 -0
  73. package/lib/bridge/getAddressWrapper.d.ts +6 -0
  74. package/lib/bridge/getAddressWrapper.d.ts.map +1 -0
  75. package/lib/bridge/getAddressWrapper.js +27 -0
  76. package/lib/bridge/getAddressWrapper.js.map +1 -0
  77. package/lib/bridge/jsHelpers.d.ts +63 -0
  78. package/lib/bridge/jsHelpers.d.ts.map +1 -0
  79. package/lib/bridge/jsHelpers.js +574 -0
  80. package/lib/bridge/jsHelpers.js.map +1 -0
  81. package/lib/cache.d.ts +10 -0
  82. package/lib/cache.d.ts.map +1 -0
  83. package/lib/cache.js +100 -0
  84. package/lib/cache.js.map +1 -0
  85. package/lib/cross.d.ts +42 -0
  86. package/lib/cross.d.ts.map +1 -0
  87. package/lib/cross.js +254 -0
  88. package/lib/cross.js.map +1 -0
  89. package/lib/cross.test.d.ts +2 -0
  90. package/lib/cross.test.d.ts.map +1 -0
  91. package/lib/cross.test.js +99 -0
  92. package/lib/cross.test.js.map +1 -0
  93. package/lib/currencies/BigNumberToLocaleString.d.ts +8 -0
  94. package/lib/currencies/BigNumberToLocaleString.d.ts.map +1 -0
  95. package/lib/currencies/BigNumberToLocaleString.js +65 -0
  96. package/lib/currencies/BigNumberToLocaleString.js.map +1 -0
  97. package/lib/currencies/BigNumberToLocaleString.test.d.ts +2 -0
  98. package/lib/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
  99. package/lib/currencies/BigNumberToLocaleString.test.js +108 -0
  100. package/lib/currencies/BigNumberToLocaleString.test.js.map +1 -0
  101. package/lib/currencies/CurrencyURIScheme.d.ts +13 -0
  102. package/lib/currencies/CurrencyURIScheme.d.ts.map +1 -0
  103. package/lib/currencies/CurrencyURIScheme.js +124 -0
  104. package/lib/currencies/CurrencyURIScheme.js.map +1 -0
  105. package/lib/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
  106. package/lib/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
  107. package/lib/currencies/chopCurrencyUnitDecimals.js +29 -0
  108. package/lib/currencies/chopCurrencyUnitDecimals.js.map +1 -0
  109. package/lib/currencies/formatCurrencyUnit.d.ts +33 -0
  110. package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -0
  111. package/lib/currencies/formatCurrencyUnit.js +126 -0
  112. package/lib/currencies/formatCurrencyUnit.js.map +1 -0
  113. package/lib/currencies/formatShort.d.ts +8 -0
  114. package/lib/currencies/formatShort.d.ts.map +1 -0
  115. package/lib/currencies/formatShort.js +27 -0
  116. package/lib/currencies/formatShort.js.map +1 -0
  117. package/lib/currencies/index.d.ts +13 -0
  118. package/lib/currencies/index.d.ts.map +1 -0
  119. package/lib/currencies/index.js +65 -0
  120. package/lib/currencies/index.js.map +1 -0
  121. package/lib/currencies/localeUtility.d.ts +8 -0
  122. package/lib/currencies/localeUtility.d.ts.map +1 -0
  123. package/lib/currencies/localeUtility.js +49 -0
  124. package/lib/currencies/localeUtility.js.map +1 -0
  125. package/lib/currencies/parseCurrencyUnit.d.ts +4 -0
  126. package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -0
  127. package/lib/currencies/parseCurrencyUnit.js +18 -0
  128. package/lib/currencies/parseCurrencyUnit.js.map +1 -0
  129. package/lib/currencies/sanitizeValueString.d.ts +6 -0
  130. package/lib/currencies/sanitizeValueString.d.ts.map +1 -0
  131. package/lib/currencies/sanitizeValueString.js +56 -0
  132. package/lib/currencies/sanitizeValueString.js.map +1 -0
  133. package/lib/currencies/support.d.ts +8 -0
  134. package/lib/currencies/support.d.ts.map +1 -0
  135. package/lib/currencies/support.js +101 -0
  136. package/lib/currencies/support.js.map +1 -0
  137. package/lib/currencies/valueFromUnit.d.ts +9 -0
  138. package/lib/currencies/valueFromUnit.d.ts.map +1 -0
  139. package/lib/currencies/valueFromUnit.js +14 -0
  140. package/lib/currencies/valueFromUnit.js.map +1 -0
  141. package/lib/derivation.d.ts +232 -0
  142. package/lib/derivation.d.ts.map +1 -0
  143. package/lib/derivation.js +501 -0
  144. package/lib/derivation.js.map +1 -0
  145. package/lib/env.d.ts +30 -0
  146. package/lib/env.d.ts.map +1 -0
  147. package/lib/env.js +773 -0
  148. package/lib/env.js.map +1 -0
  149. package/lib/errors.d.ts +7 -0
  150. package/lib/errors.d.ts.map +1 -0
  151. package/lib/errors.js +7 -0
  152. package/lib/errors.js.map +1 -0
  153. package/lib/errors.test.d.ts +2 -0
  154. package/lib/errors.test.d.ts.map +1 -0
  155. package/lib/errors.test.js +20 -0
  156. package/lib/errors.test.js.map +1 -0
  157. package/lib/mocks/account.d.ts +25 -0
  158. package/lib/mocks/account.d.ts.map +1 -0
  159. package/lib/mocks/account.js +368 -0
  160. package/lib/mocks/account.js.map +1 -0
  161. package/lib/mocks/fixtures/nfts.d.ts +27 -0
  162. package/lib/mocks/fixtures/nfts.d.ts.map +1 -0
  163. package/lib/mocks/fixtures/nfts.js +398 -0
  164. package/lib/mocks/fixtures/nfts.js.map +1 -0
  165. package/lib/mocks/fixtures/nfts.test.d.ts +2 -0
  166. package/lib/mocks/fixtures/nfts.test.d.ts.map +1 -0
  167. package/lib/mocks/fixtures/nfts.test.js +20 -0
  168. package/lib/mocks/fixtures/nfts.test.js.map +1 -0
  169. package/lib/mocks/helpers.d.ts +15 -0
  170. package/lib/mocks/helpers.d.ts.map +1 -0
  171. package/lib/mocks/helpers.js +32 -0
  172. package/lib/mocks/helpers.js.map +1 -0
  173. package/lib/network.d.ts +5 -0
  174. package/lib/network.d.ts.map +1 -0
  175. package/lib/network.js +125 -0
  176. package/lib/network.js.map +1 -0
  177. package/lib/nft/nftId.d.ts +8 -0
  178. package/lib/nft/nftId.d.ts.map +1 -0
  179. package/lib/nft/nftId.js +34 -0
  180. package/lib/nft/nftId.js.map +1 -0
  181. package/lib/operation.d.ts +24 -0
  182. package/lib/operation.d.ts.map +1 -0
  183. package/lib/operation.js +183 -0
  184. package/lib/operation.js.map +1 -0
  185. package/lib/promise.d.ts +21 -0
  186. package/lib/promise.d.ts.map +1 -0
  187. package/lib/promise.js +187 -0
  188. package/lib/promise.js.map +1 -0
  189. package/lib/promise.test.d.ts +2 -0
  190. package/lib/promise.test.d.ts.map +1 -0
  191. package/lib/promise.test.js +72 -0
  192. package/lib/promise.test.js.map +1 -0
  193. package/lib/rangeDates.d.ts +29 -0
  194. package/lib/rangeDates.d.ts.map +1 -0
  195. package/lib/rangeDates.js +94 -0
  196. package/lib/rangeDates.js.map +1 -0
  197. package/lib/rangeDates.test.d.ts +2 -0
  198. package/lib/rangeDates.test.d.ts.map +1 -0
  199. package/lib/rangeDates.test.js +51 -0
  200. package/lib/rangeDates.test.js.map +1 -0
  201. package/lib/test-helpers/staticTime.d.ts +2 -0
  202. package/lib/test-helpers/staticTime.d.ts.map +1 -0
  203. package/lib/test-helpers/staticTime.js +10 -0
  204. package/lib/test-helpers/staticTime.js.map +1 -0
  205. package/lib/transaction/common.d.ts +26 -0
  206. package/lib/transaction/common.d.ts.map +1 -0
  207. package/lib/transaction/common.js +123 -0
  208. package/lib/transaction/common.js.map +1 -0
  209. package/lib-es/account/accountId.d.ts +16 -0
  210. package/lib-es/account/accountId.d.ts.map +1 -0
  211. package/lib-es/account/accountId.js +74 -0
  212. package/lib-es/account/accountId.js.map +1 -0
  213. package/lib-es/account/accountName.d.ts +14 -0
  214. package/lib-es/account/accountName.d.ts.map +1 -0
  215. package/lib-es/account/accountName.js +12 -0
  216. package/lib-es/account/accountName.js.map +1 -0
  217. package/lib-es/account/addAccounts.d.ts +35 -0
  218. package/lib-es/account/addAccounts.d.ts.map +1 -0
  219. package/lib-es/account/addAccounts.js +200 -0
  220. package/lib-es/account/addAccounts.js.map +1 -0
  221. package/lib-es/account/balanceHistoryCache.d.ts +25 -0
  222. package/lib-es/account/balanceHistoryCache.d.ts.map +1 -0
  223. package/lib-es/account/balanceHistoryCache.js +109 -0
  224. package/lib-es/account/balanceHistoryCache.js.map +1 -0
  225. package/lib-es/account/groupOperations.d.ts +17 -0
  226. package/lib-es/account/groupOperations.d.ts.map +1 -0
  227. package/lib-es/account/groupOperations.js +122 -0
  228. package/lib-es/account/groupOperations.js.map +1 -0
  229. package/lib-es/account/helpers.d.ts +44 -0
  230. package/lib-es/account/helpers.d.ts.map +1 -0
  231. package/lib-es/account/helpers.js +303 -0
  232. package/lib-es/account/helpers.js.map +1 -0
  233. package/lib-es/account/helpers.test.d.ts +2 -0
  234. package/lib-es/account/helpers.test.d.ts.map +1 -0
  235. package/lib-es/account/helpers.test.js +361 -0
  236. package/lib-es/account/helpers.test.js.map +1 -0
  237. package/lib-es/account/index.d.ts +11 -0
  238. package/lib-es/account/index.d.ts.map +1 -0
  239. package/lib-es/account/index.js +11 -0
  240. package/lib-es/account/index.js.map +1 -0
  241. package/lib-es/account/ordering.d.ts +10 -0
  242. package/lib-es/account/ordering.d.ts.map +1 -0
  243. package/lib-es/account/ordering.js +103 -0
  244. package/lib-es/account/ordering.js.map +1 -0
  245. package/lib-es/account/pending.d.ts +33 -0
  246. package/lib-es/account/pending.d.ts.map +1 -0
  247. package/lib-es/account/pending.js +59 -0
  248. package/lib-es/account/pending.js.map +1 -0
  249. package/lib-es/account/serialization.d.ts +6 -0
  250. package/lib-es/account/serialization.d.ts.map +1 -0
  251. package/lib-es/account/serialization.js +112 -0
  252. package/lib-es/account/serialization.js.map +1 -0
  253. package/lib-es/account/support.d.ts +9 -0
  254. package/lib-es/account/support.d.ts.map +1 -0
  255. package/lib-es/account/support.js +64 -0
  256. package/lib-es/account/support.js.map +1 -0
  257. package/lib-es/account.test.d.ts +2 -0
  258. package/lib-es/account.test.d.ts.map +1 -0
  259. package/lib-es/account.test.js +252 -0
  260. package/lib-es/account.test.js.map +1 -0
  261. package/lib-es/bot/bot-test-context.d.ts +3 -0
  262. package/lib-es/bot/bot-test-context.d.ts.map +1 -0
  263. package/lib-es/bot/bot-test-context.js +21 -0
  264. package/lib-es/bot/bot-test-context.js.map +1 -0
  265. package/lib-es/bot/bot-test-context.test.d.ts +2 -0
  266. package/lib-es/bot/bot-test-context.test.d.ts.map +1 -0
  267. package/lib-es/bot/bot-test-context.test.js +39 -0
  268. package/lib-es/bot/bot-test-context.test.js.map +1 -0
  269. package/lib-es/bot/formatters.d.ts +2 -0
  270. package/lib-es/bot/formatters.d.ts.map +1 -0
  271. package/lib-es/bot/formatters.js +27 -0
  272. package/lib-es/bot/formatters.js.map +1 -0
  273. package/lib-es/bot/specs.d.ts +50 -0
  274. package/lib-es/bot/specs.d.ts.map +1 -0
  275. package/lib-es/bot/specs.js +193 -0
  276. package/lib-es/bot/specs.js.map +1 -0
  277. package/lib-es/bot/types.d.ts +178 -0
  278. package/lib-es/bot/types.d.ts.map +1 -0
  279. package/lib-es/bot/types.js +2 -0
  280. package/lib-es/bot/types.js.map +1 -0
  281. package/lib-es/bridge/getAddressWrapper.d.ts +6 -0
  282. package/lib-es/bridge/getAddressWrapper.d.ts.map +1 -0
  283. package/lib-es/bridge/getAddressWrapper.js +25 -0
  284. package/lib-es/bridge/getAddressWrapper.js.map +1 -0
  285. package/lib-es/bridge/jsHelpers.d.ts +63 -0
  286. package/lib-es/bridge/jsHelpers.d.ts.map +1 -0
  287. package/lib-es/bridge/jsHelpers.js +562 -0
  288. package/lib-es/bridge/jsHelpers.js.map +1 -0
  289. package/lib-es/cache.d.ts +10 -0
  290. package/lib-es/cache.d.ts.map +1 -0
  291. package/lib-es/cache.js +93 -0
  292. package/lib-es/cache.js.map +1 -0
  293. package/lib-es/cross.d.ts +42 -0
  294. package/lib-es/cross.d.ts.map +1 -0
  295. package/lib-es/cross.js +244 -0
  296. package/lib-es/cross.js.map +1 -0
  297. package/lib-es/cross.test.d.ts +2 -0
  298. package/lib-es/cross.test.d.ts.map +1 -0
  299. package/lib-es/cross.test.js +97 -0
  300. package/lib-es/cross.test.js.map +1 -0
  301. package/lib-es/currencies/BigNumberToLocaleString.d.ts +8 -0
  302. package/lib-es/currencies/BigNumberToLocaleString.d.ts.map +1 -0
  303. package/lib-es/currencies/BigNumberToLocaleString.js +61 -0
  304. package/lib-es/currencies/BigNumberToLocaleString.js.map +1 -0
  305. package/lib-es/currencies/BigNumberToLocaleString.test.d.ts +2 -0
  306. package/lib-es/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
  307. package/lib-es/currencies/BigNumberToLocaleString.test.js +106 -0
  308. package/lib-es/currencies/BigNumberToLocaleString.test.js.map +1 -0
  309. package/lib-es/currencies/CurrencyURIScheme.d.ts +13 -0
  310. package/lib-es/currencies/CurrencyURIScheme.d.ts.map +1 -0
  311. package/lib-es/currencies/CurrencyURIScheme.js +116 -0
  312. package/lib-es/currencies/CurrencyURIScheme.js.map +1 -0
  313. package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
  314. package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
  315. package/lib-es/currencies/chopCurrencyUnitDecimals.js +25 -0
  316. package/lib-es/currencies/chopCurrencyUnitDecimals.js.map +1 -0
  317. package/lib-es/currencies/formatCurrencyUnit.d.ts +33 -0
  318. package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -0
  319. package/lib-es/currencies/formatCurrencyUnit.js +121 -0
  320. package/lib-es/currencies/formatCurrencyUnit.js.map +1 -0
  321. package/lib-es/currencies/formatShort.d.ts +8 -0
  322. package/lib-es/currencies/formatShort.d.ts.map +1 -0
  323. package/lib-es/currencies/formatShort.js +20 -0
  324. package/lib-es/currencies/formatShort.js.map +1 -0
  325. package/lib-es/currencies/index.d.ts +13 -0
  326. package/lib-es/currencies/index.d.ts.map +1 -0
  327. package/lib-es/currencies/index.js +16 -0
  328. package/lib-es/currencies/index.js.map +1 -0
  329. package/lib-es/currencies/localeUtility.d.ts +8 -0
  330. package/lib-es/currencies/localeUtility.d.ts.map +1 -0
  331. package/lib-es/currencies/localeUtility.js +43 -0
  332. package/lib-es/currencies/localeUtility.js.map +1 -0
  333. package/lib-es/currencies/parseCurrencyUnit.d.ts +4 -0
  334. package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -0
  335. package/lib-es/currencies/parseCurrencyUnit.js +14 -0
  336. package/lib-es/currencies/parseCurrencyUnit.js.map +1 -0
  337. package/lib-es/currencies/sanitizeValueString.d.ts +6 -0
  338. package/lib-es/currencies/sanitizeValueString.d.ts.map +1 -0
  339. package/lib-es/currencies/sanitizeValueString.js +52 -0
  340. package/lib-es/currencies/sanitizeValueString.js.map +1 -0
  341. package/lib-es/currencies/support.d.ts +8 -0
  342. package/lib-es/currencies/support.d.ts.map +1 -0
  343. package/lib-es/currencies/support.js +92 -0
  344. package/lib-es/currencies/support.js.map +1 -0
  345. package/lib-es/currencies/valueFromUnit.d.ts +9 -0
  346. package/lib-es/currencies/valueFromUnit.d.ts.map +1 -0
  347. package/lib-es/currencies/valueFromUnit.js +10 -0
  348. package/lib-es/currencies/valueFromUnit.js.map +1 -0
  349. package/lib-es/derivation.d.ts +232 -0
  350. package/lib-es/derivation.d.ts.map +1 -0
  351. package/lib-es/derivation.js +473 -0
  352. package/lib-es/derivation.js.map +1 -0
  353. package/lib-es/env.d.ts +30 -0
  354. package/lib-es/env.d.ts.map +1 -0
  355. package/lib-es/env.js +758 -0
  356. package/lib-es/env.js.map +1 -0
  357. package/lib-es/errors.d.ts +7 -0
  358. package/lib-es/errors.d.ts.map +1 -0
  359. package/lib-es/errors.js +4 -0
  360. package/lib-es/errors.js.map +1 -0
  361. package/lib-es/errors.test.d.ts +2 -0
  362. package/lib-es/errors.test.d.ts.map +1 -0
  363. package/lib-es/errors.test.js +18 -0
  364. package/lib-es/errors.test.js.map +1 -0
  365. package/lib-es/mocks/account.d.ts +25 -0
  366. package/lib-es/mocks/account.d.ts.map +1 -0
  367. package/lib-es/mocks/account.js +358 -0
  368. package/lib-es/mocks/account.js.map +1 -0
  369. package/lib-es/mocks/fixtures/nfts.d.ts +27 -0
  370. package/lib-es/mocks/fixtures/nfts.d.ts.map +1 -0
  371. package/lib-es/mocks/fixtures/nfts.js +390 -0
  372. package/lib-es/mocks/fixtures/nfts.js.map +1 -0
  373. package/lib-es/mocks/fixtures/nfts.test.d.ts +2 -0
  374. package/lib-es/mocks/fixtures/nfts.test.d.ts.map +1 -0
  375. package/lib-es/mocks/fixtures/nfts.test.js +18 -0
  376. package/lib-es/mocks/fixtures/nfts.test.js.map +1 -0
  377. package/lib-es/mocks/helpers.d.ts +15 -0
  378. package/lib-es/mocks/helpers.d.ts.map +1 -0
  379. package/lib-es/mocks/helpers.js +26 -0
  380. package/lib-es/mocks/helpers.js.map +1 -0
  381. package/lib-es/network.d.ts +5 -0
  382. package/lib-es/network.d.ts.map +1 -0
  383. package/lib-es/network.js +118 -0
  384. package/lib-es/network.js.map +1 -0
  385. package/lib-es/nft/nftId.d.ts +8 -0
  386. package/lib-es/nft/nftId.d.ts.map +1 -0
  387. package/lib-es/nft/nftId.js +29 -0
  388. package/lib-es/nft/nftId.js.map +1 -0
  389. package/lib-es/operation.d.ts +24 -0
  390. package/lib-es/operation.d.ts.map +1 -0
  391. package/lib-es/operation.js +168 -0
  392. package/lib-es/operation.js.map +1 -0
  393. package/lib-es/promise.d.ts +21 -0
  394. package/lib-es/promise.d.ts.map +1 -0
  395. package/lib-es/promise.js +179 -0
  396. package/lib-es/promise.js.map +1 -0
  397. package/lib-es/promise.test.d.ts +2 -0
  398. package/lib-es/promise.test.d.ts.map +1 -0
  399. package/lib-es/promise.test.js +70 -0
  400. package/lib-es/promise.test.js.map +1 -0
  401. package/lib-es/rangeDates.d.ts +29 -0
  402. package/lib-es/rangeDates.d.ts.map +1 -0
  403. package/lib-es/rangeDates.js +84 -0
  404. package/lib-es/rangeDates.js.map +1 -0
  405. package/lib-es/rangeDates.test.d.ts +2 -0
  406. package/lib-es/rangeDates.test.d.ts.map +1 -0
  407. package/lib-es/rangeDates.test.js +49 -0
  408. package/lib-es/rangeDates.test.js.map +1 -0
  409. package/lib-es/test-helpers/staticTime.d.ts +2 -0
  410. package/lib-es/test-helpers/staticTime.d.ts.map +1 -0
  411. package/lib-es/test-helpers/staticTime.js +5 -0
  412. package/lib-es/test-helpers/staticTime.js.map +1 -0
  413. package/lib-es/transaction/common.d.ts +26 -0
  414. package/lib-es/transaction/common.d.ts.map +1 -0
  415. package/lib-es/transaction/common.js +115 -0
  416. package/lib-es/transaction/common.js.map +1 -0
  417. package/package.json +113 -0
  418. package/src/__snapshots__/account.test.ts.snap +2065 -0
  419. package/src/__snapshots__/cross.test.ts.snap +57 -0
  420. package/src/account/accountId.ts +93 -0
  421. package/src/account/accountName.ts +25 -0
  422. package/src/account/addAccounts.ts +236 -0
  423. package/src/account/balanceHistoryCache.ts +146 -0
  424. package/src/account/groupOperations.ts +164 -0
  425. package/src/account/helpers.test.ts +441 -0
  426. package/src/account/helpers.ts +380 -0
  427. package/src/account/index.ts +10 -0
  428. package/src/account/ordering.ts +109 -0
  429. package/src/account/pending.ts +66 -0
  430. package/src/account/serialization.ts +189 -0
  431. package/src/account/support.ts +96 -0
  432. package/src/account.test.ts +237 -0
  433. package/src/bot/bot-test-context.test.ts +37 -0
  434. package/src/bot/bot-test-context.ts +24 -0
  435. package/src/bot/formatters.ts +22 -0
  436. package/src/bot/specs.ts +275 -0
  437. package/src/bot/types.ts +224 -0
  438. package/src/bridge/getAddressWrapper.ts +40 -0
  439. package/src/bridge/jsHelpers.ts +645 -0
  440. package/src/cache.ts +65 -0
  441. package/src/cross.test.ts +112 -0
  442. package/src/cross.ts +366 -0
  443. package/src/currencies/BigNumberToLocaleString.test.ts +155 -0
  444. package/src/currencies/BigNumberToLocaleString.ts +80 -0
  445. package/src/currencies/CurrencyURIScheme.ts +114 -0
  446. package/src/currencies/chopCurrencyUnitDecimals.ts +34 -0
  447. package/src/currencies/formatCurrencyUnit.ts +167 -0
  448. package/src/currencies/formatShort.ts +24 -0
  449. package/src/currencies/index.ts +78 -0
  450. package/src/currencies/localeUtility.ts +50 -0
  451. package/src/currencies/parseCurrencyUnit.ts +16 -0
  452. package/src/currencies/sanitizeValueString.ts +58 -0
  453. package/src/currencies/support.ts +107 -0
  454. package/src/currencies/valueFromUnit.ts +10 -0
  455. package/src/derivation.ts +595 -0
  456. package/src/env.ts +780 -0
  457. package/src/errors.test.ts +21 -0
  458. package/src/errors.ts +9 -0
  459. package/src/mocks/account.ts +476 -0
  460. package/src/mocks/fixtures/nfts.test.ts +25 -0
  461. package/src/mocks/fixtures/nfts.ts +432 -0
  462. package/src/mocks/helpers.ts +38 -0
  463. package/src/network.ts +135 -0
  464. package/src/nft/nftId.ts +26 -0
  465. package/src/operation.ts +212 -0
  466. package/src/promise.test.ts +20 -0
  467. package/src/promise.ts +101 -0
  468. package/src/rangeDates.test.ts +66 -0
  469. package/src/rangeDates.ts +96 -0
  470. package/src/test-helpers/staticTime.ts +4 -0
  471. package/src/transaction/common.ts +157 -0
@@ -0,0 +1,63 @@
1
+ import { Observable } from "rxjs";
2
+ import Transport from "@ledgerhq/hw-transport";
3
+ import { DerivationMode } from "../derivation";
4
+ import { Resolver } from "./getAddressWrapper";
5
+ import type { Result } from "../derivation";
6
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
7
+ import type { Account, AccountBridge, CurrencyBridge, Operation, ProtoNFT, SyncConfig } from "@ledgerhq/types-live";
8
+ type IterateResult = ({ transport, index, derivationsCache, derivationScheme, derivationMode, currency, }: {
9
+ transport: Transport;
10
+ index: number;
11
+ derivationsCache: Record<string, Result>;
12
+ derivationScheme: string;
13
+ derivationMode: DerivationMode;
14
+ currency: CryptoCurrency;
15
+ }) => Promise<Result | null>;
16
+ export type IterateResultBuilder = ({ result, // derivation on the "root" of the derivation
17
+ derivationMode, // identify the current derivation scheme
18
+ derivationScheme, }: {
19
+ result: Result;
20
+ derivationMode: DerivationMode;
21
+ derivationScheme: string;
22
+ }) => Promise<IterateResult>;
23
+ export type AccountShapeInfo = {
24
+ currency: CryptoCurrency;
25
+ address: string;
26
+ index: number;
27
+ initialAccount?: Account;
28
+ derivationPath: string;
29
+ derivationMode: DerivationMode;
30
+ transport?: Transport;
31
+ rest?: any;
32
+ };
33
+ export type GetAccountShape = (arg0: AccountShapeInfo, arg1: SyncConfig) => Promise<Partial<Account>>;
34
+ export declare const sameOp: (a: Operation, b: Operation) => boolean;
35
+ export declare function mergeOps(// existing operations. sorted (newer to older). deduped.
36
+ existing: Operation[], // new fetched operations. not sorted. not deduped. time is allowed to overlap inside existing.
37
+ newFetched: Operation[]): Operation[];
38
+ export declare const mergeNfts: (oldNfts: ProtoNFT[], newNfts: ProtoNFT[]) => ProtoNFT[];
39
+ export declare const makeSync: ({ getAccountShape, postSync, shouldMergeOps, }: {
40
+ getAccountShape: GetAccountShape;
41
+ postSync?: ((initial: Account, synced: Account) => Account) | undefined;
42
+ shouldMergeOps?: boolean | undefined;
43
+ }) => AccountBridge<any>["sync"];
44
+ export type DeviceCommunication = (deviceId: string) => <T>(job: (transport: Transport) => Observable<T>) => Observable<T>;
45
+ export declare const makeScanAccounts: ({ getAccountShape, deviceCommunication, buildIterateResult, getAddressFn, }: {
46
+ getAccountShape: GetAccountShape;
47
+ deviceCommunication: DeviceCommunication;
48
+ buildIterateResult?: IterateResultBuilder | undefined;
49
+ getAddressFn: Resolver;
50
+ }) => CurrencyBridge["scanAccounts"];
51
+ export declare function makeAccountBridgeReceive(getAddressFn: Resolver, deviceCommunication: DeviceCommunication, { injectGetAddressParams, }?: {
52
+ injectGetAddressParams?: (account: Account) => any;
53
+ }): (account: Account, option: {
54
+ verify?: boolean;
55
+ deviceId: string;
56
+ subAccountId?: string;
57
+ freshAddressIndex?: number;
58
+ }) => Observable<{
59
+ address: string;
60
+ path: string;
61
+ }>;
62
+ export {};
63
+ //# sourceMappingURL=jsHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsHelpers.d.ts","sourceRoot":"","sources":["../../src/bridge/jsHelpers.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,574 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ var __values = (this && this.__values) || function(o) {
61
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
62
+ if (m) return m.call(o);
63
+ if (o && typeof o.length === "number") return {
64
+ next: function () {
65
+ if (o && i >= o.length) o = void 0;
66
+ return { value: o && o[i++], done: !o };
67
+ }
68
+ };
69
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
70
+ };
71
+ var __importDefault = (this && this.__importDefault) || function (mod) {
72
+ return (mod && mod.__esModule) ? mod : { "default": mod };
73
+ };
74
+ exports.__esModule = true;
75
+ exports.makeAccountBridgeReceive = exports.makeScanAccounts = exports.makeSync = exports.mergeNfts = exports.mergeOps = exports.sameOp = void 0;
76
+ var isEqual_1 = __importDefault(require("lodash/isEqual"));
77
+ var bignumber_js_1 = require("bignumber.js");
78
+ var rxjs_1 = require("rxjs");
79
+ var logs_1 = require("@ledgerhq/logs");
80
+ var errors_1 = require("@ledgerhq/errors");
81
+ var derivation_1 = require("../derivation");
82
+ var account_1 = require("../account");
83
+ var errors_2 = require("../errors");
84
+ var getAddressWrapper_1 = __importDefault(require("./getAddressWrapper"));
85
+ // compare that two dates are roughly the same date in order to update the case it would have drastically changed
86
+ var sameDate = function (a, b) {
87
+ return Math.abs(a.getTime() - b.getTime()) < 1000 * 60 * 30;
88
+ };
89
+ // an operation is relatively immutable, however we saw that sometimes it can temporarily change due to reorg,..
90
+ var sameOp = function (a, b) {
91
+ var _a, _b;
92
+ return a === b ||
93
+ (a.id === b.id && // hash, accountId, type are in id
94
+ (a.fee ? a.fee.isEqualTo(b.fee) : a.fee === b.fee) &&
95
+ (a.value ? a.value.isEqualTo(b.value) : a.value === b.value) &&
96
+ ((_a = a.nftOperations) === null || _a === void 0 ? void 0 : _a.length) === ((_b = b.nftOperations) === null || _b === void 0 ? void 0 : _b.length) &&
97
+ sameDate(a.date, b.date) &&
98
+ a.blockHeight === b.blockHeight &&
99
+ (0, isEqual_1["default"])(a.senders, b.senders) &&
100
+ (0, isEqual_1["default"])(a.recipients, b.recipients));
101
+ };
102
+ exports.sameOp = sameOp;
103
+ // efficiently prepend newFetched operations to existing operations
104
+ function mergeOps(// existing operations. sorted (newer to older). deduped.
105
+ existing, // new fetched operations. not sorted. not deduped. time is allowed to overlap inside existing.
106
+ newFetched) {
107
+ var e_1, _a, e_2, _b;
108
+ // there is new fetched
109
+ if (newFetched.length === 0)
110
+ return existing;
111
+ // efficient lookup map of id.
112
+ var existingIds = {};
113
+ try {
114
+ for (var existing_1 = __values(existing), existing_1_1 = existing_1.next(); !existing_1_1.done; existing_1_1 = existing_1.next()) {
115
+ var o = existing_1_1.value;
116
+ existingIds[o.id] = o;
117
+ }
118
+ }
119
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
120
+ finally {
121
+ try {
122
+ if (existing_1_1 && !existing_1_1.done && (_a = existing_1["return"])) _a.call(existing_1);
123
+ }
124
+ finally { if (e_1) throw e_1.error; }
125
+ }
126
+ // only keep the newFetched that are not in existing. this array will be mutated
127
+ var newOps = newFetched
128
+ .filter(function (o) { return !existingIds[o.id] || !(0, exports.sameOp)(existingIds[o.id], o); })
129
+ .sort(function (a, b) { return b.date.valueOf() - a.date.valueOf(); });
130
+ // Deduplicate new ops to guarantee operations don't have dups
131
+ var newOpsIds = {};
132
+ newOps.forEach(function (op) {
133
+ newOpsIds[op.id] = op;
134
+ });
135
+ newOps = Object.values(newOpsIds);
136
+ // return existing when there is no real new operations
137
+ if (newOps.length === 0)
138
+ return existing;
139
+ // edge case, existing can be empty. return the sorted list.
140
+ if (existing.length === 0)
141
+ return newOps;
142
+ // building up merging the ops
143
+ var all = [];
144
+ try {
145
+ for (var existing_2 = __values(existing), existing_2_1 = existing_2.next(); !existing_2_1.done; existing_2_1 = existing_2.next()) {
146
+ var o = existing_2_1.value;
147
+ // prepend all the new ops that have higher date
148
+ while (newOps.length > 0 && newOps[0].date >= o.date) {
149
+ all.push(newOps.shift());
150
+ }
151
+ if (!newOpsIds[o.id]) {
152
+ all.push(o);
153
+ }
154
+ }
155
+ }
156
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
157
+ finally {
158
+ try {
159
+ if (existing_2_1 && !existing_2_1.done && (_b = existing_2["return"])) _b.call(existing_2);
160
+ }
161
+ finally { if (e_2) throw e_2.error; }
162
+ }
163
+ return all;
164
+ }
165
+ exports.mergeOps = mergeOps;
166
+ var mergeNfts = function (oldNfts, newNfts) {
167
+ // Getting a map of id => NFT
168
+ var newNftsPerId = {};
169
+ newNfts.forEach(function (n) {
170
+ newNftsPerId[n.id] = n;
171
+ });
172
+ // copying the argument to avoid mutating it
173
+ var nfts = oldNfts.slice();
174
+ for (var i = 0; i < nfts.length; i++) {
175
+ var nft = nfts[i];
176
+ // The NFTs are the same, do don't anything
177
+ if (!newNftsPerId[nft.id]) {
178
+ nfts.splice(i, 1);
179
+ i--;
180
+ }
181
+ else if (!(0, isEqual_1["default"])(nft, newNftsPerId[nft.id])) {
182
+ // Use the new NFT instead
183
+ nfts[i] = newNftsPerId[nft.id];
184
+ }
185
+ // Delete it from the newNfts to keep only the un-added ones at the end
186
+ delete newNftsPerId[nft.id];
187
+ }
188
+ // Prepending newNfts to respect nfts's newest to oldest order
189
+ return Object.values(newNftsPerId).concat(nfts);
190
+ };
191
+ exports.mergeNfts = mergeNfts;
192
+ var makeSync = function (_a) {
193
+ var getAccountShape = _a.getAccountShape, _b = _a.postSync, postSync = _b === void 0 ? function (_, a) { return a; } : _b, _c = _a.shouldMergeOps, shouldMergeOps = _c === void 0 ? true : _c;
194
+ return function (initial, syncConfig) {
195
+ return rxjs_1.Observable.create(function (o) {
196
+ function main() {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var accountId, needClear, freshAddressPath, shape_1, updater, e_3;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ accountId = (0, account_1.encodeAccountId)({
203
+ type: "js",
204
+ version: "2",
205
+ currencyId: initial.currency.id,
206
+ xpubOrAddress: initial.xpub || initial.freshAddress,
207
+ derivationMode: initial.derivationMode
208
+ });
209
+ needClear = initial.id !== accountId;
210
+ _a.label = 1;
211
+ case 1:
212
+ _a.trys.push([1, 3, , 4]);
213
+ freshAddressPath = (0, derivation_1.getSeedIdentifierDerivation)(initial.currency, initial.derivationMode);
214
+ return [4 /*yield*/, getAccountShape({
215
+ currency: initial.currency,
216
+ index: initial.index,
217
+ address: initial.freshAddress,
218
+ derivationPath: freshAddressPath,
219
+ derivationMode: initial.derivationMode,
220
+ initialAccount: needClear ? (0, account_1.clearAccount)(initial) : initial
221
+ }, syncConfig)];
222
+ case 2:
223
+ shape_1 = _a.sent();
224
+ updater = function (acc) {
225
+ var a = acc; // a is a immutable version of Account, based on acc
226
+ if (needClear) {
227
+ a = (0, account_1.clearAccount)(acc);
228
+ }
229
+ // FIXME reconsider doing mergeOps here. work is redundant for impl like eth
230
+ var operations = shouldMergeOps
231
+ ? mergeOps(a.operations, shape_1.operations || [])
232
+ : shape_1.operations || [];
233
+ a = postSync(a, __assign(__assign(__assign(__assign({}, a), { id: accountId, spendableBalance: shape_1.balance || a.balance, operationsCount: shape_1.operationsCount || operations.length, lastSyncDate: new Date(), creationDate: operations.length > 0
234
+ ? operations[operations.length - 1].date
235
+ : new Date() }), shape_1), { operations: operations, pendingOperations: a.pendingOperations.filter(function (op) {
236
+ return (0, account_1.shouldRetainPendingOperation)(a, op);
237
+ }) }));
238
+ a = (0, account_1.recalculateAccountBalanceHistories)(a, acc);
239
+ if (!a.used) {
240
+ a.used = !(0, account_1.isAccountEmpty)(a);
241
+ }
242
+ return a;
243
+ };
244
+ o.next(updater);
245
+ o.complete();
246
+ return [3 /*break*/, 4];
247
+ case 3:
248
+ e_3 = _a.sent();
249
+ o.error(e_3);
250
+ return [3 /*break*/, 4];
251
+ case 4: return [2 /*return*/];
252
+ }
253
+ });
254
+ });
255
+ }
256
+ main();
257
+ });
258
+ };
259
+ };
260
+ exports.makeSync = makeSync;
261
+ var defaultIterateResultBuilder = function (getAddressFn) { return function () {
262
+ return Promise.resolve(function (_a) {
263
+ var transport = _a.transport, index = _a.index, derivationsCache = _a.derivationsCache, derivationScheme = _a.derivationScheme, derivationMode = _a.derivationMode, currency = _a.currency;
264
+ return __awaiter(void 0, void 0, void 0, function () {
265
+ var freshAddressPath, res;
266
+ return __generator(this, function (_b) {
267
+ switch (_b.label) {
268
+ case 0:
269
+ freshAddressPath = (0, derivation_1.runDerivationScheme)(derivationScheme, currency, {
270
+ account: index
271
+ });
272
+ res = derivationsCache[freshAddressPath];
273
+ if (!!res) return [3 /*break*/, 2];
274
+ return [4 /*yield*/, (0, getAddressWrapper_1["default"])(getAddressFn)(transport, {
275
+ currency: currency,
276
+ path: freshAddressPath,
277
+ derivationMode: derivationMode
278
+ })];
279
+ case 1:
280
+ res = _b.sent();
281
+ derivationsCache[freshAddressPath] = res;
282
+ _b.label = 2;
283
+ case 2: return [2 /*return*/, res];
284
+ }
285
+ });
286
+ });
287
+ });
288
+ }; };
289
+ var makeScanAccounts = function (_a) {
290
+ var getAccountShape = _a.getAccountShape, deviceCommunication = _a.deviceCommunication, buildIterateResult = _a.buildIterateResult, getAddressFn = _a.getAddressFn;
291
+ return function (_a) {
292
+ var currency = _a.currency, deviceId = _a.deviceId, syncConfig = _a.syncConfig;
293
+ return deviceCommunication(deviceId)(function (transport) {
294
+ return rxjs_1.Observable.create(function (o) {
295
+ var finished = false;
296
+ var unsubscribe = function () {
297
+ finished = true;
298
+ };
299
+ var derivationsCache = {};
300
+ function stepAccount(index, res, derivationMode, seedIdentifier, transport) {
301
+ return __awaiter(this, void 0, void 0, function () {
302
+ var address, freshAddressPath, rest, accountShape, freshAddress, operations, operationsCount, creationDate, balance, spendableBalance, initialAccount, account, showNewAccount;
303
+ return __generator(this, function (_a) {
304
+ switch (_a.label) {
305
+ case 0:
306
+ if (finished)
307
+ return [2 /*return*/];
308
+ address = res.address, freshAddressPath = res.path, rest = __rest(res, ["address", "path"]);
309
+ return [4 /*yield*/, getAccountShape({
310
+ transport: transport,
311
+ currency: currency,
312
+ index: index,
313
+ address: address,
314
+ derivationPath: freshAddressPath,
315
+ derivationMode: derivationMode,
316
+ rest: rest
317
+ }, syncConfig)];
318
+ case 1:
319
+ accountShape = _a.sent();
320
+ if (finished)
321
+ return [2 /*return*/];
322
+ freshAddress = address;
323
+ operations = accountShape.operations || [];
324
+ operationsCount = accountShape.operationsCount || operations.length;
325
+ creationDate = operations.length > 0
326
+ ? operations[operations.length - 1].date
327
+ : new Date();
328
+ balance = accountShape.balance || new bignumber_js_1.BigNumber(0);
329
+ spendableBalance = accountShape.spendableBalance || new bignumber_js_1.BigNumber(0);
330
+ if (!accountShape.id)
331
+ throw new Error("account ID must be provided");
332
+ if (balance.isNaN())
333
+ throw new Error("invalid balance NaN");
334
+ initialAccount = {
335
+ type: "Account",
336
+ id: accountShape.id,
337
+ seedIdentifier: seedIdentifier,
338
+ freshAddress: freshAddress,
339
+ freshAddressPath: freshAddressPath,
340
+ freshAddresses: [
341
+ {
342
+ address: freshAddress,
343
+ derivationPath: freshAddressPath
344
+ },
345
+ ],
346
+ derivationMode: derivationMode,
347
+ name: "",
348
+ starred: false,
349
+ used: false,
350
+ index: index,
351
+ currency: currency,
352
+ operationsCount: operationsCount,
353
+ operations: [],
354
+ swapHistory: [],
355
+ pendingOperations: [],
356
+ unit: currency.units[0],
357
+ lastSyncDate: new Date(),
358
+ creationDate: creationDate,
359
+ // overrides
360
+ balance: balance,
361
+ spendableBalance: spendableBalance,
362
+ blockHeight: 0,
363
+ balanceHistoryCache: account_1.emptyHistoryCache
364
+ };
365
+ account = __assign(__assign({}, initialAccount), accountShape);
366
+ if (account.balanceHistoryCache === account_1.emptyHistoryCache) {
367
+ account.balanceHistoryCache =
368
+ (0, account_1.generateHistoryFromOperations)(account);
369
+ }
370
+ if (!account.used) {
371
+ account.used = !(0, account_1.isAccountEmpty)(account);
372
+ }
373
+ // Bitcoin needs to compute the freshAddressPath itself,
374
+ // so we update it afterwards
375
+ if (account === null || account === void 0 ? void 0 : account.freshAddressPath) {
376
+ res.address = account.freshAddress;
377
+ derivationsCache[account.freshAddressPath] = res;
378
+ }
379
+ (0, logs_1.log)("scanAccounts", "derivationsCache", res);
380
+ (0, logs_1.log)("scanAccounts", "scanning ".concat(currency.id, " at ").concat(freshAddressPath, ": ").concat(res.address, " resulted of ").concat(account
381
+ ? "Account with ".concat(account.operations.length, " txs")
382
+ : "no account"));
383
+ if (!account)
384
+ return [2 /*return*/];
385
+ account.name = !account.used
386
+ ? (0, account_1.getNewAccountPlaceholderName)({
387
+ currency: currency,
388
+ index: index,
389
+ derivationMode: derivationMode
390
+ })
391
+ : (0, account_1.getAccountPlaceholderName)({
392
+ currency: currency,
393
+ index: index,
394
+ derivationMode: derivationMode
395
+ });
396
+ showNewAccount = (0, account_1.shouldShowNewAccount)(currency, derivationMode);
397
+ if (account.used || showNewAccount) {
398
+ (0, logs_1.log)("debug", "Emit 'discovered' event for a new account found. AccountUsed: ".concat(account.used, " - showNewAccount: ").concat(showNewAccount));
399
+ o.next({
400
+ type: "discovered",
401
+ account: account
402
+ });
403
+ }
404
+ return [2 /*return*/, account];
405
+ }
406
+ });
407
+ });
408
+ }
409
+ if (buildIterateResult === undefined) {
410
+ buildIterateResult = defaultIterateResultBuilder(getAddressFn);
411
+ }
412
+ function main() {
413
+ return __awaiter(this, void 0, void 0, function () {
414
+ var derivationModes, derivationModes_1, derivationModes_1_1, derivationMode, path, result, e_4, seedIdentifier, emptyCount, mandatoryEmptyAccountSkip, derivationScheme, stopAt, startsAt, iterateResult, index, res, account, e_5_1, e_6;
415
+ var e_5, _a;
416
+ return __generator(this, function (_b) {
417
+ switch (_b.label) {
418
+ case 0:
419
+ _b.trys.push([0, 17, , 18]);
420
+ derivationModes = (0, derivation_1.getDerivationModesForCurrency)(currency);
421
+ _b.label = 1;
422
+ case 1:
423
+ _b.trys.push([1, 14, 15, 16]);
424
+ derivationModes_1 = __values(derivationModes), derivationModes_1_1 = derivationModes_1.next();
425
+ _b.label = 2;
426
+ case 2:
427
+ if (!!derivationModes_1_1.done) return [3 /*break*/, 13];
428
+ derivationMode = derivationModes_1_1.value;
429
+ if (finished)
430
+ return [3 /*break*/, 13];
431
+ path = (0, derivation_1.getSeedIdentifierDerivation)(currency, derivationMode);
432
+ (0, logs_1.log)("scanAccounts", "scanning ".concat(currency.id, " on derivationMode=").concat(derivationMode));
433
+ result = derivationsCache[path];
434
+ if (!!result) return [3 /*break*/, 6];
435
+ _b.label = 3;
436
+ case 3:
437
+ _b.trys.push([3, 5, , 6]);
438
+ return [4 /*yield*/, getAddressFn(transport, {
439
+ currency: currency,
440
+ path: path,
441
+ derivationMode: derivationMode
442
+ })];
443
+ case 4:
444
+ result = _b.sent();
445
+ derivationsCache[path] = result;
446
+ return [3 /*break*/, 6];
447
+ case 5:
448
+ e_4 = _b.sent();
449
+ if (e_4 instanceof errors_2.UnsupportedDerivation) {
450
+ (0, logs_1.log)("scanAccounts", "ignore derivationMode=" + derivationMode);
451
+ return [3 /*break*/, 12];
452
+ }
453
+ throw e_4;
454
+ case 6:
455
+ if (!result)
456
+ return [3 /*break*/, 12];
457
+ seedIdentifier = result.publicKey;
458
+ emptyCount = 0;
459
+ mandatoryEmptyAccountSkip = (0, derivation_1.getMandatoryEmptyAccountSkip)(derivationMode);
460
+ derivationScheme = (0, derivation_1.getDerivationScheme)({
461
+ derivationMode: derivationMode,
462
+ currency: currency
463
+ });
464
+ stopAt = (0, derivation_1.isIterableDerivationMode)(derivationMode)
465
+ ? 255
466
+ : 1;
467
+ startsAt = (0, derivation_1.getDerivationModeStartsAt)(derivationMode);
468
+ (0, logs_1.log)("debug", "start scanning account process. MandatoryEmptyAccountSkip ".concat(mandatoryEmptyAccountSkip, " / StartsAt: ").concat(startsAt, " - StopAt: ").concat(stopAt));
469
+ return [4 /*yield*/, buildIterateResult({
470
+ result: result,
471
+ derivationMode: derivationMode,
472
+ derivationScheme: derivationScheme
473
+ })];
474
+ case 7:
475
+ iterateResult = _b.sent();
476
+ index = startsAt;
477
+ _b.label = 8;
478
+ case 8:
479
+ if (!(index < stopAt)) return [3 /*break*/, 12];
480
+ (0, logs_1.log)("debug", "start to scan a new account. Index: ".concat(index));
481
+ if (finished) {
482
+ (0, logs_1.log)("debug", "new account scanning process has been finished");
483
+ return [3 /*break*/, 12];
484
+ }
485
+ if (!(0, derivation_1.derivationModeSupportsIndex)(derivationMode, index))
486
+ return [3 /*break*/, 11];
487
+ return [4 /*yield*/, iterateResult({
488
+ transport: transport,
489
+ index: index,
490
+ derivationsCache: derivationsCache,
491
+ derivationMode: derivationMode,
492
+ derivationScheme: derivationScheme,
493
+ currency: currency
494
+ })];
495
+ case 9:
496
+ res = _b.sent();
497
+ if (!res)
498
+ return [3 /*break*/, 12];
499
+ return [4 /*yield*/, stepAccount(index, res, derivationMode, seedIdentifier, transport)];
500
+ case 10:
501
+ account = _b.sent();
502
+ if (account && !account.used) {
503
+ if (emptyCount >= mandatoryEmptyAccountSkip)
504
+ return [3 /*break*/, 12];
505
+ emptyCount++;
506
+ }
507
+ _b.label = 11;
508
+ case 11:
509
+ index++;
510
+ return [3 /*break*/, 8];
511
+ case 12:
512
+ derivationModes_1_1 = derivationModes_1.next();
513
+ return [3 /*break*/, 2];
514
+ case 13: return [3 /*break*/, 16];
515
+ case 14:
516
+ e_5_1 = _b.sent();
517
+ e_5 = { error: e_5_1 };
518
+ return [3 /*break*/, 16];
519
+ case 15:
520
+ try {
521
+ if (derivationModes_1_1 && !derivationModes_1_1.done && (_a = derivationModes_1["return"])) _a.call(derivationModes_1);
522
+ }
523
+ finally { if (e_5) throw e_5.error; }
524
+ return [7 /*endfinally*/];
525
+ case 16:
526
+ o.complete();
527
+ return [3 /*break*/, 18];
528
+ case 17:
529
+ e_6 = _b.sent();
530
+ o.error(e_6);
531
+ return [3 /*break*/, 18];
532
+ case 18: return [2 /*return*/];
533
+ }
534
+ });
535
+ });
536
+ }
537
+ main();
538
+ return unsubscribe;
539
+ });
540
+ });
541
+ };
542
+ };
543
+ exports.makeScanAccounts = makeScanAccounts;
544
+ function makeAccountBridgeReceive(getAddressFn, deviceCommunication, _a) {
545
+ var _b = _a === void 0 ? {} : _a, injectGetAddressParams = _b.injectGetAddressParams;
546
+ return function (account, _a) {
547
+ var verify = _a.verify, deviceId = _a.deviceId, freshAddressIndex = _a.freshAddressIndex;
548
+ var freshAddress;
549
+ if (freshAddressIndex !== undefined && freshAddressIndex !== null) {
550
+ freshAddress = account.freshAddresses[freshAddressIndex];
551
+ if (freshAddress === undefined) {
552
+ throw new errors_2.FreshAddressIndexInvalid();
553
+ }
554
+ }
555
+ var arg = __assign({ verify: verify, currency: account.currency, derivationMode: account.derivationMode, path: freshAddress
556
+ ? freshAddress.derivationPath
557
+ : account.freshAddressPath }, (injectGetAddressParams && injectGetAddressParams(account)));
558
+ return deviceCommunication(deviceId)(function (transport) {
559
+ return (0, rxjs_1.from)(getAddressFn(transport, arg).then(function (r) {
560
+ var accountAddress = freshAddress
561
+ ? freshAddress.address
562
+ : account.freshAddress;
563
+ if (r.address !== accountAddress) {
564
+ throw new errors_1.WrongDeviceForAccount("WrongDeviceForAccount ".concat(account.name), {
565
+ accountName: account.name
566
+ });
567
+ }
568
+ return r;
569
+ }));
570
+ });
571
+ };
572
+ }
573
+ exports.makeAccountBridgeReceive = makeAccountBridgeReceive;
574
+ //# sourceMappingURL=jsHelpers.js.map