@ledgerhq/hw-transport-node-hid-singleton 6.28.10-recover-beta.0 → 6.28.11-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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +25 -5
- package/lib/TransportNodeHid.d.ts +1 -1
- package/lib/TransportNodeHid.d.ts.map +1 -1
- package/lib/TransportNodeHid.js +117 -195
- package/lib/TransportNodeHid.js.map +1 -1
- package/lib/listenDevices.d.ts +1 -1
- package/lib/listenDevices.d.ts.map +1 -1
- package/lib/listenDevices.js +23 -29
- package/lib/listenDevices.js.map +1 -1
- package/lib-es/TransportNodeHid.d.ts +1 -1
- package/lib-es/TransportNodeHid.d.ts.map +1 -1
- package/lib-es/TransportNodeHid.js +108 -187
- package/lib-es/TransportNodeHid.js.map +1 -1
- package/lib-es/listenDevices.d.ts +1 -1
- package/lib-es/listenDevices.d.ts.map +1 -1
- package/lib-es/listenDevices.js +19 -25
- package/lib-es/listenDevices.js.map +1 -1
- package/package.json +7 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/hw-transport-node-hid-singleton@6.28.10
|
|
2
|
+
> @ledgerhq/hw-transport-node-hid-singleton@6.28.10 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-transport-node-hid-singleton
|
|
3
3
|
> tsc && tsc -m ES6 --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
# @ledgerhq/hw-transport-node-hid-singleton
|
|
2
2
|
|
|
3
|
-
## 6.28.
|
|
3
|
+
## 6.28.11-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`87d2349fd8`](https://github.com/LedgerHQ/ledger-live/commit/87d2349fd835e5deb39d1ee8dfcf3539f4195472)]:
|
|
8
|
+
- @ledgerhq/errors@6.12.5-next.0
|
|
9
|
+
- @ledgerhq/devices@8.0.2-next.0
|
|
10
|
+
- @ledgerhq/hw-transport@6.28.3-next.0
|
|
11
|
+
- @ledgerhq/hw-transport-node-hid-noevents@6.27.14-next.0
|
|
12
|
+
|
|
13
|
+
## 6.28.10
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`1d0b2d19eb`](https://github.com/LedgerHQ/ledger-live/commit/1d0b2d19ebc5acd058930b842c6d37f8daf2a5a3), [`ef945b05c0`](https://github.com/LedgerHQ/ledger-live/commit/ef945b05c01a791281687abb28e639e1bcc4e472), [`5fa68510b4`](https://github.com/LedgerHQ/ledger-live/commit/5fa68510b49334cfd80c30793dfe68900f1b9b3b)]:
|
|
18
|
+
- @ledgerhq/errors@6.12.4
|
|
19
|
+
- @ledgerhq/devices@8.0.1
|
|
20
|
+
- @ledgerhq/hw-transport@6.28.2
|
|
21
|
+
- @ledgerhq/hw-transport-node-hid-noevents@6.27.13
|
|
22
|
+
|
|
23
|
+
## 6.28.10-next.0
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
6
26
|
|
|
7
27
|
- Updated dependencies [[`1d0b2d19eb`](https://github.com/LedgerHQ/ledger-live/commit/1d0b2d19ebc5acd058930b842c6d37f8daf2a5a3), [`ef945b05c0`](https://github.com/LedgerHQ/ledger-live/commit/ef945b05c01a791281687abb28e639e1bcc4e472), [`5fa68510b4`](https://github.com/LedgerHQ/ledger-live/commit/5fa68510b49334cfd80c30793dfe68900f1b9b3b)]:
|
|
8
|
-
- @ledgerhq/errors@6.12.4-
|
|
9
|
-
- @ledgerhq/devices@8.0.1-
|
|
10
|
-
- @ledgerhq/hw-transport@6.28.2-
|
|
11
|
-
- @ledgerhq/hw-transport-node-hid-noevents@6.27.13-
|
|
28
|
+
- @ledgerhq/errors@6.12.4-next.0
|
|
29
|
+
- @ledgerhq/devices@8.0.1-next.0
|
|
30
|
+
- @ledgerhq/hw-transport@6.28.2-next.0
|
|
31
|
+
- @ledgerhq/hw-transport-node-hid-noevents@6.27.13-next.0
|
|
12
32
|
|
|
13
33
|
## 6.28.9
|
|
14
34
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
3
3
|
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
|
|
4
|
-
export
|
|
4
|
+
export type ListenDescriptorEvent = DescriptorEvent<any>;
|
|
5
5
|
/**
|
|
6
6
|
* node-hid Transport implementation
|
|
7
7
|
* @example
|
|
@@ -1 +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;AAwBhC,
|
|
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;AAwBhC,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;AAEzD;;;;;;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,qBAAqB,CAAC,KAAG,YAAY,CAqDvE;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"}
|
package/lib/TransportNodeHid.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -46,65 +31,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
46
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
32
|
});
|
|
48
33
|
};
|
|
49
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
-
function step(op) {
|
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
-
while (_) try {
|
|
56
|
-
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;
|
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
-
switch (op[0]) {
|
|
59
|
-
case 0: case 1: t = op; break;
|
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
-
default:
|
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
-
if (t[2]) _.ops.pop();
|
|
69
|
-
_.trys.pop(); continue;
|
|
70
|
-
}
|
|
71
|
-
op = body.call(thisArg, _);
|
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var __values = (this && this.__values) || function(o) {
|
|
77
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
78
|
-
if (m) return m.call(o);
|
|
79
|
-
if (o && typeof o.length === "number") return {
|
|
80
|
-
next: function () {
|
|
81
|
-
if (o && i >= o.length) o = void 0;
|
|
82
|
-
return { value: o && o[i++], done: !o };
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
86
|
-
};
|
|
87
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
88
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
89
36
|
};
|
|
90
|
-
exports
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const node_hid_1 = __importDefault(require("node-hid"));
|
|
39
|
+
const hw_transport_node_hid_noevents_1 = __importStar(require("@ledgerhq/hw-transport-node-hid-noevents"));
|
|
40
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
41
|
+
const devices_1 = require("@ledgerhq/devices");
|
|
42
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
43
|
+
const listenDevices_1 = require("./listenDevices");
|
|
44
|
+
let transportInstance;
|
|
45
|
+
const DISCONNECT_TIMEOUT = 5000;
|
|
46
|
+
let disconnectTimeout;
|
|
47
|
+
const clearDisconnectTimeout = () => {
|
|
101
48
|
if (disconnectTimeout) {
|
|
102
49
|
clearTimeout(disconnectTimeout);
|
|
103
50
|
}
|
|
104
51
|
};
|
|
105
|
-
|
|
52
|
+
const setDisconnectTimeout = () => {
|
|
106
53
|
clearDisconnectTimeout();
|
|
107
|
-
disconnectTimeout = setTimeout(
|
|
54
|
+
disconnectTimeout = setTimeout(() => TransportNodeHidSingleton.autoDisconnect(), DISCONNECT_TIMEOUT);
|
|
108
55
|
};
|
|
109
56
|
/**
|
|
110
57
|
* node-hid Transport implementation
|
|
@@ -113,70 +60,62 @@ var setDisconnectTimeout = function () {
|
|
|
113
60
|
* ...
|
|
114
61
|
* TransportNodeHid.create().then(transport => ...)
|
|
115
62
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_this.preventAutoDisconnect = false;
|
|
121
|
-
return _this;
|
|
63
|
+
class TransportNodeHidSingleton extends hw_transport_node_hid_noevents_1.default {
|
|
64
|
+
constructor() {
|
|
65
|
+
super(...arguments);
|
|
66
|
+
this.preventAutoDisconnect = false;
|
|
122
67
|
}
|
|
123
68
|
/**
|
|
124
69
|
* convenience wrapper for auto-disconnect logic
|
|
125
70
|
*/
|
|
126
|
-
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return [2 /*return*/];
|
|
139
|
-
});
|
|
71
|
+
static autoDisconnect() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (transportInstance && !transportInstance.preventAutoDisconnect) {
|
|
74
|
+
(0, logs_1.log)("hid-verbose", "triggering auto disconnect");
|
|
75
|
+
TransportNodeHidSingleton.disconnect();
|
|
76
|
+
}
|
|
77
|
+
else if (transportInstance) {
|
|
78
|
+
// If we have disabled the auto-disconnect, try again in DISCONNECT_TIMEOUT
|
|
79
|
+
clearDisconnectTimeout();
|
|
80
|
+
setDisconnectTimeout();
|
|
81
|
+
}
|
|
140
82
|
});
|
|
141
|
-
}
|
|
83
|
+
}
|
|
142
84
|
/**
|
|
143
85
|
* globally disconnect the transport singleton
|
|
144
86
|
*/
|
|
145
|
-
|
|
146
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
clearDisconnectTimeout();
|
|
154
|
-
return [2 /*return*/];
|
|
155
|
-
});
|
|
87
|
+
static disconnect() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (transportInstance) {
|
|
90
|
+
transportInstance.device.close();
|
|
91
|
+
transportInstance.emit("disconnect");
|
|
92
|
+
transportInstance = null;
|
|
93
|
+
}
|
|
94
|
+
clearDisconnectTimeout();
|
|
156
95
|
});
|
|
157
|
-
}
|
|
96
|
+
}
|
|
158
97
|
/**
|
|
159
98
|
* if path="" is not provided, the library will take the first device
|
|
160
99
|
*/
|
|
161
|
-
|
|
100
|
+
static open() {
|
|
162
101
|
clearDisconnectTimeout();
|
|
163
|
-
return Promise.resolve().then(
|
|
102
|
+
return Promise.resolve().then(() => {
|
|
164
103
|
if (transportInstance) {
|
|
165
104
|
(0, logs_1.log)("hid-verbose", "reusing opened transport instance");
|
|
166
105
|
return transportInstance;
|
|
167
106
|
}
|
|
168
|
-
|
|
107
|
+
const device = (0, hw_transport_node_hid_noevents_1.getDevices)()[0];
|
|
169
108
|
if (!device)
|
|
170
109
|
throw new errors_1.CantOpenDevice("no device found");
|
|
171
110
|
(0, logs_1.log)("hid-verbose", "new HID transport");
|
|
172
|
-
transportInstance = new TransportNodeHidSingleton(new node_hid_1
|
|
173
|
-
|
|
111
|
+
transportInstance = new TransportNodeHidSingleton(new node_hid_1.default.HID(device.path));
|
|
112
|
+
const unlisten = (0, listenDevices_1.listenDevices)(() => { }, () => {
|
|
174
113
|
// assume any ledger disconnection concerns current transport
|
|
175
114
|
if (transportInstance) {
|
|
176
115
|
transportInstance.emit("disconnect");
|
|
177
116
|
}
|
|
178
117
|
});
|
|
179
|
-
|
|
118
|
+
const onDisconnect = () => {
|
|
180
119
|
if (!transportInstance)
|
|
181
120
|
return;
|
|
182
121
|
(0, logs_1.log)("hid-verbose", "transport instance was disconnected");
|
|
@@ -187,108 +126,91 @@ var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
|
187
126
|
transportInstance.on("disconnect", onDisconnect);
|
|
188
127
|
return transportInstance;
|
|
189
128
|
});
|
|
190
|
-
}
|
|
191
|
-
|
|
129
|
+
}
|
|
130
|
+
setAllowAutoDisconnect(allow) {
|
|
192
131
|
this.preventAutoDisconnect = !allow;
|
|
193
|
-
}
|
|
132
|
+
}
|
|
194
133
|
/**
|
|
195
134
|
* Exchange with the device using APDU protocol.
|
|
196
135
|
* @param apdu
|
|
197
136
|
* @returns a promise of apdu response
|
|
198
137
|
*/
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return __generator(this, function (_a) {
|
|
203
|
-
switch (_a.label) {
|
|
204
|
-
case 0:
|
|
205
|
-
clearDisconnectTimeout();
|
|
206
|
-
return [4 /*yield*/, _super.prototype.exchange.call(this, apdu)];
|
|
207
|
-
case 1:
|
|
208
|
-
result = _a.sent();
|
|
209
|
-
setDisconnectTimeout();
|
|
210
|
-
return [2 /*return*/, result];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
138
|
+
exchange(apdu) {
|
|
139
|
+
const _super = Object.create(null, {
|
|
140
|
+
exchange: { get: () => super.exchange }
|
|
213
141
|
});
|
|
214
|
-
|
|
215
|
-
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
clearDisconnectTimeout();
|
|
144
|
+
const result = yield _super.exchange.call(this, apdu);
|
|
145
|
+
setDisconnectTimeout();
|
|
146
|
+
return result;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
close() {
|
|
216
150
|
// intentionally, a close will not effectively close the hid connection but
|
|
217
151
|
// will allow an auto-disconnection after some inactivity
|
|
218
152
|
this.preventAutoDisconnect = false;
|
|
219
153
|
return Promise.resolve();
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
253
|
-
finally {
|
|
254
|
-
try {
|
|
255
|
-
if (devices_2_1 && !devices_2_1.done && (_a = devices_2["return"])) _a.call(devices_2);
|
|
256
|
-
}
|
|
257
|
-
finally { if (e_1) throw e_1.error; }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.default = TransportNodeHidSingleton;
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
TransportNodeHidSingleton.isSupported = hw_transport_node_hid_noevents_1.default.isSupported;
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
TransportNodeHidSingleton.list = hw_transport_node_hid_noevents_1.default.list;
|
|
165
|
+
/**
|
|
166
|
+
*/
|
|
167
|
+
TransportNodeHidSingleton.listen = (observer) => {
|
|
168
|
+
let unsubscribed;
|
|
169
|
+
Promise.resolve((0, hw_transport_node_hid_noevents_1.getDevices)()).then((devices) => {
|
|
170
|
+
// this needs to run asynchronously so the subscription is defined during this phase
|
|
171
|
+
for (const device of devices) {
|
|
172
|
+
if (!unsubscribed) {
|
|
173
|
+
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
174
|
+
observer.next({
|
|
175
|
+
type: "add",
|
|
176
|
+
descriptor: "",
|
|
177
|
+
device: {
|
|
178
|
+
name: device.deviceName,
|
|
179
|
+
},
|
|
180
|
+
deviceModel,
|
|
181
|
+
});
|
|
258
182
|
}
|
|
259
|
-
});
|
|
260
|
-
var onAdd = function (device) {
|
|
261
|
-
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
262
|
-
observer.next({
|
|
263
|
-
type: "add",
|
|
264
|
-
descriptor: "",
|
|
265
|
-
deviceModel: deviceModel,
|
|
266
|
-
device: {
|
|
267
|
-
name: device.deviceName
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
var onRemove = function (device) {
|
|
272
|
-
var deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
273
|
-
observer.next({
|
|
274
|
-
type: "remove",
|
|
275
|
-
descriptor: "",
|
|
276
|
-
deviceModel: deviceModel,
|
|
277
|
-
device: {
|
|
278
|
-
name: device.deviceName
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
var stop = (0, listenDevices_1.listenDevices)(onAdd, onRemove);
|
|
283
|
-
function unsubscribe() {
|
|
284
|
-
stop();
|
|
285
|
-
unsubscribed = true;
|
|
286
183
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
184
|
+
});
|
|
185
|
+
const onAdd = (device) => {
|
|
186
|
+
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
187
|
+
observer.next({
|
|
188
|
+
type: "add",
|
|
189
|
+
descriptor: "",
|
|
190
|
+
deviceModel,
|
|
191
|
+
device: {
|
|
192
|
+
name: device.deviceName,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const onRemove = (device) => {
|
|
197
|
+
const deviceModel = (0, devices_1.identifyUSBProductId)(device.productId);
|
|
198
|
+
observer.next({
|
|
199
|
+
type: "remove",
|
|
200
|
+
descriptor: "",
|
|
201
|
+
deviceModel,
|
|
202
|
+
device: {
|
|
203
|
+
name: device.deviceName,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
const stop = (0, listenDevices_1.listenDevices)(onAdd, onRemove);
|
|
208
|
+
function unsubscribe() {
|
|
209
|
+
stop();
|
|
210
|
+
unsubscribed = true;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
unsubscribe,
|
|
290
214
|
};
|
|
291
|
-
|
|
292
|
-
}(hw_transport_node_hid_noevents_1["default"]));
|
|
293
|
-
exports["default"] = TransportNodeHidSingleton;
|
|
215
|
+
};
|
|
294
216
|
//# sourceMappingURL=TransportNodeHid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAC3B,2GAEkD;AAMlD,yCAAqC;AACrC,+CAAyD;AACzD,6CAAkD;AAClD,mDAAgD;AAEhD,IAAI,iBAAiB,CAAC;AAEtB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,IAAI,iBAAiB,CAAC;AACtB,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,IAAI,iBAAiB,EAAE;QACrB,YAAY,CAAC,iBAAiB,CAAC,CAAC;KACjC;AACH,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAChC,sBAAsB,EAAE,CAAC;IACzB,iBAAiB,GAAG,UAAU,CAC5B,GAAG,EAAE,CAAC,yBAAyB,CAAC,cAAc,EAAE,EAChD,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC;AAIF;;;;;;GAMG;AAEH,MAAqB,yBAA0B,SAAQ,wCAAwB;IAA/E;;QACE,0BAAqB,GAAG,KAAK,CAAC;IA4JhC,CAAC;IAxFC;;OAEG;IACH,MAAM,CAAO,cAAc;;YACzB,IAAI,iBAAiB,IAAI,CAAC,iBAAiB,CAAC,qBAAqB,EAAE;gBACjE,IAAA,UAAG,EAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;gBACjD,yBAAyB,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AAC,SAAS,CAAC,CAAC;gBAC3D,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,KAAK;oBACX,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE;wBACN,IAAI,EAAE,MAAM,CAAC,UAAU;qBACxB;oBACD,WAAW;iBACZ,CAAC,CAAC;aACJ;SACF;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,EAAE;QACvB,MAAM,WAAW,GAAG,IAAA,8BAAoB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,KAAK;YACX,UAAU,EAAE,EAAE;YACd,WAAW;YACX,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC,UAAU;aACxB;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;QAC1B,MAAM,WAAW,GAAG,IAAA,8BAAoB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,WAAW;YACX,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC,UAAU;aACxB;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,IAAA,6BAAa,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE5C,SAAS,WAAW;QAClB,IAAI,EAAE,CAAC;QACP,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO;QACL,WAAW;KACZ,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/listenDevices.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,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;AAUF,eAAO,MAAM,cAAc,MAAO,MAAM,SAEvC,CAAC;AAqBF,eAAO,MAAM,aAAa,iBACV,MAAM,KAAK,IAAI,mBACZ,MAAM,KAAK,IAAI,eAqCjC,CAAC"}
|
package/lib/listenDevices.js
CHANGED
|
@@ -1,47 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.listenDevices = exports.setUsbDebounce = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
var usbDebounce = 1000;
|
|
12
|
-
var setUsbDebounce = function (n) {
|
|
4
|
+
const usb_1 = require("usb");
|
|
5
|
+
const devices_1 = require("@ledgerhq/devices");
|
|
6
|
+
const logs_1 = require("@ledgerhq/logs");
|
|
7
|
+
const deviceToLog = ({ deviceDescriptor: { idProduct }, busNumber, deviceAddress, }) => `productId=${idProduct} busNumber=${busNumber} deviceAddress=${deviceAddress}`;
|
|
8
|
+
let usbDebounce = 1000;
|
|
9
|
+
const setUsbDebounce = (n) => {
|
|
13
10
|
usbDebounce = n;
|
|
14
11
|
};
|
|
15
12
|
exports.setUsbDebounce = setUsbDebounce;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
deviceAddress: deviceAddress
|
|
26
|
-
});
|
|
27
|
-
};
|
|
13
|
+
const mapRawDevice = ({ busNumber: locationId, deviceAddress, deviceDescriptor: { idVendor: vendorId, idProduct: productId, iSerialNumber: serialNumber, }, }) => ({
|
|
14
|
+
locationId,
|
|
15
|
+
vendorId,
|
|
16
|
+
productId,
|
|
17
|
+
deviceName: "",
|
|
18
|
+
manufacturer: "",
|
|
19
|
+
serialNumber,
|
|
20
|
+
deviceAddress,
|
|
21
|
+
});
|
|
28
22
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
const listenDevices = (onAdd, onRemove) => {
|
|
24
|
+
let timeout;
|
|
25
|
+
const add = (device) => {
|
|
32
26
|
if (device.deviceDescriptor.idVendor !== devices_1.ledgerUSBVendorId)
|
|
33
27
|
return;
|
|
34
28
|
(0, logs_1.log)("usb-detection", "add: " + deviceToLog(device));
|
|
35
29
|
if (!timeout) {
|
|
36
30
|
// a time is needed for the device to actually be connectable over HID..
|
|
37
31
|
// we also take this time to not emit the device yet and potentially cancel it if a remove happens.
|
|
38
|
-
timeout = setTimeout(
|
|
32
|
+
timeout = setTimeout(() => {
|
|
39
33
|
onAdd(mapRawDevice(device));
|
|
40
34
|
timeout = null;
|
|
41
35
|
}, usbDebounce);
|
|
42
36
|
}
|
|
43
37
|
};
|
|
44
|
-
|
|
38
|
+
const remove = (device) => {
|
|
45
39
|
if (device.deviceDescriptor.idVendor !== devices_1.ledgerUSBVendorId)
|
|
46
40
|
return;
|
|
47
41
|
(0, logs_1.log)("usb-detection", "remove: " + deviceToLog(device));
|
|
@@ -55,14 +49,14 @@ var listenDevices = function (onAdd, onRemove) {
|
|
|
55
49
|
};
|
|
56
50
|
usb_1.usb.on("attach", add);
|
|
57
51
|
usb_1.usb.on("detach", remove);
|
|
58
|
-
return
|
|
52
|
+
return () => {
|
|
59
53
|
if (timeout)
|
|
60
54
|
clearTimeout(timeout);
|
|
61
55
|
usb_1.usb.unrefHotplugEvents();
|
|
62
56
|
};
|
|
63
57
|
};
|
|
64
58
|
exports.listenDevices = listenDevices;
|
|
65
|
-
process.on("exit",
|
|
59
|
+
process.on("exit", () => {
|
|
66
60
|
usb_1.usb.unrefHotplugEvents();
|
|
67
61
|
});
|
|
68
62
|
//# sourceMappingURL=listenDevices.js.map
|
package/lib/listenDevices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,+CAAsD;AACtD,yCAAqC;AAYrC,MAAM,WAAW,GAAG,CAAC,EACnB,gBAAgB,EAAE,EAAE,SAAS,EAAE,EAC/B,SAAS,EACT,aAAa,GACd,EAAE,EAAE,CACH,aAAa,SAAS,cAAc,SAAS,kBAAkB,aAAa,EAAE,CAAC;AAEjF,IAAI,WAAW,GAAG,IAAI,CAAC;AAChB,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,EAAE;IAC1C,WAAW,GAAG,CAAC,CAAC;AAClB,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEF,MAAM,YAAY,GAAG,CAAC,EACpB,SAAS,EAAE,UAAU,EACrB,aAAa,EACb,gBAAgB,EAAE,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,YAAY,GAC5B,GACU,EAAU,EAAE,CAAC,CAAC;IACzB,UAAU;IACV,QAAQ;IACR,SAAS;IACT,UAAU,EAAE,EAAE;IACd,YAAY,EAAE,EAAE;IAChB,YAAY;IACZ,aAAa;CACd,CAAC,CAAC;AAEH,6EAA6E;AACtE,MAAM,aAAa,GAAG,CAC3B,KAA6B,EAC7B,QAAgC,EAChC,EAAE;IACF,IAAI,OAAO,CAAC;IA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C;AAC3B,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
3
3
|
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
|
|
4
|
-
export
|
|
4
|
+
export type ListenDescriptorEvent = DescriptorEvent<any>;
|
|
5
5
|
/**
|
|
6
6
|
* node-hid Transport implementation
|
|
7
7
|
* @example
|
|
@@ -1 +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;AAwBhC,
|
|
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;AAwBhC,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;AAEzD;;;;;;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,qBAAqB,CAAC,KAAG,YAAY,CAqDvE;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,18 +1,3 @@
|
|
|
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
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -22,61 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
22
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
8
|
});
|
|
24
9
|
};
|
|
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
10
|
import HID from "node-hid";
|
|
64
11
|
import TransportNodeHidNoEvents, { getDevices, } from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
65
12
|
import { log } from "@ledgerhq/logs";
|
|
66
13
|
import { identifyUSBProductId } from "@ledgerhq/devices";
|
|
67
14
|
import { CantOpenDevice } from "@ledgerhq/errors";
|
|
68
15
|
import { listenDevices } from "./listenDevices";
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
16
|
+
let transportInstance;
|
|
17
|
+
const DISCONNECT_TIMEOUT = 5000;
|
|
18
|
+
let disconnectTimeout;
|
|
19
|
+
const clearDisconnectTimeout = () => {
|
|
73
20
|
if (disconnectTimeout) {
|
|
74
21
|
clearTimeout(disconnectTimeout);
|
|
75
22
|
}
|
|
76
23
|
};
|
|
77
|
-
|
|
24
|
+
const setDisconnectTimeout = () => {
|
|
78
25
|
clearDisconnectTimeout();
|
|
79
|
-
disconnectTimeout = setTimeout(
|
|
26
|
+
disconnectTimeout = setTimeout(() => TransportNodeHidSingleton.autoDisconnect(), DISCONNECT_TIMEOUT);
|
|
80
27
|
};
|
|
81
28
|
/**
|
|
82
29
|
* node-hid Transport implementation
|
|
@@ -85,70 +32,62 @@ var setDisconnectTimeout = function () {
|
|
|
85
32
|
* ...
|
|
86
33
|
* TransportNodeHid.create().then(transport => ...)
|
|
87
34
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
_this.preventAutoDisconnect = false;
|
|
93
|
-
return _this;
|
|
35
|
+
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.preventAutoDisconnect = false;
|
|
94
39
|
}
|
|
95
40
|
/**
|
|
96
41
|
* convenience wrapper for auto-disconnect logic
|
|
97
42
|
*/
|
|
98
|
-
|
|
99
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
});
|
|
43
|
+
static autoDisconnect() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (transportInstance && !transportInstance.preventAutoDisconnect) {
|
|
46
|
+
log("hid-verbose", "triggering auto disconnect");
|
|
47
|
+
TransportNodeHidSingleton.disconnect();
|
|
48
|
+
}
|
|
49
|
+
else if (transportInstance) {
|
|
50
|
+
// If we have disabled the auto-disconnect, try again in DISCONNECT_TIMEOUT
|
|
51
|
+
clearDisconnectTimeout();
|
|
52
|
+
setDisconnectTimeout();
|
|
53
|
+
}
|
|
112
54
|
});
|
|
113
|
-
}
|
|
55
|
+
}
|
|
114
56
|
/**
|
|
115
57
|
* globally disconnect the transport singleton
|
|
116
58
|
*/
|
|
117
|
-
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
clearDisconnectTimeout();
|
|
126
|
-
return [2 /*return*/];
|
|
127
|
-
});
|
|
59
|
+
static disconnect() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
if (transportInstance) {
|
|
62
|
+
transportInstance.device.close();
|
|
63
|
+
transportInstance.emit("disconnect");
|
|
64
|
+
transportInstance = null;
|
|
65
|
+
}
|
|
66
|
+
clearDisconnectTimeout();
|
|
128
67
|
});
|
|
129
|
-
}
|
|
68
|
+
}
|
|
130
69
|
/**
|
|
131
70
|
* if path="" is not provided, the library will take the first device
|
|
132
71
|
*/
|
|
133
|
-
|
|
72
|
+
static open() {
|
|
134
73
|
clearDisconnectTimeout();
|
|
135
|
-
return Promise.resolve().then(
|
|
74
|
+
return Promise.resolve().then(() => {
|
|
136
75
|
if (transportInstance) {
|
|
137
76
|
log("hid-verbose", "reusing opened transport instance");
|
|
138
77
|
return transportInstance;
|
|
139
78
|
}
|
|
140
|
-
|
|
79
|
+
const device = getDevices()[0];
|
|
141
80
|
if (!device)
|
|
142
81
|
throw new CantOpenDevice("no device found");
|
|
143
82
|
log("hid-verbose", "new HID transport");
|
|
144
83
|
transportInstance = new TransportNodeHidSingleton(new HID.HID(device.path));
|
|
145
|
-
|
|
84
|
+
const unlisten = listenDevices(() => { }, () => {
|
|
146
85
|
// assume any ledger disconnection concerns current transport
|
|
147
86
|
if (transportInstance) {
|
|
148
87
|
transportInstance.emit("disconnect");
|
|
149
88
|
}
|
|
150
89
|
});
|
|
151
|
-
|
|
90
|
+
const onDisconnect = () => {
|
|
152
91
|
if (!transportInstance)
|
|
153
92
|
return;
|
|
154
93
|
log("hid-verbose", "transport instance was disconnected");
|
|
@@ -159,108 +98,90 @@ var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
|
159
98
|
transportInstance.on("disconnect", onDisconnect);
|
|
160
99
|
return transportInstance;
|
|
161
100
|
});
|
|
162
|
-
}
|
|
163
|
-
|
|
101
|
+
}
|
|
102
|
+
setAllowAutoDisconnect(allow) {
|
|
164
103
|
this.preventAutoDisconnect = !allow;
|
|
165
|
-
}
|
|
104
|
+
}
|
|
166
105
|
/**
|
|
167
106
|
* Exchange with the device using APDU protocol.
|
|
168
107
|
* @param apdu
|
|
169
108
|
* @returns a promise of apdu response
|
|
170
109
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
});
|
|
110
|
+
exchange(apdu) {
|
|
111
|
+
const _super = Object.create(null, {
|
|
112
|
+
exchange: { get: () => super.exchange }
|
|
185
113
|
});
|
|
186
|
-
|
|
187
|
-
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
clearDisconnectTimeout();
|
|
116
|
+
const result = yield _super.exchange.call(this, apdu);
|
|
117
|
+
setDisconnectTimeout();
|
|
118
|
+
return result;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
close() {
|
|
188
122
|
// intentionally, a close will not effectively close the hid connection but
|
|
189
123
|
// will allow an auto-disconnection after some inactivity
|
|
190
124
|
this.preventAutoDisconnect = false;
|
|
191
125
|
return Promise.resolve();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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; }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
TransportNodeHidSingleton.isSupported = TransportNodeHidNoEvents.isSupported;
|
|
132
|
+
/**
|
|
133
|
+
*
|
|
134
|
+
*/
|
|
135
|
+
TransportNodeHidSingleton.list = TransportNodeHidNoEvents.list;
|
|
136
|
+
/**
|
|
137
|
+
*/
|
|
138
|
+
TransportNodeHidSingleton.listen = (observer) => {
|
|
139
|
+
let unsubscribed;
|
|
140
|
+
Promise.resolve(getDevices()).then((devices) => {
|
|
141
|
+
// this needs to run asynchronously so the subscription is defined during this phase
|
|
142
|
+
for (const device of devices) {
|
|
143
|
+
if (!unsubscribed) {
|
|
144
|
+
const deviceModel = identifyUSBProductId(device.productId);
|
|
145
|
+
observer.next({
|
|
146
|
+
type: "add",
|
|
147
|
+
descriptor: "",
|
|
148
|
+
device: {
|
|
149
|
+
name: device.deviceName,
|
|
150
|
+
},
|
|
151
|
+
deviceModel,
|
|
152
|
+
});
|
|
230
153
|
}
|
|
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
154
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
155
|
+
});
|
|
156
|
+
const onAdd = (device) => {
|
|
157
|
+
const deviceModel = identifyUSBProductId(device.productId);
|
|
158
|
+
observer.next({
|
|
159
|
+
type: "add",
|
|
160
|
+
descriptor: "",
|
|
161
|
+
deviceModel,
|
|
162
|
+
device: {
|
|
163
|
+
name: device.deviceName,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const onRemove = (device) => {
|
|
168
|
+
const deviceModel = identifyUSBProductId(device.productId);
|
|
169
|
+
observer.next({
|
|
170
|
+
type: "remove",
|
|
171
|
+
descriptor: "",
|
|
172
|
+
deviceModel,
|
|
173
|
+
device: {
|
|
174
|
+
name: device.deviceName,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const stop = listenDevices(onAdd, onRemove);
|
|
179
|
+
function unsubscribe() {
|
|
180
|
+
stop();
|
|
181
|
+
unsubscribed = true;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
unsubscribe,
|
|
262
185
|
};
|
|
263
|
-
|
|
264
|
-
}(TransportNodeHidNoEvents));
|
|
265
|
-
export default TransportNodeHidSingleton;
|
|
186
|
+
};
|
|
266
187
|
//# sourceMappingURL=TransportNodeHid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TransportNodeHid.js","sourceRoot":"","sources":["../src/TransportNodeHid.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,wBAAwB,EAAE,EAC/B,UAAU,GACX,MAAM,0CAA0C,CAAC;AAMlD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,C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AAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;QAC1B,MAAM,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,WAAW;YACX,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC,UAAU;aACxB;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE5C,SAAS,WAAW;QAClB,IAAI,EAAE,CAAC;QACP,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO;QACL,WAAW;KACZ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"listenDevices.d.ts","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,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;AAUF,eAAO,MAAM,cAAc,MAAO,MAAM,SAEvC,CAAC;AAqBF,eAAO,MAAM,aAAa,iBACV,MAAM,KAAK,IAAI,mBACZ,MAAM,KAAK,IAAI,eAqCjC,CAAC"}
|
package/lib-es/listenDevices.js
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import { usb } from "usb";
|
|
2
2
|
import { ledgerUSBVendorId } from "@ledgerhq/devices";
|
|
3
3
|
import { log } from "@ledgerhq/logs";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
var usbDebounce = 1000;
|
|
9
|
-
export var setUsbDebounce = function (n) {
|
|
4
|
+
const deviceToLog = ({ deviceDescriptor: { idProduct }, busNumber, deviceAddress, }) => `productId=${idProduct} busNumber=${busNumber} deviceAddress=${deviceAddress}`;
|
|
5
|
+
let usbDebounce = 1000;
|
|
6
|
+
export const setUsbDebounce = (n) => {
|
|
10
7
|
usbDebounce = n;
|
|
11
8
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
deviceAddress: deviceAddress
|
|
22
|
-
});
|
|
23
|
-
};
|
|
9
|
+
const mapRawDevice = ({ busNumber: locationId, deviceAddress, deviceDescriptor: { idVendor: vendorId, idProduct: productId, iSerialNumber: serialNumber, }, }) => ({
|
|
10
|
+
locationId,
|
|
11
|
+
vendorId,
|
|
12
|
+
productId,
|
|
13
|
+
deviceName: "",
|
|
14
|
+
manufacturer: "",
|
|
15
|
+
serialNumber,
|
|
16
|
+
deviceAddress,
|
|
17
|
+
});
|
|
24
18
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
export const listenDevices = (onAdd, onRemove) => {
|
|
20
|
+
let timeout;
|
|
21
|
+
const add = (device) => {
|
|
28
22
|
if (device.deviceDescriptor.idVendor !== ledgerUSBVendorId)
|
|
29
23
|
return;
|
|
30
24
|
log("usb-detection", "add: " + deviceToLog(device));
|
|
31
25
|
if (!timeout) {
|
|
32
26
|
// a time is needed for the device to actually be connectable over HID..
|
|
33
27
|
// we also take this time to not emit the device yet and potentially cancel it if a remove happens.
|
|
34
|
-
timeout = setTimeout(
|
|
28
|
+
timeout = setTimeout(() => {
|
|
35
29
|
onAdd(mapRawDevice(device));
|
|
36
30
|
timeout = null;
|
|
37
31
|
}, usbDebounce);
|
|
38
32
|
}
|
|
39
33
|
};
|
|
40
|
-
|
|
34
|
+
const remove = (device) => {
|
|
41
35
|
if (device.deviceDescriptor.idVendor !== ledgerUSBVendorId)
|
|
42
36
|
return;
|
|
43
37
|
log("usb-detection", "remove: " + deviceToLog(device));
|
|
@@ -51,13 +45,13 @@ export var listenDevices = function (onAdd, onRemove) {
|
|
|
51
45
|
};
|
|
52
46
|
usb.on("attach", add);
|
|
53
47
|
usb.on("detach", remove);
|
|
54
|
-
return
|
|
48
|
+
return () => {
|
|
55
49
|
if (timeout)
|
|
56
50
|
clearTimeout(timeout);
|
|
57
51
|
usb.unrefHotplugEvents();
|
|
58
52
|
};
|
|
59
53
|
};
|
|
60
|
-
process.on("exit",
|
|
54
|
+
process.on("exit", () => {
|
|
61
55
|
usb.unrefHotplugEvents();
|
|
62
56
|
});
|
|
63
57
|
//# sourceMappingURL=listenDevices.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAYrC,
|
|
1
|
+
{"version":3,"file":"listenDevices.js","sourceRoot":"","sources":["../src/listenDevices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAYrC,MAAM,WAAW,GAAG,CAAC,EACnB,gBAAgB,EAAE,EAAE,SAAS,EAAE,EAC/B,SAAS,EACT,aAAa,GACd,EAAE,EAAE,CACH,aAAa,SAAS,cAAc,SAAS,k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M,CAAC,CAAC,CAAC;QAEvD,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,IAAI,CAAC;SAChB;aAAM;YACL,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;SAChC;IACH,CAAC,CAAC;IAEF,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACtB,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAEzB,OAAO,GAAG,EAAE;QACV,IAAI,OAAO;YAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,GAAG,CAAC,kBAAkB,EAAE,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;IACtB,GAAG,CAAC,kBAAkB,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-transport-node-hid-singleton",
|
|
3
|
-
"version": "6.28.
|
|
3
|
+
"version": "6.28.11-next.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet Node implementation of the communication layer, using node-hid and node-usb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"node-hid": "^2.1.2",
|
|
32
32
|
"usb": "2.5.1",
|
|
33
|
-
"@ledgerhq/devices": "^8.0.
|
|
34
|
-
"@ledgerhq/errors": "^6.12.
|
|
35
|
-
"@ledgerhq/hw-transport": "^6.28.
|
|
36
|
-
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.
|
|
33
|
+
"@ledgerhq/devices": "^8.0.2-next.0",
|
|
34
|
+
"@ledgerhq/errors": "^6.12.5-next.0",
|
|
35
|
+
"@ledgerhq/hw-transport": "^6.28.3-next.0",
|
|
36
|
+
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.14-next.0",
|
|
37
37
|
"@ledgerhq/logs": "^6.10.1"
|
|
38
38
|
},
|
|
39
39
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
@@ -42,11 +42,10 @@
|
|
|
42
42
|
"@types/node": "^18.15.3",
|
|
43
43
|
"documentation": "13.2.4",
|
|
44
44
|
"jest": "^28.1.1",
|
|
45
|
-
"rimraf": "^4.1
|
|
45
|
+
"rimraf": "^4.4.1",
|
|
46
46
|
"source-map-support": "^0.5.21",
|
|
47
47
|
"ts-jest": "^28.0.5",
|
|
48
|
-
"ts-node": "^10.4.0"
|
|
49
|
-
"typescript": "^4"
|
|
48
|
+
"ts-node": "^10.4.0"
|
|
50
49
|
},
|
|
51
50
|
"scripts": {
|
|
52
51
|
"clean": "rimraf lib lib-es",
|