@ledgerhq/live-common 22.3.0-universal.0 → 23.0.0-next.1

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 (269) hide show
  1. package/lib/__tests__/test-helpers/setup.js +2 -0
  2. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  3. package/lib/account/pending.d.ts +2 -1
  4. package/lib/account/pending.d.ts.map +1 -1
  5. package/lib/account/serialization.d.ts +3 -1
  6. package/lib/account/serialization.d.ts.map +1 -1
  7. package/lib/account/serialization.js +12 -3
  8. package/lib/account/serialization.js.map +1 -1
  9. package/lib/cross.d.ts.map +1 -1
  10. package/lib/cross.js +2 -1
  11. package/lib/cross.js.map +1 -1
  12. package/lib/derivation.d.ts +10 -1
  13. package/lib/derivation.d.ts.map +1 -1
  14. package/lib/derivation.js +28 -5
  15. package/lib/derivation.js.map +1 -1
  16. package/lib/env.d.ts +20 -5
  17. package/lib/env.d.ts.map +1 -1
  18. package/lib/env.js +16 -1
  19. package/lib/env.js.map +1 -1
  20. package/lib/env.react.d.ts +1 -1
  21. package/lib/env.react.d.ts.map +1 -1
  22. package/lib/errors.d.ts +1 -0
  23. package/lib/errors.d.ts.map +1 -1
  24. package/lib/errors.js +1 -0
  25. package/lib/errors.js.map +1 -1
  26. package/lib/families/algorand/js-synchronization.d.ts +2 -2
  27. package/lib/families/bitcoin/exchange.d.ts +1 -1
  28. package/lib/families/bitcoin/js-synchronisation.d.ts +2 -2
  29. package/lib/families/cardano/api/api-types.d.ts +38 -0
  30. package/lib/families/cardano/api/api-types.d.ts.map +1 -0
  31. package/lib/families/cardano/api/api-types.js +3 -0
  32. package/lib/families/cardano/api/api-types.js.map +1 -0
  33. package/lib/families/cardano/api/getNetworkInfo.d.ts +4 -0
  34. package/lib/families/cardano/api/getNetworkInfo.d.ts.map +1 -0
  35. package/lib/families/cardano/api/getNetworkInfo.js +83 -0
  36. package/lib/families/cardano/api/getNetworkInfo.js.map +1 -0
  37. package/lib/families/cardano/api/getTransactions.d.ts +10 -0
  38. package/lib/families/cardano/api/getTransactions.d.ts.map +1 -0
  39. package/lib/families/cardano/api/getTransactions.js +257 -0
  40. package/lib/families/cardano/api/getTransactions.js.map +1 -0
  41. package/lib/families/cardano/api/submitTransaction.d.ts +7 -0
  42. package/lib/families/cardano/api/submitTransaction.d.ts.map +1 -0
  43. package/lib/families/cardano/api/submitTransaction.js +69 -0
  44. package/lib/families/cardano/api/submitTransaction.js.map +1 -0
  45. package/lib/families/cardano/bridge/js.d.ts +8 -0
  46. package/lib/families/cardano/bridge/js.d.ts.map +1 -0
  47. package/lib/families/cardano/bridge/js.js +69 -0
  48. package/lib/families/cardano/bridge/js.js.map +1 -0
  49. package/lib/families/cardano/bridge.test.d.ts +2 -0
  50. package/lib/families/cardano/bridge.test.d.ts.map +1 -0
  51. package/lib/families/cardano/bridge.test.js +11 -0
  52. package/lib/families/cardano/bridge.test.js.map +1 -0
  53. package/lib/families/cardano/buildSubAccounts.d.ts +25 -0
  54. package/lib/families/cardano/buildSubAccounts.d.ts.map +1 -0
  55. package/lib/families/cardano/buildSubAccounts.js +176 -0
  56. package/lib/families/cardano/buildSubAccounts.js.map +1 -0
  57. package/lib/families/cardano/cli-transaction.d.ts +19 -0
  58. package/lib/families/cardano/cli-transaction.d.ts.map +1 -0
  59. package/lib/families/cardano/cli-transaction.js +70 -0
  60. package/lib/families/cardano/cli-transaction.js.map +1 -0
  61. package/lib/families/cardano/constants.d.ts +8 -0
  62. package/lib/families/cardano/constants.d.ts.map +1 -0
  63. package/lib/families/cardano/constants.js +12 -0
  64. package/lib/families/cardano/constants.js.map +1 -0
  65. package/lib/families/cardano/datasets/rawAccount.1.d.ts +3 -0
  66. package/lib/families/cardano/datasets/rawAccount.1.d.ts.map +1 -0
  67. package/lib/families/cardano/datasets/rawAccount.1.js +27 -0
  68. package/lib/families/cardano/datasets/rawAccount.1.js.map +1 -0
  69. package/lib/families/cardano/datasets/scanAccounts.d.ts +5 -0
  70. package/lib/families/cardano/datasets/scanAccounts.d.ts.map +1 -0
  71. package/lib/families/cardano/datasets/scanAccounts.js +10 -0
  72. package/lib/families/cardano/datasets/scanAccounts.js.map +1 -0
  73. package/lib/families/cardano/errors.d.ts +7 -0
  74. package/lib/families/cardano/errors.d.ts.map +1 -0
  75. package/lib/families/cardano/errors.js +9 -0
  76. package/lib/families/cardano/errors.js.map +1 -0
  77. package/lib/families/cardano/hw-getAddress.d.ts +4 -0
  78. package/lib/families/cardano/hw-getAddress.d.ts.map +1 -0
  79. package/lib/families/cardano/hw-getAddress.js +126 -0
  80. package/lib/families/cardano/hw-getAddress.js.map +1 -0
  81. package/lib/families/cardano/js-broadcast.d.ts +8 -0
  82. package/lib/families/cardano/js-broadcast.d.ts.map +1 -0
  83. package/lib/families/cardano/js-broadcast.js +65 -0
  84. package/lib/families/cardano/js-broadcast.js.map +1 -0
  85. package/lib/families/cardano/js-buildTransaction.d.ts +12 -0
  86. package/lib/families/cardano/js-buildTransaction.d.ts.map +1 -0
  87. package/lib/families/cardano/js-buildTransaction.js +253 -0
  88. package/lib/families/cardano/js-buildTransaction.js.map +1 -0
  89. package/lib/families/cardano/js-estimateMaxSpendable.d.ts +15 -0
  90. package/lib/families/cardano/js-estimateMaxSpendable.d.ts.map +1 -0
  91. package/lib/families/cardano/js-estimateMaxSpendable.js +99 -0
  92. package/lib/families/cardano/js-estimateMaxSpendable.js.map +1 -0
  93. package/lib/families/cardano/js-getFeesForTransaction.d.ts +15 -0
  94. package/lib/families/cardano/js-getFeesForTransaction.d.ts.map +1 -0
  95. package/lib/families/cardano/js-getFeesForTransaction.js +61 -0
  96. package/lib/families/cardano/js-getFeesForTransaction.js.map +1 -0
  97. package/lib/families/cardano/js-getTransactionStatus.d.ts +5 -0
  98. package/lib/families/cardano/js-getTransactionStatus.d.ts.map +1 -0
  99. package/lib/families/cardano/js-getTransactionStatus.js +156 -0
  100. package/lib/families/cardano/js-getTransactionStatus.js.map +1 -0
  101. package/lib/families/cardano/js-signOperation.d.ts +13 -0
  102. package/lib/families/cardano/js-signOperation.d.ts.map +1 -0
  103. package/lib/families/cardano/js-signOperation.js +274 -0
  104. package/lib/families/cardano/js-signOperation.js.map +1 -0
  105. package/lib/families/cardano/js-synchronisation.d.ts +11 -0
  106. package/lib/families/cardano/js-synchronisation.d.ts.map +1 -0
  107. package/lib/families/cardano/js-synchronisation.js +247 -0
  108. package/lib/families/cardano/js-synchronisation.js.map +1 -0
  109. package/lib/families/cardano/js-transaction.d.ts +23 -0
  110. package/lib/families/cardano/js-transaction.d.ts.map +1 -0
  111. package/lib/families/cardano/js-transaction.js +112 -0
  112. package/lib/families/cardano/js-transaction.js.map +1 -0
  113. package/lib/families/cardano/logic.d.ts +92 -0
  114. package/lib/families/cardano/logic.d.ts.map +1 -0
  115. package/lib/families/cardano/logic.js +378 -0
  116. package/lib/families/cardano/logic.js.map +1 -0
  117. package/lib/families/cardano/networks.d.ts +3 -0
  118. package/lib/families/cardano/networks.d.ts.map +1 -0
  119. package/lib/families/cardano/networks.js +34 -0
  120. package/lib/families/cardano/networks.js.map +1 -0
  121. package/lib/families/cardano/postSyncPatch.d.ts +7 -0
  122. package/lib/families/cardano/postSyncPatch.d.ts.map +1 -0
  123. package/lib/families/cardano/postSyncPatch.js +37 -0
  124. package/lib/families/cardano/postSyncPatch.js.map +1 -0
  125. package/lib/families/cardano/serialization.d.ts +4 -0
  126. package/lib/families/cardano/serialization.d.ts.map +1 -0
  127. package/lib/families/cardano/serialization.js +121 -0
  128. package/lib/families/cardano/serialization.js.map +1 -0
  129. package/lib/families/cardano/specs.d.ts +7 -0
  130. package/lib/families/cardano/specs.d.ts.map +1 -0
  131. package/lib/families/cardano/specs.js +83 -0
  132. package/lib/families/cardano/specs.js.map +1 -0
  133. package/lib/families/cardano/speculos-deviceActions.d.ts +7 -0
  134. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -0
  135. package/lib/families/cardano/speculos-deviceActions.js +69 -0
  136. package/lib/families/cardano/speculos-deviceActions.js.map +1 -0
  137. package/lib/families/cardano/test-dataset.d.ts +5 -0
  138. package/lib/families/cardano/test-dataset.d.ts.map +1 -0
  139. package/lib/families/cardano/test-dataset.js +42 -0
  140. package/lib/families/cardano/test-dataset.js.map +1 -0
  141. package/lib/families/cardano/transaction.d.ts +12 -0
  142. package/lib/families/cardano/transaction.d.ts.map +1 -0
  143. package/lib/families/cardano/transaction.js +47 -0
  144. package/lib/families/cardano/transaction.js.map +1 -0
  145. package/lib/families/cardano/types.d.ts +152 -0
  146. package/lib/families/cardano/types.d.ts.map +1 -0
  147. package/lib/families/cardano/types.js +18 -0
  148. package/lib/families/cardano/types.js.map +1 -0
  149. package/lib/families/celo/js-synchronisation.d.ts +2 -2
  150. package/lib/families/cosmos/js-synchronisation.d.ts +2 -2
  151. package/lib/families/crypto_org/js-synchronisation.d.ts +2 -2
  152. package/lib/families/elrond/js-synchronisation.d.ts +2 -2
  153. package/lib/families/ethereum/hw-signMessage.d.ts.map +1 -1
  154. package/lib/families/ethereum/hw-signMessage.js +10 -4
  155. package/lib/families/ethereum/hw-signMessage.js.map +1 -1
  156. package/lib/families/filecoin/bridge/account.js +18 -14
  157. package/lib/families/filecoin/bridge/account.js.map +1 -1
  158. package/lib/families/filecoin/bridge/utils/types.d.ts +1 -1
  159. package/lib/families/filecoin/bridge/utils/types.d.ts.map +1 -1
  160. package/lib/families/filecoin/bridge/utils/utils.d.ts +1 -1
  161. package/lib/families/filecoin/bridge/utils/utils.d.ts.map +1 -1
  162. package/lib/families/filecoin/bridge/utils/utils.js +9 -8
  163. package/lib/families/filecoin/bridge/utils/utils.js.map +1 -1
  164. package/lib/families/filecoin/bridge.test.d.ts +2 -0
  165. package/lib/families/filecoin/bridge.test.d.ts.map +1 -0
  166. package/lib/families/filecoin/bridge.test.js +92 -0
  167. package/lib/families/filecoin/bridge.test.js.map +1 -0
  168. package/lib/families/filecoin/specs.d.ts.map +1 -1
  169. package/lib/families/filecoin/specs.js +1 -2
  170. package/lib/families/filecoin/specs.js.map +1 -1
  171. package/lib/families/filecoin/test-dataset.d.ts.map +1 -1
  172. package/lib/families/filecoin/test-dataset.js +8 -9
  173. package/lib/families/filecoin/test-dataset.js.map +1 -1
  174. package/lib/families/hedera/js-synchronisation.d.ts +2 -2
  175. package/lib/families/polkadot/js-synchronisation.d.ts +2 -2
  176. package/lib/families/ripple/js-synchronization.d.ts +2 -2
  177. package/lib/families/stellar/js-synchronization.d.ts +2 -2
  178. package/lib/generated/bridge/js.d.ts +4 -0
  179. package/lib/generated/bridge/js.d.ts.map +1 -1
  180. package/lib/generated/bridge/js.js +30 -28
  181. package/lib/generated/bridge/js.js.map +1 -1
  182. package/lib/generated/cli-transaction.d.ts +15 -0
  183. package/lib/generated/cli-transaction.d.ts.map +1 -1
  184. package/lib/generated/cli-transaction.js +28 -26
  185. package/lib/generated/cli-transaction.js.map +1 -1
  186. package/lib/generated/exchange.d.ts +1 -1
  187. package/lib/generated/hw-getAddress.d.ts +1 -0
  188. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  189. package/lib/generated/hw-getAddress.js +30 -28
  190. package/lib/generated/hw-getAddress.js.map +1 -1
  191. package/lib/generated/specs.d.ts +3 -0
  192. package/lib/generated/specs.d.ts.map +1 -1
  193. package/lib/generated/specs.js +28 -26
  194. package/lib/generated/specs.js.map +1 -1
  195. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  196. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  197. package/lib/generated/speculos-deviceActions.js +28 -26
  198. package/lib/generated/speculos-deviceActions.js.map +1 -1
  199. package/lib/generated/test-dataset.d.ts +1 -0
  200. package/lib/generated/test-dataset.d.ts.map +1 -1
  201. package/lib/generated/test-dataset.js +26 -24
  202. package/lib/generated/test-dataset.js.map +1 -1
  203. package/lib/generated/transaction.d.ts +5 -0
  204. package/lib/generated/transaction.d.ts.map +1 -1
  205. package/lib/generated/transaction.js +30 -28
  206. package/lib/generated/transaction.js.map +1 -1
  207. package/lib/generated/types.d.ts +4 -2
  208. package/lib/generated/types.d.ts.map +1 -1
  209. package/lib/reconciliation.d.ts.map +1 -1
  210. package/lib/reconciliation.js +6 -0
  211. package/lib/reconciliation.js.map +1 -1
  212. package/lib/types/account.d.ts +3 -0
  213. package/lib/types/account.d.ts.map +1 -1
  214. package/package.json +5 -3
  215. package/src/__tests__/test-helpers/setup.ts +2 -0
  216. package/src/account/serialization.ts +15 -0
  217. package/src/cross.ts +2 -1
  218. package/src/derivation.ts +19 -2
  219. package/src/env.ts +16 -1
  220. package/src/errors.ts +1 -0
  221. package/src/families/cardano/__snapshots__/bridge.test.ts.snap +1667 -0
  222. package/src/families/cardano/api/api-types.ts +33 -0
  223. package/src/families/cardano/api/getNetworkInfo.ts +38 -0
  224. package/src/families/cardano/api/getTransactions.ts +240 -0
  225. package/src/families/cardano/api/submitTransaction.ts +27 -0
  226. package/src/families/cardano/bridge/js.ts +35 -0
  227. package/src/families/cardano/bridge.test.ts +6 -0
  228. package/src/families/cardano/buildSubAccounts.ts +182 -0
  229. package/src/families/cardano/cli-transaction.ts +78 -0
  230. package/src/families/cardano/constants.ts +12 -0
  231. package/src/families/cardano/datasets/rawAccount.1.ts +28 -0
  232. package/src/families/cardano/datasets/scanAccounts.ts +23 -0
  233. package/src/families/cardano/errors.ts +8 -0
  234. package/src/families/cardano/hw-getAddress.ts +61 -0
  235. package/src/families/cardano/js-broadcast.ts +25 -0
  236. package/src/families/cardano/js-buildTransaction.ts +293 -0
  237. package/src/families/cardano/js-estimateMaxSpendable.ts +60 -0
  238. package/src/families/cardano/js-getFeesForTransaction.ts +25 -0
  239. package/src/families/cardano/js-getTransactionStatus.ts +123 -0
  240. package/src/families/cardano/js-signOperation.ts +265 -0
  241. package/src/families/cardano/js-synchronisation.ts +255 -0
  242. package/src/families/cardano/js-transaction.ts +69 -0
  243. package/src/families/cardano/logic.ts +454 -0
  244. package/src/families/cardano/networks.ts +33 -0
  245. package/src/families/cardano/postSyncPatch.ts +45 -0
  246. package/src/families/cardano/serialization.ts +179 -0
  247. package/src/families/cardano/specs.ts +96 -0
  248. package/src/families/cardano/speculos-deviceActions.ts +66 -0
  249. package/src/families/cardano/test-dataset.ts +41 -0
  250. package/src/families/cardano/transaction.ts +55 -0
  251. package/src/families/cardano/types.ts +178 -0
  252. package/src/families/ethereum/hw-signMessage.ts +9 -5
  253. package/src/families/filecoin/__snapshots__/bridge.test.ts.snap +87 -0
  254. package/src/families/filecoin/bridge/account.ts +20 -20
  255. package/src/families/filecoin/bridge/utils/types.ts +1 -1
  256. package/src/families/filecoin/bridge/utils/utils.ts +8 -7
  257. package/src/families/filecoin/bridge.test.ts +39 -0
  258. package/src/families/filecoin/specs.ts +1 -2
  259. package/src/families/filecoin/test-dataset.ts +19 -15
  260. package/src/generated/bridge/js.ts +3 -0
  261. package/src/generated/cli-transaction.ts +3 -0
  262. package/src/generated/hw-getAddress.ts +3 -0
  263. package/src/generated/specs.ts +3 -0
  264. package/src/generated/speculos-deviceActions.ts +3 -0
  265. package/src/generated/test-dataset.ts +3 -0
  266. package/src/generated/transaction.ts +3 -0
  267. package/src/generated/types.ts +4 -0
  268. package/src/reconciliation.ts +10 -0
  269. package/src/types/account.ts +6 -0
@@ -0,0 +1,96 @@
1
+ import expect from "expect";
2
+ import type { AppSpec } from "../../bot/types";
3
+ import type { CardanoResources, Transaction } from "./types";
4
+ import { pickSiblings } from "../../bot/specs";
5
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
6
+ import { DeviceModelId } from "@ledgerhq/devices";
7
+ import BigNumber from "bignumber.js";
8
+ import invariant from "invariant";
9
+ import { utils as TyphonUtils } from "@stricahq/typhonjs";
10
+ import { mergeTokens } from "./logic";
11
+ import { parseCurrencyUnit } from "../../currencies";
12
+
13
+ const currency = getCryptoCurrencyById("cardano");
14
+ const minBalanceRequired = parseCurrencyUnit(currency.units[0], "2.2");
15
+ const minBalanceRequiredForMaxSend = parseCurrencyUnit(currency.units[0], "1");
16
+
17
+ const cardano: AppSpec<Transaction> = {
18
+ name: "cardano",
19
+ currency: getCryptoCurrencyById("cardano"),
20
+ appQuery: {
21
+ model: DeviceModelId.nanoS,
22
+ appName: "CardanoADA",
23
+ },
24
+ testTimeout: 2 * 60 * 1000,
25
+ mutations: [
26
+ {
27
+ name: "move ~50%",
28
+ maxRun: 1,
29
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
30
+ invariant(maxSpendable.gt(minBalanceRequired), "balance is too low");
31
+ const sibling = pickSiblings(siblings, 3);
32
+ const recipient = sibling.freshAddress;
33
+ const transaction = bridge.createTransaction(account);
34
+
35
+ const updates = [
36
+ { recipient },
37
+ { amount: new BigNumber(account.balance.dividedBy(2)).dp(0, 1) },
38
+ { memo: "LedgerLiveBot" },
39
+ ];
40
+
41
+ return {
42
+ transaction,
43
+ updates,
44
+ };
45
+ },
46
+ test: ({ operation, transaction }): void => {
47
+ expect(operation.extra).toEqual({
48
+ memo: transaction.memo,
49
+ });
50
+ expect(transaction.amount).toEqual(
51
+ operation.value.minus(operation.fee)
52
+ );
53
+ },
54
+ },
55
+ {
56
+ name: "send max",
57
+ maxRun: 1,
58
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
59
+ invariant(
60
+ maxSpendable.gt(minBalanceRequiredForMaxSend),
61
+ "balance is too low"
62
+ );
63
+ const sibling = pickSiblings(siblings, 3);
64
+ const recipient = sibling.freshAddress;
65
+ const transaction = bridge.createTransaction(account);
66
+
67
+ const updates = [{ recipient }, { useAllAmount: true }];
68
+
69
+ return {
70
+ transaction,
71
+ updates,
72
+ };
73
+ },
74
+ test: ({ accountBeforeTransaction, operation }): void => {
75
+ const cardanoResources =
76
+ accountBeforeTransaction.cardanoResources as CardanoResources;
77
+ const utxoTokens = cardanoResources.utxos.map((u) => u.tokens).flat();
78
+ const tokenBalance = mergeTokens(utxoTokens);
79
+ const requiredAdaForTokens = tokenBalance.length
80
+ ? TyphonUtils.calculateMinUtxoAmount(
81
+ tokenBalance,
82
+ new BigNumber(
83
+ cardanoResources.protocolParams.lovelacePerUtxoWord
84
+ ),
85
+ false
86
+ )
87
+ : new BigNumber(0);
88
+ expect(operation.value).toEqual(
89
+ accountBeforeTransaction.balance.minus(requiredAdaForTokens)
90
+ );
91
+ },
92
+ },
93
+ ],
94
+ };
95
+
96
+ export default { cardano };
@@ -0,0 +1,66 @@
1
+ import type { DeviceAction } from "../../bot/types";
2
+ import type { Transaction } from "./types";
3
+ import { formatCurrencyUnit } from "../../currencies";
4
+ import { deviceActionFlow } from "../../bot/specs";
5
+ import { Unit } from "@ledgerhq/cryptoassets";
6
+ import BigNumber from "bignumber.js";
7
+
8
+ function expectedValue(unit: Unit, value: BigNumber) {
9
+ return formatCurrencyUnit(unit, value, {
10
+ showCode: true,
11
+ disableRounding: true,
12
+ showAllDigits: true,
13
+ });
14
+ }
15
+
16
+ const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
17
+ steps: [
18
+ {
19
+ title: "Start new",
20
+ },
21
+ {
22
+ title: "ordinary transaction?",
23
+ button: "Rr",
24
+ },
25
+ {
26
+ title: "Auxiliary data hash",
27
+ button: "LRlr",
28
+ },
29
+ {
30
+ title: "Send to address",
31
+ button: "LRlr",
32
+ ignoreAssertionFailure: true,
33
+ expectedValue: ({ transaction }) => transaction.recipient,
34
+ },
35
+ {
36
+ title: "Send",
37
+ button: "LRlr",
38
+ ignoreAssertionFailure: true,
39
+ expectedValue: ({ account, status }) =>
40
+ expectedValue(account.unit, status.amount),
41
+ },
42
+ {
43
+ title: "Transaction fee",
44
+ button: "LRlr",
45
+ ignoreAssertionFailure: true,
46
+ expectedValue: ({ account, status }) =>
47
+ expectedValue(account.unit, status.estimatedFees),
48
+ },
49
+ {
50
+ title: "Transaction TTL",
51
+ button: "LRlr",
52
+ },
53
+ {
54
+ title: "...",
55
+ },
56
+ {
57
+ title: "Confirm",
58
+ },
59
+ {
60
+ title: "transaction?",
61
+ button: "Rr",
62
+ },
63
+ ],
64
+ });
65
+
66
+ export default { acceptTransaction };
@@ -0,0 +1,41 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type { DatasetTest } from "../../types";
3
+ import { cardanoRawAccount1 } from "./datasets/rawAccount.1";
4
+ import { cardanoScanAccounts } from "./datasets/scanAccounts";
5
+ import { CardanoMinAmountError } from "./errors";
6
+ import { fromTransactionRaw } from "./transaction";
7
+ import type { Transaction } from "./types";
8
+
9
+ const dataset: DatasetTest<Transaction> = {
10
+ implementations: ["js"],
11
+ currencies: {
12
+ cardano_testnet: {
13
+ scanAccounts: cardanoScanAccounts,
14
+ accounts: [
15
+ {
16
+ raw: cardanoRawAccount1,
17
+ transactions: [
18
+ {
19
+ name: "amount less then minimum",
20
+ transaction: fromTransactionRaw({
21
+ family: "cardano",
22
+ recipient:
23
+ "addr_test1qpl90kc2jl5kr9tev0s7vays9yhwcdnq8nlylyk4dqsdq3g466elxnxwrzwq72pvp5akenj30t5s9et7frfvrxxx8xcsxrzs87",
24
+ amount: "0.1",
25
+ mode: "send",
26
+ }),
27
+ expectedStatus: {
28
+ amount: new BigNumber("0.1"),
29
+ errors: {
30
+ amount: new CardanoMinAmountError(),
31
+ },
32
+ },
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ },
38
+ },
39
+ };
40
+
41
+ export default dataset;
@@ -0,0 +1,55 @@
1
+ import type { Transaction, TransactionRaw } from "./types";
2
+ import { BigNumber } from "bignumber.js";
3
+ import {
4
+ fromTransactionCommonRaw,
5
+ toTransactionCommonRaw,
6
+ } from "../../transaction/common";
7
+ import type { Account } from "../../types";
8
+ import { getAccountUnit } from "../../account";
9
+ import { formatCurrencyUnit } from "../../currencies";
10
+
11
+ export const formatTransaction = (
12
+ { mode, amount, recipient, useAllAmount, subAccountId }: Transaction,
13
+ mainAccount: Account
14
+ ): string => {
15
+ const account =
16
+ (subAccountId &&
17
+ (mainAccount.subAccounts || []).find((a) => a.id === subAccountId)) ||
18
+ mainAccount;
19
+ return `
20
+ ${mode.toUpperCase()} ${
21
+ useAllAmount
22
+ ? "MAX"
23
+ : amount.isZero()
24
+ ? ""
25
+ : " " +
26
+ formatCurrencyUnit(getAccountUnit(account), amount, {
27
+ showCode: true,
28
+ disableRounding: true,
29
+ })
30
+ }${recipient ? `\nTO ${recipient}` : ""}`;
31
+ };
32
+
33
+ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
34
+ const common = fromTransactionCommonRaw(tr);
35
+ return {
36
+ ...common,
37
+ family: tr.family,
38
+ mode: tr.mode,
39
+ fees: tr.fees ? new BigNumber(tr.fees) : undefined,
40
+ memo: tr.memo,
41
+ };
42
+ };
43
+
44
+ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
45
+ const common = toTransactionCommonRaw(t);
46
+ return {
47
+ ...common,
48
+ family: t.family,
49
+ mode: t.mode,
50
+ fees: t.fees?.toString() || undefined,
51
+ memo: t.memo,
52
+ };
53
+ };
54
+
55
+ export default { formatTransaction, fromTransactionRaw, toTransactionRaw };
@@ -0,0 +1,178 @@
1
+ import type { BigNumber } from "bignumber.js";
2
+ import { types as TyphonTypes } from "@stricahq/typhonjs";
3
+ import type {
4
+ TransactionCommon,
5
+ TransactionCommonRaw,
6
+ } from "../../types/transaction";
7
+
8
+ export enum PaymentChain {
9
+ external = 0,
10
+ internal = 1,
11
+ }
12
+
13
+ export enum StakeChain {
14
+ stake = 2,
15
+ }
16
+
17
+ export enum NetworkId {
18
+ testnet = 0,
19
+ mainnet = 1,
20
+ }
21
+
22
+ export type BipPath = {
23
+ purpose: number;
24
+ coin: number;
25
+ account: number;
26
+ chain: PaymentChain | StakeChain;
27
+ index: number;
28
+ };
29
+
30
+ export type BipPathRaw = {
31
+ purpose: number;
32
+ coin: number;
33
+ account: number;
34
+ chain: PaymentChain | StakeChain;
35
+ index: number;
36
+ };
37
+
38
+ export type Token = {
39
+ assetName: string;
40
+ policyId: string;
41
+ amount: BigNumber;
42
+ };
43
+
44
+ export type TokenRaw = {
45
+ assetName: string;
46
+ policyId: string;
47
+ amount: string;
48
+ };
49
+
50
+ export type PaymentKeyPath = {
51
+ key: string;
52
+ path: BipPath;
53
+ };
54
+
55
+ export type PaymentCredential = {
56
+ isUsed: boolean;
57
+ key: string;
58
+ path: BipPath;
59
+ };
60
+
61
+ export type PaymentCredentialRaw = {
62
+ isUsed: boolean;
63
+ key: string;
64
+ path: BipPathRaw;
65
+ };
66
+
67
+ export type StakeCredential = {
68
+ key: string;
69
+ path: BipPath;
70
+ };
71
+
72
+ export type CardanoOutput = {
73
+ hash: string;
74
+ index: number;
75
+ address: string;
76
+ amount: BigNumber;
77
+ tokens: Array<Token>;
78
+ paymentCredential: {
79
+ key: string;
80
+ path: BipPath;
81
+ };
82
+ };
83
+
84
+ export type CardanoOutputRaw = {
85
+ hash: string;
86
+ index: number;
87
+ address: string;
88
+ amount: string;
89
+ tokens: Array<TokenRaw>;
90
+ paymentCredential: {
91
+ key: string;
92
+ path: BipPath;
93
+ };
94
+ };
95
+
96
+ export type ProtocolParams = {
97
+ minFeeA: string;
98
+ minFeeB: string;
99
+ stakeKeyDeposit: string;
100
+ lovelacePerUtxoWord: string;
101
+ collateralPercent: string;
102
+ priceSteps: string;
103
+ priceMem: string;
104
+ languageView: TyphonTypes.LanguageView;
105
+ };
106
+
107
+ export type ProtocolParamsRaw = {
108
+ minFeeA: string;
109
+ minFeeB: string;
110
+ stakeKeyDeposit: string;
111
+ lovelacePerUtxoWord: string;
112
+ collateralPercent: string;
113
+ priceSteps: string;
114
+ priceMem: string;
115
+ // TyphonTypes.LanguageView is already a raw type
116
+ languageView: TyphonTypes.LanguageView;
117
+ };
118
+
119
+ /**
120
+ * Cardano account resources
121
+ */
122
+ export type CardanoResources = {
123
+ externalCredentials: Array<PaymentCredential>;
124
+ internalCredentials: Array<PaymentCredential>;
125
+ utxos: Array<CardanoOutput>;
126
+ protocolParams: ProtocolParams;
127
+ };
128
+
129
+ /**
130
+ * Cardano account resources from raw JSON
131
+ */
132
+ export type CardanoResourcesRaw = {
133
+ externalCredentials: Array<PaymentCredentialRaw>;
134
+ internalCredentials: Array<PaymentCredentialRaw>;
135
+ utxos: Array<CardanoOutputRaw>;
136
+ protocolParams: ProtocolParamsRaw;
137
+ };
138
+
139
+ /**
140
+ * Cardano transaction
141
+ */
142
+ export type Transaction = TransactionCommon & {
143
+ mode: string;
144
+ family: "cardano";
145
+ fees?: BigNumber;
146
+ memo?: string;
147
+ // add here all transaction-specific fields if you implement other modes than "send"
148
+ };
149
+
150
+ /**
151
+ * Cardano transaction from a raw JSON
152
+ */
153
+ export type TransactionRaw = TransactionCommonRaw & {
154
+ family: "cardano";
155
+ mode: string;
156
+ fees?: string;
157
+ memo?: string;
158
+ // also the transaction fields as raw JSON data
159
+ };
160
+
161
+ export type CardanoLikeNetworkParameters = {
162
+ identifier: string;
163
+ networkId: number;
164
+ chainStartTime: number;
165
+ byronSlotDuration: number;
166
+ byronSlotsPerEpoch: number;
167
+ shelleyStartEpoch: number;
168
+ shelleySlotDuration: number;
169
+ shelleySlotsPerEpoch: number;
170
+ addressPrefix: string;
171
+ };
172
+
173
+ /**
174
+ * Cardano currency data that will be preloaded.
175
+ */
176
+ export type CardanoPreloadData = {
177
+ protocolParams: ProtocolParams;
178
+ };
@@ -36,11 +36,15 @@ const resolver: EthResolver = async (
36
36
  if (typeof message === "string") {
37
37
  result = await eth.signPersonalMessage(path, rawMessage.slice(2));
38
38
  } else {
39
- result = await eth.signEIP712HashedMessage(
40
- path,
41
- bufferToHex(domainHash(message)),
42
- bufferToHex(messageHash(message))
43
- );
39
+ if (process.env.EXPERIMENTAL_EIP712) {
40
+ result = await eth.signEIP712Message(path, message);
41
+ } else {
42
+ result = await eth.signEIP712HashedMessage(
43
+ path,
44
+ bufferToHex(domainHash(message)),
45
+ bufferToHex(messageHash(message))
46
+ );
47
+ }
44
48
  }
45
49
 
46
50
  let v: string | number = result["v"] - 27;
@@ -0,0 +1,87 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`filecoin currency bridge scanAccounts filecoin seed 1 1`] = `
4
+ Array [
5
+ Object {
6
+ "balance": "100000000000000000",
7
+ "currencyId": "filecoin",
8
+ "derivationMode": "",
9
+ "freshAddress": "f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a",
10
+ "freshAddressPath": "44'/461'/0'/0/0",
11
+ "freshAddresses": Array [
12
+ Object {
13
+ "address": "f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a",
14
+ "derivationPath": "44'/461'/0'/0/0",
15
+ },
16
+ ],
17
+ "id": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:",
18
+ "index": 0,
19
+ "name": "Filecoin 1",
20
+ "nfts": undefined,
21
+ "operationsCount": 1,
22
+ "pendingOperations": Array [],
23
+ "seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
24
+ "spendableBalance": "100000000000000000",
25
+ "starred": false,
26
+ "swapHistory": Array [],
27
+ "syncHash": undefined,
28
+ "unitMagnitude": 18,
29
+ "used": true,
30
+ },
31
+ Object {
32
+ "balance": "0",
33
+ "currencyId": "filecoin",
34
+ "derivationMode": "",
35
+ "freshAddress": "f1n5rnuefec32bn2aoymugnoi7ah3xi2xynvltnqi",
36
+ "freshAddressPath": "44'/461'/1'/0/0",
37
+ "freshAddresses": Array [
38
+ Object {
39
+ "address": "f1n5rnuefec32bn2aoymugnoi7ah3xi2xynvltnqi",
40
+ "derivationPath": "44'/461'/1'/0/0",
41
+ },
42
+ ],
43
+ "id": "js:2:filecoin:f1n5rnuefec32bn2aoymugnoi7ah3xi2xynvltnqi:",
44
+ "index": 1,
45
+ "name": "Filecoin 2",
46
+ "nfts": undefined,
47
+ "operationsCount": 0,
48
+ "pendingOperations": Array [],
49
+ "seedIdentifier": "04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb0",
50
+ "spendableBalance": "0",
51
+ "starred": false,
52
+ "swapHistory": Array [],
53
+ "syncHash": undefined,
54
+ "unitMagnitude": 18,
55
+ "used": false,
56
+ },
57
+ ]
58
+ `;
59
+
60
+ exports[`filecoin currency bridge scanAccounts filecoin seed 1 2`] = `
61
+ Array [
62
+ Array [
63
+ Object {
64
+ "accountId": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:",
65
+ "blockHash": null,
66
+ "blockHeight": 1802367,
67
+ "contract": undefined,
68
+ "extra": Object {},
69
+ "fee": "0",
70
+ "hash": "bafy2bzaceaztepnzdzbul7nmkef6blk5x2luvbvangrjal25k6xi5qob36k32",
71
+ "id": "js:2:filecoin:f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a:-bafy2bzaceaztepnzdzbul7nmkef6blk5x2luvbvangrjal25k6xi5qob36k32-IN",
72
+ "operator": undefined,
73
+ "recipients": Array [
74
+ "f1p74d4mlmeyc4agflhjqsnvoyzyfdai7fmkyso2a",
75
+ ],
76
+ "senders": Array [
77
+ "f1ov6d42tujoyexkbdh34oik2vhe5unqo2a5ocqoq",
78
+ ],
79
+ "standard": undefined,
80
+ "tokenId": undefined,
81
+ "type": "IN",
82
+ "value": "100000000000000000",
83
+ },
84
+ ],
85
+ Array [],
86
+ ]
87
+ `;
@@ -29,7 +29,7 @@ import { Operation } from "../../../types/operation";
29
29
  import { calculateEstimatedFees, getPath, isError } from "../utils";
30
30
  import { log } from "@ledgerhq/logs";
31
31
  import { getAddressRaw, validateAddress } from "./utils/addresses";
32
- import { patchOperationWithHash } from "../../../operation";
32
+ import { encodeOperationId, patchOperationWithHash } from "../../../operation";
33
33
  import { withDevice } from "../../../hw/deviceAccess";
34
34
 
35
35
  const receive = makeAccountBridgeReceive();
@@ -84,10 +84,12 @@ const getTransactionStatus = async (
84
84
  const estimatedFees = calculateEstimatedFees(gasFeeCap, gasLimit);
85
85
 
86
86
  const totalSpent = useAllAmount ? balance : amount.plus(estimatedFees);
87
- amount = useAllAmount ? balance.minus(estimatedFees) : amount;
88
-
89
- if (amount.lte(0)) errors.amount = new AmountRequired();
90
- if (totalSpent.gt(a.spendableBalance)) errors.amount = new NotEnoughBalance();
87
+ if (totalSpent.gt(a.spendableBalance)) {
88
+ errors.amount = new NotEnoughBalance();
89
+ } else {
90
+ amount = useAllAmount ? balance.minus(estimatedFees) : amount;
91
+ if (amount.lte(0)) errors.amount = new AmountRequired();
92
+ }
91
93
 
92
94
  // log("debug", "[getTransactionStatus] finish fn");
93
95
 
@@ -114,29 +116,27 @@ const estimateMaxSpendable = async ({
114
116
  const a = getMainAccount(account, parentAccount);
115
117
  const { address } = getAddress(a);
116
118
 
119
+ const recipient = transaction?.recipient;
120
+
117
121
  if (!validateAddress(address).isValid) throw new InvalidAddress();
122
+ if (recipient && !validateAddress(recipient).isValid)
123
+ throw new InvalidAddress();
118
124
 
119
125
  const balances = await fetchBalances(address);
120
-
121
126
  const balance = new BigNumber(balances.spendable_balance);
122
127
 
123
- const recipient = transaction?.recipient;
124
- const amount = transaction?.amount;
125
- if (recipient) {
126
- log(
127
- "debug",
128
- "[estimateMaxSpendable] fetching estimated fees to adjust the real max spendable balance"
129
- );
128
+ if (balance.eq(0)) return balance;
130
129
 
131
- if (!validateAddress(recipient).isValid) throw new InvalidAddress();
130
+ const amount = transaction?.amount;
132
131
 
133
- const result = await fetchEstimatedFees({ to: recipient, from: address });
134
- const gasFeeCap = new BigNumber(result.gas_fee_cap);
135
- const gasLimit = new BigNumber(result.gas_limit);
132
+ const result = await fetchEstimatedFees({ to: recipient, from: address });
133
+ const gasFeeCap = new BigNumber(result.gas_fee_cap);
134
+ const gasLimit = new BigNumber(result.gas_limit);
135
+ const estimatedFees = calculateEstimatedFees(gasFeeCap, gasLimit);
136
136
 
137
- balance.minus(calculateEstimatedFees(gasFeeCap, gasLimit));
138
- }
137
+ if (balance.lte(estimatedFees)) return new BigNumber(0);
139
138
 
139
+ balance.minus(estimatedFees);
140
140
  if (amount) balance.minus(amount);
141
141
 
142
142
  // log("debug", "[estimateMaxSpendable] finish fn");
@@ -269,7 +269,7 @@ const signOperation: SignOperationFnSignature<Transaction> = ({
269
269
  const signature = `${result.signature_compact.toString("base64")}`;
270
270
 
271
271
  const operation: Operation = {
272
- id: `${accountId}-${txHash}-OUT`,
272
+ id: encodeOperationId(accountId, txHash, "OUT"),
273
273
  hash: txHash,
274
274
  type: "OUT",
275
275
  senders: [address],
@@ -1,5 +1,5 @@
1
1
  export interface EstimatedFeesRequest {
2
- to: string;
2
+ to?: string;
3
3
  from: string;
4
4
  }
5
5
 
@@ -11,6 +11,7 @@ import {
11
11
  } from "../../../../bridge/jsHelpers";
12
12
  import { fetchBalances, fetchBlockHeight, fetchTxs } from "./api";
13
13
  import { encodeAccountId } from "../../../../account";
14
+ import { encodeOperationId } from "../../../../operation";
14
15
  import flatMap from "lodash/flatMap";
15
16
 
16
17
  type TxsById = {
@@ -48,7 +49,7 @@ export const processTxs = (
48
49
  };
49
50
 
50
51
  export const mapTxToOps =
51
- (id, { address }: GetAccountShapeArg0) =>
52
+ (accountId, { address }: GetAccountShapeArg0) =>
52
53
  (tx: TransactionResponse): Operation[] => {
53
54
  const { to, from, hash, timestamp, amount, fee } = tx;
54
55
  const ops: Operation[] = [];
@@ -61,14 +62,14 @@ export const mapTxToOps =
61
62
 
62
63
  if (isSending) {
63
64
  ops.push({
64
- id: `${id}-${hash}-OUT`,
65
+ id: encodeOperationId(accountId, hash, "OUT"),
65
66
  hash,
66
67
  type: "OUT",
67
68
  value: value.plus(feeToUse),
68
69
  fee: feeToUse,
69
70
  blockHeight: tx.height,
70
71
  blockHash: null,
71
- accountId: id,
72
+ accountId,
72
73
  senders: [from],
73
74
  recipients: [to],
74
75
  date,
@@ -78,14 +79,14 @@ export const mapTxToOps =
78
79
 
79
80
  if (isReceiving) {
80
81
  ops.push({
81
- id: `${id}-${hash}-IN`,
82
+ id: encodeOperationId(accountId, hash, "IN"),
82
83
  hash,
83
84
  type: "IN",
84
85
  value,
85
86
  fee: feeToUse,
86
87
  blockHeight: tx.height,
87
88
  blockHash: null,
88
- accountId: id,
89
+ accountId,
89
90
  senders: [from],
90
91
  recipients: [to],
91
92
  date,
@@ -137,14 +138,14 @@ export const getTxToBroadcast = (
137
138
  };
138
139
 
139
140
  export const getAccountShape: GetAccountShape = async (info) => {
140
- const { address, currency } = info;
141
+ const { address, currency, derivationMode } = info;
141
142
 
142
143
  const accountId = encodeAccountId({
143
144
  type: "js",
144
145
  version: "2",
145
146
  currencyId: currency.id,
146
147
  xpubOrAddress: address,
147
- derivationMode: "",
148
+ derivationMode,
148
149
  });
149
150
 
150
151
  const blockHeight = await fetchBlockHeight();