@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,123 @@
1
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import { signMessage } from "./hw-signMessage";
4
+ import { CasperSigner, CasperSignature } from "./types";
5
+
6
+ describe("hw-signMessage", () => {
7
+ // Test fixtures
8
+ const mockDeviceId = "device_123";
9
+
10
+ // Only define the properties actually used by the signMessage function
11
+ const mockAccount = {
12
+ freshAddressPath: "44'/506'/0'/0/1",
13
+ } as unknown as Account;
14
+
15
+ // Mock signature response
16
+ const mockSignatureResponse: CasperSignature = {
17
+ errorMessage: "",
18
+ returnCode: 0x9000,
19
+ signatureRS: Buffer.from(
20
+ "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
21
+ "hex",
22
+ ),
23
+ signatureRSV: Buffer.from(
24
+ "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff01",
25
+ "hex",
26
+ ),
27
+ signature_compact: new Uint8Array(
28
+ Buffer.from("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff01", "hex"),
29
+ ),
30
+ };
31
+
32
+ // Mock a successful signer
33
+ const mockSigner: CasperSigner = {
34
+ showAddressAndPubKey: jest.fn(),
35
+ getAddressAndPubKey: jest.fn(),
36
+ sign: jest.fn().mockResolvedValue(mockSignatureResponse),
37
+ };
38
+
39
+ // Mock signerContext function
40
+ const mockSignerContext: SignerContext<CasperSigner> = jest.fn((deviceId, callback) =>
41
+ callback(mockSigner),
42
+ );
43
+
44
+ beforeEach(() => {
45
+ jest.clearAllMocks();
46
+ });
47
+
48
+ test("should sign a plain text message correctly", async () => {
49
+ const message = "Hello Casper Network";
50
+ const result = await signMessage(mockSignerContext)(mockDeviceId, mockAccount, { message });
51
+
52
+ // Verify the signer was called with correct parameters
53
+ expect(mockSignerContext).toHaveBeenCalledWith(mockDeviceId, expect.any(Function));
54
+ expect(mockSigner.sign).toHaveBeenCalledWith(mockAccount.freshAddressPath, expect.any(Buffer));
55
+
56
+ // Verify the correct signature format is returned
57
+ expect(result).toEqual({
58
+ rsv: {
59
+ r: "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
60
+ s: "01",
61
+ v: NaN,
62
+ },
63
+ signature: "0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff01",
64
+ });
65
+ });
66
+
67
+ test("should sign a hex message correctly", async () => {
68
+ const message = "0x123456789abcdef";
69
+ const result = await signMessage(mockSignerContext)(mockDeviceId, mockAccount, { message });
70
+
71
+ expect(mockSigner.sign).toHaveBeenCalledWith(mockAccount.freshAddressPath, expect.any(Buffer));
72
+ expect(result.signature).toBe(
73
+ "0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff01",
74
+ );
75
+ });
76
+
77
+ test("should sign a base64 message correctly", async () => {
78
+ const message = "SGVsbG8gQ2FzcGVyIE5ldHdvcms="; // "Hello Casper Network" in base64
79
+ const result = await signMessage(mockSignerContext)(mockDeviceId, mockAccount, { message });
80
+
81
+ expect(mockSigner.sign).toHaveBeenCalledWith(mockAccount.freshAddressPath, expect.any(Buffer));
82
+ expect(result.signature).toBe(
83
+ "0x00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff01",
84
+ );
85
+ });
86
+
87
+ test("should throw error if message is empty", async () => {
88
+ await expect(
89
+ signMessage(mockSignerContext)(mockDeviceId, mockAccount, { message: "" }),
90
+ ).rejects.toThrow("Message cannot be empty");
91
+ });
92
+
93
+ test("should throw error if message is undefined", async () => {
94
+ await expect(
95
+ signMessage(mockSignerContext)(mockDeviceId, mockAccount, { message: undefined as any }),
96
+ ).rejects.toThrow("Message cannot be empty");
97
+ });
98
+
99
+ test("should throw error if message is not a string", async () => {
100
+ await expect(
101
+ signMessage(mockSignerContext)(mockDeviceId, mockAccount, {
102
+ message: { type: "EIP712" } as any,
103
+ }),
104
+ ).rejects.toThrow("Signing EIP712Message not supported");
105
+ });
106
+
107
+ test("should propagate errors from the signer", async () => {
108
+ // Mock an error from the signer
109
+ const errorSigner: CasperSigner = {
110
+ showAddressAndPubKey: jest.fn(),
111
+ getAddressAndPubKey: jest.fn(),
112
+ sign: jest.fn().mockRejectedValue(new Error("Device disconnected")),
113
+ };
114
+
115
+ const errorSignerContext: SignerContext<CasperSigner> = jest.fn((deviceId, callback) =>
116
+ callback(errorSigner),
117
+ );
118
+
119
+ await expect(
120
+ signMessage(errorSignerContext)(mockDeviceId, mockAccount, { message: "test" }),
121
+ ).rejects.toThrow("Device disconnected");
122
+ });
123
+ });
@@ -0,0 +1,134 @@
1
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
2
+ import { KeyAlgorithm } from "casper-js-sdk";
3
+ import getAddressResolver from "./getAddress";
4
+ import { CasperSigner, CasperGetAddrResponse } from "../types";
5
+ import * as addressHelpers from "../bridge/bridgeHelpers/addresses";
6
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
7
+
8
+ describe("getAddress resolver", () => {
9
+ // Test fixtures
10
+ const mockDeviceId = "device_123";
11
+ const mockPath = "44'/506'/0'/0/0";
12
+ const mockCurrency = getCryptoCurrencyById("casper");
13
+ const mockDerivationMode = "casper_wallet";
14
+ const mockPubKey = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
15
+ const mockDerivedAddress = "02cafe0123456789abcdef";
16
+
17
+ let mockSigner: CasperSigner;
18
+ let mockSignerContext: SignerContext<CasperSigner>;
19
+
20
+ // Mock responses
21
+ const createAddressResponse = (includeAddress: boolean): CasperGetAddrResponse => ({
22
+ errorMessage: "",
23
+ returnCode: 0x9000,
24
+ publicKey: Buffer.from(mockPubKey, "hex"),
25
+ Address: {
26
+ toString: jest.fn().mockReturnValue(includeAddress ? "02CAFE0123456789ABCDEF" : ""),
27
+ length: includeAddress ? 1 : 0,
28
+ },
29
+ });
30
+
31
+ beforeEach(() => {
32
+ jest.clearAllMocks();
33
+
34
+ // Set up mocks
35
+ mockSigner = {
36
+ showAddressAndPubKey: jest.fn(),
37
+ getAddressAndPubKey: jest.fn(),
38
+ sign: jest.fn(),
39
+ };
40
+
41
+ mockSignerContext = jest.fn((deviceId, callback) => callback(mockSigner));
42
+
43
+ // Mock address derivation function
44
+ jest.spyOn(addressHelpers, "casperAddressFromPubKey").mockReturnValue(mockDerivedAddress);
45
+ });
46
+
47
+ const setupTest = (verify: boolean, includeAddress: boolean) => {
48
+ const response = createAddressResponse(includeAddress);
49
+
50
+ if (verify) {
51
+ mockSigner.showAddressAndPubKey = jest.fn().mockResolvedValue(response);
52
+ } else {
53
+ mockSigner.getAddressAndPubKey = jest.fn().mockResolvedValue(response);
54
+ }
55
+
56
+ return getAddressResolver(mockSignerContext);
57
+ };
58
+
59
+ test("should return address from device when verify=false", async () => {
60
+ const getAddressFn = setupTest(false, true);
61
+
62
+ const result = await getAddressFn(mockDeviceId, {
63
+ path: mockPath,
64
+ verify: false,
65
+ currency: mockCurrency,
66
+ derivationMode: mockDerivationMode,
67
+ });
68
+
69
+ expect(mockSigner.getAddressAndPubKey).toHaveBeenCalledWith(mockPath);
70
+ expect(mockSigner.showAddressAndPubKey).not.toHaveBeenCalled();
71
+
72
+ expect(result).toEqual({
73
+ path: mockPath,
74
+ address: mockDerivedAddress,
75
+ publicKey: mockPubKey,
76
+ });
77
+ });
78
+
79
+ test("should return address from device when verify=true", async () => {
80
+ const getAddressFn = setupTest(true, true);
81
+
82
+ const result = await getAddressFn(mockDeviceId, {
83
+ path: mockPath,
84
+ verify: true,
85
+ currency: mockCurrency,
86
+ derivationMode: mockDerivationMode,
87
+ });
88
+
89
+ expect(mockSigner.showAddressAndPubKey).toHaveBeenCalledWith(mockPath);
90
+ expect(mockSigner.getAddressAndPubKey).not.toHaveBeenCalled();
91
+
92
+ expect(result).toEqual({
93
+ path: mockPath,
94
+ address: mockDerivedAddress,
95
+ publicKey: mockPubKey,
96
+ });
97
+ });
98
+
99
+ test("should derive address when not provided by device", async () => {
100
+ const getAddressFn = setupTest(false, false);
101
+
102
+ const result = await getAddressFn(mockDeviceId, {
103
+ path: mockPath,
104
+ verify: false,
105
+ currency: mockCurrency,
106
+ derivationMode: mockDerivationMode,
107
+ });
108
+
109
+ expect(addressHelpers.casperAddressFromPubKey).toHaveBeenCalledWith(
110
+ expect.any(Buffer),
111
+ KeyAlgorithm.SECP256K1,
112
+ );
113
+
114
+ expect(result).toEqual({
115
+ path: mockPath,
116
+ address: mockDerivedAddress,
117
+ publicKey: mockPubKey,
118
+ });
119
+ });
120
+
121
+ test("should propagate errors from the signer", async () => {
122
+ mockSigner.getAddressAndPubKey = jest.fn().mockRejectedValue(new Error("Device disconnected"));
123
+ const getAddressFn = getAddressResolver(mockSignerContext);
124
+
125
+ await expect(
126
+ getAddressFn(mockDeviceId, {
127
+ path: mockPath,
128
+ verify: false,
129
+ currency: mockCurrency,
130
+ derivationMode: mockDerivationMode,
131
+ }),
132
+ ).rejects.toThrow("Device disconnected");
133
+ });
134
+ });
@@ -2,7 +2,7 @@ import { log } from "@ledgerhq/logs";
2
2
  import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
3
3
  import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
4
4
  import { SignerContext } from "@ledgerhq/coin-framework/signer";
5
- import { CLPublicKeyTag } from "casper-js-sdk";
5
+ import { KeyAlgorithm } from "casper-js-sdk";
6
6
  import { casperAddressFromPubKey } from "../bridge/bridgeHelpers/addresses";
7
7
  import { CasperSigner } from "../types";
8
8
 
@@ -22,7 +22,7 @@ function resolver(signerContext: SignerContext<CasperSigner>): GetAddressFn {
22
22
  path,
23
23
  address: r.Address.length
24
24
  ? r.Address.toString().toLowerCase()
25
- : casperAddressFromPubKey(r.publicKey, CLPublicKeyTag.SECP256K1),
25
+ : casperAddressFromPubKey(r.publicKey, KeyAlgorithm.SECP256K1),
26
26
  publicKey: r.publicKey.toString("hex"),
27
27
  };
28
28
  };
@@ -19,6 +19,7 @@ const casperSpecs: AppSpec<Transaction> = {
19
19
  appQuery: {
20
20
  model: DeviceModelId.nanoSP,
21
21
  appName: "Casper",
22
+ appVersion: "3.0.7",
22
23
  },
23
24
  genericDeviceAction: acceptTransaction,
24
25
  testTimeout: 6 * 60 * 1000,