@ledgerhq/coin-mina 1.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 (414) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +24 -0
  4. package/CHANGELOG.md +15 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/jest.integ.config.js +7 -0
  8. package/lib/api/index.d.ts +13 -0
  9. package/lib/api/index.d.ts.map +1 -0
  10. package/lib/api/index.integ.test.d.ts +2 -0
  11. package/lib/api/index.integ.test.d.ts.map +1 -0
  12. package/lib/api/index.integ.test.js +57 -0
  13. package/lib/api/index.integ.test.js.map +1 -0
  14. package/lib/api/index.js +91 -0
  15. package/lib/api/index.js.map +1 -0
  16. package/lib/api/rosetta/index.d.ts +9 -0
  17. package/lib/api/rosetta/index.d.ts.map +1 -0
  18. package/lib/api/rosetta/index.js +90 -0
  19. package/lib/api/rosetta/index.js.map +1 -0
  20. package/lib/api/rosetta/types.d.ts +143 -0
  21. package/lib/api/rosetta/types.d.ts.map +1 -0
  22. package/lib/api/rosetta/types.js +3 -0
  23. package/lib/api/rosetta/types.js.map +1 -0
  24. package/lib/api/rosetta/utils.d.ts +43 -0
  25. package/lib/api/rosetta/utils.d.ts.map +1 -0
  26. package/lib/api/rosetta/utils.js +60 -0
  27. package/lib/api/rosetta/utils.js.map +1 -0
  28. package/lib/api/rosetta/utils.test.d.ts +2 -0
  29. package/lib/api/rosetta/utils.test.d.ts.map +1 -0
  30. package/lib/api/rosetta/utils.test.js +82 -0
  31. package/lib/api/rosetta/utils.test.js.map +1 -0
  32. package/lib/bridge/broadcast.d.ts +6 -0
  33. package/lib/bridge/broadcast.d.ts.map +1 -0
  34. package/lib/bridge/broadcast.js +11 -0
  35. package/lib/bridge/broadcast.js.map +1 -0
  36. package/lib/bridge/broadcast.test.d.ts +2 -0
  37. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  38. package/lib/bridge/broadcast.test.js +36 -0
  39. package/lib/bridge/broadcast.test.js.map +1 -0
  40. package/lib/bridge/buildTransaction.d.ts +4 -0
  41. package/lib/bridge/buildTransaction.d.ts.map +1 -0
  42. package/lib/bridge/buildTransaction.js +37 -0
  43. package/lib/bridge/buildTransaction.js.map +1 -0
  44. package/lib/bridge/buildTransaction.test.d.ts +2 -0
  45. package/lib/bridge/buildTransaction.test.d.ts.map +1 -0
  46. package/lib/bridge/buildTransaction.test.js +57 -0
  47. package/lib/bridge/buildTransaction.test.js.map +1 -0
  48. package/lib/bridge/cli-transaction.d.ts +18 -0
  49. package/lib/bridge/cli-transaction.d.ts.map +1 -0
  50. package/lib/bridge/cli-transaction.js +37 -0
  51. package/lib/bridge/cli-transaction.js.map +1 -0
  52. package/lib/bridge/createTransaction.d.ts +4 -0
  53. package/lib/bridge/createTransaction.d.ts.map +1 -0
  54. package/lib/bridge/createTransaction.js +21 -0
  55. package/lib/bridge/createTransaction.js.map +1 -0
  56. package/lib/bridge/createTransaction.test.d.ts +2 -0
  57. package/lib/bridge/createTransaction.test.d.ts.map +1 -0
  58. package/lib/bridge/createTransaction.test.js +24 -0
  59. package/lib/bridge/createTransaction.test.js.map +1 -0
  60. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  61. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  62. package/lib/bridge/deviceTransactionConfig.js +8 -0
  63. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  64. package/lib/bridge/errors.d.ts +10 -0
  65. package/lib/bridge/errors.d.ts.map +1 -0
  66. package/lib/bridge/errors.js +17 -0
  67. package/lib/bridge/errors.js.map +1 -0
  68. package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
  69. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  70. package/lib/bridge/estimateMaxSpendable.js +26 -0
  71. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  72. package/lib/bridge/getEstimatedFees.d.ts +8 -0
  73. package/lib/bridge/getEstimatedFees.d.ts.map +1 -0
  74. package/lib/bridge/getEstimatedFees.js +9 -0
  75. package/lib/bridge/getEstimatedFees.js.map +1 -0
  76. package/lib/bridge/getTransactionStatus.d.ts +5 -0
  77. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  78. package/lib/bridge/getTransactionStatus.js +62 -0
  79. package/lib/bridge/getTransactionStatus.js.map +1 -0
  80. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  81. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  82. package/lib/bridge/getTransactionStatus.test.js +138 -0
  83. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  84. package/lib/bridge/index.d.ts +14 -0
  85. package/lib/bridge/index.d.ts.map +1 -0
  86. package/lib/bridge/index.js +59 -0
  87. package/lib/bridge/index.js.map +1 -0
  88. package/lib/bridge/index.test.d.ts +2 -0
  89. package/lib/bridge/index.test.d.ts.map +1 -0
  90. package/lib/bridge/index.test.js +32 -0
  91. package/lib/bridge/index.test.js.map +1 -0
  92. package/lib/bridge/prepareTransaction.d.ts +4 -0
  93. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  94. package/lib/bridge/prepareTransaction.js +23 -0
  95. package/lib/bridge/prepareTransaction.js.map +1 -0
  96. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  97. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  98. package/lib/bridge/prepareTransaction.test.js +43 -0
  99. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  100. package/lib/bridge/signOperation.d.ts +12 -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 +129 -0
  107. package/lib/bridge/signOperation.test.js.map +1 -0
  108. package/lib/bridge/synchronisation.d.ts +7 -0
  109. package/lib/bridge/synchronisation.d.ts.map +1 -0
  110. package/lib/bridge/synchronisation.js +155 -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 +164 -0
  115. package/lib/bridge/synchronisation.test.js.map +1 -0
  116. package/lib/bridge/transaction.d.ts +14 -0
  117. package/lib/bridge/transaction.d.ts.map +1 -0
  118. package/lib/bridge/transaction.js +61 -0
  119. package/lib/bridge/transaction.js.map +1 -0
  120. package/lib/common-logic/index.d.ts +9 -0
  121. package/lib/common-logic/index.d.ts.map +1 -0
  122. package/lib/common-logic/index.js +96 -0
  123. package/lib/common-logic/index.js.map +1 -0
  124. package/lib/common-logic/index.test.d.ts +2 -0
  125. package/lib/common-logic/index.test.d.ts.map +1 -0
  126. package/lib/common-logic/index.test.js +181 -0
  127. package/lib/common-logic/index.test.js.map +1 -0
  128. package/lib/config.d.ts +9 -0
  129. package/lib/config.d.ts.map +1 -0
  130. package/lib/config.js +16 -0
  131. package/lib/config.js.map +1 -0
  132. package/lib/consts.d.ts +16 -0
  133. package/lib/consts.d.ts.map +1 -0
  134. package/lib/consts.js +19 -0
  135. package/lib/consts.js.map +1 -0
  136. package/lib/signer/getAddress.d.ts +6 -0
  137. package/lib/signer/getAddress.d.ts.map +1 -0
  138. package/lib/signer/getAddress.js +22 -0
  139. package/lib/signer/getAddress.js.map +1 -0
  140. package/lib/signer/getAddress.test.d.ts +2 -0
  141. package/lib/signer/getAddress.test.d.ts.map +1 -0
  142. package/lib/signer/getAddress.test.js +106 -0
  143. package/lib/signer/getAddress.test.js.map +1 -0
  144. package/lib/signer/index.d.ts +3 -0
  145. package/lib/signer/index.d.ts.map +1 -0
  146. package/lib/signer/index.js +8 -0
  147. package/lib/signer/index.js.map +1 -0
  148. package/lib/test/bot-deviceActions.d.ts +4 -0
  149. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  150. package/lib/test/bot-deviceActions.js +67 -0
  151. package/lib/test/bot-deviceActions.js.map +1 -0
  152. package/lib/test/bot-specs.d.ts +7 -0
  153. package/lib/test/bot-specs.d.ts.map +1 -0
  154. package/lib/test/bot-specs.js +107 -0
  155. package/lib/test/bot-specs.js.map +1 -0
  156. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  157. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  158. package/lib/test/bridgeDatasetTest.js +174 -0
  159. package/lib/test/bridgeDatasetTest.js.map +1 -0
  160. package/lib/test/fixtures.d.ts +55 -0
  161. package/lib/test/fixtures.d.ts.map +1 -0
  162. package/lib/test/fixtures.js +194 -0
  163. package/lib/test/fixtures.js.map +1 -0
  164. package/lib/test/index.d.ts +4 -0
  165. package/lib/test/index.d.ts.map +1 -0
  166. package/lib/test/index.js +20 -0
  167. package/lib/test/index.js.map +1 -0
  168. package/lib/test/testUtils.d.ts +2 -0
  169. package/lib/test/testUtils.d.ts.map +1 -0
  170. package/lib/test/testUtils.js +8 -0
  171. package/lib/test/testUtils.js.map +1 -0
  172. package/lib/test/testUtils.test.d.ts +2 -0
  173. package/lib/test/testUtils.test.d.ts.map +1 -0
  174. package/lib/test/testUtils.test.js +11 -0
  175. package/lib/test/testUtils.test.js.map +1 -0
  176. package/lib/types/common.d.ts +55 -0
  177. package/lib/types/common.d.ts.map +1 -0
  178. package/lib/types/common.js +3 -0
  179. package/lib/types/common.js.map +1 -0
  180. package/lib/types/index.d.ts +3 -0
  181. package/lib/types/index.d.ts.map +1 -0
  182. package/lib/types/index.js +19 -0
  183. package/lib/types/index.js.map +1 -0
  184. package/lib/types/signer.d.ts +32 -0
  185. package/lib/types/signer.d.ts.map +1 -0
  186. package/lib/types/signer.js +3 -0
  187. package/lib/types/signer.js.map +1 -0
  188. package/lib-es/api/index.d.ts +13 -0
  189. package/lib-es/api/index.d.ts.map +1 -0
  190. package/lib-es/api/index.integ.test.d.ts +2 -0
  191. package/lib-es/api/index.integ.test.d.ts.map +1 -0
  192. package/lib-es/api/index.integ.test.js +55 -0
  193. package/lib-es/api/index.integ.test.js.map +1 -0
  194. package/lib-es/api/index.js +79 -0
  195. package/lib-es/api/index.js.map +1 -0
  196. package/lib-es/api/rosetta/index.d.ts +8 -0
  197. package/lib-es/api/rosetta/index.d.ts.map +1 -0
  198. package/lib-es/api/rosetta/index.js +78 -0
  199. package/lib-es/api/rosetta/index.js.map +1 -0
  200. package/lib-es/api/rosetta/types.d.ts +143 -0
  201. package/lib-es/api/rosetta/types.d.ts.map +1 -0
  202. package/lib-es/api/rosetta/types.js +2 -0
  203. package/lib-es/api/rosetta/types.js.map +1 -0
  204. package/lib-es/api/rosetta/utils.d.ts +43 -0
  205. package/lib-es/api/rosetta/utils.d.ts.map +1 -0
  206. package/lib-es/api/rosetta/utils.js +54 -0
  207. package/lib-es/api/rosetta/utils.js.map +1 -0
  208. package/lib-es/api/rosetta/utils.test.d.ts +2 -0
  209. package/lib-es/api/rosetta/utils.test.d.ts.map +1 -0
  210. package/lib-es/api/rosetta/utils.test.js +80 -0
  211. package/lib-es/api/rosetta/utils.test.js.map +1 -0
  212. package/lib-es/bridge/broadcast.d.ts +6 -0
  213. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  214. package/lib-es/bridge/broadcast.js +9 -0
  215. package/lib-es/bridge/broadcast.js.map +1 -0
  216. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  217. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  218. package/lib-es/bridge/broadcast.test.js +31 -0
  219. package/lib-es/bridge/broadcast.test.js.map +1 -0
  220. package/lib-es/bridge/buildTransaction.d.ts +4 -0
  221. package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
  222. package/lib-es/bridge/buildTransaction.js +30 -0
  223. package/lib-es/bridge/buildTransaction.js.map +1 -0
  224. package/lib-es/bridge/buildTransaction.test.d.ts +2 -0
  225. package/lib-es/bridge/buildTransaction.test.d.ts.map +1 -0
  226. package/lib-es/bridge/buildTransaction.test.js +55 -0
  227. package/lib-es/bridge/buildTransaction.test.js.map +1 -0
  228. package/lib-es/bridge/cli-transaction.d.ts +18 -0
  229. package/lib-es/bridge/cli-transaction.d.ts.map +1 -0
  230. package/lib-es/bridge/cli-transaction.js +31 -0
  231. package/lib-es/bridge/cli-transaction.js.map +1 -0
  232. package/lib-es/bridge/createTransaction.d.ts +4 -0
  233. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  234. package/lib-es/bridge/createTransaction.js +14 -0
  235. package/lib-es/bridge/createTransaction.js.map +1 -0
  236. package/lib-es/bridge/createTransaction.test.d.ts +2 -0
  237. package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
  238. package/lib-es/bridge/createTransaction.test.js +19 -0
  239. package/lib-es/bridge/createTransaction.test.js.map +1 -0
  240. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  241. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  242. package/lib-es/bridge/deviceTransactionConfig.js +6 -0
  243. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  244. package/lib-es/bridge/errors.d.ts +10 -0
  245. package/lib-es/bridge/errors.d.ts.map +1 -0
  246. package/lib-es/bridge/errors.js +14 -0
  247. package/lib-es/bridge/errors.js.map +1 -0
  248. package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
  249. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  250. package/lib-es/bridge/estimateMaxSpendable.js +21 -0
  251. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  252. package/lib-es/bridge/getEstimatedFees.d.ts +8 -0
  253. package/lib-es/bridge/getEstimatedFees.d.ts.map +1 -0
  254. package/lib-es/bridge/getEstimatedFees.js +7 -0
  255. package/lib-es/bridge/getEstimatedFees.js.map +1 -0
  256. package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
  257. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  258. package/lib-es/bridge/getTransactionStatus.js +60 -0
  259. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  260. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  261. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  262. package/lib-es/bridge/getTransactionStatus.test.js +133 -0
  263. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  264. package/lib-es/bridge/index.d.ts +14 -0
  265. package/lib-es/bridge/index.d.ts.map +1 -0
  266. package/lib-es/bridge/index.js +50 -0
  267. package/lib-es/bridge/index.js.map +1 -0
  268. package/lib-es/bridge/index.test.d.ts +2 -0
  269. package/lib-es/bridge/index.test.d.ts.map +1 -0
  270. package/lib-es/bridge/index.test.js +30 -0
  271. package/lib-es/bridge/index.test.js.map +1 -0
  272. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  273. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  274. package/lib-es/bridge/prepareTransaction.js +16 -0
  275. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  276. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  277. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  278. package/lib-es/bridge/prepareTransaction.test.js +38 -0
  279. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  280. package/lib-es/bridge/signOperation.d.ts +12 -0
  281. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  282. package/lib-es/bridge/signOperation.js +64 -0
  283. package/lib-es/bridge/signOperation.js.map +1 -0
  284. package/lib-es/bridge/signOperation.test.d.ts +2 -0
  285. package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
  286. package/lib-es/bridge/signOperation.test.js +127 -0
  287. package/lib-es/bridge/signOperation.test.js.map +1 -0
  288. package/lib-es/bridge/synchronisation.d.ts +7 -0
  289. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  290. package/lib-es/bridge/synchronisation.js +147 -0
  291. package/lib-es/bridge/synchronisation.js.map +1 -0
  292. package/lib-es/bridge/synchronisation.test.d.ts +2 -0
  293. package/lib-es/bridge/synchronisation.test.d.ts.map +1 -0
  294. package/lib-es/bridge/synchronisation.test.js +159 -0
  295. package/lib-es/bridge/synchronisation.test.js.map +1 -0
  296. package/lib-es/bridge/transaction.d.ts +14 -0
  297. package/lib-es/bridge/transaction.d.ts.map +1 -0
  298. package/lib-es/bridge/transaction.js +53 -0
  299. package/lib-es/bridge/transaction.js.map +1 -0
  300. package/lib-es/common-logic/index.d.ts +9 -0
  301. package/lib-es/common-logic/index.d.ts.map +1 -0
  302. package/lib-es/common-logic/index.js +84 -0
  303. package/lib-es/common-logic/index.js.map +1 -0
  304. package/lib-es/common-logic/index.test.d.ts +2 -0
  305. package/lib-es/common-logic/index.test.d.ts.map +1 -0
  306. package/lib-es/common-logic/index.test.js +179 -0
  307. package/lib-es/common-logic/index.test.js.map +1 -0
  308. package/lib-es/config.d.ts +9 -0
  309. package/lib-es/config.d.ts.map +1 -0
  310. package/lib-es/config.js +11 -0
  311. package/lib-es/config.js.map +1 -0
  312. package/lib-es/consts.d.ts +16 -0
  313. package/lib-es/consts.d.ts.map +1 -0
  314. package/lib-es/consts.js +16 -0
  315. package/lib-es/consts.js.map +1 -0
  316. package/lib-es/signer/getAddress.d.ts +6 -0
  317. package/lib-es/signer/getAddress.d.ts.map +1 -0
  318. package/lib-es/signer/getAddress.js +17 -0
  319. package/lib-es/signer/getAddress.js.map +1 -0
  320. package/lib-es/signer/getAddress.test.d.ts +2 -0
  321. package/lib-es/signer/getAddress.test.d.ts.map +1 -0
  322. package/lib-es/signer/getAddress.test.js +101 -0
  323. package/lib-es/signer/getAddress.test.js.map +1 -0
  324. package/lib-es/signer/index.d.ts +3 -0
  325. package/lib-es/signer/index.d.ts.map +1 -0
  326. package/lib-es/signer/index.js +3 -0
  327. package/lib-es/signer/index.js.map +1 -0
  328. package/lib-es/test/bot-deviceActions.d.ts +4 -0
  329. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  330. package/lib-es/test/bot-deviceActions.js +64 -0
  331. package/lib-es/test/bot-deviceActions.js.map +1 -0
  332. package/lib-es/test/bot-specs.d.ts +7 -0
  333. package/lib-es/test/bot-specs.d.ts.map +1 -0
  334. package/lib-es/test/bot-specs.js +102 -0
  335. package/lib-es/test/bot-specs.js.map +1 -0
  336. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  337. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  338. package/lib-es/test/bridgeDatasetTest.js +171 -0
  339. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  340. package/lib-es/test/fixtures.d.ts +55 -0
  341. package/lib-es/test/fixtures.d.ts.map +1 -0
  342. package/lib-es/test/fixtures.js +182 -0
  343. package/lib-es/test/fixtures.js.map +1 -0
  344. package/lib-es/test/index.d.ts +4 -0
  345. package/lib-es/test/index.d.ts.map +1 -0
  346. package/lib-es/test/index.js +4 -0
  347. package/lib-es/test/index.js.map +1 -0
  348. package/lib-es/test/testUtils.d.ts +2 -0
  349. package/lib-es/test/testUtils.d.ts.map +1 -0
  350. package/lib-es/test/testUtils.js +4 -0
  351. package/lib-es/test/testUtils.js.map +1 -0
  352. package/lib-es/test/testUtils.test.d.ts +2 -0
  353. package/lib-es/test/testUtils.test.d.ts.map +1 -0
  354. package/lib-es/test/testUtils.test.js +9 -0
  355. package/lib-es/test/testUtils.test.js.map +1 -0
  356. package/lib-es/types/common.d.ts +55 -0
  357. package/lib-es/types/common.d.ts.map +1 -0
  358. package/lib-es/types/common.js +2 -0
  359. package/lib-es/types/common.js.map +1 -0
  360. package/lib-es/types/index.d.ts +3 -0
  361. package/lib-es/types/index.d.ts.map +1 -0
  362. package/lib-es/types/index.js +3 -0
  363. package/lib-es/types/index.js.map +1 -0
  364. package/lib-es/types/signer.d.ts +32 -0
  365. package/lib-es/types/signer.d.ts.map +1 -0
  366. package/lib-es/types/signer.js +2 -0
  367. package/lib-es/types/signer.js.map +1 -0
  368. package/package.json +143 -0
  369. package/src/api/index.integ.test.ts +62 -0
  370. package/src/api/index.ts +120 -0
  371. package/src/api/rosetta/index.ts +110 -0
  372. package/src/api/rosetta/types.ts +156 -0
  373. package/src/api/rosetta/utils.test.ts +100 -0
  374. package/src/api/rosetta/utils.ts +71 -0
  375. package/src/bridge/broadcast.test.ts +35 -0
  376. package/src/bridge/broadcast.ts +17 -0
  377. package/src/bridge/buildTransaction.test.ts +68 -0
  378. package/src/bridge/buildTransaction.ts +34 -0
  379. package/src/bridge/cli-transaction.ts +43 -0
  380. package/src/bridge/createTransaction.test.ts +21 -0
  381. package/src/bridge/createTransaction.ts +19 -0
  382. package/src/bridge/deviceTransactionConfig.ts +15 -0
  383. package/src/bridge/errors.ts +16 -0
  384. package/src/bridge/estimateMaxSpendable.ts +31 -0
  385. package/src/bridge/getEstimatedFees.ts +17 -0
  386. package/src/bridge/getTransactionStatus.test.ts +175 -0
  387. package/src/bridge/getTransactionStatus.ts +87 -0
  388. package/src/bridge/index.test.ts +39 -0
  389. package/src/bridge/index.ts +72 -0
  390. package/src/bridge/prepareTransaction.test.ts +43 -0
  391. package/src/bridge/prepareTransaction.ts +24 -0
  392. package/src/bridge/signOperation.test.ts +158 -0
  393. package/src/bridge/signOperation.ts +112 -0
  394. package/src/bridge/synchronisation.test.ts +184 -0
  395. package/src/bridge/synchronisation.ts +168 -0
  396. package/src/bridge/transaction.ts +69 -0
  397. package/src/common-logic/index.test.ts +225 -0
  398. package/src/common-logic/index.ts +97 -0
  399. package/src/config.ts +21 -0
  400. package/src/consts.ts +18 -0
  401. package/src/signer/getAddress.test.ts +131 -0
  402. package/src/signer/getAddress.ts +24 -0
  403. package/src/signer/index.ts +3 -0
  404. package/src/test/bot-deviceActions.ts +73 -0
  405. package/src/test/bot-specs.ts +130 -0
  406. package/src/test/bridgeDatasetTest.ts +180 -0
  407. package/src/test/fixtures.ts +226 -0
  408. package/src/test/index.ts +3 -0
  409. package/src/test/testUtils.test.ts +9 -0
  410. package/src/test/testUtils.ts +3 -0
  411. package/src/types/common.ts +70 -0
  412. package/src/types/index.ts +2 -0
  413. package/src/types/signer.ts +29 -0
  414. package/tsconfig.json +13 -0
@@ -0,0 +1,156 @@
1
+ export type FetchNetworkStatusResponse = {
2
+ current_block_identifier: {
3
+ index: number;
4
+ hash: string;
5
+ };
6
+ current_block_timestamp: number;
7
+ genesis_block_identifier: {
8
+ index: number;
9
+ hash: string;
10
+ };
11
+ oldest_block_identifier: {
12
+ index: number;
13
+ hash: string;
14
+ };
15
+ sync_status: {
16
+ current_index: number;
17
+ stage: string;
18
+ synced: boolean;
19
+ };
20
+ peers: Array<{
21
+ peer_id: string;
22
+ }>;
23
+ };
24
+
25
+ export type FetchAccountBalanceResponse = {
26
+ block_identifier: {
27
+ index: number;
28
+ hash: string;
29
+ };
30
+ balances: Array<{
31
+ value: string;
32
+ currency: {
33
+ symbol: string;
34
+ decimals: number;
35
+ };
36
+ metadata: {
37
+ locked_balance: number;
38
+ liquid_balance: number;
39
+ total_balance: number;
40
+ };
41
+ }>;
42
+ metadata: {
43
+ created_via_historical_lookup: boolean;
44
+ nonce: string;
45
+ };
46
+ };
47
+
48
+ export type RosettaTransaction = {
49
+ block_identifier: {
50
+ index: number;
51
+ hash: string;
52
+ };
53
+ transaction: {
54
+ transaction_identifier: {
55
+ hash: string;
56
+ };
57
+ operations: Array<{
58
+ operation_identifier: {
59
+ index: number;
60
+ };
61
+ type:
62
+ | "fee_payment"
63
+ | "payment_source_dec"
64
+ | "payment_receiver_inc"
65
+ | "account_creation_fee_via_payment"
66
+ | "zkapp_fee_payer_dec"
67
+ | "delegate_change"
68
+ | "zkapp_balance_update";
69
+ status: "Success" | "Failed";
70
+ account: {
71
+ address: string;
72
+ metadata: {
73
+ token_id: string;
74
+ };
75
+ };
76
+ amount?: {
77
+ value: string;
78
+ currency: {
79
+ symbol: string;
80
+ decimals: number;
81
+ };
82
+ };
83
+ related_operations?: Array<{
84
+ index: number;
85
+ }>;
86
+ metadata?: {
87
+ delegate_change_target?: string;
88
+ };
89
+ }>;
90
+ metadata?: {
91
+ memo?: string;
92
+ nonce?: number;
93
+ };
94
+ };
95
+ timestamp: number;
96
+ };
97
+
98
+ export type FetchAccountTransactionsResponse = {
99
+ transactions: RosettaTransaction[];
100
+ total_count: number;
101
+ next_offset?: number;
102
+ };
103
+
104
+ export type RosettaPreprocessResponse = {
105
+ options: {
106
+ sender: string;
107
+ token_id: string;
108
+ receiver: string;
109
+ };
110
+ };
111
+
112
+ export type RosettaMetadataResponse = {
113
+ metadata: {
114
+ sender: string;
115
+ nonce: string;
116
+ token_id: string;
117
+ receiver: string;
118
+ account_creation_fee?: string;
119
+ };
120
+ suggested_fee: Array<{
121
+ value: string;
122
+ currency: {
123
+ symbol: string;
124
+ decimals: number;
125
+ };
126
+ metadata: {
127
+ minimum_fee: {
128
+ value: string;
129
+ currency: {
130
+ symbol: string;
131
+ decimals: number;
132
+ };
133
+ };
134
+ };
135
+ }>;
136
+ };
137
+
138
+ export type RosettaSubmitResponse = {
139
+ transaction_identifier: {
140
+ hash: string;
141
+ };
142
+ };
143
+
144
+ export type RosettaBlockInfoResponse = {
145
+ block: {
146
+ block_identifier: {
147
+ index: number;
148
+ hash: string;
149
+ };
150
+ parent_block_identifier: {
151
+ index: number;
152
+ hash: string;
153
+ };
154
+ timestamp: number;
155
+ };
156
+ };
@@ -0,0 +1,100 @@
1
+ import { addNetworkIdentifier, buildAccountIdentifier, makeTransferPayload } from "./utils";
2
+ import {
3
+ MINA_DECIMALS,
4
+ MINA_SYMBOL,
5
+ MINA_TOKEN_ID,
6
+ MAINNET_NETWORK_IDENTIFIER,
7
+ } from "../../consts";
8
+
9
+ describe("addNetworkIdentifier", () => {
10
+ it("should add network identifier to an empty object", () => {
11
+ const result = addNetworkIdentifier({});
12
+ expect(result).toEqual(MAINNET_NETWORK_IDENTIFIER);
13
+ });
14
+
15
+ it("should add network identifier to an object with existing properties", () => {
16
+ const testObj = { test: "value" };
17
+ const result = addNetworkIdentifier(testObj);
18
+ expect(result).toEqual({
19
+ ...MAINNET_NETWORK_IDENTIFIER,
20
+ test: "value",
21
+ });
22
+ });
23
+
24
+ it("should override network identifier properties if they exist in input object", () => {
25
+ // Assuming MAINNET_NETWORK_IDENTIFIER has a property like { blockchain: 'Mina' }
26
+ const testObj = { blockchain: "mina" };
27
+ const result = addNetworkIdentifier(testObj);
28
+ expect(result.network_identifier.blockchain).toEqual("mina");
29
+ });
30
+ });
31
+
32
+ describe("buildAccountIdentifier", () => {
33
+ it("should build correct account identifier with given address", () => {
34
+ const testAddress = "B62qrPN5Y5yq8kGE3FbVKbGTdTAJNdtNtB5sNVpxyRwWGcDEhpMzc8g";
35
+ const result = buildAccountIdentifier(testAddress);
36
+
37
+ expect(result).toEqual({
38
+ account_identifier: {
39
+ address: testAddress,
40
+ metadata: {
41
+ token_id: MINA_TOKEN_ID,
42
+ },
43
+ },
44
+ });
45
+ });
46
+ });
47
+
48
+ describe("makeTransferPayload", () => {
49
+ const fromAddr = "sender-address";
50
+ const toAddr = "recipient-address";
51
+ const feeNano = 1000000;
52
+ const valueNano = 5000000;
53
+
54
+ it("should create a valid transfer payload with three operations", () => {
55
+ const result = makeTransferPayload(fromAddr, toAddr, feeNano, valueNano);
56
+
57
+ expect(result.operations).toHaveLength(3);
58
+ });
59
+
60
+ it("should correctly create fee payment operation", () => {
61
+ const result = makeTransferPayload(fromAddr, toAddr, feeNano, valueNano);
62
+
63
+ const feeOp = result.operations[0];
64
+ expect(feeOp.operation_identifier.index).toBe(0);
65
+ expect(feeOp.type).toBe("fee_payment");
66
+ expect(feeOp.account.address).toBe(fromAddr);
67
+ expect(feeOp.amount.value).toBe("-" + feeNano.toString());
68
+ expect(feeOp.amount.currency.symbol).toBe(MINA_SYMBOL);
69
+ expect(feeOp.amount.currency.decimals).toBe(MINA_DECIMALS);
70
+ });
71
+
72
+ it("should correctly create payment source operation", () => {
73
+ const result = makeTransferPayload(fromAddr, toAddr, feeNano, valueNano);
74
+
75
+ const sourceOp = result.operations[1];
76
+ expect(sourceOp.operation_identifier.index).toBe(1);
77
+ expect(sourceOp.type).toBe("payment_source_dec");
78
+ expect(sourceOp.account.address).toBe(fromAddr);
79
+ expect(sourceOp.amount.value).toBe("-" + valueNano.toString());
80
+ });
81
+
82
+ it("should correctly create payment receiver operation with related operation", () => {
83
+ const result = makeTransferPayload(fromAddr, toAddr, feeNano, valueNano);
84
+
85
+ const receiverOp = result.operations[2];
86
+ expect(receiverOp.operation_identifier.index).toBe(2);
87
+ expect(receiverOp.type).toBe("payment_receiver_inc");
88
+ expect(receiverOp.account.address).toBe(toAddr);
89
+ expect(receiverOp.amount.value).toBe(valueNano.toString());
90
+ expect(receiverOp.relatedOps.related_operations).toEqual([{ index: 1 }]);
91
+ });
92
+
93
+ it("should handle zero values correctly", () => {
94
+ const result = makeTransferPayload(fromAddr, toAddr, 0, 0);
95
+
96
+ expect(result.operations[0].amount.value).toBe("-0");
97
+ expect(result.operations[1].amount.value).toBe("-0");
98
+ expect(result.operations[2].amount.value).toBe("0");
99
+ });
100
+ });
@@ -0,0 +1,71 @@
1
+ import {
2
+ MINA_DECIMALS,
3
+ MINA_SYMBOL,
4
+ MINA_TOKEN_ID,
5
+ MAINNET_NETWORK_IDENTIFIER,
6
+ } from "../../consts";
7
+
8
+ export const addNetworkIdentifier = (data: object) => {
9
+ return {
10
+ ...MAINNET_NETWORK_IDENTIFIER,
11
+ ...data,
12
+ };
13
+ };
14
+
15
+ export const buildAccountIdentifier = (address: string) => {
16
+ return {
17
+ account_identifier: {
18
+ address,
19
+ metadata: {
20
+ token_id: MINA_TOKEN_ID,
21
+ },
22
+ },
23
+ };
24
+ };
25
+
26
+ export function makeTransferPayload(from: string, to: string, feeNano: number, valueNano: number) {
27
+ function makeOperation(
28
+ idx: number,
29
+ relatedIdxs: number[],
30
+ opType: string,
31
+ addr: string,
32
+ value: number,
33
+ isPositive: boolean,
34
+ ) {
35
+ const relatedOps =
36
+ relatedIdxs.length == 0
37
+ ? {}
38
+ : {
39
+ related_operations: relatedIdxs.map(i => {
40
+ return { index: i };
41
+ }),
42
+ };
43
+
44
+ return {
45
+ operation_identifier: { index: idx },
46
+ relatedOps,
47
+ type: opType,
48
+ account: {
49
+ address: addr,
50
+ metadata: {
51
+ token_id: MINA_TOKEN_ID,
52
+ },
53
+ },
54
+ amount: {
55
+ value: (isPositive ? "" : "-") + value.toString(),
56
+ currency: {
57
+ symbol: MINA_SYMBOL,
58
+ decimals: MINA_DECIMALS,
59
+ },
60
+ },
61
+ };
62
+ }
63
+
64
+ return {
65
+ operations: [
66
+ makeOperation(0, [], "fee_payment", from, feeNano, false),
67
+ makeOperation(1, [], "payment_source_dec", from, valueNano, false),
68
+ makeOperation(2, [1], "payment_receiver_inc", to, valueNano, true),
69
+ ],
70
+ };
71
+ }
@@ -0,0 +1,35 @@
1
+ import { Account, BroadcastArg } from "@ledgerhq/types-live";
2
+ import broadcast from "./broadcast";
3
+ jest.mock("@ledgerhq/coin-framework/operation");
4
+ jest.mock("../api");
5
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
6
+ import { broadcastTransaction as broadcastLogic } from "../api";
7
+
8
+ describe("broadcast", () => {
9
+ let patchOperationSpy: jest.SpyInstance;
10
+ let broadcastSpy: jest.SpyInstance;
11
+ beforeEach(() => {
12
+ patchOperationSpy = jest.spyOn({ patchOperationWithHash }, "patchOperationWithHash");
13
+ broadcastSpy = jest.spyOn({ broadcastLogic }, "broadcastLogic");
14
+ broadcastSpy.mockResolvedValue("hash");
15
+ });
16
+
17
+ const signedOperation = {
18
+ signature: JSON.stringify({}),
19
+ operation: undefined,
20
+ };
21
+
22
+ it("should broadcast", () => {
23
+ broadcast({
24
+ signedOperation,
25
+ } as unknown as BroadcastArg<Account>);
26
+ expect(broadcastLogic).toHaveBeenCalledTimes(1);
27
+ });
28
+
29
+ it("should patch operation with hash", () => {
30
+ broadcast({
31
+ signedOperation,
32
+ } as unknown as BroadcastArg<Account>);
33
+ expect(patchOperationSpy).toHaveBeenCalledWith(undefined, "hash");
34
+ });
35
+ });
@@ -0,0 +1,17 @@
1
+ import type { Operation, SignedOperation } from "@ledgerhq/types-live";
2
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
3
+ import { broadcastTransaction } from "../api";
4
+ import { MinaSignedTransaction } from "../types/common";
5
+
6
+ const broadcast = async ({
7
+ signedOperation: { signature, operation },
8
+ }: {
9
+ signedOperation: SignedOperation;
10
+ }): Promise<Operation> => {
11
+ const signedPayload = JSON.parse(signature) as MinaSignedTransaction;
12
+ const hash = await broadcastTransaction(signedPayload);
13
+
14
+ return patchOperationWithHash(operation, hash);
15
+ };
16
+
17
+ export default broadcast;
@@ -0,0 +1,68 @@
1
+ import { Account } from "@ledgerhq/types-live";
2
+ import { buildTransaction } from "./buildTransaction";
3
+ import { MINA_MAINNET_NETWORK_ID, MINA_PAYMENT_TYPE_ID } from "../consts";
4
+ import { getAccountNumFromPath } from "../common-logic";
5
+ import { BigNumber } from "bignumber.js";
6
+ import { Transaction } from "../types";
7
+ jest.mock("../common-logic");
8
+
9
+ describe("buildTransaction", () => {
10
+ let getAccountNumSpy: jest.SpyInstance;
11
+
12
+ beforeEach(() => {
13
+ getAccountNumSpy = jest.spyOn({ getAccountNumFromPath }, "getAccountNumFromPath");
14
+ getAccountNumSpy.mockReturnValue(42); // Mock account number
15
+ });
16
+
17
+ const mockAccount: Partial<Account> = {
18
+ freshAddress: "B62qrPN5Y5yq8kGE3FbVKbGTdTAJNdHm8qSqZhhtiu1Dq56Cmuo2aJ4",
19
+ freshAddressPath: "44'/12586'/0'/0/0",
20
+ };
21
+
22
+ const mockTransaction: Transaction = {
23
+ recipient: "B62qoDWfBZUxKpaoQCoMPJEysXXWv7reVgo7CEAjqx1xAYs3CsT8Gtz",
24
+ amount: new BigNumber(1000000000),
25
+ fees: {
26
+ fee: new BigNumber(1000000),
27
+ accountCreationFee: new BigNumber(0),
28
+ },
29
+ nonce: 5,
30
+ memo: "test transaction",
31
+ family: "mina",
32
+ };
33
+
34
+ it("should build a transaction correctly", async () => {
35
+ const result = await buildTransaction(mockAccount as Account, mockTransaction);
36
+
37
+ expect(result).toEqual({
38
+ txType: MINA_PAYMENT_TYPE_ID,
39
+ senderAccount: 42,
40
+ senderAddress: mockAccount.freshAddress,
41
+ receiverAddress: mockTransaction.recipient,
42
+ amount: mockTransaction.amount.toNumber(),
43
+ fee: mockTransaction.fees.fee.toNumber(),
44
+ nonce: mockTransaction.nonce,
45
+ memo: mockTransaction.memo,
46
+ networkId: MINA_MAINNET_NETWORK_ID,
47
+ });
48
+
49
+ expect(getAccountNumFromPath).toHaveBeenCalledWith(mockAccount.freshAddressPath);
50
+ });
51
+
52
+ it("should handle empty memo", async () => {
53
+ const txWithoutMemo = {
54
+ ...mockTransaction,
55
+ memo: undefined,
56
+ };
57
+
58
+ const result = await buildTransaction(mockAccount as Account, txWithoutMemo);
59
+
60
+ expect(result.memo).toBe("");
61
+ });
62
+
63
+ it("should throw error if accountNum is undefined", async () => {
64
+ getAccountNumSpy.mockReturnValue(undefined);
65
+
66
+ await expect(buildTransaction(mockAccount as Account, mockTransaction)).rejects.toThrow();
67
+ });
68
+ });
@@ -0,0 +1,34 @@
1
+ import { log } from "@ledgerhq/logs";
2
+ import type { Account } from "@ledgerhq/types-live";
3
+ import type { MinaUnsignedTransaction, Transaction } from "../types/common";
4
+ import { MINA_MAINNET_NETWORK_ID, MINA_PAYMENT_TYPE_ID } from "../consts";
5
+ import { getAccountNumFromPath } from "../common-logic";
6
+ import invariant from "invariant";
7
+
8
+ export const buildTransaction = async (
9
+ a: Account,
10
+ t: Transaction,
11
+ ): Promise<MinaUnsignedTransaction> => {
12
+ try {
13
+ const accountNum = getAccountNumFromPath(a.freshAddressPath);
14
+ invariant(accountNum !== undefined, "mina: accountNum is required to build transaction");
15
+ return {
16
+ txType: MINA_PAYMENT_TYPE_ID,
17
+ senderAccount: accountNum,
18
+ senderAddress: a.freshAddress,
19
+ receiverAddress: t.recipient,
20
+ amount: t.amount.toNumber(),
21
+ fee: t.fees.fee.toNumber(),
22
+ nonce: t.nonce,
23
+ memo: t.memo ?? "",
24
+ networkId: MINA_MAINNET_NETWORK_ID,
25
+ };
26
+ } catch (e) {
27
+ log("error", "mina: error building transaction", {
28
+ error: e,
29
+ transaction: t,
30
+ account: a,
31
+ });
32
+ throw e;
33
+ }
34
+ };
@@ -0,0 +1,43 @@
1
+ import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
2
+ import invariant from "invariant";
3
+ import flatMap from "lodash/flatMap";
4
+ import type { Transaction } from "../types/common";
5
+
6
+ const options = [
7
+ {
8
+ name: "memo",
9
+ type: String,
10
+ desc: "set a memo",
11
+ },
12
+ ];
13
+
14
+ function inferAccounts(account: Account): AccountLikeArray {
15
+ invariant(account.currency.family === "mina", "mina family");
16
+ return [account];
17
+ }
18
+
19
+ function inferTransactions(
20
+ transactions: Array<{
21
+ account: AccountLike;
22
+ transaction: Transaction;
23
+ }>,
24
+ opts: Record<string, string>,
25
+ ): Transaction[] {
26
+ return flatMap(transactions, ({ transaction }) => {
27
+ invariant(transaction.family === "mina", "mina family");
28
+
29
+ return {
30
+ ...transaction,
31
+ family: "mina",
32
+ memo: opts.memo,
33
+ };
34
+ });
35
+ }
36
+
37
+ export default function makeCliTools() {
38
+ return {
39
+ options,
40
+ inferAccounts,
41
+ inferTransactions,
42
+ };
43
+ }
@@ -0,0 +1,21 @@
1
+ import { Account, AccountLike } from "@ledgerhq/types-live";
2
+ import { createTransaction } from "./createTransaction";
3
+ import BigNumber from "bignumber.js";
4
+
5
+ describe("createTransaction", () => {
6
+ it("should create a 0 amount transaction", () => {
7
+ expect(createTransaction({} as AccountLike<Account>).amount.toNumber()).toEqual(0);
8
+ expect(createTransaction({} as AccountLike<Account>).recipient).toEqual("");
9
+ expect(createTransaction({} as AccountLike<Account>).useAllAmount).toEqual(false);
10
+ expect(createTransaction({} as AccountLike<Account>).fees).toEqual({
11
+ fee: new BigNumber(0),
12
+ accountCreationFee: new BigNumber(0),
13
+ });
14
+ expect(createTransaction({} as AccountLike<Account>).memo).toEqual(undefined);
15
+ expect(createTransaction({} as AccountLike<Account>).nonce).toEqual(0);
16
+ });
17
+
18
+ it("should create a transaction with boilerplate family", () => {
19
+ expect(createTransaction({} as AccountLike<Account>).family).toEqual("mina");
20
+ });
21
+ });
@@ -0,0 +1,19 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { MinaAccount, Transaction } from "../types/common";
3
+ import { AccountBridge } from "@ledgerhq/types-live";
4
+
5
+ export const createTransaction: AccountBridge<
6
+ Transaction,
7
+ MinaAccount
8
+ >["createTransaction"] = () => ({
9
+ family: "mina",
10
+ amount: new BigNumber(0),
11
+ recipient: "",
12
+ useAllAmount: false,
13
+ fees: {
14
+ fee: new BigNumber(0),
15
+ accountCreationFee: new BigNumber(0),
16
+ },
17
+ memo: undefined,
18
+ nonce: 0,
19
+ });
@@ -0,0 +1,15 @@
1
+ import type { Account, AccountLike } from "@ledgerhq/types-live";
2
+ import type { Transaction, TransactionStatus } from "../types/common";
3
+ import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
4
+
5
+ function getDeviceTransactionConfig(_input: {
6
+ account: AccountLike;
7
+ parentAccount: Account | null | undefined;
8
+ transaction: Transaction;
9
+ status: TransactionStatus;
10
+ }): Array<DeviceTransactionField> {
11
+ const fields: Array<DeviceTransactionField> = [];
12
+ return fields;
13
+ }
14
+
15
+ export default getDeviceTransactionConfig;
@@ -0,0 +1,16 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+
3
+ /*
4
+ * When the memo is greater than 32 characters
5
+ */
6
+ export const InvalidMemoMina = createCustomErrorClass("InvalidMemoMina");
7
+
8
+ /*
9
+ * When the user sends less than the account creation fee of 1 MINA
10
+ */
11
+ export const AccountCreationFeeWarning = createCustomErrorClass("AccountCreationFeeWarning");
12
+
13
+ /*
14
+ * When the amount is less than the account creation fee of 1 MINA
15
+ */
16
+ export const AmountTooSmall = createCustomErrorClass("AmountTooSmall");
@@ -0,0 +1,31 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { AccountBridge } from "@ledgerhq/types-live";
3
+ import type { Transaction, MinaAccount } from "../types/common";
4
+ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
5
+ import { getMaxAmount } from "../common-logic";
6
+ import { createTransaction } from "./createTransaction";
7
+ import getEstimatedFees from "./getEstimatedFees";
8
+
9
+ const estimateMaxSpendable: AccountBridge<
10
+ Transaction,
11
+ MinaAccount
12
+ >["estimateMaxSpendable"] = async ({ account, parentAccount, transaction }): Promise<BigNumber> => {
13
+ const a = getMainAccount(account, parentAccount) as MinaAccount;
14
+ const t = {
15
+ ...createTransaction(account),
16
+ ...transaction,
17
+ amount: a.spendableBalance,
18
+ };
19
+
20
+ const { fee } = await getEstimatedFees(t, a.freshAddress);
21
+
22
+ const maxSpendable = getMaxAmount(a, t, fee);
23
+
24
+ if (maxSpendable.lt(0)) {
25
+ return new BigNumber(0);
26
+ }
27
+
28
+ return maxSpendable;
29
+ };
30
+
31
+ export default estimateMaxSpendable;
@@ -0,0 +1,17 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { getFees } from "../api";
3
+ import { Transaction } from "../types/common";
4
+
5
+ const getEstimatedFees = async (
6
+ transaction: Transaction,
7
+ address: string,
8
+ ): Promise<{
9
+ fee: BigNumber;
10
+ accountCreationFee: BigNumber;
11
+ }> => {
12
+ const { fee, accountCreationFee } = await getFees(transaction, address);
13
+
14
+ return { fee, accountCreationFee };
15
+ };
16
+
17
+ export default getEstimatedFees;