@ledgerhq/coin-filecoin 1.3.2

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 (316) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.unimportedrc.json +21 -0
  3. package/CHANGELOG.md +19 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/lib/api/api.d.ts +9 -0
  7. package/lib/api/api.d.ts.map +1 -0
  8. package/lib/api/api.js +99 -0
  9. package/lib/api/api.js.map +1 -0
  10. package/lib/api/index.d.ts +2 -0
  11. package/lib/api/index.d.ts.map +1 -0
  12. package/lib/api/index.js +18 -0
  13. package/lib/api/index.js.map +1 -0
  14. package/lib/bridge/broadcast.d.ts +4 -0
  15. package/lib/bridge/broadcast.d.ts.map +1 -0
  16. package/lib/bridge/broadcast.js +27 -0
  17. package/lib/bridge/broadcast.js.map +1 -0
  18. package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
  19. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  20. package/lib/bridge/buildOptimisticOperation.js +62 -0
  21. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  22. package/lib/bridge/createTransaction.d.ts +4 -0
  23. package/lib/bridge/createTransaction.d.ts.map +1 -0
  24. package/lib/bridge/createTransaction.js +24 -0
  25. package/lib/bridge/createTransaction.js.map +1 -0
  26. package/lib/bridge/deviceTransactionConfig.d.ts +33 -0
  27. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  28. package/lib/bridge/deviceTransactionConfig.js +71 -0
  29. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  30. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  31. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  32. package/lib/bridge/estimateMaxSpendable.js +100 -0
  33. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  34. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  35. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  36. package/lib/bridge/getTransactionStatus.js +84 -0
  37. package/lib/bridge/getTransactionStatus.js.map +1 -0
  38. package/lib/bridge/index.d.ts +8 -0
  39. package/lib/bridge/index.d.ts.map +1 -0
  40. package/lib/bridge/index.js +54 -0
  41. package/lib/bridge/index.js.map +1 -0
  42. package/lib/bridge/prepareTransaction.d.ts +4 -0
  43. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  44. package/lib/bridge/prepareTransaction.js +75 -0
  45. package/lib/bridge/prepareTransaction.js.map +1 -0
  46. package/lib/bridge/serializer.d.ts +13 -0
  47. package/lib/bridge/serializer.d.ts.map +1 -0
  48. package/lib/bridge/serializer.js +65 -0
  49. package/lib/bridge/serializer.js.map +1 -0
  50. package/lib/bridge/signOperation.d.ts +5 -0
  51. package/lib/bridge/signOperation.d.ts.map +1 -0
  52. package/lib/bridge/signOperation.js +80 -0
  53. package/lib/bridge/signOperation.js.map +1 -0
  54. package/lib/bridge/transaction.d.ts +14 -0
  55. package/lib/bridge/transaction.d.ts.map +1 -0
  56. package/lib/bridge/transaction.js +41 -0
  57. package/lib/bridge/transaction.js.map +1 -0
  58. package/lib/bridge/utils.d.ts +26 -0
  59. package/lib/bridge/utils.d.ts.map +1 -0
  60. package/lib/bridge/utils.js +67 -0
  61. package/lib/bridge/utils.js.map +1 -0
  62. package/lib/bridge/utils.unit.test.d.ts +2 -0
  63. package/lib/bridge/utils.unit.test.d.ts.map +1 -0
  64. package/lib/bridge/utils.unit.test.js +23 -0
  65. package/lib/bridge/utils.unit.test.js.map +1 -0
  66. package/lib/common-logic/index.d.ts +2 -0
  67. package/lib/common-logic/index.d.ts.map +1 -0
  68. package/lib/common-logic/index.js +13 -0
  69. package/lib/common-logic/index.js.map +1 -0
  70. package/lib/common-logic/utils.d.ts +22 -0
  71. package/lib/common-logic/utils.d.ts.map +1 -0
  72. package/lib/common-logic/utils.js +189 -0
  73. package/lib/common-logic/utils.js.map +1 -0
  74. package/lib/erc20/ERC20.json +12 -0
  75. package/lib/erc20/tokenAccounts.d.ts +10 -0
  76. package/lib/erc20/tokenAccounts.d.ts.map +1 -0
  77. package/lib/erc20/tokenAccounts.js +169 -0
  78. package/lib/erc20/tokenAccounts.js.map +1 -0
  79. package/lib/errors.d.ts +7 -0
  80. package/lib/errors.d.ts.map +1 -0
  81. package/lib/errors.js +13 -0
  82. package/lib/errors.js.map +1 -0
  83. package/lib/hw-signMessage.d.ts +12 -0
  84. package/lib/hw-signMessage.d.ts.map +1 -0
  85. package/lib/hw-signMessage.js +32 -0
  86. package/lib/hw-signMessage.js.map +1 -0
  87. package/lib/index.d.ts +2 -0
  88. package/lib/index.d.ts.map +1 -0
  89. package/lib/index.js +6 -0
  90. package/lib/index.js.map +1 -0
  91. package/lib/network/addresses.d.ts +16 -0
  92. package/lib/network/addresses.d.ts.map +1 -0
  93. package/lib/network/addresses.js +75 -0
  94. package/lib/network/addresses.js.map +1 -0
  95. package/lib/network/index.d.ts +2 -0
  96. package/lib/network/index.d.ts.map +1 -0
  97. package/lib/network/index.js +18 -0
  98. package/lib/network/index.js.map +1 -0
  99. package/lib/signer/getAddress.d.ts +6 -0
  100. package/lib/signer/getAddress.d.ts.map +1 -0
  101. package/lib/signer/getAddress.js +30 -0
  102. package/lib/signer/getAddress.js.map +1 -0
  103. package/lib/signer/index.d.ts +3 -0
  104. package/lib/signer/index.d.ts.map +1 -0
  105. package/lib/signer/index.js +8 -0
  106. package/lib/signer/index.js.map +1 -0
  107. package/lib/test/bot-specs.d.ts +7 -0
  108. package/lib/test/bot-specs.d.ts.map +1 -0
  109. package/lib/test/bot-specs.js +151 -0
  110. package/lib/test/bot-specs.js.map +1 -0
  111. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  112. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  113. package/lib/test/bridgeDatasetTest.js +401 -0
  114. package/lib/test/bridgeDatasetTest.js.map +1 -0
  115. package/lib/test/cli.d.ts +19 -0
  116. package/lib/test/cli.d.ts.map +1 -0
  117. package/lib/test/cli.js +59 -0
  118. package/lib/test/cli.js.map +1 -0
  119. package/lib/test/index.d.ts +6 -0
  120. package/lib/test/index.d.ts.map +1 -0
  121. package/lib/test/index.js +26 -0
  122. package/lib/test/index.js.map +1 -0
  123. package/lib/test/speculos-deviceActions.d.ts +5 -0
  124. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  125. package/lib/test/speculos-deviceActions.js +159 -0
  126. package/lib/test/speculos-deviceActions.js.map +1 -0
  127. package/lib/types/bridge.d.ts +35 -0
  128. package/lib/types/bridge.d.ts.map +1 -0
  129. package/lib/types/bridge.js +3 -0
  130. package/lib/types/bridge.js.map +1 -0
  131. package/lib/types/common.d.ts +96 -0
  132. package/lib/types/common.d.ts.map +1 -0
  133. package/lib/types/common.js +10 -0
  134. package/lib/types/common.js.map +1 -0
  135. package/lib/types/index.d.ts +4 -0
  136. package/lib/types/index.d.ts.map +1 -0
  137. package/lib/types/index.js +20 -0
  138. package/lib/types/index.js.map +1 -0
  139. package/lib/types/signer.d.ts +19 -0
  140. package/lib/types/signer.d.ts.map +1 -0
  141. package/lib/types/signer.js +3 -0
  142. package/lib/types/signer.js.map +1 -0
  143. package/lib-es/api/api.d.ts +9 -0
  144. package/lib-es/api/api.d.ts.map +1 -0
  145. package/lib-es/api/api.js +87 -0
  146. package/lib-es/api/api.js.map +1 -0
  147. package/lib-es/api/index.d.ts +2 -0
  148. package/lib-es/api/index.d.ts.map +1 -0
  149. package/lib-es/api/index.js +2 -0
  150. package/lib-es/api/index.js.map +1 -0
  151. package/lib-es/bridge/broadcast.d.ts +4 -0
  152. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  153. package/lib-es/bridge/broadcast.js +23 -0
  154. package/lib-es/bridge/broadcast.js.map +1 -0
  155. package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
  156. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  157. package/lib-es/bridge/buildOptimisticOperation.js +58 -0
  158. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  159. package/lib-es/bridge/createTransaction.d.ts +4 -0
  160. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  161. package/lib-es/bridge/createTransaction.js +17 -0
  162. package/lib-es/bridge/createTransaction.js.map +1 -0
  163. package/lib-es/bridge/deviceTransactionConfig.d.ts +33 -0
  164. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  165. package/lib-es/bridge/deviceTransactionConfig.js +69 -0
  166. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  167. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  168. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  169. package/lib-es/bridge/estimateMaxSpendable.js +93 -0
  170. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  171. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  172. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  173. package/lib-es/bridge/getTransactionStatus.js +80 -0
  174. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  175. package/lib-es/bridge/index.d.ts +8 -0
  176. package/lib-es/bridge/index.d.ts.map +1 -0
  177. package/lib-es/bridge/index.js +47 -0
  178. package/lib-es/bridge/index.js.map +1 -0
  179. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  180. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  181. package/lib-es/bridge/prepareTransaction.js +68 -0
  182. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  183. package/lib-es/bridge/serializer.d.ts +13 -0
  184. package/lib-es/bridge/serializer.d.ts.map +1 -0
  185. package/lib-es/bridge/serializer.js +58 -0
  186. package/lib-es/bridge/serializer.js.map +1 -0
  187. package/lib-es/bridge/signOperation.d.ts +5 -0
  188. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  189. package/lib-es/bridge/signOperation.js +76 -0
  190. package/lib-es/bridge/signOperation.js.map +1 -0
  191. package/lib-es/bridge/transaction.d.ts +14 -0
  192. package/lib-es/bridge/transaction.d.ts.map +1 -0
  193. package/lib-es/bridge/transaction.js +33 -0
  194. package/lib-es/bridge/transaction.js.map +1 -0
  195. package/lib-es/bridge/utils.d.ts +26 -0
  196. package/lib-es/bridge/utils.d.ts.map +1 -0
  197. package/lib-es/bridge/utils.js +57 -0
  198. package/lib-es/bridge/utils.js.map +1 -0
  199. package/lib-es/bridge/utils.unit.test.d.ts +2 -0
  200. package/lib-es/bridge/utils.unit.test.d.ts.map +1 -0
  201. package/lib-es/bridge/utils.unit.test.js +21 -0
  202. package/lib-es/bridge/utils.unit.test.js.map +1 -0
  203. package/lib-es/common-logic/index.d.ts +2 -0
  204. package/lib-es/common-logic/index.d.ts.map +1 -0
  205. package/lib-es/common-logic/index.js +2 -0
  206. package/lib-es/common-logic/index.js.map +1 -0
  207. package/lib-es/common-logic/utils.d.ts +22 -0
  208. package/lib-es/common-logic/utils.d.ts.map +1 -0
  209. package/lib-es/common-logic/utils.js +175 -0
  210. package/lib-es/common-logic/utils.js.map +1 -0
  211. package/lib-es/erc20/ERC20.json +12 -0
  212. package/lib-es/erc20/tokenAccounts.d.ts +10 -0
  213. package/lib-es/erc20/tokenAccounts.d.ts.map +1 -0
  214. package/lib-es/erc20/tokenAccounts.js +158 -0
  215. package/lib-es/erc20/tokenAccounts.js.map +1 -0
  216. package/lib-es/errors.d.ts +7 -0
  217. package/lib-es/errors.d.ts.map +1 -0
  218. package/lib-es/errors.js +10 -0
  219. package/lib-es/errors.js.map +1 -0
  220. package/lib-es/hw-signMessage.d.ts +12 -0
  221. package/lib-es/hw-signMessage.d.ts.map +1 -0
  222. package/lib-es/hw-signMessage.js +28 -0
  223. package/lib-es/hw-signMessage.js.map +1 -0
  224. package/lib-es/index.d.ts +2 -0
  225. package/lib-es/index.d.ts.map +1 -0
  226. package/lib-es/index.js +2 -0
  227. package/lib-es/index.js.map +1 -0
  228. package/lib-es/network/addresses.d.ts +16 -0
  229. package/lib-es/network/addresses.d.ts.map +1 -0
  230. package/lib-es/network/addresses.js +64 -0
  231. package/lib-es/network/addresses.js.map +1 -0
  232. package/lib-es/network/index.d.ts +2 -0
  233. package/lib-es/network/index.d.ts.map +1 -0
  234. package/lib-es/network/index.js +2 -0
  235. package/lib-es/network/index.js.map +1 -0
  236. package/lib-es/signer/getAddress.d.ts +6 -0
  237. package/lib-es/signer/getAddress.d.ts.map +1 -0
  238. package/lib-es/signer/getAddress.js +28 -0
  239. package/lib-es/signer/getAddress.js.map +1 -0
  240. package/lib-es/signer/index.d.ts +3 -0
  241. package/lib-es/signer/index.d.ts.map +1 -0
  242. package/lib-es/signer/index.js +3 -0
  243. package/lib-es/signer/index.js.map +1 -0
  244. package/lib-es/test/bot-specs.d.ts +7 -0
  245. package/lib-es/test/bot-specs.d.ts.map +1 -0
  246. package/lib-es/test/bot-specs.js +146 -0
  247. package/lib-es/test/bot-specs.js.map +1 -0
  248. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  249. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  250. package/lib-es/test/bridgeDatasetTest.js +395 -0
  251. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  252. package/lib-es/test/cli.d.ts +19 -0
  253. package/lib-es/test/cli.d.ts.map +1 -0
  254. package/lib-es/test/cli.js +53 -0
  255. package/lib-es/test/cli.js.map +1 -0
  256. package/lib-es/test/index.d.ts +6 -0
  257. package/lib-es/test/index.d.ts.map +1 -0
  258. package/lib-es/test/index.js +6 -0
  259. package/lib-es/test/index.js.map +1 -0
  260. package/lib-es/test/speculos-deviceActions.d.ts +5 -0
  261. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  262. package/lib-es/test/speculos-deviceActions.js +152 -0
  263. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  264. package/lib-es/types/bridge.d.ts +35 -0
  265. package/lib-es/types/bridge.d.ts.map +1 -0
  266. package/lib-es/types/bridge.js +2 -0
  267. package/lib-es/types/bridge.js.map +1 -0
  268. package/lib-es/types/common.d.ts +96 -0
  269. package/lib-es/types/common.d.ts.map +1 -0
  270. package/lib-es/types/common.js +7 -0
  271. package/lib-es/types/common.js.map +1 -0
  272. package/lib-es/types/index.d.ts +4 -0
  273. package/lib-es/types/index.d.ts.map +1 -0
  274. package/lib-es/types/index.js +4 -0
  275. package/lib-es/types/index.js.map +1 -0
  276. package/lib-es/types/signer.d.ts +19 -0
  277. package/lib-es/types/signer.d.ts.map +1 -0
  278. package/lib-es/types/signer.js +2 -0
  279. package/lib-es/types/signer.js.map +1 -0
  280. package/package.json +135 -0
  281. package/src/api/api.ts +125 -0
  282. package/src/api/index.ts +1 -0
  283. package/src/bridge/broadcast.ts +20 -0
  284. package/src/bridge/buildOptimisticOperation.ts +58 -0
  285. package/src/bridge/createTransaction.ts +20 -0
  286. package/src/bridge/deviceTransactionConfig.ts +119 -0
  287. package/src/bridge/estimateMaxSpendable.ts +120 -0
  288. package/src/bridge/getTransactionStatus.ts +80 -0
  289. package/src/bridge/index.ts +63 -0
  290. package/src/bridge/prepareTransaction.ts +82 -0
  291. package/src/bridge/serializer.ts +63 -0
  292. package/src/bridge/signOperation.ts +97 -0
  293. package/src/bridge/transaction.ts +69 -0
  294. package/src/bridge/utils.ts +73 -0
  295. package/src/bridge/utils.unit.test.ts +27 -0
  296. package/src/common-logic/index.ts +10 -0
  297. package/src/common-logic/utils.ts +232 -0
  298. package/src/erc20/ERC20.json +12 -0
  299. package/src/erc20/tokenAccounts.ts +183 -0
  300. package/src/errors.ts +13 -0
  301. package/src/hw-signMessage.ts +27 -0
  302. package/src/index.ts +1 -0
  303. package/src/network/addresses.ts +93 -0
  304. package/src/network/index.ts +1 -0
  305. package/src/signer/getAddress.ts +28 -0
  306. package/src/signer/index.ts +3 -0
  307. package/src/test/bot-specs.ts +163 -0
  308. package/src/test/bridgeDatasetTest.ts +403 -0
  309. package/src/test/cli.ts +80 -0
  310. package/src/test/index.ts +6 -0
  311. package/src/test/speculos-deviceActions.ts +166 -0
  312. package/src/types/bridge.ts +42 -0
  313. package/src/types/common.ts +105 -0
  314. package/src/types/index.ts +3 -0
  315. package/src/types/signer.ts +19 -0
  316. package/tsconfig.json +14 -0
package/src/errors.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+
3
+ /*
4
+ * When the recipient is non f0, f4 or eth address during token transfer
5
+ */
6
+ export const InvalidRecipientForTokenTransfer = createCustomErrorClass(
7
+ "InvalidRecipientForTokenTransfer",
8
+ );
9
+
10
+ /*
11
+ * When the fee estimation endpoint fails
12
+ */
13
+ export const FilecoinFeeEstimationFailed = createCustomErrorClass("FilecoinFeeEstimationFailed");
@@ -0,0 +1,27 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
3
+ import { Account, AnyMessage } from "@ledgerhq/types-live";
4
+ import { getBufferFromString } from "./bridge/utils";
5
+ import { FilecoinSigner } from "./types";
6
+
7
+ export const signMessage =
8
+ (signerContext: SignerContext<FilecoinSigner>) =>
9
+ async (deviceId: string, account: Account, { message }: AnyMessage) => {
10
+ log("debug", "start signMessage process");
11
+
12
+ if (typeof message !== "string") throw new Error("Invalid message type");
13
+ if (!message) throw new Error("Message cannot be empty");
14
+
15
+ const r = await signerContext(deviceId, signer =>
16
+ signer.sign(account.freshAddressPath, getBufferFromString(message)),
17
+ );
18
+
19
+ return {
20
+ rsv: {
21
+ r: Buffer.from(r.signature_compact.slice(0, 32)).toString("hex"),
22
+ s: Buffer.from(r.signature_compact.slice(32, 64)).toString("hex"),
23
+ v: parseInt(Buffer.from(r.signature_compact.slice(64, 65)).toString("hex"), 16),
24
+ },
25
+ signature: `0x${Buffer.from(r.signature_compact).toString("hex")}`,
26
+ };
27
+ };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { createBridges } from "./bridge/index";
@@ -0,0 +1,93 @@
1
+ import {
2
+ IAddress,
3
+ PROTOCOL_INDICATOR,
4
+ fromEthAddress,
5
+ isEthAddress,
6
+ fromString,
7
+ toEthAddress,
8
+ } from "iso-filecoin/address";
9
+ import { log } from "@ledgerhq/logs";
10
+
11
+ export type ValidateAddressResult =
12
+ | {
13
+ isValid: true;
14
+ parsedAddress: IAddress;
15
+ }
16
+ | {
17
+ isValid: false;
18
+ };
19
+
20
+ export const isFilEthAddress = (addr: IAddress) =>
21
+ addr.protocol === PROTOCOL_INDICATOR.DELEGATED && addr.namespace === 10;
22
+
23
+ export const isIdAddress = (addr: IAddress) => addr.protocol === PROTOCOL_INDICATOR.ID;
24
+
25
+ export const isEthereumConvertableAddr = (addr: IAddress) =>
26
+ isIdAddress(addr) || isFilEthAddress(addr);
27
+
28
+ export const validateAddress = (input: string): ValidateAddressResult => {
29
+ try {
30
+ const parsedAddress = fromString(input);
31
+ return { isValid: true, parsedAddress };
32
+ } catch (error) {
33
+ log("debug", `[validateAddress] fromString invalid address`);
34
+ }
35
+
36
+ try {
37
+ const parsedAddress = fromEthAddress(input, "mainnet");
38
+ return { isValid: true, parsedAddress };
39
+ } catch (error) {
40
+ log("debug", `[validateAddress] fromEthAddress invalid address`);
41
+ }
42
+
43
+ return { isValid: false };
44
+ };
45
+
46
+ export const isRecipientValidForTokenTransfer = (addr: string): boolean => {
47
+ if (addr.length < 2) {
48
+ return false;
49
+ }
50
+
51
+ const valid = validateAddress(addr);
52
+ if (!valid.isValid) {
53
+ return false;
54
+ }
55
+
56
+ if (isEthereumConvertableAddr(valid.parsedAddress)) {
57
+ return true;
58
+ }
59
+
60
+ return false;
61
+ };
62
+
63
+ export const getEquivalentAddress = (addr: string): string => {
64
+ if (isEthAddress(addr)) {
65
+ return fromEthAddress(addr, "mainnet").toString();
66
+ } else {
67
+ const parsed = fromString(addr);
68
+ if (isEthereumConvertableAddr(parsed)) {
69
+ return toEthAddress(parsed);
70
+ }
71
+ return "";
72
+ }
73
+ };
74
+
75
+ export const convertAddressFilToEth = (addr: string): string => {
76
+ if (isEthAddress(addr)) {
77
+ return addr;
78
+ }
79
+
80
+ const parsed = fromString(addr);
81
+ if (isEthereumConvertableAddr(parsed)) {
82
+ return toEthAddress(parsed);
83
+ }
84
+ throw new Error("address is not convertible to ethereum address");
85
+ };
86
+
87
+ export const convertAddressEthToFil = (addr: string): string => {
88
+ if (!isEthAddress(addr)) {
89
+ return addr;
90
+ }
91
+
92
+ return fromEthAddress(addr, "mainnet").toString();
93
+ };
@@ -0,0 +1 @@
1
+ export * from "./addresses";
@@ -0,0 +1,28 @@
1
+ import { log } from "@ledgerhq/logs";
2
+
3
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
4
+ import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
5
+ import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
6
+ import { FilecoinSigner } from "../types";
7
+
8
+ function resolver(signerContext: SignerContext<FilecoinSigner>): GetAddressFn {
9
+ return async (deviceId: string, { path, verify }: GetAddressOptions) => {
10
+ log("debug", "start getAddress process");
11
+
12
+ const { r } = await signerContext(deviceId, async signer => {
13
+ const r = verify
14
+ ? await signer.showAddressAndPubKey(path)
15
+ : await signer.getAddressAndPubKey(path);
16
+
17
+ return { r };
18
+ });
19
+
20
+ return {
21
+ path,
22
+ address: r.addrString,
23
+ publicKey: Buffer.from(r.compressed_pk).toString("hex"),
24
+ };
25
+ };
26
+ }
27
+
28
+ export default resolver;
@@ -0,0 +1,3 @@
1
+ import resolver from "./getAddress";
2
+
3
+ export default resolver;
@@ -0,0 +1,163 @@
1
+ import invariant from "invariant";
2
+ import { DeviceModelId } from "@ledgerhq/devices";
3
+ import BigNumber from "bignumber.js";
4
+ import type { Transaction } from "../types";
5
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
6
+ import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
7
+ import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
8
+ import { generateDeviceActionFlow } from "./speculos-deviceActions";
9
+ import { AccountType, BotScenario } from "../bridge/utils";
10
+
11
+ const F4_RECIPIENT = "f410fncojwmrseefktoco6rcnb3zv2eiqfli7muhvqma";
12
+ const ETH_RECIPIENT = "0x689c9b3232210aa9b84ef444d0ef35d11102ad1f";
13
+ const MIN_SAFE = new BigNumber(100000);
14
+ const maxAccount = 6;
15
+
16
+ const filecoinSpecs: AppSpec<Transaction> = {
17
+ name: "Filecoin",
18
+ currency: getCryptoCurrencyById("filecoin"),
19
+ appQuery: {
20
+ model: DeviceModelId.nanoSP,
21
+ appName: "Filecoin",
22
+ appVersion: "0.24.3",
23
+ },
24
+ genericDeviceAction: generateDeviceActionFlow(BotScenario.DEFAULT),
25
+ testTimeout: 16 * 60 * 1000,
26
+ minViableAmount: MIN_SAFE,
27
+ transactionCheck: ({ maxSpendable }) => {
28
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
29
+ },
30
+ mutations: [
31
+ {
32
+ name: "Send small to f4 address",
33
+ maxRun: 1,
34
+ deviceAction: generateDeviceActionFlow(BotScenario.F4_RECIPIENT),
35
+ testDestination: genericTestDestination,
36
+ transaction: ({ account, bridge }) => {
37
+ const amount = new BigNumber("100");
38
+
39
+ return {
40
+ transaction: bridge.createTransaction(account),
41
+ updates: [
42
+ {
43
+ recipient: F4_RECIPIENT,
44
+ },
45
+ {
46
+ amount,
47
+ },
48
+ ],
49
+ };
50
+ },
51
+ },
52
+ {
53
+ name: "Send small to eth address",
54
+ maxRun: 1,
55
+ deviceAction: generateDeviceActionFlow(BotScenario.ETH_RECIPIENT),
56
+ testDestination: genericTestDestination,
57
+ transaction: ({ account, bridge }) => {
58
+ const amount = new BigNumber("100");
59
+
60
+ return {
61
+ transaction: bridge.createTransaction(account),
62
+ updates: [
63
+ {
64
+ recipient: ETH_RECIPIENT,
65
+ },
66
+ {
67
+ amount,
68
+ },
69
+ ],
70
+ };
71
+ },
72
+ },
73
+ {
74
+ name: "Send 50%~",
75
+ maxRun: 1,
76
+ testDestination: genericTestDestination,
77
+ transaction: ({ account, siblings, bridge }) => {
78
+ const sibling = pickSiblings(siblings, maxAccount);
79
+ let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue();
80
+
81
+ if (!sibling.used && amount.lt(MIN_SAFE)) {
82
+ invariant(account.spendableBalance.gt(MIN_SAFE), "send is too low to activate account");
83
+ amount = MIN_SAFE;
84
+ }
85
+
86
+ return {
87
+ transaction: bridge.createTransaction(account),
88
+ updates: [
89
+ {
90
+ recipient: sibling.freshAddress,
91
+ },
92
+ {
93
+ amount,
94
+ },
95
+ ],
96
+ };
97
+ },
98
+ },
99
+ {
100
+ name: "Transfer Max",
101
+ maxRun: 1,
102
+ transaction: ({ account, siblings, bridge }) => {
103
+ return {
104
+ transaction: bridge.createTransaction(account),
105
+ updates: [
106
+ {
107
+ recipient: pickSiblings(siblings, maxAccount).freshAddress,
108
+ },
109
+ {
110
+ useAllAmount: true,
111
+ },
112
+ ],
113
+ };
114
+ },
115
+ },
116
+ {
117
+ name: "Send ~50% WFIL",
118
+ maxRun: 1,
119
+ deviceAction: generateDeviceActionFlow(BotScenario.TOKEN_TRANSFER),
120
+ transaction: ({ account, bridge, maxSpendable }) => {
121
+ invariant(maxSpendable.gt(0), "Spendable balance is too low");
122
+ const subAccount = account.subAccounts?.find(
123
+ a => a.type === AccountType.TokenAccount && a.spendableBalance.gt(0),
124
+ );
125
+ invariant(
126
+ subAccount && subAccount.type === AccountType.TokenAccount,
127
+ "no subAccount with WFIL",
128
+ );
129
+ const amount = subAccount.balance.div(1.9 + 0.2 * Math.random()).integerValue();
130
+ return {
131
+ transaction: bridge.createTransaction(account),
132
+ updates: [
133
+ {
134
+ subAccountId: subAccount.id,
135
+ },
136
+ {
137
+ recipient: F4_RECIPIENT,
138
+ },
139
+ {
140
+ amount,
141
+ },
142
+ ],
143
+ };
144
+ },
145
+ test: ({ account, accountBeforeTransaction, transaction, status }) => {
146
+ const subAccountId = transaction.subAccountId;
147
+ const subAccount = account.subAccounts?.find(sa => sa.id === subAccountId);
148
+ const subAccountBeforeTransaction = accountBeforeTransaction.subAccounts?.find(
149
+ sa => sa.id === subAccountId,
150
+ );
151
+ botTest("subAccount balance moved with the tx status amount", () =>
152
+ expect(subAccount?.balance.toString()).toBe(
153
+ subAccountBeforeTransaction?.balance.minus(status.amount).toString(),
154
+ ),
155
+ );
156
+ },
157
+ },
158
+ ],
159
+ };
160
+
161
+ export default {
162
+ filecoinSpecs,
163
+ };