@onekeyfe/hd-core 1.2.0-alpha.14 → 1.2.0-alpha.15

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.
@@ -0,0 +1,35 @@
1
+ import { DEVICE } from '../src/events';
2
+ import { registerHardwareUiEventListeners } from '../src/core/deviceEventRegistration';
3
+
4
+ const handlers = {
5
+ pin: jest.fn(),
6
+ button: jest.fn(),
7
+ passphrase: jest.fn(),
8
+ passphraseOnDevice: jest.fn(),
9
+ };
10
+
11
+ const createDevice = (protocolV2: boolean) => ({
12
+ isProtocolV2: jest.fn(() => protocolV2),
13
+ on: jest.fn(),
14
+ });
15
+
16
+ describe('hardware UI event registration', () => {
17
+ test('does not register hardware-originated UI events for Protocol V2 devices', () => {
18
+ const device = createDevice(true);
19
+
20
+ expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(false);
21
+ expect(device.on).not.toHaveBeenCalled();
22
+ });
23
+
24
+ test('keeps the existing interactive event listeners for Protocol V1 devices', () => {
25
+ const device = createDevice(false);
26
+
27
+ expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(true);
28
+ expect(device.on.mock.calls.map(([type]) => type)).toEqual([
29
+ DEVICE.PIN,
30
+ DEVICE.BUTTON,
31
+ DEVICE.PASSPHRASE,
32
+ DEVICE.PASSPHRASE_ON_DEVICE,
33
+ ]);
34
+ });
35
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"AllNetworkGetAddressBase.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressBase.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAe3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAI9C,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,E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AAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAOrD,CAAC;AAiMF,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,wBAAyB,SAAQ,UAAU,CACvE;IACE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EAAE,CACJ;IACC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAQ;IAE/C,IAAI;IAkBJ,kBAAkB,CAAC,EACjB,OAAO,EACP,OAAO,EACP,aAAa,GACd,EAAE;QACD,OAAO,EAAE,QAAQ,CAAC;QAClB,OAAO,EAAE,uBAAuB,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,YAAY;IAqBV,UAAU,CACd,UAAU,EAAE,MAAM,OAAO,EACzB,MAAM,EAAE,GAAG,GAAG;QACZ,MAAM,EAAE,CAAC,GAAG,GAAG;YAAE,oBAAoB,EAAE,oBAAoB,CAAA;SAAE,CAAC,EAAE,CAAC;KAClE,EACD,eAAe,EAAE,MAAM;IAwHzB,QAAQ,CAAC,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAE9E,GAAG;CAuBV"}
@@ -0,0 +1,11 @@
1
+ import { DEVICE } from '../events';
2
+ import type { Device, DeviceEvents } from '../device/Device';
3
+ export type HardwareUiEventHandlers = {
4
+ pin: (...event: DeviceEvents[typeof DEVICE.PIN]) => void;
5
+ button: (...event: DeviceEvents[typeof DEVICE.BUTTON]) => void;
6
+ passphrase: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE]) => void;
7
+ passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
8
+ };
9
+ export declare const shouldRegisterHardwareUiEvents: (device: Pick<Device, 'isProtocolV2'>) => boolean;
10
+ export declare function registerHardwareUiEventListeners(device: Pick<Device, 'isProtocolV2' | 'on'>, handlers: HardwareUiEventHandlers): boolean;
11
+ //# sourceMappingURL=deviceEventRegistration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceEventRegistration.d.ts","sourceRoot":"","sources":["../../src/core/deviceEventRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IACzD,MAAM,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC/D,UAAU,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IACvE,kBAAkB,EAAE,CAAC,GAAG,KAAK,EAAE,YAAY,CAAC,OAAO,MAAM,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;CAC1F,CAAC;AAEF,eAAO,MAAM,8BAA8B,WAAY,KAAK,MAAM,EAAE,cAAc,CAAC,YAC3D,CAAC;AAEzB,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC,EAC3C,QAAQ,EAAE,uBAAuB,WAWlC"}
@@ -1 +1 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od {
48610
48610
  }
48611
48611
  }
48612
48612
 
48613
+ const shouldRegisterHardwareUiEvents = (device) => !device.isProtocolV2();
48614
+ function registerHardwareUiEventListeners(device, handlers) {
48615
+ if (!shouldRegisterHardwareUiEvents(device)) {
48616
+ return false;
48617
+ }
48618
+ device.on(DEVICE.PIN, handlers.pin);
48619
+ device.on(DEVICE.BUTTON, handlers.button);
48620
+ device.on(DEVICE.PASSPHRASE, handlers.passphrase);
48621
+ device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
48622
+ return true;
48623
+ }
48624
+
48613
48625
  const Mainnet = 'mainnet';
48614
48626
  const networkAliases = {
48615
48627
  tbtc: { name: 'btc', coin: 'Testnet' },
@@ -48877,9 +48889,11 @@ class AllNetworkGetAddressBase extends BaseMethod {
48877
48889
  commandsInstanceId: (_c = this.device.commands) === null || _c === void 0 ? void 0 : _c.instanceId,
48878
48890
  });
48879
48891
  }
48880
- this.device.on(DEVICE.BUTTON, buttonListener);
48881
- this.device.on(DEVICE.PIN, onSignalAbort);
48882
- this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
48892
+ if (shouldRegisterHardwareUiEvents(this.device)) {
48893
+ this.device.on(DEVICE.BUTTON, buttonListener);
48894
+ this.device.on(DEVICE.PIN, onSignalAbort);
48895
+ this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
48896
+ }
48883
48897
  preCheckDeviceSupport(this.device, method);
48884
48898
  if (this.temporarySafetyCheckPrompted) {
48885
48899
  method.temporarySafetyCheckPrompted = true;
@@ -48918,9 +48932,11 @@ class AllNetworkGetAddressBase extends BaseMethod {
48918
48932
  }
48919
48933
  }
48920
48934
  finally {
48921
- this.device.off(DEVICE.BUTTON, buttonListener);
48922
- this.device.off(DEVICE.PIN, onSignalAbort);
48923
- this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
48935
+ if (shouldRegisterHardwareUiEvents(this.device)) {
48936
+ this.device.off(DEVICE.BUTTON, buttonListener);
48937
+ this.device.off(DEVICE.PIN, onSignalAbort);
48938
+ this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
48939
+ }
48924
48940
  }
48925
48941
  return result;
48926
48942
  });
@@ -58445,10 +58461,14 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
58445
58461
  if (activeRequests.length > 0) {
58446
58462
  Log.warn(`[${method.instanceId}] Device ${device.instanceId} has ${activeRequests.length} active requests:`, activeRequests.map(formatRequestContext));
58447
58463
  }
58448
- device.on(DEVICE.PIN, onDevicePinHandler);
58449
- device.on(DEVICE.BUTTON, onDeviceButtonHandler);
58450
- device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
58451
- device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
58464
+ registerHardwareUiEventListeners(device, {
58465
+ pin: onDevicePinHandler,
58466
+ button: onDeviceButtonHandler,
58467
+ passphrase: message.payload.useEmptyPassphrase
58468
+ ? onEmptyPassphraseHandler
58469
+ : onDevicePassphraseHandler,
58470
+ passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
58471
+ });
58452
58472
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
58453
58473
  device.on(DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE, onSelectDeviceInBootloaderForWebDeviceHandler);
58454
58474
  device.on(DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE, onSelectDeviceForSwitchFirmwareWebDeviceHandler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.14",
3
+ "version": "1.2.0-alpha.15",
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.14",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.14",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.15",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.15",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/w3c-web-usb": "^1.0.10",
45
45
  "@types/web-bluetooth": "^0.0.21"
46
46
  },
47
- "gitHead": "c1edaed6435fb6049c7516c64b298ee62519e797"
47
+ "gitHead": "06dd8f9cba892bb66242e5a51038a7103fb05f09"
48
48
  }
@@ -15,6 +15,7 @@ import { DEVICE, IFRAME, createUiMessage } from '../../events';
15
15
  import { isMethodVersionRangeUnsupported } from '../../utils';
16
16
  import { UI_REQUEST } from '../../constants/ui-request';
17
17
  import { onDeviceButtonHandler } from '../../core';
18
+ import { shouldRegisterHardwareUiEvents } from '../../core/deviceEventRegistration';
18
19
  import {
19
20
  completeRequestContext,
20
21
  createRequestContext,
@@ -364,11 +365,13 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
364
365
  });
365
366
  }
366
367
 
367
- // pro pin event
368
- this.device.on(DEVICE.BUTTON, buttonListener);
369
- // classic pin event
370
- this.device.on(DEVICE.PIN, onSignalAbort);
371
- this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
368
+ if (shouldRegisterHardwareUiEvents(this.device)) {
369
+ // pro pin event
370
+ this.device.on(DEVICE.BUTTON, buttonListener);
371
+ // classic pin event
372
+ this.device.on(DEVICE.PIN, onSignalAbort);
373
+ this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
374
+ }
372
375
 
373
376
  preCheckDeviceSupport(this.device, method);
374
377
  if (this.temporarySafetyCheckPrompted) {
@@ -422,9 +425,11 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
422
425
  );
423
426
  }
424
427
  } finally {
425
- this.device.off(DEVICE.BUTTON, buttonListener);
426
- this.device.off(DEVICE.PIN, onSignalAbort);
427
- this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
428
+ if (shouldRegisterHardwareUiEvents(this.device)) {
429
+ this.device.off(DEVICE.BUTTON, buttonListener);
430
+ this.device.off(DEVICE.PIN, onSignalAbort);
431
+ this.device.off(DEVICE.PASSPHRASE, onSignalAbort);
432
+ }
428
433
  }
429
434
 
430
435
  return result;
@@ -0,0 +1,28 @@
1
+ import { DEVICE } from '../events';
2
+
3
+ import type { Device, DeviceEvents } from '../device/Device';
4
+
5
+ export type HardwareUiEventHandlers = {
6
+ pin: (...event: DeviceEvents[typeof DEVICE.PIN]) => void;
7
+ button: (...event: DeviceEvents[typeof DEVICE.BUTTON]) => void;
8
+ passphrase: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE]) => void;
9
+ passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
10
+ };
11
+
12
+ export const shouldRegisterHardwareUiEvents = (device: Pick<Device, 'isProtocolV2'>) =>
13
+ !device.isProtocolV2();
14
+
15
+ export function registerHardwareUiEventListeners(
16
+ device: Pick<Device, 'isProtocolV2' | 'on'>,
17
+ handlers: HardwareUiEventHandlers
18
+ ) {
19
+ if (!shouldRegisterHardwareUiEvents(device)) {
20
+ return false;
21
+ }
22
+
23
+ device.on(DEVICE.PIN, handlers.pin);
24
+ device.on(DEVICE.BUTTON, handlers.button);
25
+ device.on(DEVICE.PASSPHRASE, handlers.passphrase);
26
+ device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
27
+ return true;
28
+ }
package/src/core/index.ts CHANGED
@@ -55,6 +55,7 @@ import {
55
55
  import TransportManager from '../data-manager/TransportManager';
56
56
  import DeviceConnector from '../device/DeviceConnector';
57
57
  import RequestQueue from './RequestQueue';
58
+ import { registerHardwareUiEventListeners } from './deviceEventRegistration';
58
59
  import { getSynchronize } from '../utils/getSynchronize';
59
60
  import { runMethodWithUnlockRetry } from '../protocols/protocol-v2/unlockRetry';
60
61
 
@@ -395,13 +396,14 @@ const onCallDevice = async (
395
396
  );
396
397
  }
397
398
 
398
- device.on(DEVICE.PIN, onDevicePinHandler);
399
- device.on(DEVICE.BUTTON, onDeviceButtonHandler);
400
- device.on(
401
- DEVICE.PASSPHRASE,
402
- message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler
403
- );
404
- device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
399
+ registerHardwareUiEventListeners(device, {
400
+ pin: onDevicePinHandler,
401
+ button: onDeviceButtonHandler,
402
+ passphrase: message.payload.useEmptyPassphrase
403
+ ? onEmptyPassphraseHandler
404
+ : onDevicePassphraseHandler,
405
+ passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
406
+ });
405
407
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
406
408
  device.on(
407
409
  DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,