@onekeyfe/hd-transport-usb 1.2.0-alpha.10 → 1.2.0-alpha.12
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -19
- package/dist/transportLog.d.ts +7 -0
- package/dist/transportLog.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +5 -22
- package/src/transportLog.ts +11 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAAS,EAAE,EAOhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAKhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAgKhC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,0BAA0B,CAAC,MAAM,CAAC;IAC9E,QAAQ,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAGlE,UAAU,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEpE,IAAI,SAAsB;IAE1B,OAAO,SAAM;IAEb,UAAU,UAAS;IAEnB,UAAU,UAAS;IAEnB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,OAAO,CAAC,aAAa,CAA6B;IAGlD,OAAO,CAAC,WAAW,CAAiC;IAGpD,OAAO,CAAC,cAAc,CAAwC;IAG9D,OAAO,CA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AAsB;cAIhB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;cAOA,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cAqBN,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1F,SAAS,CAAC,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKrE,SAAS,CAAC,+BAA+B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK;YAInE,cAAc;YAad,WAAW;IA6CzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,14 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
59
59
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
|
|
63
|
+
function shouldSuppressHighVolumeCallLog(name) {
|
|
64
|
+
return HIGH_VOLUME_CALLS.has(name);
|
|
65
|
+
}
|
|
66
|
+
function createTransportCallLog(name, protocol) {
|
|
67
|
+
return { name, protocol };
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
const { parseConfigure, ProtocolV1, check } = transport__default["default"];
|
|
63
71
|
const PACKET_SIZE = transport.PROTOCOL_V1_USB_PACKET_SIZE;
|
|
64
72
|
const REPORT_ID = transport.PROTOCOL_V1_REPORT_ID;
|
|
@@ -190,10 +198,8 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
190
198
|
return Promise.resolve();
|
|
191
199
|
}
|
|
192
200
|
configureProtocolV2(signedData) {
|
|
193
|
-
var _a;
|
|
194
201
|
this.messagesV2 = parseConfigure(signedData);
|
|
195
202
|
this.invalidateAllProtocolV2UsbLinks('Protocol V2 schema reconfigured').catch(error => { var _a; return (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[NodeUsbTransport] schema link cleanup failed:', error); });
|
|
196
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[NodeUsbTransport] Protocol V2 schema configured');
|
|
197
203
|
}
|
|
198
204
|
listen() {
|
|
199
205
|
}
|
|
@@ -303,7 +309,7 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
303
309
|
});
|
|
304
310
|
}
|
|
305
311
|
call(path, name, data, options) {
|
|
306
|
-
var _a
|
|
312
|
+
var _a;
|
|
307
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
308
314
|
this.cancelled = false;
|
|
309
315
|
if (!this.messages) {
|
|
@@ -316,11 +322,8 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
316
322
|
if (!protocol) {
|
|
317
323
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${path}`);
|
|
318
324
|
}
|
|
319
|
-
if (
|
|
320
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('NodeUsbTransport call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
|
|
325
|
+
if (!shouldSuppressHighVolumeCallLog(name)) {
|
|
326
|
+
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('transport call', createTransportCallLog(name, protocol));
|
|
324
327
|
}
|
|
325
328
|
if (protocol === 'V2') {
|
|
326
329
|
return this.callProtocolV2(path, name, data, options);
|
|
@@ -345,8 +348,6 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
345
348
|
});
|
|
346
349
|
}
|
|
347
350
|
cancel() {
|
|
348
|
-
var _a;
|
|
349
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('NodeUsbTransport cancel');
|
|
350
351
|
this.cancelled = true;
|
|
351
352
|
}
|
|
352
353
|
getOpenDevice(path) {
|
|
@@ -568,12 +569,10 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
568
569
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping');
|
|
569
570
|
}
|
|
570
571
|
detectProtocol(path, expectedProtocol) {
|
|
571
|
-
var _a, _b, _c, _d, _e;
|
|
572
572
|
return __awaiter(this, void 0, void 0, function* () {
|
|
573
573
|
if (expectedProtocol === 'V1') {
|
|
574
574
|
if (yield this.probeProtocolV1(path)) {
|
|
575
575
|
this.deviceProtocol.set(path, 'V1');
|
|
576
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1 (expected)`);
|
|
577
576
|
return 'V1';
|
|
578
577
|
}
|
|
579
578
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
@@ -581,24 +580,20 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
581
580
|
if (expectedProtocol === 'V2') {
|
|
582
581
|
if (yield this.probeProtocolV2(path)) {
|
|
583
582
|
this.deviceProtocol.set(path, 'V2');
|
|
584
|
-
(_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
|
|
585
583
|
return 'V2';
|
|
586
584
|
}
|
|
587
585
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
588
586
|
}
|
|
589
587
|
if (this.deviceProtocol.get(path) === 'V2' && (yield this.probeProtocolV2(path))) {
|
|
590
588
|
this.deviceProtocol.set(path, 'V2');
|
|
591
|
-
(_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (cached)`);
|
|
592
589
|
return 'V2';
|
|
593
590
|
}
|
|
594
591
|
if (yield this.probeProtocolV1(path)) {
|
|
595
592
|
this.deviceProtocol.set(path, 'V1');
|
|
596
|
-
(_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1`);
|
|
597
593
|
return 'V1';
|
|
598
594
|
}
|
|
599
595
|
if (yield this.probeProtocolV2(path)) {
|
|
600
596
|
this.deviceProtocol.set(path, 'V2');
|
|
601
|
-
(_e = this.Log) === null || _e === void 0 ? void 0 : _e.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2`);
|
|
602
597
|
return 'V2';
|
|
603
598
|
}
|
|
604
599
|
this.deviceProtocol.delete(path);
|
|
@@ -657,7 +652,6 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
657
652
|
});
|
|
658
653
|
}
|
|
659
654
|
probeProtocolV1(path) {
|
|
660
|
-
var _a;
|
|
661
655
|
return __awaiter(this, void 0, void 0, function* () {
|
|
662
656
|
if (!this.messages) {
|
|
663
657
|
return false;
|
|
@@ -666,8 +660,7 @@ class NodeUsbTransport extends transport.ProtocolV2UsbTransportBase {
|
|
|
666
660
|
yield this.callProtocolV1(path, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT });
|
|
667
661
|
return true;
|
|
668
662
|
}
|
|
669
|
-
catch (
|
|
670
|
-
(_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('[NodeUsbTransport] Protocol V1 Initialize probe failed:', error);
|
|
663
|
+
catch (_error) {
|
|
671
664
|
return false;
|
|
672
665
|
}
|
|
673
666
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
export declare function shouldSuppressHighVolumeCallLog(name: string): boolean;
|
|
3
|
+
export declare function createTransportCallLog(name: string, protocol: ProtocolType): {
|
|
4
|
+
name: string;
|
|
5
|
+
protocol: ProtocolType;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=transportLog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../src/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI3D,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,WAE3D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY;;;EAE1E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-usb",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.12",
|
|
4
4
|
"description": "OneKey hardware wallet direct USB transport plugin (libusb)",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.12",
|
|
24
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.12",
|
|
25
25
|
"bytebuffer": "^5.0.1",
|
|
26
26
|
"usb": "^2.14.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "3601e8003c96a2a4ca7856e865d16f48c0c5b758"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import ByteBuffer from 'bytebuffer';
|
|
2
2
|
import * as usb from 'usb';
|
|
3
3
|
import transport, {
|
|
4
|
-
LogBlockCommand,
|
|
5
4
|
PROTOCOL_V1_CHUNK_PAYLOAD_SIZE,
|
|
6
5
|
PROTOCOL_V1_MESSAGE_HEADER_SIZE,
|
|
7
6
|
PROTOCOL_V1_REPORT_ID,
|
|
@@ -13,6 +12,8 @@ import transport, {
|
|
|
13
12
|
} from '@onekeyfe/hd-transport';
|
|
14
13
|
import { ERRORS, HardwareErrorCode, ONEKEY_WEBUSB_FILTER, wait } from '@onekeyfe/hd-shared';
|
|
15
14
|
|
|
15
|
+
import { createTransportCallLog, shouldSuppressHighVolumeCallLog } from './transportLog';
|
|
16
|
+
|
|
16
17
|
import type EventEmitter from 'events';
|
|
17
18
|
import type {
|
|
18
19
|
AcquireInput,
|
|
@@ -244,7 +245,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
244
245
|
this.invalidateAllProtocolV2UsbLinks('Protocol V2 schema reconfigured').catch(error =>
|
|
245
246
|
this.Log?.debug('[NodeUsbTransport] schema link cleanup failed:', error)
|
|
246
247
|
);
|
|
247
|
-
this.Log?.debug('[NodeUsbTransport] Protocol V2 schema configured');
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
listen() {
|
|
@@ -401,18 +401,8 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
401
401
|
`Device protocol has not been detected for ${path}`
|
|
402
402
|
);
|
|
403
403
|
}
|
|
404
|
-
if (
|
|
405
|
-
this.Log?.debug('
|
|
406
|
-
} else {
|
|
407
|
-
this.Log?.debug(
|
|
408
|
-
'NodeUsbTransport call-',
|
|
409
|
-
' name: ',
|
|
410
|
-
name,
|
|
411
|
-
' data: ',
|
|
412
|
-
data,
|
|
413
|
-
' protocol: ',
|
|
414
|
-
protocol
|
|
415
|
-
);
|
|
404
|
+
if (!shouldSuppressHighVolumeCallLog(name)) {
|
|
405
|
+
this.Log?.debug('transport call', createTransportCallLog(name, protocol));
|
|
416
406
|
}
|
|
417
407
|
|
|
418
408
|
if (protocol === 'V2') {
|
|
@@ -449,7 +439,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
449
439
|
}
|
|
450
440
|
|
|
451
441
|
cancel() {
|
|
452
|
-
this.Log?.debug('NodeUsbTransport cancel');
|
|
453
442
|
this.cancelled = true;
|
|
454
443
|
}
|
|
455
444
|
|
|
@@ -757,7 +746,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
757
746
|
if (expectedProtocol === 'V1') {
|
|
758
747
|
if (await this.probeProtocolV1(path)) {
|
|
759
748
|
this.deviceProtocol.set(path, 'V1');
|
|
760
|
-
this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1 (expected)`);
|
|
761
749
|
return 'V1';
|
|
762
750
|
}
|
|
763
751
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
@@ -766,7 +754,6 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
766
754
|
if (expectedProtocol === 'V2') {
|
|
767
755
|
if (await this.probeProtocolV2(path)) {
|
|
768
756
|
this.deviceProtocol.set(path, 'V2');
|
|
769
|
-
this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (expected)`);
|
|
770
757
|
return 'V2';
|
|
771
758
|
}
|
|
772
759
|
throw this.createProtocolMismatchError(expectedProtocol);
|
|
@@ -774,19 +761,16 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
774
761
|
|
|
775
762
|
if (this.deviceProtocol.get(path) === 'V2' && (await this.probeProtocolV2(path))) {
|
|
776
763
|
this.deviceProtocol.set(path, 'V2');
|
|
777
|
-
this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (cached)`);
|
|
778
764
|
return 'V2';
|
|
779
765
|
}
|
|
780
766
|
|
|
781
767
|
if (await this.probeProtocolV1(path)) {
|
|
782
768
|
this.deviceProtocol.set(path, 'V1');
|
|
783
|
-
this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1`);
|
|
784
769
|
return 'V1';
|
|
785
770
|
}
|
|
786
771
|
|
|
787
772
|
if (await this.probeProtocolV2(path)) {
|
|
788
773
|
this.deviceProtocol.set(path, 'V2');
|
|
789
|
-
this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2`);
|
|
790
774
|
return 'V2';
|
|
791
775
|
}
|
|
792
776
|
|
|
@@ -857,8 +841,7 @@ export default class NodeUsbTransport extends ProtocolV2UsbTransportBase<string>
|
|
|
857
841
|
try {
|
|
858
842
|
await this.callProtocolV1(path, 'Initialize', {}, { timeoutMs: PROTOCOL_PROBE_TIMEOUT });
|
|
859
843
|
return true;
|
|
860
|
-
} catch (
|
|
861
|
-
this.Log?.debug('[NodeUsbTransport] Protocol V1 Initialize probe failed:', error);
|
|
844
|
+
} catch (_error) {
|
|
862
845
|
return false;
|
|
863
846
|
}
|
|
864
847
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProtocolType } from '@onekeyfe/hd-transport';
|
|
2
|
+
|
|
3
|
+
const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
|
|
4
|
+
|
|
5
|
+
export function shouldSuppressHighVolumeCallLog(name: string) {
|
|
6
|
+
return HIGH_VOLUME_CALLS.has(name);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createTransportCallLog(name: string, protocol: ProtocolType) {
|
|
10
|
+
return { name, protocol };
|
|
11
|
+
}
|