@ledgerhq/live-common 21.5.1-btcjs.0 → 21.7.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 (328) hide show
  1. package/lib/account/addAccounts.d.ts.map +1 -1
  2. package/lib/account/addAccounts.js +1 -2
  3. package/lib/account/addAccounts.js.map +1 -1
  4. package/lib/account/support.d.ts.map +1 -1
  5. package/lib/account/support.js +1 -24
  6. package/lib/account/support.js.map +1 -1
  7. package/lib/api/explorerConfig/index.js +15 -15
  8. package/lib/bot/index.d.ts +1 -2
  9. package/lib/bot/index.d.ts.map +1 -1
  10. package/lib/bot/index.js +15 -19
  11. package/lib/bot/index.js.map +1 -1
  12. package/lib/bot/test.bot.js +1 -4
  13. package/lib/bot/test.bot.js.map +1 -1
  14. package/lib/bridge/jsHelpers.d.ts +1 -6
  15. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  16. package/lib/bridge/jsHelpers.js +3 -11
  17. package/lib/bridge/jsHelpers.js.map +1 -1
  18. package/lib/env.js +1 -1
  19. package/lib/env.js.map +1 -1
  20. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  21. package/lib/exchange/swap/getExchangeRates.js +9 -8
  22. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  23. package/lib/exchange/swap/hooks/index.d.ts +11 -0
  24. package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
  25. package/lib/exchange/swap/hooks/index.js +23 -0
  26. package/lib/exchange/swap/hooks/index.js.map +1 -0
  27. package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
  28. package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
  29. package/lib/exchange/swap/hooks/useFromState.js +67 -0
  30. package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
  31. package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
  32. package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
  33. package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
  34. package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
  35. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
  36. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
  37. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
  38. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
  39. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
  40. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
  41. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
  42. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
  43. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
  44. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
  45. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
  46. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
  47. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
  48. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
  49. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
  50. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
  51. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
  52. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
  53. package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
  54. package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
  55. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
  56. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
  57. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
  58. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
  59. package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
  60. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
  61. package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
  62. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
  63. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
  64. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
  65. package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
  66. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
  67. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
  68. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
  69. package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
  70. package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
  71. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
  72. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
  73. package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
  74. package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
  75. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
  76. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
  77. package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
  78. package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
  79. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
  80. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
  81. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
  82. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
  83. package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
  84. package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
  85. package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
  86. package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
  87. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
  88. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
  89. package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
  90. package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
  91. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
  92. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
  93. package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
  94. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
  95. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
  96. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
  97. package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
  98. package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
  99. package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
  100. package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
  101. package/lib/exchange/swap/hooks/useToState.js +73 -0
  102. package/lib/exchange/swap/hooks/useToState.js.map +1 -0
  103. package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
  104. package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
  105. package/lib/exchange/swap/hooks/useToState.test.js +107 -0
  106. package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
  107. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
  108. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
  109. package/lib/{families/bitcoin/getAccountNetworkInfo.js → exchange/swap/hooks/useUpdateMaxAmount.js} +47 -65
  110. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
  111. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
  112. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
  113. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
  114. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
  115. package/lib/exchange/swap/mock.d.ts +6 -2
  116. package/lib/exchange/swap/mock.d.ts.map +1 -1
  117. package/lib/exchange/swap/mock.js +21 -6
  118. package/lib/exchange/swap/mock.js.map +1 -1
  119. package/lib/exchange/swap/types.d.ts +1 -1
  120. package/lib/exchange/swap/types.d.ts.map +1 -1
  121. package/lib/exchange/swap/utils/index.d.ts +16 -0
  122. package/lib/exchange/swap/utils/index.d.ts.map +1 -0
  123. package/lib/exchange/swap/utils/index.js +49 -0
  124. package/lib/exchange/swap/utils/index.js.map +1 -0
  125. package/lib/exchange/swap/utils/index.test.d.ts +2 -0
  126. package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
  127. package/lib/exchange/swap/utils/index.test.js +238 -0
  128. package/lib/exchange/swap/utils/index.test.js.map +1 -0
  129. package/lib/families/bitcoin/account.d.ts.map +1 -1
  130. package/lib/families/bitcoin/account.js +2 -3
  131. package/lib/families/bitcoin/account.js.map +1 -1
  132. package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
  133. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  134. package/lib/families/bitcoin/datasets/litecoin.js +3 -3
  135. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  136. package/lib/families/bitcoin/serialization.d.ts +2 -2
  137. package/lib/families/bitcoin/serialization.d.ts.map +1 -1
  138. package/lib/families/bitcoin/serialization.js +4 -8
  139. package/lib/families/bitcoin/serialization.js.map +1 -1
  140. package/lib/families/bitcoin/specs.d.ts +1 -0
  141. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  142. package/lib/families/bitcoin/specs.js +17 -8
  143. package/lib/families/bitcoin/specs.js.map +1 -1
  144. package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
  145. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  146. package/lib/families/bitcoin/test-dataset.js +1 -1
  147. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  148. package/lib/families/bitcoin/transaction.d.ts +3 -3
  149. package/lib/families/bitcoin/transaction.d.ts.map +1 -1
  150. package/lib/families/bitcoin/transaction.js +61 -64
  151. package/lib/families/bitcoin/transaction.js.map +1 -1
  152. package/lib/families/bitcoin/types.d.ts +36 -66
  153. package/lib/families/bitcoin/types.d.ts.map +1 -1
  154. package/lib/families/bitcoin/types.js +1 -16
  155. package/lib/families/bitcoin/types.js.map +1 -1
  156. package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
  157. package/lib/families/crypto_org/datasets/croeseid.js +2 -6
  158. package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
  159. package/lib/families/elrond/api/apiCalls.d.ts +0 -4
  160. package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
  161. package/lib/families/elrond/api/apiCalls.js +3 -37
  162. package/lib/families/elrond/api/apiCalls.js.map +1 -1
  163. package/lib/families/elrond/api/sdk.js +2 -2
  164. package/lib/families/elrond/api/sdk.js.map +1 -1
  165. package/lib/families/elrond/js-transaction.d.ts +2 -0
  166. package/lib/families/elrond/js-transaction.d.ts.map +1 -1
  167. package/lib/families/elrond/types.d.ts +2 -0
  168. package/lib/families/elrond/types.d.ts.map +1 -1
  169. package/lib/families/elrond/types.js.map +1 -1
  170. package/lib/families/tezos/bridge/js.js.map +1 -1
  171. package/lib/generated/bridge/js.d.ts +0 -4
  172. package/lib/generated/bridge/js.d.ts.map +1 -1
  173. package/lib/generated/bridge/js.js +18 -20
  174. package/lib/generated/bridge/js.js.map +1 -1
  175. package/lib/generated/specs.d.ts +1 -0
  176. package/lib/generated/specs.d.ts.map +1 -1
  177. package/lib/migrations/accounts-dataset.d.ts.map +1 -1
  178. package/lib/migrations/accounts-dataset.js +2 -4
  179. package/lib/migrations/accounts-dataset.js.map +1 -1
  180. package/lib/migrations/accounts.d.ts.map +1 -1
  181. package/lib/migrations/accounts.js +0 -17
  182. package/lib/migrations/accounts.js.map +1 -1
  183. package/lib/mock/account.d.ts +2 -1
  184. package/lib/mock/account.d.ts.map +1 -1
  185. package/lib/mock/account.js +5 -4
  186. package/lib/mock/account.js.map +1 -1
  187. package/package.json +12 -13
  188. package/src/.DS_Store +0 -0
  189. package/src/__tests__/.DS_Store +0 -0
  190. package/src/__tests__/__snapshots__/.DS_Store +0 -0
  191. package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
  192. package/src/account/addAccounts.ts +1 -2
  193. package/src/account/support.ts +1 -24
  194. package/src/api/explorerConfig/index.ts +15 -15
  195. package/src/bot/index.ts +3 -8
  196. package/src/bot/test.bot.ts +1 -6
  197. package/src/bridge/jsHelpers.ts +2 -22
  198. package/src/env.ts +1 -1
  199. package/src/exchange/swap/getExchangeRates.ts +8 -5
  200. package/src/exchange/swap/hooks/index.ts +10 -0
  201. package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
  202. package/src/exchange/swap/hooks/useFromState.ts +84 -0
  203. package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
  204. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
  205. package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
  206. package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
  207. package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
  208. package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
  209. package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
  210. package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
  211. package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
  212. package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
  213. package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
  214. package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
  215. package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
  216. package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
  217. package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
  218. package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
  219. package/src/exchange/swap/hooks/useToState.test.ts +53 -0
  220. package/src/exchange/swap/hooks/useToState.ts +86 -0
  221. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
  222. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
  223. package/src/exchange/swap/mock.ts +22 -3
  224. package/src/exchange/swap/types.ts +2 -1
  225. package/src/exchange/swap/utils/index.test.ts +224 -0
  226. package/src/exchange/swap/utils/index.ts +67 -0
  227. package/src/families/bitcoin/account.ts +1 -2
  228. package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
  229. package/src/families/bitcoin/datasets/litecoin.ts +6 -6
  230. package/src/families/bitcoin/serialization.ts +0 -6
  231. package/src/families/bitcoin/specs.ts +14 -5
  232. package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
  233. package/src/families/bitcoin/test-dataset.ts +1 -1
  234. package/src/families/bitcoin/transaction.ts +93 -98
  235. package/src/families/bitcoin/types.ts +37 -95
  236. package/src/families/crypto_org/datasets/croeseid.ts +7 -9
  237. package/src/families/elrond/api/apiCalls.ts +3 -31
  238. package/src/families/elrond/api/sdk.ts +2 -2
  239. package/src/families/elrond/types.ts +2 -0
  240. package/src/families/tezos/bridge/js.ts +1 -1
  241. package/src/generated/bridge/js.ts +0 -3
  242. package/src/migrations/accounts-dataset.ts +0 -3
  243. package/src/migrations/accounts.ts +0 -18
  244. package/src/mock/account.ts +2 -4
  245. package/lib/__tests__/families/bitcoin/logic.d.ts +0 -2
  246. package/lib/__tests__/families/bitcoin/logic.d.ts.map +0 -1
  247. package/lib/__tests__/families/bitcoin/logic.js +0 -39
  248. package/lib/__tests__/families/bitcoin/logic.js.map +0 -1
  249. package/lib/families/bitcoin/bridge/js.d.ts +0 -8
  250. package/lib/families/bitcoin/bridge/js.d.ts.map +0 -1
  251. package/lib/families/bitcoin/bridge/js.js +0 -149
  252. package/lib/families/bitcoin/bridge/js.js.map +0 -1
  253. package/lib/families/bitcoin/cache.d.ts +0 -28
  254. package/lib/families/bitcoin/cache.d.ts.map +0 -1
  255. package/lib/families/bitcoin/cache.js +0 -109
  256. package/lib/families/bitcoin/cache.js.map +0 -1
  257. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +0 -6
  258. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +0 -1
  259. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +0 -1
  260. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +0 -2
  261. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +0 -1
  262. package/lib/families/bitcoin/getAccountNetworkInfo.test.js +0 -71
  263. package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +0 -1
  264. package/lib/families/bitcoin/js-broadcast.d.ts +0 -11
  265. package/lib/families/bitcoin/js-broadcast.d.ts.map +0 -1
  266. package/lib/families/bitcoin/js-broadcast.js +0 -80
  267. package/lib/families/bitcoin/js-broadcast.js.map +0 -1
  268. package/lib/families/bitcoin/js-buildTransaction.d.ts +0 -5
  269. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +0 -1
  270. package/lib/families/bitcoin/js-buildTransaction.js +0 -106
  271. package/lib/families/bitcoin/js-buildTransaction.js.map +0 -1
  272. package/lib/families/bitcoin/js-createTransaction.d.ts +0 -9
  273. package/lib/families/bitcoin/js-createTransaction.d.ts.map +0 -1
  274. package/lib/families/bitcoin/js-createTransaction.js +0 -27
  275. package/lib/families/bitcoin/js-createTransaction.js.map +0 -1
  276. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +0 -15
  277. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +0 -1
  278. package/lib/families/bitcoin/js-estimateMaxSpendable.js +0 -95
  279. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +0 -1
  280. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +0 -26
  281. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +0 -1
  282. package/lib/families/bitcoin/js-getFeesForTransaction.js +0 -100
  283. package/lib/families/bitcoin/js-getFeesForTransaction.js.map +0 -1
  284. package/lib/families/bitcoin/js-getTransactionStatus.d.ts +0 -5
  285. package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +0 -1
  286. package/lib/families/bitcoin/js-getTransactionStatus.js +0 -131
  287. package/lib/families/bitcoin/js-getTransactionStatus.js.map +0 -1
  288. package/lib/families/bitcoin/js-prepareTransaction.d.ts +0 -5
  289. package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +0 -1
  290. package/lib/families/bitcoin/js-prepareTransaction.js +0 -80
  291. package/lib/families/bitcoin/js-prepareTransaction.js.map +0 -1
  292. package/lib/families/bitcoin/js-signOperation.d.ts +0 -10
  293. package/lib/families/bitcoin/js-signOperation.d.ts.map +0 -1
  294. package/lib/families/bitcoin/js-signOperation.js +0 -212
  295. package/lib/families/bitcoin/js-signOperation.js.map +0 -1
  296. package/lib/families/bitcoin/js-synchronisation.d.ts +0 -10
  297. package/lib/families/bitcoin/js-synchronisation.d.ts.map +0 -1
  298. package/lib/families/bitcoin/js-synchronisation.js +0 -411
  299. package/lib/families/bitcoin/js-synchronisation.js.map +0 -1
  300. package/lib/families/bitcoin/logic.d.ts +0 -34
  301. package/lib/families/bitcoin/logic.d.ts.map +0 -1
  302. package/lib/families/bitcoin/logic.js +0 -292
  303. package/lib/families/bitcoin/logic.js.map +0 -1
  304. package/lib/families/bitcoin/networks.d.ts +0 -3
  305. package/lib/families/bitcoin/networks.d.ts.map +0 -1
  306. package/lib/families/bitcoin/networks.js +0 -379
  307. package/lib/families/bitcoin/networks.js.map +0 -1
  308. package/lib/families/bitcoin/wallet.d.ts +0 -6
  309. package/lib/families/bitcoin/wallet.d.ts.map +0 -1
  310. package/lib/families/bitcoin/wallet.js +0 -66
  311. package/lib/families/bitcoin/wallet.js.map +0 -1
  312. package/src/__tests__/families/bitcoin/logic.ts +0 -40
  313. package/src/families/bitcoin/bridge/js.ts +0 -76
  314. package/src/families/bitcoin/cache.ts +0 -76
  315. package/src/families/bitcoin/getAccountNetworkInfo.test.ts +0 -27
  316. package/src/families/bitcoin/getAccountNetworkInfo.ts +0 -61
  317. package/src/families/bitcoin/js-broadcast.ts +0 -30
  318. package/src/families/bitcoin/js-buildTransaction.ts +0 -57
  319. package/src/families/bitcoin/js-createTransaction.ts +0 -27
  320. package/src/families/bitcoin/js-estimateMaxSpendable.ts +0 -36
  321. package/src/families/bitcoin/js-getFeesForTransaction.ts +0 -59
  322. package/src/families/bitcoin/js-getTransactionStatus.ts +0 -118
  323. package/src/families/bitcoin/js-prepareTransaction.ts +0 -35
  324. package/src/families/bitcoin/js-signOperation.ts +0 -164
  325. package/src/families/bitcoin/js-synchronisation.ts +0 -362
  326. package/src/families/bitcoin/logic.ts +0 -253
  327. package/src/families/bitcoin/networks.ts +0 -360
  328. package/src/families/bitcoin/wallet.ts +0 -21
@@ -1,362 +0,0 @@
1
- import { $Shape } from "utility-types";
2
- import type {
3
- TX,
4
- Currency,
5
- Input as WalletInput,
6
- Output as WalletOutput,
7
- } from "@ledgerhq/wallet-btc";
8
- import { DerivationModes as WalletDerivationModes } from "@ledgerhq/wallet-btc";
9
- import { BigNumber } from "bignumber.js";
10
- import Btc from "@ledgerhq/hw-app-btc";
11
- import { log } from "@ledgerhq/logs";
12
- import type {
13
- Account,
14
- Operation,
15
- OperationType,
16
- DerivationMode,
17
- } from "../../types";
18
- import type { GetAccountShape } from "../../bridge/jsHelpers";
19
- import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";
20
- import { findCurrencyExplorer } from "../../api/Ledger";
21
- import { encodeOperationId } from "../../operation";
22
- import { BitcoinOutput } from "./types";
23
- import { perCoinLogic } from "./logic";
24
- import wallet from "./wallet";
25
-
26
- // Map LL's DerivationMode to wallet-btc's
27
- const toWalletDerivationMode = (
28
- mode: DerivationMode
29
- ): WalletDerivationModes => {
30
- switch (mode) {
31
- case "segwit":
32
- case "segwit_on_legacy":
33
- case "segwit_unsplit":
34
- case "bch_on_bitcoin_segwit":
35
- case "vertcoin_128_segwit":
36
- return WalletDerivationModes.SEGWIT;
37
-
38
- case "native_segwit":
39
- return WalletDerivationModes.NATIVE_SEGWIT;
40
-
41
- default:
42
- return WalletDerivationModes.LEGACY;
43
- }
44
- };
45
-
46
- // Map LL's currency ID to wallet-btc's Account.params.network
47
- const toWalletNetwork = (currencyId: string): "testnet" | "mainnet" => {
48
- return ["bitcoin_testnet"].includes(currencyId) ? "testnet" : "mainnet";
49
- };
50
-
51
- // Map wallet-btc's Output to LL's BitcoinOutput
52
- const fromWalletUtxo = (utxo: WalletOutput): BitcoinOutput => {
53
- return {
54
- hash: utxo.output_hash,
55
- outputIndex: utxo.output_index,
56
- blockHeight: utxo.block_height,
57
- address: utxo.address,
58
- value: new BigNumber(utxo.value),
59
- rbf: utxo.rbf,
60
- isChange: false, // wallet-btc limitation: doesn't provide it
61
- path: "",
62
- };
63
- };
64
-
65
- // wallet-btc limitation: returns all transactions twice (for each side of the tx)
66
- // so we need to deduplicate them...
67
- const deduplicateOperations = (
68
- operations: (Operation | undefined)[]
69
- ): Operation[] => {
70
- const seen = {};
71
- const out: Operation[] = [];
72
- let j = 0;
73
-
74
- for (const operation of operations) {
75
- if (operation) {
76
- if (seen[operation.id] !== 1) {
77
- seen[operation.id] = 1;
78
- out[j++] = operation;
79
- }
80
- }
81
- }
82
-
83
- return out;
84
- };
85
-
86
- const mapTxToOperations = (
87
- tx: TX,
88
- currencyId: string,
89
- accountId: string,
90
- accountAddresses: string[],
91
- changeAddresses: string[]
92
- ): $Shape<Operation[]> => {
93
- const operations: Operation[] = [];
94
- const hash = tx.hash;
95
- const fee = new BigNumber(tx.fees);
96
- const blockHeight = tx.block?.height;
97
- const blockHash = tx.block?.hash;
98
- const date = new Date(tx.block?.time || tx.received_at);
99
- const senders: string[] = [];
100
- const recipients: string[] = [];
101
- let type: OperationType = "OUT";
102
- let value = new BigNumber(0);
103
- const hasFailed = false;
104
- const accountInputs: WalletInput[] = [];
105
- const accountOutputs: WalletOutput[] = [];
106
- const syncReplaceAddress = perCoinLogic[currencyId]?.syncReplaceAddress;
107
-
108
- for (const input of tx.inputs) {
109
- if (input.address) {
110
- senders.push(
111
- syncReplaceAddress ? syncReplaceAddress(input.address) : input.address
112
- );
113
-
114
- if (input.value) {
115
- if (accountAddresses.includes(input.address)) {
116
- // This address is part of the account
117
- value = value.plus(input.value);
118
- accountInputs.push(input);
119
- }
120
- }
121
- }
122
- }
123
-
124
- // All inputs of a same transaction have the same sequence
125
- const transactionSequenceNumber =
126
- (accountInputs.length > 0 && accountInputs[0].sequence) || undefined;
127
- const hasSpentNothing = value.eq(0);
128
-
129
- for (const output of tx.outputs) {
130
- if (output.address) {
131
- if (accountAddresses.includes(output.address)) {
132
- accountOutputs.push(output);
133
-
134
- if (changeAddresses.includes(output.address)) {
135
- if (
136
- (recipients.length === 0 &&
137
- output.output_hash ===
138
- tx.outputs[tx.outputs.length - 1].output_hash) || // Is that condition safe?
139
- hasSpentNothing
140
- ) {
141
- recipients.push(
142
- syncReplaceAddress
143
- ? syncReplaceAddress(output.address)
144
- : output.address
145
- );
146
- }
147
- } else {
148
- recipients.push(
149
- syncReplaceAddress
150
- ? syncReplaceAddress(output.address)
151
- : output.address
152
- );
153
- }
154
- } else {
155
- recipients.push(
156
- syncReplaceAddress
157
- ? syncReplaceAddress(output.address)
158
- : output.address
159
- );
160
- }
161
- }
162
- }
163
-
164
- if (accountInputs.length > 0) {
165
- // It's a SEND operation
166
- for (const output of accountOutputs) {
167
- if (changeAddresses.includes(output.address)) {
168
- value = value.minus(output.value);
169
- }
170
- }
171
-
172
- type = "OUT";
173
- operations.push({
174
- id: encodeOperationId(accountId, hash, type),
175
- hash,
176
- type,
177
- value,
178
- fee,
179
- senders,
180
- recipients,
181
- blockHeight,
182
- blockHash,
183
- transactionSequenceNumber,
184
- accountId,
185
- date,
186
- hasFailed,
187
- extra: {},
188
- });
189
- }
190
-
191
- if (accountOutputs.length > 0) {
192
- // It's a RECEIVE operation
193
- const filterChangeAddresses = !!accountInputs.length;
194
- let accountOutputCount = 0;
195
- let finalAmount = new BigNumber(0);
196
-
197
- for (const output of accountOutputs) {
198
- if (!filterChangeAddresses || !changeAddresses.includes(output.address)) {
199
- finalAmount = finalAmount.plus(output.value);
200
- accountOutputCount += 1;
201
- }
202
- }
203
-
204
- if (accountOutputCount > 0) {
205
- value = finalAmount;
206
- type = "IN";
207
- operations.push({
208
- id: encodeOperationId(accountId, hash, type),
209
- hash,
210
- type,
211
- value,
212
- fee,
213
- senders,
214
- recipients,
215
- blockHeight,
216
- blockHash,
217
- transactionSequenceNumber,
218
- accountId,
219
- date,
220
- hasFailed,
221
- extra: {},
222
- });
223
- }
224
- }
225
-
226
- return operations;
227
- };
228
-
229
- const getAccountShape: GetAccountShape = async (info) => {
230
- const {
231
- transport,
232
- currency,
233
- id: accountId,
234
- index,
235
- derivationPath,
236
- derivationMode,
237
- initialAccount,
238
- } = info;
239
- const paramXpub = initialAccount?.xpub;
240
-
241
- // In case we get a full derivation path, extract the seed identification part
242
- // 44'/0'/0'/0/0 --> 44'/0'
243
- // FIXME Only the CLI provides a full derivationPath: why?
244
- const rootPath = derivationPath.split("/", 2).join("/");
245
-
246
- const walletNetwork = toWalletNetwork(currency.id);
247
- const walletDerivationMode = toWalletDerivationMode(derivationMode);
248
- const explorer = findCurrencyExplorer(currency);
249
- if (!explorer) {
250
- throw new Error(`No explorer found for currency ${currency.name}`);
251
- }
252
- if (explorer.version !== "v2" && explorer.version !== "v3") {
253
- throw new Error(`Unsupported explorer version ${explorer.version}`);
254
- }
255
-
256
- const walletAccount = initialAccount?.bitcoinResources?.serializedData
257
- ? await wallet.importFromSerializedAccount(
258
- initialAccount.bitcoinResources.serializedData
259
- )
260
- : await wallet.generateAccount({
261
- btc: (!paramXpub && transport && new Btc(transport)) || undefined,
262
- xpub: paramXpub,
263
- path: rootPath,
264
- index,
265
- currency: <Currency>currency.id,
266
- network: walletNetwork,
267
- derivationMode: walletDerivationMode,
268
- explorer: explorer && `ledger${explorer.version}`,
269
- explorerURI: `${explorer.endpoint}/blockchain/${explorer.version}/${explorer.id}`,
270
- storage: "mock",
271
- storageParams: [],
272
- });
273
- const xpub = paramXpub || walletAccount.xpub.xpub;
274
- const oldOperations = initialAccount?.operations || [];
275
- await wallet.syncAccount(walletAccount);
276
- const balance = await wallet.getAccountBalance(walletAccount);
277
- const currentBlock = await walletAccount.xpub.explorer.getCurrentBlock();
278
- const blockHeight = currentBlock?.height;
279
-
280
- // @ts-expect-error return from wallet-btc should be typed
281
- const { txs: transactions } = await wallet.getAccountTransactions(
282
- walletAccount
283
- );
284
- const accountAddressesWithInfo = await walletAccount.xpub.getXpubAddresses();
285
- const accountAddresses = accountAddressesWithInfo
286
- ? accountAddressesWithInfo.map((a) => a.address)
287
- : [];
288
- const changeAddressesWithInfo =
289
- await walletAccount.xpub.storage.getUniquesAddresses({
290
- account: 1,
291
- });
292
- const changeAddresses = changeAddressesWithInfo
293
- ? changeAddressesWithInfo.map((a) => a.address)
294
- : [];
295
- const newOperations = transactions
296
- ?.map((tx) =>
297
- mapTxToOperations(
298
- tx,
299
- currency.id,
300
- accountId,
301
- accountAddresses,
302
- changeAddresses
303
- )
304
- )
305
- .flat();
306
- const newUniqueOperations = deduplicateOperations(newOperations);
307
- const operations = mergeOps(oldOperations, newUniqueOperations);
308
- const rawUtxos = await wallet.getAccountUnspentUtxos(walletAccount);
309
- const utxos = rawUtxos.map(fromWalletUtxo);
310
- const serializedData = await wallet.exportToSerializedAccount(walletAccount);
311
- return {
312
- id: accountId,
313
- xpub,
314
- balance,
315
- spendableBalance: balance,
316
- operations,
317
- operationsCount: operations.length,
318
- blockHeight,
319
- bitcoinResources: {
320
- utxos,
321
- serializedData,
322
- },
323
- };
324
- };
325
-
326
- const postSync = (initial: Account, synced: Account) => {
327
- log("bitcoin/postSync", "bitcoinResources");
328
- const perCoin = perCoinLogic[synced.currency.id];
329
-
330
- if (perCoin) {
331
- const { postBuildBitcoinResources, syncReplaceAddress } = perCoin;
332
-
333
- if (postBuildBitcoinResources) {
334
- synced.bitcoinResources = postBuildBitcoinResources(
335
- synced,
336
- synced.bitcoinResources
337
- );
338
- }
339
-
340
- if (syncReplaceAddress) {
341
- synced.freshAddress = syncReplaceAddress(synced.freshAddress);
342
- synced.freshAddresses = synced.freshAddresses.map((a) => ({
343
- ...a,
344
- address: syncReplaceAddress(a.address),
345
- }));
346
- if (synced.bitcoinResources) {
347
- synced.bitcoinResources.utxos = synced.bitcoinResources?.utxos.map(
348
- (u) => ({
349
- ...u,
350
- address: u.address && syncReplaceAddress(u.address),
351
- })
352
- );
353
- }
354
- }
355
- }
356
-
357
- log("bitcoin/postSync", "bitcoinResources DONE");
358
- return synced;
359
- };
360
-
361
- export const scanAccounts = makeScanAccounts(getAccountShape);
362
- export const sync = makeSync(getAccountShape, postSync);
@@ -1,253 +0,0 @@
1
- import cashaddr from "cashaddrjs";
2
- import bchaddr from "bchaddrjs";
3
- import { isValidAddress } from "@ledgerhq/wallet-btc";
4
- import { RecipientRequired, InvalidAddress } from "@ledgerhq/errors";
5
- import type { Account, CryptoCurrency, CryptoCurrencyIds } from "./../../types";
6
- import type {
7
- BitcoinOutput,
8
- BitcoinResources,
9
- Transaction,
10
- NetworkInfo,
11
- UtxoStrategy,
12
- CoreBitcoinLikeOutput,
13
- CoreBitcoinLikeInput,
14
- BitcoinInput,
15
- } from "./types";
16
- import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
17
-
18
- // correspond ~ to min relay fees but determined empirically for a tx to be accepted by network
19
- const minFees = {
20
- bitcoin: 1000,
21
- bitcoin_gold: 1000,
22
- pivx: 2000,
23
- stakenet: 1000,
24
- stealthcoin: 2000,
25
- qtum: 4000,
26
- stratis: 2000,
27
- vertcoin: 2000,
28
- viacoin: 2000,
29
- peercoin: 2000,
30
- };
31
- export const getMinRelayFee = (currency: CryptoCurrency): number =>
32
- minFees[currency.id] || 0;
33
- export const inferFeePerByte = (t: Transaction, networkInfo: NetworkInfo) => {
34
- if (t.feesStrategy) {
35
- const speed = networkInfo.feeItems.items.find(
36
- (item) => t.feesStrategy === item.speed
37
- );
38
-
39
- if (!speed) {
40
- return networkInfo.feeItems.defaultFeePerByte;
41
- }
42
-
43
- return speed.feePerByte;
44
- }
45
-
46
- return t.feePerByte || networkInfo.feeItems.defaultFeePerByte;
47
- };
48
- export const isValidRecipient = async (params: {
49
- currency: CryptoCurrency;
50
- recipient: string;
51
- }): Promise<Error | null | undefined> => {
52
- if (!params.recipient) {
53
- return Promise.reject(new RecipientRequired(""));
54
- }
55
-
56
- let valid: boolean;
57
- try {
58
- // Optimistically assume params.currency.id is an actual Currency
59
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
60
- // @ts-ignore halp
61
- valid = isValidAddress(params.recipient, params.currency.id);
62
- } catch (e: any) {
63
- // isValidAddress() will throw Error if c is not an actual Currency
64
- return Promise.reject(new InvalidAddress(e.message));
65
- }
66
- if (!valid) {
67
- return Promise.reject(
68
- new InvalidAddress("Invalid address for currency " + params.currency.name)
69
- );
70
- }
71
- return Promise.resolve(null);
72
- };
73
- export function isChangeOutput(output: BitcoinOutput): boolean {
74
- if (!output.path) return false;
75
- const p = output.path.split("/");
76
- return p[p.length - 2] === "1";
77
- }
78
-
79
- type UTXOStatus =
80
- | {
81
- excluded: true;
82
- reason: "pickUnconfirmedRBF" | "userExclusion";
83
- }
84
- | {
85
- excluded: false;
86
- };
87
- export const getUTXOStatus = (
88
- utxo: BitcoinOutput,
89
- utxoStrategy: UtxoStrategy
90
- ): UTXOStatus => {
91
- if (!utxoStrategy.pickUnconfirmedRBF && utxo.rbf && !utxo.blockHeight) {
92
- return {
93
- excluded: true,
94
- reason: "pickUnconfirmedRBF",
95
- };
96
- }
97
-
98
- if (
99
- utxoStrategy.excludeUTXOs.some(
100
- (u) => u.hash === utxo.hash && u.outputIndex === utxo.outputIndex
101
- )
102
- ) {
103
- return {
104
- excluded: true,
105
- reason: "userExclusion",
106
- };
107
- }
108
-
109
- return {
110
- excluded: false,
111
- };
112
- };
113
-
114
- const bchExplicit = (str: string): string => {
115
- const explicit = str.includes(":") ? str : "bitcoincash:" + str;
116
-
117
- try {
118
- const { type } = cashaddr.decode(explicit);
119
- if (type === "P2PKH") return explicit;
120
- } catch (e) {
121
- // ignore errors
122
- }
123
-
124
- return str;
125
- };
126
-
127
- type CoinLogic = {
128
- hasExtraData?: boolean;
129
- hasExpiryHeight?: boolean;
130
- getAdditionals?: (arg0: { transaction: Transaction }) => string[];
131
- asExplicitTransactionRecipient?: (arg0: string) => string;
132
- onScreenTransactionRecipient?: (arg0: string) => string;
133
- postBuildBitcoinResources?: (
134
- arg0: Account,
135
- arg1?: BitcoinResources
136
- ) => BitcoinResources;
137
- syncReplaceAddress?: (addr: string) => string;
138
- injectGetAddressParams?: (arg0: Account) => any;
139
- };
140
-
141
- const bchToCashaddrAddressWithoutPrefix = (recipient) =>
142
- recipient ? bchaddr.toCashAddress(recipient).split(":")[1] : recipient;
143
-
144
- export const perCoinLogic: Record<
145
- CryptoCurrencyIds,
146
- CoinLogic | null | undefined
147
- > = {
148
- zencash: {
149
- hasExtraData: true, // FIXME (legacy) investigate why we need this here and drop
150
- },
151
- zcash: {
152
- hasExtraData: true,
153
- hasExpiryHeight: true,
154
- getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
155
- },
156
- komodo: {
157
- hasExtraData: true,
158
- hasExpiryHeight: true,
159
- getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
160
- },
161
- decred: {
162
- hasExpiryHeight: true,
163
- },
164
- bitcoin_gold: {
165
- getAdditionals: () => ["bip143"],
166
- },
167
- bitcoin_cash: {
168
- getAdditionals: ({ transaction }) => {
169
- const additionals = ["bip143"];
170
-
171
- if (bchExplicit(transaction.recipient).startsWith("bitcoincash:")) {
172
- additionals.push("cashaddr");
173
- }
174
-
175
- return additionals;
176
- },
177
- // Due to minimal support, we need to return the explicit format of bitcoincash:.. if it's a P2PKH
178
- asExplicitTransactionRecipient: bchExplicit,
179
- // to represent what happens on the device, which do not display the bitcoincash: prefix
180
- onScreenTransactionRecipient: (str: string): string => {
181
- const prefix = "bitcoincash:";
182
- return str.startsWith(prefix) ? str.slice(prefix.length) : str;
183
- },
184
- syncReplaceAddress: (addr) => bchToCashaddrAddressWithoutPrefix(addr),
185
- injectGetAddressParams: () => ({
186
- forceFormat: "cashaddr",
187
- }),
188
- },
189
- };
190
-
191
- // TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
192
-
193
- export async function parseBitcoinInput(
194
- input: CoreBitcoinLikeInput
195
- ): Promise<BitcoinInput> {
196
- const address = await input.getAddress();
197
- const rawValue = await input.getValue();
198
- const value = rawValue ? await libcoreAmountToBigNumber(rawValue) : null;
199
- const previousTxHash = await input.getPreviousTxHash();
200
- const previousOutputIndex = await input.getPreviousOutputIndex();
201
- return {
202
- address,
203
- value,
204
- previousTxHash,
205
- previousOutputIndex,
206
- };
207
- }
208
-
209
- export async function parseBitcoinOutput(
210
- output: CoreBitcoinLikeOutput
211
- ): Promise<BitcoinOutput> {
212
- let blockHeight = await output.getBlockHeight();
213
-
214
- if (!blockHeight || blockHeight < 0) {
215
- blockHeight = undefined;
216
- }
217
-
218
- const hash = await output.getTransactionHash();
219
- const outputIndex = await output.getOutputIndex();
220
- const address = await output.getAddress();
221
- const derivationPath = await output.getDerivationPath();
222
- let path;
223
-
224
- if (derivationPath) {
225
- const isDerivationPathNull = await derivationPath.isNull();
226
-
227
- if (!isDerivationPathNull) {
228
- path = await derivationPath.toString();
229
- }
230
- }
231
-
232
- const value = await libcoreAmountToBigNumber(await output.getValue());
233
- const rbf = false; // this is unsafe to generically call this at the moment. libcore segfault.
234
-
235
- return {
236
- hash,
237
- outputIndex,
238
- blockHeight,
239
- address,
240
- isChange: false,
241
- path,
242
- value,
243
- rbf,
244
- };
245
- }
246
-
247
- export async function parseBitcoinUTXO(
248
- output: CoreBitcoinLikeOutput
249
- ): Promise<BitcoinOutput> {
250
- const utxo = await parseBitcoinOutput(output);
251
- utxo.rbf = await output.isReplaceable();
252
- return utxo;
253
- }