@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.
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +28 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +199 -154
- package/dist/inject.d.ts +1 -0
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +20 -0
- package/dist/lowLevelInject.d.ts.map +1 -0
- package/dist/topLevelInject.d.ts +7 -0
- package/dist/topLevelInject.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +1 -0
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/init.d.ts +2 -1
- package/dist/types/api/init.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/CheckBootloaderRelease.ts +1 -1
- package/src/api/firmware/updateBootloader.ts +1 -1
- package/src/core/index.ts +1 -2
- package/src/index.ts +28 -0
- package/src/inject.ts +208 -193
- package/src/lowLevelInject.ts +52 -0
- package/src/topLevelInject.ts +54 -0
- package/src/types/api/index.ts +1 -0
- package/src/types/api/init.ts +5 -1
- package/src/utils/deviceFeaturesUtils.ts +1 -1
|
@@ -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
|
+
};
|
package/src/types/api/index.ts
CHANGED
|
@@ -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>;
|
package/src/types/api/init.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { LowLevelCoreApi } from '../../lowLevelInject';
|
|
1
2
|
import type { ConnectSettings } from '../settings';
|
|
2
3
|
|
|
3
|
-
export declare function init(
|
|
4
|
+
export declare function init(
|
|
5
|
+
settings: Partial<ConnectSettings>,
|
|
6
|
+
lowLevelApi?: LowLevelCoreApi
|
|
7
|
+
): Promise<boolean>;
|