@onekeyfe/hd-core 1.2.0-alpha.110 → 1.2.0-alpha.111

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.
@@ -1,7 +1,6 @@
1
1
  import * as hdShared from '@onekeyfe/hd-shared';
2
2
 
3
3
  import FirmwareUpdateV3 from '../../src/api/FirmwareUpdateV3';
4
- import { DataManager } from '../../src/data-manager';
5
4
  import { DevicePool } from '../../src/device/DevicePool';
6
5
 
7
6
  import type { Device } from '../../src/device/Device';
@@ -113,63 +112,10 @@ describe('FirmwareUpdateV3 reconnect', () => {
113
112
  })
114
113
  ).rejects.toBe(reconnectError);
115
114
 
116
- expect(commands.typedCall).toHaveBeenCalledWith('GetFeatures', 'Features', {});
117
115
  expect(waitForDeviceReconnect).toHaveBeenCalledWith(3 * 60 * 1000);
118
116
  } finally {
119
117
  jest.clearAllTimers();
120
118
  jest.useRealTimers();
121
119
  }
122
120
  });
123
-
124
- it('lets Browser WebUSB clean up a timed out install probe before reconnecting', async () => {
125
- jest.spyOn(hdShared, 'wait').mockResolvedValue(undefined);
126
- jest.spyOn(DataManager, 'getSettings').mockReturnValue('webusb' as never);
127
- jest.spyOn(DataManager, 'isBrowserWebUsb').mockReturnValue(true);
128
- const method = new FirmwareUpdateV3({
129
- id: 1,
130
- payload: {
131
- method: 'firmwareUpdateV3',
132
- connectId: 'webusb-device',
133
- },
134
- });
135
- const reconnectError = new Error('stop after WebUSB reconnect assertion');
136
- const waitForDeviceReconnect = jest
137
- .spyOn(method, 'waitForDeviceReconnect')
138
- .mockRejectedValue(reconnectError);
139
- method.isBleReconnect = jest.fn(() => false);
140
- method.params = {
141
- platform: 'web',
142
- } as any;
143
- const commands = {
144
- typedCall: jest.fn().mockRejectedValue(new Error('Protocol V1 read timeout after 3000ms')),
145
- };
146
- method.device = {
147
- features: {},
148
- getCommands: () => commands,
149
- } as unknown as Device;
150
- (method as any).createUpdatesFolderIfNotExists = jest.fn().mockResolvedValue(undefined);
151
- (method as any).startEmmcFirmwareUpdate = jest.fn().mockResolvedValue(undefined);
152
- method.postTipMessage = jest.fn();
153
- method.postProcessingMessage = jest.fn();
154
- method.postProgressMessage = jest.fn();
155
-
156
- await expect(
157
- (method as any).executeUpdate({
158
- resourceBinary: null,
159
- resourceEntries: [],
160
- fwSources: [],
161
- bootloaderSource: null,
162
- })
163
- ).rejects.toBe(reconnectError);
164
-
165
- expect(commands.typedCall).toHaveBeenCalledWith(
166
- 'GetFeatures',
167
- 'Features',
168
- {},
169
- {
170
- timeoutMs: 3000,
171
- }
172
- );
173
- expect(waitForDeviceReconnect).toHaveBeenCalledWith(60 * 1000);
174
- });
175
121
  });
@@ -1 +1 @@
1
- {"version":3,"file":"FirmwareUpdateV3.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV3.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAc/E,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,qBAAqB,CAAC;AAMnE,eAAO,MAAM,gCAAgC,UAAU,CAAC;AAaxD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,gBAAgB,CAAS;IAEjC,OAAO,CAAC,eAAe,CAA4B;IAEnD,IAAI;IA8HE,GAAG;;;;;YAQK,aAAa;IA6D3B,OAAO,CAAC,wBAAwB;YAiBlB,kBAAkB;YAelB,oBAAoB;IAKlC,OAAO,CAAC,wBAAwB;YAgBlB,oBAAoB;YA2DpB,uBAAuB;YAuBvB,4BAA4B;YA+E5B,aAAa;IAgO3B,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,sCAAsC;IAexC,sBAAsB,CAAC,OAAO,EAAE,MAAM;CA+E7C"}
1
+ {"version":3,"file":"FirmwareUpdateV3.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV3.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAc/E,OAAO,KAAK,EAEV,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAiB,MAAM,qBAAqB,CAAC;AAMnE,eAAO,MAAM,gCAAgC,UAAU,CAAC;AAaxD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,gBAAgB,CAAS;IAEjC,OAAO,CAAC,eAAe,CAA4B;IAEnD,IAAI;IA8HE,GAAG;;;;;YAQK,aAAa;IA6D3B,OAAO,CAAC,wBAAwB;YAiBlB,kBAAkB;YAelB,oBAAoB;IAKlC,OAAO,CAAC,wBAAwB;YAgBlB,oBAAoB;YA2DpB,uBAAuB;YAuBvB,4BAA4B;YA+E5B,aAAa;IAyN3B,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,sCAAsC;IAexC,sBAAsB,CAAC,OAAO,EAAE,MAAM;CA+E7C"}
package/dist/index.js CHANGED
@@ -51318,18 +51318,12 @@ class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod {
51318
51318
  try {
51319
51319
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
51320
51320
  const timeoutMs = 3000;
51321
- const isBrowserWebUsb = DataManager.isBrowserWebUsb(DataManager.getSettings('env'));
51322
- const getFeaturesPromise = isBrowserWebUsb
51323
- ? typedCall('GetFeatures', 'Features', {}, { timeoutMs })
51324
- : typedCall('GetFeatures', 'Features', {});
51325
- const featuresRes = isBrowserWebUsb
51326
- ? yield getFeaturesPromise
51327
- : yield Promise.race([
51328
- getFeaturesPromise,
51329
- new Promise((_, reject) => {
51330
- setTimeout(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse, 'GetFeatures timeout', { method: 'GetFeatures', timeoutMs })), timeoutMs);
51331
- }),
51332
- ]);
51321
+ const featuresRes = yield Promise.race([
51322
+ typedCall('GetFeatures', 'Features', {}),
51323
+ new Promise((_, reject) => {
51324
+ setTimeout(() => reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse, 'GetFeatures timeout', { method: 'GetFeatures', timeoutMs })), timeoutMs);
51325
+ }),
51326
+ ]);
51333
51327
  getFeaturesTimeoutCount = 0;
51334
51328
  const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
51335
51329
  const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.110",
3
+ "version": "1.2.0-alpha.111",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.2.0-alpha.110",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.110",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.111",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.111",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "buffer": "^6.0.3",
@@ -46,5 +46,5 @@
46
46
  "@types/w3c-web-usb": "^1.0.10",
47
47
  "@types/web-bluetooth": "^0.0.21"
48
48
  },
49
- "gitHead": "6b487cbc8186019cf5d659cbe2fa26299e4e1aa8"
49
+ "gitHead": "7619f316471ad423fb83f68e82e1aec89f34ac0a"
50
50
  }
@@ -609,29 +609,22 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
609
609
  try {
610
610
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
611
611
  const timeoutMs = 3000;
612
- const isBrowserWebUsb = DataManager.isBrowserWebUsb(DataManager.getSettings('env'));
613
- const getFeaturesPromise = isBrowserWebUsb
614
- ? typedCall('GetFeatures', 'Features', {}, { timeoutMs })
615
- : typedCall('GetFeatures', 'Features', {});
616
- // WebUSB owns timeout cleanup so a reboot cannot leave a pending transfer blocking reconnect.
617
- const featuresRes = isBrowserWebUsb
618
- ? await getFeaturesPromise
619
- : await Promise.race<TypedResponseMessage<'Features'>>([
620
- getFeaturesPromise,
621
- new Promise<never>((_, reject) => {
622
- setTimeout(
623
- () =>
624
- reject(
625
- ERRORS.TypedError(
626
- HardwareErrorCode.CallMethodNotResponse,
627
- 'GetFeatures timeout',
628
- { method: 'GetFeatures', timeoutMs }
629
- )
630
- ),
631
- timeoutMs
632
- );
633
- }),
634
- ]);
612
+ const featuresRes = await Promise.race<TypedResponseMessage<'Features'>>([
613
+ typedCall('GetFeatures', 'Features', {}),
614
+ new Promise<never>((_, reject) => {
615
+ setTimeout(
616
+ () =>
617
+ reject(
618
+ ERRORS.TypedError(
619
+ HardwareErrorCode.CallMethodNotResponse,
620
+ 'GetFeatures timeout',
621
+ { method: 'GetFeatures', timeoutMs }
622
+ )
623
+ ),
624
+ timeoutMs
625
+ );
626
+ }),
627
+ ]);
635
628
  getFeaturesTimeoutCount = 0;
636
629
  const features = buildProtocolV1FeaturesPayload(featuresRes.message, this.device.features);
637
630
  const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');