@ledgerhq/coin-tezos 6.5.0 → 6.6.0-nightly.1

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 +4 -30
  3. package/CHANGELOG.md +20 -0
  4. package/jest.integ.config.js +1 -0
  5. package/lib/api/index.d.ts.map +1 -1
  6. package/lib/api/index.js +188 -40
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/index.test.js +79 -10
  9. package/lib/api/index.test.js.map +1 -1
  10. package/lib/api/types.d.ts +7 -5
  11. package/lib/api/types.d.ts.map +1 -1
  12. package/lib/config.d.ts +4 -3
  13. package/lib/config.d.ts.map +1 -1
  14. package/lib/config.js.map +1 -1
  15. package/lib/index.d.ts +1 -1
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +1 -3
  18. package/lib/index.js.map +1 -1
  19. package/lib/logic/craftTransaction.d.ts.map +1 -1
  20. package/lib/logic/craftTransaction.js +7 -0
  21. package/lib/logic/craftTransaction.js.map +1 -1
  22. package/lib/logic/craftTransaction.test.js +1 -0
  23. package/lib/logic/craftTransaction.test.js.map +1 -1
  24. package/lib/logic/estimateFees.d.ts.map +1 -1
  25. package/lib/logic/estimateFees.integ.test.js +8 -2
  26. package/lib/logic/estimateFees.integ.test.js.map +1 -1
  27. package/lib/logic/estimateFees.js +119 -45
  28. package/lib/logic/estimateFees.js.map +1 -1
  29. package/lib/logic/getBalance.js +1 -1
  30. package/lib/logic/getBalance.js.map +1 -1
  31. package/lib/logic/getStakes.d.ts +3 -0
  32. package/lib/logic/getStakes.d.ts.map +1 -0
  33. package/lib/logic/getStakes.js +26 -0
  34. package/lib/logic/getStakes.js.map +1 -0
  35. package/lib/logic/getStakes.test.d.ts +2 -0
  36. package/lib/logic/getStakes.test.d.ts.map +1 -0
  37. package/lib/logic/getStakes.test.js +133 -0
  38. package/lib/logic/getStakes.test.js.map +1 -0
  39. package/lib/logic/index.d.ts +2 -0
  40. package/lib/logic/index.d.ts.map +1 -1
  41. package/lib/logic/index.js +5 -1
  42. package/lib/logic/index.js.map +1 -1
  43. package/lib/logic/listOperations.d.ts.map +1 -1
  44. package/lib/logic/listOperations.js +56 -10
  45. package/lib/logic/listOperations.js.map +1 -1
  46. package/lib/logic/listOperations.test.js +14 -10
  47. package/lib/logic/listOperations.test.js.map +1 -1
  48. package/lib/logic/validateIntent.d.ts +3 -0
  49. package/lib/logic/validateIntent.d.ts.map +1 -0
  50. package/lib/logic/validateIntent.js +179 -0
  51. package/lib/logic/validateIntent.js.map +1 -0
  52. package/lib/logic/validateIntent.test.d.ts +2 -0
  53. package/lib/logic/validateIntent.test.d.ts.map +1 -0
  54. package/lib/logic/validateIntent.test.js +249 -0
  55. package/lib/logic/validateIntent.test.js.map +1 -0
  56. package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
  57. package/lib/transaction.d.ts.map +1 -0
  58. package/lib/{bridge/transaction.js → transaction.js} +3 -3
  59. package/lib/transaction.js.map +1 -0
  60. package/lib/types/bridge.d.ts +3 -0
  61. package/lib/types/bridge.d.ts.map +1 -1
  62. package/lib/types/bridge.fixture.d.ts.map +1 -1
  63. package/lib/types/bridge.fixture.js +1 -0
  64. package/lib/types/bridge.fixture.js.map +1 -1
  65. package/lib/types/bridge.js.map +1 -1
  66. package/lib/utils.d.ts +48 -0
  67. package/lib/utils.d.ts.map +1 -0
  68. package/lib/utils.js +112 -0
  69. package/lib/utils.js.map +1 -0
  70. package/lib-es/api/index.d.ts.map +1 -1
  71. package/lib-es/api/index.js +189 -41
  72. package/lib-es/api/index.js.map +1 -1
  73. package/lib-es/api/index.test.js +79 -10
  74. package/lib-es/api/index.test.js.map +1 -1
  75. package/lib-es/api/types.d.ts +7 -5
  76. package/lib-es/api/types.d.ts.map +1 -1
  77. package/lib-es/config.d.ts +4 -3
  78. package/lib-es/config.d.ts.map +1 -1
  79. package/lib-es/config.js.map +1 -1
  80. package/lib-es/index.d.ts +1 -1
  81. package/lib-es/index.d.ts.map +1 -1
  82. package/lib-es/index.js +1 -1
  83. package/lib-es/index.js.map +1 -1
  84. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  85. package/lib-es/logic/craftTransaction.js +7 -0
  86. package/lib-es/logic/craftTransaction.js.map +1 -1
  87. package/lib-es/logic/craftTransaction.test.js +1 -0
  88. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  89. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  90. package/lib-es/logic/estimateFees.integ.test.js +8 -2
  91. package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
  92. package/lib-es/logic/estimateFees.js +119 -45
  93. package/lib-es/logic/estimateFees.js.map +1 -1
  94. package/lib-es/logic/getBalance.js +1 -1
  95. package/lib-es/logic/getBalance.js.map +1 -1
  96. package/lib-es/logic/getStakes.d.ts +3 -0
  97. package/lib-es/logic/getStakes.d.ts.map +1 -0
  98. package/lib-es/logic/getStakes.js +20 -0
  99. package/lib-es/logic/getStakes.js.map +1 -0
  100. package/lib-es/logic/getStakes.test.d.ts +2 -0
  101. package/lib-es/logic/getStakes.test.d.ts.map +1 -0
  102. package/lib-es/logic/getStakes.test.js +128 -0
  103. package/lib-es/logic/getStakes.test.js.map +1 -0
  104. package/lib-es/logic/index.d.ts +2 -0
  105. package/lib-es/logic/index.d.ts.map +1 -1
  106. package/lib-es/logic/index.js +2 -0
  107. package/lib-es/logic/index.js.map +1 -1
  108. package/lib-es/logic/listOperations.d.ts.map +1 -1
  109. package/lib-es/logic/listOperations.js +56 -10
  110. package/lib-es/logic/listOperations.js.map +1 -1
  111. package/lib-es/logic/listOperations.test.js +14 -10
  112. package/lib-es/logic/listOperations.test.js.map +1 -1
  113. package/lib-es/logic/validateIntent.d.ts +3 -0
  114. package/lib-es/logic/validateIntent.d.ts.map +1 -0
  115. package/lib-es/logic/validateIntent.js +173 -0
  116. package/lib-es/logic/validateIntent.js.map +1 -0
  117. package/lib-es/logic/validateIntent.test.d.ts +2 -0
  118. package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
  119. package/lib-es/logic/validateIntent.test.js +221 -0
  120. package/lib-es/logic/validateIntent.test.js.map +1 -0
  121. package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
  122. package/lib-es/transaction.d.ts.map +1 -0
  123. package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
  124. package/lib-es/transaction.js.map +1 -0
  125. package/lib-es/types/bridge.d.ts +3 -0
  126. package/lib-es/types/bridge.d.ts.map +1 -1
  127. package/lib-es/types/bridge.fixture.d.ts.map +1 -1
  128. package/lib-es/types/bridge.fixture.js +1 -0
  129. package/lib-es/types/bridge.fixture.js.map +1 -1
  130. package/lib-es/types/bridge.js.map +1 -1
  131. package/lib-es/utils.d.ts +48 -0
  132. package/lib-es/utils.d.ts.map +1 -0
  133. package/lib-es/utils.js +105 -0
  134. package/lib-es/utils.js.map +1 -0
  135. package/package.json +9 -12
  136. package/src/api/index.test.ts +87 -15
  137. package/src/api/index.ts +204 -55
  138. package/src/api/types.ts +11 -6
  139. package/src/config.ts +9 -2
  140. package/src/index.ts +1 -2
  141. package/src/logic/craftTransaction.test.ts +1 -0
  142. package/src/logic/craftTransaction.ts +8 -0
  143. package/src/logic/estimateFees.integ.test.ts +8 -2
  144. package/src/logic/estimateFees.ts +140 -49
  145. package/src/logic/getBalance.ts +1 -1
  146. package/src/logic/getStakes.test.ts +145 -0
  147. package/src/logic/getStakes.ts +20 -0
  148. package/src/logic/index.ts +2 -0
  149. package/src/logic/listOperations.test.ts +64 -54
  150. package/src/logic/listOperations.ts +57 -9
  151. package/src/logic/validateIntent.test.ts +262 -0
  152. package/src/logic/validateIntent.ts +207 -0
  153. package/src/{bridge/transaction.ts → transaction.ts} +4 -4
  154. package/src/types/bridge.fixture.ts +1 -0
  155. package/src/types/bridge.ts +6 -1
  156. package/src/utils.ts +115 -0
  157. package/lib/bridge/broadcast.d.ts +0 -4
  158. package/lib/bridge/broadcast.d.ts.map +0 -1
  159. package/lib/bridge/broadcast.js +0 -11
  160. package/lib/bridge/broadcast.js.map +0 -1
  161. package/lib/bridge/broadcast.test.d.ts +0 -2
  162. package/lib/bridge/broadcast.test.d.ts.map +0 -1
  163. package/lib/bridge/broadcast.test.js +0 -36
  164. package/lib/bridge/broadcast.test.js.map +0 -1
  165. package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
  166. package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
  167. package/lib/bridge/buildOptimisticOperation.js +0 -28
  168. package/lib/bridge/buildOptimisticOperation.js.map +0 -1
  169. package/lib/bridge/createTransaction.d.ts +0 -4
  170. package/lib/bridge/createTransaction.d.ts.map +0 -1
  171. package/lib/bridge/createTransaction.js +0 -24
  172. package/lib/bridge/createTransaction.js.map +0 -1
  173. package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
  174. package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
  175. package/lib/bridge/estimateMaxSpendable.js +0 -30
  176. package/lib/bridge/estimateMaxSpendable.js.map +0 -1
  177. package/lib/bridge/getFeesForTransaction.d.ts +0 -21
  178. package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
  179. package/lib/bridge/getFeesForTransaction.js +0 -39
  180. package/lib/bridge/getFeesForTransaction.js.map +0 -1
  181. package/lib/bridge/getTransactionStatus.d.ts +0 -4
  182. package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
  183. package/lib/bridge/getTransactionStatus.js +0 -108
  184. package/lib/bridge/getTransactionStatus.js.map +0 -1
  185. package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
  186. package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
  187. package/lib/bridge/getTransactionStatus.test.js +0 -107
  188. package/lib/bridge/getTransactionStatus.test.js.map +0 -1
  189. package/lib/bridge/index.d.ts +0 -10
  190. package/lib/bridge/index.d.ts.map +0 -1
  191. package/lib/bridge/index.js +0 -59
  192. package/lib/bridge/index.js.map +0 -1
  193. package/lib/bridge/logic.d.ts +0 -10
  194. package/lib/bridge/logic.d.ts.map +0 -1
  195. package/lib/bridge/logic.js +0 -155
  196. package/lib/bridge/logic.js.map +0 -1
  197. package/lib/bridge/preload.d.ts +0 -9
  198. package/lib/bridge/preload.d.ts.map +0 -1
  199. package/lib/bridge/preload.js +0 -23
  200. package/lib/bridge/preload.js.map +0 -1
  201. package/lib/bridge/prepareTransaction.d.ts +0 -5
  202. package/lib/bridge/prepareTransaction.d.ts.map +0 -1
  203. package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
  204. package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  205. package/lib/bridge/prepareTransaction.integ.test.js +0 -34
  206. package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
  207. package/lib/bridge/prepareTransaction.js +0 -57
  208. package/lib/bridge/prepareTransaction.js.map +0 -1
  209. package/lib/bridge/prepareTransaction.test.d.ts +0 -2
  210. package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
  211. package/lib/bridge/prepareTransaction.test.js +0 -178
  212. package/lib/bridge/prepareTransaction.test.js.map +0 -1
  213. package/lib/bridge/serialization.d.ts +0 -7
  214. package/lib/bridge/serialization.d.ts.map +0 -1
  215. package/lib/bridge/serialization.js +0 -26
  216. package/lib/bridge/serialization.js.map +0 -1
  217. package/lib/bridge/signOperation.d.ts +0 -16
  218. package/lib/bridge/signOperation.d.ts.map +0 -1
  219. package/lib/bridge/signOperation.js +0 -88
  220. package/lib/bridge/signOperation.js.map +0 -1
  221. package/lib/bridge/signOperation.test.d.ts +0 -2
  222. package/lib/bridge/signOperation.test.d.ts.map +0 -1
  223. package/lib/bridge/signOperation.test.js +0 -283
  224. package/lib/bridge/signOperation.test.js.map +0 -1
  225. package/lib/bridge/synchronization.d.ts +0 -5
  226. package/lib/bridge/synchronization.d.ts.map +0 -1
  227. package/lib/bridge/synchronization.integ.test.d.ts +0 -2
  228. package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
  229. package/lib/bridge/synchronization.integ.test.js +0 -32
  230. package/lib/bridge/synchronization.integ.test.js.map +0 -1
  231. package/lib/bridge/synchronization.js +0 -100
  232. package/lib/bridge/synchronization.js.map +0 -1
  233. package/lib/bridge/transaction.d.ts.map +0 -1
  234. package/lib/bridge/transaction.js.map +0 -1
  235. package/lib-es/bridge/broadcast.d.ts +0 -4
  236. package/lib-es/bridge/broadcast.d.ts.map +0 -1
  237. package/lib-es/bridge/broadcast.js +0 -7
  238. package/lib-es/bridge/broadcast.js.map +0 -1
  239. package/lib-es/bridge/broadcast.test.d.ts +0 -2
  240. package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
  241. package/lib-es/bridge/broadcast.test.js +0 -31
  242. package/lib-es/bridge/broadcast.test.js.map +0 -1
  243. package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
  244. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
  245. package/lib-es/bridge/buildOptimisticOperation.js +0 -21
  246. package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
  247. package/lib-es/bridge/createTransaction.d.ts +0 -4
  248. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  249. package/lib-es/bridge/createTransaction.js +0 -17
  250. package/lib-es/bridge/createTransaction.js.map +0 -1
  251. package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
  252. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
  253. package/lib-es/bridge/estimateMaxSpendable.js +0 -23
  254. package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
  255. package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
  256. package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
  257. package/lib-es/bridge/getFeesForTransaction.js +0 -33
  258. package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
  259. package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
  260. package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
  261. package/lib-es/bridge/getTransactionStatus.js +0 -101
  262. package/lib-es/bridge/getTransactionStatus.js.map +0 -1
  263. package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
  264. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
  265. package/lib-es/bridge/getTransactionStatus.test.js +0 -102
  266. package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
  267. package/lib-es/bridge/index.d.ts +0 -10
  268. package/lib-es/bridge/index.d.ts.map +0 -1
  269. package/lib-es/bridge/index.js +0 -53
  270. package/lib-es/bridge/index.js.map +0 -1
  271. package/lib-es/bridge/logic.d.ts +0 -10
  272. package/lib-es/bridge/logic.d.ts.map +0 -1
  273. package/lib-es/bridge/logic.js +0 -145
  274. package/lib-es/bridge/logic.js.map +0 -1
  275. package/lib-es/bridge/preload.d.ts +0 -9
  276. package/lib-es/bridge/preload.d.ts.map +0 -1
  277. package/lib-es/bridge/preload.js +0 -17
  278. package/lib-es/bridge/preload.js.map +0 -1
  279. package/lib-es/bridge/prepareTransaction.d.ts +0 -5
  280. package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
  281. package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
  282. package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  283. package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
  284. package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
  285. package/lib-es/bridge/prepareTransaction.js +0 -50
  286. package/lib-es/bridge/prepareTransaction.js.map +0 -1
  287. package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
  288. package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
  289. package/lib-es/bridge/prepareTransaction.test.js +0 -173
  290. package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
  291. package/lib-es/bridge/serialization.d.ts +0 -7
  292. package/lib-es/bridge/serialization.d.ts.map +0 -1
  293. package/lib-es/bridge/serialization.js +0 -20
  294. package/lib-es/bridge/serialization.js.map +0 -1
  295. package/lib-es/bridge/signOperation.d.ts +0 -16
  296. package/lib-es/bridge/signOperation.d.ts.map +0 -1
  297. package/lib-es/bridge/signOperation.js +0 -83
  298. package/lib-es/bridge/signOperation.js.map +0 -1
  299. package/lib-es/bridge/signOperation.test.d.ts +0 -2
  300. package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
  301. package/lib-es/bridge/signOperation.test.js +0 -255
  302. package/lib-es/bridge/signOperation.test.js.map +0 -1
  303. package/lib-es/bridge/synchronization.d.ts +0 -5
  304. package/lib-es/bridge/synchronization.d.ts.map +0 -1
  305. package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
  306. package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
  307. package/lib-es/bridge/synchronization.integ.test.js +0 -27
  308. package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
  309. package/lib-es/bridge/synchronization.js +0 -70
  310. package/lib-es/bridge/synchronization.js.map +0 -1
  311. package/lib-es/bridge/transaction.d.ts.map +0 -1
  312. package/lib-es/bridge/transaction.js.map +0 -1
  313. package/src/bridge/broadcast.test.ts +0 -36
  314. package/src/bridge/broadcast.ts +0 -13
  315. package/src/bridge/buildOptimisticOperation.ts +0 -28
  316. package/src/bridge/createTransaction.ts +0 -19
  317. package/src/bridge/estimateMaxSpendable.ts +0 -37
  318. package/src/bridge/getFeesForTransaction.ts +0 -49
  319. package/src/bridge/getTransactionStatus.test.ts +0 -124
  320. package/src/bridge/getTransactionStatus.ts +0 -123
  321. package/src/bridge/index.ts +0 -74
  322. package/src/bridge/logic.ts +0 -171
  323. package/src/bridge/preload.ts +0 -18
  324. package/src/bridge/prepareTransaction.integ.test.ts +0 -35
  325. package/src/bridge/prepareTransaction.test.ts +0 -205
  326. package/src/bridge/prepareTransaction.ts +0 -69
  327. package/src/bridge/serialization.ts +0 -27
  328. package/src/bridge/signOperation.test.ts +0 -284
  329. package/src/bridge/signOperation.ts +0 -130
  330. package/src/bridge/synchronization.integ.test.ts +0 -33
  331. package/src/bridge/synchronization.ts +0 -100
@@ -1,205 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
3
- import prepareTransaction from "./prepareTransaction";
4
- import { faker } from "@faker-js/faker";
5
- import coinConfig, { TezosCoinConfig } from "../config";
6
- import { mockConfig } from "../test/config";
7
- import { COST_PER_BYTE, getRevealFee } from "@taquito/taquito";
8
-
9
- const mockTezosEstimate = jest.fn();
10
- jest.mock("../logic/tezosToolkit", () => ({
11
- getTezosToolkit: () => ({
12
- setProvider: jest.fn(),
13
- estimate: {
14
- transfer: () => mockTezosEstimate(),
15
- },
16
- }),
17
- }));
18
-
19
- describe("prepareTransaction", () => {
20
- beforeAll(() => {
21
- coinConfig.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
22
- });
23
-
24
- beforeEach(() => {
25
- mockTezosEstimate.mockReset();
26
- });
27
-
28
- it("returns the same transaction when account balance is 0", async () => {
29
- // Given
30
- const tx = createFixtureTransaction({ amount: BigNumber(0) });
31
-
32
- // When
33
- const newTx = await prepareTransaction(createFixtureAccount(), tx);
34
-
35
- // Then
36
- expect(newTx).toBe(tx);
37
- });
38
-
39
- it("returns error when amount is 0", async () => {
40
- // Given
41
- const tx = createFixtureTransaction({
42
- amount: BigNumber(0),
43
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
44
- });
45
- mockTezosEstimate.mockRejectedValue({
46
- id: "proto.020-PsParisC.contract.empty_transaction",
47
- });
48
-
49
- // When
50
- const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(10) }), tx);
51
-
52
- // Then
53
- expect(newTx.taquitoError).toEqual("proto.020-PsParisC.contract.empty_transaction");
54
- });
55
-
56
- it("returns new transaction with estimated fees by TezosToolkit", async () => {
57
- // Given
58
- const tx = createFixtureTransaction({
59
- amount: BigNumber(200),
60
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
61
- });
62
- const tezosEstimate = {
63
- suggestedFeeMutez: faker.number.int(20),
64
- gasLimit: faker.number.int(20),
65
- storageLimit: faker.number.int(20),
66
- };
67
- mockTezosEstimate.mockResolvedValue(tezosEstimate);
68
-
69
- // When
70
- const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(1_000) }), tx);
71
-
72
- // Then
73
- expect(newTx).toEqual({
74
- ...tx,
75
- fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
76
- estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
77
- gasLimit: new BigNumber(tezosEstimate.gasLimit),
78
- storageLimit: new BigNumber(tezosEstimate.storageLimit),
79
- });
80
- });
81
-
82
- it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from revealed account to revealed account", async () => {
83
- // Given
84
- const tx = createFixtureTransaction({
85
- amount: BigNumber(200),
86
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
87
- useAllAmount: true,
88
- });
89
- const tezosEstimate = {
90
- suggestedFeeMutez: faker.number.int(20),
91
- gasLimit: faker.number.int(20),
92
- storageLimit: faker.number.int(20),
93
- opSize: faker.number.int(20),
94
- burnFeeMutez: faker.number.int(0),
95
- };
96
- mockTezosEstimate.mockResolvedValue(tezosEstimate);
97
- const account = createFixtureAccount({ balance: BigNumber(1_000) });
98
-
99
- // When
100
- const newTx = await prepareTransaction(account, tx);
101
-
102
- // Then
103
- const gasLimit = 500; // hardcoded in the function
104
- const maxAmount = account.balance.minus(tezosEstimate.suggestedFeeMutez);
105
-
106
- expect(newTx).toEqual({
107
- ...tx,
108
- fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
109
- estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
110
- gasLimit: new BigNumber(tezosEstimate.gasLimit),
111
- storageLimit: new BigNumber(tezosEstimate.storageLimit),
112
- amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
113
- });
114
- });
115
-
116
- it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from revealed account to account with zero balance", async () => {
117
- // Given
118
- const tx = createFixtureTransaction({
119
- amount: BigNumber(0),
120
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
121
- useAllAmount: true,
122
- });
123
- const tezosEstimate = {
124
- suggestedFeeMutez: faker.number.int(20),
125
- gasLimit: faker.number.int(20),
126
- storageLimit: faker.number.int(20),
127
- opSize: faker.number.int(20),
128
- burnFeeMutez: faker.number.int({ min: 1, max: 20 }),
129
- };
130
- mockTezosEstimate.mockResolvedValue(tezosEstimate);
131
- const account = createFixtureAccount({ balance: BigNumber(1_000) });
132
- // When
133
- const newTx = await prepareTransaction(account, tx);
134
-
135
- // Then
136
- const gasLimit = 500; // hardcoded in the function
137
- const computedFees = new BigNumber(
138
- tezosEstimate.suggestedFeeMutez + tezosEstimate.burnFeeMutez - 20 * COST_PER_BYTE,
139
- );
140
-
141
- const maxAmount = account.balance.minus(computedFees);
142
-
143
- expect(newTx).toEqual({
144
- ...tx,
145
- fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
146
- estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
147
- gasLimit: new BigNumber(tezosEstimate.gasLimit),
148
- storageLimit: new BigNumber(tezosEstimate.storageLimit),
149
- amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
150
- });
151
- });
152
-
153
- it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from unrevealed account to revealed account", async () => {
154
- // Given
155
- const tx = createFixtureTransaction({
156
- amount: BigNumber(200),
157
- recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
158
- useAllAmount: true,
159
- });
160
- const tezosEstimate = {
161
- suggestedFeeMutez: faker.number.int(20),
162
- gasLimit: faker.number.int(20),
163
- storageLimit: faker.number.int(20),
164
- opSize: faker.number.int(20),
165
- burnFeeMutez: faker.number.int(0),
166
- };
167
- mockTezosEstimate.mockResolvedValue(tezosEstimate);
168
- const account = createFixtureAccount({ balance: BigNumber(1_000) });
169
- account.tezosResources.revealed = false;
170
- // When
171
- const newTx = await prepareTransaction(account, tx);
172
-
173
- // Then
174
- const gasLimit = 500; // hardcoded in the function
175
- const computedFees = new BigNumber(
176
- tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
177
- );
178
-
179
- const maxAmount = account.balance.minus(computedFees);
180
-
181
- expect(newTx).toEqual({
182
- ...tx,
183
- fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
184
- estimatedFees: new BigNumber(
185
- tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
186
- ),
187
- gasLimit: new BigNumber(tezosEstimate.gasLimit),
188
- storageLimit: new BigNumber(tezosEstimate.storageLimit),
189
- amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
190
- });
191
- });
192
-
193
- // it("returns the passed transaction if fees are the same", async () => {
194
- // // Given
195
- // const fees = new BigNumber(faker.number.int(50));
196
- // mockEstimateFees.mockResolvedValue(fees);
197
- // const tx = createFixtureTransaction({ fees });
198
-
199
- // // When
200
- // const newTx = await prepareTransaction(createFixtureAccount(), tx);
201
-
202
- // // Then
203
- // expect(newTx).toBe(tx);
204
- // });
205
- });
@@ -1,69 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { AccountBridge } from "@ledgerhq/types-live";
3
- import { TezosAccount, Transaction } from "../types";
4
- import { validateRecipient } from "../logic";
5
- import getEstimatedFees from "./getFeesForTransaction";
6
- import coinConfig from "../config";
7
-
8
- function bnEq(a: BigNumber | null | undefined, b: BigNumber | null | undefined): boolean {
9
- return !a && !b ? true : !a || !b ? false : a.eq(b);
10
- }
11
-
12
- function maxBigNumber(a: BigNumber, b: BigNumber): BigNumber {
13
- return a.isGreaterThan(b) ? a : b;
14
- }
15
-
16
- export const prepareTransaction: AccountBridge<
17
- Transaction,
18
- TezosAccount
19
- >["prepareTransaction"] = async (account, transaction) => {
20
- if (account.balance.lte(0)) {
21
- return Promise.resolve(transaction);
22
- }
23
-
24
- // basic check to confirm the transaction is "complete"
25
- if (transaction.mode !== "undelegate") {
26
- if (!transaction.recipient) {
27
- return Promise.resolve(transaction);
28
- }
29
-
30
- const { recipientError } = await validateRecipient(transaction.recipient);
31
- if (recipientError) {
32
- return Promise.resolve(transaction);
33
- }
34
- }
35
-
36
- const estimation = await getEstimatedFees({ account, transaction });
37
- const minGasLimit = coinConfig.getCoinConfig().fees.minGasLimit;
38
- const minStorageLimit = coinConfig.getCoinConfig().fees.minStorageLimit;
39
- const minFees = coinConfig.getCoinConfig().fees.minFees;
40
- const minEstimatedFees = coinConfig.getCoinConfig().fees.minEstimatedFees;
41
-
42
- estimation.gasLimit = maxBigNumber(estimation.gasLimit, new BigNumber(minGasLimit));
43
- estimation.storageLimit = maxBigNumber(estimation.storageLimit, new BigNumber(minStorageLimit));
44
- estimation.fees = maxBigNumber(estimation.fees, new BigNumber(minFees));
45
- estimation.estimatedFees = maxBigNumber(
46
- estimation.estimatedFees,
47
- new BigNumber(minEstimatedFees),
48
- );
49
- const tx: Transaction = {
50
- ...transaction,
51
- ...estimation,
52
- };
53
-
54
- // nothing changed
55
- if (
56
- bnEq(tx.estimatedFees, transaction.estimatedFees) &&
57
- bnEq(tx.fees, transaction.fees) &&
58
- bnEq(tx.gasLimit, transaction.gasLimit) &&
59
- bnEq(tx.storageLimit, transaction.storageLimit) &&
60
- bnEq(tx.amount, transaction.amount) &&
61
- tx.taquitoError === transaction.taquitoError
62
- ) {
63
- return transaction;
64
- }
65
-
66
- return tx;
67
- };
68
-
69
- export default prepareTransaction;
@@ -1,27 +0,0 @@
1
- import type { TezosAccount, TezosAccountRaw, TezosResources, TezosResourcesRaw } from "../types";
2
- import { Account, AccountRaw } from "@ledgerhq/types-live";
3
-
4
- export function toTezosResourcesRaw(r: TezosResources): TezosResourcesRaw {
5
- const { revealed, counter } = r;
6
- return { revealed, counter };
7
- }
8
-
9
- export function fromTezosResourcesRaw(r: TezosResourcesRaw): TezosResources {
10
- const { revealed, counter } = r;
11
- return { revealed, counter };
12
- }
13
-
14
- export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
15
- const tezosAccount = account as TezosAccount;
16
- if (tezosAccount.tezosResources) {
17
- (accountRaw as TezosAccountRaw).tezosResources = toTezosResourcesRaw(
18
- tezosAccount.tezosResources,
19
- );
20
- }
21
- }
22
-
23
- export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
24
- const tezosResourcesRaw = (accountRaw as TezosAccountRaw).tezosResources;
25
- if (tezosResourcesRaw)
26
- (account as TezosAccount).tezosResources = fromTezosResourcesRaw(tezosResourcesRaw);
27
- }
@@ -1,284 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { getRevealFee, OpKind } from "@taquito/taquito";
3
- import { SignOperationEvent } from "@ledgerhq/types-live";
4
- import buildSignOperation, { getOperationContents } from "./signOperation";
5
- import config, { type TezosCoinConfig } from "../config";
6
- import { TezosSigner } from "../types";
7
- import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
8
- import { mockConfig } from "../test/config";
9
-
10
- const mockForgeOperations = jest.fn();
11
- const mockEstimateReveal = jest.fn();
12
- jest.mock("@taquito/taquito", () => ({
13
- ...jest.requireActual("@taquito/taquito"),
14
- TezosToolkit: jest.fn().mockReturnValue({
15
- setProvider: jest.fn(),
16
- rpc: {
17
- getBlock: jest.fn().mockResolvedValue({ hash: "hash" }),
18
- getContract: jest.fn().mockResolvedValue({ counter: "12" }),
19
- forgeOperations: () => mockForgeOperations(),
20
- },
21
- estimate: {
22
- reveal: () => mockEstimateReveal(),
23
- },
24
- }),
25
- }));
26
-
27
- describe("signOperation", () => {
28
- const mockSign = jest.fn().mockResolvedValue({
29
- bytes: "SIG_BYTES",
30
- sig: "SIG",
31
- prefixSig: "PREFIX_SIG",
32
- sbytes: "03SBYTES",
33
- });
34
- const fakeSigner = {
35
- getAddress: jest.fn(),
36
- signOperation: jest.fn(),
37
- createLedgerSigner: () => ({
38
- publicKey: () => Promise.resolve("PUBKEY"),
39
- publicKeyHash: () => Promise.resolve("PUBKEYHASH"),
40
- sign: (arg: unknown) => mockSign(arg),
41
- secretKey: () => Promise.resolve(undefined),
42
- }),
43
- };
44
- const signerContext = <T>(_deviceId: string, fn: (signer: TezosSigner) => Promise<T>) =>
45
- fn(fakeSigner);
46
- const signOperation = buildSignOperation(signerContext);
47
- const deviceId = "dummyDeviceId";
48
-
49
- beforeAll(() => {
50
- config.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
51
- });
52
-
53
- afterEach(() => {
54
- mockForgeOperations.mockClear();
55
- mockEstimateReveal.mockClear();
56
- mockSign.mockClear();
57
- });
58
-
59
- it("returns events in the right order", done => {
60
- // GIVEN
61
- const account = createFixtureAccount();
62
- const transaction = createFixtureTransaction({ fees: BigNumber(0) });
63
- mockForgeOperations.mockResolvedValue("FORGED_OP");
64
-
65
- // WHEN & THEN
66
- const expectedEvent = [
67
- {
68
- type: "device-signature-requested",
69
- },
70
- {
71
- type: "device-signature-granted",
72
- },
73
- {
74
- type: "signed",
75
- },
76
- ];
77
- let eventIdx = 0;
78
- signOperation({ account, deviceId, transaction }).forEach(e => {
79
- try {
80
- expect(e.type).toEqual(expectedEvent[eventIdx].type);
81
- eventIdx++;
82
-
83
- if (eventIdx === expectedEvent.length) {
84
- done();
85
- }
86
- } catch (err) {
87
- done(err);
88
- }
89
- });
90
- });
91
-
92
- it("returns signature value from LedgerSigner", done => {
93
- // GIVEN
94
- const account = createFixtureAccount();
95
- const transaction = createFixtureTransaction({ fees: new BigNumber(0) });
96
- mockForgeOperations.mockResolvedValue("f0463d");
97
-
98
- // WHEN & THEN
99
- const subscriber = signOperation({ account, deviceId, transaction }).subscribe(
100
- (e: SignOperationEvent) => {
101
- if (e.type === "signed") {
102
- const signature = e.signedOperation.signature;
103
- expect(signature).toEqual("SBYTES");
104
- expect(mockForgeOperations).toHaveBeenCalledTimes(1);
105
- expect(mockSign).toHaveBeenCalledTimes(1);
106
- expect(mockSign.mock.lastCall[0]).toEqual(
107
- Buffer.concat([Buffer.from("03", "hex"), Buffer.from("f0463d", "hex")]).toString("hex"),
108
- );
109
-
110
- // Cleanup
111
- subscriber.unsubscribe();
112
- done();
113
- }
114
- },
115
- );
116
- });
117
- });
118
-
119
- describe("getOperationContents - revealed account", () => {
120
- const account = createFixtureAccount({ freshAddress: "tz1addr" });
121
-
122
- it("mode - send", async () => {
123
- const transaction = createFixtureTransaction({
124
- family: "tezos",
125
- amount: new BigNumber(0),
126
- recipient: "RECIPIENT_ADD",
127
- fees: new BigNumber(0),
128
- mode: "send",
129
- gasLimit: new BigNumber(0),
130
- storageLimit: new BigNumber(0),
131
- });
132
-
133
- const { type, contents } = await getOperationContents({
134
- account,
135
- transaction,
136
- counter: 0,
137
- public_key: "pk",
138
- public_key_hash: "pkh",
139
- });
140
-
141
- expect(type).toBe("OUT");
142
- expect(contents.length).toEqual(1);
143
- expect(contents).toStrictEqual([
144
- {
145
- kind: OpKind.TRANSACTION,
146
- amount: transaction.amount.toString(),
147
- destination: transaction.recipient,
148
- source: "tz1addr",
149
- counter: "1",
150
- fee: new BigNumber(0).toString(),
151
- gas_limit: new BigNumber(0).toString(),
152
- storage_limit: new BigNumber(0).toString(),
153
- },
154
- ]);
155
- expect(mockEstimateReveal).not.toHaveBeenCalled();
156
- });
157
-
158
- it("mode - delegate", async () => {
159
- const transaction = createFixtureTransaction({
160
- family: "tezos",
161
- amount: new BigNumber(0),
162
- recipient: "RECIPIENT_ADD",
163
- fees: new BigNumber(0),
164
- mode: "delegate",
165
- gasLimit: new BigNumber(0),
166
- storageLimit: new BigNumber(0),
167
- });
168
-
169
- const { type, contents } = await getOperationContents({
170
- account,
171
- transaction,
172
- counter: 0,
173
- public_key: "pk",
174
- public_key_hash: "pkh",
175
- });
176
-
177
- expect(type).toBe("DELEGATE");
178
- expect(contents.length).toEqual(1);
179
- expect(contents).toStrictEqual([
180
- {
181
- kind: OpKind.DELEGATION,
182
- source: "tz1addr",
183
- counter: "1",
184
- fee: new BigNumber(0).toString(),
185
- gas_limit: new BigNumber(0).toString(),
186
- storage_limit: new BigNumber(0).toString(),
187
- delegate: transaction.recipient,
188
- },
189
- ]);
190
- expect(mockEstimateReveal).not.toHaveBeenCalled();
191
- });
192
-
193
- it("mode - undelegate", async () => {
194
- const transaction = createFixtureTransaction({
195
- family: "tezos",
196
- amount: new BigNumber(0),
197
- recipient: "",
198
- fees: new BigNumber(0),
199
- mode: "undelegate",
200
- gasLimit: new BigNumber(0),
201
- storageLimit: new BigNumber(0),
202
- });
203
-
204
- const { type, contents } = await getOperationContents({
205
- account,
206
- transaction,
207
- counter: 0,
208
- public_key: "pk",
209
- public_key_hash: "pkh",
210
- });
211
-
212
- expect(type).toBe("UNDELEGATE");
213
- expect(contents.length).toEqual(1);
214
- expect(contents).toStrictEqual([
215
- {
216
- kind: OpKind.DELEGATION,
217
- source: "tz1addr",
218
- counter: "1",
219
- fee: new BigNumber(0).toString(),
220
- gas_limit: new BigNumber(0).toString(),
221
- storage_limit: new BigNumber(0).toString(),
222
- },
223
- ]);
224
- expect(mockEstimateReveal).not.toHaveBeenCalled();
225
- });
226
-
227
- describe("getOperationContents - not revealed account", () => {
228
- const account = createFixtureAccount({
229
- freshAddress: "tz1addr",
230
- // We don't use `counter` in the OperationContents computation
231
- tezosResources: { revealed: false, counter: -10 },
232
- });
233
-
234
- it("mode - send", async () => {
235
- // Given
236
- mockEstimateReveal.mockResolvedValue({
237
- gasLimit: 100,
238
- storageLimit: 200,
239
- });
240
- const transaction = createFixtureTransaction({
241
- family: "tezos",
242
- amount: new BigNumber(0),
243
- recipient: "RECIPIENT_ADD",
244
- fees: new BigNumber(0),
245
- mode: "send",
246
- gasLimit: new BigNumber(0),
247
- storageLimit: new BigNumber(0),
248
- });
249
-
250
- const { type, contents } = await getOperationContents({
251
- account,
252
- transaction,
253
- counter: 0,
254
- public_key: "pk",
255
- public_key_hash: "pkh",
256
- });
257
-
258
- expect(type).toBe("OUT");
259
- expect(contents.length).toEqual(2);
260
- expect(contents).toStrictEqual([
261
- {
262
- kind: OpKind.REVEAL,
263
- fee: getRevealFee(account.freshAddress).toString(),
264
- gas_limit: "100",
265
- storage_limit: "200",
266
- source: "pkh",
267
- counter: "1",
268
- public_key: "pk",
269
- },
270
- {
271
- kind: OpKind.TRANSACTION,
272
- amount: transaction.amount.toString(),
273
- destination: transaction.recipient,
274
- source: "tz1addr",
275
- counter: "2",
276
- fee: new BigNumber(0).toString(),
277
- gas_limit: new BigNumber(0).toString(),
278
- storage_limit: new BigNumber(0).toString(),
279
- },
280
- ]);
281
- expect(mockEstimateReveal).toHaveBeenCalledTimes(1);
282
- });
283
- });
284
- });