@ledgerhq/coin-stacks 0.1.1-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 (296) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +31 -0
  4. package/CHANGELOG.md +11 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/bridge/broadcast.d.ts +4 -0
  8. package/lib/bridge/broadcast.d.ts.map +1 -0
  9. package/lib/bridge/broadcast.js +28 -0
  10. package/lib/bridge/broadcast.js.map +1 -0
  11. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  12. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  13. package/lib/bridge/buildOptimisticOperation.js +34 -0
  14. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  15. package/lib/bridge/createTransaction.d.ts +4 -0
  16. package/lib/bridge/createTransaction.d.ts.map +1 -0
  17. package/lib/bridge/createTransaction.js +18 -0
  18. package/lib/bridge/createTransaction.js.map +1 -0
  19. package/lib/bridge/deviceTransactionConfig.d.ts +22 -0
  20. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  21. package/lib/bridge/deviceTransactionConfig.js +34 -0
  22. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  23. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  24. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  25. package/lib/bridge/estimateMaxSpendable.js +46 -0
  26. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  27. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  28. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  29. package/lib/bridge/getTransactionStatus.js +60 -0
  30. package/lib/bridge/getTransactionStatus.js.map +1 -0
  31. package/lib/bridge/index.d.ts +11 -0
  32. package/lib/bridge/index.d.ts.map +1 -0
  33. package/lib/bridge/index.js +56 -0
  34. package/lib/bridge/index.js.map +1 -0
  35. package/lib/bridge/prepareTransaction.d.ts +4 -0
  36. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  37. package/lib/bridge/prepareTransaction.js +56 -0
  38. package/lib/bridge/prepareTransaction.js.map +1 -0
  39. package/lib/bridge/signOperation.d.ts +5 -0
  40. package/lib/bridge/signOperation.d.ts.map +1 -0
  41. package/lib/bridge/signOperation.js +85 -0
  42. package/lib/bridge/signOperation.js.map +1 -0
  43. package/lib/bridge/synchronization.d.ts +5 -0
  44. package/lib/bridge/synchronization.d.ts.map +1 -0
  45. package/lib/bridge/synchronization.js +62 -0
  46. package/lib/bridge/synchronization.js.map +1 -0
  47. package/lib/bridge/transaction.d.ts +14 -0
  48. package/lib/bridge/transaction.d.ts.map +1 -0
  49. package/lib/bridge/transaction.js +46 -0
  50. package/lib/bridge/transaction.js.map +1 -0
  51. package/lib/bridge/utils/addresses.d.ts +13 -0
  52. package/lib/bridge/utils/addresses.d.ts.map +1 -0
  53. package/lib/bridge/utils/addresses.js +15 -0
  54. package/lib/bridge/utils/addresses.js.map +1 -0
  55. package/lib/bridge/utils/misc.d.ts +15 -0
  56. package/lib/bridge/utils/misc.d.ts.map +1 -0
  57. package/lib/bridge/utils/misc.js +186 -0
  58. package/lib/bridge/utils/misc.js.map +1 -0
  59. package/lib/bridge/utils/misc.unit.test.d.ts +2 -0
  60. package/lib/bridge/utils/misc.unit.test.d.ts.map +1 -0
  61. package/lib/bridge/utils/misc.unit.test.js +230 -0
  62. package/lib/bridge/utils/misc.unit.test.js.map +1 -0
  63. package/lib/config.d.ts +14 -0
  64. package/lib/config.d.ts.map +1 -0
  65. package/lib/config.js +16 -0
  66. package/lib/config.js.map +1 -0
  67. package/lib/errors.d.ts +4 -0
  68. package/lib/errors.d.ts.map +1 -0
  69. package/lib/errors.js +6 -0
  70. package/lib/errors.js.map +1 -0
  71. package/lib/index.d.ts +4 -0
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +21 -0
  74. package/lib/index.js.map +1 -0
  75. package/lib/network/api.d.ts +11 -0
  76. package/lib/network/api.d.ts.map +1 -0
  77. package/lib/network/api.js +139 -0
  78. package/lib/network/api.js.map +1 -0
  79. package/lib/network/api.types.d.ts +168 -0
  80. package/lib/network/api.types.d.ts.map +1 -0
  81. package/lib/network/api.types.js +9 -0
  82. package/lib/network/api.types.js.map +1 -0
  83. package/lib/network/index.d.ts +3 -0
  84. package/lib/network/index.d.ts.map +1 -0
  85. package/lib/network/index.js +19 -0
  86. package/lib/network/index.js.map +1 -0
  87. package/lib/signer/getAddress.d.ts +6 -0
  88. package/lib/signer/getAddress.d.ts.map +1 -0
  89. package/lib/signer/getAddress.js +31 -0
  90. package/lib/signer/getAddress.js.map +1 -0
  91. package/lib/signer/index.d.ts +4 -0
  92. package/lib/signer/index.d.ts.map +1 -0
  93. package/lib/signer/index.js +23 -0
  94. package/lib/signer/index.js.map +1 -0
  95. package/lib/signer/signMessage.d.ts +12 -0
  96. package/lib/signer/signMessage.d.ts.map +1 -0
  97. package/lib/signer/signMessage.js +31 -0
  98. package/lib/signer/signMessage.js.map +1 -0
  99. package/lib/test/bot-deviceActions.d.ts +4 -0
  100. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  101. package/lib/test/bot-deviceActions.js +48 -0
  102. package/lib/test/bot-deviceActions.js.map +1 -0
  103. package/lib/test/bot-specs.d.ts +7 -0
  104. package/lib/test/bot-specs.d.ts.map +1 -0
  105. package/lib/test/bot-specs.js +73 -0
  106. package/lib/test/bot-specs.js.map +1 -0
  107. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  108. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  109. package/lib/test/bridgeDatasetTest.js +129 -0
  110. package/lib/test/bridgeDatasetTest.js.map +1 -0
  111. package/lib/test/cli.d.ts +15 -0
  112. package/lib/test/cli.d.ts.map +1 -0
  113. package/lib/test/cli.js +27 -0
  114. package/lib/test/cli.js.map +1 -0
  115. package/lib/test/index.d.ts +6 -0
  116. package/lib/test/index.d.ts.map +1 -0
  117. package/lib/test/index.js +26 -0
  118. package/lib/test/index.js.map +1 -0
  119. package/lib/types/bridge.d.ts +35 -0
  120. package/lib/types/bridge.d.ts.map +1 -0
  121. package/lib/types/bridge.js +3 -0
  122. package/lib/types/bridge.js.map +1 -0
  123. package/lib/types/index.d.ts +3 -0
  124. package/lib/types/index.d.ts.map +1 -0
  125. package/lib/types/index.js +19 -0
  126. package/lib/types/index.js.map +1 -0
  127. package/lib/types/signer.d.ts +14 -0
  128. package/lib/types/signer.d.ts.map +1 -0
  129. package/lib/types/signer.js +3 -0
  130. package/lib/types/signer.js.map +1 -0
  131. package/lib/utils.d.ts +8 -0
  132. package/lib/utils.d.ts.map +1 -0
  133. package/lib/utils.js +26 -0
  134. package/lib/utils.js.map +1 -0
  135. package/lib-es/bridge/broadcast.d.ts +4 -0
  136. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  137. package/lib-es/bridge/broadcast.js +21 -0
  138. package/lib-es/bridge/broadcast.js.map +1 -0
  139. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  140. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  141. package/lib-es/bridge/buildOptimisticOperation.js +27 -0
  142. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  143. package/lib-es/bridge/createTransaction.d.ts +4 -0
  144. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  145. package/lib-es/bridge/createTransaction.js +11 -0
  146. package/lib-es/bridge/createTransaction.js.map +1 -0
  147. package/lib-es/bridge/deviceTransactionConfig.d.ts +22 -0
  148. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  149. package/lib-es/bridge/deviceTransactionConfig.js +32 -0
  150. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  151. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  152. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  153. package/lib-es/bridge/estimateMaxSpendable.js +39 -0
  154. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  155. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  156. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  157. package/lib-es/bridge/getTransactionStatus.js +53 -0
  158. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  159. package/lib-es/bridge/index.d.ts +11 -0
  160. package/lib-es/bridge/index.d.ts.map +1 -0
  161. package/lib-es/bridge/index.js +48 -0
  162. package/lib-es/bridge/index.js.map +1 -0
  163. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  164. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  165. package/lib-es/bridge/prepareTransaction.js +49 -0
  166. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  167. package/lib-es/bridge/signOperation.d.ts +5 -0
  168. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  169. package/lib-es/bridge/signOperation.js +78 -0
  170. package/lib-es/bridge/signOperation.js.map +1 -0
  171. package/lib-es/bridge/synchronization.d.ts +5 -0
  172. package/lib-es/bridge/synchronization.d.ts.map +1 -0
  173. package/lib-es/bridge/synchronization.js +55 -0
  174. package/lib-es/bridge/synchronization.js.map +1 -0
  175. package/lib-es/bridge/transaction.d.ts +14 -0
  176. package/lib-es/bridge/transaction.d.ts.map +1 -0
  177. package/lib-es/bridge/transaction.js +38 -0
  178. package/lib-es/bridge/transaction.js.map +1 -0
  179. package/lib-es/bridge/utils/addresses.d.ts +13 -0
  180. package/lib-es/bridge/utils/addresses.d.ts.map +1 -0
  181. package/lib-es/bridge/utils/addresses.js +11 -0
  182. package/lib-es/bridge/utils/addresses.js.map +1 -0
  183. package/lib-es/bridge/utils/misc.d.ts +15 -0
  184. package/lib-es/bridge/utils/misc.d.ts.map +1 -0
  185. package/lib-es/bridge/utils/misc.js +176 -0
  186. package/lib-es/bridge/utils/misc.js.map +1 -0
  187. package/lib-es/bridge/utils/misc.unit.test.d.ts +2 -0
  188. package/lib-es/bridge/utils/misc.unit.test.d.ts.map +1 -0
  189. package/lib-es/bridge/utils/misc.unit.test.js +228 -0
  190. package/lib-es/bridge/utils/misc.unit.test.js.map +1 -0
  191. package/lib-es/config.d.ts +14 -0
  192. package/lib-es/config.d.ts.map +1 -0
  193. package/lib-es/config.js +11 -0
  194. package/lib-es/config.js.map +1 -0
  195. package/lib-es/errors.d.ts +4 -0
  196. package/lib-es/errors.d.ts.map +1 -0
  197. package/lib-es/errors.js +3 -0
  198. package/lib-es/errors.js.map +1 -0
  199. package/lib-es/index.d.ts +4 -0
  200. package/lib-es/index.d.ts.map +1 -0
  201. package/lib-es/index.js +3 -0
  202. package/lib-es/index.js.map +1 -0
  203. package/lib-es/network/api.d.ts +11 -0
  204. package/lib-es/network/api.d.ts.map +1 -0
  205. package/lib-es/network/api.js +124 -0
  206. package/lib-es/network/api.js.map +1 -0
  207. package/lib-es/network/api.types.d.ts +168 -0
  208. package/lib-es/network/api.types.d.ts.map +1 -0
  209. package/lib-es/network/api.types.js +6 -0
  210. package/lib-es/network/api.types.js.map +1 -0
  211. package/lib-es/network/index.d.ts +3 -0
  212. package/lib-es/network/index.d.ts.map +1 -0
  213. package/lib-es/network/index.js +3 -0
  214. package/lib-es/network/index.js.map +1 -0
  215. package/lib-es/signer/getAddress.d.ts +6 -0
  216. package/lib-es/signer/getAddress.d.ts.map +1 -0
  217. package/lib-es/signer/getAddress.js +29 -0
  218. package/lib-es/signer/getAddress.js.map +1 -0
  219. package/lib-es/signer/index.d.ts +4 -0
  220. package/lib-es/signer/index.d.ts.map +1 -0
  221. package/lib-es/signer/index.js +4 -0
  222. package/lib-es/signer/index.js.map +1 -0
  223. package/lib-es/signer/signMessage.d.ts +12 -0
  224. package/lib-es/signer/signMessage.d.ts.map +1 -0
  225. package/lib-es/signer/signMessage.js +27 -0
  226. package/lib-es/signer/signMessage.js.map +1 -0
  227. package/lib-es/test/bot-deviceActions.d.ts +4 -0
  228. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  229. package/lib-es/test/bot-deviceActions.js +45 -0
  230. package/lib-es/test/bot-deviceActions.js.map +1 -0
  231. package/lib-es/test/bot-specs.d.ts +7 -0
  232. package/lib-es/test/bot-specs.d.ts.map +1 -0
  233. package/lib-es/test/bot-specs.js +68 -0
  234. package/lib-es/test/bot-specs.js.map +1 -0
  235. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  236. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  237. package/lib-es/test/bridgeDatasetTest.js +126 -0
  238. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  239. package/lib-es/test/cli.d.ts +15 -0
  240. package/lib-es/test/cli.d.ts.map +1 -0
  241. package/lib-es/test/cli.js +21 -0
  242. package/lib-es/test/cli.js.map +1 -0
  243. package/lib-es/test/index.d.ts +6 -0
  244. package/lib-es/test/index.d.ts.map +1 -0
  245. package/lib-es/test/index.js +6 -0
  246. package/lib-es/test/index.js.map +1 -0
  247. package/lib-es/types/bridge.d.ts +35 -0
  248. package/lib-es/types/bridge.d.ts.map +1 -0
  249. package/lib-es/types/bridge.js +2 -0
  250. package/lib-es/types/bridge.js.map +1 -0
  251. package/lib-es/types/index.d.ts +3 -0
  252. package/lib-es/types/index.d.ts.map +1 -0
  253. package/lib-es/types/index.js +3 -0
  254. package/lib-es/types/index.js.map +1 -0
  255. package/lib-es/types/signer.d.ts +14 -0
  256. package/lib-es/types/signer.d.ts.map +1 -0
  257. package/lib-es/types/signer.js +2 -0
  258. package/lib-es/types/signer.js.map +1 -0
  259. package/lib-es/utils.d.ts +8 -0
  260. package/lib-es/utils.d.ts.map +1 -0
  261. package/lib-es/utils.js +17 -0
  262. package/lib-es/utils.js.map +1 -0
  263. package/package.json +136 -0
  264. package/src/bridge/broadcast.ts +18 -0
  265. package/src/bridge/buildOptimisticOperation.ts +34 -0
  266. package/src/bridge/createTransaction.ts +13 -0
  267. package/src/bridge/deviceTransactionConfig.ts +57 -0
  268. package/src/bridge/estimateMaxSpendable.ts +50 -0
  269. package/src/bridge/getTransactionStatus.ts +56 -0
  270. package/src/bridge/index.ts +64 -0
  271. package/src/bridge/prepareTransaction.ts +60 -0
  272. package/src/bridge/signOperation.ts +91 -0
  273. package/src/bridge/synchronization.ts +55 -0
  274. package/src/bridge/transaction.ts +75 -0
  275. package/src/bridge/utils/addresses.ts +23 -0
  276. package/src/bridge/utils/misc.ts +274 -0
  277. package/src/bridge/utils/misc.unit.test.ts +237 -0
  278. package/src/config.ts +26 -0
  279. package/src/errors.ts +3 -0
  280. package/src/index.ts +4 -0
  281. package/src/network/api.ts +173 -0
  282. package/src/network/api.types.ts +180 -0
  283. package/src/network/index.ts +2 -0
  284. package/src/signer/getAddress.ts +27 -0
  285. package/src/signer/index.ts +4 -0
  286. package/src/signer/signMessage.ts +26 -0
  287. package/src/test/bot-deviceActions.ts +47 -0
  288. package/src/test/bot-specs.ts +82 -0
  289. package/src/test/bridgeDatasetTest.ts +134 -0
  290. package/src/test/cli.ts +38 -0
  291. package/src/test/index.ts +5 -0
  292. package/src/types/bridge.ts +49 -0
  293. package/src/types/index.ts +2 -0
  294. package/src/types/signer.ts +16 -0
  295. package/src/utils.ts +24 -0
  296. package/tsconfig.json +14 -0
@@ -0,0 +1,47 @@
1
+ import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
2
+ import type { Transaction } from "../types";
3
+ import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
4
+
5
+ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
6
+ steps: [
7
+ {
8
+ title: "Please",
9
+ button: SpeculosButton.RIGHT,
10
+ expectedValue: () => "review",
11
+ },
12
+ {
13
+ title: "Origin",
14
+ button: SpeculosButton.RIGHT,
15
+ expectedValue: ({ account }) => account.freshAddress,
16
+ },
17
+ {
18
+ title: "Nonce",
19
+ button: SpeculosButton.RIGHT,
20
+ expectedValue: ({ transaction }) => (transaction.nonce ? transaction.nonce.toFixed() : "0"),
21
+ },
22
+ {
23
+ title: "Fee (uSTX)",
24
+ button: SpeculosButton.RIGHT,
25
+ expectedValue: ({ transaction }) => (transaction.fee ? transaction.fee.toFixed() : "0"),
26
+ },
27
+ {
28
+ title: "Amount uSTX",
29
+ button: SpeculosButton.RIGHT,
30
+ expectedValue: ({ status }) => status.amount.toFixed(),
31
+ },
32
+ {
33
+ title: "To",
34
+ button: SpeculosButton.RIGHT,
35
+ expectedValue: ({ transaction }) => transaction.recipient,
36
+ },
37
+ {
38
+ title: "Memo",
39
+ button: SpeculosButton.RIGHT,
40
+ expectedValue: ({ transaction }) => transaction.memo || "",
41
+ },
42
+ {
43
+ title: "APPROVE",
44
+ button: SpeculosButton.BOTH,
45
+ },
46
+ ],
47
+ });
@@ -0,0 +1,82 @@
1
+ import invariant from "invariant";
2
+ import { DeviceModelId } from "@ledgerhq/devices";
3
+ import BigNumber from "bignumber.js";
4
+ import expect from "expect";
5
+
6
+ import type { Transaction } from "../types";
7
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
8
+ import { botTest, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
9
+ import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
10
+ import { acceptTransaction } from "./bot-deviceActions";
11
+
12
+ const MIN_SAFE = new BigNumber(10000);
13
+ const stacksSpecs: AppSpec<Transaction> = {
14
+ name: "Stacks",
15
+ currency: getCryptoCurrencyById("stacks"),
16
+ appQuery: {
17
+ model: DeviceModelId.nanoSP,
18
+ appName: "Stacks",
19
+ },
20
+ genericDeviceAction: acceptTransaction,
21
+ // FIXME Stacks operations can take much longer to be confirmed
22
+ // Need an evolution of the bot to tolerate unconfirmed ops and just warn maybe instead of error
23
+ testTimeout: 25 * 60 * 1000,
24
+ transactionCheck: ({ maxSpendable }) => {
25
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
26
+ },
27
+ mutations: [
28
+ {
29
+ name: "Send 50%~",
30
+ maxRun: 1,
31
+ transaction: ({ account, siblings, bridge }) => {
32
+ const sibling = pickSiblings(siblings, 2);
33
+ const recipient = sibling.freshAddress;
34
+
35
+ let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue();
36
+
37
+ if (!sibling.used && amount.lt(MIN_SAFE)) {
38
+ invariant(account.spendableBalance.gt(MIN_SAFE), "send is too low to activate account");
39
+ amount = MIN_SAFE;
40
+ }
41
+
42
+ const transaction = bridge.createTransaction(account);
43
+ const updates = [{ recipient }, { amount }];
44
+
45
+ return {
46
+ transaction,
47
+ updates,
48
+ };
49
+ },
50
+ test: ({ account, accountBeforeTransaction, operation }) => {
51
+ botTest("account balance decreased with operation value", () =>
52
+ expect(account.balance.toFixed()).toBe(
53
+ accountBeforeTransaction.balance.minus(operation.value).toFixed(),
54
+ ),
55
+ );
56
+ },
57
+ },
58
+ {
59
+ name: "Transfer Max",
60
+ maxRun: 1,
61
+ transaction: ({ account, siblings, bridge }) => {
62
+ const sibling = pickSiblings(siblings, 2);
63
+ const recipient = sibling.freshAddress;
64
+
65
+ const transaction = bridge.createTransaction(account);
66
+ const updates = [{ recipient }, { useAllAmount: true }];
67
+
68
+ return {
69
+ transaction,
70
+ updates,
71
+ };
72
+ },
73
+ test: ({ account }) => {
74
+ botTest("account balance is 0", () => expect(account.balance.toFixed()).toBe("0"));
75
+ },
76
+ },
77
+ ],
78
+ };
79
+
80
+ export default {
81
+ stacksSpecs,
82
+ };
@@ -0,0 +1,134 @@
1
+ import { CurrenciesData } from "@ledgerhq/types-live";
2
+ import { AnchorMode } from "@stacks/transactions";
3
+ import type { DatasetTest } from "@ledgerhq/types-live";
4
+ import type { Transaction } from "../types";
5
+ import { fromTransactionRaw } from "../bridge/transaction";
6
+ import { BigNumber } from "bignumber.js";
7
+ import {
8
+ AmountRequired,
9
+ InvalidAddressBecauseDestinationIsAlsoSource,
10
+ NotEnoughBalance,
11
+ } from "@ledgerhq/errors";
12
+
13
+ const SEED_IDENTIFIER = "SP3KS7VMY2ZNE6SB88PHR4SKRK2EEPHS8N8MCCBR9";
14
+ const SEED_IDENTIFIER_PUBKEY = "022a460decc9dba8c452927fecb33d7ae25a8d79dc5442b84feaf8f3aa0e2b575d";
15
+ const ACCOUNT_1 = "SP2DV2RVZP1A69Q6VAG5PHEQ6ZHQHZPCV84TMYNGN";
16
+
17
+ const stacks: CurrenciesData<Transaction> = {
18
+ FIXME_ignoreAccountFields: [],
19
+ IgnorePrepareTransactionFields: ["fee"],
20
+ scanAccounts: [
21
+ {
22
+ name: "stacks seed 1",
23
+ apdus: `
24
+ => 09010016142c0000807d160080000000800000000000000000
25
+ <= 022a460decc9dba8c452927fecb33d7ae25a8d79dc5442b84feaf8f3aa0e2b575d5350334b5337564d59325a4e45365342383850485234534b524b324545504853384e384d43434252399000
26
+ => 09010016142c0000807d160080000000800000000001000000
27
+ <= 03a2d4bbb54c2f44c3a205b15ca7d2049a2bb66e50e100304f932b3b99ed3a99cb5350324136463652374632395a3338533259434a4d37484a44564532345332564757543542545a50419000
28
+ => 09010016142c0000807d160080010000800000000000000000
29
+ <= 034bbb21911e9d4502ac170162c5c05cbba65cbb79e5b46adf95152af2d0e78a4553503244563252565a503141363951365641473550484551365a4851485a5043563834544d594e474e9000
30
+ => 09010016142c0000807d160080020000800000000000000000
31
+ <= 020637c4d824458f6a11551f51df9e5be9e96c2e3a2e5bdb25d2916cc1dd5ba2d753504e5a4e434333433244525450574a4a384e534d484d575744304643415459413843565a3834459000
32
+ => 09010016142c0000807d160080030000800000000000000000
33
+ <= 02e57bb8c28c4c768cf65f8e28935482e40afbb33168d26810199f39a719cc05f0535031564d30584546574251345a543838384654333447333047474635324459395951575a434151309000
34
+ => 09010016142c0000807d160080040000800000000000000000
35
+ <= 0264b6d44f720fa50055dc294276bf15ce22e4f3dec48510b317ab8c07419c1b7753503248574a58594e4747594354535952545036323636424a483858565a4759504d455248514538529000
36
+ `,
37
+ },
38
+ ],
39
+ accounts: [
40
+ {
41
+ raw: {
42
+ id: `js:2:stacks:${SEED_IDENTIFIER_PUBKEY}:`,
43
+ seedIdentifier: SEED_IDENTIFIER,
44
+ name: "Stacks 1",
45
+ derivationMode: "",
46
+ index: 0,
47
+ freshAddress: SEED_IDENTIFIER,
48
+ freshAddressPath: "",
49
+ blockHeight: 0,
50
+ operations: [],
51
+ xpub: SEED_IDENTIFIER_PUBKEY,
52
+ pendingOperations: [],
53
+ currencyId: "stacks",
54
+ lastSyncDate: "",
55
+ balance: "1000",
56
+ },
57
+ transactions: [
58
+ {
59
+ name: "Source and destination are the equal",
60
+ transaction: fromTransactionRaw({
61
+ family: "stacks",
62
+ nonce: "1",
63
+ network: "mainnet",
64
+ anchorMode: AnchorMode.Any,
65
+ recipient: SEED_IDENTIFIER,
66
+ amount: "1",
67
+ }),
68
+ expectedStatus: {
69
+ errors: {
70
+ recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
71
+ },
72
+ warnings: {},
73
+ },
74
+ },
75
+ {
76
+ name: "Not enough balance",
77
+ transaction: fromTransactionRaw({
78
+ family: "stacks",
79
+ nonce: "1",
80
+ network: "mainnet",
81
+ anchorMode: AnchorMode.Any,
82
+ recipient: ACCOUNT_1,
83
+ amount: "10000000000",
84
+ }),
85
+ expectedStatus: {
86
+ errors: {
87
+ amount: new NotEnoughBalance(),
88
+ },
89
+ warnings: {},
90
+ },
91
+ },
92
+ {
93
+ name: "Amount Required",
94
+ transaction: fromTransactionRaw({
95
+ family: "stacks",
96
+ nonce: "1",
97
+ network: "mainnet",
98
+ anchorMode: AnchorMode.Any,
99
+ recipient: ACCOUNT_1,
100
+ amount: "0",
101
+ }),
102
+ expectedStatus: {
103
+ errors: {
104
+ amount: new AmountRequired(),
105
+ },
106
+ warnings: {},
107
+ },
108
+ },
109
+ {
110
+ name: "New account and sufficient amount",
111
+ transaction: fromTransactionRaw({
112
+ family: "stacks",
113
+ nonce: "1",
114
+ network: "mainnet",
115
+ anchorMode: AnchorMode.Any,
116
+ recipient: ACCOUNT_1,
117
+ amount: "1",
118
+ }),
119
+ expectedStatus: {
120
+ amount: new BigNumber("1"),
121
+ errors: {},
122
+ warnings: {},
123
+ },
124
+ },
125
+ ],
126
+ },
127
+ ],
128
+ };
129
+ export const dataset: DatasetTest<Transaction> = {
130
+ implementations: ["js"],
131
+ currencies: {
132
+ stacks,
133
+ },
134
+ };
@@ -0,0 +1,38 @@
1
+ import invariant from "invariant";
2
+ import flatMap from "lodash/flatMap";
3
+
4
+ import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
5
+
6
+ import type { Transaction } from "../types";
7
+
8
+ function inferAccounts(account: Account): AccountLikeArray {
9
+ invariant(account.currency.family === "stacks", "stacks family");
10
+
11
+ const accounts: Account[] = [account];
12
+ return accounts;
13
+ }
14
+
15
+ function inferTransactions(
16
+ transactions: Array<{
17
+ account: AccountLike;
18
+ transaction: Transaction;
19
+ mainAccount: Account;
20
+ }>,
21
+ ): Transaction[] {
22
+ return flatMap(transactions, ({ transaction }) => {
23
+ invariant(transaction.family === "stacks", "stacks family");
24
+
25
+ return {
26
+ ...transaction,
27
+ family: "stacks",
28
+ } as Transaction;
29
+ });
30
+ }
31
+
32
+ export default function makeCliTools() {
33
+ return {
34
+ options: [],
35
+ inferAccounts,
36
+ inferTransactions,
37
+ };
38
+ }
@@ -0,0 +1,5 @@
1
+ import makeCliTools from "./cli";
2
+ export { makeCliTools };
3
+ export * from "./bot-deviceActions";
4
+ export * from "./bot-specs";
5
+ export * from "./bridgeDatasetTest";
@@ -0,0 +1,49 @@
1
+ import { AnchorMode } from "@stacks/transactions";
2
+ import BigNumber from "bignumber.js";
3
+
4
+ import {
5
+ Operation,
6
+ TransactionCommon,
7
+ TransactionCommonRaw,
8
+ TransactionStatusCommon,
9
+ TransactionStatusCommonRaw,
10
+ } from "@ledgerhq/types-live";
11
+
12
+ import { StacksNetwork } from "../network/api.types";
13
+
14
+ type FamilyType = "stacks";
15
+
16
+ export type NetworkInfo = {
17
+ family: FamilyType;
18
+ };
19
+ export type NetworkInfoRaw = {
20
+ family: FamilyType;
21
+ };
22
+
23
+ export type Transaction = TransactionCommon & {
24
+ family: FamilyType;
25
+ fee?: BigNumber;
26
+ nonce?: BigNumber;
27
+ memo?: string;
28
+ network: keyof typeof StacksNetwork;
29
+ anchorMode: AnchorMode;
30
+ };
31
+
32
+ export type TransactionRaw = TransactionCommonRaw & {
33
+ family: FamilyType;
34
+ fee?: string;
35
+ nonce?: string;
36
+ memo?: string;
37
+ network: string;
38
+ anchorMode: number;
39
+ };
40
+
41
+ export type TransactionStatus = TransactionStatusCommon;
42
+
43
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
44
+
45
+ export type StacksOperation = Operation<StacksOperationExtra>;
46
+
47
+ export type StacksOperationExtra = {
48
+ memo?: string | undefined;
49
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./bridge";
2
+ export * from "./signer";
@@ -0,0 +1,16 @@
1
+ import type { AddressVersion } from "@stacks/transactions";
2
+ import { ResponseAddress } from "@zondax/ledger-stacks";
3
+
4
+ export type StacksAddress = {
5
+ publicKey: string;
6
+ address: string;
7
+ chainCode?: string;
8
+ };
9
+
10
+ export type StacksSignature = string; // `0x${string}`
11
+
12
+ export interface StacksSigner {
13
+ showAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
14
+ getAddressAndPubKey(path: string, version: AddressVersion): Promise<ResponseAddress>;
15
+ sign(path: string, message: Buffer): Promise<any>;
16
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { ResponseAddress } from "@zondax/ledger-stacks";
2
+
3
+ // NOTE: inlined now, this shared utils code will be moved to coin-framework in a future PR
4
+ const validHexRegExp = new RegExp(/^(0x)?[a-fA-F0-9]+$/);
5
+ const validBase64RegExp = new RegExp(
6
+ /^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/,
7
+ );
8
+ export const isValidHex = (msg: string) => validHexRegExp.test(msg) && msg.length % 2 === 0;
9
+ export const isValidBase64 = (msg: string) => validBase64RegExp.test(msg);
10
+
11
+ export const isNoErrorReturnCode = (code: number) => code === 0x9000;
12
+
13
+ export const getPath = (path: string) => (path && path.substr(0, 2) !== "m/" ? `m/${path}` : path);
14
+
15
+ export const throwIfError = (r: ResponseAddress) => {
16
+ if (!isNoErrorReturnCode(r.returnCode)) throw new Error(`${r.returnCode} - ${r.errorMessage}`);
17
+ };
18
+
19
+ export const getBufferFromString = (message: string): Buffer =>
20
+ isValidHex(message)
21
+ ? Buffer.from(message, "hex")
22
+ : isValidBase64(message)
23
+ ? Buffer.from(message, "base64")
24
+ : Buffer.from(message);
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "../../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "noImplicitAny": false,
7
+ "module": "commonjs",
8
+ "downlevelIteration": true,
9
+ "lib": ["es2020", "dom"],
10
+ "outDir": "lib",
11
+ "typeRoots": ["./types", "./node_modules/@types"]
12
+ },
13
+ "include": ["src/**/*"]
14
+ }