@ledgerhq/coin-vechain 2.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +74 -0
  4. package/CHANGELOG.md +1186 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/account.d.ts +7 -0
  8. package/lib/account.d.ts.map +1 -0
  9. package/lib/account.js +19 -0
  10. package/lib/account.js.map +1 -0
  11. package/lib/bridge/broadcast.d.ts +8 -0
  12. package/lib/bridge/broadcast.d.ts.map +1 -0
  13. package/lib/bridge/broadcast.js +27 -0
  14. package/lib/bridge/broadcast.js.map +1 -0
  15. package/lib/bridge/buildOptimisticOperatioin.d.ts +4 -0
  16. package/lib/bridge/buildOptimisticOperatioin.d.ts.map +1 -0
  17. package/lib/bridge/buildOptimisticOperatioin.js +56 -0
  18. package/lib/bridge/buildOptimisticOperatioin.js.map +1 -0
  19. package/lib/bridge/createTransaction.d.ts +9 -0
  20. package/lib/bridge/createTransaction.d.ts.map +1 -0
  21. package/lib/bridge/createTransaction.js +36 -0
  22. package/lib/bridge/createTransaction.js.map +1 -0
  23. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  24. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  25. package/lib/bridge/estimateMaxSpendable.js +29 -0
  26. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  27. package/lib/bridge/getTransactionStatus.d.ts +5 -0
  28. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  29. package/lib/bridge/getTransactionStatus.js +76 -0
  30. package/lib/bridge/getTransactionStatus.js.map +1 -0
  31. package/lib/bridge/index.d.ts +10 -0
  32. package/lib/bridge/index.d.ts.map +1 -0
  33. package/lib/bridge/index.js +64 -0
  34. package/lib/bridge/index.js.map +1 -0
  35. package/lib/bridge/prepareTransaction.d.ts +10 -0
  36. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  37. package/lib/bridge/prepareTransaction.js +38 -0
  38. package/lib/bridge/prepareTransaction.js.map +1 -0
  39. package/lib/bridge/signOperation.d.ts +8 -0
  40. package/lib/bridge/signOperation.d.ts.map +1 -0
  41. package/lib/bridge/signOperation.js +43 -0
  42. package/lib/bridge/signOperation.js.map +1 -0
  43. package/lib/bridge/synchronisation.d.ts +4 -0
  44. package/lib/bridge/synchronisation.d.ts.map +1 -0
  45. package/lib/bridge/synchronisation.js +84 -0
  46. package/lib/bridge/synchronisation.js.map +1 -0
  47. package/lib/bridge/transaction.d.ts +17 -0
  48. package/lib/bridge/transaction.d.ts.map +1 -0
  49. package/lib/bridge/transaction.js +56 -0
  50. package/lib/bridge/transaction.js.map +1 -0
  51. package/lib/common-logic/address-utils.d.ts +2 -0
  52. package/lib/common-logic/address-utils.d.ts.map +1 -0
  53. package/lib/common-logic/address-utils.js +19 -0
  54. package/lib/common-logic/address-utils.js.map +1 -0
  55. package/lib/common-logic/hex-utils.d.ts +8 -0
  56. package/lib/common-logic/hex-utils.d.ts.map +1 -0
  57. package/lib/common-logic/hex-utils.js +52 -0
  58. package/lib/common-logic/hex-utils.js.map +1 -0
  59. package/lib/common-logic/index.d.ts +7 -0
  60. package/lib/common-logic/index.d.ts.map +1 -0
  61. package/lib/common-logic/index.js +23 -0
  62. package/lib/common-logic/index.js.map +1 -0
  63. package/lib/common-logic/logic.d.ts +5 -0
  64. package/lib/common-logic/logic.d.ts.map +1 -0
  65. package/lib/common-logic/logic.js +46 -0
  66. package/lib/common-logic/logic.js.map +1 -0
  67. package/lib/common-logic/mapping-utils.d.ts +5 -0
  68. package/lib/common-logic/mapping-utils.d.ts.map +1 -0
  69. package/lib/common-logic/mapping-utils.js +61 -0
  70. package/lib/common-logic/mapping-utils.js.map +1 -0
  71. package/lib/common-logic/pad-address.d.ts +2 -0
  72. package/lib/common-logic/pad-address.d.ts.map +1 -0
  73. package/lib/common-logic/pad-address.js +13 -0
  74. package/lib/common-logic/pad-address.js.map +1 -0
  75. package/lib/common-logic/transaction-utils.d.ts +30 -0
  76. package/lib/common-logic/transaction-utils.d.ts.map +1 -0
  77. package/lib/common-logic/transaction-utils.js +164 -0
  78. package/lib/common-logic/transaction-utils.js.map +1 -0
  79. package/lib/config.d.ts +5 -0
  80. package/lib/config.d.ts.map +1 -0
  81. package/lib/config.js +17 -0
  82. package/lib/config.js.map +1 -0
  83. package/lib/contracts/abis/VIP180.d.ts +17 -0
  84. package/lib/contracts/abis/VIP180.d.ts.map +1 -0
  85. package/lib/contracts/abis/VIP180.js +265 -0
  86. package/lib/contracts/abis/VIP180.js.map +1 -0
  87. package/lib/contracts/abis/params.d.ts +8 -0
  88. package/lib/contracts/abis/params.d.ts.map +1 -0
  89. package/lib/contracts/abis/params.js +69 -0
  90. package/lib/contracts/abis/params.js.map +1 -0
  91. package/lib/contracts/constants.d.ts +6 -0
  92. package/lib/contracts/constants.d.ts.map +1 -0
  93. package/lib/contracts/constants.js +10 -0
  94. package/lib/contracts/constants.js.map +1 -0
  95. package/lib/datasets/index.d.ts +3 -0
  96. package/lib/datasets/index.d.ts.map +1 -0
  97. package/lib/datasets/index.js +23 -0
  98. package/lib/datasets/index.js.map +1 -0
  99. package/lib/datasets/vechain.d.ts +5 -0
  100. package/lib/datasets/vechain.d.ts.map +1 -0
  101. package/lib/datasets/vechain.js +91 -0
  102. package/lib/datasets/vechain.js.map +1 -0
  103. package/lib/datasets/vechain.scanAccounts.1.d.ts +6 -0
  104. package/lib/datasets/vechain.scanAccounts.1.d.ts.map +1 -0
  105. package/lib/datasets/vechain.scanAccounts.1.js +16 -0
  106. package/lib/datasets/vechain.scanAccounts.1.js.map +1 -0
  107. package/lib/errors.d.ts +10 -0
  108. package/lib/errors.d.ts.map +1 -0
  109. package/lib/errors.js +8 -0
  110. package/lib/errors.js.map +1 -0
  111. package/lib/index.d.ts +2 -0
  112. package/lib/index.d.ts.map +1 -0
  113. package/lib/index.js +6 -0
  114. package/lib/index.js.map +1 -0
  115. package/lib/mock.d.ts +9 -0
  116. package/lib/mock.d.ts.map +1 -0
  117. package/lib/mock.js +13 -0
  118. package/lib/mock.js.map +1 -0
  119. package/lib/network/index.d.ts +3 -0
  120. package/lib/network/index.d.ts.map +1 -0
  121. package/lib/network/index.js +22 -0
  122. package/lib/network/index.js.map +1 -0
  123. package/lib/network/sdk.d.ts +47 -0
  124. package/lib/network/sdk.d.ts.map +1 -0
  125. package/lib/network/sdk.js +164 -0
  126. package/lib/network/sdk.js.map +1 -0
  127. package/lib/signer/getAddress.d.ts +6 -0
  128. package/lib/signer/getAddress.d.ts.map +1 -0
  129. package/lib/signer/getAddress.js +32 -0
  130. package/lib/signer/getAddress.js.map +1 -0
  131. package/lib/signer/index.d.ts +4 -0
  132. package/lib/signer/index.d.ts.map +1 -0
  133. package/lib/signer/index.js +23 -0
  134. package/lib/signer/index.js.map +1 -0
  135. package/lib/signer/signMessage.d.ts +4 -0
  136. package/lib/signer/signMessage.d.ts.map +1 -0
  137. package/lib/signer/signMessage.js +31 -0
  138. package/lib/signer/signMessage.js.map +1 -0
  139. package/lib/test/bot-deviceActions.d.ts +7 -0
  140. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  141. package/lib/test/bot-deviceActions.js +23 -0
  142. package/lib/test/bot-deviceActions.js.map +1 -0
  143. package/lib/test/bot-specs.d.ts +8 -0
  144. package/lib/test/bot-specs.d.ts.map +1 -0
  145. package/lib/test/bot-specs.js +161 -0
  146. package/lib/test/bot-specs.js.map +1 -0
  147. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  148. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  149. package/lib/test/bridgeDatasetTest.js +252 -0
  150. package/lib/test/bridgeDatasetTest.js.map +1 -0
  151. package/lib/test/cli.d.ts +17 -0
  152. package/lib/test/cli.d.ts.map +1 -0
  153. package/lib/test/cli.js +51 -0
  154. package/lib/test/cli.js.map +1 -0
  155. package/lib/test/index.d.ts +6 -0
  156. package/lib/test/index.d.ts.map +1 -0
  157. package/lib/test/index.js +26 -0
  158. package/lib/test/index.js.map +1 -0
  159. package/lib/types/bridge.d.ts +25 -0
  160. package/lib/types/bridge.d.ts.map +1 -0
  161. package/lib/types/bridge.js +3 -0
  162. package/lib/types/bridge.js.map +1 -0
  163. package/lib/types/constants.d.ts +6 -0
  164. package/lib/types/constants.d.ts.map +1 -0
  165. package/lib/types/constants.js +9 -0
  166. package/lib/types/constants.js.map +1 -0
  167. package/lib/types/index.d.ts +5 -0
  168. package/lib/types/index.d.ts.map +1 -0
  169. package/lib/types/index.js +21 -0
  170. package/lib/types/index.js.map +1 -0
  171. package/lib/types/network.d.ts +71 -0
  172. package/lib/types/network.d.ts.map +1 -0
  173. package/lib/types/network.js +3 -0
  174. package/lib/types/network.js.map +1 -0
  175. package/lib/types/signer.d.ts +12 -0
  176. package/lib/types/signer.d.ts.map +1 -0
  177. package/lib/types/signer.js +3 -0
  178. package/lib/types/signer.js.map +1 -0
  179. package/lib-es/account.d.ts +7 -0
  180. package/lib-es/account.d.ts.map +1 -0
  181. package/lib-es/account.js +17 -0
  182. package/lib-es/account.js.map +1 -0
  183. package/lib-es/bridge/broadcast.d.ts +8 -0
  184. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  185. package/lib-es/bridge/broadcast.js +23 -0
  186. package/lib-es/bridge/broadcast.js.map +1 -0
  187. package/lib-es/bridge/buildOptimisticOperatioin.d.ts +4 -0
  188. package/lib-es/bridge/buildOptimisticOperatioin.d.ts.map +1 -0
  189. package/lib-es/bridge/buildOptimisticOperatioin.js +49 -0
  190. package/lib-es/bridge/buildOptimisticOperatioin.js.map +1 -0
  191. package/lib-es/bridge/createTransaction.d.ts +9 -0
  192. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  193. package/lib-es/bridge/createTransaction.js +29 -0
  194. package/lib-es/bridge/createTransaction.js.map +1 -0
  195. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  196. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  197. package/lib-es/bridge/estimateMaxSpendable.js +22 -0
  198. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  199. package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
  200. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  201. package/lib-es/bridge/getTransactionStatus.js +69 -0
  202. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  203. package/lib-es/bridge/index.d.ts +10 -0
  204. package/lib-es/bridge/index.d.ts.map +1 -0
  205. package/lib-es/bridge/index.js +55 -0
  206. package/lib-es/bridge/index.js.map +1 -0
  207. package/lib-es/bridge/prepareTransaction.d.ts +10 -0
  208. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  209. package/lib-es/bridge/prepareTransaction.js +34 -0
  210. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  211. package/lib-es/bridge/signOperation.d.ts +8 -0
  212. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  213. package/lib-es/bridge/signOperation.js +39 -0
  214. package/lib-es/bridge/signOperation.js.map +1 -0
  215. package/lib-es/bridge/synchronisation.d.ts +4 -0
  216. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  217. package/lib-es/bridge/synchronisation.js +77 -0
  218. package/lib-es/bridge/synchronisation.js.map +1 -0
  219. package/lib-es/bridge/transaction.d.ts +17 -0
  220. package/lib-es/bridge/transaction.d.ts.map +1 -0
  221. package/lib-es/bridge/transaction.js +48 -0
  222. package/lib-es/bridge/transaction.js.map +1 -0
  223. package/lib-es/common-logic/address-utils.d.ts +2 -0
  224. package/lib-es/common-logic/address-utils.d.ts.map +1 -0
  225. package/lib-es/common-logic/address-utils.js +12 -0
  226. package/lib-es/common-logic/address-utils.js.map +1 -0
  227. package/lib-es/common-logic/hex-utils.d.ts +8 -0
  228. package/lib-es/common-logic/hex-utils.d.ts.map +1 -0
  229. package/lib-es/common-logic/hex-utils.js +50 -0
  230. package/lib-es/common-logic/hex-utils.js.map +1 -0
  231. package/lib-es/common-logic/index.d.ts +7 -0
  232. package/lib-es/common-logic/index.d.ts.map +1 -0
  233. package/lib-es/common-logic/index.js +7 -0
  234. package/lib-es/common-logic/index.js.map +1 -0
  235. package/lib-es/common-logic/logic.d.ts +5 -0
  236. package/lib-es/common-logic/logic.d.ts.map +1 -0
  237. package/lib-es/common-logic/logic.js +38 -0
  238. package/lib-es/common-logic/logic.js.map +1 -0
  239. package/lib-es/common-logic/mapping-utils.d.ts +5 -0
  240. package/lib-es/common-logic/mapping-utils.d.ts.map +1 -0
  241. package/lib-es/common-logic/mapping-utils.js +53 -0
  242. package/lib-es/common-logic/mapping-utils.js.map +1 -0
  243. package/lib-es/common-logic/pad-address.d.ts +2 -0
  244. package/lib-es/common-logic/pad-address.d.ts.map +1 -0
  245. package/lib-es/common-logic/pad-address.js +9 -0
  246. package/lib-es/common-logic/pad-address.js.map +1 -0
  247. package/lib-es/common-logic/transaction-utils.d.ts +30 -0
  248. package/lib-es/common-logic/transaction-utils.d.ts.map +1 -0
  249. package/lib-es/common-logic/transaction-utils.js +153 -0
  250. package/lib-es/common-logic/transaction-utils.js.map +1 -0
  251. package/lib-es/config.d.ts +5 -0
  252. package/lib-es/config.d.ts.map +1 -0
  253. package/lib-es/config.js +12 -0
  254. package/lib-es/config.js.map +1 -0
  255. package/lib-es/contracts/abis/VIP180.d.ts +17 -0
  256. package/lib-es/contracts/abis/VIP180.d.ts.map +1 -0
  257. package/lib-es/contracts/abis/VIP180.js +263 -0
  258. package/lib-es/contracts/abis/VIP180.js.map +1 -0
  259. package/lib-es/contracts/abis/params.d.ts +8 -0
  260. package/lib-es/contracts/abis/params.d.ts.map +1 -0
  261. package/lib-es/contracts/abis/params.js +67 -0
  262. package/lib-es/contracts/abis/params.js.map +1 -0
  263. package/lib-es/contracts/constants.d.ts +6 -0
  264. package/lib-es/contracts/constants.d.ts.map +1 -0
  265. package/lib-es/contracts/constants.js +7 -0
  266. package/lib-es/contracts/constants.js.map +1 -0
  267. package/lib-es/datasets/index.d.ts +3 -0
  268. package/lib-es/datasets/index.d.ts.map +1 -0
  269. package/lib-es/datasets/index.js +3 -0
  270. package/lib-es/datasets/index.js.map +1 -0
  271. package/lib-es/datasets/vechain.d.ts +5 -0
  272. package/lib-es/datasets/vechain.d.ts.map +1 -0
  273. package/lib-es/datasets/vechain.js +88 -0
  274. package/lib-es/datasets/vechain.js.map +1 -0
  275. package/lib-es/datasets/vechain.scanAccounts.1.d.ts +6 -0
  276. package/lib-es/datasets/vechain.scanAccounts.1.d.ts.map +1 -0
  277. package/lib-es/datasets/vechain.scanAccounts.1.js +14 -0
  278. package/lib-es/datasets/vechain.scanAccounts.1.js.map +1 -0
  279. package/lib-es/errors.d.ts +10 -0
  280. package/lib-es/errors.d.ts.map +1 -0
  281. package/lib-es/errors.js +5 -0
  282. package/lib-es/errors.js.map +1 -0
  283. package/lib-es/index.d.ts +2 -0
  284. package/lib-es/index.d.ts.map +1 -0
  285. package/lib-es/index.js +2 -0
  286. package/lib-es/index.js.map +1 -0
  287. package/lib-es/mock.d.ts +9 -0
  288. package/lib-es/mock.d.ts.map +1 -0
  289. package/lib-es/mock.js +11 -0
  290. package/lib-es/mock.js.map +1 -0
  291. package/lib-es/network/index.d.ts +3 -0
  292. package/lib-es/network/index.d.ts.map +1 -0
  293. package/lib-es/network/index.js +3 -0
  294. package/lib-es/network/index.js.map +1 -0
  295. package/lib-es/network/sdk.d.ts +47 -0
  296. package/lib-es/network/sdk.d.ts.map +1 -0
  297. package/lib-es/network/sdk.js +150 -0
  298. package/lib-es/network/sdk.js.map +1 -0
  299. package/lib-es/signer/getAddress.d.ts +6 -0
  300. package/lib-es/signer/getAddress.d.ts.map +1 -0
  301. package/lib-es/signer/getAddress.js +27 -0
  302. package/lib-es/signer/getAddress.js.map +1 -0
  303. package/lib-es/signer/index.d.ts +4 -0
  304. package/lib-es/signer/index.d.ts.map +1 -0
  305. package/lib-es/signer/index.js +4 -0
  306. package/lib-es/signer/index.js.map +1 -0
  307. package/lib-es/signer/signMessage.d.ts +4 -0
  308. package/lib-es/signer/signMessage.d.ts.map +1 -0
  309. package/lib-es/signer/signMessage.js +27 -0
  310. package/lib-es/signer/signMessage.js.map +1 -0
  311. package/lib-es/test/bot-deviceActions.d.ts +7 -0
  312. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  313. package/lib-es/test/bot-deviceActions.js +21 -0
  314. package/lib-es/test/bot-deviceActions.js.map +1 -0
  315. package/lib-es/test/bot-specs.d.ts +8 -0
  316. package/lib-es/test/bot-specs.d.ts.map +1 -0
  317. package/lib-es/test/bot-specs.js +156 -0
  318. package/lib-es/test/bot-specs.js.map +1 -0
  319. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  320. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  321. package/lib-es/test/bridgeDatasetTest.js +246 -0
  322. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  323. package/lib-es/test/cli.d.ts +17 -0
  324. package/lib-es/test/cli.d.ts.map +1 -0
  325. package/lib-es/test/cli.js +45 -0
  326. package/lib-es/test/cli.js.map +1 -0
  327. package/lib-es/test/index.d.ts +6 -0
  328. package/lib-es/test/index.d.ts.map +1 -0
  329. package/lib-es/test/index.js +6 -0
  330. package/lib-es/test/index.js.map +1 -0
  331. package/lib-es/types/bridge.d.ts +25 -0
  332. package/lib-es/types/bridge.d.ts.map +1 -0
  333. package/lib-es/types/bridge.js +2 -0
  334. package/lib-es/types/bridge.js.map +1 -0
  335. package/lib-es/types/constants.d.ts +6 -0
  336. package/lib-es/types/constants.d.ts.map +1 -0
  337. package/lib-es/types/constants.js +6 -0
  338. package/lib-es/types/constants.js.map +1 -0
  339. package/lib-es/types/index.d.ts +5 -0
  340. package/lib-es/types/index.d.ts.map +1 -0
  341. package/lib-es/types/index.js +5 -0
  342. package/lib-es/types/index.js.map +1 -0
  343. package/lib-es/types/network.d.ts +71 -0
  344. package/lib-es/types/network.d.ts.map +1 -0
  345. package/lib-es/types/network.js +2 -0
  346. package/lib-es/types/network.js.map +1 -0
  347. package/lib-es/types/signer.d.ts +12 -0
  348. package/lib-es/types/signer.d.ts.map +1 -0
  349. package/lib-es/types/signer.js +2 -0
  350. package/lib-es/types/signer.js.map +1 -0
  351. package/package.json +120 -0
  352. package/src/__snapshots__/bridge.integration.test.ts.snap +146 -0
  353. package/src/account.ts +22 -0
  354. package/src/bridge/broadcast.ts +23 -0
  355. package/src/bridge/buildOptimisticOperatioin.ts +46 -0
  356. package/src/bridge/createTransaction.ts +31 -0
  357. package/src/bridge/estimateMaxSpendable.ts +18 -0
  358. package/src/bridge/getTransactionStatus.ts +76 -0
  359. package/src/bridge/index.ts +63 -0
  360. package/src/bridge/prepareTransaction.ts +41 -0
  361. package/src/bridge/signOperation.ts +53 -0
  362. package/src/bridge/synchronisation.ts +86 -0
  363. package/src/bridge/transaction.ts +79 -0
  364. package/src/common-logic/address-utils.ts +11 -0
  365. package/src/common-logic/hex-utils.ts +53 -0
  366. package/src/common-logic/index.ts +6 -0
  367. package/src/common-logic/logic.ts +44 -0
  368. package/src/common-logic/mapping-utils.ts +67 -0
  369. package/src/common-logic/pad-address.ts +8 -0
  370. package/src/common-logic/transaction-utils.ts +190 -0
  371. package/src/config.ts +18 -0
  372. package/src/contracts/abis/VIP180.ts +265 -0
  373. package/src/contracts/abis/params.ts +70 -0
  374. package/src/contracts/constants.ts +11 -0
  375. package/src/datasets/index.ts +2 -0
  376. package/src/datasets/vechain.scanAccounts.1.ts +13 -0
  377. package/src/datasets/vechain.ts +92 -0
  378. package/src/errors.ts +7 -0
  379. package/src/index.ts +1 -0
  380. package/src/mock.ts +14 -0
  381. package/src/network/index.ts +2 -0
  382. package/src/network/sdk.ts +177 -0
  383. package/src/signer/getAddress.ts +25 -0
  384. package/src/signer/index.ts +4 -0
  385. package/src/signer/signMessage.ts +22 -0
  386. package/src/test/bot-deviceActions.ts +24 -0
  387. package/src/test/bot-specs.ts +210 -0
  388. package/src/test/bridgeDatasetTest.ts +262 -0
  389. package/src/test/cli.ts +86 -0
  390. package/src/test/index.ts +6 -0
  391. package/src/types/bridge.ts +35 -0
  392. package/src/types/constants.ts +5 -0
  393. package/src/types/index.ts +4 -0
  394. package/src/types/network.ts +81 -0
  395. package/src/types/signer.ts +10 -0
  396. package/tsconfig.json +13 -0
@@ -0,0 +1,71 @@
1
+ export interface AccountResponse {
2
+ balance: string;
3
+ energy: string;
4
+ hasCode: boolean;
5
+ }
6
+ export interface LogMeta {
7
+ blockID: string;
8
+ blockNumber: number;
9
+ blockTimestamp: number;
10
+ txID: string;
11
+ txOrigin: string;
12
+ clauseIndex: number;
13
+ }
14
+ export interface TransferLog {
15
+ sender: string;
16
+ recipient: string;
17
+ amount: string;
18
+ meta: LogMeta;
19
+ }
20
+ export interface EventLog {
21
+ address: string;
22
+ topics: string[];
23
+ data: string;
24
+ meta: LogMeta;
25
+ }
26
+ export interface Range {
27
+ unit: "block";
28
+ from: number;
29
+ to?: number;
30
+ }
31
+ export interface Options {
32
+ offset: number;
33
+ limit: number;
34
+ }
35
+ export interface VetCriteria {
36
+ recipient?: string;
37
+ sender?: string;
38
+ }
39
+ export interface VetTxsQuery {
40
+ range?: Range;
41
+ options?: Options;
42
+ criteriaSet: VetCriteria[];
43
+ order: "desc" | "asc";
44
+ }
45
+ export interface TokenCriteria {
46
+ address: string;
47
+ topic0?: string;
48
+ topic1?: string;
49
+ topic2?: string;
50
+ topic3?: string;
51
+ topic4?: string;
52
+ }
53
+ export interface TokenTxsQuery {
54
+ range?: Range;
55
+ options?: Options;
56
+ criteriaSet: TokenCriteria[];
57
+ order: "desc" | "asc";
58
+ }
59
+ export interface Query {
60
+ to: string;
61
+ data: string;
62
+ }
63
+ export interface QueryResponse {
64
+ data: string;
65
+ events: any[];
66
+ transfers: any[];
67
+ gasUsed: number;
68
+ reverted: boolean;
69
+ vmError: string;
70
+ }
71
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/types/network.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;CACvB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/types/network.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ export type VechainAddress = {
3
+ publicKey: string;
4
+ address: string;
5
+ chainCode?: string;
6
+ };
7
+ export type VechainSignature = Buffer;
8
+ export interface VechainSigner {
9
+ getAddress(path: string, boolDisplay?: boolean, chainCode?: boolean): Promise<VechainAddress>;
10
+ signTransaction(path: string, rawTxHex: string): Promise<VechainSignature>;
11
+ }
12
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACtC,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9F,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC5E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/types/signer.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "@ledgerhq/coin-vechain",
3
+ "version": "2.2.0-next.0",
4
+ "description": "Ledger VeChain Coin integration",
5
+ "keywords": [
6
+ "Ledger",
7
+ "LedgerWallet",
8
+ "VeChain",
9
+ "vet",
10
+ "vtho",
11
+ "Hardware Wallet"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/LedgerHQ/ledger-live.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/LedgerHQ/ledger-live/issues"
19
+ },
20
+ "homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-vechain",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "typesVersions": {
25
+ "*": {
26
+ "lib/*": [
27
+ "lib/*"
28
+ ],
29
+ "lib-es/*": [
30
+ "lib-es/*"
31
+ ],
32
+ "specs": [
33
+ "lib/test/bot-specs"
34
+ ],
35
+ "transaction": [
36
+ "lib/bridge/transaction"
37
+ ],
38
+ "*": [
39
+ "lib/*"
40
+ ]
41
+ }
42
+ },
43
+ "exports": {
44
+ "./lib/*": "./lib/*.js",
45
+ "./lib-es/*": "./lib-es/*.js",
46
+ "./logic": {
47
+ "require": "./lib/common-logic/index.js",
48
+ "default": "./lib-es/common-logic/index.js"
49
+ },
50
+ "./network": {
51
+ "require": "./lib/network/index.js",
52
+ "default": "./lib-es/network/index.js"
53
+ },
54
+ "./signer": {
55
+ "require": "./lib/signer/index.js",
56
+ "default": "./lib-es/signer/index.js"
57
+ },
58
+ "./specs": {
59
+ "require": "./lib/test/bot-specs.js",
60
+ "default": "./lib-es/test/bot-specs.js"
61
+ },
62
+ "./transaction": {
63
+ "require": "./lib/bridge/transaction.js",
64
+ "default": "./lib-es/bridge/transaction.js"
65
+ },
66
+ "./types": {
67
+ "require": "./lib/types/index.js",
68
+ "default": "./lib-es/types/index.js"
69
+ },
70
+ "./*": {
71
+ "require": "./lib/*.js",
72
+ "default": "./lib-es/*.js"
73
+ },
74
+ ".": {
75
+ "require": "./lib/index.js",
76
+ "default": "./lib-es/index.js"
77
+ },
78
+ "./package.json": "./package.json"
79
+ },
80
+ "license": "Apache-2.0",
81
+ "dependencies": {
82
+ "bignumber.js": "^9.1.2",
83
+ "eip55": "^2.1.1",
84
+ "invariant": "^2.2.2",
85
+ "lodash": "^4.17.21",
86
+ "rxjs": "^7.8.1",
87
+ "thor-devkit": "^2.0.6",
88
+ "@ledgerhq/coin-framework": "^0.20.0-next.0",
89
+ "@ledgerhq/cryptoassets": "^13.7.0",
90
+ "@ledgerhq/devices": "^8.4.4",
91
+ "@ledgerhq/errors": "^6.19.1",
92
+ "@ledgerhq/live-env": "^2.4.1",
93
+ "@ledgerhq/live-network": "^2.0.3"
94
+ },
95
+ "devDependencies": {
96
+ "@types/invariant": "^2.2.2",
97
+ "@types/jest": "^29.5.10",
98
+ "@types/lodash": "^4.14.191",
99
+ "dotenv": "^16.4.5",
100
+ "jest": "^29.7.0",
101
+ "ts-jest": "^29.1.1",
102
+ "@ledgerhq/coin-tester": "^0.3.0-next.0",
103
+ "@ledgerhq/types-cryptoassets": "^7.17.0",
104
+ "@ledgerhq/types-live": "^6.54.0-next.0"
105
+ },
106
+ "scripts": {
107
+ "clean": "rimraf lib lib-es",
108
+ "build": "tsc && tsc -m ES6 --outDir lib-es",
109
+ "coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-vechain.json",
110
+ "prewatch": "pnpm build",
111
+ "watch": "tsc --watch",
112
+ "doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
113
+ "lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
114
+ "lint:fix": "pnpm lint --fix",
115
+ "typecheck": "tsc --noEmit",
116
+ "test": "jest --passWithNoTests",
117
+ "test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
118
+ "unimported": "unimported"
119
+ }
120
+ }
@@ -0,0 +1,146 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`vechain currency bridge scanAccounts vechain seed 1 1`] = `
4
+ [
5
+ {
6
+ "currencyId": "vechain",
7
+ "derivationMode": "vechain",
8
+ "feesCurrencyId": "vechain/vip180/vtho",
9
+ "freshAddress": "0x0fe6688548f0C303932bB197B0A96034f1d74dba",
10
+ "freshAddressPath": "44'/818'/0'/0/0",
11
+ "id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain",
12
+ "index": 0,
13
+ "operationsCount": 1,
14
+ "pendingOperations": [],
15
+ "seedIdentifier": "04de5a8f11cc426ff5617aeffd397c5dd77b58424662f368f2cd539a8c42fd2e7d0c6245c9c3a4306f70d7f292e95642651a6832d66fd9823fa6a0af575113e94e",
16
+ "subAccounts": [],
17
+ "swapHistory": [],
18
+ "syncHash": undefined,
19
+ "used": true,
20
+ },
21
+ {
22
+ "id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvip180%2Fvtho",
23
+ "operationsCount": 1,
24
+ "parentId": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain",
25
+ "pendingOperations": [],
26
+ "swapHistory": [],
27
+ "tokenId": "vechain/vip180/vtho",
28
+ "type": "TokenAccountRaw",
29
+ },
30
+ {
31
+ "currencyId": "vechain",
32
+ "derivationMode": "vechain",
33
+ "feesCurrencyId": "vechain/vip180/vtho",
34
+ "freshAddress": "0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86",
35
+ "freshAddressPath": "44'/818'/0'/0/1",
36
+ "id": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain",
37
+ "index": 1,
38
+ "operationsCount": 1,
39
+ "pendingOperations": [],
40
+ "seedIdentifier": "04de5a8f11cc426ff5617aeffd397c5dd77b58424662f368f2cd539a8c42fd2e7d0c6245c9c3a4306f70d7f292e95642651a6832d66fd9823fa6a0af575113e94e",
41
+ "subAccounts": [],
42
+ "swapHistory": [],
43
+ "syncHash": undefined,
44
+ "used": true,
45
+ },
46
+ {
47
+ "id": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain+vechain%2Fvip180%2Fvtho",
48
+ "operationsCount": 0,
49
+ "parentId": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain",
50
+ "pendingOperations": [],
51
+ "swapHistory": [],
52
+ "tokenId": "vechain/vip180/vtho",
53
+ "type": "TokenAccountRaw",
54
+ },
55
+ {
56
+ "currencyId": "vechain",
57
+ "derivationMode": "vechain",
58
+ "feesCurrencyId": "vechain/vip180/vtho",
59
+ "freshAddress": "0xFbC8653C0b842dd33361CE8938B24e407dd4838C",
60
+ "freshAddressPath": "44'/818'/0'/0/2",
61
+ "id": "js:2:vechain:0xFbC8653C0b842dd33361CE8938B24e407dd4838C:vechain",
62
+ "index": 2,
63
+ "operationsCount": 0,
64
+ "pendingOperations": [],
65
+ "seedIdentifier": "04de5a8f11cc426ff5617aeffd397c5dd77b58424662f368f2cd539a8c42fd2e7d0c6245c9c3a4306f70d7f292e95642651a6832d66fd9823fa6a0af575113e94e",
66
+ "subAccounts": [],
67
+ "swapHistory": [],
68
+ "syncHash": undefined,
69
+ "used": false,
70
+ },
71
+ {
72
+ "id": "js:2:vechain:0xFbC8653C0b842dd33361CE8938B24e407dd4838C:vechain+vechain%2Fvip180%2Fvtho",
73
+ "operationsCount": 0,
74
+ "parentId": "js:2:vechain:0xFbC8653C0b842dd33361CE8938B24e407dd4838C:vechain",
75
+ "pendingOperations": [],
76
+ "swapHistory": [],
77
+ "tokenId": "vechain/vip180/vtho",
78
+ "type": "TokenAccountRaw",
79
+ },
80
+ ]
81
+ `;
82
+
83
+ exports[`vechain currency bridge scanAccounts vechain seed 1 2`] = `
84
+ [
85
+ [
86
+ {
87
+ "accountId": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain",
88
+ "blockHash": "0x00fa5b35f158cee280b6be35b4ada7669951035a79806244aaa11e5d2764d5bd",
89
+ "blockHeight": 16407349,
90
+ "extra": {},
91
+ "fee": "210000000000000000",
92
+ "hash": "0xe113f82af98a24c6f2473802f8673f0d69eed1c0f51a5a87d3cc6b8cf96ccfd6",
93
+ "id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain-0xe113f82af98a24c6f2473802f8673f0d69eed1c0f51a5a87d3cc6b8cf96ccfd6-IN",
94
+ "recipients": [
95
+ "0x0fe6688548f0c303932bb197b0a96034f1d74dba",
96
+ ],
97
+ "senders": [
98
+ "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
99
+ ],
100
+ "type": "IN",
101
+ "value": "10000000000000000000",
102
+ },
103
+ ],
104
+ [
105
+ {
106
+ "accountId": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvip180%2Fvtho",
107
+ "blockHash": "0x00fa5b4ee2eca5cf65907e3695bbea044cd1f78224534dc0ba02526890055ecc",
108
+ "blockHeight": 16407374,
109
+ "extra": {},
110
+ "fee": "365180000000000000",
111
+ "hash": "0x5fdd7191c4d476a8e86060d516366e87421f65667b9b3c14c33a740c04921b10",
112
+ "id": "js:2:vechain:0x0fe6688548f0C303932bB197B0A96034f1d74dba:vechain+vechain%2Fvip180%2Fvtho-0x5fdd7191c4d476a8e86060d516366e87421f65667b9b3c14c33a740c04921b10-IN",
113
+ "recipients": [
114
+ "0x0fe6688548f0c303932bb197b0a96034f1d74dba",
115
+ ],
116
+ "senders": [
117
+ "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
118
+ ],
119
+ "type": "IN",
120
+ "value": "10000000000000000000",
121
+ },
122
+ ],
123
+ [
124
+ {
125
+ "accountId": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain",
126
+ "blockHash": "0x00fa5b547b0d542ba8e62a85aa99cf355f1b2a70bd34e3949f889b0856776e05",
127
+ "blockHeight": 16407380,
128
+ "extra": {},
129
+ "fee": "210000000000000000",
130
+ "hash": "0xa4096186f2d58ecc68e6ea11c9757ef5bd78b21b87d73b4618eb6fd3508431ec",
131
+ "id": "js:2:vechain:0x02961B92B8D20A4ea12f1f1CeFA74Dd7B4355A86:vechain-0xa4096186f2d58ecc68e6ea11c9757ef5bd78b21b87d73b4618eb6fd3508431ec-IN",
132
+ "recipients": [
133
+ "0x02961b92b8d20a4ea12f1f1cefa74dd7b4355a86",
134
+ ],
135
+ "senders": [
136
+ "0xcf130b42ae31c4931298b4b1c0f1d974b8732957",
137
+ ],
138
+ "type": "IN",
139
+ "value": "10000000000000000000",
140
+ },
141
+ ],
142
+ [],
143
+ [],
144
+ [],
145
+ ]
146
+ `;
package/src/account.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
2
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
3
+ import type { Account } from "@ledgerhq/types-live";
4
+
5
+ function formatAccountSpecifics(account: Account): string {
6
+ const unit = getAccountCurrency(account).units[0];
7
+ const formatConfig = {
8
+ disableRounding: true,
9
+ alwaysShowSign: false,
10
+ showCode: true,
11
+ };
12
+
13
+ let str = " ";
14
+
15
+ str += formatCurrencyUnit(unit, account.spendableBalance, formatConfig) + " spendable. ";
16
+
17
+ return str;
18
+ }
19
+
20
+ export default {
21
+ formatAccountSpecifics,
22
+ };
@@ -0,0 +1,23 @@
1
+ import { Transaction as VeChainThorTransaction } from "thor-devkit";
2
+ import type { AccountBridge } from "@ledgerhq/types-live";
3
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
4
+
5
+ import { Transaction } from "../types";
6
+ import { submit } from "../network";
7
+
8
+ /**
9
+ * Broadcast the signed transaction
10
+ */
11
+ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
12
+ signedOperation: { signature, operation, rawData },
13
+ }) => {
14
+ const transaction = new VeChainThorTransaction(
15
+ (rawData as unknown as VeChainThorTransaction).body,
16
+ );
17
+ transaction.signature = Buffer.from(signature, "hex");
18
+ const hash = await submit(transaction);
19
+
20
+ return patchOperationWithHash(operation, hash);
21
+ };
22
+
23
+ export default broadcast;
@@ -0,0 +1,46 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account, Operation } from "@ledgerhq/types-live";
3
+ import { Transaction } from "../types";
4
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
5
+
6
+ export const buildOptimisticOperation = async (
7
+ account: Account,
8
+ transaction: Transaction,
9
+ ): Promise<Operation> => {
10
+ const TYPE_OUT = "OUT";
11
+ const subAccountId = transaction.subAccountId;
12
+ const operation: Operation = {
13
+ id: encodeOperationId(account.id, "", TYPE_OUT),
14
+ hash: "",
15
+ type: subAccountId ? "NONE" : TYPE_OUT,
16
+ value: subAccountId ? new BigNumber(0) : new BigNumber(transaction.amount),
17
+ fee: subAccountId ? new BigNumber(0) : new BigNumber(transaction.estimatedFees),
18
+ blockHash: null,
19
+ blockHeight: null,
20
+ senders: [account.freshAddress],
21
+ recipients: [transaction.recipient].filter(Boolean),
22
+ accountId: account.id,
23
+ date: new Date(),
24
+ extra: {},
25
+ subOperations: subAccountId
26
+ ? [
27
+ {
28
+ id: encodeOperationId(subAccountId, "", "OUT"),
29
+ hash: "",
30
+ type: "OUT",
31
+ value: transaction.amount,
32
+ fee: subAccountId ? new BigNumber(transaction.estimatedFees) : new BigNumber(0),
33
+ blockHash: null,
34
+ blockHeight: null,
35
+ senders: [account.freshAddress],
36
+ recipients: [transaction.recipient].filter(Boolean),
37
+ accountId: subAccountId,
38
+ date: new Date(),
39
+ extra: {},
40
+ },
41
+ ]
42
+ : [],
43
+ };
44
+
45
+ return operation;
46
+ };
@@ -0,0 +1,31 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { generateNonce } from "../common-logic";
4
+ import { Transaction, DEFAULT_GAS_COEFFICIENT, MAINNET_CHAIN_TAG } from "../types";
5
+
6
+ /**
7
+ * Create an empty VET or VTHO transaction
8
+ *
9
+ * @returns {Transaction}
10
+ */
11
+ export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => {
12
+ const chainTag = MAINNET_CHAIN_TAG;
13
+
14
+ return {
15
+ family: "vechain",
16
+ body: {
17
+ chainTag,
18
+ blockRef: "0x0000000000000000",
19
+ expiration: 18,
20
+ clauses: [],
21
+ gasPriceCoef: DEFAULT_GAS_COEFFICIENT,
22
+ gas: "0",
23
+ dependsOn: null,
24
+ nonce: generateNonce(),
25
+ },
26
+ amount: new BigNumber(0),
27
+ estimatedFees: "0",
28
+ recipient: "",
29
+ useAllAmount: false,
30
+ };
31
+ };
@@ -0,0 +1,18 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { calculateGasFees } from "../common-logic";
4
+ import type { Transaction } from "../types";
5
+
6
+ export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
7
+ account,
8
+ transaction,
9
+ }): Promise<BigNumber> => {
10
+ if (account.type === "Account" || !transaction) {
11
+ return account.balance;
12
+ }
13
+
14
+ const { estimatedGasFees: maxTokenFees } = await calculateGasFees(transaction, true);
15
+ const spendable = account.balance.minus(maxTokenFees);
16
+ if (spendable.gt(0)) return account.balance.minus(maxTokenFees);
17
+ return new BigNumber(0);
18
+ };
@@ -0,0 +1,76 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ AmountRequired,
4
+ FeeNotLoaded,
5
+ InvalidAddress,
6
+ InvalidAddressBecauseDestinationIsAlsoSource,
7
+ NotEnoughBalance,
8
+ RecipientRequired,
9
+ } from "@ledgerhq/errors";
10
+ import { AccountBridge } from "@ledgerhq/types-live";
11
+ import { calculateTransactionInfo, isValid } from "../common-logic";
12
+ import type { Transaction } from "../types";
13
+ import { NotEnoughVTHO } from "../errors";
14
+
15
+ export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
16
+ account,
17
+ transaction,
18
+ ) => {
19
+ const { freshAddress, currency, subAccounts } = account;
20
+ const { body, recipient, amount } = transaction;
21
+ const errors: Record<string, Error> = {};
22
+ const warnings: Record<string, Error> = {};
23
+ const { isTokenAccount, spendableBalance } = await calculateTransactionInfo(
24
+ account,
25
+ transaction,
26
+ {
27
+ estimatedGas: body.gas as number,
28
+ estimatedGasFees: new BigNumber(transaction.estimatedFees),
29
+ },
30
+ );
31
+
32
+ if (!body || !body.gas) {
33
+ errors.fees = new FeeNotLoaded();
34
+ }
35
+
36
+ if (!recipient) {
37
+ errors.recipient = new RecipientRequired();
38
+ } else if (freshAddress.toLowerCase() === recipient.toLowerCase()) {
39
+ warnings.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
40
+ } else if (!isValid(recipient)) {
41
+ errors.recipient = new InvalidAddress("", {
42
+ currencyName: currency.name,
43
+ });
44
+ }
45
+ const estimatedFees = new BigNumber(transaction.estimatedFees);
46
+ if (!amount.gt(0)) {
47
+ if (!transaction.useAllAmount) errors.amount = new AmountRequired();
48
+ else errors.amount = new NotEnoughBalance();
49
+ } else {
50
+ if (amount.gt(spendableBalance)) {
51
+ errors.amount = new NotEnoughBalance();
52
+ }
53
+ if (!isTokenAccount) {
54
+ // vet
55
+ const vthoBalance = subAccounts?.[0].balance;
56
+ if (estimatedFees.gt(vthoBalance || 0)) {
57
+ errors.amount = new NotEnoughVTHO();
58
+ }
59
+ }
60
+ }
61
+
62
+ let totalSpent = amount;
63
+ if (isTokenAccount) {
64
+ totalSpent = amount.plus(estimatedFees);
65
+ }
66
+
67
+ return Promise.resolve({
68
+ errors,
69
+ warnings,
70
+ estimatedFees,
71
+ amount,
72
+ totalSpent,
73
+ });
74
+ };
75
+
76
+ export default getTransactionStatus;
@@ -0,0 +1,63 @@
1
+ import { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
2
+ import {
3
+ defaultUpdateTransaction,
4
+ makeAccountBridgeReceive,
5
+ makeScanAccounts,
6
+ makeSync,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
10
+ import { getTransactionStatus } from "./getTransactionStatus";
11
+ import { estimateMaxSpendable } from "./estimateMaxSpendable";
12
+ import { prepareTransaction } from "./prepareTransaction";
13
+ import { createTransaction } from "./createTransaction";
14
+ import { getAccountShape } from "./synchronisation";
15
+ import { buildSignOperation } from "./signOperation";
16
+ import { broadcast } from "./broadcast";
17
+ import resolver from "../signer";
18
+ import type { Transaction, VechainSigner } from "../types";
19
+
20
+ export function buildCurrencyBridge(signerContext: SignerContext<VechainSigner>): CurrencyBridge {
21
+ const getAddress = resolver(signerContext);
22
+
23
+ const scanAccounts = makeScanAccounts({
24
+ getAccountShape,
25
+ getAddressFn: getAddressWrapper(getAddress),
26
+ });
27
+
28
+ return {
29
+ preload: async () => Promise.resolve({}),
30
+ hydrate: () => {},
31
+ scanAccounts,
32
+ };
33
+ }
34
+
35
+ const sync = makeSync({ getAccountShape });
36
+
37
+ export function buildAccountBridge(
38
+ signerContext: SignerContext<VechainSigner>,
39
+ ): AccountBridge<Transaction> {
40
+ const getAddress = resolver(signerContext);
41
+
42
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
43
+ const signOperation = buildSignOperation(signerContext);
44
+
45
+ return {
46
+ estimateMaxSpendable,
47
+ createTransaction,
48
+ updateTransaction: defaultUpdateTransaction,
49
+ getTransactionStatus,
50
+ prepareTransaction,
51
+ sync,
52
+ receive,
53
+ signOperation,
54
+ broadcast,
55
+ };
56
+ }
57
+
58
+ export function createBridges(signerContext: SignerContext<VechainSigner>) {
59
+ return {
60
+ currencyBridge: buildCurrencyBridge(signerContext),
61
+ accountBridge: buildAccountBridge(signerContext),
62
+ };
63
+ }