@ledgerhq/coin-multiversx 0.2.0-next.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 (378) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +31 -0
  4. package/CHANGELOG.md +400 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/api/apiCalls.d.ts +22 -0
  8. package/lib/api/apiCalls.d.ts.map +1 -0
  9. package/lib/api/apiCalls.js +153 -0
  10. package/lib/api/apiCalls.js.map +1 -0
  11. package/lib/api/dtos/multiversx-account.d.ts +9 -0
  12. package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
  13. package/lib/api/dtos/multiversx-account.js +17 -0
  14. package/lib/api/dtos/multiversx-account.js.map +1 -0
  15. package/lib/api/index.d.ts +2 -0
  16. package/lib/api/index.d.ts.map +1 -0
  17. package/lib/api/index.js +16 -0
  18. package/lib/api/index.js.map +1 -0
  19. package/lib/api/sdk.d.ts +29 -0
  20. package/lib/api/sdk.d.ts.map +1 -0
  21. package/lib/api/sdk.js +281 -0
  22. package/lib/api/sdk.js.map +1 -0
  23. package/lib/bridge/js.d.ts +11 -0
  24. package/lib/bridge/js.d.ts.map +1 -0
  25. package/lib/bridge/js.js +62 -0
  26. package/lib/bridge/js.js.map +1 -0
  27. package/lib/bridge.integration.test.d.ts +4 -0
  28. package/lib/bridge.integration.test.d.ts.map +1 -0
  29. package/lib/bridge.integration.test.js +142 -0
  30. package/lib/bridge.integration.test.js.map +1 -0
  31. package/lib/broadcast.d.ts +9 -0
  32. package/lib/broadcast.d.ts.map +1 -0
  33. package/lib/broadcast.js +16 -0
  34. package/lib/broadcast.js.map +1 -0
  35. package/lib/buildOptimisticOperation.d.ts +4 -0
  36. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  37. package/lib/buildOptimisticOperation.js +100 -0
  38. package/lib/buildOptimisticOperation.js.map +1 -0
  39. package/lib/buildOptimisticOperation.test.d.ts +2 -0
  40. package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
  41. package/lib/buildOptimisticOperation.test.js +78 -0
  42. package/lib/buildOptimisticOperation.test.js.map +1 -0
  43. package/lib/buildSubAccounts.d.ts +11 -0
  44. package/lib/buildSubAccounts.d.ts.map +1 -0
  45. package/lib/buildSubAccounts.js +117 -0
  46. package/lib/buildSubAccounts.js.map +1 -0
  47. package/lib/buildTransaction.d.ts +19 -0
  48. package/lib/buildTransaction.d.ts.map +1 -0
  49. package/lib/buildTransaction.js +49 -0
  50. package/lib/buildTransaction.js.map +1 -0
  51. package/lib/buildTransaction.unit.test.d.ts +2 -0
  52. package/lib/buildTransaction.unit.test.d.ts.map +1 -0
  53. package/lib/buildTransaction.unit.test.js +47 -0
  54. package/lib/buildTransaction.unit.test.js.map +1 -0
  55. package/lib/cli-transaction.d.ts +16 -0
  56. package/lib/cli-transaction.d.ts.map +1 -0
  57. package/lib/cli-transaction.js +35 -0
  58. package/lib/cli-transaction.js.map +1 -0
  59. package/lib/config.d.ts +14 -0
  60. package/lib/config.d.ts.map +1 -0
  61. package/lib/config.js +16 -0
  62. package/lib/config.js.map +1 -0
  63. package/lib/constants.d.ts +21 -0
  64. package/lib/constants.d.ts.map +1 -0
  65. package/lib/constants.js +27 -0
  66. package/lib/constants.js.map +1 -0
  67. package/lib/createTransaction.d.ts +9 -0
  68. package/lib/createTransaction.d.ts.map +1 -0
  69. package/lib/createTransaction.js +26 -0
  70. package/lib/createTransaction.js.map +1 -0
  71. package/lib/datasets/multiversx1.d.ts +3 -0
  72. package/lib/datasets/multiversx1.d.ts.map +1 -0
  73. package/lib/datasets/multiversx1.js +21 -0
  74. package/lib/datasets/multiversx1.js.map +1 -0
  75. package/lib/deviceTransactionConfig.d.ts +10 -0
  76. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  77. package/lib/deviceTransactionConfig.js +60 -0
  78. package/lib/deviceTransactionConfig.js.map +1 -0
  79. package/lib/encode.d.ts +11 -0
  80. package/lib/encode.d.ts.map +1 -0
  81. package/lib/encode.js +39 -0
  82. package/lib/encode.js.map +1 -0
  83. package/lib/errors.d.ts +16 -0
  84. package/lib/errors.d.ts.map +1 -0
  85. package/lib/errors.js +10 -0
  86. package/lib/errors.js.map +1 -0
  87. package/lib/estimateMaxSpendable.d.ts +10 -0
  88. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  89. package/lib/estimateMaxSpendable.js +35 -0
  90. package/lib/estimateMaxSpendable.js.map +1 -0
  91. package/lib/formatters.d.ts +11 -0
  92. package/lib/formatters.d.ts.map +1 -0
  93. package/lib/formatters.js +65 -0
  94. package/lib/formatters.js.map +1 -0
  95. package/lib/getTransactionStatus.d.ts +5 -0
  96. package/lib/getTransactionStatus.d.ts.map +1 -0
  97. package/lib/getTransactionStatus.js +107 -0
  98. package/lib/getTransactionStatus.js.map +1 -0
  99. package/lib/helpers/denominate.d.ts +9 -0
  100. package/lib/helpers/denominate.d.ts.map +1 -0
  101. package/lib/helpers/denominate.js +75 -0
  102. package/lib/helpers/denominate.js.map +1 -0
  103. package/lib/helpers/handleTransactionStatus.d.ts +7 -0
  104. package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
  105. package/lib/helpers/handleTransactionStatus.js +18 -0
  106. package/lib/helpers/handleTransactionStatus.js.map +1 -0
  107. package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  108. package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  109. package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
  110. package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
  111. package/lib/helpers/randomizeProviders.d.ts +7 -0
  112. package/lib/helpers/randomizeProviders.d.ts.map +1 -0
  113. package/lib/helpers/randomizeProviders.js +12 -0
  114. package/lib/helpers/randomizeProviders.js.map +1 -0
  115. package/lib/hw-getAddress.d.ts +6 -0
  116. package/lib/hw-getAddress.d.ts.map +1 -0
  117. package/lib/hw-getAddress.js +14 -0
  118. package/lib/hw-getAddress.js.map +1 -0
  119. package/lib/logic.d.ts +15 -0
  120. package/lib/logic.d.ts.map +1 -0
  121. package/lib/logic.js +77 -0
  122. package/lib/logic.js.map +1 -0
  123. package/lib/preload.d.ts +11 -0
  124. package/lib/preload.d.ts.map +1 -0
  125. package/lib/preload.js +94 -0
  126. package/lib/preload.js.map +1 -0
  127. package/lib/prepareTransaction.d.ts +10 -0
  128. package/lib/prepareTransaction.d.ts.map +1 -0
  129. package/lib/prepareTransaction.js +72 -0
  130. package/lib/prepareTransaction.js.map +1 -0
  131. package/lib/reconciliation.d.ts +3 -0
  132. package/lib/reconciliation.d.ts.map +1 -0
  133. package/lib/reconciliation.js +56 -0
  134. package/lib/reconciliation.js.map +1 -0
  135. package/lib/serialization.d.ts +9 -0
  136. package/lib/serialization.d.ts.map +1 -0
  137. package/lib/serialization.js +65 -0
  138. package/lib/serialization.js.map +1 -0
  139. package/lib/signOperation.d.ts +10 -0
  140. package/lib/signOperation.d.ts.map +1 -0
  141. package/lib/signOperation.js +65 -0
  142. package/lib/signOperation.js.map +1 -0
  143. package/lib/signer.d.ts +16 -0
  144. package/lib/signer.d.ts.map +1 -0
  145. package/lib/signer.js +3 -0
  146. package/lib/signer.js.map +1 -0
  147. package/lib/specs.d.ts +7 -0
  148. package/lib/specs.d.ts.map +1 -0
  149. package/lib/specs.js +286 -0
  150. package/lib/specs.js.map +1 -0
  151. package/lib/speculos-deviceActions.d.ts +16 -0
  152. package/lib/speculos-deviceActions.d.ts.map +1 -0
  153. package/lib/speculos-deviceActions.js +250 -0
  154. package/lib/speculos-deviceActions.js.map +1 -0
  155. package/lib/synchronisation.d.ts +5 -0
  156. package/lib/synchronisation.d.ts.map +1 -0
  157. package/lib/synchronisation.js +69 -0
  158. package/lib/synchronisation.js.map +1 -0
  159. package/lib/transaction.d.ts +15 -0
  160. package/lib/transaction.d.ts.map +1 -0
  161. package/lib/transaction.js +62 -0
  162. package/lib/transaction.js.map +1 -0
  163. package/lib/types.d.ts +188 -0
  164. package/lib/types.d.ts.map +1 -0
  165. package/lib/types.js +17 -0
  166. package/lib/types.js.map +1 -0
  167. package/lib/utils/binary.utils.d.ts +5 -0
  168. package/lib/utils/binary.utils.d.ts.map +1 -0
  169. package/lib/utils/binary.utils.js +16 -0
  170. package/lib/utils/binary.utils.js.map +1 -0
  171. package/lib-es/api/apiCalls.d.ts +22 -0
  172. package/lib-es/api/apiCalls.d.ts.map +1 -0
  173. package/lib-es/api/apiCalls.js +147 -0
  174. package/lib-es/api/apiCalls.js.map +1 -0
  175. package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
  176. package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
  177. package/lib-es/api/dtos/multiversx-account.js +13 -0
  178. package/lib-es/api/dtos/multiversx-account.js.map +1 -0
  179. package/lib-es/api/index.d.ts +2 -0
  180. package/lib-es/api/index.d.ts.map +1 -0
  181. package/lib-es/api/index.js +2 -0
  182. package/lib-es/api/index.js.map +1 -0
  183. package/lib-es/api/sdk.d.ts +29 -0
  184. package/lib-es/api/sdk.d.ts.map +1 -0
  185. package/lib-es/api/sdk.js +264 -0
  186. package/lib-es/api/sdk.js.map +1 -0
  187. package/lib-es/bridge/js.d.ts +11 -0
  188. package/lib-es/bridge/js.d.ts.map +1 -0
  189. package/lib-es/bridge/js.js +53 -0
  190. package/lib-es/bridge/js.js.map +1 -0
  191. package/lib-es/bridge.integration.test.d.ts +4 -0
  192. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  193. package/lib-es/bridge.integration.test.js +139 -0
  194. package/lib-es/bridge.integration.test.js.map +1 -0
  195. package/lib-es/broadcast.d.ts +9 -0
  196. package/lib-es/broadcast.d.ts.map +1 -0
  197. package/lib-es/broadcast.js +12 -0
  198. package/lib-es/broadcast.js.map +1 -0
  199. package/lib-es/buildOptimisticOperation.d.ts +4 -0
  200. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  201. package/lib-es/buildOptimisticOperation.js +93 -0
  202. package/lib-es/buildOptimisticOperation.js.map +1 -0
  203. package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
  204. package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
  205. package/lib-es/buildOptimisticOperation.test.js +73 -0
  206. package/lib-es/buildOptimisticOperation.test.js.map +1 -0
  207. package/lib-es/buildSubAccounts.d.ts +11 -0
  208. package/lib-es/buildSubAccounts.d.ts.map +1 -0
  209. package/lib-es/buildSubAccounts.js +112 -0
  210. package/lib-es/buildSubAccounts.js.map +1 -0
  211. package/lib-es/buildTransaction.d.ts +19 -0
  212. package/lib-es/buildTransaction.d.ts.map +1 -0
  213. package/lib-es/buildTransaction.js +44 -0
  214. package/lib-es/buildTransaction.js.map +1 -0
  215. package/lib-es/buildTransaction.unit.test.d.ts +2 -0
  216. package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
  217. package/lib-es/buildTransaction.unit.test.js +42 -0
  218. package/lib-es/buildTransaction.unit.test.js.map +1 -0
  219. package/lib-es/cli-transaction.d.ts +16 -0
  220. package/lib-es/cli-transaction.d.ts.map +1 -0
  221. package/lib-es/cli-transaction.js +29 -0
  222. package/lib-es/cli-transaction.js.map +1 -0
  223. package/lib-es/config.d.ts +14 -0
  224. package/lib-es/config.d.ts.map +1 -0
  225. package/lib-es/config.js +11 -0
  226. package/lib-es/config.js.map +1 -0
  227. package/lib-es/constants.d.ts +21 -0
  228. package/lib-es/constants.d.ts.map +1 -0
  229. package/lib-es/constants.js +21 -0
  230. package/lib-es/constants.js.map +1 -0
  231. package/lib-es/createTransaction.d.ts +9 -0
  232. package/lib-es/createTransaction.d.ts.map +1 -0
  233. package/lib-es/createTransaction.js +19 -0
  234. package/lib-es/createTransaction.js.map +1 -0
  235. package/lib-es/datasets/multiversx1.d.ts +3 -0
  236. package/lib-es/datasets/multiversx1.d.ts.map +1 -0
  237. package/lib-es/datasets/multiversx1.js +18 -0
  238. package/lib-es/datasets/multiversx1.js.map +1 -0
  239. package/lib-es/deviceTransactionConfig.d.ts +10 -0
  240. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  241. package/lib-es/deviceTransactionConfig.js +55 -0
  242. package/lib-es/deviceTransactionConfig.js.map +1 -0
  243. package/lib-es/encode.d.ts +11 -0
  244. package/lib-es/encode.d.ts.map +1 -0
  245. package/lib-es/encode.js +35 -0
  246. package/lib-es/encode.js.map +1 -0
  247. package/lib-es/errors.d.ts +16 -0
  248. package/lib-es/errors.d.ts.map +1 -0
  249. package/lib-es/errors.js +7 -0
  250. package/lib-es/errors.js.map +1 -0
  251. package/lib-es/estimateMaxSpendable.d.ts +10 -0
  252. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  253. package/lib-es/estimateMaxSpendable.js +31 -0
  254. package/lib-es/estimateMaxSpendable.js.map +1 -0
  255. package/lib-es/formatters.d.ts +11 -0
  256. package/lib-es/formatters.d.ts.map +1 -0
  257. package/lib-es/formatters.js +60 -0
  258. package/lib-es/formatters.js.map +1 -0
  259. package/lib-es/getTransactionStatus.d.ts +5 -0
  260. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  261. package/lib-es/getTransactionStatus.js +100 -0
  262. package/lib-es/getTransactionStatus.js.map +1 -0
  263. package/lib-es/helpers/denominate.d.ts +9 -0
  264. package/lib-es/helpers/denominate.d.ts.map +1 -0
  265. package/lib-es/helpers/denominate.js +71 -0
  266. package/lib-es/helpers/denominate.js.map +1 -0
  267. package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
  268. package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
  269. package/lib-es/helpers/handleTransactionStatus.js +14 -0
  270. package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
  271. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  272. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  273. package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
  274. package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
  275. package/lib-es/helpers/randomizeProviders.d.ts +7 -0
  276. package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
  277. package/lib-es/helpers/randomizeProviders.js +8 -0
  278. package/lib-es/helpers/randomizeProviders.js.map +1 -0
  279. package/lib-es/hw-getAddress.d.ts +6 -0
  280. package/lib-es/hw-getAddress.d.ts.map +1 -0
  281. package/lib-es/hw-getAddress.js +12 -0
  282. package/lib-es/hw-getAddress.js.map +1 -0
  283. package/lib-es/logic.d.ts +15 -0
  284. package/lib-es/logic.d.ts.map +1 -0
  285. package/lib-es/logic.js +65 -0
  286. package/lib-es/logic.js.map +1 -0
  287. package/lib-es/preload.d.ts +11 -0
  288. package/lib-es/preload.d.ts.map +1 -0
  289. package/lib-es/preload.js +85 -0
  290. package/lib-es/preload.js.map +1 -0
  291. package/lib-es/prepareTransaction.d.ts +10 -0
  292. package/lib-es/prepareTransaction.d.ts.map +1 -0
  293. package/lib-es/prepareTransaction.js +68 -0
  294. package/lib-es/prepareTransaction.js.map +1 -0
  295. package/lib-es/reconciliation.d.ts +3 -0
  296. package/lib-es/reconciliation.d.ts.map +1 -0
  297. package/lib-es/reconciliation.js +52 -0
  298. package/lib-es/reconciliation.js.map +1 -0
  299. package/lib-es/serialization.d.ts +9 -0
  300. package/lib-es/serialization.d.ts.map +1 -0
  301. package/lib-es/serialization.js +53 -0
  302. package/lib-es/serialization.js.map +1 -0
  303. package/lib-es/signOperation.d.ts +10 -0
  304. package/lib-es/signOperation.d.ts.map +1 -0
  305. package/lib-es/signOperation.js +61 -0
  306. package/lib-es/signOperation.js.map +1 -0
  307. package/lib-es/signer.d.ts +16 -0
  308. package/lib-es/signer.d.ts.map +1 -0
  309. package/lib-es/signer.js +2 -0
  310. package/lib-es/signer.js.map +1 -0
  311. package/lib-es/specs.d.ts +7 -0
  312. package/lib-es/specs.d.ts.map +1 -0
  313. package/lib-es/specs.js +281 -0
  314. package/lib-es/specs.js.map +1 -0
  315. package/lib-es/speculos-deviceActions.d.ts +16 -0
  316. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  317. package/lib-es/speculos-deviceActions.js +244 -0
  318. package/lib-es/speculos-deviceActions.js.map +1 -0
  319. package/lib-es/synchronisation.d.ts +5 -0
  320. package/lib-es/synchronisation.d.ts.map +1 -0
  321. package/lib-es/synchronisation.js +62 -0
  322. package/lib-es/synchronisation.js.map +1 -0
  323. package/lib-es/transaction.d.ts +15 -0
  324. package/lib-es/transaction.d.ts.map +1 -0
  325. package/lib-es/transaction.js +56 -0
  326. package/lib-es/transaction.js.map +1 -0
  327. package/lib-es/types.d.ts +188 -0
  328. package/lib-es/types.d.ts.map +1 -0
  329. package/lib-es/types.js +12 -0
  330. package/lib-es/types.js.map +1 -0
  331. package/lib-es/utils/binary.utils.d.ts +5 -0
  332. package/lib-es/utils/binary.utils.d.ts.map +1 -0
  333. package/lib-es/utils/binary.utils.js +12 -0
  334. package/lib-es/utils/binary.utils.js.map +1 -0
  335. package/package.json +86 -0
  336. package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
  337. package/src/api/apiCalls.ts +243 -0
  338. package/src/api/dtos/multiversx-account.ts +20 -0
  339. package/src/api/index.ts +13 -0
  340. package/src/api/sdk.ts +368 -0
  341. package/src/bridge/js.ts +77 -0
  342. package/src/bridge.integration.test.ts +147 -0
  343. package/src/broadcast.ts +16 -0
  344. package/src/buildOptimisticOperation.test.ts +88 -0
  345. package/src/buildOptimisticOperation.ts +120 -0
  346. package/src/buildSubAccounts.ts +153 -0
  347. package/src/buildTransaction.ts +67 -0
  348. package/src/buildTransaction.unit.test.ts +49 -0
  349. package/src/cli-transaction.ts +41 -0
  350. package/src/config.ts +26 -0
  351. package/src/constants.ts +24 -0
  352. package/src/createTransaction.ts +21 -0
  353. package/src/datasets/multiversx1.ts +19 -0
  354. package/src/deviceTransactionConfig.ts +74 -0
  355. package/src/encode.ts +46 -0
  356. package/src/errors.ts +19 -0
  357. package/src/estimateMaxSpendable.ts +43 -0
  358. package/src/formatters.ts +76 -0
  359. package/src/getTransactionStatus.ts +151 -0
  360. package/src/helpers/denominate.ts +95 -0
  361. package/src/helpers/handleTransactionStatus.ts +26 -0
  362. package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
  363. package/src/helpers/randomizeProviders.ts +20 -0
  364. package/src/hw-getAddress.ts +19 -0
  365. package/src/logic.ts +83 -0
  366. package/src/preload.ts +95 -0
  367. package/src/prepareTransaction.ts +78 -0
  368. package/src/reconciliation.ts +64 -0
  369. package/src/serialization.ts +72 -0
  370. package/src/signOperation.ts +99 -0
  371. package/src/signer.ts +21 -0
  372. package/src/specs.ts +387 -0
  373. package/src/speculos-deviceActions.ts +269 -0
  374. package/src/synchronisation.ts +74 -0
  375. package/src/transaction.ts +76 -0
  376. package/src/types.ts +235 -0
  377. package/src/utils/binary.utils.ts +13 -0
  378. package/tsconfig.json +13 -0
@@ -0,0 +1,77 @@
1
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import {
3
+ getSerializedAddressParameters,
4
+ updateTransaction,
5
+ makeAccountBridgeReceive,
6
+ makeScanAccounts,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import { SignerContext } from "@ledgerhq/coin-framework/lib/signer";
9
+ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
10
+ import { broadcast } from "../broadcast";
11
+ import { createTransaction } from "../createTransaction";
12
+ import { estimateMaxSpendable } from "../estimateMaxSpendable";
13
+ import { getTransactionStatus } from "../getTransactionStatus";
14
+ import resolver from "../hw-getAddress";
15
+ import { getPreloadStrategy, hydrate, preload } from "../preload";
16
+ import { prepareTransaction } from "../prepareTransaction";
17
+ import {
18
+ assignFromAccountRaw,
19
+ assignToAccountRaw,
20
+ fromOperationExtraRaw,
21
+ toOperationExtraRaw,
22
+ } from "../serialization";
23
+ import { MultiversXSigner } from "../signer";
24
+ import { buildSignOperation } from "../signOperation";
25
+ import { getAccountShape, sync } from "../synchronisation";
26
+ import type { MultiversXAccount, Transaction, TransactionStatus } from "../types";
27
+
28
+ export function buildCurrencyBridge(
29
+ signerContext: SignerContext<MultiversXSigner>,
30
+ ): CurrencyBridge {
31
+ const getAddress = resolver(signerContext);
32
+
33
+ const scanAccounts = makeScanAccounts({
34
+ getAccountShape,
35
+ getAddressFn: getAddress,
36
+ });
37
+
38
+ return {
39
+ getPreloadStrategy,
40
+ preload,
41
+ hydrate,
42
+ scanAccounts,
43
+ };
44
+ }
45
+
46
+ export function buildAccountBridge(
47
+ signerContext: SignerContext<MultiversXSigner>,
48
+ ): AccountBridge<Transaction, MultiversXAccount, TransactionStatus> {
49
+ const getAddress = resolver(signerContext);
50
+
51
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
52
+ const signOperation = buildSignOperation(signerContext);
53
+
54
+ return {
55
+ estimateMaxSpendable,
56
+ createTransaction,
57
+ updateTransaction,
58
+ getTransactionStatus,
59
+ prepareTransaction,
60
+ sync,
61
+ receive,
62
+ signOperation,
63
+ broadcast,
64
+ assignFromAccountRaw,
65
+ assignToAccountRaw,
66
+ fromOperationExtraRaw,
67
+ toOperationExtraRaw,
68
+ getSerializedAddressParameters,
69
+ };
70
+ }
71
+
72
+ export function createBridges(signerContext: SignerContext<MultiversXSigner>) {
73
+ return {
74
+ currencyBridge: buildCurrencyBridge(signerContext),
75
+ accountBridge: buildAccountBridge(signerContext),
76
+ };
77
+ }
@@ -0,0 +1,147 @@
1
+ import { InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalance } from "@ledgerhq/errors";
2
+ import type { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
3
+ import { BigNumber } from "bignumber.js";
4
+
5
+ import { fromTransactionRaw } from "./transaction";
6
+ import type { Transaction } from "./types";
7
+
8
+ const TEST_ADDRESS = "erd1vgfp3g7azqjx4wsmtt7067m0l62v3psmqzr24j6xvywj2tlz0gesvyzsq2";
9
+
10
+ const elrond: CurrenciesData<Transaction> = {
11
+ FIXME_ignorePreloadFields: [
12
+ "validators", // They are always changing
13
+ ],
14
+ scanAccounts: [
15
+ {
16
+ name: "multiversx seed 1",
17
+ apdus: `
18
+ => ed030000080000000080000000
19
+ <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
20
+ => ed030000080000000080000000
21
+ <= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
22
+ => ed030000080000000080000001
23
+ <= 3e65726431706d33676a65326c6d643576796c6463767579366a7078676465347261706a70756a76756a6b65653661376a77327a6d6834747172653739367a9000
24
+ `,
25
+ },
26
+ ],
27
+ accounts: [
28
+ {
29
+ raw: {
30
+ id: `js:2:multiversx:${TEST_ADDRESS}:`,
31
+ seedIdentifier: `${TEST_ADDRESS}`,
32
+ name: "MultiversX 1",
33
+ derivationMode: "",
34
+ index: 0,
35
+ freshAddress: `${TEST_ADDRESS}`,
36
+ freshAddressPath: "44'/508'/0'/0'/0'",
37
+ blockHeight: 0,
38
+ operations: [],
39
+ pendingOperations: [],
40
+ currencyId: "elrond",
41
+ lastSyncDate: "",
42
+ balance: "299569965",
43
+ subAccounts: [
44
+ {
45
+ // MEX account
46
+ id: `js:2:multiversx:${TEST_ADDRESS}:+4d45582d343535633537`,
47
+ balance: "100",
48
+ spendableBalance: "100",
49
+ type: "TokenAccountRaw",
50
+ tokenId: "multiversx/esdt/4d45582d343535633537",
51
+ parentId: `js:2:multiversx:${TEST_ADDRESS}:`,
52
+ operations: [],
53
+ pendingOperations: [],
54
+ },
55
+ ],
56
+ },
57
+ transactions: [
58
+ {
59
+ name: "recipient and sender must not be the same",
60
+ transaction: fromTransactionRaw({
61
+ family: "multiversx",
62
+ recipient: `${TEST_ADDRESS}`,
63
+ amount: "100000000",
64
+ mode: "send",
65
+ fees: null,
66
+ gasLimit: 50000000,
67
+ }),
68
+ expectedStatus: {
69
+ amount: new BigNumber("100000000"),
70
+ errors: {
71
+ recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
72
+ },
73
+ warnings: {},
74
+ },
75
+ },
76
+ {
77
+ name: "Not enough balance",
78
+ transaction: fromTransactionRaw({
79
+ family: "multiversx",
80
+ recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
81
+ amount: "1000000000000000000000000",
82
+ mode: "send",
83
+ fees: null,
84
+ gasLimit: 50000000,
85
+ }),
86
+ expectedStatus: {
87
+ errors: {
88
+ amount: new NotEnoughBalance(),
89
+ },
90
+ warnings: {},
91
+ },
92
+ },
93
+ {
94
+ name: "Not enough balance (ESDT transfer)",
95
+ transaction: fromTransactionRaw({
96
+ family: "multiversx",
97
+ recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
98
+ amount: "1000000000000000000000000",
99
+ mode: "send",
100
+ fees: null,
101
+ gasLimit: 50000000,
102
+ subAccountId: `js:2:multiversx:${TEST_ADDRESS}:+4d45582d343535633537`,
103
+ }),
104
+ expectedStatus: {
105
+ errors: {
106
+ amount: new NotEnoughBalance(),
107
+ },
108
+ warnings: {},
109
+ },
110
+ },
111
+ {
112
+ name: "Send max",
113
+ transaction: fromTransactionRaw({
114
+ family: "multiversx",
115
+ recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
116
+ useAllAmount: true,
117
+ amount: "0",
118
+ mode: "send",
119
+ fees: null,
120
+ gasLimit: 50000000,
121
+ }),
122
+ expectedStatus: (account, _, status) => {
123
+ return {
124
+ amount: account.balance.minus(status.estimatedFees),
125
+ warnings: {},
126
+ errors: {},
127
+ };
128
+ },
129
+ },
130
+ ],
131
+ },
132
+ ],
133
+ };
134
+
135
+ export const dataset: DatasetTest<Transaction> = {
136
+ implementations: ["js"],
137
+ currencies: {
138
+ // multiversx,
139
+ elrond,
140
+ },
141
+ };
142
+
143
+ describe("MultiversX bridge", () => {
144
+ test.todo(
145
+ "This is an empty test to make jest command pass. Remove it once there is a real test.",
146
+ );
147
+ });
@@ -0,0 +1,16 @@
1
+ import type { AccountBridge } from "@ledgerhq/types-live";
2
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
3
+ import { broadcastTransaction } from "./api";
4
+ import { Transaction } from "./types";
5
+
6
+ /**
7
+ * Broadcast the signed transaction
8
+ * @param {signature: string, operation: string} signedOperation
9
+ */
10
+ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({ signedOperation }) => {
11
+ const hash = await broadcastTransaction(signedOperation);
12
+
13
+ return patchOperationWithHash(signedOperation.operation, hash);
14
+ };
15
+
16
+ export default broadcast;
@@ -0,0 +1,88 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { buildOptimisticOperation } from "./buildOptimisticOperation";
3
+ import { MultiversXAccount, MultiversXProtocolTransaction, Transaction } from "./types";
4
+
5
+ describe("buildOptimisticOperation", () => {
6
+ it("should work with mode = send", async () => {
7
+ const account = {
8
+ freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
9
+ } as MultiversXAccount;
10
+
11
+ const transaction = {
12
+ family: "multiversx",
13
+ mode: "send",
14
+ fees: new BigNumber("1"),
15
+ amount: new BigNumber("42"),
16
+ recipient: "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
17
+ } as Transaction;
18
+
19
+ const notSignedTransaction: MultiversXProtocolTransaction = {
20
+ nonce: 7,
21
+ } as MultiversXProtocolTransaction;
22
+
23
+ const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
24
+
25
+ expect(operation.type).toEqual("OUT");
26
+ expect(operation.value).toEqual(new BigNumber("43"));
27
+ expect(operation.fee).toEqual(new BigNumber("1"));
28
+ expect(operation.extra).toEqual({
29
+ amount: new BigNumber("0"),
30
+ });
31
+ });
32
+
33
+ it("should work with mode = delegate", async () => {
34
+ const account = {
35
+ freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
36
+ } as MultiversXAccount;
37
+
38
+ const transaction = {
39
+ family: "multiversx",
40
+ mode: "delegate",
41
+ fees: new BigNumber("1"),
42
+ amount: new BigNumber("42"),
43
+ recipient: "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqppllllls9ftvxy",
44
+ data: "delegate",
45
+ } as Transaction;
46
+
47
+ const notSignedTransaction: MultiversXProtocolTransaction = {
48
+ nonce: 7,
49
+ } as MultiversXProtocolTransaction;
50
+
51
+ const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
52
+
53
+ expect(operation.type).toEqual("DELEGATE");
54
+ expect(operation.value).toEqual(new BigNumber("43"));
55
+ expect(operation.fee).toEqual(new BigNumber("1"));
56
+ expect(operation.extra).toEqual({
57
+ amount: new BigNumber("42"),
58
+ });
59
+ });
60
+
61
+ it("should work with mode = claimRewards", async () => {
62
+ const account = {
63
+ freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
64
+ } as MultiversXAccount;
65
+
66
+ const transaction = {
67
+ family: "multiversx",
68
+ mode: "claimRewards",
69
+ fees: new BigNumber("1"),
70
+ amount: new BigNumber("42"),
71
+ recipient: "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqppllllls9ftvxy",
72
+ data: "claimRewards",
73
+ } as Transaction;
74
+
75
+ const notSignedTransaction: MultiversXProtocolTransaction = {
76
+ nonce: 7,
77
+ } as MultiversXProtocolTransaction;
78
+
79
+ const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
80
+
81
+ expect(operation.type).toEqual("REWARD");
82
+ expect(operation.value).toEqual(new BigNumber("1"));
83
+ expect(operation.fee).toEqual(new BigNumber("1"));
84
+ expect(operation.extra).toEqual({
85
+ amount: new BigNumber("0"),
86
+ });
87
+ });
88
+ });
@@ -0,0 +1,120 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { FeeNotLoaded } from "@ledgerhq/errors";
3
+ import { Address } from "@multiversx/sdk-core";
4
+ import { Operation, OperationType } from "@ledgerhq/types-live";
5
+ import { BinaryUtils } from "./utils/binary.utils";
6
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
7
+ import {
8
+ MultiversXAccount,
9
+ MultiversXProtocolTransaction,
10
+ MultiversXTransactionMode,
11
+ Transaction,
12
+ } from "./types";
13
+
14
+ function getOptimisticOperationType(transactionMode: MultiversXTransactionMode): OperationType {
15
+ switch (transactionMode) {
16
+ case "delegate":
17
+ return "DELEGATE";
18
+ case "unDelegate":
19
+ return "UNDELEGATE";
20
+ case "withdraw":
21
+ return "WITHDRAW_UNBONDED";
22
+ case "claimRewards":
23
+ return "REWARD";
24
+ case "reDelegateRewards":
25
+ return "DELEGATE";
26
+ default:
27
+ return "OUT";
28
+ }
29
+ }
30
+
31
+ function getOptimisticOperationDelegationAmount(transaction: Transaction): BigNumber | undefined {
32
+ let dataDecoded;
33
+ switch (transaction.mode) {
34
+ case "delegate":
35
+ return transaction.amount;
36
+
37
+ case "unDelegate":
38
+ dataDecoded = BinaryUtils.base64Decode(transaction.data ?? "");
39
+ return new BigNumber(`0x${dataDecoded.split("@")[1]}`);
40
+
41
+ default:
42
+ return new BigNumber(0);
43
+ }
44
+ }
45
+
46
+ export const buildOptimisticOperation = (
47
+ account: MultiversXAccount,
48
+ transaction: Transaction,
49
+ unsignedTx: MultiversXProtocolTransaction,
50
+ ): Operation => {
51
+ const senders = [account.freshAddress];
52
+ const recipients = [transaction.recipient];
53
+ const { subAccountId, fees } = transaction;
54
+
55
+ if (!fees) {
56
+ throw new FeeNotLoaded();
57
+ }
58
+
59
+ const type = getOptimisticOperationType(transaction.mode);
60
+
61
+ const tokenAccount =
62
+ (subAccountId &&
63
+ account.subAccounts &&
64
+ account.subAccounts.find(ta => ta.id === subAccountId)) ||
65
+ null;
66
+
67
+ const value =
68
+ tokenAccount || (transaction.mode !== "send" && transaction.mode != "delegate")
69
+ ? fees
70
+ : transaction.amount.plus(transaction.fees || new BigNumber(0));
71
+
72
+ const delegationAmount = getOptimisticOperationDelegationAmount(transaction);
73
+
74
+ const operation: Operation = {
75
+ id: encodeOperationId(account.id, "", type),
76
+ hash: "",
77
+ type,
78
+ value,
79
+ fee: fees,
80
+ blockHash: null,
81
+ blockHeight: null,
82
+ senders,
83
+ recipients,
84
+ accountId: account.id,
85
+ transactionSequenceNumber: unsignedTx.nonce,
86
+ date: new Date(),
87
+ extra: {
88
+ amount: delegationAmount,
89
+ },
90
+ };
91
+
92
+ const contract = new Address(transaction.recipient).isContractAddress()
93
+ ? transaction.recipient
94
+ : undefined;
95
+
96
+ if (contract) {
97
+ operation.contract = contract;
98
+ }
99
+
100
+ if (tokenAccount && subAccountId) {
101
+ operation.subOperations = [
102
+ {
103
+ id: encodeOperationId(subAccountId, "", "OUT"),
104
+ hash: "",
105
+ type: "OUT",
106
+ value: transaction.amount,
107
+ fee: new BigNumber(0),
108
+ blockHash: null,
109
+ blockHeight: null,
110
+ senders,
111
+ recipients,
112
+ accountId: subAccountId,
113
+ date: new Date(),
114
+ extra: {},
115
+ },
116
+ ];
117
+ }
118
+
119
+ return operation;
120
+ };
@@ -0,0 +1,153 @@
1
+ import { findTokenById, listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
2
+ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { Account, SyncConfig, TokenAccount } from "@ledgerhq/types-live";
4
+ import BigNumber from "bignumber.js";
5
+ import { emptyHistoryCache, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
6
+ import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
7
+ import { getESDTOperations, getAccountESDTTokens } from "./api";
8
+ import { addPrefixToken, extractTokenId } from "./logic";
9
+
10
+ async function buildMultiversXESDTTokenAccount({
11
+ parentAccountId,
12
+ accountAddress,
13
+ token,
14
+ balance,
15
+ }: {
16
+ parentAccountId: string;
17
+ accountAddress: string;
18
+ token: TokenCurrency;
19
+ balance: BigNumber;
20
+ }) {
21
+ const tokenAccountId = encodeTokenAccountId(parentAccountId, token);
22
+ const tokenIdentifierHex = extractTokenId(token.id);
23
+ const tokenIdentifier = Buffer.from(tokenIdentifierHex, "hex").toString();
24
+
25
+ const operations = await getESDTOperations(tokenAccountId, accountAddress, tokenIdentifier, 0);
26
+
27
+ const tokenAccount: TokenAccount = {
28
+ type: "TokenAccount",
29
+ id: tokenAccountId,
30
+ parentId: parentAccountId,
31
+ token,
32
+ operationsCount: operations.length,
33
+ operations,
34
+ pendingOperations: [],
35
+ balance,
36
+ spendableBalance: balance,
37
+ swapHistory: [],
38
+ creationDate: operations.length > 0 ? operations[operations.length - 1].date : new Date(),
39
+ balanceHistoryCache: emptyHistoryCache, // calculated in the jsHelpers
40
+ };
41
+ return tokenAccount;
42
+ }
43
+
44
+ async function syncESDTTokenAccountOperations(
45
+ tokenAccount: TokenAccount,
46
+ address: string,
47
+ ): Promise<TokenAccount> {
48
+ const oldOperations = tokenAccount?.operations || [];
49
+ // Needed for incremental synchronisation
50
+ const startAt = oldOperations.length ? Math.floor(oldOperations[0].date.valueOf() / 1000) : 0;
51
+
52
+ const tokenIdentifierHex = extractTokenId(tokenAccount.token.id);
53
+ const tokenIdentifier = Buffer.from(tokenIdentifierHex, "hex").toString();
54
+
55
+ // Merge new operations with the previously synced ones
56
+ const newOperations = await getESDTOperations(tokenAccount.id, address, tokenIdentifier, startAt);
57
+ const operations = mergeOps(oldOperations, newOperations);
58
+
59
+ if (operations === oldOperations) return tokenAccount;
60
+
61
+ const copy = { ...tokenAccount };
62
+ copy.operations = operations;
63
+ copy.operationsCount = operations.length;
64
+ return copy;
65
+ }
66
+
67
+ async function MultiversXBuildESDTTokenAccounts({
68
+ currency,
69
+ accountId,
70
+ accountAddress,
71
+ existingAccount,
72
+ syncConfig,
73
+ }: {
74
+ currency: CryptoCurrency;
75
+ accountId: string;
76
+ accountAddress: string;
77
+ existingAccount: Account | null | undefined;
78
+ syncConfig: SyncConfig;
79
+ }): Promise<TokenAccount[] | undefined> {
80
+ const { blacklistedTokenIds = [] } = syncConfig;
81
+ if (listTokensForCryptoCurrency(currency).length === 0) {
82
+ return undefined;
83
+ }
84
+
85
+ const tokenAccounts: TokenAccount[] = [];
86
+
87
+ const existingAccountByTicker: { [key: string]: TokenAccount } = {}; // used for fast lookup
88
+
89
+ const existingAccountTickers: string[] = []; // used to keep track of ordering
90
+
91
+ if (existingAccount && existingAccount.subAccounts) {
92
+ for (const existingSubAccount of existingAccount.subAccounts) {
93
+ if (existingSubAccount.type === "TokenAccount") {
94
+ const { ticker, id } = existingSubAccount.token;
95
+
96
+ if (!blacklistedTokenIds.includes(id)) {
97
+ existingAccountTickers.push(ticker);
98
+ existingAccountByTicker[ticker] = existingSubAccount;
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ const accountESDTs = await getAccountESDTTokens(accountAddress);
105
+ for (const esdt of accountESDTs) {
106
+ const esdtIdentifierHex = Buffer.from(esdt.identifier).toString("hex");
107
+ const token = findTokenById(addPrefixToken(esdtIdentifierHex));
108
+
109
+ if (token && !blacklistedTokenIds.includes(token.id)) {
110
+ let tokenAccount = existingAccountByTicker[token.ticker];
111
+ if (!tokenAccount) {
112
+ tokenAccount = await buildMultiversXESDTTokenAccount({
113
+ parentAccountId: accountId,
114
+ accountAddress,
115
+ token,
116
+ balance: new BigNumber(esdt.balance),
117
+ });
118
+ } else {
119
+ const inputTokenAccount = tokenAccount;
120
+ tokenAccount = await syncESDTTokenAccountOperations(inputTokenAccount, accountAddress);
121
+ const balance = new BigNumber(esdt.balance);
122
+ if (!balance.eq(tokenAccount.balance)) {
123
+ // only recreate the object if balance changed
124
+ if (inputTokenAccount === tokenAccount) {
125
+ tokenAccount = { ...tokenAccount };
126
+ }
127
+ tokenAccount.balance = balance;
128
+ tokenAccount.spendableBalance = balance;
129
+ }
130
+ }
131
+
132
+ if (tokenAccount) {
133
+ tokenAccounts.push(tokenAccount);
134
+ existingAccountTickers.push(token.ticker);
135
+ existingAccountByTicker[token.ticker] = tokenAccount;
136
+ }
137
+ }
138
+ }
139
+
140
+ // Preserve order of tokenAccounts from the existing token accounts
141
+ tokenAccounts.sort((a, b) => {
142
+ const i = existingAccountTickers.indexOf(a.token.ticker);
143
+ const j = existingAccountTickers.indexOf(b.token.ticker);
144
+ if (i === j) return 0;
145
+ if (i < 0) return 1;
146
+ if (j < 0) return -1;
147
+ return i - j;
148
+ });
149
+
150
+ return tokenAccounts;
151
+ }
152
+
153
+ export default MultiversXBuildESDTTokenAccounts;
@@ -0,0 +1,67 @@
1
+ import { IGasLimit, INetworkConfig, INonce } from "@multiversx/sdk-core";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import { getAccountNonce, getNetworkConfig } from "./api";
4
+ import {
5
+ GAS_PRICE,
6
+ TRANSACTION_OPTIONS_TX_HASH_SIGN,
7
+ TRANSACTION_VERSION_DEFAULT,
8
+ } from "./constants";
9
+ import { isAmountSpentFromBalance } from "./logic";
10
+ import type { MultiversXProtocolTransaction, Transaction } from "./types";
11
+
12
+ /**
13
+ *
14
+ * @param {MultiversXAccount} account
15
+ * @param {SubAccount | null | undefined} tokenAccount
16
+ * @param {Transaction} transaction
17
+ */
18
+ export const buildTransactionToSign = async (
19
+ account: Account,
20
+ transaction: Transaction,
21
+ ): Promise<string> => {
22
+ const sender = account.freshAddress;
23
+ const nonce = await getAccountNonce(sender);
24
+ const networkConfig: INetworkConfig = await getNetworkConfig();
25
+ const chainID = networkConfig.ChainID.valueOf();
26
+
27
+ const isTokenAccount = account.subAccounts?.some(ta => ta.id === transaction.subAccountId);
28
+ const value =
29
+ !isTokenAccount && isAmountSpentFromBalance(transaction.mode)
30
+ ? transaction.amount.toFixed()
31
+ : "0";
32
+
33
+ return doBuildTransactionToSign({
34
+ transaction,
35
+ sender: sender,
36
+ nonce,
37
+ value,
38
+ minGasLimit: networkConfig.MinGasLimit,
39
+ chainID,
40
+ });
41
+ };
42
+
43
+ export const doBuildTransactionToSign = async (options: {
44
+ transaction: Transaction;
45
+ sender: string;
46
+ nonce: INonce;
47
+ value: string;
48
+ minGasLimit: IGasLimit;
49
+ chainID: string;
50
+ }): Promise<string> => {
51
+ const gasLimit = options.transaction.gasLimit || options.minGasLimit.valueOf();
52
+
53
+ const transaction: MultiversXProtocolTransaction = {
54
+ nonce: options.nonce.valueOf(),
55
+ value: options.value,
56
+ receiver: options.transaction.recipient,
57
+ sender: options.sender,
58
+ gasPrice: GAS_PRICE,
59
+ gasLimit: gasLimit,
60
+ ...(options.transaction.data ? { data: options.transaction.data } : {}),
61
+ chainID: options.chainID,
62
+ version: TRANSACTION_VERSION_DEFAULT,
63
+ options: TRANSACTION_OPTIONS_TX_HASH_SIGN,
64
+ };
65
+
66
+ return JSON.stringify(transaction);
67
+ };