@ledgerhq/coin-hedera 1.12.1-nightly.1 → 1.13.0-nightly.3

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 (386) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/jest.config.js +1 -1
  5. package/jest.integ.config.js +8 -0
  6. package/lib/api/index.d.ts +4 -0
  7. package/lib/api/index.d.ts.map +1 -0
  8. package/lib/api/index.js +119 -0
  9. package/lib/api/index.js.map +1 -0
  10. package/lib/bridge/broadcast.d.ts +1 -1
  11. package/lib/bridge/broadcast.d.ts.map +1 -1
  12. package/lib/bridge/broadcast.js +6 -9
  13. package/lib/bridge/broadcast.js.map +1 -1
  14. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  15. package/lib/bridge/buildOptimisticOperation.js +14 -11
  16. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  17. package/lib/bridge/createTransaction.d.ts +1 -1
  18. package/lib/bridge/createTransaction.d.ts.map +1 -1
  19. package/lib/bridge/createTransaction.js +2 -0
  20. package/lib/bridge/createTransaction.js.map +1 -1
  21. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  22. package/lib/bridge/estimateMaxSpendable.js +2 -2
  23. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  24. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  25. package/lib/bridge/getTransactionStatus.js +11 -10
  26. package/lib/bridge/getTransactionStatus.js.map +1 -1
  27. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  28. package/lib/bridge/prepareTransaction.js +6 -5
  29. package/lib/bridge/prepareTransaction.js.map +1 -1
  30. package/lib/bridge/signOperation.d.ts +1 -1
  31. package/lib/bridge/signOperation.d.ts.map +1 -1
  32. package/lib/bridge/signOperation.js +53 -14
  33. package/lib/bridge/signOperation.js.map +1 -1
  34. package/lib/bridge/synchronisation.d.ts.map +1 -1
  35. package/lib/bridge/synchronisation.js +24 -11
  36. package/lib/bridge/synchronisation.js.map +1 -1
  37. package/lib/bridge/utils.d.ts +3 -13
  38. package/lib/bridge/utils.d.ts.map +1 -1
  39. package/lib/bridge/utils.js +10 -119
  40. package/lib/bridge/utils.js.map +1 -1
  41. package/lib/config.d.ts +8 -0
  42. package/lib/config.d.ts.map +1 -0
  43. package/lib/config.js +9 -0
  44. package/lib/config.js.map +1 -0
  45. package/lib/constants.d.ts +11 -8
  46. package/lib/constants.d.ts.map +1 -1
  47. package/lib/constants.js +17 -13
  48. package/lib/constants.js.map +1 -1
  49. package/lib/deviceTransactionConfig.d.ts +2 -2
  50. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  51. package/lib/deviceTransactionConfig.js +4 -4
  52. package/lib/deviceTransactionConfig.js.map +1 -1
  53. package/lib/logic/broadcast.d.ts +3 -0
  54. package/lib/logic/broadcast.d.ts.map +1 -0
  55. package/lib/logic/broadcast.js +11 -0
  56. package/lib/logic/broadcast.js.map +1 -0
  57. package/lib/logic/combine.d.ts +2 -0
  58. package/lib/logic/combine.d.ts.map +1 -0
  59. package/lib/logic/combine.js +19 -0
  60. package/lib/logic/combine.js.map +1 -0
  61. package/lib/logic/craftTransaction.d.ts +8 -0
  62. package/lib/logic/craftTransaction.d.ts.map +1 -0
  63. package/lib/logic/craftTransaction.js +107 -0
  64. package/lib/logic/craftTransaction.js.map +1 -0
  65. package/lib/logic/estimateFees.d.ts +5 -0
  66. package/lib/logic/estimateFees.d.ts.map +1 -0
  67. package/lib/logic/estimateFees.js +25 -0
  68. package/lib/logic/estimateFees.js.map +1 -0
  69. package/lib/logic/getAssetFromToken.d.ts +4 -0
  70. package/lib/logic/getAssetFromToken.d.ts.map +1 -0
  71. package/lib/logic/getAssetFromToken.js +14 -0
  72. package/lib/logic/getAssetFromToken.js.map +1 -0
  73. package/lib/logic/getBalance.d.ts +4 -0
  74. package/lib/logic/getBalance.d.ts.map +1 -0
  75. package/lib/logic/getBalance.js +36 -0
  76. package/lib/logic/getBalance.js.map +1 -0
  77. package/lib/logic/getTokenFromAsset.d.ts +4 -0
  78. package/lib/logic/getTokenFromAsset.d.ts.map +1 -0
  79. package/lib/logic/getTokenFromAsset.js +13 -0
  80. package/lib/logic/getTokenFromAsset.js.map +1 -0
  81. package/lib/logic/index.d.ts +10 -0
  82. package/lib/logic/index.d.ts.map +1 -0
  83. package/lib/logic/index.js +22 -0
  84. package/lib/logic/index.js.map +1 -0
  85. package/lib/logic/lastBlock.d.ts +12 -0
  86. package/lib/logic/lastBlock.d.ts.map +1 -0
  87. package/lib/logic/lastBlock.js +25 -0
  88. package/lib/logic/lastBlock.js.map +1 -0
  89. package/lib/logic/listOperations.d.ts +19 -0
  90. package/lib/logic/listOperations.d.ts.map +1 -0
  91. package/lib/logic/listOperations.js +179 -0
  92. package/lib/logic/listOperations.js.map +1 -0
  93. package/lib/logic/utils.d.ts +55 -0
  94. package/lib/logic/utils.d.ts.map +1 -0
  95. package/lib/logic/utils.js +197 -0
  96. package/lib/logic/utils.js.map +1 -0
  97. package/lib/network/api.d.ts +24 -0
  98. package/lib/network/api.d.ts.map +1 -0
  99. package/lib/network/api.js +119 -0
  100. package/lib/network/api.js.map +1 -0
  101. package/lib/network/rpc.d.ts +12 -0
  102. package/lib/network/rpc.d.ts.map +1 -0
  103. package/lib/network/rpc.js +22 -0
  104. package/lib/network/rpc.js.map +1 -0
  105. package/lib/{api → network}/utils.d.ts +1 -5
  106. package/lib/network/utils.d.ts.map +1 -0
  107. package/lib/network/utils.js +52 -0
  108. package/lib/network/utils.js.map +1 -0
  109. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  110. package/lib/test/bridgeDatasetTest.js +5 -1
  111. package/lib/test/bridgeDatasetTest.js.map +1 -1
  112. package/lib/test/fixtures/account.fixture.d.ts +17 -0
  113. package/lib/test/fixtures/account.fixture.d.ts.map +1 -1
  114. package/lib/test/fixtures/account.fixture.js +18 -1
  115. package/lib/test/fixtures/account.fixture.js.map +1 -1
  116. package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
  117. package/lib/test/fixtures/currency.fixture.js +1 -1
  118. package/lib/test/fixtures/currency.fixture.js.map +1 -1
  119. package/lib/test/fixtures/mirror.fixture.d.ts +1 -1
  120. package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
  121. package/lib/test/fixtures/network.fixture.d.ts +3 -0
  122. package/lib/test/fixtures/network.fixture.d.ts.map +1 -0
  123. package/lib/test/fixtures/network.fixture.js +9 -0
  124. package/lib/test/fixtures/network.fixture.js.map +1 -0
  125. package/lib/test/fixtures/transaction.fixture.d.ts.map +1 -1
  126. package/lib/test/fixtures/transaction.fixture.js +3 -0
  127. package/lib/test/fixtures/transaction.fixture.js.map +1 -1
  128. package/lib/transaction.d.ts +1 -1
  129. package/lib/transaction.d.ts.map +1 -1
  130. package/lib/transaction.js +35 -6
  131. package/lib/transaction.js.map +1 -1
  132. package/lib/types/alpaca.d.ts +3 -0
  133. package/lib/types/alpaca.d.ts.map +1 -0
  134. package/lib/{api/types.js → types/alpaca.js} +1 -1
  135. package/lib/types/alpaca.js.map +1 -0
  136. package/lib/types/bridge.d.ts +28 -9
  137. package/lib/types/bridge.d.ts.map +1 -1
  138. package/lib/types/index.d.ts +2 -0
  139. package/lib/types/index.d.ts.map +1 -1
  140. package/lib/types/index.js +2 -0
  141. package/lib/types/index.js.map +1 -1
  142. package/lib/{api/types.d.ts → types/mirror.d.ts} +21 -2
  143. package/lib/types/mirror.d.ts.map +1 -0
  144. package/lib/types/mirror.js +3 -0
  145. package/lib/types/mirror.js.map +1 -0
  146. package/lib-es/api/index.d.ts +4 -0
  147. package/lib-es/api/index.d.ts.map +1 -0
  148. package/lib-es/api/index.js +112 -0
  149. package/lib-es/api/index.js.map +1 -0
  150. package/lib-es/bridge/broadcast.d.ts +1 -1
  151. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  152. package/lib-es/bridge/broadcast.js +4 -7
  153. package/lib-es/bridge/broadcast.js.map +1 -1
  154. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  155. package/lib-es/bridge/buildOptimisticOperation.js +12 -9
  156. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  157. package/lib-es/bridge/createTransaction.d.ts +1 -1
  158. package/lib-es/bridge/createTransaction.d.ts.map +1 -1
  159. package/lib-es/bridge/createTransaction.js +2 -0
  160. package/lib-es/bridge/createTransaction.js.map +1 -1
  161. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  162. package/lib-es/bridge/estimateMaxSpendable.js +2 -2
  163. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  164. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  165. package/lib-es/bridge/getTransactionStatus.js +7 -6
  166. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  167. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  168. package/lib-es/bridge/prepareTransaction.js +4 -3
  169. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  170. package/lib-es/bridge/signOperation.d.ts +1 -1
  171. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  172. package/lib-es/bridge/signOperation.js +53 -14
  173. package/lib-es/bridge/signOperation.js.map +1 -1
  174. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  175. package/lib-es/bridge/synchronisation.js +24 -11
  176. package/lib-es/bridge/synchronisation.js.map +1 -1
  177. package/lib-es/bridge/utils.d.ts +3 -13
  178. package/lib-es/bridge/utils.d.ts.map +1 -1
  179. package/lib-es/bridge/utils.js +7 -113
  180. package/lib-es/bridge/utils.js.map +1 -1
  181. package/lib-es/config.d.ts +8 -0
  182. package/lib-es/config.d.ts.map +1 -0
  183. package/lib-es/config.js +4 -0
  184. package/lib-es/config.js.map +1 -0
  185. package/lib-es/constants.d.ts +11 -8
  186. package/lib-es/constants.d.ts.map +1 -1
  187. package/lib-es/constants.js +13 -9
  188. package/lib-es/constants.js.map +1 -1
  189. package/lib-es/deviceTransactionConfig.d.ts +2 -2
  190. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  191. package/lib-es/deviceTransactionConfig.js +2 -2
  192. package/lib-es/deviceTransactionConfig.js.map +1 -1
  193. package/lib-es/logic/broadcast.d.ts +3 -0
  194. package/lib-es/logic/broadcast.d.ts.map +1 -0
  195. package/lib-es/logic/broadcast.js +7 -0
  196. package/lib-es/logic/broadcast.js.map +1 -0
  197. package/lib-es/logic/combine.d.ts +2 -0
  198. package/lib-es/logic/combine.d.ts.map +1 -0
  199. package/lib-es/logic/combine.js +12 -0
  200. package/lib-es/logic/combine.js.map +1 -0
  201. package/lib-es/logic/craftTransaction.d.ts +8 -0
  202. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  203. package/lib-es/logic/craftTransaction.js +100 -0
  204. package/lib-es/logic/craftTransaction.js.map +1 -0
  205. package/lib-es/logic/estimateFees.d.ts +5 -0
  206. package/lib-es/logic/estimateFees.d.ts.map +1 -0
  207. package/lib-es/logic/estimateFees.js +18 -0
  208. package/lib-es/logic/estimateFees.js.map +1 -0
  209. package/lib-es/logic/getAssetFromToken.d.ts +4 -0
  210. package/lib-es/logic/getAssetFromToken.d.ts.map +1 -0
  211. package/lib-es/logic/getAssetFromToken.js +10 -0
  212. package/lib-es/logic/getAssetFromToken.js.map +1 -0
  213. package/lib-es/logic/getBalance.d.ts +4 -0
  214. package/lib-es/logic/getBalance.d.ts.map +1 -0
  215. package/lib-es/logic/getBalance.js +32 -0
  216. package/lib-es/logic/getBalance.js.map +1 -0
  217. package/lib-es/logic/getTokenFromAsset.d.ts +4 -0
  218. package/lib-es/logic/getTokenFromAsset.d.ts.map +1 -0
  219. package/lib-es/logic/getTokenFromAsset.js +9 -0
  220. package/lib-es/logic/getTokenFromAsset.js.map +1 -0
  221. package/lib-es/logic/index.d.ts +10 -0
  222. package/lib-es/logic/index.d.ts.map +1 -0
  223. package/lib-es/logic/index.js +10 -0
  224. package/lib-es/logic/index.js.map +1 -0
  225. package/lib-es/logic/lastBlock.d.ts +12 -0
  226. package/lib-es/logic/lastBlock.d.ts.map +1 -0
  227. package/lib-es/logic/lastBlock.js +21 -0
  228. package/lib-es/logic/lastBlock.js.map +1 -0
  229. package/lib-es/logic/listOperations.d.ts +19 -0
  230. package/lib-es/logic/listOperations.d.ts.map +1 -0
  231. package/lib-es/logic/listOperations.js +172 -0
  232. package/lib-es/logic/listOperations.js.map +1 -0
  233. package/lib-es/logic/utils.d.ts +55 -0
  234. package/lib-es/logic/utils.d.ts.map +1 -0
  235. package/lib-es/logic/utils.js +174 -0
  236. package/lib-es/logic/utils.js.map +1 -0
  237. package/lib-es/network/api.d.ts +24 -0
  238. package/lib-es/network/api.d.ts.map +1 -0
  239. package/lib-es/network/api.js +113 -0
  240. package/lib-es/network/api.js.map +1 -0
  241. package/lib-es/network/rpc.d.ts +12 -0
  242. package/lib-es/network/rpc.d.ts.map +1 -0
  243. package/lib-es/network/rpc.js +19 -0
  244. package/lib-es/network/rpc.js.map +1 -0
  245. package/lib-es/{api → network}/utils.d.ts +1 -5
  246. package/lib-es/network/utils.d.ts.map +1 -0
  247. package/lib-es/network/utils.js +45 -0
  248. package/lib-es/network/utils.js.map +1 -0
  249. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  250. package/lib-es/test/bridgeDatasetTest.js +5 -1
  251. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  252. package/lib-es/test/fixtures/account.fixture.d.ts +17 -0
  253. package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -1
  254. package/lib-es/test/fixtures/account.fixture.js +17 -0
  255. package/lib-es/test/fixtures/account.fixture.js.map +1 -1
  256. package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
  257. package/lib-es/test/fixtures/currency.fixture.js +1 -1
  258. package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
  259. package/lib-es/test/fixtures/mirror.fixture.d.ts +1 -1
  260. package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
  261. package/lib-es/test/fixtures/network.fixture.d.ts +3 -0
  262. package/lib-es/test/fixtures/network.fixture.d.ts.map +1 -0
  263. package/lib-es/test/fixtures/network.fixture.js +5 -0
  264. package/lib-es/test/fixtures/network.fixture.js.map +1 -0
  265. package/lib-es/test/fixtures/transaction.fixture.d.ts.map +1 -1
  266. package/lib-es/test/fixtures/transaction.fixture.js +3 -0
  267. package/lib-es/test/fixtures/transaction.fixture.js.map +1 -1
  268. package/lib-es/transaction.d.ts +1 -1
  269. package/lib-es/transaction.d.ts.map +1 -1
  270. package/lib-es/transaction.js +35 -6
  271. package/lib-es/transaction.js.map +1 -1
  272. package/lib-es/types/alpaca.d.ts +3 -0
  273. package/lib-es/types/alpaca.d.ts.map +1 -0
  274. package/lib-es/types/alpaca.js +2 -0
  275. package/lib-es/types/alpaca.js.map +1 -0
  276. package/lib-es/types/bridge.d.ts +28 -9
  277. package/lib-es/types/bridge.d.ts.map +1 -1
  278. package/lib-es/types/index.d.ts +2 -0
  279. package/lib-es/types/index.d.ts.map +1 -1
  280. package/lib-es/types/index.js +2 -0
  281. package/lib-es/types/index.js.map +1 -1
  282. package/lib-es/{api/types.d.ts → types/mirror.d.ts} +21 -2
  283. package/lib-es/types/mirror.d.ts.map +1 -0
  284. package/lib-es/types/mirror.js +2 -0
  285. package/lib-es/types/mirror.js.map +1 -0
  286. package/package.json +8 -7
  287. package/src/api/index.integ.test.ts +401 -0
  288. package/src/api/index.test.ts +30 -0
  289. package/src/api/index.ts +149 -0
  290. package/src/bridge/broadcast.ts +5 -10
  291. package/src/bridge/buildOptimisticOperation.integration.test.ts +8 -8
  292. package/src/bridge/buildOptimisticOperation.ts +13 -10
  293. package/src/bridge/createTransaction.ts +3 -1
  294. package/src/bridge/estimateMaxSpendable.ts +6 -3
  295. package/src/bridge/getTransactionStatus.test.ts +11 -10
  296. package/src/bridge/getTransactionStatus.ts +12 -11
  297. package/src/bridge/js-estimateMaxSpendable.integration.test.ts +6 -3
  298. package/src/bridge/prepareTransaction.test.ts +9 -17
  299. package/src/bridge/prepareTransaction.ts +5 -4
  300. package/src/bridge/serialization.test.ts +6 -6
  301. package/src/bridge/signOperation.ts +69 -16
  302. package/src/bridge/synchronisation.ts +22 -14
  303. package/src/bridge/utils.integration.test.ts +19 -248
  304. package/src/bridge/utils.ts +14 -160
  305. package/src/config.ts +7 -0
  306. package/src/constants.ts +15 -9
  307. package/src/deviceTransactionConfig.ts +4 -4
  308. package/src/logic/broadcast.test.ts +58 -0
  309. package/src/logic/broadcast.ts +8 -0
  310. package/src/logic/combine.test.ts +119 -0
  311. package/src/logic/combine.ts +14 -0
  312. package/src/logic/craftTransaction.test.ts +215 -0
  313. package/src/logic/craftTransaction.ts +175 -0
  314. package/src/logic/estimateFees.test.ts +99 -0
  315. package/src/logic/estimateFees.ts +28 -0
  316. package/src/logic/getAssetFromToken.test.ts +27 -0
  317. package/src/logic/getAssetFromToken.ts +12 -0
  318. package/src/logic/getBalance.test.ts +200 -0
  319. package/src/logic/getBalance.ts +39 -0
  320. package/src/logic/getTokenFromAsset.test.ts +22 -0
  321. package/src/logic/getTokenFromAsset.ts +17 -0
  322. package/src/logic/index.ts +9 -0
  323. package/src/logic/lastBlock.test.ts +23 -0
  324. package/src/logic/lastBlock.ts +23 -0
  325. package/src/logic/listOperations.test.ts +388 -0
  326. package/src/logic/listOperations.ts +247 -0
  327. package/src/logic/utils.test.ts +432 -0
  328. package/src/logic/utils.ts +255 -0
  329. package/src/{api/mirror.test.ts → network/api.test.ts} +81 -35
  330. package/src/network/api.ts +159 -0
  331. package/src/network/rpc.test.ts +68 -0
  332. package/src/network/rpc.ts +25 -0
  333. package/src/network/utils.test.ts +175 -0
  334. package/src/network/utils.ts +58 -0
  335. package/src/test/bridgeDatasetTest.ts +6 -2
  336. package/src/test/fixtures/account.fixture.ts +18 -0
  337. package/src/test/fixtures/currency.fixture.ts +1 -1
  338. package/src/test/fixtures/mirror.fixture.ts +1 -1
  339. package/src/test/fixtures/network.fixture.ts +6 -0
  340. package/src/test/fixtures/transaction.fixture.ts +5 -2
  341. package/src/transaction.ts +40 -9
  342. package/src/types/alpaca.ts +3 -0
  343. package/src/types/bridge.ts +36 -10
  344. package/src/types/index.ts +2 -0
  345. package/src/{api/types.ts → types/mirror.ts} +23 -1
  346. package/lib/api/mirror.d.ts +0 -6
  347. package/lib/api/mirror.d.ts.map +0 -1
  348. package/lib/api/mirror.js +0 -84
  349. package/lib/api/mirror.js.map +0 -1
  350. package/lib/api/network.d.ts +0 -11
  351. package/lib/api/network.d.ts.map +0 -1
  352. package/lib/api/network.js +0 -80
  353. package/lib/api/network.js.map +0 -1
  354. package/lib/api/types.d.ts.map +0 -1
  355. package/lib/api/types.js.map +0 -1
  356. package/lib/api/utils.d.ts.map +0 -1
  357. package/lib/api/utils.js +0 -132
  358. package/lib/api/utils.js.map +0 -1
  359. package/lib/logic.d.ts +0 -11
  360. package/lib/logic.d.ts.map +0 -1
  361. package/lib/logic.js +0 -37
  362. package/lib/logic.js.map +0 -1
  363. package/lib-es/api/mirror.d.ts +0 -6
  364. package/lib-es/api/mirror.d.ts.map +0 -1
  365. package/lib-es/api/mirror.js +0 -74
  366. package/lib-es/api/mirror.js.map +0 -1
  367. package/lib-es/api/network.d.ts +0 -11
  368. package/lib-es/api/network.d.ts.map +0 -1
  369. package/lib-es/api/network.js +0 -71
  370. package/lib-es/api/network.js.map +0 -1
  371. package/lib-es/api/types.d.ts.map +0 -1
  372. package/lib-es/api/types.js +0 -2
  373. package/lib-es/api/types.js.map +0 -1
  374. package/lib-es/api/utils.d.ts.map +0 -1
  375. package/lib-es/api/utils.js +0 -124
  376. package/lib-es/api/utils.js.map +0 -1
  377. package/lib-es/logic.d.ts +0 -11
  378. package/lib-es/logic.d.ts.map +0 -1
  379. package/lib-es/logic.js +0 -29
  380. package/lib-es/logic.js.map +0 -1
  381. package/src/api/mirror.ts +0 -91
  382. package/src/api/network.test.ts +0 -49
  383. package/src/api/network.ts +0 -125
  384. package/src/api/utils.ts +0 -150
  385. package/src/logic.test.ts +0 -152
  386. package/src/logic.ts +0 -66
@@ -0,0 +1,28 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import {
4
+ BASE_USD_FEE_BY_OPERATION_TYPE,
5
+ DEFAULT_TINYBAR_FEE,
6
+ ESTIMATED_FEE_SAFETY_RATE,
7
+ HEDERA_OPERATION_TYPES,
8
+ } from "../constants";
9
+ import { getCurrencyToUSDRate } from "./utils";
10
+
11
+ export const estimateFees = async (
12
+ currency: CryptoCurrency,
13
+ operationType: HEDERA_OPERATION_TYPES,
14
+ ): Promise<BigNumber> => {
15
+ let fee: BigNumber | undefined;
16
+ const usdRate = await getCurrencyToUSDRate(currency).catch(() => null);
17
+
18
+ if (usdRate) {
19
+ fee = new BigNumber(BASE_USD_FEE_BY_OPERATION_TYPE[operationType])
20
+ .dividedBy(new BigNumber(usdRate))
21
+ .integerValue(BigNumber.ROUND_CEIL)
22
+ .multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
23
+ } else {
24
+ fee = new BigNumber(DEFAULT_TINYBAR_FEE).multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
25
+ }
26
+
27
+ return fee;
28
+ };
@@ -0,0 +1,27 @@
1
+ import { getAssetFromToken } from "./getAssetFromToken";
2
+ import { getMockedTokenCurrency } from "../test/fixtures/currency.fixture";
3
+
4
+ describe("getAssetFromToken", () => {
5
+ it("returns asset from TEST token", () => {
6
+ const owner = "owner";
7
+ const token = getMockedTokenCurrency({
8
+ contractAddress: "0.0.1234567",
9
+ name: "TEST",
10
+ units: [
11
+ {
12
+ name: "Test",
13
+ code: "TEST",
14
+ magnitude: 8,
15
+ },
16
+ ],
17
+ });
18
+
19
+ expect(getAssetFromToken(token, owner)).toEqual({
20
+ assetReference: token.contractAddress,
21
+ assetOwner: owner,
22
+ name: token.name,
23
+ type: token.tokenType,
24
+ unit: token.units[0],
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,12 @@
1
+ import type { AssetInfo } from "@ledgerhq/coin-framework/api/types";
2
+ import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+
4
+ export function getAssetFromToken(token: TokenCurrency, owner: string): AssetInfo {
5
+ return {
6
+ type: token.tokenType,
7
+ assetReference: token.contractAddress,
8
+ assetOwner: owner,
9
+ name: token.name,
10
+ unit: token.units[0],
11
+ };
12
+ }
@@ -0,0 +1,200 @@
1
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
2
+ import { getBalance } from "./getBalance";
3
+ import { apiClient } from "../network/api";
4
+ import { getMockedCurrency } from "../test/fixtures/currency.fixture";
5
+
6
+ jest.mock("../network/api");
7
+ jest.mock("@ledgerhq/cryptoassets/tokens");
8
+
9
+ describe("getBalance", () => {
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ });
13
+
14
+ it("should return native balance when only HBAR is present", async () => {
15
+ const address = "0.0.12345";
16
+ const mockCurrency = getMockedCurrency();
17
+ const mockMirrorAccount = {
18
+ balance: {
19
+ balance: "1000000000",
20
+ },
21
+ };
22
+
23
+ (apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
24
+ (apiClient.getAccountTokens as jest.Mock).mockResolvedValue([]);
25
+
26
+ const result = await getBalance(mockCurrency, address);
27
+
28
+ expect(apiClient.getAccount).toHaveBeenCalledTimes(1);
29
+ expect(apiClient.getAccount).toHaveBeenCalledWith(address);
30
+ expect(apiClient.getAccountTokens).toHaveBeenCalledTimes(1);
31
+ expect(apiClient.getAccountTokens).toHaveBeenCalledWith(address);
32
+ expect(result).toHaveLength(1);
33
+ expect(result).toEqual([
34
+ {
35
+ asset: { type: "native" },
36
+ value: BigInt("1000000000"),
37
+ },
38
+ ]);
39
+ });
40
+
41
+ it("should return native balance and token balances", async () => {
42
+ const address = "0.0.12345";
43
+ const mockCurrency = getMockedCurrency();
44
+ const mockMirrorAccount = {
45
+ balance: {
46
+ balance: "1000000000",
47
+ },
48
+ };
49
+ const mockMirrorTokens = [
50
+ {
51
+ token_id: "0.0.7890",
52
+ balance: "5000",
53
+ },
54
+ {
55
+ token_id: "0.0.9876",
56
+ balance: "10000",
57
+ },
58
+ ];
59
+ const mockToken1 = {
60
+ id: "token1",
61
+ contractAddress: "0.0.7890",
62
+ tokenType: "hts",
63
+ name: "Test Token 1",
64
+ units: [{ name: "TT1", code: "tt1", magnitude: 6 }],
65
+ };
66
+ const mockToken2 = {
67
+ id: "token2",
68
+ contractAddress: "0.0.9876",
69
+ tokenType: "hts",
70
+ name: "Test Token 2",
71
+ units: [{ name: "TT2", code: "tt2", magnitude: 8 }],
72
+ };
73
+
74
+ (apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
75
+ (apiClient.getAccountTokens as jest.Mock).mockResolvedValue(mockMirrorTokens);
76
+ (findTokenByAddressInCurrency as jest.Mock).mockImplementation(tokenId => {
77
+ if (tokenId === "0.0.7890") return mockToken1;
78
+ if (tokenId === "0.0.9876") return mockToken2;
79
+ return null;
80
+ });
81
+
82
+ const result = await getBalance(mockCurrency, address);
83
+
84
+ expect(apiClient.getAccount).toHaveBeenCalledTimes(1);
85
+ expect(apiClient.getAccount).toHaveBeenCalledWith(address);
86
+ expect(apiClient.getAccountTokens).toHaveBeenCalledTimes(1);
87
+ expect(apiClient.getAccountTokens).toHaveBeenCalledWith(address);
88
+ expect(findTokenByAddressInCurrency).toHaveBeenCalledTimes(2);
89
+ expect(findTokenByAddressInCurrency).toHaveBeenCalledWith("0.0.7890", "hedera");
90
+ expect(findTokenByAddressInCurrency).toHaveBeenCalledWith("0.0.9876", "hedera");
91
+ expect(result).toHaveLength(3);
92
+ expect(result).toEqual(
93
+ expect.arrayContaining([
94
+ {
95
+ asset: { type: "native" },
96
+ value: BigInt("1000000000"),
97
+ },
98
+ {
99
+ value: BigInt("5000"),
100
+ asset: {
101
+ type: mockToken1.tokenType,
102
+ assetReference: mockToken1.contractAddress,
103
+ assetOwner: address,
104
+ name: mockToken1.name,
105
+ unit: mockToken1.units[0],
106
+ },
107
+ },
108
+ {
109
+ value: BigInt("10000"),
110
+ asset: {
111
+ type: mockToken2.tokenType,
112
+ assetReference: mockToken2.contractAddress,
113
+ assetOwner: address,
114
+ name: mockToken2.name,
115
+ unit: mockToken2.units[0],
116
+ },
117
+ },
118
+ ]),
119
+ );
120
+ });
121
+
122
+ it("should skip tokens not found in CAL", async () => {
123
+ const address = "0.0.12345";
124
+ const mockCurrency = getMockedCurrency();
125
+ const mockMirrorAccount = {
126
+ balance: {
127
+ balance: "1000000000",
128
+ },
129
+ };
130
+ const mockMirrorTokens = [
131
+ {
132
+ token_id: "0.0.7890",
133
+ balance: "5000",
134
+ },
135
+ {
136
+ token_id: "0.0.9876",
137
+ balance: "10000",
138
+ },
139
+ ];
140
+ const mockToken1 = {
141
+ id: "token1",
142
+ contractAddress: "0.0.7890",
143
+ tokenType: "hts",
144
+ name: "Test Token 1",
145
+ units: [{ name: "TT1", code: "tt1", magnitude: 6 }],
146
+ };
147
+
148
+ (apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
149
+ (apiClient.getAccountTokens as jest.Mock).mockResolvedValue(mockMirrorTokens);
150
+ (findTokenByAddressInCurrency as jest.Mock).mockImplementation(tokenId => {
151
+ if (tokenId === "0.0.7890") return mockToken1;
152
+ return null;
153
+ });
154
+
155
+ const result = await getBalance(mockCurrency, address);
156
+
157
+ expect(result).toHaveLength(2);
158
+ expect(result[0]).toEqual({
159
+ asset: { type: "native" },
160
+ value: BigInt("1000000000"),
161
+ });
162
+ expect(result[1]).toEqual({
163
+ value: BigInt("5000"),
164
+ asset: {
165
+ type: mockToken1.tokenType,
166
+ assetReference: mockToken1.contractAddress,
167
+ assetOwner: address,
168
+ name: mockToken1.name,
169
+ unit: mockToken1.units[0],
170
+ },
171
+ });
172
+ });
173
+
174
+ it("should throw when failing to getAccount data", async () => {
175
+ const address = "0.0.12345";
176
+ const mockCurrency = getMockedCurrency();
177
+ const error = new Error("Network error");
178
+
179
+ (apiClient.getAccount as jest.Mock).mockRejectedValue(error);
180
+ (apiClient.getAccountTokens as jest.Mock).mockResolvedValue([]);
181
+
182
+ await expect(getBalance(mockCurrency, address)).rejects.toThrow(error);
183
+ });
184
+
185
+ it("should throw when failing to getAccountTokens data", async () => {
186
+ const address = "0.0.12345";
187
+ const mockCurrency = getMockedCurrency();
188
+ const error = new Error("Network error");
189
+ const mockMirrorAccount = {
190
+ balance: {
191
+ balance: "1000000000",
192
+ },
193
+ };
194
+
195
+ (apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
196
+ (apiClient.getAccountTokens as jest.Mock).mockRejectedValue(error);
197
+
198
+ await expect(getBalance(mockCurrency, address)).rejects.toThrow(error);
199
+ });
200
+ });
@@ -0,0 +1,39 @@
1
+ import type { Balance } from "@ledgerhq/coin-framework/api/types";
2
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
4
+ import { apiClient } from "../network/api";
5
+
6
+ export async function getBalance(currency: CryptoCurrency, address: string): Promise<Balance[]> {
7
+ const [mirrorAccount, mirrorTokens] = await Promise.all([
8
+ apiClient.getAccount(address),
9
+ apiClient.getAccountTokens(address),
10
+ ]);
11
+
12
+ const balance: Balance[] = [
13
+ {
14
+ asset: { type: "native" },
15
+ value: BigInt(mirrorAccount.balance.balance),
16
+ },
17
+ ];
18
+
19
+ for (const mirrorToken of mirrorTokens) {
20
+ const calToken = findTokenByAddressInCurrency(mirrorToken.token_id, currency.id);
21
+
22
+ if (!calToken) {
23
+ continue;
24
+ }
25
+
26
+ balance.push({
27
+ value: BigInt(mirrorToken.balance),
28
+ asset: {
29
+ type: calToken.tokenType,
30
+ assetReference: calToken.contractAddress,
31
+ assetOwner: address,
32
+ name: calToken.name,
33
+ unit: calToken.units[0],
34
+ },
35
+ });
36
+ }
37
+
38
+ return balance;
39
+ }
@@ -0,0 +1,22 @@
1
+ import { getTokenFromAsset } from "./getTokenFromAsset";
2
+ import { getMockedCurrency } from "../test/fixtures/currency.fixture";
3
+
4
+ describe("getTokenFromAsset", () => {
5
+ const mockCurrency = getMockedCurrency();
6
+
7
+ it("returns token from USDC asset", async () => {
8
+ const asset1 = { type: "hts", assetReference: "0.0.5022567" };
9
+
10
+ expect(await getTokenFromAsset(mockCurrency, asset1)).toMatchObject({
11
+ id: "hedera/hts/hbark_0.0.5022567",
12
+ contractAddress: "0.0.5022567",
13
+ name: "hBARK",
14
+ });
15
+ });
16
+
17
+ it("returns undefined for native asset", async () => {
18
+ const nativeAsset = { type: "native" };
19
+
20
+ expect(await getTokenFromAsset(mockCurrency, nativeAsset)).toBeUndefined();
21
+ });
22
+ });
@@ -0,0 +1,17 @@
1
+ import type { AssetInfo } from "@ledgerhq/coin-framework/api/types";
2
+ import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
4
+
5
+ export async function getTokenFromAsset(
6
+ currency: CryptoCurrency,
7
+ asset: AssetInfo,
8
+ ): Promise<TokenCurrency | undefined> {
9
+ const tokenId =
10
+ asset.type !== "native" && "assetReference" in asset ? asset.assetReference : undefined;
11
+
12
+ if (!tokenId) {
13
+ return;
14
+ }
15
+
16
+ return findTokenByAddressInCurrency(tokenId, currency.id);
17
+ }
@@ -0,0 +1,9 @@
1
+ export { broadcast } from "./broadcast";
2
+ export { combine } from "./combine";
3
+ export { craftTransaction } from "./craftTransaction";
4
+ export { estimateFees } from "./estimateFees";
5
+ export { getBalance } from "./getBalance";
6
+ export { lastBlock } from "./lastBlock";
7
+ export { listOperations } from "./listOperations";
8
+ export { getAssetFromToken } from "./getAssetFromToken";
9
+ export { getTokenFromAsset } from "./getTokenFromAsset";
@@ -0,0 +1,23 @@
1
+ import { lastBlock } from "./lastBlock";
2
+ import { apiClient } from "../network/api";
3
+ import { getSyntheticBlock } from "./utils";
4
+
5
+ jest.mock("../network/api");
6
+
7
+ describe("lastBlock", () => {
8
+ it("should return the last block info", async () => {
9
+ const mockTransaction = {
10
+ consensus_timestamp: "1625097600.000000000",
11
+ };
12
+
13
+ (apiClient.getLatestTransaction as jest.Mock).mockResolvedValue(mockTransaction);
14
+
15
+ const result = await lastBlock();
16
+ const expectedSyntheticBlock = getSyntheticBlock(mockTransaction.consensus_timestamp);
17
+
18
+ expect(apiClient.getLatestTransaction).toHaveBeenCalledTimes(1);
19
+ expect(result.height).toEqual(expectedSyntheticBlock.blockHeight);
20
+ expect(result.hash).toEqual(expectedSyntheticBlock.blockHash);
21
+ expect(result.time).toEqual(expectedSyntheticBlock.blockTime);
22
+ });
23
+ });
@@ -0,0 +1,23 @@
1
+ import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
2
+ import { apiClient } from "../network/api";
3
+ import { getSyntheticBlock } from "./utils";
4
+
5
+ /**
6
+ * Gets the latest "block" information for Hedera.
7
+ *
8
+ * Hedera doesn't have actual blocks - it uses a timestamp-based consensus model.
9
+ * To make Hedera compatible with block-based architecture:
10
+ * 1. We fetch the most recent transaction from the mirror node
11
+ * 2. Extract its consensus timestamp
12
+ * 3. Convert this timestamp into a synthetic block using a hardcoded time window (10 seconds by default)
13
+ */
14
+ export async function lastBlock(): Promise<BlockInfo> {
15
+ const latestTransaction = await apiClient.getLatestTransaction();
16
+ const syntheticBlock = getSyntheticBlock(latestTransaction.consensus_timestamp);
17
+
18
+ return {
19
+ height: syntheticBlock.blockHeight,
20
+ hash: syntheticBlock.blockHash,
21
+ time: syntheticBlock.blockTime,
22
+ };
23
+ }