@ledgerhq/coin-icon 0.4.1-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 (341) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +41 -0
  4. package/CHANGELOG.md +495 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +11 -0
  7. package/lib/__test__/api/index.unit.test.d.ts +2 -0
  8. package/lib/__test__/api/index.unit.test.d.ts.map +1 -0
  9. package/lib/__test__/api/index.unit.test.js +173 -0
  10. package/lib/__test__/api/index.unit.test.js.map +1 -0
  11. package/lib/__test__/unit/buildTransaction.test.d.ts +2 -0
  12. package/lib/__test__/unit/buildTransaction.test.d.ts.map +1 -0
  13. package/lib/__test__/unit/buildTransaction.test.js +76 -0
  14. package/lib/__test__/unit/buildTransaction.test.js.map +1 -0
  15. package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
  16. package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
  17. package/lib/__test__/unit/getFeesForTransaction.unit.test.js +101 -0
  18. package/lib/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
  19. package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
  20. package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
  21. package/lib/__test__/unit/getTransactionStatus.unit.test.js +178 -0
  22. package/lib/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
  23. package/lib/__test__/unit/logic.unit.test.d.ts +2 -0
  24. package/lib/__test__/unit/logic.unit.test.d.ts.map +1 -0
  25. package/lib/__test__/unit/logic.unit.test.js +112 -0
  26. package/lib/__test__/unit/logic.unit.test.js.map +1 -0
  27. package/lib/__test__/unit/serializations.unit.test.d.ts +2 -0
  28. package/lib/__test__/unit/serializations.unit.test.d.ts.map +1 -0
  29. package/lib/__test__/unit/serializations.unit.test.js +73 -0
  30. package/lib/__test__/unit/serializations.unit.test.js.map +1 -0
  31. package/lib/__test__/unit/transaction.unit.test.d.ts +2 -0
  32. package/lib/__test__/unit/transaction.unit.test.d.ts.map +1 -0
  33. package/lib/__test__/unit/transaction.unit.test.js +130 -0
  34. package/lib/__test__/unit/transaction.unit.test.js.map +1 -0
  35. package/lib/account.d.ts +7 -0
  36. package/lib/account.d.ts.map +1 -0
  37. package/lib/account.js +26 -0
  38. package/lib/account.js.map +1 -0
  39. package/lib/api/api-type.d.ts +62 -0
  40. package/lib/api/api-type.d.ts.map +1 -0
  41. package/lib/api/api-type.js +3 -0
  42. package/lib/api/api-type.js.map +1 -0
  43. package/lib/api/index.d.ts +13 -0
  44. package/lib/api/index.d.ts.map +1 -0
  45. package/lib/api/index.js +134 -0
  46. package/lib/api/index.js.map +1 -0
  47. package/lib/api/node.d.ts +31 -0
  48. package/lib/api/node.d.ts.map +1 -0
  49. package/lib/api/node.js +112 -0
  50. package/lib/api/node.js.map +1 -0
  51. package/lib/bridge/index.d.ts +13 -0
  52. package/lib/bridge/index.d.ts.map +1 -0
  53. package/lib/bridge/index.js +71 -0
  54. package/lib/bridge/index.js.map +1 -0
  55. package/lib/bridge.integration.test.d.ts +4 -0
  56. package/lib/bridge.integration.test.d.ts.map +1 -0
  57. package/lib/bridge.integration.test.js +105 -0
  58. package/lib/bridge.integration.test.js.map +1 -0
  59. package/lib/broadcast.d.ts +9 -0
  60. package/lib/broadcast.d.ts.map +1 -0
  61. package/lib/broadcast.js +25 -0
  62. package/lib/broadcast.js.map +1 -0
  63. package/lib/buildTransaction.d.ts +12 -0
  64. package/lib/buildTransaction.d.ts.map +1 -0
  65. package/lib/buildTransaction.js +55 -0
  66. package/lib/buildTransaction.js.map +1 -0
  67. package/lib/cli-transaction.d.ts +16 -0
  68. package/lib/cli-transaction.d.ts.map +1 -0
  69. package/lib/cli-transaction.js +35 -0
  70. package/lib/cli-transaction.js.map +1 -0
  71. package/lib/config.d.ts +15 -0
  72. package/lib/config.d.ts.map +1 -0
  73. package/lib/config.js +17 -0
  74. package/lib/config.js.map +1 -0
  75. package/lib/constants.d.ts +14 -0
  76. package/lib/constants.d.ts.map +1 -0
  77. package/lib/constants.js +17 -0
  78. package/lib/constants.js.map +1 -0
  79. package/lib/createTransaction.d.ts +8 -0
  80. package/lib/createTransaction.d.ts.map +1 -0
  81. package/lib/createTransaction.js +19 -0
  82. package/lib/createTransaction.js.map +1 -0
  83. package/lib/deviceTransactionConfig.d.ts +15 -0
  84. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  85. package/lib/deviceTransactionConfig.js +24 -0
  86. package/lib/deviceTransactionConfig.js.map +1 -0
  87. package/lib/errors.d.ts +10 -0
  88. package/lib/errors.d.ts.map +1 -0
  89. package/lib/errors.js +8 -0
  90. package/lib/errors.js.map +1 -0
  91. package/lib/estimateMaxSpendable.d.ts +14 -0
  92. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  93. package/lib/estimateMaxSpendable.js +38 -0
  94. package/lib/estimateMaxSpendable.js.map +1 -0
  95. package/lib/getFeesForTransaction.d.ts +14 -0
  96. package/lib/getFeesForTransaction.d.ts.map +1 -0
  97. package/lib/getFeesForTransaction.js +44 -0
  98. package/lib/getFeesForTransaction.js.map +1 -0
  99. package/lib/getTransactionStatus.d.ts +4 -0
  100. package/lib/getTransactionStatus.d.ts.map +1 -0
  101. package/lib/getTransactionStatus.js +114 -0
  102. package/lib/getTransactionStatus.js.map +1 -0
  103. package/lib/hw-getAddress.d.ts +6 -0
  104. package/lib/hw-getAddress.d.ts.map +1 -0
  105. package/lib/hw-getAddress.js +23 -0
  106. package/lib/hw-getAddress.js.map +1 -0
  107. package/lib/initAccount.d.ts +3 -0
  108. package/lib/initAccount.d.ts.map +1 -0
  109. package/lib/initAccount.js +13 -0
  110. package/lib/initAccount.js.map +1 -0
  111. package/lib/logic.d.ts +55 -0
  112. package/lib/logic.d.ts.map +1 -0
  113. package/lib/logic.js +124 -0
  114. package/lib/logic.js.map +1 -0
  115. package/lib/prepareTransaction.d.ts +9 -0
  116. package/lib/prepareTransaction.d.ts.map +1 -0
  117. package/lib/prepareTransaction.js +33 -0
  118. package/lib/prepareTransaction.js.map +1 -0
  119. package/lib/serialization.d.ts +7 -0
  120. package/lib/serialization.d.ts.map +1 -0
  121. package/lib/serialization.js +36 -0
  122. package/lib/serialization.js.map +1 -0
  123. package/lib/signOperation.d.ts +10 -0
  124. package/lib/signOperation.d.ts.map +1 -0
  125. package/lib/signOperation.js +96 -0
  126. package/lib/signOperation.js.map +1 -0
  127. package/lib/signer.d.ts +14 -0
  128. package/lib/signer.d.ts.map +1 -0
  129. package/lib/signer.js +3 -0
  130. package/lib/signer.js.map +1 -0
  131. package/lib/specs.d.ts +7 -0
  132. package/lib/specs.d.ts.map +1 -0
  133. package/lib/specs.js +100 -0
  134. package/lib/specs.js.map +1 -0
  135. package/lib/speculos-deviceActions.d.ts +4 -0
  136. package/lib/speculos-deviceActions.d.ts.map +1 -0
  137. package/lib/speculos-deviceActions.js +44 -0
  138. package/lib/speculos-deviceActions.js.map +1 -0
  139. package/lib/synchronization.d.ts +3 -0
  140. package/lib/synchronization.d.ts.map +1 -0
  141. package/lib/synchronization.js +76 -0
  142. package/lib/synchronization.js.map +1 -0
  143. package/lib/transaction.d.ts +15 -0
  144. package/lib/transaction.d.ts.map +1 -0
  145. package/lib/transaction.js +39 -0
  146. package/lib/transaction.js.map +1 -0
  147. package/lib/types/bridge.fixture.d.ts +5 -0
  148. package/lib/types/bridge.fixture.d.ts.map +1 -0
  149. package/lib/types/bridge.fixture.js +77 -0
  150. package/lib/types/bridge.fixture.js.map +1 -0
  151. package/lib/types/index.d.ts +46 -0
  152. package/lib/types/index.d.ts.map +1 -0
  153. package/lib/types/index.js +3 -0
  154. package/lib/types/index.js.map +1 -0
  155. package/lib-es/__test__/api/index.unit.test.d.ts +2 -0
  156. package/lib-es/__test__/api/index.unit.test.d.ts.map +1 -0
  157. package/lib-es/__test__/api/index.unit.test.js +145 -0
  158. package/lib-es/__test__/api/index.unit.test.js.map +1 -0
  159. package/lib-es/__test__/unit/buildTransaction.test.d.ts +2 -0
  160. package/lib-es/__test__/unit/buildTransaction.test.d.ts.map +1 -0
  161. package/lib-es/__test__/unit/buildTransaction.test.js +71 -0
  162. package/lib-es/__test__/unit/buildTransaction.test.js.map +1 -0
  163. package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
  164. package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
  165. package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js +73 -0
  166. package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
  167. package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
  168. package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
  169. package/lib-es/__test__/unit/getTransactionStatus.unit.test.js +153 -0
  170. package/lib-es/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
  171. package/lib-es/__test__/unit/logic.unit.test.d.ts +2 -0
  172. package/lib-es/__test__/unit/logic.unit.test.d.ts.map +1 -0
  173. package/lib-es/__test__/unit/logic.unit.test.js +107 -0
  174. package/lib-es/__test__/unit/logic.unit.test.js.map +1 -0
  175. package/lib-es/__test__/unit/serializations.unit.test.d.ts +2 -0
  176. package/lib-es/__test__/unit/serializations.unit.test.d.ts.map +1 -0
  177. package/lib-es/__test__/unit/serializations.unit.test.js +71 -0
  178. package/lib-es/__test__/unit/serializations.unit.test.js.map +1 -0
  179. package/lib-es/__test__/unit/transaction.unit.test.d.ts +2 -0
  180. package/lib-es/__test__/unit/transaction.unit.test.d.ts.map +1 -0
  181. package/lib-es/__test__/unit/transaction.unit.test.js +128 -0
  182. package/lib-es/__test__/unit/transaction.unit.test.js.map +1 -0
  183. package/lib-es/account.d.ts +7 -0
  184. package/lib-es/account.d.ts.map +1 -0
  185. package/lib-es/account.js +24 -0
  186. package/lib-es/account.js.map +1 -0
  187. package/lib-es/api/api-type.d.ts +62 -0
  188. package/lib-es/api/api-type.d.ts.map +1 -0
  189. package/lib-es/api/api-type.js +2 -0
  190. package/lib-es/api/api-type.js.map +1 -0
  191. package/lib-es/api/index.d.ts +13 -0
  192. package/lib-es/api/index.d.ts.map +1 -0
  193. package/lib-es/api/index.js +123 -0
  194. package/lib-es/api/index.js.map +1 -0
  195. package/lib-es/api/node.d.ts +31 -0
  196. package/lib-es/api/node.d.ts.map +1 -0
  197. package/lib-es/api/node.js +99 -0
  198. package/lib-es/api/node.js.map +1 -0
  199. package/lib-es/bridge/index.d.ts +13 -0
  200. package/lib-es/bridge/index.d.ts.map +1 -0
  201. package/lib-es/bridge/index.js +62 -0
  202. package/lib-es/bridge/index.js.map +1 -0
  203. package/lib-es/bridge.integration.test.d.ts +4 -0
  204. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  205. package/lib-es/bridge.integration.test.js +99 -0
  206. package/lib-es/bridge.integration.test.js.map +1 -0
  207. package/lib-es/broadcast.d.ts +9 -0
  208. package/lib-es/broadcast.d.ts.map +1 -0
  209. package/lib-es/broadcast.js +21 -0
  210. package/lib-es/broadcast.js.map +1 -0
  211. package/lib-es/buildTransaction.d.ts +12 -0
  212. package/lib-es/buildTransaction.d.ts.map +1 -0
  213. package/lib-es/buildTransaction.js +48 -0
  214. package/lib-es/buildTransaction.js.map +1 -0
  215. package/lib-es/cli-transaction.d.ts +16 -0
  216. package/lib-es/cli-transaction.d.ts.map +1 -0
  217. package/lib-es/cli-transaction.js +29 -0
  218. package/lib-es/cli-transaction.js.map +1 -0
  219. package/lib-es/config.d.ts +15 -0
  220. package/lib-es/config.d.ts.map +1 -0
  221. package/lib-es/config.js +12 -0
  222. package/lib-es/config.js.map +1 -0
  223. package/lib-es/constants.d.ts +14 -0
  224. package/lib-es/constants.d.ts.map +1 -0
  225. package/lib-es/constants.js +14 -0
  226. package/lib-es/constants.js.map +1 -0
  227. package/lib-es/createTransaction.d.ts +8 -0
  228. package/lib-es/createTransaction.d.ts.map +1 -0
  229. package/lib-es/createTransaction.js +15 -0
  230. package/lib-es/createTransaction.js.map +1 -0
  231. package/lib-es/deviceTransactionConfig.d.ts +15 -0
  232. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  233. package/lib-es/deviceTransactionConfig.js +22 -0
  234. package/lib-es/deviceTransactionConfig.js.map +1 -0
  235. package/lib-es/errors.d.ts +10 -0
  236. package/lib-es/errors.d.ts.map +1 -0
  237. package/lib-es/errors.js +5 -0
  238. package/lib-es/errors.js.map +1 -0
  239. package/lib-es/estimateMaxSpendable.d.ts +14 -0
  240. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  241. package/lib-es/estimateMaxSpendable.js +31 -0
  242. package/lib-es/estimateMaxSpendable.js.map +1 -0
  243. package/lib-es/getFeesForTransaction.d.ts +14 -0
  244. package/lib-es/getFeesForTransaction.d.ts.map +1 -0
  245. package/lib-es/getFeesForTransaction.js +42 -0
  246. package/lib-es/getFeesForTransaction.js.map +1 -0
  247. package/lib-es/getTransactionStatus.d.ts +4 -0
  248. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  249. package/lib-es/getTransactionStatus.js +109 -0
  250. package/lib-es/getTransactionStatus.js.map +1 -0
  251. package/lib-es/hw-getAddress.d.ts +6 -0
  252. package/lib-es/hw-getAddress.d.ts.map +1 -0
  253. package/lib-es/hw-getAddress.js +21 -0
  254. package/lib-es/hw-getAddress.js.map +1 -0
  255. package/lib-es/initAccount.d.ts +3 -0
  256. package/lib-es/initAccount.d.ts.map +1 -0
  257. package/lib-es/initAccount.js +9 -0
  258. package/lib-es/initAccount.js.map +1 -0
  259. package/lib-es/logic.d.ts +55 -0
  260. package/lib-es/logic.d.ts.map +1 -0
  261. package/lib-es/logic.js +109 -0
  262. package/lib-es/logic.js.map +1 -0
  263. package/lib-es/prepareTransaction.d.ts +9 -0
  264. package/lib-es/prepareTransaction.d.ts.map +1 -0
  265. package/lib-es/prepareTransaction.js +26 -0
  266. package/lib-es/prepareTransaction.js.map +1 -0
  267. package/lib-es/serialization.d.ts +7 -0
  268. package/lib-es/serialization.d.ts.map +1 -0
  269. package/lib-es/serialization.js +29 -0
  270. package/lib-es/serialization.js.map +1 -0
  271. package/lib-es/signOperation.d.ts +10 -0
  272. package/lib-es/signOperation.d.ts.map +1 -0
  273. package/lib-es/signOperation.js +89 -0
  274. package/lib-es/signOperation.js.map +1 -0
  275. package/lib-es/signer.d.ts +14 -0
  276. package/lib-es/signer.d.ts.map +1 -0
  277. package/lib-es/signer.js +2 -0
  278. package/lib-es/signer.js.map +1 -0
  279. package/lib-es/specs.d.ts +7 -0
  280. package/lib-es/specs.d.ts.map +1 -0
  281. package/lib-es/specs.js +95 -0
  282. package/lib-es/specs.js.map +1 -0
  283. package/lib-es/speculos-deviceActions.d.ts +4 -0
  284. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  285. package/lib-es/speculos-deviceActions.js +41 -0
  286. package/lib-es/speculos-deviceActions.js.map +1 -0
  287. package/lib-es/synchronization.d.ts +3 -0
  288. package/lib-es/synchronization.d.ts.map +1 -0
  289. package/lib-es/synchronization.js +69 -0
  290. package/lib-es/synchronization.js.map +1 -0
  291. package/lib-es/transaction.d.ts +15 -0
  292. package/lib-es/transaction.d.ts.map +1 -0
  293. package/lib-es/transaction.js +33 -0
  294. package/lib-es/transaction.js.map +1 -0
  295. package/lib-es/types/bridge.fixture.d.ts +5 -0
  296. package/lib-es/types/bridge.fixture.d.ts.map +1 -0
  297. package/lib-es/types/bridge.fixture.js +68 -0
  298. package/lib-es/types/bridge.fixture.js.map +1 -0
  299. package/lib-es/types/index.d.ts +46 -0
  300. package/lib-es/types/index.d.ts.map +1 -0
  301. package/lib-es/types/index.js +2 -0
  302. package/lib-es/types/index.js.map +1 -0
  303. package/package.json +85 -0
  304. package/src/__test__/api/index.unit.test.ts +151 -0
  305. package/src/__test__/unit/buildTransaction.test.ts +76 -0
  306. package/src/__test__/unit/getFeesForTransaction.unit.test.ts +76 -0
  307. package/src/__test__/unit/getTransactionStatus.unit.test.ts +172 -0
  308. package/src/__test__/unit/logic.unit.test.ts +145 -0
  309. package/src/__test__/unit/serializations.unit.test.ts +92 -0
  310. package/src/__test__/unit/transaction.unit.test.ts +144 -0
  311. package/src/account.ts +30 -0
  312. package/src/api/api-type.ts +65 -0
  313. package/src/api/index.ts +156 -0
  314. package/src/api/node.ts +115 -0
  315. package/src/bridge/index.ts +76 -0
  316. package/src/bridge.integration.test.ts +107 -0
  317. package/src/broadcast.ts +18 -0
  318. package/src/buildTransaction.ts +53 -0
  319. package/src/cli-transaction.ts +49 -0
  320. package/src/config.ts +29 -0
  321. package/src/constants.ts +14 -0
  322. package/src/createTransaction.ts +16 -0
  323. package/src/deviceTransactionConfig.ts +44 -0
  324. package/src/errors.ts +5 -0
  325. package/src/estimateMaxSpendable.ts +34 -0
  326. package/src/getFeesForTransaction.ts +46 -0
  327. package/src/getTransactionStatus.ts +139 -0
  328. package/src/hw-getAddress.ts +19 -0
  329. package/src/initAccount.ts +11 -0
  330. package/src/logic.ts +132 -0
  331. package/src/prepareTransaction.ts +24 -0
  332. package/src/serialization.ts +34 -0
  333. package/src/signOperation.ts +140 -0
  334. package/src/signer.ts +14 -0
  335. package/src/specs.ts +124 -0
  336. package/src/speculos-deviceActions.ts +46 -0
  337. package/src/synchronization.ts +70 -0
  338. package/src/transaction.ts +60 -0
  339. package/src/types/bridge.fixture.ts +75 -0
  340. package/src/types/index.ts +61 -0
  341. package/tsconfig.json +12 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@ledgerhq/coin-icon",
3
+ "version": "0.4.1-next.0",
4
+ "description": "Ledger Icon Coin integration",
5
+ "keywords": [
6
+ "Ledger",
7
+ "LedgerWallet",
8
+ "icx",
9
+ "Icon",
10
+ "Hardware Wallet"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/LedgerHQ/ledger-live.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/LedgerHQ/ledger-live/issues"
18
+ },
19
+ "homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-icon",
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ "lib/*": [
26
+ "lib/*"
27
+ ],
28
+ "lib-es/*": [
29
+ "lib-es/*"
30
+ ],
31
+ "*": [
32
+ "lib/*"
33
+ ]
34
+ }
35
+ },
36
+ "exports": {
37
+ "./lib/*": "./lib/*.js",
38
+ "./lib-es/*": "./lib-es/*.js",
39
+ "./*": {
40
+ "require": "./lib/*.js",
41
+ "default": "./lib-es/*.js"
42
+ },
43
+ "./package.json": "./package.json"
44
+ },
45
+ "license": "Apache-2.0",
46
+ "dependencies": {
47
+ "@faker-js/faker": "^8.4.1",
48
+ "bignumber.js": "^9.1.2",
49
+ "expect": "^27.4.6",
50
+ "icon-sdk-js": "1.5.2",
51
+ "invariant": "^2.2.2",
52
+ "lodash": "^4.17.21",
53
+ "prando": "^6.0.1",
54
+ "rxjs": "^7.8.1",
55
+ "@ledgerhq/coin-framework": "^0.17.0-next.0",
56
+ "@ledgerhq/cryptoassets": "^13.3.0-next.0",
57
+ "@ledgerhq/devices": "^8.4.2",
58
+ "@ledgerhq/errors": "^6.18.0",
59
+ "@ledgerhq/live-env": "^2.2.0-next.0",
60
+ "@ledgerhq/live-network": "^1.4.0-next.0",
61
+ "@ledgerhq/live-promise": "^0.1.0",
62
+ "@ledgerhq/logs": "^6.12.0",
63
+ "@ledgerhq/types-cryptoassets": "^7.15.0-next.0",
64
+ "@ledgerhq/types-live": "^6.50.0-next.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/invariant": "^2.2.2",
68
+ "@types/jest": "^29.5.10",
69
+ "@types/lodash": "^4.14.191",
70
+ "jest": "^29.7.0",
71
+ "ts-jest": "^29.1.1"
72
+ },
73
+ "scripts": {
74
+ "coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-icon.json",
75
+ "clean": "rimraf lib lib-es",
76
+ "build": "tsc && tsc -m ES6 --outDir lib-es",
77
+ "prewatch": "pnpm build",
78
+ "watch": "tsc --watch",
79
+ "doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
80
+ "lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
81
+ "lint:fix": "pnpm lint --fix",
82
+ "test": "jest",
83
+ "unimported": "unimported"
84
+ }
85
+ }
@@ -0,0 +1,151 @@
1
+ import network from "@ledgerhq/live-network/network";
2
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
+
4
+ import { fetchOperationList } from "../../api";
5
+ import { IconTransactionType } from "../../api/api-type";
6
+ import { isTestnet } from "../../logic";
7
+ import { getCoinConfig } from "../../config";
8
+ import querystring from "querystring";
9
+ import * as contants from "../../constants";
10
+
11
+ // Mock the necessary modules and functions
12
+ jest.mock("@ledgerhq/live-network/network");
13
+ jest.mock("@ledgerhq/coin-framework/operation");
14
+ jest.mock("@ledgerhq/cryptoassets");
15
+ jest.mock("../../logic");
16
+ jest.mock("../../config");
17
+ jest.mock("querystring");
18
+ jest.mock("@ledgerhq/logs");
19
+
20
+ describe("ICON API", () => {
21
+ const networkMock = network as jest.Mock;
22
+ const isTestnetMock = isTestnet as jest.Mock;
23
+ const getCoinConfigMock = getCoinConfig as jest.Mock;
24
+ const querystringMock = querystring.stringify as jest.Mock;
25
+ const mockedLogic = jest.mocked(contants);
26
+
27
+ isTestnetMock.mockReturnValue(true);
28
+ getCoinConfigMock.mockReturnValue({
29
+ infra: {
30
+ indexer: "mainnet-url",
31
+ indexer_testnet: "testnet-url",
32
+ },
33
+ });
34
+ beforeEach(() => {
35
+ jest.clearAllMocks();
36
+ });
37
+
38
+ describe("fetchOperationList", () => {
39
+ it("should recursively fetch operation list correctly", async () => {
40
+ const accountId = "accountId";
41
+ const addr = "hx123";
42
+ const skip = 0;
43
+ const network = { id: "icon" } as CryptoCurrency;
44
+ const maxLength = 10;
45
+ // @ts-expect-error type
46
+ mockedLogic.LIMIT = 10;
47
+
48
+ const tx1 = {
49
+ hash: "tx1",
50
+ from_address: addr,
51
+ to_address: "hx456",
52
+ transaction_fee: "10",
53
+ block_number: 12345,
54
+ block_timestamp: 1609459200000,
55
+ status: "0x1",
56
+ value: "1000",
57
+ } as IconTransactionType;
58
+ const tx2 = {
59
+ hash: "tx2",
60
+ from_address: "hx456",
61
+ to_address: addr,
62
+ transaction_fee: "5",
63
+ block_number: 12346,
64
+ block_timestamp: 1609459201000,
65
+ status: "0x1",
66
+ value: "2000",
67
+ } as IconTransactionType;
68
+ const txHistory = [tx1, tx2];
69
+ querystringMock.mockReturnValue("address=hx123&skip=0&limit=10");
70
+ networkMock.mockResolvedValue({ data: txHistory });
71
+
72
+ const result = await fetchOperationList(accountId, addr, skip, network, maxLength);
73
+ expect(result.length).toBe(2);
74
+ expect(networkMock).toHaveBeenCalledWith({
75
+ method: "GET",
76
+ url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip}&limit=${10}`,
77
+ });
78
+ });
79
+ it("should recursively fetch operation list correctly", async () => {
80
+ const accountId = "accountId";
81
+ const addr = "hx123";
82
+ const skip = 0;
83
+ const network = { id: "icon" } as CryptoCurrency;
84
+ const maxLength = 10;
85
+ // @ts-expect-error type
86
+ mockedLogic.LIMIT = 2; // set a small limit for easier testing
87
+
88
+ const tx1 = {
89
+ hash: "tx1",
90
+ from_address: addr,
91
+ to_address: "hx456",
92
+ transaction_fee: "10",
93
+ block_number: 12345,
94
+ block_timestamp: 1609459200000,
95
+ status: "0x1",
96
+ value: "1000",
97
+ } as IconTransactionType;
98
+ const tx2 = {
99
+ hash: "tx2",
100
+ from_address: "hx456",
101
+ to_address: addr,
102
+ transaction_fee: "5",
103
+ block_number: 12346,
104
+ block_timestamp: 1609459201000,
105
+ status: "0x1",
106
+ value: "2000",
107
+ } as IconTransactionType;
108
+ const tx3 = {
109
+ hash: "tx3",
110
+ from_address: addr,
111
+ to_address: "hx456",
112
+ transaction_fee: "15",
113
+ block_number: 12347,
114
+ block_timestamp: 1609459202000,
115
+ status: "0x1",
116
+ value: "1500",
117
+ } as IconTransactionType;
118
+
119
+ networkMock
120
+ .mockResolvedValueOnce({ data: [tx1, tx2] }) // First fetch returns two transactions
121
+ .mockResolvedValueOnce({ data: [tx3] }); // Second fetch returns one transaction
122
+
123
+ querystringMock
124
+ .mockReturnValueOnce("address=hx123&skip=0&limit=2")
125
+ .mockReturnValueOnce("address=hx123&skip=2&limit=2");
126
+
127
+ const result = await fetchOperationList(accountId, addr, skip, network, maxLength);
128
+
129
+ // Verify that the function was called recursively
130
+ expect(networkMock).toHaveBeenCalledTimes(2);
131
+
132
+ // Verify that the result includes all transactions fetched
133
+ expect(result.length).toBe(3);
134
+ expect(result).toEqual([
135
+ expect.objectContaining({ hash: "tx1" }),
136
+ expect.objectContaining({ hash: "tx2" }),
137
+ expect.objectContaining({ hash: "tx3" }),
138
+ ]);
139
+
140
+ // Verify the URLs used in the network calls
141
+ expect(networkMock).toHaveBeenCalledWith({
142
+ method: "GET",
143
+ url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip}&limit=${2}`,
144
+ });
145
+ expect(networkMock).toHaveBeenCalledWith({
146
+ method: "GET",
147
+ url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip + 2}&limit=${2}`,
148
+ });
149
+ });
150
+ });
151
+ });
@@ -0,0 +1,76 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Transaction, IconAccount } from "../../types";
3
+ import { createFixtureAccount, createFixtureTransaction } from "../../types/bridge.fixture";
4
+ import { buildTransaction } from "../../buildTransaction";
5
+
6
+ const mockFrom = jest.fn().mockReturnThis();
7
+ const mockTo = jest.fn().mockReturnThis();
8
+ const mockValue = jest.fn().mockReturnThis();
9
+ const mockNid = jest.fn().mockReturnThis();
10
+ const mockNonce = jest.fn().mockReturnThis();
11
+ const mockTimestamp = jest.fn().mockReturnThis();
12
+ const mockVersion = jest.fn().mockReturnThis();
13
+ const mockStepLimit = jest.fn().mockReturnThis();
14
+ const mockBuild = jest.fn().mockReturnValue("mocked-transaction");
15
+
16
+ jest.mock("icon-sdk-js", () => ({
17
+ IconBuilder: {
18
+ IcxTransactionBuilder: jest.fn().mockImplementation(() => ({
19
+ from: mockFrom,
20
+ to: mockTo,
21
+ value: mockValue,
22
+ nid: mockNid,
23
+ nonce: mockNonce,
24
+ timestamp: mockTimestamp,
25
+ version: mockVersion,
26
+ stepLimit: mockStepLimit,
27
+ build: mockBuild,
28
+ })),
29
+ },
30
+ IconConverter: {
31
+ toHexNumber: jest.fn(value => `0x${value}`),
32
+ },
33
+ }));
34
+
35
+ jest.mock("../../logic", () => ({
36
+ getNid: jest.fn().mockReturnValue(1),
37
+ getNonce: jest.fn().mockReturnValue(1),
38
+ }));
39
+
40
+ describe("buildTransaction", () => {
41
+ const account = createFixtureAccount() as IconAccount;
42
+ const transaction = createFixtureTransaction({
43
+ mode: "send",
44
+ recipient: "WHATEVER",
45
+ }) as Transaction;
46
+
47
+ afterEach(() => {
48
+ jest.clearAllMocks();
49
+ });
50
+
51
+ it("should build a transfer transaction", async () => {
52
+ const stepLimit = new BigNumber(100000);
53
+ const result = await buildTransaction(account, transaction, stepLimit);
54
+
55
+ expect(mockFrom).toHaveBeenCalledWith(account.freshAddress);
56
+ expect(mockTo).toHaveBeenCalledWith(transaction.recipient);
57
+ expect(mockValue).toHaveBeenCalledWith(expect.any(String));
58
+ expect(mockNid).toHaveBeenCalledWith(expect.any(String));
59
+ expect(mockNonce).toHaveBeenCalledWith(expect.any(String));
60
+ expect(mockTimestamp).toHaveBeenCalledWith(expect.any(String));
61
+ expect(mockVersion).toHaveBeenCalledWith(expect.any(String));
62
+ expect(mockStepLimit).toHaveBeenCalledWith(expect.any(String));
63
+ expect(result.unsigned).toBe("mocked-transaction");
64
+ });
65
+
66
+ it("should throw an error for unsupported transaction mode", async () => {
67
+ const invalidTransaction: Transaction = {
68
+ ...transaction,
69
+ mode: "invalid-mode",
70
+ };
71
+
72
+ await expect(buildTransaction(account, invalidTransaction)).rejects.toThrow(
73
+ "Unsupported transaction mode: invalid-mode",
74
+ );
75
+ });
76
+ });
@@ -0,0 +1,76 @@
1
+ import { BigNumber } from "bignumber.js";
2
+
3
+ import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
4
+ import { IconAccount } from "../../types";
5
+ import { buildTransaction } from "../../buildTransaction";
6
+ import { getFees, getStepPrice } from "../../api/node";
7
+ import getEstimatedFees from "../../getFeesForTransaction";
8
+ import * as logic from "../../logic";
9
+
10
+ jest.mock("../../buildTransaction");
11
+ jest.mock("../../api/node");
12
+ jest.mock("@ledgerhq/cryptoassets");
13
+ jest.mock("../../logic");
14
+
15
+ const mockedLogic = jest.mocked(logic);
16
+
17
+ describe("getEstimatedFees", () => {
18
+ beforeAll(() => {
19
+ (global as any).FEES_SAFETY_BUFFER = new BigNumber(100);
20
+ });
21
+ it("should fetch the estimated fees correctly", async () => {
22
+ const account: IconAccount = {
23
+ currency: { id: "icon" },
24
+ spendableBalance: new BigNumber(1000),
25
+ pendingOperations: [],
26
+ iconResources: { nonce: 1 },
27
+ } as any;
28
+
29
+ const transaction = {
30
+ amount: new BigNumber(100),
31
+ recipient: "recipient-address",
32
+ fees: new BigNumber(10),
33
+ } as any;
34
+
35
+ const unsignedTx = {
36
+ /* mock unsigned transaction */
37
+ };
38
+ const stepLimit = new BigNumber(100000);
39
+ const stepPrice = new BigNumber(10);
40
+
41
+ (getAbandonSeedAddress as jest.Mock).mockReturnValue("fake-recipient-address");
42
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
43
+ (buildTransaction as jest.Mock).mockResolvedValue({ unsigned: unsignedTx });
44
+ (getFees as jest.Mock).mockResolvedValue(stepLimit);
45
+ (getStepPrice as jest.Mock).mockResolvedValue(stepPrice);
46
+
47
+ const estimatedFees = await getEstimatedFees({ account, transaction });
48
+ expect(estimatedFees.isEqualTo(stepLimit.multipliedBy(stepPrice))).toBe(true);
49
+ expect(transaction.stepLimit).toEqual(stepLimit);
50
+ });
51
+
52
+ it("should return FEES_SAFETY_BUFFER if an error occurs", async () => {
53
+ const account = {
54
+ currency: { id: "icon" },
55
+ spendableBalance: new BigNumber(1000),
56
+ pendingOperations: [],
57
+ iconResources: { nonce: 1 },
58
+ } as any;
59
+
60
+ const transaction = {
61
+ amount: new BigNumber(100),
62
+ recipient: "recipient-address",
63
+ fees: new BigNumber(10),
64
+ } as any;
65
+
66
+ (getAbandonSeedAddress as jest.Mock).mockReturnValue("fake-recipient-address");
67
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
68
+ // @ts-expect-error type
69
+ mockedLogic.FEES_SAFETY_BUFFER = new BigNumber(100);
70
+ (buildTransaction as jest.Mock).mockRejectedValue(new Error("Error"));
71
+ // Mock getFees and getStepPrice if necessary, but they won't be called in this test case
72
+
73
+ const estimatedFees = await getEstimatedFees({ account, transaction });
74
+ expect(estimatedFees.isEqualTo(new BigNumber(100))).toBe(true);
75
+ });
76
+ });
@@ -0,0 +1,172 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import {
3
+ NotEnoughBalance,
4
+ RecipientRequired,
5
+ InvalidAddress,
6
+ FeeNotLoaded,
7
+ InvalidAddressBecauseDestinationIsAlsoSource,
8
+ AmountRequired,
9
+ } from "@ledgerhq/errors";
10
+ import * as logic from "../../logic";
11
+ import { IconAccount, Transaction } from "../../types";
12
+ import { getSendTransactionStatus, getTransactionStatus } from "../../getTransactionStatus";
13
+ import * as TransactionStatus from "../../getTransactionStatus";
14
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
15
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
16
+ import { IconDoMaxSendInstead } from "../../errors";
17
+
18
+ jest.mock("../../logic");
19
+ jest.mock("../../api");
20
+ jest.mock("@ledgerhq/coin-framework/currencies/index");
21
+
22
+ const mockedLogic = jest.mocked(logic);
23
+ const mockedFormatCurrencyUnit = jest.mocked(formatCurrencyUnit);
24
+
25
+ describe("getSendTransactionStatus", () => {
26
+ let account: IconAccount;
27
+ let transaction: Transaction;
28
+
29
+ beforeEach(() => {
30
+ account = {
31
+ spendableBalance: new BigNumber(1000),
32
+ currency: {
33
+ name: "Icon",
34
+ units: [
35
+ {
36
+ code: "ICX",
37
+ name: "",
38
+ magnitude: 0,
39
+ },
40
+ ],
41
+ } as CryptoCurrency,
42
+ iconResources: {
43
+ totalDelegated: new BigNumber(0),
44
+ votingPower: new BigNumber(0),
45
+ nonce: 0,
46
+ },
47
+ } as IconAccount;
48
+ transaction = {
49
+ fees: new BigNumber(10),
50
+ recipient: "test-recipient",
51
+ useAllAmount: false,
52
+ } as Transaction;
53
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
54
+ mockedLogic.getMinimumBalance.mockReturnValue(new BigNumber(50));
55
+ mockedLogic.isSelfTransaction.mockReturnValue(false);
56
+ mockedLogic.isValidAddress.mockReturnValue(true);
57
+ mockedFormatCurrencyUnit.mockReturnValue("1 ICX");
58
+ });
59
+
60
+ it("should return FeeNotLoaded error if fees are not loaded", async () => {
61
+ transaction.fees = null;
62
+ const result = await getSendTransactionStatus(account, transaction);
63
+ expect(result.errors.fees).toBeInstanceOf(FeeNotLoaded);
64
+ });
65
+
66
+ it("should return RecipientRequired error if recipient is missing", async () => {
67
+ transaction.recipient = "";
68
+ const result = await getSendTransactionStatus(account, transaction);
69
+ expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
70
+ });
71
+
72
+ it("should return InvalidAddressBecauseDestinationIsAlsoSource error if recipient is the same as source", async () => {
73
+ mockedLogic.isSelfTransaction.mockReturnValue(true);
74
+ const result = await getSendTransactionStatus(account, transaction);
75
+ expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
76
+ });
77
+
78
+ it("should return InvalidAddress error if recipient is invalid", async () => {
79
+ mockedLogic.isValidAddress.mockReturnValue(false);
80
+ const result = await getSendTransactionStatus(account, transaction);
81
+ expect(result.errors.recipient).toBeInstanceOf(InvalidAddress);
82
+ });
83
+
84
+ it("should return AmountRequired error if amount is less than or equal to zero", async () => {
85
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(0));
86
+ const result = await getSendTransactionStatus(account, transaction);
87
+ expect(result.errors.amount).toBeInstanceOf(AmountRequired);
88
+ });
89
+
90
+ it("should return NotEnoughBalance error if total spent exceeds spendable balance", async () => {
91
+ account.spendableBalance = new BigNumber(50);
92
+ const result = await getSendTransactionStatus(account, transaction);
93
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
94
+ });
95
+
96
+ it("should return proper TransactionStatus when everything is valid", async () => {
97
+ const result = await getSendTransactionStatus(account, transaction);
98
+ expect(result.errors).toEqual({});
99
+ expect(result.warnings).toEqual({});
100
+ expect(result.estimatedFees).toEqual(transaction.fees);
101
+ expect(result.amount).toEqual(new BigNumber(100));
102
+ expect(result.totalSpent).toEqual(new BigNumber(110));
103
+ });
104
+
105
+ it("should return IconDoMaxSendInstead error if leftover balance is less than minimumBalanceExistential but greater than zero", async () => {
106
+ account.spendableBalance = new BigNumber(120);
107
+ const result = await getSendTransactionStatus(account, transaction);
108
+ expect(result.errors.amount).toBeInstanceOf(IconDoMaxSendInstead);
109
+ expect(result.errors.amount.message).toBe(
110
+ "Balance cannot be below {{minimumBalance}}. Send max to empty account.",
111
+ );
112
+ });
113
+ });
114
+
115
+ describe("getTransactionStatus", () => {
116
+ let account: IconAccount;
117
+ let transaction: Transaction;
118
+
119
+ beforeEach(() => {
120
+ account = {
121
+ spendableBalance: new BigNumber(1000),
122
+ currency: { name: "ICON", units: [{ code: "ICX" }] },
123
+ } as IconAccount;
124
+ transaction = {
125
+ fees: new BigNumber(10),
126
+ mode: "send",
127
+ useAllAmount: false,
128
+ } as Transaction;
129
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
130
+ });
131
+
132
+ it("should delegate to getSendTransactionStatus for send mode", async () => {
133
+ const sendTransactionStatus = {
134
+ errors: {},
135
+ warnings: {},
136
+ estimatedFees: new BigNumber(10),
137
+ amount: new BigNumber(100),
138
+ totalSpent: new BigNumber(110),
139
+ } as any;
140
+ jest
141
+ .spyOn(TransactionStatus, "getSendTransactionStatus")
142
+ .mockResolvedValue(sendTransactionStatus);
143
+ const result = await getTransactionStatus(account, transaction);
144
+ expect(result).toEqual(sendTransactionStatus);
145
+ });
146
+
147
+ it("should handle default case correctly", async () => {
148
+ transaction.mode = "other";
149
+ const result = await getTransactionStatus(account, transaction);
150
+ expect(result.errors).toEqual({});
151
+ expect(result.warnings).toEqual({});
152
+ expect(result.estimatedFees).toEqual(transaction.fees);
153
+ expect(result.amount).toEqual(new BigNumber(100));
154
+ expect(result.totalSpent).toEqual(new BigNumber(110));
155
+ });
156
+
157
+ it("should return NotEnoughBalance error if totalSpent is greater than spendableBalance", async () => {
158
+ transaction.mode = "";
159
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(1000));
160
+ transaction.fees = new BigNumber(100);
161
+ const result = await getTransactionStatus(account, transaction);
162
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
163
+ });
164
+
165
+ it("should return AmountRequired error if amount is less than or equal to zero and useAllAmount is false", async () => {
166
+ transaction.mode = "";
167
+ mockedLogic.calculateAmount.mockReturnValue(new BigNumber(0));
168
+ transaction.useAllAmount = false;
169
+ const result = await getTransactionStatus(account, transaction);
170
+ expect(result.errors.amount).toBeInstanceOf(AmountRequired);
171
+ });
172
+ });