@ledgerhq/live-common 27.0.0 → 27.0.1-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 (405) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +2 -2
  2. package/lib/__tests__/test-helpers/environment.d.ts +2 -0
  3. package/lib/__tests__/test-helpers/environment.d.ts.map +1 -0
  4. package/lib/__tests__/test-helpers/environment.js +107 -0
  5. package/lib/__tests__/test-helpers/environment.js.map +1 -0
  6. package/lib/__tests__/test-helpers/setup.d.ts +1 -1
  7. package/lib/__tests__/test-helpers/setup.d.ts.map +1 -1
  8. package/lib/__tests__/test-helpers/setup.js +1 -101
  9. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  10. package/lib/account/serialization.d.ts.map +1 -1
  11. package/lib/account/serialization.js +83 -40
  12. package/lib/account/serialization.js.map +1 -1
  13. package/lib/bot/bot-test-context.d.ts +3 -0
  14. package/lib/bot/bot-test-context.d.ts.map +1 -0
  15. package/lib/bot/bot-test-context.js +26 -0
  16. package/lib/bot/bot-test-context.js.map +1 -0
  17. package/lib/bot/bot-test-context.test.d.ts +2 -0
  18. package/lib/bot/bot-test-context.test.d.ts.map +1 -0
  19. package/lib/bot/bot-test-context.test.js +41 -0
  20. package/lib/bot/bot-test-context.test.js.map +1 -0
  21. package/lib/bot/cli.d.ts +2 -0
  22. package/lib/bot/cli.d.ts.map +1 -0
  23. package/lib/bot/cli.js +14 -0
  24. package/lib/bot/cli.js.map +1 -0
  25. package/lib/bot/engine.d.ts +5 -5
  26. package/lib/bot/engine.d.ts.map +1 -1
  27. package/lib/bot/engine.js +161 -112
  28. package/lib/bot/engine.js.map +1 -1
  29. package/lib/bot/formatters.d.ts +2 -2
  30. package/lib/bot/formatters.d.ts.map +1 -1
  31. package/lib/bot/formatters.js +41 -15
  32. package/lib/bot/formatters.js.map +1 -1
  33. package/lib/bot/index.d.ts +1 -1
  34. package/lib/bot/index.d.ts.map +1 -1
  35. package/lib/bot/index.js +90 -15
  36. package/lib/bot/index.js.map +1 -1
  37. package/lib/bot/specs.d.ts +2 -1
  38. package/lib/bot/specs.d.ts.map +1 -1
  39. package/lib/bot/specs.js +13 -9
  40. package/lib/bot/specs.js.map +1 -1
  41. package/lib/bot/types.d.ts +5 -2
  42. package/lib/bot/types.d.ts.map +1 -1
  43. package/lib/countervalues/logic.integration.test.js +65 -0
  44. package/lib/countervalues/logic.integration.test.js.map +1 -1
  45. package/lib/countervalues/modules/weth.d.ts.map +1 -1
  46. package/lib/countervalues/modules/weth.js +5 -10
  47. package/lib/countervalues/modules/weth.js.map +1 -1
  48. package/lib/currencies/sortByMarketcap.d.ts +0 -2
  49. package/lib/currencies/sortByMarketcap.d.ts.map +1 -1
  50. package/lib/currencies/sortByMarketcap.js +3 -17
  51. package/lib/currencies/sortByMarketcap.js.map +1 -1
  52. package/lib/currencies/sortByMarketcap.test.js +0 -5
  53. package/lib/currencies/sortByMarketcap.test.js.map +1 -1
  54. package/lib/env.js +1 -1
  55. package/lib/families/algorand/specs.d.ts.map +1 -1
  56. package/lib/families/algorand/specs.js +18 -10
  57. package/lib/families/algorand/specs.js.map +1 -1
  58. package/lib/families/algorand/speculos-deviceActions.d.ts +1 -4
  59. package/lib/families/algorand/speculos-deviceActions.d.ts.map +1 -1
  60. package/lib/families/algorand/speculos-deviceActions.js +25 -8
  61. package/lib/families/algorand/speculos-deviceActions.js.map +1 -1
  62. package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
  63. package/lib/families/bitcoin/bridge/mock.js +6 -1
  64. package/lib/families/bitcoin/bridge/mock.js.map +1 -1
  65. package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
  66. package/lib/families/bitcoin/datasets/bitcoin_cash.js +1 -1
  67. package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
  68. package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
  69. package/lib/families/bitcoin/datasets/dash.js +1 -1
  70. package/lib/families/bitcoin/datasets/dash.js.map +1 -1
  71. package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
  72. package/lib/families/bitcoin/datasets/decred.js +1 -1
  73. package/lib/families/bitcoin/datasets/decred.js.map +1 -1
  74. package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
  75. package/lib/families/bitcoin/datasets/digibyte.js +8 -2
  76. package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
  77. package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
  78. package/lib/families/bitcoin/datasets/dogecoin.js +1 -1
  79. package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
  80. package/lib/families/bitcoin/datasets/komodo.js +1 -1
  81. package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
  82. package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
  83. package/lib/families/bitcoin/datasets/litecoin.js +8 -2
  84. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  85. package/lib/families/bitcoin/datasets/peercoin.js +1 -1
  86. package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
  87. package/lib/families/bitcoin/datasets/pivx.js +1 -1
  88. package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
  89. package/lib/families/bitcoin/datasets/qtum.js +1 -1
  90. package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
  91. package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
  92. package/lib/families/bitcoin/datasets/stakenet.js +1 -1
  93. package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
  94. package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
  95. package/lib/families/bitcoin/datasets/vertcoin.js +1 -1
  96. package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
  97. package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
  98. package/lib/families/bitcoin/datasets/viacoin.js +1 -1
  99. package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
  100. package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
  101. package/lib/families/bitcoin/datasets/zcash.js +1 -1
  102. package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
  103. package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
  104. package/lib/families/bitcoin/datasets/zencash.js +1 -1
  105. package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
  106. package/lib/families/bitcoin/platformAdapter.test.d.ts +2 -0
  107. package/lib/families/bitcoin/platformAdapter.test.d.ts.map +1 -0
  108. package/lib/families/bitcoin/platformAdapter.test.js +48 -0
  109. package/lib/families/bitcoin/platformAdapter.test.js.map +1 -0
  110. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  111. package/lib/families/bitcoin/specs.js +62 -24
  112. package/lib/families/bitcoin/specs.js.map +1 -1
  113. package/lib/families/bitcoin/speculos-deviceActions.d.ts +1 -4
  114. package/lib/families/bitcoin/speculos-deviceActions.d.ts.map +1 -1
  115. package/lib/families/bitcoin/speculos-deviceActions.js +2 -4
  116. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  117. package/lib/families/cardano/js-estimateMaxSpendable.js +1 -1
  118. package/lib/families/cardano/js-estimateMaxSpendable.js.map +1 -1
  119. package/lib/families/cardano/specs.d.ts.map +1 -1
  120. package/lib/families/cardano/specs.js +19 -8
  121. package/lib/families/cardano/specs.js.map +1 -1
  122. package/lib/families/cardano/speculos-deviceActions.d.ts +1 -4
  123. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  124. package/lib/families/cardano/speculos-deviceActions.js +2 -2
  125. package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
  126. package/lib/families/celo/specs.d.ts.map +1 -1
  127. package/lib/families/celo/specs.js +2 -0
  128. package/lib/families/celo/specs.js.map +1 -1
  129. package/lib/families/celo/speculos-deviceActions.d.ts +1 -4
  130. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
  131. package/lib/families/celo/speculos-deviceActions.js +2 -4
  132. package/lib/families/celo/speculos-deviceActions.js.map +1 -1
  133. package/lib/families/cosmos/specs.d.ts.map +1 -1
  134. package/lib/families/cosmos/specs.js +41 -25
  135. package/lib/families/cosmos/specs.js.map +1 -1
  136. package/lib/families/cosmos/speculos-deviceActions.d.ts +1 -4
  137. package/lib/families/cosmos/speculos-deviceActions.d.ts.map +1 -1
  138. package/lib/families/cosmos/speculos-deviceActions.js +2 -4
  139. package/lib/families/cosmos/speculos-deviceActions.js.map +1 -1
  140. package/lib/families/crypto_org/specs.d.ts.map +1 -1
  141. package/lib/families/crypto_org/specs.js +3 -0
  142. package/lib/families/crypto_org/specs.js.map +1 -1
  143. package/lib/families/crypto_org/speculos-deviceActions.d.ts +1 -4
  144. package/lib/families/crypto_org/speculos-deviceActions.d.ts.map +1 -1
  145. package/lib/families/crypto_org/speculos-deviceActions.js +2 -2
  146. package/lib/families/crypto_org/speculos-deviceActions.js.map +1 -1
  147. package/lib/families/elrond/specs.d.ts.map +1 -1
  148. package/lib/families/elrond/specs.js +15 -2
  149. package/lib/families/elrond/specs.js.map +1 -1
  150. package/lib/families/elrond/speculos-deviceActions.d.ts +1 -4
  151. package/lib/families/elrond/speculos-deviceActions.d.ts.map +1 -1
  152. package/lib/families/elrond/speculos-deviceActions.js +2 -4
  153. package/lib/families/elrond/speculos-deviceActions.js.map +1 -1
  154. package/lib/families/ethereum/platformAdapter.test.d.ts +2 -0
  155. package/lib/families/ethereum/platformAdapter.test.d.ts.map +1 -0
  156. package/lib/families/ethereum/platformAdapter.test.js +88 -0
  157. package/lib/families/ethereum/platformAdapter.test.js.map +1 -0
  158. package/lib/families/ethereum/specs.d.ts.map +1 -1
  159. package/lib/families/ethereum/specs.js +36 -12
  160. package/lib/families/ethereum/specs.js.map +1 -1
  161. package/lib/families/ethereum/speculos-deviceActions.d.ts +1 -4
  162. package/lib/families/ethereum/speculos-deviceActions.d.ts.map +1 -1
  163. package/lib/families/ethereum/speculos-deviceActions.js +2 -4
  164. package/lib/families/ethereum/speculos-deviceActions.js.map +1 -1
  165. package/lib/families/filecoin/specs.d.ts.map +1 -1
  166. package/lib/families/filecoin/specs.js +2 -0
  167. package/lib/families/filecoin/specs.js.map +1 -1
  168. package/lib/families/filecoin/speculos-deviceActions.d.ts +1 -4
  169. package/lib/families/filecoin/speculos-deviceActions.d.ts.map +1 -1
  170. package/lib/families/filecoin/speculos-deviceActions.js +2 -2
  171. package/lib/families/filecoin/speculos-deviceActions.js.map +1 -1
  172. package/lib/families/hedera/specs.d.ts.map +1 -1
  173. package/lib/families/hedera/specs.js +11 -3
  174. package/lib/families/hedera/specs.js.map +1 -1
  175. package/lib/families/hedera/speculos-deviceActions.d.ts +1 -4
  176. package/lib/families/hedera/speculos-deviceActions.d.ts.map +1 -1
  177. package/lib/families/hedera/speculos-deviceActions.js +4 -4
  178. package/lib/families/hedera/speculos-deviceActions.js.map +1 -1
  179. package/lib/families/osmosis/specs.d.ts.map +1 -1
  180. package/lib/families/osmosis/specs.js +13 -5
  181. package/lib/families/osmosis/specs.js.map +1 -1
  182. package/lib/families/osmosis/speculos-deviceActions.d.ts +1 -4
  183. package/lib/families/osmosis/speculos-deviceActions.d.ts.map +1 -1
  184. package/lib/families/osmosis/speculos-deviceActions.js +2 -4
  185. package/lib/families/osmosis/speculos-deviceActions.js.map +1 -1
  186. package/lib/families/polkadot/platformAdapter.test.d.ts +2 -0
  187. package/lib/families/polkadot/platformAdapter.test.d.ts.map +1 -0
  188. package/lib/families/polkadot/platformAdapter.test.js +51 -0
  189. package/lib/families/polkadot/platformAdapter.test.js.map +1 -0
  190. package/lib/families/polkadot/specs.d.ts.map +1 -1
  191. package/lib/families/polkadot/specs.js +12 -1
  192. package/lib/families/polkadot/specs.js.map +1 -1
  193. package/lib/families/polkadot/speculos-deviceActions.d.ts +1 -4
  194. package/lib/families/polkadot/speculos-deviceActions.d.ts.map +1 -1
  195. package/lib/families/polkadot/speculos-deviceActions.js +2 -4
  196. package/lib/families/polkadot/speculos-deviceActions.js.map +1 -1
  197. package/lib/families/ripple/platformAdapter.test.d.ts +2 -0
  198. package/lib/families/ripple/platformAdapter.test.d.ts.map +1 -0
  199. package/lib/families/ripple/platformAdapter.test.js +51 -0
  200. package/lib/families/ripple/platformAdapter.test.js.map +1 -0
  201. package/lib/families/ripple/specs.d.ts.map +1 -1
  202. package/lib/families/ripple/specs.js +9 -4
  203. package/lib/families/ripple/specs.js.map +1 -1
  204. package/lib/families/ripple/speculos-deviceActions.d.ts +1 -4
  205. package/lib/families/ripple/speculos-deviceActions.d.ts.map +1 -1
  206. package/lib/families/ripple/speculos-deviceActions.js +2 -4
  207. package/lib/families/ripple/speculos-deviceActions.js.map +1 -1
  208. package/lib/families/solana/specs.d.ts.map +1 -1
  209. package/lib/families/solana/specs.js +29 -11
  210. package/lib/families/solana/specs.js.map +1 -1
  211. package/lib/families/solana/speculos-deviceActions.d.ts +0 -5
  212. package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -1
  213. package/lib/families/solana/speculos-deviceActions.js +0 -4
  214. package/lib/families/solana/speculos-deviceActions.js.map +1 -1
  215. package/lib/families/stellar/api/horizon.d.ts.map +1 -1
  216. package/lib/families/stellar/api/horizon.js +15 -10
  217. package/lib/families/stellar/api/horizon.js.map +1 -1
  218. package/lib/families/stellar/specs.d.ts.map +1 -1
  219. package/lib/families/stellar/specs.js +30 -12
  220. package/lib/families/stellar/specs.js.map +1 -1
  221. package/lib/families/stellar/speculos-deviceActions.d.ts +1 -4
  222. package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
  223. package/lib/families/stellar/speculos-deviceActions.js +2 -4
  224. package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
  225. package/lib/families/tezos/bakers.whitelist-default.d.ts.map +1 -1
  226. package/lib/families/tezos/bakers.whitelist-default.js +1 -1
  227. package/lib/families/tezos/bakers.whitelist-default.js.map +1 -1
  228. package/lib/families/tezos/specs.d.ts.map +1 -1
  229. package/lib/families/tezos/specs.js +2 -0
  230. package/lib/families/tezos/specs.js.map +1 -1
  231. package/lib/families/tezos/speculos-deviceActions.d.ts +1 -4
  232. package/lib/families/tezos/speculos-deviceActions.d.ts.map +1 -1
  233. package/lib/families/tezos/speculos-deviceActions.js +2 -2
  234. package/lib/families/tezos/speculos-deviceActions.js.map +1 -1
  235. package/lib/families/tron/specs.d.ts.map +1 -1
  236. package/lib/families/tron/specs.js +49 -17
  237. package/lib/families/tron/specs.js.map +1 -1
  238. package/lib/families/tron/speculos-deviceActions.d.ts +1 -4
  239. package/lib/families/tron/speculos-deviceActions.d.ts.map +1 -1
  240. package/lib/families/tron/speculos-deviceActions.js +2 -4
  241. package/lib/families/tron/speculos-deviceActions.js.map +1 -1
  242. package/lib/hw/getGenuineCheckFromDeviceId.d.ts +22 -0
  243. package/lib/hw/getGenuineCheckFromDeviceId.d.ts.map +1 -0
  244. package/lib/hw/getGenuineCheckFromDeviceId.js +49 -0
  245. package/lib/hw/getGenuineCheckFromDeviceId.js.map +1 -0
  246. package/lib/hw/getGenuineCheckFromDeviceId.test.d.ts +2 -0
  247. package/lib/hw/getGenuineCheckFromDeviceId.test.d.ts.map +1 -0
  248. package/lib/hw/getGenuineCheckFromDeviceId.test.js +84 -0
  249. package/lib/hw/getGenuineCheckFromDeviceId.test.js.map +1 -0
  250. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.d.ts +17 -0
  251. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.d.ts.map +1 -0
  252. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.js +27 -0
  253. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.js.map +1 -0
  254. package/lib/hw/hooks/useGenuineCheck.d.ts +34 -0
  255. package/lib/hw/hooks/useGenuineCheck.d.ts.map +1 -0
  256. package/lib/hw/hooks/useGenuineCheck.js +115 -0
  257. package/lib/hw/hooks/useGenuineCheck.js.map +1 -0
  258. package/lib/hw/hooks/useGenuineCheck.test.d.ts +2 -0
  259. package/lib/hw/hooks/useGenuineCheck.test.d.ts.map +1 -0
  260. package/lib/hw/hooks/useGenuineCheck.test.js +316 -0
  261. package/lib/hw/hooks/useGenuineCheck.test.js.map +1 -0
  262. package/lib/hw/hooks/useGetLatestAvailableFirmware.d.ts +29 -0
  263. package/lib/hw/hooks/useGetLatestAvailableFirmware.d.ts.map +1 -0
  264. package/lib/hw/hooks/useGetLatestAvailableFirmware.js +72 -0
  265. package/lib/hw/hooks/useGetLatestAvailableFirmware.js.map +1 -0
  266. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.d.ts +2 -0
  267. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.d.ts.map +1 -0
  268. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.js +155 -0
  269. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.js.map +1 -0
  270. package/lib/load/speculos.d.ts +1 -0
  271. package/lib/load/speculos.d.ts.map +1 -1
  272. package/lib/load/speculos.js +2 -1
  273. package/lib/load/speculos.js.map +1 -1
  274. package/lib/mock/fixtures/cryptoCurrencies.d.ts +5 -0
  275. package/lib/mock/fixtures/cryptoCurrencies.d.ts.map +1 -0
  276. package/lib/mock/fixtures/cryptoCurrencies.js +91 -0
  277. package/lib/mock/fixtures/cryptoCurrencies.js.map +1 -0
  278. package/lib/platform/converters.test.js +44 -218
  279. package/lib/platform/converters.test.js.map +1 -1
  280. package/lib/platform/logic.d.ts +44 -0
  281. package/lib/platform/logic.d.ts.map +1 -1
  282. package/lib/platform/logic.js +147 -1
  283. package/lib/platform/logic.js.map +1 -1
  284. package/lib/platform/logic.test.d.ts +2 -0
  285. package/lib/platform/logic.test.d.ts.map +1 -0
  286. package/lib/platform/logic.test.js +903 -0
  287. package/lib/platform/logic.test.js.map +1 -0
  288. package/lib/platform/react.d.ts +6 -0
  289. package/lib/platform/react.d.ts.map +1 -1
  290. package/lib/platform/react.js +6 -0
  291. package/lib/platform/react.js.map +1 -1
  292. package/lib/platform/tracking.d.ts +1 -1
  293. package/lib/platform/tracking.d.ts.map +1 -1
  294. package/lib/platform/tracking.test.js +14 -41
  295. package/lib/platform/tracking.test.js.map +1 -1
  296. package/lib/reconciliation.d.ts.map +1 -1
  297. package/lib/reconciliation.js +28 -10
  298. package/lib/reconciliation.js.map +1 -1
  299. package/package.json +5 -6
  300. package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +2 -2
  301. package/src/__tests__/test-helpers/environment.ts +91 -0
  302. package/src/__tests__/test-helpers/setup.ts +2 -91
  303. package/src/account/serialization.ts +103 -64
  304. package/src/bot/bot-test-context.test.ts +37 -0
  305. package/src/bot/bot-test-context.ts +24 -0
  306. package/src/bot/cli.ts +18 -0
  307. package/src/bot/engine.ts +109 -73
  308. package/src/bot/formatters.ts +40 -14
  309. package/src/bot/index.ts +124 -18
  310. package/src/bot/specs.ts +10 -5
  311. package/src/bot/types.ts +7 -3
  312. package/src/countervalues/logic.integration.test.ts +50 -0
  313. package/src/countervalues/modules/weth.ts +9 -12
  314. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +59 -1
  315. package/src/currencies/sortByMarketcap.test.ts +1 -12
  316. package/src/currencies/sortByMarketcap.ts +2 -22
  317. package/src/env.ts +1 -1
  318. package/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap +733 -8
  319. package/src/families/algorand/specs.ts +26 -16
  320. package/src/families/algorand/speculos-deviceActions.ts +31 -10
  321. package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +43309 -7957
  322. package/src/families/bitcoin/bridge/mock.ts +7 -1
  323. package/src/families/bitcoin/datasets/bitcoin_cash.ts +73 -13
  324. package/src/families/bitcoin/datasets/dash.ts +29 -17
  325. package/src/families/bitcoin/datasets/decred.ts +42 -12
  326. package/src/families/bitcoin/datasets/digibyte.ts +9 -3
  327. package/src/families/bitcoin/datasets/dogecoin.ts +29 -17
  328. package/src/families/bitcoin/datasets/komodo.ts +22 -22
  329. package/src/families/bitcoin/datasets/litecoin.ts +9 -3
  330. package/src/families/bitcoin/datasets/peercoin.ts +17 -17
  331. package/src/families/bitcoin/datasets/pivx.ts +17 -17
  332. package/src/families/bitcoin/datasets/qtum.ts +40 -40
  333. package/src/families/bitcoin/datasets/stakenet.ts +56 -26
  334. package/src/families/bitcoin/datasets/vertcoin.ts +43 -55
  335. package/src/families/bitcoin/datasets/viacoin.ts +35 -23
  336. package/src/families/bitcoin/datasets/zcash.ts +78 -12
  337. package/src/families/bitcoin/datasets/zencash.ts +56 -10
  338. package/src/families/bitcoin/platformAdapter.test.ts +58 -0
  339. package/src/families/bitcoin/specs.ts +81 -41
  340. package/src/families/bitcoin/speculos-deviceActions.ts +68 -69
  341. package/src/families/cardano/js-estimateMaxSpendable.ts +1 -1
  342. package/src/families/cardano/specs.ts +28 -11
  343. package/src/families/cardano/speculos-deviceActions.ts +65 -66
  344. package/src/families/celo/specs.ts +2 -0
  345. package/src/families/celo/speculos-deviceActions.ts +42 -43
  346. package/src/families/cosmos/__snapshots__/bridge.integration.test.ts.snap +246 -5
  347. package/src/families/cosmos/specs.ts +44 -28
  348. package/src/families/cosmos/speculos-deviceActions.ts +82 -83
  349. package/src/families/crypto_org/specs.ts +3 -0
  350. package/src/families/crypto_org/speculos-deviceActions.ts +58 -59
  351. package/src/families/elrond/specs.ts +21 -4
  352. package/src/families/elrond/speculos-deviceActions.ts +41 -42
  353. package/src/families/ethereum/__snapshots__/bridge.integration.test.ts.snap +90 -90
  354. package/src/families/ethereum/platformAdapter.test.ts +112 -0
  355. package/src/families/ethereum/specs.ts +47 -23
  356. package/src/families/ethereum/speculos-deviceActions.ts +93 -95
  357. package/src/families/filecoin/specs.ts +2 -1
  358. package/src/families/filecoin/speculos-deviceActions.ts +61 -62
  359. package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +57 -2
  360. package/src/families/hedera/specs.ts +13 -5
  361. package/src/families/hedera/speculos-deviceActions.ts +59 -60
  362. package/src/families/osmosis/specs.ts +15 -7
  363. package/src/families/osmosis/speculos-deviceActions.ts +82 -83
  364. package/src/families/polkadot/platformAdapter.test.ts +61 -0
  365. package/src/families/polkadot/specs.ts +20 -2
  366. package/src/families/polkadot/speculos-deviceActions.ts +83 -82
  367. package/src/families/ripple/platformAdapter.test.ts +54 -0
  368. package/src/families/ripple/specs.ts +14 -7
  369. package/src/families/ripple/speculos-deviceActions.ts +72 -73
  370. package/src/families/solana/specs.ts +33 -14
  371. package/src/families/solana/speculos-deviceActions.ts +0 -5
  372. package/src/families/stellar/api/horizon.ts +10 -6
  373. package/src/families/stellar/specs.ts +37 -19
  374. package/src/families/stellar/speculos-deviceActions.ts +85 -87
  375. package/src/families/tezos/bakers.whitelist-default.ts +0 -1
  376. package/src/families/tezos/specs.ts +2 -0
  377. package/src/families/tezos/speculos-deviceActions.ts +76 -77
  378. package/src/families/tron/specs.ts +67 -30
  379. package/src/families/tron/speculos-deviceActions.ts +81 -84
  380. package/src/hw/getGenuineCheckFromDeviceId.test.ts +98 -0
  381. package/src/hw/getGenuineCheckFromDeviceId.ts +61 -0
  382. package/src/hw/getLatestAvailableFirmwareFromDeviceId.ts +37 -0
  383. package/src/hw/hooks/useGenuineCheck.test.ts +232 -0
  384. package/src/hw/hooks/useGenuineCheck.ts +138 -0
  385. package/src/hw/hooks/useGetLatestAvailableFirmware.test.ts +111 -0
  386. package/src/hw/hooks/useGetLatestAvailableFirmware.ts +90 -0
  387. package/src/load/speculos.ts +2 -0
  388. package/src/mock/fixtures/cryptoCurrencies.ts +88 -0
  389. package/src/platform/converters.test.ts +49 -282
  390. package/src/platform/logic.test.ts +756 -0
  391. package/src/platform/logic.ts +285 -0
  392. package/src/platform/react.ts +6 -0
  393. package/src/platform/tracking.test.ts +6 -7
  394. package/src/platform/tracking.ts +1 -1
  395. package/src/reconciliation.ts +66 -43
  396. package/lib/bot/test.bot.d.ts +0 -2
  397. package/lib/bot/test.bot.d.ts.map +0 -1
  398. package/lib/bot/test.bot.js +0 -62
  399. package/lib/bot/test.bot.js.map +0 -1
  400. package/lib/generated/speculos-deviceActions.d.ts +0 -56
  401. package/lib/generated/speculos-deviceActions.d.ts.map +0 -1
  402. package/lib/generated/speculos-deviceActions.js +0 -42
  403. package/lib/generated/speculos-deviceActions.js.map +0 -1
  404. package/src/bot/test.bot.ts +0 -21
  405. package/src/generated/speculos-deviceActions.ts +0 -37
@@ -0,0 +1,903 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (_) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __read = (this && this.__read) || function (o, n) {
73
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
74
+ if (!m) return o;
75
+ var i = m.call(o), r, ar = [], e;
76
+ try {
77
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
78
+ }
79
+ catch (error) { e = { error: error }; }
80
+ finally {
81
+ try {
82
+ if (r && !r.done && (m = i["return"])) m.call(i);
83
+ }
84
+ finally { if (e) throw e.error; }
85
+ }
86
+ return ar;
87
+ };
88
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
89
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
90
+ if (ar || !(i in from)) {
91
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
92
+ ar[i] = from[i];
93
+ }
94
+ }
95
+ return to.concat(ar || Array.prototype.slice.call(from));
96
+ };
97
+ var __importDefault = (this && this.__importDefault) || function (mod) {
98
+ return (mod && mod.__esModule) ? mod : { "default": mod };
99
+ };
100
+ exports.__esModule = true;
101
+ var logic_1 = require("./logic");
102
+ var cryptoCurrencies_1 = require("../mock/fixtures/cryptoCurrencies");
103
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
104
+ var converters = __importStar(require("./converters"));
105
+ var serializers = __importStar(require("./serializers"));
106
+ var signMessage = __importStar(require("../hw/signMessage/index"));
107
+ var currencies_1 = require("../currencies");
108
+ describe("receiveOnAccountLogic", function () {
109
+ // Given
110
+ var mockPlatformReceiveRequested = jest.fn();
111
+ var mockPlatformReceiveFail = jest.fn();
112
+ var context = createContextContainingAccountId({
113
+ platformReceiveRequested: mockPlatformReceiveRequested,
114
+ platformReceiveFail: mockPlatformReceiveFail
115
+ }, "11", "12");
116
+ var uiNavigation = jest.fn();
117
+ beforeEach(function () {
118
+ mockPlatformReceiveRequested.mockClear();
119
+ mockPlatformReceiveFail.mockClear();
120
+ uiNavigation.mockClear();
121
+ });
122
+ describe("when nominal case", function () {
123
+ // Given
124
+ var accountId = "ethereumjs:2:ethereum:0x012:";
125
+ var expectedResult = "Function called";
126
+ beforeEach(function () { return uiNavigation.mockResolvedValueOnce(expectedResult); });
127
+ it("calls uiNavigation callback with an accountAddress", function () { return __awaiter(void 0, void 0, void 0, function () {
128
+ var convertedAccount, result;
129
+ return __generator(this, function (_a) {
130
+ switch (_a.label) {
131
+ case 0:
132
+ convertedAccount = __assign(__assign({}, createPlatformAccount()), { address: "Converted address" });
133
+ jest
134
+ .spyOn(converters, "accountToPlatformAccount")
135
+ .mockReturnValueOnce(convertedAccount);
136
+ return [4 /*yield*/, (0, logic_1.receiveOnAccountLogic)(context, accountId, uiNavigation)];
137
+ case 1:
138
+ result = _a.sent();
139
+ // Then
140
+ expect(uiNavigation).toBeCalledTimes(1);
141
+ expect(uiNavigation.mock.calls[0][2]).toEqual("Converted address");
142
+ expect(result).toEqual(expectedResult);
143
+ return [2 /*return*/];
144
+ }
145
+ });
146
+ }); });
147
+ it("calls the tracking for success", function () { return __awaiter(void 0, void 0, void 0, function () {
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0:
151
+ // When
152
+ return [4 /*yield*/, (0, logic_1.receiveOnAccountLogic)(context, accountId, uiNavigation)];
153
+ case 1:
154
+ // When
155
+ _a.sent();
156
+ // Then
157
+ expect(mockPlatformReceiveRequested).toBeCalledTimes(1);
158
+ expect(mockPlatformReceiveFail).toBeCalledTimes(0);
159
+ return [2 /*return*/];
160
+ }
161
+ });
162
+ }); });
163
+ });
164
+ describe("when account cannot be found", function () {
165
+ // Given
166
+ var nonFoundAccountId = "ethereumjs:2:ethereum:0x010:";
167
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
168
+ return __generator(this, function (_a) {
169
+ switch (_a.label) {
170
+ case 0:
171
+ // When
172
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0: return [4 /*yield*/, (0, logic_1.receiveOnAccountLogic)(context, nonFoundAccountId, uiNavigation)];
176
+ case 1:
177
+ _a.sent();
178
+ return [2 /*return*/];
179
+ }
180
+ });
181
+ }); }).rejects.toThrowError("Account required")];
182
+ case 1:
183
+ // When
184
+ _a.sent();
185
+ // Then
186
+ expect(uiNavigation).toBeCalledTimes(0);
187
+ return [2 /*return*/];
188
+ }
189
+ });
190
+ }); });
191
+ it("calls the tracking for error", function () { return __awaiter(void 0, void 0, void 0, function () {
192
+ return __generator(this, function (_a) {
193
+ switch (_a.label) {
194
+ case 0:
195
+ // When
196
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0: return [4 /*yield*/, (0, logic_1.receiveOnAccountLogic)(context, nonFoundAccountId, uiNavigation)];
200
+ case 1:
201
+ _a.sent();
202
+ return [2 /*return*/];
203
+ }
204
+ });
205
+ }); }).rejects.toThrow()];
206
+ case 1:
207
+ // When
208
+ _a.sent();
209
+ // Then
210
+ expect(mockPlatformReceiveRequested).toBeCalledTimes(1);
211
+ expect(mockPlatformReceiveFail).toBeCalledTimes(1);
212
+ return [2 /*return*/];
213
+ }
214
+ });
215
+ }); });
216
+ });
217
+ });
218
+ describe("completeExchangeLogic", function () {
219
+ // Given
220
+ var mockPlatformCompleteExchangeRequested = jest.fn();
221
+ var context = createContextContainingAccountId({
222
+ platformCompleteExchangeRequested: mockPlatformCompleteExchangeRequested
223
+ }, "11", "12");
224
+ var uiNavigation = jest.fn();
225
+ beforeAll(function () {
226
+ (0, currencies_1.setSupportedCurrencies)(["bitcoin", "ethereum"]);
227
+ });
228
+ afterAll(function () {
229
+ (0, currencies_1.setSupportedCurrencies)([]);
230
+ });
231
+ beforeEach(function () {
232
+ mockPlatformCompleteExchangeRequested.mockClear();
233
+ uiNavigation.mockClear();
234
+ });
235
+ describe("when nominal case", function () {
236
+ // Given
237
+ var expectedResult = "Function called";
238
+ beforeEach(function () { return uiNavigation.mockResolvedValueOnce(expectedResult); });
239
+ it("calls uiNavigation callback", function () { return __awaiter(void 0, void 0, void 0, function () {
240
+ var fromAccount, rawPlatformTransaction, completeExchangeRequest, expectedTransaction, result;
241
+ return __generator(this, function (_a) {
242
+ switch (_a.label) {
243
+ case 0:
244
+ fromAccount = (0, cryptoCurrencies_1.createFixtureAccount)("17");
245
+ context.accounts = __spreadArray(__spreadArray([], __read(context.accounts), false), [fromAccount], false);
246
+ rawPlatformTransaction = createRawEtherumTransaction();
247
+ completeExchangeRequest = {
248
+ provider: "provider",
249
+ fromAccountId: "ethereumjs:2:ethereum:0x017:",
250
+ toAccountId: "ethereumjs:2:ethereum:0x042:",
251
+ transaction: rawPlatformTransaction,
252
+ binaryPayload: "binaryPayload",
253
+ signature: "signature",
254
+ feesStrategy: "medium",
255
+ exchangeType: 8
256
+ };
257
+ expectedTransaction = {
258
+ family: "ethereum",
259
+ amount: new bignumber_js_1["default"]("1000000000"),
260
+ recipient: "0x0123456",
261
+ nonce: 8,
262
+ data: Buffer.from("Some data...", "hex"),
263
+ gasPrice: new bignumber_js_1["default"]("700000"),
264
+ userGasLimit: new bignumber_js_1["default"]("1200000"),
265
+ feesStrategy: "medium",
266
+ estimatedGasLimit: null,
267
+ feeCustomUnit: { name: "Gwei", code: "Gwei", magnitude: 9 },
268
+ mode: "send",
269
+ networkInfo: null,
270
+ useAllAmount: false
271
+ };
272
+ return [4 /*yield*/, (0, logic_1.completeExchangeLogic)(context, completeExchangeRequest, uiNavigation)];
273
+ case 1:
274
+ result = _a.sent();
275
+ // Then
276
+ expect(uiNavigation).toBeCalledTimes(1);
277
+ expect(uiNavigation.mock.calls[0][0]).toEqual({
278
+ provider: "provider",
279
+ exchange: {
280
+ fromAccount: fromAccount,
281
+ fromParentAccount: null,
282
+ toAccount: undefined,
283
+ toParentAccount: null
284
+ },
285
+ transaction: expectedTransaction,
286
+ binaryPayload: "binaryPayload",
287
+ signature: "signature",
288
+ feesStrategy: "medium",
289
+ exchangeType: 8
290
+ });
291
+ expect(result).toEqual(expectedResult);
292
+ return [2 /*return*/];
293
+ }
294
+ });
295
+ }); });
296
+ it.each(["slow", "medium", "fast", "custom"])("calls uiNavigation with a transaction that has the %s feeStrategy", function (expectedFeeStrategy) { return __awaiter(void 0, void 0, void 0, function () {
297
+ var fromAccount, rawPlatformTransaction, completeExchangeRequest;
298
+ return __generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0:
301
+ fromAccount = (0, cryptoCurrencies_1.createFixtureAccount)("17");
302
+ context.accounts = __spreadArray(__spreadArray([], __read(context.accounts), false), [fromAccount], false);
303
+ rawPlatformTransaction = createRawEtherumTransaction();
304
+ completeExchangeRequest = {
305
+ provider: "provider",
306
+ fromAccountId: "ethereumjs:2:ethereum:0x017:",
307
+ toAccountId: "ethereumjs:2:ethereum:0x042:",
308
+ transaction: rawPlatformTransaction,
309
+ binaryPayload: "binaryPayload",
310
+ signature: "signature",
311
+ feesStrategy: expectedFeeStrategy,
312
+ exchangeType: 8
313
+ };
314
+ // When
315
+ return [4 /*yield*/, (0, logic_1.completeExchangeLogic)(context, completeExchangeRequest, uiNavigation)];
316
+ case 1:
317
+ // When
318
+ _a.sent();
319
+ // Then
320
+ expect(uiNavigation).toBeCalledTimes(1);
321
+ expect(uiNavigation.mock.calls[0][0]["transaction"].feesStrategy).toEqual(expectedFeeStrategy);
322
+ return [2 /*return*/];
323
+ }
324
+ });
325
+ }); });
326
+ it("calls the tracking for success", function () { return __awaiter(void 0, void 0, void 0, function () {
327
+ var completeExchangeRequest;
328
+ return __generator(this, function (_a) {
329
+ switch (_a.label) {
330
+ case 0:
331
+ completeExchangeRequest = {
332
+ provider: "provider",
333
+ fromAccountId: "ethereumjs:2:ethereum:0x012:",
334
+ toAccountId: "ethereumjs:2:ethereum:0x042:",
335
+ transaction: createRawEtherumTransaction(),
336
+ binaryPayload: "binaryPayload",
337
+ signature: "signature",
338
+ feesStrategy: "feeStrategy",
339
+ exchangeType: 8
340
+ };
341
+ // When
342
+ return [4 /*yield*/, (0, logic_1.completeExchangeLogic)(context, completeExchangeRequest, uiNavigation)];
343
+ case 1:
344
+ // When
345
+ _a.sent();
346
+ // Then
347
+ expect(mockPlatformCompleteExchangeRequested).toBeCalledTimes(1);
348
+ return [2 /*return*/];
349
+ }
350
+ });
351
+ }); });
352
+ });
353
+ describe("when Account is from a different family than the transaction", function () {
354
+ // Given
355
+ var expectedResult = "Function called";
356
+ beforeEach(function () { return uiNavigation.mockResolvedValueOnce(expectedResult); });
357
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
358
+ var fromAccount, rawPlatformTransaction, completeExchangeRequest;
359
+ return __generator(this, function (_a) {
360
+ switch (_a.label) {
361
+ case 0:
362
+ fromAccount = (0, cryptoCurrencies_1.createFixtureAccount)("17");
363
+ context.accounts = __spreadArray(__spreadArray([], __read(context.accounts), false), [fromAccount], false);
364
+ rawPlatformTransaction = createRawBitcoinTransaction();
365
+ completeExchangeRequest = {
366
+ provider: "provider",
367
+ fromAccountId: "ethereumjs:2:ethereum:0x017:",
368
+ toAccountId: "ethereumjs:2:ethereum:0x042:",
369
+ transaction: rawPlatformTransaction,
370
+ binaryPayload: "binaryPayload",
371
+ signature: "signature",
372
+ feesStrategy: "feeStrategy",
373
+ exchangeType: 8
374
+ };
375
+ // When
376
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
377
+ return __generator(this, function (_a) {
378
+ switch (_a.label) {
379
+ case 0: return [4 /*yield*/, (0, logic_1.completeExchangeLogic)(context, completeExchangeRequest, uiNavigation)];
380
+ case 1:
381
+ _a.sent();
382
+ return [2 /*return*/];
383
+ }
384
+ });
385
+ }); }).rejects.toThrowError("Account and transaction must be from the same family")];
386
+ case 1:
387
+ // When
388
+ _a.sent();
389
+ // Then
390
+ expect(uiNavigation).toBeCalledTimes(0);
391
+ return [2 /*return*/];
392
+ }
393
+ });
394
+ }); });
395
+ });
396
+ });
397
+ describe("broadcastTransactionLogic", function () {
398
+ // Given
399
+ var mockplatformBroadcastFail = jest.fn();
400
+ var context = createContextContainingAccountId({
401
+ platformBroadcastFail: mockplatformBroadcastFail
402
+ }, "11", "12");
403
+ var uiNavigation = jest.fn();
404
+ beforeEach(function () {
405
+ mockplatformBroadcastFail.mockClear();
406
+ uiNavigation.mockClear();
407
+ });
408
+ describe("when nominal case", function () {
409
+ // Given
410
+ var accountId = "ethereumjs:2:ethereum:0x012:";
411
+ var rawSignedTransaction = createSignedOperationRaw();
412
+ it("calls uiNavigation callback with a signedOperation", function () { return __awaiter(void 0, void 0, void 0, function () {
413
+ var expectedResult, signedOperation, result;
414
+ return __generator(this, function (_a) {
415
+ switch (_a.label) {
416
+ case 0:
417
+ expectedResult = "Function called";
418
+ signedOperation = createSignedOperation();
419
+ jest
420
+ .spyOn(serializers, "deserializePlatformSignedTransaction")
421
+ .mockReturnValueOnce(signedOperation);
422
+ uiNavigation.mockResolvedValueOnce(expectedResult);
423
+ return [4 /*yield*/, (0, logic_1.broadcastTransactionLogic)(context, accountId, rawSignedTransaction, uiNavigation)];
424
+ case 1:
425
+ result = _a.sent();
426
+ // Then
427
+ expect(uiNavigation).toBeCalledTimes(1);
428
+ expect(uiNavigation.mock.calls[0][2]).toEqual(signedOperation);
429
+ expect(result).toEqual(expectedResult);
430
+ return [2 /*return*/];
431
+ }
432
+ });
433
+ }); });
434
+ it("calls the tracking for success", function () { return __awaiter(void 0, void 0, void 0, function () {
435
+ return __generator(this, function (_a) {
436
+ switch (_a.label) {
437
+ case 0:
438
+ // When
439
+ return [4 /*yield*/, (0, logic_1.broadcastTransactionLogic)(context, accountId, rawSignedTransaction, uiNavigation)];
440
+ case 1:
441
+ // When
442
+ _a.sent();
443
+ // Then
444
+ expect(mockplatformBroadcastFail).toBeCalledTimes(0);
445
+ return [2 /*return*/];
446
+ }
447
+ });
448
+ }); });
449
+ });
450
+ describe("when account cannot be found", function () {
451
+ // Given
452
+ var nonFoundAccountId = "ethereumjs:2:ethereum:0x010:";
453
+ var rawSignedTransaction = createSignedOperationRaw();
454
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
455
+ var expectedResult, signedOperation;
456
+ return __generator(this, function (_a) {
457
+ switch (_a.label) {
458
+ case 0:
459
+ expectedResult = "Function called";
460
+ signedOperation = createSignedOperation();
461
+ jest
462
+ .spyOn(serializers, "deserializePlatformSignedTransaction")
463
+ .mockReturnValueOnce(signedOperation);
464
+ uiNavigation.mockResolvedValueOnce(expectedResult);
465
+ // When
466
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
467
+ return __generator(this, function (_a) {
468
+ switch (_a.label) {
469
+ case 0: return [4 /*yield*/, (0, logic_1.broadcastTransactionLogic)(context, nonFoundAccountId, rawSignedTransaction, uiNavigation)];
470
+ case 1:
471
+ _a.sent();
472
+ return [2 /*return*/];
473
+ }
474
+ });
475
+ }); }).rejects.toThrowError("Account required")];
476
+ case 1:
477
+ // When
478
+ _a.sent();
479
+ // Then
480
+ expect(uiNavigation).toBeCalledTimes(0);
481
+ return [2 /*return*/];
482
+ }
483
+ });
484
+ }); });
485
+ it("calls the tracking for error", function () { return __awaiter(void 0, void 0, void 0, function () {
486
+ return __generator(this, function (_a) {
487
+ switch (_a.label) {
488
+ case 0:
489
+ // When
490
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
491
+ return __generator(this, function (_a) {
492
+ switch (_a.label) {
493
+ case 0: return [4 /*yield*/, (0, logic_1.broadcastTransactionLogic)(context, nonFoundAccountId, rawSignedTransaction, uiNavigation)];
494
+ case 1:
495
+ _a.sent();
496
+ return [2 /*return*/];
497
+ }
498
+ });
499
+ }); }).rejects.toThrow()];
500
+ case 1:
501
+ // When
502
+ _a.sent();
503
+ // Then
504
+ expect(mockplatformBroadcastFail).toBeCalledTimes(1);
505
+ return [2 /*return*/];
506
+ }
507
+ });
508
+ }); });
509
+ });
510
+ });
511
+ describe("signMessageLogic", function () {
512
+ // Given
513
+ var mockPlatformSignMessageRequested = jest.fn();
514
+ var mockPlatformSignMessageFail = jest.fn();
515
+ var context = createContextContainingAccountId({
516
+ platformSignMessageRequested: mockPlatformSignMessageRequested,
517
+ platformSignMessageFail: mockPlatformSignMessageFail
518
+ }, "11", "12");
519
+ var uiNavigation = jest.fn();
520
+ beforeEach(function () {
521
+ mockPlatformSignMessageRequested.mockClear();
522
+ mockPlatformSignMessageFail.mockClear();
523
+ uiNavigation.mockClear();
524
+ });
525
+ describe("when nominal case", function () {
526
+ // Given
527
+ var accountId = "ethereumjs:2:ethereum:0x012:";
528
+ var messageToSign = "Message to sign";
529
+ var spyPrepareMessageToSign = jest.spyOn(signMessage, "prepareMessageToSign");
530
+ beforeEach(function () { return spyPrepareMessageToSign.mockClear(); });
531
+ it("calls uiNavigation callback with a signedOperation", function () { return __awaiter(void 0, void 0, void 0, function () {
532
+ var expectedResult, formattedMessage, result;
533
+ return __generator(this, function (_a) {
534
+ switch (_a.label) {
535
+ case 0:
536
+ expectedResult = "Function called";
537
+ formattedMessage = createMessageData();
538
+ spyPrepareMessageToSign.mockReturnValueOnce(formattedMessage);
539
+ uiNavigation.mockResolvedValueOnce(expectedResult);
540
+ return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, accountId, messageToSign, uiNavigation)];
541
+ case 1:
542
+ result = _a.sent();
543
+ // Then
544
+ expect(uiNavigation).toBeCalledTimes(1);
545
+ expect(uiNavigation.mock.calls[0][1]).toEqual(formattedMessage);
546
+ expect(result).toEqual(expectedResult);
547
+ return [2 /*return*/];
548
+ }
549
+ });
550
+ }); });
551
+ it("calls the tracking for success", function () { return __awaiter(void 0, void 0, void 0, function () {
552
+ return __generator(this, function (_a) {
553
+ switch (_a.label) {
554
+ case 0:
555
+ // When
556
+ return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, accountId, messageToSign, uiNavigation)];
557
+ case 1:
558
+ // When
559
+ _a.sent();
560
+ // Then
561
+ expect(mockPlatformSignMessageRequested).toBeCalledTimes(1);
562
+ expect(mockPlatformSignMessageFail).toBeCalledTimes(0);
563
+ return [2 /*return*/];
564
+ }
565
+ });
566
+ }); });
567
+ });
568
+ describe("when account cannot be found", function () {
569
+ // Given
570
+ var nonFoundAccountId = "ethereumjs:2:ethereum:0x010:";
571
+ var messageToSign = "Message to sign";
572
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
573
+ return __generator(this, function (_a) {
574
+ switch (_a.label) {
575
+ case 0:
576
+ // When
577
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
578
+ return __generator(this, function (_a) {
579
+ switch (_a.label) {
580
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, nonFoundAccountId, messageToSign, uiNavigation)];
581
+ case 1:
582
+ _a.sent();
583
+ return [2 /*return*/];
584
+ }
585
+ });
586
+ }); }).rejects.toThrowError("account not found")];
587
+ case 1:
588
+ // When
589
+ _a.sent();
590
+ // Then
591
+ expect(uiNavigation).toBeCalledTimes(0);
592
+ return [2 /*return*/];
593
+ }
594
+ });
595
+ }); });
596
+ it("calls the tracking for error", function () { return __awaiter(void 0, void 0, void 0, function () {
597
+ return __generator(this, function (_a) {
598
+ switch (_a.label) {
599
+ case 0:
600
+ // When
601
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
602
+ return __generator(this, function (_a) {
603
+ switch (_a.label) {
604
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, nonFoundAccountId, messageToSign, uiNavigation)];
605
+ case 1:
606
+ _a.sent();
607
+ return [2 /*return*/];
608
+ }
609
+ });
610
+ }); }).rejects.toThrow()];
611
+ case 1:
612
+ // When
613
+ _a.sent();
614
+ // Then
615
+ expect(mockPlatformSignMessageRequested).toBeCalledTimes(1);
616
+ expect(mockPlatformSignMessageFail).toBeCalledTimes(1);
617
+ return [2 /*return*/];
618
+ }
619
+ });
620
+ }); });
621
+ });
622
+ describe("when account found is not of type 'Account'", function () {
623
+ // Given
624
+ var tokenAccountId = "15";
625
+ var messageToSign = "Message to sign";
626
+ context.accounts = __spreadArray([
627
+ createTokenAccount(tokenAccountId)
628
+ ], __read(context.accounts), false);
629
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
630
+ return __generator(this, function (_a) {
631
+ switch (_a.label) {
632
+ case 0:
633
+ // When
634
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
635
+ return __generator(this, function (_a) {
636
+ switch (_a.label) {
637
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, tokenAccountId, messageToSign, uiNavigation)];
638
+ case 1:
639
+ _a.sent();
640
+ return [2 /*return*/];
641
+ }
642
+ });
643
+ }); }).rejects.toThrowError("account provided should be the main one")];
644
+ case 1:
645
+ // When
646
+ _a.sent();
647
+ // Then
648
+ expect(uiNavigation).toBeCalledTimes(0);
649
+ return [2 /*return*/];
650
+ }
651
+ });
652
+ }); });
653
+ it("calls the tracking for error", function () { return __awaiter(void 0, void 0, void 0, function () {
654
+ return __generator(this, function (_a) {
655
+ switch (_a.label) {
656
+ case 0:
657
+ // When
658
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
659
+ return __generator(this, function (_a) {
660
+ switch (_a.label) {
661
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, tokenAccountId, messageToSign, uiNavigation)];
662
+ case 1:
663
+ _a.sent();
664
+ return [2 /*return*/];
665
+ }
666
+ });
667
+ }); }).rejects.toThrow()];
668
+ case 1:
669
+ // When
670
+ _a.sent();
671
+ // Then
672
+ expect(mockPlatformSignMessageRequested).toBeCalledTimes(1);
673
+ expect(mockPlatformSignMessageFail).toBeCalledTimes(1);
674
+ return [2 /*return*/];
675
+ }
676
+ });
677
+ }); });
678
+ });
679
+ describe("when inner call prepareMessageToSign raise an error", function () {
680
+ // Given
681
+ var accountId = "ethereumjs:2:ethereum:0x012:";
682
+ var messageToSign = "Message to sign";
683
+ var spyPrepareMessageToSign = jest.spyOn(signMessage, "prepareMessageToSign");
684
+ beforeEach(function () { return spyPrepareMessageToSign.mockClear(); });
685
+ it("returns an error", function () { return __awaiter(void 0, void 0, void 0, function () {
686
+ return __generator(this, function (_a) {
687
+ switch (_a.label) {
688
+ case 0:
689
+ // Given
690
+ spyPrepareMessageToSign.mockImplementationOnce(function () {
691
+ throw new Error("Some error");
692
+ });
693
+ // When
694
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
695
+ return __generator(this, function (_a) {
696
+ switch (_a.label) {
697
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, accountId, messageToSign, uiNavigation)];
698
+ case 1:
699
+ _a.sent();
700
+ return [2 /*return*/];
701
+ }
702
+ });
703
+ }); }).rejects.toThrowError("Some error")];
704
+ case 1:
705
+ // When
706
+ _a.sent();
707
+ // Then
708
+ expect(uiNavigation).toBeCalledTimes(0);
709
+ return [2 /*return*/];
710
+ }
711
+ });
712
+ }); });
713
+ it("calls the tracking for error", function () { return __awaiter(void 0, void 0, void 0, function () {
714
+ return __generator(this, function (_a) {
715
+ switch (_a.label) {
716
+ case 0:
717
+ // Given
718
+ spyPrepareMessageToSign.mockImplementationOnce(function () {
719
+ throw new Error("Some error");
720
+ });
721
+ // When
722
+ return [4 /*yield*/, expect(function () { return __awaiter(void 0, void 0, void 0, function () {
723
+ return __generator(this, function (_a) {
724
+ switch (_a.label) {
725
+ case 0: return [4 /*yield*/, (0, logic_1.signMessageLogic)(context, accountId, messageToSign, uiNavigation)];
726
+ case 1:
727
+ _a.sent();
728
+ return [2 /*return*/];
729
+ }
730
+ });
731
+ }); }).rejects.toThrow()];
732
+ case 1:
733
+ // When
734
+ _a.sent();
735
+ // Then
736
+ expect(mockPlatformSignMessageRequested).toBeCalledTimes(1);
737
+ expect(mockPlatformSignMessageFail).toBeCalledTimes(1);
738
+ return [2 /*return*/];
739
+ }
740
+ });
741
+ }); });
742
+ });
743
+ });
744
+ function createAppManifest(id) {
745
+ if (id === void 0) { id = "1"; }
746
+ return {
747
+ id: id,
748
+ private: false,
749
+ name: "New App Manifest",
750
+ url: "https://www.ledger.com",
751
+ homepageUrl: "https://www.ledger.com",
752
+ supportUrl: "https://www.ledger.com",
753
+ icon: null,
754
+ platform: "all",
755
+ apiVersion: "1.0.0",
756
+ manifestVersion: "1.0.0",
757
+ branch: "debug",
758
+ params: undefined,
759
+ categories: [],
760
+ currencies: "*",
761
+ content: {
762
+ shortDescription: {
763
+ en: "short description"
764
+ },
765
+ description: {
766
+ en: "description"
767
+ }
768
+ },
769
+ permissions: [],
770
+ domains: []
771
+ };
772
+ }
773
+ function createContextContainingAccountId(tracking) {
774
+ var accountIds = [];
775
+ for (var _i = 1; _i < arguments.length; _i++) {
776
+ accountIds[_i - 1] = arguments[_i];
777
+ }
778
+ return {
779
+ manifest: createAppManifest(),
780
+ accounts: __spreadArray(__spreadArray([], __read(accountIds.map(function (val) { return (0, cryptoCurrencies_1.createFixtureAccount)(val); })), false), [
781
+ (0, cryptoCurrencies_1.createFixtureAccount)(),
782
+ ], false),
783
+ tracking: tracking
784
+ };
785
+ }
786
+ function createSignedOperation() {
787
+ var operation = {
788
+ id: "42",
789
+ hash: "hashed",
790
+ type: "IN",
791
+ value: new bignumber_js_1["default"](0),
792
+ fee: new bignumber_js_1["default"](0),
793
+ senders: [],
794
+ recipients: [],
795
+ blockHeight: null,
796
+ blockHash: null,
797
+ accountId: "14",
798
+ date: new Date(),
799
+ extra: {}
800
+ };
801
+ return {
802
+ operation: operation,
803
+ signature: "Signature",
804
+ expirationDate: null
805
+ };
806
+ }
807
+ function createSignedOperationRaw() {
808
+ var rawOperation = {
809
+ id: "12",
810
+ hash: "123456",
811
+ type: "CREATE",
812
+ value: "0",
813
+ fee: "0",
814
+ senders: [],
815
+ recipients: [],
816
+ blockHeight: null,
817
+ blockHash: null,
818
+ accountId: "12",
819
+ date: "01/01/1970",
820
+ extra: {}
821
+ };
822
+ return {
823
+ operation: rawOperation,
824
+ signature: "Signature",
825
+ expirationDate: null
826
+ };
827
+ }
828
+ function createPlatformAccount() {
829
+ return {
830
+ id: "12",
831
+ name: "",
832
+ address: "",
833
+ currency: "",
834
+ balance: new bignumber_js_1["default"](0),
835
+ spendableBalance: new bignumber_js_1["default"](0),
836
+ blockHeight: 0,
837
+ lastSyncDate: new Date()
838
+ };
839
+ }
840
+ function createMessageData() {
841
+ return {
842
+ currency: (0, cryptoCurrencies_1.createFixtureCryptoCurrency)("eth"),
843
+ path: "path",
844
+ derivationMode: "ethM",
845
+ message: "default message",
846
+ rawMessage: "raw default message"
847
+ };
848
+ }
849
+ function createTokenAccount(id) {
850
+ if (id === void 0) { id = "32"; }
851
+ return {
852
+ type: "TokenAccount",
853
+ id: id,
854
+ parentId: "whatever",
855
+ token: createTokenCurrency(),
856
+ balance: new bignumber_js_1["default"](0),
857
+ spendableBalance: new bignumber_js_1["default"](0),
858
+ creationDate: new Date(),
859
+ operationsCount: 0,
860
+ operations: [],
861
+ pendingOperations: [],
862
+ starred: false,
863
+ balanceHistoryCache: {
864
+ WEEK: { latestDate: null, balances: [] },
865
+ HOUR: { latestDate: null, balances: [] },
866
+ DAY: { latestDate: null, balances: [] }
867
+ },
868
+ swapHistory: []
869
+ };
870
+ }
871
+ function createTokenCurrency() {
872
+ return {
873
+ type: "TokenCurrency",
874
+ id: "3",
875
+ contractAddress: "",
876
+ parentCurrency: (0, cryptoCurrencies_1.createFixtureCryptoCurrency)("eth"),
877
+ tokenType: "",
878
+ //-- CurrencyCommon
879
+ name: "",
880
+ ticker: "",
881
+ units: []
882
+ };
883
+ }
884
+ function createRawEtherumTransaction() {
885
+ return {
886
+ family: "ethereum",
887
+ amount: "1000000000",
888
+ recipient: "0x0123456",
889
+ nonce: 8,
890
+ data: "Some data...",
891
+ gasPrice: "700000",
892
+ gasLimit: "1200000"
893
+ };
894
+ }
895
+ function createRawBitcoinTransaction() {
896
+ return {
897
+ family: "bitcoin",
898
+ amount: "1000000000",
899
+ recipient: "0x0123456",
900
+ feePerByte: "900000"
901
+ };
902
+ }
903
+ //# sourceMappingURL=logic.test.js.map