@onekeyfe/hd-core 1.1.2-alpha.2 → 1.1.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.
Files changed (56) hide show
  1. package/dist/api/BaseMethod.d.ts +0 -2
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +28 -4
  4. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
  5. package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -1
  6. package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
  7. package/dist/api/evm/EVMGetPublicKey.d.ts +0 -1
  8. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  9. package/dist/api/index.d.ts +0 -1
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/core/RequestQueue.d.ts +0 -4
  12. package/dist/core/RequestQueue.d.ts.map +1 -1
  13. package/dist/core/index.d.ts +2 -1
  14. package/dist/core/index.d.ts.map +1 -1
  15. package/dist/device/Device.d.ts +0 -1
  16. package/dist/device/Device.d.ts.map +1 -1
  17. package/dist/events/call.d.ts +0 -9
  18. package/dist/events/call.d.ts.map +1 -1
  19. package/dist/events/core.d.ts +2 -2
  20. package/dist/events/core.d.ts.map +1 -1
  21. package/dist/events/iframe.d.ts +1 -11
  22. package/dist/events/iframe.d.ts.map +1 -1
  23. package/dist/index.d.ts +10 -39
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +104 -272
  26. package/dist/inject.d.ts +0 -3
  27. package/dist/inject.d.ts.map +1 -1
  28. package/dist/types/api/allNetworkGetAddress.d.ts +1 -11
  29. package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
  30. package/dist/types/api/evmGetPublicKey.d.ts +0 -1
  31. package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
  32. package/dist/types/api/index.d.ts +1 -2
  33. package/dist/types/api/index.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/src/api/BaseMethod.ts +0 -3
  36. package/src/api/allnetwork/AllNetworkGetAddress.ts +407 -5
  37. package/src/api/cosmos/CosmosGetPublicKey.ts +1 -1
  38. package/src/api/evm/EVMGetPublicKey.ts +3 -9
  39. package/src/api/index.ts +0 -1
  40. package/src/core/RequestQueue.ts +0 -26
  41. package/src/core/index.ts +2 -28
  42. package/src/device/Device.ts +0 -14
  43. package/src/events/call.ts +0 -10
  44. package/src/events/core.ts +1 -7
  45. package/src/events/iframe.ts +1 -12
  46. package/src/index.ts +1 -2
  47. package/src/inject.ts +0 -47
  48. package/src/types/api/allNetworkGetAddress.ts +1 -17
  49. package/src/types/api/evmGetPublicKey.ts +0 -1
  50. package/src/types/api/index.ts +1 -2
  51. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +0 -46
  52. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +0 -1
  53. package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts +0 -8
  54. package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts.map +0 -1
  55. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +0 -427
  56. package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +0 -104
package/src/core/index.ts CHANGED
@@ -52,7 +52,7 @@ import { getSynchronize } from '../utils/getSynchronize';
52
52
 
53
53
  const Log = getLogger(LoggerNames.Core);
54
54
 
55
- export type CoreContext = ReturnType<Core['getCoreContext']>;
55
+ type CoreContext = ReturnType<Core['getCoreContext']>;
56
56
 
57
57
  function hasDeriveCardano(method: BaseMethod): boolean {
58
58
  if (
@@ -195,11 +195,6 @@ const onCallDevice = async (
195
195
  DevicePool.clearDeviceCache(method.payload.connectId);
196
196
  }
197
197
 
198
- // 等待之前的 callback 任务完成(确保设备不会并发调用)
199
- if (method.connectId) {
200
- await context.waitForCallbackTasks(method.connectId);
201
- }
202
-
203
198
  await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
204
199
 
205
200
  const task = requestQueue.createTask(method);
@@ -230,7 +225,6 @@ const onCallDevice = async (
230
225
 
231
226
  Log.debug('Call API - setDevice: ', device.mainId);
232
227
  method.setDevice?.(device);
233
- method.context = context;
234
228
 
235
229
  device.on(DEVICE.PIN, onDevicePinHandler);
236
230
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
@@ -246,10 +240,6 @@ const onCallDevice = async (
246
240
  );
247
241
 
248
242
  try {
249
- if (method.connectId) {
250
- await context.waitForCallbackTasks(method.connectId);
251
- }
252
-
253
243
  await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
254
244
 
255
245
  const inner = async (): Promise<void> => {
@@ -720,10 +710,6 @@ export const cancel = (context: CoreContext, connectId?: string) => {
720
710
  // }
721
711
  // setPrePendingCallPromise(device?.interruptionFromUser());
722
712
  // requestQueue.abortRequestsByConnectId(connectId);
723
-
724
- // cancel callback tasks
725
- requestQueue.cancelCallbackTasks(connectId);
726
-
727
713
  const requestIds = requestQueue.getRequestTasksId();
728
714
  Log.debug(
729
715
  `Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(
@@ -961,7 +947,7 @@ const removeUiPromise = (promise: Deferred<any>) => {
961
947
  export default class Core extends EventEmitter {
962
948
  private requestQueue = new RequestQueue();
963
949
 
964
- // background task
950
+ // 上一个请求的 promise 完成,后续需要清理的工作,需要在下一次请求前完成
965
951
  private prePendingCallPromise: Promise<void> | undefined;
966
952
 
967
953
  private methodSynchronize = getSynchronize();
@@ -974,13 +960,6 @@ export default class Core extends EventEmitter {
974
960
  setPrePendingCallPromise: (promise: Promise<void> | undefined) => {
975
961
  this.prePendingCallPromise = promise;
976
962
  },
977
- // callback 任务管理
978
- registerCallbackTask: (connectId: string, callbackPromise: Deferred<any>) => {
979
- this.requestQueue.registerPendingCallbackTask(connectId, callbackPromise);
980
- },
981
- waitForCallbackTasks: (connectId: string) =>
982
- this.requestQueue.waitForPendingCallbackTasks(connectId),
983
- cancelCallbackTasks: (connectId: string) => this.requestQueue.cancelCallbackTasks(connectId),
984
963
  };
985
964
  }
986
965
 
@@ -1031,11 +1010,6 @@ export default class Core extends EventEmitter {
1031
1010
  cancel(this.getCoreContext(), message.payload.connectId);
1032
1011
  break;
1033
1012
  }
1034
- case IFRAME.CALLBACK: {
1035
- Log.log('callback message: ', message);
1036
- postMessage(message);
1037
- break;
1038
- }
1039
1013
  default:
1040
1014
  break;
1041
1015
  }
@@ -151,8 +151,6 @@ export class Device extends EventEmitter {
151
151
 
152
152
  passphraseState: string | undefined = undefined;
153
153
 
154
- pendingCallbackPromise?: Deferred<void>;
155
-
156
154
  constructor(descriptor: DeviceDescriptor) {
157
155
  super();
158
156
  this.originalDescriptor = descriptor;
@@ -266,18 +264,6 @@ export class Device extends EventEmitter {
266
264
  (this.isUsedHere() && !this.keepSession && this.mainId) ||
267
265
  (this.mainId && DataManager.isBleConnect(env))
268
266
  ) {
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
-
281
267
  if (this.commands) {
282
268
  this.commands.dispose(false);
283
269
  if (this.commands.callPromise) {
@@ -58,16 +58,6 @@ 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
-
71
61
  export const RESPONSE_EVENT = 'RESPONSE_EVENT';
72
62
 
73
63
  export interface MethodResponseMessage {
@@ -1,11 +1,6 @@
1
1
  import { HardwareError } from '@onekeyfe/hd-shared';
2
2
  import { Unsuccessful } from '../types/params';
3
- import {
4
- IFrameCallMessage,
5
- IFrameCancelMessage,
6
- IFrameSwitchTransportMessage,
7
- IFrameCallbackMessage,
8
- } from './call';
3
+ import { IFrameCallMessage, IFrameCancelMessage, IFrameSwitchTransportMessage } from './call';
9
4
  import { DeviceEventMessage } from './device';
10
5
  import { IFrameEventMessage } from './iframe';
11
6
  import { UiEventMessage } from './ui-request';
@@ -23,7 +18,6 @@ export type CoreMessage = {
23
18
  | IFrameCallMessage
24
19
  | IFrameCancelMessage
25
20
  | IFrameSwitchTransportMessage
26
- | IFrameCallbackMessage
27
21
  | UiResponseMessage
28
22
  | UiEventMessage
29
23
  | DeviceEventMessage
@@ -8,7 +8,6 @@ export const IFRAME = {
8
8
  CALL: 'iframe-call',
9
9
  CANCEL: 'iframe-cancel',
10
10
  SWITCH_TRANSPORT: 'iframe-switch-transport',
11
- CALLBACK: 'iframe-callback',
12
11
  } as const;
13
12
 
14
13
  export interface IFrameInit {
@@ -30,17 +29,7 @@ export interface IFrameSwitchTransport {
30
29
  };
31
30
  }
32
31
 
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;
32
+ export type IFrameEvent = IFrameInit | IFrameBridge | IFrameSwitchTransport;
44
33
  export type IFrameEventMessage = IFrameEvent & { event: typeof UI_EVENT };
45
34
 
46
35
  export const createIFrameMessage: MessageFactoryFn<typeof UI_EVENT, IFrameEvent> = (
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { inject, InjectApi, executeCallback, cleanupCallback } from './inject';
1
+ import { inject, InjectApi } from './inject';
2
2
  import { lowLevelInject, LowLevelInjectApi, LowLevelCoreApi } from './lowLevelInject';
3
3
  import { topLevelInject } from './topLevelInject';
4
4
  import { CoreApi } from './types/api';
@@ -14,7 +14,6 @@ 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 };
18
17
 
19
18
  const HardwareSdk = ({
20
19
  init,
package/src/inject.ts CHANGED
@@ -1,31 +1,6 @@
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 };
29
4
 
30
5
  export interface InjectApi {
31
6
  call: CallMethod;
@@ -172,28 +147,6 @@ export const createCoreApi = (
172
147
 
173
148
  allNetworkGetAddress: (connectId, deviceId, params) =>
174
149
  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
- },
197
150
 
198
151
  evmGetAddress: (connectId, deviceId, params) =>
199
152
  call({ ...params, connectId, deviceId, method: 'evmGetAddress' }),
@@ -91,7 +91,7 @@ type AllNetworkAddressPayload =
91
91
  xpubSegwit: string;
92
92
  };
93
93
 
94
- export type AllNetworkAddress = AllNetworkAddressParams & {
94
+ export type AllNetworkAddress = CommonResponseParams & {
95
95
  success: boolean;
96
96
  payload?:
97
97
  | AllNetworkAddressPayload
@@ -108,24 +108,8 @@ 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
-
121
111
  export declare function allNetworkGetAddress(
122
112
  connectId: string,
123
113
  deviceId: string,
124
114
  params: CommonParams & AllNetworkGetAddressParams
125
115
  ): Response<AllNetworkAddress[]>;
126
-
127
- export declare function allNetworkGetAddressByLoop(
128
- connectId: string,
129
- deviceId: string,
130
- params: CommonParams & AllNetworkGetAddressParamsByLoop
131
- ): Response<string[]>;
@@ -14,7 +14,6 @@ export type EVMGetPublicKeyParams = {
14
14
  path: string | number[];
15
15
  showOnOneKey?: boolean;
16
16
  chainId?: number;
17
- useBatch?: boolean;
18
17
  };
19
18
 
20
19
  export declare function evmGetPublicKey(
@@ -43,7 +43,7 @@ import { setU2FCounter } from './setU2FCounter';
43
43
 
44
44
  import { cipherKeyValue } from './cipherKeyValue';
45
45
 
46
- import { allNetworkGetAddress, allNetworkGetAddressByLoop } from './allNetworkGetAddress';
46
+ import { allNetworkGetAddress } from './allNetworkGetAddress';
47
47
 
48
48
  import { evmGetAddress } from './evmGetAddress';
49
49
  import { evmGetPublicKey } from './evmGetPublicKey';
@@ -230,7 +230,6 @@ export type CoreApi = {
230
230
  * All network function
231
231
  */
232
232
  allNetworkGetAddress: typeof allNetworkGetAddress;
233
- allNetworkGetAddressByLoop: typeof allNetworkGetAddressByLoop;
234
233
 
235
234
  /**
236
235
  * EVM function
@@ -1,46 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import { CoreApi } from '../../types';
3
- import type { AllNetworkAddressParams, INetwork, AllNetworkAddress, CommonResponseParams } from '../../types/api/allNetworkGetAddress';
4
- export type NetworkConfig = {
5
- methodName: keyof CoreApi;
6
- getParams?: (baseParams: AllNetworkAddressParams, chainName?: string, methodName?: string) => any;
7
- dependOnMethodName?: (keyof CoreApi)[];
8
- };
9
- export type INetworkReal = Exclude<INetwork, 'tbtc' | 'bch' | 'doge' | 'ltc' | 'neurai'>;
10
- export type NetworkConfigMap = {
11
- [K in INetworkReal]: NetworkConfig;
12
- };
13
- export declare const networkAliases: {
14
- [key: string]: {
15
- name: INetworkReal;
16
- coin: string;
17
- };
18
- };
19
- type MethodParams = {
20
- methodName: keyof CoreApi;
21
- params: Parameters<CoreApi[keyof CoreApi]>[0];
22
- _originRequestParams: AllNetworkAddressParams;
23
- _originalIndex: number;
24
- };
25
- export default abstract class AllNetworkGetAddressBase extends BaseMethod<{
26
- address_n: number[];
27
- show_display: boolean;
28
- network: string;
29
- chain_name?: string;
30
- }[]> {
31
- init(): void;
32
- generateMethodName({ network, payload, originalIndex, }: {
33
- network: INetwork;
34
- payload: AllNetworkAddressParams;
35
- originalIndex: number;
36
- }): MethodParams;
37
- callMethod(methodName: keyof CoreApi, params: any & {
38
- bundle: (any & {
39
- _originRequestParams: CommonResponseParams;
40
- })[];
41
- }): Promise<AllNetworkAddress[]>;
42
- abstract getAllNetworkAddress(): Promise<AllNetworkAddress[]>;
43
- run(): Promise<AllNetworkAddress[]>;
44
- }
45
- export {};
46
- //# sourceMappingURL=AllNetworkGetAddressBase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AllNetworkGetAddressBase.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressBase.ts"],"names":[],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;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EAAE,CACJ;IACC,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;IAyDH,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAEvD,GAAG;CAGV"}
@@ -1,8 +0,0 @@
1
- import AllNetworkGetAddressBase from './AllNetworkGetAddressBase';
2
- export default class AllNetworkGetAddressByLoop extends AllNetworkGetAddressBase {
3
- getAllNetworkAddress(): Promise<never[]>;
4
- private processCallbacksInBackground;
5
- private sendFinishCallback;
6
- private sendItemCallback;
7
- }
8
- //# sourceMappingURL=AllNetworkGetAddressByLoop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AllNetworkGetAddressByLoop.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressByLoop.ts"],"names":[],"mappings":"AAOA,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAElE,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IACxE,oBAAoB;YAwBZ,4BAA4B;IA4C1C,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,gBAAgB;CAczB"}