@ledgerhq/hw-transport-node-hid-singleton 6.27.1 → 6.27.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.
- package/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +13 -0
- package/README.md +1 -1
- package/jest.config.ts +6 -0
- package/lib/TransportNodeHid.d.ts +1 -1
- package/lib/TransportNodeHid.d.ts.map +1 -1
- package/lib-es/TransportNodeHid.d.ts +13 -0
- package/lib-es/TransportNodeHid.d.ts.map +1 -1
- package/lib-es/TransportNodeHid.js +62 -2
- package/lib-es/TransportNodeHid.js.map +1 -1
- package/package.json +14 -11
- package/src/TransportNodeHid.ts +1 -1
- package/LICENSE +0 -202
- package/lib-es/TransportNodeHid.js.flow +0 -138
- package/lib-es/listenDevices.js.flow +0 -84
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
@ledgerhq/hw-transport-node-hid-singleton:build: cache hit, replaying output f9e5759e49bb5ad4
|
|
2
|
+
@ledgerhq/hw-transport-node-hid-singleton:build:
|
|
3
|
+
@ledgerhq/hw-transport-node-hid-singleton:build: > @ledgerhq/hw-transport-node-hid-singleton@6.27.1 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:
|
|
6
|
+
@ledgerhq/hw-transport-node-hid-singleton:build: /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-transport-node-hid-singleton
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @ledgerhq/hw-transport-node-hid-singleton
|
|
2
|
+
|
|
3
|
+
## 6.27.2-nightly.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f6f2d8f15: add dummy changesets
|
|
8
|
+
- Updated dependencies [f6f2d8f15]
|
|
9
|
+
- @ledgerhq/devices@6.27.2-nightly.0
|
|
10
|
+
- @ledgerhq/errors@6.10.1-nightly.0
|
|
11
|
+
- @ledgerhq/hw-transport@6.27.2-nightly.0
|
|
12
|
+
- @ledgerhq/hw-transport-node-hid-noevents@6.27.2-nightly.0
|
|
13
|
+
- @ledgerhq/logs@6.10.1-nightly.0
|
package/README.md
CHANGED
package/jest.config.ts
ADDED
|
@@ -24,7 +24,7 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
24
24
|
/**
|
|
25
25
|
* convenience wrapper for auto-disconnect logic
|
|
26
26
|
*/
|
|
27
|
-
static autoDisconnect(): void
|
|
27
|
+
static autoDisconnect(): Promise<void>;
|
|
28
28
|
/**
|
|
29
29
|
* globally disconnect the transport singleton
|
|
30
30
|
*/
|
|
@@ -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;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,IAAI;
|
|
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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import TransportNodeHidNoEvents from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
2
3
|
import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-transport";
|
|
3
4
|
/**
|
|
@@ -8,6 +9,7 @@ import type { Observer, DescriptorEvent, Subscription } from "@ledgerhq/hw-trans
|
|
|
8
9
|
* TransportNodeHid.create().then(transport => ...)
|
|
9
10
|
*/
|
|
10
11
|
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
|
|
12
|
+
preventAutoDisconnect: boolean;
|
|
11
13
|
/**
|
|
12
14
|
*
|
|
13
15
|
*/
|
|
@@ -19,6 +21,10 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
19
21
|
/**
|
|
20
22
|
*/
|
|
21
23
|
static listen: (observer: Observer<DescriptorEvent<any>>) => Subscription;
|
|
24
|
+
/**
|
|
25
|
+
* convenience wrapper for auto-disconnect logic
|
|
26
|
+
*/
|
|
27
|
+
static autoDisconnect(): Promise<void>;
|
|
22
28
|
/**
|
|
23
29
|
* globally disconnect the transport singleton
|
|
24
30
|
*/
|
|
@@ -27,6 +33,13 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
27
33
|
* if path="" is not provided, the library will take the first device
|
|
28
34
|
*/
|
|
29
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>;
|
|
30
43
|
close(): Promise<void>;
|
|
31
44
|
}
|
|
32
45
|
//# sourceMappingURL=TransportNodeHid.d.ts.map
|
|
@@ -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;
|
|
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"}
|
|
@@ -67,6 +67,17 @@ import { identifyUSBProductId } from "@ledgerhq/devices";
|
|
|
67
67
|
import { CantOpenDevice } from "@ledgerhq/errors";
|
|
68
68
|
import { listenDevices } from "./listenDevices";
|
|
69
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
|
+
};
|
|
70
81
|
/**
|
|
71
82
|
* node-hid Transport implementation
|
|
72
83
|
* @example
|
|
@@ -77,8 +88,29 @@ var transportInstance;
|
|
|
77
88
|
var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
78
89
|
__extends(TransportNodeHidSingleton, _super);
|
|
79
90
|
function TransportNodeHidSingleton() {
|
|
80
|
-
|
|
91
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
92
|
+
_this.preventAutoDisconnect = false;
|
|
93
|
+
return _this;
|
|
81
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
|
+
};
|
|
82
114
|
/**
|
|
83
115
|
* globally disconnect the transport singleton
|
|
84
116
|
*/
|
|
@@ -90,6 +122,7 @@ var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
|
90
122
|
transportInstance.emit("disconnect");
|
|
91
123
|
transportInstance = null;
|
|
92
124
|
}
|
|
125
|
+
clearDisconnectTimeout();
|
|
93
126
|
return [2 /*return*/];
|
|
94
127
|
});
|
|
95
128
|
});
|
|
@@ -98,6 +131,7 @@ var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
|
98
131
|
* if path="" is not provided, the library will take the first device
|
|
99
132
|
*/
|
|
100
133
|
TransportNodeHidSingleton.open = function () {
|
|
134
|
+
clearDisconnectTimeout();
|
|
101
135
|
return Promise.resolve().then(function () {
|
|
102
136
|
if (transportInstance) {
|
|
103
137
|
log("hid-verbose", "reusing opened transport instance");
|
|
@@ -126,8 +160,34 @@ var TransportNodeHidSingleton = /** @class */ (function (_super) {
|
|
|
126
160
|
return transportInstance;
|
|
127
161
|
});
|
|
128
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
|
+
};
|
|
129
187
|
TransportNodeHidSingleton.prototype.close = function () {
|
|
130
|
-
// intentionally, a close will not effectively close the hid connection
|
|
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;
|
|
131
191
|
return Promise.resolve();
|
|
132
192
|
};
|
|
133
193
|
/**
|
|
@@ -1 +1 @@
|
|
|
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,CAAC;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ightly.0",
|
|
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,20 +27,23 @@
|
|
|
27
27
|
"types": "lib/TransportNodeHid.d.ts",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ledgerhq/devices": "^6.27.
|
|
31
|
-
"@ledgerhq/errors": "^6.10.0",
|
|
32
|
-
"@ledgerhq/hw-transport": "^6.27.
|
|
33
|
-
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.
|
|
34
|
-
"@ledgerhq/logs": "^6.10.0",
|
|
30
|
+
"@ledgerhq/devices": "^6.27.2-nightly.0",
|
|
31
|
+
"@ledgerhq/errors": "^6.10.1-nightly.0",
|
|
32
|
+
"@ledgerhq/hw-transport": "^6.27.2-nightly.0",
|
|
33
|
+
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.2-nightly.0",
|
|
34
|
+
"@ledgerhq/logs": "^6.10.1-nightly.0",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"node-hid": "2.1.1",
|
|
37
|
-
"usb-detection": "
|
|
37
|
+
"usb-detection": "4.13.0"
|
|
38
38
|
},
|
|
39
|
+
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
39
40
|
"scripts": {
|
|
40
41
|
"clean": "bash ../../script/clean.sh",
|
|
41
42
|
"build": "bash ../../script/build.sh",
|
|
42
43
|
"watch": "bash ../../script/watch.sh",
|
|
43
|
-
"doc": "bash ../../script/doc.sh"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
"doc": "bash ../../script/doc.sh",
|
|
45
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
|
|
46
|
+
"lint:fix": "pnpm lint --fix",
|
|
47
|
+
"test": "jest"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/TransportNodeHid.ts
CHANGED
|
@@ -109,7 +109,7 @@ export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents
|
|
|
109
109
|
/**
|
|
110
110
|
* convenience wrapper for auto-disconnect logic
|
|
111
111
|
*/
|
|
112
|
-
static async autoDisconnect(): void {
|
|
112
|
+
static async autoDisconnect(): Promise<void> {
|
|
113
113
|
if (transportInstance && !transportInstance.preventAutoDisconnect) {
|
|
114
114
|
log("hid-verbose", "triggering auto disconnect");
|
|
115
115
|
TransportNodeHidSingleton.disconnect();
|
package/LICENSE
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright {yyyy} {name of copyright owner}
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
202
|
-
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
//@flow
|
|
2
|
-
|
|
3
|
-
import HID from "node-hid";
|
|
4
|
-
import TransportNodeHidNoEvents, {
|
|
5
|
-
getDevices,
|
|
6
|
-
} from "@ledgerhq/hw-transport-node-hid-noevents";
|
|
7
|
-
import type {
|
|
8
|
-
Observer,
|
|
9
|
-
DescriptorEvent,
|
|
10
|
-
Subscription,
|
|
11
|
-
} from "@ledgerhq/hw-transport";
|
|
12
|
-
import { log } from "@ledgerhq/logs";
|
|
13
|
-
import { identifyUSBProductId } from "@ledgerhq/devices";
|
|
14
|
-
import { CantOpenDevice } from "@ledgerhq/errors";
|
|
15
|
-
import { listenDevices } from "./listenDevices";
|
|
16
|
-
|
|
17
|
-
let transportInstance;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* node-hid Transport implementation
|
|
21
|
-
* @example
|
|
22
|
-
* import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
|
|
23
|
-
* ...
|
|
24
|
-
* TransportNodeHid.create().then(transport => ...)
|
|
25
|
-
*/
|
|
26
|
-
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
static isSupported = TransportNodeHidNoEvents.isSupported;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
static list = TransportNodeHidNoEvents.list;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
*/
|
|
39
|
-
static listen = (observer: Observer<DescriptorEvent<*>>): Subscription => {
|
|
40
|
-
let unsubscribed;
|
|
41
|
-
Promise.resolve(getDevices()).then((devices) => {
|
|
42
|
-
// this needs to run asynchronously so the subscription is defined during this phase
|
|
43
|
-
for (const device of devices) {
|
|
44
|
-
if (!unsubscribed) {
|
|
45
|
-
const deviceModel = identifyUSBProductId(device.productId);
|
|
46
|
-
observer.next({
|
|
47
|
-
type: "add",
|
|
48
|
-
descriptor: "",
|
|
49
|
-
device: { name: device.deviceName },
|
|
50
|
-
deviceModel,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const onAdd = (device) => {
|
|
57
|
-
const deviceModel = identifyUSBProductId(device.productId);
|
|
58
|
-
observer.next({
|
|
59
|
-
type: "add",
|
|
60
|
-
descriptor: "",
|
|
61
|
-
deviceModel,
|
|
62
|
-
device: { name: device.deviceName },
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const onRemove = (device) => {
|
|
67
|
-
const deviceModel = identifyUSBProductId(device.productId);
|
|
68
|
-
observer.next({
|
|
69
|
-
type: "remove",
|
|
70
|
-
descriptor: "",
|
|
71
|
-
deviceModel,
|
|
72
|
-
device: { name: device.deviceName },
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const stop = listenDevices(onAdd, onRemove);
|
|
77
|
-
|
|
78
|
-
function unsubscribe() {
|
|
79
|
-
stop();
|
|
80
|
-
unsubscribed = true;
|
|
81
|
-
}
|
|
82
|
-
return { unsubscribe };
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* globally disconnect the transport singleton
|
|
87
|
-
*/
|
|
88
|
-
static async disconnect() {
|
|
89
|
-
if (transportInstance) {
|
|
90
|
-
transportInstance.device.close();
|
|
91
|
-
transportInstance.emit("disconnect");
|
|
92
|
-
transportInstance = null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* if path="" is not provided, the library will take the first device
|
|
98
|
-
*/
|
|
99
|
-
static open(): Promise<TransportNodeHidSingleton> {
|
|
100
|
-
return Promise.resolve().then(() => {
|
|
101
|
-
if (transportInstance) {
|
|
102
|
-
log("hid-verbose", "reusing opened transport instance");
|
|
103
|
-
return transportInstance;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const device = getDevices()[0];
|
|
107
|
-
if (!device) throw new CantOpenDevice("no device found");
|
|
108
|
-
log("hid-verbose", "new HID transport");
|
|
109
|
-
transportInstance = new TransportNodeHidSingleton(
|
|
110
|
-
new HID.HID(device.path)
|
|
111
|
-
);
|
|
112
|
-
const unlisten = listenDevices(
|
|
113
|
-
() => {},
|
|
114
|
-
() => {
|
|
115
|
-
// assume any ledger disconnection concerns current transport
|
|
116
|
-
if (transportInstance) {
|
|
117
|
-
transportInstance.emit("disconnect");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
const onDisconnect = () => {
|
|
122
|
-
if (!transportInstance) return;
|
|
123
|
-
log("hid-verbose", "transport instance was disconnected");
|
|
124
|
-
transportInstance.off("disconnect", onDisconnect);
|
|
125
|
-
transportInstance = null;
|
|
126
|
-
unlisten();
|
|
127
|
-
};
|
|
128
|
-
transportInstance.on("disconnect", onDisconnect);
|
|
129
|
-
|
|
130
|
-
return transportInstance;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
close() {
|
|
135
|
-
// intentionally, a close will not effectively close the hid connection
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import usbDetect from "usb-detection";
|
|
3
|
-
import { ledgerUSBVendorId } from "@ledgerhq/devices";
|
|
4
|
-
import { log } from "@ledgerhq/logs";
|
|
5
|
-
|
|
6
|
-
export type Device = {
|
|
7
|
-
locationId: number,
|
|
8
|
-
vendorId: number,
|
|
9
|
-
productId: number,
|
|
10
|
-
deviceName: string,
|
|
11
|
-
manufacturer: string,
|
|
12
|
-
serialNumber: string,
|
|
13
|
-
deviceAddress: number,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const deviceToLog = ({ productId, locationId, deviceAddress }) =>
|
|
17
|
-
`productId=${productId} locationId=${locationId} deviceAddress=${deviceAddress}`;
|
|
18
|
-
|
|
19
|
-
let usbDebounce = 1000;
|
|
20
|
-
|
|
21
|
-
export const setUsbDebounce = (n: number) => {
|
|
22
|
-
usbDebounce = n;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
let monitoring = false;
|
|
26
|
-
const monitor = () => {
|
|
27
|
-
if (!monitoring) {
|
|
28
|
-
monitoring = true;
|
|
29
|
-
usbDetect.startMonitoring();
|
|
30
|
-
}
|
|
31
|
-
return () => {};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// No better way for now. see https://github.com/LedgerHQ/ledgerjs/issues/434
|
|
35
|
-
process.on("exit", () => {
|
|
36
|
-
if (monitoring) {
|
|
37
|
-
// redeem the monitoring so the process can be terminated.
|
|
38
|
-
usbDetect.stopMonitoring();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const listenDevices = (
|
|
43
|
-
onAdd: (Device) => void,
|
|
44
|
-
onRemove: (Device) => void
|
|
45
|
-
) => {
|
|
46
|
-
const unmonitor = monitor();
|
|
47
|
-
|
|
48
|
-
const addEvent = "add:" + ledgerUSBVendorId;
|
|
49
|
-
const removeEvent = "remove:" + ledgerUSBVendorId;
|
|
50
|
-
|
|
51
|
-
let timeout;
|
|
52
|
-
|
|
53
|
-
const add = (device) => {
|
|
54
|
-
log("usb-detection", "add: " + deviceToLog(device));
|
|
55
|
-
if (!timeout) {
|
|
56
|
-
// a time is needed for the device to actually be connectable over HID..
|
|
57
|
-
// we also take this time to not emit the device yet and potentially cancel it if a remove happens.
|
|
58
|
-
timeout = setTimeout(() => {
|
|
59
|
-
onAdd(device);
|
|
60
|
-
timeout = null;
|
|
61
|
-
}, usbDebounce);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const remove = (device) => {
|
|
66
|
-
log("usb-detection", "remove: " + deviceToLog(device));
|
|
67
|
-
if (timeout) {
|
|
68
|
-
clearTimeout(timeout);
|
|
69
|
-
timeout = null;
|
|
70
|
-
} else {
|
|
71
|
-
onRemove(device);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
usbDetect.on(addEvent, add);
|
|
76
|
-
usbDetect.on(removeEvent, remove);
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
if (timeout) clearTimeout(timeout);
|
|
80
|
-
usbDetect.off(addEvent, add);
|
|
81
|
-
usbDetect.off(removeEvent, remove);
|
|
82
|
-
unmonitor();
|
|
83
|
-
};
|
|
84
|
-
};
|