@onekeyfe/hd-transport-web-device 1.2.0-alpha.34 → 1.2.0-alpha.35

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.
@@ -3,7 +3,7 @@ import transport, {
3
3
  ProtocolV2,
4
4
  ProtocolV2LinkError,
5
5
  } from '@onekeyfe/hd-transport';
6
- import { ONEKEY_WEBUSB_FILTER } from '@onekeyfe/hd-shared';
6
+ import { HardwareErrorCode, ONEKEY_WEBUSB_FILTER } from '@onekeyfe/hd-shared';
7
7
 
8
8
  import WebUsbTransport from '../src/webusb';
9
9
 
@@ -96,6 +96,25 @@ describe('WebUsbTransport Protocol V2 timeout recovery', () => {
96
96
  expect(webusb.deviceProtocol.get(path)).toBe('V2');
97
97
  });
98
98
 
99
+ test('reports DeviceNotFound when automatic protocol detection exhausts both probes', async () => {
100
+ const webusb = new WebUsbTransport() as any;
101
+ const path = 'unresponsive-webusb';
102
+ webusb.probeProtocolV1 = jest.fn().mockResolvedValue(false);
103
+ webusb.probeProtocolV2 = jest.fn().mockResolvedValue(false);
104
+ webusb.resetConnectionAfterProbe = jest.fn().mockResolvedValue(undefined);
105
+ webusb.closeConnectionAfterProbe = jest.fn().mockResolvedValue(undefined);
106
+
107
+ await expect(webusb.detectProtocol(path)).rejects.toMatchObject({
108
+ errorCode: HardwareErrorCode.DeviceNotFound,
109
+ });
110
+
111
+ expect(webusb.probeProtocolV1).toHaveBeenCalledTimes(1);
112
+ expect(webusb.probeProtocolV2).toHaveBeenCalledTimes(1);
113
+ expect(webusb.resetConnectionAfterProbe).toHaveBeenCalledTimes(1);
114
+ expect(webusb.closeConnectionAfterProbe).toHaveBeenCalledTimes(1);
115
+ expect(webusb.deviceProtocol.has(path)).toBe(false);
116
+ });
117
+
99
118
  test('allows legacy WebUSB Initialize up to the Node USB probe timeout', async () => {
100
119
  const webusb = new WebUsbTransport() as any;
101
120
  const path = 'pro-webusb';
package/dist/index.js CHANGED
@@ -41,14 +41,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
41
41
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
42
42
  };
43
43
 
44
- const HIGH_VOLUME_CALLS = new Set(['FileWrite', 'FilesystemFileWrite', 'EmmcFileWrite']);
45
- function shouldSuppressHighVolumeCallLog(name) {
46
- return HIGH_VOLUME_CALLS.has(name);
47
- }
48
- function createTransportCallLog(name, protocol) {
49
- return { name, protocol };
50
- }
51
-
52
44
  const { parseConfigure: parseConfigure$1, check: check$1, ProtocolV1: ProtocolV1$1 } = transport__default["default"];
53
45
  const CONFIGURATION_ID = 1;
54
46
  const INTERFACE_ID = 0;
@@ -188,7 +180,7 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
188
180
  return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol ${expected} probe timeout after ${attempts} attempts`);
189
181
  }
190
182
  createProtocolDetectionError() {
191
- return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping');
183
+ return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
192
184
  }
193
185
  detectProtocol(path, expectedProtocol, protocolHint) {
194
186
  var _a;
@@ -611,8 +603,8 @@ class WebUsbTransport extends transport.ProtocolV2UsbTransportBase {
611
603
  if (!protocol) {
612
604
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${path}`);
613
605
  }
614
- if (!shouldSuppressHighVolumeCallLog(name)) {
615
- this.Log.debug('transport call', createTransportCallLog(name, protocol));
606
+ if (!transport.shouldSuppressHighVolumeCallLog(name)) {
607
+ this.Log.debug('transport call', transport.createTransportCallLog(name, protocol, data));
616
608
  }
617
609
  if (protocol === 'V2') {
618
610
  return this.callProtocolV2(path, name, data, options);
@@ -1287,8 +1279,8 @@ class ElectronBleTransport {
1287
1279
  if (!protocol) {
1288
1280
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol has not been detected for ${uuid}`);
1289
1281
  }
1290
- if (!shouldSuppressHighVolumeCallLog(name)) {
1291
- (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('transport call', createTransportCallLog(name, protocol));
1282
+ if (!transport.shouldSuppressHighVolumeCallLog(name)) {
1283
+ (_a = this.Log) === null || _a === void 0 ? void 0 : _a.debug('transport call', transport.createTransportCallLog(name, protocol, data));
1292
1284
  }
1293
1285
  if (protocol === 'V2') {
1294
1286
  return this.callProtocolV2(uuid, name, data, options);
@@ -1,7 +1,2 @@
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
- };
1
+ export { createTransportCallLog, shouldSuppressHighVolumeCallLog } from '@onekeyfe/hd-transport';
7
2
  //# sourceMappingURL=transportLog.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"transportLog.d.ts","sourceRoot":"","sources":["../src/transportLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"webusb.d.ts","sourceRoot":"","sources":["../src/webusb.ts"],"names":[],"mappings":";AACA,OAAO,SAAS,EAAE,EAQhB,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAYhC,OAAO,K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E,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,IAAI,CAAC;cAIA,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,CAAC,UAAU,CAAC;cASN,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;IAWjF,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-web-device",
3
- "version": "1.2.0-alpha.34",
3
+ "version": "1.2.0-alpha.35",
4
4
  "author": "OneKey",
5
5
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
6
6
  "license": "MIT",
@@ -21,13 +21,13 @@
21
21
  "lint:fix": "eslint . --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@onekeyfe/hd-shared": "1.2.0-alpha.34",
25
- "@onekeyfe/hd-transport": "1.2.0-alpha.34"
24
+ "@onekeyfe/hd-shared": "1.2.0-alpha.35",
25
+ "@onekeyfe/hd-transport": "1.2.0-alpha.35"
26
26
  },
27
27
  "devDependencies": {
28
- "@onekeyfe/hd-transport-electron": "1.2.0-alpha.34",
28
+ "@onekeyfe/hd-transport-electron": "1.2.0-alpha.35",
29
29
  "@types/w3c-web-usb": "^1.0.6",
30
30
  "@types/web-bluetooth": "^0.0.17"
31
31
  },
32
- "gitHead": "07f10b4c9fab177da7c36d976ec18b075492b57f"
32
+ "gitHead": "638bd33030686c4a3321e4feb4924c3f9f5c81a8"
33
33
  }
@@ -706,7 +706,7 @@ export default class ElectronBleTransport {
706
706
  );
707
707
  }
708
708
  if (!shouldSuppressHighVolumeCallLog(name)) {
709
- this.Log?.debug('transport call', createTransportCallLog(name, protocol));
709
+ this.Log?.debug('transport call', createTransportCallLog(name, protocol, data));
710
710
  }
711
711
 
712
712
  if (protocol === 'V2') {
@@ -1,11 +1 @@
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
- }
1
+ export { createTransportCallLog, shouldSuppressHighVolumeCallLog } from '@onekeyfe/hd-transport';
package/src/webusb.ts CHANGED
@@ -272,10 +272,7 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
272
272
  }
273
273
 
274
274
  private createProtocolDetectionError() {
275
- return ERRORS.TypedError(
276
- HardwareErrorCode.RuntimeError,
277
- 'Unable to detect USB protocol: device did not respond to Protocol V1 Initialize or Protocol V2 Ping'
278
- );
275
+ return ERRORS.TypedError(HardwareErrorCode.DeviceNotFound);
279
276
  }
280
277
 
281
278
  private async detectProtocol(
@@ -771,7 +768,7 @@ export default class WebUsbTransport extends ProtocolV2UsbTransportBase<string>
771
768
  }
772
769
 
773
770
  if (!shouldSuppressHighVolumeCallLog(name)) {
774
- this.Log.debug('transport call', createTransportCallLog(name, protocol));
771
+ this.Log.debug('transport call', createTransportCallLog(name, protocol, data));
775
772
  }
776
773
 
777
774
  if (protocol === 'V2') {