@ledgerhq/coin-tezos 6.6.0-nightly.1 → 6.6.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 (331) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +30 -4
  3. package/CHANGELOG.md +17 -8
  4. package/jest.integ.config.js +0 -1
  5. package/lib/api/index.d.ts.map +1 -1
  6. package/lib/api/index.js +40 -188
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/index.test.js +10 -79
  9. package/lib/api/index.test.js.map +1 -1
  10. package/lib/api/types.d.ts +5 -7
  11. package/lib/api/types.d.ts.map +1 -1
  12. package/lib/bridge/broadcast.d.ts +4 -0
  13. package/lib/bridge/broadcast.d.ts.map +1 -0
  14. package/lib/bridge/broadcast.js +11 -0
  15. package/lib/bridge/broadcast.js.map +1 -0
  16. package/lib/bridge/broadcast.test.d.ts +2 -0
  17. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  18. package/lib/bridge/broadcast.test.js +36 -0
  19. package/lib/bridge/broadcast.test.js.map +1 -0
  20. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  21. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  22. package/lib/bridge/buildOptimisticOperation.js +28 -0
  23. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  24. package/lib/bridge/createTransaction.d.ts +4 -0
  25. package/lib/bridge/createTransaction.d.ts.map +1 -0
  26. package/lib/bridge/createTransaction.js +24 -0
  27. package/lib/bridge/createTransaction.js.map +1 -0
  28. package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
  29. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  30. package/lib/bridge/estimateMaxSpendable.js +30 -0
  31. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  32. package/lib/bridge/getFeesForTransaction.d.ts +21 -0
  33. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
  34. package/lib/bridge/getFeesForTransaction.js +39 -0
  35. package/lib/bridge/getFeesForTransaction.js.map +1 -0
  36. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  37. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  38. package/lib/bridge/getTransactionStatus.js +108 -0
  39. package/lib/bridge/getTransactionStatus.js.map +1 -0
  40. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  41. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  42. package/lib/bridge/getTransactionStatus.test.js +107 -0
  43. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  44. package/lib/bridge/index.d.ts +10 -0
  45. package/lib/bridge/index.d.ts.map +1 -0
  46. package/lib/bridge/index.js +59 -0
  47. package/lib/bridge/index.js.map +1 -0
  48. package/lib/bridge/logic.d.ts +10 -0
  49. package/lib/bridge/logic.d.ts.map +1 -0
  50. package/lib/bridge/logic.js +155 -0
  51. package/lib/bridge/logic.js.map +1 -0
  52. package/lib/bridge/preload.d.ts +9 -0
  53. package/lib/bridge/preload.d.ts.map +1 -0
  54. package/lib/bridge/preload.js +23 -0
  55. package/lib/bridge/preload.js.map +1 -0
  56. package/lib/bridge/prepareTransaction.d.ts +5 -0
  57. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  58. package/lib/bridge/prepareTransaction.integ.test.d.ts +2 -0
  59. package/lib/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
  60. package/lib/bridge/prepareTransaction.integ.test.js +34 -0
  61. package/lib/bridge/prepareTransaction.integ.test.js.map +1 -0
  62. package/lib/bridge/prepareTransaction.js +57 -0
  63. package/lib/bridge/prepareTransaction.js.map +1 -0
  64. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  65. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  66. package/lib/bridge/prepareTransaction.test.js +178 -0
  67. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  68. package/lib/bridge/serialization.d.ts +7 -0
  69. package/lib/bridge/serialization.d.ts.map +1 -0
  70. package/lib/bridge/serialization.js +26 -0
  71. package/lib/bridge/serialization.js.map +1 -0
  72. package/lib/bridge/signOperation.d.ts +16 -0
  73. package/lib/bridge/signOperation.d.ts.map +1 -0
  74. package/lib/bridge/signOperation.js +88 -0
  75. package/lib/bridge/signOperation.js.map +1 -0
  76. package/lib/bridge/signOperation.test.d.ts +2 -0
  77. package/lib/bridge/signOperation.test.d.ts.map +1 -0
  78. package/lib/bridge/signOperation.test.js +283 -0
  79. package/lib/bridge/signOperation.test.js.map +1 -0
  80. package/lib/bridge/synchronization.d.ts +5 -0
  81. package/lib/bridge/synchronization.d.ts.map +1 -0
  82. package/lib/bridge/synchronization.integ.test.d.ts +2 -0
  83. package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
  84. package/lib/bridge/synchronization.integ.test.js +32 -0
  85. package/lib/bridge/synchronization.integ.test.js.map +1 -0
  86. package/lib/bridge/synchronization.js +100 -0
  87. package/lib/bridge/synchronization.js.map +1 -0
  88. package/lib/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
  89. package/lib/bridge/transaction.d.ts.map +1 -0
  90. package/lib/{transaction.js → bridge/transaction.js} +3 -3
  91. package/lib/bridge/transaction.js.map +1 -0
  92. package/lib/config.d.ts +3 -4
  93. package/lib/config.d.ts.map +1 -1
  94. package/lib/config.js.map +1 -1
  95. package/lib/index.d.ts +1 -1
  96. package/lib/index.d.ts.map +1 -1
  97. package/lib/index.js +3 -1
  98. package/lib/index.js.map +1 -1
  99. package/lib/logic/craftTransaction.d.ts.map +1 -1
  100. package/lib/logic/craftTransaction.js +0 -7
  101. package/lib/logic/craftTransaction.js.map +1 -1
  102. package/lib/logic/craftTransaction.test.js +0 -1
  103. package/lib/logic/craftTransaction.test.js.map +1 -1
  104. package/lib/logic/estimateFees.d.ts.map +1 -1
  105. package/lib/logic/estimateFees.integ.test.js +2 -8
  106. package/lib/logic/estimateFees.integ.test.js.map +1 -1
  107. package/lib/logic/estimateFees.js +45 -119
  108. package/lib/logic/estimateFees.js.map +1 -1
  109. package/lib/logic/getBalance.js +1 -1
  110. package/lib/logic/getBalance.js.map +1 -1
  111. package/lib/logic/index.d.ts +0 -2
  112. package/lib/logic/index.d.ts.map +1 -1
  113. package/lib/logic/index.js +1 -5
  114. package/lib/logic/index.js.map +1 -1
  115. package/lib/logic/listOperations.d.ts.map +1 -1
  116. package/lib/logic/listOperations.js +10 -56
  117. package/lib/logic/listOperations.js.map +1 -1
  118. package/lib/logic/listOperations.test.js +10 -14
  119. package/lib/logic/listOperations.test.js.map +1 -1
  120. package/lib/types/bridge.d.ts +0 -3
  121. package/lib/types/bridge.d.ts.map +1 -1
  122. package/lib/types/bridge.fixture.d.ts.map +1 -1
  123. package/lib/types/bridge.fixture.js +0 -1
  124. package/lib/types/bridge.fixture.js.map +1 -1
  125. package/lib/types/bridge.js.map +1 -1
  126. package/lib-es/api/index.d.ts.map +1 -1
  127. package/lib-es/api/index.js +41 -189
  128. package/lib-es/api/index.js.map +1 -1
  129. package/lib-es/api/index.test.js +10 -79
  130. package/lib-es/api/index.test.js.map +1 -1
  131. package/lib-es/api/types.d.ts +5 -7
  132. package/lib-es/api/types.d.ts.map +1 -1
  133. package/lib-es/bridge/broadcast.d.ts +4 -0
  134. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  135. package/lib-es/bridge/broadcast.js +7 -0
  136. package/lib-es/bridge/broadcast.js.map +1 -0
  137. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  138. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  139. package/lib-es/bridge/broadcast.test.js +31 -0
  140. package/lib-es/bridge/broadcast.test.js.map +1 -0
  141. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  142. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  143. package/lib-es/bridge/buildOptimisticOperation.js +21 -0
  144. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  145. package/lib-es/bridge/createTransaction.d.ts +4 -0
  146. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  147. package/lib-es/bridge/createTransaction.js +17 -0
  148. package/lib-es/bridge/createTransaction.js.map +1 -0
  149. package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
  150. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  151. package/lib-es/bridge/estimateMaxSpendable.js +23 -0
  152. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  153. package/lib-es/bridge/getFeesForTransaction.d.ts +21 -0
  154. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
  155. package/lib-es/bridge/getFeesForTransaction.js +33 -0
  156. package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
  157. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  158. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  159. package/lib-es/bridge/getTransactionStatus.js +101 -0
  160. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  161. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  162. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  163. package/lib-es/bridge/getTransactionStatus.test.js +102 -0
  164. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  165. package/lib-es/bridge/index.d.ts +10 -0
  166. package/lib-es/bridge/index.d.ts.map +1 -0
  167. package/lib-es/bridge/index.js +53 -0
  168. package/lib-es/bridge/index.js.map +1 -0
  169. package/lib-es/bridge/logic.d.ts +10 -0
  170. package/lib-es/bridge/logic.d.ts.map +1 -0
  171. package/lib-es/bridge/logic.js +145 -0
  172. package/lib-es/bridge/logic.js.map +1 -0
  173. package/lib-es/bridge/preload.d.ts +9 -0
  174. package/lib-es/bridge/preload.d.ts.map +1 -0
  175. package/lib-es/bridge/preload.js +17 -0
  176. package/lib-es/bridge/preload.js.map +1 -0
  177. package/lib-es/bridge/prepareTransaction.d.ts +5 -0
  178. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  179. package/lib-es/bridge/prepareTransaction.integ.test.d.ts +2 -0
  180. package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
  181. package/lib-es/bridge/prepareTransaction.integ.test.js +29 -0
  182. package/lib-es/bridge/prepareTransaction.integ.test.js.map +1 -0
  183. package/lib-es/bridge/prepareTransaction.js +50 -0
  184. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  185. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  186. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  187. package/lib-es/bridge/prepareTransaction.test.js +173 -0
  188. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  189. package/lib-es/bridge/serialization.d.ts +7 -0
  190. package/lib-es/bridge/serialization.d.ts.map +1 -0
  191. package/lib-es/bridge/serialization.js +20 -0
  192. package/lib-es/bridge/serialization.js.map +1 -0
  193. package/lib-es/bridge/signOperation.d.ts +16 -0
  194. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  195. package/lib-es/bridge/signOperation.js +83 -0
  196. package/lib-es/bridge/signOperation.js.map +1 -0
  197. package/lib-es/bridge/signOperation.test.d.ts +2 -0
  198. package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
  199. package/lib-es/bridge/signOperation.test.js +255 -0
  200. package/lib-es/bridge/signOperation.test.js.map +1 -0
  201. package/lib-es/bridge/synchronization.d.ts +5 -0
  202. package/lib-es/bridge/synchronization.d.ts.map +1 -0
  203. package/lib-es/bridge/synchronization.integ.test.d.ts +2 -0
  204. package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
  205. package/lib-es/bridge/synchronization.integ.test.js +27 -0
  206. package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
  207. package/lib-es/bridge/synchronization.js +70 -0
  208. package/lib-es/bridge/synchronization.js.map +1 -0
  209. package/lib-es/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
  210. package/lib-es/bridge/transaction.d.ts.map +1 -0
  211. package/lib-es/{transaction.js → bridge/transaction.js} +3 -3
  212. package/lib-es/bridge/transaction.js.map +1 -0
  213. package/lib-es/config.d.ts +3 -4
  214. package/lib-es/config.d.ts.map +1 -1
  215. package/lib-es/config.js.map +1 -1
  216. package/lib-es/index.d.ts +1 -1
  217. package/lib-es/index.d.ts.map +1 -1
  218. package/lib-es/index.js +1 -1
  219. package/lib-es/index.js.map +1 -1
  220. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  221. package/lib-es/logic/craftTransaction.js +0 -7
  222. package/lib-es/logic/craftTransaction.js.map +1 -1
  223. package/lib-es/logic/craftTransaction.test.js +0 -1
  224. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  225. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  226. package/lib-es/logic/estimateFees.integ.test.js +2 -8
  227. package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
  228. package/lib-es/logic/estimateFees.js +45 -119
  229. package/lib-es/logic/estimateFees.js.map +1 -1
  230. package/lib-es/logic/getBalance.js +1 -1
  231. package/lib-es/logic/getBalance.js.map +1 -1
  232. package/lib-es/logic/index.d.ts +0 -2
  233. package/lib-es/logic/index.d.ts.map +1 -1
  234. package/lib-es/logic/index.js +0 -2
  235. package/lib-es/logic/index.js.map +1 -1
  236. package/lib-es/logic/listOperations.d.ts.map +1 -1
  237. package/lib-es/logic/listOperations.js +10 -56
  238. package/lib-es/logic/listOperations.js.map +1 -1
  239. package/lib-es/logic/listOperations.test.js +10 -14
  240. package/lib-es/logic/listOperations.test.js.map +1 -1
  241. package/lib-es/types/bridge.d.ts +0 -3
  242. package/lib-es/types/bridge.d.ts.map +1 -1
  243. package/lib-es/types/bridge.fixture.d.ts.map +1 -1
  244. package/lib-es/types/bridge.fixture.js +0 -1
  245. package/lib-es/types/bridge.fixture.js.map +1 -1
  246. package/lib-es/types/bridge.js.map +1 -1
  247. package/package.json +14 -11
  248. package/src/api/index.test.ts +15 -87
  249. package/src/api/index.ts +55 -204
  250. package/src/api/types.ts +6 -11
  251. package/src/bridge/broadcast.test.ts +36 -0
  252. package/src/bridge/broadcast.ts +13 -0
  253. package/src/bridge/buildOptimisticOperation.ts +28 -0
  254. package/src/bridge/createTransaction.ts +19 -0
  255. package/src/bridge/estimateMaxSpendable.ts +37 -0
  256. package/src/bridge/getFeesForTransaction.ts +49 -0
  257. package/src/bridge/getTransactionStatus.test.ts +124 -0
  258. package/src/bridge/getTransactionStatus.ts +123 -0
  259. package/src/bridge/index.ts +74 -0
  260. package/src/bridge/logic.ts +171 -0
  261. package/src/bridge/preload.ts +18 -0
  262. package/src/bridge/prepareTransaction.integ.test.ts +35 -0
  263. package/src/bridge/prepareTransaction.test.ts +205 -0
  264. package/src/bridge/prepareTransaction.ts +69 -0
  265. package/src/bridge/serialization.ts +27 -0
  266. package/src/bridge/signOperation.test.ts +284 -0
  267. package/src/bridge/signOperation.ts +130 -0
  268. package/src/bridge/synchronization.integ.test.ts +33 -0
  269. package/src/bridge/synchronization.ts +100 -0
  270. package/src/{transaction.ts → bridge/transaction.ts} +4 -4
  271. package/src/config.ts +2 -9
  272. package/src/index.ts +2 -1
  273. package/src/logic/craftTransaction.test.ts +0 -1
  274. package/src/logic/craftTransaction.ts +0 -8
  275. package/src/logic/estimateFees.integ.test.ts +2 -8
  276. package/src/logic/estimateFees.ts +49 -140
  277. package/src/logic/getBalance.ts +1 -1
  278. package/src/logic/index.ts +0 -2
  279. package/src/logic/listOperations.test.ts +54 -64
  280. package/src/logic/listOperations.ts +9 -57
  281. package/src/types/bridge.fixture.ts +0 -1
  282. package/src/types/bridge.ts +1 -6
  283. package/lib/logic/getStakes.d.ts +0 -3
  284. package/lib/logic/getStakes.d.ts.map +0 -1
  285. package/lib/logic/getStakes.js +0 -26
  286. package/lib/logic/getStakes.js.map +0 -1
  287. package/lib/logic/getStakes.test.d.ts +0 -2
  288. package/lib/logic/getStakes.test.d.ts.map +0 -1
  289. package/lib/logic/getStakes.test.js +0 -133
  290. package/lib/logic/getStakes.test.js.map +0 -1
  291. package/lib/logic/validateIntent.d.ts +0 -3
  292. package/lib/logic/validateIntent.d.ts.map +0 -1
  293. package/lib/logic/validateIntent.js +0 -179
  294. package/lib/logic/validateIntent.js.map +0 -1
  295. package/lib/logic/validateIntent.test.d.ts +0 -2
  296. package/lib/logic/validateIntent.test.d.ts.map +0 -1
  297. package/lib/logic/validateIntent.test.js +0 -249
  298. package/lib/logic/validateIntent.test.js.map +0 -1
  299. package/lib/transaction.d.ts.map +0 -1
  300. package/lib/transaction.js.map +0 -1
  301. package/lib/utils.d.ts +0 -48
  302. package/lib/utils.d.ts.map +0 -1
  303. package/lib/utils.js +0 -112
  304. package/lib/utils.js.map +0 -1
  305. package/lib-es/logic/getStakes.d.ts +0 -3
  306. package/lib-es/logic/getStakes.d.ts.map +0 -1
  307. package/lib-es/logic/getStakes.js +0 -20
  308. package/lib-es/logic/getStakes.js.map +0 -1
  309. package/lib-es/logic/getStakes.test.d.ts +0 -2
  310. package/lib-es/logic/getStakes.test.d.ts.map +0 -1
  311. package/lib-es/logic/getStakes.test.js +0 -128
  312. package/lib-es/logic/getStakes.test.js.map +0 -1
  313. package/lib-es/logic/validateIntent.d.ts +0 -3
  314. package/lib-es/logic/validateIntent.d.ts.map +0 -1
  315. package/lib-es/logic/validateIntent.js +0 -173
  316. package/lib-es/logic/validateIntent.js.map +0 -1
  317. package/lib-es/logic/validateIntent.test.d.ts +0 -2
  318. package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
  319. package/lib-es/logic/validateIntent.test.js +0 -221
  320. package/lib-es/logic/validateIntent.test.js.map +0 -1
  321. package/lib-es/transaction.d.ts.map +0 -1
  322. package/lib-es/transaction.js.map +0 -1
  323. package/lib-es/utils.d.ts +0 -48
  324. package/lib-es/utils.d.ts.map +0 -1
  325. package/lib-es/utils.js +0 -105
  326. package/lib-es/utils.js.map +0 -1
  327. package/src/logic/getStakes.test.ts +0 -145
  328. package/src/logic/getStakes.ts +0 -20
  329. package/src/logic/validateIntent.test.ts +0 -262
  330. package/src/logic/validateIntent.ts +0 -207
  331. package/src/utils.ts +0 -115
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-tezos",
3
- "version": "6.6.0-nightly.1",
3
+ "version": "6.6.0",
4
4
  "description": "Tezos Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -56,8 +56,8 @@
56
56
  "default": "./lib-es/test/bot-specs.js"
57
57
  },
58
58
  "./transaction": {
59
- "require": "./lib/transaction.js",
60
- "default": "./lib-es/transaction.js"
59
+ "require": "./lib/bridge/transaction.js",
60
+ "default": "./lib-es/bridge/transaction.js"
61
61
  },
62
62
  "./*": {
63
63
  "require": "./lib/*.js",
@@ -72,20 +72,24 @@
72
72
  "@taquito/taquito": "^23.0.0-RC.0",
73
73
  "@taquito/utils": "^23.0.0-RC.0",
74
74
  "bignumber.js": "^9.1.2",
75
+ "@noble/hashes": "1.8.0",
76
+ "bs58check": "^3.0.1",
75
77
  "invariant": "^2.2.4",
76
78
  "lodash": "^4.17.21",
77
79
  "rxjs": "^7.8.1",
78
- "@ledgerhq/coin-framework": "^6.6.0-nightly.1",
79
- "@ledgerhq/cryptoassets": "^13.30.0-nightly.0",
80
- "@ledgerhq/devices": "8.6.0",
81
- "@ledgerhq/errors": "^6.26.0-nightly.0",
82
- "@ledgerhq/live-network": "^2.0.18",
80
+ "@ledgerhq/coin-framework": "^6.6.0",
81
+ "@ledgerhq/cryptoassets": "^13.30.0",
82
+ "@ledgerhq/devices": "8.6.1",
83
+ "@ledgerhq/errors": "^6.26.0",
84
+ "@ledgerhq/live-network": "^2.0.19",
83
85
  "@ledgerhq/logs": "^6.13.0",
84
- "@ledgerhq/types-live": "^6.86.0-nightly.0"
86
+ "@ledgerhq/types-cryptoassets": "^7.28.0",
87
+ "@ledgerhq/types-live": "^6.86.0"
85
88
  },
86
89
  "devDependencies": {
87
90
  "@faker-js/faker": "^8.4.1",
88
91
  "@taquito/local-forging": "^23.0.0-RC.0",
92
+ "@types/bs58check": "^2.1.2",
89
93
  "@types/invariant": "^2.2.37",
90
94
  "@types/jest": "^29.5.12",
91
95
  "@types/lodash": "^4.17.4",
@@ -93,8 +97,7 @@
93
97
  "msw": "^2.7.3",
94
98
  "ts-jest": "^29.1.4",
95
99
  "typescript": "^5.4.5",
96
- "@ledgerhq/disable-network-setup": "^0.0.0",
97
- "@ledgerhq/types-cryptoassets": "^7.28.0-nightly.0"
100
+ "@ledgerhq/disable-network-setup": "^0.0.0"
98
101
  },
99
102
  "overrides": {
100
103
  "@taquito/ledger-signer": {
@@ -24,18 +24,11 @@ jest.mock("../logic", () => ({
24
24
  rawEncode: () => Promise.resolve("tz1heMGVHQnx7ALDcDKqez8fan64Eyicw4DJ"),
25
25
  }));
26
26
 
27
- jest.spyOn(networkApi, "getAccountByAddress").mockResolvedValue({
28
- type: "user",
29
- balance: 1000,
30
- revealed: true,
31
- address: "tz1test",
32
- publicKey: "edpktest",
33
- counter: 0,
34
- delegationLevel: 0,
35
- delegationTime: "2021-01-01T00:00:00Z",
36
- numTransactions: 0,
37
- firstActivityTime: "2021-01-01T00:00:00Z",
38
- } as APIAccount);
27
+ jest
28
+ .spyOn(networkApi, "getAccountByAddress")
29
+ .mockImplementation((_adress: string) =>
30
+ Promise.resolve({ type: "user", balance: 1000 } as APIAccount),
31
+ );
39
32
 
40
33
  const api = createApi({
41
34
  baker: {
@@ -101,27 +94,12 @@ describe("Testing craftTransaction function", () => {
101
94
  beforeEach(() => jest.clearAllMocks());
102
95
 
103
96
  it("should use estimated fees when user does not provide them for crafting a transaction ", async () => {
104
- logicEstimateFees.mockResolvedValue({
105
- estimatedFees: DEFAULT_ESTIMATED_FEES,
106
- gasLimit: DEFAULT_GAS_LIMIT,
107
- storageLimit: DEFAULT_STORAGE_LIMIT,
108
- });
109
- await api.craftTransaction({
110
- type: "send",
111
- sender: "tz1test",
112
- recipient: "tz1recipient",
113
- amount: 1000n,
114
- } as TezosTransactionIntent);
97
+ logicEstimateFees.mockResolvedValue({ estimatedFees: DEFAULT_ESTIMATED_FEES });
98
+ await api.craftTransaction({ type: "send", sender: {} } as TezosTransactionIntent);
115
99
  expect(logicEstimateFees).toHaveBeenCalledTimes(1);
116
100
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
117
- expect.objectContaining({ address: "tz1test" }),
118
- expect.objectContaining({
119
- fee: expect.objectContaining({
120
- fees: DEFAULT_ESTIMATED_FEES.toString(),
121
- gasLimit: DEFAULT_GAS_LIMIT.toString(),
122
- storageLimit: DEFAULT_STORAGE_LIMIT.toString(),
123
- }),
124
- }),
101
+ expect.any(Object),
102
+ expect.objectContaining({ fee: { fees: DEFAULT_ESTIMATED_FEES.toString() } }),
125
103
  );
126
104
  });
127
105
 
@@ -132,22 +110,10 @@ describe("Testing craftTransaction function", () => {
132
110
  estimatedFees: DEFAULT_ESTIMATED_FEES,
133
111
  gasLimit: DEFAULT_GAS_LIMIT,
134
112
  storageLimit: DEFAULT_STORAGE_LIMIT,
135
- parameters: {
136
- gasLimit: DEFAULT_GAS_LIMIT,
137
- storageLimit: DEFAULT_STORAGE_LIMIT,
138
- },
139
113
  });
140
- await api.craftTransaction(
141
- {
142
- type: "send",
143
- sender: "tz1test",
144
- recipient: "tz1recipient",
145
- amount: 1000n,
146
- } as TezosTransactionIntent,
147
- {
148
- value: customFees,
149
- },
150
- );
114
+ await api.craftTransaction({ type: "send", sender: {} } as TezosTransactionIntent, {
115
+ value: customFees,
116
+ });
151
117
  expect(logicEstimateFees).toHaveBeenCalledTimes(1);
152
118
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
153
119
  expect.any(Object),
@@ -172,12 +138,7 @@ describe("Testing estimateFees function", () => {
172
138
  gasLimit: DEFAULT_GAS_LIMIT,
173
139
  storageLimit: DEFAULT_STORAGE_LIMIT,
174
140
  });
175
- const result = await api.estimateFees({
176
- type: "send",
177
- sender: "tz1test",
178
- recipient: "tz1recipient",
179
- amount: 1000n,
180
- } as TezosTransactionIntent);
141
+ const result = await api.estimateFees({ type: "send", sender: {} } as TezosTransactionIntent);
181
142
  expect(result).toEqual({
182
143
  value: DEFAULT_ESTIMATED_FEES,
183
144
  parameters: {
@@ -188,42 +149,9 @@ describe("Testing estimateFees function", () => {
188
149
  });
189
150
 
190
151
  it("should throw taquito errors", async () => {
191
- logicEstimateFees.mockResolvedValue({
192
- estimatedFees: DEFAULT_ESTIMATED_FEES,
193
- gasLimit: DEFAULT_GAS_LIMIT,
194
- storageLimit: DEFAULT_STORAGE_LIMIT,
195
- taquitoError: "test",
196
- });
152
+ logicEstimateFees.mockResolvedValue({ taquitoError: "test" });
197
153
  await expect(
198
- api.estimateFees({
199
- type: "send",
200
- sender: "tz1test",
201
- recipient: "tz1recipient",
202
- amount: 1000n,
203
- } as TezosTransactionIntent),
154
+ api.estimateFees({ type: "send", sender: {} } as TezosTransactionIntent),
204
155
  ).rejects.toThrow("Fees estimation failed: test");
205
156
  });
206
-
207
- it("should not throw for delegate.unchanged errors", async () => {
208
- logicEstimateFees.mockResolvedValue({
209
- estimatedFees: DEFAULT_ESTIMATED_FEES,
210
- gasLimit: DEFAULT_GAS_LIMIT,
211
- storageLimit: DEFAULT_STORAGE_LIMIT,
212
- taquitoError: "proto.022-PsRiotum.delegate.unchanged",
213
- });
214
- const result = await api.estimateFees({
215
- type: "delegate",
216
- sender: "tz1test",
217
- recipient: "tz1validator",
218
- amount: 0n,
219
- } as TezosTransactionIntent);
220
-
221
- expect(result).toEqual({
222
- value: DEFAULT_ESTIMATED_FEES,
223
- parameters: {
224
- gasLimit: DEFAULT_GAS_LIMIT,
225
- storageLimit: DEFAULT_STORAGE_LIMIT,
226
- },
227
- });
228
- });
229
157
  });
package/src/api/index.ts CHANGED
@@ -21,20 +21,11 @@ import {
21
21
  lastBlock,
22
22
  listOperations,
23
23
  rawEncode,
24
- validateIntent,
25
- getStakes,
26
24
  } from "../logic";
27
25
  import api from "../network/tzkt";
28
26
  import type { TezosApi, TezosFeeEstimation } from "./types";
29
- import type { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
30
- import { RecommendUndelegation } from "@ledgerhq/errors";
31
- import { validatePublicKey, ValidationResult, getPkhfromPk } from "@taquito/utils";
32
- import { getRevealFee } from "@taquito/taquito";
33
- import {
34
- DUST_MARGIN_MUTEZ,
35
- mapIntentTypeToTezosMode,
36
- normalizePublicKeyForAddress,
37
- } from "../utils";
27
+ import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
28
+ import { TezosOperationMode } from "../types";
38
29
 
39
30
  export function createApi(config: TezosConfig): TezosApi {
40
31
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
@@ -47,54 +38,31 @@ export function createApi(config: TezosConfig): TezosApi {
47
38
  getBalance: balance,
48
39
  lastBlock,
49
40
  listOperations: operations,
50
- getStakes,
51
- validateIntent,
52
- // required by signer to compute next valid sequence/counter
53
- getSequence: async (address: string) => {
54
- const accountInfo = await api.getAccountByAddress(address);
55
- return accountInfo.type === "user" ? accountInfo.counter + 1 : 0;
56
- },
57
41
  getBlock(_height): Promise<Block> {
58
42
  throw new Error("getBlock is not supported");
59
43
  },
60
44
  getBlockInfo(_height: number): Promise<BlockInfo> {
61
45
  throw new Error("getBlockInfo is not supported");
62
46
  },
47
+ getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
48
+ throw new Error("getStakes is not supported");
49
+ },
63
50
  getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
64
51
  throw new Error("getRewards is not supported");
65
52
  },
66
53
  };
67
54
  }
68
55
 
69
- function isTezosTransactionType(
70
- type: string,
71
- ): type is "send" | "delegate" | "undelegate" | "stake" | "unstake" {
72
- return ["send", "delegate", "undelegate", "stake", "unstake"].includes(type);
56
+ function isTezosTransactionType(type: string): type is "send" | "delegate" | "undelegate" {
57
+ return ["send", "delegate", "undelegate"].includes(type);
73
58
  }
74
59
 
75
60
  async function balance(address: string): Promise<Balance[]> {
76
61
  const value = await getBalance(address);
77
- const accountInfo = await api.getAccountByAddress(address);
78
- // tzkt returns `type: "empty"` for untouched accounts; legacy logic returns -1 in that case
79
- // the generic bridge expects non-negative balances
80
- const normalized = value < 0n ? 0n : value;
81
- // include stake information so ui can reflect delegation on account page
82
- const stake: Stake | undefined =
83
- accountInfo.type === "user" && accountInfo.delegate?.address
84
- ? {
85
- uid: address,
86
- address,
87
- delegate: accountInfo.delegate.address,
88
- state: "active",
89
- asset: { type: "native" },
90
- amount: BigInt(accountInfo.balance ?? 0),
91
- }
92
- : undefined;
93
62
  return [
94
63
  {
95
- value: normalized,
64
+ value,
96
65
  asset: { type: "native" },
97
- stake,
98
66
  },
99
67
  ];
100
68
  }
@@ -107,180 +75,64 @@ async function craft(
107
75
  throw new IncorrectTypeError(transactionIntent.type);
108
76
  }
109
77
 
110
- // Always estimate to get gasLimit/storageLimit
111
- const estimation = await estimate(transactionIntent);
112
- const fee = {
113
- fees: (customFees?.value ?? estimation.value).toString(),
114
- gasLimit: estimation.parameters?.gasLimit?.toString(),
115
- storageLimit: estimation.parameters?.storageLimit?.toString(),
116
- };
117
-
118
- // Map generic staking intents to tezos modes
119
- const mappedType = mapIntentTypeToTezosMode(transactionIntent.type);
120
-
121
- // Guard: send max is incompatible with delegated accounts
122
- let amountToUse = transactionIntent.amount;
123
- if (mappedType === "send" && transactionIntent.useAllAmount) {
124
- const senderInfo = await api.getAccountByAddress(transactionIntent.sender);
125
- if (senderInfo.type === "user" && senderInfo.delegate?.address) {
126
- throw new RecommendUndelegation();
127
- }
128
- if (senderInfo.type === "user") {
129
- // Use the amount calculated by the estimation which includes proper buffers and adjustments
130
- if (estimation.parameters?.amount !== undefined) {
131
- amountToUse = estimation.parameters.amount;
132
- } else {
133
- // Fallback to the original calculation if estimation doesn't provide amount
134
- const bal = BigInt(senderInfo.balance);
135
- const feeBI = BigInt(fee.fees || "0");
136
- const dustMargin = BigInt(DUST_MARGIN_MUTEZ);
137
- const totalToDeduct = feeBI + dustMargin;
138
- amountToUse = bal > totalToDeduct ? bal - totalToDeduct : 0n;
139
- }
140
- } else {
141
- amountToUse = 0n;
142
- }
143
- }
78
+ // note that an estimation is always necessary to get gasLimit and storageLimit, if even using custom fees
79
+ const fee = await estimate(transactionIntent).then(fees => ({
80
+ fees: (customFees?.value ?? fees.value).toString(),
81
+ gasLimit: fees.parameters?.gasLimit?.toString(),
82
+ storageLimit: fees.parameters?.storageLimit?.toString(),
83
+ }));
144
84
 
145
- const accountForCraft = {
146
- address: transactionIntent.sender,
147
- };
148
- const senderApiAcc = await api.getAccountByAddress(transactionIntent.sender);
149
- const needsReveal = senderApiAcc.type === "user" && !senderApiAcc.revealed;
150
- const totalFee = Number(fee.fees || "0");
151
-
152
- let txFee: number;
153
- if (customFees) {
154
- txFee = totalFee;
155
- } else if (estimation.parameters?.txFee !== undefined) {
156
- txFee = Number(estimation.parameters.txFee);
157
- } else {
158
- txFee = needsReveal ? Math.max(totalFee - getRevealFee(transactionIntent.sender), 0) : totalFee;
159
- }
160
-
161
- const txForCraft = {
162
- type: mappedType,
163
- recipient: transactionIntent.recipient,
164
- amount: amountToUse,
165
- fee: { ...fee, fees: txFee.toString() },
166
- };
167
- const publicKeyForCraft =
168
- needsReveal && transactionIntent.senderPublicKey
169
- ? (() => {
170
- // Accept either base58 or hex from device, and map curve using sender address
171
- let pk = transactionIntent.senderPublicKey;
172
- if (validatePublicKey(pk) !== ValidationResult.VALID) {
173
- pk = normalizePublicKeyForAddress(pk, transactionIntent.sender) || pk;
174
- }
175
- // Verify the public key matches the sender address to avoid inconsistent_hash
176
- let isPublicKeyValid = false;
177
- try {
178
- const derived = getPkhfromPk(pk);
179
- isPublicKeyValid = derived === transactionIntent.sender;
180
- } catch {
181
- // getPkhfromPk failed = will fallback to basic validation below
182
- isPublicKeyValid = false;
183
- }
85
+ const { contents } = await craftTransaction(
86
+ { address: transactionIntent.sender },
87
+ {
88
+ type: transactionIntent.type,
89
+ recipient: transactionIntent.recipient,
90
+ amount: transactionIntent.amount,
91
+ fee,
92
+ },
93
+ );
184
94
 
185
- if (!isPublicKeyValid) {
186
- // If derivation failed/doesn't match, check if the key is atleast valid format
187
- if (validatePublicKey(pk) !== ValidationResult.VALID) {
188
- throw new Error("Unable to normalize sender public key");
189
- }
190
- }
191
- return { publicKey: pk, publicKeyHash: transactionIntent.sender };
192
- })()
193
- : undefined;
194
- const { contents } = await craftTransaction(accountForCraft, txForCraft, publicKeyForCraft);
195
95
  const tx = await rawEncode(contents);
96
+
196
97
  return { transaction: tx };
197
98
  }
198
99
 
199
100
  async function estimate(transactionIntent: TransactionIntent): Promise<TezosFeeEstimation> {
200
- // avoid taquito error when estimating a 0-amount transfer during input
201
- if (
202
- transactionIntent.type === "send" &&
203
- transactionIntent.amount === 0n &&
204
- !transactionIntent.useAllAmount
205
- ) {
206
- return {
207
- value: BigInt(DUST_MARGIN_MUTEZ),
208
- parameters: {
209
- gasLimit: 10000n,
210
- storageLimit: 300n,
211
- amount: 0n,
212
- txFee: BigInt(DUST_MARGIN_MUTEZ),
213
- },
214
- };
215
- }
216
101
  const senderAccountInfo = await api.getAccountByAddress(transactionIntent.sender);
217
- // If the sender is not a user account, return default estimation values
218
- if (senderAccountInfo.type !== "user") {
219
- return {
220
- value: BigInt(DUST_MARGIN_MUTEZ),
221
- parameters: {
222
- gasLimit: 10000n,
223
- storageLimit: 300n,
224
- amount: 0n,
225
- txFee: BigInt(DUST_MARGIN_MUTEZ),
226
- },
227
- };
228
- }
229
102
 
230
- try {
231
- const estimation = await estimateFees({
232
- account: {
233
- address: transactionIntent.sender,
234
- revealed: senderAccountInfo.revealed,
235
- balance: BigInt(senderAccountInfo.balance),
236
- // try intent public key first and fallback to tzkt public key
237
- xpub: transactionIntent.senderPublicKey ?? senderAccountInfo.publicKey,
238
- },
239
- transaction: {
240
- // reuse the same mapping as craft
241
- mode: mapIntentTypeToTezosMode(transactionIntent.type),
242
- recipient: transactionIntent.recipient,
243
- amount: transactionIntent.amount,
244
- // legacy estimator needs this flag to pre-estimate fees
245
- useAllAmount: !!transactionIntent.useAllAmount,
246
- },
247
- });
248
-
249
- if (
250
- estimation.taquitoError &&
251
- !estimation.taquitoError.includes("delegate.unchanged") &&
252
- !estimation.taquitoError.includes("subtraction_underflow") &&
253
- !estimation.taquitoError.includes("balance_too_low")
254
- ) {
255
- throw new Error(`Fees estimation failed: ${estimation.taquitoError}`);
256
- }
103
+ const {
104
+ estimatedFees: value,
105
+ gasLimit,
106
+ storageLimit,
107
+ taquitoError,
108
+ } = await estimateFees({
109
+ account: {
110
+ address: transactionIntent.sender,
111
+ revealed: senderAccountInfo.type === "user" && senderAccountInfo.revealed,
112
+ balance: BigInt(senderAccountInfo.type === "user" ? senderAccountInfo.balance : 0),
113
+ // NOTE: previously we checked for .sender.xpub
114
+ xpub:
115
+ transactionIntent.senderPublicKey ??
116
+ (senderAccountInfo.type === "user" ? senderAccountInfo.publicKey : undefined),
117
+ },
118
+ transaction: {
119
+ mode: transactionIntent.type as TezosOperationMode,
120
+ recipient: transactionIntent.recipient,
121
+ amount: transactionIntent.amount,
122
+ },
123
+ });
257
124
 
258
- return {
259
- value: estimation.estimatedFees,
260
- parameters: {
261
- gasLimit: estimation.gasLimit,
262
- storageLimit: estimation.storageLimit,
263
- amount: estimation.amount,
264
- txFee: estimation.fees,
265
- },
266
- };
267
- } catch (error: any) {
268
- // Handle PublicKeyNotFoundError
269
- if (error?.message?.includes("Public key not found")) {
270
- return {
271
- value: 1000n, // Safe default with reveal fees (500 + 374 reveal + buffer)
272
- parameters: {
273
- gasLimit: 10000n,
274
- storageLimit: 300n,
275
- amount: 0n,
276
- txFee: 1000n,
277
- },
278
- };
279
- } else {
280
- // Re-throw other errors
281
- throw error;
282
- }
125
+ if (taquitoError !== undefined) {
126
+ throw new Error(`Fees estimation failed: ${taquitoError}`);
283
127
  }
128
+
129
+ return {
130
+ value,
131
+ parameters: {
132
+ gasLimit,
133
+ storageLimit,
134
+ },
135
+ };
284
136
  }
285
137
 
286
138
  async function operations(
@@ -293,6 +145,5 @@ async function operations(
293
145
  sort: pagination.order === "asc" ? "Ascending" : "Descending",
294
146
  minHeight: pagination.minHeight,
295
147
  });
296
-
297
148
  return [operations, newNextCursor || ""];
298
149
  }
package/src/api/types.ts CHANGED
@@ -1,16 +1,11 @@
1
- import type { Api, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
1
+ import { AlpacaApi, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
2
2
 
3
- export type TezosFeeParameters = {
4
- gasLimit: bigint;
5
- storageLimit: bigint;
6
- amount?: bigint;
7
- txFee?: bigint;
8
- };
9
- export type TezosFeeEstimation = FeeEstimation & {
10
- parameters?: TezosFeeParameters & Record<string, unknown>;
11
- };
3
+ export type TezosFeeParameters = { gasLimit: bigint; storageLimit: bigint };
4
+ export type TezosFeeEstimation = FeeEstimation;
12
5
 
13
6
  export type TezosSender = { address: string; xpub?: string };
14
7
  export type TezosTransactionIntent = TransactionIntent;
15
8
 
16
- export type TezosApi = Api;
9
+ export type TezosApi = AlpacaApi & {
10
+ estimateFees: (transactionIntent: TezosTransactionIntent) => Promise<TezosFeeEstimation>;
11
+ };
@@ -0,0 +1,36 @@
1
+ import { SignedOperation } from "@ledgerhq/types-live";
2
+ import { createFixtureOperation } from "../types/bridge.fixture";
3
+ import config, { type TezosCoinConfig } from "../config";
4
+ import { broadcast } from "./broadcast";
5
+ import { mockConfig } from "../test/config";
6
+
7
+ const mockInjectOperation = jest.fn();
8
+ jest.mock("@taquito/taquito", () => ({
9
+ TezosToolkit: jest.fn().mockReturnValue({
10
+ rpc: {
11
+ injectOperation: () => mockInjectOperation(),
12
+ },
13
+ }),
14
+ }));
15
+
16
+ describe("broadcast", () => {
17
+ beforeAll(() => {
18
+ config.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
19
+ });
20
+
21
+ it("calls 'injectOperation' from TezosToolkit and returns its hash computation", async () => {
22
+ // GIVEN
23
+ const signedOperation: SignedOperation = {
24
+ operation: createFixtureOperation(),
25
+ signature: "SIGNATURE",
26
+ };
27
+ mockInjectOperation.mockResolvedValue("SIGN_HASH");
28
+
29
+ // WHEN
30
+ const op = await broadcast({ signedOperation, account: {} as any });
31
+
32
+ // THEN
33
+ expect(mockInjectOperation).toHaveBeenCalledTimes(1);
34
+ expect(op.hash).toEqual("SIGN_HASH");
35
+ });
36
+ });
@@ -0,0 +1,13 @@
1
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
2
+ import { AccountBridge, SignedOperation } from "@ledgerhq/types-live";
3
+ import { Transaction } from "../types";
4
+ import { broadcast as logicBroadcast } from "../logic";
5
+
6
+ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
7
+ signedOperation: { operation, signature },
8
+ }: {
9
+ signedOperation: SignedOperation;
10
+ }) => {
11
+ const hash = await logicBroadcast(signature);
12
+ return patchOperationWithHash(operation, hash);
13
+ };
@@ -0,0 +1,28 @@
1
+ import { OperationType } from "@ledgerhq/types-live";
2
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
3
+ import { TezosAccount, TezosOperation, Transaction } from "../types";
4
+ import BigNumber from "bignumber.js";
5
+
6
+ export const buildOptimisticOperation = (
7
+ account: TezosAccount,
8
+ transaction: Transaction,
9
+ operationType: OperationType,
10
+ ): TezosOperation => {
11
+ const txHash = ""; // resolved at broadcast time
12
+ const { id: accountId } = account;
13
+
14
+ return {
15
+ id: encodeOperationId(accountId, txHash, operationType),
16
+ hash: txHash,
17
+ type: operationType,
18
+ value: transaction.amount,
19
+ fee: transaction.fees || new BigNumber(0),
20
+ extra: {},
21
+ blockHash: null,
22
+ blockHeight: null,
23
+ senders: [account.freshAddress],
24
+ recipients: [transaction.recipient],
25
+ accountId,
26
+ date: new Date(),
27
+ };
28
+ };
@@ -0,0 +1,19 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { Transaction } from "../types";
4
+
5
+ export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => {
6
+ return {
7
+ family: "tezos",
8
+ mode: "send",
9
+ amount: new BigNumber(0),
10
+ fees: null,
11
+ gasLimit: null,
12
+ storageLimit: null,
13
+ recipient: "",
14
+ networkInfo: null,
15
+ useAllAmount: false,
16
+ taquitoError: null,
17
+ estimatedFees: null,
18
+ };
19
+ };
@@ -0,0 +1,37 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account, AccountBridge, AccountLike } from "@ledgerhq/types-live";
3
+ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
+ import { TezosAccount, Transaction } from "../types";
5
+ import { prepareTransaction } from "./prepareTransaction";
6
+ import { createTransaction } from "./createTransaction";
7
+ import getEstimatedFees from "./getFeesForTransaction";
8
+
9
+ const TEZOS_BURN_ADDRESS = "tz1burnburnburnburnburnburnburjAYjjX";
10
+
11
+ export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
12
+ account,
13
+ parentAccount,
14
+ transaction,
15
+ }: {
16
+ account: AccountLike;
17
+ parentAccount: Account | undefined;
18
+ transaction: Transaction;
19
+ }): Promise<BigNumber> => {
20
+ const mainAccount = getMainAccount(account, parentAccount) as TezosAccount;
21
+ const tx = await prepareTransaction(mainAccount, {
22
+ ...createTransaction(account),
23
+ ...transaction,
24
+ // estimate using a burn address that exists so we don't enter into NotEnoughBalanceBecauseDestinationNotCreated
25
+ recipient: transaction?.recipient || TEZOS_BURN_ADDRESS,
26
+ useAllAmount: true,
27
+ });
28
+ const estimation = await getEstimatedFees({
29
+ account: mainAccount,
30
+ transaction: tx,
31
+ });
32
+
33
+ // As we use `useAllAmount`, we know we will receive an amount value.
34
+ return estimation.amount!;
35
+ };
36
+
37
+ export default estimateMaxSpendable;