@ledgerhq/coin-framework 0.0.2-next.0

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 +783 -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 +768 -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 +790 -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,595 @@
1
+ import invariant from "invariant";
2
+ import { Observable, defer, of, range, empty } from "rxjs";
3
+ import {
4
+ catchError,
5
+ switchMap,
6
+ concatMap,
7
+ takeWhile,
8
+ map,
9
+ } from "rxjs/operators";
10
+ import { log } from "@ledgerhq/logs";
11
+ import { TransportStatusError, UserRefusedAddress } from "@ledgerhq/errors";
12
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
13
+ import { getCryptoCurrencyById } from "./currencies";
14
+ import { getEnv } from "./env";
15
+ import type { CryptoCurrencyIds } from "@ledgerhq/types-live";
16
+ export type ModeSpec = {
17
+ mandatoryEmptyAccountSkip?: number;
18
+ isNonIterable?: boolean;
19
+ startsAt?: number;
20
+ overridesDerivation?: string;
21
+ isSegwit?: boolean;
22
+ isNativeSegwit?: boolean;
23
+ isTaproot?: boolean;
24
+ // TODO drop
25
+ isUnsplit?: boolean;
26
+ // TODO drop
27
+ skipFirst?: true;
28
+ overridesCoinType?: number;
29
+ // force a given cointype
30
+ purpose?: number;
31
+ isInvalid?: boolean;
32
+ // invalid means it's not a path we ever supported. some users fall into this and we support scanning for them in SCAN_FOR_INVALID_PATHS is set.
33
+ tag?: string;
34
+ addressFormat?: string;
35
+ };
36
+
37
+ // FIXME: DerivationMode SHOULD BE IN LIVE-TYPES ?
38
+ // IN LIVE-TYPES DerivationMode = string which does not work
39
+ export type DerivationMode = keyof typeof modes;
40
+
41
+ export type Result = {
42
+ address: string;
43
+ path: string;
44
+ publicKey: string;
45
+ chainCode?: string;
46
+ };
47
+ export type GetAddressOptions = {
48
+ currency: CryptoCurrency;
49
+ path: string;
50
+ derivationMode: DerivationMode;
51
+ verify?: boolean;
52
+ askChainCode?: boolean;
53
+ forceFormat?: string;
54
+ devicePath?: string;
55
+ segwit?: boolean;
56
+ };
57
+
58
+ const modes = Object.freeze({
59
+ // this is "default" by convention
60
+ "": {},
61
+ // MEW legacy derivation
62
+ ethM: {
63
+ mandatoryEmptyAccountSkip: 10,
64
+ overridesDerivation: "44'/60'/0'/<account>",
65
+ tag: "legacy",
66
+ },
67
+ // MetaMask style
68
+ ethMM: {
69
+ overridesDerivation: "44'/60'/0'/0/<account>",
70
+ skipFirst: true,
71
+ // already included in the normal bip44,
72
+ tag: "metamask",
73
+ },
74
+ // Deprecated and should no longer be used.
75
+ bch_on_bitcoin_segwit: {
76
+ overridesCoinType: 0,
77
+ isInvalid: true,
78
+ isSegwit: true,
79
+ purpose: 49,
80
+ addressFormat: "p2sh",
81
+ },
82
+ // many users have wrongly sent BTC on BCH paths
83
+ legacy_on_bch: {
84
+ overridesCoinType: 145,
85
+ isInvalid: true,
86
+ },
87
+ // chrome app and LL wrongly used to derivate vertcoin on 128
88
+ vertcoin_128: {
89
+ tag: "legacy",
90
+ overridesCoinType: 128,
91
+ },
92
+ vertcoin_128_segwit: {
93
+ tag: "legacy",
94
+ overridesCoinType: 128,
95
+ isSegwit: true,
96
+ purpose: 49,
97
+ addressFormat: "p2sh",
98
+ },
99
+ // MEW legacy derivation for eth
100
+ etcM: {
101
+ mandatoryEmptyAccountSkip: 10,
102
+ overridesDerivation: "44'/60'/160720'/0'/<account>",
103
+ tag: "legacy",
104
+ },
105
+ aeternity: {
106
+ overridesDerivation: "<account>",
107
+ },
108
+ // default derivation of tezbox offerred to users
109
+ tezbox: {
110
+ overridesDerivation: "44'/1729'/<account>'/0'",
111
+ },
112
+ tezosbip44h: {
113
+ tag: "galleon",
114
+ overridesDerivation: "44'/1729'/<account>'/0'/0'",
115
+ },
116
+ galleonL: {
117
+ tag: "legacy",
118
+ startsAt: 1,
119
+ overridesDerivation: "44'/1729'/0'/0'/<account>'",
120
+ },
121
+ tezboxL: {
122
+ tag: "legacy",
123
+ startsAt: 1,
124
+ overridesDerivation: "44'/1729'/0'/<account>'",
125
+ },
126
+ taproot: {
127
+ purpose: 86,
128
+ addressFormat: "bech32m",
129
+ tag: "taproot",
130
+ isSegwit: true,
131
+ isTaproot: true,
132
+ },
133
+ native_segwit: {
134
+ purpose: 84,
135
+ addressFormat: "bech32",
136
+ tag: "native segwit",
137
+ isSegwit: true,
138
+ isNativeSegwit: true,
139
+ },
140
+ segwit: {
141
+ isSegwit: true,
142
+ purpose: 49,
143
+ tag: "segwit",
144
+ addressFormat: "p2sh",
145
+ },
146
+ segwit_on_legacy: {
147
+ isSegwit: true,
148
+ purpose: 44,
149
+ addressFormat: "p2sh",
150
+ isInvalid: true,
151
+ },
152
+ legacy_on_segwit: {
153
+ purpose: 49,
154
+ isInvalid: true,
155
+ },
156
+ legacy_on_native_segwit: {
157
+ purpose: 84,
158
+ isInvalid: true,
159
+ },
160
+ segwit_unsplit: {
161
+ isSegwit: true,
162
+ purpose: 49,
163
+ addressFormat: "p2sh",
164
+ isUnsplit: true,
165
+ tag: "segwit unsplit",
166
+ },
167
+ sep5: {
168
+ overridesDerivation: "44'/148'/<account>'",
169
+ },
170
+ unsplit: {
171
+ isUnsplit: true,
172
+ tag: "unsplit",
173
+ },
174
+ polkadotbip44: {
175
+ overridesDerivation: "44'/354'/<account>'/0'/<address>'",
176
+ },
177
+ gliflegacy: {
178
+ overridesDerivation: "44'/1'/0'/0/<account>",
179
+ tag: "legacy",
180
+ },
181
+ glif: {
182
+ overridesDerivation: "44'/461'/0'/0/<account>",
183
+ startsAt: 1,
184
+ tag: "third-party",
185
+ },
186
+ solanaMain: {
187
+ isNonIterable: true,
188
+ overridesDerivation: "44'/501'",
189
+ },
190
+ solanaSub: {
191
+ overridesDerivation: "44'/501'/<account>'",
192
+ },
193
+ hederaBip44: {
194
+ overridesDerivation: "44/3030",
195
+ },
196
+ cardano: {
197
+ purpose: 1852,
198
+ overridesDerivation: "1852'/1815'/<account>'/<node>/<address>",
199
+ },
200
+ nearbip44h: {
201
+ overridesDerivation: "44'/397'/0'/0'/<account>'",
202
+ mandatoryEmptyAccountSkip: 1,
203
+ },
204
+ });
205
+ modes as Record<DerivationMode, ModeSpec>; // eslint-disable-line
206
+
207
+ // FIXME: CryptoCurrencyConfig was a flowtype we could not easily convert to ts so it has been deleted
208
+ // previous types: Partial<CryptoCurrencyConfig<DerivationMode[]>>
209
+ const legacyDerivations: Record<CryptoCurrencyIds, DerivationMode[]> = {
210
+ aeternity: ["aeternity"],
211
+ bitcoin_cash: [],
212
+ bitcoin: ["legacy_on_bch"],
213
+ vertcoin: ["vertcoin_128", "vertcoin_128_segwit"],
214
+ ethereum_classic: ["etcM"],
215
+ tezos: ["galleonL", "tezboxL", "tezosbip44h", "tezbox"],
216
+ stellar: ["sep5"],
217
+ polkadot: ["polkadotbip44"],
218
+ hedera: ["hederaBip44"],
219
+ filecoin: ["gliflegacy", "glif"],
220
+ cardano: ["cardano"],
221
+ cardano_testnet: ["cardano"],
222
+ near: ["nearbip44h"],
223
+ };
224
+
225
+ const legacyDerivationsPerFamily: Record<string, DerivationMode[]> = {
226
+ ethereum: ["ethM", "ethMM"],
227
+ };
228
+
229
+ export const asDerivationMode = (derivationMode: string): DerivationMode => {
230
+ invariant(
231
+ derivationMode in modes,
232
+ "not a derivationMode. Got: '%s'",
233
+ derivationMode
234
+ );
235
+ return derivationMode as DerivationMode;
236
+ };
237
+ export const getAllDerivationModes = (): DerivationMode[] =>
238
+ Object.keys(modes) as DerivationMode[];
239
+ export const getMandatoryEmptyAccountSkip = (
240
+ derivationMode: DerivationMode
241
+ ): number =>
242
+ (modes[derivationMode] as { mandatoryEmptyAccountSkip: number })
243
+ .mandatoryEmptyAccountSkip || 0;
244
+ export const isInvalidDerivationMode = (
245
+ derivationMode: DerivationMode
246
+ ): boolean =>
247
+ (modes[derivationMode] as { isInvalid: boolean }).isInvalid || false;
248
+ export const isSegwitDerivationMode = (
249
+ derivationMode: DerivationMode
250
+ ): boolean =>
251
+ (modes[derivationMode] as { isSegwit: boolean }).isSegwit || false;
252
+ export const isNativeSegwitDerivationMode = (
253
+ derivationMode: DerivationMode
254
+ ): boolean =>
255
+ (modes[derivationMode] as { isNativeSegwit: boolean }).isNativeSegwit ||
256
+ false;
257
+ export const isTaprootDerivationMode = (
258
+ derivationMode: DerivationMode
259
+ ): boolean =>
260
+ (modes[derivationMode] as { isTaproot: boolean }).isTaproot || false;
261
+
262
+ export const isUnsplitDerivationMode = (
263
+ derivationMode: DerivationMode
264
+ ): boolean =>
265
+ (modes[derivationMode] as { isUnsplit: boolean }).isUnsplit || false;
266
+ export const isIterableDerivationMode = (
267
+ derivationMode: DerivationMode
268
+ ): boolean =>
269
+ !(modes[derivationMode] as { isNonIterable: boolean }).isNonIterable;
270
+ export const getDerivationModeStartsAt = (
271
+ derivationMode: DerivationMode
272
+ ): number => (modes[derivationMode] as { startsAt: number }).startsAt || 0;
273
+ export const getPurposeDerivationMode = (
274
+ derivationMode: DerivationMode
275
+ ): number => (modes[derivationMode] as { purpose: number }).purpose || 44;
276
+ export const getTagDerivationMode = (
277
+ currency: CryptoCurrency,
278
+ derivationMode: DerivationMode
279
+ ): string | null | undefined => {
280
+ const mode = modes[derivationMode] as { tag: any; isInvalid: any };
281
+
282
+ if (mode.tag) {
283
+ return mode.tag;
284
+ }
285
+
286
+ if (mode.isInvalid) {
287
+ return "custom";
288
+ }
289
+
290
+ if (currency.supportsSegwit && !isSegwitDerivationMode(derivationMode)) {
291
+ return "legacy";
292
+ }
293
+
294
+ return null;
295
+ };
296
+ export const getAddressFormatDerivationMode = (
297
+ derivationMode: DerivationMode
298
+ ): string =>
299
+ (modes[derivationMode] as { addressFormat: string }).addressFormat ||
300
+ "legacy";
301
+ export const derivationModeSupportsIndex = (
302
+ derivationMode: DerivationMode,
303
+ index: number
304
+ ): boolean => {
305
+ const mode = modes[derivationMode];
306
+ if ((mode as { skipFirst: boolean }).skipFirst && index === 0) return false;
307
+ return true;
308
+ };
309
+ const currencyForceCoinType = {
310
+ vertcoin: true,
311
+ };
312
+
313
+ /**
314
+ * return a ledger-lib-core compatible DerivationScheme format
315
+ * for a given currency and derivationMode (you can pass an Account because same shape)
316
+ */
317
+ export const getDerivationScheme = ({
318
+ derivationMode,
319
+ currency,
320
+ }: {
321
+ derivationMode: DerivationMode;
322
+ currency: CryptoCurrency;
323
+ }): string => {
324
+ const { overridesDerivation, overridesCoinType } = modes[derivationMode] as {
325
+ overridesDerivation: string;
326
+ overridesCoinType: string;
327
+ };
328
+ if (overridesDerivation) return overridesDerivation;
329
+ const splitFrom =
330
+ isUnsplitDerivationMode(derivationMode) && currency.forkedFrom;
331
+ const coinType = splitFrom
332
+ ? getCryptoCurrencyById(splitFrom).coinType
333
+ : typeof overridesCoinType === "number"
334
+ ? overridesCoinType
335
+ : currencyForceCoinType
336
+ ? currency.coinType
337
+ : "<coin_type>";
338
+ const purpose = getPurposeDerivationMode(derivationMode);
339
+ return `${purpose}'/${coinType}'/<account>'/<node>/<address>`;
340
+ };
341
+ // Execute a derivation scheme
342
+ export const runDerivationScheme = (
343
+ derivationScheme: string,
344
+ {
345
+ coinType,
346
+ }: {
347
+ coinType: number;
348
+ },
349
+ opts: {
350
+ account?: number | string;
351
+ node?: number | string;
352
+ address?: number | string;
353
+ } = {}
354
+ ) =>
355
+ derivationScheme
356
+ .replace("<coin_type>", String(coinType))
357
+ .replace("<account>", String(opts.account || 0))
358
+ .replace("<node>", String(opts.node || 0))
359
+ .replace("<address>", String(opts.address || 0));
360
+ // execute the derivation on the account part of the scheme
361
+ export const runAccountDerivationScheme = (
362
+ scheme: string,
363
+ currency: {
364
+ coinType: number;
365
+ },
366
+ opts: {
367
+ account?: number | string;
368
+ } = {}
369
+ ) =>
370
+ runDerivationScheme(scheme, currency, {
371
+ ...opts,
372
+ address: "_",
373
+ node: "_",
374
+ }).replace(/[_/]+$/, "");
375
+ const disableBIP44: Record<string, boolean> = {
376
+ aeternity: true,
377
+ tezos: true,
378
+ // current workaround, device app does not seem to support bip44
379
+ stellar: true,
380
+ polkadot: true,
381
+ solana: true,
382
+ hedera: true,
383
+ cardano: true,
384
+ cardano_testnet: true,
385
+ near: true,
386
+ };
387
+ type SeedInfo = {
388
+ purpose: number;
389
+ coinType: number;
390
+ };
391
+ type SeedPathFn = (info: SeedInfo) => string;
392
+ const seedIdentifierPath: Record<string, SeedPathFn> = {
393
+ neo: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
394
+ filecoin: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
395
+ solana: ({ purpose, coinType }) => `${purpose}'/${coinType}'`,
396
+ hedera: ({ purpose, coinType }) => `${purpose}/${coinType}`,
397
+ cardano: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
398
+ cardano_testnet: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
399
+ near: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0'/0'`,
400
+ _: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'`,
401
+ };
402
+ export const getSeedIdentifierDerivation = (
403
+ currency: CryptoCurrency,
404
+ derivationMode: DerivationMode
405
+ ): string => {
406
+ const unsplitFork = isUnsplitDerivationMode(derivationMode)
407
+ ? currency.forkedFrom
408
+ : null;
409
+ const purpose = getPurposeDerivationMode(derivationMode);
410
+ const { coinType } = unsplitFork
411
+ ? getCryptoCurrencyById(unsplitFork)
412
+ : currency;
413
+ const f = seedIdentifierPath[currency.id] || seedIdentifierPath._;
414
+ return f({
415
+ purpose,
416
+ coinType,
417
+ });
418
+ };
419
+ // return an array of ways to derivate, by convention the latest is the standard one.
420
+ export const getDerivationModesForCurrency = (
421
+ currency: CryptoCurrency
422
+ ): DerivationMode[] => {
423
+ let all: DerivationMode[] = [];
424
+ if (currency.family in legacyDerivationsPerFamily) {
425
+ all = all.concat(legacyDerivationsPerFamily[currency.family]);
426
+ }
427
+ if (currency.id in legacyDerivations) {
428
+ all = all.concat(legacyDerivations[currency.id]);
429
+ }
430
+ if (currency.forkedFrom) {
431
+ all.push("unsplit");
432
+
433
+ if (currency.supportsSegwit) {
434
+ all.push("segwit_unsplit");
435
+ }
436
+ }
437
+
438
+ if (currency.supportsSegwit) {
439
+ all.push("segwit_on_legacy");
440
+ all.push("legacy_on_segwit");
441
+ all.push("legacy_on_native_segwit");
442
+ }
443
+
444
+ if (currency.supportsNativeSegwit) {
445
+ all.push("native_segwit");
446
+ }
447
+
448
+ // taproot logic. FIXME should move per family
449
+ if (currency.family === "bitcoin") {
450
+ if (currency.id === "bitcoin" || currency.id === "bitcoin_testnet") {
451
+ all.push("taproot");
452
+ }
453
+ }
454
+
455
+ if (currency.supportsSegwit) {
456
+ all.push("segwit");
457
+ }
458
+
459
+ if (!disableBIP44[currency.id]) {
460
+ all.push("");
461
+ }
462
+
463
+ if (currency.family === "solana") {
464
+ all.push("solanaMain", "solanaSub");
465
+ }
466
+
467
+ if (!getEnv("SCAN_FOR_INVALID_PATHS")) {
468
+ return all.filter((a) => !isInvalidDerivationMode(a));
469
+ }
470
+
471
+ return all;
472
+ };
473
+ const preferredList: DerivationMode[] = [
474
+ "native_segwit",
475
+ "taproot",
476
+ "segwit",
477
+ "",
478
+ ];
479
+ // null => no settings
480
+ // [ .. ]
481
+ export const getPreferredNewAccountScheme = (
482
+ currency: CryptoCurrency
483
+ ): DerivationMode[] | null | undefined => {
484
+ if (currency.family !== "bitcoin") return null;
485
+ const derivationsModes = getDerivationModesForCurrency(currency);
486
+ const list = preferredList.filter((p) =>
487
+ derivationsModes.includes(p as DerivationMode)
488
+ );
489
+ if (list.length === 1) return null;
490
+ return list as DerivationMode[];
491
+ };
492
+ export const getDefaultPreferredNewAccountScheme = (
493
+ currency: CryptoCurrency
494
+ ): DerivationMode | null | undefined => {
495
+ const list = getPreferredNewAccountScheme(currency);
496
+ return list && list[0];
497
+ };
498
+ export type StepAddressInput = {
499
+ index: number;
500
+ parentDerivation: Result;
501
+ accountDerivation: Result;
502
+ derivationMode: DerivationMode;
503
+ shouldSkipEmpty: boolean;
504
+ seedIdentifier: string;
505
+ };
506
+ export type WalletDerivationInput<R> = {
507
+ currency: CryptoCurrency;
508
+ derivationMode: DerivationMode;
509
+ derivateAddress: (arg0: GetAddressOptions) => Observable<Result>;
510
+ stepAddress: (arg0: StepAddressInput) => Observable<{
511
+ result?: R;
512
+ complete?: boolean;
513
+ }>;
514
+ shouldDerivesOnAccount?: boolean;
515
+ };
516
+ export function walletDerivation<R>({
517
+ currency,
518
+ derivationMode,
519
+ derivateAddress,
520
+ stepAddress,
521
+ shouldDerivesOnAccount,
522
+ }: WalletDerivationInput<R>): Observable<R> {
523
+ const path = getSeedIdentifierDerivation(currency, derivationMode);
524
+ return defer(() =>
525
+ derivateAddress({
526
+ currency,
527
+ path,
528
+ derivationMode,
529
+ }).pipe(
530
+ catchError((e) => {
531
+ if (
532
+ e instanceof TransportStatusError ||
533
+ e instanceof UserRefusedAddress
534
+ ) {
535
+ log("scanAccounts", "ignore derivationMode=" + derivationMode);
536
+ }
537
+
538
+ return empty();
539
+ })
540
+ )
541
+ ).pipe(
542
+ switchMap((parentDerivation) => {
543
+ const seedIdentifier = parentDerivation.publicKey;
544
+ const emptyCount = 0;
545
+ const mandatoryEmptyAccountSkip =
546
+ getMandatoryEmptyAccountSkip(derivationMode);
547
+ const derivationScheme = getDerivationScheme({
548
+ derivationMode,
549
+ currency,
550
+ });
551
+ const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1;
552
+ const startsAt = getDerivationModeStartsAt(derivationMode);
553
+ return range(startsAt, stopAt - startsAt).pipe(
554
+ // derivate addresses/xpubs
555
+ concatMap((index) => {
556
+ if (!derivationModeSupportsIndex(derivationMode, index)) {
557
+ return empty();
558
+ }
559
+
560
+ const path = shouldDerivesOnAccount
561
+ ? runAccountDerivationScheme(derivationScheme, currency, {
562
+ account: index,
563
+ })
564
+ : runDerivationScheme(derivationScheme, currency, {
565
+ account: index,
566
+ });
567
+ return derivateAddress({
568
+ currency,
569
+ path,
570
+ derivationMode,
571
+ }).pipe(
572
+ map((accountDerivation) => ({
573
+ parentDerivation,
574
+ accountDerivation,
575
+ index,
576
+ }))
577
+ );
578
+ }), // do action with these derivations (e.g. synchronize)
579
+ concatMap(({ parentDerivation, accountDerivation, index }) =>
580
+ stepAddress({
581
+ index,
582
+ parentDerivation,
583
+ accountDerivation,
584
+ derivationMode,
585
+ shouldSkipEmpty: emptyCount < mandatoryEmptyAccountSkip,
586
+ seedIdentifier,
587
+ })
588
+ ), // take until the list is complete (based on criteria defined by stepAddress)
589
+ // $FlowFixMe
590
+ takeWhile((r) => !r.complete, true), // emit just the results
591
+ concatMap(({ result }) => (result ? of(result) : empty()))
592
+ );
593
+ })
594
+ );
595
+ }