@ledgerhq/coin-aptos 2.0.0 → 2.1.0-next.1

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 (391) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +36 -0
  3. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  4. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  5. package/lib/__tests__/api/craftTransaction.unit.test.js +187 -0
  6. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  7. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  8. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  9. package/lib/__tests__/api/getBalance.unit.test.js +41 -0
  10. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  11. package/lib/__tests__/api/index.integ.test.js +276 -9
  12. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  13. package/lib/__tests__/api/index.test.js +1 -1
  14. package/lib/__tests__/api/index.test.js.map +1 -1
  15. package/lib/__tests__/bridge/logic.test.js +8 -558
  16. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  17. package/lib/__tests__/bridge/signOperation.test.js +7 -11
  18. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  19. package/lib/__tests__/index.test.js +1 -1
  20. package/lib/__tests__/index.test.js.map +1 -1
  21. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  22. package/lib/__tests__/{bridge → logic}/buildTransaction.test.js +14 -8
  23. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  24. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  25. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  26. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  27. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  28. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  29. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  30. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  31. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  32. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  33. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  34. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  35. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  36. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  37. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  38. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  39. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  40. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  41. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  42. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  43. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  44. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  45. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  46. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  47. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  48. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  49. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  50. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  51. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  52. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  53. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  54. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  55. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  56. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  57. package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
  58. package/lib/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  59. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  60. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  61. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  62. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  63. package/lib/__tests__/network/client.test.js +613 -9
  64. package/lib/__tests__/network/client.test.js.map +1 -1
  65. package/lib/api/index.d.ts.map +1 -1
  66. package/lib/api/index.js +7 -12
  67. package/lib/api/index.js.map +1 -1
  68. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  69. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  70. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  71. package/lib/bridge/getFeesForTransaction.js +1 -1
  72. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  73. package/lib/bridge/index.js +1 -1
  74. package/lib/bridge/index.js.map +1 -1
  75. package/lib/bridge/logic.d.ts +1 -17
  76. package/lib/bridge/logic.d.ts.map +1 -1
  77. package/lib/bridge/logic.js +12 -204
  78. package/lib/bridge/logic.js.map +1 -1
  79. package/lib/bridge/prepareTransaction.js +1 -1
  80. package/lib/bridge/prepareTransaction.js.map +1 -1
  81. package/lib/bridge/signOperation.d.ts.map +1 -1
  82. package/lib/bridge/signOperation.js +1 -1
  83. package/lib/bridge/signOperation.js.map +1 -1
  84. package/lib/config.d.ts +1 -1
  85. package/lib/config.d.ts.map +1 -1
  86. package/lib/constants.d.ts +7 -4
  87. package/lib/constants.d.ts.map +1 -1
  88. package/lib/constants.js +8 -4
  89. package/lib/constants.js.map +1 -1
  90. package/lib/logic/buildTransaction.d.ts +9 -0
  91. package/lib/logic/buildTransaction.d.ts.map +1 -0
  92. package/lib/logic/buildTransaction.js +47 -0
  93. package/lib/logic/buildTransaction.js.map +1 -0
  94. package/lib/logic/calculateAmount.d.ts +3 -0
  95. package/lib/logic/calculateAmount.d.ts.map +1 -0
  96. package/lib/logic/calculateAmount.js +13 -0
  97. package/lib/logic/calculateAmount.js.map +1 -0
  98. package/lib/logic/combine.d.ts +4 -0
  99. package/lib/logic/combine.d.ts.map +1 -0
  100. package/lib/logic/combine.js +34 -0
  101. package/lib/logic/combine.js.map +1 -0
  102. package/lib/logic/craftTransaction.d.ts +5 -0
  103. package/lib/logic/craftTransaction.d.ts.map +1 -0
  104. package/lib/logic/craftTransaction.js +68 -0
  105. package/lib/logic/craftTransaction.js.map +1 -0
  106. package/lib/logic/createTransaction.d.ts.map +1 -0
  107. package/lib/logic/createTransaction.js.map +1 -0
  108. package/lib/logic/getBalance.d.ts +5 -0
  109. package/lib/logic/getBalance.d.ts.map +1 -0
  110. package/lib/logic/getBalance.js +12 -0
  111. package/lib/logic/getBalance.js.map +1 -0
  112. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  113. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  114. package/lib/logic/getCoinAndAmounts.js +112 -0
  115. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  116. package/lib/logic/getFunctionAddress.d.ts +3 -0
  117. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  118. package/lib/logic/getFunctionAddress.js +12 -0
  119. package/lib/logic/getFunctionAddress.js.map +1 -0
  120. package/lib/logic/getResourceAddress.d.ts +4 -0
  121. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  122. package/lib/logic/getResourceAddress.js +17 -0
  123. package/lib/logic/getResourceAddress.js.map +1 -0
  124. package/lib/logic/isTestnet.d.ts +2 -0
  125. package/lib/logic/isTestnet.d.ts.map +1 -0
  126. package/lib/logic/isTestnet.js +9 -0
  127. package/lib/logic/isTestnet.js.map +1 -0
  128. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  129. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  130. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  131. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  132. package/lib/logic/normalizeAddress.d.ts +2 -0
  133. package/lib/logic/normalizeAddress.d.ts.map +1 -0
  134. package/lib/logic/normalizeAddress.js +12 -0
  135. package/lib/logic/normalizeAddress.js.map +1 -0
  136. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  137. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  138. package/lib/logic/normalizeTransactionOptions.js +21 -0
  139. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  140. package/lib/logic/processRecipients.d.ts +6 -0
  141. package/lib/logic/processRecipients.d.ts.map +1 -0
  142. package/lib/logic/processRecipients.js +58 -0
  143. package/lib/logic/processRecipients.js.map +1 -0
  144. package/lib/logic/transactionsToOperations.d.ts +7 -0
  145. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  146. package/lib/logic/transactionsToOperations.js +89 -0
  147. package/lib/logic/transactionsToOperations.js.map +1 -0
  148. package/lib/network/client.d.ts +6 -4
  149. package/lib/network/client.d.ts.map +1 -1
  150. package/lib/network/client.js +50 -14
  151. package/lib/network/client.js.map +1 -1
  152. package/lib/network/index.d.ts.map +1 -1
  153. package/lib/network/index.js +4 -7
  154. package/lib/network/index.js.map +1 -1
  155. package/lib/types/assets.d.ts +5 -1
  156. package/lib/types/assets.d.ts.map +1 -1
  157. package/lib/types/index.d.ts +4 -0
  158. package/lib/types/index.d.ts.map +1 -1
  159. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  160. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  161. package/lib-es/__tests__/api/craftTransaction.unit.test.js +185 -0
  162. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  163. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  164. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  165. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  166. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  167. package/lib-es/__tests__/api/index.integ.test.js +277 -10
  168. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  169. package/lib-es/__tests__/api/index.test.js +1 -1
  170. package/lib-es/__tests__/api/index.test.js.map +1 -1
  171. package/lib-es/__tests__/bridge/logic.test.js +8 -558
  172. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  173. package/lib-es/__tests__/bridge/signOperation.test.js +7 -11
  174. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  175. package/lib-es/__tests__/index.test.js +1 -1
  176. package/lib-es/__tests__/index.test.js.map +1 -1
  177. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  178. package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.js +11 -5
  179. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  180. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  181. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  182. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  183. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  184. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  185. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  186. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  187. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  188. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  189. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  190. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  191. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  192. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  193. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  194. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  195. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  196. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  197. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  198. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  199. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  200. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  201. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  202. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  203. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  204. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  205. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  206. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  207. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  208. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  209. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  210. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  211. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  212. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  213. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
  214. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  215. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  216. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  217. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  218. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  219. package/lib-es/__tests__/network/client.test.js +614 -10
  220. package/lib-es/__tests__/network/client.test.js.map +1 -1
  221. package/lib-es/api/index.d.ts.map +1 -1
  222. package/lib-es/api/index.js +7 -12
  223. package/lib-es/api/index.js.map +1 -1
  224. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  225. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  226. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  227. package/lib-es/bridge/getFeesForTransaction.js +1 -1
  228. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  229. package/lib-es/bridge/index.js +1 -1
  230. package/lib-es/bridge/index.js.map +1 -1
  231. package/lib-es/bridge/logic.d.ts +1 -17
  232. package/lib-es/bridge/logic.d.ts.map +1 -1
  233. package/lib-es/bridge/logic.js +6 -187
  234. package/lib-es/bridge/logic.js.map +1 -1
  235. package/lib-es/bridge/prepareTransaction.js +1 -1
  236. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  237. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  238. package/lib-es/bridge/signOperation.js +1 -1
  239. package/lib-es/bridge/signOperation.js.map +1 -1
  240. package/lib-es/config.d.ts +1 -1
  241. package/lib-es/config.d.ts.map +1 -1
  242. package/lib-es/constants.d.ts +7 -4
  243. package/lib-es/constants.d.ts.map +1 -1
  244. package/lib-es/constants.js +7 -3
  245. package/lib-es/constants.js.map +1 -1
  246. package/lib-es/logic/buildTransaction.d.ts +9 -0
  247. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  248. package/lib-es/logic/buildTransaction.js +43 -0
  249. package/lib-es/logic/buildTransaction.js.map +1 -0
  250. package/lib-es/logic/calculateAmount.d.ts +3 -0
  251. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  252. package/lib-es/logic/calculateAmount.js +9 -0
  253. package/lib-es/logic/calculateAmount.js.map +1 -0
  254. package/lib-es/logic/combine.d.ts +4 -0
  255. package/lib-es/logic/combine.d.ts.map +1 -0
  256. package/lib-es/logic/combine.js +29 -0
  257. package/lib-es/logic/combine.js.map +1 -0
  258. package/lib-es/logic/craftTransaction.d.ts +5 -0
  259. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  260. package/lib-es/logic/craftTransaction.js +38 -0
  261. package/lib-es/logic/craftTransaction.js.map +1 -0
  262. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  263. package/lib-es/logic/createTransaction.js.map +1 -0
  264. package/lib-es/logic/getBalance.d.ts +5 -0
  265. package/lib-es/logic/getBalance.d.ts.map +1 -0
  266. package/lib-es/logic/getBalance.js +8 -0
  267. package/lib-es/logic/getBalance.js.map +1 -0
  268. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  269. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  270. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  271. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  272. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  273. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  274. package/lib-es/logic/getFunctionAddress.js +8 -0
  275. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  276. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  277. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  278. package/lib-es/logic/getResourceAddress.js +13 -0
  279. package/lib-es/logic/getResourceAddress.js.map +1 -0
  280. package/lib-es/logic/isTestnet.d.ts +2 -0
  281. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  282. package/lib-es/logic/isTestnet.js +5 -0
  283. package/lib-es/logic/isTestnet.js.map +1 -0
  284. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  285. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  286. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  287. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  288. package/lib-es/logic/normalizeAddress.d.ts +2 -0
  289. package/lib-es/logic/normalizeAddress.d.ts.map +1 -0
  290. package/lib-es/logic/normalizeAddress.js +8 -0
  291. package/lib-es/logic/normalizeAddress.js.map +1 -0
  292. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  293. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  294. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  295. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  296. package/lib-es/logic/processRecipients.d.ts +6 -0
  297. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  298. package/lib-es/logic/processRecipients.js +54 -0
  299. package/lib-es/logic/processRecipients.js.map +1 -0
  300. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  301. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  302. package/lib-es/logic/transactionsToOperations.js +81 -0
  303. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  304. package/lib-es/network/client.d.ts +6 -4
  305. package/lib-es/network/client.d.ts.map +1 -1
  306. package/lib-es/network/client.js +50 -14
  307. package/lib-es/network/client.js.map +1 -1
  308. package/lib-es/network/index.d.ts.map +1 -1
  309. package/lib-es/network/index.js +5 -8
  310. package/lib-es/network/index.js.map +1 -1
  311. package/lib-es/types/assets.d.ts +5 -1
  312. package/lib-es/types/assets.d.ts.map +1 -1
  313. package/lib-es/types/index.d.ts +4 -0
  314. package/lib-es/types/index.d.ts.map +1 -1
  315. package/package.json +13 -13
  316. package/src/__tests__/api/craftTransaction.unit.test.ts +243 -0
  317. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  318. package/src/__tests__/api/index.integ.test.ts +355 -12
  319. package/src/__tests__/api/index.test.ts +1 -1
  320. package/src/__tests__/bridge/logic.test.ts +9 -654
  321. package/src/__tests__/bridge/signOperation.test.ts +7 -11
  322. package/src/__tests__/index.test.ts +1 -1
  323. package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +14 -7
  324. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  325. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  326. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  327. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +1 -1
  328. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  329. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  330. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  331. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  332. package/src/__tests__/logic/normalizeAddress.unit.test.ts +15 -0
  333. package/src/__tests__/logic/processRecipients.unit.test.ts +95 -0
  334. package/src/__tests__/network/client.test.ts +650 -11
  335. package/src/api/index.ts +10 -13
  336. package/src/bridge/estimateMaxSpendable.ts +1 -1
  337. package/src/bridge/getFeesForTransaction.ts +1 -1
  338. package/src/bridge/index.ts +1 -1
  339. package/src/bridge/logic.ts +8 -279
  340. package/src/bridge/prepareTransaction.ts +1 -1
  341. package/src/bridge/signOperation.ts +1 -1
  342. package/src/config.ts +1 -1
  343. package/src/constants.ts +8 -4
  344. package/src/logic/buildTransaction.ts +70 -0
  345. package/src/logic/calculateAmount.ts +15 -0
  346. package/src/logic/combine.ts +51 -0
  347. package/src/logic/craftTransaction.ts +65 -0
  348. package/src/logic/getBalance.ts +15 -0
  349. package/src/logic/getCoinAndAmounts.ts +141 -0
  350. package/src/logic/getFunctionAddress.ts +9 -0
  351. package/src/logic/getResourceAddress.ts +24 -0
  352. package/src/logic/isTestnet.ts +5 -0
  353. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  354. package/src/logic/normalizeAddress.ts +8 -0
  355. package/src/logic/normalizeTransactionOptions.ts +18 -0
  356. package/src/logic/processRecipients.ts +88 -0
  357. package/src/logic/transactionsToOperations.ts +106 -0
  358. package/src/network/client.ts +88 -29
  359. package/src/network/index.ts +4 -13
  360. package/src/types/assets.ts +6 -1
  361. package/src/types/index.ts +5 -0
  362. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  363. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  364. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  365. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  366. package/lib/bridge/buildTransaction.d.ts +0 -7
  367. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  368. package/lib/bridge/buildTransaction.js +0 -45
  369. package/lib/bridge/buildTransaction.js.map +0 -1
  370. package/lib/bridge/createTransaction.d.ts.map +0 -1
  371. package/lib/bridge/createTransaction.js.map +0 -1
  372. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  373. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  374. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  375. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  376. package/lib-es/bridge/buildTransaction.d.ts +0 -7
  377. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  378. package/lib-es/bridge/buildTransaction.js +0 -43
  379. package/lib-es/bridge/buildTransaction.js.map +0 -1
  380. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  381. package/lib-es/bridge/createTransaction.js.map +0 -1
  382. package/src/bridge/buildTransaction.ts +0 -62
  383. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  384. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  385. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  386. /package/lib/{bridge → logic}/createTransaction.js +0 -0
  387. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  388. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  389. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  390. /package/lib-es/{bridge → logic}/createTransaction.js +0 -0
  391. /package/src/{bridge → logic}/createTransaction.ts +0 -0
@@ -0,0 +1,141 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { APTOS_ASSET_ID, APTOS_FUNGIBLE_STORE, APTOS_OBJECT_CORE } from "../constants";
3
+ import {
4
+ AptosFungibleoObjectCoreResourceData,
5
+ AptosFungibleStoreResourceData,
6
+ AptosMoveResource,
7
+ AptosTransaction,
8
+ } from "../types";
9
+ import { MoveResource, WriteSetChangeWriteResource, Event } from "@aptos-labs/ts-sdk";
10
+ import { getResourceAddress } from "./getResourceAddress";
11
+ import { isWriteSetChangeWriteResource } from "./isWriteSetChangeWriteResource";
12
+
13
+ const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
14
+
15
+ export function compareAddress(addressA: string, addressB: string) {
16
+ return (
17
+ addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
18
+ addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
19
+ );
20
+ }
21
+
22
+ export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
23
+ for (const change of tx.changes) {
24
+ if (isWriteSetChangeWriteResource(change)) {
25
+ const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
26
+ if (
27
+ change.address == event.data.store &&
28
+ storeData.type == APTOS_OBJECT_CORE &&
29
+ storeData.data.owner == user_address
30
+ ) {
31
+ return true;
32
+ }
33
+ }
34
+ }
35
+ return false;
36
+ }
37
+
38
+ /**
39
+ * Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
40
+ * @param {string} str - The input string containing the address.
41
+ * @returns {string | null} - The extracted address or null if not found.
42
+ */
43
+ function extractAddress(str: string): string | null {
44
+ const match = /<([^<>]+)>$/.exec(str);
45
+ return match ? match[1] : null;
46
+ }
47
+
48
+ export function getEventCoinAddress(
49
+ change: WriteSetChangeWriteResource,
50
+ event: Event,
51
+ event_name: string,
52
+ ): string | null {
53
+ const change_data = change.data;
54
+
55
+ const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
56
+
57
+ if (!(event_name in mr.data)) {
58
+ return null;
59
+ }
60
+
61
+ const change_event_data = mr.data[event_name];
62
+ if (
63
+ change_event_data.guid.id.addr !== event.guid.account_address ||
64
+ change_event_data.guid.id.creation_num !== event.guid.creation_number
65
+ ) {
66
+ return null;
67
+ }
68
+
69
+ const address = extractAddress(mr.type);
70
+
71
+ return address;
72
+ }
73
+
74
+ export function getEventFAAddress(
75
+ change: WriteSetChangeWriteResource,
76
+ event: Event,
77
+ _event_name: string,
78
+ ): string | null {
79
+ const change_data = change.data;
80
+
81
+ if (change_data.type !== APTOS_FUNGIBLE_STORE) {
82
+ return null;
83
+ }
84
+
85
+ const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
86
+
87
+ if (change.address !== event.data.store) {
88
+ return null;
89
+ }
90
+
91
+ return mr.data.metadata.inner;
92
+ }
93
+
94
+ export function getCoinAndAmounts(
95
+ tx: AptosTransaction,
96
+ address: string,
97
+ ): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
98
+ let coin_id: string | null = null;
99
+ let amount_in = BigNumber(0);
100
+ let amount_out = BigNumber(0);
101
+
102
+ // collect all events related to the address and calculate the overall amounts
103
+ tx.events.forEach(event => {
104
+ switch (event.type) {
105
+ case "0x1::coin::WithdrawEvent":
106
+ if (compareAddress(event.guid.account_address, address)) {
107
+ coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
108
+ amount_out = amount_out.plus(event.data.amount);
109
+ }
110
+ break;
111
+ case "0x1::coin::DepositEvent":
112
+ if (compareAddress(event.guid.account_address, address)) {
113
+ coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
114
+ amount_in = amount_in.plus(event.data.amount);
115
+ }
116
+ break;
117
+ case "0x1::fungible_asset::Withdraw":
118
+ if (checkFAOwner(tx, event, address)) {
119
+ coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
120
+ amount_out = amount_out.plus(event.data.amount);
121
+ }
122
+ break;
123
+ case "0x1::fungible_asset::Deposit":
124
+ if (checkFAOwner(tx, event, address)) {
125
+ coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
126
+ amount_in = amount_in.plus(event.data.amount);
127
+ }
128
+ break;
129
+ case "0x1::transaction_fee::FeeStatement":
130
+ if (tx.sender === address) {
131
+ coin_id ??= APTOS_ASSET_ID;
132
+ if (coin_id === APTOS_ASSET_ID) {
133
+ const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
134
+ amount_out = amount_out.plus(fees);
135
+ }
136
+ }
137
+ break;
138
+ }
139
+ });
140
+ return { coin_id, amount_in, amount_out };
141
+ }
@@ -0,0 +1,9 @@
1
+ import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
2
+
3
+ export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
4
+ if (payload.function) {
5
+ const parts = payload.function.split("::");
6
+ return parts.length === 3 && parts[0].length ? parts[0] : undefined;
7
+ }
8
+ return undefined;
9
+ }
@@ -0,0 +1,24 @@
1
+ import { WriteSetChangeWriteResource, Event } from "@aptos-labs/ts-sdk";
2
+ import { AptosTransaction } from "../types";
3
+ import { isWriteSetChangeWriteResource } from "./isWriteSetChangeWriteResource";
4
+
5
+ export function getResourceAddress(
6
+ tx: AptosTransaction,
7
+ event: Event,
8
+ event_name: string,
9
+ getAddressProcessor: (
10
+ change: WriteSetChangeWriteResource,
11
+ event: Event,
12
+ event_name: string,
13
+ ) => string | null,
14
+ ): string | null {
15
+ for (const change of tx.changes) {
16
+ if (isWriteSetChangeWriteResource(change)) {
17
+ const address = getAddressProcessor(change, event, event_name);
18
+ if (address !== null) {
19
+ return address;
20
+ }
21
+ }
22
+ }
23
+ return null;
24
+ }
@@ -0,0 +1,5 @@
1
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
2
+
3
+ export function isTestnet(currencyId: string): boolean {
4
+ return !!getCryptoCurrencyById(currencyId).isTestnetFor;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { WriteSetChange, WriteSetChangeWriteResource } from "@aptos-labs/ts-sdk";
2
+
3
+ export function isWriteSetChangeWriteResource(
4
+ change: WriteSetChange,
5
+ ): change is WriteSetChangeWriteResource {
6
+ return (change as WriteSetChangeWriteResource).data !== undefined;
7
+ }
@@ -0,0 +1,8 @@
1
+ export const normalizeAddress = (address: string): string => {
2
+ const rawAddresss = address.slice(2);
3
+ if (rawAddresss.length === 64) {
4
+ return address;
5
+ }
6
+
7
+ return "0x" + rawAddresss.padStart(64, "0");
8
+ };
@@ -0,0 +1,18 @@
1
+ import type { TransactionOptions } from "../types";
2
+
3
+ export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
4
+ // FIXME: this is wrong. TransactionOptions is
5
+ // {
6
+ // maxGasAmount: string;
7
+ // gasUnitPrice: string;
8
+ // sequenceNumber?: string;
9
+ // expirationTimestampSecs?: string;
10
+ // }
11
+ // meaning we can't return undefined in check method.
12
+ // This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
13
+ const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
14
+ return {
15
+ maxGasAmount: check(options.maxGasAmount),
16
+ gasUnitPrice: check(options.gasUnitPrice),
17
+ };
18
+ }
@@ -0,0 +1,88 @@
1
+ import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
2
+ import { Operation } from "@ledgerhq/types-live";
3
+ import { Operation as APIOperation } from "@ledgerhq/coin-framework/api/types";
4
+ import { AptosAsset } from "../types/assets";
5
+ import {
6
+ BATCH_TRANSFER_TYPES,
7
+ COIN_TRANSFER_TYPES,
8
+ DELEGATION_POOL_TYPES,
9
+ FA_TRANSFER_TYPES,
10
+ } from "../constants";
11
+ import { compareAddress } from "./getCoinAndAmounts";
12
+ import { normalizeAddress } from "./normalizeAddress";
13
+
14
+ const transferLikeFunctions = (payload: InputEntryFunctionData) =>
15
+ COIN_TRANSFER_TYPES.includes(payload.function) ||
16
+ DELEGATION_POOL_TYPES.includes(payload.function);
17
+
18
+ const addLikeFunctionsToRecipients = (
19
+ op: Operation | APIOperation<AptosAsset>,
20
+ payload: InputEntryFunctionData,
21
+ ) => {
22
+ if (
23
+ payload.functionArguments &&
24
+ payload.functionArguments.length > 0 &&
25
+ typeof payload.functionArguments[0] === "string"
26
+ ) {
27
+ op.recipients.push(normalizeAddress(payload.functionArguments[0]));
28
+ }
29
+ };
30
+
31
+ const addFungibleToRecipients = (
32
+ op: Operation | APIOperation<AptosAsset>,
33
+ payload: InputEntryFunctionData,
34
+ ) => {
35
+ if (
36
+ payload.functionArguments &&
37
+ payload.functionArguments.length > 1 &&
38
+ typeof payload.functionArguments[0] === "object" &&
39
+ typeof payload.functionArguments[1] === "string"
40
+ ) {
41
+ op.recipients.push(normalizeAddress(payload.functionArguments[1].toString()));
42
+ }
43
+ };
44
+
45
+ const addBatchedFunctions = (
46
+ op: Operation | APIOperation<AptosAsset>,
47
+ payload: InputEntryFunctionData,
48
+ address: string,
49
+ ) => {
50
+ if (
51
+ !(
52
+ payload.functionArguments &&
53
+ payload.functionArguments.length > 0 &&
54
+ Array.isArray(payload.functionArguments[0])
55
+ )
56
+ ) {
57
+ return;
58
+ }
59
+ for (const recipient of payload.functionArguments[0]) {
60
+ if (recipient && compareAddress(recipient.toString(), address)) {
61
+ op.recipients.push(normalizeAddress(recipient.toString()));
62
+ }
63
+ }
64
+ };
65
+
66
+ export function processRecipients(
67
+ payload: InputEntryFunctionData,
68
+ address: string,
69
+ op: Operation | APIOperation<AptosAsset>,
70
+ function_address: string,
71
+ ): void {
72
+ // get recipients by 3 groups
73
+ if (transferLikeFunctions(payload)) {
74
+ // 1. Transfer like functions (includes some delegation pool functions)
75
+ addLikeFunctionsToRecipients(op, payload);
76
+ } else if (FA_TRANSFER_TYPES.includes(payload.function)) {
77
+ // 1. Transfer like functions (includes some delegation pool functions)
78
+ addFungibleToRecipients(op, payload);
79
+ } else if (BATCH_TRANSFER_TYPES.includes(payload.function)) {
80
+ // 2. Batch function, to validate we are in the recipients list
81
+ if (!compareAddress(op.senders[0], address)) {
82
+ addBatchedFunctions(op, payload, address);
83
+ }
84
+ } else {
85
+ // 3. other smart contracts, in this case smart contract will be treated as a recipient
86
+ op.recipients.push(function_address);
87
+ }
88
+ }
@@ -0,0 +1,106 @@
1
+ import { AptosTransaction } from "../types";
2
+ import { Operation } from "@ledgerhq/coin-framework/api/types";
3
+ import { AptosAsset } from "../types/assets";
4
+ import BigNumber from "bignumber.js";
5
+ import { EntryFunctionPayloadResponse, InputEntryFunctionData } from "@aptos-labs/ts-sdk";
6
+ import { APTOS_ASSET_ID, DIRECTION } from "../constants";
7
+ import { compareAddress, getCoinAndAmounts } from "./getCoinAndAmounts";
8
+ import { calculateAmount } from "./calculateAmount";
9
+ import { processRecipients } from "./processRecipients";
10
+ import { getFunctionAddress } from "./getFunctionAddress";
11
+ import { normalizeAddress } from "./normalizeAddress";
12
+
13
+ export const convertFunctionPayloadResponseToInputEntryFunctionData = (
14
+ payload: EntryFunctionPayloadResponse,
15
+ ): InputEntryFunctionData => ({
16
+ function: payload.function,
17
+ typeArguments: payload.type_arguments,
18
+ functionArguments: payload.arguments,
19
+ });
20
+
21
+ const detectType = (address: string, tx: AptosTransaction, value: BigNumber): DIRECTION => {
22
+ let type = compareAddress(tx.sender, address) ? DIRECTION.OUT : DIRECTION.IN;
23
+
24
+ if (!value) {
25
+ // skip transaction that result no Aptos change
26
+ type = DIRECTION.UNKNOWN;
27
+ }
28
+
29
+ return type;
30
+ };
31
+
32
+ const getTokenStandard = (coin_id: string): string => {
33
+ const parts = coin_id.split("::");
34
+ if (parts.length === 3) {
35
+ return "coin";
36
+ }
37
+ return "fungible_asset";
38
+ };
39
+
40
+ export function transactionsToOperations(
41
+ address: string,
42
+ txs: (AptosTransaction | null)[],
43
+ ): Operation<AptosAsset>[] {
44
+ const operations: Operation<AptosAsset>[] = [];
45
+
46
+ return txs.reduce((acc, tx) => {
47
+ if (tx === null) {
48
+ return acc;
49
+ }
50
+
51
+ const payload = convertFunctionPayloadResponseToInputEntryFunctionData(
52
+ tx.payload as EntryFunctionPayloadResponse,
53
+ );
54
+
55
+ const function_address = getFunctionAddress(payload);
56
+
57
+ if (!function_address) {
58
+ return acc; // skip transaction without functions in payload
59
+ }
60
+
61
+ const { coin_id, amount_in, amount_out } = getCoinAndAmounts(tx, address);
62
+ const value = calculateAmount(tx.sender, address, amount_in, amount_out);
63
+ const type = detectType(address, tx, value);
64
+
65
+ const op: Operation<AptosAsset> = {
66
+ id: tx.hash,
67
+ type,
68
+ senders: [],
69
+ recipients: [],
70
+ value: BigInt(0),
71
+ asset: { type: "native" },
72
+ details: {
73
+ hasFailed: !tx.success,
74
+ },
75
+ tx: {
76
+ hash: tx.hash,
77
+ block: { height: 0 },
78
+ fees: BigInt(0),
79
+ date: new Date(parseInt(tx.timestamp) / 1000),
80
+ },
81
+ };
82
+
83
+ const fees = new BigNumber(tx.gas_used).multipliedBy(new BigNumber(tx.gas_unit_price));
84
+ op.tx.fees = BigInt(fees.toString());
85
+
86
+ op.value = BigInt(value.isNaN() ? 0 : value.toString());
87
+ op.senders.push(normalizeAddress(tx.sender));
88
+
89
+ processRecipients(payload, address, op, function_address);
90
+
91
+ if (op.type !== DIRECTION.UNKNOWN && coin_id !== null) {
92
+ if (coin_id === APTOS_ASSET_ID) {
93
+ acc.push(op);
94
+ return acc;
95
+ } else {
96
+ op.asset = {
97
+ type: "token",
98
+ standard: getTokenStandard(coin_id),
99
+ contractAddress: coin_id,
100
+ };
101
+ acc.push(op);
102
+ }
103
+ }
104
+ return acc;
105
+ }, operations);
106
+ }
@@ -1,41 +1,54 @@
1
1
  import { ApolloClient, InMemoryCache } from "@apollo/client";
2
2
 
3
3
  import {
4
- AccountData,
4
+ type AccountData,
5
5
  Aptos,
6
- AptosApiType,
7
6
  AptosConfig,
8
7
  Ed25519PublicKey,
9
- GasEstimation,
10
- InputEntryFunctionData,
11
- InputGenerateTransactionOptions,
8
+ type GasEstimation,
9
+ type InputEntryFunctionData,
10
+ type InputGenerateTransactionOptions,
12
11
  MimeType,
13
- post,
14
- RawTransaction,
15
- SimpleTransaction,
16
- TransactionResponse,
17
- UserTransactionResponse,
18
- PostRequestOptions,
19
- Block,
20
- AptosSettings,
21
- MoveFunctionId,
12
+ type RawTransaction,
13
+ type SimpleTransaction,
14
+ type TransactionResponse,
15
+ type UserTransactionResponse,
16
+ type Block,
17
+ type AptosSettings,
18
+ Hex,
19
+ postAptosFullNode,
20
+ type PendingTransactionResponse,
22
21
  } from "@aptos-labs/ts-sdk";
23
22
  import { getEnv } from "@ledgerhq/live-env";
24
23
  import network from "@ledgerhq/live-network";
25
24
  import BigNumber from "bignumber.js";
26
25
  import isUndefined from "lodash/isUndefined";
27
- import { APTOS_ASSET_ID, DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
28
- import { isTestnet } from "../bridge/logic";
29
- import type { AptosTransaction, TransactionOptions } from "../types";
30
- import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
31
26
  import {
27
+ APTOS_ASSET_ID,
28
+ DEFAULT_GAS,
29
+ DEFAULT_GAS_PRICE,
30
+ ESTIMATE_GAS_MUL,
31
+ TOKEN_TYPE,
32
+ } from "../constants";
33
+ import type { AptosBalance, AptosTransaction, TransactionOptions } from "../types";
34
+ import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
35
+ import type {
32
36
  GetAccountTransactionsDataQuery,
33
37
  GetAccountTransactionsDataGtQueryVariables,
34
38
  } from "./graphql/types";
35
39
  import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
36
- import { BlockInfo, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
40
+ import {
41
+ BlockInfo,
42
+ FeeEstimation,
43
+ Operation,
44
+ Pagination,
45
+ TransactionIntent,
46
+ } from "@ledgerhq/coin-framework/api/types";
37
47
  import { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
38
48
  import { log } from "@ledgerhq/logs";
49
+ import { transactionsToOperations } from "../logic/transactionsToOperations";
50
+ import { isTestnet } from "../logic/isTestnet";
51
+ import { normalizeAddress } from "../logic/normalizeAddress";
39
52
 
40
53
  const getApiEndpoint = (currencyId: string) =>
41
54
  isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
@@ -140,25 +153,26 @@ export class AptosAPI {
140
153
  });
141
154
  }
142
155
 
143
- async broadcast(signature: string): Promise<string> {
144
- const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
145
- const pendingTx = await post<PostRequestOptions, TransactionResponse>({
146
- contentType: MimeType.BCS_SIGNED_TRANSACTION,
156
+ async broadcast(tx: string): Promise<string> {
157
+ const txBytes = Hex.fromHexString(tx).toUint8Array();
158
+
159
+ const pendingTx = await postAptosFullNode<Uint8Array, PendingTransactionResponse>({
147
160
  aptosConfig: this.aptosClient.config,
148
161
  body: txBytes,
149
162
  path: "transactions",
150
- type: AptosApiType.FULLNODE,
151
163
  originMethod: "",
164
+ contentType: MimeType.BCS_SIGNED_TRANSACTION,
152
165
  });
166
+
153
167
  return pendingTx.data.hash;
154
168
  }
155
169
 
156
170
  async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
157
171
  if (token.tokenType === "coin") {
158
172
  return await this.getCoinBalance(address, token.contractAddress);
159
- } else {
160
- return await this.getFABalance(address, token.contractAddress);
161
173
  }
174
+
175
+ return await this.getFABalance(address, token.contractAddress);
162
176
  }
163
177
 
164
178
  async getLastBlock(): Promise<BlockInfo> {
@@ -167,7 +181,7 @@ export class AptosAPI {
167
181
  return {
168
182
  height: Number(block.block_height),
169
183
  hash: block.block_hash,
170
- time: new Date(Number(block.block_timestamp)),
184
+ time: new Date(Number(block.block_timestamp) / 1_000),
171
185
  };
172
186
  }
173
187
 
@@ -213,14 +227,30 @@ export class AptosAPI {
213
227
  transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
214
228
  ): Promise<FeeEstimation<AptosFeeParameters>> {
215
229
  const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
216
- const fn: MoveFunctionId = "0x1::aptos_account::transfer_coins";
217
230
 
218
231
  const txPayload: InputEntryFunctionData = {
219
- function: fn,
232
+ function: "0x1::aptos_account::transfer_coins",
220
233
  typeArguments: [APTOS_ASSET_ID],
221
234
  functionArguments: [transactionIntent.recipient, transactionIntent.amount],
222
235
  };
223
236
 
237
+ if (transactionIntent.asset.type === "token") {
238
+ const { standard } = transactionIntent.asset;
239
+
240
+ if (standard === TOKEN_TYPE.FUNGIBLE_ASSET) {
241
+ txPayload.function = "0x1::primary_fungible_store::transfer";
242
+ txPayload.typeArguments = ["0x1::fungible_asset::Metadata"];
243
+ txPayload.functionArguments = [
244
+ transactionIntent.asset.contractAddress,
245
+ transactionIntent.recipient,
246
+ transactionIntent.amount,
247
+ ];
248
+ } else if (standard === TOKEN_TYPE.COIN) {
249
+ txPayload.function = "0x1::aptos_account::transfer_coins";
250
+ txPayload.typeArguments = [transactionIntent.asset.contractAddress];
251
+ }
252
+ }
253
+
224
254
  const txOptions: TransactionOptions = {
225
255
  maxGasAmount: DEFAULT_GAS.toString(),
226
256
  gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
@@ -249,6 +279,17 @@ export class AptosAPI {
249
279
  };
250
280
  }
251
281
 
282
+ async listOperations(
283
+ rawAddress: string,
284
+ pagination: Pagination,
285
+ ): Promise<[Operation<AptosAsset>[], string]> {
286
+ const address = normalizeAddress(rawAddress);
287
+ const transactions = await this.getAccountInfo(address, pagination.minHeight.toString());
288
+ const newOperations = transactionsToOperations(address, transactions.transactions);
289
+
290
+ return [newOperations, ""];
291
+ }
292
+
252
293
  private async fetchTransactions(address: string, gt?: string) {
253
294
  if (!address) {
254
295
  return [];
@@ -312,4 +353,22 @@ export class AptosAPI {
312
353
  hash: block.block_hash,
313
354
  };
314
355
  }
356
+
357
+ async getBalances(address: string): Promise<AptosBalance[]> {
358
+ const response = await this.aptosClient.getCurrentFungibleAssetBalances({
359
+ options: {
360
+ offset: 0,
361
+ limit: 1000,
362
+ where: {
363
+ asset_type: { _eq: APTOS_ASSET_ID }, // to return all asset balances (native / token) we should remove this filter
364
+ owner_address: { _eq: address },
365
+ },
366
+ },
367
+ });
368
+
369
+ return response.map(x => ({
370
+ contractAddress: x.asset_type ?? "-",
371
+ amount: BigNumber(x.amount),
372
+ }));
373
+ }
315
374
  }
@@ -1,11 +1,8 @@
1
1
  import {
2
2
  AccountAddress,
3
- AccountAuthenticatorEd25519,
4
3
  Ed25519PublicKey,
5
4
  Ed25519Signature,
6
- generateSignedTransaction,
7
5
  generateSigningMessageForTransaction,
8
- Hex,
9
6
  RawTransaction,
10
7
  SimpleTransaction,
11
8
  } from "@aptos-labs/ts-sdk";
@@ -13,6 +10,7 @@ import { SignerContext } from "@ledgerhq/coin-framework/signer";
13
10
  import { Account } from "@ledgerhq/types-live";
14
11
  import { AptosSigner } from "../types";
15
12
  import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
13
+ import { combineSignedTransaction } from "../logic/combine";
16
14
  export * from "./client";
17
15
 
18
16
  export async function signTransaction(
@@ -41,15 +39,8 @@ export async function signTransaction(
41
39
  async signer => await signer.signTransaction(derivationPath, Buffer.from(signingMessage)),
42
40
  );
43
41
 
44
- const sigHexStr = Hex.fromHexString(response.signature.toString("hex"));
45
- const signature = new Ed25519Signature(sigHexStr.toUint8Array());
46
- const authenticator = new AccountAuthenticatorEd25519(
47
- new Ed25519PublicKey(publicKey.toString("hex")),
48
- signature,
49
- );
42
+ const signature = new Ed25519Signature(response.signature.toString("hex"));
43
+ const pubkey = new Ed25519PublicKey(publicKey.toString("hex"));
50
44
 
51
- return generateSignedTransaction({
52
- transaction: { rawTransaction: rawTxn } as SimpleTransaction,
53
- senderAuthenticator: authenticator,
54
- });
45
+ return combineSignedTransaction(rawTxn, signature, pubkey);
55
46
  }
@@ -1,6 +1,11 @@
1
1
  import type { Asset } from "@ledgerhq/coin-framework/api/types";
2
2
 
3
- export type AptosAsset = Asset;
3
+ export type AptosAsset = Asset<AptosTokenInformation>;
4
+
5
+ export type AptosTokenInformation = {
6
+ standard: string;
7
+ contractAddress: string;
8
+ };
4
9
 
5
10
  export type AptosExtra = Record<string, unknown>;
6
11
 
@@ -86,3 +86,8 @@ export type AptosMoveResourceData = {
86
86
  export type AptosMoveResource = {
87
87
  [key: string]: AptosMoveResourceData;
88
88
  };
89
+
90
+ export type AptosBalance = {
91
+ contractAddress: string;
92
+ amount: BigNumber;
93
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildTransaction.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/bridge/buildTransaction.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildTransaction.test.js","sourceRoot":"","sources":["../../../src/__tests__/bridge/buildTransaction.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAKqC;AACrC,qFAA6D;AAC7D,2CAAyC;AACzC,8CAAiE;AAIjE,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;AAEhD,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,2BAA2B,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1C,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IACH,WAAW,EAAE,GAAG;IAChB,iBAAiB,EAAE,GAAG;CACvB,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE;IAC9B,OAAO;QACL,QAAQ,EAAE;YACR,OAAO;gBACL,mBAAmB;aACpB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,GAAG,EAAE;IACb,IAAI,CAAC,aAAa,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,OAAO,GAAG,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