@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,388 @@
1
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
2
+ import { encodeTokenAccountId } from "@ledgerhq/coin-framework/account/accountId";
3
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
4
+ import type { Pagination } from "@ledgerhq/coin-framework/api/types";
5
+ import { listOperations } from "./listOperations";
6
+ import { apiClient } from "../network/api";
7
+ import { getMockedCurrency } from "../test/fixtures/currency.fixture";
8
+ import * as utils from "./utils";
9
+
10
+ jest.mock("@ledgerhq/cryptoassets/tokens");
11
+ jest.mock("@ledgerhq/coin-framework/account/accountId");
12
+ jest.mock("@ledgerhq/coin-framework/operation");
13
+ jest.mock("../network/api");
14
+ jest.mock("./utils");
15
+
16
+ describe("listOperations", () => {
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+ (utils.getMemoFromBase64 as jest.Mock).mockImplementation(memo =>
20
+ memo ? `decoded-${memo}` : null,
21
+ );
22
+ (encodeOperationId as jest.Mock).mockImplementation(
23
+ (accountId, hash, type) => `${accountId}-${hash}-${type}`,
24
+ );
25
+ (encodeTokenAccountId as jest.Mock).mockImplementation(
26
+ (accountId, token) => `${accountId}-${token.id}`,
27
+ );
28
+ });
29
+
30
+ it("should return empty arrays when no transactions are found", async () => {
31
+ const address = "0.0.12345";
32
+ const mockCurrency = getMockedCurrency();
33
+ const pagination: Pagination = {
34
+ minHeight: 0,
35
+ limit: 10,
36
+ order: "asc",
37
+ };
38
+
39
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
40
+ transactions: [],
41
+ nextCursor: null,
42
+ });
43
+
44
+ const result = await listOperations({
45
+ currency: mockCurrency,
46
+ address,
47
+ pagination,
48
+ mirrorTokens: [],
49
+ fetchAllPages: true,
50
+ skipFeesForTokenOperations: false,
51
+ useEncodedHash: false,
52
+ useSyntheticBlocks: false,
53
+ });
54
+
55
+ expect(apiClient.getAccountTransactions).toHaveBeenCalledTimes(1);
56
+ expect(apiClient.getAccountTransactions).toHaveBeenCalledWith({
57
+ address,
58
+ fetchAllPages: true,
59
+ pagingToken: null,
60
+ order: "asc",
61
+ limit: 10,
62
+ });
63
+ expect(result.coinOperations).toEqual([]);
64
+ expect(result.tokenOperations).toEqual([]);
65
+ });
66
+
67
+ it("should parse HBAR transfer transactions correctly", async () => {
68
+ const address = "0.0.1234567";
69
+ const mockCurrency = getMockedCurrency();
70
+ const pagination: Pagination = {
71
+ minHeight: 0,
72
+ limit: 10,
73
+ order: "desc",
74
+ };
75
+
76
+ const mockTransactions = [
77
+ {
78
+ consensus_timestamp: "1625097600.000000000",
79
+ transaction_hash: "hash1",
80
+ charged_tx_fee: 500000,
81
+ result: "SUCCESS",
82
+ memo_base64: "test-memo",
83
+ token_transfers: [],
84
+ transfers: [
85
+ { account: address, amount: "-1000000" },
86
+ { account: "0.0.67890", amount: "1000000" },
87
+ ],
88
+ name: "CRYPTOTRANSFER",
89
+ },
90
+ ];
91
+
92
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
93
+ transactions: mockTransactions,
94
+ nextCursor: null,
95
+ });
96
+
97
+ const result = await listOperations({
98
+ currency: mockCurrency,
99
+ address,
100
+ pagination,
101
+ mirrorTokens: [],
102
+ fetchAllPages: true,
103
+ skipFeesForTokenOperations: false,
104
+ useEncodedHash: false,
105
+ useSyntheticBlocks: false,
106
+ });
107
+
108
+ expect(result.coinOperations).toHaveLength(1);
109
+ expect(result.tokenOperations).toEqual([]);
110
+
111
+ expect(result.coinOperations).toMatchObject([
112
+ {
113
+ type: "OUT",
114
+ value: expect.any(Object),
115
+ hash: "hash1",
116
+ fee: expect.any(Object),
117
+ date: expect.any(Date),
118
+ senders: [address],
119
+ recipients: ["0.0.67890"],
120
+ extra: {
121
+ pagingToken: "1625097600.000000000",
122
+ consensusTimestamp: "1625097600.000000000",
123
+ memo: "decoded-test-memo",
124
+ },
125
+ },
126
+ ]);
127
+ });
128
+
129
+ it("should parse token transfer transactions correctly", async () => {
130
+ const address = "0.0.12345";
131
+ const mockCurrency = getMockedCurrency();
132
+ const tokenId = "0.0.7890";
133
+ const pagination: Pagination = {
134
+ minHeight: 0,
135
+ limit: 10,
136
+ order: "desc",
137
+ };
138
+
139
+ const mockToken = {
140
+ id: "token1",
141
+ contractAddress: tokenId,
142
+ standard: "hts",
143
+ name: "Test Token",
144
+ units: [{ name: "TT", code: "tt", magnitude: 6 }],
145
+ };
146
+
147
+ const mockTransactions = [
148
+ {
149
+ consensus_timestamp: "1625097600.000000000",
150
+ transaction_hash: "hash1",
151
+ charged_tx_fee: 500000,
152
+ result: "SUCCESS",
153
+ token_transfers: [
154
+ { token_id: tokenId, account: address, amount: "-1000" },
155
+ { token_id: tokenId, account: "0.0.67890", amount: "1000" },
156
+ ],
157
+ transfers: [],
158
+ name: "CRYPTOTRANSFER",
159
+ },
160
+ ];
161
+
162
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
163
+ transactions: mockTransactions,
164
+ nextCursor: null,
165
+ });
166
+ (findTokenByAddressInCurrency as jest.Mock).mockReturnValue(mockToken);
167
+
168
+ const result = await listOperations({
169
+ currency: mockCurrency,
170
+ address,
171
+ pagination,
172
+ mirrorTokens: [],
173
+ fetchAllPages: true,
174
+ skipFeesForTokenOperations: false,
175
+ useEncodedHash: false,
176
+ useSyntheticBlocks: false,
177
+ });
178
+
179
+ expect(result.coinOperations).toHaveLength(1);
180
+ expect(result.tokenOperations).toHaveLength(1);
181
+
182
+ expect(result.coinOperations).toMatchObject([
183
+ {
184
+ type: "FEES",
185
+ fee: expect.any(Object),
186
+ },
187
+ ]);
188
+
189
+ expect(result.tokenOperations).toMatchObject([
190
+ {
191
+ type: "OUT",
192
+ value: expect.any(Object),
193
+ hash: "hash1",
194
+ contract: tokenId,
195
+ standard: "hts",
196
+ senders: [address],
197
+ recipients: ["0.0.67890"],
198
+ extra: {
199
+ pagingToken: "1625097600.000000000",
200
+ consensusTimestamp: "1625097600.000000000",
201
+ },
202
+ },
203
+ ]);
204
+ });
205
+
206
+ it("should parse token associate transactions correctly", async () => {
207
+ const address = "0.0.12345";
208
+ const mockCurrency = getMockedCurrency();
209
+ const pagination: Pagination = {
210
+ minHeight: 0,
211
+ limit: 10,
212
+ order: "desc",
213
+ };
214
+
215
+ const mockTransactions = [
216
+ {
217
+ consensus_timestamp: "1625097600.000000000",
218
+ transaction_hash: "hash1",
219
+ charged_tx_fee: 500000,
220
+ result: "SUCCESS",
221
+ token_transfers: [],
222
+ transfers: [{ account: address, amount: "-500000" }],
223
+ name: "TOKENASSOCIATE",
224
+ },
225
+ ];
226
+
227
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
228
+ transactions: mockTransactions,
229
+ nextCursor: null,
230
+ });
231
+
232
+ const result = await listOperations({
233
+ currency: mockCurrency,
234
+ address,
235
+ pagination,
236
+ mirrorTokens: [],
237
+ fetchAllPages: true,
238
+ skipFeesForTokenOperations: false,
239
+ useEncodedHash: false,
240
+ useSyntheticBlocks: false,
241
+ });
242
+
243
+ expect(result.coinOperations).toHaveLength(1);
244
+ expect(result.tokenOperations).toHaveLength(0);
245
+
246
+ expect(result.coinOperations).toMatchObject([
247
+ {
248
+ type: "ASSOCIATE_TOKEN",
249
+ value: expect.any(Object),
250
+ hash: "hash1",
251
+ fee: expect.any(Object),
252
+ senders: [address],
253
+ recipients: [],
254
+ extra: {
255
+ pagingToken: "1625097600.000000000",
256
+ consensusTimestamp: "1625097600.000000000",
257
+ },
258
+ },
259
+ ]);
260
+ });
261
+
262
+ it("should skip token operations when token is not found in cryptoassets", async () => {
263
+ const address = "0.0.12345";
264
+ const mockCurrency = getMockedCurrency();
265
+ const tokenId = "0.0.7890";
266
+ const pagination: Pagination = {
267
+ minHeight: 0,
268
+ limit: 10,
269
+ order: "desc",
270
+ };
271
+
272
+ const mockTransactions = [
273
+ {
274
+ consensus_timestamp: "1625097600.000000000",
275
+ transaction_hash: "hash1",
276
+ charged_tx_fee: 500000,
277
+ result: "SUCCESS",
278
+ token_transfers: [
279
+ { token_id: tokenId, account: address, amount: "-1000" },
280
+ { token_id: tokenId, account: "0.0.67890", amount: "1000" },
281
+ ],
282
+ transfers: [],
283
+ name: "CRYPTOTRANSFER",
284
+ },
285
+ ];
286
+
287
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
288
+ transactions: mockTransactions,
289
+ nextCursor: null,
290
+ });
291
+ (findTokenByAddressInCurrency as jest.Mock).mockReturnValue(null);
292
+
293
+ const result = await listOperations({
294
+ currency: mockCurrency,
295
+ address,
296
+ pagination,
297
+ mirrorTokens: [],
298
+ fetchAllPages: true,
299
+ skipFeesForTokenOperations: false,
300
+ useEncodedHash: false,
301
+ useSyntheticBlocks: false,
302
+ });
303
+
304
+ expect(result.coinOperations).toHaveLength(0);
305
+ expect(result.tokenOperations).toHaveLength(0);
306
+ });
307
+
308
+ it("should use pagination parameters correctly", async () => {
309
+ const address = "0.0.12345";
310
+ const mockCurrency = getMockedCurrency();
311
+ const pagination: Pagination = {
312
+ minHeight: 0,
313
+ limit: 20,
314
+ order: "asc",
315
+ lastPagingToken: "1625097500.000000000",
316
+ };
317
+
318
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
319
+ transactions: [],
320
+ nextCursor: null,
321
+ });
322
+
323
+ await listOperations({
324
+ currency: mockCurrency,
325
+ address,
326
+ pagination,
327
+ mirrorTokens: [],
328
+ fetchAllPages: true,
329
+ skipFeesForTokenOperations: false,
330
+ useEncodedHash: false,
331
+ useSyntheticBlocks: false,
332
+ });
333
+
334
+ expect(apiClient.getAccountTransactions).toHaveBeenCalledTimes(1);
335
+ expect(apiClient.getAccountTransactions).toHaveBeenCalledWith({
336
+ address,
337
+ fetchAllPages: true,
338
+ pagingToken: "1625097500.000000000",
339
+ order: "asc",
340
+ limit: 20,
341
+ });
342
+ });
343
+
344
+ it("should handle failed transactions", async () => {
345
+ const address = "0.0.12345";
346
+ const mockCurrency = getMockedCurrency();
347
+ const pagination: Pagination = {
348
+ minHeight: 0,
349
+ limit: 10,
350
+ order: "desc",
351
+ };
352
+
353
+ const mockTransactions = [
354
+ {
355
+ consensus_timestamp: "1625097600.000000000",
356
+ transaction_hash: "hash1",
357
+ charged_tx_fee: 500000,
358
+ result: "INVALID_SIGNATURE",
359
+ memo_base64: null,
360
+ token_transfers: [],
361
+ transfers: [
362
+ { account: address, amount: "-1000000" },
363
+ { account: "0.0.67890", amount: "1000000" },
364
+ ],
365
+ name: "CRYPTOTRANSFER",
366
+ },
367
+ ];
368
+
369
+ (apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
370
+ transactions: mockTransactions,
371
+ nextCursor: null,
372
+ });
373
+
374
+ const result = await listOperations({
375
+ currency: mockCurrency,
376
+ address,
377
+ pagination,
378
+ mirrorTokens: [],
379
+ fetchAllPages: true,
380
+ skipFeesForTokenOperations: false,
381
+ useEncodedHash: false,
382
+ useSyntheticBlocks: false,
383
+ });
384
+
385
+ expect(result.coinOperations).toHaveLength(1);
386
+ expect(result.coinOperations[0].hasFailed).toBe(true);
387
+ });
388
+ });
@@ -0,0 +1,247 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type { Operation } from "@ledgerhq/types-live";
3
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import type { Pagination } from "@ledgerhq/coin-framework/api/types";
5
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
6
+ import { encodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/accountId";
7
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
8
+ import { apiClient } from "../network/api";
9
+ import { parseTransfers } from "../network/utils";
10
+ import type { HederaMirrorToken, HederaMirrorTransaction, HederaOperationExtra } from "../types";
11
+ import { base64ToUrlSafeBase64, getMemoFromBase64, getSyntheticBlock } from "./utils";
12
+
13
+ function getCommonOperationData(
14
+ rawTx: HederaMirrorTransaction,
15
+ useEncodedHash: boolean,
16
+ useSyntheticBlocks: boolean,
17
+ ) {
18
+ const timestamp = new Date(Number.parseInt(rawTx.consensus_timestamp.split(".")[0], 10) * 1000);
19
+ const hash = useEncodedHash
20
+ ? base64ToUrlSafeBase64(rawTx.transaction_hash)
21
+ : rawTx.transaction_hash;
22
+ const fee = new BigNumber(rawTx.charged_tx_fee);
23
+ const hasFailed = rawTx.result !== "SUCCESS";
24
+ const syntheticBlock = getSyntheticBlock(rawTx.consensus_timestamp);
25
+ const memo = getMemoFromBase64(rawTx.memo_base64);
26
+ const extra: HederaOperationExtra = {
27
+ pagingToken: rawTx.consensus_timestamp,
28
+ consensusTimestamp: rawTx.consensus_timestamp,
29
+ ...(memo && { memo }),
30
+ };
31
+
32
+ return {
33
+ timestamp,
34
+ hash,
35
+ fee,
36
+ hasFailed,
37
+ blockHeight: useSyntheticBlocks ? syntheticBlock.blockHeight : 10,
38
+ blockHash: useSyntheticBlocks ? syntheticBlock.blockHash : null,
39
+ extra,
40
+ };
41
+ }
42
+
43
+ function processTokenTransfers({
44
+ rawTx,
45
+ address,
46
+ currency,
47
+ ledgerAccountId,
48
+ commonData,
49
+ skipFeesForTokenOperations,
50
+ }: {
51
+ rawTx: HederaMirrorTransaction;
52
+ address: string;
53
+ currency: CryptoCurrency;
54
+ ledgerAccountId: string;
55
+ commonData: ReturnType<typeof getCommonOperationData>;
56
+ skipFeesForTokenOperations: boolean;
57
+ }): {
58
+ coinOperation: Operation<HederaOperationExtra> | undefined;
59
+ tokenOperation: Operation<HederaOperationExtra>;
60
+ } | null {
61
+ const tokenTransfers = rawTx.token_transfers ?? [];
62
+ if (tokenTransfers.length === 0) return null;
63
+
64
+ const tokenId = tokenTransfers[0].token_id;
65
+ const token = findTokenByAddressInCurrency(tokenId, currency.id);
66
+ if (!token) return null;
67
+
68
+ const encodedTokenId = encodeTokenAccountId(ledgerAccountId, token);
69
+ const { type, value, senders, recipients } = parseTransfers(tokenTransfers, address);
70
+ const { hash, fee, timestamp, blockHeight, blockHash, hasFailed } = commonData;
71
+ const extra = { ...commonData.extra };
72
+
73
+ let coinOperation: Operation<HederaOperationExtra> | undefined;
74
+
75
+ // Add main FEES coin operation for send token transfer
76
+ if (type === "OUT" && !skipFeesForTokenOperations) {
77
+ coinOperation = {
78
+ id: encodeOperationId(ledgerAccountId, hash, "FEES"),
79
+ accountId: ledgerAccountId,
80
+ type: "FEES",
81
+ value: fee,
82
+ recipients,
83
+ senders,
84
+ hash,
85
+ fee,
86
+ date: timestamp,
87
+ blockHeight,
88
+ blockHash,
89
+ hasFailed,
90
+ extra,
91
+ };
92
+ }
93
+
94
+ const tokenOperation = {
95
+ id: encodeOperationId(encodedTokenId, hash, type),
96
+ accountId: encodedTokenId,
97
+ contract: token.contractAddress,
98
+ standard: "hts",
99
+ type,
100
+ value,
101
+ recipients,
102
+ senders,
103
+ hash,
104
+ fee,
105
+ date: timestamp,
106
+ blockHeight,
107
+ blockHash,
108
+ hasFailed,
109
+ extra,
110
+ } satisfies Operation<HederaOperationExtra>;
111
+
112
+ return {
113
+ coinOperation,
114
+ tokenOperation,
115
+ };
116
+ }
117
+
118
+ function processTransfers({
119
+ rawTx,
120
+ address,
121
+ ledgerAccountId,
122
+ commonData,
123
+ mirrorTokens,
124
+ }: {
125
+ rawTx: HederaMirrorTransaction;
126
+ address: string;
127
+ ledgerAccountId: string;
128
+ commonData: ReturnType<typeof getCommonOperationData>;
129
+ mirrorTokens: HederaMirrorToken[];
130
+ }): Operation<HederaOperationExtra> | null {
131
+ const transfers = rawTx.transfers ?? [];
132
+ if (transfers.length === 0) return null;
133
+
134
+ const { type, value, senders, recipients } = parseTransfers(transfers, address);
135
+ const { hash, fee, timestamp, blockHeight, blockHash, hasFailed } = commonData;
136
+ const extra = { ...commonData.extra };
137
+ let operationType = type;
138
+
139
+ // try to enrich ASSOCIATE_TOKEN operation with extra.associatedTokenId
140
+ // this value is used by custom OperationDetails components in Hedera family
141
+ // accounts or contracts must first associate with an HTS token before they can receive or send that token; without association, token transfers fail
142
+ if (rawTx.name === "TOKENASSOCIATE") {
143
+ operationType = "ASSOCIATE_TOKEN";
144
+
145
+ const relatedMirrorToken = mirrorTokens.find(t => {
146
+ return t.created_timestamp === rawTx.consensus_timestamp;
147
+ });
148
+
149
+ if (relatedMirrorToken) {
150
+ extra.associatedTokenId = relatedMirrorToken.token_id;
151
+ }
152
+ }
153
+
154
+ return {
155
+ id: encodeOperationId(ledgerAccountId, hash, operationType),
156
+ accountId: ledgerAccountId,
157
+ type: operationType,
158
+ value,
159
+ recipients,
160
+ senders,
161
+ hash,
162
+ fee,
163
+ date: timestamp,
164
+ blockHeight,
165
+ blockHash,
166
+ hasFailed,
167
+ extra,
168
+ };
169
+ }
170
+
171
+ export async function listOperations({
172
+ currency,
173
+ address,
174
+ mirrorTokens,
175
+ pagination,
176
+ fetchAllPages,
177
+ skipFeesForTokenOperations,
178
+ useEncodedHash,
179
+ useSyntheticBlocks,
180
+ }: {
181
+ currency: CryptoCurrency;
182
+ address: string;
183
+ mirrorTokens: HederaMirrorToken[];
184
+ pagination: Pagination;
185
+ // options for compatibility with old bridge
186
+ fetchAllPages: boolean;
187
+ skipFeesForTokenOperations: boolean;
188
+ useEncodedHash: boolean;
189
+ useSyntheticBlocks: boolean;
190
+ }): Promise<{
191
+ coinOperations: Operation<HederaOperationExtra>[];
192
+ tokenOperations: Operation<HederaOperationExtra>[];
193
+ nextCursor: string | null;
194
+ }> {
195
+ const coinOperations: Operation<HederaOperationExtra>[] = [];
196
+ const tokenOperations: Operation<HederaOperationExtra>[] = [];
197
+ const mirrorResult = await apiClient.getAccountTransactions({
198
+ address,
199
+ pagingToken: pagination.lastPagingToken ?? null,
200
+ order: pagination.order,
201
+ limit: pagination.limit,
202
+ fetchAllPages,
203
+ });
204
+ const ledgerAccountId = encodeAccountId({
205
+ type: "js",
206
+ version: "2",
207
+ currencyId: currency.id,
208
+ xpubOrAddress: address,
209
+ derivationMode: "hederaBip44",
210
+ });
211
+
212
+ for (const rawTx of mirrorResult.transactions) {
213
+ const commonData = getCommonOperationData(rawTx, useEncodedHash, useSyntheticBlocks);
214
+
215
+ // process token transfers
216
+ const tokenResult = processTokenTransfers({
217
+ rawTx,
218
+ address,
219
+ currency,
220
+ ledgerAccountId,
221
+ commonData,
222
+ skipFeesForTokenOperations,
223
+ });
224
+
225
+ if (tokenResult?.coinOperation) coinOperations.push(tokenResult.coinOperation);
226
+ if (tokenResult?.tokenOperation) tokenOperations.push(tokenResult.tokenOperation);
227
+
228
+ // process regular transfers only if there were no token transfers
229
+ if (!tokenResult) {
230
+ const coinOperation = processTransfers({
231
+ rawTx,
232
+ address,
233
+ ledgerAccountId,
234
+ commonData,
235
+ mirrorTokens,
236
+ });
237
+
238
+ if (coinOperation) coinOperations.push(coinOperation);
239
+ }
240
+ }
241
+
242
+ return {
243
+ coinOperations,
244
+ tokenOperations,
245
+ nextCursor: mirrorResult.nextCursor,
246
+ };
247
+ }