@ledgerhq/coin-aptos 2.0.0 → 2.1.0-nightly.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 (390) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  3. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  4. package/lib/__tests__/api/craftTransaction.unit.test.js +187 -0
  5. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  6. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  7. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/getBalance.unit.test.js +41 -0
  9. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  10. package/lib/__tests__/api/index.integ.test.js +276 -9
  11. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  12. package/lib/__tests__/api/index.test.js +1 -1
  13. package/lib/__tests__/api/index.test.js.map +1 -1
  14. package/lib/__tests__/bridge/logic.test.js +8 -558
  15. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  16. package/lib/__tests__/bridge/signOperation.test.js +7 -11
  17. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  18. package/lib/__tests__/index.test.js +1 -1
  19. package/lib/__tests__/index.test.js.map +1 -1
  20. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  21. package/lib/__tests__/{bridge → logic}/buildTransaction.test.js +14 -8
  22. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  23. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  24. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  25. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  26. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  27. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  28. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  29. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  30. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  31. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  32. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  33. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  34. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  35. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  36. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  37. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  38. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  39. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  40. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  41. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  42. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  43. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  44. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  45. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  46. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  47. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  48. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  49. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  50. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  51. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  52. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  53. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  54. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  55. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  56. package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
  57. package/lib/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  58. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  59. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  60. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  61. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  62. package/lib/__tests__/network/client.test.js +613 -9
  63. package/lib/__tests__/network/client.test.js.map +1 -1
  64. package/lib/api/index.d.ts.map +1 -1
  65. package/lib/api/index.js +7 -12
  66. package/lib/api/index.js.map +1 -1
  67. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  68. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  69. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  70. package/lib/bridge/getFeesForTransaction.js +1 -1
  71. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  72. package/lib/bridge/index.js +1 -1
  73. package/lib/bridge/index.js.map +1 -1
  74. package/lib/bridge/logic.d.ts +1 -17
  75. package/lib/bridge/logic.d.ts.map +1 -1
  76. package/lib/bridge/logic.js +12 -204
  77. package/lib/bridge/logic.js.map +1 -1
  78. package/lib/bridge/prepareTransaction.js +1 -1
  79. package/lib/bridge/prepareTransaction.js.map +1 -1
  80. package/lib/bridge/signOperation.d.ts.map +1 -1
  81. package/lib/bridge/signOperation.js +1 -1
  82. package/lib/bridge/signOperation.js.map +1 -1
  83. package/lib/config.d.ts +1 -1
  84. package/lib/config.d.ts.map +1 -1
  85. package/lib/constants.d.ts +7 -4
  86. package/lib/constants.d.ts.map +1 -1
  87. package/lib/constants.js +8 -4
  88. package/lib/constants.js.map +1 -1
  89. package/lib/logic/buildTransaction.d.ts +9 -0
  90. package/lib/logic/buildTransaction.d.ts.map +1 -0
  91. package/lib/logic/buildTransaction.js +47 -0
  92. package/lib/logic/buildTransaction.js.map +1 -0
  93. package/lib/logic/calculateAmount.d.ts +3 -0
  94. package/lib/logic/calculateAmount.d.ts.map +1 -0
  95. package/lib/logic/calculateAmount.js +13 -0
  96. package/lib/logic/calculateAmount.js.map +1 -0
  97. package/lib/logic/combine.d.ts +4 -0
  98. package/lib/logic/combine.d.ts.map +1 -0
  99. package/lib/logic/combine.js +34 -0
  100. package/lib/logic/combine.js.map +1 -0
  101. package/lib/logic/craftTransaction.d.ts +5 -0
  102. package/lib/logic/craftTransaction.d.ts.map +1 -0
  103. package/lib/logic/craftTransaction.js +68 -0
  104. package/lib/logic/craftTransaction.js.map +1 -0
  105. package/lib/logic/createTransaction.d.ts.map +1 -0
  106. package/lib/logic/createTransaction.js.map +1 -0
  107. package/lib/logic/getBalance.d.ts +5 -0
  108. package/lib/logic/getBalance.d.ts.map +1 -0
  109. package/lib/logic/getBalance.js +12 -0
  110. package/lib/logic/getBalance.js.map +1 -0
  111. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  112. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  113. package/lib/logic/getCoinAndAmounts.js +112 -0
  114. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  115. package/lib/logic/getFunctionAddress.d.ts +3 -0
  116. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  117. package/lib/logic/getFunctionAddress.js +12 -0
  118. package/lib/logic/getFunctionAddress.js.map +1 -0
  119. package/lib/logic/getResourceAddress.d.ts +4 -0
  120. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  121. package/lib/logic/getResourceAddress.js +17 -0
  122. package/lib/logic/getResourceAddress.js.map +1 -0
  123. package/lib/logic/isTestnet.d.ts +2 -0
  124. package/lib/logic/isTestnet.d.ts.map +1 -0
  125. package/lib/logic/isTestnet.js +9 -0
  126. package/lib/logic/isTestnet.js.map +1 -0
  127. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  128. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  129. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  130. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  131. package/lib/logic/normalizeAddress.d.ts +2 -0
  132. package/lib/logic/normalizeAddress.d.ts.map +1 -0
  133. package/lib/logic/normalizeAddress.js +12 -0
  134. package/lib/logic/normalizeAddress.js.map +1 -0
  135. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  136. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  137. package/lib/logic/normalizeTransactionOptions.js +21 -0
  138. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  139. package/lib/logic/processRecipients.d.ts +6 -0
  140. package/lib/logic/processRecipients.d.ts.map +1 -0
  141. package/lib/logic/processRecipients.js +58 -0
  142. package/lib/logic/processRecipients.js.map +1 -0
  143. package/lib/logic/transactionsToOperations.d.ts +7 -0
  144. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  145. package/lib/logic/transactionsToOperations.js +89 -0
  146. package/lib/logic/transactionsToOperations.js.map +1 -0
  147. package/lib/network/client.d.ts +6 -4
  148. package/lib/network/client.d.ts.map +1 -1
  149. package/lib/network/client.js +50 -14
  150. package/lib/network/client.js.map +1 -1
  151. package/lib/network/index.d.ts.map +1 -1
  152. package/lib/network/index.js +4 -7
  153. package/lib/network/index.js.map +1 -1
  154. package/lib/types/assets.d.ts +5 -1
  155. package/lib/types/assets.d.ts.map +1 -1
  156. package/lib/types/index.d.ts +4 -0
  157. package/lib/types/index.d.ts.map +1 -1
  158. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  159. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  160. package/lib-es/__tests__/api/craftTransaction.unit.test.js +185 -0
  161. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  162. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  163. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  164. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  165. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  166. package/lib-es/__tests__/api/index.integ.test.js +277 -10
  167. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  168. package/lib-es/__tests__/api/index.test.js +1 -1
  169. package/lib-es/__tests__/api/index.test.js.map +1 -1
  170. package/lib-es/__tests__/bridge/logic.test.js +8 -558
  171. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  172. package/lib-es/__tests__/bridge/signOperation.test.js +7 -11
  173. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  174. package/lib-es/__tests__/index.test.js +1 -1
  175. package/lib-es/__tests__/index.test.js.map +1 -1
  176. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  177. package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.js +11 -5
  178. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  179. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  180. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  181. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  182. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  183. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  184. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  185. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  186. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  187. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  188. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  189. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  190. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  191. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  192. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  193. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  194. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  195. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  196. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  197. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  198. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  199. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  200. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  201. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  202. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  203. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  204. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  205. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  206. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  207. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  208. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  209. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  210. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  211. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  212. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
  213. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  214. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  215. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  216. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  217. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  218. package/lib-es/__tests__/network/client.test.js +614 -10
  219. package/lib-es/__tests__/network/client.test.js.map +1 -1
  220. package/lib-es/api/index.d.ts.map +1 -1
  221. package/lib-es/api/index.js +7 -12
  222. package/lib-es/api/index.js.map +1 -1
  223. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  224. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  225. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  226. package/lib-es/bridge/getFeesForTransaction.js +1 -1
  227. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  228. package/lib-es/bridge/index.js +1 -1
  229. package/lib-es/bridge/index.js.map +1 -1
  230. package/lib-es/bridge/logic.d.ts +1 -17
  231. package/lib-es/bridge/logic.d.ts.map +1 -1
  232. package/lib-es/bridge/logic.js +6 -187
  233. package/lib-es/bridge/logic.js.map +1 -1
  234. package/lib-es/bridge/prepareTransaction.js +1 -1
  235. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  236. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  237. package/lib-es/bridge/signOperation.js +1 -1
  238. package/lib-es/bridge/signOperation.js.map +1 -1
  239. package/lib-es/config.d.ts +1 -1
  240. package/lib-es/config.d.ts.map +1 -1
  241. package/lib-es/constants.d.ts +7 -4
  242. package/lib-es/constants.d.ts.map +1 -1
  243. package/lib-es/constants.js +7 -3
  244. package/lib-es/constants.js.map +1 -1
  245. package/lib-es/logic/buildTransaction.d.ts +9 -0
  246. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  247. package/lib-es/logic/buildTransaction.js +43 -0
  248. package/lib-es/logic/buildTransaction.js.map +1 -0
  249. package/lib-es/logic/calculateAmount.d.ts +3 -0
  250. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  251. package/lib-es/logic/calculateAmount.js +9 -0
  252. package/lib-es/logic/calculateAmount.js.map +1 -0
  253. package/lib-es/logic/combine.d.ts +4 -0
  254. package/lib-es/logic/combine.d.ts.map +1 -0
  255. package/lib-es/logic/combine.js +29 -0
  256. package/lib-es/logic/combine.js.map +1 -0
  257. package/lib-es/logic/craftTransaction.d.ts +5 -0
  258. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  259. package/lib-es/logic/craftTransaction.js +38 -0
  260. package/lib-es/logic/craftTransaction.js.map +1 -0
  261. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  262. package/lib-es/logic/createTransaction.js.map +1 -0
  263. package/lib-es/logic/getBalance.d.ts +5 -0
  264. package/lib-es/logic/getBalance.d.ts.map +1 -0
  265. package/lib-es/logic/getBalance.js +8 -0
  266. package/lib-es/logic/getBalance.js.map +1 -0
  267. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  268. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  269. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  270. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  271. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  272. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  273. package/lib-es/logic/getFunctionAddress.js +8 -0
  274. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  275. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  276. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  277. package/lib-es/logic/getResourceAddress.js +13 -0
  278. package/lib-es/logic/getResourceAddress.js.map +1 -0
  279. package/lib-es/logic/isTestnet.d.ts +2 -0
  280. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  281. package/lib-es/logic/isTestnet.js +5 -0
  282. package/lib-es/logic/isTestnet.js.map +1 -0
  283. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  284. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  285. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  286. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  287. package/lib-es/logic/normalizeAddress.d.ts +2 -0
  288. package/lib-es/logic/normalizeAddress.d.ts.map +1 -0
  289. package/lib-es/logic/normalizeAddress.js +8 -0
  290. package/lib-es/logic/normalizeAddress.js.map +1 -0
  291. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  292. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  293. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  294. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  295. package/lib-es/logic/processRecipients.d.ts +6 -0
  296. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  297. package/lib-es/logic/processRecipients.js +54 -0
  298. package/lib-es/logic/processRecipients.js.map +1 -0
  299. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  300. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  301. package/lib-es/logic/transactionsToOperations.js +81 -0
  302. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  303. package/lib-es/network/client.d.ts +6 -4
  304. package/lib-es/network/client.d.ts.map +1 -1
  305. package/lib-es/network/client.js +50 -14
  306. package/lib-es/network/client.js.map +1 -1
  307. package/lib-es/network/index.d.ts.map +1 -1
  308. package/lib-es/network/index.js +5 -8
  309. package/lib-es/network/index.js.map +1 -1
  310. package/lib-es/types/assets.d.ts +5 -1
  311. package/lib-es/types/assets.d.ts.map +1 -1
  312. package/lib-es/types/index.d.ts +4 -0
  313. package/lib-es/types/index.d.ts.map +1 -1
  314. package/package.json +10 -10
  315. package/src/__tests__/api/craftTransaction.unit.test.ts +243 -0
  316. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  317. package/src/__tests__/api/index.integ.test.ts +355 -12
  318. package/src/__tests__/api/index.test.ts +1 -1
  319. package/src/__tests__/bridge/logic.test.ts +9 -654
  320. package/src/__tests__/bridge/signOperation.test.ts +7 -11
  321. package/src/__tests__/index.test.ts +1 -1
  322. package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +14 -7
  323. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  324. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  325. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  326. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +1 -1
  327. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  328. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  329. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  330. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  331. package/src/__tests__/logic/normalizeAddress.unit.test.ts +15 -0
  332. package/src/__tests__/logic/processRecipients.unit.test.ts +95 -0
  333. package/src/__tests__/network/client.test.ts +650 -11
  334. package/src/api/index.ts +10 -13
  335. package/src/bridge/estimateMaxSpendable.ts +1 -1
  336. package/src/bridge/getFeesForTransaction.ts +1 -1
  337. package/src/bridge/index.ts +1 -1
  338. package/src/bridge/logic.ts +8 -279
  339. package/src/bridge/prepareTransaction.ts +1 -1
  340. package/src/bridge/signOperation.ts +1 -1
  341. package/src/config.ts +1 -1
  342. package/src/constants.ts +8 -4
  343. package/src/logic/buildTransaction.ts +70 -0
  344. package/src/logic/calculateAmount.ts +15 -0
  345. package/src/logic/combine.ts +51 -0
  346. package/src/logic/craftTransaction.ts +65 -0
  347. package/src/logic/getBalance.ts +15 -0
  348. package/src/logic/getCoinAndAmounts.ts +141 -0
  349. package/src/logic/getFunctionAddress.ts +9 -0
  350. package/src/logic/getResourceAddress.ts +24 -0
  351. package/src/logic/isTestnet.ts +5 -0
  352. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  353. package/src/logic/normalizeAddress.ts +8 -0
  354. package/src/logic/normalizeTransactionOptions.ts +18 -0
  355. package/src/logic/processRecipients.ts +88 -0
  356. package/src/logic/transactionsToOperations.ts +106 -0
  357. package/src/network/client.ts +88 -29
  358. package/src/network/index.ts +4 -13
  359. package/src/types/assets.ts +6 -1
  360. package/src/types/index.ts +5 -0
  361. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  362. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  363. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  364. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  365. package/lib/bridge/buildTransaction.d.ts +0 -7
  366. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  367. package/lib/bridge/buildTransaction.js +0 -45
  368. package/lib/bridge/buildTransaction.js.map +0 -1
  369. package/lib/bridge/createTransaction.d.ts.map +0 -1
  370. package/lib/bridge/createTransaction.js.map +0 -1
  371. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  372. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  373. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  374. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  375. package/lib-es/bridge/buildTransaction.d.ts +0 -7
  376. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  377. package/lib-es/bridge/buildTransaction.js +0 -43
  378. package/lib-es/bridge/buildTransaction.js.map +0 -1
  379. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  380. package/lib-es/bridge/createTransaction.js.map +0 -1
  381. package/src/bridge/buildTransaction.ts +0 -62
  382. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  383. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  384. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  385. /package/lib/{bridge → logic}/createTransaction.js +0 -0
  386. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  387. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  388. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  389. /package/lib-es/{bridge → logic}/createTransaction.js +0 -0
  390. /package/src/{bridge → logic}/createTransaction.ts +0 -0
package/src/api/index.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import type { Api } from "@ledgerhq/coin-framework/api/index";
2
2
  import type { AptosConfig as AptosConfigApi } from "../config";
3
- import type { Balance, Operation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
3
+ import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
4
4
  import coinConfig from "../config";
5
5
  import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
6
6
  import { AptosAPI } from "../network";
7
+ import { combine } from "../logic/combine";
8
+ import { craftTransaction } from "../logic/craftTransaction";
9
+ import { getBalance } from "../logic/getBalance";
7
10
 
8
11
  export function createApi(
9
12
  config: AptosConfigApi,
@@ -14,20 +17,14 @@ export function createApi(
14
17
 
15
18
  return {
16
19
  broadcast: (tx: string) => client.broadcast(tx),
17
- combine: (_tx, _signature, _pubkey): string => {
18
- throw new Error("Not Implemented");
19
- },
20
- craftTransaction: (_transactionIntent, _customFees): Promise<string> => {
21
- throw new Error("Not Implemented");
22
- },
20
+ combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
21
+ craftTransaction: (transactionIntent, _customFees): Promise<string> =>
22
+ craftTransaction(client, transactionIntent),
23
23
  estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
24
24
  client.estimateFees(transactionIntent),
25
- getBalance: (_address): Promise<Balance<AptosAsset>[]> => {
26
- throw new Error("Not Implemented");
27
- },
25
+ getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalance(client, address),
28
26
  lastBlock: () => client.getLastBlock(),
29
- listOperations: (_address, _pagination): Promise<[Operation<AptosAsset>[], string]> => {
30
- throw new Error("Not Implemented");
31
- },
27
+ listOperations: (address: string, pagination: Pagination) =>
28
+ client.listOperations(address, pagination),
32
29
  };
33
30
  }
@@ -4,8 +4,8 @@ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
4
  import { AptosAPI } from "../network";
5
5
  import { getEstimatedGas } from "./getFeesForTransaction";
6
6
  import { getMaxSendBalance } from "./logic";
7
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
8
7
  import type { Transaction } from "../types";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
9
9
 
10
10
  const estimateMaxSpendable = async ({
11
11
  account,
@@ -4,10 +4,10 @@ import type { Account } from "@ledgerhq/types-live";
4
4
  import BigNumber from "bignumber.js";
5
5
  import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
6
6
  import { AptosAPI } from "../network";
7
- import buildTransaction from "./buildTransaction";
8
7
  import { getTokenAccount } from "./logic";
9
8
  import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
10
9
  import type { Transaction, TransactionErrors } from "../types";
10
+ import buildTransaction from "../logic/buildTransaction";
11
11
 
12
12
  type IGetEstimatedGasReturnType = {
13
13
  fees: BigNumber;
@@ -13,10 +13,10 @@ import type { Transaction, TransactionStatus, AptosSigner } from "../types";
13
13
  import getTransactionStatus from "./getTransactionStatus";
14
14
  import estimateMaxSpendable from "./estimateMaxSpendable";
15
15
  import prepareTransaction from "./prepareTransaction";
16
- import createTransaction from "./createTransaction";
17
16
  import { getAccountShape } from "./synchronisation";
18
17
  import buildSignOperation from "./signOperation";
19
18
  import broadcast from "./broadcast";
19
+ import createTransaction from "../logic/createTransaction";
20
20
 
21
21
  function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
22
22
  const getAddress = resolver(signerContext);
@@ -1,12 +1,4 @@
1
- import {
2
- EntryFunctionPayloadResponse,
3
- Event,
4
- InputEntryFunctionData,
5
- MoveResource,
6
- WriteSetChange,
7
- WriteSetChangeWriteResource,
8
- } from "@aptos-labs/ts-sdk";
9
- import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
1
+ import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
10
2
  import type { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
11
3
  import {
12
4
  decodeTokenAccountId,
@@ -16,31 +8,14 @@ import {
16
8
  } from "@ledgerhq/coin-framework/account/index";
17
9
  import BigNumber from "bignumber.js";
18
10
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
19
- import {
20
- APTOS_ASSET_ID,
21
- APTOS_FUNGIBLE_STORE,
22
- BATCH_TRANSFER_TYPES,
23
- DELEGATION_POOL_TYPES,
24
- DIRECTION,
25
- COIN_TRANSFER_TYPES,
26
- FA_TRANSFER_TYPES,
27
- APTOS_OBJECT_CORE,
28
- } from "../constants";
29
- import type {
30
- AptosFungibleoObjectCoreResourceData,
31
- AptosFungibleStoreResourceData,
32
- AptosMoveResource,
33
- AptosTransaction,
34
- Transaction,
35
- TransactionOptions,
36
- } from "../types";
11
+ import { APTOS_ASSET_ID, DIRECTION } from "../constants";
12
+ import type { AptosTransaction, Transaction } from "../types";
37
13
  import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
38
-
39
- const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
40
-
41
- export function isTestnet(currencyId: string): boolean {
42
- return getCryptoCurrencyById(currencyId).isTestnetFor ? true : false;
43
- }
14
+ import { convertFunctionPayloadResponseToInputEntryFunctionData } from "../logic/transactionsToOperations";
15
+ import { compareAddress, getCoinAndAmounts } from "../logic/getCoinAndAmounts";
16
+ import { calculateAmount } from "../logic/calculateAmount";
17
+ import { processRecipients } from "../logic/processRecipients";
18
+ import { getFunctionAddress } from "../logic/getFunctionAddress";
44
19
 
45
20
  export const getMaxSendBalance = (
46
21
  gas: BigNumber,
@@ -60,23 +35,6 @@ export const getMaxSendBalance = (
60
35
  : new BigNumber(0);
61
36
  };
62
37
 
63
- export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
64
- // FIXME: this is wrong. TransactionOptions is
65
- // {
66
- // maxGasAmount: string;
67
- // gasUnitPrice: string;
68
- // sequenceNumber?: string;
69
- // expirationTimestampSecs?: string;
70
- // }
71
- // meaning we can't return undefined in check method.
72
- // This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
73
- const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
74
- return {
75
- maxGasAmount: check(options.maxGasAmount),
76
- gasUnitPrice: check(options.gasUnitPrice),
77
- };
78
- }
79
-
80
38
  export const getBlankOperation = (
81
39
  tx: AptosTransaction,
82
40
  id: string,
@@ -97,14 +55,6 @@ export const getBlankOperation = (
97
55
  hasFailed: false,
98
56
  });
99
57
 
100
- const convertFunctionPayloadResponseToInputEntryFunctionData = (
101
- payload: EntryFunctionPayloadResponse,
102
- ): InputEntryFunctionData => ({
103
- function: payload.function,
104
- typeArguments: payload.type_arguments,
105
- functionArguments: payload.arguments,
106
- });
107
-
108
58
  export const txsToOps = (
109
59
  info: { address: string },
110
60
  id: string,
@@ -169,227 +119,6 @@ export const txsToOps = (
169
119
  return [ops, opsTokens];
170
120
  };
171
121
 
172
- export function compareAddress(addressA: string, addressB: string) {
173
- return (
174
- addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
175
- addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
176
- );
177
- }
178
-
179
- export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
180
- if (payload.function) {
181
- const parts = payload.function.split("::");
182
- return parts.length === 3 && parts[0].length ? parts[0] : undefined;
183
- }
184
- return undefined;
185
- }
186
-
187
- export function processRecipients(
188
- payload: InputEntryFunctionData,
189
- address: string,
190
- op: Operation,
191
- function_address: string,
192
- ): void {
193
- // get recipients buy 3 groups
194
- if (
195
- (COIN_TRANSFER_TYPES.includes(payload.function) ||
196
- DELEGATION_POOL_TYPES.includes(payload.function)) &&
197
- payload.functionArguments &&
198
- payload.functionArguments.length > 0 &&
199
- typeof payload.functionArguments[0] === "string"
200
- ) {
201
- // 1. Transfer like functions (includes some delegation pool functions)
202
- op.recipients.push(payload.functionArguments[0].toString());
203
- } else if (
204
- FA_TRANSFER_TYPES.includes(payload.function) &&
205
- payload.functionArguments &&
206
- payload.functionArguments.length > 1 &&
207
- typeof payload.functionArguments[0] === "object" &&
208
- typeof payload.functionArguments[1] === "string"
209
- ) {
210
- // 1. Transfer like functions (includes some delegation pool functions)
211
- op.recipients.push(payload.functionArguments[1].toString());
212
- } else if (
213
- BATCH_TRANSFER_TYPES.includes(payload.function) &&
214
- payload.functionArguments &&
215
- payload.functionArguments.length > 0 &&
216
- Array.isArray(payload.functionArguments[0])
217
- ) {
218
- // 2. Batch function, to validate we are in the recipients list
219
- if (!compareAddress(op.senders[0], address)) {
220
- for (const recipient of payload.functionArguments[0]) {
221
- if (recipient && compareAddress(recipient.toString(), address)) {
222
- op.recipients.push(recipient.toString());
223
- }
224
- }
225
- }
226
- } else {
227
- // 3. other smart contracts, in this case smart contract will be treated as a recipient
228
- op.recipients.push(function_address);
229
- }
230
- }
231
-
232
- export function getEventCoinAddress(
233
- change: WriteSetChangeWriteResource,
234
- event: Event,
235
- event_name: string,
236
- ): string | null {
237
- const change_data = change.data;
238
-
239
- const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
240
-
241
- if (!(event_name in mr.data)) {
242
- return null;
243
- }
244
-
245
- const change_event_data = mr.data[event_name];
246
- if (
247
- change_event_data.guid.id.addr !== event.guid.account_address ||
248
- change_event_data.guid.id.creation_num !== event.guid.creation_number
249
- ) {
250
- return null;
251
- }
252
-
253
- const address = extractAddress(mr.type);
254
-
255
- return address;
256
- }
257
-
258
- export function getEventFAAddress(
259
- change: WriteSetChangeWriteResource,
260
- event: Event,
261
- _event_name: string,
262
- ): string | null {
263
- const change_data = change.data;
264
-
265
- if (change_data.type !== APTOS_FUNGIBLE_STORE) {
266
- return null;
267
- }
268
-
269
- const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
270
-
271
- if (change.address !== event.data.store) {
272
- return null;
273
- }
274
-
275
- return mr.data.metadata.inner;
276
- }
277
-
278
- export function getResourceAddress(
279
- tx: AptosTransaction,
280
- event: Event,
281
- event_name: string,
282
- getAddressProcessor: (
283
- change: WriteSetChangeWriteResource,
284
- event: Event,
285
- event_name: string,
286
- ) => string | null,
287
- ): string | null {
288
- for (const change of tx.changes) {
289
- if (isWriteSetChangeWriteResource(change)) {
290
- const address = getAddressProcessor(change, event, event_name);
291
- if (address !== null) {
292
- return address;
293
- }
294
- }
295
- }
296
- return null;
297
- }
298
-
299
- function isWriteSetChangeWriteResource(
300
- change: WriteSetChange,
301
- ): change is WriteSetChangeWriteResource {
302
- return (change as WriteSetChangeWriteResource).data !== undefined;
303
- }
304
-
305
- export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
306
- for (const change of tx.changes) {
307
- if (isWriteSetChangeWriteResource(change)) {
308
- const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
309
- if (
310
- change.address == event.data.store &&
311
- storeData.type == APTOS_OBJECT_CORE &&
312
- storeData.data.owner == user_address
313
- ) {
314
- return true;
315
- }
316
- }
317
- }
318
- return false;
319
- }
320
-
321
- export function getCoinAndAmounts(
322
- tx: AptosTransaction,
323
- address: string,
324
- ): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
325
- let coin_id: string | null = null;
326
- let amount_in = BigNumber(0);
327
- let amount_out = BigNumber(0);
328
-
329
- // collect all events related to the address and calculate the overall amounts
330
- tx.events.forEach(event => {
331
- switch (event.type) {
332
- case "0x1::coin::WithdrawEvent":
333
- if (compareAddress(event.guid.account_address, address)) {
334
- coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
335
- amount_out = amount_out.plus(event.data.amount);
336
- }
337
- break;
338
- case "0x1::coin::DepositEvent":
339
- if (compareAddress(event.guid.account_address, address)) {
340
- coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
341
- amount_in = amount_in.plus(event.data.amount);
342
- }
343
- break;
344
- case "0x1::fungible_asset::Withdraw":
345
- if (checkFAOwner(tx, event, address)) {
346
- coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
347
- amount_out = amount_out.plus(event.data.amount);
348
- }
349
- break;
350
- case "0x1::fungible_asset::Deposit":
351
- if (checkFAOwner(tx, event, address)) {
352
- coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
353
- amount_in = amount_in.plus(event.data.amount);
354
- }
355
- break;
356
- case "0x1::transaction_fee::FeeStatement":
357
- if (tx.sender === address) {
358
- if (coin_id === null) coin_id = APTOS_ASSET_ID;
359
- if (coin_id === APTOS_ASSET_ID) {
360
- const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
361
- amount_out = amount_out.plus(fees);
362
- }
363
- }
364
- break;
365
- }
366
- });
367
- return { coin_id, amount_in, amount_out }; // TODO: manage situation when there are several coinID from the events parsing
368
- }
369
-
370
- export function calculateAmount(
371
- sender: string,
372
- address: string,
373
- amount_in: BigNumber,
374
- amount_out: BigNumber,
375
- ): BigNumber {
376
- const is_sender: boolean = compareAddress(sender, address);
377
- // LL negates the amount for SEND transactions
378
- // to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
379
- // we need to make it negative
380
- return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
381
- }
382
-
383
- /**
384
- * Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
385
- * @param {string} str - The input string containing the address.
386
- * @returns {string | null} - The extracted address or null if not found.
387
- */
388
- function extractAddress(str: string): string | null {
389
- const match = str.match(/<([^<>]+)>{1}$/);
390
- return match ? match[1] : null;
391
- }
392
-
393
122
  export function getTokenAccount(
394
123
  account: Account,
395
124
  transaction: Transaction,
@@ -5,7 +5,7 @@ import { AptosAPI } from "../network";
5
5
  import { getEstimatedGas } from "./getFeesForTransaction";
6
6
  import type { Transaction } from "../types";
7
7
  import { getMaxSendBalance } from "./logic";
8
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "./../constants";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
9
9
 
10
10
  const prepareTransaction = async (
11
11
  account: Account,
@@ -1,7 +1,6 @@
1
1
  import type { AptosAccount, Transaction } from "../types";
2
2
  import { Observable } from "rxjs";
3
3
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
4
- import buildTransaction from "./buildTransaction";
5
4
  import BigNumber from "bignumber.js";
6
5
  import type { Account, AccountBridge, Operation, OperationType } from "@ledgerhq/types-live";
7
6
  import { AptosAPI } from "../network";
@@ -10,6 +9,7 @@ import { SignerContext } from "@ledgerhq/coin-framework/signer";
10
9
  import { AptosSigner } from "../types";
11
10
  import { signTransaction } from "../network";
12
11
  import { findSubAccountById } from "@ledgerhq/coin-framework/account/helpers";
12
+ import buildTransaction from "../logic/buildTransaction";
13
13
 
14
14
  export const getAddress = (a: Account) => ({
15
15
  address: a.freshAddress,
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type AptosSettings } from "@aptos-labs/ts-sdk";
1
+ import type { AptosSettings } from "@aptos-labs/ts-sdk";
2
2
  import buildCoinConfig, {
3
3
  type CoinConfig,
4
4
  type CurrencyConfig,
package/src/constants.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { MoveStructId } from "@aptos-labs/ts-sdk";
1
+ import type { MoveStructId } from "@aptos-labs/ts-sdk";
2
2
  import BigNumber from "bignumber.js";
3
3
 
4
- export const DEFAULT_GAS = new BigNumber(200);
5
- export const DEFAULT_GAS_PRICE = new BigNumber(100);
6
4
  export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
7
5
 
8
6
  export const LOAD_LIMIT = 10;
@@ -47,4 +45,10 @@ export enum DIRECTION {
47
45
  UNKNOWN = "UNKNOWN",
48
46
  }
49
47
 
50
- export const SUPPORTED_TOKEN_TYPES = ["coin", "fungible_asset"];
48
+ export enum TOKEN_TYPE {
49
+ COIN = "coin",
50
+ FUNGIBLE_ASSET = "fungible_asset",
51
+ }
52
+
53
+ export const DEFAULT_GAS = new BigNumber(200);
54
+ export const DEFAULT_GAS_PRICE = new BigNumber(100);
@@ -0,0 +1,70 @@
1
+ import type { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
2
+ import type { Account } from "@ledgerhq/types-live";
3
+ import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
4
+ import { APTOS_ASSET_ID, TOKEN_TYPE } from "../constants";
5
+ import type { AptosAPI } from "../network";
6
+ import { normalizeTransactionOptions } from "./normalizeTransactionOptions";
7
+ import type { Transaction } from "../types";
8
+ import type BigNumber from "bignumber.js";
9
+
10
+ const buildTransaction = async (
11
+ account: Account,
12
+ transaction: Transaction,
13
+ aptosClient: AptosAPI,
14
+ contractAddress?: string,
15
+ tokenType?: TOKEN_TYPE,
16
+ ): Promise<RawTransaction> => {
17
+ const subAccount = findSubAccountById(account, transaction.subAccountId ?? "");
18
+
19
+ const payloadContracAddress = subAccount ? subAccount.token.contractAddress : contractAddress;
20
+ const payloadTokenType = (subAccount?.token?.tokenType as TOKEN_TYPE) ?? tokenType;
21
+
22
+ const txPayload = getPayload({
23
+ amount: transaction.amount,
24
+ recipient: transaction.recipient,
25
+ contractAddress: payloadContracAddress,
26
+ tokenType: payloadTokenType,
27
+ });
28
+
29
+ const txOptions = normalizeTransactionOptions(transaction.options);
30
+
31
+ const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
32
+
33
+ return tx;
34
+ };
35
+
36
+ const getPayload = (args: {
37
+ amount: BigNumber;
38
+ recipient: string;
39
+ contractAddress?: string | undefined;
40
+ tokenType?: string;
41
+ }): InputEntryFunctionData => {
42
+ if (args.tokenType !== undefined && !isTokenType(args.tokenType)) {
43
+ throw new Error(`Token type ${args.tokenType} not supported`);
44
+ }
45
+
46
+ if (args.tokenType === TOKEN_TYPE.FUNGIBLE_ASSET) {
47
+ return {
48
+ function: "0x1::primary_fungible_store::transfer",
49
+ typeArguments: ["0x1::fungible_asset::Metadata"],
50
+ functionArguments: [args.contractAddress, args.recipient, args.amount.toString()],
51
+ };
52
+ }
53
+
54
+ let address = args.contractAddress ?? "";
55
+ if (address === "") {
56
+ address = APTOS_ASSET_ID;
57
+ }
58
+
59
+ return {
60
+ function: "0x1::aptos_account::transfer_coins",
61
+ typeArguments: [address],
62
+ functionArguments: [args.recipient, args.amount.toString()],
63
+ };
64
+ };
65
+
66
+ export const isTokenType = (value: string): boolean => {
67
+ return Object.values(TOKEN_TYPE).includes(value as TOKEN_TYPE);
68
+ };
69
+
70
+ export default buildTransaction;
@@ -0,0 +1,15 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { compareAddress } from "./getCoinAndAmounts";
3
+
4
+ export function calculateAmount(
5
+ sender: string,
6
+ address: string,
7
+ amount_in: BigNumber,
8
+ amount_out: BigNumber,
9
+ ): BigNumber {
10
+ const is_sender: boolean = compareAddress(sender, address);
11
+ // LL negates the amount for SEND transactions
12
+ // to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
13
+ // we need to make it negative
14
+ return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
15
+ }
@@ -0,0 +1,51 @@
1
+ import {
2
+ AccountAuthenticatorEd25519,
3
+ Deserializer,
4
+ Ed25519PublicKey,
5
+ Ed25519Signature,
6
+ Hex,
7
+ RawTransaction,
8
+ type SimpleTransaction,
9
+ generateSignedTransaction,
10
+ } from "@aptos-labs/ts-sdk";
11
+
12
+ export function combineSignedTransaction(
13
+ txRaw: RawTransaction,
14
+ signature: Ed25519Signature,
15
+ pubkey: Ed25519PublicKey,
16
+ ): Uint8Array {
17
+ const authenticator = new AccountAuthenticatorEd25519(pubkey, signature);
18
+
19
+ return generateSignedTransaction({
20
+ transaction: { rawTransaction: txRaw } as SimpleTransaction,
21
+ senderAuthenticator: authenticator,
22
+ });
23
+ }
24
+
25
+ export function combine(tx: string, signature: string, pubkey?: string) {
26
+ if (!Hex.isValid(tx).valid) {
27
+ throw new Error("tx must be a valid hex value");
28
+ }
29
+
30
+ if (!Hex.isValid(signature).valid) {
31
+ throw new Error("signature must be a valid hex value");
32
+ }
33
+
34
+ if (pubkey === undefined) {
35
+ throw new Error("account must have a public key");
36
+ }
37
+
38
+ if (!Hex.isValid(pubkey).valid) {
39
+ throw new Error("pubkey must be a valid hex value");
40
+ }
41
+
42
+ const ed25519Signature = new Ed25519Signature(signature);
43
+ const ed25519PubKey = new Ed25519PublicKey(pubkey);
44
+
45
+ const txBytes = Hex.fromHexString(tx).toUint8Array();
46
+ const txRaw = RawTransaction.deserialize(new Deserializer(txBytes));
47
+
48
+ const signedTxBytes = combineSignedTransaction(txRaw, ed25519Signature, ed25519PubKey);
49
+
50
+ return Hex.fromHexInput(signedTxBytes).toString();
51
+ }
@@ -0,0 +1,65 @@
1
+ import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
2
+ import type { AptosAsset, AptosExtra, AptosSender } from "../types/assets";
3
+ import type { Account, TokenAccount } from "@ledgerhq/types-live";
4
+ import type { AptosAPI } from "../network";
5
+ import buildTransaction, { isTokenType } from "./buildTransaction";
6
+ import createTransaction from "./createTransaction";
7
+ import BigNumber from "bignumber.js";
8
+ import { APTOS_ASSET_ID, type TOKEN_TYPE } from "../constants";
9
+ import type { AptosBalance } from "../types";
10
+
11
+ export async function craftTransaction(
12
+ aptosClient: AptosAPI,
13
+ transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
14
+ ): Promise<string> {
15
+ const newTx = createTransaction();
16
+ newTx.amount = BigNumber(transactionIntent.amount.toString());
17
+ newTx.recipient = transactionIntent.recipient;
18
+ newTx.mode = transactionIntent.type;
19
+ newTx.useAllAmount = transactionIntent.amount === BigInt(0);
20
+
21
+ const account = {
22
+ freshAddress: transactionIntent.sender.freshAddress,
23
+ xpub: transactionIntent.sender.xpub,
24
+ subAccounts: new Array<TokenAccount>(),
25
+ } as Account;
26
+
27
+ let tokenType: TOKEN_TYPE | undefined;
28
+ const contractAddress = getContractAddress(transactionIntent);
29
+ let balance: AptosBalance | undefined;
30
+
31
+ if (newTx.useAllAmount === true) {
32
+ const balances = await aptosClient.getBalances(transactionIntent.sender.freshAddress);
33
+ balance = balances?.find(
34
+ b => b.contractAddress.toLowerCase() === contractAddress?.toLowerCase(),
35
+ );
36
+
37
+ if (balance !== undefined) {
38
+ newTx.amount = BigNumber(balance.amount.toString());
39
+ }
40
+ }
41
+
42
+ if (transactionIntent.asset.type === "token") {
43
+ tokenType = transactionIntent.asset.standard as TOKEN_TYPE;
44
+ }
45
+
46
+ const aptosTx = await buildTransaction(
47
+ account,
48
+ newTx,
49
+ aptosClient,
50
+ contractAddress,
51
+ tokenType ?? undefined,
52
+ );
53
+
54
+ return aptosTx.bcsToHex().toString();
55
+ }
56
+
57
+ function getContractAddress(
58
+ txIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
59
+ ): string {
60
+ if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
61
+ return txIntent.asset.contractAddress;
62
+ }
63
+
64
+ return APTOS_ASSET_ID;
65
+ }
@@ -0,0 +1,15 @@
1
+ import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
2
+ import type { AptosAsset } from "../types/assets";
3
+ import type { AptosAPI } from "../network";
4
+
5
+ export async function getBalance(
6
+ aptosClient: AptosAPI,
7
+ address: string,
8
+ ): Promise<Balance<AptosAsset>[]> {
9
+ const balance = await aptosClient.getBalances(address);
10
+
11
+ return balance.map(x => ({
12
+ value: BigInt(x.amount.toString()),
13
+ asset: { type: "native" },
14
+ }));
15
+ }