@ledgerhq/coin-casper 1.7.3 → 2.0.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 (278) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +11 -35
  3. package/CHANGELOG.md +14 -0
  4. package/jest.config.js +2 -5
  5. package/lib/api/index.d.ts +8 -6
  6. package/lib/api/index.d.ts.map +1 -1
  7. package/lib/api/index.integ.test.js +12 -3
  8. package/lib/api/index.integ.test.js.map +1 -1
  9. package/lib/api/index.js +53 -91
  10. package/lib/api/index.js.map +1 -1
  11. package/lib/api/index.test.d.ts +2 -0
  12. package/lib/api/index.test.d.ts.map +1 -0
  13. package/lib/api/index.test.js +274 -0
  14. package/lib/api/index.test.js.map +1 -0
  15. package/lib/api/types.d.ts +2 -67
  16. package/lib/api/types.d.ts.map +1 -1
  17. package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -1
  18. package/lib/bridge/bridgeHelpers/accountShape.js +5 -7
  19. package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -1
  20. package/lib/bridge/bridgeHelpers/accountShape.test.d.ts +2 -0
  21. package/lib/bridge/bridgeHelpers/accountShape.test.d.ts.map +1 -0
  22. package/lib/bridge/bridgeHelpers/accountShape.test.js +94 -0
  23. package/lib/bridge/bridgeHelpers/accountShape.test.js.map +1 -0
  24. package/lib/bridge/bridgeHelpers/addresses.d.ts +3 -9
  25. package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
  26. package/lib/bridge/bridgeHelpers/addresses.js +5 -62
  27. package/lib/bridge/bridgeHelpers/addresses.js.map +1 -1
  28. package/lib/bridge/bridgeHelpers/txn.d.ts +2 -2
  29. package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -1
  30. package/lib/bridge/bridgeHelpers/txn.js +9 -11
  31. package/lib/bridge/bridgeHelpers/txn.js.map +1 -1
  32. package/lib/bridge/bridgeHelpers/txn.test.d.ts +2 -0
  33. package/lib/bridge/bridgeHelpers/txn.test.d.ts.map +1 -0
  34. package/lib/bridge/bridgeHelpers/txn.test.js +306 -0
  35. package/lib/bridge/bridgeHelpers/txn.test.js.map +1 -0
  36. package/lib/bridge/broadcast.d.ts.map +1 -1
  37. package/lib/bridge/broadcast.js +7 -6
  38. package/lib/bridge/broadcast.js.map +1 -1
  39. package/lib/bridge/broadcast.test.d.ts +2 -0
  40. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  41. package/lib/bridge/broadcast.test.js +72 -0
  42. package/lib/bridge/broadcast.test.js.map +1 -0
  43. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  44. package/lib/bridge/buildOptimisticOperation.js +2 -0
  45. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  46. package/lib/bridge/buildOptimisticOperation.test.d.ts +2 -0
  47. package/lib/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  48. package/lib/bridge/buildOptimisticOperation.test.js +76 -0
  49. package/lib/bridge/buildOptimisticOperation.test.js.map +1 -0
  50. package/lib/bridge/createTransaction.test.d.ts +2 -0
  51. package/lib/bridge/createTransaction.test.d.ts.map +1 -0
  52. package/lib/bridge/createTransaction.test.js +41 -0
  53. package/lib/bridge/createTransaction.test.js.map +1 -0
  54. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
  55. package/lib/bridge/deviceTransactionConfig.js +13 -0
  56. package/lib/bridge/deviceTransactionConfig.js.map +1 -1
  57. package/lib/bridge/deviceTransactionConfig.test.d.ts +2 -0
  58. package/lib/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  59. package/lib/bridge/deviceTransactionConfig.test.js +148 -0
  60. package/lib/bridge/deviceTransactionConfig.test.js.map +1 -0
  61. package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
  62. package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  63. package/lib/bridge/estimateMaxSpendable.test.js +133 -0
  64. package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
  65. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  66. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  67. package/lib/bridge/getTransactionStatus.test.js +214 -0
  68. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  69. package/lib/bridge/index.d.ts +2 -1
  70. package/lib/bridge/index.d.ts.map +1 -1
  71. package/lib/bridge/index.js +3 -1
  72. package/lib/bridge/index.js.map +1 -1
  73. package/lib/bridge/prepareTransaction.js +1 -1
  74. package/lib/bridge/prepareTransaction.js.map +1 -1
  75. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  76. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  77. package/lib/bridge/prepareTransaction.test.js +159 -0
  78. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  79. package/lib/bridge/signOperation.d.ts.map +1 -1
  80. package/lib/bridge/signOperation.js +14 -12
  81. package/lib/bridge/signOperation.js.map +1 -1
  82. package/lib/bridge/transaction.test.d.ts +2 -0
  83. package/lib/bridge/transaction.test.d.ts.map +1 -0
  84. package/lib/bridge/transaction.test.js +179 -0
  85. package/lib/bridge/transaction.test.js.map +1 -0
  86. package/lib/common-logic/utils.additional.test.d.ts +2 -0
  87. package/lib/common-logic/utils.additional.test.d.ts.map +1 -0
  88. package/lib/common-logic/utils.additional.test.js +58 -0
  89. package/lib/common-logic/utils.additional.test.js.map +1 -0
  90. package/lib/common-logic/utils.unit.test.js +6 -4
  91. package/lib/common-logic/utils.unit.test.js.map +1 -1
  92. package/lib/config.d.ts +10 -0
  93. package/lib/config.d.ts.map +1 -0
  94. package/lib/config.js +16 -0
  95. package/lib/config.js.map +1 -0
  96. package/lib/consts.d.ts +3 -0
  97. package/lib/consts.d.ts.map +1 -1
  98. package/lib/consts.js +5 -1
  99. package/lib/consts.js.map +1 -1
  100. package/lib/hw-signMessage.test.d.ts +2 -0
  101. package/lib/hw-signMessage.test.d.ts.map +1 -0
  102. package/lib/hw-signMessage.test.js +80 -0
  103. package/lib/hw-signMessage.test.js.map +1 -0
  104. package/lib/signer/getAddress.js +1 -1
  105. package/lib/signer/getAddress.js.map +1 -1
  106. package/lib/signer/getAddress.test.d.ts +2 -0
  107. package/lib/signer/getAddress.test.d.ts.map +1 -0
  108. package/lib/signer/getAddress.test.js +133 -0
  109. package/lib/signer/getAddress.test.js.map +1 -0
  110. package/lib/test/bot-specs.d.ts.map +1 -1
  111. package/lib/test/bot-specs.js +1 -0
  112. package/lib/test/bot-specs.js.map +1 -1
  113. package/lib/test/fixtures.d.ts +131 -0
  114. package/lib/test/fixtures.d.ts.map +1 -0
  115. package/lib/test/fixtures.js +395 -0
  116. package/lib/test/fixtures.js.map +1 -0
  117. package/lib/test/index.d.ts +2 -0
  118. package/lib/test/index.d.ts.map +1 -1
  119. package/lib/test/index.js +2 -0
  120. package/lib/test/index.js.map +1 -1
  121. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  122. package/lib/test/speculos-deviceActions.js +4 -3
  123. package/lib/test/speculos-deviceActions.js.map +1 -1
  124. package/lib-es/api/index.d.ts +8 -6
  125. package/lib-es/api/index.d.ts.map +1 -1
  126. package/lib-es/api/index.integ.test.js +13 -4
  127. package/lib-es/api/index.integ.test.js.map +1 -1
  128. package/lib-es/api/index.js +51 -90
  129. package/lib-es/api/index.js.map +1 -1
  130. package/lib-es/api/index.test.d.ts +2 -0
  131. package/lib-es/api/index.test.d.ts.map +1 -0
  132. package/lib-es/api/index.test.js +269 -0
  133. package/lib-es/api/index.test.js.map +1 -0
  134. package/lib-es/api/types.d.ts +2 -67
  135. package/lib-es/api/types.d.ts.map +1 -1
  136. package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -1
  137. package/lib-es/bridge/bridgeHelpers/accountShape.js +6 -8
  138. package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -1
  139. package/lib-es/bridge/bridgeHelpers/accountShape.test.d.ts +2 -0
  140. package/lib-es/bridge/bridgeHelpers/accountShape.test.d.ts.map +1 -0
  141. package/lib-es/bridge/bridgeHelpers/accountShape.test.js +89 -0
  142. package/lib-es/bridge/bridgeHelpers/accountShape.test.js.map +1 -0
  143. package/lib-es/bridge/bridgeHelpers/addresses.d.ts +3 -9
  144. package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
  145. package/lib-es/bridge/bridgeHelpers/addresses.js +5 -60
  146. package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -1
  147. package/lib-es/bridge/bridgeHelpers/txn.d.ts +2 -2
  148. package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -1
  149. package/lib-es/bridge/bridgeHelpers/txn.js +10 -12
  150. package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -1
  151. package/lib-es/bridge/bridgeHelpers/txn.test.d.ts +2 -0
  152. package/lib-es/bridge/bridgeHelpers/txn.test.d.ts.map +1 -0
  153. package/lib-es/bridge/bridgeHelpers/txn.test.js +278 -0
  154. package/lib-es/bridge/bridgeHelpers/txn.test.js.map +1 -0
  155. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  156. package/lib-es/bridge/broadcast.js +8 -7
  157. package/lib-es/bridge/broadcast.js.map +1 -1
  158. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  159. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  160. package/lib-es/bridge/broadcast.test.js +70 -0
  161. package/lib-es/bridge/broadcast.test.js.map +1 -0
  162. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  163. package/lib-es/bridge/buildOptimisticOperation.js +2 -0
  164. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  165. package/lib-es/bridge/buildOptimisticOperation.test.d.ts +2 -0
  166. package/lib-es/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  167. package/lib-es/bridge/buildOptimisticOperation.test.js +74 -0
  168. package/lib-es/bridge/buildOptimisticOperation.test.js.map +1 -0
  169. package/lib-es/bridge/createTransaction.test.d.ts +2 -0
  170. package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
  171. package/lib-es/bridge/createTransaction.test.js +36 -0
  172. package/lib-es/bridge/createTransaction.test.js.map +1 -0
  173. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
  174. package/lib-es/bridge/deviceTransactionConfig.js +13 -0
  175. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
  176. package/lib-es/bridge/deviceTransactionConfig.test.d.ts +2 -0
  177. package/lib-es/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  178. package/lib-es/bridge/deviceTransactionConfig.test.js +143 -0
  179. package/lib-es/bridge/deviceTransactionConfig.test.js.map +1 -0
  180. package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
  181. package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  182. package/lib-es/bridge/estimateMaxSpendable.test.js +131 -0
  183. package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
  184. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  185. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  186. package/lib-es/bridge/getTransactionStatus.test.js +212 -0
  187. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  188. package/lib-es/bridge/index.d.ts +2 -1
  189. package/lib-es/bridge/index.d.ts.map +1 -1
  190. package/lib-es/bridge/index.js +3 -1
  191. package/lib-es/bridge/index.js.map +1 -1
  192. package/lib-es/bridge/prepareTransaction.js +1 -1
  193. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  194. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  195. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  196. package/lib-es/bridge/prepareTransaction.test.js +157 -0
  197. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  198. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  199. package/lib-es/bridge/signOperation.js +16 -14
  200. package/lib-es/bridge/signOperation.js.map +1 -1
  201. package/lib-es/bridge/transaction.test.d.ts +2 -0
  202. package/lib-es/bridge/transaction.test.d.ts.map +1 -0
  203. package/lib-es/bridge/transaction.test.js +154 -0
  204. package/lib-es/bridge/transaction.test.js.map +1 -0
  205. package/lib-es/common-logic/utils.additional.test.d.ts +2 -0
  206. package/lib-es/common-logic/utils.additional.test.d.ts.map +1 -0
  207. package/lib-es/common-logic/utils.additional.test.js +56 -0
  208. package/lib-es/common-logic/utils.additional.test.js.map +1 -0
  209. package/lib-es/common-logic/utils.unit.test.js +7 -5
  210. package/lib-es/common-logic/utils.unit.test.js.map +1 -1
  211. package/lib-es/config.d.ts +10 -0
  212. package/lib-es/config.d.ts.map +1 -0
  213. package/lib-es/config.js +11 -0
  214. package/lib-es/config.js.map +1 -0
  215. package/lib-es/consts.d.ts +3 -0
  216. package/lib-es/consts.d.ts.map +1 -1
  217. package/lib-es/consts.js +4 -0
  218. package/lib-es/consts.js.map +1 -1
  219. package/lib-es/hw-signMessage.test.d.ts +2 -0
  220. package/lib-es/hw-signMessage.test.d.ts.map +1 -0
  221. package/lib-es/hw-signMessage.test.js +78 -0
  222. package/lib-es/hw-signMessage.test.js.map +1 -0
  223. package/lib-es/signer/getAddress.js +2 -2
  224. package/lib-es/signer/getAddress.js.map +1 -1
  225. package/lib-es/signer/getAddress.test.d.ts +2 -0
  226. package/lib-es/signer/getAddress.test.d.ts.map +1 -0
  227. package/lib-es/signer/getAddress.test.js +105 -0
  228. package/lib-es/signer/getAddress.test.js.map +1 -0
  229. package/lib-es/test/bot-specs.d.ts.map +1 -1
  230. package/lib-es/test/bot-specs.js +1 -0
  231. package/lib-es/test/bot-specs.js.map +1 -1
  232. package/lib-es/test/fixtures.d.ts +131 -0
  233. package/lib-es/test/fixtures.d.ts.map +1 -0
  234. package/lib-es/test/fixtures.js +381 -0
  235. package/lib-es/test/fixtures.js.map +1 -0
  236. package/lib-es/test/index.d.ts +2 -0
  237. package/lib-es/test/index.d.ts.map +1 -1
  238. package/lib-es/test/index.js +2 -0
  239. package/lib-es/test/index.js.map +1 -1
  240. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  241. package/lib-es/test/speculos-deviceActions.js +5 -4
  242. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  243. package/package.json +17 -12
  244. package/src/api/index.integ.test.ts +14 -4
  245. package/src/api/index.test.ts +386 -0
  246. package/src/api/index.ts +59 -117
  247. package/src/api/types.ts +2 -75
  248. package/src/bridge/bridgeHelpers/accountShape.test.ts +122 -0
  249. package/src/bridge/bridgeHelpers/accountShape.ts +7 -9
  250. package/src/bridge/bridgeHelpers/addresses.ts +6 -73
  251. package/src/bridge/bridgeHelpers/txn.test.ts +339 -0
  252. package/src/bridge/bridgeHelpers/txn.ts +18 -18
  253. package/src/bridge/broadcast.test.ts +89 -0
  254. package/src/bridge/broadcast.ts +9 -7
  255. package/src/bridge/buildOptimisticOperation.test.ts +89 -0
  256. package/src/bridge/buildOptimisticOperation.ts +2 -0
  257. package/src/bridge/createTransaction.test.ts +43 -0
  258. package/src/bridge/deviceTransactionConfig.test.ts +171 -0
  259. package/src/bridge/deviceTransactionConfig.ts +14 -0
  260. package/src/bridge/estimateMaxSpendable.test.ts +155 -0
  261. package/src/bridge/getTransactionStatus.test.ts +264 -0
  262. package/src/bridge/index.ts +8 -1
  263. package/src/bridge/prepareTransaction.test.ts +174 -0
  264. package/src/bridge/prepareTransaction.ts +1 -1
  265. package/src/bridge/signOperation.ts +16 -25
  266. package/src/bridge/transaction.test.ts +182 -0
  267. package/src/common-logic/utils.additional.test.ts +75 -0
  268. package/src/common-logic/utils.unit.test.ts +9 -7
  269. package/src/config.ts +22 -0
  270. package/src/consts.ts +5 -0
  271. package/src/hw-signMessage.test.ts +123 -0
  272. package/src/signer/getAddress.test.ts +134 -0
  273. package/src/signer/getAddress.ts +2 -2
  274. package/src/test/bot-specs.ts +1 -0
  275. package/src/test/fixtures.ts +448 -0
  276. package/src/test/index.ts +2 -0
  277. package/src/test/speculos-deviceActions.ts +6 -4
  278. package/tsconfig.json +1 -4
@@ -0,0 +1,448 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account, Operation, OperationType } from "@ledgerhq/types-live";
3
+ import type { Transaction, CasperOperation } from "../types";
4
+ import { getEstimatedFees } from "../bridge/bridgeHelpers/fee";
5
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
7
+ import { CASPER_MINIMUM_VALID_AMOUNT_MOTES } from "../consts";
8
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
9
+ import { ITxnHistoryData } from "../api/types";
10
+ import { DerivationMode } from "@ledgerhq/types-live";
11
+
12
+ /**
13
+ * Sample Casper addresses for testing
14
+ */
15
+ export const TEST_ADDRESSES = {
16
+ // Sample public key for SECP256K1 derivation
17
+ SECP256K1: "0202ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b01581",
18
+ // Sample recipient address for SECP256K1 format
19
+ RECIPIENT_SECP256K1: "0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB",
20
+ // Sample recipient address for ED25519 format
21
+ RECIPIENT_ED25519: "01e28f293af356e7a15068e535c248ec07c887b2ab7a5d9557037a0e998e5d97bf",
22
+ // Invalid address for negative tests
23
+ INVALID: "notavalidaddress",
24
+ };
25
+
26
+ /**
27
+ * Sample transaction hashes for testing
28
+ */
29
+ export const TEST_TRANSACTION_HASHES = {
30
+ VALID: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
31
+ PENDING: "pending0123456789abcdef0123456789abcdef0123456789abcdef01234567",
32
+ FAILED: "failed00123456789abcdef0123456789abcdef0123456789abcdef01234567",
33
+ };
34
+
35
+ /**
36
+ * Sample transfer IDs for testing
37
+ */
38
+ export const TEST_TRANSFER_IDS = {
39
+ VALID: "123456",
40
+ NUMERIC: "654321",
41
+ INVALID: "not-a-valid-id",
42
+ };
43
+
44
+ /**
45
+ * Create a mock Casper account for testing
46
+ *
47
+ * @param options Optional parameters to override default values
48
+ * @returns A mock Casper account
49
+ */
50
+ export const createMockAccount = (options?: Partial<Account>): Account => {
51
+ const seedIdentifier = options?.seedIdentifier || TEST_ADDRESSES.SECP256K1;
52
+ const currency = getCryptoCurrencyById("casper");
53
+
54
+ const account: Account = {
55
+ id: `js:2:casper:${seedIdentifier}:casper_wallet`,
56
+ seedIdentifier,
57
+ derivationMode: "casper_wallet",
58
+ index: options?.index || 0,
59
+ freshAddress: options?.freshAddress || seedIdentifier,
60
+ freshAddressPath: options?.freshAddressPath || "44'/506'/0'/0/1",
61
+ blockHeight: options?.blockHeight || 0,
62
+ balance:
63
+ options?.balance instanceof BigNumber
64
+ ? options.balance
65
+ : new BigNumber(options?.balance || "10000000000"), // 10 CSPR
66
+ spendableBalance:
67
+ options?.spendableBalance instanceof BigNumber
68
+ ? options.spendableBalance
69
+ : new BigNumber(options?.spendableBalance || "10000000000"), // 10 CSPR
70
+ operations: options?.operations || [],
71
+ pendingOperations: options?.pendingOperations || [],
72
+ type: "Account",
73
+ swapHistory: [],
74
+ syncHash: undefined,
75
+ nfts: [],
76
+ used: true,
77
+ currency,
78
+ operationsCount: 0,
79
+ subAccounts: [],
80
+ creationDate: new Date(),
81
+ lastSyncDate: new Date(),
82
+ balanceHistoryCache: {
83
+ HOUR: { latestDate: null, balances: [] },
84
+ DAY: { latestDate: null, balances: [] },
85
+ WEEK: { latestDate: null, balances: [] },
86
+ },
87
+ };
88
+
89
+ return { ...account, ...options };
90
+ };
91
+
92
+ /**
93
+ * Create a mock Casper transaction for testing
94
+ *
95
+ * @param options Optional parameters to override default values
96
+ * @returns A mock Casper transaction
97
+ */
98
+ export const createMockTransaction = (options?: Partial<Transaction>): Transaction => {
99
+ const defaultFees = getEstimatedFees();
100
+
101
+ const transaction: Transaction = {
102
+ family: "casper",
103
+ amount:
104
+ options?.amount instanceof BigNumber
105
+ ? options.amount
106
+ : new BigNumber(options?.amount || CASPER_MINIMUM_VALID_AMOUNT_MOTES),
107
+ recipient: options?.recipient || TEST_ADDRESSES.RECIPIENT_SECP256K1,
108
+ fees: options?.fees instanceof BigNumber ? options.fees : defaultFees,
109
+ transferId: options?.transferId,
110
+ useAllAmount: options?.useAllAmount || false,
111
+ };
112
+
113
+ return { ...transaction, ...options };
114
+ };
115
+
116
+ /**
117
+ * Create a mock Casper operation for testing
118
+ *
119
+ * @param account The account associated with the operation
120
+ * @param transaction The transaction details
121
+ * @param options Optional parameters to override default values
122
+ * @returns A mock Casper operation
123
+ */
124
+ export const createMockOperation = (
125
+ account: Account,
126
+ transaction: Transaction,
127
+ options?: Partial<Operation>,
128
+ ): CasperOperation => {
129
+ const hash = options?.hash || "0x" + Math.random().toString(16).substring(2, 10);
130
+ const type = (options?.type as OperationType) || "OUT";
131
+
132
+ const operation: CasperOperation = {
133
+ id: options?.id || encodeOperationId(account.id, hash, type),
134
+ hash,
135
+ type,
136
+ senders: [account.freshAddress],
137
+ recipients: [transaction.recipient],
138
+ accountId: account.id,
139
+ blockHash: options?.blockHash || null,
140
+ blockHeight: options?.blockHeight || null,
141
+ value: transaction.amount.plus(transaction.fees),
142
+ fee: transaction.fees,
143
+ date: options?.date || new Date(),
144
+ extra: {
145
+ transferId: transaction.transferId,
146
+ },
147
+ nftOperations: [],
148
+ subOperations: [],
149
+ };
150
+
151
+ return { ...operation, ...options } as CasperOperation;
152
+ };
153
+
154
+ /**
155
+ * Creates a set of accounts with different balances and statuses for comprehensive testing
156
+ *
157
+ * @returns An array of mock Casper accounts
158
+ */
159
+ export const createMockAccountSet = (): Account[] => {
160
+ return [
161
+ // Standard account with balance
162
+ createMockAccount(),
163
+
164
+ // Empty account
165
+ createMockAccount({
166
+ balance: new BigNumber("0"),
167
+ spendableBalance: new BigNumber("0"),
168
+ }),
169
+
170
+ // Account with pending operations
171
+ createMockAccount({
172
+ pendingOperations: [
173
+ createMockOperation(
174
+ createMockAccount(),
175
+ createMockTransaction({ amount: new BigNumber("500000000") }),
176
+ { type: "OUT", id: "pending-op-1" },
177
+ ),
178
+ ],
179
+ }),
180
+
181
+ // Account with high balance
182
+ createMockAccount({
183
+ balance: new BigNumber("100000000000000"), // 100,000 CSPR
184
+ spendableBalance: new BigNumber("100000000000000"),
185
+ }),
186
+ ];
187
+ };
188
+
189
+ /**
190
+ * Creates a set of transactions with different parameters for validation testing
191
+ *
192
+ * @returns An array of mock Casper transactions
193
+ */
194
+ export const createMockTransactionSet = (): Transaction[] => {
195
+ return [
196
+ // Standard valid transaction
197
+ createMockTransaction({
198
+ amount: new BigNumber("1000000000"), // 1 CSPR
199
+ }),
200
+
201
+ // Transaction with invalid recipient
202
+ createMockTransaction({
203
+ recipient: TEST_ADDRESSES.INVALID,
204
+ }),
205
+
206
+ // Transaction with zero amount (should fail validation)
207
+ createMockTransaction({
208
+ amount: new BigNumber("0"),
209
+ }),
210
+
211
+ // Transaction with very high amount (should trigger warnings)
212
+ createMockTransaction({
213
+ amount: new BigNumber("999000000000"), // 999 CSPR
214
+ }),
215
+
216
+ // Transaction with transfer ID
217
+ createMockTransaction({
218
+ transferId: TEST_TRANSFER_IDS.VALID,
219
+ }),
220
+
221
+ // Transaction with invalid transfer ID
222
+ createMockTransaction({
223
+ transferId: TEST_TRANSFER_IDS.INVALID,
224
+ }),
225
+
226
+ // Transaction with useAllAmount flag
227
+ createMockTransaction({
228
+ useAllAmount: true,
229
+ }),
230
+ ];
231
+ };
232
+
233
+ /**
234
+ * Creates a set of operations with different types and statuses for testing
235
+ *
236
+ * @param account The account to associate with the operations
237
+ * @returns An array of mock Casper operations
238
+ */
239
+ export const createMockOperationSet = (account: Account): CasperOperation[] => {
240
+ const standardTx = createMockTransaction({
241
+ amount: new BigNumber("1000000000"),
242
+ });
243
+
244
+ const largeTx = createMockTransaction({
245
+ amount: new BigNumber("5000000000"),
246
+ });
247
+
248
+ const smallTx = createMockTransaction({
249
+ amount: new BigNumber("100000000"),
250
+ });
251
+
252
+ const transferIdTx = createMockTransaction({
253
+ transferId: TEST_TRANSFER_IDS.VALID,
254
+ });
255
+
256
+ // Create operations with different dates for sorting tests
257
+ const now = new Date();
258
+ const yesterday = new Date(now);
259
+ yesterday.setDate(yesterday.getDate() - 1);
260
+ const lastWeek = new Date(now);
261
+ lastWeek.setDate(lastWeek.getDate() - 7);
262
+ const lastMonth = new Date(now);
263
+ lastMonth.setMonth(lastMonth.getMonth() - 1);
264
+
265
+ return [
266
+ // Standard OUT operation
267
+ createMockOperation(account, standardTx, {
268
+ type: "OUT",
269
+ hash: "0xoutoperation1",
270
+ date: now,
271
+ }),
272
+
273
+ // IN operation
274
+ createMockOperation(account, standardTx, {
275
+ type: "IN",
276
+ hash: "0xinoperation1",
277
+ date: yesterday,
278
+ senders: [TEST_ADDRESSES.RECIPIENT_SECP256K1], // Override sender
279
+ }),
280
+
281
+ // Large amount operation
282
+ createMockOperation(account, largeTx, {
283
+ type: "OUT",
284
+ hash: "0xoutlarge1",
285
+ date: lastWeek,
286
+ }),
287
+
288
+ // Small amount operation
289
+ createMockOperation(account, smallTx, {
290
+ type: "OUT",
291
+ hash: "0xoutsmall1",
292
+ date: lastMonth,
293
+ }),
294
+
295
+ // Operation with transfer ID
296
+ createMockOperation(account, transferIdTx, {
297
+ type: "OUT",
298
+ hash: "0xtransferid1",
299
+ date: lastMonth,
300
+ }),
301
+
302
+ // Operation with block height
303
+ createMockOperation(account, standardTx, {
304
+ type: "OUT",
305
+ hash: "0xwithblock1",
306
+ blockHeight: 12345,
307
+ blockHash: "0xblockhash123",
308
+ date: lastMonth,
309
+ }),
310
+ ];
311
+ };
312
+
313
+ /**
314
+ * Creates a mock signed operation for testing broadcast functionality
315
+ *
316
+ * @param account The account associated with the operation
317
+ * @param transaction The transaction to create the signed operation from
318
+ * @param options Optional parameters to override default values
319
+ * @returns A mock signed operation
320
+ */
321
+ export const createMockSignedOperation = (
322
+ account: Account,
323
+ transaction: Transaction,
324
+ options?: {
325
+ signature?: string;
326
+ rawTxJson?: object;
327
+ operationOptions?: Partial<Operation>;
328
+ },
329
+ ) => {
330
+ const operation = createMockOperation(account, transaction, options?.operationOptions);
331
+
332
+ return {
333
+ signature: options?.signature || "deadbeef1234567890abcdef",
334
+ operation,
335
+ rawData: {
336
+ tx: JSON.stringify(
337
+ options?.rawTxJson || {
338
+ hash: TEST_TRANSACTION_HASHES.VALID,
339
+ header: {
340
+ account: account.freshAddress,
341
+ timestamp: new Date().getTime(),
342
+ },
343
+ payment: {
344
+ target: transaction.recipient,
345
+ amount: transaction.amount.toString(),
346
+ },
347
+ fee: transaction.fees.toString(),
348
+ },
349
+ ),
350
+ },
351
+ };
352
+ };
353
+
354
+ /**
355
+ * Creates mock data for testing account shape functionality
356
+ *
357
+ * @returns Object containing mock data for account shape tests
358
+ */
359
+ export const createMockAccountShapeData = () => {
360
+ const mockAddress = TEST_ADDRESSES.SECP256K1;
361
+ const mockCurrency = getCryptoCurrencyById("casper");
362
+ const mockDerivationMode: DerivationMode = "casper_wallet";
363
+ const mockAccountInfo = {
364
+ address: mockAddress,
365
+ currency: mockCurrency,
366
+ derivationMode: mockDerivationMode,
367
+ index: 0,
368
+ derivationPath: "44'/506'/0'/0/0",
369
+ };
370
+
371
+ const mockAccountId = encodeAccountId({
372
+ type: "js",
373
+ version: "2",
374
+ currencyId: mockCurrency.id,
375
+ xpubOrAddress: mockAddress,
376
+ derivationMode: mockDerivationMode,
377
+ });
378
+
379
+ const mockBlockHeight = 12345;
380
+ const mockPurseUref = "uref-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef-007";
381
+ const mockAccountHash =
382
+ "account-hash-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
383
+ const mockBalance = new BigNumber("1000000000");
384
+
385
+ const mockTxs: ITxnHistoryData[] = [
386
+ {
387
+ deploy_hash: "deploy-hash-1",
388
+ block_hash: "block-hash-1",
389
+ caller_public_key: mockAddress,
390
+ execution_type_id: 1,
391
+ cost: "10000",
392
+ payment_amount: "100000000",
393
+ timestamp: "2023-01-01T12:00:00Z",
394
+ status: "success",
395
+ args: {
396
+ id: {
397
+ parsed: 12345,
398
+ cl_type: {
399
+ Option: "U64",
400
+ },
401
+ },
402
+ amount: {
403
+ parsed: "500000000",
404
+ cl_type: "U512",
405
+ },
406
+ target: {
407
+ parsed: TEST_ADDRESSES.RECIPIENT_SECP256K1,
408
+ cl_type: "PublicKey",
409
+ },
410
+ },
411
+ amount: "500000000",
412
+ },
413
+ ];
414
+
415
+ const mockOperations = [
416
+ {
417
+ id: "mock-operation-id",
418
+ hash: "deploy-hash-1",
419
+ type: "OUT",
420
+ value: new BigNumber("550000000"),
421
+ fee: new BigNumber("50000000"),
422
+ blockHeight: 12345,
423
+ blockHash: null,
424
+ hasFailed: false,
425
+ accountId: mockAccountId,
426
+ senders: [mockAccountHash],
427
+ recipients: ["recipient-account-hash"],
428
+ date: new Date("2023-01-01T12:00:00Z"),
429
+ extra: {
430
+ transferId: "12345",
431
+ },
432
+ },
433
+ ];
434
+
435
+ return {
436
+ mockAddress,
437
+ mockCurrency,
438
+ mockDerivationMode,
439
+ mockAccountInfo,
440
+ mockAccountId,
441
+ mockBlockHeight,
442
+ mockPurseUref,
443
+ mockAccountHash,
444
+ mockBalance,
445
+ mockTxs,
446
+ mockOperations,
447
+ };
448
+ };
package/src/test/index.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./bridgeDatasetTest";
2
2
  export * from "./bot-specs";
3
3
  export * from "./speculos-deviceActions";
4
+ export * from "./cli";
5
+ export * from "./fixtures";
@@ -1,7 +1,9 @@
1
1
  import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
2
2
  import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
3
- import { casperGetCLPublicKey } from "../bridge/bridgeHelpers/addresses";
3
+
4
4
  import type { Transaction } from "../types";
5
+ import { casperAccountHashFromPublicKey } from "../bridge/bridgeHelpers/addresses";
6
+ import { CASPER_NETWORK } from "../consts";
5
7
 
6
8
  export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
7
9
  steps: [
@@ -22,12 +24,12 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
22
24
  {
23
25
  title: "Chain ID",
24
26
  button: SpeculosButton.RIGHT,
25
- expectedValue: () => "casper",
27
+ expectedValue: () => CASPER_NETWORK,
26
28
  },
27
29
  {
28
30
  title: "Account",
29
31
  button: SpeculosButton.RIGHT,
30
- expectedValue: ({ account }) => casperGetCLPublicKey(account.freshAddress).toHex(true),
32
+ expectedValue: ({ account }) => casperAccountHashFromPublicKey(account.freshAddress),
31
33
  },
32
34
  {
33
35
  title: "Fee",
@@ -38,7 +40,7 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
38
40
  {
39
41
  title: "Target",
40
42
  button: SpeculosButton.RIGHT,
41
- expectedValue: ({ transaction }) => casperGetCLPublicKey(transaction.recipient).toHex(true),
43
+ expectedValue: ({ transaction }) => casperAccountHashFromPublicKey(transaction.recipient),
42
44
  },
43
45
  {
44
46
  title: "Amount",
package/tsconfig.json CHANGED
@@ -5,11 +5,8 @@
5
5
  "declarationMap": true,
6
6
  "downlevelIteration": true,
7
7
  "lib": ["es2020", "dom"],
8
- "rootDir": "./src",
9
8
  "outDir": "lib",
10
- "exactOptionalPropertyTypes": true,
11
- "module": "esnext",
12
- "moduleResolution": "bundler"
9
+ "exactOptionalPropertyTypes": true
13
10
  },
14
11
  "include": ["src/**/*", "deviceTransactionConfig.ts", "transaction.ts"]
15
12
  }