@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 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,wBAAwB,GAAG,4CAA4C,CAAC;AACxE,QAAA,kBAAkB,GAAG,4CAA4C,CAAC;AAClE,QAAA,KAAK,GAAG,GAAG,CAAC;AACZ,QAAA,kBAAkB,GAAG,CAAC,CAAC;AACvB,QAAA,WAAW,GAAG,CAAC,CAAC;AAChB,QAAA,YAAY,GAAG,IAAI,CAAC;AACpB,QAAA,WAAW,GAAG,CAAC,CAAC;AAChB,QAAA,kBAAkB,GAAG,MAAM,CAAC;AAE5B,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;IAChB,SAAS,EAAE,WAAW;CACvB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Transaction } from "./types";
2
+ /**
3
+ * Create an empty transaction
4
+ *
5
+ * @returns {Transaction}
6
+ */
7
+ export declare const createTransaction: () => Transaction;
8
+ //# sourceMappingURL=createTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransaction.d.ts","sourceRoot":"","sources":["../src/createTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAO,WAOnC,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTransaction = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ /**
6
+ * Create an empty transaction
7
+ *
8
+ * @returns {Transaction}
9
+ */
10
+ const createTransaction = () => ({
11
+ family: "icon",
12
+ mode: "send",
13
+ amount: new bignumber_js_1.BigNumber(0),
14
+ recipient: "",
15
+ useAllAmount: false,
16
+ fees: null,
17
+ });
18
+ exports.createTransaction = createTransaction;
19
+ //# sourceMappingURL=createTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransaction.js","sourceRoot":"","sources":["../src/createTransaction.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAGzC;;;;GAIG;AACI,MAAM,iBAAiB,GAAG,GAAgB,EAAE,CAAC,CAAC;IACnD,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC;IACxB,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,KAAK;IACnB,IAAI,EAAE,IAAI;CACX,CAAC,CAAC;AAPU,QAAA,iBAAiB,qBAO3B"}
@@ -0,0 +1,15 @@
1
+ import type { AccountLike, Account } from "@ledgerhq/types-live";
2
+ import type { Transaction, TransactionStatus } from "./types";
3
+ import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
4
+ export type ExtraDeviceTransactionField = {
5
+ type: "icon.fees";
6
+ label: string;
7
+ };
8
+ declare function getDeviceTransactionConfig({ transaction, account, parentAccount, status: { amount }, }: {
9
+ account: AccountLike;
10
+ parentAccount?: Account;
11
+ transaction: Transaction;
12
+ status: TransactionStatus;
13
+ }): Array<DeviceTransactionField>;
14
+ export default getDeviceTransactionConfig;
15
+ //# sourceMappingURL=deviceTransactionConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceTransactionConfig.d.ts","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,IAAI,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAG1H,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,iBAAS,0BAA0B,CAAC,EAClC,WAAW,EACX,OAAO,EACP,aAAa,EACb,MAAM,EAAE,EAAE,MAAM,EAAE,GACnB,EAAE;IACD,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,GAAG,KAAK,CAAC,sBAAsB,CAAC,CAqBhC;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("@ledgerhq/coin-framework/account/index");
4
+ function getDeviceTransactionConfig({ transaction, account, parentAccount, status: { amount }, }) {
5
+ const fields = [];
6
+ const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
7
+ const { mode } = transaction;
8
+ if (!amount.isZero()) {
9
+ fields.push({
10
+ type: "amount",
11
+ label: "Amount",
12
+ });
13
+ }
14
+ if (mode !== "send") {
15
+ fields.push({
16
+ type: "address",
17
+ label: "From Address",
18
+ address: mainAccount.freshAddress,
19
+ });
20
+ }
21
+ return fields;
22
+ }
23
+ exports.default = getDeviceTransactionConfig;
24
+ //# sourceMappingURL=deviceTransactionConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceTransactionConfig.js","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":";;AAGA,kEAAwE;AAOxE,SAAS,0BAA0B,CAAC,EAClC,WAAW,EACX,OAAO,EACP,aAAa,EACb,MAAM,EAAE,EAAE,MAAM,EAAE,GAMnB;IACC,MAAM,MAAM,GAAkC,EAAE,CAAC;IACjD,MAAM,WAAW,GAAG,IAAA,sBAAc,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAE7B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,WAAW,CAAC,YAAY;SAClC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,0BAA0B,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare const IconAllFundsWarning: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
2
+ [key: string]: unknown;
3
+ }>;
4
+ export declare const IconValidatorsRequired: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
5
+ [key: string]: unknown;
6
+ }>;
7
+ export declare const IconDoMaxSendInstead: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
8
+ [key: string]: unknown;
9
+ }>;
10
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;EAAgD,CAAC;AACjF,eAAO,MAAM,sBAAsB;;EAAmD,CAAC;AACvF,eAAO,MAAM,oBAAoB;;EAAiD,CAAC"}
package/lib/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IconDoMaxSendInstead = exports.IconValidatorsRequired = exports.IconAllFundsWarning = void 0;
4
+ const errors_1 = require("@ledgerhq/errors");
5
+ exports.IconAllFundsWarning = (0, errors_1.createCustomErrorClass)("IconAllFundsWarning");
6
+ exports.IconValidatorsRequired = (0, errors_1.createCustomErrorClass)("IconValidatorsRequired");
7
+ exports.IconDoMaxSendInstead = (0, errors_1.createCustomErrorClass)("IconDoMaxSendInstead");
8
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE7C,QAAA,mBAAmB,GAAG,IAAA,+BAAsB,EAAC,qBAAqB,CAAC,CAAC;AACpE,QAAA,sBAAsB,GAAG,IAAA,+BAAsB,EAAC,wBAAwB,CAAC,CAAC;AAC1E,QAAA,oBAAoB,GAAG,IAAA,+BAAsB,EAAC,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { AccountLike, Account } from "@ledgerhq/types-live";
3
+ import type { Transaction } from "./types";
4
+ /**
5
+ * Returns the maximum possible amount for transaction
6
+ *
7
+ * @param {Object} param - the account, parentAccount and transaction
8
+ */
9
+ export declare const estimateMaxSpendable: ({ account, parentAccount, transaction, }: {
10
+ account: AccountLike;
11
+ parentAccount: Account | null | undefined;
12
+ transaction: Transaction | null | undefined;
13
+ }) => Promise<BigNumber>;
14
+ //# sourceMappingURL=estimateMaxSpendable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAKxD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;aAKtB,WAAW;mBACL,OAAO,GAAG,IAAI,GAAG,SAAS;iBAC5B,WAAW,GAAG,IAAI,GAAG,SAAS;MACzC,QAAQ,SAAS,CAYpB,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.estimateMaxSpendable = void 0;
16
+ const index_1 = require("@ledgerhq/coin-framework/account/index");
17
+ const createTransaction_1 = require("./createTransaction");
18
+ const getFeesForTransaction_1 = __importDefault(require("./getFeesForTransaction"));
19
+ const logic_1 = require("./logic");
20
+ /**
21
+ * Returns the maximum possible amount for transaction
22
+ *
23
+ * @param {Object} param - the account, parentAccount and transaction
24
+ */
25
+ const estimateMaxSpendable = (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, parentAccount, transaction, }) {
26
+ const acc = (0, index_1.getMainAccount)(account, parentAccount);
27
+ const tx = Object.assign(Object.assign(Object.assign({}, (0, createTransaction_1.createTransaction)()), transaction), { useAllAmount: true });
28
+ const fees = yield (0, getFeesForTransaction_1.default)({
29
+ account: acc,
30
+ transaction: tx,
31
+ });
32
+ return (0, logic_1.calculateAmount)({
33
+ account: acc,
34
+ transaction: Object.assign(Object.assign({}, tx), { fees }),
35
+ });
36
+ });
37
+ exports.estimateMaxSpendable = estimateMaxSpendable;
38
+ //# sourceMappingURL=estimateMaxSpendable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,kEAAwE;AAExE,2DAAwD;AACxD,oFAAuD;AACvD,mCAA0C;AAE1C;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,KAQb,EAAE,4CARkB,EACzC,OAAO,EACP,aAAa,EACb,WAAW,GAKZ;IACC,MAAM,GAAG,GAAG,IAAA,sBAAc,EAAC,OAAO,EAAE,aAAa,CAAgB,CAAC;IAClE,MAAM,EAAE,iDAAQ,IAAA,qCAAiB,GAAE,GAAK,WAAW,KAAE,YAAY,EAAE,IAAI,GAAE,CAAC;IAC1E,MAAM,IAAI,GAAG,MAAM,IAAA,+BAAgB,EAAC;QAClC,OAAO,EAAE,GAAG;QACZ,WAAW,EAAE,EAAE;KAChB,CAAC,CAAC;IAEH,OAAO,IAAA,uBAAe,EAAC;QACrB,OAAO,EAAE,GAAG;QACZ,WAAW,kCAAO,EAAE,KAAE,IAAI,GAAE;KAC7B,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AApBW,QAAA,oBAAoB,wBAoB/B"}
@@ -0,0 +1,14 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { IconAccount, Transaction } from "./types";
3
+ /**
4
+ * Fetch the transaction fees for a transaction
5
+ *
6
+ * @param {IconAccount} account
7
+ * @param {Transaction} transaction
8
+ */
9
+ declare const getEstimatedFees: ({ account, transaction, }: {
10
+ account: IconAccount;
11
+ transaction: Transaction;
12
+ }) => Promise<BigNumber>;
13
+ export default getEstimatedFees;
14
+ //# sourceMappingURL=getFeesForTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFeesForTransaction.d.ts","sourceRoot":"","sources":["../src/getFeesForTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAOxD;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB;aAIX,WAAW;iBACP,WAAW;MACtB,QAAQ,SAAS,CAuBpB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const bignumber_js_1 = require("bignumber.js");
13
+ const node_1 = require("./api/node");
14
+ const buildTransaction_1 = require("./buildTransaction");
15
+ const node_2 = require("./api/node");
16
+ const logic_1 = require("./logic");
17
+ const cryptoassets_1 = require("@ledgerhq/cryptoassets");
18
+ /**
19
+ * Fetch the transaction fees for a transaction
20
+ *
21
+ * @param {IconAccount} account
22
+ * @param {Transaction} transaction
23
+ */
24
+ const getEstimatedFees = (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, transaction, }) {
25
+ const tx = Object.assign(Object.assign({}, transaction), { recipient: (0, cryptoassets_1.getAbandonSeedAddress)(account.currency.id),
26
+ // Always use a fake recipient to estimate fees
27
+ amount: (0, logic_1.calculateAmount)({
28
+ account,
29
+ transaction: Object.assign(Object.assign({}, transaction), { fees: new bignumber_js_1.BigNumber(0) }),
30
+ }) });
31
+ try {
32
+ const { unsigned } = yield (0, buildTransaction_1.buildTransaction)(account, tx);
33
+ const stepLimit = yield (0, node_1.getFees)(unsigned, account);
34
+ transaction.stepLimit = stepLimit;
35
+ const stepPrice = yield (0, node_2.getStepPrice)(account);
36
+ return stepLimit.multipliedBy(stepPrice);
37
+ }
38
+ catch (_error) {
39
+ // Fix ME, the API of Icon throws an error when getting the fee with maximum balance
40
+ return logic_1.FEES_SAFETY_BUFFER;
41
+ }
42
+ });
43
+ exports.default = getEstimatedFees;
44
+ //# sourceMappingURL=getFeesForTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFeesForTransaction.js","sourceRoot":"","sources":["../src/getFeesForTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+CAAyC;AAEzC,qCAAqC;AACrC,yDAAsD;AACtD,qCAA0C;AAC1C,mCAA8D;AAC9D,yDAA+D;AAE/D;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,KAMF,EAAE,4CANO,EAC9B,OAAO,EACP,WAAW,GAIZ;IACC,MAAM,EAAE,mCACH,WAAW,KACd,SAAS,EAAE,IAAA,oCAAqB,EAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,+CAA+C;QAC/C,MAAM,EAAE,IAAA,uBAAe,EAAC;YACtB,OAAO;YACP,WAAW,kCACN,WAAW,KACd,IAAI,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC,GACvB;SACF,CAAC,GACH,CAAC;IACF,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,mCAAgB,EAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACzD,MAAM,SAAS,GAAG,MAAM,IAAA,cAAO,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnD,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC;QAClC,MAAM,SAAS,GAAG,MAAM,IAAA,mBAAY,EAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,oFAAoF;QACpF,OAAO,0BAAkB,CAAC;IAC5B,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,kBAAe,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { IconAccount, Transaction, TransactionStatus } from "./types";
2
+ export declare const getSendTransactionStatus: (account: IconAccount, transaction: Transaction) => Promise<TransactionStatus>;
3
+ export declare const getTransactionStatus: (account: IconAccount, transaction: Transaction) => Promise<TransactionStatus>;
4
+ //# sourceMappingURL=getTransactionStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAc3E,eAAO,MAAM,wBAAwB,YAC1B,WAAW,eACP,WAAW,KACvB,QAAQ,iBAAiB,CA4E3B,CAAC;AAEF,eAAO,MAAM,oBAAoB,YACtB,WAAW,eACP,WAAW,KACvB,QAAQ,iBAAiB,CA8B3B,CAAC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getTransactionStatus = exports.getSendTransactionStatus = void 0;
13
+ const bignumber_js_1 = require("bignumber.js");
14
+ const errors_1 = require("@ledgerhq/errors");
15
+ const logic_1 = require("./logic");
16
+ const index_1 = require("@ledgerhq/coin-framework/currencies/index");
17
+ const errors_2 = require("./errors");
18
+ const getSendTransactionStatus = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a, _b;
20
+ const errors = {};
21
+ const warnings = {};
22
+ // Check if fees are loaded
23
+ if (!transaction.fees) {
24
+ errors.fees = new errors_1.FeeNotLoaded();
25
+ }
26
+ // Validate recipient
27
+ if (!transaction.recipient) {
28
+ errors.recipient = new errors_1.RecipientRequired();
29
+ }
30
+ else if ((0, logic_1.isSelfTransaction)(account, transaction)) {
31
+ errors.recipient = new errors_1.InvalidAddressBecauseDestinationIsAlsoSource();
32
+ }
33
+ else if (!(0, logic_1.isValidAddress)(transaction.recipient)) {
34
+ errors.recipient = new errors_1.InvalidAddress("", {
35
+ currencyName: account.currency.name,
36
+ });
37
+ }
38
+ const estimatedFees = transaction.fees || new bignumber_js_1.BigNumber(0);
39
+ const amount = (0, logic_1.calculateAmount)({ account, transaction });
40
+ const totalSpent = amount.plus(estimatedFees);
41
+ // Check if amount is valid
42
+ if (amount.lte(0) && !transaction.useAllAmount) {
43
+ errors.amount = new errors_1.AmountRequired();
44
+ }
45
+ else {
46
+ const minimumBalanceExistential = (0, logic_1.getMinimumBalance)(account);
47
+ const leftover = account.spendableBalance.minus(totalSpent);
48
+ if (minimumBalanceExistential.gt(0) &&
49
+ leftover.lt(minimumBalanceExistential) &&
50
+ leftover.gt(0)) {
51
+ errors.amount = new errors_2.IconDoMaxSendInstead("Balance cannot be below {{minimumBalance}}. Send max to empty account.", {
52
+ minimumBalance: (0, index_1.formatCurrencyUnit)(account.currency.units[0], logic_1.EXISTENTIAL_DEPOSIT, {
53
+ showCode: true,
54
+ }),
55
+ });
56
+ }
57
+ else if (!errors.amount &&
58
+ !transaction.useAllAmount &&
59
+ account.spendableBalance.lte(logic_1.EXISTENTIAL_DEPOSIT.plus(logic_1.EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN))) {
60
+ errors.amount = new errors_1.NotEnoughBalance();
61
+ }
62
+ else if (totalSpent.gt(account.spendableBalance)) {
63
+ errors.amount = new errors_1.NotEnoughBalance();
64
+ }
65
+ if (!errors.amount &&
66
+ new bignumber_js_1.BigNumber((_a = account.iconResources) === null || _a === void 0 ? void 0 : _a.totalDelegated)
67
+ .plus((_b = account.iconResources) === null || _b === void 0 ? void 0 : _b.votingPower)
68
+ .gt(0) &&
69
+ (transaction.useAllAmount ||
70
+ account.spendableBalance.minus(totalSpent).lt(logic_1.FEES_SAFETY_BUFFER))) {
71
+ warnings.amount = new errors_2.IconAllFundsWarning();
72
+ }
73
+ if (totalSpent.gt(account.spendableBalance)) {
74
+ errors.amount = new errors_1.NotEnoughBalance();
75
+ }
76
+ }
77
+ return Promise.resolve({
78
+ errors,
79
+ warnings,
80
+ estimatedFees,
81
+ amount: amount.lt(0) ? new bignumber_js_1.BigNumber(0) : amount,
82
+ totalSpent,
83
+ });
84
+ });
85
+ exports.getSendTransactionStatus = getSendTransactionStatus;
86
+ const getTransactionStatus = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
87
+ switch (transaction.mode) {
88
+ case "send":
89
+ return yield (0, exports.getSendTransactionStatus)(account, transaction);
90
+ default: {
91
+ const errors = {};
92
+ const warnings = {};
93
+ const amount = (0, logic_1.calculateAmount)({ account, transaction });
94
+ const estimatedFees = transaction.fees || new bignumber_js_1.BigNumber(0);
95
+ const totalSpent = amount.plus(estimatedFees);
96
+ if (totalSpent.gt(account.spendableBalance)) {
97
+ errors.amount = new errors_1.NotEnoughBalance();
98
+ }
99
+ // Validate amount
100
+ if (amount.lte(0) && !transaction.useAllAmount) {
101
+ errors.amount = new errors_1.AmountRequired();
102
+ }
103
+ return {
104
+ errors,
105
+ warnings,
106
+ estimatedFees,
107
+ amount: amount.lt(0) ? new bignumber_js_1.BigNumber(0) : amount,
108
+ totalSpent,
109
+ };
110
+ }
111
+ }
112
+ });
113
+ exports.getTransactionStatus = getTransactionStatus;
114
+ //# sourceMappingURL=getTransactionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
3
+ import { IconSigner } from "./signer";
4
+ declare const resolver: (signerContext: SignerContext<IconSigner>) => GetAddressFn;
5
+ export default resolver;
6
+ //# sourceMappingURL=hw-getAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hw-getAddress.d.ts","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE,OAAO,EAAe,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnD,QAAA,MAAM,QAAQ,kBAAmB,cAAc,UAAU,CAAC,KAAG,YAW5D,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const resolver = (signerContext) => {
13
+ return (deviceId_1, _a) => __awaiter(void 0, [deviceId_1, _a], void 0, function* (deviceId, { path, verify }) {
14
+ const r = (yield signerContext(deviceId, signer => signer.getAddress(path, verify || false)));
15
+ return {
16
+ address: r.address,
17
+ publicKey: r.publicKey,
18
+ path,
19
+ };
20
+ });
21
+ };
22
+ exports.default = resolver;
23
+ //# sourceMappingURL=hw-getAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hw-getAddress.js","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":";;;;;;;;;;;AAKA,MAAM,QAAQ,GAAG,CAAC,aAAwC,EAAgB,EAAE;IAC1E,OAAO,iBAA8D,EAAE,wDAAzD,QAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAqB;QACjE,MAAM,CAAC,GAAG,CAAC,MAAM,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAChD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK,CAAC,CACzC,CAAgB,CAAC;QAClB,OAAO;YACL,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,IAAI;SACL,CAAC;IACJ,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Account } from "@ledgerhq/types-live";
2
+ export declare function initAccount(account: Account): void;
3
+ //# sourceMappingURL=initAccount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initAccount.d.ts","sourceRoot":"","sources":["../src/initAccount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAMlD"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initAccount = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ function initAccount(account) {
6
+ account.iconResources = {
7
+ nonce: 0,
8
+ votingPower: (0, bignumber_js_1.BigNumber)(0),
9
+ totalDelegated: (0, bignumber_js_1.BigNumber)(0),
10
+ };
11
+ }
12
+ exports.initAccount = initAccount;
13
+ //# sourceMappingURL=initAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initAccount.js","sourceRoot":"","sources":["../src/initAccount.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAIzC,SAAgB,WAAW,CAAC,OAAgB;IACzC,OAAuB,CAAC,aAAa,GAAG;QACvC,KAAK,EAAE,CAAC;QACR,WAAW,EAAE,IAAA,wBAAS,EAAC,CAAC,CAAC;QACzB,cAAc,EAAE,IAAA,wBAAS,EAAC,CAAC,CAAC;KAC7B,CAAC;AACJ,CAAC;AAND,kCAMC"}
package/lib/logic.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import type { Account } from "@ledgerhq/types-live";
4
+ import type { IconAccount, Transaction } from "./types";
5
+ /**
6
+ * @param {string|number|BigNumber} value value as loop
7
+ * @returns {BigNumber} value as ICX
8
+ */
9
+ export declare const convertLoopToIcx: (value: string | number | BigNumber) => BigNumber;
10
+ /**
11
+ * @param {string|number|BigNumber} value value as ICX
12
+ * @returns {BigNumber} value as loop
13
+ */
14
+ export declare const convertICXtoLoop: (value: string | number | BigNumber) => BigNumber;
15
+ export declare const EXISTENTIAL_DEPOSIT: BigNumber;
16
+ export declare const EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN: BigNumber;
17
+ export declare const FEES_SAFETY_BUFFER: BigNumber;
18
+ export declare const MAX_AMOUNT_INPUT: BigNumber;
19
+ /**
20
+ * Returns true if address is a valid md5
21
+ *
22
+ * @param {string} address
23
+ */
24
+ export declare const isValidAddress: (address: string) => boolean;
25
+ /**
26
+ * Returns true if transaction is a self transaction
27
+ *
28
+ * @param {Account} account
29
+ * @param {Transaction} transaction
30
+ */
31
+ export declare const isSelfTransaction: (account: Account, transaction: Transaction) => boolean;
32
+ /**
33
+ * Returns nonce for an account
34
+ *
35
+ * @param {Account} account
36
+ */
37
+ export declare const getNonce: (account: IconAccount) => number;
38
+ /**
39
+ * Returns true if the current currency is testnet
40
+ *
41
+ * @param {currency} CryptoCurrency
42
+ */
43
+ export declare function isTestnet(currency: CryptoCurrency): boolean;
44
+ export declare function getNid(currency: CryptoCurrency): number;
45
+ /**
46
+ * Calculates correct amount if useAllAmount
47
+ *
48
+ * @param {*} param
49
+ */
50
+ export declare const calculateAmount: ({ account, transaction, }: {
51
+ account: IconAccount;
52
+ transaction: Transaction;
53
+ }) => BigNumber;
54
+ export declare const getMinimumBalance: (account: Account) => BigNumber;
55
+ //# sourceMappingURL=logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIxD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,GAAG,MAAM,GAAG,SAAS,KAAG,SAErE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,GAAG,MAAM,GAAG,SAAS,KAAG,SAErE,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAA4B,CAAC;AAC7D,eAAO,MAAM,sCAAsC,WAA4B,CAAC;AAChF,eAAO,MAAM,kBAAkB,WAA4B,CAAC;AAC5D,eAAO,MAAM,gBAAgB,WAAyB,CAAC;AACvD;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,KAAG,OAGhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,YAAa,OAAO,eAAe,WAAW,KAAG,OAE9E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,YAAa,WAAW,KAAG,MAW/C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAE3D;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAMvD;AAaD;;;;GAIG;AACH,eAAO,MAAM,eAAe;aAIjB,WAAW;iBACP,WAAW;MACtB,SAkBH,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAa,OAAO,KAAG,SAKpD,CAAC"}
package/lib/logic.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMinimumBalance = exports.calculateAmount = exports.getNid = exports.isTestnet = exports.getNonce = exports.isSelfTransaction = exports.isValidAddress = exports.MAX_AMOUNT_INPUT = exports.FEES_SAFETY_BUFFER = exports.EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN = exports.EXISTENTIAL_DEPOSIT = exports.convertICXtoLoop = exports.convertLoopToIcx = void 0;
7
+ const cryptoassets_1 = require("@ledgerhq/cryptoassets");
8
+ const bignumber_js_1 = require("bignumber.js");
9
+ const icon_sdk_js_1 = __importDefault(require("icon-sdk-js"));
10
+ const { IconAmount } = icon_sdk_js_1.default;
11
+ const constants_1 = require("./constants");
12
+ /**
13
+ * @param {string|number|BigNumber} value value as loop
14
+ * @returns {BigNumber} value as ICX
15
+ */
16
+ const convertLoopToIcx = (value) => {
17
+ return new bignumber_js_1.BigNumber(IconAmount.fromLoop(value, IconAmount.Unit.ICX.toString()));
18
+ };
19
+ exports.convertLoopToIcx = convertLoopToIcx;
20
+ /**
21
+ * @param {string|number|BigNumber} value value as ICX
22
+ * @returns {BigNumber} value as loop
23
+ */
24
+ const convertICXtoLoop = (value) => {
25
+ return new bignumber_js_1.BigNumber(IconAmount.toLoop(value, IconAmount.Unit.ICX.toString()));
26
+ };
27
+ exports.convertICXtoLoop = convertICXtoLoop;
28
+ exports.EXISTENTIAL_DEPOSIT = (0, exports.convertICXtoLoop)(0.00125);
29
+ exports.EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN = (0, exports.convertICXtoLoop)(0.00125);
30
+ exports.FEES_SAFETY_BUFFER = (0, exports.convertICXtoLoop)(0.00125); // Arbitrary buffer for paying fees of next transactions
31
+ exports.MAX_AMOUNT_INPUT = (0, exports.convertICXtoLoop)(5000);
32
+ /**
33
+ * Returns true if address is a valid md5
34
+ *
35
+ * @param {string} address
36
+ */
37
+ const isValidAddress = (address) => {
38
+ if (!address)
39
+ return false;
40
+ return !!address.match(/^[a-z0-9]{42}$/);
41
+ };
42
+ exports.isValidAddress = isValidAddress;
43
+ /**
44
+ * Returns true if transaction is a self transaction
45
+ *
46
+ * @param {Account} account
47
+ * @param {Transaction} transaction
48
+ */
49
+ const isSelfTransaction = (account, transaction) => {
50
+ return transaction.recipient === account.freshAddress;
51
+ };
52
+ exports.isSelfTransaction = isSelfTransaction;
53
+ /**
54
+ * Returns nonce for an account
55
+ *
56
+ * @param {Account} account
57
+ */
58
+ const getNonce = (account) => {
59
+ var _a;
60
+ const lastPendingOp = account.pendingOperations[0];
61
+ const nonce = Math.max(((_a = account.iconResources) === null || _a === void 0 ? void 0 : _a.nonce) || 0, lastPendingOp && typeof lastPendingOp.transactionSequenceNumber === "number"
62
+ ? lastPendingOp.transactionSequenceNumber + 1
63
+ : 0);
64
+ return nonce;
65
+ };
66
+ exports.getNonce = getNonce;
67
+ /**
68
+ * Returns true if the current currency is testnet
69
+ *
70
+ * @param {currency} CryptoCurrency
71
+ */
72
+ function isTestnet(currency) {
73
+ return (0, cryptoassets_1.getCryptoCurrencyById)(currency.id).isTestnetFor ? true : false;
74
+ }
75
+ exports.isTestnet = isTestnet;
76
+ function getNid(currency) {
77
+ let nid = constants_1.MAINNET_NID;
78
+ if (isTestnet(currency)) {
79
+ nid = constants_1.BERLIN_TESTNET_NID;
80
+ }
81
+ return nid;
82
+ }
83
+ exports.getNid = getNid;
84
+ /**
85
+ * Calculate the real spendable
86
+ *
87
+ * @param {*} account
88
+ * @param {*} transaction
89
+ */
90
+ const calculateMaxSend = (account, transaction) => {
91
+ const amount = account.spendableBalance.minus(transaction.fees || 0);
92
+ return amount.lt(0) ? new bignumber_js_1.BigNumber(0) : (0, bignumber_js_1.BigNumber)(amount.toFixed(5));
93
+ };
94
+ /**
95
+ * Calculates correct amount if useAllAmount
96
+ *
97
+ * @param {*} param
98
+ */
99
+ const calculateAmount = ({ account, transaction, }) => {
100
+ let amount = transaction.amount;
101
+ if (transaction.useAllAmount) {
102
+ switch (transaction.mode) {
103
+ case "send":
104
+ amount = calculateMaxSend(account, transaction);
105
+ break;
106
+ default:
107
+ amount = account.spendableBalance.minus(transaction.fees || 0);
108
+ break;
109
+ }
110
+ }
111
+ else if (transaction.amount.gt(exports.MAX_AMOUNT_INPUT)) {
112
+ return new bignumber_js_1.BigNumber(exports.MAX_AMOUNT_INPUT);
113
+ }
114
+ return amount.lt(0) ? new bignumber_js_1.BigNumber(0) : amount;
115
+ };
116
+ exports.calculateAmount = calculateAmount;
117
+ const getMinimumBalance = (account) => {
118
+ const lockedBalance = account.balance.minus(account.spendableBalance);
119
+ return lockedBalance.lte(exports.EXISTENTIAL_DEPOSIT)
120
+ ? exports.EXISTENTIAL_DEPOSIT.minus(lockedBalance)
121
+ : new bignumber_js_1.BigNumber(0);
122
+ };
123
+ exports.getMinimumBalance = getMinimumBalance;
124
+ //# sourceMappingURL=logic.js.map