@ledgerhq/coin-tezos 6.5.0 → 6.6.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 (330) hide show
  1. package/.unimportedrc.json +4 -30
  2. package/CHANGELOG.md +13 -0
  3. package/jest.integ.config.js +1 -0
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.js +188 -40
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/api/index.test.js +79 -10
  8. package/lib/api/index.test.js.map +1 -1
  9. package/lib/api/types.d.ts +7 -5
  10. package/lib/api/types.d.ts.map +1 -1
  11. package/lib/config.d.ts +4 -3
  12. package/lib/config.d.ts.map +1 -1
  13. package/lib/config.js.map +1 -1
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -3
  17. package/lib/index.js.map +1 -1
  18. package/lib/logic/craftTransaction.d.ts.map +1 -1
  19. package/lib/logic/craftTransaction.js +7 -0
  20. package/lib/logic/craftTransaction.js.map +1 -1
  21. package/lib/logic/craftTransaction.test.js +1 -0
  22. package/lib/logic/craftTransaction.test.js.map +1 -1
  23. package/lib/logic/estimateFees.d.ts.map +1 -1
  24. package/lib/logic/estimateFees.integ.test.js +8 -2
  25. package/lib/logic/estimateFees.integ.test.js.map +1 -1
  26. package/lib/logic/estimateFees.js +119 -45
  27. package/lib/logic/estimateFees.js.map +1 -1
  28. package/lib/logic/getBalance.js +1 -1
  29. package/lib/logic/getBalance.js.map +1 -1
  30. package/lib/logic/getStakes.d.ts +3 -0
  31. package/lib/logic/getStakes.d.ts.map +1 -0
  32. package/lib/logic/getStakes.js +26 -0
  33. package/lib/logic/getStakes.js.map +1 -0
  34. package/lib/logic/getStakes.test.d.ts +2 -0
  35. package/lib/logic/getStakes.test.d.ts.map +1 -0
  36. package/lib/logic/getStakes.test.js +133 -0
  37. package/lib/logic/getStakes.test.js.map +1 -0
  38. package/lib/logic/index.d.ts +2 -0
  39. package/lib/logic/index.d.ts.map +1 -1
  40. package/lib/logic/index.js +5 -1
  41. package/lib/logic/index.js.map +1 -1
  42. package/lib/logic/listOperations.d.ts.map +1 -1
  43. package/lib/logic/listOperations.js +56 -10
  44. package/lib/logic/listOperations.js.map +1 -1
  45. package/lib/logic/listOperations.test.js +14 -10
  46. package/lib/logic/listOperations.test.js.map +1 -1
  47. package/lib/logic/validateIntent.d.ts +3 -0
  48. package/lib/logic/validateIntent.d.ts.map +1 -0
  49. package/lib/logic/validateIntent.js +179 -0
  50. package/lib/logic/validateIntent.js.map +1 -0
  51. package/lib/logic/validateIntent.test.d.ts +2 -0
  52. package/lib/logic/validateIntent.test.d.ts.map +1 -0
  53. package/lib/logic/validateIntent.test.js +249 -0
  54. package/lib/logic/validateIntent.test.js.map +1 -0
  55. package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
  56. package/lib/transaction.d.ts.map +1 -0
  57. package/lib/{bridge/transaction.js → transaction.js} +3 -3
  58. package/lib/transaction.js.map +1 -0
  59. package/lib/types/bridge.d.ts +3 -0
  60. package/lib/types/bridge.d.ts.map +1 -1
  61. package/lib/types/bridge.fixture.d.ts.map +1 -1
  62. package/lib/types/bridge.fixture.js +1 -0
  63. package/lib/types/bridge.fixture.js.map +1 -1
  64. package/lib/types/bridge.js.map +1 -1
  65. package/lib/utils.d.ts +48 -0
  66. package/lib/utils.d.ts.map +1 -0
  67. package/lib/utils.js +112 -0
  68. package/lib/utils.js.map +1 -0
  69. package/lib-es/api/index.d.ts.map +1 -1
  70. package/lib-es/api/index.js +189 -41
  71. package/lib-es/api/index.js.map +1 -1
  72. package/lib-es/api/index.test.js +79 -10
  73. package/lib-es/api/index.test.js.map +1 -1
  74. package/lib-es/api/types.d.ts +7 -5
  75. package/lib-es/api/types.d.ts.map +1 -1
  76. package/lib-es/config.d.ts +4 -3
  77. package/lib-es/config.d.ts.map +1 -1
  78. package/lib-es/config.js.map +1 -1
  79. package/lib-es/index.d.ts +1 -1
  80. package/lib-es/index.d.ts.map +1 -1
  81. package/lib-es/index.js +1 -1
  82. package/lib-es/index.js.map +1 -1
  83. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  84. package/lib-es/logic/craftTransaction.js +7 -0
  85. package/lib-es/logic/craftTransaction.js.map +1 -1
  86. package/lib-es/logic/craftTransaction.test.js +1 -0
  87. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  88. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  89. package/lib-es/logic/estimateFees.integ.test.js +8 -2
  90. package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
  91. package/lib-es/logic/estimateFees.js +119 -45
  92. package/lib-es/logic/estimateFees.js.map +1 -1
  93. package/lib-es/logic/getBalance.js +1 -1
  94. package/lib-es/logic/getBalance.js.map +1 -1
  95. package/lib-es/logic/getStakes.d.ts +3 -0
  96. package/lib-es/logic/getStakes.d.ts.map +1 -0
  97. package/lib-es/logic/getStakes.js +20 -0
  98. package/lib-es/logic/getStakes.js.map +1 -0
  99. package/lib-es/logic/getStakes.test.d.ts +2 -0
  100. package/lib-es/logic/getStakes.test.d.ts.map +1 -0
  101. package/lib-es/logic/getStakes.test.js +128 -0
  102. package/lib-es/logic/getStakes.test.js.map +1 -0
  103. package/lib-es/logic/index.d.ts +2 -0
  104. package/lib-es/logic/index.d.ts.map +1 -1
  105. package/lib-es/logic/index.js +2 -0
  106. package/lib-es/logic/index.js.map +1 -1
  107. package/lib-es/logic/listOperations.d.ts.map +1 -1
  108. package/lib-es/logic/listOperations.js +56 -10
  109. package/lib-es/logic/listOperations.js.map +1 -1
  110. package/lib-es/logic/listOperations.test.js +14 -10
  111. package/lib-es/logic/listOperations.test.js.map +1 -1
  112. package/lib-es/logic/validateIntent.d.ts +3 -0
  113. package/lib-es/logic/validateIntent.d.ts.map +1 -0
  114. package/lib-es/logic/validateIntent.js +173 -0
  115. package/lib-es/logic/validateIntent.js.map +1 -0
  116. package/lib-es/logic/validateIntent.test.d.ts +2 -0
  117. package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
  118. package/lib-es/logic/validateIntent.test.js +221 -0
  119. package/lib-es/logic/validateIntent.test.js.map +1 -0
  120. package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
  121. package/lib-es/transaction.d.ts.map +1 -0
  122. package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
  123. package/lib-es/transaction.js.map +1 -0
  124. package/lib-es/types/bridge.d.ts +3 -0
  125. package/lib-es/types/bridge.d.ts.map +1 -1
  126. package/lib-es/types/bridge.fixture.d.ts.map +1 -1
  127. package/lib-es/types/bridge.fixture.js +1 -0
  128. package/lib-es/types/bridge.fixture.js.map +1 -1
  129. package/lib-es/types/bridge.js.map +1 -1
  130. package/lib-es/utils.d.ts +48 -0
  131. package/lib-es/utils.d.ts.map +1 -0
  132. package/lib-es/utils.js +105 -0
  133. package/lib-es/utils.js.map +1 -0
  134. package/package.json +9 -12
  135. package/src/api/index.test.ts +87 -15
  136. package/src/api/index.ts +204 -55
  137. package/src/api/types.ts +11 -6
  138. package/src/config.ts +9 -2
  139. package/src/index.ts +1 -2
  140. package/src/logic/craftTransaction.test.ts +1 -0
  141. package/src/logic/craftTransaction.ts +8 -0
  142. package/src/logic/estimateFees.integ.test.ts +8 -2
  143. package/src/logic/estimateFees.ts +140 -49
  144. package/src/logic/getBalance.ts +1 -1
  145. package/src/logic/getStakes.test.ts +145 -0
  146. package/src/logic/getStakes.ts +20 -0
  147. package/src/logic/index.ts +2 -0
  148. package/src/logic/listOperations.test.ts +64 -54
  149. package/src/logic/listOperations.ts +57 -9
  150. package/src/logic/validateIntent.test.ts +262 -0
  151. package/src/logic/validateIntent.ts +207 -0
  152. package/src/{bridge/transaction.ts → transaction.ts} +4 -4
  153. package/src/types/bridge.fixture.ts +1 -0
  154. package/src/types/bridge.ts +6 -1
  155. package/src/utils.ts +115 -0
  156. package/lib/bridge/broadcast.d.ts +0 -4
  157. package/lib/bridge/broadcast.d.ts.map +0 -1
  158. package/lib/bridge/broadcast.js +0 -11
  159. package/lib/bridge/broadcast.js.map +0 -1
  160. package/lib/bridge/broadcast.test.d.ts +0 -2
  161. package/lib/bridge/broadcast.test.d.ts.map +0 -1
  162. package/lib/bridge/broadcast.test.js +0 -36
  163. package/lib/bridge/broadcast.test.js.map +0 -1
  164. package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
  165. package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
  166. package/lib/bridge/buildOptimisticOperation.js +0 -28
  167. package/lib/bridge/buildOptimisticOperation.js.map +0 -1
  168. package/lib/bridge/createTransaction.d.ts +0 -4
  169. package/lib/bridge/createTransaction.d.ts.map +0 -1
  170. package/lib/bridge/createTransaction.js +0 -24
  171. package/lib/bridge/createTransaction.js.map +0 -1
  172. package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
  173. package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
  174. package/lib/bridge/estimateMaxSpendable.js +0 -30
  175. package/lib/bridge/estimateMaxSpendable.js.map +0 -1
  176. package/lib/bridge/getFeesForTransaction.d.ts +0 -21
  177. package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
  178. package/lib/bridge/getFeesForTransaction.js +0 -39
  179. package/lib/bridge/getFeesForTransaction.js.map +0 -1
  180. package/lib/bridge/getTransactionStatus.d.ts +0 -4
  181. package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
  182. package/lib/bridge/getTransactionStatus.js +0 -108
  183. package/lib/bridge/getTransactionStatus.js.map +0 -1
  184. package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
  185. package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
  186. package/lib/bridge/getTransactionStatus.test.js +0 -107
  187. package/lib/bridge/getTransactionStatus.test.js.map +0 -1
  188. package/lib/bridge/index.d.ts +0 -10
  189. package/lib/bridge/index.d.ts.map +0 -1
  190. package/lib/bridge/index.js +0 -59
  191. package/lib/bridge/index.js.map +0 -1
  192. package/lib/bridge/logic.d.ts +0 -10
  193. package/lib/bridge/logic.d.ts.map +0 -1
  194. package/lib/bridge/logic.js +0 -155
  195. package/lib/bridge/logic.js.map +0 -1
  196. package/lib/bridge/preload.d.ts +0 -9
  197. package/lib/bridge/preload.d.ts.map +0 -1
  198. package/lib/bridge/preload.js +0 -23
  199. package/lib/bridge/preload.js.map +0 -1
  200. package/lib/bridge/prepareTransaction.d.ts +0 -5
  201. package/lib/bridge/prepareTransaction.d.ts.map +0 -1
  202. package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
  203. package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  204. package/lib/bridge/prepareTransaction.integ.test.js +0 -34
  205. package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
  206. package/lib/bridge/prepareTransaction.js +0 -57
  207. package/lib/bridge/prepareTransaction.js.map +0 -1
  208. package/lib/bridge/prepareTransaction.test.d.ts +0 -2
  209. package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
  210. package/lib/bridge/prepareTransaction.test.js +0 -178
  211. package/lib/bridge/prepareTransaction.test.js.map +0 -1
  212. package/lib/bridge/serialization.d.ts +0 -7
  213. package/lib/bridge/serialization.d.ts.map +0 -1
  214. package/lib/bridge/serialization.js +0 -26
  215. package/lib/bridge/serialization.js.map +0 -1
  216. package/lib/bridge/signOperation.d.ts +0 -16
  217. package/lib/bridge/signOperation.d.ts.map +0 -1
  218. package/lib/bridge/signOperation.js +0 -88
  219. package/lib/bridge/signOperation.js.map +0 -1
  220. package/lib/bridge/signOperation.test.d.ts +0 -2
  221. package/lib/bridge/signOperation.test.d.ts.map +0 -1
  222. package/lib/bridge/signOperation.test.js +0 -283
  223. package/lib/bridge/signOperation.test.js.map +0 -1
  224. package/lib/bridge/synchronization.d.ts +0 -5
  225. package/lib/bridge/synchronization.d.ts.map +0 -1
  226. package/lib/bridge/synchronization.integ.test.d.ts +0 -2
  227. package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
  228. package/lib/bridge/synchronization.integ.test.js +0 -32
  229. package/lib/bridge/synchronization.integ.test.js.map +0 -1
  230. package/lib/bridge/synchronization.js +0 -100
  231. package/lib/bridge/synchronization.js.map +0 -1
  232. package/lib/bridge/transaction.d.ts.map +0 -1
  233. package/lib/bridge/transaction.js.map +0 -1
  234. package/lib-es/bridge/broadcast.d.ts +0 -4
  235. package/lib-es/bridge/broadcast.d.ts.map +0 -1
  236. package/lib-es/bridge/broadcast.js +0 -7
  237. package/lib-es/bridge/broadcast.js.map +0 -1
  238. package/lib-es/bridge/broadcast.test.d.ts +0 -2
  239. package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
  240. package/lib-es/bridge/broadcast.test.js +0 -31
  241. package/lib-es/bridge/broadcast.test.js.map +0 -1
  242. package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
  243. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
  244. package/lib-es/bridge/buildOptimisticOperation.js +0 -21
  245. package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
  246. package/lib-es/bridge/createTransaction.d.ts +0 -4
  247. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  248. package/lib-es/bridge/createTransaction.js +0 -17
  249. package/lib-es/bridge/createTransaction.js.map +0 -1
  250. package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
  251. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
  252. package/lib-es/bridge/estimateMaxSpendable.js +0 -23
  253. package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
  254. package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
  255. package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
  256. package/lib-es/bridge/getFeesForTransaction.js +0 -33
  257. package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
  258. package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
  259. package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
  260. package/lib-es/bridge/getTransactionStatus.js +0 -101
  261. package/lib-es/bridge/getTransactionStatus.js.map +0 -1
  262. package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
  263. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
  264. package/lib-es/bridge/getTransactionStatus.test.js +0 -102
  265. package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
  266. package/lib-es/bridge/index.d.ts +0 -10
  267. package/lib-es/bridge/index.d.ts.map +0 -1
  268. package/lib-es/bridge/index.js +0 -53
  269. package/lib-es/bridge/index.js.map +0 -1
  270. package/lib-es/bridge/logic.d.ts +0 -10
  271. package/lib-es/bridge/logic.d.ts.map +0 -1
  272. package/lib-es/bridge/logic.js +0 -145
  273. package/lib-es/bridge/logic.js.map +0 -1
  274. package/lib-es/bridge/preload.d.ts +0 -9
  275. package/lib-es/bridge/preload.d.ts.map +0 -1
  276. package/lib-es/bridge/preload.js +0 -17
  277. package/lib-es/bridge/preload.js.map +0 -1
  278. package/lib-es/bridge/prepareTransaction.d.ts +0 -5
  279. package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
  280. package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
  281. package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  282. package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
  283. package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
  284. package/lib-es/bridge/prepareTransaction.js +0 -50
  285. package/lib-es/bridge/prepareTransaction.js.map +0 -1
  286. package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
  287. package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
  288. package/lib-es/bridge/prepareTransaction.test.js +0 -173
  289. package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
  290. package/lib-es/bridge/serialization.d.ts +0 -7
  291. package/lib-es/bridge/serialization.d.ts.map +0 -1
  292. package/lib-es/bridge/serialization.js +0 -20
  293. package/lib-es/bridge/serialization.js.map +0 -1
  294. package/lib-es/bridge/signOperation.d.ts +0 -16
  295. package/lib-es/bridge/signOperation.d.ts.map +0 -1
  296. package/lib-es/bridge/signOperation.js +0 -83
  297. package/lib-es/bridge/signOperation.js.map +0 -1
  298. package/lib-es/bridge/signOperation.test.d.ts +0 -2
  299. package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
  300. package/lib-es/bridge/signOperation.test.js +0 -255
  301. package/lib-es/bridge/signOperation.test.js.map +0 -1
  302. package/lib-es/bridge/synchronization.d.ts +0 -5
  303. package/lib-es/bridge/synchronization.d.ts.map +0 -1
  304. package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
  305. package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
  306. package/lib-es/bridge/synchronization.integ.test.js +0 -27
  307. package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
  308. package/lib-es/bridge/synchronization.js +0 -70
  309. package/lib-es/bridge/synchronization.js.map +0 -1
  310. package/lib-es/bridge/transaction.d.ts.map +0 -1
  311. package/lib-es/bridge/transaction.js.map +0 -1
  312. package/src/bridge/broadcast.test.ts +0 -36
  313. package/src/bridge/broadcast.ts +0 -13
  314. package/src/bridge/buildOptimisticOperation.ts +0 -28
  315. package/src/bridge/createTransaction.ts +0 -19
  316. package/src/bridge/estimateMaxSpendable.ts +0 -37
  317. package/src/bridge/getFeesForTransaction.ts +0 -49
  318. package/src/bridge/getTransactionStatus.test.ts +0 -124
  319. package/src/bridge/getTransactionStatus.ts +0 -123
  320. package/src/bridge/index.ts +0 -74
  321. package/src/bridge/logic.ts +0 -171
  322. package/src/bridge/preload.ts +0 -18
  323. package/src/bridge/prepareTransaction.integ.test.ts +0 -35
  324. package/src/bridge/prepareTransaction.test.ts +0 -205
  325. package/src/bridge/prepareTransaction.ts +0 -69
  326. package/src/bridge/serialization.ts +0 -27
  327. package/src/bridge/signOperation.test.ts +0 -284
  328. package/src/bridge/signOperation.ts +0 -130
  329. package/src/bridge/synchronization.integ.test.ts +0 -33
  330. package/src/bridge/synchronization.ts +0 -100
package/src/api/index.ts CHANGED
@@ -21,11 +21,20 @@ import {
21
21
  lastBlock,
22
22
  listOperations,
23
23
  rawEncode,
24
+ validateIntent,
25
+ getStakes,
24
26
  } from "../logic";
25
27
  import api from "../network/tzkt";
26
28
  import type { TezosApi, TezosFeeEstimation } from "./types";
27
- import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
28
- import { TezosOperationMode } 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";
29
38
 
30
39
  export function createApi(config: TezosConfig): TezosApi {
31
40
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
@@ -38,31 +47,54 @@ export function createApi(config: TezosConfig): TezosApi {
38
47
  getBalance: balance,
39
48
  lastBlock,
40
49
  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
+ },
41
57
  getBlock(_height): Promise<Block> {
42
58
  throw new Error("getBlock is not supported");
43
59
  },
44
60
  getBlockInfo(_height: number): Promise<BlockInfo> {
45
61
  throw new Error("getBlockInfo is not supported");
46
62
  },
47
- getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
48
- throw new Error("getStakes is not supported");
49
- },
50
63
  getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
51
64
  throw new Error("getRewards is not supported");
52
65
  },
53
66
  };
54
67
  }
55
68
 
56
- function isTezosTransactionType(type: string): type is "send" | "delegate" | "undelegate" {
57
- return ["send", "delegate", "undelegate"].includes(type);
69
+ function isTezosTransactionType(
70
+ type: string,
71
+ ): type is "send" | "delegate" | "undelegate" | "stake" | "unstake" {
72
+ return ["send", "delegate", "undelegate", "stake", "unstake"].includes(type);
58
73
  }
59
74
 
60
75
  async function balance(address: string): Promise<Balance[]> {
61
76
  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;
62
93
  return [
63
94
  {
64
- value,
95
+ value: normalized,
65
96
  asset: { type: "native" },
97
+ stake,
66
98
  },
67
99
  ];
68
100
  }
@@ -75,64 +107,180 @@ async function craft(
75
107
  throw new IncorrectTypeError(transactionIntent.type);
76
108
  }
77
109
 
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
- }));
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
+ };
84
117
 
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
- );
118
+ // Map generic staking intents to tezos modes
119
+ const mappedType = mapIntentTypeToTezosMode(transactionIntent.type);
94
120
 
95
- const tx = await rawEncode(contents);
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
+ }
144
+
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
+ }
96
184
 
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
+ const tx = await rawEncode(contents);
97
196
  return { transaction: tx };
98
197
  }
99
198
 
100
199
  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
+ }
101
216
  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
+ }
102
229
 
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
- });
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
+ });
124
248
 
125
- if (taquitoError !== undefined) {
126
- throw new Error(`Fees estimation failed: ${taquitoError}`);
127
- }
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
+ }
128
257
 
129
- return {
130
- value,
131
- parameters: {
132
- gasLimit,
133
- storageLimit,
134
- },
135
- };
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
+ }
283
+ }
136
284
  }
137
285
 
138
286
  async function operations(
@@ -145,5 +293,6 @@ async function operations(
145
293
  sort: pagination.order === "asc" ? "Ascending" : "Descending",
146
294
  minHeight: pagination.minHeight,
147
295
  });
296
+
148
297
  return [operations, newNextCursor || ""];
149
298
  }
package/src/api/types.ts CHANGED
@@ -1,11 +1,16 @@
1
- import { AlpacaApi, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
1
+ import type { Api, FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
2
2
 
3
- export type TezosFeeParameters = { gasLimit: bigint; storageLimit: bigint };
4
- export type TezosFeeEstimation = FeeEstimation;
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
+ };
5
12
 
6
13
  export type TezosSender = { address: string; xpub?: string };
7
14
  export type TezosTransactionIntent = TransactionIntent;
8
15
 
9
- export type TezosApi = AlpacaApi & {
10
- estimateFees: (transactionIntent: TezosTransactionIntent) => Promise<TezosFeeEstimation>;
11
- };
16
+ export type TezosApi = Api;
package/src/config.ts CHANGED
@@ -1,4 +1,8 @@
1
- import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
1
+ import buildCoinConfig, {
2
+ type CoinConfig,
3
+ type CurrencyConfig,
4
+ } from "@ledgerhq/coin-framework/config";
5
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
6
 
3
7
  export type TezosConfig = {
4
8
  baker: {
@@ -22,6 +26,9 @@ export type TezosConfig = {
22
26
 
23
27
  export type TezosCoinConfig = CurrencyConfig & TezosConfig;
24
28
 
25
- const coinConfig = buildCoinConfig<TezosCoinConfig>();
29
+ const coinConfig: {
30
+ setCoinConfig: (config: CoinConfig<TezosCoinConfig>) => void;
31
+ getCoinConfig: (currency?: CryptoCurrency) => TezosCoinConfig;
32
+ } = buildCoinConfig<TezosCoinConfig>();
26
33
 
27
34
  export default coinConfig;
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./types";
2
-
3
- export { createBridges } from "./bridge/index";
2
+ export * from "./transaction";
@@ -21,6 +21,7 @@ describe("craftTransaction", () => {
21
21
  estimate: {
22
22
  reveal: jest.fn(),
23
23
  },
24
+ setProvider: jest.fn(),
24
25
  };
25
26
 
26
27
  beforeEach(() => {
@@ -3,6 +3,7 @@ import { getRevealFee } from "@taquito/taquito";
3
3
  import coinConfig from "../config";
4
4
  import { UnsupportedTransactionMode } from "../types/errors";
5
5
  import { getTezosToolkit } from "./tezosToolkit";
6
+ import { createMockSigner } from "../utils";
6
7
 
7
8
  export type TransactionFee = {
8
9
  fees?: string;
@@ -37,6 +38,13 @@ export async function craftTransaction(
37
38
 
38
39
  const tezosToolkit = getTezosToolkit();
39
40
 
41
+ // Configure signer for Taquito operations (same as in estimateFees)
42
+ if (publicKey) {
43
+ tezosToolkit.setProvider({
44
+ signer: createMockSigner(publicKey.publicKeyHash, publicKey.publicKey),
45
+ });
46
+ }
47
+
40
48
  const sourceData = await tezosToolkit.rpc.getContract(address);
41
49
  const counter = account.counter ?? Number(sourceData.counter);
42
50
 
@@ -22,7 +22,10 @@ describe("estimateFees", () => {
22
22
  },
23
23
  ];
24
24
 
25
- it.each(accounts)("returns correct value", async account => {
25
+ it.each([
26
+ [accounts[0], "with xpub"],
27
+ [accounts[1], "without xpub"],
28
+ ])("returns correct value %s", async (account, _description) => {
26
29
  // Given
27
30
  const transaction = {
28
31
  mode: "send",
@@ -42,7 +45,10 @@ describe("estimateFees", () => {
42
45
  });
43
46
  });
44
47
 
45
- it.each(accounts)("returns correct value when useAllAmount", async account => {
48
+ it.each([
49
+ [accounts[0], "with xpub"],
50
+ [accounts[1], "without xpub"],
51
+ ])("returns correct value when useAllAmount %s", async (account, _description) => {
46
52
  // Given
47
53
  const transaction = {
48
54
  mode: "send",
@@ -1,11 +1,17 @@
1
- import { DerivationType } from "@taquito/ledger-signer";
2
- import { compressPublicKey } from "@taquito/ledger-signer/dist/lib/utils";
3
1
  import { COST_PER_BYTE, getRevealFee, ORIGINATION_SIZE, Estimate } from "@taquito/taquito";
4
- import { b58Encode, PrefixV2 } from "@taquito/utils";
2
+ import { validatePublicKey, ValidationResult } from "@taquito/utils";
5
3
  import { log } from "@ledgerhq/logs";
6
4
  import { getTezosToolkit } from "./tezosToolkit";
7
5
  import { TezosOperationMode } from "../types/model";
8
6
  import { UnsupportedTransactionMode } from "../types/errors";
7
+ import {
8
+ createFallbackEstimation,
9
+ createMockSigner,
10
+ DUST_MARGIN_MUTEZ,
11
+ MIN_SUGGESTED_FEE_SMALL_TRANSFER,
12
+ OP_SIZE_XTZ_TRANSFER,
13
+ normalizePublicKeyForAddress,
14
+ } from "../utils";
9
15
 
10
16
  export type CoreAccountInfo = {
11
17
  address: string;
@@ -41,54 +47,43 @@ export async function estimateFees({
41
47
  account: CoreAccountInfo;
42
48
  transaction: CoreTransactionInfo;
43
49
  }): Promise<EstimatedFees> {
44
- let derivationType: DerivationType;
45
- let prefix: PrefixV2;
46
- if (account.address?.startsWith("tz1")) {
47
- derivationType = DerivationType.ED25519;
48
- prefix = PrefixV2.Ed25519PublicKey;
49
- } else if (account.address?.startsWith("tz2")) {
50
- derivationType = DerivationType.SECP256K1;
51
- prefix = PrefixV2.Secp256k1PublicKey;
52
- } else if (account.address?.startsWith("tz3")) {
53
- derivationType = DerivationType.P256;
54
- prefix = PrefixV2.P256PublicKey;
55
- } else {
56
- throw Error(`Failed detecting key derivation type from address ${account.address}`);
57
- }
58
-
59
- const encodedPubKey = b58Encode(
60
- compressPublicKey(Buffer.from(account.xpub || "", "hex"), derivationType),
61
- prefix,
62
- );
50
+ // Normalize public key (hex -> base58) when provided (may be undefined for unrevealed accounts)
51
+ // before the device is connected
52
+ const encodedPubKey = account.xpub
53
+ ? normalizePublicKeyForAddress(account.xpub, account.address)
54
+ : undefined;
63
55
 
64
56
  const tezosToolkit = getTezosToolkit();
65
- tezosToolkit.setProvider({
66
- signer: {
67
- publicKeyHash: async () => account.address,
68
- publicKey: async () => encodedPubKey,
69
- sign: () => Promise.reject(new Error("unsupported")),
70
- secretKey: () => Promise.reject(new Error("unsupported")),
71
- },
72
- });
57
+ if (encodedPubKey && validatePublicKey(encodedPubKey) === ValidationResult.VALID) {
58
+ tezosToolkit.setProvider({ signer: createMockSigner(account.address, encodedPubKey) });
59
+ } else {
60
+ tezosToolkit.setProvider({ signer: createMockSigner(account.address, "") });
61
+ }
73
62
 
74
63
  const estimation: EstimatedFees = {
75
- fees: BigInt(0),
76
- gasLimit: BigInt(0),
77
- storageLimit: BigInt(0),
78
- estimatedFees: BigInt(0),
64
+ fees: 0n,
65
+ gasLimit: 0n,
66
+ storageLimit: 0n,
67
+ estimatedFees: 0n,
79
68
  };
80
69
 
81
70
  // For legacy compatibility
82
- if (account.balance === BigInt(0)) {
83
- return transaction.useAllAmount ? { ...estimation, amount: BigInt(0) } : estimation;
71
+ if (account.balance === 0n) {
72
+ return transaction.useAllAmount ? { ...estimation, amount: 0n } : estimation;
84
73
  }
85
74
 
86
75
  let amount = transaction.amount;
87
- if (transaction.useAllAmount) {
88
- amount = BigInt(1); // send max do a pre-estimation with minimum amount (taquito refuses 0)
76
+ if (transaction.useAllAmount || amount === 0n) {
77
+ amount = 1n; // send max do a pre-estimation with minimum amount (taquito refuses 0)
89
78
  }
90
79
 
91
80
  try {
81
+ if (transaction.mode === "send" && !transaction.recipient) {
82
+ return {
83
+ ...estimation,
84
+ ...createFallbackEstimation(),
85
+ };
86
+ }
92
87
  let estimate: Estimate;
93
88
  switch (transaction.mode) {
94
89
  case "send":
@@ -96,6 +91,7 @@ export async function estimateFees({
96
91
  mutez: true,
97
92
  to: transaction.recipient,
98
93
  amount: Number(amount),
94
+ source: account.address, // avoid requiring signer for estimation
99
95
  storageLimit: ORIGINATION_SIZE, // https://github.com/TezTech/eztz/blob/master/PROTO_003_FEES.md for originating an account
100
96
  });
101
97
  break;
@@ -129,16 +125,14 @@ export async function estimateFees({
129
125
  // NOTE: from https://github.com/ecadlabs/taquito/blob/a70c64c4b105381bb9f1d04c9c70e8ef26e9241c/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts#L33
130
126
  // Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
131
127
  // we need to increase the gasLimit and fee returned by the estimation
132
- const gasBuffer = 500;
133
128
  const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
134
129
  const increasedFee = (gasBuffer: number, opSize: number) => {
135
130
  return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
136
131
  };
137
- const incr = increasedFee(gasBuffer, Number(estimate.opSize));
138
-
139
- const maxMinusBuff = maxAmount - (gasBuffer - incr);
140
- estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : BigInt(0);
132
+ const incr = increasedFee(DUST_MARGIN_MUTEZ, Number(estimate.opSize));
141
133
 
134
+ const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
135
+ estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : 0n;
142
136
  estimation.fees = BigInt(estimate.suggestedFeeMutez);
143
137
  estimation.gasLimit = BigInt(estimate.gasLimit);
144
138
  } else {
@@ -146,6 +140,7 @@ export async function estimateFees({
146
140
  estimation.gasLimit = BigInt(estimate.gasLimit);
147
141
  estimation.amount = transaction.amount;
148
142
  }
143
+
149
144
  estimation.storageLimit = BigInt(estimate.storageLimit);
150
145
  estimation.estimatedFees = estimation.fees;
151
146
  if (!account.revealed) {
@@ -157,13 +152,109 @@ export async function estimateFees({
157
152
  estimation.taquitoError = (e as { id: string }).id;
158
153
  log("taquito-error", "taquito got error " + e.id);
159
154
  } else if ("status" in e) {
160
- // in case of http 400, log & ignore (more case to handle)
161
- log("taquito-network-error", String((e as unknown as { message: string }).message || ""), {
162
- transaction: transaction,
163
- });
164
- throw e;
155
+ const errorMessage = String((e as unknown as { message: string }).message || "");
156
+ if (
157
+ errorMessage.includes("Public key not found") ||
158
+ errorMessage.includes("wallet or contract API")
159
+ ) {
160
+ log(
161
+ "taquito-network-error",
162
+ "Recipient address not found (new account), using default fees",
163
+ {
164
+ transaction: transaction,
165
+ },
166
+ );
167
+ const fallback = createFallbackEstimation();
168
+ estimation.fees = fallback.fees;
169
+ estimation.gasLimit = fallback.gasLimit;
170
+ estimation.storageLimit = fallback.storageLimit;
171
+ estimation.estimatedFees = fallback.fees;
172
+ if (!account.revealed) {
173
+ estimation.estimatedFees =
174
+ estimation.estimatedFees + BigInt(getRevealFee(account.address));
175
+ }
176
+ // Handle useAllAmount also for send mode when estimation falls back
177
+ if (transaction.useAllAmount) {
178
+ // Approximate Taquito behavior for send-max using stable constants
179
+ const suggestedFee =
180
+ transaction.mode === "send"
181
+ ? MIN_SUGGESTED_FEE_SMALL_TRANSFER
182
+ : Number(estimation.fees);
183
+
184
+ // For display consistency in tests, align fees to suggestedFee in send-max
185
+ if (transaction.mode === "send") {
186
+ estimation.fees = BigInt(suggestedFee);
187
+ estimation.estimatedFees = BigInt(suggestedFee);
188
+ if (!account.revealed) {
189
+ estimation.estimatedFees =
190
+ estimation.estimatedFees + BigInt(getRevealFee(account.address));
191
+ }
192
+ }
193
+
194
+ const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
195
+ const totalFees =
196
+ suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
197
+
198
+ const revealFee = account.revealed ? 0 : getRevealFee(account.address);
199
+ const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
200
+
201
+ const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
202
+ const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
203
+ const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
204
+ estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
205
+ } else {
206
+ // preserve input amount in fallback for readability/tests
207
+ estimation.amount = transaction.amount;
208
+ }
209
+ } else {
210
+ log("taquito-network-error", errorMessage, {
211
+ transaction: transaction,
212
+ });
213
+ throw e;
214
+ }
165
215
  } else {
166
- throw e;
216
+ const msg = String((e as any).message || "");
217
+ if (msg.includes("No signer has been configured")) {
218
+ const fallback = createFallbackEstimation();
219
+ estimation.fees = fallback.fees;
220
+ estimation.gasLimit = fallback.gasLimit;
221
+ estimation.storageLimit = fallback.storageLimit;
222
+ estimation.estimatedFees = fallback.estimatedFees;
223
+ if (!account.revealed) {
224
+ estimation.estimatedFees =
225
+ estimation.estimatedFees + BigInt(getRevealFee(account.address));
226
+ }
227
+ if (transaction.useAllAmount) {
228
+ const suggestedFee =
229
+ transaction.mode === "send"
230
+ ? MIN_SUGGESTED_FEE_SMALL_TRANSFER
231
+ : Number(estimation.fees);
232
+
233
+ if (transaction.mode === "send") {
234
+ estimation.fees = BigInt(suggestedFee);
235
+ estimation.estimatedFees = BigInt(suggestedFee);
236
+ if (!account.revealed) {
237
+ estimation.estimatedFees =
238
+ estimation.estimatedFees + BigInt(getRevealFee(account.address));
239
+ }
240
+ }
241
+
242
+ const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
243
+ const totalFees =
244
+ suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
245
+ const revealFee = account.revealed ? 0 : getRevealFee(account.address);
246
+ const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
247
+ const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
248
+ const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
249
+ const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
250
+ estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
251
+ } else {
252
+ // preserve input amount in fallback for readability/tests
253
+ estimation.amount = transaction.amount;
254
+ }
255
+ } else {
256
+ throw e;
257
+ }
167
258
  }
168
259
  }
169
260
  return estimation;