@ledgerhq/coin-sui 0.2.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 (459) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +19 -0
  4. package/CHANGELOG.md +16 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +9 -0
  7. package/jest.integ.config.js +7 -0
  8. package/lib/api/chain/index.d.ts +16 -0
  9. package/lib/api/chain/index.d.ts.map +1 -0
  10. package/lib/api/chain/index.js +3 -0
  11. package/lib/api/chain/index.js.map +1 -0
  12. package/lib/bridge/bridge.integration.test.d.ts +4 -0
  13. package/lib/bridge/bridge.integration.test.d.ts.map +1 -0
  14. package/lib/bridge/bridge.integration.test.js +136 -0
  15. package/lib/bridge/bridge.integration.test.js.map +1 -0
  16. package/lib/bridge/broadcast.d.ts +12 -0
  17. package/lib/bridge/broadcast.d.ts.map +1 -0
  18. package/lib/bridge/broadcast.js +20 -0
  19. package/lib/bridge/broadcast.js.map +1 -0
  20. package/lib/bridge/broadcast.test.d.ts +2 -0
  21. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  22. package/lib/bridge/broadcast.test.js +48 -0
  23. package/lib/bridge/broadcast.test.js.map +1 -0
  24. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  25. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  26. package/lib/bridge/buildOptimisticOperation.js +76 -0
  27. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  28. package/lib/bridge/buildOptimisticOperation.test.d.ts +2 -0
  29. package/lib/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  30. package/lib/bridge/buildOptimisticOperation.test.js +52 -0
  31. package/lib/bridge/buildOptimisticOperation.test.js.map +1 -0
  32. package/lib/bridge/buildTransaction.d.ts +9 -0
  33. package/lib/bridge/buildTransaction.d.ts.map +1 -0
  34. package/lib/bridge/buildTransaction.js +19 -0
  35. package/lib/bridge/buildTransaction.js.map +1 -0
  36. package/lib/bridge/buildTransaction.test.d.ts +2 -0
  37. package/lib/bridge/buildTransaction.test.d.ts.map +1 -0
  38. package/lib/bridge/buildTransaction.test.js +17 -0
  39. package/lib/bridge/buildTransaction.test.js.map +1 -0
  40. package/lib/bridge/createTransaction.d.ts +10 -0
  41. package/lib/bridge/createTransaction.d.ts.map +1 -0
  42. package/lib/bridge/createTransaction.js +24 -0
  43. package/lib/bridge/createTransaction.js.map +1 -0
  44. package/lib/bridge/estimateMaxSpendable.d.ts +14 -0
  45. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  46. package/lib/bridge/estimateMaxSpendable.js +44 -0
  47. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  48. package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
  49. package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  50. package/lib/bridge/estimateMaxSpendable.test.js +25 -0
  51. package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
  52. package/lib/bridge/formatters.d.ts +10 -0
  53. package/lib/bridge/formatters.d.ts.map +1 -0
  54. package/lib/bridge/formatters.js +24 -0
  55. package/lib/bridge/formatters.js.map +1 -0
  56. package/lib/bridge/formatters.test.d.ts +2 -0
  57. package/lib/bridge/formatters.test.d.ts.map +1 -0
  58. package/lib/bridge/formatters.test.js +18 -0
  59. package/lib/bridge/formatters.test.js.map +1 -0
  60. package/lib/bridge/getFeesForTransaction.d.ts +15 -0
  61. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
  62. package/lib/bridge/getFeesForTransaction.js +32 -0
  63. package/lib/bridge/getFeesForTransaction.js.map +1 -0
  64. package/lib/bridge/getFeesForTransaction.test.d.ts +2 -0
  65. package/lib/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  66. package/lib/bridge/getFeesForTransaction.test.js +35 -0
  67. package/lib/bridge/getFeesForTransaction.test.js.map +1 -0
  68. package/lib/bridge/getTransactionStatus.d.ts +12 -0
  69. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  70. package/lib/bridge/getTransactionStatus.js +59 -0
  71. package/lib/bridge/getTransactionStatus.js.map +1 -0
  72. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  73. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  74. package/lib/bridge/getTransactionStatus.test.js +48 -0
  75. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  76. package/lib/bridge/index.d.ts +10 -0
  77. package/lib/bridge/index.d.ts.map +1 -0
  78. package/lib/bridge/index.js +63 -0
  79. package/lib/bridge/index.js.map +1 -0
  80. package/lib/bridge/preload.d.ts +11 -0
  81. package/lib/bridge/preload.d.ts.map +1 -0
  82. package/lib/bridge/preload.js +41 -0
  83. package/lib/bridge/preload.js.map +1 -0
  84. package/lib/bridge/prepareTransaction.d.ts +13 -0
  85. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  86. package/lib/bridge/prepareTransaction.js +43 -0
  87. package/lib/bridge/prepareTransaction.js.map +1 -0
  88. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  89. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  90. package/lib/bridge/prepareTransaction.test.js +45 -0
  91. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  92. package/lib/bridge/serialization.d.ts +7 -0
  93. package/lib/bridge/serialization.d.ts.map +1 -0
  94. package/lib/bridge/serialization.js +27 -0
  95. package/lib/bridge/serialization.js.map +1 -0
  96. package/lib/bridge/serialization.test.d.ts +2 -0
  97. package/lib/bridge/serialization.test.d.ts.map +1 -0
  98. package/lib/bridge/serialization.test.js +131 -0
  99. package/lib/bridge/serialization.test.js.map +1 -0
  100. package/lib/bridge/signOperation.d.ts +9 -0
  101. package/lib/bridge/signOperation.d.ts.map +1 -0
  102. package/lib/bridge/signOperation.js +72 -0
  103. package/lib/bridge/signOperation.js.map +1 -0
  104. package/lib/bridge/signOperation.test.d.ts +2 -0
  105. package/lib/bridge/signOperation.test.d.ts.map +1 -0
  106. package/lib/bridge/signOperation.test.js +76 -0
  107. package/lib/bridge/signOperation.test.js.map +1 -0
  108. package/lib/bridge/synchronisation.d.ts +21 -0
  109. package/lib/bridge/synchronisation.d.ts.map +1 -0
  110. package/lib/bridge/synchronisation.js +65 -0
  111. package/lib/bridge/synchronisation.js.map +1 -0
  112. package/lib/bridge/synchronisation.test.d.ts +2 -0
  113. package/lib/bridge/synchronisation.test.d.ts.map +1 -0
  114. package/lib/bridge/synchronisation.test.js +118 -0
  115. package/lib/bridge/synchronisation.test.js.map +1 -0
  116. package/lib/bridge/transaction.d.ts +15 -0
  117. package/lib/bridge/transaction.d.ts.map +1 -0
  118. package/lib/bridge/transaction.js +55 -0
  119. package/lib/bridge/transaction.js.map +1 -0
  120. package/lib/bridge/transaction.test.d.ts +2 -0
  121. package/lib/bridge/transaction.test.d.ts.map +1 -0
  122. package/lib/bridge/transaction.test.js +65 -0
  123. package/lib/bridge/transaction.test.js.map +1 -0
  124. package/lib/bridge/utils.d.ts +27 -0
  125. package/lib/bridge/utils.d.ts.map +1 -0
  126. package/lib/bridge/utils.js +57 -0
  127. package/lib/bridge/utils.js.map +1 -0
  128. package/lib/config.d.ts +15 -0
  129. package/lib/config.d.ts.map +1 -0
  130. package/lib/config.js +9 -0
  131. package/lib/config.js.map +1 -0
  132. package/lib/index.d.ts +3 -0
  133. package/lib/index.d.ts.map +1 -0
  134. package/lib/index.js +21 -0
  135. package/lib/index.js.map +1 -0
  136. package/lib/logic/broadcast.d.ts +9 -0
  137. package/lib/logic/broadcast.d.ts.map +1 -0
  138. package/lib/logic/broadcast.js +26 -0
  139. package/lib/logic/broadcast.js.map +1 -0
  140. package/lib/logic/craftTransaction.d.ts +17 -0
  141. package/lib/logic/craftTransaction.d.ts.map +1 -0
  142. package/lib/logic/craftTransaction.js +22 -0
  143. package/lib/logic/craftTransaction.js.map +1 -0
  144. package/lib/logic/estimateFees.d.ts +10 -0
  145. package/lib/logic/estimateFees.d.ts.map +1 -0
  146. package/lib/logic/estimateFees.js +20 -0
  147. package/lib/logic/estimateFees.js.map +1 -0
  148. package/lib/logic/index.d.ts +4 -0
  149. package/lib/logic/index.d.ts.map +1 -0
  150. package/lib/logic/index.js +10 -0
  151. package/lib/logic/index.js.map +1 -0
  152. package/lib/network/index.d.ts +18 -0
  153. package/lib/network/index.d.ts.map +1 -0
  154. package/lib/network/index.js +17 -0
  155. package/lib/network/index.js.map +1 -0
  156. package/lib/network/sdk.d.ts +61 -0
  157. package/lib/network/sdk.d.ts.map +1 -0
  158. package/lib/network/sdk.integration.test.d.ts +2 -0
  159. package/lib/network/sdk.integration.test.d.ts.map +1 -0
  160. package/lib/network/sdk.integration.test.js +70 -0
  161. package/lib/network/sdk.integration.test.js.map +1 -0
  162. package/lib/network/sdk.js +205 -0
  163. package/lib/network/sdk.js.map +1 -0
  164. package/lib/network/sdk.test.d.ts +2 -0
  165. package/lib/network/sdk.test.d.ts.map +1 -0
  166. package/lib/network/sdk.test.js +166 -0
  167. package/lib/network/sdk.test.js.map +1 -0
  168. package/lib/signer/getAddress.d.ts +6 -0
  169. package/lib/signer/getAddress.d.ts.map +1 -0
  170. package/lib/signer/getAddress.js +20 -0
  171. package/lib/signer/getAddress.js.map +1 -0
  172. package/lib/signer/getAddress.test.d.ts +2 -0
  173. package/lib/signer/getAddress.test.d.ts.map +1 -0
  174. package/lib/signer/getAddress.test.js +106 -0
  175. package/lib/signer/getAddress.test.js.map +1 -0
  176. package/lib/signer/index.d.ts +6 -0
  177. package/lib/signer/index.d.ts.map +1 -0
  178. package/lib/signer/index.js +11 -0
  179. package/lib/signer/index.js.map +1 -0
  180. package/lib/test/cli.d.ts +16 -0
  181. package/lib/test/cli.d.ts.map +1 -0
  182. package/lib/test/cli.js +16 -0
  183. package/lib/test/cli.js.map +1 -0
  184. package/lib/types/bridge.d.ts +72 -0
  185. package/lib/types/bridge.d.ts.map +1 -0
  186. package/lib/types/bridge.fixture.d.ts +30 -0
  187. package/lib/types/bridge.fixture.d.ts.map +1 -0
  188. package/lib/types/bridge.fixture.js +86 -0
  189. package/lib/types/bridge.fixture.js.map +1 -0
  190. package/lib/types/bridge.js +3 -0
  191. package/lib/types/bridge.js.map +1 -0
  192. package/lib/types/index.d.ts +4 -0
  193. package/lib/types/index.d.ts.map +1 -0
  194. package/lib/types/index.js +20 -0
  195. package/lib/types/index.js.map +1 -0
  196. package/lib/types/model.d.ts +6 -0
  197. package/lib/types/model.d.ts.map +1 -0
  198. package/lib/types/model.js +3 -0
  199. package/lib/types/model.js.map +1 -0
  200. package/lib/types/signer.d.ts +13 -0
  201. package/lib/types/signer.d.ts.map +1 -0
  202. package/lib/types/signer.js +3 -0
  203. package/lib/types/signer.js.map +1 -0
  204. package/lib/utils.d.ts +7 -0
  205. package/lib/utils.d.ts.map +1 -0
  206. package/lib/utils.js +13 -0
  207. package/lib/utils.js.map +1 -0
  208. package/lib-es/api/chain/index.d.ts +16 -0
  209. package/lib-es/api/chain/index.d.ts.map +1 -0
  210. package/lib-es/api/chain/index.js +2 -0
  211. package/lib-es/api/chain/index.js.map +1 -0
  212. package/lib-es/bridge/bridge.integration.test.d.ts +4 -0
  213. package/lib-es/bridge/bridge.integration.test.d.ts.map +1 -0
  214. package/lib-es/bridge/bridge.integration.test.js +130 -0
  215. package/lib-es/bridge/bridge.integration.test.js.map +1 -0
  216. package/lib-es/bridge/broadcast.d.ts +12 -0
  217. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  218. package/lib-es/bridge/broadcast.js +16 -0
  219. package/lib-es/bridge/broadcast.js.map +1 -0
  220. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  221. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  222. package/lib-es/bridge/broadcast.test.js +46 -0
  223. package/lib-es/bridge/broadcast.test.js.map +1 -0
  224. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  225. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  226. package/lib-es/bridge/buildOptimisticOperation.js +69 -0
  227. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  228. package/lib-es/bridge/buildOptimisticOperation.test.d.ts +2 -0
  229. package/lib-es/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
  230. package/lib-es/bridge/buildOptimisticOperation.test.js +47 -0
  231. package/lib-es/bridge/buildOptimisticOperation.test.js.map +1 -0
  232. package/lib-es/bridge/buildTransaction.d.ts +9 -0
  233. package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
  234. package/lib-es/bridge/buildTransaction.js +11 -0
  235. package/lib-es/bridge/buildTransaction.js.map +1 -0
  236. package/lib-es/bridge/buildTransaction.test.d.ts +2 -0
  237. package/lib-es/bridge/buildTransaction.test.d.ts.map +1 -0
  238. package/lib-es/bridge/buildTransaction.test.js +15 -0
  239. package/lib-es/bridge/buildTransaction.test.js.map +1 -0
  240. package/lib-es/bridge/createTransaction.d.ts +10 -0
  241. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  242. package/lib-es/bridge/createTransaction.js +20 -0
  243. package/lib-es/bridge/createTransaction.js.map +1 -0
  244. package/lib-es/bridge/estimateMaxSpendable.d.ts +14 -0
  245. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  246. package/lib-es/bridge/estimateMaxSpendable.js +37 -0
  247. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  248. package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
  249. package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  250. package/lib-es/bridge/estimateMaxSpendable.test.js +23 -0
  251. package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
  252. package/lib-es/bridge/formatters.d.ts +10 -0
  253. package/lib-es/bridge/formatters.d.ts.map +1 -0
  254. package/lib-es/bridge/formatters.js +19 -0
  255. package/lib-es/bridge/formatters.js.map +1 -0
  256. package/lib-es/bridge/formatters.test.d.ts +2 -0
  257. package/lib-es/bridge/formatters.test.d.ts.map +1 -0
  258. package/lib-es/bridge/formatters.test.js +16 -0
  259. package/lib-es/bridge/formatters.test.js.map +1 -0
  260. package/lib-es/bridge/getFeesForTransaction.d.ts +15 -0
  261. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
  262. package/lib-es/bridge/getFeesForTransaction.js +29 -0
  263. package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
  264. package/lib-es/bridge/getFeesForTransaction.test.d.ts +2 -0
  265. package/lib-es/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  266. package/lib-es/bridge/getFeesForTransaction.test.js +30 -0
  267. package/lib-es/bridge/getFeesForTransaction.test.js.map +1 -0
  268. package/lib-es/bridge/getTransactionStatus.d.ts +12 -0
  269. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  270. package/lib-es/bridge/getTransactionStatus.js +55 -0
  271. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  272. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  273. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  274. package/lib-es/bridge/getTransactionStatus.test.js +43 -0
  275. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  276. package/lib-es/bridge/index.d.ts +10 -0
  277. package/lib-es/bridge/index.d.ts.map +1 -0
  278. package/lib-es/bridge/index.js +56 -0
  279. package/lib-es/bridge/index.js.map +1 -0
  280. package/lib-es/bridge/preload.d.ts +11 -0
  281. package/lib-es/bridge/preload.d.ts.map +1 -0
  282. package/lib-es/bridge/preload.js +32 -0
  283. package/lib-es/bridge/preload.js.map +1 -0
  284. package/lib-es/bridge/prepareTransaction.d.ts +13 -0
  285. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  286. package/lib-es/bridge/prepareTransaction.js +36 -0
  287. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  288. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  289. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  290. package/lib-es/bridge/prepareTransaction.test.js +40 -0
  291. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  292. package/lib-es/bridge/serialization.d.ts +7 -0
  293. package/lib-es/bridge/serialization.d.ts.map +1 -0
  294. package/lib-es/bridge/serialization.js +20 -0
  295. package/lib-es/bridge/serialization.js.map +1 -0
  296. package/lib-es/bridge/serialization.test.d.ts +2 -0
  297. package/lib-es/bridge/serialization.test.d.ts.map +1 -0
  298. package/lib-es/bridge/serialization.test.js +126 -0
  299. package/lib-es/bridge/serialization.test.js.map +1 -0
  300. package/lib-es/bridge/signOperation.d.ts +9 -0
  301. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  302. package/lib-es/bridge/signOperation.js +68 -0
  303. package/lib-es/bridge/signOperation.js.map +1 -0
  304. package/lib-es/bridge/signOperation.test.d.ts +2 -0
  305. package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
  306. package/lib-es/bridge/signOperation.test.js +71 -0
  307. package/lib-es/bridge/signOperation.test.js.map +1 -0
  308. package/lib-es/bridge/synchronisation.d.ts +21 -0
  309. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  310. package/lib-es/bridge/synchronisation.js +61 -0
  311. package/lib-es/bridge/synchronisation.js.map +1 -0
  312. package/lib-es/bridge/synchronisation.test.d.ts +2 -0
  313. package/lib-es/bridge/synchronisation.test.d.ts.map +1 -0
  314. package/lib-es/bridge/synchronisation.test.js +113 -0
  315. package/lib-es/bridge/synchronisation.test.js.map +1 -0
  316. package/lib-es/bridge/transaction.d.ts +15 -0
  317. package/lib-es/bridge/transaction.d.ts.map +1 -0
  318. package/lib-es/bridge/transaction.js +49 -0
  319. package/lib-es/bridge/transaction.js.map +1 -0
  320. package/lib-es/bridge/transaction.test.d.ts +2 -0
  321. package/lib-es/bridge/transaction.test.d.ts.map +1 -0
  322. package/lib-es/bridge/transaction.test.js +63 -0
  323. package/lib-es/bridge/transaction.test.js.map +1 -0
  324. package/lib-es/bridge/utils.d.ts +27 -0
  325. package/lib-es/bridge/utils.d.ts.map +1 -0
  326. package/lib-es/bridge/utils.js +51 -0
  327. package/lib-es/bridge/utils.js.map +1 -0
  328. package/lib-es/config.d.ts +15 -0
  329. package/lib-es/config.d.ts.map +1 -0
  330. package/lib-es/config.js +4 -0
  331. package/lib-es/config.js.map +1 -0
  332. package/lib-es/index.d.ts +3 -0
  333. package/lib-es/index.d.ts.map +1 -0
  334. package/lib-es/index.js +3 -0
  335. package/lib-es/index.js.map +1 -0
  336. package/lib-es/logic/broadcast.d.ts +9 -0
  337. package/lib-es/logic/broadcast.d.ts.map +1 -0
  338. package/lib-es/logic/broadcast.js +19 -0
  339. package/lib-es/logic/broadcast.js.map +1 -0
  340. package/lib-es/logic/craftTransaction.d.ts +17 -0
  341. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  342. package/lib-es/logic/craftTransaction.js +15 -0
  343. package/lib-es/logic/craftTransaction.js.map +1 -0
  344. package/lib-es/logic/estimateFees.d.ts +10 -0
  345. package/lib-es/logic/estimateFees.d.ts.map +1 -0
  346. package/lib-es/logic/estimateFees.js +13 -0
  347. package/lib-es/logic/estimateFees.js.map +1 -0
  348. package/lib-es/logic/index.d.ts +4 -0
  349. package/lib-es/logic/index.d.ts.map +1 -0
  350. package/lib-es/logic/index.js +4 -0
  351. package/lib-es/logic/index.js.map +1 -0
  352. package/lib-es/network/index.d.ts +18 -0
  353. package/lib-es/network/index.d.ts.map +1 -0
  354. package/lib-es/network/index.js +10 -0
  355. package/lib-es/network/index.js.map +1 -0
  356. package/lib-es/network/sdk.d.ts +61 -0
  357. package/lib-es/network/sdk.d.ts.map +1 -0
  358. package/lib-es/network/sdk.integration.test.d.ts +2 -0
  359. package/lib-es/network/sdk.integration.test.d.ts.map +1 -0
  360. package/lib-es/network/sdk.integration.test.js +65 -0
  361. package/lib-es/network/sdk.integration.test.js.map +1 -0
  362. package/lib-es/network/sdk.js +189 -0
  363. package/lib-es/network/sdk.js.map +1 -0
  364. package/lib-es/network/sdk.test.d.ts +2 -0
  365. package/lib-es/network/sdk.test.d.ts.map +1 -0
  366. package/lib-es/network/sdk.test.js +164 -0
  367. package/lib-es/network/sdk.test.js.map +1 -0
  368. package/lib-es/signer/getAddress.d.ts +6 -0
  369. package/lib-es/signer/getAddress.d.ts.map +1 -0
  370. package/lib-es/signer/getAddress.js +18 -0
  371. package/lib-es/signer/getAddress.js.map +1 -0
  372. package/lib-es/signer/getAddress.test.d.ts +2 -0
  373. package/lib-es/signer/getAddress.test.d.ts.map +1 -0
  374. package/lib-es/signer/getAddress.test.js +101 -0
  375. package/lib-es/signer/getAddress.test.js.map +1 -0
  376. package/lib-es/signer/index.d.ts +6 -0
  377. package/lib-es/signer/index.d.ts.map +1 -0
  378. package/lib-es/signer/index.js +6 -0
  379. package/lib-es/signer/index.js.map +1 -0
  380. package/lib-es/test/cli.d.ts +16 -0
  381. package/lib-es/test/cli.d.ts.map +1 -0
  382. package/lib-es/test/cli.js +13 -0
  383. package/lib-es/test/cli.js.map +1 -0
  384. package/lib-es/types/bridge.d.ts +72 -0
  385. package/lib-es/types/bridge.d.ts.map +1 -0
  386. package/lib-es/types/bridge.fixture.d.ts +30 -0
  387. package/lib-es/types/bridge.fixture.d.ts.map +1 -0
  388. package/lib-es/types/bridge.fixture.js +80 -0
  389. package/lib-es/types/bridge.fixture.js.map +1 -0
  390. package/lib-es/types/bridge.js +2 -0
  391. package/lib-es/types/bridge.js.map +1 -0
  392. package/lib-es/types/index.d.ts +4 -0
  393. package/lib-es/types/index.d.ts.map +1 -0
  394. package/lib-es/types/index.js +4 -0
  395. package/lib-es/types/index.js.map +1 -0
  396. package/lib-es/types/model.d.ts +6 -0
  397. package/lib-es/types/model.d.ts.map +1 -0
  398. package/lib-es/types/model.js +2 -0
  399. package/lib-es/types/model.js.map +1 -0
  400. package/lib-es/types/signer.d.ts +13 -0
  401. package/lib-es/types/signer.d.ts.map +1 -0
  402. package/lib-es/types/signer.js +2 -0
  403. package/lib-es/types/signer.js.map +1 -0
  404. package/lib-es/utils.d.ts +7 -0
  405. package/lib-es/utils.d.ts.map +1 -0
  406. package/lib-es/utils.js +9 -0
  407. package/lib-es/utils.js.map +1 -0
  408. package/package.json +152 -0
  409. package/src/api/chain/index.ts +17 -0
  410. package/src/bridge/bridge.integration.test.ts +140 -0
  411. package/src/bridge/broadcast.test.ts +52 -0
  412. package/src/bridge/broadcast.ts +21 -0
  413. package/src/bridge/buildOptimisticOperation.test.ts +53 -0
  414. package/src/bridge/buildOptimisticOperation.ts +105 -0
  415. package/src/bridge/buildTransaction.test.ts +17 -0
  416. package/src/bridge/buildTransaction.ts +14 -0
  417. package/src/bridge/createTransaction.ts +23 -0
  418. package/src/bridge/estimateMaxSpendable.test.ts +27 -0
  419. package/src/bridge/estimateMaxSpendable.ts +46 -0
  420. package/src/bridge/formatters.test.ts +17 -0
  421. package/src/bridge/formatters.ts +26 -0
  422. package/src/bridge/getFeesForTransaction.test.ts +36 -0
  423. package/src/bridge/getFeesForTransaction.ts +37 -0
  424. package/src/bridge/getTransactionStatus.test.ts +57 -0
  425. package/src/bridge/getTransactionStatus.ts +73 -0
  426. package/src/bridge/index.ts +77 -0
  427. package/src/bridge/preload.ts +46 -0
  428. package/src/bridge/prepareTransaction.test.ts +47 -0
  429. package/src/bridge/prepareTransaction.ts +44 -0
  430. package/src/bridge/serialization.test.ts +135 -0
  431. package/src/bridge/serialization.ts +24 -0
  432. package/src/bridge/signOperation.test.ts +80 -0
  433. package/src/bridge/signOperation.ts +101 -0
  434. package/src/bridge/synchronisation.test.ts +140 -0
  435. package/src/bridge/synchronisation.ts +75 -0
  436. package/src/bridge/transaction.test.ts +73 -0
  437. package/src/bridge/transaction.ts +61 -0
  438. package/src/bridge/utils.ts +69 -0
  439. package/src/config.ts +19 -0
  440. package/src/index.ts +3 -0
  441. package/src/logic/broadcast.ts +19 -0
  442. package/src/logic/craftTransaction.ts +28 -0
  443. package/src/logic/estimateFees.ts +14 -0
  444. package/src/logic/index.ts +3 -0
  445. package/src/network/index.ts +17 -0
  446. package/src/network/sdk.integration.test.ts +75 -0
  447. package/src/network/sdk.test.ts +203 -0
  448. package/src/network/sdk.ts +262 -0
  449. package/src/signer/getAddress.test.ts +119 -0
  450. package/src/signer/getAddress.ts +26 -0
  451. package/src/signer/index.ts +7 -0
  452. package/src/test/cli.ts +21 -0
  453. package/src/types/bridge.fixture.ts +84 -0
  454. package/src/types/bridge.ts +95 -0
  455. package/src/types/index.ts +3 -0
  456. package/src/types/model.ts +7 -0
  457. package/src/types/signer.ts +12 -0
  458. package/src/utils.ts +8 -0
  459. package/tsconfig.json +14 -0
@@ -0,0 +1,46 @@
1
+ import { Observable, Subject } from "rxjs";
2
+ import { log } from "@ledgerhq/logs";
3
+
4
+ import type { SuiPreloadData } from "../types";
5
+
6
+ const PRELOAD_MAX_AGE = 30 * 60 * 1000; // 30 minutes
7
+
8
+ let currentPreloadedData: SuiPreloadData = {};
9
+
10
+ function fromHydratePreloadData(_data: SuiPreloadData): SuiPreloadData {
11
+ return {};
12
+ }
13
+
14
+ const updates = new Subject<SuiPreloadData>();
15
+
16
+ export function getCurrentSuiPreloadData(): SuiPreloadData {
17
+ return currentPreloadedData;
18
+ }
19
+
20
+ export function setSuiPreloadData(data: SuiPreloadData) {
21
+ if (data === currentPreloadedData) return;
22
+
23
+ currentPreloadedData = data;
24
+
25
+ updates.next(data);
26
+ }
27
+
28
+ export function getSuiPreloadDataUpdates(): Observable<SuiPreloadData> {
29
+ return updates.asObservable();
30
+ }
31
+
32
+ export const getPreloadStrategy = () => ({
33
+ preloadMaxAge: PRELOAD_MAX_AGE,
34
+ });
35
+
36
+ export const preload = async (): Promise<SuiPreloadData> => {
37
+ log("sui/preload", "preloading sui data...");
38
+
39
+ return {};
40
+ };
41
+
42
+ export const hydrate = (data: SuiPreloadData) => {
43
+ const hydrated = fromHydratePreloadData(data);
44
+
45
+ setSuiPreloadData(hydrated);
46
+ };
@@ -0,0 +1,47 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
3
+ import prepareTransaction from "./prepareTransaction";
4
+ import { faker } from "@faker-js/faker";
5
+
6
+ const mockEstimateFees = jest.fn();
7
+ jest.mock("../logic", () => ({
8
+ estimateFees: () => mockEstimateFees(),
9
+ }));
10
+
11
+ describe("prepareTransaction", () => {
12
+ afterEach(() => {
13
+ mockEstimateFees.mockClear();
14
+ });
15
+
16
+ it("returns a new Transaction with new fees", async () => {
17
+ // GIVEN
18
+ const fees = new BigNumber(faker.number.int(50));
19
+ mockEstimateFees.mockResolvedValue(fees);
20
+ const tx = createFixtureTransaction();
21
+
22
+ // WHEN
23
+ const newTx = await prepareTransaction(createFixtureAccount(), tx);
24
+
25
+ // THEN
26
+ expect(newTx.fees).toEqual(fees);
27
+ expect(newTx).not.toBe(tx);
28
+ expect(newTx).toMatchObject({
29
+ amount: tx.amount,
30
+ recipient: tx.recipient,
31
+ mode: tx.mode,
32
+ });
33
+ });
34
+
35
+ it("returns the passed transaction if fees are the same", async () => {
36
+ // GIVEN
37
+ const fees = new BigNumber(faker.number.int(50));
38
+ mockEstimateFees.mockResolvedValue(fees);
39
+ const tx = createFixtureTransaction({ fees });
40
+
41
+ // WHEN
42
+ const newTx = await prepareTransaction(createFixtureAccount(), tx);
43
+
44
+ // THEN
45
+ expect(newTx).toBe(tx);
46
+ });
47
+ });
@@ -0,0 +1,44 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import { updateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
3
+ import type { SuiAccount, Transaction } from "../types";
4
+ import { estimateMaxSpendable } from "./estimateMaxSpendable";
5
+ import getFeesForTransaction from "./getFeesForTransaction";
6
+ import BigNumber from "bignumber.js";
7
+
8
+ /**
9
+ * Calculate fees for the current transaction
10
+ * @function prepareTransaction
11
+ * @description Prepares a transaction by calculating the amount, fees, and validating the recipient address.
12
+ * @param {SuiAccount} account - The account from which the transaction is being prepared.
13
+ * @param {Transaction} transaction - The transaction object containing details such as amount, fees, and recipient.
14
+ * @returns {Promise<Transaction>} A promise that resolves to the updated transaction object.
15
+ */
16
+ export const prepareTransaction: AccountBridge<
17
+ Transaction,
18
+ SuiAccount
19
+ >["prepareTransaction"] = async (account, transaction) => {
20
+ let amount = transaction.amount;
21
+ const spendable = await estimateMaxSpendable({ account, transaction });
22
+ if (transaction.useAllAmount) {
23
+ amount = spendable;
24
+ }
25
+
26
+ let fees: BigNumber;
27
+ try {
28
+ fees = await getFeesForTransaction({
29
+ account,
30
+ transaction,
31
+ });
32
+ } catch (e) {
33
+ fees = BigNumber(0);
34
+ }
35
+
36
+ const patch: Partial<Transaction> = {
37
+ amount,
38
+ fees,
39
+ };
40
+
41
+ return updateTransaction(transaction, patch);
42
+ };
43
+
44
+ export default prepareTransaction;
@@ -0,0 +1,135 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ toSuiResourcesRaw,
4
+ fromSuiResourcesRaw,
5
+ assignToAccountRaw,
6
+ assignFromAccountRaw,
7
+ } from "./serialization";
8
+
9
+ const account = {
10
+ type: "Account" as const,
11
+ id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
12
+ used: true,
13
+ seedIdentifier: "99807c4b6e1b8b25120f633f5f7816a393e4d3e7f84bdf24bd8afe725911be91",
14
+ derivationMode: "sui" as const,
15
+ index: 0,
16
+ freshAddress: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
17
+ freshAddressPath: "44'/784'/0'/0'/0'",
18
+ blockHeight: 10,
19
+ creationDate: new Date(),
20
+ balance: BigNumber(9998990120),
21
+ spendableBalance: BigNumber(9998990120),
22
+ operations: [
23
+ {
24
+ id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui-DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt-IN",
25
+ hash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
26
+ type: "IN" as const,
27
+ senders: ["0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24"],
28
+ recipients: ["0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0"],
29
+ accountId: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
30
+ blockHash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
31
+ blockHeight: 5,
32
+ date: new Date(),
33
+ value: BigNumber(9998990120),
34
+ fee: BigNumber(1009880),
35
+ extra: {},
36
+ hasFailed: false,
37
+ },
38
+ ],
39
+ operationsCount: 1,
40
+ pendingOperations: [],
41
+ currency: {
42
+ type: "CryptoCurrency" as const,
43
+ id: "sui" as const,
44
+ coinType: 784,
45
+ name: "Sui",
46
+ managerAppName: "Sui",
47
+ ticker: "SUI",
48
+ scheme: "sui",
49
+ color: "#000",
50
+ family: "sui",
51
+ units: [{ name: "Sui", code: "SUI", magnitude: 9 }],
52
+ explorerViews: [
53
+ {
54
+ tx: "https://suiscan.xyz/mainnet/tx/$hash",
55
+ address: "https://suiscan.xyz/mainnet/account/$address",
56
+ },
57
+ {
58
+ tx: "https://suivision.xyz/txblock/$hash",
59
+ address: "https://suivision.xyz/account/$address",
60
+ },
61
+ ],
62
+ },
63
+ lastSyncDate: new Date(),
64
+ swapHistory: [],
65
+ balanceHistoryCache: {
66
+ HOUR: { balances: [0, 9998990120, 9998990120, 9998990120], latestDate: 1742302800000 },
67
+ DAY: { balances: [0], latestDate: 1742245200000 },
68
+ WEEK: { balances: [0], latestDate: 1742072400000 },
69
+ },
70
+ suiResources: {},
71
+ };
72
+ const accountRaw = {
73
+ id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
74
+ seedIdentifier: "99807c4b6e1b8b25120f633f5f7816a393e4d3e7f84bdf24bd8afe725911be91",
75
+ used: true,
76
+ derivationMode: "sui" as const,
77
+ index: 0,
78
+ freshAddress: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
79
+ freshAddressPath: "44'/784'/0'/0'/0'",
80
+ blockHeight: 10,
81
+ creationDate: "2025-03-18T10:40:54.878Z",
82
+ operationsCount: 1,
83
+ operations: [
84
+ {
85
+ id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui-DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt-IN",
86
+ hash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
87
+ type: "IN" as const,
88
+ senders: ["0x65449f57946938c84c512732f1d69405d1fce417d9c9894696ddf4522f479e24"],
89
+ recipients: ["0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0"],
90
+ accountId: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
91
+ blockHash: "DhKLpX5kwuKuyRa71RGqpX5EY2M8Efw535ZVXYXsRiDt",
92
+ blockHeight: 5,
93
+ extra: {},
94
+ date: "2025-03-18T10:40:54.878Z",
95
+ value: "9998990120",
96
+ fee: "1009880",
97
+ hasFailed: false,
98
+ },
99
+ ],
100
+ pendingOperations: [],
101
+ currencyId: "sui",
102
+ lastSyncDate: "2025-03-18T10:40:54.878Z",
103
+ balance: "9998990120",
104
+ spendableBalance: "9998990120",
105
+ balanceHistoryCache: {
106
+ HOUR: { balances: [0, 9998990120, 9998990120, 9998990120], latestDate: 1742302800000 },
107
+ DAY: { balances: [0], latestDate: 1742245200000 },
108
+ WEEK: { balances: [0], latestDate: 1742072400000 },
109
+ },
110
+ suiResources: {},
111
+ };
112
+
113
+ describe("serialization", () => {
114
+ test("toSuiResourcesRaw should convert SuiResources to SuiResourcesRaw", () => {
115
+ const resources = {};
116
+ const result = toSuiResourcesRaw(resources);
117
+ expect(result).toEqual({});
118
+ });
119
+
120
+ test("fromSuiResourcesRaw should convert SuiResourcesRaw to SuiResources", () => {
121
+ const resourcesRaw = {};
122
+ const result = fromSuiResourcesRaw(resourcesRaw);
123
+ expect(result).toEqual({});
124
+ });
125
+
126
+ test("assignToAccountRaw should assign SuiResources to AccountRaw", () => {
127
+ assignToAccountRaw(account, accountRaw);
128
+ expect(accountRaw.suiResources).toBeDefined();
129
+ });
130
+
131
+ test("assignFromAccountRaw should assign SuiResourcesRaw to Account", () => {
132
+ assignFromAccountRaw(accountRaw, account);
133
+ expect(account.suiResources).toBeDefined();
134
+ });
135
+ });
@@ -0,0 +1,24 @@
1
+ import { Account, AccountRaw } from "@ledgerhq/types-live";
2
+ import type { SuiAccount, SuiAccountRaw, SuiResourcesRaw, SuiResources } from "../types";
3
+
4
+ export function toSuiResourcesRaw(_resources: SuiResources): SuiResourcesRaw {
5
+ return {};
6
+ }
7
+
8
+ export function fromSuiResourcesRaw(_resources: SuiResourcesRaw): SuiResources {
9
+ return {};
10
+ }
11
+
12
+ export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
13
+ const suiAccount = account as SuiAccount;
14
+ const suiAccountRaw = accountRaw as SuiAccountRaw;
15
+ if (suiAccount.suiResources) {
16
+ suiAccountRaw.suiResources = toSuiResourcesRaw(suiAccount.suiResources);
17
+ }
18
+ }
19
+ export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
20
+ const suiResourcesRaw = (accountRaw as SuiAccountRaw).suiResources;
21
+ if (suiResourcesRaw) {
22
+ (account as SuiAccount).suiResources = fromSuiResourcesRaw(suiResourcesRaw);
23
+ }
24
+ }
@@ -0,0 +1,80 @@
1
+ import buildSignOperation from "./signOperation";
2
+ import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
3
+ import { SuiSigner } from "../types";
4
+ import coinConfig from "../config";
5
+
6
+ jest.mock("../config");
7
+ const mockGetConfig = jest.mocked(coinConfig.getCoinConfig);
8
+
9
+ describe("signOperation", () => {
10
+ const fakeSignature = new Uint8Array(64).fill(0x42);
11
+ const fakeSigner = {
12
+ getPublicKey: jest.fn().mockResolvedValue({
13
+ publicKey: new Uint8Array(32).fill(0x01),
14
+ address: "0x1234567890abcdef",
15
+ }),
16
+ signTransaction: jest.fn().mockResolvedValue({
17
+ signature: fakeSignature,
18
+ }),
19
+ getVersion: jest.fn().mockResolvedValue({ major: 0, minor: 1, patch: 0 }),
20
+ transport: {} as any,
21
+ } as unknown as SuiSigner;
22
+ const signerContext = <T>(_deviceId: string, fn: (signer: SuiSigner) => Promise<T>) =>
23
+ fn(fakeSigner);
24
+ const signOperation = buildSignOperation(signerContext);
25
+ const deviceId = "dummyDeviceId";
26
+
27
+ beforeAll(() => {
28
+ mockGetConfig.mockImplementation((): any => {
29
+ return {};
30
+ });
31
+ });
32
+
33
+ it("returns events in the right order", done => {
34
+ // GIVEN
35
+ const account = createFixtureAccount();
36
+ const transaction = createFixtureTransaction();
37
+
38
+ // WHEN & THEN
39
+ const expectedEvent = [
40
+ {
41
+ type: "device-signature-requested",
42
+ },
43
+ {
44
+ type: "device-signature-granted",
45
+ },
46
+ {
47
+ type: "signed",
48
+ },
49
+ ];
50
+ let eventIdx = 0;
51
+
52
+ signOperation({ account, deviceId, transaction }).forEach((e: { type: string }) => {
53
+ try {
54
+ expect(e.type).toEqual(expectedEvent[eventIdx].type);
55
+ eventIdx++;
56
+
57
+ if (eventIdx === expectedEvent.length) {
58
+ done();
59
+ }
60
+ } catch (err) {
61
+ done(err);
62
+ }
63
+ });
64
+ });
65
+
66
+ it("throws an error of transaction has no fees", done => {
67
+ // GIVEN
68
+ const account = createFixtureAccount();
69
+ const transaction = createFixtureTransaction({ fees: undefined });
70
+
71
+ // WHEN & THEN
72
+ const observer = {
73
+ error: (e: Error) => {
74
+ expect(e.name).toMatch("FeeNotLoaded");
75
+ done();
76
+ },
77
+ };
78
+ signOperation({ account, deviceId, transaction }).subscribe(observer);
79
+ });
80
+ });
@@ -0,0 +1,101 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { Observable } from "rxjs";
3
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
4
+ import { FeeNotLoaded } from "@ledgerhq/errors";
5
+ import type { AccountBridge } from "@ledgerhq/types-live";
6
+ import { messageWithIntent, toSerializedSignature } from "@mysten/sui/cryptography";
7
+ import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
8
+ import { verifyTransactionSignature } from "@mysten/sui/verify";
9
+ import { buildOptimisticOperation } from "./buildOptimisticOperation";
10
+ import { buildTransaction } from "./buildTransaction";
11
+ import { calculateAmount } from "./utils";
12
+ import type { SuiSignedOperation, SuiAccount, SuiSigner, Transaction } from "../types";
13
+ import { ensureAddressFormat } from "../utils";
14
+
15
+ /**
16
+ * Sign Transaction with Ledger hardware
17
+ */
18
+ export const buildSignOperation =
19
+ (
20
+ signerContext: SignerContext<SuiSigner>,
21
+ ): AccountBridge<Transaction, SuiAccount>["signOperation"] =>
22
+ ({ account, deviceId, transaction }) =>
23
+ new Observable(subscriber => {
24
+ async function main() {
25
+ subscriber.next({
26
+ type: "device-signature-requested",
27
+ });
28
+
29
+ if (!transaction.fees) {
30
+ throw new FeeNotLoaded();
31
+ }
32
+
33
+ // Ensure amount is filled when useAllAmount
34
+ const transactionToSign = {
35
+ ...transaction,
36
+ amount: calculateAmount({
37
+ account,
38
+ transaction,
39
+ }),
40
+ };
41
+
42
+ const { unsigned } = await buildTransaction(account, transactionToSign);
43
+
44
+ const signData = messageWithIntent("TransactionData", unsigned);
45
+
46
+ const { signature } = await signerContext(deviceId, signer =>
47
+ signer.signTransaction(account.freshAddressPath, signData),
48
+ );
49
+
50
+ const publicKeyResult = await signerContext(deviceId, signer =>
51
+ signer.getPublicKey(account.freshAddressPath),
52
+ );
53
+ const publicKey = new Ed25519PublicKey(publicKeyResult.publicKey);
54
+
55
+ const serializedSignature = toSerializedSignature({
56
+ signature,
57
+ signatureScheme: "ED25519",
58
+ publicKey,
59
+ });
60
+
61
+ if (!transaction.skipVerify) {
62
+ const verify = await verifyTransactionSignature(unsigned, serializedSignature, {
63
+ address: ensureAddressFormat(account.freshAddress),
64
+ });
65
+ if (!verify) {
66
+ throw new Error("verifyTransactionSignature failed");
67
+ }
68
+ }
69
+
70
+ subscriber.next({
71
+ type: "device-signature-granted",
72
+ });
73
+
74
+ const operation = buildOptimisticOperation(
75
+ account,
76
+ transactionToSign,
77
+ transactionToSign.fees ?? new BigNumber(0),
78
+ );
79
+
80
+ const signedOperation: SuiSignedOperation = {
81
+ operation,
82
+ signature: Buffer.from(signature).toString("base64"),
83
+ rawData: {
84
+ serializedSignature,
85
+ unsigned: Buffer.from(unsigned).toString("base64"),
86
+ },
87
+ };
88
+
89
+ subscriber.next({
90
+ type: "signed",
91
+ signedOperation,
92
+ });
93
+ }
94
+
95
+ main().then(
96
+ () => subscriber.complete(),
97
+ e => subscriber.error(e),
98
+ );
99
+ });
100
+
101
+ export default buildSignOperation;
@@ -0,0 +1,140 @@
1
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
2
+ import BigNumber from "bignumber.js";
3
+ import { faker } from "@faker-js/faker";
4
+ import { createFixtureAccount, createFixtureOperation } from "../types/bridge.fixture";
5
+
6
+ import { getAccountShape } from "./synchronisation";
7
+
8
+ const mockGetAccount = jest.fn();
9
+ const mockGetOperations = jest.fn();
10
+ jest.mock("../network", () => ({
11
+ getAccount: () => mockGetAccount(),
12
+ getOperations: () => mockGetOperations(),
13
+ }));
14
+
15
+ describe("getAccountShape", () => {
16
+ beforeEach(() => {
17
+ mockGetAccount.mockClear();
18
+ mockGetOperations.mockClear();
19
+ });
20
+
21
+ it("calls getAccount and getOperations", async () => {
22
+ // GIVEN
23
+ const initialAccount = undefined;
24
+ const accountInfo = createAccountInfo();
25
+ mockGetAccount.mockResolvedValue(accountInfo);
26
+ mockGetOperations.mockResolvedValue([]);
27
+
28
+ // WHEN
29
+ await getAccountShape(
30
+ {
31
+ index: -1, // not used but mandatory
32
+ derivationPath: "not used",
33
+ currency: getCryptoCurrencyById("sui"),
34
+ address: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
35
+ initialAccount,
36
+ derivationMode: "sui",
37
+ },
38
+ { paginationConfig: {} },
39
+ );
40
+
41
+ // THEN
42
+ expect(mockGetAccount).toHaveBeenCalledTimes(1);
43
+ expect(mockGetOperations).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it("returns an AccountShapeInfo based on getAccount API", async () => {
47
+ // GIVEN
48
+ const initialAccount = undefined;
49
+ const accountInfo = createAccountInfo();
50
+ mockGetAccount.mockResolvedValue(accountInfo);
51
+ mockGetOperations.mockResolvedValue([]);
52
+
53
+ // WHEN
54
+ const shape = await getAccountShape(
55
+ {
56
+ index: -1, // not used but mandatory
57
+ derivationPath: "not used",
58
+ currency: getCryptoCurrencyById("sui"),
59
+ address: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
60
+ initialAccount,
61
+ derivationMode: "sui",
62
+ },
63
+ { paginationConfig: {} },
64
+ );
65
+
66
+ // THEN
67
+ expect(shape).toEqual({
68
+ id: "js:2:sui:0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0:sui",
69
+ balance: accountInfo.balance,
70
+ spendableBalance: accountInfo.balance,
71
+ blockHeight: accountInfo.blockHeight,
72
+ operations: [],
73
+ operationsCount: 0,
74
+ suiResources: {},
75
+ });
76
+ });
77
+
78
+ it("returns an AccountShapeInfo with operations from initialAccount", async () => {
79
+ // GIVEN
80
+ const initialOperations = [createFixtureOperation({ id: faker.string.uuid() })];
81
+ const initialAccount = createFixtureAccount({ operations: initialOperations });
82
+ const accountInfo = createAccountInfo();
83
+ mockGetAccount.mockResolvedValue(accountInfo);
84
+ mockGetOperations.mockResolvedValue([]);
85
+
86
+ // WHEN
87
+ const shape = await getAccountShape(
88
+ {
89
+ index: -1, // not used but mandatory
90
+ derivationPath: "not used",
91
+ currency: getCryptoCurrencyById("sui"),
92
+ address: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
93
+ initialAccount,
94
+ derivationMode: "sui",
95
+ },
96
+ { paginationConfig: {} },
97
+ );
98
+
99
+ // THEN
100
+ expect(shape.operationsCount).toEqual(1);
101
+ expect(shape.operations).toEqual(expect.arrayContaining(initialOperations));
102
+ });
103
+
104
+ it("returns an AccountShapeInfo with operations from getOperations API", async () => {
105
+ // GIVEN
106
+ const initialAccount = createFixtureAccount();
107
+ const accountInfo = createAccountInfo();
108
+ mockGetAccount.mockResolvedValue(accountInfo);
109
+ const apiOperations = [
110
+ createFixtureOperation({ id: faker.string.uuid() }),
111
+ createFixtureOperation({ id: faker.string.uuid() }),
112
+ ];
113
+ mockGetOperations.mockResolvedValue(apiOperations);
114
+
115
+ // WHEN
116
+ const shape = await getAccountShape(
117
+ {
118
+ index: -1, // not used but mandatory
119
+ derivationPath: "not used",
120
+ currency: getCryptoCurrencyById("sui"),
121
+ address: "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0",
122
+ initialAccount,
123
+ derivationMode: "sui",
124
+ },
125
+ { paginationConfig: {} },
126
+ );
127
+
128
+ // THEN
129
+ expect(shape.operationsCount).toEqual(initialAccount.operations.length + apiOperations.length);
130
+ expect(shape.operations).toEqual(expect.arrayContaining(apiOperations));
131
+ });
132
+ });
133
+
134
+ function createAccountInfo() {
135
+ return {
136
+ blockHeight: 10,
137
+ balance: new BigNumber(faker.string.numeric()),
138
+ spendableBalance: new BigNumber(faker.string.numeric()),
139
+ };
140
+ }
@@ -0,0 +1,75 @@
1
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
2
+ import { log } from "@ledgerhq/logs";
3
+ import {
4
+ makeSync,
5
+ mergeOps,
6
+ type GetAccountShape,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import { getAccount, getOperations } from "../network";
9
+ import { SuiAccount } from "../types";
10
+ import { OperationType, type Operation } from "@ledgerhq/types-live";
11
+
12
+ /**
13
+ * Get the shape of the account including its operations and balance.
14
+ * @function getAccountShape
15
+ * @param {Object} info - The information needed to retrieve the account shape.
16
+ * @param {string} info.address - The address of the account.
17
+ * @param {SuiAccount} info.initialAccount - The initial account data.
18
+ * @param {Object} info.currency - The currency information.
19
+ * @param {string} info.derivationMode - The derivation mode for the account.
20
+ * @returns {Promise<Object>} A promise that resolves to the account shape including balance and operations.
21
+ */
22
+ export const getAccountShape: GetAccountShape<SuiAccount> = async info => {
23
+ const { address, initialAccount, currency, derivationMode } = info;
24
+ const oldOperations = initialAccount?.operations || [];
25
+ const accountId = encodeAccountId({
26
+ type: "js",
27
+ version: "2",
28
+ currencyId: currency.id,
29
+ xpubOrAddress: address,
30
+ derivationMode,
31
+ });
32
+
33
+ const { blockHeight, balance } = await getAccount(address);
34
+
35
+ // Merge new operations with the previously synced ones
36
+ let operations: Operation[] = [];
37
+ try {
38
+ // Needed for incremental synchronisation
39
+ const startAtIn = latestHash(oldOperations, "IN");
40
+ const startAtOut = latestHash(oldOperations, "OUT");
41
+ const newOperations = await getOperations(accountId, address, startAtIn, startAtOut);
42
+ operations = mergeOps(oldOperations, newOperations);
43
+ } catch (e) {
44
+ log(
45
+ "sui/getAccountShape",
46
+ "failed to sync with incremental strategy, falling back to full resync",
47
+ { error: e },
48
+ );
49
+ // if we could NOT sync with existing transaction - we start from the beggining, rewritting transaction history
50
+ operations = await getOperations(accountId, address);
51
+ }
52
+
53
+ operations.sort((a, b) => b.date.valueOf() - a.date.valueOf());
54
+ const shape = {
55
+ id: accountId,
56
+ balance,
57
+ spendableBalance: balance,
58
+ operationsCount: operations.length,
59
+ blockHeight,
60
+ suiResources: {},
61
+ };
62
+ return { ...shape, operations };
63
+ };
64
+
65
+ /**
66
+ * Synchronise the account with the latest operations and balance.
67
+ * @function sync
68
+ * @param {Object} params - The parameters for synchronisation.
69
+ * @returns {Promise<void>} A promise that resolves when synchronisation is complete.
70
+ */
71
+ export const sync = makeSync({ getAccountShape });
72
+
73
+ function latestHash(operations: Operation[], type: OperationType) {
74
+ return operations.find(el => type === el.type)?.blockHash ?? null;
75
+ }