@onekeyfe/hd-core 0.2.46 → 0.2.49-alpha.0
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/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/index.d.ts +28 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -159
- 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/firmware/uploadFirmware.ts +5 -3
- package/src/api/polkadot/PolkadotGetAddress.ts +2 -2
- package/src/api/polkadot/PolkadotSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/index.ts +28 -0
- package/src/inject.ts +203 -187
- package/src/lowLevelInject.ts +52 -0
- package/src/topLevelInject.ts +55 -0
- package/src/types/api/index.ts +1 -0
- package/src/types/api/init.ts +5 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { CallMethod, CoreMessage } from './events';
|
|
3
|
+
import { CoreApi } from './types/api';
|
|
4
|
+
import { createCoreApi } from './inject';
|
|
5
|
+
|
|
6
|
+
type IAddHardwareGlobalEventListener = (coreMessage: CoreMessage) => void;
|
|
7
|
+
|
|
8
|
+
export interface LowLevelInjectApi {
|
|
9
|
+
call: CallMethod;
|
|
10
|
+
eventEmitter: EventEmitter;
|
|
11
|
+
init: CoreApi['init'];
|
|
12
|
+
dispose: CoreApi['dispose'];
|
|
13
|
+
uiResponse: CoreApi['uiResponse'];
|
|
14
|
+
cancel: CoreApi['cancel'];
|
|
15
|
+
addHardwareGlobalEventListener: (listener: IAddHardwareGlobalEventListener) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type LowLevelCoreApi = Omit<CoreApi, 'on' | 'off'> & {
|
|
19
|
+
addHardwareGlobalEventListener: (listener: IAddHardwareGlobalEventListener) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const lowLevelInject = ({
|
|
23
|
+
call,
|
|
24
|
+
cancel,
|
|
25
|
+
dispose,
|
|
26
|
+
eventEmitter,
|
|
27
|
+
init,
|
|
28
|
+
uiResponse,
|
|
29
|
+
addHardwareGlobalEventListener,
|
|
30
|
+
}: LowLevelInjectApi): LowLevelCoreApi => {
|
|
31
|
+
const api: LowLevelCoreApi = {
|
|
32
|
+
addHardwareGlobalEventListener,
|
|
33
|
+
removeAllListeners: type => {
|
|
34
|
+
eventEmitter.removeAllListeners(type);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
init,
|
|
38
|
+
|
|
39
|
+
call,
|
|
40
|
+
|
|
41
|
+
dispose,
|
|
42
|
+
|
|
43
|
+
uiResponse,
|
|
44
|
+
|
|
45
|
+
cancel,
|
|
46
|
+
|
|
47
|
+
emit: () => {},
|
|
48
|
+
|
|
49
|
+
...createCoreApi(call),
|
|
50
|
+
};
|
|
51
|
+
return api;
|
|
52
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
const EmptyFN = () => {};
|
|
14
|
+
|
|
15
|
+
export const topLevelInject = () => {
|
|
16
|
+
let lowLevelApi: LowLevelCoreApi | undefined;
|
|
17
|
+
const call = (params: any) => {
|
|
18
|
+
if (!lowLevelApi) return Promise.resolve(undefined);
|
|
19
|
+
return lowLevelApi.call(params);
|
|
20
|
+
};
|
|
21
|
+
const api: CoreApi = {
|
|
22
|
+
on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
|
|
23
|
+
eventEmitter.on(type, fn);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
emit: (eventName: string, ...args: any[]) => {
|
|
27
|
+
eventEmitter.emit(eventName, ...args);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
off: (type, fn) => {
|
|
31
|
+
eventEmitter.emit(type, fn);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
init: (settings, hardwareLowLeverApi) => {
|
|
35
|
+
lowLevelApi = hardwareLowLeverApi;
|
|
36
|
+
return lowLevelApi?.init(settings) ?? Promise.resolve(false);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
call,
|
|
40
|
+
|
|
41
|
+
...createCoreApi(call),
|
|
42
|
+
|
|
43
|
+
removeAllListeners: type => {
|
|
44
|
+
eventEmitter.removeAllListeners(type);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
dispose: lowLevelApi?.dispose ?? EmptyFN,
|
|
48
|
+
|
|
49
|
+
uiResponse: lowLevelApi?.uiResponse ?? EmptyFN,
|
|
50
|
+
|
|
51
|
+
cancel: lowLevelApi?.cancel ?? EmptyFN,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return api;
|
|
55
|
+
};
|
package/src/types/api/index.ts
CHANGED
|
@@ -113,6 +113,7 @@ export type CoreApi = {
|
|
|
113
113
|
init: typeof init;
|
|
114
114
|
on: typeof on;
|
|
115
115
|
off: typeof off;
|
|
116
|
+
emit: (event: string, ...args: any[]) => void;
|
|
116
117
|
removeAllListeners: typeof removeAllListeners;
|
|
117
118
|
dispose: () => void;
|
|
118
119
|
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>;
|