@ledgerhq/live-cli 21.32.2-nightly.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 (235) hide show
  1. package/README.md +520 -0
  2. package/bin/index.js +2 -0
  3. package/lib/cli.d.ts +2 -0
  4. package/lib/cli.d.ts.map +1 -0
  5. package/lib/cli.js +137 -0
  6. package/lib/cli.js.map +1 -0
  7. package/lib/commands/app.d.ts +45 -0
  8. package/lib/commands/app.d.ts.map +1 -0
  9. package/lib/commands/app.js +131 -0
  10. package/lib/commands/app.js.map +1 -0
  11. package/lib/commands/appUninstallAll.d.ts +15 -0
  12. package/lib/commands/appUninstallAll.d.ts.map +1 -0
  13. package/lib/commands/appUninstallAll.js +31 -0
  14. package/lib/commands/appUninstallAll.js.map +1 -0
  15. package/lib/commands/appsCheckAllAppVersions.d.ts +20 -0
  16. package/lib/commands/appsCheckAllAppVersions.d.ts.map +1 -0
  17. package/lib/commands/appsCheckAllAppVersions.js +484 -0
  18. package/lib/commands/appsCheckAllAppVersions.js.map +1 -0
  19. package/lib/commands/appsInstallAll.d.ts +15 -0
  20. package/lib/commands/appsInstallAll.d.ts.map +1 -0
  21. package/lib/commands/appsInstallAll.js +34 -0
  22. package/lib/commands/appsInstallAll.js.map +1 -0
  23. package/lib/commands/appsUpdateTestAll.d.ts +20 -0
  24. package/lib/commands/appsUpdateTestAll.d.ts.map +1 -0
  25. package/lib/commands/appsUpdateTestAll.js +101 -0
  26. package/lib/commands/appsUpdateTestAll.js.map +1 -0
  27. package/lib/commands/balanceHistory.d.ts +50 -0
  28. package/lib/commands/balanceHistory.d.ts.map +1 -0
  29. package/lib/commands/balanceHistory.js +110 -0
  30. package/lib/commands/balanceHistory.js.map +1 -0
  31. package/lib/commands/bot.d.ts +12 -0
  32. package/lib/commands/bot.d.ts.map +1 -0
  33. package/lib/commands/bot.js +33 -0
  34. package/lib/commands/bot.js.map +1 -0
  35. package/lib/commands/botPortfolio.d.ts +15 -0
  36. package/lib/commands/botPortfolio.d.ts.map +1 -0
  37. package/lib/commands/botPortfolio.js +41 -0
  38. package/lib/commands/botPortfolio.js.map +1 -0
  39. package/lib/commands/botTransfer.d.ts +7 -0
  40. package/lib/commands/botTransfer.d.ts.map +1 -0
  41. package/lib/commands/botTransfer.js +376 -0
  42. package/lib/commands/botTransfer.js.map +1 -0
  43. package/lib/commands/broadcast.d.ts +42 -0
  44. package/lib/commands/broadcast.d.ts.map +1 -0
  45. package/lib/commands/broadcast.js +48 -0
  46. package/lib/commands/broadcast.js.map +1 -0
  47. package/lib/commands/cleanSpeculos.d.ts +7 -0
  48. package/lib/commands/cleanSpeculos.d.ts.map +1 -0
  49. package/lib/commands/cleanSpeculos.js +20 -0
  50. package/lib/commands/cleanSpeculos.js.map +1 -0
  51. package/lib/commands/countervalues.d.ts +84 -0
  52. package/lib/commands/countervalues.d.ts.map +1 -0
  53. package/lib/commands/countervalues.js +302 -0
  54. package/lib/commands/countervalues.js.map +1 -0
  55. package/lib/commands/derivation.d.ts +6 -0
  56. package/lib/commands/derivation.d.ts.map +1 -0
  57. package/lib/commands/derivation.js +44 -0
  58. package/lib/commands/derivation.js.map +1 -0
  59. package/lib/commands/devDeviceAppsScenario.d.ts +24 -0
  60. package/lib/commands/devDeviceAppsScenario.d.ts.map +1 -0
  61. package/lib/commands/devDeviceAppsScenario.js +97 -0
  62. package/lib/commands/devDeviceAppsScenario.js.map +1 -0
  63. package/lib/commands/deviceAppVersion.d.ts +19 -0
  64. package/lib/commands/deviceAppVersion.d.ts.map +1 -0
  65. package/lib/commands/deviceAppVersion.js +17 -0
  66. package/lib/commands/deviceAppVersion.js.map +1 -0
  67. package/lib/commands/deviceInfo.d.ts +14 -0
  68. package/lib/commands/deviceInfo.d.ts.map +1 -0
  69. package/lib/commands/deviceInfo.js +17 -0
  70. package/lib/commands/deviceInfo.js.map +1 -0
  71. package/lib/commands/deviceVersion.d.ts +14 -0
  72. package/lib/commands/deviceVersion.d.ts.map +1 -0
  73. package/lib/commands/deviceVersion.js +17 -0
  74. package/lib/commands/deviceVersion.js.map +1 -0
  75. package/lib/commands/discoverDevices.d.ts +23 -0
  76. package/lib/commands/discoverDevices.d.ts.map +1 -0
  77. package/lib/commands/discoverDevices.js +86 -0
  78. package/lib/commands/discoverDevices.js.map +1 -0
  79. package/lib/commands/envs.d.ts +7 -0
  80. package/lib/commands/envs.d.ts.map +1 -0
  81. package/lib/commands/envs.js +15 -0
  82. package/lib/commands/envs.js.map +1 -0
  83. package/lib/commands/estimateMaxSpendable.d.ts +41 -0
  84. package/lib/commands/estimateMaxSpendable.d.ts.map +1 -0
  85. package/lib/commands/estimateMaxSpendable.js +65 -0
  86. package/lib/commands/estimateMaxSpendable.js.map +1 -0
  87. package/lib/commands/exportAccounts.d.ts +48 -0
  88. package/lib/commands/exportAccounts.d.ts.map +1 -0
  89. package/lib/commands/exportAccounts.js +69 -0
  90. package/lib/commands/exportAccounts.js.map +1 -0
  91. package/lib/commands/firmwareRepair.d.ts +22 -0
  92. package/lib/commands/firmwareRepair.d.ts.map +1 -0
  93. package/lib/commands/firmwareRepair.js +23 -0
  94. package/lib/commands/firmwareRepair.js.map +1 -0
  95. package/lib/commands/firmwareUpdate.d.ts +26 -0
  96. package/lib/commands/firmwareUpdate.d.ts.map +1 -0
  97. package/lib/commands/firmwareUpdate.js +154 -0
  98. package/lib/commands/firmwareUpdate.js.map +1 -0
  99. package/lib/commands/generateAppJsonFromDataset.d.ts +7 -0
  100. package/lib/commands/generateAppJsonFromDataset.d.ts.map +1 -0
  101. package/lib/commands/generateAppJsonFromDataset.js +212 -0
  102. package/lib/commands/generateAppJsonFromDataset.js.map +1 -0
  103. package/lib/commands/generateTestScanAccounts.d.ts +49 -0
  104. package/lib/commands/generateTestScanAccounts.d.ts.map +1 -0
  105. package/lib/commands/generateTestScanAccounts.js +60 -0
  106. package/lib/commands/generateTestScanAccounts.js.map +1 -0
  107. package/lib/commands/generateTestTransaction.d.ts +44 -0
  108. package/lib/commands/generateTestTransaction.d.ts.map +1 -0
  109. package/lib/commands/generateTestTransaction.js +118 -0
  110. package/lib/commands/generateTestTransaction.js.map +1 -0
  111. package/lib/commands/genuineCheck.d.ts +15 -0
  112. package/lib/commands/genuineCheck.d.ts.map +1 -0
  113. package/lib/commands/genuineCheck.js +22 -0
  114. package/lib/commands/genuineCheck.js.map +1 -0
  115. package/lib/commands/getAddress.d.ts +28 -0
  116. package/lib/commands/getAddress.d.ts.map +1 -0
  117. package/lib/commands/getAddress.js +53 -0
  118. package/lib/commands/getAddress.js.map +1 -0
  119. package/lib/commands/getTransactionStatus.d.ts +52 -0
  120. package/lib/commands/getTransactionStatus.d.ts.map +1 -0
  121. package/lib/commands/getTransactionStatus.js +86 -0
  122. package/lib/commands/getTransactionStatus.js.map +1 -0
  123. package/lib/commands/liveData.d.ts +49 -0
  124. package/lib/commands/liveData.d.ts.map +1 -0
  125. package/lib/commands/liveData.js +82 -0
  126. package/lib/commands/liveData.js.map +1 -0
  127. package/lib/commands/makeCompoundSummary.d.ts +54 -0
  128. package/lib/commands/makeCompoundSummary.d.ts.map +1 -0
  129. package/lib/commands/makeCompoundSummary.js +190 -0
  130. package/lib/commands/makeCompoundSummary.js.map +1 -0
  131. package/lib/commands/managerListApps.d.ts +21 -0
  132. package/lib/commands/managerListApps.d.ts.map +1 -0
  133. package/lib/commands/managerListApps.js +47 -0
  134. package/lib/commands/managerListApps.js.map +1 -0
  135. package/lib/commands/portfolio.d.ts +66 -0
  136. package/lib/commands/portfolio.d.ts.map +1 -0
  137. package/lib/commands/portfolio.js +138 -0
  138. package/lib/commands/portfolio.js.map +1 -0
  139. package/lib/commands/proxy.d.ts +36 -0
  140. package/lib/commands/proxy.d.ts.map +1 -0
  141. package/lib/commands/proxy.js +413 -0
  142. package/lib/commands/proxy.js.map +1 -0
  143. package/lib/commands/receive.d.ts +48 -0
  144. package/lib/commands/receive.d.ts.map +1 -0
  145. package/lib/commands/receive.js +68 -0
  146. package/lib/commands/receive.js.map +1 -0
  147. package/lib/commands/repl.d.ts +22 -0
  148. package/lib/commands/repl.d.ts.map +1 -0
  149. package/lib/commands/repl.js +26 -0
  150. package/lib/commands/repl.js.map +1 -0
  151. package/lib/commands/satstack.d.ts +37 -0
  152. package/lib/commands/satstack.d.ts.map +1 -0
  153. package/lib/commands/satstack.js +110 -0
  154. package/lib/commands/satstack.js.map +1 -0
  155. package/lib/commands/satstackStatus.d.ts +13 -0
  156. package/lib/commands/satstackStatus.d.ts.map +1 -0
  157. package/lib/commands/satstackStatus.js +24 -0
  158. package/lib/commands/satstackStatus.js.map +1 -0
  159. package/lib/commands/scanDescriptors.d.ts +15 -0
  160. package/lib/commands/scanDescriptors.d.ts.map +1 -0
  161. package/lib/commands/scanDescriptors.js +18 -0
  162. package/lib/commands/scanDescriptors.js.map +1 -0
  163. package/lib/commands/send.d.ts +48 -0
  164. package/lib/commands/send.d.ts.map +1 -0
  165. package/lib/commands/send.js +116 -0
  166. package/lib/commands/send.js.map +1 -0
  167. package/lib/commands/signMessage.d.ts +16 -0
  168. package/lib/commands/signMessage.d.ts.map +1 -0
  169. package/lib/commands/signMessage.js +58 -0
  170. package/lib/commands/signMessage.js.map +1 -0
  171. package/lib/commands/speculosList.d.ts +7 -0
  172. package/lib/commands/speculosList.d.ts.map +1 -0
  173. package/lib/commands/speculosList.js +71 -0
  174. package/lib/commands/speculosList.js.map +1 -0
  175. package/lib/commands/swap.d.ts +55 -0
  176. package/lib/commands/swap.d.ts.map +1 -0
  177. package/lib/commands/swap.js +341 -0
  178. package/lib/commands/swap.js.map +1 -0
  179. package/lib/commands/sync.d.ts +49 -0
  180. package/lib/commands/sync.d.ts.map +1 -0
  181. package/lib/commands/sync.js +135 -0
  182. package/lib/commands/sync.js.map +1 -0
  183. package/lib/commands/testDetectOpCollision.d.ts +41 -0
  184. package/lib/commands/testDetectOpCollision.d.ts.map +1 -0
  185. package/lib/commands/testDetectOpCollision.js +57 -0
  186. package/lib/commands/testDetectOpCollision.js.map +1 -0
  187. package/lib/commands/testGetTrustedInputFromTxHash.d.ts +23 -0
  188. package/lib/commands/testGetTrustedInputFromTxHash.d.ts.map +1 -0
  189. package/lib/commands/testGetTrustedInputFromTxHash.js +114 -0
  190. package/lib/commands/testGetTrustedInputFromTxHash.js.map +1 -0
  191. package/lib/commands/user.d.ts +6 -0
  192. package/lib/commands/user.d.ts.map +1 -0
  193. package/lib/commands/user.js +9 -0
  194. package/lib/commands/user.js.map +1 -0
  195. package/lib/commands/version.d.ts +7 -0
  196. package/lib/commands/version.d.ts.map +1 -0
  197. package/lib/commands/version.js +12 -0
  198. package/lib/commands/version.js.map +1 -0
  199. package/lib/commands/walletconnect.d.ts +62 -0
  200. package/lib/commands/walletconnect.d.ts.map +1 -0
  201. package/lib/commands/walletconnect.js +272 -0
  202. package/lib/commands/walletconnect.js.map +1 -0
  203. package/lib/commands-index.d.ts +1511 -0
  204. package/lib/commands-index.d.ts.map +1 -0
  205. package/lib/commands-index.js +106 -0
  206. package/lib/commands-index.js.map +1 -0
  207. package/lib/live-common-setup-base.d.ts +2 -0
  208. package/lib/live-common-setup-base.d.ts.map +1 -0
  209. package/lib/live-common-setup-base.js +131 -0
  210. package/lib/live-common-setup-base.js.map +1 -0
  211. package/lib/live-common-setup.d.ts +5 -0
  212. package/lib/live-common-setup.d.ts.map +1 -0
  213. package/lib/live-common-setup.js +318 -0
  214. package/lib/live-common-setup.js.map +1 -0
  215. package/lib/qr.d.ts +3 -0
  216. package/lib/qr.d.ts.map +1 -0
  217. package/lib/qr.js +18 -0
  218. package/lib/qr.js.map +1 -0
  219. package/lib/scan.d.ts +71 -0
  220. package/lib/scan.d.ts.map +1 -0
  221. package/lib/scan.js +299 -0
  222. package/lib/scan.js.map +1 -0
  223. package/lib/signedOperation.d.ts +13 -0
  224. package/lib/signedOperation.d.ts.map +1 -0
  225. package/lib/signedOperation.js +31 -0
  226. package/lib/signedOperation.js.map +1 -0
  227. package/lib/stream.d.ts +7 -0
  228. package/lib/stream.d.ts.map +1 -0
  229. package/lib/stream.js +82 -0
  230. package/lib/stream.js.map +1 -0
  231. package/lib/transaction.d.ts +31 -0
  232. package/lib/transaction.d.ts.map +1 -0
  233. package/lib/transaction.js +202 -0
  234. package/lib/transaction.js.map +1 -0
  235. package/package.json +63 -0
@@ -0,0 +1,66 @@
1
+ import type { ScanCommonOpts } from "../scan";
2
+ declare const _default: {
3
+ description: string;
4
+ args: ({
5
+ name: string;
6
+ alias: string;
7
+ type: StringConstructor;
8
+ desc: string;
9
+ } | {
10
+ name: string;
11
+ type: StringConstructor;
12
+ desc: string;
13
+ multiple: boolean;
14
+ typeDesc?: undefined;
15
+ alias?: undefined;
16
+ } | {
17
+ name: string;
18
+ type: StringConstructor;
19
+ typeDesc: string;
20
+ desc: string;
21
+ multiple?: undefined;
22
+ alias?: undefined;
23
+ } | {
24
+ name: string;
25
+ alias: string;
26
+ type: NumberConstructor;
27
+ desc: string;
28
+ multiple?: undefined;
29
+ typeDesc?: undefined;
30
+ } | {
31
+ name: string;
32
+ type: NumberConstructor;
33
+ desc: string;
34
+ multiple?: undefined;
35
+ typeDesc?: undefined;
36
+ alias?: undefined;
37
+ } | {
38
+ name: string;
39
+ type: StringConstructor;
40
+ desc: string;
41
+ alias?: undefined;
42
+ } | {
43
+ name: string;
44
+ alias: string;
45
+ type: BooleanConstructor;
46
+ desc: string;
47
+ })[];
48
+ job: (opts: Partial<Partial<{
49
+ device: string;
50
+ id: string[];
51
+ xpub: string[];
52
+ file: string;
53
+ appjsonFile: string;
54
+ currency: string;
55
+ scheme: string;
56
+ index: number;
57
+ length: number;
58
+ paginateOperations: number;
59
+ }> & {
60
+ disableAutofillGaps: boolean;
61
+ countervalue: string;
62
+ period: string;
63
+ }>) => import("rxjs").Observable<string>;
64
+ };
65
+ export default _default;
66
+ //# sourceMappingURL=portfolio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../../src/commands/portfolio.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0CjB,OAAO;sBACd,MAAM;gBACZ,MAAM;;;AA3BtB,wBAgJE"}
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ exports.__esModule = true;
31
+ var bignumber_js_1 = require("bignumber.js");
32
+ var asciichart_1 = __importDefault(require("asciichart"));
33
+ var invariant_1 = __importDefault(require("invariant"));
34
+ var rxjs_1 = require("rxjs");
35
+ var operators_1 = require("rxjs/operators");
36
+ var account_1 = require("@ledgerhq/live-common/lib/account");
37
+ var v2_1 = require("@ledgerhq/live-common/lib/portfolio/v2");
38
+ var range_1 = require("@ledgerhq/live-common/lib/portfolio/v2/range");
39
+ var currencies_1 = require("@ledgerhq/live-common/lib/currencies");
40
+ var scan_1 = require("../scan");
41
+ var logic_1 = require("@ledgerhq/live-common/lib/countervalues/logic");
42
+ function asPortfolioRange(period) {
43
+ var ranges = (0, range_1.getRanges)();
44
+ (0, invariant_1["default"])(ranges.includes(period), "invalid period. valid values are %s", ranges.join(" | "));
45
+ return period;
46
+ }
47
+ exports["default"] = {
48
+ description: "Get a portfolio summary for accounts",
49
+ args: __spreadArray(__spreadArray([], __read(scan_1.scanCommonOpts), false), [
50
+ {
51
+ name: "countervalue",
52
+ type: String,
53
+ desc: "ticker of a currency"
54
+ },
55
+ {
56
+ name: "period",
57
+ alias: "p",
58
+ type: String,
59
+ desc: (0, range_1.getRanges)().join(" | ")
60
+ },
61
+ {
62
+ name: "disableAutofillGaps",
63
+ alias: "g",
64
+ type: Boolean,
65
+ desc: "if set, disable the autofill of gaps to evaluate the rates availability"
66
+ },
67
+ ], false),
68
+ job: function (opts) {
69
+ var countervalue = (0, currencies_1.findCurrencyByTicker)(opts.countervalue || "USD");
70
+ (0, invariant_1["default"])(countervalue, "currency not found with ticker=" + opts.countervalue);
71
+ return (0, scan_1.scan)(opts).pipe((0, operators_1.reduce)(function (all, a) { return all.concat(a); }, []), (0, operators_1.concatMap)(function (accounts) {
72
+ return (0, rxjs_1.from)((0, logic_1.loadCountervalues)(logic_1.initialState, {
73
+ trackingPairs: (0, logic_1.inferTrackingPairForAccounts)(accounts, countervalue),
74
+ autofillGaps: !opts.disableAutofillGaps
75
+ })).pipe((0, operators_1.map)(function (state) {
76
+ var all = (0, account_1.flattenAccounts)(accounts);
77
+ var period = asPortfolioRange(opts.period || "month");
78
+ var unit = countervalue.units[0];
79
+ function render(title, accounts) {
80
+ var portfolio = (0, v2_1.getPortfolio)(accounts, period, state, countervalue);
81
+ var balance = portfolio.balanceHistory[portfolio.balanceHistory.length - 1]
82
+ .value;
83
+ return (title +
84
+ " " +
85
+ (0, currencies_1.formatCurrencyUnit)(unit, new bignumber_js_1.BigNumber(balance), {
86
+ showCode: true,
87
+ disableRounding: true
88
+ }) +
89
+ (portfolio.countervalueChange.percentage
90
+ ? " ::: " +
91
+ "on a " +
92
+ period +
93
+ " period: " +
94
+ Math.round(portfolio.countervalueChange.percentage * 100).toString() +
95
+ "% (" +
96
+ (0, currencies_1.formatCurrencyUnit)(unit, new bignumber_js_1.BigNumber(portfolio.countervalueChange.value), {
97
+ showCode: true
98
+ }) +
99
+ ")"
100
+ : "") +
101
+ "\n" +
102
+ asciichart_1["default"].plot(portfolio.balanceHistory.map(function (h) {
103
+ return new bignumber_js_1.BigNumber(h.value)
104
+ .div(new bignumber_js_1.BigNumber(10).pow(unit.magnitude))
105
+ .toNumber();
106
+ }), {
107
+ height: 10,
108
+ format: function (value) {
109
+ return (0, currencies_1.formatCurrencyUnit)(unit, new bignumber_js_1.BigNumber(value).times(new bignumber_js_1.BigNumber(10).pow(unit.magnitude)), {
110
+ showCode: true,
111
+ disableRounding: true
112
+ }).padStart(20);
113
+ }
114
+ }));
115
+ }
116
+ var str = "";
117
+ accounts.forEach(function (top) {
118
+ str += render("Account " + (0, account_1.getAccountName)(top), [top]);
119
+ str += "\n";
120
+ if (top.subAccounts) {
121
+ top.subAccounts.forEach(function (sub) {
122
+ str += render("Account " +
123
+ (0, account_1.getAccountName)(top) +
124
+ " > " +
125
+ (0, account_1.getAccountName)(sub), [sub]).replace(/\n/s, " \n");
126
+ str += "\n";
127
+ });
128
+ }
129
+ str += "\n";
130
+ });
131
+ str += "\n";
132
+ str += render("SUMMARY OF PORTFOLIO: " + all.length + " accounts, total of ", accounts);
133
+ return str;
134
+ }));
135
+ }));
136
+ }
137
+ };
138
+ //# sourceMappingURL=portfolio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portfolio.js","sourceRoot":"","sources":["../../src/commands/portfolio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyC;AACzC,0DAAoC;AACpC,wDAAkC;AAClC,6BAA4B;AAC5B,4CAAwD;AAMxD,6DAG2C;AAC3C,6DAAsE;AACtE,sEAAyE;AACzE,mEAG8C;AAC9C,gC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IAAI,IAAI,CAAC;gBACZ,GAAG,IAAI,MAAM,CACX,wBAAwB,GAAG,GAAG,CAAC,MAAM,GAAG,sBAAsB,EAC9D,QAAQ,CACT,CAAC;gBACF,OAAO,GAAG,CAAC;YACb,CAAC,CAAC,CACH;QArGD,CAqGC,CACF,CACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { Observable } from "rxjs";
2
+ declare const _default: {
3
+ args: ({
4
+ name: string;
5
+ alias: string;
6
+ type: StringConstructor;
7
+ descOpt: string;
8
+ desc: string;
9
+ } | {
10
+ name: string;
11
+ alias: string;
12
+ type: StringConstructor;
13
+ desc: string;
14
+ } | {
15
+ name: string;
16
+ alias: string;
17
+ type: BooleanConstructor;
18
+ desc: string;
19
+ } | {
20
+ name: string;
21
+ type: BooleanConstructor;
22
+ desc: string;
23
+ alias?: undefined;
24
+ })[];
25
+ job: ({ device, file, record, port, silent, verbose, "disable-auto-skip": noAutoSkip, }: {
26
+ device: any;
27
+ file: any;
28
+ record: any;
29
+ port: any;
30
+ silent: any;
31
+ verbose: any;
32
+ "disable-auto-skip": any;
33
+ }) => Observable<unknown>;
34
+ };
35
+ export default _default;
36
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/commands/proxy.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6UlC,wBAGE"}
@@ -0,0 +1,413 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __read = (this && this.__read) || function (o, n) {
39
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
40
+ if (!m) return o;
41
+ var i = m.call(o), r, ar = [], e;
42
+ try {
43
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
+ }
45
+ catch (error) { e = { error: error }; }
46
+ finally {
47
+ try {
48
+ if (r && !r.done && (m = i["return"])) m.call(i);
49
+ }
50
+ finally { if (e) throw e.error; }
51
+ }
52
+ return ar;
53
+ };
54
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
+ if (ar || !(i in from)) {
57
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
+ ar[i] = from[i];
59
+ }
60
+ }
61
+ return to.concat(ar || Array.prototype.slice.call(from));
62
+ };
63
+ var __importDefault = (this && this.__importDefault) || function (mod) {
64
+ return (mod && mod.__esModule) ? mod : { "default": mod };
65
+ };
66
+ exports.__esModule = true;
67
+ /* eslint-disable global-require */
68
+ var hw_transport_mocker_1 = require("@ledgerhq/hw-transport-mocker");
69
+ var logs_1 = require("@ledgerhq/logs");
70
+ var hw_1 = require("@ledgerhq/live-common/lib/hw");
71
+ var fs_1 = __importDefault(require("fs"));
72
+ var http_1 = __importDefault(require("http"));
73
+ var express_1 = __importDefault(require("express"));
74
+ var cors_1 = __importDefault(require("cors"));
75
+ var ws_1 = __importDefault(require("ws"));
76
+ var body_parser_1 = __importDefault(require("body-parser"));
77
+ var os_1 = __importDefault(require("os"));
78
+ var rxjs_1 = require("rxjs");
79
+ var scan_1 = require("../scan");
80
+ var args = [
81
+ scan_1.deviceOpt,
82
+ {
83
+ name: "file",
84
+ alias: "f",
85
+ type: String,
86
+ desc: "in combination with --record, will save all the proxied APDUs to a provided file. If --record is not provided, proxy will start in replay mode of the provided file. If --file is not used at all, the proxy will just act as a proxy without saving the APDU."
87
+ },
88
+ {
89
+ name: "verbose",
90
+ alias: "v",
91
+ type: Boolean,
92
+ desc: "verbose mode"
93
+ },
94
+ {
95
+ name: "silent",
96
+ alias: "s",
97
+ type: Boolean,
98
+ desc: "do not output the proxy logs"
99
+ },
100
+ {
101
+ name: "disable-auto-skip",
102
+ type: Boolean,
103
+ desc: "auto skip apdu that don't replay instead of error"
104
+ },
105
+ {
106
+ name: "port",
107
+ alias: "p",
108
+ type: String,
109
+ desc: "specify the http port to use (default: 8435)"
110
+ },
111
+ {
112
+ name: "record",
113
+ alias: "r",
114
+ type: Boolean,
115
+ desc: "see the description of --file"
116
+ },
117
+ ];
118
+ var job = function (_a) {
119
+ var device = _a.device, file = _a.file, record = _a.record, port = _a.port, silent = _a.silent, verbose = _a.verbose, noAutoSkip = _a["disable-auto-skip"];
120
+ return new rxjs_1.Observable(function (o) {
121
+ var unsub = (0, logs_1.listen)(function (l) {
122
+ if (verbose) {
123
+ o.next(l.type + ": " + l.message);
124
+ }
125
+ else if (!silent && l.type === "proxy") {
126
+ o.next(l.message);
127
+ }
128
+ });
129
+ var Transport;
130
+ var saveToFile = null;
131
+ var recordStore;
132
+ var getTransportLike = function () {
133
+ return {
134
+ open: function () { return (0, hw_1.open)(device || ""); },
135
+ create: function () { return (0, hw_1.open)(device || ""); }
136
+ };
137
+ };
138
+ // --file <file>
139
+ // There are two ways to use the mock, either you record or you replay
140
+ // record: using --record means that it's a decoration in node-hid that will just save to a file
141
+ // replay: without --record, it's going to re-use a recorded file and mock a transport instead of using an actual device
142
+ if (file) {
143
+ if (record) {
144
+ (0, logs_1.log)("proxy", "the APDUs will be recorded in ".concat(file));
145
+ saveToFile = file;
146
+ recordStore = new hw_transport_mocker_1.RecordStore([]);
147
+ // FIXME: ok this is the funky part with `DecoratedTransport`, ignoring for now cuz it's bullshit typings
148
+ // Has to be tackled during refacto
149
+ // @ts-expect-error getTransportLike should return a Partial<Transport> and createTransportRecorder should accept it
150
+ Transport = (0, hw_transport_mocker_1.createTransportRecorder)(getTransportLike(), recordStore);
151
+ }
152
+ else {
153
+ recordStore = hw_transport_mocker_1.RecordStore.fromString(fs_1["default"].readFileSync(file, "utf8"), {
154
+ autoSkipUnknownApdu: !noAutoSkip
155
+ });
156
+ if (recordStore.isEmpty()) {
157
+ process.exit(0);
158
+ }
159
+ (0, logs_1.log)("proxy", "".concat(recordStore.queue.length, " mocked APDUs will be replayed from ").concat(file));
160
+ Transport = {
161
+ open: function () { return (0, hw_transport_mocker_1.openTransportReplayer)(recordStore); },
162
+ create: function () { return (0, hw_transport_mocker_1.openTransportReplayer)(recordStore); }
163
+ };
164
+ }
165
+ }
166
+ else {
167
+ Transport = getTransportLike();
168
+ }
169
+ var ifaces = os_1["default"].networkInterfaces();
170
+ var ips = Object.keys(ifaces)
171
+ .reduce(function (acc, ifname) {
172
+ return acc.concat(ifaces[ifname].map(function (iface) {
173
+ if (iface.family !== "IPv4" || iface.internal !== false) {
174
+ // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
175
+ return;
176
+ }
177
+ return iface.address;
178
+ }));
179
+ }, [])
180
+ .filter(function (a) { return a; });
181
+ var PORT = port || "8435";
182
+ var app = (0, express_1["default"])();
183
+ var server = http_1["default"].createServer(app);
184
+ var wss = new ws_1["default"].Server({
185
+ server: server
186
+ });
187
+ app.use((0, cors_1["default"])());
188
+ app.get("/", function (req, res) {
189
+ res.sendStatus(200);
190
+ });
191
+ if (recordStore) {
192
+ app.post("/end", function (req, res) {
193
+ try {
194
+ if (!saveToFile) {
195
+ recordStore.ensureQueueEmpty();
196
+ }
197
+ res.sendStatus(200);
198
+ process.exit(0);
199
+ }
200
+ catch (e) {
201
+ res.sendStatus(400);
202
+ console.error(e.message);
203
+ process.exit(1);
204
+ }
205
+ });
206
+ }
207
+ var pending = false;
208
+ app.post("/", body_parser_1["default"].json(), function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
209
+ var data, error, transport, e_1, result;
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0:
213
+ if (!req.body)
214
+ return [2 /*return*/, res.sendStatus(400)];
215
+ data = null;
216
+ error = null;
217
+ if (pending) {
218
+ return [2 /*return*/, res.status(400).json({
219
+ error: "an exchange query was already pending"
220
+ })];
221
+ }
222
+ pending = true;
223
+ _a.label = 1;
224
+ case 1:
225
+ _a.trys.push([1, 7, , 8]);
226
+ return [4 /*yield*/, Transport.open()];
227
+ case 2:
228
+ transport = _a.sent();
229
+ _a.label = 3;
230
+ case 3:
231
+ _a.trys.push([3, , 5, 6]);
232
+ return [4 /*yield*/, transport.exchange(Buffer.from(req.body.apduHex, "hex"))];
233
+ case 4:
234
+ data = _a.sent();
235
+ return [3 /*break*/, 6];
236
+ case 5:
237
+ transport.close();
238
+ if (saveToFile) {
239
+ fs_1["default"].writeFileSync(saveToFile, recordStore.toString());
240
+ }
241
+ else if (recordStore) {
242
+ if (recordStore.isEmpty()) {
243
+ process.exit(0);
244
+ }
245
+ }
246
+ return [7 /*endfinally*/];
247
+ case 6: return [3 /*break*/, 8];
248
+ case 7:
249
+ e_1 = _a.sent();
250
+ error = e_1.toString();
251
+ return [3 /*break*/, 8];
252
+ case 8:
253
+ pending = false;
254
+ result = {
255
+ data: data,
256
+ error: error
257
+ };
258
+ if (data) {
259
+ // @ts-expect-error 3 args only, we give 5
260
+ (0, logs_1.log)("proxy", "HTTP:", req.body.apduHex, "=>", data.toString("hex"));
261
+ }
262
+ else {
263
+ // @ts-expect-error 3 args only, we give 5
264
+ (0, logs_1.log)("proxy", "HTTP:", req.body.apduHex, "=>", error);
265
+ }
266
+ res.json(result);
267
+ if (error && error.name === "RecordStoreWrongAPDU") {
268
+ console.error(error.message);
269
+ process.exit(1);
270
+ }
271
+ return [2 /*return*/];
272
+ }
273
+ });
274
+ }); });
275
+ var wsIndex = 0;
276
+ var wsBusyIndex = 0;
277
+ wss.on("connection", function (ws) {
278
+ var index = ++wsIndex;
279
+ try {
280
+ var transport_1;
281
+ var transportP_1;
282
+ var destroyed_1 = false;
283
+ var onClose = function () { return __awaiter(void 0, void 0, void 0, function () {
284
+ return __generator(this, function (_a) {
285
+ switch (_a.label) {
286
+ case 0:
287
+ if (destroyed_1)
288
+ return [2 /*return*/];
289
+ destroyed_1 = true;
290
+ if (!(wsBusyIndex === index)) return [3 /*break*/, 2];
291
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): close"));
292
+ return [4 /*yield*/, transportP_1.then(function (t) { return t.close(); }, function () { })];
293
+ case 1:
294
+ _a.sent();
295
+ wsBusyIndex = 0;
296
+ _a.label = 2;
297
+ case 2:
298
+ if (saveToFile) {
299
+ fs_1["default"].writeFileSync(saveToFile, recordStore.toString());
300
+ }
301
+ else if (recordStore) {
302
+ if (recordStore.isEmpty()) {
303
+ process.exit(0);
304
+ }
305
+ }
306
+ return [2 /*return*/];
307
+ }
308
+ });
309
+ }); };
310
+ ws.on("close", onClose);
311
+ ws.on("message", function (apduHex) { return __awaiter(void 0, void 0, void 0, function () {
312
+ var e_2, res, e_3;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0:
316
+ if (destroyed_1)
317
+ return [2 /*return*/];
318
+ if (!(apduHex === "open")) return [3 /*break*/, 5];
319
+ if (wsBusyIndex) {
320
+ ws.send(JSON.stringify({
321
+ error: "WebSocket is busy (previous session not closed)"
322
+ }));
323
+ ws.close();
324
+ destroyed_1 = true;
325
+ return [2 /*return*/];
326
+ }
327
+ transportP_1 = Transport.open();
328
+ wsBusyIndex = index;
329
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): opening..."));
330
+ _a.label = 1;
331
+ case 1:
332
+ _a.trys.push([1, 3, , 4]);
333
+ return [4 /*yield*/, transportP_1];
334
+ case 2:
335
+ transport_1 = _a.sent();
336
+ transport_1.on("disconnect", function () { return ws.close(); });
337
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): opened!"));
338
+ ws.send(JSON.stringify({
339
+ type: "opened"
340
+ }));
341
+ return [3 /*break*/, 4];
342
+ case 3:
343
+ e_2 = _a.sent();
344
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): open failed! ").concat(e_2));
345
+ ws.send(JSON.stringify({
346
+ error: e_2.message
347
+ }));
348
+ ws.close();
349
+ return [3 /*break*/, 4];
350
+ case 4: return [2 /*return*/];
351
+ case 5:
352
+ if (wsBusyIndex !== index) {
353
+ console.warn("ignoring message because busy transport");
354
+ return [2 /*return*/];
355
+ }
356
+ if (!transport_1) {
357
+ console.warn("received message before device was opened");
358
+ return [2 /*return*/];
359
+ }
360
+ _a.label = 6;
361
+ case 6:
362
+ _a.trys.push([6, 8, , 9]);
363
+ return [4 /*yield*/, transport_1.exchange(Buffer.from(apduHex, "hex"))];
364
+ case 7:
365
+ res = _a.sent();
366
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): ").concat(apduHex, " => ").concat(res.toString("hex")));
367
+ if (destroyed_1)
368
+ return [2 /*return*/];
369
+ ws.send(JSON.stringify({
370
+ type: "response",
371
+ data: res.toString("hex")
372
+ }));
373
+ return [3 /*break*/, 9];
374
+ case 8:
375
+ e_3 = _a.sent();
376
+ (0, logs_1.log)("proxy", "WS(".concat(index, "): ").concat(apduHex, " =>"), e_3);
377
+ if (destroyed_1)
378
+ return [2 /*return*/];
379
+ ws.send(JSON.stringify({
380
+ type: "error",
381
+ error: e_3.message
382
+ }));
383
+ if (e_3.name === "RecordStoreWrongAPDU") {
384
+ console.error(e_3.message);
385
+ process.exit(1);
386
+ }
387
+ return [3 /*break*/, 9];
388
+ case 9: return [2 /*return*/];
389
+ }
390
+ });
391
+ }); });
392
+ }
393
+ catch (e) {
394
+ ws.close();
395
+ }
396
+ });
397
+ __spreadArray(["localhost"], __read(ips), false).map(function (ip) { return "ws://".concat(ip, ":").concat(PORT); })
398
+ .forEach(function (ip) {
399
+ (0, logs_1.log)("proxy", "DEVICE_PROXY_URL=" + ip);
400
+ });
401
+ server.listen(PORT, function () {
402
+ (0, logs_1.log)("proxy", "\nNano S proxy started on ".concat(ips[0], "\n"));
403
+ });
404
+ return function () {
405
+ unsub();
406
+ };
407
+ });
408
+ };
409
+ exports["default"] = {
410
+ args: args,
411
+ job: job
412
+ };
413
+ //# sourceMappingURL=proxy.js.map