@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
@@ -1,145 +0,0 @@
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
- });
@@ -1,20 +0,0 @@
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
- }
@@ -1,262 +0,0 @@
1
- import { validateIntent } from "./validateIntent";
2
- import * as estimateFeesModule from "./estimateFees";
3
- import tzktApi from "../network/tzkt";
4
- import coinConfig from "../config";
5
- import {
6
- RecipientRequired,
7
- InvalidAddress,
8
- InvalidAddressBecauseDestinationIsAlsoSource,
9
- AmountRequired,
10
- NotEnoughBalance,
11
- } from "@ledgerhq/errors";
12
-
13
- describe("validateIntent", () => {
14
- const senderAddress = "tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8";
15
- const validRecipient = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
16
-
17
- const mockEstimateFees = jest.spyOn(estimateFeesModule, "estimateFees");
18
- const mockGetAccountByAddress = jest.spyOn(tzktApi, "getAccountByAddress");
19
-
20
- beforeEach(() => {
21
- jest.clearAllMocks();
22
-
23
- coinConfig.setCoinConfig(() => ({
24
- status: { type: "active" },
25
- baker: { url: "http://baker.example.com" },
26
- explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
27
- node: { url: "http://tezos.node.com" },
28
- fees: {
29
- minGasLimit: 600,
30
- minRevealGasLimit: 300,
31
- minStorageLimit: 0,
32
- minFees: 500,
33
- minEstimatedFees: 500,
34
- },
35
- }));
36
-
37
- mockEstimateFees.mockResolvedValue({
38
- fees: BigInt(1000),
39
- gasLimit: BigInt(10000),
40
- storageLimit: BigInt(0),
41
- estimatedFees: BigInt(1000),
42
- });
43
-
44
- mockGetAccountByAddress.mockResolvedValue({
45
- type: "user",
46
- address: senderAddress,
47
- publicKey: "edpk...",
48
- balance: 5000000,
49
- revealed: true,
50
- counter: 0,
51
- delegationLevel: 0,
52
- delegationTime: "2021-01-01T00:00:00Z",
53
- numTransactions: 0,
54
- firstActivityTime: "2021-01-01T00:00:00Z",
55
- });
56
- });
57
-
58
- describe("recipient validation", () => {
59
- it("should return RecipientRequired error when recipient is missing", async () => {
60
- const result = await validateIntent({
61
- asset: { type: "native" },
62
- type: "send",
63
- sender: senderAddress,
64
- recipient: "",
65
- amount: BigInt(1000),
66
- });
67
-
68
- expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
69
- });
70
-
71
- it("should return InvalidAddress error for invalid recipient", async () => {
72
- const result = await validateIntent({
73
- asset: { type: "native" },
74
- type: "send",
75
- sender: senderAddress,
76
- recipient: "invalid_address",
77
- amount: BigInt(1000),
78
- });
79
-
80
- expect(result.errors.recipient).toBeInstanceOf(InvalidAddress);
81
- });
82
-
83
- it("should return InvalidAddressBecauseDestinationIsAlsoSource when sender equals recipient", async () => {
84
- const result = await validateIntent({
85
- asset: { type: "native" },
86
- type: "send",
87
- sender: senderAddress,
88
- recipient: senderAddress,
89
- amount: BigInt(1000),
90
- });
91
-
92
- expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
93
- });
94
- });
95
-
96
- describe("amount validation", () => {
97
- it("should return AmountRequired error when amount is zero and not useAllAmount", async () => {
98
- const result = await validateIntent({
99
- asset: { type: "native" },
100
- type: "send",
101
- sender: senderAddress,
102
- recipient: validRecipient,
103
- amount: BigInt(0),
104
- useAllAmount: false,
105
- });
106
-
107
- expect(result.errors.amount).toBeInstanceOf(AmountRequired);
108
- });
109
-
110
- it("should not return AmountRequired error when useAllAmount is true", async () => {
111
- const result = await validateIntent({
112
- asset: { type: "native" },
113
- type: "send",
114
- sender: senderAddress,
115
- recipient: validRecipient,
116
- amount: BigInt(0),
117
- useAllAmount: true,
118
- });
119
-
120
- expect(result.errors.amount).toBeUndefined();
121
- });
122
- });
123
-
124
- describe("balance validation", () => {
125
- it("should return NotEnoughBalance error when amount exceeds balance", async () => {
126
- const balance = 1000000; // 1 XTZ
127
- const amount = 2000000; // 2 XTZ
128
-
129
- mockGetAccountByAddress.mockResolvedValue({
130
- type: "user",
131
- address: senderAddress,
132
- publicKey: "edpk...",
133
- balance,
134
- revealed: true,
135
- counter: 0,
136
- delegationLevel: 0,
137
- delegationTime: "2021-01-01T00:00:00Z",
138
- numTransactions: 0,
139
- firstActivityTime: "2021-01-01T00:00:00Z",
140
- });
141
-
142
- const result = await validateIntent({
143
- asset: { type: "native" },
144
- type: "send",
145
- sender: senderAddress,
146
- recipient: validRecipient,
147
- amount: BigInt(amount),
148
- });
149
-
150
- expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
151
- });
152
-
153
- it("should pass validation when amount is within balance", async () => {
154
- const balance = 5000000; // 5 XTZ
155
- const amount = 1000000; // 1 XTZ
156
-
157
- mockGetAccountByAddress.mockResolvedValue({
158
- type: "user",
159
- address: senderAddress,
160
- publicKey: "edpk...",
161
- balance,
162
- revealed: true,
163
- counter: 0,
164
- delegationLevel: 0,
165
- delegationTime: "2021-01-01T00:00:00Z",
166
- numTransactions: 0,
167
- firstActivityTime: "2021-01-01T00:00:00Z",
168
- });
169
-
170
- const result = await validateIntent({
171
- asset: { type: "native" },
172
- type: "send",
173
- sender: senderAddress,
174
- recipient: validRecipient,
175
- amount: BigInt(amount),
176
- });
177
-
178
- expect(result.errors.amount).toBeUndefined();
179
- expect(result.amount).toBe(BigInt(amount));
180
- });
181
- });
182
-
183
- describe("transaction types", () => {
184
- it("should pass validation for delegate transaction", async () => {
185
- const result = await validateIntent({
186
- asset: { type: "native" },
187
- type: "delegate",
188
- sender: senderAddress,
189
- recipient: validRecipient,
190
- amount: BigInt(0),
191
- });
192
-
193
- expect(result.errors).toEqual({});
194
- });
195
-
196
- it("should pass validation for undelegate transaction", async () => {
197
- const result = await validateIntent({
198
- asset: { type: "native" },
199
- type: "undelegate",
200
- sender: senderAddress,
201
- recipient: "",
202
- amount: BigInt(0),
203
- });
204
-
205
- expect(result.errors).toEqual({});
206
- });
207
-
208
- it("should handle stake intent (mapped to delegate)", async () => {
209
- const result = await validateIntent({
210
- asset: { type: "native" },
211
- type: "stake",
212
- sender: senderAddress,
213
- recipient: validRecipient,
214
- amount: BigInt(0),
215
- });
216
-
217
- expect(result.errors).toEqual({});
218
- });
219
-
220
- it("should handle unstake intent (mapped to undelegate)", async () => {
221
- const result = await validateIntent({
222
- asset: { type: "native" },
223
- type: "unstake",
224
- sender: senderAddress,
225
- recipient: "",
226
- amount: BigInt(0),
227
- });
228
-
229
- expect(result.errors).toEqual({});
230
- });
231
- });
232
-
233
- describe("successful validation", () => {
234
- it("should return valid result with correct values", async () => {
235
- const amount = BigInt(1000000);
236
- const estimatedFees = BigInt(1500);
237
-
238
- mockEstimateFees.mockResolvedValue({
239
- fees: BigInt(1000),
240
- gasLimit: BigInt(10000),
241
- storageLimit: BigInt(0),
242
- estimatedFees,
243
- });
244
-
245
- const result = await validateIntent({
246
- asset: { type: "native" },
247
- type: "send",
248
- sender: senderAddress,
249
- recipient: validRecipient,
250
- amount,
251
- });
252
-
253
- expect(result).toMatchObject({
254
- errors: {},
255
- warnings: {},
256
- estimatedFees,
257
- amount,
258
- totalSpent: amount + estimatedFees,
259
- });
260
- });
261
- });
262
- });
@@ -1,207 +0,0 @@
1
- import type { TransactionIntent, TransactionValidation } from "@ledgerhq/coin-framework/api/types";
2
- import {
3
- InvalidAddress,
4
- RecipientRequired,
5
- RecommendUndelegation,
6
- NotEnoughBalance,
7
- NotEnoughBalanceToDelegate,
8
- AmountRequired,
9
- InvalidAddressBecauseDestinationIsAlsoSource,
10
- } from "@ledgerhq/errors";
11
- import { validateAddress, ValidationResult } from "@taquito/utils";
12
- import api from "../network/tzkt";
13
- import { estimateFees } from "./estimateFees";
14
- import { InvalidAddressBecauseAlreadyDelegated } from "../types/errors";
15
- import { mapIntentTypeToTezosMode } from "../utils";
16
-
17
- /**
18
- * Validates basic recipient and amount for send transactions
19
- */
20
- function validateBasicSendParams(intent: TransactionIntent): Record<string, Error> {
21
- const errors: Record<string, Error> = {};
22
-
23
- if (intent.type !== "send") {
24
- return errors;
25
- }
26
-
27
- if (!intent.recipient) {
28
- errors.recipient = new RecipientRequired("");
29
- } else if (validateAddress(intent.recipient) !== ValidationResult.VALID) {
30
- errors.recipient = new InvalidAddress(undefined, { currencyName: "Tezos" });
31
- } else if (intent.sender === intent.recipient) {
32
- errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
33
- }
34
-
35
- if (intent.amount === 0n && !intent.useAllAmount) {
36
- errors.amount = new AmountRequired();
37
- } else if (intent.amount < 0n) {
38
- errors.amount = new NotEnoughBalance();
39
- }
40
-
41
- return errors;
42
- }
43
-
44
- /**
45
- * Validates specific transaction constraints based on account state
46
- */
47
- function validateTransactionConstraints(
48
- intent: TransactionIntent,
49
- senderInfo: any,
50
- ): Record<string, Error> {
51
- const errors: Record<string, Error> = {};
52
-
53
- // send max not allowed on delegated accounts (must undelegate acc first)
54
- if (intent.type === "send" && intent.useAllAmount) {
55
- if (senderInfo.type === "user" && senderInfo.delegate?.address) {
56
- errors.amount = new RecommendUndelegation();
57
- }
58
- }
59
-
60
- // stake requires non-zero balance
61
- if (intent.type === "stake") {
62
- const balance = BigInt(senderInfo.balance || "0");
63
- if (balance === 0n) {
64
- errors.amount = new NotEnoughBalanceToDelegate();
65
- }
66
- }
67
-
68
- return errors;
69
- }
70
-
71
- /**
72
- * Maps Taquito-specific errors to our error types
73
- */
74
- function mapTaquitoErrors(taquitoError: string, intentType: string): Record<string, Error> {
75
- const errors: Record<string, Error> = {};
76
-
77
- if (taquitoError.endsWith("balance_too_low") || taquitoError.endsWith("subtraction_underflow")) {
78
- if (intentType === "stake") {
79
- errors.amount = new NotEnoughBalanceToDelegate();
80
- } else {
81
- errors.amount = new NotEnoughBalance();
82
- }
83
- } else if (taquitoError.endsWith("delegate.unchanged") && intentType === "stake") {
84
- errors.recipient = new InvalidAddressBecauseAlreadyDelegated();
85
- } else if (taquitoError.includes("empty_implicit_contract")) {
86
- errors.amount = new NotEnoughBalanceToDelegate();
87
- } else {
88
- errors.amount = new Error(taquitoError);
89
- }
90
-
91
- return errors;
92
- }
93
-
94
- /**
95
- * Calculates final amounts based on transaction type
96
- */
97
- function calculateAmounts(
98
- intent: TransactionIntent,
99
- senderInfo: any,
100
- estimatedFees: bigint,
101
- ): { amount: bigint; totalSpent: bigint } {
102
- if (intent.type === "stake" || intent.type === "unstake") {
103
- const amount = BigInt(senderInfo.type === "user" ? senderInfo.balance : 0);
104
- return { amount, totalSpent: estimatedFees };
105
- }
106
-
107
- if (intent.type === "send" && intent.useAllAmount) {
108
- if (senderInfo.type === "user") {
109
- const balance = BigInt(senderInfo.balance);
110
- const amount = balance > estimatedFees ? balance - estimatedFees : 0n;
111
- return { amount, totalSpent: amount + estimatedFees };
112
- }
113
- return { amount: 0n, totalSpent: 0n };
114
- }
115
-
116
- const amount = intent.amount;
117
- return { amount, totalSpent: amount + estimatedFees };
118
- }
119
-
120
- /**
121
- * Validates balance coverage for the transaction
122
- */
123
- function validateBalanceCoverage(senderInfo: any, totalSpent: bigint): Record<string, Error> {
124
- const errors: Record<string, Error> = {};
125
-
126
- if (senderInfo.type === "user") {
127
- const accountBalance = BigInt(senderInfo.balance);
128
- if (totalSpent > accountBalance) {
129
- errors.amount = new NotEnoughBalance();
130
- }
131
- }
132
-
133
- return errors;
134
- }
135
-
136
- export async function validateIntent(intent: TransactionIntent): Promise<TransactionValidation> {
137
- const errors: Record<string, Error> = {};
138
- const warnings: Record<string, Error> = {};
139
- let estimatedFees: bigint;
140
- let amount: bigint;
141
- let totalSpent: bigint;
142
-
143
- // Basic validation for send transactions
144
- const basicErrors = validateBasicSendParams(intent);
145
- Object.assign(errors, basicErrors);
146
-
147
- if (Object.keys(errors).length > 0) {
148
- return { errors, warnings, estimatedFees: 0n, amount: 0n, totalSpent: 0n };
149
- }
150
-
151
- try {
152
- // Get sender account information
153
- const senderInfo = await api.getAccountByAddress(intent.sender);
154
- if (senderInfo.type !== "user") throw new Error("unexpected account type");
155
-
156
- // Validate transaction-specific constraints
157
- const constraintErrors = validateTransactionConstraints(intent, senderInfo);
158
- Object.assign(errors, constraintErrors);
159
-
160
- if (Object.keys(errors).length > 0) {
161
- return { errors, warnings, estimatedFees: 0n, amount: 0n, totalSpent: 0n };
162
- }
163
-
164
- // Estimate fees
165
- if (senderInfo.revealed) {
166
- const estimation = await estimateFees({
167
- account: {
168
- address: intent.sender,
169
- revealed: senderInfo.revealed,
170
- balance: BigInt(senderInfo.balance),
171
- xpub: intent.senderPublicKey ?? senderInfo.publicKey,
172
- },
173
- transaction: {
174
- mode: mapIntentTypeToTezosMode(intent.type),
175
- recipient: intent.recipient,
176
- amount: intent.amount,
177
- useAllAmount: !!intent.useAllAmount,
178
- },
179
- });
180
- estimatedFees = estimation.estimatedFees;
181
-
182
- // Handle Taquito errors
183
- if (estimation.taquitoError) {
184
- const taquitoErrors = mapTaquitoErrors(estimation.taquitoError, intent.type);
185
- Object.assign(errors, taquitoErrors);
186
- }
187
- } else {
188
- estimatedFees = 2000n;
189
- }
190
-
191
- // Calculate final amounts
192
- const amounts = calculateAmounts(intent, senderInfo, estimatedFees);
193
- amount = amounts.amount;
194
- totalSpent = amounts.totalSpent;
195
-
196
- // Final balance validation
197
- const balanceErrors = validateBalanceCoverage(senderInfo, totalSpent);
198
- Object.assign(errors, balanceErrors);
199
- } catch (e) {
200
- errors.estimation = e as Error;
201
- estimatedFees = 0n;
202
- amount = intent.amount;
203
- totalSpent = intent.amount;
204
- }
205
-
206
- return { errors, warnings, estimatedFees, amount, totalSpent };
207
- }