@onekeyfe/hd-core 0.2.56 → 0.3.1

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,54 @@
1
+ import EventEmitter from 'events';
2
+ import { CoreApi } from './types/api';
3
+ import { createCoreApi } from './inject';
4
+ import type { LowLevelCoreApi } from './lowLevelInject';
5
+
6
+ export interface TopLevelInjectApi {
7
+ init: CoreApi['init'];
8
+ call: CoreApi['call'];
9
+ }
10
+
11
+ const eventEmitter = new EventEmitter();
12
+
13
+ export const topLevelInject = () => {
14
+ let lowLevelApi: LowLevelCoreApi | undefined;
15
+ const call = (params: any) => {
16
+ if (!lowLevelApi) return Promise.resolve(undefined);
17
+ return lowLevelApi.call(params);
18
+ };
19
+ const api: CoreApi = {
20
+ on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
21
+ eventEmitter.on(type, fn);
22
+ },
23
+
24
+ emit: (eventName: string, ...args: any[]) => {
25
+ eventEmitter.emit(eventName, ...args);
26
+ },
27
+
28
+ off: (type, fn) => {
29
+ eventEmitter.emit(type, fn);
30
+ },
31
+
32
+ init: (settings, hardwareLowLeverApi) => {
33
+ lowLevelApi = hardwareLowLeverApi;
34
+ return lowLevelApi?.init(settings) ?? Promise.resolve(false);
35
+ },
36
+
37
+ call,
38
+
39
+ ...createCoreApi(call),
40
+
41
+ removeAllListeners: type => {
42
+ eventEmitter.removeAllListeners(type);
43
+ lowLevelApi?.removeAllListeners(type);
44
+ },
45
+
46
+ dispose: () => lowLevelApi?.dispose(),
47
+
48
+ uiResponse: response => lowLevelApi?.uiResponse(response),
49
+
50
+ cancel: (connectId?: string) => lowLevelApi?.cancel(connectId),
51
+ };
52
+
53
+ return api;
54
+ };
@@ -116,6 +116,7 @@ export type CoreApi = {
116
116
  init: typeof init;
117
117
  on: typeof on;
118
118
  off: typeof off;
119
+ emit: (event: string, ...args: any[]) => void;
119
120
  removeAllListeners: typeof removeAllListeners;
120
121
  dispose: () => void;
121
122
  call: (params: any) => Promise<any>;
@@ -1,3 +1,7 @@
1
+ import { LowLevelCoreApi } from '../../lowLevelInject';
1
2
  import type { ConnectSettings } from '../settings';
2
3
 
3
- export declare function init(settings: Partial<ConnectSettings>): Promise<boolean>;
4
+ export declare function init(
5
+ settings: Partial<ConnectSettings>,
6
+ lowLevelApi?: LowLevelCoreApi
7
+ ): Promise<boolean>;
@@ -184,7 +184,7 @@ export const getFirmwareUpdateField = (features: Features, updateType: 'firmware
184
184
  return 'ble';
185
185
  }
186
186
 
187
- if (deviceType === 'classic') {
187
+ if (deviceType === 'classic' || deviceType === 'mini') {
188
188
  return 'firmware-v2';
189
189
  }
190
190