@ledgerhq/coin-casper 1.4.0-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 (304) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.unimportedrc.json +49 -0
  3. package/CHANGELOG.md +15 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/lib/api/index.d.ts +11 -0
  7. package/lib/api/index.d.ts.map +1 -0
  8. package/lib/api/index.js +129 -0
  9. package/lib/api/index.js.map +1 -0
  10. package/lib/api/types.d.ts +105 -0
  11. package/lib/api/types.d.ts.map +1 -0
  12. package/lib/api/types.js +3 -0
  13. package/lib/api/types.js.map +1 -0
  14. package/lib/bridge/bridgeHelpers/accountShape.d.ts +3 -0
  15. package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
  16. package/lib/bridge/bridgeHelpers/accountShape.js +38 -0
  17. package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -0
  18. package/lib/bridge/bridgeHelpers/addresses.d.ts +18 -0
  19. package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  20. package/lib/bridge/bridgeHelpers/addresses.js +83 -0
  21. package/lib/bridge/bridgeHelpers/addresses.js.map +1 -0
  22. package/lib/bridge/bridgeHelpers/fee.d.ts +3 -0
  23. package/lib/bridge/bridgeHelpers/fee.d.ts.map +1 -0
  24. package/lib/bridge/bridgeHelpers/fee.js +13 -0
  25. package/lib/bridge/bridgeHelpers/fee.js.map +1 -0
  26. package/lib/bridge/bridgeHelpers/transferId.d.ts +2 -0
  27. package/lib/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
  28. package/lib/bridge/bridgeHelpers/transferId.js +14 -0
  29. package/lib/bridge/bridgeHelpers/transferId.js.map +1 -0
  30. package/lib/bridge/bridgeHelpers/txn.d.ts +9 -0
  31. package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  32. package/lib/bridge/bridgeHelpers/txn.js +100 -0
  33. package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
  34. package/lib/bridge/broadcast.d.ts +4 -0
  35. package/lib/bridge/broadcast.d.ts.map +1 -0
  36. package/lib/bridge/broadcast.js +15 -0
  37. package/lib/bridge/broadcast.js.map +1 -0
  38. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  39. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  40. package/lib/bridge/buildOptimisticOperation.js +27 -0
  41. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  42. package/lib/bridge/createTransaction.d.ts +4 -0
  43. package/lib/bridge/createTransaction.d.ts.map +1 -0
  44. package/lib/bridge/createTransaction.js +19 -0
  45. package/lib/bridge/createTransaction.js.map +1 -0
  46. package/lib/bridge/deviceTransactionConfig.d.ts +18 -0
  47. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  48. package/lib/bridge/deviceTransactionConfig.js +26 -0
  49. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  50. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  51. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  52. package/lib/bridge/estimateMaxSpendable.js +23 -0
  53. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  54. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  55. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  56. package/lib/bridge/getTransactionStatus.js +75 -0
  57. package/lib/bridge/getTransactionStatus.js.map +1 -0
  58. package/lib/bridge/index.d.ts +8 -0
  59. package/lib/bridge/index.d.ts.map +1 -0
  60. package/lib/bridge/index.js +54 -0
  61. package/lib/bridge/index.js.map +1 -0
  62. package/lib/bridge/prepareTransaction.d.ts +4 -0
  63. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  64. package/lib/bridge/prepareTransaction.js +16 -0
  65. package/lib/bridge/prepareTransaction.js.map +1 -0
  66. package/lib/bridge/signOperation.d.ts +6 -0
  67. package/lib/bridge/signOperation.d.ts.map +1 -0
  68. package/lib/bridge/signOperation.js +47 -0
  69. package/lib/bridge/signOperation.js.map +1 -0
  70. package/lib/bridge/transaction.d.ts +14 -0
  71. package/lib/bridge/transaction.d.ts.map +1 -0
  72. package/lib/bridge/transaction.js +53 -0
  73. package/lib/bridge/transaction.js.map +1 -0
  74. package/lib/common-logic/index.d.ts +2 -0
  75. package/lib/common-logic/index.d.ts.map +1 -0
  76. package/lib/common-logic/index.js +13 -0
  77. package/lib/common-logic/index.js.map +1 -0
  78. package/lib/common-logic/utils.d.ts +14 -0
  79. package/lib/common-logic/utils.d.ts.map +1 -0
  80. package/lib/common-logic/utils.js +53 -0
  81. package/lib/common-logic/utils.js.map +1 -0
  82. package/lib/common-logic/utils.unit.test.d.ts +2 -0
  83. package/lib/common-logic/utils.unit.test.d.ts.map +1 -0
  84. package/lib/common-logic/utils.unit.test.js +50 -0
  85. package/lib/common-logic/utils.unit.test.js.map +1 -0
  86. package/lib/consts.d.ts +10 -0
  87. package/lib/consts.d.ts.map +1 -0
  88. package/lib/consts.js +18 -0
  89. package/lib/consts.js.map +1 -0
  90. package/lib/errors.d.ts +10 -0
  91. package/lib/errors.d.ts.map +1 -0
  92. package/lib/errors.js +8 -0
  93. package/lib/errors.js.map +1 -0
  94. package/lib/hw-signMessage.d.ts +23 -0
  95. package/lib/hw-signMessage.d.ts.map +1 -0
  96. package/lib/hw-signMessage.js +24 -0
  97. package/lib/hw-signMessage.js.map +1 -0
  98. package/lib/signer/getAddress.d.ts +6 -0
  99. package/lib/signer/getAddress.d.ts.map +1 -0
  100. package/lib/signer/getAddress.js +25 -0
  101. package/lib/signer/getAddress.js.map +1 -0
  102. package/lib/signer/index.d.ts +3 -0
  103. package/lib/signer/index.d.ts.map +1 -0
  104. package/lib/signer/index.js +8 -0
  105. package/lib/signer/index.js.map +1 -0
  106. package/lib/test/bot-specs.d.ts +7 -0
  107. package/lib/test/bot-specs.d.ts.map +1 -0
  108. package/lib/test/bot-specs.js +110 -0
  109. package/lib/test/bot-specs.js.map +1 -0
  110. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  111. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  112. package/lib/test/bridgeDatasetTest.js +177 -0
  113. package/lib/test/bridgeDatasetTest.js.map +1 -0
  114. package/lib/test/cli.d.ts +15 -0
  115. package/lib/test/cli.d.ts.map +1 -0
  116. package/lib/test/cli.js +30 -0
  117. package/lib/test/cli.js.map +1 -0
  118. package/lib/test/index.d.ts +4 -0
  119. package/lib/test/index.d.ts.map +1 -0
  120. package/lib/test/index.js +20 -0
  121. package/lib/test/index.js.map +1 -0
  122. package/lib/test/speculos-deviceActions.d.ts +4 -0
  123. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  124. package/lib/test/speculos-deviceActions.js +53 -0
  125. package/lib/test/speculos-deviceActions.js.map +1 -0
  126. package/lib/types/common.d.ts +23 -0
  127. package/lib/types/common.d.ts.map +1 -0
  128. package/lib/types/common.js +3 -0
  129. package/lib/types/common.js.map +1 -0
  130. package/lib/types/index.d.ts +3 -0
  131. package/lib/types/index.d.ts.map +1 -0
  132. package/lib/types/index.js +19 -0
  133. package/lib/types/index.js.map +1 -0
  134. package/lib/types/signer.d.ts +21 -0
  135. package/lib/types/signer.d.ts.map +1 -0
  136. package/lib/types/signer.js +3 -0
  137. package/lib/types/signer.js.map +1 -0
  138. package/lib-es/api/index.d.ts +11 -0
  139. package/lib-es/api/index.d.ts.map +1 -0
  140. package/lib-es/api/index.js +118 -0
  141. package/lib-es/api/index.js.map +1 -0
  142. package/lib-es/api/types.d.ts +105 -0
  143. package/lib-es/api/types.d.ts.map +1 -0
  144. package/lib-es/api/types.js +2 -0
  145. package/lib-es/api/types.js.map +1 -0
  146. package/lib-es/bridge/bridgeHelpers/accountShape.d.ts +3 -0
  147. package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
  148. package/lib-es/bridge/bridgeHelpers/accountShape.js +31 -0
  149. package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -0
  150. package/lib-es/bridge/bridgeHelpers/addresses.d.ts +18 -0
  151. package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  152. package/lib-es/bridge/bridgeHelpers/addresses.js +74 -0
  153. package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -0
  154. package/lib-es/bridge/bridgeHelpers/fee.d.ts +3 -0
  155. package/lib-es/bridge/bridgeHelpers/fee.d.ts.map +1 -0
  156. package/lib-es/bridge/bridgeHelpers/fee.js +6 -0
  157. package/lib-es/bridge/bridgeHelpers/fee.js.map +1 -0
  158. package/lib-es/bridge/bridgeHelpers/transferId.d.ts +2 -0
  159. package/lib-es/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
  160. package/lib-es/bridge/bridgeHelpers/transferId.js +10 -0
  161. package/lib-es/bridge/bridgeHelpers/transferId.js.map +1 -0
  162. package/lib-es/bridge/bridgeHelpers/txn.d.ts +9 -0
  163. package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
  164. package/lib-es/bridge/bridgeHelpers/txn.js +91 -0
  165. package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
  166. package/lib-es/bridge/broadcast.d.ts +4 -0
  167. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  168. package/lib-es/bridge/broadcast.js +11 -0
  169. package/lib-es/bridge/broadcast.js.map +1 -0
  170. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  171. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  172. package/lib-es/bridge/buildOptimisticOperation.js +23 -0
  173. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  174. package/lib-es/bridge/createTransaction.d.ts +4 -0
  175. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  176. package/lib-es/bridge/createTransaction.js +12 -0
  177. package/lib-es/bridge/createTransaction.js.map +1 -0
  178. package/lib-es/bridge/deviceTransactionConfig.d.ts +18 -0
  179. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  180. package/lib-es/bridge/deviceTransactionConfig.js +24 -0
  181. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  182. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  183. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  184. package/lib-es/bridge/estimateMaxSpendable.js +16 -0
  185. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  186. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  187. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  188. package/lib-es/bridge/getTransactionStatus.js +68 -0
  189. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  190. package/lib-es/bridge/index.d.ts +8 -0
  191. package/lib-es/bridge/index.d.ts.map +1 -0
  192. package/lib-es/bridge/index.js +47 -0
  193. package/lib-es/bridge/index.js.map +1 -0
  194. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  195. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  196. package/lib-es/bridge/prepareTransaction.js +12 -0
  197. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  198. package/lib-es/bridge/signOperation.d.ts +6 -0
  199. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  200. package/lib-es/bridge/signOperation.js +43 -0
  201. package/lib-es/bridge/signOperation.js.map +1 -0
  202. package/lib-es/bridge/transaction.d.ts +14 -0
  203. package/lib-es/bridge/transaction.d.ts.map +1 -0
  204. package/lib-es/bridge/transaction.js +45 -0
  205. package/lib-es/bridge/transaction.js.map +1 -0
  206. package/lib-es/common-logic/index.d.ts +2 -0
  207. package/lib-es/common-logic/index.d.ts.map +1 -0
  208. package/lib-es/common-logic/index.js +2 -0
  209. package/lib-es/common-logic/index.js.map +1 -0
  210. package/lib-es/common-logic/utils.d.ts +14 -0
  211. package/lib-es/common-logic/utils.d.ts.map +1 -0
  212. package/lib-es/common-logic/utils.js +39 -0
  213. package/lib-es/common-logic/utils.js.map +1 -0
  214. package/lib-es/common-logic/utils.unit.test.d.ts +2 -0
  215. package/lib-es/common-logic/utils.unit.test.d.ts.map +1 -0
  216. package/lib-es/common-logic/utils.unit.test.js +48 -0
  217. package/lib-es/common-logic/utils.unit.test.js.map +1 -0
  218. package/lib-es/consts.d.ts +10 -0
  219. package/lib-es/consts.d.ts.map +1 -0
  220. package/lib-es/consts.js +15 -0
  221. package/lib-es/consts.js.map +1 -0
  222. package/lib-es/errors.d.ts +10 -0
  223. package/lib-es/errors.d.ts.map +1 -0
  224. package/lib-es/errors.js +5 -0
  225. package/lib-es/errors.js.map +1 -0
  226. package/lib-es/hw-signMessage.d.ts +23 -0
  227. package/lib-es/hw-signMessage.d.ts.map +1 -0
  228. package/lib-es/hw-signMessage.js +20 -0
  229. package/lib-es/hw-signMessage.js.map +1 -0
  230. package/lib-es/signer/getAddress.d.ts +6 -0
  231. package/lib-es/signer/getAddress.d.ts.map +1 -0
  232. package/lib-es/signer/getAddress.js +23 -0
  233. package/lib-es/signer/getAddress.js.map +1 -0
  234. package/lib-es/signer/index.d.ts +3 -0
  235. package/lib-es/signer/index.d.ts.map +1 -0
  236. package/lib-es/signer/index.js +3 -0
  237. package/lib-es/signer/index.js.map +1 -0
  238. package/lib-es/test/bot-specs.d.ts +7 -0
  239. package/lib-es/test/bot-specs.d.ts.map +1 -0
  240. package/lib-es/test/bot-specs.js +105 -0
  241. package/lib-es/test/bot-specs.js.map +1 -0
  242. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  243. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  244. package/lib-es/test/bridgeDatasetTest.js +171 -0
  245. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  246. package/lib-es/test/cli.d.ts +15 -0
  247. package/lib-es/test/cli.d.ts.map +1 -0
  248. package/lib-es/test/cli.js +24 -0
  249. package/lib-es/test/cli.js.map +1 -0
  250. package/lib-es/test/index.d.ts +4 -0
  251. package/lib-es/test/index.d.ts.map +1 -0
  252. package/lib-es/test/index.js +4 -0
  253. package/lib-es/test/index.js.map +1 -0
  254. package/lib-es/test/speculos-deviceActions.d.ts +4 -0
  255. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  256. package/lib-es/test/speculos-deviceActions.js +50 -0
  257. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  258. package/lib-es/types/common.d.ts +23 -0
  259. package/lib-es/types/common.d.ts.map +1 -0
  260. package/lib-es/types/common.js +2 -0
  261. package/lib-es/types/common.js.map +1 -0
  262. package/lib-es/types/index.d.ts +3 -0
  263. package/lib-es/types/index.d.ts.map +1 -0
  264. package/lib-es/types/index.js +3 -0
  265. package/lib-es/types/index.js.map +1 -0
  266. package/lib-es/types/signer.d.ts +21 -0
  267. package/lib-es/types/signer.d.ts.map +1 -0
  268. package/lib-es/types/signer.js +2 -0
  269. package/lib-es/types/signer.js.map +1 -0
  270. package/package.json +127 -0
  271. package/src/api/index.ts +166 -0
  272. package/src/api/types.ts +113 -0
  273. package/src/bridge/bridgeHelpers/accountShape.ts +39 -0
  274. package/src/bridge/bridgeHelpers/addresses.ts +94 -0
  275. package/src/bridge/bridgeHelpers/fee.ts +6 -0
  276. package/src/bridge/bridgeHelpers/transferId.ts +9 -0
  277. package/src/bridge/bridgeHelpers/txn.ts +121 -0
  278. package/src/bridge/broadcast.ts +18 -0
  279. package/src/bridge/buildOptimisticOperation.ts +31 -0
  280. package/src/bridge/createTransaction.ts +15 -0
  281. package/src/bridge/deviceTransactionConfig.ts +46 -0
  282. package/src/bridge/estimateMaxSpendable.ts +26 -0
  283. package/src/bridge/getTransactionStatus.ts +96 -0
  284. package/src/bridge/index.ts +65 -0
  285. package/src/bridge/prepareTransaction.ts +19 -0
  286. package/src/bridge/signOperation.ts +73 -0
  287. package/src/bridge/transaction.ts +61 -0
  288. package/src/common-logic/index.ts +10 -0
  289. package/src/common-logic/utils.ts +53 -0
  290. package/src/common-logic/utils.unit.test.ts +75 -0
  291. package/src/consts.ts +18 -0
  292. package/src/errors.ts +5 -0
  293. package/src/hw-signMessage.ts +30 -0
  294. package/src/signer/getAddress.ts +31 -0
  295. package/src/signer/index.ts +3 -0
  296. package/src/test/bot-specs.ts +127 -0
  297. package/src/test/bridgeDatasetTest.ts +178 -0
  298. package/src/test/cli.ts +36 -0
  299. package/src/test/index.ts +3 -0
  300. package/src/test/speculos-deviceActions.ts +54 -0
  301. package/src/types/common.ts +38 -0
  302. package/src/types/index.ts +2 -0
  303. package/src/types/signer.ts +20 -0
  304. package/tsconfig.json +15 -0
@@ -0,0 +1,127 @@
1
+ import invariant from "invariant";
2
+ import { DeviceModelId } from "@ledgerhq/devices";
3
+ import BigNumber from "bignumber.js";
4
+ import expect from "expect";
5
+ import type { Transaction } from "../types";
6
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
7
+ import { genericTestDestination, pickSiblings, botTest } from "@ledgerhq/coin-framework/bot/specs";
8
+ import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
9
+ import { acceptTransaction } from "./speculos-deviceActions";
10
+ import { CASPER_MINIMUM_VALID_AMOUNT_MOTES, MayBlockAccountError } from "../consts";
11
+ import { getRandomTransferID } from "../common-logic";
12
+
13
+ const MIN_SAFE = new BigNumber(CASPER_MINIMUM_VALID_AMOUNT_MOTES * 2);
14
+ const maxAccount = 6;
15
+
16
+ const casperSpecs: AppSpec<Transaction> = {
17
+ name: "Casper",
18
+ currency: getCryptoCurrencyById("casper"),
19
+ appQuery: {
20
+ model: DeviceModelId.nanoSP,
21
+ appName: "Casper",
22
+ },
23
+ genericDeviceAction: acceptTransaction,
24
+ testTimeout: 6 * 60 * 1000,
25
+ minViableAmount: MIN_SAFE,
26
+ transactionCheck: ({ maxSpendable }) => {
27
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
28
+ },
29
+ mutations: [
30
+ {
31
+ name: "Send ~50%",
32
+ feature: "send",
33
+ maxRun: 1,
34
+ testDestination: genericTestDestination,
35
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
36
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
37
+ const sibling = pickSiblings(siblings, maxAccount);
38
+ const recipient = sibling.freshAddress;
39
+ const amount = maxSpendable.div(2).integerValue();
40
+
41
+ const transaction = bridge.createTransaction(account);
42
+ const updates: Array<Partial<Transaction>> = [
43
+ {
44
+ recipient,
45
+ },
46
+ { amount },
47
+ ];
48
+
49
+ if (Math.random() < 0.5) {
50
+ updates.push({
51
+ transferId: getRandomTransferID(),
52
+ });
53
+ }
54
+
55
+ return {
56
+ transaction,
57
+ updates,
58
+ };
59
+ },
60
+
61
+ test: ({ accountBeforeTransaction, operation, account, transaction }) => {
62
+ botTest("account spendable balance decreased with operation", () =>
63
+ expect(account.spendableBalance).toEqual(
64
+ accountBeforeTransaction.spendableBalance.minus(operation.value),
65
+ ),
66
+ );
67
+
68
+ if (transaction.transferId) {
69
+ botTest("operation transferId", () =>
70
+ expect(operation.extra).toMatchObject({
71
+ transferId: transaction.transferId,
72
+ }),
73
+ );
74
+ }
75
+ },
76
+ },
77
+ {
78
+ name: "Transfer Max",
79
+ feature: "sendMax",
80
+ maxRun: 1,
81
+ transaction: ({ account, siblings, bridge }) => {
82
+ const updates: Array<Partial<Transaction>> = [
83
+ {
84
+ recipient: pickSiblings(siblings, maxAccount).freshAddress,
85
+ },
86
+ {
87
+ useAllAmount: true,
88
+ },
89
+ ];
90
+
91
+ if (Math.random() < 0.5) {
92
+ updates.push({
93
+ transferId: getRandomTransferID(),
94
+ });
95
+ }
96
+
97
+ return {
98
+ transaction: bridge.createTransaction(account),
99
+ updates,
100
+ };
101
+ },
102
+ expectStatusWarnings: _ => {
103
+ return {
104
+ amount: MayBlockAccountError,
105
+ };
106
+ },
107
+ testDestination: genericTestDestination,
108
+ test: ({ account, transaction, operation }) => {
109
+ botTest("account spendable balance is zero", () =>
110
+ expect(account.spendableBalance.toString()).toBe("0"),
111
+ );
112
+
113
+ if (transaction.transferId) {
114
+ botTest("operation transferId", () =>
115
+ expect(operation.extra).toMatchObject({
116
+ transferId: transaction.transferId,
117
+ }),
118
+ );
119
+ }
120
+ },
121
+ },
122
+ ],
123
+ };
124
+
125
+ export default {
126
+ casperSpecs,
127
+ };
@@ -0,0 +1,178 @@
1
+ import type { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "../types";
3
+ import { fromTransactionRaw } from "../bridge/transaction";
4
+ import BigNumber from "bignumber.js";
5
+ import { AmountRequired, InvalidAddress, NotEnoughBalance } from "@ledgerhq/errors";
6
+ import { CasperInvalidTransferId, InvalidMinimumAmount, MayBlockAccount } from "../errors";
7
+ import { getEstimatedFees } from "../bridge/bridgeHelpers/fee";
8
+
9
+ const SEED_IDENTIFIER = "0202ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b01581";
10
+ const RECIPIENT_ADDRESS_SECP256k1 =
11
+ "0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB";
12
+ const RECIPIENT_ADDRESS_EDSA25519 =
13
+ "0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB";
14
+
15
+ const casper: CurrenciesData<Transaction> = {
16
+ scanAccounts: [
17
+ {
18
+ name: "casper seed 1",
19
+ apdus: `
20
+ => 11010000142c000080fa010080000000800000000000000000
21
+ <= 038c8cb0f62b4efcd0c7868c2e749dda649affe30ff0f95fc91ce48ea67f077d1630323033384338636230663632623445466344304337383638633265373439446461363439614646453330664630663935666339314345343845413637463037374431369000
22
+ => 11010000142c000080fa010080000000800000000001000000
23
+ <= 02ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b0158130323032624136444339386362453637373731316134356266303238413033363436463965353838393936654232323366616432343835653862633339316230313538319000
24
+ => 11010000142c000080fa010080000000800000000002000000
25
+ <= 022aab9b6ed404f8cffe76ce493e1995d195b5f141ee7d5b7fb20fce60f2a4969130323032324141423942364544343034663843464645373663653439334531393935643139354235463134314565374435423766623230464345363066324134393639319000
26
+ `,
27
+ },
28
+ ],
29
+ accounts: [
30
+ {
31
+ raw: {
32
+ id: `js:2:casper:${SEED_IDENTIFIER}:casper_wallet`,
33
+ seedIdentifier: SEED_IDENTIFIER,
34
+ name: "Casper 1",
35
+ derivationMode: "casper_wallet" as const,
36
+ index: 0,
37
+ freshAddress: SEED_IDENTIFIER,
38
+ freshAddressPath: "44'/506'/0'/0/1",
39
+ blockHeight: 0,
40
+ operations: [],
41
+ pendingOperations: [],
42
+ currencyId: "casper",
43
+ lastSyncDate: "",
44
+ balance: "1000",
45
+ },
46
+ transactions: [
47
+ {
48
+ name: "not a valid address",
49
+ transaction: fromTransactionRaw({
50
+ family: "casper",
51
+ recipient: "novalidaddress",
52
+ fees: getEstimatedFees().toString(),
53
+ amount: "1000",
54
+ }),
55
+ expectedStatus: {
56
+ errors: {
57
+ recipient: new InvalidAddress(),
58
+ },
59
+ warnings: {},
60
+ },
61
+ },
62
+ {
63
+ name: "not enough balance",
64
+ transaction: fromTransactionRaw({
65
+ family: "casper",
66
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
67
+ fees: getEstimatedFees().toString(),
68
+ amount: (300 * 1e9).toString(),
69
+ }),
70
+ expectedStatus: {
71
+ errors: {
72
+ amount: new NotEnoughBalance(),
73
+ },
74
+ warnings: {},
75
+ },
76
+ },
77
+ {
78
+ name: "amount required",
79
+ transaction: fromTransactionRaw({
80
+ family: "casper",
81
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
82
+ amount: "0",
83
+ fees: getEstimatedFees().toString(),
84
+ }),
85
+ expectedStatus: {
86
+ errors: {
87
+ amount: new AmountRequired(),
88
+ },
89
+ warnings: {},
90
+ },
91
+ },
92
+ {
93
+ name: "minimum amount required",
94
+ transaction: fromTransactionRaw({
95
+ family: "casper",
96
+ fees: getEstimatedFees().toString(),
97
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
98
+ amount: "1",
99
+ }),
100
+
101
+ expectedStatus: {
102
+ errors: {
103
+ amount: new InvalidMinimumAmount(),
104
+ },
105
+ warnings: {},
106
+ },
107
+ },
108
+ {
109
+ name: "sufficient amount - recipient address secp256k1",
110
+ transaction: fromTransactionRaw({
111
+ family: "casper",
112
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
113
+ amount: "3",
114
+ fees: getEstimatedFees().toString(),
115
+ }),
116
+ expectedStatus: {
117
+ amount: new BigNumber("3"),
118
+ errors: {},
119
+ warnings: {},
120
+ },
121
+ },
122
+ {
123
+ name: "sufficient amount - recipient address ed25519",
124
+ transaction: fromTransactionRaw({
125
+ family: "casper",
126
+ recipient: RECIPIENT_ADDRESS_EDSA25519,
127
+ amount: "3",
128
+ fees: getEstimatedFees().toString(),
129
+ }),
130
+ expectedStatus: {
131
+ amount: new BigNumber("3"),
132
+ errors: {},
133
+ warnings: {},
134
+ },
135
+ },
136
+ {
137
+ name: "invalid transferID",
138
+ transaction: fromTransactionRaw({
139
+ family: "casper",
140
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
141
+ fees: getEstimatedFees().toString(),
142
+ amount: "3",
143
+ transferId: "afdsaf1",
144
+ }),
145
+ expectedStatus: {
146
+ amount: new BigNumber("3"),
147
+ errors: {
148
+ sender: new CasperInvalidTransferId(),
149
+ },
150
+ warnings: {},
151
+ },
152
+ },
153
+ {
154
+ name: "may block account warning",
155
+ transaction: fromTransactionRaw({
156
+ family: "casper",
157
+ recipient: RECIPIENT_ADDRESS_SECP256k1,
158
+ fees: getEstimatedFees().toString(),
159
+ amount: (999 * 1e9).toString(),
160
+ }),
161
+ expectedStatus: {
162
+ errors: {},
163
+ warnings: {
164
+ amount: new MayBlockAccount(),
165
+ },
166
+ },
167
+ },
168
+ ],
169
+ },
170
+ ],
171
+ };
172
+
173
+ export const dataset: DatasetTest<Transaction> = {
174
+ implementations: ["js"],
175
+ currencies: {
176
+ casper,
177
+ },
178
+ };
@@ -0,0 +1,36 @@
1
+ import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
2
+ import invariant from "invariant";
3
+ import flatMap from "lodash/flatMap";
4
+ import type { Transaction } from "../types";
5
+
6
+ function inferAccounts(account: Account): AccountLikeArray {
7
+ invariant(account.currency.family === "casper", "casper family");
8
+
9
+ const accounts: Account[] = [account];
10
+ return accounts;
11
+ }
12
+
13
+ function inferTransactions(
14
+ transactions: Array<{
15
+ account: AccountLike;
16
+ transaction: Transaction;
17
+ mainAccount: Account;
18
+ }>,
19
+ ): Transaction[] {
20
+ return flatMap(transactions, ({ transaction }) => {
21
+ invariant(transaction.family === "casper", "casper family");
22
+
23
+ return {
24
+ ...transaction,
25
+ family: "casper",
26
+ } as Transaction;
27
+ });
28
+ }
29
+
30
+ export default function makeCliTools() {
31
+ return {
32
+ options: [],
33
+ inferAccounts,
34
+ inferTransactions,
35
+ };
36
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./bridgeDatasetTest";
2
+ export * from "./bot-specs";
3
+ export * from "./speculos-deviceActions";
@@ -0,0 +1,54 @@
1
+ import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
2
+ import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
3
+ import { casperGetCLPublicKey } from "../bridge/bridgeHelpers/addresses";
4
+ import type { Transaction } from "../types";
5
+
6
+ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
7
+ steps: [
8
+ {
9
+ title: "Please",
10
+ button: SpeculosButton.RIGHT,
11
+ expectedValue: () => "review",
12
+ },
13
+ {
14
+ title: "Txn hash",
15
+ button: SpeculosButton.RIGHT,
16
+ },
17
+ {
18
+ title: "Type",
19
+ button: SpeculosButton.RIGHT,
20
+ expectedValue: () => "Token transfer",
21
+ },
22
+ {
23
+ title: "Chain ID",
24
+ button: SpeculosButton.RIGHT,
25
+ expectedValue: () => "casper",
26
+ },
27
+ {
28
+ title: "Account",
29
+ button: SpeculosButton.RIGHT,
30
+ expectedValue: ({ account }) => casperGetCLPublicKey(account.freshAddress).toHex(true),
31
+ },
32
+ {
33
+ title: "Fee",
34
+ button: SpeculosButton.RIGHT,
35
+ expectedValue: ({ transaction }) =>
36
+ `${transaction.fees.toNumber().toLocaleString("en-US").replace(/,/g, " ")} motes`,
37
+ },
38
+ {
39
+ title: "Target",
40
+ button: SpeculosButton.RIGHT,
41
+ expectedValue: ({ transaction }) => casperGetCLPublicKey(transaction.recipient).toHex(true),
42
+ },
43
+ {
44
+ title: "Amount",
45
+ button: SpeculosButton.RIGHT,
46
+ expectedValue: ({ status }) =>
47
+ `${status.amount.toNumber().toLocaleString("en-US").replace(/,/g, " ")} motes`,
48
+ },
49
+ {
50
+ title: "APPROVE",
51
+ button: SpeculosButton.BOTH,
52
+ },
53
+ ],
54
+ });
@@ -0,0 +1,38 @@
1
+ import {
2
+ Account,
3
+ Operation,
4
+ TransactionCommon,
5
+ TransactionCommonRaw,
6
+ TransactionStatusCommon,
7
+ TransactionStatusCommonRaw,
8
+ } from "@ledgerhq/types-live";
9
+ import BigNumber from "bignumber.js";
10
+ import { ExtraDeviceTransactionField } from "../bridge/deviceTransactionConfig";
11
+
12
+ type FamilyType = "casper";
13
+
14
+ export type CasperAccount = Account;
15
+
16
+ export type Transaction = TransactionCommon & {
17
+ family: FamilyType;
18
+ fees: BigNumber;
19
+ transferId?: string | undefined;
20
+ };
21
+
22
+ export type CasperOperation = Operation<CasperOperationExtra>;
23
+
24
+ interface CasperOperationExtra {
25
+ transferId?: string | undefined;
26
+ }
27
+
28
+ export type TransactionRaw = TransactionCommonRaw & {
29
+ family: FamilyType;
30
+ transferId?: string | undefined;
31
+ fees: string;
32
+ };
33
+
34
+ export type TransactionStatus = TransactionStatusCommon;
35
+
36
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
37
+
38
+ export type { ExtraDeviceTransactionField };
@@ -0,0 +1,2 @@
1
+ export * from "./common";
2
+ export * from "./signer";
@@ -0,0 +1,20 @@
1
+ export type CasperSignature = {
2
+ errorMessage: string;
3
+ returnCode: number;
4
+ signatureRS: Buffer;
5
+ signatureRSV: Buffer;
6
+ signature_compact: Uint8Array;
7
+ };
8
+
9
+ export type CasperGetAddrResponse = {
10
+ errorMessage: string;
11
+ returnCode: number;
12
+ publicKey: Buffer;
13
+ Address: any;
14
+ };
15
+
16
+ export interface CasperSigner {
17
+ showAddressAndPubKey(path: string): Promise<CasperGetAddrResponse>;
18
+ getAddressAndPubKey(path: string): Promise<CasperGetAddrResponse>;
19
+ sign(path: string, message: Buffer): Promise<CasperSignature>;
20
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "downlevelIteration": true,
7
+ "lib": ["es2020", "dom"],
8
+ "rootDir": "./src",
9
+ "outDir": "lib",
10
+ "exactOptionalPropertyTypes": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "bundler"
13
+ },
14
+ "include": ["src/**/*", "deviceTransactionConfig.ts", "transaction.ts"]
15
+ }