@ledgerhq/coin-cardano 0.1.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 (377) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +35 -0
  4. package/CHANGELOG.md +19 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/account.d.ts +7 -0
  8. package/lib/account.d.ts.map +1 -0
  9. package/lib/account.js +41 -0
  10. package/lib/account.js.map +1 -0
  11. package/lib/address.unit.test.d.ts +2 -0
  12. package/lib/address.unit.test.d.ts.map +1 -0
  13. package/lib/address.unit.test.js +21 -0
  14. package/lib/address.unit.test.js.map +1 -0
  15. package/lib/api/api-types.d.ts +106 -0
  16. package/lib/api/api-types.d.ts.map +1 -0
  17. package/lib/api/api-types.js +9 -0
  18. package/lib/api/api-types.js.map +1 -0
  19. package/lib/api/getDelegationInfo.d.ts +4 -0
  20. package/lib/api/getDelegationInfo.d.ts.map +1 -0
  21. package/lib/api/getDelegationInfo.js +48 -0
  22. package/lib/api/getDelegationInfo.js.map +1 -0
  23. package/lib/api/getNetworkInfo.d.ts +5 -0
  24. package/lib/api/getNetworkInfo.d.ts.map +1 -0
  25. package/lib/api/getNetworkInfo.js +46 -0
  26. package/lib/api/getNetworkInfo.js.map +1 -0
  27. package/lib/api/getPools.d.ts +5 -0
  28. package/lib/api/getPools.d.ts.map +1 -0
  29. package/lib/api/getPools.js +45 -0
  30. package/lib/api/getPools.js.map +1 -0
  31. package/lib/api/getTransactions.d.ts +10 -0
  32. package/lib/api/getTransactions.d.ts.map +1 -0
  33. package/lib/api/getTransactions.js +139 -0
  34. package/lib/api/getTransactions.js.map +1 -0
  35. package/lib/api/submitTransaction.d.ts +7 -0
  36. package/lib/api/submitTransaction.d.ts.map +1 -0
  37. package/lib/api/submitTransaction.js +34 -0
  38. package/lib/api/submitTransaction.js.map +1 -0
  39. package/lib/bridge/index.d.ts +11 -0
  40. package/lib/bridge/index.d.ts.map +1 -0
  41. package/lib/bridge/index.js +70 -0
  42. package/lib/bridge/index.js.map +1 -0
  43. package/lib/bridge.integration.test.d.ts +4 -0
  44. package/lib/bridge.integration.test.d.ts.map +1 -0
  45. package/lib/bridge.integration.test.js +113 -0
  46. package/lib/bridge.integration.test.js.map +1 -0
  47. package/lib/broadcast.d.ts +8 -0
  48. package/lib/broadcast.d.ts.map +1 -0
  49. package/lib/broadcast.js +28 -0
  50. package/lib/broadcast.js.map +1 -0
  51. package/lib/buildOptimisticOperation.d.ts +4 -0
  52. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  53. package/lib/buildOptimisticOperation.js +125 -0
  54. package/lib/buildOptimisticOperation.js.map +1 -0
  55. package/lib/buildSubAccounts.d.ts +26 -0
  56. package/lib/buildSubAccounts.d.ts.map +1 -0
  57. package/lib/buildSubAccounts.js +124 -0
  58. package/lib/buildSubAccounts.js.map +1 -0
  59. package/lib/buildTransaction.d.ts +11 -0
  60. package/lib/buildTransaction.d.ts.map +1 -0
  61. package/lib/buildTransaction.js +342 -0
  62. package/lib/buildTransaction.js.map +1 -0
  63. package/lib/cli-transaction.d.ts +18 -0
  64. package/lib/cli-transaction.d.ts.map +1 -0
  65. package/lib/cli-transaction.js +66 -0
  66. package/lib/cli-transaction.js.map +1 -0
  67. package/lib/constants.d.ts +8 -0
  68. package/lib/constants.d.ts.map +1 -0
  69. package/lib/constants.js +12 -0
  70. package/lib/constants.js.map +1 -0
  71. package/lib/createTransaction.d.ts +9 -0
  72. package/lib/createTransaction.d.ts.map +1 -0
  73. package/lib/createTransaction.js +23 -0
  74. package/lib/createTransaction.js.map +1 -0
  75. package/lib/datasets/rawAccount.1.d.ts +3 -0
  76. package/lib/datasets/rawAccount.1.d.ts.map +1 -0
  77. package/lib/datasets/rawAccount.1.js +20 -0
  78. package/lib/datasets/rawAccount.1.js.map +1 -0
  79. package/lib/datasets/scanAccounts.d.ts +5 -0
  80. package/lib/datasets/scanAccounts.d.ts.map +1 -0
  81. package/lib/datasets/scanAccounts.js +27 -0
  82. package/lib/datasets/scanAccounts.js.map +1 -0
  83. package/lib/deviceTransactionConfig.d.ts +11 -0
  84. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  85. package/lib/deviceTransactionConfig.js +106 -0
  86. package/lib/deviceTransactionConfig.js.map +1 -0
  87. package/lib/errors.d.ts +22 -0
  88. package/lib/errors.d.ts.map +1 -0
  89. package/lib/errors.js +18 -0
  90. package/lib/errors.js.map +1 -0
  91. package/lib/estimateMaxSpendable.d.ts +9 -0
  92. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  93. package/lib/estimateMaxSpendable.js +53 -0
  94. package/lib/estimateMaxSpendable.js.map +1 -0
  95. package/lib/getTransactionStatus.d.ts +4 -0
  96. package/lib/getTransactionStatus.d.ts.map +1 -0
  97. package/lib/getTransactionStatus.js +214 -0
  98. package/lib/getTransactionStatus.js.map +1 -0
  99. package/lib/getTransactionStatus.unit.test.d.ts +2 -0
  100. package/lib/getTransactionStatus.unit.test.d.ts.map +1 -0
  101. package/lib/getTransactionStatus.unit.test.js +54 -0
  102. package/lib/getTransactionStatus.unit.test.js.map +1 -0
  103. package/lib/hw-getAddress.d.ts +6 -0
  104. package/lib/hw-getAddress.d.ts.map +1 -0
  105. package/lib/hw-getAddress.js +37 -0
  106. package/lib/hw-getAddress.js.map +1 -0
  107. package/lib/logic.d.ts +88 -0
  108. package/lib/logic.d.ts.map +1 -0
  109. package/lib/logic.js +264 -0
  110. package/lib/logic.js.map +1 -0
  111. package/lib/logic.unit.test.d.ts +2 -0
  112. package/lib/logic.unit.test.d.ts.map +1 -0
  113. package/lib/logic.unit.test.js +40 -0
  114. package/lib/logic.unit.test.js.map +1 -0
  115. package/lib/networks.d.ts +3 -0
  116. package/lib/networks.d.ts.map +1 -0
  117. package/lib/networks.js +36 -0
  118. package/lib/networks.js.map +1 -0
  119. package/lib/postSyncPatch.d.ts +6 -0
  120. package/lib/postSyncPatch.d.ts.map +1 -0
  121. package/lib/postSyncPatch.js +35 -0
  122. package/lib/postSyncPatch.js.map +1 -0
  123. package/lib/prepareTransaction.d.ts +10 -0
  124. package/lib/prepareTransaction.d.ts.map +1 -0
  125. package/lib/prepareTransaction.js +44 -0
  126. package/lib/prepareTransaction.js.map +1 -0
  127. package/lib/serialization.d.ts +7 -0
  128. package/lib/serialization.d.ts.map +1 -0
  129. package/lib/serialization.js +146 -0
  130. package/lib/serialization.js.map +1 -0
  131. package/lib/signOperation.d.ts +9 -0
  132. package/lib/signOperation.d.ts.map +1 -0
  133. package/lib/signOperation.js +71 -0
  134. package/lib/signOperation.js.map +1 -0
  135. package/lib/signer.d.ts +92 -0
  136. package/lib/signer.d.ts.map +1 -0
  137. package/lib/signer.js +3 -0
  138. package/lib/signer.js.map +1 -0
  139. package/lib/specs.d.ts +7 -0
  140. package/lib/specs.d.ts.map +1 -0
  141. package/lib/specs.js +218 -0
  142. package/lib/specs.js.map +1 -0
  143. package/lib/speculos-deviceActions.d.ts +4 -0
  144. package/lib/speculos-deviceActions.d.ts.map +1 -0
  145. package/lib/speculos-deviceActions.js +128 -0
  146. package/lib/speculos-deviceActions.js.map +1 -0
  147. package/lib/synchronisation.d.ts +6 -0
  148. package/lib/synchronisation.d.ts.map +1 -0
  149. package/lib/synchronisation.js +237 -0
  150. package/lib/synchronisation.js.map +1 -0
  151. package/lib/synchronisation.unit.test.d.ts +2 -0
  152. package/lib/synchronisation.unit.test.d.ts.map +1 -0
  153. package/lib/synchronisation.unit.test.js +129 -0
  154. package/lib/synchronisation.unit.test.js.map +1 -0
  155. package/lib/transaction.d.ts +15 -0
  156. package/lib/transaction.d.ts.map +1 -0
  157. package/lib/transaction.js +43 -0
  158. package/lib/transaction.js.map +1 -0
  159. package/lib/types.d.ts +188 -0
  160. package/lib/types.d.ts.map +1 -0
  161. package/lib/types.js +18 -0
  162. package/lib/types.js.map +1 -0
  163. package/lib/typhonSerializer.d.ts +17 -0
  164. package/lib/typhonSerializer.d.ts.map +1 -0
  165. package/lib/typhonSerializer.js +213 -0
  166. package/lib/typhonSerializer.js.map +1 -0
  167. package/lib/utils.d.ts +2 -0
  168. package/lib/utils.d.ts.map +1 -0
  169. package/lib/utils.js +8 -0
  170. package/lib/utils.js.map +1 -0
  171. package/lib-es/account.d.ts +7 -0
  172. package/lib-es/account.d.ts.map +1 -0
  173. package/lib-es/account.js +34 -0
  174. package/lib-es/account.js.map +1 -0
  175. package/lib-es/address.unit.test.d.ts +2 -0
  176. package/lib-es/address.unit.test.d.ts.map +1 -0
  177. package/lib-es/address.unit.test.js +19 -0
  178. package/lib-es/address.unit.test.js.map +1 -0
  179. package/lib-es/api/api-types.d.ts +106 -0
  180. package/lib-es/api/api-types.d.ts.map +1 -0
  181. package/lib-es/api/api-types.js +6 -0
  182. package/lib-es/api/api-types.js.map +1 -0
  183. package/lib-es/api/getDelegationInfo.d.ts +4 -0
  184. package/lib-es/api/getDelegationInfo.d.ts.map +1 -0
  185. package/lib-es/api/getDelegationInfo.js +41 -0
  186. package/lib-es/api/getDelegationInfo.js.map +1 -0
  187. package/lib-es/api/getNetworkInfo.d.ts +5 -0
  188. package/lib-es/api/getNetworkInfo.d.ts.map +1 -0
  189. package/lib-es/api/getNetworkInfo.js +39 -0
  190. package/lib-es/api/getNetworkInfo.js.map +1 -0
  191. package/lib-es/api/getPools.d.ts +5 -0
  192. package/lib-es/api/getPools.d.ts.map +1 -0
  193. package/lib-es/api/getPools.js +37 -0
  194. package/lib-es/api/getPools.js.map +1 -0
  195. package/lib-es/api/getTransactions.d.ts +10 -0
  196. package/lib-es/api/getTransactions.d.ts.map +1 -0
  197. package/lib-es/api/getTransactions.js +132 -0
  198. package/lib-es/api/getTransactions.js.map +1 -0
  199. package/lib-es/api/submitTransaction.d.ts +7 -0
  200. package/lib-es/api/submitTransaction.d.ts.map +1 -0
  201. package/lib-es/api/submitTransaction.js +27 -0
  202. package/lib-es/api/submitTransaction.js.map +1 -0
  203. package/lib-es/bridge/index.d.ts +11 -0
  204. package/lib-es/bridge/index.d.ts.map +1 -0
  205. package/lib-es/bridge/index.js +61 -0
  206. package/lib-es/bridge/index.js.map +1 -0
  207. package/lib-es/bridge.integration.test.d.ts +4 -0
  208. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  209. package/lib-es/bridge.integration.test.js +107 -0
  210. package/lib-es/bridge.integration.test.js.map +1 -0
  211. package/lib-es/broadcast.d.ts +8 -0
  212. package/lib-es/broadcast.d.ts.map +1 -0
  213. package/lib-es/broadcast.js +24 -0
  214. package/lib-es/broadcast.js.map +1 -0
  215. package/lib-es/buildOptimisticOperation.d.ts +4 -0
  216. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  217. package/lib-es/buildOptimisticOperation.js +118 -0
  218. package/lib-es/buildOptimisticOperation.js.map +1 -0
  219. package/lib-es/buildSubAccounts.d.ts +26 -0
  220. package/lib-es/buildSubAccounts.d.ts.map +1 -0
  221. package/lib-es/buildSubAccounts.js +114 -0
  222. package/lib-es/buildSubAccounts.js.map +1 -0
  223. package/lib-es/buildTransaction.d.ts +11 -0
  224. package/lib-es/buildTransaction.d.ts.map +1 -0
  225. package/lib-es/buildTransaction.js +335 -0
  226. package/lib-es/buildTransaction.js.map +1 -0
  227. package/lib-es/cli-transaction.d.ts +18 -0
  228. package/lib-es/cli-transaction.d.ts.map +1 -0
  229. package/lib-es/cli-transaction.js +60 -0
  230. package/lib-es/cli-transaction.js.map +1 -0
  231. package/lib-es/constants.d.ts +8 -0
  232. package/lib-es/constants.d.ts.map +1 -0
  233. package/lib-es/constants.js +9 -0
  234. package/lib-es/constants.js.map +1 -0
  235. package/lib-es/createTransaction.d.ts +9 -0
  236. package/lib-es/createTransaction.d.ts.map +1 -0
  237. package/lib-es/createTransaction.js +16 -0
  238. package/lib-es/createTransaction.js.map +1 -0
  239. package/lib-es/datasets/rawAccount.1.d.ts +3 -0
  240. package/lib-es/datasets/rawAccount.1.d.ts.map +1 -0
  241. package/lib-es/datasets/rawAccount.1.js +17 -0
  242. package/lib-es/datasets/rawAccount.1.js.map +1 -0
  243. package/lib-es/datasets/scanAccounts.d.ts +5 -0
  244. package/lib-es/datasets/scanAccounts.d.ts.map +1 -0
  245. package/lib-es/datasets/scanAccounts.js +24 -0
  246. package/lib-es/datasets/scanAccounts.js.map +1 -0
  247. package/lib-es/deviceTransactionConfig.d.ts +11 -0
  248. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  249. package/lib-es/deviceTransactionConfig.js +101 -0
  250. package/lib-es/deviceTransactionConfig.js.map +1 -0
  251. package/lib-es/errors.d.ts +22 -0
  252. package/lib-es/errors.d.ts.map +1 -0
  253. package/lib-es/errors.js +15 -0
  254. package/lib-es/errors.js.map +1 -0
  255. package/lib-es/estimateMaxSpendable.d.ts +9 -0
  256. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  257. package/lib-es/estimateMaxSpendable.js +49 -0
  258. package/lib-es/estimateMaxSpendable.js.map +1 -0
  259. package/lib-es/getTransactionStatus.d.ts +4 -0
  260. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  261. package/lib-es/getTransactionStatus.js +210 -0
  262. package/lib-es/getTransactionStatus.js.map +1 -0
  263. package/lib-es/getTransactionStatus.unit.test.d.ts +2 -0
  264. package/lib-es/getTransactionStatus.unit.test.d.ts.map +1 -0
  265. package/lib-es/getTransactionStatus.unit.test.js +49 -0
  266. package/lib-es/getTransactionStatus.unit.test.js.map +1 -0
  267. package/lib-es/hw-getAddress.d.ts +6 -0
  268. package/lib-es/hw-getAddress.d.ts.map +1 -0
  269. package/lib-es/hw-getAddress.js +35 -0
  270. package/lib-es/hw-getAddress.js.map +1 -0
  271. package/lib-es/logic.d.ts +88 -0
  272. package/lib-es/logic.d.ts.map +1 -0
  273. package/lib-es/logic.js +236 -0
  274. package/lib-es/logic.js.map +1 -0
  275. package/lib-es/logic.unit.test.d.ts +2 -0
  276. package/lib-es/logic.unit.test.d.ts.map +1 -0
  277. package/lib-es/logic.unit.test.js +35 -0
  278. package/lib-es/logic.unit.test.js.map +1 -0
  279. package/lib-es/networks.d.ts +3 -0
  280. package/lib-es/networks.d.ts.map +1 -0
  281. package/lib-es/networks.js +32 -0
  282. package/lib-es/networks.js.map +1 -0
  283. package/lib-es/postSyncPatch.d.ts +6 -0
  284. package/lib-es/postSyncPatch.d.ts.map +1 -0
  285. package/lib-es/postSyncPatch.js +31 -0
  286. package/lib-es/postSyncPatch.js.map +1 -0
  287. package/lib-es/prepareTransaction.d.ts +10 -0
  288. package/lib-es/prepareTransaction.d.ts.map +1 -0
  289. package/lib-es/prepareTransaction.js +40 -0
  290. package/lib-es/prepareTransaction.js.map +1 -0
  291. package/lib-es/serialization.d.ts +7 -0
  292. package/lib-es/serialization.d.ts.map +1 -0
  293. package/lib-es/serialization.js +139 -0
  294. package/lib-es/serialization.js.map +1 -0
  295. package/lib-es/signOperation.d.ts +9 -0
  296. package/lib-es/signOperation.d.ts.map +1 -0
  297. package/lib-es/signOperation.js +64 -0
  298. package/lib-es/signOperation.js.map +1 -0
  299. package/lib-es/signer.d.ts +92 -0
  300. package/lib-es/signer.d.ts.map +1 -0
  301. package/lib-es/signer.js +2 -0
  302. package/lib-es/signer.js.map +1 -0
  303. package/lib-es/specs.d.ts +7 -0
  304. package/lib-es/specs.d.ts.map +1 -0
  305. package/lib-es/specs.js +213 -0
  306. package/lib-es/specs.js.map +1 -0
  307. package/lib-es/speculos-deviceActions.d.ts +4 -0
  308. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  309. package/lib-es/speculos-deviceActions.js +125 -0
  310. package/lib-es/speculos-deviceActions.js.map +1 -0
  311. package/lib-es/synchronisation.d.ts +6 -0
  312. package/lib-es/synchronisation.d.ts.map +1 -0
  313. package/lib-es/synchronisation.js +230 -0
  314. package/lib-es/synchronisation.js.map +1 -0
  315. package/lib-es/synchronisation.unit.test.d.ts +2 -0
  316. package/lib-es/synchronisation.unit.test.d.ts.map +1 -0
  317. package/lib-es/synchronisation.unit.test.js +124 -0
  318. package/lib-es/synchronisation.unit.test.js.map +1 -0
  319. package/lib-es/transaction.d.ts +15 -0
  320. package/lib-es/transaction.d.ts.map +1 -0
  321. package/lib-es/transaction.js +37 -0
  322. package/lib-es/transaction.js.map +1 -0
  323. package/lib-es/types.d.ts +188 -0
  324. package/lib-es/types.d.ts.map +1 -0
  325. package/lib-es/types.js +15 -0
  326. package/lib-es/types.js.map +1 -0
  327. package/lib-es/typhonSerializer.d.ts +17 -0
  328. package/lib-es/typhonSerializer.d.ts.map +1 -0
  329. package/lib-es/typhonSerializer.js +207 -0
  330. package/lib-es/typhonSerializer.js.map +1 -0
  331. package/lib-es/utils.d.ts +2 -0
  332. package/lib-es/utils.d.ts.map +1 -0
  333. package/lib-es/utils.js +5 -0
  334. package/lib-es/utils.js.map +1 -0
  335. package/package.json +91 -0
  336. package/src/account.ts +39 -0
  337. package/src/address.unit.test.ts +32 -0
  338. package/src/api/api-types.ts +115 -0
  339. package/src/api/getDelegationInfo.ts +39 -0
  340. package/src/api/getNetworkInfo.ts +34 -0
  341. package/src/api/getPools.ts +35 -0
  342. package/src/api/getTransactions.ts +218 -0
  343. package/src/api/submitTransaction.ts +24 -0
  344. package/src/bridge/index.ts +69 -0
  345. package/src/bridge.integration.test.ts +113 -0
  346. package/src/broadcast.ts +21 -0
  347. package/src/buildOptimisticOperation.ts +181 -0
  348. package/src/buildSubAccounts.ts +170 -0
  349. package/src/buildTransaction.ts +435 -0
  350. package/src/cli-transaction.ts +82 -0
  351. package/src/constants.ts +10 -0
  352. package/src/createTransaction.ts +18 -0
  353. package/src/datasets/rawAccount.1.ts +19 -0
  354. package/src/datasets/scanAccounts.ts +23 -0
  355. package/src/deviceTransactionConfig.ts +128 -0
  356. package/src/errors.ts +18 -0
  357. package/src/estimateMaxSpendable.ts +61 -0
  358. package/src/getTransactionStatus.ts +251 -0
  359. package/src/getTransactionStatus.unit.test.ts +45 -0
  360. package/src/hw-getAddress.ts +37 -0
  361. package/src/logic.ts +330 -0
  362. package/src/logic.unit.test.ts +39 -0
  363. package/src/networks.ts +33 -0
  364. package/src/postSyncPatch.ts +42 -0
  365. package/src/prepareTransaction.ts +41 -0
  366. package/src/serialization.ts +219 -0
  367. package/src/signOperation.ts +82 -0
  368. package/src/signer.ts +98 -0
  369. package/src/specs.ts +253 -0
  370. package/src/speculos-deviceActions.ts +132 -0
  371. package/src/synchronisation.ts +347 -0
  372. package/src/synchronisation.unit.test.ts +137 -0
  373. package/src/transaction.ts +66 -0
  374. package/src/types.ts +227 -0
  375. package/src/typhonSerializer.ts +259 -0
  376. package/src/utils.ts +4 -0
  377. package/tsconfig.json +12 -0
package/src/types.ts ADDED
@@ -0,0 +1,227 @@
1
+ import type { BigNumber } from "bignumber.js";
2
+ import { types as TyphonTypes } from "@stricahq/typhonjs";
3
+ import type {
4
+ Account,
5
+ AccountRaw,
6
+ Operation,
7
+ OperationRaw,
8
+ TransactionCommon,
9
+ TransactionCommonRaw,
10
+ TransactionStatusCommon,
11
+ TransactionStatusCommonRaw,
12
+ } from "@ledgerhq/types-live";
13
+
14
+ export enum PaymentChain {
15
+ external = 0,
16
+ internal = 1,
17
+ }
18
+
19
+ export enum StakeChain {
20
+ stake = 2,
21
+ }
22
+
23
+ export enum NetworkId {
24
+ testnet = 0,
25
+ mainnet = 1,
26
+ }
27
+
28
+ export type BipPath = {
29
+ purpose: number;
30
+ coin: number;
31
+ account: number;
32
+ chain: PaymentChain | StakeChain;
33
+ index: number;
34
+ };
35
+
36
+ export type BipPathRaw = {
37
+ purpose: number;
38
+ coin: number;
39
+ account: number;
40
+ chain: PaymentChain | StakeChain;
41
+ index: number;
42
+ };
43
+
44
+ export type Token = {
45
+ assetName: string;
46
+ policyId: string;
47
+ amount: BigNumber;
48
+ };
49
+
50
+ export type TokenRaw = {
51
+ assetName: string;
52
+ policyId: string;
53
+ amount: string;
54
+ };
55
+
56
+ export type PaymentKeyPath = {
57
+ key: string;
58
+ path: BipPath;
59
+ };
60
+
61
+ export type PaymentCredential = {
62
+ isUsed: boolean;
63
+ key: string;
64
+ path: BipPath;
65
+ };
66
+
67
+ export type PaymentCredentialRaw = {
68
+ isUsed: boolean;
69
+ key: string;
70
+ path: BipPathRaw;
71
+ };
72
+
73
+ export type StakeCredential = {
74
+ key: string;
75
+ path: BipPath;
76
+ };
77
+
78
+ export type CardanoOutput = {
79
+ hash: string;
80
+ index: number;
81
+ address: string;
82
+ amount: BigNumber;
83
+ tokens: Array<Token>;
84
+ paymentCredential: {
85
+ key: string;
86
+ path: BipPath;
87
+ };
88
+ };
89
+
90
+ export type CardanoOutputRaw = {
91
+ hash: string;
92
+ index: number;
93
+ address: string;
94
+ amount: string;
95
+ tokens: Array<TokenRaw>;
96
+ paymentCredential: {
97
+ key: string;
98
+ path: BipPath;
99
+ };
100
+ };
101
+
102
+ export type ProtocolParams = {
103
+ minFeeA: string;
104
+ minFeeB: string;
105
+ stakeKeyDeposit: string;
106
+ lovelacePerUtxoWord: string;
107
+ collateralPercent: string;
108
+ priceSteps: string;
109
+ priceMem: string;
110
+ languageView: TyphonTypes.LanguageView;
111
+ };
112
+
113
+ export type ProtocolParamsRaw = {
114
+ minFeeA: string;
115
+ minFeeB: string;
116
+ stakeKeyDeposit: string;
117
+ lovelacePerUtxoWord: string;
118
+ collateralPercent: string;
119
+ priceSteps: string;
120
+ priceMem: string;
121
+ // TyphonTypes.LanguageView is already a raw type
122
+ languageView: TyphonTypes.LanguageView;
123
+ };
124
+
125
+ export type CardanoDelegation = {
126
+ status: boolean;
127
+ poolId: string;
128
+ ticker: string;
129
+ name: string;
130
+ rewards: BigNumber;
131
+ };
132
+
133
+ export type CardanoDelegationRaw = {
134
+ status: boolean;
135
+ poolId: string;
136
+ ticker: string;
137
+ name: string;
138
+ rewards: string;
139
+ };
140
+
141
+ /**
142
+ * Cardano account resources
143
+ */
144
+ export type CardanoResources = {
145
+ externalCredentials: Array<PaymentCredential>;
146
+ internalCredentials: Array<PaymentCredential>;
147
+ delegation: CardanoDelegation | undefined;
148
+ utxos: Array<CardanoOutput>;
149
+ protocolParams: ProtocolParams;
150
+ };
151
+
152
+ /**
153
+ * Cardano account resources from raw JSON
154
+ */
155
+ export type CardanoResourcesRaw = {
156
+ externalCredentials: Array<PaymentCredentialRaw>;
157
+ internalCredentials: Array<PaymentCredentialRaw>;
158
+ delegation: CardanoDelegationRaw | undefined;
159
+ utxos: Array<CardanoOutputRaw>;
160
+ protocolParams: ProtocolParamsRaw;
161
+ };
162
+
163
+ export type CardanoOperationMode = "send" | "delegate" | "undelegate";
164
+
165
+ /**
166
+ * Cardano transaction
167
+ */
168
+ export type Transaction = TransactionCommon & {
169
+ mode: CardanoOperationMode;
170
+ family: "cardano";
171
+ fees?: BigNumber;
172
+ memo?: string;
173
+ poolId: string | undefined;
174
+ // add here all transaction-specific fields if you implement other modes than "send"
175
+ };
176
+
177
+ /**
178
+ * Cardano transaction from a raw JSON
179
+ */
180
+ export type TransactionRaw = TransactionCommonRaw & {
181
+ family: "cardano";
182
+ mode: CardanoOperationMode;
183
+ fees?: string;
184
+ memo?: string;
185
+ poolId: string | undefined;
186
+ // also the transaction fields as raw JSON data
187
+ };
188
+
189
+ export type CardanoLikeNetworkParameters = {
190
+ identifier: string;
191
+ networkId: number;
192
+ chainStartTime: number;
193
+ byronSlotDuration: number;
194
+ byronSlotsPerEpoch: number;
195
+ shelleyStartEpoch: number;
196
+ shelleySlotDuration: number;
197
+ shelleySlotsPerEpoch: number;
198
+ addressPrefix: string;
199
+ poolIdPrefix: string;
200
+ };
201
+
202
+ /**
203
+ * Cardano currency data that will be preloaded.
204
+ */
205
+ export type CardanoPreloadData = {
206
+ protocolParams: ProtocolParams;
207
+ };
208
+
209
+ export type CardanoAccount = Account & { cardanoResources: CardanoResources };
210
+
211
+ export type CardanoAccountRaw = AccountRaw & {
212
+ cardanoResources: CardanoResourcesRaw;
213
+ };
214
+
215
+ export type TransactionStatus = TransactionStatusCommon;
216
+
217
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
218
+
219
+ export type CardanoOperation = Operation<CardanoOperationExtra>;
220
+ export type CardanoOperationRaw = OperationRaw<CardanoOperationExtra>;
221
+
222
+ export type CardanoOperationExtra = {
223
+ memo?: string;
224
+ deposit?: string;
225
+ refund?: string;
226
+ rewards?: string;
227
+ };
@@ -0,0 +1,259 @@
1
+ import {
2
+ types as TyphonTypes,
3
+ address as TyphonAddress,
4
+ Transaction as TyphonTransaction,
5
+ } from "@stricahq/typhonjs";
6
+ import groupBy from "lodash/groupBy";
7
+ import { getBipPathString } from "./logic";
8
+ import { CertificateType } from "@stricahq/typhonjs/dist/types";
9
+ import { SignerTxCertificate, SignerTxInput, SignerTxOutput, SignerTxWithdrawal } from "./signer";
10
+
11
+ /**
12
+ * Convert StricaTypes Transaction into a simpler types.
13
+ * We are keeping the minimal necessary for a signer.
14
+ */
15
+ export default function (transaction: TyphonTransaction, accountIndex: number) {
16
+ const ledgerAppInputs = transaction.getInputs().map(prepareLedgerInput(accountIndex));
17
+ const ledgerAppOutputs = transaction.getOutputs().map(prepareLedgerOutput(accountIndex));
18
+ const ledgerCertificates = transaction.getCertificates().map(prepareCertificate);
19
+ const ledgerWithdrawals = transaction.getWithdrawals().map(prepareWithdrawal);
20
+ const auxiliaryDataHashHex = transaction.getAuxiliaryDataHashHex();
21
+
22
+ return {
23
+ inputs: ledgerAppInputs,
24
+ outputs: ledgerAppOutputs,
25
+ certificates: ledgerCertificates,
26
+ withdrawals: ledgerWithdrawals,
27
+ fee: transaction.getFee().toString(),
28
+ ttl: transaction.getTTL()?.toString(),
29
+ validityIntervalStart: null,
30
+ auxiliaryData: auxiliaryDataHashHex ?? null,
31
+ };
32
+ }
33
+
34
+ /**
35
+ * returns the formatted transactionInput for ledger cardano app
36
+ *
37
+ * @param {TyphonTypes.Input} input
38
+ * @param {number} accountIndex
39
+ * @returns {TxInput}
40
+ */
41
+ const prepareLedgerInput =
42
+ (accountIndex: number) =>
43
+ (input: TyphonTypes.Input): SignerTxInput => {
44
+ const paymentKeyPath =
45
+ input.address.paymentCredential.type === TyphonTypes.HashType.ADDRESS
46
+ ? input.address.paymentCredential.bipPath
47
+ : undefined;
48
+ return {
49
+ txHashHex: input.txId,
50
+ outputIndex: input.index,
51
+ path: paymentKeyPath
52
+ ? getBipPathString({
53
+ account: accountIndex,
54
+ chain: paymentKeyPath.chain,
55
+ index: paymentKeyPath.index,
56
+ })
57
+ : null,
58
+ };
59
+ };
60
+
61
+ /**
62
+ * returns the formatted transactionOutput for ledger cardano app
63
+ *
64
+ * @param output
65
+ * @param accountIndex
66
+ * @returns {TxOutput}
67
+ */
68
+ const prepareLedgerOutput =
69
+ (accountIndex: number) =>
70
+ (output: TyphonTypes.Output): SignerTxOutput => {
71
+ const isByronAddress = output.address instanceof TyphonAddress.ByronAddress;
72
+ let isDeviceOwnedAddress = false;
73
+
74
+ if (!isByronAddress) {
75
+ const address = output.address as TyphonTypes.ShelleyAddress;
76
+ isDeviceOwnedAddress =
77
+ address.paymentCredential &&
78
+ address.paymentCredential.type === TyphonTypes.HashType.ADDRESS &&
79
+ address.paymentCredential.bipPath !== undefined;
80
+ }
81
+
82
+ let destination;
83
+ if (isDeviceOwnedAddress) {
84
+ const address = output.address as TyphonAddress.BaseAddress;
85
+
86
+ const paymentKeyPath = (address.paymentCredential as TyphonTypes.HashCredential)
87
+ .bipPath as TyphonTypes.BipPath;
88
+ const stakingKeyPath = (address.stakeCredential as TyphonTypes.HashCredential)
89
+ .bipPath as TyphonTypes.BipPath;
90
+
91
+ const paymentKeyPathString = getBipPathString({
92
+ account: accountIndex,
93
+ chain: paymentKeyPath.chain,
94
+ index: paymentKeyPath.index,
95
+ });
96
+ const stakingKeyPathString = getBipPathString({
97
+ account: accountIndex,
98
+ chain: stakingKeyPath.chain,
99
+ index: stakingKeyPath.index,
100
+ });
101
+
102
+ destination = {
103
+ isDeviceOwnedAddress,
104
+ params: {
105
+ spendingPath: paymentKeyPathString,
106
+ stakingPath: stakingKeyPathString,
107
+ },
108
+ };
109
+ } else {
110
+ const address = output.address;
111
+ destination = {
112
+ isDeviceOwnedAddress,
113
+ params: {
114
+ addressHex: address.getHex(),
115
+ },
116
+ };
117
+ }
118
+
119
+ const tokenBundle = Object.values(groupBy(output.tokens, ({ policyId }) => policyId)).map(
120
+ tokens => ({
121
+ policyIdHex: tokens[0].policyId,
122
+ tokens: tokens.map(token => ({
123
+ assetNameHex: token.assetName,
124
+ amount: token.amount.toString(),
125
+ })),
126
+ }),
127
+ );
128
+
129
+ return {
130
+ amount: output.amount.toString(),
131
+ destination,
132
+ tokenBundle,
133
+ };
134
+ };
135
+
136
+ function prepareCertificate(cert: TyphonTypes.Certificate): SignerTxCertificate {
137
+ if (cert.certType === CertificateType.STAKE_REGISTRATION) {
138
+ return prepareStakeRegistrationCertificate(cert as TyphonTypes.StakeRegistrationCertificate);
139
+ } else if (cert.certType === CertificateType.STAKE_DELEGATION) {
140
+ return prepareStakeDelegationCertificate(cert as TyphonTypes.StakeDelegationCertificate);
141
+ } else if (cert.certType === CertificateType.STAKE_DE_REGISTRATION) {
142
+ return prepareStakeDeRegistrationCertificate(
143
+ cert as TyphonTypes.StakeDeRegistrationCertificate,
144
+ );
145
+ } else {
146
+ throw new Error("Invalid Certificate type");
147
+ }
148
+ }
149
+
150
+ function prepareStakeRegistrationCertificate(
151
+ certificate: TyphonTypes.StakeRegistrationCertificate,
152
+ ): {
153
+ type: "REGISTRATION";
154
+ params: {
155
+ stakeCredential: {
156
+ keyPath: string;
157
+ };
158
+ };
159
+ } {
160
+ if (
161
+ certificate.stakeCredential.type === TyphonTypes.HashType.ADDRESS &&
162
+ certificate.stakeCredential.bipPath
163
+ ) {
164
+ return {
165
+ type: "REGISTRATION",
166
+ params: {
167
+ stakeCredential: {
168
+ keyPath: getBipPathString({
169
+ account: certificate.stakeCredential.bipPath.account,
170
+ chain: certificate.stakeCredential.bipPath.chain,
171
+ index: certificate.stakeCredential.bipPath.index,
172
+ }),
173
+ },
174
+ },
175
+ };
176
+ } else {
177
+ throw new Error("Invalid stakeKey type");
178
+ }
179
+ }
180
+
181
+ function prepareStakeDelegationCertificate(certificate: TyphonTypes.StakeDelegationCertificate): {
182
+ type: "DELEGATION";
183
+ params: {
184
+ stakeCredential: {
185
+ keyPath: string;
186
+ };
187
+ poolKeyHashHex: string;
188
+ };
189
+ } {
190
+ if (
191
+ certificate.stakeCredential.type === TyphonTypes.HashType.ADDRESS &&
192
+ certificate.stakeCredential.bipPath
193
+ ) {
194
+ return {
195
+ type: "DELEGATION",
196
+ params: {
197
+ stakeCredential: {
198
+ keyPath: getBipPathString({
199
+ account: certificate.stakeCredential.bipPath.account,
200
+ chain: certificate.stakeCredential.bipPath.chain,
201
+ index: certificate.stakeCredential.bipPath.index,
202
+ }),
203
+ },
204
+ poolKeyHashHex: certificate.poolHash,
205
+ },
206
+ };
207
+ } else {
208
+ throw new Error("Invalid stakeKey type");
209
+ }
210
+ }
211
+
212
+ function prepareStakeDeRegistrationCertificate(certificate: TyphonTypes.Certificate): {
213
+ type: "DEREGISTRATION";
214
+ params: {
215
+ stakeCredential: {
216
+ keyPath: string;
217
+ };
218
+ };
219
+ } {
220
+ if (
221
+ certificate.stakeCredential.type === TyphonTypes.HashType.ADDRESS &&
222
+ certificate.stakeCredential.bipPath
223
+ ) {
224
+ return {
225
+ type: "DEREGISTRATION",
226
+ params: {
227
+ stakeCredential: {
228
+ keyPath: getBipPathString({
229
+ account: certificate.stakeCredential.bipPath.account,
230
+ chain: certificate.stakeCredential.bipPath.chain,
231
+ index: certificate.stakeCredential.bipPath.index,
232
+ }),
233
+ },
234
+ },
235
+ };
236
+ } else {
237
+ throw new Error("Invalid stakeKey type");
238
+ }
239
+ }
240
+
241
+ function prepareWithdrawal(withdrawal: TyphonTypes.Withdrawal): SignerTxWithdrawal {
242
+ if (
243
+ withdrawal.rewardAccount.stakeCredential.type === TyphonTypes.HashType.ADDRESS &&
244
+ withdrawal.rewardAccount.stakeCredential.bipPath
245
+ ) {
246
+ return {
247
+ stakeCredential: {
248
+ keyPath: getBipPathString({
249
+ account: withdrawal.rewardAccount.stakeCredential.bipPath.account,
250
+ chain: withdrawal.rewardAccount.stakeCredential.bipPath.chain,
251
+ index: withdrawal.rewardAccount.stakeCredential.bipPath.index,
252
+ }),
253
+ },
254
+ amount: withdrawal.amount.toString(),
255
+ };
256
+ } else {
257
+ throw new Error("Invalid stakeKey type");
258
+ }
259
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,4 @@
1
+ // the IDs of ledger stake pools to shows in lld and llm
2
+ export const LEDGER_POOL_IDS: Array<string> = [
3
+ "4a9c9902c9538da900b10b716d5d1b214487455fdb06028b32ffa180",
4
+ ];
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "module": "commonjs",
7
+ "downlevelIteration": true,
8
+ "lib": ["es2020", "dom"],
9
+ "outDir": "lib"
10
+ },
11
+ "include": ["src/**/*"]
12
+ }