@onekeyfe/hd-core 1.1.2-alpha.1 → 1.1.2-alpha.2
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/BaseMethod.d.ts +2 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +4 -28
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +46 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -0
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts +8 -0
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts.map +1 -0
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +4 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -0
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/events/call.d.ts +9 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +11 -1
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +39 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +272 -104
- package/dist/inject.d.ts +3 -0
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/allNetworkGetAddress.d.ts +11 -1
- package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
- package/dist/types/api/evmGetPublicKey.d.ts +1 -0
- package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +3 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +5 -407
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +427 -0
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +104 -0
- package/src/api/cosmos/CosmosGetPublicKey.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +9 -3
- package/src/api/index.ts +1 -0
- package/src/core/RequestQueue.ts +26 -0
- package/src/core/index.ts +28 -2
- package/src/device/Device.ts +14 -0
- package/src/events/call.ts +10 -0
- package/src/events/core.ts +7 -1
- package/src/events/iframe.ts +12 -1
- package/src/index.ts +2 -1
- package/src/inject.ts +47 -0
- package/src/types/api/allNetworkGetAddress.ts +17 -1
- package/src/types/api/evmGetPublicKey.ts +1 -0
- package/src/types/api/index.ts +2 -1
package/src/device/Device.ts
CHANGED
|
@@ -151,6 +151,8 @@ export class Device extends EventEmitter {
|
|
|
151
151
|
|
|
152
152
|
passphraseState: string | undefined = undefined;
|
|
153
153
|
|
|
154
|
+
pendingCallbackPromise?: Deferred<void>;
|
|
155
|
+
|
|
154
156
|
constructor(descriptor: DeviceDescriptor) {
|
|
155
157
|
super();
|
|
156
158
|
this.originalDescriptor = descriptor;
|
|
@@ -264,6 +266,18 @@ export class Device extends EventEmitter {
|
|
|
264
266
|
(this.isUsedHere() && !this.keepSession && this.mainId) ||
|
|
265
267
|
(this.mainId && DataManager.isBleConnect(env))
|
|
266
268
|
) {
|
|
269
|
+
// wait for callback tasks to complete before releasing device
|
|
270
|
+
if (this.pendingCallbackPromise) {
|
|
271
|
+
try {
|
|
272
|
+
Log.debug(
|
|
273
|
+
'Waiting for callback tasks to complete before releasing device (in release method)'
|
|
274
|
+
);
|
|
275
|
+
await this.pendingCallbackPromise.promise;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
Log.error('Error waiting for callback tasks in release method:', error);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
267
281
|
if (this.commands) {
|
|
268
282
|
this.commands.dispose(false);
|
|
269
283
|
if (this.commands.callPromise) {
|
package/src/events/call.ts
CHANGED
|
@@ -58,6 +58,16 @@ export interface IFrameSwitchTransportMessage {
|
|
|
58
58
|
payload: { env: ConnectSettings['env'] };
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export interface IFrameCallbackMessage {
|
|
62
|
+
event: typeof IFRAME.CALLBACK;
|
|
63
|
+
type: typeof IFRAME.CALLBACK;
|
|
64
|
+
payload: {
|
|
65
|
+
callbackId: string;
|
|
66
|
+
data?: any;
|
|
67
|
+
error?: any;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
61
71
|
export const RESPONSE_EVENT = 'RESPONSE_EVENT';
|
|
62
72
|
|
|
63
73
|
export interface MethodResponseMessage {
|
package/src/events/core.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { HardwareError } from '@onekeyfe/hd-shared';
|
|
2
2
|
import { Unsuccessful } from '../types/params';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
IFrameCallMessage,
|
|
5
|
+
IFrameCancelMessage,
|
|
6
|
+
IFrameSwitchTransportMessage,
|
|
7
|
+
IFrameCallbackMessage,
|
|
8
|
+
} from './call';
|
|
4
9
|
import { DeviceEventMessage } from './device';
|
|
5
10
|
import { IFrameEventMessage } from './iframe';
|
|
6
11
|
import { UiEventMessage } from './ui-request';
|
|
@@ -18,6 +23,7 @@ export type CoreMessage = {
|
|
|
18
23
|
| IFrameCallMessage
|
|
19
24
|
| IFrameCancelMessage
|
|
20
25
|
| IFrameSwitchTransportMessage
|
|
26
|
+
| IFrameCallbackMessage
|
|
21
27
|
| UiResponseMessage
|
|
22
28
|
| UiEventMessage
|
|
23
29
|
| DeviceEventMessage
|
package/src/events/iframe.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const IFRAME = {
|
|
|
8
8
|
CALL: 'iframe-call',
|
|
9
9
|
CANCEL: 'iframe-cancel',
|
|
10
10
|
SWITCH_TRANSPORT: 'iframe-switch-transport',
|
|
11
|
+
CALLBACK: 'iframe-callback',
|
|
11
12
|
} as const;
|
|
12
13
|
|
|
13
14
|
export interface IFrameInit {
|
|
@@ -29,7 +30,17 @@ export interface IFrameSwitchTransport {
|
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export
|
|
33
|
+
export interface IFrameCallback {
|
|
34
|
+
type: typeof IFRAME.CALLBACK;
|
|
35
|
+
payload: {
|
|
36
|
+
callbackId: string;
|
|
37
|
+
data?: any;
|
|
38
|
+
error?: any;
|
|
39
|
+
finished?: boolean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type IFrameEvent = IFrameInit | IFrameBridge | IFrameSwitchTransport | IFrameCallback;
|
|
33
44
|
export type IFrameEventMessage = IFrameEvent & { event: typeof UI_EVENT };
|
|
34
45
|
|
|
35
46
|
export const createIFrameMessage: MessageFactoryFn<typeof UI_EVENT, IFrameEvent> = (
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject, InjectApi } from './inject';
|
|
1
|
+
import { inject, InjectApi, executeCallback, cleanupCallback } from './inject';
|
|
2
2
|
import { lowLevelInject, LowLevelInjectApi, LowLevelCoreApi } from './lowLevelInject';
|
|
3
3
|
import { topLevelInject } from './topLevelInject';
|
|
4
4
|
import { CoreApi } from './types/api';
|
|
@@ -14,6 +14,7 @@ export * from './data-manager';
|
|
|
14
14
|
export * from './events';
|
|
15
15
|
export * from './types';
|
|
16
16
|
export { whitelist, whitelistExtension } from './data/config';
|
|
17
|
+
export { executeCallback, cleanupCallback };
|
|
17
18
|
|
|
18
19
|
const HardwareSdk = ({
|
|
19
20
|
init,
|
package/src/inject.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { CallMethod } from './events';
|
|
3
3
|
import { CoreApi } from './types/api';
|
|
4
|
+
import type { AllNetworkAddress } from './types/api/allNetworkGetAddress';
|
|
5
|
+
|
|
6
|
+
type CallbackFunction = (data?: any, error?: { message: string; code?: number }) => void;
|
|
7
|
+
|
|
8
|
+
const callbackManager = new Map<string, CallbackFunction>();
|
|
9
|
+
|
|
10
|
+
const generateCallbackId = () =>
|
|
11
|
+
`callback_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
12
|
+
|
|
13
|
+
const registerCallback = (id: string, callback: CallbackFunction) => {
|
|
14
|
+
callbackManager.set(id, callback);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const executeCallback = (id: string, ...args: any[]) => {
|
|
18
|
+
const callback = callbackManager.get(id);
|
|
19
|
+
if (callback) {
|
|
20
|
+
callback(...args);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const cleanupCallback = (id: string) => {
|
|
25
|
+
callbackManager.delete(id);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { executeCallback, cleanupCallback };
|
|
4
29
|
|
|
5
30
|
export interface InjectApi {
|
|
6
31
|
call: CallMethod;
|
|
@@ -147,6 +172,28 @@ export const createCoreApi = (
|
|
|
147
172
|
|
|
148
173
|
allNetworkGetAddress: (connectId, deviceId, params) =>
|
|
149
174
|
call({ ...params, connectId, deviceId, method: 'allNetworkGetAddress' }),
|
|
175
|
+
allNetworkGetAddressByLoop: (connectId, deviceId, params) => {
|
|
176
|
+
const { onLoopItemResponse, onAllItemsResponse, ...restParams } = params;
|
|
177
|
+
|
|
178
|
+
const callbackId = generateCallbackId();
|
|
179
|
+
registerCallback(callbackId, onLoopItemResponse);
|
|
180
|
+
|
|
181
|
+
const callbackIdFinish = generateCallbackId();
|
|
182
|
+
registerCallback(callbackIdFinish, (data?: AllNetworkAddress[]) => {
|
|
183
|
+
onAllItemsResponse?.(data);
|
|
184
|
+
cleanupCallback(callbackIdFinish);
|
|
185
|
+
cleanupCallback(callbackId);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return call({
|
|
189
|
+
...restParams,
|
|
190
|
+
connectId,
|
|
191
|
+
deviceId,
|
|
192
|
+
method: 'allNetworkGetAddressByLoop',
|
|
193
|
+
callbackId,
|
|
194
|
+
callbackIdFinish,
|
|
195
|
+
});
|
|
196
|
+
},
|
|
150
197
|
|
|
151
198
|
evmGetAddress: (connectId, deviceId, params) =>
|
|
152
199
|
call({ ...params, connectId, deviceId, method: 'evmGetAddress' }),
|
|
@@ -91,7 +91,7 @@ type AllNetworkAddressPayload =
|
|
|
91
91
|
xpubSegwit: string;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
export type AllNetworkAddress =
|
|
94
|
+
export type AllNetworkAddress = AllNetworkAddressParams & {
|
|
95
95
|
success: boolean;
|
|
96
96
|
payload?:
|
|
97
97
|
| AllNetworkAddressPayload
|
|
@@ -108,8 +108,24 @@ export type AllNetworkGetAddressParams = {
|
|
|
108
108
|
bundle: AllNetworkAddressParams[];
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
export type AllNetworkGetAddressParamsByLoop = {
|
|
112
|
+
callbackId?: string;
|
|
113
|
+
callbackIdFinish?: string;
|
|
114
|
+
onLoopItemResponse: (
|
|
115
|
+
data?: AllNetworkAddress,
|
|
116
|
+
error?: { message: string; code?: number }
|
|
117
|
+
) => void;
|
|
118
|
+
onAllItemsResponse: (data?: AllNetworkAddress[]) => void;
|
|
119
|
+
};
|
|
120
|
+
|
|
111
121
|
export declare function allNetworkGetAddress(
|
|
112
122
|
connectId: string,
|
|
113
123
|
deviceId: string,
|
|
114
124
|
params: CommonParams & AllNetworkGetAddressParams
|
|
115
125
|
): Response<AllNetworkAddress[]>;
|
|
126
|
+
|
|
127
|
+
export declare function allNetworkGetAddressByLoop(
|
|
128
|
+
connectId: string,
|
|
129
|
+
deviceId: string,
|
|
130
|
+
params: CommonParams & AllNetworkGetAddressParamsByLoop
|
|
131
|
+
): Response<string[]>;
|
package/src/types/api/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ import { setU2FCounter } from './setU2FCounter';
|
|
|
43
43
|
|
|
44
44
|
import { cipherKeyValue } from './cipherKeyValue';
|
|
45
45
|
|
|
46
|
-
import { allNetworkGetAddress } from './allNetworkGetAddress';
|
|
46
|
+
import { allNetworkGetAddress, allNetworkGetAddressByLoop } from './allNetworkGetAddress';
|
|
47
47
|
|
|
48
48
|
import { evmGetAddress } from './evmGetAddress';
|
|
49
49
|
import { evmGetPublicKey } from './evmGetPublicKey';
|
|
@@ -230,6 +230,7 @@ export type CoreApi = {
|
|
|
230
230
|
* All network function
|
|
231
231
|
*/
|
|
232
232
|
allNetworkGetAddress: typeof allNetworkGetAddress;
|
|
233
|
+
allNetworkGetAddressByLoop: typeof allNetworkGetAddressByLoop;
|
|
233
234
|
|
|
234
235
|
/**
|
|
235
236
|
* EVM function
|