@ledgerhq/coin-tezos 6.6.0 → 6.7.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 (335) hide show
  1. package/.unimportedrc.json +4 -30
  2. package/CHANGELOG.md +15 -0
  3. package/jest.integ.config.js +1 -0
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.integ.test.js +6 -0
  6. package/lib/api/index.integ.test.js.map +1 -1
  7. package/lib/api/index.js +221 -40
  8. package/lib/api/index.js.map +1 -1
  9. package/lib/api/index.test.js +84 -10
  10. package/lib/api/index.test.js.map +1 -1
  11. package/lib/api/types.d.ts +7 -6
  12. package/lib/api/types.d.ts.map +1 -1
  13. package/lib/config.d.ts +4 -3
  14. package/lib/config.d.ts.map +1 -1
  15. package/lib/config.js.map +1 -1
  16. package/lib/index.d.ts +1 -1
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +1 -3
  19. package/lib/index.js.map +1 -1
  20. package/lib/logic/craftTransaction.d.ts.map +1 -1
  21. package/lib/logic/craftTransaction.js +7 -0
  22. package/lib/logic/craftTransaction.js.map +1 -1
  23. package/lib/logic/craftTransaction.test.js +1 -0
  24. package/lib/logic/craftTransaction.test.js.map +1 -1
  25. package/lib/logic/estimateFees.d.ts.map +1 -1
  26. package/lib/logic/estimateFees.integ.test.js +8 -2
  27. package/lib/logic/estimateFees.integ.test.js.map +1 -1
  28. package/lib/logic/estimateFees.js +119 -45
  29. package/lib/logic/estimateFees.js.map +1 -1
  30. package/lib/logic/getBalance.js +1 -1
  31. package/lib/logic/getBalance.js.map +1 -1
  32. package/lib/logic/getStakes.d.ts +3 -0
  33. package/lib/logic/getStakes.d.ts.map +1 -0
  34. package/lib/logic/getStakes.js +26 -0
  35. package/lib/logic/getStakes.js.map +1 -0
  36. package/lib/logic/getStakes.test.d.ts +2 -0
  37. package/lib/logic/getStakes.test.d.ts.map +1 -0
  38. package/lib/logic/getStakes.test.js +133 -0
  39. package/lib/logic/getStakes.test.js.map +1 -0
  40. package/lib/logic/index.d.ts +2 -0
  41. package/lib/logic/index.d.ts.map +1 -1
  42. package/lib/logic/index.js +5 -1
  43. package/lib/logic/index.js.map +1 -1
  44. package/lib/logic/listOperations.d.ts.map +1 -1
  45. package/lib/logic/listOperations.js +69 -11
  46. package/lib/logic/listOperations.js.map +1 -1
  47. package/lib/logic/listOperations.test.js +14 -10
  48. package/lib/logic/listOperations.test.js.map +1 -1
  49. package/lib/logic/validateIntent.d.ts +3 -0
  50. package/lib/logic/validateIntent.d.ts.map +1 -0
  51. package/lib/logic/validateIntent.js +179 -0
  52. package/lib/logic/validateIntent.js.map +1 -0
  53. package/lib/logic/validateIntent.test.d.ts +2 -0
  54. package/lib/logic/validateIntent.test.d.ts.map +1 -0
  55. package/lib/logic/validateIntent.test.js +261 -0
  56. package/lib/logic/validateIntent.test.js.map +1 -0
  57. package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
  58. package/lib/transaction.d.ts.map +1 -0
  59. package/lib/{bridge/transaction.js → transaction.js} +3 -3
  60. package/lib/transaction.js.map +1 -0
  61. package/lib/types/bridge.d.ts +3 -0
  62. package/lib/types/bridge.d.ts.map +1 -1
  63. package/lib/types/bridge.fixture.d.ts.map +1 -1
  64. package/lib/types/bridge.fixture.js +1 -0
  65. package/lib/types/bridge.fixture.js.map +1 -1
  66. package/lib/types/bridge.js.map +1 -1
  67. package/lib/utils.d.ts +50 -0
  68. package/lib/utils.d.ts.map +1 -0
  69. package/lib/utils.js +111 -0
  70. package/lib/utils.js.map +1 -0
  71. package/lib-es/api/index.d.ts.map +1 -1
  72. package/lib-es/api/index.integ.test.js +6 -0
  73. package/lib-es/api/index.integ.test.js.map +1 -1
  74. package/lib-es/api/index.js +222 -41
  75. package/lib-es/api/index.js.map +1 -1
  76. package/lib-es/api/index.test.js +84 -10
  77. package/lib-es/api/index.test.js.map +1 -1
  78. package/lib-es/api/types.d.ts +7 -6
  79. package/lib-es/api/types.d.ts.map +1 -1
  80. package/lib-es/config.d.ts +4 -3
  81. package/lib-es/config.d.ts.map +1 -1
  82. package/lib-es/config.js.map +1 -1
  83. package/lib-es/index.d.ts +1 -1
  84. package/lib-es/index.d.ts.map +1 -1
  85. package/lib-es/index.js +1 -1
  86. package/lib-es/index.js.map +1 -1
  87. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  88. package/lib-es/logic/craftTransaction.js +7 -0
  89. package/lib-es/logic/craftTransaction.js.map +1 -1
  90. package/lib-es/logic/craftTransaction.test.js +1 -0
  91. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  92. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  93. package/lib-es/logic/estimateFees.integ.test.js +8 -2
  94. package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
  95. package/lib-es/logic/estimateFees.js +119 -45
  96. package/lib-es/logic/estimateFees.js.map +1 -1
  97. package/lib-es/logic/getBalance.js +1 -1
  98. package/lib-es/logic/getBalance.js.map +1 -1
  99. package/lib-es/logic/getStakes.d.ts +3 -0
  100. package/lib-es/logic/getStakes.d.ts.map +1 -0
  101. package/lib-es/logic/getStakes.js +20 -0
  102. package/lib-es/logic/getStakes.js.map +1 -0
  103. package/lib-es/logic/getStakes.test.d.ts +2 -0
  104. package/lib-es/logic/getStakes.test.d.ts.map +1 -0
  105. package/lib-es/logic/getStakes.test.js +128 -0
  106. package/lib-es/logic/getStakes.test.js.map +1 -0
  107. package/lib-es/logic/index.d.ts +2 -0
  108. package/lib-es/logic/index.d.ts.map +1 -1
  109. package/lib-es/logic/index.js +2 -0
  110. package/lib-es/logic/index.js.map +1 -1
  111. package/lib-es/logic/listOperations.d.ts.map +1 -1
  112. package/lib-es/logic/listOperations.js +69 -11
  113. package/lib-es/logic/listOperations.js.map +1 -1
  114. package/lib-es/logic/listOperations.test.js +14 -10
  115. package/lib-es/logic/listOperations.test.js.map +1 -1
  116. package/lib-es/logic/validateIntent.d.ts +3 -0
  117. package/lib-es/logic/validateIntent.d.ts.map +1 -0
  118. package/lib-es/logic/validateIntent.js +173 -0
  119. package/lib-es/logic/validateIntent.js.map +1 -0
  120. package/lib-es/logic/validateIntent.test.d.ts +2 -0
  121. package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
  122. package/lib-es/logic/validateIntent.test.js +233 -0
  123. package/lib-es/logic/validateIntent.test.js.map +1 -0
  124. package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
  125. package/lib-es/transaction.d.ts.map +1 -0
  126. package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
  127. package/lib-es/transaction.js.map +1 -0
  128. package/lib-es/types/bridge.d.ts +3 -0
  129. package/lib-es/types/bridge.d.ts.map +1 -1
  130. package/lib-es/types/bridge.fixture.d.ts.map +1 -1
  131. package/lib-es/types/bridge.fixture.js +1 -0
  132. package/lib-es/types/bridge.fixture.js.map +1 -1
  133. package/lib-es/types/bridge.js.map +1 -1
  134. package/lib-es/utils.d.ts +50 -0
  135. package/lib-es/utils.d.ts.map +1 -0
  136. package/lib-es/utils.js +100 -0
  137. package/lib-es/utils.js.map +1 -0
  138. package/package.json +8 -11
  139. package/src/api/index.integ.test.ts +8 -1
  140. package/src/api/index.test.ts +93 -16
  141. package/src/api/index.ts +248 -55
  142. package/src/api/types.ts +11 -7
  143. package/src/config.ts +9 -2
  144. package/src/index.ts +1 -2
  145. package/src/logic/craftTransaction.test.ts +1 -0
  146. package/src/logic/craftTransaction.ts +8 -0
  147. package/src/logic/estimateFees.integ.test.ts +8 -2
  148. package/src/logic/estimateFees.ts +140 -49
  149. package/src/logic/getBalance.ts +1 -1
  150. package/src/logic/getStakes.test.ts +145 -0
  151. package/src/logic/getStakes.ts +20 -0
  152. package/src/logic/index.ts +2 -0
  153. package/src/logic/listOperations.test.ts +64 -54
  154. package/src/logic/listOperations.ts +70 -10
  155. package/src/logic/validateIntent.test.ts +274 -0
  156. package/src/logic/validateIntent.ts +207 -0
  157. package/src/{bridge/transaction.ts → transaction.ts} +4 -4
  158. package/src/types/bridge.fixture.ts +1 -0
  159. package/src/types/bridge.ts +6 -1
  160. package/src/utils.ts +111 -0
  161. package/lib/bridge/broadcast.d.ts +0 -4
  162. package/lib/bridge/broadcast.d.ts.map +0 -1
  163. package/lib/bridge/broadcast.js +0 -11
  164. package/lib/bridge/broadcast.js.map +0 -1
  165. package/lib/bridge/broadcast.test.d.ts +0 -2
  166. package/lib/bridge/broadcast.test.d.ts.map +0 -1
  167. package/lib/bridge/broadcast.test.js +0 -36
  168. package/lib/bridge/broadcast.test.js.map +0 -1
  169. package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
  170. package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
  171. package/lib/bridge/buildOptimisticOperation.js +0 -28
  172. package/lib/bridge/buildOptimisticOperation.js.map +0 -1
  173. package/lib/bridge/createTransaction.d.ts +0 -4
  174. package/lib/bridge/createTransaction.d.ts.map +0 -1
  175. package/lib/bridge/createTransaction.js +0 -24
  176. package/lib/bridge/createTransaction.js.map +0 -1
  177. package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
  178. package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
  179. package/lib/bridge/estimateMaxSpendable.js +0 -30
  180. package/lib/bridge/estimateMaxSpendable.js.map +0 -1
  181. package/lib/bridge/getFeesForTransaction.d.ts +0 -21
  182. package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
  183. package/lib/bridge/getFeesForTransaction.js +0 -39
  184. package/lib/bridge/getFeesForTransaction.js.map +0 -1
  185. package/lib/bridge/getTransactionStatus.d.ts +0 -4
  186. package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
  187. package/lib/bridge/getTransactionStatus.js +0 -108
  188. package/lib/bridge/getTransactionStatus.js.map +0 -1
  189. package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
  190. package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
  191. package/lib/bridge/getTransactionStatus.test.js +0 -107
  192. package/lib/bridge/getTransactionStatus.test.js.map +0 -1
  193. package/lib/bridge/index.d.ts +0 -10
  194. package/lib/bridge/index.d.ts.map +0 -1
  195. package/lib/bridge/index.js +0 -59
  196. package/lib/bridge/index.js.map +0 -1
  197. package/lib/bridge/logic.d.ts +0 -10
  198. package/lib/bridge/logic.d.ts.map +0 -1
  199. package/lib/bridge/logic.js +0 -155
  200. package/lib/bridge/logic.js.map +0 -1
  201. package/lib/bridge/preload.d.ts +0 -9
  202. package/lib/bridge/preload.d.ts.map +0 -1
  203. package/lib/bridge/preload.js +0 -23
  204. package/lib/bridge/preload.js.map +0 -1
  205. package/lib/bridge/prepareTransaction.d.ts +0 -5
  206. package/lib/bridge/prepareTransaction.d.ts.map +0 -1
  207. package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
  208. package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  209. package/lib/bridge/prepareTransaction.integ.test.js +0 -34
  210. package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
  211. package/lib/bridge/prepareTransaction.js +0 -57
  212. package/lib/bridge/prepareTransaction.js.map +0 -1
  213. package/lib/bridge/prepareTransaction.test.d.ts +0 -2
  214. package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
  215. package/lib/bridge/prepareTransaction.test.js +0 -178
  216. package/lib/bridge/prepareTransaction.test.js.map +0 -1
  217. package/lib/bridge/serialization.d.ts +0 -7
  218. package/lib/bridge/serialization.d.ts.map +0 -1
  219. package/lib/bridge/serialization.js +0 -26
  220. package/lib/bridge/serialization.js.map +0 -1
  221. package/lib/bridge/signOperation.d.ts +0 -16
  222. package/lib/bridge/signOperation.d.ts.map +0 -1
  223. package/lib/bridge/signOperation.js +0 -88
  224. package/lib/bridge/signOperation.js.map +0 -1
  225. package/lib/bridge/signOperation.test.d.ts +0 -2
  226. package/lib/bridge/signOperation.test.d.ts.map +0 -1
  227. package/lib/bridge/signOperation.test.js +0 -283
  228. package/lib/bridge/signOperation.test.js.map +0 -1
  229. package/lib/bridge/synchronization.d.ts +0 -5
  230. package/lib/bridge/synchronization.d.ts.map +0 -1
  231. package/lib/bridge/synchronization.integ.test.d.ts +0 -2
  232. package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
  233. package/lib/bridge/synchronization.integ.test.js +0 -32
  234. package/lib/bridge/synchronization.integ.test.js.map +0 -1
  235. package/lib/bridge/synchronization.js +0 -100
  236. package/lib/bridge/synchronization.js.map +0 -1
  237. package/lib/bridge/transaction.d.ts.map +0 -1
  238. package/lib/bridge/transaction.js.map +0 -1
  239. package/lib-es/bridge/broadcast.d.ts +0 -4
  240. package/lib-es/bridge/broadcast.d.ts.map +0 -1
  241. package/lib-es/bridge/broadcast.js +0 -7
  242. package/lib-es/bridge/broadcast.js.map +0 -1
  243. package/lib-es/bridge/broadcast.test.d.ts +0 -2
  244. package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
  245. package/lib-es/bridge/broadcast.test.js +0 -31
  246. package/lib-es/bridge/broadcast.test.js.map +0 -1
  247. package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
  248. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
  249. package/lib-es/bridge/buildOptimisticOperation.js +0 -21
  250. package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
  251. package/lib-es/bridge/createTransaction.d.ts +0 -4
  252. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  253. package/lib-es/bridge/createTransaction.js +0 -17
  254. package/lib-es/bridge/createTransaction.js.map +0 -1
  255. package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
  256. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
  257. package/lib-es/bridge/estimateMaxSpendable.js +0 -23
  258. package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
  259. package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
  260. package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
  261. package/lib-es/bridge/getFeesForTransaction.js +0 -33
  262. package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
  263. package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
  264. package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
  265. package/lib-es/bridge/getTransactionStatus.js +0 -101
  266. package/lib-es/bridge/getTransactionStatus.js.map +0 -1
  267. package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
  268. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
  269. package/lib-es/bridge/getTransactionStatus.test.js +0 -102
  270. package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
  271. package/lib-es/bridge/index.d.ts +0 -10
  272. package/lib-es/bridge/index.d.ts.map +0 -1
  273. package/lib-es/bridge/index.js +0 -53
  274. package/lib-es/bridge/index.js.map +0 -1
  275. package/lib-es/bridge/logic.d.ts +0 -10
  276. package/lib-es/bridge/logic.d.ts.map +0 -1
  277. package/lib-es/bridge/logic.js +0 -145
  278. package/lib-es/bridge/logic.js.map +0 -1
  279. package/lib-es/bridge/preload.d.ts +0 -9
  280. package/lib-es/bridge/preload.d.ts.map +0 -1
  281. package/lib-es/bridge/preload.js +0 -17
  282. package/lib-es/bridge/preload.js.map +0 -1
  283. package/lib-es/bridge/prepareTransaction.d.ts +0 -5
  284. package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
  285. package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
  286. package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  287. package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
  288. package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
  289. package/lib-es/bridge/prepareTransaction.js +0 -50
  290. package/lib-es/bridge/prepareTransaction.js.map +0 -1
  291. package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
  292. package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
  293. package/lib-es/bridge/prepareTransaction.test.js +0 -173
  294. package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
  295. package/lib-es/bridge/serialization.d.ts +0 -7
  296. package/lib-es/bridge/serialization.d.ts.map +0 -1
  297. package/lib-es/bridge/serialization.js +0 -20
  298. package/lib-es/bridge/serialization.js.map +0 -1
  299. package/lib-es/bridge/signOperation.d.ts +0 -16
  300. package/lib-es/bridge/signOperation.d.ts.map +0 -1
  301. package/lib-es/bridge/signOperation.js +0 -83
  302. package/lib-es/bridge/signOperation.js.map +0 -1
  303. package/lib-es/bridge/signOperation.test.d.ts +0 -2
  304. package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
  305. package/lib-es/bridge/signOperation.test.js +0 -255
  306. package/lib-es/bridge/signOperation.test.js.map +0 -1
  307. package/lib-es/bridge/synchronization.d.ts +0 -5
  308. package/lib-es/bridge/synchronization.d.ts.map +0 -1
  309. package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
  310. package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
  311. package/lib-es/bridge/synchronization.integ.test.js +0 -27
  312. package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
  313. package/lib-es/bridge/synchronization.js +0 -70
  314. package/lib-es/bridge/synchronization.js.map +0 -1
  315. package/lib-es/bridge/transaction.d.ts.map +0 -1
  316. package/lib-es/bridge/transaction.js.map +0 -1
  317. package/src/bridge/broadcast.test.ts +0 -36
  318. package/src/bridge/broadcast.ts +0 -13
  319. package/src/bridge/buildOptimisticOperation.ts +0 -28
  320. package/src/bridge/createTransaction.ts +0 -19
  321. package/src/bridge/estimateMaxSpendable.ts +0 -37
  322. package/src/bridge/getFeesForTransaction.ts +0 -49
  323. package/src/bridge/getTransactionStatus.test.ts +0 -124
  324. package/src/bridge/getTransactionStatus.ts +0 -123
  325. package/src/bridge/index.ts +0 -74
  326. package/src/bridge/logic.ts +0 -171
  327. package/src/bridge/preload.ts +0 -18
  328. package/src/bridge/prepareTransaction.integ.test.ts +0 -35
  329. package/src/bridge/prepareTransaction.test.ts +0 -205
  330. package/src/bridge/prepareTransaction.ts +0 -69
  331. package/src/bridge/serialization.ts +0 -27
  332. package/src/bridge/signOperation.test.ts +0 -284
  333. package/src/bridge/signOperation.ts +0 -130
  334. package/src/bridge/synchronization.integ.test.ts +0 -33
  335. package/src/bridge/synchronization.ts +0 -100
@@ -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;
@@ -6,5 +6,5 @@ import api from "../network/tzkt";
6
6
  */
7
7
  export async function getBalance(address: string): Promise<bigint> {
8
8
  const apiAccount = await api.getAccountByAddress(address);
9
- return apiAccount.type === "user" ? BigInt(apiAccount.balance) : BigInt(-1);
9
+ return apiAccount.type === "user" ? BigInt(apiAccount.balance) : -1n;
10
10
  }
@@ -0,0 +1,145 @@
1
+ import { createApi } from "../api/index";
2
+ import tzktApi from "../network/tzkt";
3
+ import coinConfig from "../config";
4
+
5
+ describe("getStakes", () => {
6
+ const api = createApi({
7
+ baker: { url: "http://baker.example.com" },
8
+ explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
9
+ node: { url: "http://tezos.node.com" },
10
+ fees: {
11
+ minGasLimit: 600,
12
+ minRevealGasLimit: 300,
13
+ minStorageLimit: 0,
14
+ minFees: 500,
15
+ minEstimatedFees: 500,
16
+ },
17
+ });
18
+
19
+ const mockGetAccountByAddress = jest.spyOn(tzktApi, "getAccountByAddress");
20
+
21
+ beforeEach(() => {
22
+ jest.clearAllMocks();
23
+
24
+ coinConfig.setCoinConfig(() => ({
25
+ status: { type: "active" },
26
+ baker: { url: "http://baker.example.com" },
27
+ explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
28
+ node: { url: "http://tezos.node.com" },
29
+ fees: {
30
+ minGasLimit: 600,
31
+ minRevealGasLimit: 300,
32
+ minStorageLimit: 0,
33
+ minFees: 500,
34
+ minEstimatedFees: 500,
35
+ },
36
+ }));
37
+ });
38
+
39
+ describe("account types", () => {
40
+ it("should return empty stakes for non-delegated account", async () => {
41
+ mockGetAccountByAddress.mockResolvedValue({
42
+ type: "user",
43
+ address: "tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq",
44
+ publicKey: "edpk...",
45
+ balance: 1000000,
46
+ revealed: true,
47
+ counter: 0,
48
+ delegationLevel: 0,
49
+ delegationTime: "2021-01-01T00:00:00Z",
50
+ numTransactions: 0,
51
+ firstActivityTime: "2021-01-01T00:00:00Z",
52
+ });
53
+
54
+ const result = await api.getStakes("tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq");
55
+
56
+ expect(result.items).toEqual([]);
57
+ });
58
+
59
+ it("should return empty stakes for non user account", async () => {
60
+ mockGetAccountByAddress.mockResolvedValue({
61
+ type: "empty",
62
+ address: "tz1EmptyAccount",
63
+ counter: 0,
64
+ });
65
+
66
+ const result = await api.getStakes("tz1EmptyAccount");
67
+
68
+ expect(result.items).toEqual([]);
69
+ });
70
+ });
71
+
72
+ describe("delegated accounts", () => {
73
+ it("should return stake for delegated account", async () => {
74
+ const address = "tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8";
75
+ const delegateAddress = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
76
+ const balance = 5000000;
77
+
78
+ mockGetAccountByAddress.mockResolvedValue({
79
+ type: "user",
80
+ address,
81
+ publicKey: "edpk...",
82
+ balance,
83
+ revealed: true,
84
+ counter: 0,
85
+ delegate: {
86
+ alias: "Test Delegate",
87
+ address: delegateAddress,
88
+ active: true,
89
+ },
90
+ delegationLevel: 100,
91
+ delegationTime: "2021-01-01T00:00:00Z",
92
+ numTransactions: 10,
93
+ firstActivityTime: "2021-01-01T00:00:00Z",
94
+ });
95
+
96
+ const result = await api.getStakes(address);
97
+
98
+ expect(result.items).toEqual([
99
+ expect.objectContaining({
100
+ uid: address,
101
+ address,
102
+ delegate: delegateAddress,
103
+ state: "active",
104
+ asset: { type: "native" },
105
+ amount: BigInt(balance),
106
+ }),
107
+ ]);
108
+ });
109
+
110
+ it("should handle account with zero balance but delegation", async () => {
111
+ const address = "tz1ZeroBalanceAccount";
112
+ const delegateAddress = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
113
+
114
+ mockGetAccountByAddress.mockResolvedValue({
115
+ type: "user",
116
+ address,
117
+ publicKey: "edpk...",
118
+ balance: 0,
119
+ revealed: true,
120
+ counter: 0,
121
+ delegate: {
122
+ alias: "Test Delegate",
123
+ address: delegateAddress,
124
+ active: true,
125
+ },
126
+ delegationLevel: 100,
127
+ delegationTime: "2021-01-01T00:00:00Z",
128
+ numTransactions: 0,
129
+ firstActivityTime: "2021-01-01T00:00:00Z",
130
+ });
131
+
132
+ const result = await api.getStakes(address);
133
+
134
+ expect(result.items).toHaveLength(1);
135
+ expect(result.items[0]).toMatchObject({
136
+ uid: address,
137
+ address,
138
+ delegate: delegateAddress,
139
+ state: "active",
140
+ asset: { type: "native" },
141
+ amount: BigInt(0),
142
+ });
143
+ });
144
+ });
145
+ });
@@ -0,0 +1,20 @@
1
+ import type { Cursor, Page, Stake } from "@ledgerhq/coin-framework/api/types";
2
+ import api from "../network/tzkt";
3
+
4
+ export async function getStakes(address: string, _cursor?: Cursor): Promise<Page<Stake>> {
5
+ // tezos exposes a single staking position via delegation when a delegate is set
6
+ const accountInfo = await api.getAccountByAddress(address);
7
+ if (accountInfo.type !== "user" || !accountInfo.delegate?.address) return { items: [] };
8
+ return {
9
+ items: [
10
+ {
11
+ uid: address,
12
+ address,
13
+ delegate: accountInfo.delegate.address,
14
+ state: "active",
15
+ asset: { type: "native" },
16
+ amount: BigInt(accountInfo.balance ?? 0),
17
+ },
18
+ ],
19
+ };
20
+ }
@@ -7,3 +7,5 @@ export { estimateFees } from "./estimateFees";
7
7
  export { getBalance } from "./getBalance";
8
8
  export { lastBlock } from "./lastBlock";
9
9
  export { listOperations } from "./listOperations";
10
+ export { validateIntent } from "./validateIntent";
11
+ export { getStakes } from "./getStakes";
@@ -83,45 +83,50 @@ describe("listOperations", () => {
83
83
  };
84
84
 
85
85
  it.each([
86
- ["undelegate", undelegate],
87
- ["delegate", delegate],
88
- ["transfer", transfer],
89
- ])("should return %s operation with proper recipient list", async (_label, operation) => {
90
- // Given
91
- mockNetworkGetTransactions.mockResolvedValue([operation]);
92
- // When
93
- const [results] = await listOperations("any address", options);
94
- // Then
95
- expect(results).toEqual([
96
- {
97
- id: `${operation.hash}-${operation.id}`,
98
- asset: { type: "native" },
99
- details: {
100
- counter: operation.counter,
101
- gasLimit: operation.gasLimit,
102
- storageLimit: operation.storageLimit,
103
- },
104
- senders: [someSenderAddress],
105
- recipients: [someDestinationAddress],
106
- tx: {
107
- block: {
108
- hash: operation.block,
109
- height: operation.level,
110
- time: new Date(operation.timestamp),
86
+ ["undelegate", undelegate, "DELEGATE", "DELEGATE"],
87
+ ["delegate", delegate, "UNDELEGATE", "UNDELEGATE"],
88
+ ["transfer", transfer, "OUT", undefined],
89
+ ])(
90
+ "should return %s operation with proper recipient list",
91
+ async (_label, operation, expectedType, expectedLedgerOpType) => {
92
+ // Given
93
+ mockNetworkGetTransactions.mockResolvedValue([operation]);
94
+ // When
95
+ const [results] = await listOperations("any address", options);
96
+ // Then
97
+ expect(results).toEqual([
98
+ {
99
+ id: `${operation.hash}-${operation.id}`,
100
+ asset: { type: "native" },
101
+ details: {
102
+ counter: operation.counter,
103
+ gasLimit: operation.gasLimit,
104
+ storageLimit: operation.storageLimit,
105
+ status: operation.status,
106
+ ledgerOpType: expectedLedgerOpType,
107
+ },
108
+ senders: [someSenderAddress],
109
+ recipients: [someDestinationAddress],
110
+ tx: {
111
+ block: {
112
+ hash: operation.block,
113
+ height: operation.level,
114
+ time: new Date(operation.timestamp),
115
+ },
116
+ date: new Date(operation.timestamp),
117
+ hash: operation.hash,
118
+ fees: BigInt(
119
+ (operation.allocationFee ?? 0) +
120
+ (operation.bakerFee ?? 0) +
121
+ (operation.storageFee ?? 0),
122
+ ),
111
123
  },
112
- date: new Date(operation.timestamp),
113
- hash: operation.hash,
114
- fees: BigInt(
115
- (operation.allocationFee ?? 0) +
116
- (operation.bakerFee ?? 0) +
117
- (operation.storageFee ?? 0),
118
- ),
124
+ type: expectedType,
125
+ value: BigInt(operation.amount),
119
126
  },
120
- type: operation.type,
121
- value: BigInt(operation.amount),
122
- },
123
- ]);
124
- });
127
+ ]);
128
+ },
129
+ );
125
130
 
126
131
  it.each([
127
132
  ["undelegate", undelegate],
@@ -142,23 +147,28 @@ describe("listOperations", () => {
142
147
  );
143
148
 
144
149
  it.each([
145
- ["undelegate", undelegate],
146
- ["delegate", delegate],
147
- ["transfer", transfer],
148
- ["reveal", reveal],
149
- ])("should return %s operation with expected details", async (_label, operation) => {
150
- // Given
151
- mockNetworkGetTransactions.mockResolvedValue([operation]);
152
- // When
153
- const [results, _] = await listOperations("any address", options);
154
- // Then
155
- expect(results.length).toEqual(1);
156
- expect(results[0].details).toEqual({
157
- counter: 65214462,
158
- gasLimit: 4,
159
- storageLimit: 5,
160
- });
161
- });
150
+ ["undelegate", undelegate, "DELEGATE"],
151
+ ["delegate", delegate, "UNDELEGATE"],
152
+ ["transfer", transfer, undefined],
153
+ ["reveal", reveal, "REVEAL"],
154
+ ])(
155
+ "should return %s operation with expected details",
156
+ async (_label, operation, expectedLedgerOpType) => {
157
+ // Given
158
+ mockNetworkGetTransactions.mockResolvedValue([operation]);
159
+ // When
160
+ const [results, _] = await listOperations("any address", options);
161
+ // Then
162
+ expect(results.length).toEqual(1);
163
+ expect(results[0].details).toEqual({
164
+ counter: 65214462,
165
+ gasLimit: 4,
166
+ storageLimit: 5,
167
+ status: operation.status,
168
+ ledgerOpType: expectedLedgerOpType,
169
+ });
170
+ },
171
+ );
162
172
 
163
173
  it.each([
164
174
  { ...undelegate, newDelegate: null, prevDelegate: null },