@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,499 @@
1
+ import { ApolloClient } from "@apollo/client";
2
+ import {
3
+ AccountAddress,
4
+ Aptos,
5
+ ChainId,
6
+ Ed25519PublicKey,
7
+ InputEntryFunctionData,
8
+ RawTransaction,
9
+ Serializable,
10
+ post,
11
+ } from "@aptos-labs/ts-sdk";
12
+ import network from "@ledgerhq/live-network";
13
+ import BigNumber from "bignumber.js";
14
+ import { AptosAPI } from "../../api";
15
+
16
+ jest.mock("@aptos-labs/ts-sdk");
17
+ jest.mock("@apollo/client");
18
+ let mockedAptos: jest.Mocked<any>;
19
+ let mockedApolloClient: jest.Mocked<any>;
20
+ let mockedPost = jest.fn();
21
+
22
+ jest.mock("@ledgerhq/live-network/network");
23
+ const mockedNetwork = jest.mocked(network);
24
+
25
+ describe("Aptos API", () => {
26
+ beforeEach(() => {
27
+ mockedAptos = jest.mocked(Aptos);
28
+ mockedApolloClient = jest.mocked(ApolloClient);
29
+ mockedPost = jest.mocked(post);
30
+ });
31
+
32
+ afterEach(() => jest.clearAllMocks());
33
+
34
+ it("builds the client properly for mainnet", () => {
35
+ const api = new AptosAPI("aptos");
36
+
37
+ expect(api.broadcast).toBeDefined();
38
+ expect(typeof api.broadcast).toBe("function");
39
+ expect(api.estimateGasPrice).toBeDefined();
40
+ expect(typeof api.estimateGasPrice).toBe("function");
41
+ expect(api.generateTransaction).toBeDefined();
42
+ expect(typeof api.generateTransaction).toBe("function");
43
+ expect(api.getAccount).toBeDefined();
44
+ expect(typeof api.getAccount).toBe("function");
45
+ expect(api.getAccountInfo).toBeDefined();
46
+ expect(typeof api.getAccountInfo).toBe("function");
47
+ expect(api.simulateTransaction).toBeDefined();
48
+ expect(typeof api.simulateTransaction).toBe("function");
49
+ });
50
+
51
+ it("builds the client properly for testnet", () => {
52
+ const api = new AptosAPI("aptos_testnet");
53
+
54
+ expect(api.broadcast).toBeDefined();
55
+ expect(typeof api.broadcast).toBe("function");
56
+ expect(api.estimateGasPrice).toBeDefined();
57
+ expect(typeof api.estimateGasPrice).toBe("function");
58
+ expect(api.generateTransaction).toBeDefined();
59
+ expect(typeof api.generateTransaction).toBe("function");
60
+ expect(api.getAccount).toBeDefined();
61
+ expect(typeof api.getAccount).toBe("function");
62
+ expect(api.getAccountInfo).toBeDefined();
63
+ expect(typeof api.getAccountInfo).toBe("function");
64
+ expect(api.simulateTransaction).toBeDefined();
65
+ expect(typeof api.simulateTransaction).toBe("function");
66
+ });
67
+
68
+ describe("getAccount", () => {
69
+ it("calls getAccountInfo", async () => {
70
+ const mockGetAccountInfo = jest.fn();
71
+ mockedAptos.mockImplementation(() => ({
72
+ getAccountInfo: mockGetAccountInfo,
73
+ }));
74
+
75
+ const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
76
+
77
+ const api = new AptosAPI("aptos");
78
+ await api.getAccount("address");
79
+
80
+ expect(mockGetAccountSpy).toHaveBeenCalledWith({
81
+ accountAddress: "address",
82
+ });
83
+ });
84
+ });
85
+
86
+ describe("getAccountInfo", () => {
87
+ it("calls getBalance, fetchTransactions and getHeight", async () => {
88
+ mockedAptos.mockImplementation(() => ({
89
+ view: jest.fn().mockReturnValue(["123"]),
90
+ getTransactionByVersion: jest.fn().mockReturnValue({
91
+ type: "user_transaction",
92
+ version: "v1",
93
+ }),
94
+ getBlockByVersion: jest.fn().mockReturnValue({
95
+ block_height: "1",
96
+ block_hash: "83ca6d",
97
+ }),
98
+ }));
99
+
100
+ mockedNetwork.mockResolvedValue(
101
+ Promise.resolve({
102
+ data: {
103
+ account: {
104
+ account_number: 1,
105
+ sequence: 0,
106
+ pub_key: { key: "k", "@type": "type" },
107
+ base_account: {
108
+ account_number: 2,
109
+ sequence: 42,
110
+ pub_key: { key: "k2", "@type": "type2" },
111
+ },
112
+ },
113
+ block_height: "999",
114
+ },
115
+ status: 200,
116
+ headers: {} as any,
117
+ statusText: "",
118
+ config: {
119
+ headers: {} as any,
120
+ },
121
+ }),
122
+ );
123
+
124
+ mockedApolloClient.mockImplementation(() => ({
125
+ query: async () => ({
126
+ data: {
127
+ address_version_from_move_resources: [{ transaction_version: "v1" }],
128
+ },
129
+ loading: false,
130
+ networkStatus: 7,
131
+ }),
132
+ }));
133
+
134
+ const api = new AptosAPI("aptos");
135
+ const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
136
+
137
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
138
+ expect(accountInfo.transactions).toEqual([
139
+ {
140
+ type: "user_transaction",
141
+ version: "v1",
142
+ block: {
143
+ height: 1,
144
+ hash: "83ca6d",
145
+ },
146
+ },
147
+ ]);
148
+ expect(accountInfo.blockHeight).toEqual(999);
149
+ });
150
+
151
+ it("return balance = 0 if it fails to fetch balance", async () => {
152
+ mockedAptos.mockImplementation(() => ({
153
+ view: jest.fn().mockImplementation(() => {
154
+ throw new Error("error");
155
+ }),
156
+ getTransactionByVersion: jest.fn().mockReturnValue({
157
+ type: "user_transaction",
158
+ version: "v1",
159
+ }),
160
+ getBlockByVersion: jest.fn().mockReturnValue({
161
+ block_height: "1",
162
+ block_hash: "83ca6d",
163
+ }),
164
+ }));
165
+
166
+ mockedNetwork.mockResolvedValue(
167
+ Promise.resolve({
168
+ data: {
169
+ account: {
170
+ account_number: 1,
171
+ sequence: 0,
172
+ pub_key: { key: "k", "@type": "type" },
173
+ base_account: {
174
+ account_number: 2,
175
+ sequence: 42,
176
+ pub_key: { key: "k2", "@type": "type2" },
177
+ },
178
+ },
179
+ block_height: "999",
180
+ },
181
+ status: 200,
182
+ headers: {} as any,
183
+ statusText: "",
184
+ config: {
185
+ headers: {} as any,
186
+ },
187
+ }),
188
+ );
189
+
190
+ mockedApolloClient.mockImplementation(() => ({
191
+ query: async () => ({
192
+ data: {
193
+ address_version_from_move_resources: [{ transaction_version: "v1" }],
194
+ },
195
+ loading: false,
196
+ networkStatus: 7,
197
+ }),
198
+ }));
199
+
200
+ const api = new AptosAPI("aptos");
201
+ const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
202
+
203
+ expect(accountInfo.balance).toEqual(new BigNumber(0));
204
+ expect(accountInfo.transactions).toEqual([
205
+ {
206
+ type: "user_transaction",
207
+ version: "v1",
208
+ block: {
209
+ height: 1,
210
+ hash: "83ca6d",
211
+ },
212
+ },
213
+ ]);
214
+ expect(accountInfo.blockHeight).toEqual(999);
215
+ });
216
+
217
+ it("returns no transactions if it the address is empty", async () => {
218
+ mockedAptos.mockImplementation(() => ({
219
+ view: jest.fn().mockReturnValue(["123"]),
220
+ getTransactionByVersion: jest.fn().mockReturnValue({
221
+ type: "user_transaction",
222
+ version: "v1",
223
+ }),
224
+ getBlockByVersion: jest.fn().mockReturnValue({
225
+ block_height: "1",
226
+ block_hash: "83ca6d",
227
+ }),
228
+ }));
229
+
230
+ mockedNetwork.mockResolvedValue(
231
+ Promise.resolve({
232
+ data: {
233
+ account: {
234
+ account_number: 1,
235
+ sequence: 0,
236
+ pub_key: { key: "k", "@type": "type" },
237
+ base_account: {
238
+ account_number: 2,
239
+ sequence: 42,
240
+ pub_key: { key: "k2", "@type": "type2" },
241
+ },
242
+ },
243
+ block_height: "999",
244
+ },
245
+ status: 200,
246
+ headers: {} as any,
247
+ statusText: "",
248
+ config: {
249
+ headers: {} as any,
250
+ },
251
+ }),
252
+ );
253
+
254
+ mockedApolloClient.mockImplementation(() => ({
255
+ query: async () => ({
256
+ data: {
257
+ address_version_from_move_resources: [{ transaction_version: "v1" }],
258
+ },
259
+ loading: false,
260
+ networkStatus: 7,
261
+ }),
262
+ }));
263
+
264
+ const api = new AptosAPI("aptos");
265
+ const accountInfo = await api.getAccountInfo("", "1");
266
+
267
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
268
+ expect(accountInfo.transactions).toEqual([]);
269
+ expect(accountInfo.blockHeight).toEqual(999);
270
+ });
271
+
272
+ it("returns a null transaction if it fails to getTransactionByVersion", async () => {
273
+ mockedAptos.mockImplementation(() => ({
274
+ view: jest.fn().mockReturnValue(["123"]),
275
+ getTransactionByVersion: jest.fn().mockImplementation(() => {
276
+ throw new Error("error");
277
+ }),
278
+ getBlockByVersion: jest.fn().mockReturnValue({
279
+ block_height: "1",
280
+ block_hash: "83ca6d",
281
+ }),
282
+ }));
283
+
284
+ mockedNetwork.mockResolvedValue(
285
+ Promise.resolve({
286
+ data: {
287
+ account: {
288
+ account_number: 1,
289
+ sequence: 0,
290
+ pub_key: { key: "k", "@type": "type" },
291
+ base_account: {
292
+ account_number: 2,
293
+ sequence: 42,
294
+ pub_key: { key: "k2", "@type": "type2" },
295
+ },
296
+ },
297
+ block_height: "999",
298
+ },
299
+ status: 200,
300
+ headers: {} as any,
301
+ statusText: "",
302
+ config: {
303
+ headers: {} as any,
304
+ },
305
+ }),
306
+ );
307
+
308
+ mockedApolloClient.mockImplementation(() => ({
309
+ query: async () => ({
310
+ data: {
311
+ address_version_from_move_resources: [{ transaction_version: "v1" }],
312
+ },
313
+ loading: false,
314
+ networkStatus: 7,
315
+ }),
316
+ }));
317
+
318
+ const api = new AptosAPI("aptos");
319
+ const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
320
+
321
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
322
+ expect(accountInfo.transactions).toEqual([null]);
323
+ expect(accountInfo.blockHeight).toEqual(999);
324
+ });
325
+ });
326
+
327
+ describe("estimateGasPrice", () => {
328
+ it("estimates the gas price", async () => {
329
+ const gasEstimation = { gas_estimate: 100 };
330
+ mockedAptos.mockImplementation(() => ({
331
+ getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
332
+ }));
333
+
334
+ const api = new AptosAPI("aptos");
335
+ const gasPrice = await api.estimateGasPrice();
336
+
337
+ expect(gasPrice.gas_estimate).toEqual(100);
338
+ });
339
+ });
340
+
341
+ describe("generateTransaction", () => {
342
+ const payload: InputEntryFunctionData = {
343
+ function: "0x1::coin::transfer",
344
+ functionArguments: ["0x13", 1],
345
+ };
346
+
347
+ it("generates a transaction without expireTimestamp", async () => {
348
+ const options = {
349
+ maxGasAmount: "100",
350
+ gasUnitPrice: "50",
351
+ };
352
+
353
+ const mockSimple = jest.fn().mockImplementation(async () => ({
354
+ rawTransaction: null,
355
+ }));
356
+ mockedAptos.mockImplementation(() => ({
357
+ transaction: {
358
+ build: {
359
+ simple: mockSimple,
360
+ },
361
+ },
362
+ }));
363
+
364
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
365
+
366
+ const api = new AptosAPI("aptos");
367
+ await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
368
+
369
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
370
+ data: payload,
371
+ options: {
372
+ maxGasAmount: Number(options.maxGasAmount),
373
+ gasUnitPrice: Number(options.gasUnitPrice),
374
+ },
375
+ sender: "APTOS_1_ADDRESS",
376
+ });
377
+ });
378
+
379
+ it("generates a transaction with default expireTimestamp", async () => {
380
+ const options = {
381
+ maxGasAmount: "100",
382
+ gasUnitPrice: "50",
383
+ };
384
+
385
+ const mockSimple = jest.fn().mockImplementation(async () => ({
386
+ rawTransaction: null,
387
+ }));
388
+ const mockGetLedgerInfo = jest.fn().mockImplementation(async () => ({
389
+ ledger_timestamp: "0",
390
+ }));
391
+ mockedAptos.mockImplementation(() => ({
392
+ transaction: {
393
+ build: {
394
+ simple: mockSimple,
395
+ },
396
+ },
397
+ getLedgerInfo: mockGetLedgerInfo,
398
+ }));
399
+
400
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
401
+
402
+ const api = new AptosAPI("aptos");
403
+ await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
404
+
405
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
406
+ data: payload,
407
+ options: {
408
+ maxGasAmount: Number(options.maxGasAmount),
409
+ gasUnitPrice: Number(options.gasUnitPrice),
410
+ expireTimestamp: 120,
411
+ },
412
+ sender: "APTOS_1_ADDRESS",
413
+ });
414
+ });
415
+
416
+ it("throws an error when failing to build a transaction", async () => {
417
+ const options = {
418
+ maxGasAmount: "100",
419
+ gasUnitPrice: "50",
420
+ };
421
+
422
+ const mockSimple = jest.fn().mockImplementation(async () => null);
423
+ mockedAptos.mockImplementation(() => ({
424
+ transaction: {
425
+ build: {
426
+ simple: mockSimple,
427
+ },
428
+ },
429
+ }));
430
+
431
+ const api = new AptosAPI("aptos");
432
+ expect(
433
+ async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options),
434
+ ).rejects.toThrow();
435
+ });
436
+ });
437
+
438
+ describe("simulateTransaction", () => {
439
+ it("simulates a transaction with the correct options", async () => {
440
+ const mockSimple = jest.fn().mockImplementation(async () => ({
441
+ rawTransaction: null,
442
+ }));
443
+ mockedAptos.mockImplementation(() => ({
444
+ transaction: {
445
+ simulate: {
446
+ simple: mockSimple,
447
+ },
448
+ },
449
+ }));
450
+
451
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
452
+
453
+ const api = new AptosAPI("aptos");
454
+ const address = new Ed25519PublicKey("APTOS_1_ADDRESS");
455
+ const tx = new RawTransaction(
456
+ new AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))),
457
+ BigInt(1),
458
+ "" as unknown as Serializable,
459
+ BigInt(100),
460
+ BigInt(50),
461
+ BigInt(1),
462
+ { chainId: 1 } as ChainId,
463
+ );
464
+ await api.simulateTransaction(address, tx);
465
+
466
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
467
+ signerPublicKey: address,
468
+ transaction: { rawTransaction: tx },
469
+ options: {
470
+ estimateGasUnitPrice: true,
471
+ estimateMaxGasAmount: true,
472
+ estimatePrioritizedGasUnitPrice: false,
473
+ },
474
+ });
475
+ });
476
+ });
477
+ describe("broadcast", () => {
478
+ it("broadcasts the transaction", async () => {
479
+ mockedPost.mockImplementation(async () => ({ data: { hash: "ok" } }));
480
+ const mockedPostSpy = jest.spyOn({ post: mockedPost }, "post");
481
+
482
+ mockedAptos.mockImplementation(() => ({
483
+ config: "config",
484
+ }));
485
+
486
+ const api = new AptosAPI("aptos");
487
+ await api.broadcast("signature");
488
+
489
+ expect(mockedPostSpy).toHaveBeenCalledWith({
490
+ contentType: "application/x.aptos.signed_transaction+bcs",
491
+ aptosConfig: "config",
492
+ body: Uint8Array.from(Buffer.from("signature", "hex")),
493
+ path: "transactions",
494
+ type: "Fullnode",
495
+ originMethod: "",
496
+ });
497
+ });
498
+ });
499
+ });
@@ -0,0 +1,98 @@
1
+ import broadcast from "../../bridge/broadcast";
2
+ import { AptosAPI } from "../../api";
3
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
4
+ import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
5
+ import BigNumber from "bignumber.js";
6
+
7
+ jest.mock("../../api");
8
+ jest.mock("@ledgerhq/coin-framework/operation");
9
+
10
+ describe("broadcast", () => {
11
+ const mockAccount: Account = {
12
+ type: "Account",
13
+ seedIdentifier: "mockSeedIdentifier",
14
+ operationsCount: 0,
15
+ id: "mockAccountId",
16
+ currency: {
17
+ type: "CryptoCurrency",
18
+ id: "aptos",
19
+ name: "Aptos",
20
+ ticker: "APT",
21
+ units: [{ name: "APT", code: "APT", magnitude: 6 }],
22
+ managerAppName: "Aptos",
23
+ coinType: 637,
24
+ scheme: "aptos",
25
+ color: "#000000",
26
+ family: "aptos",
27
+ blockAvgTime: 5,
28
+ explorerViews: [],
29
+ },
30
+ balance: BigNumber(1000),
31
+ spendableBalance: BigNumber(1000),
32
+ operations: [],
33
+ pendingOperations: [],
34
+ lastSyncDate: new Date(),
35
+ blockHeight: 0,
36
+ index: 0,
37
+ derivationMode: "",
38
+ freshAddress: "",
39
+ freshAddressPath: "",
40
+ used: false,
41
+ swapHistory: [],
42
+ creationDate: new Date(),
43
+ balanceHistoryCache: {
44
+ HOUR: { latestDate: 0, balances: [] },
45
+ DAY: { latestDate: 0, balances: [] },
46
+ WEEK: { latestDate: 0, balances: [] },
47
+ },
48
+ };
49
+
50
+ const mockOperation: Operation = {
51
+ id: "mockOperationId",
52
+ hash: "",
53
+ type: "OUT",
54
+ value: BigNumber(100),
55
+ fee: BigNumber(1),
56
+ senders: ["sender"],
57
+ recipients: ["recipient"],
58
+ blockHeight: null,
59
+ blockHash: null,
60
+ accountId: "mockAccountId",
61
+ date: new Date(),
62
+ extra: {},
63
+ };
64
+
65
+ const mockSignedOperation: SignedOperation = {
66
+ operation: mockOperation,
67
+ signature: "mockSignature",
68
+ };
69
+
70
+ it("should broadcast the signed operation and return the patched operation", async () => {
71
+ const mockHash = "mockHash";
72
+ (AptosAPI.prototype.broadcast as jest.Mock).mockResolvedValue(mockHash);
73
+ (patchOperationWithHash as jest.Mock).mockReturnValue({
74
+ ...mockOperation,
75
+ hash: mockHash,
76
+ });
77
+
78
+ const result = await broadcast({
79
+ signedOperation: mockSignedOperation,
80
+ account: mockAccount,
81
+ });
82
+
83
+ expect(AptosAPI.prototype.broadcast).toHaveBeenCalledWith("mockSignature");
84
+ expect(patchOperationWithHash).toHaveBeenCalledWith(mockOperation, mockHash);
85
+ expect(result).toEqual({ ...mockOperation, hash: mockHash });
86
+ });
87
+
88
+ it("should throw an error if broadcast fails", async () => {
89
+ (AptosAPI.prototype.broadcast as jest.Mock).mockRejectedValue(new Error("Broadcast failed"));
90
+
91
+ await expect(
92
+ broadcast({
93
+ signedOperation: mockSignedOperation,
94
+ account: mockAccount,
95
+ }),
96
+ ).rejects.toThrow("Broadcast failed");
97
+ });
98
+ });
@@ -0,0 +1,61 @@
1
+ import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
2
+ import buildTransaction from "../../bridge/buildTransaction";
3
+ import { AptosAPI } from "../../api";
4
+ import { normalizeTransactionOptions } from "../../bridge/logic";
5
+ import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
6
+ import { TransactionOptions } from "../../types";
7
+
8
+ const generateTransaction = jest.fn(() => "tx");
9
+
10
+ jest.mock("../../bridge/logic", () => ({
11
+ normalizeTransactionOptions: jest.fn(() => ({
12
+ maxGasAmount: "100",
13
+ gasUnitPrice: "200",
14
+ })),
15
+ DEFAULT_GAS: 100,
16
+ DEFAULT_GAS_PRICE: 200,
17
+ }));
18
+
19
+ jest.mock("../../api", () => {
20
+ return {
21
+ AptosAPI: function () {
22
+ return {
23
+ generateTransaction,
24
+ };
25
+ },
26
+ };
27
+ });
28
+
29
+ describe("buildTransaction Test", () => {
30
+ it("should return tx", async () => {
31
+ const account = createFixtureAccount();
32
+ const transaction = createFixtureTransaction();
33
+ const aptosClient = new AptosAPI(account.currency.id);
34
+ const result = await buildTransaction(account, transaction, aptosClient);
35
+
36
+ const expected = "tx";
37
+
38
+ expect(result).toBe(expected);
39
+
40
+ const mockedNormalizeTransactionOptions = jest.mocked(normalizeTransactionOptions);
41
+
42
+ expect(mockedNormalizeTransactionOptions).toHaveBeenCalledTimes(1);
43
+ expect(generateTransaction).toHaveBeenCalledTimes(1);
44
+
45
+ const generateTransactionArgs: [string, InputEntryFunctionData, TransactionOptions][] =
46
+ generateTransaction.mock.calls[0];
47
+
48
+ expect(mockedNormalizeTransactionOptions.mock.calls[0][0]).toEqual({
49
+ maxGasAmount: "0",
50
+ gasUnitPrice: "0",
51
+ });
52
+
53
+ expect(generateTransactionArgs[0]).toBe("address");
54
+ expect(generateTransactionArgs[1]).toEqual({
55
+ function: "0x1::aptos_account::transfer_coins",
56
+ typeArguments: ["0x1::aptos_coin::AptosCoin"],
57
+ functionArguments: ["", "0"],
58
+ });
59
+ expect(generateTransactionArgs[2]).toEqual({ maxGasAmount: "100", gasUnitPrice: "200" });
60
+ });
61
+ });
@@ -0,0 +1,27 @@
1
+ import BigNumber from "bignumber.js";
2
+ import createTransaction from "../../bridge/createTransaction";
3
+
4
+ jest.mock("../../bridge/logic", () => ({
5
+ DEFAULT_GAS: 100,
6
+ DEFAULT_GAS_PRICE: 200,
7
+ }));
8
+
9
+ describe("createTransaction Test", () => {
10
+ it("should return a transaction object", async () => {
11
+ const result = createTransaction();
12
+
13
+ const expected = {
14
+ family: "aptos",
15
+ mode: "send",
16
+ amount: BigNumber(0),
17
+ recipient: "",
18
+ useAllAmount: false,
19
+ options: {
20
+ maxGasAmount: "100",
21
+ gasUnitPrice: "200",
22
+ },
23
+ };
24
+
25
+ expect(result).toEqual(expected);
26
+ });
27
+ });
@@ -0,0 +1,19 @@
1
+ import getDeviceTransactionConfig, { methodToString } from "../../bridge/deviceTransactionConfig";
2
+
3
+ describe("deviceTransactionConfig", () => {
4
+ test("methodToString", () => {
5
+ expect(methodToString(0)).toBe("Coin transfer");
6
+ expect(methodToString(1)).toBe("Unknown");
7
+ });
8
+
9
+ test("getDeviceTransactionConfig", () => {
10
+ const fields = getDeviceTransactionConfig();
11
+ expect(fields).toMatchObject([
12
+ {
13
+ type: "text",
14
+ label: "Type",
15
+ value: "Coin transfer",
16
+ },
17
+ ]);
18
+ });
19
+ });