@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
@@ -0,0 +1,82 @@
1
+ import { Observable } from "rxjs";
2
+ import { FeeNotLoaded } from "@ledgerhq/errors";
3
+ import { Bip32PublicKey } from "@stricahq/bip32ed25519";
4
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
5
+ import { AccountBridge, SignOperationEvent } from "@ledgerhq/types-live";
6
+ import { Transaction as TyphonTransaction, types as TyphonTypes } from "@stricahq/typhonjs";
7
+ import { buildOptimisticOperation } from "./buildOptimisticOperation";
8
+ import type { CardanoAccount, Transaction } from "./types";
9
+ import { getExtendedPublicKeyFromHex } from "./logic";
10
+ import { buildTransaction } from "./buildTransaction";
11
+ import { getNetworkParameters } from "./networks";
12
+ import { CardanoSigner, Witness } from "./signer";
13
+ import typhonSerializer from "./typhonSerializer";
14
+
15
+ /**
16
+ * Sign Transaction with Ledger hardware
17
+ */
18
+ export const buildSignOperation =
19
+ (
20
+ signerContext: SignerContext<CardanoSigner>,
21
+ ): AccountBridge<Transaction, CardanoAccount>["signOperation"] =>
22
+ ({ account, deviceId, transaction }): Observable<SignOperationEvent> =>
23
+ new Observable(o => {
24
+ async function main() {
25
+ o.next({ type: "device-signature-requested" });
26
+
27
+ if (!transaction.fees) {
28
+ throw new FeeNotLoaded();
29
+ }
30
+
31
+ const unsignedTransaction = await buildTransaction(account, transaction);
32
+ const signerTransaction = typhonSerializer(unsignedTransaction, account.index);
33
+
34
+ const networkParams = getNetworkParameters(account.currency.id);
35
+ const signedData = await signerContext(deviceId, signer =>
36
+ signer.sign({
37
+ transaction: signerTransaction,
38
+ networkParams,
39
+ }),
40
+ );
41
+
42
+ const accountPubKey = getExtendedPublicKeyFromHex(account.xpub as string);
43
+ const signed = signTx(unsignedTransaction, accountPubKey, signedData.witnesses);
44
+
45
+ o.next({ type: "device-signature-granted" });
46
+
47
+ const operation = buildOptimisticOperation(account, unsignedTransaction, transaction);
48
+
49
+ o.next({
50
+ type: "signed",
51
+ signedOperation: {
52
+ operation,
53
+ signature: signed.payload,
54
+ },
55
+ });
56
+ }
57
+ main().then(
58
+ () => o.complete(),
59
+ e => o.error(e),
60
+ );
61
+ });
62
+
63
+ /**
64
+ * Adds signatures to unsigned transaction
65
+ */
66
+ const signTx = (
67
+ unsignedTransaction: TyphonTransaction,
68
+ accountKey: Bip32PublicKey,
69
+ witnesses: Array<Witness>,
70
+ ) => {
71
+ witnesses.forEach(witness => {
72
+ const [, , , chainType, index] = witness.path;
73
+ const publicKey = accountKey.derive(chainType).derive(index).toPublicKey().toBytes();
74
+ const vKeyWitness: TyphonTypes.VKeyWitness = {
75
+ signature: Buffer.from(witness.witnessSignatureHex, "hex"),
76
+ publicKey: Buffer.from(publicKey),
77
+ };
78
+ unsignedTransaction.addWitness(vKeyWitness);
79
+ });
80
+
81
+ return unsignedTransaction.buildTransaction();
82
+ };
package/src/signer.ts ADDED
@@ -0,0 +1,98 @@
1
+ import { CardanoLikeNetworkParameters } from "./types";
2
+
3
+ export type CardanoAddress = {
4
+ addressHex: string;
5
+ };
6
+ // Coming from @cardano-foundation/ledgerjs-hw-app-cardano code (type SignedTransactionData)
7
+ type BIP32Path = Array<number>;
8
+ export type Witness = {
9
+ path: BIP32Path;
10
+ witnessSignatureHex: string;
11
+ };
12
+ export type CardanoSignature = {
13
+ txHashHex: string;
14
+ witnesses: Array<Witness>;
15
+ };
16
+ // Coming from @cardano-foundation/ledgerjs-hw-app-cardano code (type ExtendedPublicKey)
17
+ export type CardanoExtendedPublicKey = {
18
+ publicKeyHex: string;
19
+ chainCodeHex: string;
20
+ };
21
+ export type GetAddressRequest = {
22
+ path: string;
23
+ stakingPathString: string;
24
+ networkParams: CardanoLikeNetworkParameters;
25
+ verify?: boolean;
26
+ };
27
+
28
+ export type SignerTxInput = {
29
+ txHashHex: string;
30
+ outputIndex: number;
31
+ path: string | null;
32
+ };
33
+ export type SignerTxOutput = {
34
+ amount: string;
35
+ destination:
36
+ | {
37
+ isDeviceOwnedAddress: false;
38
+ params: {
39
+ addressHex: string;
40
+ };
41
+ }
42
+ | {
43
+ isDeviceOwnedAddress: true;
44
+ params: {
45
+ spendingPath: string;
46
+ stakingPath: string;
47
+ };
48
+ };
49
+ tokenBundle: Array<{
50
+ policyIdHex: string;
51
+ tokens: Array<{
52
+ assetNameHex: string;
53
+ amount: string;
54
+ }>;
55
+ }>;
56
+ };
57
+ export type SignerTxCertificate =
58
+ | {
59
+ type: "REGISTRATION" | "DEREGISTRATION";
60
+ params: {
61
+ stakeCredential: {
62
+ keyPath: string;
63
+ };
64
+ };
65
+ }
66
+ | {
67
+ type: "DELEGATION";
68
+ params: {
69
+ stakeCredential: {
70
+ keyPath: string;
71
+ };
72
+ poolKeyHashHex: string;
73
+ };
74
+ };
75
+ export type SignerTxWithdrawal = {
76
+ stakeCredential: {
77
+ keyPath: string;
78
+ };
79
+ amount: string;
80
+ };
81
+ export type SignerTransaction = {
82
+ inputs: Array<SignerTxInput>;
83
+ outputs: Array<SignerTxOutput>;
84
+ certificates: Array<SignerTxCertificate>;
85
+ withdrawals: Array<SignerTxWithdrawal>;
86
+ fee: string;
87
+ ttl?: string;
88
+ auxiliaryData: string | null;
89
+ };
90
+ export type CardanoSignRequest = {
91
+ transaction: SignerTransaction;
92
+ networkParams: CardanoLikeNetworkParameters;
93
+ };
94
+ export interface CardanoSigner {
95
+ getAddress(addressRequest: GetAddressRequest): Promise<CardanoAddress>;
96
+ getPublicKey(accountPath: string): Promise<CardanoExtendedPublicKey>;
97
+ sign(signRequest: CardanoSignRequest): Promise<CardanoSignature>;
98
+ }
package/src/specs.ts ADDED
@@ -0,0 +1,253 @@
1
+ import expect from "expect";
2
+ import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
3
+ import type { CardanoAccount, CardanoOperationExtra, CardanoResources, Transaction } from "./types";
4
+ import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
5
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
6
+ import { DeviceModelId } from "@ledgerhq/devices";
7
+ import BigNumber from "bignumber.js";
8
+ import invariant from "invariant";
9
+ import { utils as TyphonUtils } from "@stricahq/typhonjs";
10
+ import { mergeTokens } from "./logic";
11
+ import { formatCurrencyUnit, parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
12
+ import { SubAccount } from "@ledgerhq/types-live";
13
+ import { acceptTransaction } from "./speculos-deviceActions";
14
+
15
+ const maxAccounts = 5;
16
+ const currency = getCryptoCurrencyById("cardano");
17
+ const minBalanceRequired = parseCurrencyUnit(currency.units[0], "2.2");
18
+ const minBalanceRequiredForMaxSend = parseCurrencyUnit(currency.units[0], "1");
19
+ const minBalanceRequiredForDelegate = parseCurrencyUnit(currency.units[0], "3");
20
+ const minSpendableRequiredForTokenTx = parseCurrencyUnit(currency.units[0], "1");
21
+
22
+ const cardano: AppSpec<Transaction> = {
23
+ name: "cardano",
24
+ currency: getCryptoCurrencyById("cardano"),
25
+ appQuery: {
26
+ model: DeviceModelId.nanoSP,
27
+ appName: "CardanoADA",
28
+ // FIXME latest (v7) app version requires to update cardano libs
29
+ appVersion: "6.1.2",
30
+ },
31
+ minViableAmount: minBalanceRequired,
32
+ genericDeviceAction: acceptTransaction,
33
+ testTimeout: 5 * 60 * 1000,
34
+ mutations: [
35
+ {
36
+ name: "move ~10% token",
37
+ maxRun: 1,
38
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
39
+ invariant(maxSpendable.gte(minSpendableRequiredForTokenTx), "balance is too low");
40
+ const sibling = pickSiblings(siblings, maxAccounts);
41
+ const recipient = sibling.freshAddress;
42
+ const transaction = bridge.createTransaction(account);
43
+
44
+ const subAccount = account.subAccounts?.find(subAccount =>
45
+ subAccount.balance.gt(1),
46
+ ) as SubAccount;
47
+ invariant(subAccount, "No token account with balance");
48
+
49
+ const updates = [
50
+ { subAccountId: subAccount.id },
51
+ { recipient },
52
+ {
53
+ amount: new BigNumber(subAccount.balance.dividedBy(10)).dp(0, BigNumber.ROUND_CEIL),
54
+ },
55
+ ];
56
+
57
+ return {
58
+ transaction,
59
+ updates,
60
+ };
61
+ },
62
+ test: ({ operation, transaction }): void => {
63
+ botTest("subOperations is defined", () => expect(operation.subOperations).toBeTruthy());
64
+
65
+ botTest("there's only one subOperation", () =>
66
+ expect(operation.subOperations?.length).toEqual(1),
67
+ );
68
+
69
+ const subOperation = operation.subOperations && operation.subOperations[0];
70
+
71
+ botTest("subOperation have correct tx amount", () =>
72
+ expect(subOperation?.value).toEqual(transaction.amount),
73
+ );
74
+ },
75
+ },
76
+ {
77
+ testDestination: genericTestDestination,
78
+ name: "move ~50%",
79
+ maxRun: 1,
80
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
81
+ invariant(maxSpendable.gt(minBalanceRequired), "balance is too low");
82
+ const sibling = pickSiblings(siblings, maxAccounts);
83
+ const recipient = sibling.freshAddress;
84
+ const transaction = bridge.createTransaction(account);
85
+
86
+ const updates = [
87
+ { recipient },
88
+ {
89
+ amount: new BigNumber(account.balance.dividedBy(2)).dp(0, BigNumber.ROUND_CEIL),
90
+ },
91
+ { memo: "LedgerLiveBot" },
92
+ ];
93
+
94
+ return {
95
+ transaction,
96
+ updates,
97
+ };
98
+ },
99
+ test: ({ accountBeforeTransaction, operation, transaction }): void => {
100
+ const cardanoResources = (accountBeforeTransaction as CardanoAccount)
101
+ .cardanoResources as CardanoResources;
102
+
103
+ const extra: CardanoOperationExtra = {
104
+ memo: transaction.memo,
105
+ };
106
+
107
+ if (cardanoResources.delegation?.rewards.gt(0)) {
108
+ extra.rewards = formatCurrencyUnit(
109
+ accountBeforeTransaction.currency.units[0],
110
+ new BigNumber(cardanoResources.delegation.rewards),
111
+ {
112
+ showCode: true,
113
+ disableRounding: true,
114
+ },
115
+ );
116
+ }
117
+
118
+ botTest("operation extra matches memo", () => expect(operation.extra).toEqual(extra));
119
+
120
+ botTest("optimistic value matches transaction amount", () =>
121
+ expect(transaction.amount).toEqual(operation.value.minus(operation.fee)),
122
+ );
123
+ },
124
+ },
125
+ {
126
+ name: "send max",
127
+ maxRun: 1,
128
+ testDestination: genericTestDestination,
129
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
130
+ invariant(maxSpendable.gt(minBalanceRequiredForMaxSend), "balance is too low");
131
+ const sibling = pickSiblings(siblings, maxAccounts);
132
+ const recipient = sibling.freshAddress;
133
+ const transaction = bridge.createTransaction(account);
134
+
135
+ const updates = [{ recipient }, { useAllAmount: true }];
136
+
137
+ return {
138
+ transaction,
139
+ updates,
140
+ };
141
+ },
142
+ test: ({ account }): void => {
143
+ const cardanoResources = (account as CardanoAccount).cardanoResources as CardanoResources;
144
+ const utxoTokens = cardanoResources.utxos.map(u => u.tokens).flat();
145
+ const tokenBalance = mergeTokens(utxoTokens);
146
+ const requiredAdaForTokens = tokenBalance.length
147
+ ? TyphonUtils.calculateMinUtxoAmount(
148
+ tokenBalance,
149
+ new BigNumber(cardanoResources.protocolParams.lovelacePerUtxoWord),
150
+ false,
151
+ )
152
+ : new BigNumber(0);
153
+
154
+ botTest("remaining balance equals requiredAdaForTokens)", () =>
155
+ expect(account.balance).toEqual(requiredAdaForTokens),
156
+ );
157
+ },
158
+ },
159
+ {
160
+ name: "delegate to pool",
161
+ maxRun: 1,
162
+ transaction: ({ account, bridge, maxSpendable }) => {
163
+ invariant(maxSpendable.gte(minBalanceRequiredForDelegate), "balance is too low");
164
+ const transaction = bridge.createTransaction(account);
165
+ return {
166
+ transaction,
167
+ updates: [
168
+ {
169
+ mode: "delegate",
170
+ poolId: "7df262feae9201d1b2e32d4c825ca91b29fbafb2b8e556f6efb7f549",
171
+ },
172
+ ],
173
+ };
174
+ },
175
+ test: ({ operation, transaction, accountBeforeTransaction }): void => {
176
+ botTest("check delegate operation type", () => {
177
+ expect(operation.type).toEqual("DELEGATE");
178
+ });
179
+
180
+ botTest("check operation value", () => {
181
+ const cardanoResources = (accountBeforeTransaction as CardanoAccount).cardanoResources;
182
+ const isStakeKeyRegistered = cardanoResources.delegation?.status ?? false;
183
+ let opValue = transaction.fees as BigNumber;
184
+ if (!isStakeKeyRegistered) {
185
+ opValue = opValue.plus(cardanoResources.protocolParams.stakeKeyDeposit);
186
+ }
187
+ expect(operation.value.toString()).toEqual(opValue.toString());
188
+ });
189
+ },
190
+ },
191
+ {
192
+ name: "redelegate to pool",
193
+ maxRun: 1,
194
+ transaction: ({ account, bridge, maxSpendable }) => {
195
+ invariant(maxSpendable.gte(minBalanceRequiredForDelegate), "balance is too low");
196
+ invariant(
197
+ (account as CardanoAccount).cardanoResources.delegation?.poolId,
198
+ "account should already be delegated to redelegate",
199
+ );
200
+ const transaction = bridge.createTransaction(account);
201
+ return {
202
+ transaction,
203
+ updates: [
204
+ {
205
+ mode: "delegate",
206
+ poolId: "da50099e7aa1d926e1888990b1c404caf554dd6f68a1cb0322999d1d",
207
+ },
208
+ ],
209
+ };
210
+ },
211
+ test: ({ operation, transaction }): void => {
212
+ botTest("check delegate operation type", () => {
213
+ expect(operation.type).toEqual("DELEGATE");
214
+ });
215
+
216
+ botTest("op value should be equal to fees", () => {
217
+ expect(operation.value.toString()).toEqual(transaction.fees?.toString());
218
+ });
219
+ },
220
+ },
221
+ {
222
+ name: "undelegate",
223
+ maxRun: 1,
224
+ transaction: ({ account, bridge, maxSpendable }) => {
225
+ invariant(maxSpendable.gte(minBalanceRequiredForDelegate), "balance is too low");
226
+ invariant(
227
+ (account as CardanoAccount).cardanoResources.delegation?.poolId,
228
+ "account should already be delegated to undelegate",
229
+ );
230
+ const transaction = bridge.createTransaction(account);
231
+ return {
232
+ transaction,
233
+ updates: [
234
+ {
235
+ mode: "undelegate",
236
+ },
237
+ ],
238
+ };
239
+ },
240
+ test: ({ operation, transaction }): void => {
241
+ botTest("check undelegate operation type", () => {
242
+ expect(operation.type).toEqual("UNDELEGATE");
243
+ });
244
+
245
+ botTest("op value should be equal to fees", () => {
246
+ expect(operation.value.toString()).toEqual(transaction.fees?.toString());
247
+ });
248
+ },
249
+ },
250
+ ],
251
+ };
252
+
253
+ export default { cardano };
@@ -0,0 +1,132 @@
1
+ import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
2
+ import type { Transaction } from "./types";
3
+ import { getAccountStakeCredential, getBipPathString } from "./logic";
4
+ import {
5
+ deviceActionFlow,
6
+ formatDeviceAmount,
7
+ SpeculosButton,
8
+ } from "@ledgerhq/coin-framework/bot/specs";
9
+
10
+ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
11
+ steps: [
12
+ {
13
+ title: "New ordinary",
14
+ },
15
+ {
16
+ title: "transaction?",
17
+ button: SpeculosButton.BOTH,
18
+ },
19
+ {
20
+ title: "Warning:",
21
+ button: SpeculosButton.BOTH,
22
+ expectedValue: () => "cannot verify network id: no outputs or withrawals",
23
+ },
24
+ {
25
+ title: "Auxiliary data hash",
26
+ button: SpeculosButton.BOTH,
27
+ },
28
+ {
29
+ title: "Send to address (1/3)",
30
+ button: SpeculosButton.RIGHT,
31
+ },
32
+ {
33
+ title: "Send to address (2/3)",
34
+ button: SpeculosButton.RIGHT,
35
+ },
36
+ {
37
+ title: "Send to address (3/3)",
38
+ button: SpeculosButton.BOTH,
39
+ },
40
+ {
41
+ title: "Send to address (1/2)",
42
+ button: SpeculosButton.RIGHT,
43
+ },
44
+ {
45
+ title: "Send to address (2/2)",
46
+ button: SpeculosButton.BOTH,
47
+ },
48
+ {
49
+ title: "Send",
50
+ button: SpeculosButton.BOTH,
51
+ ignoreAssertionFailure: true,
52
+ expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.amount),
53
+ },
54
+ {
55
+ title: "Asset fingerprint",
56
+ button: SpeculosButton.BOTH,
57
+ },
58
+ {
59
+ title: "Token amount",
60
+ button: SpeculosButton.BOTH,
61
+ },
62
+ {
63
+ title: "Confirm",
64
+ },
65
+ {
66
+ title: "output?",
67
+ button: SpeculosButton.BOTH,
68
+ },
69
+ {
70
+ title: "Transaction fee",
71
+ button: SpeculosButton.BOTH,
72
+ ignoreAssertionFailure: true,
73
+ expectedValue: ({ account, status }) =>
74
+ formatDeviceAmount(account.currency, status.estimatedFees),
75
+ },
76
+ {
77
+ title: "Register",
78
+ },
79
+ {
80
+ title: "Deregister",
81
+ },
82
+ {
83
+ title: "stake key",
84
+ button: SpeculosButton.BOTH,
85
+ },
86
+ {
87
+ title: "Stake key",
88
+ button: SpeculosButton.BOTH,
89
+ expectedValue: ({ account }) => {
90
+ const stakeCred = getAccountStakeCredential(account.xpub as string, account.index);
91
+ const bipPath = getBipPathString({
92
+ account: stakeCred.path.account,
93
+ chain: stakeCred.path.chain,
94
+ index: stakeCred.path.index,
95
+ });
96
+ return `m/${bipPath}`;
97
+ },
98
+ },
99
+ {
100
+ title: "Transaction TTL",
101
+ button: SpeculosButton.BOTH,
102
+ },
103
+ {
104
+ title: "...",
105
+ },
106
+ {
107
+ title: "registration?",
108
+ button: SpeculosButton.BOTH,
109
+ },
110
+ {
111
+ title: "deregistration?",
112
+ button: SpeculosButton.BOTH,
113
+ },
114
+ {
115
+ title: "Delegate stake (1/2)",
116
+ button: SpeculosButton.RIGHT,
117
+ },
118
+ {
119
+ title: "Delegate stake (2/2)",
120
+ button: SpeculosButton.BOTH,
121
+ },
122
+ {
123
+ title: "delegation?",
124
+ button: SpeculosButton.BOTH,
125
+ },
126
+ {
127
+ title: "transaction?",
128
+ final: true,
129
+ button: SpeculosButton.BOTH,
130
+ },
131
+ ],
132
+ });