@ledgerhq/coin-internet_computer 1.4.0-nightly.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 +38 -0
  3. package/CHANGELOG.md +7 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +9 -0
  6. package/lib/api/api.d.ts +12 -0
  7. package/lib/api/api.d.ts.map +1 -0
  8. package/lib/api/api.js +82 -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/bridgeHelpers/account.d.ts +3 -0
  15. package/lib/bridge/bridgeHelpers/account.d.ts.map +1 -0
  16. package/lib/bridge/bridgeHelpers/account.js +127 -0
  17. package/lib/bridge/bridgeHelpers/account.js.map +1 -0
  18. package/lib/bridge/bridgeHelpers/addresses.d.ts +12 -0
  19. package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  20. package/lib/bridge/bridgeHelpers/addresses.js +46 -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/icpRosetta/index.d.ts +30 -0
  27. package/lib/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +1 -0
  28. package/lib/bridge/bridgeHelpers/icpRosetta/index.js +87 -0
  29. package/lib/bridge/bridgeHelpers/icpRosetta/index.js.map +1 -0
  30. package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts +145 -0
  31. package/lib/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +1 -0
  32. package/lib/bridge/bridgeHelpers/icpRosetta/types.js +3 -0
  33. package/lib/bridge/bridgeHelpers/icpRosetta/types.js.map +1 -0
  34. package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts +17 -0
  35. package/lib/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +1 -0
  36. package/lib/bridge/bridgeHelpers/icpRosetta/utils.js +154 -0
  37. package/lib/bridge/bridgeHelpers/icpRosetta/utils.js.map +1 -0
  38. package/lib/bridge/broadcast.d.ts +4 -0
  39. package/lib/bridge/broadcast.d.ts.map +1 -0
  40. package/lib/bridge/broadcast.js +21 -0
  41. package/lib/bridge/broadcast.js.map +1 -0
  42. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  43. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  44. package/lib/bridge/buildOptimisticOperation.js +37 -0
  45. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  46. package/lib/bridge/createTransaction.d.ts +4 -0
  47. package/lib/bridge/createTransaction.d.ts.map +1 -0
  48. package/lib/bridge/createTransaction.js +20 -0
  49. package/lib/bridge/createTransaction.js.map +1 -0
  50. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  51. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  52. package/lib/bridge/deviceTransactionConfig.js +41 -0
  53. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  54. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  55. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  56. package/lib/bridge/estimateMaxSpendable.js +28 -0
  57. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  58. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  59. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  60. package/lib/bridge/getTransactionStatus.js +71 -0
  61. package/lib/bridge/getTransactionStatus.js.map +1 -0
  62. package/lib/bridge/index.d.ts +8 -0
  63. package/lib/bridge/index.d.ts.map +1 -0
  64. package/lib/bridge/index.js +54 -0
  65. package/lib/bridge/index.js.map +1 -0
  66. package/lib/bridge/prepareTransaction.d.ts +4 -0
  67. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  68. package/lib/bridge/prepareTransaction.js +32 -0
  69. package/lib/bridge/prepareTransaction.js.map +1 -0
  70. package/lib/bridge/signOperation.d.ts +6 -0
  71. package/lib/bridge/signOperation.d.ts.map +1 -0
  72. package/lib/bridge/signOperation.js +53 -0
  73. package/lib/bridge/signOperation.js.map +1 -0
  74. package/lib/bridge/transaction.d.ts +14 -0
  75. package/lib/bridge/transaction.d.ts.map +1 -0
  76. package/lib/bridge/transaction.js +41 -0
  77. package/lib/bridge/transaction.js.map +1 -0
  78. package/lib/common-logic/index.d.ts +2 -0
  79. package/lib/common-logic/index.d.ts.map +1 -0
  80. package/lib/common-logic/index.js +12 -0
  81. package/lib/common-logic/index.js.map +1 -0
  82. package/lib/common-logic/utils.d.ts +9 -0
  83. package/lib/common-logic/utils.d.ts.map +1 -0
  84. package/lib/common-logic/utils.js +44 -0
  85. package/lib/common-logic/utils.js.map +1 -0
  86. package/lib/consts.d.ts +6 -0
  87. package/lib/consts.d.ts.map +1 -0
  88. package/lib/consts.js +12 -0
  89. package/lib/consts.js.map +1 -0
  90. package/lib/errors.d.ts +4 -0
  91. package/lib/errors.d.ts.map +1 -0
  92. package/lib/errors.js +9 -0
  93. package/lib/errors.js.map +1 -0
  94. package/lib/hw-signMessage.d.ts +12 -0
  95. package/lib/hw-signMessage.d.ts.map +1 -0
  96. package/lib/hw-signMessage.js +43 -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 +35 -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 +103 -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 +141 -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 +27 -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 +55 -0
  125. package/lib/test/speculos-deviceActions.js.map +1 -0
  126. package/lib/types/common.d.ts +21 -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 +22 -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/api.d.ts +12 -0
  139. package/lib-es/api/api.d.ts.map +1 -0
  140. package/lib-es/api/api.js +71 -0
  141. package/lib-es/api/api.js.map +1 -0
  142. package/lib-es/api/index.d.ts +2 -0
  143. package/lib-es/api/index.d.ts.map +1 -0
  144. package/lib-es/api/index.js +2 -0
  145. package/lib-es/api/index.js.map +1 -0
  146. package/lib-es/bridge/bridgeHelpers/account.d.ts +3 -0
  147. package/lib-es/bridge/bridgeHelpers/account.d.ts.map +1 -0
  148. package/lib-es/bridge/bridgeHelpers/account.js +120 -0
  149. package/lib-es/bridge/bridgeHelpers/account.js.map +1 -0
  150. package/lib-es/bridge/bridgeHelpers/addresses.d.ts +12 -0
  151. package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
  152. package/lib-es/bridge/bridgeHelpers/addresses.js +37 -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/icpRosetta/index.d.ts +30 -0
  159. package/lib-es/bridge/bridgeHelpers/icpRosetta/index.d.ts.map +1 -0
  160. package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js +75 -0
  161. package/lib-es/bridge/bridgeHelpers/icpRosetta/index.js.map +1 -0
  162. package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts +145 -0
  163. package/lib-es/bridge/bridgeHelpers/icpRosetta/types.d.ts.map +1 -0
  164. package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js +2 -0
  165. package/lib-es/bridge/bridgeHelpers/icpRosetta/types.js.map +1 -0
  166. package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts +17 -0
  167. package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.d.ts.map +1 -0
  168. package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js +122 -0
  169. package/lib-es/bridge/bridgeHelpers/icpRosetta/utils.js.map +1 -0
  170. package/lib-es/bridge/broadcast.d.ts +4 -0
  171. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  172. package/lib-es/bridge/broadcast.js +17 -0
  173. package/lib-es/bridge/broadcast.js.map +1 -0
  174. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  175. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  176. package/lib-es/bridge/buildOptimisticOperation.js +33 -0
  177. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  178. package/lib-es/bridge/createTransaction.d.ts +4 -0
  179. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  180. package/lib-es/bridge/createTransaction.js +13 -0
  181. package/lib-es/bridge/createTransaction.js.map +1 -0
  182. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  183. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  184. package/lib-es/bridge/deviceTransactionConfig.js +39 -0
  185. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  186. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  187. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  188. package/lib-es/bridge/estimateMaxSpendable.js +21 -0
  189. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  190. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  191. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  192. package/lib-es/bridge/getTransactionStatus.js +67 -0
  193. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  194. package/lib-es/bridge/index.d.ts +8 -0
  195. package/lib-es/bridge/index.d.ts.map +1 -0
  196. package/lib-es/bridge/index.js +47 -0
  197. package/lib-es/bridge/index.js.map +1 -0
  198. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  199. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  200. package/lib-es/bridge/prepareTransaction.js +28 -0
  201. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  202. package/lib-es/bridge/signOperation.d.ts +6 -0
  203. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  204. package/lib-es/bridge/signOperation.js +49 -0
  205. package/lib-es/bridge/signOperation.js.map +1 -0
  206. package/lib-es/bridge/transaction.d.ts +14 -0
  207. package/lib-es/bridge/transaction.d.ts.map +1 -0
  208. package/lib-es/bridge/transaction.js +33 -0
  209. package/lib-es/bridge/transaction.js.map +1 -0
  210. package/lib-es/common-logic/index.d.ts +2 -0
  211. package/lib-es/common-logic/index.d.ts.map +1 -0
  212. package/lib-es/common-logic/index.js +2 -0
  213. package/lib-es/common-logic/index.js.map +1 -0
  214. package/lib-es/common-logic/utils.d.ts +9 -0
  215. package/lib-es/common-logic/utils.d.ts.map +1 -0
  216. package/lib-es/common-logic/utils.js +34 -0
  217. package/lib-es/common-logic/utils.js.map +1 -0
  218. package/lib-es/consts.d.ts +6 -0
  219. package/lib-es/consts.d.ts.map +1 -0
  220. package/lib-es/consts.js +9 -0
  221. package/lib-es/consts.js.map +1 -0
  222. package/lib-es/errors.d.ts +4 -0
  223. package/lib-es/errors.d.ts.map +1 -0
  224. package/lib-es/errors.js +6 -0
  225. package/lib-es/errors.js.map +1 -0
  226. package/lib-es/hw-signMessage.d.ts +12 -0
  227. package/lib-es/hw-signMessage.d.ts.map +1 -0
  228. package/lib-es/hw-signMessage.js +39 -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 +33 -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 +98 -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 +135 -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 +21 -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 +52 -0
  257. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  258. package/lib-es/types/common.d.ts +21 -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 +22 -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 +128 -0
  271. package/src/api/api.ts +92 -0
  272. package/src/api/index.ts +1 -0
  273. package/src/bridge/bridgeHelpers/account.ts +134 -0
  274. package/src/bridge/bridgeHelpers/addresses.ts +33 -0
  275. package/src/bridge/bridgeHelpers/fee.ts +6 -0
  276. package/src/bridge/bridgeHelpers/icpRosetta/index.ts +154 -0
  277. package/src/bridge/bridgeHelpers/icpRosetta/types.ts +166 -0
  278. package/src/bridge/bridgeHelpers/icpRosetta/utils.ts +151 -0
  279. package/src/bridge/broadcast.ts +15 -0
  280. package/src/bridge/buildOptimisticOperation.ts +32 -0
  281. package/src/bridge/createTransaction.ts +15 -0
  282. package/src/bridge/deviceTransactionConfig.ts +53 -0
  283. package/src/bridge/estimateMaxSpendable.ts +19 -0
  284. package/src/bridge/getTransactionStatus.ts +75 -0
  285. package/src/bridge/index.ts +63 -0
  286. package/src/bridge/prepareTransaction.ts +28 -0
  287. package/src/bridge/signOperation.ts +59 -0
  288. package/src/bridge/transaction.ts +61 -0
  289. package/src/common-logic/index.ts +9 -0
  290. package/src/common-logic/utils.ts +47 -0
  291. package/src/consts.ts +11 -0
  292. package/src/errors.ts +6 -0
  293. package/src/hw-signMessage.ts +42 -0
  294. package/src/signer/getAddress.ts +34 -0
  295. package/src/signer/index.ts +3 -0
  296. package/src/test/bot-specs.ts +120 -0
  297. package/src/test/bridgeDatasetTest.ts +141 -0
  298. package/src/test/cli.ts +36 -0
  299. package/src/test/index.ts +3 -0
  300. package/src/test/speculos-deviceActions.ts +61 -0
  301. package/src/types/common.ts +31 -0
  302. package/src/types/index.ts +2 -0
  303. package/src/types/signer.ts +22 -0
  304. package/tsconfig.json +14 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
2
+ import type { Transaction } from "../types";
3
+ export declare const acceptTransaction: DeviceAction<Transaction, any>;
4
+ //# sourceMappingURL=speculos-deviceActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculos-deviceActions.d.ts","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,WAAW,EAAE,GAAG,CAiD3D,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { deviceActionFlow, formatDeviceAmount, SpeculosButton, } from "@ledgerhq/coin-framework/bot/specs";
2
+ import { methodToString } from "../common-logic/utils";
3
+ const ignoreSpaces = (s) => s.replace(/ /g, "");
4
+ export const acceptTransaction = deviceActionFlow({
5
+ steps: [
6
+ {
7
+ title: "Transaction type",
8
+ button: SpeculosButton.RIGHT,
9
+ expectedValue: () => {
10
+ return methodToString(0);
11
+ },
12
+ },
13
+ {
14
+ title: "From account",
15
+ button: SpeculosButton.RIGHT,
16
+ stepValueTransform: ignoreSpaces,
17
+ expectedValue: ({ account }) => account.freshAddress,
18
+ },
19
+ {
20
+ title: "To account",
21
+ button: SpeculosButton.RIGHT,
22
+ stepValueTransform: ignoreSpaces,
23
+ expectedValue: ({ transaction }) => transaction.recipient,
24
+ },
25
+ {
26
+ title: "Amount (ICP)",
27
+ button: SpeculosButton.RIGHT,
28
+ expectedValue: ({ status, account }) => formatDeviceAmount(account.currency, status.amount, {
29
+ hideCode: true,
30
+ showAllDigits: false,
31
+ }),
32
+ },
33
+ {
34
+ title: "Maximum fee (ICP)",
35
+ button: SpeculosButton.RIGHT,
36
+ expectedValue: ({ status, account }) => formatDeviceAmount(account.currency, status.estimatedFees, {
37
+ hideCode: true,
38
+ showAllDigits: false,
39
+ }),
40
+ },
41
+ {
42
+ title: "Memo",
43
+ button: SpeculosButton.RIGHT,
44
+ expectedValue: ({ transaction }) => { var _a; return (_a = transaction.memo) !== null && _a !== void 0 ? _a : "0"; },
45
+ },
46
+ {
47
+ title: "APPROVE",
48
+ button: SpeculosButton.BOTH,
49
+ },
50
+ ],
51
+ });
52
+ //# sourceMappingURL=speculos-deviceActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculos-deviceActions.js","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,iBAAiB,GAAmC,gBAAgB,CAAC;IAChF,KAAK,EAAE;QACL;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,GAAG,EAAE;gBAClB,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;SACF;QACD;YACE,KAAK,EAAE,cAAc;YACrB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,kBAAkB,EAAE,YAAY;YAChC,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY;SACrD;QACD;YACE,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,kBAAkB,EAAE,YAAY;YAChC,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS;SAC1D;QACD;YACE,KAAK,EAAE,cAAc;YACrB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CACrC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;gBAClD,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,KAAK;aACrB,CAAC;SACL;QACD;YACE,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CACrC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,aAAa,EAAE;gBACzD,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,KAAK;aACrB,CAAC;SACL;QACD;YACE,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,WAAC,OAAA,MAAA,WAAW,CAAC,IAAI,mCAAI,GAAG,CAAA,EAAA;SAC5D;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;KACF;CACF,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Operation, TransactionCommon, TransactionCommonRaw, TransactionStatusCommon, TransactionStatusCommonRaw } from "@ledgerhq/types-live";
2
+ import BigNumber from "bignumber.js";
3
+ type FamilyType = "internet_computer";
4
+ export type Transaction = TransactionCommon & {
5
+ family: FamilyType;
6
+ fees: BigNumber;
7
+ memo?: string | undefined;
8
+ };
9
+ export type TransactionRaw = TransactionCommonRaw & {
10
+ family: FamilyType;
11
+ fees: string;
12
+ memo?: string | undefined;
13
+ };
14
+ export type TransactionStatus = TransactionStatusCommon;
15
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
16
+ export type InternetComputerOperation = Operation<InternetComputerOperationExtra>;
17
+ export type InternetComputerOperationExtra = {
18
+ memo?: string | undefined;
19
+ };
20
+ export {};
21
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,KAAK,UAAU,GAAG,mBAAmB,CAAC;AAEtC,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG;IAC5C,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG;IAClD,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D,MAAM,MAAM,yBAAyB,GAAG,SAAS,CAAC,8BAA8B,CAAC,CAAC;AAElF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./signer";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./common";
2
+ export * from "./signer";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ export type ICPSignature = {
3
+ returnCode: number;
4
+ errorMessage?: string;
5
+ preSignHash?: Buffer;
6
+ signatureRS?: Buffer;
7
+ signatureDER?: Buffer;
8
+ };
9
+ export type ICPGetAddrResponse = {
10
+ returnCode: number;
11
+ errorMessage: string;
12
+ publicKey?: Buffer;
13
+ principal?: Buffer;
14
+ address?: Buffer;
15
+ principalText?: string;
16
+ };
17
+ export interface ICPSigner {
18
+ showAddressAndPubKey(path: string): Promise<ICPGetAddrResponse>;
19
+ getAddressAndPubKey(path: string): Promise<ICPGetAddrResponse>;
20
+ sign(path: string, message: Buffer, txtype: number): Promise<ICPSignature>;
21
+ }
22
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChE,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC5E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "name": "@ledgerhq/coin-internet_computer",
3
+ "version": "1.4.0-nightly.0",
4
+ "description": "Ledger Internet Computer integration",
5
+ "keywords": [
6
+ "Ledger",
7
+ "LedgerWallet",
8
+ "ICP",
9
+ "Internet Computer"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/LedgerHQ/ledger-live.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/LedgerHQ/ledger-live/issues"
17
+ },
18
+ "homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-internet_computer",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "typesVersions": {
23
+ "*": {
24
+ "lib/*": [
25
+ "lib/*"
26
+ ],
27
+ "lib-es/*": [
28
+ "lib-es/*"
29
+ ],
30
+ "specs": [
31
+ "lib/test/bot-specs"
32
+ ],
33
+ "*": [
34
+ "lib/*",
35
+ "lib/api/*",
36
+ "lib/bridge/*",
37
+ "lib/common-logic/*",
38
+ "lib/signer/*",
39
+ "lib/test/*",
40
+ "lib/types/*"
41
+ ]
42
+ }
43
+ },
44
+ "exports": {
45
+ "./lib/*": "./lib/*.js",
46
+ "./lib-es/*": "./lib-es/*.js",
47
+ "./api": {
48
+ "require": "./lib/api/index.js",
49
+ "default": "./lib-es/api/index.js"
50
+ },
51
+ "./deviceTransactionConfig": {
52
+ "require": "./lib/bridge/deviceTransactionConfig.js",
53
+ "default": "./lib-es/bridge/deviceTransactionConfig.js"
54
+ },
55
+ "./logic": {
56
+ "require": "./lib/common-logic/index.js",
57
+ "default": "./lib-es/common-logic/index.js"
58
+ },
59
+ "./signer": {
60
+ "require": "./lib/signer/index.js",
61
+ "default": "./lib-es/signer/index.js"
62
+ },
63
+ "./specs": {
64
+ "require": "./lib/test/bot-specs.js",
65
+ "default": "./lib-es/test/bot-specs.js"
66
+ },
67
+ "./transaction": {
68
+ "require": "./lib/bridge/transaction.js",
69
+ "default": "./lib-es/bridge/transaction.js"
70
+ },
71
+ "./types": {
72
+ "require": "./lib/types/index.js",
73
+ "default": "./lib-es/types/index.js"
74
+ },
75
+ "./*": {
76
+ "require": "./lib/*.js",
77
+ "default": "./lib-es/*.js"
78
+ },
79
+ ".": {
80
+ "require": "./lib/index.js",
81
+ "default": "./lib-es/index.js"
82
+ },
83
+ "./package.json": "./package.json"
84
+ },
85
+ "license": "Apache-2.0",
86
+ "dependencies": {
87
+ "@dfinity/agent": "^0.21.0",
88
+ "@dfinity/candid": "^0.21.0",
89
+ "@dfinity/principal": "^0.15.6",
90
+ "bignumber.js": "^9.1.2",
91
+ "invariant": "^2.2.2",
92
+ "lodash": "^4.17.21",
93
+ "simple-cbor": "^0.4.1",
94
+ "big-integer": "^1.6.51",
95
+ "rxjs": "^7.8.1",
96
+ "expect": "^27.4.6",
97
+ "@ledgerhq/coin-framework": "^0.21.0-nightly.3",
98
+ "@ledgerhq/cryptoassets": "^13.7.0",
99
+ "@ledgerhq/devices": "8.4.4",
100
+ "@ledgerhq/errors": "^6.19.1",
101
+ "@ledgerhq/live-env": "^2.4.1",
102
+ "@ledgerhq/live-network": "^2.0.3",
103
+ "@ledgerhq/logs": "^6.12.0",
104
+ "@ledgerhq/types-live": "^6.55.0-nightly.2"
105
+ },
106
+ "devDependencies": {
107
+ "@types/invariant": "^2.2.2",
108
+ "@types/jest": "^29.5.10",
109
+ "@types/lodash": "^4.14.191",
110
+ "@types/semver": "^7.5.8",
111
+ "jest": "^29.7.0",
112
+ "ts-jest": "^29.1.1",
113
+ "axios": "1.7.7"
114
+ },
115
+ "scripts": {
116
+ "clean": "rimraf lib lib-es",
117
+ "build": "tsc && tsc -m ES6 --outDir lib-es",
118
+ "coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-icp.json",
119
+ "prewatch": "pnpm build",
120
+ "watch": "tsc --watch",
121
+ "watch:es": "tsc --watch -m ES6 --outDir lib-es",
122
+ "doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
123
+ "lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
124
+ "lint:fix": "pnpm lint --fix",
125
+ "test": "jest",
126
+ "unimported": "unimported"
127
+ }
128
+ }
package/src/api/api.ts ADDED
@@ -0,0 +1,92 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
3
+ import { getEnv } from "@ledgerhq/live-env";
4
+ import network from "@ledgerhq/live-network/network";
5
+ import { ICP_BLK_NAME_ROSETTA, ICP_NET_ID_ROSETTA } from "../consts";
6
+ import {
7
+ ICPRosettaBlockHeightResponse,
8
+ ICPRosettaGetBalancesResponse,
9
+ ICPRosettaGetTxnsHistoryResponse,
10
+ } from "../bridge/bridgeHelpers/icpRosetta/types";
11
+
12
+ const getICPURL = (path?: string): string => {
13
+ const baseUrl = getEnv("API_ICP_ENDPOINT");
14
+ if (!baseUrl) throw new Error("API base URL not available");
15
+
16
+ return `${baseUrl}${path ? path : ""}`;
17
+ };
18
+
19
+ const ICPFetchWrapper = async <T>(path: string, body: any) => {
20
+ const url = getICPURL(path);
21
+
22
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
23
+ const opts: AxiosRequestConfig = {
24
+ method: "POST",
25
+ data: body,
26
+ url,
27
+ };
28
+ const rawResponse = await network(opts);
29
+ if (rawResponse && rawResponse.data && rawResponse.data.details?.error_message) {
30
+ log("error", rawResponse.data.details?.error_message);
31
+ }
32
+
33
+ // We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
34
+ const { data } = rawResponse as AxiosResponse<T>;
35
+
36
+ log("http", url);
37
+ return data;
38
+ };
39
+
40
+ export const getICPRosettaNetworkIdentifier = () => {
41
+ return {
42
+ network_identifier: {
43
+ blockchain: ICP_BLK_NAME_ROSETTA,
44
+ network: ICP_NET_ID_ROSETTA,
45
+ },
46
+ };
47
+ };
48
+
49
+ export const fetchBlockHeight = async (): Promise<ICPRosettaBlockHeightResponse> => {
50
+ const data = await ICPFetchWrapper<ICPRosettaBlockHeightResponse>(
51
+ "network/status",
52
+ getICPRosettaNetworkIdentifier(),
53
+ );
54
+ return data;
55
+ };
56
+
57
+ export const fetchBalances = async (accountId: string): Promise<ICPRosettaGetBalancesResponse> => {
58
+ const body = {
59
+ ...getICPRosettaNetworkIdentifier(),
60
+ account_identifier: {
61
+ address: accountId,
62
+ metadata: {},
63
+ },
64
+ };
65
+ const data = await ICPFetchWrapper<ICPRosettaGetBalancesResponse>("account/balance", body);
66
+ return data;
67
+ };
68
+
69
+ export const fetchTxns = async (accountId: string): Promise<ICPRosettaGetTxnsHistoryResponse> => {
70
+ const body = {
71
+ ...getICPRosettaNetworkIdentifier(),
72
+ account_identifier: {
73
+ address: accountId,
74
+ metadata: {},
75
+ },
76
+ };
77
+ const data = await ICPFetchWrapper<ICPRosettaGetTxnsHistoryResponse>("search/transactions", body);
78
+ return data;
79
+ };
80
+
81
+ export const constructionInvoke = async <TRequest, TResponse>(
82
+ opts: TRequest,
83
+ method: string,
84
+ ): Promise<TResponse> => {
85
+ const body: TRequest = {
86
+ ...opts,
87
+ };
88
+
89
+ const data = await ICPFetchWrapper<TResponse>(`construction/${method}`, body);
90
+
91
+ return data;
92
+ };
@@ -0,0 +1 @@
1
+ export * from "./api";
@@ -0,0 +1,134 @@
1
+ import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
+ import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
3
+ import { fetchBalances, fetchBlockHeight, fetchTxns } from "../../api";
4
+ import flatMap from "lodash/flatMap";
5
+ import { Account } from "@ledgerhq/types-live";
6
+ import BigNumber from "bignumber.js";
7
+ import { ICPRosettaGetTxnsHistoryResponse } from "./icpRosetta/types";
8
+ import { ICP_FEES } from "../../consts";
9
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
10
+ import { normalizeEpochTimestamp } from "../../common-logic/utils";
11
+ import { InternetComputerOperation } from "../../types";
12
+ import invariant from "invariant";
13
+ import { deriveAddressFromPubkey } from "./icpRosetta";
14
+
15
+ export const getAccountShape: GetAccountShape = async info => {
16
+ const { currency, derivationMode, rest = {}, initialAccount } = info;
17
+ const publicKey = reconciliatePublicKey(rest.publicKey, initialAccount);
18
+ invariant(publicKey, "publicKey is required");
19
+
20
+ // deriving address from public key
21
+ const address = await deriveAddressFromPubkey(publicKey);
22
+ invariant(address, "address is required");
23
+
24
+ const accountId = encodeAccountId({
25
+ type: "js",
26
+ version: "2",
27
+ currencyId: currency.id,
28
+ xpubOrAddress: publicKey,
29
+ derivationMode,
30
+ });
31
+
32
+ // log("debug", `Generation account shape for ${address}`);
33
+
34
+ const blockHeight = await fetchBlockHeight();
35
+ const balanceResp = await fetchBalances(address);
36
+ const balance = balanceResp.balances[0];
37
+
38
+ const txns = await fetchTxns(address);
39
+ const result: Partial<Account> = {
40
+ id: accountId,
41
+ balance: BigNumber(balance.value),
42
+ spendableBalance: BigNumber(balance.value),
43
+ operations: flatMap(txns.transactions.reverse(), mapTxToOps(accountId, address)),
44
+ blockHeight: blockHeight.current_block_identifier.index,
45
+ operationsCount: txns.transactions.length,
46
+ xpub: publicKey,
47
+ };
48
+
49
+ return result;
50
+ };
51
+
52
+ function reconciliatePublicKey(publicKey?: string, initialAccount?: Account): string {
53
+ if (publicKey) return publicKey;
54
+ if (initialAccount) {
55
+ const { xpubOrAddress } = decodeAccountId(initialAccount.id);
56
+ return xpubOrAddress;
57
+ }
58
+ throw new Error("publicKey wasn't properly restored");
59
+ }
60
+
61
+ const mapTxToOps = (accountId: string, address: string, fee = ICP_FEES) => {
62
+ return (
63
+ txInfo: ICPRosettaGetTxnsHistoryResponse["transactions"][0],
64
+ ): InternetComputerOperation[] => {
65
+ const ops: InternetComputerOperation[] = [];
66
+ const ownerOperation = txInfo.transaction.operations.find(
67
+ cur => cur.account.address === address,
68
+ );
69
+ const counterOperation = txInfo.transaction.operations.find(
70
+ cur => cur.account.address !== address,
71
+ );
72
+
73
+ if (!ownerOperation || !counterOperation) return ops;
74
+
75
+ const timeStamp = txInfo.transaction.metadata.timestamp;
76
+ const amount = BigNumber(ownerOperation.amount.value);
77
+ const hash = txInfo.transaction.transaction_identifier.hash;
78
+ const fromAccount = amount.isPositive()
79
+ ? counterOperation.account.address
80
+ : ownerOperation.account.address;
81
+ const toAccount = amount.isNegative()
82
+ ? counterOperation.account.address
83
+ : ownerOperation.account.address;
84
+ const memo = txInfo.transaction.metadata.memo.toString();
85
+ const blockHeight = txInfo.transaction.metadata.block_height;
86
+
87
+ const date = new Date(normalizeEpochTimestamp(timeStamp.toString()));
88
+ const value = amount.abs();
89
+ const feeToUse = BigNumber(fee);
90
+
91
+ const isSending = amount.isNegative();
92
+ const isReceiving = amount.isPositive();
93
+
94
+ if (isSending) {
95
+ ops.push({
96
+ id: encodeOperationId(accountId, hash, "OUT"),
97
+ hash,
98
+ type: "OUT",
99
+ value: value.plus(feeToUse),
100
+ fee: feeToUse,
101
+ blockHeight,
102
+ blockHash: null,
103
+ accountId,
104
+ senders: [fromAccount],
105
+ recipients: [toAccount],
106
+ date,
107
+ extra: {
108
+ memo,
109
+ },
110
+ });
111
+ }
112
+
113
+ if (isReceiving) {
114
+ ops.push({
115
+ id: encodeOperationId(accountId, hash, "IN"),
116
+ hash,
117
+ type: "IN",
118
+ value,
119
+ fee: feeToUse,
120
+ blockHeight,
121
+ blockHash: null,
122
+ accountId,
123
+ senders: [fromAccount],
124
+ recipients: [toAccount],
125
+ date,
126
+ extra: {
127
+ memo,
128
+ },
129
+ });
130
+ }
131
+
132
+ return ops;
133
+ };
134
+ };
@@ -0,0 +1,33 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import BigNumber from "bignumber.js";
4
+ import { MAX_MEMO_VALUE } from "../../consts";
5
+ import { fetchBalances } from "../../api";
6
+
7
+ export const getAddress = (
8
+ a: Account,
9
+ ): {
10
+ address: string;
11
+ derivationPath: string;
12
+ } => ({ address: a.freshAddress, derivationPath: a.freshAddressPath });
13
+
14
+ export async function validateAddress(address: string): Promise<{ isValid: boolean }> {
15
+ try {
16
+ const res = await fetchBalances(address);
17
+ if (!res.balances) throw Error(res.details?.error_message);
18
+ return { isValid: true };
19
+ } catch (e: any) {
20
+ log("error", e.message ?? "Failed to validate address");
21
+ return { isValid: false };
22
+ }
23
+ }
24
+
25
+ export function validateMemo(memo?: string): { isValid: boolean } {
26
+ const res = BigNumber(memo ?? 0);
27
+
28
+ if (res.isNaN() || res.lt(0) || res.gt(BigNumber(MAX_MEMO_VALUE))) {
29
+ return { isValid: false };
30
+ }
31
+
32
+ return { isValid: true };
33
+ }
@@ -0,0 +1,6 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { ICP_FEES } from "../../consts";
3
+
4
+ export function getEstimatedFees(): BigNumber {
5
+ return new BigNumber(ICP_FEES);
6
+ }