@ledgerhq/hw-transport-node-hid-singleton 6.26.1-monorepo.0 → 6.26.1-monorepo.4

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.
@@ -1,12 +1,5 @@
1
- @ledgerhq/hw-transport-node-hid-singleton:build: cache hit, replaying output 33aa3f61bd38629b
2
- @ledgerhq/hw-transport-node-hid-singleton:build: 
3
- @ledgerhq/hw-transport-node-hid-singleton:build: > @ledgerhq/hw-transport-node-hid-singleton@6.26.0 build /Users/valmeida/projects/live/ledger-live/libs/ledgerjs/packages/hw-transport-node-hid-singleton
4
- @ledgerhq/hw-transport-node-hid-singleton:build: > bash ../../script/build.sh
5
- @ledgerhq/hw-transport-node-hid-singleton:build: 
6
- @ledgerhq/hw-transport-node-hid-singleton:build: src/listenDevices.ts(2,35): error TS2307: Cannot find module '@ledgerhq/devices' or its corresponding type declarations.
7
- @ledgerhq/hw-transport-node-hid-singleton:build: src/listenDevices.ts(3,21): error TS2307: Cannot find module '@ledgerhq/logs' or its corresponding type declarations.
8
- @ledgerhq/hw-transport-node-hid-singleton:build: src/TransportNodeHid.ts(9,8): error TS2307: Cannot find module '@ledgerhq/hw-transport' or its corresponding type declarations.
9
- @ledgerhq/hw-transport-node-hid-singleton:build: src/TransportNodeHid.ts(10,21): error TS2307: Cannot find module '@ledgerhq/logs' or its corresponding type declarations.
10
- @ledgerhq/hw-transport-node-hid-singleton:build: src/TransportNodeHid.ts(11,38): error TS2307: Cannot find module '@ledgerhq/devices' or its corresponding type declarations.
11
- @ledgerhq/hw-transport-node-hid-singleton:build: src/TransportNodeHid.ts(12,32): error TS2307: Cannot find module '@ledgerhq/errors' or its corresponding type declarations.
12
- @ledgerhq/hw-transport-node-hid-singleton:build:  ELIFECYCLE  Command failed with exit code 2.
1
+ @ledgerhq/hw-transport-node-hid-singleton:build: cache hit, replaying output 8ed73b2bf95b9f6e
2
+ @ledgerhq/hw-transport-node-hid-singleton:build:
3
+ @ledgerhq/hw-transport-node-hid-singleton:build: > @ledgerhq/hw-transport-node-hid-singleton@6.26.1-monorepo.4 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-transport-node-hid-singleton
4
+ @ledgerhq/hw-transport-node-hid-singleton:build: > bash ../../script/build.sh
5
+ @ledgerhq/hw-transport-node-hid-singleton:build:
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # @ledgerhq/hw-transport-node-hid-singleton
2
2
 
3
+ ## 6.26.1-monorepo.4
4
+
5
+ ### Patch Changes
6
+
7
+ - f6cb87454: test prerelease
8
+ - Updated dependencies [f6cb87454]
9
+ - @ledgerhq/devices@6.24.2-monorepo.4
10
+ - @ledgerhq/errors@6.10.1-monorepo.4
11
+ - @ledgerhq/hw-transport@6.24.2-monorepo.4
12
+ - @ledgerhq/hw-transport-node-hid-noevents@6.24.2-monorepo.4
13
+ - @ledgerhq/logs@6.10.1-monorepo.4
14
+
15
+ ## 6.26.1-monorepo.3
16
+
17
+ ### Patch Changes
18
+
19
+ - 7f4a91716: clean pnpm-lock file
20
+ - Updated dependencies [7f4a91716]
21
+ - @ledgerhq/devices@6.24.2-monorepo.3
22
+ - @ledgerhq/errors@6.10.1-monorepo.3
23
+ - @ledgerhq/hw-transport@6.24.2-monorepo.3
24
+ - @ledgerhq/hw-transport-node-hid-noevents@6.24.2-monorepo.3
25
+ - @ledgerhq/logs@6.10.1-monorepo.3
26
+
27
+ ## 6.26.1-monorepo.2
28
+
29
+ ### Patch Changes
30
+
31
+ - a439963a7: test prerelease
32
+ - Updated dependencies [a439963a7]
33
+ - @ledgerhq/devices@6.24.2-monorepo.2
34
+ - @ledgerhq/errors@6.10.1-monorepo.2
35
+ - @ledgerhq/hw-transport@6.24.2-monorepo.2
36
+ - @ledgerhq/hw-transport-node-hid-noevents@6.24.2-monorepo.2
37
+ - @ledgerhq/logs@6.10.1-monorepo.2
38
+
39
+ ## 6.26.1-monorepo.1
40
+
41
+ ### Patch Changes
42
+
43
+ - 1b6fec9db: monorepo prelease 2
44
+ - Updated dependencies [1b6fec9db]
45
+ - @ledgerhq/devices@6.24.2-monorepo.1
46
+ - @ledgerhq/errors@6.10.1-monorepo.1
47
+ - @ledgerhq/hw-transport-node-hid-noevents@6.24.2-monorepo.1
48
+ - @ledgerhq/hw-transport@6.24.2-monorepo.1
49
+ - @ledgerhq/logs@6.10.1-monorepo.1
50
+
3
51
  ## 6.26.1-monorepo.0
4
52
 
5
53
  ### Patch Changes
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
3
+ import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
3
4
  /**
4
5
  * node-hid Transport implementation
5
6
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;AA4BlD;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,wBAAwB;IAC7E,qBAAqB,UAAS;IAC9B;;OAEG;IACH,MAAM,CAAC,WAAW,yBAAwC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,qBAAiC;IAE5C;OACG;IACH,MAAM,CAAC,MAAM,6DAqDX;IAEF;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;WACU,UAAU;IASvB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAqCjD,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI5C;;;;OAIG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvB"}
1
+ {"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACb,MAAM,wBAAwB,CAAC;AAuBhC;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,wBAAwB;IAC7E,qBAAqB,UAAS;IAC9B;;OAEG;IACH,MAAM,CAAC,WAAW,yBAAwC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,qBAAiC;IAE5C;OACG;IACH,MAAM,CAAC,MAAM,aAAc,SAAS,gBAAgB,GAAG,CAAC,CAAC,KAAG,YAAY,CAqDtE;IAEF;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;WACU,UAAU;IASvB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAqCjD,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI5C;;;;OAIG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvB"}
@@ -0,0 +1,45 @@
1
+ /// <reference types="node" />
2
+ import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
3
+ import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
4
+ /**
5
+ * node-hid Transport implementation
6
+ * @example
7
+ * import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
8
+ * ...
9
+ * TransportNodeHid.create().then(transport => ...)
10
+ */
11
+ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
12
+ preventAutoDisconnect: boolean;
13
+ /**
14
+ *
15
+ */
16
+ static isSupported: () => Promise<boolean>;
17
+ /**
18
+ *
19
+ */
20
+ static list: () => Promise<any>;
21
+ /**
22
+ */
23
+ static listen: (observer: Observer<DescriptorEvent<any>>) => Subscription;
24
+ /**
25
+ * convenience wrapper for auto-disconnect logic
26
+ */
27
+ static autoDisconnect(): Promise<void>;
28
+ /**
29
+ * globally disconnect the transport singleton
30
+ */
31
+ static disconnect(): Promise<void>;
32
+ /**
33
+ * if path="" is not provided, the library will take the first device
34
+ */
35
+ static open(): Promise<TransportNodeHidSingleton>;
36
+ setAllowAutoDisconnect(allow: boolean): void;
37
+ /**
38
+ * Exchange with the device using APDU protocol.
39
+ * @param apdu
40
+ * @returns a promise of apdu response
41
+ */
42
+ exchange(apdu: Buffer): Promise<Buffer>;
43
+ close(): Promise<void>;
44
+ }
45
+ //# sourceMappingURL=TransportNodeHid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransportNodeHid.d.ts","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";AACA,OAAO,wBAEN,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACb,MAAM,wBAAwB,CAAC;AAuBhC;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,wBAAwB;IAC7E,qBAAqB,UAAS;IAC9B;;OAEG;IACH,MAAM,CAAC,WAAW,yBAAwC;IAE1D;;OAEG;IACH,MAAM,CAAC,IAAI,qBAAiC;IAE5C;OACG;IACH,MAAM,CAAC,MAAM,aAAc,SAAS,gBAAgB,GAAG,CAAC,CAAC,KAAG,YAAY,CAqDtE;IAEF;;OAEG;WACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;WACU,UAAU;IASvB;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAqCjD,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI5C;;;;OAIG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvB"}
@@ -0,0 +1,266 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (_) try {
32
+ 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;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ var __values = (this && this.__values) || function(o) {
53
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
54
+ if (m) return m.call(o);
55
+ if (o && typeof o.length === "number") return {
56
+ next: function () {
57
+ if (o && i >= o.length) o = void 0;
58
+ return { value: o && o[i++], done: !o };
59
+ }
60
+ };
61
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
62
+ };
63
+ import HID from "node-hid";
64
+ import TransportNodeHidNoEvents, { getDevices, } from "@ledgerhq/hw-transport-node-hid-noevents";
65
+ import { log } from "@ledgerhq/logs";
66
+ import { identifyUSBProductId } from "@ledgerhq/devices";
67
+ import { CantOpenDevice } from "@ledgerhq/errors";
68
+ import { listenDevices } from "./listenDevices";
69
+ var transportInstance;
70
+ var DISCONNECT_TIMEOUT = 5000;
71
+ var disconnectTimeout;
72
+ var clearDisconnectTimeout = function () {
73
+ if (disconnectTimeout) {
74
+ clearTimeout(disconnectTimeout);
75
+ }
76
+ };
77
+ var setDisconnectTimeout = function () {
78
+ clearDisconnectTimeout();
79
+ disconnectTimeout = setTimeout(function () { return TransportNodeHidSingleton.autoDisconnect(); }, DISCONNECT_TIMEOUT);
80
+ };
81
+ /**
82
+ * node-hid Transport implementation
83
+ * @example
84
+ * import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
85
+ * ...
86
+ * TransportNodeHid.create().then(transport => ...)
87
+ */
88
+ var TransportNodeHidSingleton = /** @class */ (function (_super) {
89
+ __extends(TransportNodeHidSingleton, _super);
90
+ function TransportNodeHidSingleton() {
91
+ var _this = _super !== null && _super.apply(this, arguments) || this;
92
+ _this.preventAutoDisconnect = false;
93
+ return _this;
94
+ }
95
+ /**
96
+ * convenience wrapper for auto-disconnect logic
97
+ */
98
+ TransportNodeHidSingleton.autoDisconnect = function () {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ if (transportInstance && !transportInstance.preventAutoDisconnect) {
102
+ log("hid-verbose", "triggering auto disconnect");
103
+ TransportNodeHidSingleton.disconnect();
104
+ }
105
+ else if (transportInstance) {
106
+ // If we have disabled the auto-disconnect, try again in DISCONNECT_TIMEOUT
107
+ clearDisconnectTimeout();
108
+ setDisconnectTimeout();
109
+ }
110
+ return [2 /*return*/];
111
+ });
112
+ });
113
+ };
114
+ /**
115
+ * globally disconnect the transport singleton
116
+ */
117
+ TransportNodeHidSingleton.disconnect = function () {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ return __generator(this, function (_a) {
120
+ if (transportInstance) {
121
+ transportInstance.device.close();
122
+ transportInstance.emit("disconnect");
123
+ transportInstance = null;
124
+ }
125
+ clearDisconnectTimeout();
126
+ return [2 /*return*/];
127
+ });
128
+ });
129
+ };
130
+ /**
131
+ * if path="" is not provided, the library will take the first device
132
+ */
133
+ TransportNodeHidSingleton.open = function () {
134
+ clearDisconnectTimeout();
135
+ return Promise.resolve().then(function () {
136
+ if (transportInstance) {
137
+ log("hid-verbose", "reusing opened transport instance");
138
+ return transportInstance;
139
+ }
140
+ var device = getDevices()[0];
141
+ if (!device)
142
+ throw new CantOpenDevice("no device found");
143
+ log("hid-verbose", "new HID transport");
144
+ transportInstance = new TransportNodeHidSingleton(new HID.HID(device.path));
145
+ var unlisten = listenDevices(function () { }, function () {
146
+ // assume any ledger disconnection concerns current transport
147
+ if (transportInstance) {
148
+ transportInstance.emit("disconnect");
149
+ }
150
+ });
151
+ var onDisconnect = function () {
152
+ if (!transportInstance)
153
+ return;
154
+ log("hid-verbose", "transport instance was disconnected");
155
+ transportInstance.off("disconnect", onDisconnect);
156
+ transportInstance = null;
157
+ unlisten();
158
+ };
159
+ transportInstance.on("disconnect", onDisconnect);
160
+ return transportInstance;
161
+ });
162
+ };
163
+ TransportNodeHidSingleton.prototype.setAllowAutoDisconnect = function (allow) {
164
+ this.preventAutoDisconnect = !allow;
165
+ };
166
+ /**
167
+ * Exchange with the device using APDU protocol.
168
+ * @param apdu
169
+ * @returns a promise of apdu response
170
+ */
171
+ TransportNodeHidSingleton.prototype.exchange = function (apdu) {
172
+ return __awaiter(this, void 0, void 0, function () {
173
+ var result;
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0:
177
+ clearDisconnectTimeout();
178
+ return [4 /*yield*/, _super.prototype.exchange.call(this, apdu)];
179
+ case 1:
180
+ result = _a.sent();
181
+ setDisconnectTimeout();
182
+ return [2 /*return*/, result];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ TransportNodeHidSingleton.prototype.close = function () {
188
+ // intentionally, a close will not effectively close the hid connection but
189
+ // will allow an auto-disconnection after some inactivity
190
+ this.preventAutoDisconnect = false;
191
+ return Promise.resolve();
192
+ };
193
+ /**
194
+ *
195
+ */
196
+ TransportNodeHidSingleton.isSupported = TransportNodeHidNoEvents.isSupported;
197
+ /**
198
+ *
199
+ */
200
+ TransportNodeHidSingleton.list = TransportNodeHidNoEvents.list;
201
+ /**
202
+ */
203
+ TransportNodeHidSingleton.listen = function (observer) {
204
+ var unsubscribed;
205
+ Promise.resolve(getDevices()).then(function (devices) {
206
+ var e_1, _a;
207
+ try {
208
+ // this needs to run asynchronously so the subscription is defined during this phase
209
+ for (var devices_1 = __values(devices), devices_1_1 = devices_1.next(); !devices_1_1.done; devices_1_1 = devices_1.next()) {
210
+ var device = devices_1_1.value;
211
+ if (!unsubscribed) {
212
+ var deviceModel = identifyUSBProductId(device.productId);
213
+ observer.next({
214
+ type: "add",
215
+ descriptor: "",
216
+ device: {
217
+ name: device.deviceName
218
+ },
219
+ deviceModel: deviceModel
220
+ });
221
+ }
222
+ }
223
+ }
224
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
225
+ finally {
226
+ try {
227
+ if (devices_1_1 && !devices_1_1.done && (_a = devices_1["return"])) _a.call(devices_1);
228
+ }
229
+ finally { if (e_1) throw e_1.error; }
230
+ }
231
+ });
232
+ var onAdd = function (device) {
233
+ var deviceModel = identifyUSBProductId(device.productId);
234
+ observer.next({
235
+ type: "add",
236
+ descriptor: "",
237
+ deviceModel: deviceModel,
238
+ device: {
239
+ name: device.deviceName
240
+ }
241
+ });
242
+ };
243
+ var onRemove = function (device) {
244
+ var deviceModel = identifyUSBProductId(device.productId);
245
+ observer.next({
246
+ type: "remove",
247
+ descriptor: "",
248
+ deviceModel: deviceModel,
249
+ device: {
250
+ name: device.deviceName
251
+ }
252
+ });
253
+ };
254
+ var stop = listenDevices(onAdd, onRemove);
255
+ function unsubscribe() {
256
+ stop();
257
+ unsubscribed = true;
258
+ }
259
+ return {
260
+ unsubscribe: unsubscribe
261
+ };
262
+ };
263
+ return TransportNodeHidSingleton;
264
+ }(TransportNodeHidNoEvents));
265
+ export default TransportNodeHidSingleton;
266
+ //# sourceMappingURL=TransportNodeHid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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MAAM,CAAC,SAAS,CAAC,CAAC;YAC3D,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,KAAK;gBACX,UAAU,EAAE,EAAE;gBACd,WAAW,aAAA;gBACX,MAAM,EAAE;oBACN,IAAI,EAAE,MAAM,CAAC,UAAU;iBACxB;aACF,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAM,QAAQ,GAAG,UAAC,MAAM;YACtB,IAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC3D,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE;gBACd,WAAW,aAAA;gBACX,MAAM,EAAE;oBACN,IAAI,EAAE,MAAM,CAAC,UAAU;iBACxB;aACF,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE5C,SAAS,WAAW;YAClB,IAAI,EAAE,CAAC;YACP,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,OAAO;YACL,WAAW,aAAA;SACZ,CAAC;IACJ,CAAC,CAAC;IA0FJ,gCAAC;CAAA,AA7JD,CAAuD,wBAAwB,GA6J9E;eA7JoB,yBAAyB"}
@@ -0,0 +1,12 @@
1
+ export declare type Device = {
2
+ locationId: number;
3
+ vendorId: number;
4
+ productId: number;
5
+ deviceName: string;
6
+ manufacturer: string;
7
+ serialNumber: string;
8
+ deviceAddress: number;
9
+ };
10
+ export declare const setUsbDebounce: (n: number) => void;
11
+ export declare const listenDevices: (onAdd: (arg0: Device) => void, onRemove: (arg0: Device) => void) => () => void;
12
+ //# sourceMappingURL=listenDevices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAGA,oBAAY,MAAM,GAAG;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAMF,eAAO,MAAM,cAAc,MAAO,MAAM,SAEvC,CAAC;AAmBF,eAAO,MAAM,aAAa,iBACV,MAAM,KAAK,IAAI,mBACZ,MAAM,KAAK,IAAI,eAyCjC,CAAC"}
@@ -0,0 +1,65 @@
1
+ import usbDetect from "usb-detection";
2
+ import { ledgerUSBVendorId } from "@ledgerhq/devices";
3
+ import { log } from "@ledgerhq/logs";
4
+ var deviceToLog = function (_a) {
5
+ var productId = _a.productId, locationId = _a.locationId, deviceAddress = _a.deviceAddress;
6
+ return "productId=".concat(productId, " locationId=").concat(locationId, " deviceAddress=").concat(deviceAddress);
7
+ };
8
+ var usbDebounce = 1000;
9
+ export var setUsbDebounce = function (n) {
10
+ usbDebounce = n;
11
+ };
12
+ var monitoring = false;
13
+ var monitor = function () {
14
+ if (!monitoring) {
15
+ monitoring = true;
16
+ usbDetect.startMonitoring();
17
+ }
18
+ return function () { };
19
+ };
20
+ // No better way for now. see https://github.com/LedgerHQ/ledgerjs/issues/434
21
+ process.on("exit", function () {
22
+ if (monitoring) {
23
+ // redeem the monitoring so the process can be terminated.
24
+ usbDetect.stopMonitoring();
25
+ }
26
+ });
27
+ export var listenDevices = function (onAdd, onRemove) {
28
+ var unmonitor = monitor();
29
+ var addEvent = "add:" + ledgerUSBVendorId;
30
+ var removeEvent = "remove:" + ledgerUSBVendorId;
31
+ var timeout;
32
+ var add = function (device) {
33
+ log("usb-detection", "add: " + deviceToLog(device));
34
+ if (!timeout) {
35
+ // a time is needed for the device to actually be connectable over HID..
36
+ // we also take this time to not emit the device yet and potentially cancel it if a remove happens.
37
+ timeout = setTimeout(function () {
38
+ onAdd(device);
39
+ timeout = null;
40
+ }, usbDebounce);
41
+ }
42
+ };
43
+ var remove = function (device) {
44
+ log("usb-detection", "remove: " + deviceToLog(device));
45
+ if (timeout) {
46
+ clearTimeout(timeout);
47
+ timeout = null;
48
+ }
49
+ else {
50
+ onRemove(device);
51
+ }
52
+ };
53
+ usbDetect.on(addEvent, add);
54
+ usbDetect.on(removeEvent, remove);
55
+ return function () {
56
+ if (timeout)
57
+ clearTimeout(timeout);
58
+ // @ts-expect-error not all EventEmitter methods are covered in its definition file
59
+ usbDetect.off(addEvent, add);
60
+ // @ts-expect-error not all EventEmitter methods are covered in its definition file
61
+ usbDetect.off(removeEvent, remove);
62
+ unmonitor();
63
+ };
64
+ };
65
+ //# sourceMappingURL=listenDevices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAWrC,IAAM,WAAW,GAAG,UAAC,EAAwC;QAAtC,SAAS,eAAA,EAAE,UAAU,gBAAA,EAAE,aAAa,mBAAA;IACzD,OAAA,oBAAa,SAAS,yBAAe,UAAU,4BAAkB,aAAa,CAAE;AAAhF,CAAgF,CAAC;AAEnF,IAAI,WAAW,GAAG,IAAI,CAAC;AACvB,MAAM,CAAC,IAAM,cAAc,GAAG,UAAC,CAAS;IACtC,WAAW,GAAG,CAAC,CAAC;AAClB,CAAC,CAAC;AACF,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,IAAM,OAAO,GAAG;IACd,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,IAAI,CAAC;QAClB,SAAS,CAAC,eAAe,EAAE,CAAC;KAC7B;IAED,OAAO,cAAO,CAAC,CAAC;AAClB,CAAC,CAAC;AAEF,6EAA6E;AAC7E,OAAO,CAAC,EAAE,CAAC,M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AAmF;QACnF,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACnC,SAAS,EAAE,CAAC;IACd,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/hw-transport-node-hid-singleton",
3
- "version": "6.26.1-monorepo.0",
3
+ "version": "6.26.1-monorepo.4",
4
4
  "description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid and usb-detection",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -27,11 +27,11 @@
27
27
  "types": "lib/TransportNodeHid.d.ts",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@ledgerhq/devices": "^6.24.2-monorepo.0",
31
- "@ledgerhq/errors": "^6.10.1-monorepo.0",
32
- "@ledgerhq/hw-transport": "^6.24.2-monorepo.0",
33
- "@ledgerhq/hw-transport-node-hid-noevents": "^6.24.2-monorepo.0",
34
- "@ledgerhq/logs": "^6.10.1-monorepo.0",
30
+ "@ledgerhq/devices": "^6.24.2-monorepo.4",
31
+ "@ledgerhq/errors": "^6.10.1-monorepo.4",
32
+ "@ledgerhq/hw-transport": "^6.24.2-monorepo.4",
33
+ "@ledgerhq/hw-transport-node-hid-noevents": "^6.24.2-monorepo.4",
34
+ "@ledgerhq/logs": "^6.10.1-monorepo.4",
35
35
  "lodash": "^4.17.21",
36
36
  "node-hid": "2.1.1",
37
37
  "usb-detection": "^4.13.0"