@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,27 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import { avoidDups } from "./getAccountNetworkInfo";
3
- test("avoidFeeDupsInFeePerByte [3,2,2] => [4,3,2]", async () => {
4
- expect(
5
- avoidDups([new BigNumber(3), new BigNumber(3), new BigNumber(2)])
6
- ).toEqual([new BigNumber(4), new BigNumber(3), new BigNumber(2)]);
7
- });
8
- test("avoidFeeDupsInFeePerByte [2,2,1] => [3,2,1]", async () => {
9
- expect(
10
- avoidDups([new BigNumber(2), new BigNumber(2), new BigNumber(1)])
11
- ).toEqual([new BigNumber(3), new BigNumber(2), new BigNumber(1)]);
12
- });
13
- test("avoidFeeDupsInFeePerByte [3,3,3] => [5,4,3]", async () => {
14
- expect(
15
- avoidDups([new BigNumber(3), new BigNumber(3), new BigNumber(3)])
16
- ).toEqual([new BigNumber(5), new BigNumber(4), new BigNumber(3)]);
17
- });
18
- test("avoidFeeDupsInFeePerByte [3,2,1] => [3,2,1]", async () => {
19
- expect(
20
- avoidDups([new BigNumber(3), new BigNumber(2), new BigNumber(1)])
21
- ).toEqual([new BigNumber(3), new BigNumber(2), new BigNumber(1)]);
22
- });
23
- test("avoidFeeDupsInFeePerByte [100,100,1] => [101,100,1]", async () => {
24
- expect(
25
- avoidDups([new BigNumber(100), new BigNumber(100), new BigNumber(1)])
26
- ).toEqual([new BigNumber(101), new BigNumber(100), new BigNumber(1)]);
27
- });
@@ -1,61 +0,0 @@
1
- import flow from "lodash/flow";
2
- import { BigNumber } from "bignumber.js";
3
- import type { Account } from "../../types";
4
- import type { NetworkInfo } from "./types";
5
- import { getWalletAccount } from "./wallet";
6
- const speeds = ["fast", "medium", "slow"];
7
- export function avoidDups(nums: Array<BigNumber>): Array<BigNumber> {
8
- nums = nums.slice(0);
9
-
10
- for (let i = nums.length - 2; i >= 0; i--) {
11
- if (nums[i + 1].gte(nums[i])) {
12
- nums[i] = nums[i + 1].plus(1);
13
- }
14
- }
15
-
16
- return nums;
17
- }
18
- export async function getAccountNetworkInfo(
19
- account: Account
20
- ): Promise<NetworkInfo> {
21
- const walletAccount = await getWalletAccount(account);
22
- const rawFees = await walletAccount.xpub.explorer.getFees();
23
- // Convoluted logic to convert from:
24
- // { "2": 2435, "3": 1241, "6": 1009, "last_updated": 1627973170 }
25
- // to:
26
- // { 2435, 1241, 1009 }
27
- const feesPerByte = flow([
28
- // Remove the 'last_updated' key
29
- Object.entries,
30
- (entries) => entries.filter(([key]) => !isNaN(key)),
31
- // Reconstruct the array with only the values
32
- Object.fromEntries,
33
- Object.values,
34
- // Safety against invalid data
35
- (f) => f.filter((f) => f != null && typeof f === "number"),
36
- // Normalize values
37
- (f) =>
38
- f.map((f) =>
39
- new BigNumber(f).div(1000).integerValue(BigNumber.ROUND_CEIL)
40
- ),
41
- avoidDups,
42
- ])(rawFees);
43
-
44
- if (feesPerByte.length !== 3) {
45
- throw new Error("cardinality of feesPerByte should be exactly 3");
46
- }
47
-
48
- const feeItems = {
49
- items: feesPerByte.map((feePerByte, i) => ({
50
- key: String(i),
51
- speed: speeds[i],
52
- feePerByte,
53
- })),
54
- defaultFeePerByte:
55
- feesPerByte[Math.floor(feesPerByte.length / 2)] || new BigNumber(0),
56
- };
57
- return {
58
- family: "bitcoin",
59
- feeItems,
60
- };
61
- }
@@ -1,30 +0,0 @@
1
- import { patchOperationWithHash } from "./../../operation";
2
- import type { Account, Operation, SignedOperation } from "./../../types";
3
- import wallet from "./wallet";
4
-
5
- /**
6
- * Broadcast a signed transaction
7
- * @param {signature: string, operation: string} signedOperation
8
- */
9
- const broadcast = async ({
10
- account,
11
- signedOperation,
12
- }: {
13
- account: Account;
14
- signedOperation: SignedOperation;
15
- }): Promise<Operation> => {
16
- const { signature, operation } = signedOperation;
17
- const walletData = account.bitcoinResources?.serializedData;
18
- if (!walletData) {
19
- throw new Error("bitcoin wallet account expected");
20
- }
21
- const walletAccount = await wallet.importFromSerializedAccount(walletData);
22
- try {
23
- const hash = await wallet.broadcastTx(walletAccount, signature);
24
- return patchOperationWithHash(operation, hash);
25
- } catch (error: any) {
26
- throw new Error(error); // TODO Improve error message for broadcast failure cases
27
- }
28
- };
29
-
30
- export default broadcast;
@@ -1,57 +0,0 @@
1
- import type { Account as WalletAccount } from "@ledgerhq/wallet-btc";
2
- import { CoinSelect, DeepFirst, Merge } from "@ledgerhq/wallet-btc";
3
- import type { TransactionInfo as WalletTxInfo } from "@ledgerhq/wallet-btc";
4
- import { FeeNotLoaded } from "@ledgerhq/errors";
5
-
6
- import type { Account } from "../../types";
7
- import type { Transaction, UtxoStrategy } from "./types";
8
- import { bitcoinPickingStrategy } from "./types";
9
- import wallet, { getWalletAccount } from "./wallet";
10
-
11
- const selectUtxoPickingStrategy = (
12
- walletAccount: WalletAccount,
13
- utxoStrategy: UtxoStrategy
14
- ) => {
15
- const handler = {
16
- [bitcoinPickingStrategy.MERGE_OUTPUTS]: Merge,
17
- [bitcoinPickingStrategy.DEEP_OUTPUTS_FIRST]: DeepFirst,
18
- [bitcoinPickingStrategy.OPTIMIZE_SIZE]: CoinSelect,
19
- }[utxoStrategy.strategy];
20
- if (!handler) throw new Error("Unsupported Bitcoin UTXO picking strategy");
21
-
22
- return new handler(
23
- walletAccount.xpub.crypto,
24
- walletAccount.xpub.derivationMode,
25
- utxoStrategy.excludeUTXOs
26
- );
27
- };
28
-
29
- export const buildTransaction = async (
30
- account: Account,
31
- transaction: Transaction
32
- ): Promise<WalletTxInfo> => {
33
- if (!transaction.feePerByte) {
34
- throw new FeeNotLoaded();
35
- }
36
- const walletAccount = await getWalletAccount(account);
37
- const utxoPickingStrategy = selectUtxoPickingStrategy(
38
- walletAccount,
39
- transaction.utxoStrategy
40
- );
41
-
42
- const maxSpendable = await wallet.estimateAccountMaxSpendable(
43
- walletAccount,
44
- transaction.feePerByte.toNumber() //!\ wallet-btc handles fees as JS number
45
- );
46
-
47
- const txInfo = await wallet.buildAccountTx({
48
- fromAccount: walletAccount,
49
- dest: transaction.recipient,
50
- amount: transaction.useAllAmount ? maxSpendable : transaction.amount,
51
- feePerByte: transaction.feePerByte.toNumber(), //!\ wallet-btc handles fees as JS number
52
- utxoPickingStrategy,
53
- // Definition of replaceable, per the standard: https://github.com/bitcoin/bips/blob/61ccc84930051e5b4a99926510d0db4a8475a4e6/bip-0125.mediawiki#summary
54
- sequence: transaction.rbf ? 0 : 0xffffffff,
55
- });
56
- return txInfo;
57
- };
@@ -1,27 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import type { Transaction } from "./types";
3
-
4
- /**
5
- * Create an empty transaction
6
- *
7
- * @returns {Transaction}
8
- */
9
- const createTransaction = (): Transaction => {
10
- return {
11
- family: "bitcoin",
12
- amount: new BigNumber(0),
13
- utxoStrategy: {
14
- strategy: 0,
15
- pickUnconfirmedRBF: false,
16
- excludeUTXOs: [],
17
- },
18
- recipient: "",
19
- rbf: false,
20
- feePerByte: null,
21
- networkInfo: null,
22
- useAllAmount: false,
23
- feesStrategy: "medium",
24
- };
25
- };
26
-
27
- export default createTransaction;
@@ -1,36 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import type { AccountLike, Account } from "../../types";
3
- import type { Transaction } from "./types";
4
- import { getMainAccount } from "../../account";
5
- import wallet, { getWalletAccount } from "./wallet";
6
- import { getAccountNetworkInfo } from "./getAccountNetworkInfo";
7
-
8
- /**
9
- * Returns the maximum possible amount for transaction
10
- *
11
- * @param {Object} param - the account, parentAccount and transaction
12
- */
13
- const estimateMaxSpendable = async ({
14
- account,
15
- parentAccount,
16
- transaction,
17
- }: {
18
- account: AccountLike;
19
- parentAccount: Account | null | undefined;
20
- transaction: Transaction | null | undefined;
21
- }): Promise<BigNumber> => {
22
- const mainAccount = getMainAccount(account, parentAccount);
23
- const walletAccount = await getWalletAccount(mainAccount);
24
- let feePerByte = transaction?.feePerByte;
25
- if (!feePerByte) {
26
- const networkInfo = await getAccountNetworkInfo(mainAccount);
27
- feePerByte = networkInfo.feeItems.defaultFeePerByte;
28
- }
29
- const maxSpendable = await wallet.estimateAccountMaxSpendable(
30
- walletAccount,
31
- feePerByte.toNumber() //!\ wallet-btc handles fees as JS number
32
- );
33
- return maxSpendable.lt(0) ? new BigNumber(0) : maxSpendable;
34
- };
35
-
36
- export default estimateMaxSpendable;
@@ -1,59 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import type { Account } from "./../../types";
3
- import type { Transaction } from "./types";
4
- import { buildTransaction } from "./js-buildTransaction";
5
- import { perCoinLogic } from "./logic";
6
-
7
- const getFeesForTransaction = async ({
8
- account,
9
- transaction,
10
- }: {
11
- account: Account;
12
- transaction: Transaction;
13
- }) => {
14
- const walletTx = await buildTransaction(account, transaction);
15
- const fees = new BigNumber(walletTx.fee).integerValue();
16
- let txInputs = walletTx.inputs.map((i) => {
17
- return {
18
- address: i.address,
19
- value: new BigNumber(i.value),
20
- previousTxHash: i.output_hash,
21
- previousOutputIndex: i.output_index,
22
- };
23
- });
24
- let txOutputs = walletTx.outputs.map((o) => {
25
- return {
26
- outputIndex: walletTx.outputs.indexOf(o),
27
- address: o.address,
28
- isChange: o.isChange,
29
- value: new BigNumber(o.value),
30
- hash: undefined,
31
- blockHeight: undefined,
32
- rbf: transaction.rbf,
33
- };
34
- });
35
- const perCoin = perCoinLogic[account.currency.id];
36
-
37
- if (perCoin) {
38
- const { syncReplaceAddress } = perCoin;
39
-
40
- if (syncReplaceAddress) {
41
- txInputs = txInputs.map((i) => ({
42
- ...i,
43
- address: i.address && syncReplaceAddress(i.address),
44
- }));
45
- txOutputs = txOutputs.map((o) => ({
46
- ...o,
47
- address: o.address && syncReplaceAddress(o.address),
48
- }));
49
- }
50
- }
51
-
52
- return {
53
- fees,
54
- txInputs,
55
- txOutputs,
56
- };
57
- };
58
-
59
- export default getFeesForTransaction;
@@ -1,118 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import { log } from "@ledgerhq/logs";
3
- import {
4
- AmountRequired,
5
- NotEnoughBalance,
6
- FeeNotLoaded,
7
- FeeTooHigh,
8
- FeeRequired,
9
- } from "@ledgerhq/errors";
10
- import { LowerThanMinimumRelayFee } from "./../../errors";
11
- import type { Account, TransactionStatus } from "./../../types";
12
- import type { Transaction } from "./types";
13
- import { calculateFees, validateRecipient } from "./cache";
14
- import { getMinRelayFee } from "./logic";
15
-
16
- const getTransactionStatus = async (
17
- a: Account,
18
- t: Transaction
19
- ): Promise<TransactionStatus> => {
20
- const errors: any = {};
21
- const warnings: any = {};
22
- const useAllAmount = !!t.useAllAmount;
23
- const { recipientError, recipientWarning } = await validateRecipient(
24
- a.currency,
25
- t.recipient
26
- );
27
-
28
- if (recipientError) {
29
- errors.recipient = recipientError;
30
- }
31
-
32
- if (recipientWarning) {
33
- warnings.recipient = recipientWarning;
34
- }
35
-
36
- let txInputs;
37
- let txOutputs;
38
- let estimatedFees = new BigNumber(0);
39
-
40
- if (!t.feePerByte) {
41
- errors.feePerByte = new FeeNotLoaded();
42
- } else if (t.feePerByte.eq(0)) {
43
- errors.feePerByte = new FeeRequired();
44
- } else if (t.recipient && !errors.recipient) {
45
- await calculateFees({
46
- account: a,
47
- transaction: t,
48
- }).then(
49
- (res) => {
50
- txInputs = res.txInputs;
51
- txOutputs = res.txOutputs;
52
- estimatedFees = res.fees;
53
- },
54
- (error) => {
55
- if (error.name === "NotEnoughBalance") {
56
- errors.amount = error;
57
- } else {
58
- throw error;
59
- }
60
- }
61
- );
62
- }
63
-
64
- const sumOfInputs = (txInputs || []).reduce(
65
- (sum, input) => sum.plus(input.value),
66
- new BigNumber(0)
67
- );
68
- const sumOfChanges = (txOutputs || [])
69
- .filter((o) => o.isChange)
70
- .reduce((sum, output) => sum.plus(output.value), new BigNumber(0));
71
-
72
- if (txInputs) {
73
- log("bitcoin", `${txInputs.length} inputs, sum: ${sumOfInputs.toString()}`);
74
- }
75
-
76
- if (txOutputs) {
77
- log(
78
- "bitcoin",
79
- `${txOutputs.length} outputs, sum of changes: ${sumOfChanges.toString()}`
80
- );
81
- }
82
-
83
- const totalSpent = sumOfInputs.minus(sumOfChanges);
84
- const amount = useAllAmount ? totalSpent.minus(estimatedFees) : t.amount;
85
- log(
86
- "bitcoin",
87
- `totalSpent ${totalSpent.toString()} amount ${amount.toString()}`
88
- );
89
-
90
- if (!errors.amount && !amount.gt(0)) {
91
- errors.amount = useAllAmount
92
- ? new NotEnoughBalance()
93
- : new AmountRequired();
94
- }
95
-
96
- if (
97
- process.env.EXPERIMENTAL_MIN_RELAY_FEE &&
98
- estimatedFees &&
99
- estimatedFees.gt(0) &&
100
- estimatedFees.lt(getMinRelayFee(a.currency))
101
- ) {
102
- warnings.feePerByte = new LowerThanMinimumRelayFee();
103
- } else if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
104
- warnings.feeTooHigh = new FeeTooHigh();
105
- }
106
-
107
- return Promise.resolve({
108
- errors,
109
- warnings,
110
- estimatedFees,
111
- amount,
112
- totalSpent,
113
- txInputs,
114
- txOutputs,
115
- });
116
- };
117
-
118
- export default getTransactionStatus;
@@ -1,35 +0,0 @@
1
- import invariant from "invariant";
2
- import type { Account } from "../../types";
3
- import type { Transaction } from "./types";
4
- import { getAccountNetworkInfo } from "./getAccountNetworkInfo";
5
- import { inferFeePerByte } from "./logic";
6
-
7
- const prepareTransaction = async (
8
- a: Account,
9
- t: Transaction
10
- ): Promise<Transaction> => {
11
- let networkInfo = t.networkInfo;
12
-
13
- if (!networkInfo) {
14
- networkInfo = await getAccountNetworkInfo(a);
15
- invariant(networkInfo.family === "bitcoin", "bitcoin networkInfo expected");
16
- }
17
-
18
- const feePerByte = inferFeePerByte(t, networkInfo);
19
-
20
- if (
21
- t.networkInfo === networkInfo &&
22
- (feePerByte === t.feePerByte || feePerByte.eq(t.feePerByte || 0))
23
- ) {
24
- // nothing changed
25
- return t;
26
- }
27
-
28
- return {
29
- ...t,
30
- networkInfo,
31
- feePerByte,
32
- };
33
- };
34
-
35
- export default prepareTransaction;
@@ -1,164 +0,0 @@
1
- import { BigNumber } from "bignumber.js";
2
- import { Observable } from "rxjs";
3
- import Btc from "@ledgerhq/hw-app-btc";
4
- import { log } from "@ledgerhq/logs";
5
- import type { Account, Operation, SignOperationEvent } from "./../../types";
6
- import { isSegwitDerivationMode } from "./../../derivation";
7
- import { encodeOperationId } from "./../../operation";
8
- import { open, close } from "./../../hw";
9
- import type { Transaction } from "./types";
10
- import { getNetworkParameters } from "./networks";
11
- import { buildTransaction } from "./js-buildTransaction";
12
- import { calculateFees } from "./cache";
13
- import wallet, { getWalletAccount } from "./wallet";
14
- import { perCoinLogic } from "./logic";
15
-
16
- const signOperation = ({
17
- account,
18
- deviceId,
19
- transaction,
20
- }: {
21
- account: Account;
22
- deviceId: any;
23
- transaction: Transaction;
24
- }): Observable<SignOperationEvent> =>
25
- Observable.create((o) => {
26
- async function main() {
27
- const { currency } = account;
28
- const transport = await open(deviceId);
29
- const hwApp = new Btc(transport);
30
- const walletAccount = await getWalletAccount(account);
31
-
32
- try {
33
- log("hw", `signTransaction ${currency.id} for account ${account.id}`);
34
- const txInfo = await buildTransaction(account, transaction);
35
- let senders: string[] = [];
36
- let recipients: string[] = [];
37
- let fee = new BigNumber(0);
38
- // Maybe better not re-calculate these fields here, instead include them
39
- // in Transaction type and set them in prepareTransaction?
40
- await calculateFees({
41
- account,
42
- transaction,
43
- }).then((res) => {
44
- senders = res.txInputs
45
- .map((i) => i.address)
46
- .filter(Boolean) as string[];
47
- recipients = res.txOutputs
48
- .map((o) => o.address)
49
- .filter(Boolean) as string[];
50
- fee = res.fees;
51
- });
52
-
53
- // FIXME (legacy)
54
- // should be `transaction.getLockTime()` as soon as lock time is
55
- // handled by libcore (actually: it always returns a default value
56
- // and that caused issue with zcash (see #904))
57
- // cf. https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/transaction_builders/BitcoinLikeUtxoPicker.cpp#L156-L159
58
- let lockTime;
59
-
60
- // (legacy) Set lockTime for Komodo to enable reward claiming on UTXOs created by
61
- // Ledger Live. We should only set this if the currency is Komodo and
62
- // lockTime isn't already defined.
63
- if (currency.id === "komodo" && lockTime === undefined) {
64
- const unixtime = Math.floor(Date.now() / 1000);
65
- lockTime = unixtime - 777;
66
- }
67
-
68
- const networkParams = getNetworkParameters(currency.id);
69
- const sigHashType = networkParams.sigHash;
70
- if (isNaN(sigHashType)) {
71
- throw new Error("sigHashType should not be NaN");
72
- }
73
-
74
- const segwit = isSegwitDerivationMode(account.derivationMode);
75
-
76
- // FIXME Call to explorer needed to set timestamp
77
- // cf. https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/transaction_builders/BitcoinLikeUtxoPicker.cpp#L150-L154
78
- /*
79
- const hasTimestamp = networkParams.usesTimestampedTransaction;
80
- const initialTimestamp = hasTimestamp
81
- ? transaction.timestamp
82
- : undefined;
83
- */
84
-
85
- const perCoin = perCoinLogic[currency.id];
86
- let additionals = [currency.id];
87
-
88
- if (account.derivationMode === "native_segwit") {
89
- additionals.push("bech32");
90
- }
91
-
92
- if (perCoin?.getAdditionals) {
93
- additionals = additionals.concat(
94
- perCoin.getAdditionals({
95
- transaction,
96
- })
97
- );
98
- }
99
-
100
- const expiryHeight = perCoin?.hasExpiryHeight
101
- ? Buffer.from([0x00, 0x00, 0x00, 0x00])
102
- : undefined;
103
-
104
- const signature = await wallet.signAccountTx({
105
- btc: hwApp,
106
- fromAccount: walletAccount,
107
- txInfo,
108
- lockTime,
109
- sigHashType,
110
- segwit,
111
- //initialTimestamp,
112
- additionals,
113
- expiryHeight,
114
- onDeviceSignatureGranted: () =>
115
- o.next({
116
- type: "device-signature-granted",
117
- }),
118
- onDeviceSignatureRequested: () =>
119
- o.next({
120
- type: "device-signature-requested",
121
- }),
122
- onDeviceStreaming: ({ progress, index, total }) =>
123
- o.next({
124
- type: "device-streaming",
125
- progress,
126
- index,
127
- total,
128
- }),
129
- });
130
- // Build the optimistic operation
131
- const operation: Operation = {
132
- id: encodeOperationId(account.id, "", "OUT"),
133
- hash: "", // Will be resolved in broadcast()
134
- type: "OUT",
135
- value: new BigNumber(transaction.amount).plus(fee),
136
- fee,
137
- blockHash: null,
138
- blockHeight: null,
139
- senders,
140
- recipients,
141
- accountId: account.id,
142
- date: new Date(),
143
- extra: {},
144
- };
145
- o.next({
146
- type: "signed",
147
- signedOperation: {
148
- operation,
149
- signature,
150
- expirationDate: null,
151
- },
152
- });
153
- } finally {
154
- close(transport, deviceId);
155
- }
156
- }
157
-
158
- main().then(
159
- () => o.complete(),
160
- (e) => o.error(e)
161
- );
162
- });
163
-
164
- export default signOperation;