@onekeyfe/hd-transport-usb 1.1.27-alpha.35 → 1.1.27-alpha.36

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 CHANGED
@@ -45,6 +45,7 @@ declare class NodeUsbTransport {
45
45
  private transferInWithRetry;
46
46
  private openDevice;
47
47
  private createProtocolMismatchError;
48
+ private createProtocolDetectionError;
48
49
  private detectProtocol;
49
50
  private resetConnectionAfterProbe;
50
51
  private withProtocolReadTimeout;
@@ -54,7 +55,7 @@ declare class NodeUsbTransport {
54
55
  private receiveProtocolV2Frame;
55
56
  private callProtocolV2;
56
57
  private receiveData;
57
- getProtocolType(path: string): ProtocolType;
58
+ getProtocolType(path: string): ProtocolType | undefined;
58
59
  }
59
60
 
60
61
  export { NodeUsbTransport as default };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,SAWN,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAgKhC,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,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;IAG9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AAE,CAAC;IA8BxC,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAqB7C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAMhD,eAAe;IA6BvB,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,oBAAoB;YAwClB,cAAc;IA0B5B,MAAM;IAWN,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,kBAAkB;IAmB1B,OAAO,CAAC,iBAAiB;YAmDX,sBAAsB;YAyCtB,mBAAmB;IAsCjC,OAAO,CAAC,UAAU;IA8DlB,OAAO,CAAC,2BAA2B;IAOnC,OAAO,CAAC,4BAA4B;YAOtB,cAAc;YA4Cd,yBAAyB;YAazB,uBAAuB;YA0CvB,eAAe;YAcf,eAAe;YAcf,oBAAoB;YA+BpB,sBAAsB;YAuCtB,cAAc;YAuCd,WAAW;IA6CzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/dist/index.js CHANGED
@@ -295,7 +295,7 @@ class NodeUsbTransport {
295
295
  });
296
296
  }
297
297
  call(path, name, data, options) {
298
- var _a, _b, _c;
298
+ var _a, _b;
299
299
  return __awaiter(this, void 0, void 0, function* () {
300
300
  this.cancelled = false;
301
301
  if (!this.messages) {
@@ -304,12 +304,15 @@ class NodeUsbTransport {
304
304
  if (!this.openDevices.get(path)) {
305
305
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Device not acquired: ${path}`);
306
306
  }
307
- const protocol = (_a = this.deviceProtocol.get(path)) !== null && _a !== void 0 ? _a : 'V1';
307
+ const protocol = this.deviceProtocol.get(path);
308
+ if (!protocol) {
309
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${path}`);
310
+ }
308
311
  if (transport.LogBlockCommand.has(name)) {
309
- (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('NodeUsbTransport call-', ' name: ', name, ' protocol: ', protocol);
312
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('NodeUsbTransport call-', ' name: ', name, ' protocol: ', protocol);
310
313
  }
311
314
  else {
312
- (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug('NodeUsbTransport call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
315
+ (_b = this.Log) === null || _b === void 0 ? void 0 : _b.debug('NodeUsbTransport call-', ' name: ', name, ' data: ', data, ' protocol: ', protocol);
313
316
  }
314
317
  if (protocol === 'V2') {
315
318
  return this.callProtocolV2(path, name, data, options);
@@ -521,8 +524,11 @@ class NodeUsbTransport {
521
524
  createProtocolMismatchError(expected) {
522
525
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
523
526
  }
527
+ createProtocolDetectionError() {
528
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping');
529
+ }
524
530
  detectProtocol(path, expectedProtocol) {
525
- var _a, _b, _c, _d;
531
+ var _a, _b, _c, _d, _e;
526
532
  return __awaiter(this, void 0, void 0, function* () {
527
533
  if (expectedProtocol === 'V1') {
528
534
  if (yield this.probeProtocolV1(path)) {
@@ -545,13 +551,18 @@ class NodeUsbTransport {
545
551
  (_c = this.Log) === null || _c === void 0 ? void 0 : _c.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2 (cached)`);
546
552
  return 'V2';
547
553
  }
548
- let protocol = 'V1';
549
- if (!(yield this.probeProtocolV1(path)) && (yield this.probeProtocolV2(path))) {
550
- protocol = 'V2';
554
+ if (yield this.probeProtocolV1(path)) {
555
+ this.deviceProtocol.set(path, 'V1');
556
+ (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1`);
557
+ return 'V1';
551
558
  }
552
- this.deviceProtocol.set(path, protocol);
553
- (_d = this.Log) === null || _d === void 0 ? void 0 : _d.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> ${protocol}`);
554
- return protocol;
559
+ if (yield this.probeProtocolV2(path)) {
560
+ this.deviceProtocol.set(path, 'V2');
561
+ (_e = this.Log) === null || _e === void 0 ? void 0 : _e.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2`);
562
+ return 'V2';
563
+ }
564
+ this.deviceProtocol.delete(path);
565
+ throw this.createProtocolDetectionError();
555
566
  });
556
567
  }
557
568
  resetConnectionAfterProbe(path) {
@@ -755,8 +766,7 @@ class NodeUsbTransport {
755
766
  });
756
767
  }
757
768
  getProtocolType(path) {
758
- var _a;
759
- return (_a = this.deviceProtocol.get(path)) !== null && _a !== void 0 ? _a : 'V1';
769
+ return this.deviceProtocol.get(path);
760
770
  }
761
771
  }
762
772
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-usb",
3
- "version": "1.1.27-alpha.35",
3
+ "version": "1.1.27-alpha.36",
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.1.27-alpha.35",
24
- "@onekeyfe/hd-transport": "1.1.27-alpha.35",
23
+ "@onekeyfe/hd-shared": "1.1.27-alpha.36",
24
+ "@onekeyfe/hd-transport": "1.1.27-alpha.36",
25
25
  "bytebuffer": "^5.0.1",
26
26
  "usb": "^2.14.0"
27
27
  },
28
- "gitHead": "3a5eb264b57a6cc2338d1f9534be0ba265c2db35"
28
+ "gitHead": "1aaff42d7dd10933009ba7e0c0b7324e91d8e993"
29
29
  }
package/src/index.ts CHANGED
@@ -381,7 +381,13 @@ export default class NodeUsbTransport {
381
381
  throw ERRORS.TypedError(HardwareErrorCode.DeviceNotFound, `Device not acquired: ${path}`);
382
382
  }
383
383
 
384
- const protocol = this.deviceProtocol.get(path) ?? 'V1';
384
+ const protocol = this.deviceProtocol.get(path);
385
+ if (!protocol) {
386
+ throw ERRORS.TypedError(
387
+ HardwareErrorCode.RuntimeError,
388
+ `Device protocol has not been detected for ${path}`
389
+ );
390
+ }
385
391
  if (LogBlockCommand.has(name)) {
386
392
  this.Log?.debug('NodeUsbTransport call-', ' name: ', name, ' protocol: ', protocol);
387
393
  } else {
@@ -692,6 +698,13 @@ export default class NodeUsbTransport {
692
698
  );
693
699
  }
694
700
 
701
+ private createProtocolDetectionError() {
702
+ return ERRORS.TypedError(
703
+ HardwareErrorCode.RuntimeError,
704
+ 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping'
705
+ );
706
+ }
707
+
695
708
  private async detectProtocol(
696
709
  path: string,
697
710
  expectedProtocol?: ProtocolType
@@ -720,13 +733,20 @@ export default class NodeUsbTransport {
720
733
  return 'V2';
721
734
  }
722
735
 
723
- let protocol: ProtocolType = 'V1';
724
- if (!(await this.probeProtocolV1(path)) && (await this.probeProtocolV2(path))) {
725
- protocol = 'V2';
736
+ if (await this.probeProtocolV1(path)) {
737
+ this.deviceProtocol.set(path, 'V1');
738
+ this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V1`);
739
+ return 'V1';
726
740
  }
727
- this.deviceProtocol.set(path, protocol);
728
- this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> ${protocol}`);
729
- return protocol;
741
+
742
+ if (await this.probeProtocolV2(path)) {
743
+ this.deviceProtocol.set(path, 'V2');
744
+ this.Log?.debug(`[NodeUsbTransport] detectProtocol: path=${path} -> V2`);
745
+ return 'V2';
746
+ }
747
+
748
+ this.deviceProtocol.delete(path);
749
+ throw this.createProtocolDetectionError();
730
750
  }
731
751
 
732
752
  private async resetConnectionAfterProbe(path: string) {
@@ -966,7 +986,7 @@ export default class NodeUsbTransport {
966
986
  return Buffer.from(result as unknown as ArrayBuffer).toString('hex');
967
987
  }
968
988
 
969
- getProtocolType(path: string): ProtocolType {
970
- return this.deviceProtocol.get(path) ?? 'V1';
989
+ getProtocolType(path: string): ProtocolType | undefined {
990
+ return this.deviceProtocol.get(path);
971
991
  }
972
992
  }