@onekeyfe/hd-core 1.2.0-alpha.131 → 1.2.0-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.
@@ -1,7 +1,7 @@
1
1
  import { EDeviceType, ERRORS, HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
2
2
  import { DeviceType, TRANSPORT_EVENT } from '@onekeyfe/hd-transport';
3
3
 
4
- import { initConnector, initCore } from '../src/core';
4
+ import { initConnector, initCore, isMissingDetectedProtocolV2Error } from '../src/core';
5
5
  import { DataManager } from '../src/data-manager';
6
6
  import TransportManager from '../src/data-manager/TransportManager';
7
7
  import { Device } from '../src/device/Device';
@@ -251,6 +251,22 @@ describe('public device lifecycle events', () => {
251
251
  expect(device.getProtocol()).toBe('V2');
252
252
  });
253
253
 
254
+ test.each([
255
+ ['V2', true],
256
+ ['V1', false],
257
+ ] as const)(
258
+ 'retries a missing detected protocol only for an explicit Protocol %s connection',
259
+ (connectProtocol, expected) => {
260
+ const method = { payload: { connectProtocol } } as never;
261
+ const error = {
262
+ errorCode: HardwareErrorCode.RuntimeError,
263
+ message: 'Device protocol has not been detected for ble-id',
264
+ };
265
+
266
+ expect(isMissingDetectedProtocolV2Error(method, error)).toBe(expected);
267
+ }
268
+ );
269
+
254
270
  test('converts an internal transport disconnect into a public KnownDevice snapshot', () => {
255
271
  jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
256
272
  core = initCore();
@@ -361,8 +361,8 @@ describe('DeviceSettings protocol routing', () => {
361
361
  expect(getDeviceState).toHaveBeenCalledWith({ refreshSections: ['settings'] });
362
362
  });
363
363
 
364
- it('rejects a successful Pro2 page response when the hardware did not reach the target', async () => {
365
- const { device, getDeviceState } = createDevice({ protocol: 'V2' });
364
+ it('does not overwrite Pro2 passphrase state when refreshed state does not match', async () => {
365
+ const { device, getDeviceState, updateState } = createDevice({ protocol: 'V2' });
366
366
  getDeviceState.mockResolvedValue({
367
367
  status: { passphraseProtection: false },
368
368
  });
@@ -376,14 +376,12 @@ describe('DeviceSettings protocol routing', () => {
376
376
  method.init();
377
377
  (method as any).device = device;
378
378
 
379
- await expect(method.run()).rejects.toMatchObject({
380
- errorCode: HardwareErrorCode.RuntimeError,
381
- message: 'Protocol V2 passphrase setting did not reach the requested value.',
382
- });
379
+ await expect(method.run()).resolves.toEqual({ message: 'Success' });
380
+ expect(updateState).not.toHaveBeenCalled();
383
381
  });
384
382
 
385
- it('accepts a locked Pro2 as confirmation after disabling passphrase', async () => {
386
- const { device, getDeviceState } = createDevice({ protocol: 'V2' });
383
+ it('keeps the previous Pro2 passphrase state when refreshed state is unavailable after locking', async () => {
384
+ const { device, getDeviceState, updateState } = createDevice({ protocol: 'V2' });
387
385
  getDeviceState
388
386
  .mockResolvedValueOnce({
389
387
  status: { unlocked: true, passphraseProtection: true },
@@ -402,6 +400,7 @@ describe('DeviceSettings protocol routing', () => {
402
400
  (method as any).device = device;
403
401
 
404
402
  await expect(method.run()).resolves.toEqual({ message: 'Success' });
403
+ expect(updateState).not.toHaveBeenCalled();
405
404
  });
406
405
 
407
406
  it('keeps Protocol V1 passphrase settings on ApplySettings', async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceSettings.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceSettings.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAgB3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA0D5D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU,CAAC,aAAa,CAAC;IACnE,qBAAqB;IAIrB,IAAI;IA0EJ,eAAe;;;;;;;IAWT,GAAG;CAwIV"}
1
+ {"version":3,"file":"DeviceSettings.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceSettings.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAgB3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA0D5D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU,CAAC,aAAa,CAAC;IACnE,qBAAqB;IAIrB,IAAI;IA0EJ,eAAe;;;;;;;IAWT,GAAG;CA2HV"}
@@ -5,8 +5,10 @@ import DeviceConnector from '../device/DeviceConnector';
5
5
  import type { ConnectSettings } from '../types';
6
6
  import type { CoreMessage } from '../events';
7
7
  import type { LowlevelTransportSharedPlugin } from '@onekeyfe/hd-transport';
8
+ import type { BaseMethod } from '../api/BaseMethod';
8
9
  export type CoreContext = ReturnType<Core['getCoreContext']>;
9
10
  export declare const callAPI: (context: CoreContext, message: CoreMessage) => Promise<any>;
11
+ export declare function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unknown): boolean;
10
12
  export declare const cancel: (context: CoreContext, connectId?: string) => void;
11
13
  export declare const onDeviceButtonHandler: (__0_0: Device, __0_1: import("../events").DeviceButtonRequestPayload) => void;
12
14
  export default class Core extends EventEmitter {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2BAA2B,CAAC;AAYxD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAmD,MAAM,WAAW,CAAC;AAI9F,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,wBAAwB,CAAC;AAYhC,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAmE7D,eAAO,MAAM,OAAO,YAAmB,WAAW,WAAW,WAAW,iBAoFvE,CAAC;AAw6BF,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SAqF9D,CAAC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vE,CAAC;AA2qBF,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAQlF;AAsPD,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SAqF9D,CAAC;AAmGF,eAAO,MAAM,qBAAqB,gFAejC,CAAC;AAiLF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,cAAc,CAAoB;IAE1C,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,YAAY,CAAsB;IAE1C,OAAO,CAAC,cAAc,CAAC,CAAgB;IAGvC,OAAO,CAAC,sBAAsB,CAAoC;IAElE,OAAO,CAAC,iBAAiB,CAAoB;;IAS7C,OAAO,CAAC,cAAc;IA6BhB,aAAa,CAAC,OAAO,EAAE,WAAW;IAuExC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAOV,gBAAgB;CAiC/B;AAED,eAAO,MAAM,QAAQ,YAIpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAiBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;UASf,CAAC"}
package/dist/index.js CHANGED
@@ -48526,14 +48526,7 @@ class DeviceSettings extends BaseMethod {
48526
48526
  const res = yield this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
48527
48527
  page: hdTransport.DeviceSettingsPage.DevicePassphrase,
48528
48528
  });
48529
- const updated = yield refreshStatusAndSettings();
48530
- const lockedAfterDisabling = requestedPassphrase === false &&
48531
- current.status.unlocked === true &&
48532
- updated.status.unlocked === false;
48533
- if (updated.status.passphraseProtection !== requestedPassphrase &&
48534
- !lockedAfterDisabling) {
48535
- throw hdShared.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 passphrase setting did not reach the requested value.');
48536
- }
48529
+ yield refreshStatusAndSettings();
48537
48530
  return res.message;
48538
48531
  }
48539
48532
  if (requestedAirgap !== undefined) {
@@ -65613,9 +65606,10 @@ function isRetryableBleProtocolV2ProbeError(method, error) {
65613
65606
  message.includes('expected V2') &&
65614
65607
  message.includes('did not respond to expected protocol'));
65615
65608
  }
65616
- function isMissingDetectedProtocolError(error) {
65609
+ function isMissingDetectedProtocolV2Error(method, error) {
65617
65610
  const typedError = error;
65618
- return ((typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.RuntimeError &&
65611
+ return (method.payload.connectProtocol === 'V2' &&
65612
+ (typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.RuntimeError &&
65619
65613
  typeof typedError.message === 'string' &&
65620
65614
  typedError.message.includes('Device protocol has not been detected'));
65621
65615
  }
@@ -65653,7 +65647,7 @@ function connectDeviceForBle(method, device, retryCount = 0) {
65653
65647
  }
65654
65648
  }
65655
65649
  catch (err) {
65656
- const requiresColdReconnect = isMissingDetectedProtocolError(err);
65650
+ const requiresColdReconnect = isMissingDetectedProtocolV2Error(method, err);
65657
65651
  if ((hdShared.ERROR_CODES_REQUIRE_DISCONNECT.includes(err.errorCode) || requiresColdReconnect) &&
65658
65652
  device.mainId &&
65659
65653
  device.deviceConnector) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.131",
3
+ "version": "1.2.0-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.0-alpha.131",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.131",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.132",
29
+ "@onekeyfe/hd-transport": "1.2.0-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": "81b472e983e80e6aa771b991dc9c0c9b1bdcf07b"
49
+ "gitHead": "e02f784ed4bd26e3efee4592c0c286f0d740425e"
50
50
  }
@@ -200,20 +200,7 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
200
200
  const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
201
201
  page: DeviceSettingsPage.DevicePassphrase,
202
202
  });
203
- const updated = await refreshStatusAndSettings();
204
- const lockedAfterDisabling =
205
- requestedPassphrase === false &&
206
- current.status.unlocked === true &&
207
- updated.status.unlocked === false;
208
- if (
209
- updated.status.passphraseProtection !== requestedPassphrase &&
210
- !lockedAfterDisabling
211
- ) {
212
- throw TypedError(
213
- HardwareErrorCode.RuntimeError,
214
- 'Protocol V2 passphrase setting did not reach the requested value.'
215
- );
216
- }
203
+ await refreshStatusAndSettings();
217
204
  return res.message;
218
205
  }
219
206
  if (requestedAirgap !== undefined) {
package/src/core/index.ts CHANGED
@@ -924,9 +924,10 @@ function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown)
924
924
  );
925
925
  }
926
926
 
927
- function isMissingDetectedProtocolError(error: unknown) {
927
+ export function isMissingDetectedProtocolV2Error(method: BaseMethod, error: unknown) {
928
928
  const typedError = error as { errorCode?: unknown; message?: unknown };
929
929
  return (
930
+ method.payload.connectProtocol === 'V2' &&
930
931
  typedError?.errorCode === HardwareErrorCode.RuntimeError &&
931
932
  typeof typedError.message === 'string' &&
932
933
  typedError.message.includes('Device protocol has not been detected')
@@ -970,7 +971,7 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
970
971
  DevicePool.emitter.emit(DEVICE.CONNECT, device);
971
972
  }
972
973
  } catch (err) {
973
- const requiresColdReconnect = isMissingDetectedProtocolError(err);
974
+ const requiresColdReconnect = isMissingDetectedProtocolV2Error(method, err);
974
975
  // Device.run()'s REQUIRE_DISCONNECT handling never sees acquire/initialize
975
976
  // failures, so with keep-alive a wedged link would be reused by every retry
976
977
  // (field case: Initialize timing out at 25s per attempt, forever). Drop it