@onekeyfe/hd-core 1.2.8-alpha.130 → 1.2.8-alpha.132

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.
@@ -284,37 +284,57 @@ describe('writeProtocolV2File', () => {
284
284
  }
285
285
  );
286
286
 
287
- test('refreshes unlock status after reconnect even when the original preflight completed', async () => {
288
- const { commands, device, typedCall } = createCommands();
289
- typedCall.mockResolvedValueOnce({ type: 'DeviceStatus', message: { unlocked: false } });
290
- const unlockDevice = jest.fn().mockResolvedValue({ unlocked: true });
291
- const method = {
292
- name: 'deviceUploadWallpaper',
293
- device: {
294
- ...device,
295
- state: {
296
- ...device.state,
297
- identity: { serialNo: 'test-device', deviceType: EDeviceType.Pro2 },
298
- status: { mode: 'normal', initialized: true },
287
+ test.each(['react-native', 'desktop-web-ble'])(
288
+ 'disconnects a cached %s link and refreshes unlock status after reconnect',
289
+ async env => {
290
+ jest.spyOn(DataManager, 'getSettings').mockReturnValue(env);
291
+ const { commands, device, typedCall } = createCommands();
292
+ typedCall.mockResolvedValueOnce({ type: 'DeviceStatus', message: { unlocked: false } });
293
+ const unlockDevice = jest.fn().mockResolvedValue({ unlocked: true });
294
+ let nativeConnected = true;
295
+ const disconnect = jest.fn(() => {
296
+ nativeConnected = false;
297
+ return Promise.resolve();
298
+ });
299
+ const acquire = jest.fn(() => {
300
+ if (nativeConnected) {
301
+ return Promise.reject(new Error('reused the timed-out native connection'));
302
+ }
303
+ nativeConnected = true;
304
+ return Promise.resolve();
305
+ });
306
+ const method = {
307
+ name: 'deviceUploadWallpaper',
308
+ device: {
309
+ ...device,
310
+ state: {
311
+ ...device.state,
312
+ identity: { serialNo: 'test-device', deviceType: EDeviceType.Pro2 },
313
+ status: { mode: 'normal', initialized: true },
314
+ },
315
+ commands,
316
+ originalDescriptor: { id: 'ble-device' },
317
+ deviceConnector: { disconnect },
318
+ acquire,
319
+ initialize: jest.fn().mockResolvedValue(undefined),
320
+ updateProtocolV2Status: (status: unknown) => status,
321
+ unlockDevice,
322
+ toMessageObject: () => ({}),
299
323
  },
300
- commands,
301
- acquire: jest.fn().mockResolvedValue(undefined),
302
- initialize: jest.fn().mockResolvedValue(undefined),
303
- updateProtocolV2Status: (status: unknown) => status,
304
- unlockDevice,
305
- toMessageObject: () => ({}),
306
- },
307
- unlockPolicy: 'unlock-before-run',
308
- useDevicePassphraseState: false,
309
- protocolV2PreUnlockPinType: DeviceSessionPinType.Any,
310
- protocolV2UnlockContext: { preflightCompleted: true },
311
- postMessage: jest.fn(),
312
- payload: {},
313
- } as unknown as BaseMethod;
314
- await expect(createProtocolV2AssetFileWriteRecovery(method)()).resolves.toBe(commands);
315
- expect(typedCall).toHaveBeenCalledWith('DeviceStatusGet', 'DeviceStatus', {});
316
- expect(unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Any, expect.any(Object));
317
- });
324
+ unlockPolicy: 'unlock-before-run',
325
+ useDevicePassphraseState: false,
326
+ protocolV2PreUnlockPinType: DeviceSessionPinType.Any,
327
+ protocolV2UnlockContext: { preflightCompleted: true },
328
+ postMessage: jest.fn(),
329
+ payload: {},
330
+ } as unknown as BaseMethod;
331
+ await expect(createProtocolV2AssetFileWriteRecovery(method)()).resolves.toBe(commands);
332
+ expect(disconnect).toHaveBeenCalledWith('ble-device');
333
+ expect(acquire).toHaveBeenCalledWith('V2', { throwOnRunPromiseError: true });
334
+ expect(typedCall).toHaveBeenCalledWith('DeviceStatusGet', 'DeviceStatus', {});
335
+ expect(unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Any, expect.any(Object));
336
+ }
337
+ );
318
338
 
319
339
  const serialCases: {
320
340
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"protocolV2FileWrite.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/protocolV2FileWrite.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,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B,CAAC,UAAU,CAAC,CAAC,CAuDvD;AA2FD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,WASzD;AAkDD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B;;;;;;GA2X5E"}
package/dist/index.js CHANGED
@@ -52763,25 +52763,31 @@ function createProtocolV2AssetFileWriteRecovery(method) {
52763
52763
  const expectedSerialNo = (_b = (_a = device.state) === null || _a === void 0 ? void 0 : _a.identity) === null || _b === void 0 ? void 0 : _b.serialNo;
52764
52764
  const expectedDeviceType = (_d = (_c = device.state) === null || _c === void 0 ? void 0 : _c.identity) === null || _d === void 0 ? void 0 : _d.deviceType;
52765
52765
  return () => __awaiter(this, void 0, void 0, function* () {
52766
- var _e, _f, _g, _h, _j, _k, _l, _m;
52766
+ var _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
52767
52767
  if ((_e = method.abortSignal) === null || _e === void 0 ? void 0 : _e.aborted) {
52768
52768
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
52769
52769
  }
52770
52770
  if (!expectedSerialNo) {
52771
52771
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
52772
52772
  }
52773
+ if (DataManager.isBleConnect(DataManager.getSettings('env'))) {
52774
+ yield ((_f = device.deviceConnector) === null || _f === void 0 ? void 0 : _f.disconnect(device.originalDescriptor.id));
52775
+ if ((_g = method.abortSignal) === null || _g === void 0 ? void 0 : _g.aborted) {
52776
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
52777
+ }
52778
+ }
52773
52779
  yield device.acquire('V2', { throwOnRunPromiseError: true });
52774
- if ((_f = method.abortSignal) === null || _f === void 0 ? void 0 : _f.aborted) {
52780
+ if ((_h = method.abortSignal) === null || _h === void 0 ? void 0 : _h.aborted) {
52775
52781
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
52776
52782
  }
52777
52783
  yield device.initialize();
52778
52784
  if (!device.isProtocolV2() ||
52779
- ((_g = device.state) === null || _g === void 0 ? void 0 : _g.identity.serialNo) !== expectedSerialNo ||
52780
- ((_h = device.state) === null || _h === void 0 ? void 0 : _h.identity.deviceType) !== expectedDeviceType ||
52781
- !['normal', 'notInitialized'].includes((_k = (_j = device.state) === null || _j === void 0 ? void 0 : _j.status.mode) !== null && _k !== void 0 ? _k : '')) {
52785
+ ((_j = device.state) === null || _j === void 0 ? void 0 : _j.identity.serialNo) !== expectedSerialNo ||
52786
+ ((_k = device.state) === null || _k === void 0 ? void 0 : _k.identity.deviceType) !== expectedDeviceType ||
52787
+ !['normal', 'notInitialized'].includes((_m = (_l = device.state) === null || _l === void 0 ? void 0 : _l.status.mode) !== null && _m !== void 0 ? _m : '')) {
52782
52788
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError);
52783
52789
  }
52784
- if ((_l = method.abortSignal) === null || _l === void 0 ? void 0 : _l.aborted) {
52790
+ if ((_o = method.abortSignal) === null || _o === void 0 ? void 0 : _o.aborted) {
52785
52791
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
52786
52792
  }
52787
52793
  yield runMethodWithUnlockPolicy({
@@ -52794,7 +52800,7 @@ function createProtocolV2AssetFileWriteRecovery(method) {
52794
52800
  params: undefined,
52795
52801
  run: () => Promise.resolve(undefined),
52796
52802
  }, device, { uiCoordinator: new ProtocolV2UiInteractionCoordinator(device, method.postMessage) });
52797
- if ((_m = method.abortSignal) === null || _m === void 0 ? void 0 : _m.aborted) {
52803
+ if ((_p = method.abortSignal) === null || _p === void 0 ? void 0 : _p.aborted) {
52798
52804
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallQueueActionCancelled);
52799
52805
  }
52800
52806
  DevicePool.emitter.emit(DEVICE.CONNECT, device);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.8-alpha.130",
3
+ "version": "1.2.8-alpha.132",
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.8-alpha.130",
29
- "@onekeyfe/hd-transport": "1.2.8-alpha.130",
28
+ "@onekeyfe/hd-shared": "1.2.8-alpha.132",
29
+ "@onekeyfe/hd-transport": "1.2.8-alpha.132",
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": "bacd066a15648891f9683586fcd06e063b98dfec"
49
+ "gitHead": "b8eef508535a14385e67317042fe187dc9b5f660"
50
50
  }
@@ -93,6 +93,13 @@ export function createProtocolV2AssetFileWriteRecovery(
93
93
  if (!expectedSerialNo) {
94
94
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
95
95
  }
96
+ if (DataManager.isBleConnect(DataManager.getSettings('env'))) {
97
+ // Acquire may otherwise reuse a native connection with an uncertain in-flight write.
98
+ await device.deviceConnector?.disconnect(device.originalDescriptor.id);
99
+ if (method.abortSignal?.aborted) {
100
+ throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);
101
+ }
102
+ }
96
103
  await device.acquire('V2', { throwOnRunPromiseError: true });
97
104
  if (method.abortSignal?.aborted) {
98
105
  throw ERRORS.TypedError(HardwareErrorCode.CallQueueActionCancelled);