@ledgerhq/coin-aptos 1.4.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 (439) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.unimportedrc.json +16 -0
  3. package/CHANGELOG.md +18 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/lib/__tests__/api/index.test.d.ts +2 -0
  7. package/lib/__tests__/api/index.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/index.test.js +447 -0
  9. package/lib/__tests__/api/index.test.js.map +1 -0
  10. package/lib/__tests__/bridge/broadcast.test.d.ts +2 -0
  11. package/lib/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  12. package/lib/__tests__/bridge/broadcast.test.js +98 -0
  13. package/lib/__tests__/bridge/broadcast.test.js.map +1 -0
  14. package/lib/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  15. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  16. package/lib/__tests__/bridge/buildTransaction.test.js +62 -0
  17. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -0
  18. package/lib/__tests__/bridge/createTransaction.test.d.ts +2 -0
  19. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  20. package/lib/__tests__/bridge/createTransaction.test.js +38 -0
  21. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -0
  22. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  23. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  24. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +43 -0
  25. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  26. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  27. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  28. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +84 -0
  29. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  30. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  31. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  32. package/lib/__tests__/bridge/getFeesForTransaction.test.js +188 -0
  33. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  34. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  35. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  36. package/lib/__tests__/bridge/getTransactionStatus.test.js +133 -0
  37. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  38. package/lib/__tests__/bridge/index.test.d.ts +2 -0
  39. package/lib/__tests__/bridge/index.test.d.ts.map +1 -0
  40. package/lib/__tests__/bridge/index.test.js +116 -0
  41. package/lib/__tests__/bridge/index.test.js.map +1 -0
  42. package/lib/__tests__/bridge/logic.test.d.ts +2 -0
  43. package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
  44. package/lib/__tests__/bridge/logic.test.js +773 -0
  45. package/lib/__tests__/bridge/logic.test.js.map +1 -0
  46. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  47. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  48. package/lib/__tests__/bridge/prepareTransaction.test.js +121 -0
  49. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  50. package/lib/__tests__/bridge/signOperation.test.d.ts +2 -0
  51. package/lib/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  52. package/lib/__tests__/bridge/signOperation.test.js +185 -0
  53. package/lib/__tests__/bridge/signOperation.test.js.map +1 -0
  54. package/lib/__tests__/bridge/synchronisation.test.d.ts +2 -0
  55. package/lib/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  56. package/lib/__tests__/bridge/synchronisation.test.js +349 -0
  57. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -0
  58. package/lib/__tests__/bridge/transaction.test.d.ts +2 -0
  59. package/lib/__tests__/bridge/transaction.test.d.ts.map +1 -0
  60. package/lib/__tests__/bridge/transaction.test.js +231 -0
  61. package/lib/__tests__/bridge/transaction.test.js.map +1 -0
  62. package/lib/__tests__/errors.test.d.ts +2 -0
  63. package/lib/__tests__/errors.test.d.ts.map +1 -0
  64. package/lib/__tests__/errors.test.js +18 -0
  65. package/lib/__tests__/errors.test.js.map +1 -0
  66. package/lib/__tests__/index.test.d.ts +2 -0
  67. package/lib/__tests__/index.test.d.ts.map +1 -0
  68. package/lib/__tests__/index.test.js +27 -0
  69. package/lib/__tests__/index.test.js.map +1 -0
  70. package/lib/__tests__/network/index.test.d.ts +2 -0
  71. package/lib/__tests__/network/index.test.d.ts.map +1 -0
  72. package/lib/__tests__/network/index.test.js +57 -0
  73. package/lib/__tests__/network/index.test.js.map +1 -0
  74. package/lib/__tests__/signer/index.test.d.ts +2 -0
  75. package/lib/__tests__/signer/index.test.d.ts.map +1 -0
  76. package/lib/__tests__/signer/index.test.js +37 -0
  77. package/lib/__tests__/signer/index.test.js.map +1 -0
  78. package/lib/api/graphql/queries.d.ts +5 -0
  79. package/lib/api/graphql/queries.d.ts.map +1 -0
  80. package/lib/api/graphql/queries.js +56 -0
  81. package/lib/api/graphql/queries.js.map +1 -0
  82. package/lib/api/graphql/types.d.ts +79 -0
  83. package/lib/api/graphql/types.d.ts.map +1 -0
  84. package/lib/api/graphql/types.js +3 -0
  85. package/lib/api/graphql/types.js.map +1 -0
  86. package/lib/api/index.d.ts +31 -0
  87. package/lib/api/index.d.ts.map +1 -0
  88. package/lib/api/index.js +200 -0
  89. package/lib/api/index.js.map +1 -0
  90. package/lib/bridge/bridge.fixture.d.ts +4 -0
  91. package/lib/bridge/bridge.fixture.d.ts.map +1 -0
  92. package/lib/bridge/bridge.fixture.js +56 -0
  93. package/lib/bridge/bridge.fixture.js.map +1 -0
  94. package/lib/bridge/broadcast.d.ts +7 -0
  95. package/lib/bridge/broadcast.d.ts.map +1 -0
  96. package/lib/bridge/broadcast.js +20 -0
  97. package/lib/bridge/broadcast.js.map +1 -0
  98. package/lib/bridge/buildTransaction.d.ts +7 -0
  99. package/lib/bridge/buildTransaction.d.ts.map +1 -0
  100. package/lib/bridge/buildTransaction.js +28 -0
  101. package/lib/bridge/buildTransaction.js.map +1 -0
  102. package/lib/bridge/createTransaction.d.ts +4 -0
  103. package/lib/bridge/createTransaction.d.ts.map +1 -0
  104. package/lib/bridge/createTransaction.js +20 -0
  105. package/lib/bridge/createTransaction.js.map +1 -0
  106. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  107. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  108. package/lib/bridge/deviceTransactionConfig.js +23 -0
  109. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  110. package/lib/bridge/estimateMaxSpendable.d.ts +10 -0
  111. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  112. package/lib/bridge/estimateMaxSpendable.js +30 -0
  113. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  114. package/lib/bridge/getFeesForTransaction.d.ts +16 -0
  115. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
  116. package/lib/bridge/getFeesForTransaction.js +74 -0
  117. package/lib/bridge/getFeesForTransaction.js.map +1 -0
  118. package/lib/bridge/getTransactionStatus.d.ts +5 -0
  119. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  120. package/lib/bridge/getTransactionStatus.js +48 -0
  121. package/lib/bridge/getTransactionStatus.js.map +1 -0
  122. package/lib/bridge/index.d.ts +8 -0
  123. package/lib/bridge/index.d.ts.map +1 -0
  124. package/lib/bridge/index.js +54 -0
  125. package/lib/bridge/index.js.map +1 -0
  126. package/lib/bridge/logic.d.ts +24 -0
  127. package/lib/bridge/logic.d.ts.map +1 -0
  128. package/lib/bridge/logic.js +200 -0
  129. package/lib/bridge/logic.js.map +1 -0
  130. package/lib/bridge/prepareTransaction.d.ts +5 -0
  131. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  132. package/lib/bridge/prepareTransaction.js +44 -0
  133. package/lib/bridge/prepareTransaction.js.map +1 -0
  134. package/lib/bridge/signOperation.d.ts +11 -0
  135. package/lib/bridge/signOperation.d.ts.map +1 -0
  136. package/lib/bridge/signOperation.js +77 -0
  137. package/lib/bridge/signOperation.js.map +1 -0
  138. package/lib/bridge/synchronisation.d.ts +3 -0
  139. package/lib/bridge/synchronisation.d.ts.map +1 -0
  140. package/lib/bridge/synchronisation.js +53 -0
  141. package/lib/bridge/synchronisation.js.map +1 -0
  142. package/lib/bridge/transaction.d.ts +15 -0
  143. package/lib/bridge/transaction.d.ts.map +1 -0
  144. package/lib/bridge/transaction.js +37 -0
  145. package/lib/bridge/transaction.js.map +1 -0
  146. package/lib/constants.d.ts +19 -0
  147. package/lib/constants.d.ts.map +1 -0
  148. package/lib/constants.js +33 -0
  149. package/lib/constants.js.map +1 -0
  150. package/lib/errors.d.ts +10 -0
  151. package/lib/errors.d.ts.map +1 -0
  152. package/lib/errors.js +8 -0
  153. package/lib/errors.js.map +1 -0
  154. package/lib/index.d.ts +3 -0
  155. package/lib/index.d.ts.map +1 -0
  156. package/lib/index.js +21 -0
  157. package/lib/index.js.map +1 -0
  158. package/lib/network/index.d.ts +6 -0
  159. package/lib/network/index.d.ts.map +1 -0
  160. package/lib/network/index.js +39 -0
  161. package/lib/network/index.js.map +1 -0
  162. package/lib/signer/index.d.ts +6 -0
  163. package/lib/signer/index.d.ts.map +1 -0
  164. package/lib/signer/index.js +23 -0
  165. package/lib/signer/index.js.map +1 -0
  166. package/lib/test/bot-specs.d.ts +7 -0
  167. package/lib/test/bot-specs.d.ts.map +1 -0
  168. package/lib/test/bot-specs.js +77 -0
  169. package/lib/test/bot-specs.js.map +1 -0
  170. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  171. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  172. package/lib/test/bridgeDatasetTest.js +85 -0
  173. package/lib/test/bridgeDatasetTest.js.map +1 -0
  174. package/lib/test/cli.d.ts +19 -0
  175. package/lib/test/cli.d.ts.map +1 -0
  176. package/lib/test/cli.js +59 -0
  177. package/lib/test/cli.js.map +1 -0
  178. package/lib/test/index.d.ts +4 -0
  179. package/lib/test/index.d.ts.map +1 -0
  180. package/lib/test/index.js +20 -0
  181. package/lib/test/index.js.map +1 -0
  182. package/lib/test/speculos-deviceActions.d.ts +5 -0
  183. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  184. package/lib/test/speculos-deviceActions.js +46 -0
  185. package/lib/test/speculos-deviceActions.js.map +1 -0
  186. package/lib/types/bridge.d.ts +5 -0
  187. package/lib/types/bridge.d.ts.map +1 -0
  188. package/lib/types/bridge.js +9 -0
  189. package/lib/types/bridge.js.map +1 -0
  190. package/lib/types/index.d.ts +62 -0
  191. package/lib/types/index.d.ts.map +1 -0
  192. package/lib/types/index.js +19 -0
  193. package/lib/types/index.js.map +1 -0
  194. package/lib/types/signer.d.ts +27 -0
  195. package/lib/types/signer.d.ts.map +1 -0
  196. package/lib/types/signer.js +3 -0
  197. package/lib/types/signer.js.map +1 -0
  198. package/lib-es/__tests__/api/index.test.d.ts +2 -0
  199. package/lib-es/__tests__/api/index.test.d.ts.map +1 -0
  200. package/lib-es/__tests__/api/index.test.js +442 -0
  201. package/lib-es/__tests__/api/index.test.js.map +1 -0
  202. package/lib-es/__tests__/bridge/broadcast.test.d.ts +2 -0
  203. package/lib-es/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  204. package/lib-es/__tests__/bridge/broadcast.test.js +93 -0
  205. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -0
  206. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  207. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  208. package/lib-es/__tests__/bridge/buildTransaction.test.js +57 -0
  209. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
  210. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
  211. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  212. package/lib-es/__tests__/bridge/createTransaction.test.js +33 -0
  213. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
  214. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  215. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  216. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +18 -0
  217. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  218. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  219. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  220. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +79 -0
  221. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  222. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  223. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  224. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +160 -0
  225. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  226. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  227. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  228. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +128 -0
  229. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  230. package/lib-es/__tests__/bridge/index.test.d.ts +2 -0
  231. package/lib-es/__tests__/bridge/index.test.d.ts.map +1 -0
  232. package/lib-es/__tests__/bridge/index.test.js +111 -0
  233. package/lib-es/__tests__/bridge/index.test.js.map +1 -0
  234. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  235. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  236. package/lib-es/__tests__/bridge/logic.test.js +768 -0
  237. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  238. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  239. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  240. package/lib-es/__tests__/bridge/prepareTransaction.test.js +116 -0
  241. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  242. package/lib-es/__tests__/bridge/signOperation.test.d.ts +2 -0
  243. package/lib-es/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  244. package/lib-es/__tests__/bridge/signOperation.test.js +157 -0
  245. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -0
  246. package/lib-es/__tests__/bridge/synchronisation.test.d.ts +2 -0
  247. package/lib-es/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  248. package/lib-es/__tests__/bridge/synchronisation.test.js +347 -0
  249. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -0
  250. package/lib-es/__tests__/bridge/transaction.test.d.ts +2 -0
  251. package/lib-es/__tests__/bridge/transaction.test.d.ts.map +1 -0
  252. package/lib-es/__tests__/bridge/transaction.test.js +226 -0
  253. package/lib-es/__tests__/bridge/transaction.test.js.map +1 -0
  254. package/lib-es/__tests__/errors.test.d.ts +2 -0
  255. package/lib-es/__tests__/errors.test.d.ts.map +1 -0
  256. package/lib-es/__tests__/errors.test.js +16 -0
  257. package/lib-es/__tests__/errors.test.js.map +1 -0
  258. package/lib-es/__tests__/index.test.d.ts +2 -0
  259. package/lib-es/__tests__/index.test.d.ts.map +1 -0
  260. package/lib-es/__tests__/index.test.js +25 -0
  261. package/lib-es/__tests__/index.test.js.map +1 -0
  262. package/lib-es/__tests__/network/index.test.d.ts +2 -0
  263. package/lib-es/__tests__/network/index.test.d.ts.map +1 -0
  264. package/lib-es/__tests__/network/index.test.js +55 -0
  265. package/lib-es/__tests__/network/index.test.js.map +1 -0
  266. package/lib-es/__tests__/signer/index.test.d.ts +2 -0
  267. package/lib-es/__tests__/signer/index.test.d.ts.map +1 -0
  268. package/lib-es/__tests__/signer/index.test.js +32 -0
  269. package/lib-es/__tests__/signer/index.test.js.map +1 -0
  270. package/lib-es/api/graphql/queries.d.ts +5 -0
  271. package/lib-es/api/graphql/queries.d.ts.map +1 -0
  272. package/lib-es/api/graphql/queries.js +53 -0
  273. package/lib-es/api/graphql/queries.js.map +1 -0
  274. package/lib-es/api/graphql/types.d.ts +79 -0
  275. package/lib-es/api/graphql/types.d.ts.map +1 -0
  276. package/lib-es/api/graphql/types.js +2 -0
  277. package/lib-es/api/graphql/types.js.map +1 -0
  278. package/lib-es/api/index.d.ts +31 -0
  279. package/lib-es/api/index.d.ts.map +1 -0
  280. package/lib-es/api/index.js +193 -0
  281. package/lib-es/api/index.js.map +1 -0
  282. package/lib-es/bridge/bridge.fixture.d.ts +4 -0
  283. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -0
  284. package/lib-es/bridge/bridge.fixture.js +48 -0
  285. package/lib-es/bridge/bridge.fixture.js.map +1 -0
  286. package/lib-es/bridge/broadcast.d.ts +7 -0
  287. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  288. package/lib-es/bridge/broadcast.js +18 -0
  289. package/lib-es/bridge/broadcast.js.map +1 -0
  290. package/lib-es/bridge/buildTransaction.d.ts +7 -0
  291. package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
  292. package/lib-es/bridge/buildTransaction.js +26 -0
  293. package/lib-es/bridge/buildTransaction.js.map +1 -0
  294. package/lib-es/bridge/createTransaction.d.ts +4 -0
  295. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  296. package/lib-es/bridge/createTransaction.js +15 -0
  297. package/lib-es/bridge/createTransaction.js.map +1 -0
  298. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  299. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  300. package/lib-es/bridge/deviceTransactionConfig.js +19 -0
  301. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  302. package/lib-es/bridge/estimateMaxSpendable.d.ts +10 -0
  303. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  304. package/lib-es/bridge/estimateMaxSpendable.js +28 -0
  305. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  306. package/lib-es/bridge/getFeesForTransaction.d.ts +16 -0
  307. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
  308. package/lib-es/bridge/getFeesForTransaction.js +66 -0
  309. package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
  310. package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
  311. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  312. package/lib-es/bridge/getTransactionStatus.js +46 -0
  313. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  314. package/lib-es/bridge/index.d.ts +8 -0
  315. package/lib-es/bridge/index.d.ts.map +1 -0
  316. package/lib-es/bridge/index.js +47 -0
  317. package/lib-es/bridge/index.js.map +1 -0
  318. package/lib-es/bridge/logic.d.ts +24 -0
  319. package/lib-es/bridge/logic.d.ts.map +1 -0
  320. package/lib-es/bridge/logic.js +183 -0
  321. package/lib-es/bridge/logic.js.map +1 -0
  322. package/lib-es/bridge/prepareTransaction.d.ts +5 -0
  323. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  324. package/lib-es/bridge/prepareTransaction.js +39 -0
  325. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  326. package/lib-es/bridge/signOperation.d.ts +11 -0
  327. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  328. package/lib-es/bridge/signOperation.js +70 -0
  329. package/lib-es/bridge/signOperation.js.map +1 -0
  330. package/lib-es/bridge/synchronisation.d.ts +3 -0
  331. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  332. package/lib-es/bridge/synchronisation.js +49 -0
  333. package/lib-es/bridge/synchronisation.js.map +1 -0
  334. package/lib-es/bridge/transaction.d.ts +15 -0
  335. package/lib-es/bridge/transaction.d.ts.map +1 -0
  336. package/lib-es/bridge/transaction.js +31 -0
  337. package/lib-es/bridge/transaction.js.map +1 -0
  338. package/lib-es/constants.d.ts +19 -0
  339. package/lib-es/constants.d.ts.map +1 -0
  340. package/lib-es/constants.js +30 -0
  341. package/lib-es/constants.js.map +1 -0
  342. package/lib-es/errors.d.ts +10 -0
  343. package/lib-es/errors.d.ts.map +1 -0
  344. package/lib-es/errors.js +5 -0
  345. package/lib-es/errors.js.map +1 -0
  346. package/lib-es/index.d.ts +3 -0
  347. package/lib-es/index.d.ts.map +1 -0
  348. package/lib-es/index.js +3 -0
  349. package/lib-es/index.js.map +1 -0
  350. package/lib-es/network/index.d.ts +6 -0
  351. package/lib-es/network/index.d.ts.map +1 -0
  352. package/lib-es/network/index.js +35 -0
  353. package/lib-es/network/index.js.map +1 -0
  354. package/lib-es/signer/index.d.ts +6 -0
  355. package/lib-es/signer/index.d.ts.map +1 -0
  356. package/lib-es/signer/index.js +21 -0
  357. package/lib-es/signer/index.js.map +1 -0
  358. package/lib-es/test/bot-specs.d.ts +7 -0
  359. package/lib-es/test/bot-specs.d.ts.map +1 -0
  360. package/lib-es/test/bot-specs.js +72 -0
  361. package/lib-es/test/bot-specs.js.map +1 -0
  362. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  363. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  364. package/lib-es/test/bridgeDatasetTest.js +79 -0
  365. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  366. package/lib-es/test/cli.d.ts +19 -0
  367. package/lib-es/test/cli.d.ts.map +1 -0
  368. package/lib-es/test/cli.js +53 -0
  369. package/lib-es/test/cli.js.map +1 -0
  370. package/lib-es/test/index.d.ts +4 -0
  371. package/lib-es/test/index.d.ts.map +1 -0
  372. package/lib-es/test/index.js +4 -0
  373. package/lib-es/test/index.js.map +1 -0
  374. package/lib-es/test/speculos-deviceActions.d.ts +5 -0
  375. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  376. package/lib-es/test/speculos-deviceActions.js +43 -0
  377. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  378. package/lib-es/types/bridge.d.ts +5 -0
  379. package/lib-es/types/bridge.d.ts.map +1 -0
  380. package/lib-es/types/bridge.js +6 -0
  381. package/lib-es/types/bridge.js.map +1 -0
  382. package/lib-es/types/index.d.ts +62 -0
  383. package/lib-es/types/index.d.ts.map +1 -0
  384. package/lib-es/types/index.js +3 -0
  385. package/lib-es/types/index.js.map +1 -0
  386. package/lib-es/types/signer.d.ts +27 -0
  387. package/lib-es/types/signer.d.ts.map +1 -0
  388. package/lib-es/types/signer.js +2 -0
  389. package/lib-es/types/signer.js.map +1 -0
  390. package/package.json +124 -0
  391. package/src/__tests__/api/index.test.ts +499 -0
  392. package/src/__tests__/bridge/broadcast.test.ts +98 -0
  393. package/src/__tests__/bridge/buildTransaction.test.ts +61 -0
  394. package/src/__tests__/bridge/createTransaction.test.ts +27 -0
  395. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +19 -0
  396. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +94 -0
  397. package/src/__tests__/bridge/getFeesForTransaction.test.ts +189 -0
  398. package/src/__tests__/bridge/getTransactionStatus.test.ts +155 -0
  399. package/src/__tests__/bridge/index.test.ts +108 -0
  400. package/src/__tests__/bridge/logic.test.ts +876 -0
  401. package/src/__tests__/bridge/prepareTransaction.test.ts +118 -0
  402. package/src/__tests__/bridge/signOperation.test.ts +178 -0
  403. package/src/__tests__/bridge/synchronisation.test.ts +374 -0
  404. package/src/__tests__/bridge/transaction.test.ts +261 -0
  405. package/src/__tests__/errors.test.ts +25 -0
  406. package/src/__tests__/index.test.ts +26 -0
  407. package/src/__tests__/network/index.test.ts +95 -0
  408. package/src/__tests__/signer/index.test.ts +24 -0
  409. package/src/api/graphql/queries.ts +53 -0
  410. package/src/api/graphql/types.ts +85 -0
  411. package/src/api/index.ts +224 -0
  412. package/src/bridge/bridge.fixture.ts +53 -0
  413. package/src/bridge/broadcast.ts +17 -0
  414. package/src/bridge/buildTransaction.ts +29 -0
  415. package/src/bridge/createTransaction.ts +17 -0
  416. package/src/bridge/deviceTransactionConfig.ts +30 -0
  417. package/src/bridge/estimateMaxSpendable.ts +35 -0
  418. package/src/bridge/getFeesForTransaction.ts +87 -0
  419. package/src/bridge/getTransactionStatus.ts +54 -0
  420. package/src/bridge/index.ts +65 -0
  421. package/src/bridge/logic.ts +265 -0
  422. package/src/bridge/prepareTransaction.ts +55 -0
  423. package/src/bridge/signOperation.ts +82 -0
  424. package/src/bridge/synchronisation.ts +50 -0
  425. package/src/bridge/transaction.ts +61 -0
  426. package/src/constants.ts +34 -0
  427. package/src/errors.ts +7 -0
  428. package/src/index.ts +3 -0
  429. package/src/network/index.ts +54 -0
  430. package/src/signer/index.ts +17 -0
  431. package/src/test/bot-specs.ts +86 -0
  432. package/src/test/bridgeDatasetTest.ts +82 -0
  433. package/src/test/cli.ts +80 -0
  434. package/src/test/index.ts +3 -0
  435. package/src/test/speculos-deviceActions.ts +52 -0
  436. package/src/types/bridge.ts +4 -0
  437. package/src/types/index.ts +74 -0
  438. package/src/types/signer.ts +26 -0
  439. package/tsconfig.json +14 -0
@@ -0,0 +1,224 @@
1
+ import { ApolloClient, InMemoryCache } from "@apollo/client";
2
+ import {
3
+ AccountData,
4
+ Aptos,
5
+ AptosApiType,
6
+ AptosConfig,
7
+ Ed25519PublicKey,
8
+ GasEstimation,
9
+ InputEntryFunctionData,
10
+ InputGenerateTransactionOptions,
11
+ MimeType,
12
+ post,
13
+ RawTransaction,
14
+ SimpleTransaction,
15
+ TransactionResponse,
16
+ UserTransactionResponse,
17
+ PostRequestOptions,
18
+ Block,
19
+ } from "@aptos-labs/ts-sdk";
20
+ import { getEnv } from "@ledgerhq/live-env";
21
+ import network from "@ledgerhq/live-network";
22
+ import BigNumber from "bignumber.js";
23
+ import isUndefined from "lodash/isUndefined";
24
+ import { APTOS_ASSET_ID } from "../constants";
25
+ import { isTestnet } from "../bridge/logic";
26
+ import type { AptosTransaction, TransactionOptions } from "../types";
27
+ import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
28
+ import {
29
+ GetAccountTransactionsDataQuery,
30
+ GetAccountTransactionsDataGtQueryVariables,
31
+ } from "./graphql/types";
32
+
33
+ const getApiEndpoint = (currencyId: string) =>
34
+ isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
35
+ const getIndexerEndpoint = (currencyId: string) =>
36
+ isTestnet(currencyId)
37
+ ? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
38
+ : getEnv("APTOS_INDEXER_ENDPOINT");
39
+
40
+ export class AptosAPI {
41
+ private apiUrl: string;
42
+ private indexerUrl: string;
43
+ private aptosConfig: AptosConfig;
44
+ private aptosClient: Aptos;
45
+ private apolloClient: ApolloClient<object>;
46
+
47
+ constructor(currencyId: string) {
48
+ this.apiUrl = getApiEndpoint(currencyId);
49
+ this.indexerUrl = getIndexerEndpoint(currencyId);
50
+ this.aptosConfig = new AptosConfig({
51
+ fullnode: this.apiUrl,
52
+ indexer: this.indexerUrl,
53
+ });
54
+ this.aptosClient = new Aptos(this.aptosConfig);
55
+ this.apolloClient = new ApolloClient({
56
+ uri: this.indexerUrl,
57
+ cache: new InMemoryCache(),
58
+ headers: {
59
+ "x-client": "ledger-live",
60
+ },
61
+ });
62
+ }
63
+
64
+ async getAccount(address: string): Promise<AccountData> {
65
+ return this.aptosClient.getAccountInfo({ accountAddress: address });
66
+ }
67
+
68
+ async getAccountInfo(address: string, startAt: string) {
69
+ const [balance, transactions, blockHeight] = await Promise.all([
70
+ this.getBalance(address),
71
+ this.fetchTransactions(address, startAt),
72
+ this.getHeight(),
73
+ ]);
74
+
75
+ return {
76
+ balance,
77
+ transactions,
78
+ blockHeight,
79
+ };
80
+ }
81
+
82
+ async estimateGasPrice(): Promise<GasEstimation> {
83
+ return this.aptosClient.getGasPriceEstimation();
84
+ }
85
+
86
+ async generateTransaction(
87
+ address: string,
88
+ payload: InputEntryFunctionData,
89
+ options: TransactionOptions,
90
+ ): Promise<RawTransaction> {
91
+ const opts: Partial<InputGenerateTransactionOptions> = {};
92
+ if (!isUndefined(options.maxGasAmount)) {
93
+ opts.maxGasAmount = Number(options.maxGasAmount);
94
+ }
95
+
96
+ if (!isUndefined(options.gasUnitPrice)) {
97
+ opts.gasUnitPrice = Number(options.gasUnitPrice);
98
+ }
99
+
100
+ try {
101
+ const { ledger_timestamp } = await this.aptosClient.getLedgerInfo();
102
+ opts.expireTimestamp = Number(Math.ceil(+ledger_timestamp / 1_000_000 + 2 * 60)); // in milliseconds
103
+ } catch {
104
+ // skip
105
+ }
106
+
107
+ return this.aptosClient.transaction.build
108
+ .simple({
109
+ sender: address,
110
+ data: payload,
111
+ options: opts,
112
+ })
113
+ .then(t => t.rawTransaction)
114
+ .catch(error => {
115
+ throw error;
116
+ });
117
+ }
118
+
119
+ async simulateTransaction(
120
+ address: Ed25519PublicKey,
121
+ tx: RawTransaction,
122
+ options = {
123
+ estimateGasUnitPrice: true,
124
+ estimateMaxGasAmount: true,
125
+ estimatePrioritizedGasUnitPrice: false,
126
+ },
127
+ ): Promise<UserTransactionResponse[]> {
128
+ return this.aptosClient.transaction.simulate.simple({
129
+ signerPublicKey: address,
130
+ transaction: { rawTransaction: tx } as SimpleTransaction,
131
+ options,
132
+ });
133
+ }
134
+
135
+ async broadcast(signature: string): Promise<string> {
136
+ const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
137
+ const pendingTx = await post<PostRequestOptions, TransactionResponse>({
138
+ contentType: MimeType.BCS_SIGNED_TRANSACTION,
139
+ aptosConfig: this.aptosClient.config,
140
+ body: txBytes,
141
+ path: "transactions",
142
+ type: AptosApiType.FULLNODE,
143
+ originMethod: "",
144
+ });
145
+ return pendingTx.data.hash;
146
+ }
147
+
148
+ private async getBalance(address: string): Promise<BigNumber> {
149
+ try {
150
+ const [balanceStr] = await this.aptosClient.view<[string]>({
151
+ payload: {
152
+ function: "0x1::coin::balance",
153
+ typeArguments: [APTOS_ASSET_ID],
154
+ functionArguments: [address],
155
+ },
156
+ });
157
+ const balance = parseInt(balanceStr, 10);
158
+ return new BigNumber(balance);
159
+ } catch (_) {
160
+ return new BigNumber(0);
161
+ }
162
+ }
163
+
164
+ private async fetchTransactions(address: string, gt?: string) {
165
+ if (!address) {
166
+ return [];
167
+ }
168
+
169
+ let query = GetAccountTransactionsData;
170
+ if (gt) {
171
+ query = GetAccountTransactionsDataGt;
172
+ }
173
+
174
+ const queryResponse = await this.apolloClient.query<
175
+ GetAccountTransactionsDataQuery,
176
+ GetAccountTransactionsDataGtQueryVariables
177
+ >({
178
+ query,
179
+ variables: {
180
+ address,
181
+ limit: 1000,
182
+ gt,
183
+ },
184
+ fetchPolicy: "network-only",
185
+ });
186
+
187
+ return Promise.all(
188
+ queryResponse.data.address_version_from_move_resources.map(({ transaction_version }) => {
189
+ return this.richItemByVersion(transaction_version);
190
+ }),
191
+ );
192
+ }
193
+
194
+ private async richItemByVersion(version: number): Promise<AptosTransaction | null> {
195
+ try {
196
+ const tx: TransactionResponse = await this.aptosClient.getTransactionByVersion({
197
+ ledgerVersion: version,
198
+ });
199
+ const block = await this.getBlock(version);
200
+ return {
201
+ ...tx,
202
+ block,
203
+ } as AptosTransaction;
204
+ } catch (error) {
205
+ return null;
206
+ }
207
+ }
208
+
209
+ private async getHeight(): Promise<number> {
210
+ const { data } = await network<Block>({
211
+ method: "GET",
212
+ url: this.apiUrl,
213
+ });
214
+ return parseInt(data.block_height);
215
+ }
216
+
217
+ private async getBlock(version: number) {
218
+ const block = await this.aptosClient.getBlockByVersion({ ledgerVersion: version });
219
+ return {
220
+ height: parseInt(block.block_height),
221
+ hash: block.block_hash,
222
+ };
223
+ }
224
+ }
@@ -0,0 +1,53 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { faker } from "@faker-js/faker";
3
+ import type { AptosAccount, Transaction } from "../types/index";
4
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
5
+ import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
6
+
7
+ const currency = getCryptoCurrencyById("aptos");
8
+
9
+ export function createFixtureAccount(account?: Partial<AptosAccount>): AptosAccount {
10
+ const freshAddress = {
11
+ address: "address",
12
+ derivationPath: "derivation_path",
13
+ };
14
+
15
+ return {
16
+ type: "Account",
17
+ id: faker.string.uuid(),
18
+ seedIdentifier: faker.string.uuid(),
19
+ derivationMode: "",
20
+ index: faker.number.int(),
21
+ freshAddress: account?.freshAddress || freshAddress.address,
22
+ freshAddressPath: account?.freshAddressPath || freshAddress.derivationPath,
23
+ used: true,
24
+ balance: account?.balance || new BigNumber(0),
25
+ spendableBalance: account?.spendableBalance || new BigNumber(0),
26
+ creationDate: faker.date.past(),
27
+ blockHeight: faker.number.int({ min: 100_000, max: 200_000 }),
28
+ currency,
29
+ operationsCount: account?.operationsCount || 0,
30
+ operations: account?.operations || [],
31
+ pendingOperations: account?.pendingOperations || [],
32
+ lastSyncDate: new Date(),
33
+ balanceHistoryCache: emptyHistoryCache,
34
+ swapHistory: [],
35
+ };
36
+ }
37
+
38
+ export function createFixtureTransaction(tx?: Partial<Transaction>): Transaction {
39
+ const transaction: Transaction = {
40
+ amount: tx?.amount || new BigNumber(0),
41
+ recipient: tx?.recipient || "",
42
+ useAllAmount: tx?.useAllAmount || false,
43
+ family: "aptos",
44
+ mode: tx?.mode || "send",
45
+ fees: tx?.fees || null,
46
+ options: {
47
+ maxGasAmount: BigNumber(0).toString(),
48
+ gasUnitPrice: BigNumber(0).toString(),
49
+ },
50
+ };
51
+
52
+ return transaction;
53
+ }
@@ -0,0 +1,17 @@
1
+ import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
2
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
3
+ import { AptosAPI } from "../api";
4
+
5
+ const broadcast = async ({
6
+ signedOperation,
7
+ account,
8
+ }: {
9
+ signedOperation: SignedOperation;
10
+ account: Account;
11
+ }): Promise<Operation> => {
12
+ const { signature, operation } = signedOperation;
13
+ const hash = await new AptosAPI(account.currency.id).broadcast(signature);
14
+ return patchOperationWithHash(operation, hash);
15
+ };
16
+
17
+ export default broadcast;
@@ -0,0 +1,29 @@
1
+ import { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
2
+ import type { Account } from "@ledgerhq/types-live";
3
+ import BigNumber from "bignumber.js";
4
+ import { AptosAPI } from "../api";
5
+ import { APTOS_ASSET_ID } from "../constants";
6
+ import { normalizeTransactionOptions } from "./logic";
7
+ import type { Transaction } from "../types";
8
+
9
+ const buildTransaction = async (
10
+ account: Account,
11
+ transaction: Transaction,
12
+ aptosClient: AptosAPI,
13
+ ): Promise<RawTransaction> => {
14
+ const txPayload = getPayload(transaction.recipient, transaction.amount);
15
+ const txOptions = normalizeTransactionOptions(transaction.options);
16
+ const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
17
+
18
+ return tx;
19
+ };
20
+
21
+ const getPayload = (sendTo: string, amount: BigNumber): InputEntryFunctionData => {
22
+ return {
23
+ function: "0x1::aptos_account::transfer_coins",
24
+ typeArguments: [APTOS_ASSET_ID],
25
+ functionArguments: [sendTo, amount.toString()],
26
+ };
27
+ };
28
+
29
+ export default buildTransaction;
@@ -0,0 +1,17 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type { Transaction } from "../types";
3
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "./logic";
4
+
5
+ const createTransaction = (): Transaction => ({
6
+ family: "aptos",
7
+ mode: "send",
8
+ amount: BigNumber(0),
9
+ recipient: "",
10
+ useAllAmount: false,
11
+ options: {
12
+ maxGasAmount: DEFAULT_GAS.toString(),
13
+ gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
14
+ },
15
+ });
16
+
17
+ export default createTransaction;
@@ -0,0 +1,30 @@
1
+ import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
2
+ import BigNumber from "bignumber.js";
3
+
4
+ export const methodToString = (method: number): string => {
5
+ switch (method) {
6
+ case 0:
7
+ return "Coin transfer";
8
+ default:
9
+ return "Unknown";
10
+ }
11
+ };
12
+
13
+ export type ExtraDeviceTransactionField = {
14
+ type: "aptos.extendedAmount";
15
+ label: string;
16
+ value: number | BigNumber;
17
+ };
18
+
19
+ function getDeviceTransactionConfig(): Array<DeviceTransactionField> {
20
+ const fields: Array<DeviceTransactionField> = [];
21
+ fields.push({
22
+ type: "text",
23
+ label: "Type",
24
+ value: methodToString(0),
25
+ });
26
+
27
+ return fields;
28
+ }
29
+
30
+ export default getDeviceTransactionConfig;
@@ -0,0 +1,35 @@
1
+ import type { Account, AccountLike } from "@ledgerhq/types-live";
2
+ import { BigNumber } from "bignumber.js";
3
+ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
+ import { AptosAPI } from "../api";
5
+ import { getEstimatedGas } from "./getFeesForTransaction";
6
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
7
+ import type { Transaction } from "../types";
8
+
9
+ const estimateMaxSpendable = async ({
10
+ account,
11
+ parentAccount,
12
+ transaction,
13
+ }: {
14
+ account: AccountLike;
15
+ parentAccount?: Account;
16
+ transaction?: Transaction;
17
+ }): Promise<BigNumber> => {
18
+ const mainAccount = getMainAccount(account, parentAccount);
19
+
20
+ const aptosClient = new AptosAPI(mainAccount.currency.id);
21
+
22
+ let maxGasAmount = new BigNumber(DEFAULT_GAS);
23
+ let gasUnitPrice = new BigNumber(DEFAULT_GAS_PRICE);
24
+
25
+ if (transaction) {
26
+ const { estimate } = await getEstimatedGas(mainAccount, transaction, aptosClient);
27
+
28
+ maxGasAmount = BigNumber(estimate.maxGasAmount);
29
+ gasUnitPrice = BigNumber(estimate.gasUnitPrice);
30
+ }
31
+
32
+ return getMaxSendBalance(mainAccount.spendableBalance, maxGasAmount, gasUnitPrice);
33
+ };
34
+
35
+ export default estimateMaxSpendable;
@@ -0,0 +1,87 @@
1
+ import { Ed25519PublicKey } from "@aptos-labs/ts-sdk";
2
+ import { log } from "@ledgerhq/logs";
3
+ import type { Account } from "@ledgerhq/types-live";
4
+ import BigNumber from "bignumber.js";
5
+ import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
6
+ import { AptosAPI } from "../api";
7
+ import buildTransaction from "./buildTransaction";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "./logic";
9
+ import type { Transaction, TransactionErrors } from "../types";
10
+
11
+ type IGetEstimatedGasReturnType = {
12
+ fees: BigNumber;
13
+ estimate: {
14
+ maxGasAmount: string;
15
+ gasUnitPrice: string;
16
+ };
17
+ errors: TransactionErrors;
18
+ };
19
+
20
+ export const getFee = async (
21
+ account: Account,
22
+ transaction: Transaction,
23
+ aptosClient: AptosAPI,
24
+ ): Promise<IGetEstimatedGasReturnType> => {
25
+ const res = {
26
+ fees: new BigNumber(DEFAULT_GAS).multipliedBy(DEFAULT_GAS_PRICE),
27
+ estimate: {
28
+ maxGasAmount: DEFAULT_GAS.toString(),
29
+ gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
30
+ },
31
+ errors: { ...transaction.errors },
32
+ };
33
+
34
+ let gasLimit = DEFAULT_GAS;
35
+ let gasPrice = DEFAULT_GAS_PRICE;
36
+ transaction.options = {
37
+ maxGasAmount: gasLimit.toString(),
38
+ gasUnitPrice: gasPrice.toString(),
39
+ };
40
+ if (account.xpub) {
41
+ try {
42
+ const publicKeyEd = new Ed25519PublicKey(account.xpub as string);
43
+ const tx = await buildTransaction(account, transaction, aptosClient);
44
+ const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
45
+ const completedTx = simulation[0];
46
+
47
+ gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
48
+ gasPrice = new BigNumber(completedTx.gas_unit_price);
49
+
50
+ const expectedGas = gasPrice.multipliedBy(gasLimit);
51
+
52
+ const isUnderMaxSpendable = transaction.amount
53
+ .plus(expectedGas)
54
+ .isLessThan(account.spendableBalance);
55
+
56
+ if (isUnderMaxSpendable && !completedTx.success) {
57
+ // we want to skip INSUFFICIENT_BALANCE error because it will be processed by getTransactionStatus
58
+ if (!completedTx.vm_status.includes("INSUFFICIENT_BALANCE")) {
59
+ throw Error(`Simulation failed with following error: ${completedTx.vm_status}`);
60
+ }
61
+ }
62
+ res.fees = expectedGas;
63
+ res.estimate.maxGasAmount = gasLimit.toString();
64
+ res.estimate.gasUnitPrice = completedTx.gas_unit_price;
65
+ } catch (error: any) {
66
+ log(error.message);
67
+ throw error;
68
+ }
69
+ }
70
+ return res;
71
+ };
72
+
73
+ const CACHE = makeLRUCache(
74
+ getFee,
75
+ (_account: Account, transaction: Transaction, _aptosClient: AptosAPI) => {
76
+ return transaction.amount.toString();
77
+ },
78
+ seconds(30),
79
+ );
80
+
81
+ export const getEstimatedGas = async (
82
+ account: Account,
83
+ transaction: Transaction,
84
+ aptosClient: AptosAPI,
85
+ ): Promise<IGetEstimatedGasReturnType> => {
86
+ return await CACHE(account, transaction, aptosClient);
87
+ };
@@ -0,0 +1,54 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import {
3
+ NotEnoughBalance,
4
+ RecipientRequired,
5
+ InvalidAddress,
6
+ FeeNotLoaded,
7
+ InvalidAddressBecauseDestinationIsAlsoSource,
8
+ AmountRequired,
9
+ } from "@ledgerhq/errors";
10
+ import type { Account } from "@ledgerhq/types-live";
11
+ import type { Transaction, TransactionStatus } from "../types";
12
+
13
+ import { AccountAddress } from "@aptos-labs/ts-sdk";
14
+
15
+ const getTransactionStatus = async (a: Account, t: Transaction): Promise<TransactionStatus> => {
16
+ const errors: Record<string, Error> = {};
17
+ const warnings = {};
18
+
19
+ if (!t.fees) {
20
+ errors.fees = new FeeNotLoaded();
21
+ }
22
+
23
+ const estimatedFees = t.fees || BigNumber(0);
24
+
25
+ if (t.amount.eq(0)) {
26
+ errors.amount = new AmountRequired();
27
+ }
28
+
29
+ const amount = t.amount;
30
+
31
+ const totalSpent = BigNumber(t.amount).plus(estimatedFees);
32
+
33
+ if (totalSpent.gt(a.balance) && !errors.amount) {
34
+ errors.amount = new NotEnoughBalance();
35
+ }
36
+
37
+ if (!t.recipient) {
38
+ errors.recipient = new RecipientRequired();
39
+ } else if (AccountAddress.isValid({ input: t.recipient }).valid === false && !errors.recipient) {
40
+ errors.recipient = new InvalidAddress("", { currencyName: a.currency.name });
41
+ } else if (t.recipient === a.freshAddress && !errors.recipient) {
42
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
43
+ }
44
+
45
+ return Promise.resolve({
46
+ errors,
47
+ warnings,
48
+ estimatedFees,
49
+ amount,
50
+ totalSpent,
51
+ });
52
+ };
53
+
54
+ export default getTransactionStatus;
@@ -0,0 +1,65 @@
1
+ import {
2
+ makeAccountBridgeReceive,
3
+ makeScanAccounts,
4
+ getSerializedAddressParameters,
5
+ makeSync,
6
+ updateTransaction,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
9
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
10
+ import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
11
+ import resolver from "../signer";
12
+ import type { Transaction, TransactionStatus, AptosSigner } from "../types";
13
+ import getTransactionStatus from "./getTransactionStatus";
14
+ import estimateMaxSpendable from "./estimateMaxSpendable";
15
+ import prepareTransaction from "./prepareTransaction";
16
+ import createTransaction from "./createTransaction";
17
+ import { getAccountShape } from "./synchronisation";
18
+ import buildSignOperation from "./signOperation";
19
+ import broadcast from "./broadcast";
20
+
21
+ function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
22
+ const getAddress = resolver(signerContext);
23
+
24
+ const scanAccounts = makeScanAccounts({
25
+ getAccountShape,
26
+ getAddressFn: getAddressWrapper(getAddress),
27
+ });
28
+
29
+ return {
30
+ preload: () => Promise.resolve({}),
31
+ hydrate: () => {},
32
+ scanAccounts,
33
+ };
34
+ }
35
+
36
+ const sync = makeSync({ getAccountShape });
37
+
38
+ function buildAccountBridge(
39
+ signerContext: SignerContext<AptosSigner>,
40
+ ): AccountBridge<Transaction, Account, TransactionStatus> {
41
+ const getAddress = resolver(signerContext);
42
+
43
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
44
+ const signOperation = buildSignOperation(signerContext);
45
+
46
+ return {
47
+ estimateMaxSpendable,
48
+ createTransaction,
49
+ updateTransaction,
50
+ getTransactionStatus,
51
+ getSerializedAddressParameters,
52
+ prepareTransaction,
53
+ sync,
54
+ receive,
55
+ signOperation,
56
+ broadcast,
57
+ };
58
+ }
59
+
60
+ export function createBridges(signerContext: SignerContext<AptosSigner>) {
61
+ return {
62
+ currencyBridge: buildCurrencyBridge(signerContext),
63
+ accountBridge: buildAccountBridge(signerContext),
64
+ };
65
+ }