@onekeyfe/hd-core 1.2.0-alpha.18 → 1.2.0-alpha.19
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/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +30 -0
- package/__tests__/device-pool-state.test.ts +113 -0
- package/__tests__/device-settings.test.ts +108 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +163 -0
- package/__tests__/device-state-mapper.test.ts +222 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +115 -0
- package/__tests__/device-wallet-session-store.test.ts +46 -0
- package/__tests__/deviceFeaturesUtils.test.ts +13 -1
- package/__tests__/deviceSettings.test.ts +54 -0
- package/__tests__/get-device-state.test.ts +367 -0
- package/__tests__/logBlockEvent.test.ts +13 -0
- package/__tests__/protocol-v2.test.ts +358 -413
- package/__tests__/public-device-state-api.test.ts +153 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +93 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts +7 -0
- package/dist/api/GetDeviceState.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -4
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/internal.d.ts +4 -0
- package/dist/api/internal.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +0 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
- package/dist/api/utils.d.ts +2 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +22 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +4 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +1 -0
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +8 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +23 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/events/device.d.ts +7 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/index.d.ts +688 -639
- package/dist/index.js +1274 -942
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +1 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -1
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +8 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +12 -0
- package/dist/types/api/getDeviceState.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +4 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -6
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +121 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/tracing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdateV4.ts +15 -7
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +8 -3
- package/src/api/GetOnekeyFeatures.ts +3 -72
- package/src/api/GetPassphraseState.ts +3 -1
- package/src/api/SearchDevices.ts +25 -4
- package/src/api/device/DeviceRebootToBoardloader.ts +1 -0
- package/src/api/device/DeviceRebootToBootloader.ts +1 -0
- package/src/api/device/DeviceSettings.ts +28 -0
- package/src/api/index.ts +1 -4
- package/src/api/internal.ts +9 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -5
- package/src/api/protocol-v2/DeviceReboot.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsGet.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +2 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/utils.ts +9 -3
- package/src/constants/index.ts +1 -4
- package/src/core/index.ts +7 -1
- package/src/data/messages/messages-protocol-v2.json +22 -13
- package/src/device/Device.ts +256 -78
- package/src/device/DeviceFeaturesState.ts +34 -0
- package/src/device/DevicePool.ts +35 -9
- package/src/device/DeviceStateMapper.ts +364 -0
- package/src/device/DeviceStateProjector.ts +92 -0
- package/src/device/DeviceStateStore.ts +242 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +166 -109
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +13 -1
- package/src/events/logBlockEvent.ts +1 -1
- package/src/inject.ts +4 -5
- package/src/protocols/protocol-v2/features.ts +18 -9
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +5 -7
- package/src/types/api/deviceSettings.ts +8 -0
- package/src/types/api/getDeviceState.ts +19 -0
- package/src/types/api/index.ts +3 -20
- package/src/types/api/protocolV2.ts +0 -24
- package/src/types/device.ts +148 -1
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceSettings.ts +41 -0
- package/src/utils/tracing.ts +3 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -22
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -88
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -152
- package/src/deviceProfile/buildDeviceProfile.ts +0 -370
- package/src/types/api/getDeviceInfo.ts +0 -106
|
@@ -1,83 +1,21 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
+
import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
3
|
|
|
3
4
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
5
|
import { fixVersion } from '../utils/deviceFeaturesUtils';
|
|
5
|
-
import { PROTOCOL_V2_DEVICE_INFO_REQUEST } from '../protocols/protocol-v2';
|
|
6
|
-
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
7
6
|
import { BaseMethod } from './BaseMethod';
|
|
8
7
|
|
|
9
8
|
import type { OnekeyFeatures } from '../types';
|
|
10
9
|
|
|
11
|
-
const ONEKEY_FEATURE_KEYS: Array<keyof OnekeyFeatures> = [
|
|
12
|
-
'onekey_device_type',
|
|
13
|
-
'onekey_board_version',
|
|
14
|
-
'onekey_boot_version',
|
|
15
|
-
'onekey_firmware_version',
|
|
16
|
-
'onekey_board_hash',
|
|
17
|
-
'onekey_boot_hash',
|
|
18
|
-
'onekey_firmware_hash',
|
|
19
|
-
'onekey_board_build_id',
|
|
20
|
-
'onekey_boot_build_id',
|
|
21
|
-
'onekey_firmware_build_id',
|
|
22
|
-
'onekey_serial_no',
|
|
23
|
-
'onekey_ble_name',
|
|
24
|
-
'onekey_ble_version',
|
|
25
|
-
'onekey_ble_build_id',
|
|
26
|
-
'onekey_ble_hash',
|
|
27
|
-
'onekey_se_type',
|
|
28
|
-
'onekey_se01_state',
|
|
29
|
-
'onekey_se02_state',
|
|
30
|
-
'onekey_se03_state',
|
|
31
|
-
'onekey_se04_state',
|
|
32
|
-
'onekey_se01_version',
|
|
33
|
-
'onekey_se02_version',
|
|
34
|
-
'onekey_se03_version',
|
|
35
|
-
'onekey_se04_version',
|
|
36
|
-
'onekey_se01_hash',
|
|
37
|
-
'onekey_se02_hash',
|
|
38
|
-
'onekey_se03_hash',
|
|
39
|
-
'onekey_se04_hash',
|
|
40
|
-
'onekey_se01_build_id',
|
|
41
|
-
'onekey_se02_build_id',
|
|
42
|
-
'onekey_se03_build_id',
|
|
43
|
-
'onekey_se04_build_id',
|
|
44
|
-
'onekey_se01_boot_version',
|
|
45
|
-
'onekey_se02_boot_version',
|
|
46
|
-
'onekey_se03_boot_version',
|
|
47
|
-
'onekey_se04_boot_version',
|
|
48
|
-
'onekey_se01_boot_hash',
|
|
49
|
-
'onekey_se02_boot_hash',
|
|
50
|
-
'onekey_se03_boot_hash',
|
|
51
|
-
'onekey_se04_boot_hash',
|
|
52
|
-
'onekey_se01_boot_build_id',
|
|
53
|
-
'onekey_se02_boot_build_id',
|
|
54
|
-
'onekey_se03_boot_build_id',
|
|
55
|
-
'onekey_se04_boot_build_id',
|
|
56
|
-
];
|
|
57
|
-
|
|
58
10
|
function normalizeOnekeyFirmwareVersion(message: OnekeyFeatures) {
|
|
59
11
|
if (message.onekey_firmware_version && !semver.valid(message.onekey_firmware_version)) {
|
|
60
12
|
message.onekey_firmware_version = fixVersion(message.onekey_firmware_version);
|
|
61
13
|
}
|
|
62
14
|
}
|
|
63
15
|
|
|
64
|
-
function pickOnekeyFeatures(features?: OnekeyFeatures | null): OnekeyFeatures {
|
|
65
|
-
const message: OnekeyFeatures = {};
|
|
66
|
-
if (!features) return message;
|
|
67
|
-
|
|
68
|
-
for (const key of ONEKEY_FEATURE_KEYS) {
|
|
69
|
-
const value = features[key];
|
|
70
|
-
if (value !== undefined && value !== null) {
|
|
71
|
-
(message as Record<string, unknown>)[key] = value;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
normalizeOnekeyFirmwareVersion(message);
|
|
76
|
-
return message;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
16
|
export default class GetOnekeyFeatures extends BaseMethod {
|
|
80
17
|
init() {
|
|
18
|
+
this.unlockPolicy = 'none';
|
|
81
19
|
this.allowDeviceMode = [
|
|
82
20
|
...this.allowDeviceMode,
|
|
83
21
|
UI_REQUEST.NOT_INITIALIZE,
|
|
@@ -89,14 +27,7 @@ export default class GetOnekeyFeatures extends BaseMethod {
|
|
|
89
27
|
|
|
90
28
|
async run() {
|
|
91
29
|
if (this.device.isProtocolV2()) {
|
|
92
|
-
|
|
93
|
-
// 取完整 DeviceInfoGet(含 SE/hash/build_id)后刷新结构化 features 缓存。
|
|
94
|
-
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
95
|
-
commands: this.device.commands,
|
|
96
|
-
request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
97
|
-
});
|
|
98
|
-
const features = this.device.updateProtocolV2Features(deviceInfo);
|
|
99
|
-
return pickOnekeyFeatures(features as OnekeyFeatures);
|
|
30
|
+
throw createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
100
31
|
}
|
|
101
32
|
|
|
102
33
|
const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
@@ -21,7 +21,9 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
21
21
|
const deviceType = this.device.getCurrentDeviceType();
|
|
22
22
|
|
|
23
23
|
if (deviceType === EDeviceType.Pro2) {
|
|
24
|
-
|
|
24
|
+
// Protocol V2 的钱包身份由 DeviceSession 返回的 btc_test_address 决定,
|
|
25
|
+
// 不依赖固件 passphrase_enabled 状态。
|
|
26
|
+
return Promise.resolve(passphraseState);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
return Promise.resolve(
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BaseMethod } from './BaseMethod';
|
|
2
2
|
import TransportManager from '../data-manager/TransportManager';
|
|
3
3
|
import { DataManager } from '../data-manager';
|
|
4
|
-
import { getDeviceTypeByBleName } from '../utils';
|
|
4
|
+
import { LoggerNames, getDeviceTypeByBleName, getLogger } from '../utils';
|
|
5
5
|
import { DevicePool } from '../device/DevicePool';
|
|
6
6
|
|
|
7
7
|
import type DeviceConnector from '../device/DeviceConnector';
|
|
8
8
|
|
|
9
|
+
const Log = getLogger(LoggerNames.DevicePool);
|
|
10
|
+
|
|
9
11
|
export default class SearchDevices extends BaseMethod {
|
|
10
12
|
connector?: DeviceConnector;
|
|
11
13
|
|
|
@@ -47,9 +49,28 @@ export default class SearchDevices extends BaseMethod {
|
|
|
47
49
|
return devices;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
const deviceList = [];
|
|
53
|
+
for (const descriptor of devicesDescriptor) {
|
|
54
|
+
try {
|
|
55
|
+
// 设备发现是尽力而为的操作。浏览器可能保留已经离线、忙碌或尚未就绪的
|
|
56
|
+
// WebUSB 授权记录,单个描述符初始化失败不应中断其余设备的发现。
|
|
57
|
+
const result = await DevicePool.getDevices([descriptor], descriptor.path, {
|
|
58
|
+
connectProtocol: this.payload.connectProtocol,
|
|
59
|
+
refreshRuntimeState: true,
|
|
60
|
+
});
|
|
61
|
+
deviceList.push(...result.deviceList);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const errorCode =
|
|
64
|
+
error && typeof error === 'object' && 'errorCode' in error
|
|
65
|
+
? (error as { errorCode?: unknown }).errorCode
|
|
66
|
+
: undefined;
|
|
67
|
+
Log.debug('Skip unavailable device during search', {
|
|
68
|
+
path: descriptor.path,
|
|
69
|
+
...(errorCode !== undefined ? { errorCode } : {}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
53
74
|
return deviceList.map(device => device.toMessageObject());
|
|
54
75
|
}
|
|
55
76
|
}
|
|
@@ -28,6 +28,7 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
28
28
|
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
29
|
reboot_type: DeviceRebootType.Romloader,
|
|
30
30
|
});
|
|
31
|
+
this.device.markProtocolV2Reboot(DeviceRebootType.Romloader);
|
|
31
32
|
return Promise.resolve(res.message);
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -28,6 +28,7 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
28
28
|
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
29
|
reboot_type: DeviceRebootType.Bootloader,
|
|
30
30
|
});
|
|
31
|
+
this.device.markProtocolV2Reboot(DeviceRebootType.Bootloader);
|
|
31
32
|
return Promise.resolve(res.message);
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { HardwareErrorCode, TypedError } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
|
+
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
4
5
|
import { validateParams } from '../helpers/paramsValidator';
|
|
6
|
+
import {
|
|
7
|
+
mapApplySettingsToState,
|
|
8
|
+
mapCommonSettingsToProtocolV2,
|
|
9
|
+
mapDeviceSettingsToState,
|
|
10
|
+
} from '../../device/DeviceStateMapper';
|
|
5
11
|
import { LANGUAGE_LABELS } from '../../utils/deviceSettings';
|
|
6
12
|
|
|
7
13
|
import type { ApplySettings } from '@onekeyfe/hd-transport';
|
|
@@ -24,7 +30,15 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
24
30
|
{ name: 'experimentalFeatures', type: 'boolean' },
|
|
25
31
|
{ name: 'autoShutdownDelayMs', type: 'number' },
|
|
26
32
|
{ name: 'changeBrightness', type: 'boolean' },
|
|
33
|
+
{ name: 'brightness', type: 'number' },
|
|
27
34
|
{ name: 'hapticFeedback', type: 'boolean' },
|
|
35
|
+
{ name: 'bluetoothEnabled', type: 'boolean' },
|
|
36
|
+
{ name: 'animationEnabled', type: 'boolean' },
|
|
37
|
+
{ name: 'tapToWake', type: 'boolean' },
|
|
38
|
+
{ name: 'deviceNameDisplayEnabled', type: 'boolean' },
|
|
39
|
+
{ name: 'fidoEnabled', type: 'boolean' },
|
|
40
|
+
{ name: 'usbLockEnabled', type: 'boolean' },
|
|
41
|
+
{ name: 'randomKeypad', type: 'boolean' },
|
|
28
42
|
]);
|
|
29
43
|
|
|
30
44
|
// init params
|
|
@@ -60,9 +74,23 @@ export default class DeviceSettings extends BaseMethod<ApplySettings> {
|
|
|
60
74
|
|
|
61
75
|
async run() {
|
|
62
76
|
try {
|
|
77
|
+
if (this.device.isProtocolV2()) {
|
|
78
|
+
const settings = mapCommonSettingsToProtocolV2(this.payload);
|
|
79
|
+
if (Object.keys(settings).length === 0) {
|
|
80
|
+
throw invalidParameter('No Protocol V2 compatible setting provided.');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', {
|
|
84
|
+
settings,
|
|
85
|
+
});
|
|
86
|
+
this.device.updateState(mapDeviceSettingsToState(settings), 'apply-settings');
|
|
87
|
+
return res.message;
|
|
88
|
+
}
|
|
89
|
+
|
|
63
90
|
const res = await this.device.commands.typedCall('ApplySettings', 'Success', {
|
|
64
91
|
...this.params,
|
|
65
92
|
});
|
|
93
|
+
this.device.updateState(mapApplySettingsToState(this.params), 'apply-settings');
|
|
66
94
|
return res.message;
|
|
67
95
|
} catch (error) {
|
|
68
96
|
if (error.message?.toLowerCase().includes('no setting provided')) {
|
package/src/api/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { default as preInitialize } from './device/PreInitialize';
|
|
|
3
3
|
|
|
4
4
|
export { default as searchDevices } from './SearchDevices';
|
|
5
5
|
export { default as getFeatures } from './GetFeatures';
|
|
6
|
-
export { default as
|
|
6
|
+
export { default as getDeviceState } from './GetDeviceState';
|
|
7
7
|
export { default as getOnekeyFeatures } from './GetOnekeyFeatures';
|
|
8
8
|
export { default as getPassphraseState } from './GetPassphraseState';
|
|
9
9
|
export { default as getLogs } from './GetLogs';
|
|
@@ -47,15 +47,12 @@ export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
|
47
47
|
export { default as protocolInfoRequest } from './protocol-v2/ProtocolInfoRequest';
|
|
48
48
|
export { default as ping } from './protocol-v2/Ping';
|
|
49
49
|
export { default as deviceReboot } from './protocol-v2/DeviceReboot';
|
|
50
|
-
export { default as deviceInfoGet } from './protocol-v2/DeviceInfoGet';
|
|
51
|
-
export { default as deviceStatusGet } from './protocol-v2/DeviceStatusGet';
|
|
52
50
|
export { default as deviceGetOnboardingStatus } from './protocol-v2/DeviceGetOnboardingStatus';
|
|
53
51
|
export { default as deviceSessionOpen } from './protocol-v2/DeviceSessionOpen';
|
|
54
52
|
export { default as deviceFirmwareUpdate } from './protocol-v2/DeviceFirmwareUpdate';
|
|
55
53
|
export { default as deviceGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
56
54
|
export { default as deviceFactoryInfoSet } from './protocol-v2/DeviceFactoryInfoSet';
|
|
57
55
|
export { default as deviceFactoryInfoGet } from './protocol-v2/DeviceFactoryInfoGet';
|
|
58
|
-
export { default as deviceSettingsGet } from './protocol-v2/DeviceSettingsGet';
|
|
59
56
|
export { default as deviceSettingsSet } from './protocol-v2/DeviceSettingsSet';
|
|
60
57
|
export { default as deviceSettingsPageShow } from './protocol-v2/DeviceSettingsPageShow';
|
|
61
58
|
export { default as deviceUploadWallpaper } from './protocol-v2/DeviceUploadWallpaper';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 内部原生命令注册表。
|
|
3
|
+
*
|
|
4
|
+
* 这些方法允许开发工具通过低层 `call` 调试 Protocol V2,但不会进入
|
|
5
|
+
* `CoreApi` 或公开的便捷方法集合;业务接入仍应使用统一 DeviceState API。
|
|
6
|
+
*/
|
|
7
|
+
export { default as deviceInfoGet } from './protocol-v2/DeviceInfoGet';
|
|
8
|
+
export { default as deviceStatusGet } from './protocol-v2/DeviceStatusGet';
|
|
9
|
+
export { default as deviceSettingsGet } from './protocol-v2/DeviceSettingsGet';
|
|
@@ -13,7 +13,6 @@ export type DeviceInfoGetTargets = {
|
|
|
13
13
|
se2?: boolean;
|
|
14
14
|
se3?: boolean;
|
|
15
15
|
se4?: boolean;
|
|
16
|
-
status?: boolean;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
export type DeviceInfoGetTypes = {
|
|
@@ -36,7 +35,6 @@ const TARGET_KEYS: (keyof DeviceInfoGetTargets)[] = [
|
|
|
36
35
|
'se2',
|
|
37
36
|
'se3',
|
|
38
37
|
'se4',
|
|
39
|
-
'status',
|
|
40
38
|
];
|
|
41
39
|
|
|
42
40
|
const TYPE_KEYS: (keyof DeviceInfoGetTypes)[] = ['version', 'build_id', 'hash', 'specific'];
|
|
@@ -104,9 +102,8 @@ function normalizeTypes(value: unknown): DeviceInfoGetTypes | undefined {
|
|
|
104
102
|
/**
|
|
105
103
|
* 原生 DeviceInfoGet(Protocol V2 only)。
|
|
106
104
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* 用于调试固件字段上报。
|
|
105
|
+
* SDK 内部按需构造 targets/types,并返回未加工的 DeviceInfo 消息。
|
|
106
|
+
* 该 command 不属于公共 CoreApi;业务接入统一使用 getDeviceState。
|
|
110
107
|
*/
|
|
111
108
|
export default class DeviceInfoGet extends BaseMethod<{
|
|
112
109
|
targets: DeviceInfoGetTargets;
|
|
@@ -115,6 +112,7 @@ export default class DeviceInfoGet extends BaseMethod<{
|
|
|
115
112
|
init() {
|
|
116
113
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
117
114
|
this.requireProtocolV2 = true;
|
|
115
|
+
this.unlockPolicy = 'none';
|
|
118
116
|
this.allowDeviceMode = [
|
|
119
117
|
...this.allowDeviceMode,
|
|
120
118
|
UI_REQUEST.NOT_INITIALIZE,
|
|
@@ -16,9 +16,11 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async run() {
|
|
19
|
+
const rebootType = normalizeRebootType(this.params.reboot_type ?? this.params.rebootType);
|
|
19
20
|
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
20
|
-
reboot_type:
|
|
21
|
+
reboot_type: rebootType,
|
|
21
22
|
});
|
|
23
|
+
this.device.markProtocolV2Reboot(rebootType);
|
|
22
24
|
return Promise.resolve(res.message);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
|
|
2
3
|
|
|
3
4
|
export default class DeviceSettingsGet extends BaseMethod {
|
|
4
5
|
init() {
|
|
5
6
|
this.requireProtocolV2 = true;
|
|
6
|
-
this.unlockPolicy = '
|
|
7
|
+
this.unlockPolicy = 'none';
|
|
7
8
|
this.skipForceUpdateCheck = true;
|
|
8
9
|
this.useDevicePassphraseState = false;
|
|
9
10
|
this.params = undefined;
|
|
@@ -11,6 +12,7 @@ export default class DeviceSettingsGet extends BaseMethod {
|
|
|
11
12
|
|
|
12
13
|
async run() {
|
|
13
14
|
const res = await this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
15
|
+
this.device.updateState(mapDeviceSettingsToState(res.message), 'apply-settings');
|
|
14
16
|
return Promise.resolve(res.message);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
|
|
2
3
|
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
3
4
|
|
|
4
5
|
import type { DeviceSettings } from '@onekeyfe/hd-transport';
|
|
@@ -44,6 +45,7 @@ export default class DeviceSettingsSet extends BaseMethod<{
|
|
|
44
45
|
|
|
45
46
|
async run() {
|
|
46
47
|
const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', this.params);
|
|
48
|
+
this.device.updateState(mapDeviceSettingsToState(this.params.settings), 'apply-settings');
|
|
47
49
|
return Promise.resolve(res.message);
|
|
48
50
|
}
|
|
49
51
|
}
|
package/src/api/utils.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import * as ApiMethods from './index';
|
|
4
|
+
import * as InternalApiMethods from './internal';
|
|
4
5
|
|
|
6
|
+
import type { BaseMethod } from './BaseMethod';
|
|
5
7
|
import type { IFrameCallMessage } from '../events';
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
type MethodConstructor = new (message: IFrameCallMessage & { id?: number }) => BaseMethod<any>;
|
|
10
|
+
|
|
11
|
+
const publicMethodRegistry = ApiMethods as unknown as Record<string, MethodConstructor>;
|
|
12
|
+
const internalMethodRegistry = InternalApiMethods as unknown as Record<string, MethodConstructor>;
|
|
13
|
+
|
|
14
|
+
export function findMethod(message: IFrameCallMessage & { id?: number }): BaseMethod<any> {
|
|
8
15
|
const { method } = message.payload;
|
|
9
16
|
if (typeof method !== 'string') {
|
|
10
17
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
|
|
11
18
|
}
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
const MethodConstructor = ApiMethods[method];
|
|
20
|
+
const MethodConstructor = publicMethodRegistry[method] ?? internalMethodRegistry[method];
|
|
15
21
|
if (MethodConstructor) {
|
|
16
22
|
return new MethodConstructor(message);
|
|
17
23
|
}
|
package/src/constants/index.ts
CHANGED
package/src/core/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
updateRequestContext,
|
|
37
37
|
} from '../utils/tracing';
|
|
38
38
|
import { Device } from '../device/Device';
|
|
39
|
+
import { checkLiveDeviceId } from '../device/deviceIdentity';
|
|
39
40
|
import { DeviceList } from '../device/DeviceList';
|
|
40
41
|
import { DevicePool } from '../device/DevicePool';
|
|
41
42
|
import { PollingStateManager } from './PollingStateManager';
|
|
@@ -410,6 +411,7 @@ const onCallDevice = async (
|
|
|
410
411
|
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
411
412
|
});
|
|
412
413
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
414
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
413
415
|
device.on(
|
|
414
416
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
415
417
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
@@ -549,7 +551,7 @@ const onCallDevice = async (
|
|
|
549
551
|
}
|
|
550
552
|
|
|
551
553
|
if (method.deviceId && method.checkDeviceId) {
|
|
552
|
-
const isSameDeviceID = device
|
|
554
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
553
555
|
if (!isSameDeviceID) {
|
|
554
556
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
555
557
|
}
|
|
@@ -1240,6 +1242,10 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1240
1242
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1241
1243
|
};
|
|
1242
1244
|
|
|
1245
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1246
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1247
|
+
};
|
|
1248
|
+
|
|
1243
1249
|
const onDevicePassphraseHandler = async (
|
|
1244
1250
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1245
1251
|
) => {
|
|
@@ -11586,7 +11586,8 @@
|
|
|
11586
11586
|
"LayoutSafeTxCreate": 1,
|
|
11587
11587
|
"LayoutFinalConfirm": 2,
|
|
11588
11588
|
"Layout7702": 3,
|
|
11589
|
-
"LayoutFlat": 4
|
|
11589
|
+
"LayoutFlat": 4,
|
|
11590
|
+
"LayoutEthApprove": 5
|
|
11590
11591
|
}
|
|
11591
11592
|
},
|
|
11592
11593
|
"ViewSignPage": {
|
|
@@ -11645,6 +11646,18 @@
|
|
|
11645
11646
|
"rule": "required",
|
|
11646
11647
|
"type": "string",
|
|
11647
11648
|
"id": 3
|
|
11649
|
+
},
|
|
11650
|
+
"network": {
|
|
11651
|
+
"type": "string",
|
|
11652
|
+
"id": 4
|
|
11653
|
+
},
|
|
11654
|
+
"derive_type": {
|
|
11655
|
+
"type": "string",
|
|
11656
|
+
"id": 5
|
|
11657
|
+
},
|
|
11658
|
+
"value_key": {
|
|
11659
|
+
"type": "uint32",
|
|
11660
|
+
"id": 6
|
|
11648
11661
|
}
|
|
11649
11662
|
}
|
|
11650
11663
|
},
|
|
@@ -11852,10 +11865,6 @@
|
|
|
11852
11865
|
"type": "string",
|
|
11853
11866
|
"id": 4
|
|
11854
11867
|
},
|
|
11855
|
-
"passphrase_enable": {
|
|
11856
|
-
"type": "bool",
|
|
11857
|
-
"id": 6
|
|
11858
|
-
},
|
|
11859
11868
|
"brightness": {
|
|
11860
11869
|
"type": "uint32",
|
|
11861
11870
|
"id": 7
|
|
@@ -11888,14 +11897,6 @@
|
|
|
11888
11897
|
"type": "bool",
|
|
11889
11898
|
"id": 14
|
|
11890
11899
|
},
|
|
11891
|
-
"fido_enabled": {
|
|
11892
|
-
"type": "bool",
|
|
11893
|
-
"id": 15
|
|
11894
|
-
},
|
|
11895
|
-
"experimental_features": {
|
|
11896
|
-
"type": "bool",
|
|
11897
|
-
"id": 16
|
|
11898
|
-
},
|
|
11899
11900
|
"usb_lock_enable": {
|
|
11900
11901
|
"type": "bool",
|
|
11901
11902
|
"id": 17
|
|
@@ -11903,6 +11904,14 @@
|
|
|
11903
11904
|
"random_keypad": {
|
|
11904
11905
|
"type": "bool",
|
|
11905
11906
|
"id": 18
|
|
11907
|
+
},
|
|
11908
|
+
"passphrase_enable": {
|
|
11909
|
+
"type": "bool",
|
|
11910
|
+
"id": 100
|
|
11911
|
+
},
|
|
11912
|
+
"fido_enabled": {
|
|
11913
|
+
"type": "bool",
|
|
11914
|
+
"id": 101
|
|
11906
11915
|
}
|
|
11907
11916
|
}
|
|
11908
11917
|
},
|