@ledgerhq/coin-concordium 0.2.0-nightly.20251209140356

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 (385) hide show
  1. package/.env.integ.test.example +2 -0
  2. package/.eslintrc.js +37 -0
  3. package/.turbo/turbo-build.log +4 -0
  4. package/.unimportedrc.json +29 -0
  5. package/CHANGELOG.md +18 -0
  6. package/LICENSE.txt +21 -0
  7. package/jest.config.js +21 -0
  8. package/jest.integ.config.js +8 -0
  9. package/lib/api/index.d.ts +4 -0
  10. package/lib/api/index.d.ts.map +1 -0
  11. package/lib/api/index.js +56 -0
  12. package/lib/api/index.js.map +1 -0
  13. package/lib/bridge/broadcast.d.ts +4 -0
  14. package/lib/bridge/broadcast.d.ts.map +1 -0
  15. package/lib/bridge/broadcast.js +11 -0
  16. package/lib/bridge/broadcast.js.map +1 -0
  17. package/lib/bridge/createTransaction.d.ts +4 -0
  18. package/lib/bridge/createTransaction.d.ts.map +1 -0
  19. package/lib/bridge/createTransaction.js +19 -0
  20. package/lib/bridge/createTransaction.js.map +1 -0
  21. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  22. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  23. package/lib/bridge/deviceTransactionConfig.js +21 -0
  24. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  25. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  26. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  27. package/lib/bridge/estimateMaxSpendable.js +26 -0
  28. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  29. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  30. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  31. package/lib/bridge/getTransactionStatus.js +78 -0
  32. package/lib/bridge/getTransactionStatus.js.map +1 -0
  33. package/lib/bridge/index.d.ts +11 -0
  34. package/lib/bridge/index.d.ts.map +1 -0
  35. package/lib/bridge/index.js +54 -0
  36. package/lib/bridge/index.js.map +1 -0
  37. package/lib/bridge/prepareTransaction.d.ts +4 -0
  38. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  39. package/lib/bridge/prepareTransaction.js +20 -0
  40. package/lib/bridge/prepareTransaction.js.map +1 -0
  41. package/lib/bridge/signOperation.d.ts +5 -0
  42. package/lib/bridge/signOperation.d.ts.map +1 -0
  43. package/lib/bridge/signOperation.js +75 -0
  44. package/lib/bridge/signOperation.js.map +1 -0
  45. package/lib/bridge/sync.d.ts +3 -0
  46. package/lib/bridge/sync.d.ts.map +1 -0
  47. package/lib/bridge/sync.js +86 -0
  48. package/lib/bridge/sync.js.map +1 -0
  49. package/lib/bridge/transaction.d.ts +15 -0
  50. package/lib/bridge/transaction.d.ts.map +1 -0
  51. package/lib/bridge/transaction.js +50 -0
  52. package/lib/bridge/transaction.js.map +1 -0
  53. package/lib/bridge/updateTransaction.d.ts +4 -0
  54. package/lib/bridge/updateTransaction.d.ts.map +1 -0
  55. package/lib/bridge/updateTransaction.js +17 -0
  56. package/lib/bridge/updateTransaction.js.map +1 -0
  57. package/lib/common-logic/account/getBalance.d.ts +3 -0
  58. package/lib/common-logic/account/getBalance.d.ts.map +1 -0
  59. package/lib/common-logic/account/getBalance.js +10 -0
  60. package/lib/common-logic/account/getBalance.js.map +1 -0
  61. package/lib/common-logic/account/getNextSequence.d.ts +2 -0
  62. package/lib/common-logic/account/getNextSequence.d.ts.map +1 -0
  63. package/lib/common-logic/account/getNextSequence.js +9 -0
  64. package/lib/common-logic/account/getNextSequence.js.map +1 -0
  65. package/lib/common-logic/common.d.ts +3 -0
  66. package/lib/common-logic/common.d.ts.map +1 -0
  67. package/lib/common-logic/common.js +11 -0
  68. package/lib/common-logic/common.js.map +1 -0
  69. package/lib/common-logic/history/lastBlock.d.ts +3 -0
  70. package/lib/common-logic/history/lastBlock.d.ts.map +1 -0
  71. package/lib/common-logic/history/lastBlock.js +13 -0
  72. package/lib/common-logic/history/lastBlock.js.map +1 -0
  73. package/lib/common-logic/history/listOperations.d.ts +11 -0
  74. package/lib/common-logic/history/listOperations.d.ts.map +1 -0
  75. package/lib/common-logic/history/listOperations.js +53 -0
  76. package/lib/common-logic/history/listOperations.js.map +1 -0
  77. package/lib/common-logic/index.d.ts +11 -0
  78. package/lib/common-logic/index.d.ts.map +1 -0
  79. package/lib/common-logic/index.js +24 -0
  80. package/lib/common-logic/index.js.map +1 -0
  81. package/lib/common-logic/transaction/broadcast.d.ts +2 -0
  82. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -0
  83. package/lib/common-logic/transaction/broadcast.js +9 -0
  84. package/lib/common-logic/transaction/broadcast.js.map +1 -0
  85. package/lib/common-logic/transaction/combine.d.ts +2 -0
  86. package/lib/common-logic/transaction/combine.d.ts.map +1 -0
  87. package/lib/common-logic/transaction/combine.js +9 -0
  88. package/lib/common-logic/transaction/combine.js.map +1 -0
  89. package/lib/common-logic/transaction/craftTransaction.d.ts +15 -0
  90. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -0
  91. package/lib/common-logic/transaction/craftTransaction.js +20 -0
  92. package/lib/common-logic/transaction/craftTransaction.js.map +1 -0
  93. package/lib/common-logic/transaction/estimateFees.d.ts +2 -0
  94. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -0
  95. package/lib/common-logic/transaction/estimateFees.js +21 -0
  96. package/lib/common-logic/transaction/estimateFees.js.map +1 -0
  97. package/lib/common-logic/utils.d.ts +6 -0
  98. package/lib/common-logic/utils.d.ts.map +1 -0
  99. package/lib/common-logic/utils.js +22 -0
  100. package/lib/common-logic/utils.js.map +1 -0
  101. package/lib/config.d.ts +12 -0
  102. package/lib/config.d.ts.map +1 -0
  103. package/lib/config.js +9 -0
  104. package/lib/config.js.map +1 -0
  105. package/lib/index.d.ts +4 -0
  106. package/lib/index.d.ts.map +1 -0
  107. package/lib/index.js +21 -0
  108. package/lib/index.js.map +1 -0
  109. package/lib/network/indexer.d.ts +6 -0
  110. package/lib/network/indexer.d.ts.map +1 -0
  111. package/lib/network/indexer.js +19 -0
  112. package/lib/network/indexer.js.map +1 -0
  113. package/lib/network/mock-network.d.ts +5 -0
  114. package/lib/network/mock-network.d.ts.map +1 -0
  115. package/lib/network/mock-network.js +29 -0
  116. package/lib/network/mock-network.js.map +1 -0
  117. package/lib/network/node.d.ts +12 -0
  118. package/lib/network/node.d.ts.map +1 -0
  119. package/lib/network/node.js +92 -0
  120. package/lib/network/node.js.map +1 -0
  121. package/lib/network/types.d.ts +47 -0
  122. package/lib/network/types.d.ts.map +1 -0
  123. package/lib/network/types.js +7 -0
  124. package/lib/network/types.js.map +1 -0
  125. package/lib/signer/getAddress.d.ts +6 -0
  126. package/lib/signer/getAddress.d.ts.map +1 -0
  127. package/lib/signer/getAddress.js +14 -0
  128. package/lib/signer/getAddress.js.map +1 -0
  129. package/lib/signer/index.d.ts +6 -0
  130. package/lib/signer/index.d.ts.map +1 -0
  131. package/lib/signer/index.js +11 -0
  132. package/lib/signer/index.js.map +1 -0
  133. package/lib/test/bot-deviceActions.d.ts +4 -0
  134. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  135. package/lib/test/bot-deviceActions.js +44 -0
  136. package/lib/test/bot-deviceActions.js.map +1 -0
  137. package/lib/test/bot-specs.d.ts +2 -0
  138. package/lib/test/bot-specs.d.ts.map +1 -0
  139. package/lib/test/bot-specs.js +79 -0
  140. package/lib/test/bot-specs.js.map +1 -0
  141. package/lib/test/bridgeDatasetTest.d.ts +5 -0
  142. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  143. package/lib/test/bridgeDatasetTest.js +148 -0
  144. package/lib/test/bridgeDatasetTest.js.map +1 -0
  145. package/lib/test/cli.d.ts +26 -0
  146. package/lib/test/cli.d.ts.map +1 -0
  147. package/lib/test/cli.js +36 -0
  148. package/lib/test/cli.js.map +1 -0
  149. package/lib/test/index.d.ts +5 -0
  150. package/lib/test/index.d.ts.map +1 -0
  151. package/lib/test/index.js +26 -0
  152. package/lib/test/index.js.map +1 -0
  153. package/lib/types/assets.d.ts +3 -0
  154. package/lib/types/assets.d.ts.map +1 -0
  155. package/lib/types/assets.js +3 -0
  156. package/lib/types/assets.js.map +1 -0
  157. package/lib/types/bridge.d.ts +23 -0
  158. package/lib/types/bridge.d.ts.map +1 -0
  159. package/lib/types/bridge.js +3 -0
  160. package/lib/types/bridge.js.map +1 -0
  161. package/lib/types/errors.d.ts +4 -0
  162. package/lib/types/errors.d.ts.map +1 -0
  163. package/lib/types/errors.js +6 -0
  164. package/lib/types/errors.js.map +1 -0
  165. package/lib/types/index.d.ts +13 -0
  166. package/lib/types/index.d.ts.map +1 -0
  167. package/lib/types/index.js +19 -0
  168. package/lib/types/index.js.map +1 -0
  169. package/lib/types/signer.d.ts +10 -0
  170. package/lib/types/signer.d.ts.map +1 -0
  171. package/lib/types/signer.js +3 -0
  172. package/lib/types/signer.js.map +1 -0
  173. package/lib-es/api/index.d.ts +4 -0
  174. package/lib-es/api/index.d.ts.map +1 -0
  175. package/lib-es/api/index.js +50 -0
  176. package/lib-es/api/index.js.map +1 -0
  177. package/lib-es/bridge/broadcast.d.ts +4 -0
  178. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  179. package/lib-es/bridge/broadcast.js +7 -0
  180. package/lib-es/bridge/broadcast.js.map +1 -0
  181. package/lib-es/bridge/createTransaction.d.ts +4 -0
  182. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  183. package/lib-es/bridge/createTransaction.js +12 -0
  184. package/lib-es/bridge/createTransaction.js.map +1 -0
  185. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  186. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  187. package/lib-es/bridge/deviceTransactionConfig.js +19 -0
  188. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  189. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  190. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  191. package/lib-es/bridge/estimateMaxSpendable.js +19 -0
  192. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  193. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  194. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  195. package/lib-es/bridge/getTransactionStatus.js +71 -0
  196. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  197. package/lib-es/bridge/index.d.ts +11 -0
  198. package/lib-es/bridge/index.d.ts.map +1 -0
  199. package/lib-es/bridge/index.js +48 -0
  200. package/lib-es/bridge/index.js.map +1 -0
  201. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  202. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  203. package/lib-es/bridge/prepareTransaction.js +13 -0
  204. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  205. package/lib-es/bridge/signOperation.d.ts +5 -0
  206. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  207. package/lib-es/bridge/signOperation.js +68 -0
  208. package/lib-es/bridge/signOperation.js.map +1 -0
  209. package/lib-es/bridge/sync.d.ts +3 -0
  210. package/lib-es/bridge/sync.d.ts.map +1 -0
  211. package/lib-es/bridge/sync.js +79 -0
  212. package/lib-es/bridge/sync.js.map +1 -0
  213. package/lib-es/bridge/transaction.d.ts +15 -0
  214. package/lib-es/bridge/transaction.d.ts.map +1 -0
  215. package/lib-es/bridge/transaction.js +44 -0
  216. package/lib-es/bridge/transaction.js.map +1 -0
  217. package/lib-es/bridge/updateTransaction.d.ts +4 -0
  218. package/lib-es/bridge/updateTransaction.d.ts.map +1 -0
  219. package/lib-es/bridge/updateTransaction.js +13 -0
  220. package/lib-es/bridge/updateTransaction.js.map +1 -0
  221. package/lib-es/common-logic/account/getBalance.d.ts +3 -0
  222. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -0
  223. package/lib-es/common-logic/account/getBalance.js +7 -0
  224. package/lib-es/common-logic/account/getBalance.js.map +1 -0
  225. package/lib-es/common-logic/account/getNextSequence.d.ts +2 -0
  226. package/lib-es/common-logic/account/getNextSequence.d.ts.map +1 -0
  227. package/lib-es/common-logic/account/getNextSequence.js +6 -0
  228. package/lib-es/common-logic/account/getNextSequence.js.map +1 -0
  229. package/lib-es/common-logic/common.d.ts +3 -0
  230. package/lib-es/common-logic/common.d.ts.map +1 -0
  231. package/lib-es/common-logic/common.js +7 -0
  232. package/lib-es/common-logic/common.js.map +1 -0
  233. package/lib-es/common-logic/history/lastBlock.d.ts +3 -0
  234. package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -0
  235. package/lib-es/common-logic/history/lastBlock.js +10 -0
  236. package/lib-es/common-logic/history/lastBlock.js.map +1 -0
  237. package/lib-es/common-logic/history/listOperations.d.ts +11 -0
  238. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -0
  239. package/lib-es/common-logic/history/listOperations.js +50 -0
  240. package/lib-es/common-logic/history/listOperations.js.map +1 -0
  241. package/lib-es/common-logic/index.d.ts +11 -0
  242. package/lib-es/common-logic/index.d.ts.map +1 -0
  243. package/lib-es/common-logic/index.js +11 -0
  244. package/lib-es/common-logic/index.js.map +1 -0
  245. package/lib-es/common-logic/transaction/broadcast.d.ts +2 -0
  246. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -0
  247. package/lib-es/common-logic/transaction/broadcast.js +6 -0
  248. package/lib-es/common-logic/transaction/broadcast.js.map +1 -0
  249. package/lib-es/common-logic/transaction/combine.d.ts +2 -0
  250. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -0
  251. package/lib-es/common-logic/transaction/combine.js +6 -0
  252. package/lib-es/common-logic/transaction/combine.js.map +1 -0
  253. package/lib-es/common-logic/transaction/craftTransaction.d.ts +15 -0
  254. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -0
  255. package/lib-es/common-logic/transaction/craftTransaction.js +17 -0
  256. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -0
  257. package/lib-es/common-logic/transaction/estimateFees.d.ts +2 -0
  258. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -0
  259. package/lib-es/common-logic/transaction/estimateFees.js +18 -0
  260. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -0
  261. package/lib-es/common-logic/utils.d.ts +6 -0
  262. package/lib-es/common-logic/utils.d.ts.map +1 -0
  263. package/lib-es/common-logic/utils.js +13 -0
  264. package/lib-es/common-logic/utils.js.map +1 -0
  265. package/lib-es/config.d.ts +12 -0
  266. package/lib-es/config.d.ts.map +1 -0
  267. package/lib-es/config.js +4 -0
  268. package/lib-es/config.js.map +1 -0
  269. package/lib-es/index.d.ts +4 -0
  270. package/lib-es/index.d.ts.map +1 -0
  271. package/lib-es/index.js +3 -0
  272. package/lib-es/index.js.map +1 -0
  273. package/lib-es/network/indexer.d.ts +6 -0
  274. package/lib-es/network/indexer.d.ts.map +1 -0
  275. package/lib-es/network/indexer.js +12 -0
  276. package/lib-es/network/indexer.js.map +1 -0
  277. package/lib-es/network/mock-network.d.ts +5 -0
  278. package/lib-es/network/mock-network.d.ts.map +1 -0
  279. package/lib-es/network/mock-network.js +25 -0
  280. package/lib-es/network/mock-network.js.map +1 -0
  281. package/lib-es/network/node.d.ts +12 -0
  282. package/lib-es/network/node.d.ts.map +1 -0
  283. package/lib-es/network/node.js +80 -0
  284. package/lib-es/network/node.js.map +1 -0
  285. package/lib-es/network/types.d.ts +47 -0
  286. package/lib-es/network/types.d.ts.map +1 -0
  287. package/lib-es/network/types.js +4 -0
  288. package/lib-es/network/types.js.map +1 -0
  289. package/lib-es/signer/getAddress.d.ts +6 -0
  290. package/lib-es/signer/getAddress.d.ts.map +1 -0
  291. package/lib-es/signer/getAddress.js +12 -0
  292. package/lib-es/signer/getAddress.js.map +1 -0
  293. package/lib-es/signer/index.d.ts +6 -0
  294. package/lib-es/signer/index.d.ts.map +1 -0
  295. package/lib-es/signer/index.js +6 -0
  296. package/lib-es/signer/index.js.map +1 -0
  297. package/lib-es/test/bot-deviceActions.d.ts +4 -0
  298. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  299. package/lib-es/test/bot-deviceActions.js +41 -0
  300. package/lib-es/test/bot-deviceActions.js.map +1 -0
  301. package/lib-es/test/bot-specs.d.ts +1 -0
  302. package/lib-es/test/bot-specs.d.ts.map +1 -0
  303. package/lib-es/test/bot-specs.js +78 -0
  304. package/lib-es/test/bot-specs.js.map +1 -0
  305. package/lib-es/test/bridgeDatasetTest.d.ts +5 -0
  306. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  307. package/lib-es/test/bridgeDatasetTest.js +142 -0
  308. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  309. package/lib-es/test/cli.d.ts +26 -0
  310. package/lib-es/test/cli.d.ts.map +1 -0
  311. package/lib-es/test/cli.js +30 -0
  312. package/lib-es/test/cli.js.map +1 -0
  313. package/lib-es/test/index.d.ts +5 -0
  314. package/lib-es/test/index.d.ts.map +1 -0
  315. package/lib-es/test/index.js +6 -0
  316. package/lib-es/test/index.js.map +1 -0
  317. package/lib-es/types/assets.d.ts +3 -0
  318. package/lib-es/types/assets.d.ts.map +1 -0
  319. package/lib-es/types/assets.js +2 -0
  320. package/lib-es/types/assets.js.map +1 -0
  321. package/lib-es/types/bridge.d.ts +23 -0
  322. package/lib-es/types/bridge.d.ts.map +1 -0
  323. package/lib-es/types/bridge.js +2 -0
  324. package/lib-es/types/bridge.js.map +1 -0
  325. package/lib-es/types/errors.d.ts +4 -0
  326. package/lib-es/types/errors.d.ts.map +1 -0
  327. package/lib-es/types/errors.js +3 -0
  328. package/lib-es/types/errors.js.map +1 -0
  329. package/lib-es/types/index.d.ts +13 -0
  330. package/lib-es/types/index.d.ts.map +1 -0
  331. package/lib-es/types/index.js +3 -0
  332. package/lib-es/types/index.js.map +1 -0
  333. package/lib-es/types/signer.d.ts +10 -0
  334. package/lib-es/types/signer.d.ts.map +1 -0
  335. package/lib-es/types/signer.js +2 -0
  336. package/lib-es/types/signer.js.map +1 -0
  337. package/package.json +137 -0
  338. package/src/api/index.test.ts +22 -0
  339. package/src/api/index.ts +88 -0
  340. package/src/bridge/broadcast.test.ts +36 -0
  341. package/src/bridge/broadcast.ts +11 -0
  342. package/src/bridge/createTransaction.test.ts +12 -0
  343. package/src/bridge/createTransaction.ts +14 -0
  344. package/src/bridge/deviceTransactionConfig.test.ts +20 -0
  345. package/src/bridge/deviceTransactionConfig.ts +34 -0
  346. package/src/bridge/estimateMaxSpendable.ts +25 -0
  347. package/src/bridge/getTransactionStatus.ts +88 -0
  348. package/src/bridge/index.test.ts +26 -0
  349. package/src/bridge/index.ts +65 -0
  350. package/src/bridge/prepareTransaction.test.ts +29 -0
  351. package/src/bridge/prepareTransaction.ts +25 -0
  352. package/src/bridge/signOperation.ts +94 -0
  353. package/src/bridge/sync.ts +106 -0
  354. package/src/bridge/transaction.ts +61 -0
  355. package/src/bridge/updateTransaction.ts +17 -0
  356. package/src/common-logic/account/getBalance.ts +8 -0
  357. package/src/common-logic/account/getNextSequence.ts +6 -0
  358. package/src/common-logic/common.ts +8 -0
  359. package/src/common-logic/history/lastBlock.ts +11 -0
  360. package/src/common-logic/history/listOperations.ts +65 -0
  361. package/src/common-logic/index.ts +11 -0
  362. package/src/common-logic/transaction/broadcast.ts +6 -0
  363. package/src/common-logic/transaction/combine.ts +6 -0
  364. package/src/common-logic/transaction/craftTransaction.ts +36 -0
  365. package/src/common-logic/transaction/estimateFees.ts +16 -0
  366. package/src/common-logic/utils.ts +18 -0
  367. package/src/config.ts +12 -0
  368. package/src/index.ts +4 -0
  369. package/src/network/indexer.ts +17 -0
  370. package/src/network/mock-network.ts +25 -0
  371. package/src/network/node.ts +94 -0
  372. package/src/network/types.ts +51 -0
  373. package/src/signer/getAddress.ts +20 -0
  374. package/src/signer/index.ts +7 -0
  375. package/src/test/bot-deviceActions.ts +48 -0
  376. package/src/test/bot-specs.ts +76 -0
  377. package/src/test/bridgeDatasetTest.ts +147 -0
  378. package/src/test/cli.ts +44 -0
  379. package/src/test/index.ts +6 -0
  380. package/src/types/assets.ts +3 -0
  381. package/src/types/bridge.ts +33 -0
  382. package/src/types/errors.ts +3 -0
  383. package/src/types/index.ts +13 -0
  384. package/src/types/signer.ts +11 -0
  385. package/tsconfig.json +12 -0
@@ -0,0 +1,88 @@
1
+ import {
2
+ AlpacaApi,
3
+ Block,
4
+ BlockInfo,
5
+ Cursor,
6
+ Page,
7
+ Validator,
8
+ FeeEstimation,
9
+ Reward,
10
+ Stake,
11
+ TransactionIntent,
12
+ CraftedTransaction,
13
+ } from "@ledgerhq/coin-framework/api/index";
14
+ import BigNumber from "bignumber.js";
15
+ import coinConfig, { type ConcordiumConfig } from "../config";
16
+ import {
17
+ broadcast,
18
+ combine,
19
+ craftTransaction,
20
+ estimateFees,
21
+ getBalance,
22
+ getNextValidSequence,
23
+ lastBlock,
24
+ listOperations,
25
+ } from "../common-logic";
26
+
27
+ export function createApi(config: ConcordiumConfig): AlpacaApi {
28
+ coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
29
+
30
+ return {
31
+ broadcast,
32
+ combine,
33
+ craftTransaction: craft,
34
+ craftRawTransaction: (
35
+ _transaction: string,
36
+ _sender: string,
37
+ _publicKey: string,
38
+ _sequence: bigint,
39
+ ): Promise<CraftedTransaction> => {
40
+ throw new Error("craftRawTransaction is not supported");
41
+ },
42
+ estimateFees: estimate,
43
+ getBalance,
44
+ lastBlock,
45
+ listOperations,
46
+ getBlock(_height): Promise<Block> {
47
+ throw new Error("getBlock is not supported");
48
+ },
49
+ getBlockInfo(_height: number): Promise<BlockInfo> {
50
+ throw new Error("getBlockInfo is not supported");
51
+ },
52
+ getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
53
+ throw new Error("getStakes is not supported");
54
+ },
55
+ getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
56
+ throw new Error("getRewards is not supported");
57
+ },
58
+ getValidators(_cursor?: Cursor): Promise<Page<Validator>> {
59
+ throw new Error("getValidators is not supported");
60
+ },
61
+ };
62
+ }
63
+
64
+ async function craft(transactionIntent: TransactionIntent): Promise<CraftedTransaction> {
65
+ const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
66
+ const tx = await craftTransaction(
67
+ { address: transactionIntent.sender, nextSequenceNumber },
68
+ {
69
+ recipient: transactionIntent.recipient,
70
+ amount: new BigNumber(transactionIntent.amount.toString()),
71
+ },
72
+ );
73
+ return { transaction: tx.serializedTransaction };
74
+ }
75
+
76
+ async function estimate(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
77
+ const { serializedTransaction } = await craftTransaction(
78
+ { address: transactionIntent.sender },
79
+ {
80
+ recipient: transactionIntent.recipient,
81
+ amount: new BigNumber(transactionIntent.amount.toString()),
82
+ },
83
+ );
84
+
85
+ const value = await estimateFees(serializedTransaction);
86
+
87
+ return { value };
88
+ }
@@ -0,0 +1,36 @@
1
+ import { Account, BroadcastArg } from "@ledgerhq/types-live";
2
+ jest.mock("@ledgerhq/coin-framework/operation");
3
+ jest.mock("../common-logic");
4
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
5
+ import { broadcast as broadcastLogic } from "../common-logic";
6
+ import { broadcast } from "./broadcast";
7
+
8
+ describe("broadcast", () => {
9
+ let patchOperationSpy: jest.SpyInstance;
10
+ let broadcastSpy: jest.SpyInstance;
11
+ beforeEach(() => {
12
+ patchOperationSpy = jest.spyOn({ patchOperationWithHash }, "patchOperationWithHash");
13
+ broadcastSpy = jest.spyOn({ broadcastLogic }, "broadcastLogic");
14
+ broadcastSpy.mockResolvedValue("hash");
15
+ });
16
+
17
+ it("should broadcast", () => {
18
+ broadcast({
19
+ signedOperation: {
20
+ signature: undefined,
21
+ operation: undefined,
22
+ },
23
+ } as unknown as BroadcastArg<Account>);
24
+ expect(broadcastLogic).toHaveBeenCalledTimes(1);
25
+ });
26
+
27
+ it("should patch operation with hash", () => {
28
+ broadcast({
29
+ signedOperation: {
30
+ signature: undefined,
31
+ operation: undefined,
32
+ },
33
+ } as unknown as BroadcastArg<Account>);
34
+ expect(patchOperationSpy).toHaveBeenCalledWith(undefined, "hash");
35
+ });
36
+ });
@@ -0,0 +1,11 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
3
+ import { broadcast as broadcastLogic } from "../common-logic";
4
+ import { Transaction } from "../types";
5
+
6
+ export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
7
+ signedOperation: { signature, operation },
8
+ }) => {
9
+ const hash = await broadcastLogic(signature);
10
+ return patchOperationWithHash(operation, hash);
11
+ };
@@ -0,0 +1,12 @@
1
+ import { Account, AccountLike } from "@ledgerhq/types-live";
2
+ import { createTransaction } from "./createTransaction";
3
+
4
+ describe("createTransaction", () => {
5
+ it("should create a 0 amount transaction", () => {
6
+ expect(createTransaction({} as AccountLike<Account>).amount.toNumber()).toEqual(0);
7
+ });
8
+
9
+ it("should create a transaction with concordium family", () => {
10
+ expect(createTransaction({} as AccountLike<Account>).family).toEqual("concordium");
11
+ });
12
+ });
@@ -0,0 +1,14 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { Transaction } from "../types";
4
+
5
+ // We create an empty transaction that will be filled later
6
+ export const createTransaction: AccountBridge<Transaction>["createTransaction"] = () => ({
7
+ family: "concordium",
8
+ amount: new BigNumber(0),
9
+ recipient: "",
10
+ fee: null,
11
+ memo: undefined,
12
+ networkInfo: null,
13
+ feeCustomUnit: null,
14
+ });
@@ -0,0 +1,20 @@
1
+ import BigNumber from "bignumber.js";
2
+ import getDeviceTransactionConfig from "./deviceTransactionConfig";
3
+
4
+ describe("getDeviceTransactionConfig", () => {
5
+ it("should return amount field when it's more than 0", async () => {
6
+ const result = await getDeviceTransactionConfig({
7
+ transaction: {},
8
+ status: { amount: new BigNumber(1), estimatedFees: new BigNumber(0) },
9
+ } as any);
10
+ expect(result[0]).toEqual({ type: "amount", label: "Amount" });
11
+ });
12
+
13
+ it("should return fee field when it's more than 0", async () => {
14
+ const result = await getDeviceTransactionConfig({
15
+ transaction: {},
16
+ status: { amount: new BigNumber(0), estimatedFees: new BigNumber(1) },
17
+ } as any);
18
+ expect(result[0]).toEqual({ type: "fees", label: "Fees" });
19
+ });
20
+ });
@@ -0,0 +1,34 @@
1
+ import type { AccountLike, Account } from "@ledgerhq/types-live";
2
+ import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
3
+ import type { Transaction, TransactionStatus } from "../types";
4
+
5
+ // This method adds additional fields that need to be reviewed when signing a transaction on the device.
6
+ async function getDeviceTransactionConfig({
7
+ transaction: {},
8
+ status: { amount, estimatedFees },
9
+ }: {
10
+ account: AccountLike;
11
+ parentAccount: Account | null | undefined;
12
+ transaction: Transaction;
13
+ status: TransactionStatus;
14
+ }): Promise<Array<CommonDeviceTransactionField>> {
15
+ const fields: Array<CommonDeviceTransactionField> = [];
16
+
17
+ if (!amount.isZero()) {
18
+ fields.push({
19
+ type: "amount",
20
+ label: "Amount",
21
+ });
22
+ }
23
+
24
+ if (!estimatedFees.isZero()) {
25
+ fields.push({
26
+ type: "fees",
27
+ label: "Fees",
28
+ });
29
+ }
30
+
31
+ return fields;
32
+ }
33
+
34
+ export default getDeviceTransactionConfig;
@@ -0,0 +1,25 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AccountBridge } from "@ledgerhq/types-live";
3
+ import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
+ import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
5
+ import { Transaction } from "../types";
6
+ import { getTransactionStatus } from "./getTransactionStatus";
7
+ import { prepareTransaction } from "./prepareTransaction";
8
+ import { createTransaction } from "./createTransaction";
9
+
10
+ export const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"] = async ({
11
+ account,
12
+ parentAccount,
13
+ transaction,
14
+ }) => {
15
+ const mainAccount = getMainAccount(account, parentAccount);
16
+ const newTransaction = await prepareTransaction(mainAccount, {
17
+ ...createTransaction(account),
18
+ ...transaction,
19
+ // fee estimation might require a recipient to work, in that case, we use a dummy one
20
+ recipient: transaction?.recipient || getAbandonSeedAddress("concordium"),
21
+ amount: new BigNumber(0),
22
+ });
23
+ const status = await getTransactionStatus(mainAccount, newTransaction);
24
+ return BigNumber.max(0, account.spendableBalance.minus(status.estimatedFees));
25
+ };
@@ -0,0 +1,88 @@
1
+ import {
2
+ AmountRequired,
3
+ FeeNotLoaded,
4
+ FeeRequired,
5
+ FeeTooHigh,
6
+ InvalidAddress,
7
+ InvalidAddressBecauseDestinationIsAlsoSource,
8
+ NotEnoughBalanceBecauseDestinationNotCreated,
9
+ NotEnoughSpendableBalance,
10
+ RecipientRequired,
11
+ } from "@ledgerhq/errors";
12
+ import BigNumber from "bignumber.js";
13
+ import { Account, AccountBridge } from "@ledgerhq/types-live";
14
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
15
+ import { Transaction, TransactionStatus } from "../types";
16
+ import { isRecipientValid } from "../common-logic/utils";
17
+ import coinConfig from "../config";
18
+
19
+ export const getTransactionStatus: AccountBridge<
20
+ Transaction,
21
+ Account,
22
+ TransactionStatus
23
+ >["getTransactionStatus"] = async (account, transaction) => {
24
+ const errors: Record<string, Error> = {};
25
+ const warnings: Record<string, Error> = {};
26
+
27
+ // reserveAmount is the minimum amount of currency that an account must hold in order to stay activated
28
+ const reserveAmount = new BigNumber(coinConfig.getCoinConfig().minReserve);
29
+ const estimatedFees = new BigNumber(transaction.fee || 0);
30
+ const totalSpent = new BigNumber(transaction.amount).plus(estimatedFees);
31
+ const amount = new BigNumber(transaction.amount);
32
+
33
+ if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
34
+ // if the fee is more than 10 times the amount, we warn the user that fee is high compared to what he is sending
35
+ warnings.feeTooHigh = new FeeTooHigh();
36
+ }
37
+
38
+ if (!transaction.fee) {
39
+ // if the fee is not loaded, we can't do much
40
+ errors.fee = new FeeNotLoaded();
41
+ } else if (transaction.fee.eq(0)) {
42
+ // On some chains, 0 fee could still work so this is optional
43
+ errors.fee = new FeeRequired();
44
+ } else if (totalSpent.gt(account.balance.minus(reserveAmount))) {
45
+ // if the total spent is greater than the balance minus the reserve amount, tx is invalid
46
+ errors.amount = new NotEnoughSpendableBalance("", {
47
+ minimumAmount: formatCurrencyUnit(account.currency.units[0], reserveAmount, {
48
+ disableRounding: true,
49
+ useGrouping: false,
50
+ showCode: true,
51
+ }),
52
+ });
53
+ } else if (transaction.recipient && transaction.amount.lt(reserveAmount)) {
54
+ // if we send an amount lower than reserve amount AND target account is new, we need to warn the user that the target account will not be activated
55
+ errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
56
+ minimalAmount: formatCurrencyUnit(account.currency.units[0], reserveAmount, {
57
+ disableRounding: true,
58
+ useGrouping: false,
59
+ showCode: true,
60
+ }),
61
+ });
62
+ }
63
+
64
+ if (!transaction.recipient) {
65
+ errors.recipient = new RecipientRequired("");
66
+ } else if (account.freshAddress === transaction.recipient) {
67
+ // we want to prevent user from sending to themselves (even if it's technically feasible)
68
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
69
+ } else if (!isRecipientValid(transaction.recipient)) {
70
+ // We want to prevent user from sending to an invalid address
71
+ errors.recipient = new InvalidAddress("", {
72
+ currencyName: account.currency.name,
73
+ });
74
+ }
75
+
76
+ if (!errors.amount && amount.eq(0)) {
77
+ // if the amount is 0, we prevent the user from sending the tx (even if it's technically feasible)
78
+ errors.amount = new AmountRequired();
79
+ }
80
+
81
+ return {
82
+ errors,
83
+ warnings,
84
+ estimatedFees,
85
+ amount,
86
+ totalSpent,
87
+ };
88
+ };
@@ -0,0 +1,26 @@
1
+ import { createBridges } from ".";
2
+
3
+ describe("createBridges", () => {
4
+ it("has a currency bridge and an account bridge with required methods", () => {
5
+ expect(createBridges(undefined as any, {} as any)).toEqual({
6
+ accountBridge: {
7
+ broadcast: expect.any(Function),
8
+ createTransaction: expect.any(Function),
9
+ estimateMaxSpendable: expect.any(Function),
10
+ getSerializedAddressParameters: expect.any(Function),
11
+ getTransactionStatus: expect.any(Function),
12
+ prepareTransaction: expect.any(Function),
13
+ receive: expect.any(Function),
14
+ signOperation: expect.any(Function),
15
+ signRawOperation: expect.any(Function),
16
+ sync: expect.any(Function),
17
+ updateTransaction: expect.any(Function),
18
+ },
19
+ currencyBridge: {
20
+ preload: expect.any(Function),
21
+ hydrate: expect.any(Function),
22
+ scanAccounts: expect.any(Function),
23
+ },
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,65 @@
1
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import {
3
+ getSerializedAddressParameters,
4
+ makeAccountBridgeReceive,
5
+ makeScanAccounts,
6
+ makeSync,
7
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
+ import { CoinConfig } from "@ledgerhq/coin-framework/config";
9
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
10
+ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
11
+ import concordiumCoinConfig, { type ConcordiumCoinConfig } from "../config";
12
+ import resolver from "../signer";
13
+ import { ConcordiumSigner } from "../types";
14
+ import type { Transaction } from "../types";
15
+ import { broadcast } from "./broadcast";
16
+ import { createTransaction } from "./createTransaction";
17
+ import { estimateMaxSpendable } from "./estimateMaxSpendable";
18
+ import { getTransactionStatus } from "./getTransactionStatus";
19
+ import { prepareTransaction } from "./prepareTransaction";
20
+ import { buildSignOperation } from "./signOperation";
21
+ import { getAccountShape } from "./sync";
22
+ import { updateTransaction } from "./updateTransaction";
23
+
24
+ export function createBridges(
25
+ signerContext: SignerContext<ConcordiumSigner>,
26
+ coinConfig: CoinConfig<ConcordiumCoinConfig>,
27
+ ) {
28
+ concordiumCoinConfig.setCoinConfig(coinConfig);
29
+
30
+ const getAddress = resolver(signerContext);
31
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
32
+
33
+ const scanAccounts = makeScanAccounts({ getAccountShape, getAddressFn: getAddress });
34
+ const currencyBridge: CurrencyBridge = {
35
+ preload: () => Promise.resolve({}),
36
+ hydrate: () => {},
37
+ scanAccounts,
38
+ };
39
+
40
+ const signOperation = buildSignOperation(signerContext);
41
+ const sync = makeSync({ getAccountShape });
42
+ // we want one method per file
43
+ const accountBridge: AccountBridge<Transaction> = {
44
+ broadcast,
45
+ createTransaction,
46
+ updateTransaction,
47
+ // NOTE: use updateTransaction: defaultUpdateTransaction<Transaction>,
48
+ // if you don't need to update the transaction patch object
49
+ prepareTransaction,
50
+ getTransactionStatus,
51
+ estimateMaxSpendable,
52
+ sync,
53
+ receive,
54
+ signOperation,
55
+ signRawOperation: () => {
56
+ throw new Error("signRawOperation is not supported");
57
+ },
58
+ getSerializedAddressParameters,
59
+ };
60
+
61
+ return {
62
+ currencyBridge,
63
+ accountBridge,
64
+ };
65
+ }
@@ -0,0 +1,29 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import { craftTransaction, estimateFees } from "../common-logic";
4
+ import { getNextSequence } from "../network/node";
5
+ import { Transaction } from "../types";
6
+ import { prepareTransaction } from "./prepareTransaction";
7
+
8
+ jest.mock("../network/node");
9
+ jest.mock("../common-logic");
10
+
11
+ describe("prepareTransaction", () => {
12
+ let estimateFeesSpy: jest.SpyInstance;
13
+ let getNextSequenceSpy: jest.SpyInstance;
14
+ let craftTransactionSpy: jest.SpyInstance;
15
+ beforeEach(() => {
16
+ getNextSequenceSpy = jest.spyOn({ getNextSequence }, "getNextSequence");
17
+ estimateFeesSpy = jest.spyOn({ estimateFees }, "estimateFees");
18
+ craftTransactionSpy = jest.spyOn({ craftTransaction }, "craftTransaction");
19
+ craftTransactionSpy.mockReturnValue({ serializedTransaction: "serialized" });
20
+ });
21
+
22
+ it("should update fee field if it's different", async () => {
23
+ getNextSequenceSpy.mockResolvedValue(42);
24
+ const oldTx = { fee: new BigNumber(0) };
25
+ estimateFeesSpy.mockResolvedValue(BigInt(1));
26
+ const newTx = await prepareTransaction({} as Account, oldTx as Transaction);
27
+ expect(newTx.fee).toEqual(new BigNumber(1));
28
+ });
29
+ });
@@ -0,0 +1,25 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import BigNumber from "bignumber.js";
3
+ import { Transaction } from "../types";
4
+ import { craftTransaction, estimateFees } from "../common-logic";
5
+ import { getNextSequence } from "../network/node";
6
+
7
+ export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"] = async (
8
+ account,
9
+ transaction,
10
+ ) => {
11
+ const seq = await getNextSequence(account.freshAddress);
12
+
13
+ const craftedTransaction = await craftTransaction(
14
+ { address: account.freshAddress, nextSequenceNumber: seq },
15
+ { amount: transaction.amount, recipient: transaction.recipient },
16
+ );
17
+
18
+ const fee = await estimateFees(craftedTransaction.serializedTransaction);
19
+
20
+ if (transaction.fee !== new BigNumber(fee.toString())) {
21
+ return { ...transaction, fee: new BigNumber(fee.toString()) };
22
+ }
23
+
24
+ return transaction;
25
+ };
@@ -0,0 +1,94 @@
1
+ import { Observable } from "rxjs";
2
+ import { FeeNotLoaded } from "@ledgerhq/errors";
3
+ import { AccountBridge, Operation } from "@ledgerhq/types-live";
4
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
5
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
+ import BigNumber from "bignumber.js";
7
+ import { combine, craftTransaction, getNextValidSequence } from "../common-logic";
8
+ import { Transaction, ConcordiumSigner, ConcordiumNativeTransaction } from "../types";
9
+
10
+ export const buildSignOperation =
11
+ (signerContext: SignerContext<ConcordiumSigner>): AccountBridge<Transaction>["signOperation"] =>
12
+ ({ account, deviceId, transaction }) =>
13
+ new Observable(o => {
14
+ async function main() {
15
+ const { fee } = transaction;
16
+ if (!fee) throw new FeeNotLoaded();
17
+
18
+ try {
19
+ // o observables allows to define steps of the signing process with the device
20
+ o.next({
21
+ type: "device-signature-requested",
22
+ });
23
+
24
+ const nextSequenceNumber = await getNextValidSequence(account.freshAddress);
25
+
26
+ const signature = await signerContext(deviceId, async signer => {
27
+ const { freshAddressPath: derivationPath } = account;
28
+ const { publicKey } = await signer.getAddress(derivationPath);
29
+
30
+ const { nativeTransaction, serializedTransaction } = await craftTransaction(
31
+ {
32
+ address: account.freshAddress,
33
+ publicKey,
34
+ },
35
+ {
36
+ recipient: transaction.recipient,
37
+ amount: transaction.amount,
38
+ fee: fee,
39
+ },
40
+ );
41
+
42
+ const transactionSignature = await signer.signTransaction(
43
+ derivationPath,
44
+ serializedTransaction,
45
+ );
46
+
47
+ return combine(serializedTransaction, transactionSignature, publicKey);
48
+ });
49
+
50
+ o.next({
51
+ type: "device-signature-granted",
52
+ });
53
+
54
+ // We create an optimistic operation here, the framework will then replace this transaction with the one returned by the indexer
55
+ const hash = "";
56
+ const operation: Operation = {
57
+ id: encodeOperationId(account.id, hash, "OUT"),
58
+ hash,
59
+ accountId: account.id,
60
+ type: "OUT",
61
+ value: transaction.amount,
62
+ fee,
63
+ blockHash: null,
64
+ blockHeight: null,
65
+ senders: [account.freshAddress],
66
+ recipients: [transaction.recipient],
67
+ date: new Date(),
68
+ transactionSequenceNumber: new BigNumber(nextSequenceNumber),
69
+ extra: {},
70
+ };
71
+
72
+ o.next({
73
+ type: "signed",
74
+ signedOperation: {
75
+ operation,
76
+ signature,
77
+ },
78
+ });
79
+ } catch (e) {
80
+ if (e instanceof Error) {
81
+ throw new Error(
82
+ (e as Error & { data?: { resultMessage?: string } })?.data?.resultMessage,
83
+ );
84
+ }
85
+
86
+ throw e;
87
+ }
88
+ }
89
+
90
+ main().then(
91
+ () => o.complete(),
92
+ e => o.error(e),
93
+ );
94
+ });