@ledgerhq/coin-vechain 3.0.0 → 4.0.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 (249) hide show
  1. package/.unimportedrc.json +2 -1
  2. package/CHANGELOG.md +42 -2699
  3. package/lib/api/index.d.ts +2 -2
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.js +25 -22
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/bridge/broadcast.d.ts.map +1 -1
  8. package/lib/bridge/broadcast.js +2 -1
  9. package/lib/bridge/broadcast.js.map +1 -1
  10. package/lib/bridge/createTransaction.js +1 -1
  11. package/lib/bridge/createTransaction.js.map +1 -1
  12. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  13. package/lib/bridge/estimateMaxSpendable.js +2 -1
  14. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  15. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  16. package/lib/bridge/getTransactionStatus.js +2 -1
  17. package/lib/bridge/getTransactionStatus.js.map +1 -1
  18. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  19. package/lib/bridge/prepareTransaction.js +4 -2
  20. package/lib/bridge/prepareTransaction.js.map +1 -1
  21. package/lib/bridge/synchronisation.d.ts.map +1 -1
  22. package/lib/bridge/synchronisation.js +6 -4
  23. package/lib/bridge/synchronisation.js.map +1 -1
  24. package/lib/common-logic/calculateGasFees.d.ts +2 -1
  25. package/lib/common-logic/calculateGasFees.d.ts.map +1 -1
  26. package/lib/common-logic/calculateGasFees.js +3 -3
  27. package/lib/common-logic/calculateGasFees.js.map +1 -1
  28. package/lib/common-logic/calculateTransactionInfo.d.ts +2 -1
  29. package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -1
  30. package/lib/common-logic/calculateTransactionInfo.js +2 -2
  31. package/lib/common-logic/calculateTransactionInfo.js.map +1 -1
  32. package/lib/common-logic/estimateGas.d.ts +2 -1
  33. package/lib/common-logic/estimateGas.d.ts.map +1 -1
  34. package/lib/common-logic/estimateGas.js +2 -2
  35. package/lib/common-logic/estimateGas.js.map +1 -1
  36. package/lib/common-logic/getThorClient.d.ts +2 -1
  37. package/lib/common-logic/getThorClient.d.ts.map +1 -1
  38. package/lib/common-logic/getThorClient.js +2 -2
  39. package/lib/common-logic/getThorClient.js.map +1 -1
  40. package/lib/common-logic/mapTransfersToOperations.d.ts +3 -2
  41. package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -1
  42. package/lib/common-logic/mapTransfersToOperations.js +4 -4
  43. package/lib/common-logic/mapTransfersToOperations.js.map +1 -1
  44. package/lib/config.d.ts +10 -4
  45. package/lib/config.d.ts.map +1 -1
  46. package/lib/config.js +9 -5
  47. package/lib/config.js.map +1 -1
  48. package/lib/logic/account/getBalance.d.ts +2 -1
  49. package/lib/logic/account/getBalance.d.ts.map +1 -1
  50. package/lib/logic/account/getBalance.js +3 -2
  51. package/lib/logic/account/getBalance.js.map +1 -1
  52. package/lib/logic/history/getBlock.d.ts +2 -1
  53. package/lib/logic/history/getBlock.d.ts.map +1 -1
  54. package/lib/logic/history/getBlock.js +3 -2
  55. package/lib/logic/history/getBlock.js.map +1 -1
  56. package/lib/logic/history/getBlockInfo.d.ts +2 -1
  57. package/lib/logic/history/getBlockInfo.d.ts.map +1 -1
  58. package/lib/logic/history/getBlockInfo.js +3 -2
  59. package/lib/logic/history/getBlockInfo.js.map +1 -1
  60. package/lib/logic/history/lastBlock.d.ts +2 -1
  61. package/lib/logic/history/lastBlock.d.ts.map +1 -1
  62. package/lib/logic/history/lastBlock.js +4 -3
  63. package/lib/logic/history/lastBlock.js.map +1 -1
  64. package/lib/logic/history/listOperations.d.ts +2 -1
  65. package/lib/logic/history/listOperations.d.ts.map +1 -1
  66. package/lib/logic/history/listOperations.js +5 -4
  67. package/lib/logic/history/listOperations.js.map +1 -1
  68. package/lib/logic/transaction/broadcast.d.ts +2 -1
  69. package/lib/logic/transaction/broadcast.d.ts.map +1 -1
  70. package/lib/logic/transaction/broadcast.js +3 -2
  71. package/lib/logic/transaction/broadcast.js.map +1 -1
  72. package/lib/logic/transaction/combine.d.ts +1 -1
  73. package/lib/logic/transaction/combine.d.ts.map +1 -1
  74. package/lib/logic/transaction/combine.js +4 -1
  75. package/lib/logic/transaction/combine.js.map +1 -1
  76. package/lib/logic/transaction/craftTransaction.d.ts +2 -1
  77. package/lib/logic/transaction/craftTransaction.d.ts.map +1 -1
  78. package/lib/logic/transaction/craftTransaction.js +11 -10
  79. package/lib/logic/transaction/craftTransaction.js.map +1 -1
  80. package/lib/logic/transaction/estimateFees.d.ts +2 -1
  81. package/lib/logic/transaction/estimateFees.d.ts.map +1 -1
  82. package/lib/logic/transaction/estimateFees.js +2 -2
  83. package/lib/logic/transaction/estimateFees.js.map +1 -1
  84. package/lib/network/getBlock.d.ts +2 -1
  85. package/lib/network/getBlock.d.ts.map +1 -1
  86. package/lib/network/getBlock.js +2 -2
  87. package/lib/network/getBlock.js.map +1 -1
  88. package/lib/network/getFees.d.ts +2 -1
  89. package/lib/network/getFees.d.ts.map +1 -1
  90. package/lib/network/getFees.js +2 -2
  91. package/lib/network/getFees.js.map +1 -1
  92. package/lib/network/sdk.d.ts +7 -6
  93. package/lib/network/sdk.d.ts.map +1 -1
  94. package/lib/network/sdk.js +18 -18
  95. package/lib/network/sdk.js.map +1 -1
  96. package/lib/test/context.d.ts +6 -0
  97. package/lib/test/context.d.ts.map +1 -0
  98. package/lib/test/context.js +15 -0
  99. package/lib/test/context.js.map +1 -0
  100. package/lib-es/api/index.d.ts +2 -2
  101. package/lib-es/api/index.d.ts.map +1 -1
  102. package/lib-es/api/index.js +25 -22
  103. package/lib-es/api/index.js.map +1 -1
  104. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  105. package/lib-es/bridge/broadcast.js +2 -1
  106. package/lib-es/bridge/broadcast.js.map +1 -1
  107. package/lib-es/bridge/createTransaction.js +2 -2
  108. package/lib-es/bridge/createTransaction.js.map +1 -1
  109. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  110. package/lib-es/bridge/estimateMaxSpendable.js +2 -1
  111. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  112. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  113. package/lib-es/bridge/getTransactionStatus.js +2 -1
  114. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  115. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  116. package/lib-es/bridge/prepareTransaction.js +4 -2
  117. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  118. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  119. package/lib-es/bridge/synchronisation.js +6 -4
  120. package/lib-es/bridge/synchronisation.js.map +1 -1
  121. package/lib-es/common-logic/calculateGasFees.d.ts +2 -1
  122. package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -1
  123. package/lib-es/common-logic/calculateGasFees.js +3 -3
  124. package/lib-es/common-logic/calculateGasFees.js.map +1 -1
  125. package/lib-es/common-logic/calculateTransactionInfo.d.ts +2 -1
  126. package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -1
  127. package/lib-es/common-logic/calculateTransactionInfo.js +2 -2
  128. package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -1
  129. package/lib-es/common-logic/estimateGas.d.ts +2 -1
  130. package/lib-es/common-logic/estimateGas.d.ts.map +1 -1
  131. package/lib-es/common-logic/estimateGas.js +2 -2
  132. package/lib-es/common-logic/estimateGas.js.map +1 -1
  133. package/lib-es/common-logic/getThorClient.d.ts +2 -1
  134. package/lib-es/common-logic/getThorClient.d.ts.map +1 -1
  135. package/lib-es/common-logic/getThorClient.js +2 -2
  136. package/lib-es/common-logic/getThorClient.js.map +1 -1
  137. package/lib-es/common-logic/mapTransfersToOperations.d.ts +3 -2
  138. package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -1
  139. package/lib-es/common-logic/mapTransfersToOperations.js +4 -4
  140. package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -1
  141. package/lib-es/config.d.ts +10 -4
  142. package/lib-es/config.d.ts.map +1 -1
  143. package/lib-es/config.js +9 -5
  144. package/lib-es/config.js.map +1 -1
  145. package/lib-es/logic/account/getBalance.d.ts +2 -1
  146. package/lib-es/logic/account/getBalance.d.ts.map +1 -1
  147. package/lib-es/logic/account/getBalance.js +3 -2
  148. package/lib-es/logic/account/getBalance.js.map +1 -1
  149. package/lib-es/logic/history/getBlock.d.ts +2 -1
  150. package/lib-es/logic/history/getBlock.d.ts.map +1 -1
  151. package/lib-es/logic/history/getBlock.js +3 -2
  152. package/lib-es/logic/history/getBlock.js.map +1 -1
  153. package/lib-es/logic/history/getBlockInfo.d.ts +2 -1
  154. package/lib-es/logic/history/getBlockInfo.d.ts.map +1 -1
  155. package/lib-es/logic/history/getBlockInfo.js +3 -2
  156. package/lib-es/logic/history/getBlockInfo.js.map +1 -1
  157. package/lib-es/logic/history/lastBlock.d.ts +2 -1
  158. package/lib-es/logic/history/lastBlock.d.ts.map +1 -1
  159. package/lib-es/logic/history/lastBlock.js +4 -3
  160. package/lib-es/logic/history/lastBlock.js.map +1 -1
  161. package/lib-es/logic/history/listOperations.d.ts +2 -1
  162. package/lib-es/logic/history/listOperations.d.ts.map +1 -1
  163. package/lib-es/logic/history/listOperations.js +5 -4
  164. package/lib-es/logic/history/listOperations.js.map +1 -1
  165. package/lib-es/logic/transaction/broadcast.d.ts +2 -1
  166. package/lib-es/logic/transaction/broadcast.d.ts.map +1 -1
  167. package/lib-es/logic/transaction/broadcast.js +3 -2
  168. package/lib-es/logic/transaction/broadcast.js.map +1 -1
  169. package/lib-es/logic/transaction/combine.d.ts +1 -1
  170. package/lib-es/logic/transaction/combine.d.ts.map +1 -1
  171. package/lib-es/logic/transaction/combine.js +4 -1
  172. package/lib-es/logic/transaction/combine.js.map +1 -1
  173. package/lib-es/logic/transaction/craftTransaction.d.ts +2 -1
  174. package/lib-es/logic/transaction/craftTransaction.d.ts.map +1 -1
  175. package/lib-es/logic/transaction/craftTransaction.js +11 -10
  176. package/lib-es/logic/transaction/craftTransaction.js.map +1 -1
  177. package/lib-es/logic/transaction/estimateFees.d.ts +2 -1
  178. package/lib-es/logic/transaction/estimateFees.d.ts.map +1 -1
  179. package/lib-es/logic/transaction/estimateFees.js +2 -2
  180. package/lib-es/logic/transaction/estimateFees.js.map +1 -1
  181. package/lib-es/network/getBlock.d.ts +2 -1
  182. package/lib-es/network/getBlock.d.ts.map +1 -1
  183. package/lib-es/network/getBlock.js +2 -2
  184. package/lib-es/network/getBlock.js.map +1 -1
  185. package/lib-es/network/getFees.d.ts +2 -1
  186. package/lib-es/network/getFees.d.ts.map +1 -1
  187. package/lib-es/network/getFees.js +2 -2
  188. package/lib-es/network/getFees.js.map +1 -1
  189. package/lib-es/network/sdk.d.ts +7 -6
  190. package/lib-es/network/sdk.d.ts.map +1 -1
  191. package/lib-es/network/sdk.js +18 -18
  192. package/lib-es/network/sdk.js.map +1 -1
  193. package/lib-es/test/context.d.ts +6 -0
  194. package/lib-es/test/context.d.ts.map +1 -0
  195. package/lib-es/test/context.js +11 -0
  196. package/lib-es/test/context.js.map +1 -0
  197. package/package.json +6 -6
  198. package/src/api/index.integ.test.ts +21 -24
  199. package/src/api/index.ts +74 -27
  200. package/src/api/index.unit.test.ts +68 -48
  201. package/src/bridge/broadcast.integ.test.ts +2 -1
  202. package/src/bridge/broadcast.test.ts +1 -1
  203. package/src/bridge/broadcast.ts +2 -1
  204. package/src/bridge/createTransaction.ts +2 -2
  205. package/src/bridge/estimateMaxSpendable.test.ts +19 -3
  206. package/src/bridge/estimateMaxSpendable.ts +2 -0
  207. package/src/bridge/getTransactionStatus.test.ts +11 -6
  208. package/src/bridge/getTransactionStatus.ts +2 -0
  209. package/src/bridge/prepareTransaction.test.ts +5 -1
  210. package/src/bridge/prepareTransaction.ts +4 -2
  211. package/src/bridge/synchronisation.ts +7 -3
  212. package/src/common-logic/calculateGasFees.test.ts +101 -27
  213. package/src/common-logic/calculateGasFees.ts +4 -2
  214. package/src/common-logic/calculateTransactionInfo.test.ts +71 -16
  215. package/src/common-logic/calculateTransactionInfo.ts +3 -1
  216. package/src/common-logic/estimateGas.test.ts +13 -10
  217. package/src/common-logic/estimateGas.ts +3 -1
  218. package/src/common-logic/getThorClient.test.ts +7 -7
  219. package/src/common-logic/getThorClient.ts +3 -3
  220. package/src/common-logic/mapTransfersToOperations.test.ts +48 -13
  221. package/src/common-logic/mapTransfersToOperations.ts +5 -2
  222. package/src/config.test.ts +3 -3
  223. package/src/config.ts +13 -6
  224. package/src/logic/account/getBalance.ts +4 -2
  225. package/src/logic/account/getBalance.unit.test.ts +6 -4
  226. package/src/logic/history/getBlock.ts +4 -2
  227. package/src/logic/history/getBlock.unit.test.ts +8 -5
  228. package/src/logic/history/getBlockInfo.ts +4 -2
  229. package/src/logic/history/getBlockInfo.unit.test.ts +6 -3
  230. package/src/logic/history/lastBlock.ts +5 -3
  231. package/src/logic/history/lastBlock.unit.test.ts +6 -3
  232. package/src/logic/history/listOperations.ts +6 -3
  233. package/src/logic/history/listOperations.unit.test.ts +10 -6
  234. package/src/logic/transaction/broadcast.msw.test.ts +7 -2
  235. package/src/logic/transaction/broadcast.ts +8 -2
  236. package/src/logic/transaction/broadcast.unit.test.ts +6 -3
  237. package/src/logic/transaction/combine.ts +6 -2
  238. package/src/logic/transaction/combine.unit.test.ts +3 -3
  239. package/src/logic/transaction/craftTransaction.ts +16 -9
  240. package/src/logic/transaction/craftTransaction.unit.test.ts +29 -28
  241. package/src/logic/transaction/estimateFees.ts +3 -0
  242. package/src/logic/transaction/estimateFees.unit.test.ts +15 -12
  243. package/src/network/getBlock.ts +3 -2
  244. package/src/network/getBlock.unit.test.ts +11 -6
  245. package/src/network/getFees.ts +6 -3
  246. package/src/network/sdk.integ.test.ts +8 -1
  247. package/src/network/sdk.test.ts +18 -7
  248. package/src/network/sdk.ts +25 -15
  249. package/src/test/context.ts +15 -0
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type {
7
7
  Balance,
8
+ BalanceOptions,
8
9
  CoinModuleApi,
9
10
  CraftedTransaction,
10
11
  FeeEstimation,
@@ -13,7 +14,8 @@ import type {
13
14
  TransactionIntent,
14
15
  } from "@ledgerhq/coin-module-framework/api/index";
15
16
  import { createApi } from "./index";
16
- import { getCoinConfig } from "../config";
17
+ import { getCoinConfig, setCoinConfig, type VechainCurrencyConfig } from "../config";
18
+ import { createMockVechainContext } from "../test/context";
17
19
  import { broadcast } from "../logic/transaction/broadcast";
18
20
  import { combine } from "../logic/transaction/combine";
19
21
  import { craftTransaction } from "../logic/transaction/craftTransaction";
@@ -58,8 +60,8 @@ describe("createApi", () => {
58
60
  jest.clearAllMocks();
59
61
  });
60
62
 
61
- it("sets the coin config, forcing status active", () => {
62
- createApi(config, "vechain");
63
+ it("exposes the coin config through the singleton", () => {
64
+ setCoinConfig(config);
63
65
 
64
66
  expect(getCoinConfig()).toEqual({
65
67
  status: { type: "active" },
@@ -68,7 +70,7 @@ describe("createApi", () => {
68
70
  });
69
71
 
70
72
  it("returns an object with every CoinModuleApi method", () => {
71
- const api = createApi(config, "vechain");
73
+ const api = createApi();
72
74
 
73
75
  expect(api).toEqual(
74
76
  expect.objectContaining({
@@ -96,73 +98,78 @@ describe("createApi", () => {
96
98
 
97
99
  it("delegates broadcast to the logic function", async () => {
98
100
  jest.mocked(broadcast).mockResolvedValueOnce("txHash");
99
- const api = createApi(config, "vechain");
101
+ const api = createApi();
102
+ const context = createMockVechainContext();
100
103
 
101
- const result = await api.broadcast("signedTx");
104
+ const result = await api.broadcast(context, "signedTx");
102
105
 
103
- expect(broadcast).toHaveBeenCalledWith("signedTx");
106
+ expect(broadcast).toHaveBeenCalledWith(context, "signedTx", undefined);
104
107
  expect(result).toBe("txHash");
105
108
  });
106
109
 
107
110
  it("delegates combine to the logic function", () => {
108
111
  jest.mocked(combine).mockReturnValueOnce("0xsigned");
109
- const api = createApi(config, "vechain");
112
+ const api = createApi();
113
+ const context = createMockVechainContext();
110
114
 
111
- const result = api.combine("tx", "sig");
115
+ const result = api.combine(context, "tx", ["sig"]);
112
116
 
113
- expect(combine).toHaveBeenCalledWith("tx", "sig");
117
+ expect(combine).toHaveBeenCalledWith("tx", ["sig"]);
114
118
  expect(result).toBe("0xsigned");
115
119
  });
116
120
 
117
121
  it("delegates craftTransaction to the logic function (intent, customFees)", async () => {
118
122
  const crafted: CraftedTransaction = { transaction: "{}", details: { fee: "1000" } };
119
123
  jest.mocked(craftTransaction).mockResolvedValueOnce(crafted);
120
- const api = createApi(config, "vechain");
124
+ const api = createApi();
125
+ const context = createMockVechainContext();
121
126
  const customFees: FeeEstimation = { value: 5000n };
122
127
 
123
- const result = await api.craftTransaction(nativeIntent, customFees);
128
+ const result = await api.craftTransaction(context, nativeIntent, { customFees });
124
129
 
125
- expect(craftTransaction).toHaveBeenCalledWith(nativeIntent, customFees);
130
+ expect(craftTransaction).toHaveBeenCalledWith(context, nativeIntent, customFees);
126
131
  expect(result).toEqual(crafted);
127
132
  });
128
133
 
129
134
  it("delegates estimateFees to the logic function (intent, params)", async () => {
130
135
  const fees: FeeEstimation = { value: 1000n };
131
136
  jest.mocked(estimateFees).mockResolvedValueOnce(fees);
132
- const api = createApi(config, "vechain");
137
+ const api = createApi();
138
+ const context = createMockVechainContext();
133
139
 
134
- const result = await api.estimateFees(nativeIntent);
140
+ const result = await api.estimateFees(context, nativeIntent);
135
141
 
136
- expect(estimateFees).toHaveBeenCalledWith(nativeIntent, undefined);
142
+ expect(estimateFees).toHaveBeenCalledWith(context, nativeIntent, undefined);
137
143
  expect(result).toEqual(fees);
138
144
  });
139
145
 
140
146
  it("delegates getBalance to the logic function (address)", async () => {
141
147
  const balances: Balance[] = [{ value: 1000n, asset: { type: "native" } }];
142
148
  jest.mocked(getBalance).mockResolvedValueOnce(balances);
143
- const api = createApi(config, "vechain");
149
+ const api = createApi();
150
+ const context = createMockVechainContext();
144
151
 
145
- const result = await api.getBalance(SENDER);
152
+ const result = await api.getBalance(context, SENDER);
146
153
 
147
- expect(getBalance).toHaveBeenCalledWith(SENDER);
154
+ expect(getBalance).toHaveBeenCalledWith(context, SENDER);
148
155
  expect(result).toEqual(balances);
149
156
  });
150
157
 
151
158
  it("rejects getBalance when options are provided (not supported)", async () => {
152
- const api = createApi(config, "vechain");
159
+ const api = createApi();
160
+ const context = createMockVechainContext();
153
161
 
154
- await expect(
155
- api.getBalance(SENDER, {} as Parameters<CoinModuleApi["getBalance"]>[1]),
156
- ).rejects.toThrow();
162
+ await expect(api.getBalance(context, SENDER, {} as BalanceOptions)).rejects.toThrow();
157
163
  expect(getBalance).not.toHaveBeenCalled();
158
164
  });
159
165
 
160
166
  it("delegates lastBlock to the logic function", async () => {
161
167
  const block = { height: 100, hash: "abc", time: new Date() };
162
168
  jest.mocked(lastBlock).mockResolvedValueOnce(block);
163
- const api = createApi(config, "vechain");
169
+ const api = createApi();
170
+ const context = createMockVechainContext();
164
171
 
165
- const result = await api.lastBlock();
172
+ const result = await api.lastBlock(context);
166
173
 
167
174
  expect(lastBlock).toHaveBeenCalled();
168
175
  expect(result).toEqual(block);
@@ -171,70 +178,83 @@ describe("createApi", () => {
171
178
  it("delegates getBlockInfo to the logic function (height)", async () => {
172
179
  const info = { height: 42, hash: "abc", time: new Date() };
173
180
  jest.mocked(getBlockInfo).mockResolvedValueOnce(info);
174
- const api = createApi(config, "vechain");
181
+ const api = createApi();
182
+ const context = createMockVechainContext();
175
183
 
176
- const result = await api.getBlockInfo(42);
184
+ const result = await api.getBlockInfo(context, 42);
177
185
 
178
- expect(getBlockInfo).toHaveBeenCalledWith(42);
186
+ expect(getBlockInfo).toHaveBeenCalledWith(context, 42);
179
187
  expect(result).toEqual(info);
180
188
  });
181
189
 
182
190
  it("delegates getBlock to the logic function (height)", async () => {
183
191
  const block = { info: { height: 42, hash: "abc", time: new Date() }, transactions: [] };
184
192
  jest.mocked(getBlock).mockResolvedValueOnce(block);
185
- const api = createApi(config, "vechain");
193
+ const api = createApi();
194
+ const context = createMockVechainContext();
186
195
 
187
- const result = await api.getBlock(42);
196
+ const result = await api.getBlock(context, 42);
188
197
 
189
- expect(getBlock).toHaveBeenCalledWith(42);
198
+ expect(getBlock).toHaveBeenCalledWith(context, 42);
190
199
  expect(result).toEqual(block);
191
200
  });
192
201
 
193
202
  it("delegates listOperations to the logic function (address, options)", async () => {
194
203
  const page: Page<Operation> = { items: [], next: undefined };
195
204
  jest.mocked(listOperations).mockResolvedValueOnce(page);
196
- const api = createApi(config, "vechain");
205
+ const api = createApi();
206
+ const context = createMockVechainContext();
197
207
 
198
- const result = await api.listOperations(SENDER, { minHeight: 0 });
208
+ const result = await api.listOperations(context, SENDER, { minHeight: 0 });
199
209
 
200
- expect(listOperations).toHaveBeenCalledWith(SENDER, { minHeight: 0 });
210
+ expect(listOperations).toHaveBeenCalledWith(context, SENDER, { minHeight: 0 });
201
211
  expect(result).toEqual(page);
202
212
  });
203
213
 
204
214
  it("delegates validateIntent to the logic function (intent, balances, customFees)", async () => {
205
215
  const validation = { errors: {}, warnings: {}, estimatedFees: 0n, amount: 0n, totalSpent: 0n };
206
216
  jest.mocked(validateIntent).mockResolvedValueOnce(validation);
207
- const api = createApi(config, "vechain");
217
+ const api = createApi();
218
+ const context = createMockVechainContext();
208
219
 
209
- const result = await api.validateIntent(nativeIntent, [], undefined);
220
+ const result = await api.validateIntent(context, nativeIntent, [], undefined);
210
221
 
211
222
  expect(validateIntent).toHaveBeenCalledWith(nativeIntent, [], undefined);
212
223
  expect(result).toEqual(validation);
213
224
  });
214
225
 
215
226
  it("throws synchronously for methods not applicable/supported for Vechain", () => {
216
- const api = createApi(config, "vechain");
227
+ const api = createApi();
228
+ const context = createMockVechainContext();
217
229
 
218
- expect(() => api.getNextSequence(SENDER)).toThrow(
230
+ expect(() => api.getNextSequence(context, SENDER)).toThrow(
219
231
  "getNextSequence is not applicable for Vechain",
220
232
  );
221
- expect(() => api.craftRawTransaction("raw", SENDER, "pubkey", 0n)).toThrow(
233
+ expect(() => api.craftRawTransaction(context, "raw", SENDER, "pubkey", 0n)).toThrow(
222
234
  "craftRawTransaction is not supported",
223
235
  );
224
- expect(() => api.getStakes(SENDER)).toThrow("getStakes is not supported");
225
- expect(() => api.getRewards(SENDER)).toThrow("getRewards is not supported");
226
- expect(() => api.getValidators()).toThrow("getValidators is not supported");
236
+ expect(() => api.getStakes(context, SENDER)).toThrow("getStakes is not supported");
237
+ expect(() => api.getRewards(context, SENDER)).toThrow("getRewards is not supported");
238
+ expect(() => api.getValidators(context)).toThrow("getValidators is not supported");
227
239
  });
228
240
 
229
241
  it("throws for call (not supported)", () => {
230
- const api = createApi(config, "vechain");
231
- expect(() => api.call({})).toThrow("call is not supported");
242
+ const api = createApi();
243
+ const context = createMockVechainContext();
244
+ expect(() => api.call(context, {})).toThrow("call is not supported");
245
+ });
246
+
247
+ it("throws for register (not supported)", async () => {
248
+ const api = createApi();
249
+ const context = createMockVechainContext();
250
+ await expect(api.register(context, SENDER)).rejects.toThrow("register is not supported");
232
251
  });
233
252
 
234
253
  it("validates addresses via parseAddress", async () => {
235
- const api = createApi(config, "vechain");
236
- await expect(api.validateAddress(SENDER, {})).resolves.toBe(true);
237
- await expect(api.validateAddress("0xnot-an-address", {})).resolves.toBe(false);
238
- await expect(api.validateAddress("", {})).resolves.toBe(false);
254
+ const api = createApi();
255
+ const context = createMockVechainContext();
256
+ await expect(api.validateAddress(context, SENDER, {})).resolves.toBe(true);
257
+ await expect(api.validateAddress(context, "0xnot-an-address", {})).resolves.toBe(false);
258
+ await expect(api.validateAddress(context, "", {})).resolves.toBe(false);
239
259
  });
240
260
  });
@@ -1,13 +1,14 @@
1
1
  import { Transaction, Secp256k1, Hex } from "@vechain/sdk-core";
2
2
  import broadcast from "./broadcast";
3
3
  import { getBlockRef } from "../network";
4
+ import { getCoinConfig } from "../config";
4
5
 
5
6
  describe("Broadcast", () => {
6
7
  it("throws on insufficient funds", async () => {
7
8
  const privateKey = await Secp256k1.generatePrivateKey();
8
9
  const body = {
9
10
  chainTag: 74,
10
- blockRef: await getBlockRef(),
11
+ blockRef: await getBlockRef(getCoinConfig()),
11
12
  expiration: 18,
12
13
  clauses: [
13
14
  {
@@ -107,7 +107,7 @@ describe("broadcast", () => {
107
107
  mockTransactionBody,
108
108
  Buffer.from("1234567890abcdef", "hex"),
109
109
  );
110
- expect(mockedSubmit).toHaveBeenCalledWith(mockTransaction);
110
+ expect(mockedSubmit).toHaveBeenCalledWith(expect.anything(), mockTransaction);
111
111
  expect(mockedPatchOperationWithHash).toHaveBeenCalledWith(mockOperation, mockTxHash);
112
112
  expect(result).toEqual(mockPatchedOperation);
113
113
  });
@@ -3,6 +3,7 @@ import { patchOperationWithHash } from "@ledgerhq/ledger-wallet-framework/operat
3
3
 
4
4
  import { Transaction, VechainSDKTransaction } from "../types";
5
5
  import { submit } from "../network";
6
+ import { getCoinConfig } from "../config";
6
7
 
7
8
  /**
8
9
  * Broadcast the signed transaction
@@ -14,7 +15,7 @@ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
14
15
  (rawData as unknown as VechainSDKTransaction).body,
15
16
  Buffer.from(signature, "hex"),
16
17
  );
17
- const hash = await submit(transaction);
18
+ const hash = await submit(getCoinConfig(), transaction);
18
19
 
19
20
  return patchOperationWithHash(operation, hash);
20
21
  };
@@ -1,7 +1,7 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { AccountBridge } from "@ledgerhq/types-live";
3
3
  import { generateNonce } from "../common-logic";
4
- import { getChainTag } from "../config";
4
+ import { getChainTag, getCoinConfig } from "../config";
5
5
  import { Transaction } from "../types";
6
6
 
7
7
  /**
@@ -10,7 +10,7 @@ import { Transaction } from "../types";
10
10
  * @returns {Transaction}
11
11
  */
12
12
  export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => {
13
- const chainTag = getChainTag();
13
+ const chainTag = getChainTag(getCoinConfig());
14
14
 
15
15
  return {
16
16
  family: "vechain",
@@ -116,7 +116,12 @@ describe("estimateMaxSpendable", () => {
116
116
  });
117
117
 
118
118
  expect(result).toEqual(new BigNumber("999790000000000000000")); // 1000 - 0.21 VTHO
119
- expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true, "0x123");
119
+ expect(mockedCalculateGasFees).toHaveBeenCalledWith(
120
+ expect.anything(),
121
+ mockTransaction,
122
+ true,
123
+ "0x123",
124
+ );
120
125
  });
121
126
 
122
127
  it("should calculate max spendable for token account with sufficient balance, when parentAccount provided", async () => {
@@ -128,6 +133,7 @@ describe("estimateMaxSpendable", () => {
128
133
 
129
134
  expect(result).toEqual(new BigNumber("999790000000000000000")); // 1000 - 0.21 VTHO
130
135
  expect(mockedCalculateGasFees).toHaveBeenCalledWith(
136
+ expect.anything(),
131
137
  mockTransaction,
132
138
  true,
133
139
  mockAccount.freshAddress,
@@ -190,7 +196,12 @@ describe("estimateMaxSpendable", () => {
190
196
  transaction: mockTransaction,
191
197
  });
192
198
 
193
- expect(mockedCalculateGasFees).toHaveBeenCalledWith(mockTransaction, true, "0x123");
199
+ expect(mockedCalculateGasFees).toHaveBeenCalledWith(
200
+ expect.anything(),
201
+ mockTransaction,
202
+ true,
203
+ "0x123",
204
+ );
194
205
  expect(mockedCalculateGasFees).toHaveBeenCalledTimes(1);
195
206
  });
196
207
 
@@ -263,7 +274,12 @@ describe("estimateMaxSpendable", () => {
263
274
  transaction: tokenTransaction,
264
275
  });
265
276
 
266
- expect(mockedCalculateGasFees).toHaveBeenCalledWith(tokenTransaction, true, "0x123");
277
+ expect(mockedCalculateGasFees).toHaveBeenCalledWith(
278
+ expect.anything(),
279
+ tokenTransaction,
280
+ true,
281
+ "0x123",
282
+ );
267
283
  });
268
284
  });
269
285
 
@@ -2,6 +2,7 @@ import BigNumber from "bignumber.js";
2
2
  import { AccountBridge } from "@ledgerhq/types-live";
3
3
  import { calculateGasFees } from "../common-logic";
4
4
  import type { Transaction } from "../types";
5
+ import { getCoinConfig } from "../config";
5
6
 
6
7
  const PATTERN_ADDRESS_IN_TOKEN_ACCOUNT_ID = /:(0x\w+):/;
7
8
 
@@ -22,6 +23,7 @@ export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpenda
22
23
 
23
24
  if (originAddress) {
24
25
  const { estimatedGasFees: maxTokenFees } = await calculateGasFees(
26
+ getCoinConfig(),
25
27
  transaction,
26
28
  true,
27
29
  originAddress,
@@ -333,12 +333,17 @@ describe("getTransactionStatus", () => {
333
333
  it("should call calculateTransactionInfo with correct parameters", async () => {
334
334
  await getTransactionStatus(mockAccount, mockTransaction);
335
335
 
336
- expect(mockedCalculateTransactionInfo).toHaveBeenCalledWith(mockAccount, mockTransaction, {
337
- estimatedGas: mockTransaction.body.gas,
338
- estimatedGasFees: new BigNumber(mockTransaction.estimatedFees),
339
- maxFeePerGas: mockTransaction.body.maxFeePerGas,
340
- maxPriorityFeePerGas: mockTransaction.body.maxPriorityFeePerGas,
341
- });
336
+ expect(mockedCalculateTransactionInfo).toHaveBeenCalledWith(
337
+ expect.anything(),
338
+ mockAccount,
339
+ mockTransaction,
340
+ {
341
+ estimatedGas: mockTransaction.body.gas,
342
+ estimatedGasFees: new BigNumber(mockTransaction.estimatedFees),
343
+ maxFeePerGas: mockTransaction.body.maxFeePerGas,
344
+ maxPriorityFeePerGas: mockTransaction.body.maxPriorityFeePerGas,
345
+ },
346
+ );
342
347
  });
343
348
 
344
349
  it("should handle calculateTransactionInfo errors", async () => {
@@ -11,6 +11,7 @@ import { AccountBridge } from "@ledgerhq/types-live";
11
11
  import { calculateTransactionInfo, parseAddress } from "../common-logic";
12
12
  import type { Transaction } from "../types";
13
13
  import { NotEnoughVTHO } from "../errors";
14
+ import { getCoinConfig } from "../config";
14
15
 
15
16
  export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
16
17
  account,
@@ -21,6 +22,7 @@ export const getTransactionStatus: AccountBridge<Transaction>["getTransactionSta
21
22
  const errors: Record<string, Error> = {};
22
23
  const warnings: Record<string, Error> = {};
23
24
  const { isTokenAccount, spendableBalance } = await calculateTransactionInfo(
25
+ getCoinConfig(),
24
26
  account,
25
27
  transaction,
26
28
  {
@@ -188,7 +188,11 @@ describe("prepareTransaction", () => {
188
188
  it("should call calculateTransactionInfo with correct parameters", async () => {
189
189
  await prepareTransaction(mockAccount, mockTransaction);
190
190
 
191
- expect(mockedCalculateTransactionInfo).toHaveBeenCalledWith(mockAccount, mockTransaction);
191
+ expect(mockedCalculateTransactionInfo).toHaveBeenCalledWith(
192
+ expect.anything(),
193
+ mockAccount,
194
+ mockTransaction,
195
+ );
192
196
  });
193
197
 
194
198
  it("should use transaction info results in the prepared transaction", async () => {
@@ -7,6 +7,7 @@ import {
7
7
  } from "../common-logic";
8
8
  import { Transaction, VechainSDKTransactionClause } from "../types";
9
9
  import { getBlockRef } from "../network";
10
+ import { getCoinConfig } from "../config";
10
11
 
11
12
  /**
12
13
  * Prepare transaction before checking status
@@ -18,6 +19,7 @@ export const prepareTransaction = async (
18
19
  account: Account,
19
20
  transaction: Transaction,
20
21
  ): Promise<Transaction> => {
22
+ const config = getCoinConfig();
21
23
  const {
22
24
  amount,
23
25
  isTokenAccount,
@@ -25,13 +27,13 @@ export const prepareTransaction = async (
25
27
  estimatedGas,
26
28
  maxFeePerGas,
27
29
  maxPriorityFeePerGas,
28
- } = await calculateTransactionInfo(account, transaction);
30
+ } = await calculateTransactionInfo(config, account, transaction);
29
31
 
30
32
  let blockRef = "";
31
33
 
32
34
  let clauses: Array<VechainSDKTransactionClause> = [];
33
35
  if (transaction.recipient && parseAddress(transaction.recipient)) {
34
- blockRef = await getBlockRef();
36
+ blockRef = await getBlockRef(config);
35
37
  if (isTokenAccount) {
36
38
  clauses = await calculateClausesVtho(transaction.recipient, amount);
37
39
  } else {
@@ -13,6 +13,7 @@ import { Account } from "@ledgerhq/types-live";
13
13
  import { isAccountEmpty } from "./helpers";
14
14
  import { VTHO_ADDRESS } from "@vechain/sdk-core";
15
15
  import { getCryptoAssetsStore } from "@ledgerhq/ledger-wallet-framework/cryptoAssetsStore";
16
+ import { getCoinConfig } from "../config";
16
17
 
17
18
  export const getAccountShape: GetAccountShape<Account> = async info => {
18
19
  const { initialAccount, currency, derivationMode } = info;
@@ -29,20 +30,23 @@ export const getAccountShape: GetAccountShape<Account> = async info => {
29
30
  derivationMode,
30
31
  });
31
32
 
33
+ const config = getCoinConfig();
34
+
32
35
  // get the current account balance state depending your api implementation
33
- const { balance, energy } = await getAccount(address);
36
+ const { balance, energy } = await getAccount(config, address);
34
37
 
35
38
  // get the current block height
36
- const blockHeight = await getLastBlockHeight();
39
+ const blockHeight = await getLastBlockHeight(config);
37
40
 
38
41
  // Merge new operations with the previously synced ones
39
- const newOperations = await getOperations(accountId, address, startAt, blockHeight);
42
+ const newOperations = await getOperations(config, accountId, address, startAt, blockHeight);
40
43
 
41
44
  //Get last token operations
42
45
  const vthoToken = await getCryptoAssetsStore().findTokenById("vechain/vip180/vtho");
43
46
  if (!vthoToken) throw new Error("VTHO token not found");
44
47
  const vthoAccountId = encodeTokenAccountId(accountId, vthoToken);
45
48
  const vthoOperations = await getTokenOperations(
49
+ config,
46
50
  vthoAccountId,
47
51
  address,
48
52
  VTHO_ADDRESS,