@onekeyfe/hd-core 1.1.3-alpha.3 → 1.1.3
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 +0 -2
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +28 -4
- package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -1
- package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -0
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts +0 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +0 -4
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -4
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/events/call.d.ts +0 -9
- 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 +1 -11
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +12 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -394
- package/dist/inject.d.ts +0 -3
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/allNetworkGetAddress.d.ts +2 -9
- package/dist/types/api/allNetworkGetAddress.d.ts.map +1 -1
- package/dist/types/api/evmGetPublicKey.d.ts +0 -1
- package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +1 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +0 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +407 -14
- package/src/api/btc/BTCGetPublicKey.ts +0 -13
- package/src/api/cosmos/CosmosGetPublicKey.ts +1 -1
- package/src/api/device/DeviceUnlock.ts +48 -1
- package/src/api/evm/EVMGetPublicKey.ts +3 -9
- package/src/api/index.ts +0 -1
- package/src/core/RequestQueue.ts +0 -26
- package/src/core/index.ts +3 -29
- package/src/device/Device.ts +0 -66
- package/src/events/call.ts +0 -10
- package/src/events/core.ts +1 -7
- package/src/events/iframe.ts +1 -12
- package/src/index.ts +1 -2
- package/src/inject.ts +0 -47
- package/src/types/api/allNetworkGetAddress.ts +2 -16
- package/src/types/api/evmGetPublicKey.ts +0 -1
- package/src/types/api/index.ts +1 -2
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +0 -47
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +0 -1
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts +0 -8
- package/dist/api/allnetwork/AllNetworkGetAddressByLoop.d.ts.map +0 -1
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +0 -477
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +0 -151
|
@@ -2,7 +2,7 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
2
2
|
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
import { validateParams, validateResult } from '../helpers/paramsValidator';
|
|
5
|
-
import
|
|
5
|
+
import { CosmosAddress, CosmosGetPublicKeyParams } from '../../types';
|
|
6
6
|
import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
|
|
7
7
|
|
|
8
8
|
export default class CosmosGetPublicKey extends BaseMethod<any> {
|
|
@@ -1,12 +1,59 @@
|
|
|
1
1
|
import { LockDevice } from '@onekeyfe/hd-transport';
|
|
2
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
|
+
import semver from 'semver';
|
|
2
4
|
import { BaseMethod } from '../BaseMethod';
|
|
5
|
+
import { toHardened } from '../helpers/pathUtils';
|
|
6
|
+
import { DeviceFirmwareRange } from '../../types';
|
|
7
|
+
import { getDeviceFirmwareVersion, getMethodVersionRange } from '../../utils';
|
|
3
8
|
|
|
4
9
|
export default class DeviceUnlock extends BaseMethod<LockDevice> {
|
|
5
10
|
init() {
|
|
6
11
|
this.useDevicePassphraseState = false;
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
15
|
+
return {
|
|
16
|
+
pro: {
|
|
17
|
+
min: '4.15.0',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
async run() {
|
|
10
|
-
|
|
23
|
+
const firmwareVersion = getDeviceFirmwareVersion(this.device.features)?.join('.');
|
|
24
|
+
const versionRange = getMethodVersionRange(
|
|
25
|
+
this.device.features,
|
|
26
|
+
type => this.supportUnlockVersionRange()[type]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (versionRange && semver.gte(firmwareVersion, versionRange.min)) {
|
|
30
|
+
const res = await this.device.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
31
|
+
if (this.device.features) {
|
|
32
|
+
this.device.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
33
|
+
this.device.features.unlocked_attach_pin =
|
|
34
|
+
res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
|
|
35
|
+
this.device.features.passphrase_protection =
|
|
36
|
+
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
37
|
+
|
|
38
|
+
return Promise.resolve(this.device.features);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const featuresRes = await this.device.commands.typedCall('GetFeatures', 'Features');
|
|
42
|
+
return Promise.resolve(featuresRes.message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { type } = await this.device.commands.typedCall('GetAddress', 'Address', {
|
|
46
|
+
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
47
|
+
coin_name: 'Testnet',
|
|
48
|
+
script_type: 'SPENDADDRESS',
|
|
49
|
+
show_display: false,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
if (type === 'CallMethodError') {
|
|
54
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
|
|
55
|
+
}
|
|
56
|
+
const res = await this.device.commands.typedCall('GetFeatures', 'Features');
|
|
57
|
+
return Promise.resolve(res.message);
|
|
11
58
|
}
|
|
12
59
|
}
|
|
@@ -13,8 +13,6 @@ import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
|
|
|
13
13
|
export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneKey[]> {
|
|
14
14
|
hasBundle = false;
|
|
15
15
|
|
|
16
|
-
confirmShowOnOneKey = false;
|
|
17
|
-
|
|
18
16
|
useBatch = false;
|
|
19
17
|
|
|
20
18
|
init() {
|
|
@@ -22,13 +20,9 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
|
|
|
22
20
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
23
21
|
|
|
24
22
|
this.hasBundle = !!this.payload?.bundle;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(item: EVMGetPublicKeyParams) => !!item.showOnOneKey
|
|
23
|
+
this.useBatch = this.payload?.bundle?.every(
|
|
24
|
+
(item: EVMGetPublicKeyParams) => item.showOnOneKey !== true
|
|
28
25
|
);
|
|
29
|
-
|
|
30
|
-
this.useBatch = !this.confirmShowOnOneKey && this.hasBundle && this.payload.useBatch;
|
|
31
|
-
|
|
32
26
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
33
27
|
|
|
34
28
|
// check payload
|
|
@@ -72,7 +66,7 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
|
|
|
72
66
|
async run() {
|
|
73
67
|
const responses: EVMPublicKey[] = [];
|
|
74
68
|
|
|
75
|
-
if (this.useBatch && supportBatchPublicKey(this.device?.features)) {
|
|
69
|
+
if (this.useBatch && this.hasBundle && supportBatchPublicKey(this.device?.features)) {
|
|
76
70
|
try {
|
|
77
71
|
const res = await batchGetPublickeys(this.device, this.params, 'secp256k1', 60, {
|
|
78
72
|
includeNode: false,
|
package/src/api/index.ts
CHANGED
|
@@ -41,7 +41,6 @@ export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
|
41
41
|
export { default as cipherKeyValue } from './CipherKeyValue';
|
|
42
42
|
|
|
43
43
|
export { default as allNetworkGetAddress } from './allnetwork/AllNetworkGetAddress';
|
|
44
|
-
export { default as allNetworkGetAddressByLoop } from './allnetwork/AllNetworkGetAddressByLoop';
|
|
45
44
|
|
|
46
45
|
export { default as btcGetAddress } from './btc/BTCGetAddress';
|
|
47
46
|
export { default as btcGetPublicKey } from './btc/BTCGetPublicKey';
|
package/src/core/RequestQueue.ts
CHANGED
|
@@ -13,8 +13,6 @@ export type RequestTask = {
|
|
|
13
13
|
export default class RequestQueue {
|
|
14
14
|
private requestQueue = new Map<number, RequestTask>();
|
|
15
15
|
|
|
16
|
-
private pendingCallbackTasks = new Map<string, Deferred<void>>();
|
|
17
|
-
|
|
18
16
|
// 生成唯一请求ID
|
|
19
17
|
public generateRequestId = (method?: BaseMethod) => {
|
|
20
18
|
if (method && method.responseID != null) {
|
|
@@ -106,28 +104,4 @@ export default class RequestQueue {
|
|
|
106
104
|
public releaseTask(requestId: number) {
|
|
107
105
|
this.requestQueue.delete(requestId);
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
public registerPendingCallbackTask(connectId: string, callbackPromise: Deferred<void>) {
|
|
111
|
-
this.pendingCallbackTasks.set(connectId, callbackPromise);
|
|
112
|
-
|
|
113
|
-
callbackPromise.promise.finally(() => {
|
|
114
|
-
Log.debug(`Callback task completed for connectId: ${connectId}`);
|
|
115
|
-
this.pendingCallbackTasks.delete(connectId);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public async waitForPendingCallbackTasks(connectId: string): Promise<void> {
|
|
120
|
-
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
121
|
-
if (pendingTask) {
|
|
122
|
-
Log.debug(`Waiting for pending callback task to complete for connectId: ${connectId}`);
|
|
123
|
-
await pendingTask.promise;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public cancelCallbackTasks(connectId: string) {
|
|
128
|
-
const pendingTask = this.pendingCallbackTasks.get(connectId);
|
|
129
|
-
if (pendingTask) {
|
|
130
|
-
pendingTask.resolve();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
107
|
}
|
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
|
-
|
|
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
|
-
// wait for previous callback tasks to complete (ensure device does not call concurrently)
|
|
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(
|
|
@@ -857,7 +843,7 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
|
|
|
857
843
|
callback(null, uiResp.payload);
|
|
858
844
|
};
|
|
859
845
|
|
|
860
|
-
|
|
846
|
+
const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
861
847
|
postMessage(createDeviceMessage(DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
|
|
862
848
|
|
|
863
849
|
if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
|
|
@@ -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
|
-
//
|
|
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
|
}
|
package/src/device/Device.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import semver from 'semver';
|
|
3
2
|
import { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
4
3
|
import {
|
|
5
4
|
createDeferred,
|
|
@@ -17,7 +16,6 @@ import {
|
|
|
17
16
|
getDeviceType,
|
|
18
17
|
getDeviceUUID,
|
|
19
18
|
getLogger,
|
|
20
|
-
getMethodVersionRange,
|
|
21
19
|
LoggerNames,
|
|
22
20
|
} from '../utils';
|
|
23
21
|
import {
|
|
@@ -30,7 +28,6 @@ import type DeviceConnector from './DeviceConnector';
|
|
|
30
28
|
import { DeviceCommands, PassphrasePromptResponse } from './DeviceCommands';
|
|
31
29
|
|
|
32
30
|
import {
|
|
33
|
-
type DeviceFirmwareRange,
|
|
34
31
|
EOneKeyDeviceMode,
|
|
35
32
|
type Device as DeviceTyped,
|
|
36
33
|
type Features,
|
|
@@ -46,7 +43,6 @@ import {
|
|
|
46
43
|
import { PROTO } from '../constants';
|
|
47
44
|
import { DataManager } from '../data-manager';
|
|
48
45
|
import TransportManager from '../data-manager/TransportManager';
|
|
49
|
-
import { toHardened } from '../api/helpers/pathUtils';
|
|
50
46
|
|
|
51
47
|
export type InitOptions = {
|
|
52
48
|
initSession?: boolean;
|
|
@@ -155,8 +151,6 @@ export class Device extends EventEmitter {
|
|
|
155
151
|
|
|
156
152
|
passphraseState: string | undefined = undefined;
|
|
157
153
|
|
|
158
|
-
pendingCallbackPromise?: Deferred<void>;
|
|
159
|
-
|
|
160
154
|
constructor(descriptor: DeviceDescriptor) {
|
|
161
155
|
super();
|
|
162
156
|
this.originalDescriptor = descriptor;
|
|
@@ -270,18 +264,6 @@ export class Device extends EventEmitter {
|
|
|
270
264
|
(this.isUsedHere() && !this.keepSession && this.mainId) ||
|
|
271
265
|
(this.mainId && DataManager.isBleConnect(env))
|
|
272
266
|
) {
|
|
273
|
-
// wait for callback tasks to complete before releasing device
|
|
274
|
-
if (this.pendingCallbackPromise) {
|
|
275
|
-
try {
|
|
276
|
-
Log.debug(
|
|
277
|
-
'Waiting for callback tasks to complete before releasing device (in release method)'
|
|
278
|
-
);
|
|
279
|
-
await this.pendingCallbackPromise.promise;
|
|
280
|
-
} catch (error) {
|
|
281
|
-
Log.error('Error waiting for callback tasks in release method:', error);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
267
|
if (this.commands) {
|
|
286
268
|
this.commands.dispose(false);
|
|
287
269
|
if (this.commands.callPromise) {
|
|
@@ -750,54 +732,6 @@ export class Device extends EventEmitter {
|
|
|
750
732
|
return res.message;
|
|
751
733
|
}
|
|
752
734
|
|
|
753
|
-
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
754
|
-
return {
|
|
755
|
-
pro: {
|
|
756
|
-
min: '4.15.0',
|
|
757
|
-
},
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
async unlockDevice() {
|
|
762
|
-
const firmwareVersion = getDeviceFirmwareVersion(this.features)?.join('.');
|
|
763
|
-
const versionRange = getMethodVersionRange(
|
|
764
|
-
this.features,
|
|
765
|
-
type => this.supportUnlockVersionRange()[type]
|
|
766
|
-
);
|
|
767
|
-
|
|
768
|
-
if (versionRange && semver.gte(firmwareVersion, versionRange.min)) {
|
|
769
|
-
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
|
770
|
-
if (this.features) {
|
|
771
|
-
this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
|
|
772
|
-
this.features.unlocked_attach_pin =
|
|
773
|
-
res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
|
|
774
|
-
this.features.passphrase_protection =
|
|
775
|
-
res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
|
|
776
|
-
|
|
777
|
-
return Promise.resolve(this.features);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
const featuresRes = await this.commands.typedCall('GetFeatures', 'Features');
|
|
781
|
-
this._updateFeatures(featuresRes.message);
|
|
782
|
-
return Promise.resolve(featuresRes.message);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const { type } = await this.commands.typedCall('GetAddress', 'Address', {
|
|
786
|
-
address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
|
|
787
|
-
coin_name: 'Testnet',
|
|
788
|
-
script_type: 'SPENDADDRESS',
|
|
789
|
-
show_display: false,
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
// @ts-expect-error
|
|
793
|
-
if (type === 'CallMethodError') {
|
|
794
|
-
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'unlock device error');
|
|
795
|
-
}
|
|
796
|
-
const res = await this.commands.typedCall('GetFeatures', 'Features');
|
|
797
|
-
this._updateFeatures(res.message);
|
|
798
|
-
return Promise.resolve(res.message);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
735
|
async checkPassphraseStateSafety(
|
|
802
736
|
passphraseState?: string,
|
|
803
737
|
useEmptyPassphrase?: boolean,
|
package/src/events/call.ts
CHANGED
|
@@ -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 {
|
package/src/events/core.ts
CHANGED
|
@@ -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
|
package/src/events/iframe.ts
CHANGED
|
@@ -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
|
|
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
|
|
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' }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CommonParams, Response
|
|
1
|
+
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type { CardanoAddressParameters } from './cardano';
|
|
3
3
|
|
|
4
4
|
export type INetwork =
|
|
@@ -91,7 +91,7 @@ type AllNetworkAddressPayload =
|
|
|
91
91
|
xpubSegwit: string;
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
-
export type AllNetworkAddress =
|
|
94
|
+
export type AllNetworkAddress = CommonResponseParams & {
|
|
95
95
|
success: boolean;
|
|
96
96
|
payload?:
|
|
97
97
|
| AllNetworkAddressPayload
|
|
@@ -108,22 +108,8 @@ export type AllNetworkGetAddressParams = {
|
|
|
108
108
|
bundle: AllNetworkAddressParams[];
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
export type AllNetworkGetAddressParamsByLoop = AllNetworkGetAddressParams & {
|
|
112
|
-
callbackId?: string;
|
|
113
|
-
callbackIdFinish?: string;
|
|
114
|
-
onLoopItemResponse: (data?: AllNetworkAddress) => void;
|
|
115
|
-
onAllItemsResponse: (data?: AllNetworkAddress[], error?: Unsuccessful) => void;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
111
|
export declare function allNetworkGetAddress(
|
|
119
112
|
connectId: string,
|
|
120
113
|
deviceId: string,
|
|
121
114
|
params: CommonParams & AllNetworkGetAddressParams
|
|
122
115
|
): Response<AllNetworkAddress[]>;
|
|
123
|
-
|
|
124
|
-
export declare function allNetworkGetAddressByLoop(
|
|
125
|
-
connectId: string,
|
|
126
|
-
deviceId: string,
|
|
127
|
-
params: CommonParams & AllNetworkGetAddressParamsByLoop
|
|
128
|
-
// only return empty array
|
|
129
|
-
): Response<AllNetworkAddress[]>;
|
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
|
|
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,47 +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
|
-
abortController: AbortController | null;
|
|
32
|
-
init(): void;
|
|
33
|
-
generateMethodName({ network, payload, originalIndex, }: {
|
|
34
|
-
network: INetwork;
|
|
35
|
-
payload: AllNetworkAddressParams;
|
|
36
|
-
originalIndex: number;
|
|
37
|
-
}): MethodParams;
|
|
38
|
-
callMethod(methodName: keyof CoreApi, params: any & {
|
|
39
|
-
bundle: (any & {
|
|
40
|
-
_originRequestParams: CommonResponseParams;
|
|
41
|
-
})[];
|
|
42
|
-
}): Promise<AllNetworkAddress[]>;
|
|
43
|
-
abstract getAllNetworkAddress(): Promise<AllNetworkAddress[]>;
|
|
44
|
-
run(): Promise<AllNetworkAddress[]>;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
47
|
-
//# sourceMappingURL=AllNetworkGetAddressBase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AllNetworkGetAddressBase.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddressBase.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EACV,uBAAuB,EACvB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAa9C,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,uBAAuB,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;IAClG,kBAAkB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG;KAC5B,CAAC,IAAI,YAAY,GAAG,aAAa;CACnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAOrD,CAAC;AA8LF,KAAK,YAAY,GAAG;IAClB,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,wBAAyB,SAAQ,UAAU,CACvE;IACE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EAAE,CACJ;IACC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAQ;IAE/C,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;IAgFH,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAEvD,GAAG;CAuBV"}
|
|
@@ -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":"AAaA,OAAO,wBAAwB,MAAM,4BAA4B,CAAC;AAGlE,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,wBAAwB;IACxE,oBAAoB;YAwBZ,4BAA4B;IA4E1C,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,gBAAgB;CAazB"}
|