@ledgerhq/coin-vechain 2.9.1-nightly.0 → 2.10.0-nightly.2

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 (475) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +16 -4
  3. package/CHANGELOG.md +24 -0
  4. package/lib/bridge/broadcast.d.ts.map +1 -1
  5. package/lib/bridge/broadcast.js +2 -3
  6. package/lib/bridge/broadcast.js.map +1 -1
  7. package/lib/bridge/broadcast.test.d.ts +2 -0
  8. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  9. package/lib/bridge/broadcast.test.js +188 -0
  10. package/lib/bridge/broadcast.test.js.map +1 -0
  11. package/lib/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
  12. package/lib/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
  13. package/lib/bridge/buildOptimisticOperatioin.test.js +286 -0
  14. package/lib/bridge/buildOptimisticOperatioin.test.js.map +1 -0
  15. package/lib/bridge/createTransaction.d.ts.map +1 -1
  16. package/lib/bridge/createTransaction.js +2 -1
  17. package/lib/bridge/createTransaction.js.map +1 -1
  18. package/lib/bridge/createTransaction.test.d.ts +2 -0
  19. package/lib/bridge/createTransaction.test.d.ts.map +1 -0
  20. package/lib/bridge/createTransaction.test.js +167 -0
  21. package/lib/bridge/createTransaction.test.js.map +1 -0
  22. package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
  23. package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  24. package/lib/bridge/estimateMaxSpendable.test.js +269 -0
  25. package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
  26. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  27. package/lib/bridge/getTransactionStatus.js +3 -1
  28. package/lib/bridge/getTransactionStatus.js.map +1 -1
  29. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  30. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  31. package/lib/bridge/getTransactionStatus.test.js +282 -0
  32. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  33. package/lib/bridge/helpers.test.d.ts +2 -0
  34. package/lib/bridge/helpers.test.d.ts.map +1 -0
  35. package/lib/bridge/helpers.test.js +298 -0
  36. package/lib/bridge/helpers.test.js.map +1 -0
  37. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  38. package/lib/bridge/prepareTransaction.js +10 -3
  39. package/lib/bridge/prepareTransaction.js.map +1 -1
  40. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  41. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  42. package/lib/bridge/prepareTransaction.test.js +277 -0
  43. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  44. package/lib/bridge/signOperation.d.ts.map +1 -1
  45. package/lib/bridge/signOperation.js +3 -3
  46. package/lib/bridge/signOperation.js.map +1 -1
  47. package/lib/bridge/signOperation.test.d.ts +2 -0
  48. package/lib/bridge/signOperation.test.d.ts.map +1 -0
  49. package/lib/bridge/signOperation.test.js +295 -0
  50. package/lib/bridge/signOperation.test.js.map +1 -0
  51. package/lib/bridge/synchronisation.d.ts.map +1 -1
  52. package/lib/bridge/synchronisation.js +2 -2
  53. package/lib/bridge/synchronisation.js.map +1 -1
  54. package/lib/bridge/transaction.test.d.ts +2 -0
  55. package/lib/bridge/transaction.test.d.ts.map +1 -0
  56. package/lib/bridge/transaction.test.js +353 -0
  57. package/lib/bridge/transaction.test.js.map +1 -0
  58. package/lib/common-logic/calculateClauses.d.ts +5 -0
  59. package/lib/common-logic/calculateClauses.d.ts.map +1 -0
  60. package/lib/common-logic/{logic.js → calculateClauses.js} +7 -10
  61. package/lib/common-logic/calculateClauses.js.map +1 -0
  62. package/lib/common-logic/calculateClauses.test.d.ts +2 -0
  63. package/lib/common-logic/calculateClauses.test.d.ts.map +1 -0
  64. package/lib/common-logic/calculateClauses.test.js +156 -0
  65. package/lib/common-logic/calculateClauses.test.js.map +1 -0
  66. package/lib/common-logic/calculateGasFees.d.ts +9 -0
  67. package/lib/common-logic/calculateGasFees.d.ts.map +1 -0
  68. package/lib/common-logic/calculateGasFees.js +39 -0
  69. package/lib/common-logic/calculateGasFees.js.map +1 -0
  70. package/lib/common-logic/calculateGasFees.test.d.ts +2 -0
  71. package/lib/common-logic/calculateGasFees.test.d.ts.map +1 -0
  72. package/lib/common-logic/calculateGasFees.test.js +279 -0
  73. package/lib/common-logic/calculateGasFees.test.js.map +1 -0
  74. package/lib/common-logic/calculateTransactionInfo.d.ts +10 -0
  75. package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -0
  76. package/lib/common-logic/calculateTransactionInfo.js +81 -0
  77. package/lib/common-logic/calculateTransactionInfo.js.map +1 -0
  78. package/lib/common-logic/calculateTransactionInfo.test.d.ts +2 -0
  79. package/lib/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
  80. package/lib/common-logic/calculateTransactionInfo.test.js +314 -0
  81. package/lib/common-logic/calculateTransactionInfo.test.js.map +1 -0
  82. package/lib/common-logic/estimateGas.d.ts +10 -0
  83. package/lib/common-logic/estimateGas.d.ts.map +1 -0
  84. package/lib/common-logic/estimateGas.js +17 -0
  85. package/lib/common-logic/estimateGas.js.map +1 -0
  86. package/lib/common-logic/estimateGas.test.d.ts +2 -0
  87. package/lib/common-logic/estimateGas.test.d.ts.map +1 -0
  88. package/lib/common-logic/estimateGas.test.js +129 -0
  89. package/lib/common-logic/estimateGas.test.js.map +1 -0
  90. package/lib/common-logic/fixPrefixCase.d.ts +2 -0
  91. package/lib/common-logic/fixPrefixCase.d.ts.map +1 -0
  92. package/lib/common-logic/fixPrefixCase.js +9 -0
  93. package/lib/common-logic/fixPrefixCase.js.map +1 -0
  94. package/lib/common-logic/fixPrefixCase.test.d.ts +2 -0
  95. package/lib/common-logic/fixPrefixCase.test.d.ts.map +1 -0
  96. package/lib/common-logic/fixPrefixCase.test.js +46 -0
  97. package/lib/common-logic/fixPrefixCase.test.js.map +1 -0
  98. package/lib/common-logic/generateNonce.d.ts +6 -0
  99. package/lib/common-logic/generateNonce.d.ts.map +1 -0
  100. package/lib/common-logic/generateNonce.js +13 -0
  101. package/lib/common-logic/generateNonce.js.map +1 -0
  102. package/lib/common-logic/generateNonce.test.d.ts +2 -0
  103. package/lib/common-logic/generateNonce.test.d.ts.map +1 -0
  104. package/lib/common-logic/generateNonce.test.js +59 -0
  105. package/lib/common-logic/generateNonce.test.js.map +1 -0
  106. package/lib/common-logic/getThorClient.d.ts +7 -0
  107. package/lib/common-logic/getThorClient.d.ts.map +1 -0
  108. package/lib/common-logic/getThorClient.js +14 -0
  109. package/lib/common-logic/getThorClient.js.map +1 -0
  110. package/lib/common-logic/getThorClient.test.d.ts +2 -0
  111. package/lib/common-logic/getThorClient.test.d.ts.map +1 -0
  112. package/lib/common-logic/getThorClient.test.js +53 -0
  113. package/lib/common-logic/getThorClient.test.js.map +1 -0
  114. package/lib/common-logic/index.d.ts +8 -6
  115. package/lib/common-logic/index.d.ts.map +1 -1
  116. package/lib/common-logic/index.js +8 -6
  117. package/lib/common-logic/index.js.map +1 -1
  118. package/lib/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
  119. package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -0
  120. package/lib/common-logic/{mapping-utils.js → mapTransfersToOperations.js} +26 -19
  121. package/lib/common-logic/mapTransfersToOperations.js.map +1 -0
  122. package/lib/common-logic/mapTransfersToOperations.test.d.ts +2 -0
  123. package/lib/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
  124. package/lib/common-logic/mapTransfersToOperations.test.js +274 -0
  125. package/lib/common-logic/mapTransfersToOperations.test.js.map +1 -0
  126. package/lib/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
  127. package/lib/common-logic/padAddress.d.ts.map +1 -0
  128. package/lib/common-logic/{pad-address.js → padAddress.js} +1 -1
  129. package/lib/common-logic/padAddress.js.map +1 -0
  130. package/lib/common-logic/padAddress.test.d.ts +2 -0
  131. package/lib/common-logic/padAddress.test.d.ts.map +1 -0
  132. package/lib/common-logic/padAddress.test.js +59 -0
  133. package/lib/common-logic/padAddress.test.js.map +1 -0
  134. package/lib/common-logic/parseAddress.d.ts +7 -0
  135. package/lib/common-logic/parseAddress.d.ts.map +1 -0
  136. package/lib/common-logic/parseAddress.js +15 -0
  137. package/lib/common-logic/parseAddress.js.map +1 -0
  138. package/lib/common-logic/parseAddress.test.d.ts +2 -0
  139. package/lib/common-logic/parseAddress.test.d.ts.map +1 -0
  140. package/lib/common-logic/parseAddress.test.js +97 -0
  141. package/lib/common-logic/parseAddress.test.js.map +1 -0
  142. package/lib/constants/env.d.ts +2 -0
  143. package/lib/constants/env.d.ts.map +1 -0
  144. package/lib/constants/env.js +6 -0
  145. package/lib/constants/env.js.map +1 -0
  146. package/lib/constants/index.d.ts +2 -0
  147. package/lib/constants/index.d.ts.map +1 -0
  148. package/lib/constants/index.js +18 -0
  149. package/lib/constants/index.js.map +1 -0
  150. package/lib/network/sdk.d.ts +3 -10
  151. package/lib/network/sdk.d.ts.map +1 -1
  152. package/lib/network/sdk.js +15 -30
  153. package/lib/network/sdk.js.map +1 -1
  154. package/lib/signer/getAddress.test.d.ts +2 -0
  155. package/lib/signer/getAddress.test.d.ts.map +1 -0
  156. package/lib/signer/getAddress.test.js +357 -0
  157. package/lib/signer/getAddress.test.js.map +1 -0
  158. package/lib/signer/signMessage.d.ts.map +1 -1
  159. package/lib/signer/signMessage.js +3 -3
  160. package/lib/signer/signMessage.js.map +1 -1
  161. package/lib/signer/signMessage.test.d.ts +2 -0
  162. package/lib/signer/signMessage.test.d.ts.map +1 -0
  163. package/lib/signer/signMessage.test.js +242 -0
  164. package/lib/signer/signMessage.test.js.map +1 -0
  165. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  166. package/lib/test/bridgeDatasetTest.js +79 -53
  167. package/lib/test/bridgeDatasetTest.js.map +1 -1
  168. package/lib/test/cli.d.ts.map +1 -1
  169. package/lib/test/cli.js +5 -4
  170. package/lib/test/cli.js.map +1 -1
  171. package/lib/types/bridge.d.ts +11 -3
  172. package/lib/types/bridge.d.ts.map +1 -1
  173. package/lib/types/bridge.js +3 -0
  174. package/lib/types/bridge.js.map +1 -1
  175. package/lib/types/constants.d.ts +0 -3
  176. package/lib/types/constants.d.ts.map +1 -1
  177. package/lib/types/constants.js +1 -4
  178. package/lib/types/constants.js.map +1 -1
  179. package/lib/types/signer.d.ts +0 -2
  180. package/lib/types/signer.d.ts.map +1 -1
  181. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  182. package/lib-es/bridge/broadcast.js +2 -3
  183. package/lib-es/bridge/broadcast.js.map +1 -1
  184. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  185. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  186. package/lib-es/bridge/broadcast.test.js +183 -0
  187. package/lib-es/bridge/broadcast.test.js.map +1 -0
  188. package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
  189. package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
  190. package/lib-es/bridge/buildOptimisticOperatioin.test.js +281 -0
  191. package/lib-es/bridge/buildOptimisticOperatioin.test.js.map +1 -0
  192. package/lib-es/bridge/createTransaction.d.ts.map +1 -1
  193. package/lib-es/bridge/createTransaction.js +3 -2
  194. package/lib-es/bridge/createTransaction.js.map +1 -1
  195. package/lib-es/bridge/createTransaction.test.d.ts +2 -0
  196. package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
  197. package/lib-es/bridge/createTransaction.test.js +162 -0
  198. package/lib-es/bridge/createTransaction.test.js.map +1 -0
  199. package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
  200. package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  201. package/lib-es/bridge/estimateMaxSpendable.test.js +264 -0
  202. package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
  203. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  204. package/lib-es/bridge/getTransactionStatus.js +4 -2
  205. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  206. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  207. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  208. package/lib-es/bridge/getTransactionStatus.test.js +277 -0
  209. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  210. package/lib-es/bridge/helpers.test.d.ts +2 -0
  211. package/lib-es/bridge/helpers.test.d.ts.map +1 -0
  212. package/lib-es/bridge/helpers.test.js +293 -0
  213. package/lib-es/bridge/helpers.test.js.map +1 -0
  214. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  215. package/lib-es/bridge/prepareTransaction.js +11 -4
  216. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  217. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  218. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  219. package/lib-es/bridge/prepareTransaction.test.js +272 -0
  220. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  221. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  222. package/lib-es/bridge/signOperation.js +3 -3
  223. package/lib-es/bridge/signOperation.js.map +1 -1
  224. package/lib-es/bridge/signOperation.test.d.ts +2 -0
  225. package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
  226. package/lib-es/bridge/signOperation.test.js +290 -0
  227. package/lib-es/bridge/signOperation.test.js.map +1 -0
  228. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  229. package/lib-es/bridge/synchronisation.js +1 -1
  230. package/lib-es/bridge/synchronisation.js.map +1 -1
  231. package/lib-es/bridge/transaction.test.d.ts +2 -0
  232. package/lib-es/bridge/transaction.test.d.ts.map +1 -0
  233. package/lib-es/bridge/transaction.test.js +347 -0
  234. package/lib-es/bridge/transaction.test.js.map +1 -0
  235. package/lib-es/common-logic/calculateClauses.d.ts +5 -0
  236. package/lib-es/common-logic/calculateClauses.d.ts.map +1 -0
  237. package/lib-es/common-logic/{logic.js → calculateClauses.js} +6 -6
  238. package/lib-es/common-logic/calculateClauses.js.map +1 -0
  239. package/lib-es/common-logic/calculateClauses.test.d.ts +2 -0
  240. package/lib-es/common-logic/calculateClauses.test.d.ts.map +1 -0
  241. package/lib-es/common-logic/calculateClauses.test.js +151 -0
  242. package/lib-es/common-logic/calculateClauses.test.js.map +1 -0
  243. package/lib-es/common-logic/calculateGasFees.d.ts +9 -0
  244. package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -0
  245. package/lib-es/common-logic/calculateGasFees.js +32 -0
  246. package/lib-es/common-logic/calculateGasFees.js.map +1 -0
  247. package/lib-es/common-logic/calculateGasFees.test.d.ts +2 -0
  248. package/lib-es/common-logic/calculateGasFees.test.d.ts.map +1 -0
  249. package/lib-es/common-logic/calculateGasFees.test.js +274 -0
  250. package/lib-es/common-logic/calculateGasFees.test.js.map +1 -0
  251. package/lib-es/common-logic/calculateTransactionInfo.d.ts +10 -0
  252. package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -0
  253. package/lib-es/common-logic/calculateTransactionInfo.js +74 -0
  254. package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -0
  255. package/lib-es/common-logic/calculateTransactionInfo.test.d.ts +2 -0
  256. package/lib-es/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
  257. package/lib-es/common-logic/calculateTransactionInfo.test.js +309 -0
  258. package/lib-es/common-logic/calculateTransactionInfo.test.js.map +1 -0
  259. package/lib-es/common-logic/estimateGas.d.ts +10 -0
  260. package/lib-es/common-logic/estimateGas.d.ts.map +1 -0
  261. package/lib-es/common-logic/estimateGas.js +13 -0
  262. package/lib-es/common-logic/estimateGas.js.map +1 -0
  263. package/lib-es/common-logic/estimateGas.test.d.ts +2 -0
  264. package/lib-es/common-logic/estimateGas.test.d.ts.map +1 -0
  265. package/lib-es/common-logic/estimateGas.test.js +127 -0
  266. package/lib-es/common-logic/estimateGas.test.js.map +1 -0
  267. package/lib-es/common-logic/fixPrefixCase.d.ts +2 -0
  268. package/lib-es/common-logic/fixPrefixCase.d.ts.map +1 -0
  269. package/lib-es/common-logic/fixPrefixCase.js +5 -0
  270. package/lib-es/common-logic/fixPrefixCase.js.map +1 -0
  271. package/lib-es/common-logic/fixPrefixCase.test.d.ts +2 -0
  272. package/lib-es/common-logic/fixPrefixCase.test.d.ts.map +1 -0
  273. package/lib-es/common-logic/fixPrefixCase.test.js +44 -0
  274. package/lib-es/common-logic/fixPrefixCase.test.js.map +1 -0
  275. package/lib-es/common-logic/generateNonce.d.ts +6 -0
  276. package/lib-es/common-logic/generateNonce.d.ts.map +1 -0
  277. package/lib-es/common-logic/generateNonce.js +9 -0
  278. package/lib-es/common-logic/generateNonce.js.map +1 -0
  279. package/lib-es/common-logic/generateNonce.test.d.ts +2 -0
  280. package/lib-es/common-logic/generateNonce.test.d.ts.map +1 -0
  281. package/lib-es/common-logic/generateNonce.test.js +57 -0
  282. package/lib-es/common-logic/generateNonce.test.js.map +1 -0
  283. package/lib-es/common-logic/getThorClient.d.ts +7 -0
  284. package/lib-es/common-logic/getThorClient.d.ts.map +1 -0
  285. package/lib-es/common-logic/getThorClient.js +10 -0
  286. package/lib-es/common-logic/getThorClient.js.map +1 -0
  287. package/lib-es/common-logic/getThorClient.test.d.ts +2 -0
  288. package/lib-es/common-logic/getThorClient.test.d.ts.map +1 -0
  289. package/lib-es/common-logic/getThorClient.test.js +51 -0
  290. package/lib-es/common-logic/getThorClient.test.js.map +1 -0
  291. package/lib-es/common-logic/index.d.ts +8 -6
  292. package/lib-es/common-logic/index.d.ts.map +1 -1
  293. package/lib-es/common-logic/index.js +8 -6
  294. package/lib-es/common-logic/index.js.map +1 -1
  295. package/lib-es/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
  296. package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -0
  297. package/lib-es/common-logic/mapTransfersToOperations.js +51 -0
  298. package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -0
  299. package/lib-es/common-logic/mapTransfersToOperations.test.d.ts +2 -0
  300. package/lib-es/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
  301. package/lib-es/common-logic/mapTransfersToOperations.test.js +269 -0
  302. package/lib-es/common-logic/mapTransfersToOperations.test.js.map +1 -0
  303. package/lib-es/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
  304. package/lib-es/common-logic/padAddress.d.ts.map +1 -0
  305. package/lib-es/common-logic/{pad-address.js → padAddress.js} +1 -1
  306. package/lib-es/common-logic/padAddress.js.map +1 -0
  307. package/lib-es/common-logic/padAddress.test.d.ts +2 -0
  308. package/lib-es/common-logic/padAddress.test.d.ts.map +1 -0
  309. package/lib-es/common-logic/padAddress.test.js +57 -0
  310. package/lib-es/common-logic/padAddress.test.js.map +1 -0
  311. package/lib-es/common-logic/parseAddress.d.ts +7 -0
  312. package/lib-es/common-logic/parseAddress.d.ts.map +1 -0
  313. package/lib-es/common-logic/parseAddress.js +11 -0
  314. package/lib-es/common-logic/parseAddress.js.map +1 -0
  315. package/lib-es/common-logic/parseAddress.test.d.ts +2 -0
  316. package/lib-es/common-logic/parseAddress.test.d.ts.map +1 -0
  317. package/lib-es/common-logic/parseAddress.test.js +95 -0
  318. package/lib-es/common-logic/parseAddress.test.js.map +1 -0
  319. package/lib-es/constants/env.d.ts +2 -0
  320. package/lib-es/constants/env.d.ts.map +1 -0
  321. package/lib-es/constants/env.js +3 -0
  322. package/lib-es/constants/env.js.map +1 -0
  323. package/lib-es/constants/index.d.ts +2 -0
  324. package/lib-es/constants/index.d.ts.map +1 -0
  325. package/lib-es/constants/index.js +2 -0
  326. package/lib-es/constants/index.js.map +1 -0
  327. package/lib-es/network/sdk.d.ts +3 -10
  328. package/lib-es/network/sdk.d.ts.map +1 -1
  329. package/lib-es/network/sdk.js +5 -19
  330. package/lib-es/network/sdk.js.map +1 -1
  331. package/lib-es/signer/getAddress.test.d.ts +2 -0
  332. package/lib-es/signer/getAddress.test.d.ts.map +1 -0
  333. package/lib-es/signer/getAddress.test.js +352 -0
  334. package/lib-es/signer/getAddress.test.js.map +1 -0
  335. package/lib-es/signer/signMessage.d.ts.map +1 -1
  336. package/lib-es/signer/signMessage.js +3 -3
  337. package/lib-es/signer/signMessage.js.map +1 -1
  338. package/lib-es/signer/signMessage.test.d.ts +2 -0
  339. package/lib-es/signer/signMessage.test.d.ts.map +1 -0
  340. package/lib-es/signer/signMessage.test.js +240 -0
  341. package/lib-es/signer/signMessage.test.js.map +1 -0
  342. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  343. package/lib-es/test/bridgeDatasetTest.js +80 -54
  344. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  345. package/lib-es/test/cli.d.ts.map +1 -1
  346. package/lib-es/test/cli.js +4 -3
  347. package/lib-es/test/cli.js.map +1 -1
  348. package/lib-es/types/bridge.d.ts +11 -3
  349. package/lib-es/types/bridge.d.ts.map +1 -1
  350. package/lib-es/types/bridge.js +6 -1
  351. package/lib-es/types/bridge.js.map +1 -1
  352. package/lib-es/types/constants.d.ts +0 -3
  353. package/lib-es/types/constants.d.ts.map +1 -1
  354. package/lib-es/types/constants.js +0 -3
  355. package/lib-es/types/constants.js.map +1 -1
  356. package/lib-es/types/signer.d.ts +0 -2
  357. package/lib-es/types/signer.d.ts.map +1 -1
  358. package/package.json +8 -7
  359. package/src/bridge/broadcast.test.ts +236 -0
  360. package/src/bridge/broadcast.ts +4 -5
  361. package/src/bridge/buildOptimisticOperatioin.test.ts +364 -0
  362. package/src/bridge/createTransaction.test.ts +201 -0
  363. package/src/bridge/createTransaction.ts +3 -2
  364. package/src/bridge/estimateMaxSpendable.test.ts +319 -0
  365. package/src/bridge/getTransactionStatus.test.ts +353 -0
  366. package/src/bridge/getTransactionStatus.ts +4 -2
  367. package/src/bridge/helpers.test.ts +356 -0
  368. package/src/bridge/prepareTransaction.test.ts +345 -0
  369. package/src/bridge/prepareTransaction.ts +20 -10
  370. package/src/bridge/signOperation.test.ts +354 -0
  371. package/src/bridge/signOperation.ts +6 -3
  372. package/src/bridge/synchronisation.ts +1 -1
  373. package/src/bridge/transaction.test.ts +440 -0
  374. package/src/common-logic/calculateClauses.test.ts +186 -0
  375. package/src/common-logic/calculateClauses.ts +44 -0
  376. package/src/common-logic/calculateGasFees.test.ts +363 -0
  377. package/src/common-logic/calculateGasFees.ts +45 -0
  378. package/src/common-logic/calculateTransactionInfo.test.ts +396 -0
  379. package/src/common-logic/calculateTransactionInfo.ts +96 -0
  380. package/src/common-logic/estimateGas.test.ts +162 -0
  381. package/src/common-logic/estimateGas.ts +18 -0
  382. package/src/common-logic/fixPrefixCase.test.ts +51 -0
  383. package/src/common-logic/fixPrefixCase.ts +5 -0
  384. package/src/common-logic/generateNonce.test.ts +72 -0
  385. package/src/common-logic/generateNonce.ts +9 -0
  386. package/src/common-logic/getThorClient.test.ts +66 -0
  387. package/src/common-logic/getThorClient.ts +10 -0
  388. package/src/common-logic/index.ts +8 -6
  389. package/src/common-logic/mapTransfersToOperations.test.ts +342 -0
  390. package/src/common-logic/mapTransfersToOperations.ts +77 -0
  391. package/src/common-logic/padAddress.test.ts +65 -0
  392. package/src/common-logic/parseAddress.test.ts +130 -0
  393. package/src/common-logic/parseAddress.ts +11 -0
  394. package/src/constants/env.ts +3 -0
  395. package/src/constants/index.ts +1 -0
  396. package/src/network/sdk.ts +22 -30
  397. package/src/signer/getAddress.test.ts +454 -0
  398. package/src/signer/signMessage.test.ts +329 -0
  399. package/src/signer/signMessage.ts +4 -5
  400. package/src/test/bridgeDatasetTest.ts +86 -58
  401. package/src/test/cli.ts +4 -3
  402. package/src/types/bridge.ts +16 -3
  403. package/src/types/constants.ts +0 -3
  404. package/lib/common-logic/address-utils.d.ts +0 -2
  405. package/lib/common-logic/address-utils.d.ts.map +0 -1
  406. package/lib/common-logic/address-utils.js +0 -19
  407. package/lib/common-logic/address-utils.js.map +0 -1
  408. package/lib/common-logic/hex-utils.d.ts +0 -8
  409. package/lib/common-logic/hex-utils.d.ts.map +0 -1
  410. package/lib/common-logic/hex-utils.js +0 -52
  411. package/lib/common-logic/hex-utils.js.map +0 -1
  412. package/lib/common-logic/logic.d.ts +0 -5
  413. package/lib/common-logic/logic.d.ts.map +0 -1
  414. package/lib/common-logic/logic.js.map +0 -1
  415. package/lib/common-logic/mapping-utils.d.ts.map +0 -1
  416. package/lib/common-logic/mapping-utils.js.map +0 -1
  417. package/lib/common-logic/pad-address.d.ts.map +0 -1
  418. package/lib/common-logic/pad-address.js.map +0 -1
  419. package/lib/common-logic/transaction-utils.d.ts +0 -30
  420. package/lib/common-logic/transaction-utils.d.ts.map +0 -1
  421. package/lib/common-logic/transaction-utils.js +0 -161
  422. package/lib/common-logic/transaction-utils.js.map +0 -1
  423. package/lib/contracts/abis/VIP180.d.ts +0 -17
  424. package/lib/contracts/abis/VIP180.d.ts.map +0 -1
  425. package/lib/contracts/abis/VIP180.js +0 -265
  426. package/lib/contracts/abis/VIP180.js.map +0 -1
  427. package/lib/contracts/abis/params.d.ts +0 -8
  428. package/lib/contracts/abis/params.d.ts.map +0 -1
  429. package/lib/contracts/abis/params.js +0 -69
  430. package/lib/contracts/abis/params.js.map +0 -1
  431. package/lib/contracts/constants.d.ts +0 -6
  432. package/lib/contracts/constants.d.ts.map +0 -1
  433. package/lib/contracts/constants.js +0 -10
  434. package/lib/contracts/constants.js.map +0 -1
  435. package/lib-es/common-logic/address-utils.d.ts +0 -2
  436. package/lib-es/common-logic/address-utils.d.ts.map +0 -1
  437. package/lib-es/common-logic/address-utils.js +0 -12
  438. package/lib-es/common-logic/address-utils.js.map +0 -1
  439. package/lib-es/common-logic/hex-utils.d.ts +0 -8
  440. package/lib-es/common-logic/hex-utils.d.ts.map +0 -1
  441. package/lib-es/common-logic/hex-utils.js +0 -50
  442. package/lib-es/common-logic/hex-utils.js.map +0 -1
  443. package/lib-es/common-logic/logic.d.ts +0 -5
  444. package/lib-es/common-logic/logic.d.ts.map +0 -1
  445. package/lib-es/common-logic/logic.js.map +0 -1
  446. package/lib-es/common-logic/mapping-utils.d.ts.map +0 -1
  447. package/lib-es/common-logic/mapping-utils.js +0 -44
  448. package/lib-es/common-logic/mapping-utils.js.map +0 -1
  449. package/lib-es/common-logic/pad-address.d.ts.map +0 -1
  450. package/lib-es/common-logic/pad-address.js.map +0 -1
  451. package/lib-es/common-logic/transaction-utils.d.ts +0 -30
  452. package/lib-es/common-logic/transaction-utils.d.ts.map +0 -1
  453. package/lib-es/common-logic/transaction-utils.js +0 -150
  454. package/lib-es/common-logic/transaction-utils.js.map +0 -1
  455. package/lib-es/contracts/abis/VIP180.d.ts +0 -17
  456. package/lib-es/contracts/abis/VIP180.d.ts.map +0 -1
  457. package/lib-es/contracts/abis/VIP180.js +0 -263
  458. package/lib-es/contracts/abis/VIP180.js.map +0 -1
  459. package/lib-es/contracts/abis/params.d.ts +0 -8
  460. package/lib-es/contracts/abis/params.d.ts.map +0 -1
  461. package/lib-es/contracts/abis/params.js +0 -67
  462. package/lib-es/contracts/abis/params.js.map +0 -1
  463. package/lib-es/contracts/constants.d.ts +0 -6
  464. package/lib-es/contracts/constants.d.ts.map +0 -1
  465. package/lib-es/contracts/constants.js +0 -7
  466. package/lib-es/contracts/constants.js.map +0 -1
  467. package/src/common-logic/address-utils.ts +0 -11
  468. package/src/common-logic/hex-utils.ts +0 -53
  469. package/src/common-logic/logic.ts +0 -44
  470. package/src/common-logic/mapping-utils.ts +0 -67
  471. package/src/common-logic/transaction-utils.ts +0 -190
  472. package/src/contracts/abis/VIP180.ts +0 -265
  473. package/src/contracts/abis/params.ts +0 -70
  474. package/src/contracts/constants.ts +0 -11
  475. /package/src/common-logic/{pad-address.ts → padAddress.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ import { fixPrefixCase } from "./fixPrefixCase";
2
+
3
+ describe("fixPrefixCase", () => {
4
+ it("should convert uppercase 0X prefix to lowercase 0x", () => {
5
+ const input = "0X1234567890abcdef";
6
+ const result = fixPrefixCase(input);
7
+ expect(result).toBe("0x1234567890abcdef");
8
+ });
9
+
10
+ it("should keep lowercase 0x prefix unchanged", () => {
11
+ const input = "0x1234567890abcdef";
12
+ const result = fixPrefixCase(input);
13
+ expect(result).toBe("0x1234567890abcdef");
14
+ });
15
+
16
+ it("should add 0x prefix when missing", () => {
17
+ const input = "1234567890abcdef";
18
+ const result = fixPrefixCase(input);
19
+ expect(result).toBe("0x1234567890abcdef");
20
+ });
21
+
22
+ it("should handle empty string by adding 0x prefix", () => {
23
+ const input = "";
24
+ const result = fixPrefixCase(input);
25
+ expect(result).toBe("0x");
26
+ });
27
+
28
+ it("should handle mixed case prefix 0X", () => {
29
+ const input = "0X123abc";
30
+ const result = fixPrefixCase(input);
31
+ expect(result).toBe("0x123abc");
32
+ });
33
+
34
+ it("should handle string starting with just 0 by adding x", () => {
35
+ const input = "01234";
36
+ const result = fixPrefixCase(input);
37
+ expect(result).toBe("0x01234");
38
+ });
39
+
40
+ it("should handle valid ethereum address", () => {
41
+ const input = "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
42
+ const result = fixPrefixCase(input);
43
+ expect(result).toBe("0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4");
44
+ });
45
+
46
+ it("should handle address without prefix", () => {
47
+ const input = "742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
48
+ const result = fixPrefixCase(input);
49
+ expect(result).toBe("0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4");
50
+ });
51
+ });
@@ -0,0 +1,5 @@
1
+ const PREFIX_REGEX = /^0[xX]/;
2
+
3
+ export const fixPrefixCase = (hex: string): string => {
4
+ return PREFIX_REGEX.test(hex) ? hex.replace(PREFIX_REGEX, "0x") : `${"0x"}${hex}`;
5
+ };
@@ -0,0 +1,72 @@
1
+ import { generateNonce } from "./generateNonce";
2
+ import { Hex } from "@vechain/sdk-core";
3
+
4
+ // Mock the Hex.random method
5
+ jest.mock("@vechain/sdk-core", () => ({
6
+ Hex: {
7
+ random: jest.fn(),
8
+ },
9
+ }));
10
+
11
+ const mockedHex = jest.mocked(Hex);
12
+
13
+ describe("generateNonce", () => {
14
+ beforeEach(() => {
15
+ jest.clearAllMocks();
16
+ });
17
+
18
+ it("should generate a nonce using Hex.random with length 8", () => {
19
+ const mockHexValue = {
20
+ toString: jest.fn().mockReturnValue("0x1234567890abcdef"),
21
+ };
22
+ mockedHex.random.mockReturnValue(mockHexValue as any);
23
+
24
+ const result = generateNonce();
25
+
26
+ expect(mockedHex.random).toHaveBeenCalledWith(8);
27
+ expect(mockHexValue.toString).toHaveBeenCalled();
28
+ expect(result).toBe("0x1234567890abcdef");
29
+ });
30
+
31
+ it("should return a string", () => {
32
+ const mockHexValue = {
33
+ toString: jest.fn().mockReturnValue("0xabcdef1234567890"),
34
+ };
35
+ mockedHex.random.mockReturnValue(mockHexValue as any);
36
+
37
+ const result = generateNonce();
38
+
39
+ expect(typeof result).toBe("string");
40
+ });
41
+
42
+ it("should call toString on the hex value", () => {
43
+ const mockHexValue = {
44
+ toString: jest.fn().mockReturnValue("0x123456789abcdef0"),
45
+ };
46
+ mockedHex.random.mockReturnValue(mockHexValue as any);
47
+
48
+ generateNonce();
49
+
50
+ expect(mockHexValue.toString).toHaveBeenCalledTimes(1);
51
+ });
52
+
53
+ it("should handle different hex values", () => {
54
+ const testCases = [
55
+ "0x0000000000000000",
56
+ "0xffffffffffffffff",
57
+ "0x123456789abcdef0",
58
+ "0xa1b2c3d4e5f67890",
59
+ ];
60
+
61
+ testCases.forEach(expectedValue => {
62
+ const mockHexValue = {
63
+ toString: jest.fn().mockReturnValue(expectedValue),
64
+ };
65
+ mockedHex.random.mockReturnValue(mockHexValue as any);
66
+
67
+ const result = generateNonce();
68
+
69
+ expect(result).toBe(expectedValue);
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,9 @@
1
+ import { Hex } from "@vechain/sdk-core";
2
+
3
+ /**
4
+ * Generate a Unique ID to be used as a nonce
5
+ * @returns a unique string
6
+ */
7
+ export const generateNonce = (): string => {
8
+ return Hex.random(8).toString();
9
+ };
@@ -0,0 +1,66 @@
1
+ import { getThorClient } from "./getThorClient";
2
+ import { ThorClient } from "@vechain/sdk-network";
3
+ import { VECHAIN_NODE_URL } from "../constants";
4
+
5
+ // Mock the ThorClient
6
+ jest.mock("@vechain/sdk-network", () => ({
7
+ ThorClient: {
8
+ at: jest.fn(),
9
+ },
10
+ }));
11
+
12
+ // Mock the constants
13
+ jest.mock("../constants", () => ({
14
+ VECHAIN_NODE_URL: "https://testnet.veblocks.net",
15
+ }));
16
+
17
+ const mockedThorClient = jest.mocked(ThorClient);
18
+
19
+ describe("getThorClient", () => {
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ });
23
+
24
+ it("should create a ThorClient instance with VECHAIN_NODE_URL", () => {
25
+ const mockClient = {
26
+ /* mock ThorClient properties */
27
+ };
28
+ mockedThorClient.at.mockReturnValue(mockClient as any);
29
+
30
+ const result = getThorClient();
31
+
32
+ expect(mockedThorClient.at).toHaveBeenCalledWith(VECHAIN_NODE_URL);
33
+ expect(result).toBe(mockClient);
34
+ });
35
+
36
+ it("should return the same type of object from ThorClient.at", () => {
37
+ const mockClient = {
38
+ test: "thorClient",
39
+ transactions: {},
40
+ gas: {},
41
+ };
42
+ mockedThorClient.at.mockReturnValue(mockClient as any);
43
+
44
+ const result = getThorClient();
45
+
46
+ expect(result).toEqual(mockClient);
47
+ });
48
+
49
+ it("should call ThorClient.at exactly once", () => {
50
+ const mockClient = {};
51
+ mockedThorClient.at.mockReturnValue(mockClient as any);
52
+
53
+ getThorClient();
54
+
55
+ expect(mockedThorClient.at).toHaveBeenCalledTimes(1);
56
+ });
57
+
58
+ it("should use the correct URL from constants", () => {
59
+ const mockClient = {};
60
+ mockedThorClient.at.mockReturnValue(mockClient as any);
61
+
62
+ getThorClient();
63
+
64
+ expect(mockedThorClient.at).toHaveBeenCalledWith("https://testnet.veblocks.net");
65
+ });
66
+ });
@@ -0,0 +1,10 @@
1
+ import { ThorClient } from "@vechain/sdk-network";
2
+ import { VECHAIN_NODE_URL } from "../constants";
3
+
4
+ /**
5
+ * Returns a ThorClient instance configured with the VeChain node URL
6
+ * @returns {ThorClient} Configured ThorClient instance for interacting with the VeChain network
7
+ */
8
+ export const getThorClient = (): ThorClient => {
9
+ return ThorClient.at(VECHAIN_NODE_URL);
10
+ };
@@ -1,6 +1,8 @@
1
- export * from "./address-utils";
2
- export * from "./hex-utils";
3
- export * from "./logic";
4
- export * from "./mapping-utils";
5
- export * from "./pad-address";
6
- export * from "./transaction-utils";
1
+ export * from "./fixPrefixCase";
2
+ export * from "./calculateClauses";
3
+ export * from "./mapTransfersToOperations";
4
+ export * from "./padAddress";
5
+ export * from "./calculateTransactionInfo";
6
+ export * from "./calculateGasFees";
7
+ export * from "./generateNonce";
8
+ export * from "./parseAddress";
@@ -0,0 +1,342 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { TransferLog, EventLog } from "../types";
3
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
4
+
5
+ // Mock dependencies before importing the function under test
6
+ jest.mock("../network", () => ({
7
+ getFees: jest.fn(),
8
+ }));
9
+ jest.mock("@ledgerhq/coin-framework/operation", () => ({
10
+ encodeOperationId: jest.fn(),
11
+ }));
12
+ jest.mock("@vechain/sdk-core", () => ({
13
+ ABIEvent: {
14
+ parseLog: jest.fn(),
15
+ },
16
+ Hex: {
17
+ of: jest.fn(),
18
+ },
19
+ VIP180_ABI: {},
20
+ }));
21
+
22
+ // Import the functions under test after mocking
23
+ import {
24
+ mapVetTransfersToOperations,
25
+ mapTokenTransfersToOperations,
26
+ } from "./mapTransfersToOperations";
27
+ import { getFees } from "../network";
28
+
29
+ const { ABIEvent, Hex, VIP180_ABI } = jest.requireMock("@vechain/sdk-core");
30
+
31
+ const mockedGetFees = jest.mocked(getFees);
32
+ const mockedEncodeOperationId = jest.mocked(encodeOperationId);
33
+ const mockedABIEvent = ABIEvent;
34
+ const mockedHex = Hex;
35
+
36
+ describe("mapVetTransfersToOperations", () => {
37
+ const mockAccountId = "vechain:1:0x123:";
38
+ const mockAddr = "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
39
+
40
+ const mockTransferLogs: TransferLog[] = [
41
+ {
42
+ sender: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
43
+ recipient: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
44
+ amount: "1000000000000000000",
45
+ meta: {
46
+ blockID: "0xblock123",
47
+ blockNumber: 12345,
48
+ blockTimestamp: 1640995200,
49
+ txID: "0xtx123",
50
+ txOrigin: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
51
+ clauseIndex: 0,
52
+ },
53
+ },
54
+ {
55
+ sender: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
56
+ recipient: "0x456789012345678901234567890123456789abcd",
57
+ amount: "2000000000000000000",
58
+ meta: {
59
+ blockID: "0xblock456",
60
+ blockNumber: 12346,
61
+ blockTimestamp: 1640995260,
62
+ txID: "0xtx456",
63
+ txOrigin: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
64
+ clauseIndex: 0,
65
+ },
66
+ },
67
+ ];
68
+
69
+ beforeEach(() => {
70
+ jest.clearAllMocks();
71
+ mockedGetFees.mockResolvedValue(new BigNumber("21000000000000000"));
72
+ mockedEncodeOperationId.mockImplementation(
73
+ (accountId, hash, type) => `${accountId}${hash}${type}`,
74
+ );
75
+ });
76
+
77
+ it("should map incoming VET transfers to operations", async () => {
78
+ const result = await mapVetTransfersToOperations(
79
+ [mockTransferLogs[0]],
80
+ mockAccountId,
81
+ mockAddr,
82
+ );
83
+
84
+ expect(result).toHaveLength(1);
85
+ expect(result[0]).toEqual({
86
+ id: `${mockAccountId}0xtx123IN`,
87
+ hash: "0xtx123",
88
+ type: "IN",
89
+ value: new BigNumber("1000000000000000000"),
90
+ fee: new BigNumber("21000000000000000"),
91
+ senders: ["0x5034aa590125b64023a0262112b98d72e3c8e40e"],
92
+ recipients: ["0x742d35cc6634c0532925a3b8d0b251d8c1743ec4"],
93
+ blockHeight: 12345,
94
+ blockHash: "0xblock123",
95
+ accountId: mockAccountId,
96
+ date: new Date(1640995200 * 1000),
97
+ extra: {},
98
+ });
99
+ });
100
+
101
+ it("should map outgoing VET transfers to operations", async () => {
102
+ const result = await mapVetTransfersToOperations(
103
+ [mockTransferLogs[1]],
104
+ mockAccountId,
105
+ mockAddr,
106
+ );
107
+
108
+ expect(result).toHaveLength(1);
109
+ expect(result[0]).toEqual({
110
+ id: `${mockAccountId}0xtx456OUT`,
111
+ hash: "0xtx456",
112
+ type: "OUT",
113
+ value: new BigNumber("2000000000000000000"),
114
+ fee: new BigNumber("21000000000000000"),
115
+ senders: ["0x742d35cc6634c0532925a3b8d0b251d8c1743ec4"],
116
+ recipients: ["0x456789012345678901234567890123456789abcd"],
117
+ blockHeight: 12346,
118
+ blockHash: "0xblock456",
119
+ accountId: mockAccountId,
120
+ date: new Date(1640995260 * 1000),
121
+ extra: {},
122
+ });
123
+ });
124
+
125
+ it("should handle multiple transfers", async () => {
126
+ const result = await mapVetTransfersToOperations(mockTransferLogs, mockAccountId, mockAddr);
127
+
128
+ expect(result).toHaveLength(2);
129
+ expect(result[0].type).toBe("IN");
130
+ expect(result[1].type).toBe("OUT");
131
+ });
132
+
133
+ it("should call getFees for each transfer", async () => {
134
+ await mapVetTransfersToOperations(mockTransferLogs, mockAccountId, mockAddr);
135
+
136
+ expect(mockedGetFees).toHaveBeenCalledTimes(2);
137
+ expect(mockedGetFees).toHaveBeenCalledWith("0xtx123");
138
+ expect(mockedGetFees).toHaveBeenCalledWith("0xtx456");
139
+ });
140
+
141
+ it("should handle case-insensitive address comparison", async () => {
142
+ const upperCaseAddr = mockAddr.toUpperCase();
143
+ const transferWithUpperCase: TransferLog = {
144
+ ...mockTransferLogs[0],
145
+ recipient: upperCaseAddr,
146
+ };
147
+
148
+ const result = await mapVetTransfersToOperations(
149
+ [transferWithUpperCase],
150
+ mockAccountId,
151
+ mockAddr,
152
+ );
153
+
154
+ expect(result[0].type).toBe("IN");
155
+ });
156
+
157
+ it("should convert addresses to lowercase in the operation", async () => {
158
+ const transferWithMixedCase: TransferLog = {
159
+ ...mockTransferLogs[0],
160
+ sender: "0x5034AA590125B64023A0262112B98D72E3C8E40E",
161
+ recipient: "0x742D35CC6634C0532925A3B8D0B251D8C1743EC4",
162
+ };
163
+
164
+ const result = await mapVetTransfersToOperations(
165
+ [transferWithMixedCase],
166
+ mockAccountId,
167
+ mockAddr,
168
+ );
169
+
170
+ expect(result[0].senders[0]).toBe("0x5034aa590125b64023a0262112b98d72e3c8e40e");
171
+ expect(result[0].recipients[0]).toBe("0x742d35cc6634c0532925a3b8d0b251d8c1743ec4");
172
+ });
173
+ });
174
+
175
+ describe("mapTokenTransfersToOperations", () => {
176
+ const mockAccountId = "vechain:1:0x123:";
177
+ const mockAddr = "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4";
178
+
179
+ const mockEventLogs: EventLog[] = [
180
+ {
181
+ address: "0x0000000000000000000000000000456e65726779",
182
+ topics: [
183
+ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
184
+ "0x0000000000000000000000005034aa590125b64023a0262112b98d72e3c8e40e",
185
+ "0x000000000000000000000000742d35cc6634c0532925a3b8d0b251d8c1743ec4",
186
+ ],
187
+ data: "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000",
188
+ meta: {
189
+ blockID: "0xblock789",
190
+ blockNumber: 12347,
191
+ blockTimestamp: 1640995320,
192
+ txID: "0xtx789",
193
+ txOrigin: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
194
+ clauseIndex: 0,
195
+ },
196
+ },
197
+ ];
198
+
199
+ const mockDecodedEvent = {
200
+ eventName: "Transfer" as const,
201
+ args: {
202
+ from: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
203
+ to: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
204
+ value: BigInt("1000000000000000000"),
205
+ },
206
+ };
207
+
208
+ beforeEach(() => {
209
+ jest.clearAllMocks();
210
+ mockedGetFees.mockResolvedValue(new BigNumber("37000000000000000"));
211
+ mockedEncodeOperationId.mockImplementation(
212
+ (accountId, hash, type) => `${accountId}${hash}${type}`,
213
+ );
214
+ mockedHex.of.mockImplementation((exp: any) => ({ toString: () => exp.toString() }) as any);
215
+ mockedABIEvent.parseLog.mockReturnValue(mockDecodedEvent);
216
+ });
217
+
218
+ it("should map incoming token transfers to operations", async () => {
219
+ const result = await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
220
+
221
+ expect(result).toHaveLength(1);
222
+ expect(result[0]).toEqual({
223
+ id: `${mockAccountId}0xtx789IN`,
224
+ hash: "0xtx789",
225
+ type: "IN",
226
+ value: new BigNumber("1000000000000000000"),
227
+ fee: new BigNumber("37000000000000000"),
228
+ senders: ["0x5034aa590125b64023a0262112b98d72e3c8e40e"],
229
+ recipients: ["0x742d35cc6634c0532925a3b8d0b251d8c1743ec4"],
230
+ blockHeight: 12347,
231
+ blockHash: "0xblock789",
232
+ accountId: mockAccountId,
233
+ date: new Date(1640995320 * 1000),
234
+ extra: {},
235
+ });
236
+ });
237
+
238
+ it("should map outgoing token transfers to operations", async () => {
239
+ const outgoingEvent = {
240
+ eventName: "Transfer" as const,
241
+ args: {
242
+ from: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
243
+ to: "0x456789012345678901234567890123456789abcd",
244
+ value: BigInt("2000000000000000000"),
245
+ },
246
+ };
247
+ mockedABIEvent.parseLog.mockReturnValue(outgoingEvent);
248
+
249
+ const result = await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
250
+
251
+ expect(result[0].type).toBe("OUT");
252
+ expect(result[0].value).toEqual(new BigNumber("2000000000000000000"));
253
+ });
254
+
255
+ it("should decode event logs correctly", async () => {
256
+ await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
257
+
258
+ expect(mockedHex.of).toHaveBeenCalledWith(mockEventLogs[0].data);
259
+ expect(mockedHex.of).toHaveBeenCalledWith(mockEventLogs[0].topics[0]);
260
+ expect(mockedHex.of).toHaveBeenCalledWith(mockEventLogs[0].topics[1]);
261
+ expect(mockedHex.of).toHaveBeenCalledWith(mockEventLogs[0].topics[2]);
262
+
263
+ expect(mockedABIEvent.parseLog).toHaveBeenCalledWith(
264
+ VIP180_ABI,
265
+ expect.objectContaining({
266
+ data: expect.anything(),
267
+ topics: expect.any(Array),
268
+ }),
269
+ );
270
+ });
271
+
272
+ it("should handle bigint values correctly", async () => {
273
+ const largeValueEvent = {
274
+ eventName: "Transfer" as const,
275
+ args: {
276
+ from: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
277
+ to: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
278
+ value: BigInt("123456789012345678901234567890"),
279
+ },
280
+ };
281
+ mockedABIEvent.parseLog.mockReturnValue(largeValueEvent);
282
+
283
+ const result = await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
284
+
285
+ expect(result[0].value).toEqual(new BigNumber("123456789012345678901234567890"));
286
+ });
287
+
288
+ it("should call getFees for each event", async () => {
289
+ await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
290
+
291
+ expect(mockedGetFees).toHaveBeenCalledTimes(1);
292
+ expect(mockedGetFees).toHaveBeenCalledWith("0xtx789");
293
+ });
294
+
295
+ it("should handle multiple events", async () => {
296
+ const multipleEvents = [
297
+ mockEventLogs[0],
298
+ {
299
+ ...mockEventLogs[0],
300
+ meta: { ...mockEventLogs[0].meta, txID: "0xtx790" },
301
+ },
302
+ ];
303
+
304
+ await mapTokenTransfersToOperations(multipleEvents, mockAccountId, mockAddr);
305
+
306
+ expect(mockedGetFees).toHaveBeenCalledTimes(2);
307
+ expect(mockedABIEvent.parseLog).toHaveBeenCalledTimes(2);
308
+ });
309
+
310
+ it("should handle case-insensitive address comparison for tokens", async () => {
311
+ const upperCaseEvent = {
312
+ eventName: "Transfer" as const,
313
+ args: {
314
+ from: "0x5034aa590125b64023a0262112b98d72e3c8e40e",
315
+ to: mockAddr.toUpperCase(),
316
+ value: BigInt("1000000000000000000"),
317
+ },
318
+ };
319
+ mockedABIEvent.parseLog.mockReturnValue(upperCaseEvent);
320
+
321
+ const result = await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
322
+
323
+ expect(result[0].type).toBe("IN");
324
+ });
325
+
326
+ it("should convert token addresses to lowercase", async () => {
327
+ const mixedCaseEvent = {
328
+ eventName: "Transfer" as const,
329
+ args: {
330
+ from: "0x5034AA590125B64023A0262112B98D72E3C8E40E",
331
+ to: "0x742D35CC6634C0532925A3B8D0B251D8C1743EC4",
332
+ value: BigInt("1000000000000000000"),
333
+ },
334
+ };
335
+ mockedABIEvent.parseLog.mockReturnValue(mixedCaseEvent);
336
+
337
+ const result = await mapTokenTransfersToOperations(mockEventLogs, mockAccountId, mockAddr);
338
+
339
+ expect(result[0].senders[0]).toBe("0x5034aa590125b64023a0262112b98d72e3c8e40e");
340
+ expect(result[0].recipients[0]).toBe("0x742d35cc6634c0532925a3b8d0b251d8c1743ec4");
341
+ });
342
+ });
@@ -0,0 +1,77 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Operation } from "@ledgerhq/types-live";
3
+ import { EventLog, TransferLog } from "../types";
4
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
5
+ import { getFees } from "../network";
6
+ import { ABIEvent, Hex, VIP180_ABI } from "@vechain/sdk-core";
7
+
8
+ export const mapVetTransfersToOperations = async (
9
+ txs: TransferLog[],
10
+ accountId: string,
11
+ addr: string,
12
+ ): Promise<Operation[]> => {
13
+ return Promise.all(
14
+ txs.map(async tx => {
15
+ const fees = await getFees(tx.meta.txID);
16
+ return {
17
+ id: encodeOperationId(
18
+ accountId,
19
+ tx.meta.txID,
20
+ tx.recipient.toLowerCase() === addr.toLowerCase() ? "IN" : "OUT",
21
+ ),
22
+ hash: tx.meta.txID,
23
+ type: tx.recipient.toLowerCase() === addr.toLowerCase() ? "IN" : "OUT",
24
+ value: new BigNumber(tx.amount),
25
+ fee: new BigNumber(fees),
26
+ senders: [tx.sender.toLowerCase()],
27
+ recipients: [tx.recipient.toLowerCase()],
28
+ blockHeight: tx.meta.blockNumber,
29
+ blockHash: tx.meta.blockID,
30
+ accountId,
31
+ date: new Date(tx.meta.blockTimestamp * 1000),
32
+ extra: {},
33
+ };
34
+ }),
35
+ );
36
+ };
37
+
38
+ export const mapTokenTransfersToOperations = async (
39
+ events: EventLog[],
40
+ accountId: string,
41
+ addr: string,
42
+ ): Promise<Operation[]> => {
43
+ return Promise.all(
44
+ events.map(async event => {
45
+ const decoded = ABIEvent.parseLog(VIP180_ABI, {
46
+ data: Hex.of(event.data),
47
+ topics: event.topics.map(topic => Hex.of(topic)),
48
+ }) as {
49
+ eventName: "Transfer";
50
+ args: {
51
+ from: string;
52
+ to: string;
53
+ value: bigint;
54
+ };
55
+ };
56
+ const from = decoded.args.from;
57
+ const to = decoded.args.to;
58
+ const value = decoded.args.value;
59
+ const type = to.toLowerCase() === addr.toLowerCase() ? "IN" : "OUT";
60
+ const fees = await getFees(event.meta.txID);
61
+ return {
62
+ id: encodeOperationId(accountId, event.meta.txID, type),
63
+ hash: event.meta.txID,
64
+ type,
65
+ value: new BigNumber(value.toString()),
66
+ fee: fees,
67
+ senders: [from.toLowerCase()],
68
+ recipients: [to.toLowerCase()],
69
+ blockHeight: event.meta.blockNumber,
70
+ blockHash: event.meta.blockID,
71
+ accountId,
72
+ date: new Date(event.meta.blockTimestamp * 1000),
73
+ extra: {},
74
+ };
75
+ }),
76
+ );
77
+ };