@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
@@ -1,124 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { getTransactionStatus } from "./getTransactionStatus";
3
- import { validateRecipient } from "../logic";
4
- import { isAccountDelegating } from "../network/bakers";
5
- import api from "../network/tzkt";
6
- import {
7
- AmountRequired,
8
- FeeTooHigh,
9
- InvalidAddressBecauseDestinationIsAlsoSource,
10
- NotEnoughBalance,
11
- NotEnoughBalanceBecauseDestinationNotCreated,
12
- RecommendUndelegation,
13
- } from "@ledgerhq/errors";
14
- import { TezosAccount, Transaction } from "../types";
15
-
16
- jest.mock("../logic", () => ({
17
- validateRecipient: jest.fn(),
18
- }));
19
-
20
- jest.mock("../network/bakers", () => ({
21
- isAccountDelegating: jest.fn(),
22
- }));
23
-
24
- jest.mock("../network/tzkt", () => ({
25
- getAccountByAddress: jest.fn(),
26
- }));
27
-
28
- describe("getTransactionStatus", () => {
29
- const mockAccount = {
30
- type: "Account",
31
- freshAddress: "tz1SourceAddress",
32
- balance: new BigNumber(1000000),
33
- currency: {
34
- type: "CryptoCurrency",
35
- units: [
36
- {
37
- name: "tezos",
38
- code: "XTZ",
39
- magnitude: 6,
40
- },
41
- ],
42
- },
43
- tezosResources: {
44
- revealed: true,
45
- counter: 0,
46
- },
47
- } as unknown as TezosAccount;
48
-
49
- const mockTransaction = {
50
- family: "tezos",
51
- mode: "send",
52
- amount: new BigNumber(500000),
53
- recipient: "tz1RecipientAddress",
54
- estimatedFees: new BigNumber(1000),
55
- useAllAmount: false,
56
- } as Transaction;
57
-
58
- beforeEach(() => {
59
- jest.clearAllMocks();
60
- (validateRecipient as jest.Mock).mockResolvedValue({
61
- recipientError: null,
62
- recipientWarning: null,
63
- });
64
- (api.getAccountByAddress as jest.Mock).mockResolvedValue({ type: "empty" });
65
- });
66
-
67
- it("should return an error if the recipient is the same as the source address", async () => {
68
- const transaction = { ...mockTransaction, recipient: mockAccount.freshAddress };
69
- const result = await getTransactionStatus(mockAccount, transaction);
70
- expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
71
- });
72
-
73
- it("should return an error if the amount is zero and useAllAmount is false", async () => {
74
- const transaction = { ...mockTransaction, amount: new BigNumber(0) };
75
- const result = await getTransactionStatus(mockAccount, transaction);
76
- expect(result.errors.amount).toBeInstanceOf(AmountRequired);
77
- });
78
-
79
- it("should return a warning if the fees are too high compared to the amount", async () => {
80
- const transaction = { ...mockTransaction, amount: new BigNumber(1000) };
81
- const result = await getTransactionStatus(mockAccount, transaction);
82
- expect(result.warnings.feeTooHigh).toBeInstanceOf(FeeTooHigh);
83
- });
84
-
85
- it("should return a warning if the balance after transaction is below the threshold", async () => {
86
- (isAccountDelegating as jest.Mock).mockReturnValue(true);
87
- const transaction = { ...mockTransaction, amount: new BigNumber(999000) };
88
- const result = await getTransactionStatus(mockAccount, transaction);
89
- expect(result.warnings.amount).toBeInstanceOf(RecommendUndelegation);
90
- });
91
-
92
- it("should map taquito errors to appropriate errors", async () => {
93
- const transaction = { ...mockTransaction, taquitoError: "balance_too_low" };
94
- const result = await getTransactionStatus(mockAccount, transaction);
95
- expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
96
- });
97
-
98
- it("should return an error if the account balance is zero or less", async () => {
99
- const account = { ...mockAccount, balance: new BigNumber(0) };
100
- const result = await getTransactionStatus(account, mockTransaction);
101
- expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
102
- });
103
-
104
- it("should return an error if the account balance is less than the estimated fees for delegation", async () => {
105
- const transaction = { ...mockTransaction, mode: "delegate" } as Transaction;
106
- const account = { ...mockAccount, balance: new BigNumber(500) };
107
- const result = await getTransactionStatus(account, transaction);
108
- expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
109
- });
110
-
111
- it("should return an error if the recipient account is empty and the amount is below the existential deposit", async () => {
112
- const transaction = { ...mockTransaction, amount: new BigNumber(100000) };
113
- const result = await getTransactionStatus(mockAccount, transaction);
114
- expect(result.errors.amount).toBeInstanceOf(NotEnoughBalanceBecauseDestinationNotCreated);
115
- });
116
-
117
- it("should return no errors or warnings for a valid transaction", async () => {
118
- const account = { ...mockAccount, balance: new BigNumber(2000000) };
119
- const transaction = { ...mockTransaction, amount: new BigNumber(500000) };
120
- const result = await getTransactionStatus(account, transaction);
121
- expect(result.errors).toEqual({});
122
- expect(result.warnings).toEqual({});
123
- });
124
- });
@@ -1,123 +0,0 @@
1
- import {
2
- AmountRequired,
3
- FeeTooHigh,
4
- InvalidAddressBecauseDestinationIsAlsoSource,
5
- NotEnoughBalance,
6
- NotEnoughBalanceBecauseDestinationNotCreated,
7
- NotEnoughBalanceToDelegate,
8
- RecommendUndelegation,
9
- } from "@ledgerhq/errors";
10
- import { log } from "@ledgerhq/logs";
11
- import BigNumber from "bignumber.js";
12
- import { AccountBridge } from "@ledgerhq/types-live";
13
- import { InvalidAddressBecauseAlreadyDelegated } from "../types/errors";
14
- import { validateRecipient } from "../logic";
15
- import { isAccountDelegating } from "../network/bakers";
16
- import api from "../network/tzkt";
17
- import { Transaction } from "../types";
18
-
19
- const EXISTENTIAL_DEPOSIT = new BigNumber(275000);
20
-
21
- export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
22
- account,
23
- transaction,
24
- ) => {
25
- const errors: Record<string, Error> = {};
26
- const warnings: Record<string, Error> = {};
27
- let resetTotalSpent = false;
28
-
29
- // Recipient validation logic
30
- if (transaction.mode !== "undelegate") {
31
- if (account.freshAddress === transaction.recipient) {
32
- errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
33
- } else {
34
- const { recipientError, recipientWarning } = await validateRecipient(transaction.recipient);
35
- if (recipientError) {
36
- errors.recipient = recipientError;
37
- }
38
- if (recipientWarning) {
39
- warnings.recipient = recipientWarning;
40
- }
41
- }
42
- }
43
-
44
- // Pre validation of amount field
45
- const estimatedFees = transaction.estimatedFees || new BigNumber(0);
46
- if (transaction.mode === "send") {
47
- if (!errors.amount && transaction.amount.eq(0) && !transaction.useAllAmount) {
48
- resetTotalSpent = true;
49
- errors.amount = new AmountRequired();
50
- } else if (transaction.amount.gt(0) && estimatedFees.times(10).gt(transaction.amount)) {
51
- warnings.feeTooHigh = new FeeTooHigh();
52
- }
53
- const thresholdWarning = 0.5 * 10 ** account.currency.units[0].magnitude;
54
- if (
55
- !errors.amount &&
56
- account.balance.minus(transaction.amount).minus(estimatedFees).lt(thresholdWarning)
57
- ) {
58
- if (isAccountDelegating(account)) {
59
- if (transaction.useAllAmount) {
60
- errors.amount = new RecommendUndelegation();
61
- } else {
62
- warnings.amount = new RecommendUndelegation();
63
- }
64
- }
65
- }
66
- }
67
-
68
- // effective amount
69
- // if we also have taquitoError, we interprete them and they override the previously inferred errors
70
- if (transaction.taquitoError) {
71
- log("taquitoerror", String(transaction.taquitoError));
72
-
73
- // remap taquito errors
74
- if (
75
- transaction.taquitoError.endsWith("balance_too_low") ||
76
- transaction.taquitoError.endsWith("subtraction_underflow")
77
- ) {
78
- if (transaction.mode === "send") {
79
- resetTotalSpent = true;
80
- errors.amount = new NotEnoughBalance();
81
- } else {
82
- errors.amount = new NotEnoughBalanceToDelegate();
83
- }
84
- } else if (transaction.taquitoError.endsWith("delegate.unchanged")) {
85
- errors.recipient = new InvalidAddressBecauseAlreadyDelegated();
86
- } else if (!errors.amount) {
87
- // unidentified error case
88
- errors.amount = new Error(transaction.taquitoError);
89
- resetTotalSpent = true;
90
- }
91
- }
92
-
93
- if (!errors.amount && account.balance.lte(0)) {
94
- resetTotalSpent = true;
95
- errors.amount = new NotEnoughBalance();
96
- }
97
-
98
- if (!errors.amount && transaction.mode === "delegate" && account.balance.lte(estimatedFees)) {
99
- resetTotalSpent = true;
100
- errors.amount = new NotEnoughBalance();
101
- }
102
-
103
- // Catch a specific case that requires a minimum amount
104
- if (
105
- !errors.amount &&
106
- transaction.mode === "send" &&
107
- transaction.amount.lt(EXISTENTIAL_DEPOSIT) &&
108
- (await api.getAccountByAddress(transaction.recipient)).type === "empty"
109
- ) {
110
- resetTotalSpent = true;
111
- errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
112
- minimalAmount: "0.275 XTZ",
113
- });
114
- }
115
-
116
- return {
117
- errors,
118
- warnings,
119
- estimatedFees,
120
- amount: transaction.amount,
121
- totalSpent: resetTotalSpent ? new BigNumber(0) : transaction.amount.plus(estimatedFees),
122
- };
123
- };
@@ -1,74 +0,0 @@
1
- import {
2
- getSerializedAddressParameters,
3
- updateTransaction,
4
- makeAccountBridgeReceive,
5
- makeScanAccounts,
6
- } from "@ledgerhq/coin-framework/bridge/jsHelpers";
7
- import { CoinConfig } from "@ledgerhq/coin-framework/config";
8
- import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
- import type { CurrencyBridge, AccountBridge } from "@ledgerhq/types-live";
10
- import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
11
- import type { TezosAccount, TezosSigner, Transaction, TransactionStatus } from "../types";
12
- import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
13
- import { getPreloadStrategy, hydrate, preload } from "./preload";
14
- import { estimateMaxSpendable } from "./estimateMaxSpendable";
15
- import { getTransactionStatus } from "./getTransactionStatus";
16
- import { prepareTransaction } from "./prepareTransaction";
17
- import { getAccountShape, sync } from "./synchronization";
18
- import { createTransaction } from "./createTransaction";
19
- import { buildSignOperation } from "./signOperation";
20
- import signerGetAddress from "../signer";
21
- import { broadcast } from "./broadcast";
22
- import tezosCoinConfig, { TezosCoinConfig } from "../config";
23
-
24
- function buildCurrencyBridge(signerContext: SignerContext<TezosSigner>): CurrencyBridge {
25
- const getAddress = signerGetAddress(signerContext);
26
-
27
- const scanAccounts = makeScanAccounts({
28
- getAccountShape,
29
- getAddressFn: getAddressWrapper(getAddress),
30
- });
31
-
32
- return {
33
- getPreloadStrategy,
34
- preload,
35
- hydrate,
36
- scanAccounts,
37
- };
38
- }
39
-
40
- function buildAccountBridge(
41
- signerContext: SignerContext<TezosSigner>,
42
- ): AccountBridge<Transaction, TezosAccount, TransactionStatus> {
43
- const getAddress = signerGetAddress(signerContext);
44
-
45
- const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
46
- const signOperation = buildSignOperation(signerContext);
47
-
48
- return {
49
- estimateMaxSpendable,
50
- createTransaction,
51
- updateTransaction,
52
- getTransactionStatus,
53
- prepareTransaction,
54
- sync,
55
- receive,
56
- signOperation,
57
- broadcast,
58
- assignFromAccountRaw,
59
- assignToAccountRaw,
60
- getSerializedAddressParameters,
61
- };
62
- }
63
-
64
- export function createBridges(
65
- signerContext: SignerContext<TezosSigner>,
66
- coinConfig: CoinConfig<TezosCoinConfig>,
67
- ) {
68
- tezosCoinConfig.setCoinConfig(coinConfig);
69
-
70
- return {
71
- currencyBridge: buildCurrencyBridge(signerContext),
72
- accountBridge: buildAccountBridge(signerContext),
73
- };
74
- }
@@ -1,171 +0,0 @@
1
- import { blake2b } from "@noble/hashes/blake2";
2
- import bs58check from "bs58check";
3
- import BigNumber from "bignumber.js";
4
- import { OperationType } from "@ledgerhq/types-live";
5
- import { decodeAccountId } from "@ledgerhq/coin-framework/account";
6
- import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
7
- import { type APIOperation } from "../network/types";
8
- import { TezosAccount, TezosOperation } from "../types";
9
-
10
- export const txToOp =
11
- ({ address, accountId }: { address: string; accountId: string }) =>
12
- (tx: APIOperation): TezosOperation | null | undefined => {
13
- let type: OperationType;
14
- let maybeValue;
15
- let senders: string[] = [];
16
- let recipients: string[] = [];
17
- const hasFailed = tx.status ? tx.status !== "applied" : false;
18
-
19
- switch (tx.type) {
20
- case "transaction": {
21
- const initiator = tx.initiator?.address;
22
- const from = tx.sender?.address;
23
- const to = tx.target?.address;
24
- if (from !== address && to !== address && initiator !== address) {
25
- // failsafe for a case that shouldn't happen.
26
- console.warn("found tx is unrelated to account! " + tx.hash);
27
- return null;
28
- }
29
- senders = [from || initiator || ""];
30
- recipients = [to || ""];
31
- if (
32
- (from === address && to === address) || // self tx
33
- (from !== address && to !== address) // initiator but not in from/to
34
- ) {
35
- // we just pay fees in that case
36
- type = "FEES";
37
- } else {
38
- type = to === address ? "IN" : "OUT";
39
- if (!hasFailed) {
40
- maybeValue = new BigNumber(tx.amount || 0);
41
- if (maybeValue.eq(0)) {
42
- type = "FEES";
43
- }
44
- }
45
- }
46
- break;
47
- }
48
- case "delegation":
49
- type = tx.newDelegate ? "DELEGATE" : "UNDELEGATE";
50
- senders = [address];
51
- // convention was to use recipient for the new delegation address or "" if undelegation
52
- recipients = [tx.newDelegate ? tx.newDelegate.address : ""];
53
- break;
54
- case "reveal":
55
- type = "REVEAL";
56
- senders = [address];
57
- recipients = [address];
58
- break;
59
- case "migration":
60
- type = tx.balanceChange < 0 ? "OUT" : "IN";
61
- maybeValue = new BigNumber(Math.abs(tx.balanceChange || 0));
62
- senders = [address];
63
- recipients = [address];
64
- break;
65
- case "origination":
66
- type = "CREATE";
67
- maybeValue = new BigNumber(tx.contractBalance || 0);
68
- senders = [address];
69
- recipients = [tx.originatedContract?.address || ""];
70
- break;
71
- case "activation":
72
- type = "IN";
73
- senders = [address];
74
- recipients = [address];
75
- maybeValue = new BigNumber(tx.balance || 0);
76
- break;
77
- // TODO more type of tx
78
- default:
79
- console.warn("unsupported tx:", tx);
80
- return null;
81
- }
82
-
83
- let { hash } = tx;
84
- const {
85
- id,
86
- allocationFee,
87
- bakerFee,
88
- storageFee,
89
- level: blockHeight,
90
- block: blockHash,
91
- timestamp,
92
- } = tx;
93
-
94
- if (!hash) {
95
- // in migration case, there is no hash...
96
- hash = "";
97
- }
98
-
99
- let value = maybeValue || new BigNumber(0);
100
- if (type === "IN" && value.eq(0)) {
101
- return; // not interesting op
102
- }
103
-
104
- let fee = new BigNumber(bakerFee || 0);
105
-
106
- if (!hasFailed) {
107
- fee = fee.plus(allocationFee || 0).plus(storageFee || 0);
108
- }
109
-
110
- if (type !== "IN") {
111
- value = value.plus(fee);
112
- }
113
-
114
- return {
115
- id: encodeOperationId(accountId, hash, type),
116
- hash,
117
- type,
118
- value,
119
- fee,
120
- senders,
121
- recipients,
122
- blockHeight,
123
- blockHash,
124
- accountId,
125
- date: new Date(timestamp),
126
- extra: { id },
127
- hasFailed,
128
- };
129
- };
130
-
131
- export function reconciliatePublicKey(
132
- publicKey: string | undefined,
133
- account: TezosAccount | undefined,
134
- ): string {
135
- if (publicKey) return publicKey;
136
- if (account) {
137
- const { xpubOrAddress } = decodeAccountId(account.id);
138
- return xpubOrAddress;
139
- }
140
- throw new Error("publicKey wasn't properly restored");
141
- }
142
-
143
- export function encodeAddress(publicKey: Buffer) {
144
- const curve = 0;
145
- const curveData = {
146
- pkB58Prefix: Buffer.from([13, 15, 37, 217]),
147
- pkhB58Prefix: Buffer.from([6, 161, 159]),
148
- compressPublicKey: (publicKey: Buffer, curve: number) => {
149
- publicKey = publicKey.slice(0);
150
- publicKey[0] = curve;
151
- return publicKey;
152
- },
153
- };
154
- const publicKeyBuf = curveData.compressPublicKey(publicKey, curve);
155
- const key = publicKeyBuf.slice(1);
156
- const keyHashSize = 20;
157
- const hash = Buffer.from(blake2b(key, { dkLen: keyHashSize }));
158
- const address = bs58check.encode(Buffer.concat([curveData.pkhB58Prefix, hash]));
159
- return address;
160
- }
161
-
162
- export function isStringHex(s: string): boolean {
163
- for (let i = 0; i < s.length; i += 2) {
164
- const ss = s.slice(i, i + 2);
165
- const x = parseInt(ss, 16);
166
- if (Number.isNaN(x)) {
167
- return false;
168
- }
169
- }
170
- return true;
171
- }
@@ -1,18 +0,0 @@
1
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
- import { fetchAllBakers, hydrateBakers } from "../network/bakers";
3
-
4
- export const getPreloadStrategy = (_currency: CryptoCurrency) => ({
5
- preloadMaxAge: 30 * 1000,
6
- });
7
-
8
- export const preload = async () => {
9
- const bakers = await fetchAllBakers();
10
- return { bakers };
11
- };
12
-
13
- export const hydrate = (data: any) => {
14
- if (!data || typeof data !== "object") return;
15
- const { bakers } = data;
16
- if (!bakers || typeof bakers !== "object" || !Array.isArray(bakers)) return;
17
- hydrateBakers(bakers);
18
- };
@@ -1,35 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
3
- import prepareTransaction from "./prepareTransaction";
4
- import coinConfig, { TezosCoinConfig } from "../config";
5
- import { mockConfig } from "../test/config";
6
-
7
- describe.only("prepareTransaction", () => {
8
- beforeAll(() => {
9
- coinConfig.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
10
- });
11
-
12
- it("returns the same transaction when account balance is 0", async () => {
13
- // Given
14
- const tx = createFixtureTransaction({ amount: BigNumber(0) });
15
-
16
- // When
17
- const newTx = await prepareTransaction(createFixtureAccount(), tx);
18
-
19
- // Then
20
- expect(newTx).toBe(tx);
21
- });
22
-
23
- it("returns error when amount is 0", async () => {
24
- const tx = createFixtureTransaction({
25
- amount: BigNumber(0),
26
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
27
- });
28
-
29
- const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(10) }), tx);
30
-
31
- // initial expectation was proto.020-PsParisC.contract.empty_transaction
32
- // and evolved to proto.021-PsQuebec.contract.empty_transaction
33
- expect(newTx.taquitoError?.includes(".contract.empty_transaction")).toBeTruthy();
34
- });
35
- });