@onekeyfe/hd-core 1.1.4-alpha.0 → 1.1.4-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 +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/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 +10 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +193 -402
- 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/dist/utils/findDefectiveBatchDevice.d.ts +5 -0
- package/dist/utils/findDefectiveBatchDevice.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 +82 -41
- 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/src/utils/findDefectiveBatchDevice.ts +29 -0
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { GetPublicKey } from '@onekeyfe/hd-transport';
|
|
2
|
-
import { HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
2
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
4
3
|
import { getScriptType, isTaprootPath, serializedPath, validatePath } from '../helpers/pathUtils';
|
|
5
4
|
import { BaseMethod } from '../BaseMethod';
|
|
@@ -122,18 +121,6 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
|
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
123
|
} catch (error) {
|
|
125
|
-
if (error instanceof HardwareError) {
|
|
126
|
-
const { errorCode } = error;
|
|
127
|
-
if (
|
|
128
|
-
errorCode === HardwareErrorCode.PinCancelled ||
|
|
129
|
-
errorCode === HardwareErrorCode.ActionCancelled ||
|
|
130
|
-
errorCode === HardwareErrorCode.ResponseUnexpectTypeError ||
|
|
131
|
-
errorCode === HardwareErrorCode.PinInvalid
|
|
132
|
-
) {
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
124
|
// clear responses
|
|
138
125
|
responses = [];
|
|
139
126
|
|
|
@@ -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
|
@@ -3,17 +3,19 @@ import EventEmitter from 'events';
|
|
|
3
3
|
import { Features, LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
4
4
|
import {
|
|
5
5
|
createDeferred,
|
|
6
|
-
createDeprecatedHardwareError,
|
|
7
|
-
createNeedUpgradeFirmwareHardwareError,
|
|
8
|
-
createNewFirmwareForceUpdateHardwareError,
|
|
9
|
-
createNewFirmwareUnReleaseHardwareError,
|
|
10
6
|
Deferred,
|
|
11
7
|
ERRORS,
|
|
12
8
|
HardwareError,
|
|
13
9
|
HardwareErrorCode,
|
|
10
|
+
createDeprecatedHardwareError,
|
|
11
|
+
createNeedUpgradeFirmwareHardwareError,
|
|
12
|
+
createNewFirmwareForceUpdateHardwareError,
|
|
13
|
+
createNewFirmwareUnReleaseHardwareError,
|
|
14
|
+
createDefectiveFirmwareError,
|
|
14
15
|
} from '@onekeyfe/hd-shared';
|
|
15
16
|
import {
|
|
16
17
|
getDeviceFirmwareVersion,
|
|
18
|
+
getDeviceBLEFirmwareVersion,
|
|
17
19
|
enableLog,
|
|
18
20
|
getLogger,
|
|
19
21
|
LoggerNames,
|
|
@@ -21,6 +23,10 @@ import {
|
|
|
21
23
|
wait,
|
|
22
24
|
getMethodVersionRange,
|
|
23
25
|
} from '../utils';
|
|
26
|
+
import {
|
|
27
|
+
findDefectiveBatchDevice,
|
|
28
|
+
getDefectiveDeviceInfo,
|
|
29
|
+
} from '../utils/findDefectiveBatchDevice';
|
|
24
30
|
import { supportNewPassphrase } from '../utils/deviceFeaturesUtils';
|
|
25
31
|
import { Device, DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
26
32
|
import { DeviceList } from '../device/DeviceList';
|
|
@@ -52,7 +58,7 @@ import { getSynchronize } from '../utils/getSynchronize';
|
|
|
52
58
|
|
|
53
59
|
const Log = getLogger(LoggerNames.Core);
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
type CoreContext = ReturnType<Core['getCoreContext']>;
|
|
56
62
|
|
|
57
63
|
function hasDeriveCardano(method: BaseMethod): boolean {
|
|
58
64
|
if (
|
|
@@ -195,11 +201,6 @@ const onCallDevice = async (
|
|
|
195
201
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
196
202
|
}
|
|
197
203
|
|
|
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
204
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
204
205
|
|
|
205
206
|
const task = requestQueue.createTask(method);
|
|
@@ -230,7 +231,6 @@ const onCallDevice = async (
|
|
|
230
231
|
|
|
231
232
|
Log.debug('Call API - setDevice: ', device.mainId);
|
|
232
233
|
method.setDevice?.(device);
|
|
233
|
-
method.context = context;
|
|
234
234
|
|
|
235
235
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
236
236
|
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
@@ -246,10 +246,6 @@ const onCallDevice = async (
|
|
|
246
246
|
);
|
|
247
247
|
|
|
248
248
|
try {
|
|
249
|
-
if (method.connectId) {
|
|
250
|
-
await context.waitForCallbackTasks(method.connectId);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
249
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
254
250
|
|
|
255
251
|
const inner = async (): Promise<void> => {
|
|
@@ -261,35 +257,96 @@ const onCallDevice = async (
|
|
|
261
257
|
|
|
262
258
|
if (device.features) {
|
|
263
259
|
await DataManager.checkAndReloadData();
|
|
260
|
+
|
|
261
|
+
// 检测故障固件设备
|
|
262
|
+
if (findDefectiveBatchDevice(device.features)) {
|
|
263
|
+
const defectiveInfo = getDefectiveDeviceInfo(device.features);
|
|
264
|
+
if (defectiveInfo) {
|
|
265
|
+
throw createDefectiveFirmwareError(
|
|
266
|
+
defectiveInfo.serialNo,
|
|
267
|
+
defectiveInfo.seVersion || 'Unknown',
|
|
268
|
+
defectiveInfo.deviceType,
|
|
269
|
+
method.connectId,
|
|
270
|
+
method.deviceId
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
264
275
|
const newVersionStatus = DataManager.getFirmwareStatus(device.features);
|
|
265
276
|
const bleVersionStatus = DataManager.getBLEFirmwareStatus(device.features);
|
|
277
|
+
|
|
278
|
+
const currentFirmwareVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
279
|
+
const currentBleVersion = getDeviceBLEFirmwareVersion(device.features).join('.');
|
|
266
280
|
if (
|
|
267
281
|
(newVersionStatus === 'required' || bleVersionStatus === 'required') &&
|
|
268
282
|
method.skipForceUpdateCheck === false
|
|
269
283
|
) {
|
|
270
|
-
|
|
284
|
+
// Get current version information for error reporting
|
|
285
|
+
const currentVersions = {
|
|
286
|
+
firmware: currentFirmwareVersion,
|
|
287
|
+
ble: currentBleVersion,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// Provide more specific error message based on which version check failed
|
|
291
|
+
if (newVersionStatus === 'required' && bleVersionStatus === 'required') {
|
|
292
|
+
throw createNewFirmwareForceUpdateHardwareError(
|
|
293
|
+
method.connectId,
|
|
294
|
+
method.deviceId,
|
|
295
|
+
'both',
|
|
296
|
+
currentVersions
|
|
297
|
+
);
|
|
298
|
+
} else if (newVersionStatus === 'required') {
|
|
299
|
+
throw createNewFirmwareForceUpdateHardwareError(
|
|
300
|
+
method.connectId,
|
|
301
|
+
method.deviceId,
|
|
302
|
+
'firmware',
|
|
303
|
+
currentVersions
|
|
304
|
+
);
|
|
305
|
+
} else {
|
|
306
|
+
throw createNewFirmwareForceUpdateHardwareError(
|
|
307
|
+
method.connectId,
|
|
308
|
+
method.deviceId,
|
|
309
|
+
'ble',
|
|
310
|
+
currentVersions
|
|
311
|
+
);
|
|
312
|
+
}
|
|
271
313
|
}
|
|
272
314
|
|
|
273
315
|
if (versionRange) {
|
|
274
|
-
|
|
275
|
-
|
|
316
|
+
if (
|
|
317
|
+
semver.valid(versionRange.min) &&
|
|
318
|
+
semver.lt(currentFirmwareVersion, versionRange.min)
|
|
319
|
+
) {
|
|
276
320
|
if (newVersionStatus === 'none' || newVersionStatus === 'valid') {
|
|
277
|
-
throw createNewFirmwareUnReleaseHardwareError(
|
|
321
|
+
throw createNewFirmwareUnReleaseHardwareError(
|
|
322
|
+
currentFirmwareVersion,
|
|
323
|
+
versionRange.min,
|
|
324
|
+
method.name
|
|
325
|
+
);
|
|
278
326
|
}
|
|
279
327
|
|
|
280
328
|
return Promise.reject(
|
|
281
|
-
createNeedUpgradeFirmwareHardwareError(
|
|
329
|
+
createNeedUpgradeFirmwareHardwareError(
|
|
330
|
+
currentFirmwareVersion,
|
|
331
|
+
versionRange.min,
|
|
332
|
+
method.name
|
|
333
|
+
)
|
|
282
334
|
);
|
|
283
335
|
}
|
|
284
336
|
if (
|
|
285
337
|
versionRange.max &&
|
|
286
338
|
semver.valid(versionRange.max) &&
|
|
287
|
-
semver.gte(
|
|
339
|
+
semver.gte(currentFirmwareVersion, versionRange.max)
|
|
288
340
|
) {
|
|
289
|
-
return Promise.reject(
|
|
341
|
+
return Promise.reject(
|
|
342
|
+
createDeprecatedHardwareError(currentFirmwareVersion, versionRange.max, method.name)
|
|
343
|
+
);
|
|
290
344
|
}
|
|
291
345
|
} else if (method.strictCheckDeviceSupport) {
|
|
292
|
-
throw ERRORS.TypedError(
|
|
346
|
+
throw ERRORS.TypedError(
|
|
347
|
+
HardwareErrorCode.DeviceNotSupportMethod,
|
|
348
|
+
`Method '${method.name}' is not supported by this device`
|
|
349
|
+
);
|
|
293
350
|
}
|
|
294
351
|
}
|
|
295
352
|
|
|
@@ -720,10 +777,6 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
720
777
|
// }
|
|
721
778
|
// setPrePendingCallPromise(device?.interruptionFromUser());
|
|
722
779
|
// requestQueue.abortRequestsByConnectId(connectId);
|
|
723
|
-
|
|
724
|
-
// cancel callback tasks
|
|
725
|
-
requestQueue.cancelCallbackTasks(connectId);
|
|
726
|
-
|
|
727
780
|
const requestIds = requestQueue.getRequestTasksId();
|
|
728
781
|
Log.debug(
|
|
729
782
|
`Cancel Api connect requestQueues: length:${requestIds.length} requestIds:${requestIds.join(
|
|
@@ -857,7 +910,7 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
|
|
|
857
910
|
callback(null, uiResp.payload);
|
|
858
911
|
};
|
|
859
912
|
|
|
860
|
-
|
|
913
|
+
const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
|
|
861
914
|
postMessage(createDeviceMessage(DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
|
|
862
915
|
|
|
863
916
|
if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
|
|
@@ -961,7 +1014,7 @@ const removeUiPromise = (promise: Deferred<any>) => {
|
|
|
961
1014
|
export default class Core extends EventEmitter {
|
|
962
1015
|
private requestQueue = new RequestQueue();
|
|
963
1016
|
|
|
964
|
-
//
|
|
1017
|
+
// 上一个请求的 promise 完成,后续需要清理的工作,需要在下一次请求前完成
|
|
965
1018
|
private prePendingCallPromise: Promise<void> | undefined;
|
|
966
1019
|
|
|
967
1020
|
private methodSynchronize = getSynchronize();
|
|
@@ -974,13 +1027,6 @@ export default class Core extends EventEmitter {
|
|
|
974
1027
|
setPrePendingCallPromise: (promise: Promise<void> | undefined) => {
|
|
975
1028
|
this.prePendingCallPromise = promise;
|
|
976
1029
|
},
|
|
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
1030
|
};
|
|
985
1031
|
}
|
|
986
1032
|
|
|
@@ -1031,11 +1077,6 @@ export default class Core extends EventEmitter {
|
|
|
1031
1077
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
1032
1078
|
break;
|
|
1033
1079
|
}
|
|
1034
|
-
case IFRAME.CALLBACK: {
|
|
1035
|
-
Log.log('callback message: ', message);
|
|
1036
|
-
postMessage(message);
|
|
1037
|
-
break;
|
|
1038
|
-
}
|
|
1039
1080
|
default:
|
|
1040
1081
|
break;
|
|
1041
1082
|
}
|
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' }),
|