@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Device } from './Device';
|
|
2
|
+
|
|
3
|
+
type DeviceIdentityReader = Pick<Device, 'isProtocolV2' | 'getDeviceState' | 'checkDeviceId'>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Protocol V2 的 deviceId 来自运行态状态,比较前必须读取一次实时 status。
|
|
7
|
+
* Protocol V1 继续复用 Initialize/GetFeatures 已经返回的设备身份。
|
|
8
|
+
*/
|
|
9
|
+
export async function checkLiveDeviceId(
|
|
10
|
+
device: DeviceIdentityReader,
|
|
11
|
+
expectedDeviceId: string
|
|
12
|
+
): Promise<boolean> {
|
|
13
|
+
if (device.isProtocolV2()) {
|
|
14
|
+
await device.getDeviceState({ refreshSections: ['status'] });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return device.checkDeviceId(expectedDeviceId);
|
|
18
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { Enum_Capability } from '@onekeyfe/hd-transport';
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
isProtocolV2BootloaderDeviceInfo,
|
|
@@ -52,8 +53,8 @@ const versionFromParts = (major?: number | null, minor?: number | null, patch?:
|
|
|
52
53
|
const getProtocolV1Mode = (features: ProtocolV1FeaturesCompat): Features['mode'] => {
|
|
53
54
|
if (features.bootloader_mode === true) return 'bootloader';
|
|
54
55
|
if (features.initialized === false) return 'notInitialized';
|
|
55
|
-
if (features.
|
|
56
|
-
return '
|
|
56
|
+
if (features.no_backup === true) return 'backupMode';
|
|
57
|
+
return 'normal';
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
const getProtocolV1DeviceType = (features: ProtocolV1FeaturesCompat): Features['deviceType'] => {
|
|
@@ -96,20 +97,19 @@ const getProtocolV1FirmwareType = (
|
|
|
96
97
|
features: ProtocolV1FeaturesCompat
|
|
97
98
|
): Features['firmwareType'] => {
|
|
98
99
|
if (features.fw_vendor === 'OneKey Bitcoin-only') return EFirmwareType.BitcoinOnly;
|
|
100
|
+
const capabilities = features.capabilities as unknown as Array<number | string> | undefined;
|
|
101
|
+
if (
|
|
102
|
+
capabilities?.length &&
|
|
103
|
+
!capabilities.includes(Enum_Capability.Capability_Bitcoin_like) &&
|
|
104
|
+
!capabilities.includes('Capability_Bitcoin_like')
|
|
105
|
+
) {
|
|
106
|
+
return EFirmwareType.BitcoinOnly;
|
|
107
|
+
}
|
|
99
108
|
return EFirmwareType.Universal;
|
|
100
109
|
};
|
|
101
110
|
|
|
102
|
-
const getProtocolV1Label = (
|
|
103
|
-
features:
|
|
104
|
-
deviceType: Features['deviceType'],
|
|
105
|
-
bleName: string | null
|
|
106
|
-
) => {
|
|
107
|
-
if (features.label) return features.label;
|
|
108
|
-
if (bleName) return bleName;
|
|
109
|
-
if (deviceType === EDeviceType.Unknown) return null;
|
|
110
|
-
if (deviceType === EDeviceType.ClassicPure) return 'OneKey Classic 1S';
|
|
111
|
-
return `OneKey ${deviceType.charAt(0).toUpperCase()}${deviceType.slice(1)}`;
|
|
112
|
-
};
|
|
111
|
+
const getProtocolV1Label = (features: ProtocolV1FeaturesCompat) =>
|
|
112
|
+
typeof features.label === 'string' && features.label.length > 0 ? features.label : null;
|
|
113
113
|
|
|
114
114
|
export const buildProtocolV1FeaturesPayload = (
|
|
115
115
|
protocolV1Features: PROTO.Features,
|
|
@@ -119,20 +119,27 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
119
119
|
const firmwareVersion = firstMeaningfulVersion(
|
|
120
120
|
features.onekey_firmware_version,
|
|
121
121
|
features.onekey_version,
|
|
122
|
-
versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
122
|
+
versionFromParts(features.major_version, features.minor_version, features.patch_version),
|
|
123
|
+
previous?.firmwareVersion
|
|
123
124
|
);
|
|
124
125
|
const bootloaderVersion = firstMeaningfulVersion(
|
|
125
126
|
features.onekey_boot_version,
|
|
126
127
|
features.bootloader_version,
|
|
127
128
|
features.bootloader_mode
|
|
128
129
|
? versionFromParts(features.major_version, features.minor_version, features.patch_version)
|
|
129
|
-
: null
|
|
130
|
+
: null,
|
|
131
|
+
previous?.bootloaderVersion
|
|
130
132
|
);
|
|
131
133
|
const boardVersion = firstMeaningfulVersion(
|
|
132
134
|
features.onekey_board_version,
|
|
133
|
-
features.boardloader_version
|
|
135
|
+
features.boardloader_version,
|
|
136
|
+
previous?.boardVersion
|
|
137
|
+
);
|
|
138
|
+
const bleVersion = firstMeaningfulVersion(
|
|
139
|
+
features.onekey_ble_version,
|
|
140
|
+
features.ble_ver,
|
|
141
|
+
previous?.bleVersion
|
|
134
142
|
);
|
|
135
|
-
const bleVersion = firstMeaningfulVersion(features.onekey_ble_version, features.ble_ver);
|
|
136
143
|
const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no || '';
|
|
137
144
|
const bleName = features.onekey_ble_name || features.ble_name || null;
|
|
138
145
|
const deviceType = getProtocolV1DeviceType(features);
|
|
@@ -148,7 +155,7 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
148
155
|
vendor: features.vendor ?? null,
|
|
149
156
|
deviceId: features.device_id ?? null,
|
|
150
157
|
serialNo,
|
|
151
|
-
label: getProtocolV1Label(features
|
|
158
|
+
label: getProtocolV1Label(features),
|
|
152
159
|
bleName,
|
|
153
160
|
capabilities: features.capabilities ?? [],
|
|
154
161
|
mode: getProtocolV1Mode(features),
|
|
@@ -168,48 +175,73 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
168
175
|
sdProtection: features.sd_protection ?? null,
|
|
169
176
|
wipeCodeProtection: features.wipe_code_protection ?? null,
|
|
170
177
|
passphraseAlwaysOnDevice: features.passphrase_always_on_device ?? null,
|
|
178
|
+
attachToPinEnabled: features.attach_to_pin_user ?? previous?.attachToPinEnabled ?? null,
|
|
179
|
+
unlockedAttachPin: features.unlocked_attach_pin ?? previous?.unlockedAttachPin ?? undefined,
|
|
171
180
|
safetyChecks: features.safety_checks ?? null,
|
|
172
181
|
autoLockDelayMs: features.auto_lock_delay_ms ?? null,
|
|
182
|
+
autoShutdownDelayMs: features.auto_shutdown_delay_ms ?? null,
|
|
173
183
|
displayRotation: features.display_rotation ?? null,
|
|
174
184
|
experimentalFeatures: features.experimental_features ?? null,
|
|
185
|
+
wallpaperPath: previous?.wallpaperPath ?? null,
|
|
186
|
+
brightness: features.brightness_prcent ?? previous?.brightness ?? null,
|
|
187
|
+
animationEnabled: previous?.animationEnabled ?? null,
|
|
188
|
+
tapToWake: previous?.tapToWake ?? null,
|
|
189
|
+
hapticFeedback: features.haptic_feedback ?? previous?.hapticFeedback ?? null,
|
|
190
|
+
deviceNameDisplayEnabled: previous?.deviceNameDisplayEnabled ?? null,
|
|
191
|
+
airgapMode: previous?.airgapMode ?? null,
|
|
192
|
+
fidoEnabled: previous?.fidoEnabled ?? null,
|
|
193
|
+
usbLockEnabled: previous?.usbLockEnabled ?? null,
|
|
194
|
+
randomKeypad: previous?.randomKeypad ?? null,
|
|
175
195
|
firmwareVersion,
|
|
176
196
|
bootloaderVersion,
|
|
177
197
|
boardVersion,
|
|
178
198
|
bleVersion,
|
|
179
|
-
se01Version: firstMeaningfulVersion(features.onekey_se01_version),
|
|
180
|
-
se02Version: firstMeaningfulVersion(features.onekey_se02_version),
|
|
181
|
-
se03Version: firstMeaningfulVersion(features.onekey_se03_version),
|
|
182
|
-
se04Version: firstMeaningfulVersion(features.onekey_se04_version),
|
|
183
|
-
se01BootVersion: firstMeaningfulVersion(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
199
|
+
se01Version: firstMeaningfulVersion(features.onekey_se01_version, previous?.se01Version),
|
|
200
|
+
se02Version: firstMeaningfulVersion(features.onekey_se02_version, previous?.se02Version),
|
|
201
|
+
se03Version: firstMeaningfulVersion(features.onekey_se03_version, previous?.se03Version),
|
|
202
|
+
se04Version: firstMeaningfulVersion(features.onekey_se04_version, previous?.se04Version),
|
|
203
|
+
se01BootVersion: firstMeaningfulVersion(
|
|
204
|
+
features.onekey_se01_boot_version,
|
|
205
|
+
previous?.se01BootVersion
|
|
206
|
+
),
|
|
207
|
+
se02BootVersion: firstMeaningfulVersion(
|
|
208
|
+
features.onekey_se02_boot_version,
|
|
209
|
+
previous?.se02BootVersion
|
|
210
|
+
),
|
|
211
|
+
se03BootVersion: firstMeaningfulVersion(
|
|
212
|
+
features.onekey_se03_boot_version,
|
|
213
|
+
previous?.se03BootVersion
|
|
214
|
+
),
|
|
215
|
+
se04BootVersion: firstMeaningfulVersion(
|
|
216
|
+
features.onekey_se04_boot_version,
|
|
217
|
+
previous?.se04BootVersion
|
|
218
|
+
),
|
|
219
|
+
seVersion: features.se_ver ?? previous?.seVersion ?? null,
|
|
188
220
|
verify: {
|
|
189
|
-
firmwareBuildId: features.onekey_firmware_build_id,
|
|
190
|
-
firmwareHash: features.onekey_firmware_hash,
|
|
191
|
-
bootloaderBuildId: features.onekey_boot_build_id,
|
|
192
|
-
bootloaderHash: features.onekey_boot_hash,
|
|
193
|
-
boardBuildId: features.onekey_board_build_id,
|
|
194
|
-
boardHash: features.onekey_board_hash,
|
|
195
|
-
bleBuildId: features.onekey_ble_build_id,
|
|
196
|
-
bleHash: features.onekey_ble_hash,
|
|
197
|
-
se01BuildId: features.onekey_se01_build_id,
|
|
198
|
-
se01Hash: features.onekey_se01_hash,
|
|
199
|
-
se02BuildId: features.onekey_se02_build_id,
|
|
200
|
-
se02Hash: features.onekey_se02_hash,
|
|
201
|
-
se03BuildId: features.onekey_se03_build_id,
|
|
202
|
-
se03Hash: features.onekey_se03_hash,
|
|
203
|
-
se04BuildId: features.onekey_se04_build_id,
|
|
204
|
-
se04Hash: features.onekey_se04_hash,
|
|
205
|
-
se01BootBuildId: features.onekey_se01_boot_build_id,
|
|
206
|
-
se01BootHash: features.onekey_se01_boot_hash,
|
|
207
|
-
se02BootBuildId: features.onekey_se02_boot_build_id,
|
|
208
|
-
se02BootHash: features.onekey_se02_boot_hash,
|
|
209
|
-
se03BootBuildId: features.onekey_se03_boot_build_id,
|
|
210
|
-
se03BootHash: features.onekey_se03_boot_hash,
|
|
211
|
-
se04BootBuildId: features.onekey_se04_boot_build_id,
|
|
212
|
-
se04BootHash: features.onekey_se04_boot_hash,
|
|
221
|
+
firmwareBuildId: features.onekey_firmware_build_id ?? previous?.verify?.firmwareBuildId,
|
|
222
|
+
firmwareHash: features.onekey_firmware_hash ?? previous?.verify?.firmwareHash,
|
|
223
|
+
bootloaderBuildId: features.onekey_boot_build_id ?? previous?.verify?.bootloaderBuildId,
|
|
224
|
+
bootloaderHash: features.onekey_boot_hash ?? previous?.verify?.bootloaderHash,
|
|
225
|
+
boardBuildId: features.onekey_board_build_id ?? previous?.verify?.boardBuildId,
|
|
226
|
+
boardHash: features.onekey_board_hash ?? previous?.verify?.boardHash,
|
|
227
|
+
bleBuildId: features.onekey_ble_build_id ?? previous?.verify?.bleBuildId,
|
|
228
|
+
bleHash: features.onekey_ble_hash ?? previous?.verify?.bleHash,
|
|
229
|
+
se01BuildId: features.onekey_se01_build_id ?? previous?.verify?.se01BuildId,
|
|
230
|
+
se01Hash: features.onekey_se01_hash ?? previous?.verify?.se01Hash,
|
|
231
|
+
se02BuildId: features.onekey_se02_build_id ?? previous?.verify?.se02BuildId,
|
|
232
|
+
se02Hash: features.onekey_se02_hash ?? previous?.verify?.se02Hash,
|
|
233
|
+
se03BuildId: features.onekey_se03_build_id ?? previous?.verify?.se03BuildId,
|
|
234
|
+
se03Hash: features.onekey_se03_hash ?? previous?.verify?.se03Hash,
|
|
235
|
+
se04BuildId: features.onekey_se04_build_id ?? previous?.verify?.se04BuildId,
|
|
236
|
+
se04Hash: features.onekey_se04_hash ?? previous?.verify?.se04Hash,
|
|
237
|
+
se01BootBuildId: features.onekey_se01_boot_build_id ?? previous?.verify?.se01BootBuildId,
|
|
238
|
+
se01BootHash: features.onekey_se01_boot_hash ?? previous?.verify?.se01BootHash,
|
|
239
|
+
se02BootBuildId: features.onekey_se02_boot_build_id ?? previous?.verify?.se02BootBuildId,
|
|
240
|
+
se02BootHash: features.onekey_se02_boot_hash ?? previous?.verify?.se02BootHash,
|
|
241
|
+
se03BootBuildId: features.onekey_se03_boot_build_id ?? previous?.verify?.se03BootBuildId,
|
|
242
|
+
se03BootHash: features.onekey_se03_boot_hash ?? previous?.verify?.se03BootHash,
|
|
243
|
+
se04BootBuildId: features.onekey_se04_boot_build_id ?? previous?.verify?.se04BootBuildId,
|
|
244
|
+
se04BootHash: features.onekey_se04_boot_hash ?? previous?.verify?.se04BootHash,
|
|
213
245
|
},
|
|
214
246
|
sessionId,
|
|
215
247
|
session_id: sessionId ?? undefined,
|
|
@@ -224,7 +256,7 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
224
256
|
*
|
|
225
257
|
* 这是 Device 内部唯一缓存状态。字段只来自 DeviceInfoGet 或前一次 features
|
|
226
258
|
* 缓存的同名字段级合并;不存在协议等价语义的字段保持 null/空值,不再通过
|
|
227
|
-
*
|
|
259
|
+
* 统一 DeviceState 或 transport path 做身份兜底。
|
|
228
260
|
*/
|
|
229
261
|
export const buildProtocolV2FeaturesPayload = ({
|
|
230
262
|
deviceInfo,
|
|
@@ -241,31 +273,39 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
241
273
|
const fwBoard = info?.fw?.romloader;
|
|
242
274
|
const bleApplication = info?.coprocessor?.application;
|
|
243
275
|
const status = deviceStatus;
|
|
276
|
+
const incomingSerialNo = info?.hw?.serial_no;
|
|
277
|
+
const samePhysicalDevice =
|
|
278
|
+
!incomingSerialNo || !previous?.serialNo || incomingSerialNo === previous.serialNo;
|
|
279
|
+
const cached = samePhysicalDevice ? previous : undefined;
|
|
244
280
|
|
|
245
281
|
const firmwareVersion = firstMeaningfulVersion(
|
|
246
282
|
getImageVersion(fwApplication),
|
|
247
|
-
|
|
283
|
+
cached?.firmwareVersion
|
|
248
284
|
);
|
|
249
285
|
const bootloaderVersion = firstMeaningfulVersion(
|
|
250
286
|
getImageVersion(fwBootloader),
|
|
251
|
-
|
|
287
|
+
cached?.bootloaderVersion
|
|
252
288
|
);
|
|
253
|
-
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard),
|
|
254
|
-
const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication),
|
|
255
|
-
const deviceId = status?.device_id ?? null;
|
|
256
|
-
const serialNo = firstValue(
|
|
257
|
-
const label =
|
|
258
|
-
const bleName = firstValue(info?.coprocessor?.bt_adv_name,
|
|
259
|
-
const initialized = firstValue(status?.init_states,
|
|
289
|
+
const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), cached?.boardVersion);
|
|
290
|
+
const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), cached?.bleVersion);
|
|
291
|
+
const deviceId = status?.device_id ?? cached?.deviceId ?? null;
|
|
292
|
+
const serialNo = firstValue(incomingSerialNo, cached?.serialNo) ?? '';
|
|
293
|
+
const label = cached?.label ?? null;
|
|
294
|
+
const bleName = firstValue(info?.coprocessor?.bt_adv_name, cached?.bleName);
|
|
295
|
+
const initialized = firstValue(status?.init_states, cached?.initialized) ?? null;
|
|
260
296
|
// Pro2 在锁定状态下返回的 passphrase_enabled 不是最终钱包状态。
|
|
261
297
|
// 只有完成 PIN 解锁后的 DeviceStatus 才能作为 passphrase 开关真值来源。
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const
|
|
298
|
+
let passphraseProtection = cached?.passphraseProtection ?? null;
|
|
299
|
+
if (status?.unlocked === true) {
|
|
300
|
+
passphraseProtection = status.passphrase_enabled ?? null;
|
|
301
|
+
}
|
|
302
|
+
const language = cached?.language ?? null;
|
|
303
|
+
const backupRequired = firstValue(status?.backup_required, cached?.backupRequired) ?? null;
|
|
304
|
+
const bleEnabled = cached?.bleEnabled;
|
|
305
|
+
const unlocked = firstValue(status?.unlocked, cached?.unlocked) ?? null;
|
|
306
|
+
const attachToPinEnabled = status?.attach_to_pin_enabled ?? cached?.attachToPinEnabled ?? null;
|
|
307
|
+
const unlockedAttachPin =
|
|
308
|
+
status?.unlocked_by_attach_to_pin ?? cached?.unlockedAttachPin ?? undefined;
|
|
269
309
|
const romloaderMode = isProtocolV2RomloaderDeviceInfo(info, status);
|
|
270
310
|
const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info, status);
|
|
271
311
|
let mode: DeviceFeaturesMode = 'unknown';
|
|
@@ -277,13 +317,19 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
277
317
|
mode = 'notInitialized';
|
|
278
318
|
} else if (initialized === true) {
|
|
279
319
|
mode = 'normal';
|
|
320
|
+
} else if (cached?.mode === 'notInitialized' || cached?.mode === 'backupMode') {
|
|
321
|
+
mode = cached.mode;
|
|
322
|
+
} else if (info) {
|
|
323
|
+
mode = 'normal';
|
|
324
|
+
} else if (cached?.mode) {
|
|
325
|
+
mode = cached.mode;
|
|
280
326
|
}
|
|
281
327
|
|
|
282
328
|
return {
|
|
283
329
|
protocol: 'V2',
|
|
284
|
-
protocolVersion: deviceInfo?.protocol_version ??
|
|
330
|
+
protocolVersion: deviceInfo?.protocol_version ?? cached?.protocolVersion ?? null,
|
|
285
331
|
deviceType: EDeviceType.Pro2,
|
|
286
|
-
firmwareType:
|
|
332
|
+
firmwareType: cached?.firmwareType ?? EFirmwareType.Universal,
|
|
287
333
|
model: 'pro2',
|
|
288
334
|
vendor: 'onekey.so',
|
|
289
335
|
deviceId,
|
|
@@ -295,7 +341,7 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
295
341
|
initialized,
|
|
296
342
|
bootloaderMode,
|
|
297
343
|
unlocked,
|
|
298
|
-
firmwarePresent:
|
|
344
|
+
firmwarePresent: cached?.firmwarePresent ?? null,
|
|
299
345
|
passphraseProtection,
|
|
300
346
|
pinProtection: null,
|
|
301
347
|
backupRequired,
|
|
@@ -310,80 +356,91 @@ export const buildProtocolV2FeaturesPayload = ({
|
|
|
310
356
|
passphraseAlwaysOnDevice: null,
|
|
311
357
|
attachToPinEnabled,
|
|
312
358
|
safetyChecks: null,
|
|
313
|
-
autoLockDelayMs: null,
|
|
359
|
+
autoLockDelayMs: cached?.autoLockDelayMs ?? null,
|
|
360
|
+
autoShutdownDelayMs: cached?.autoShutdownDelayMs ?? null,
|
|
314
361
|
displayRotation: null,
|
|
315
|
-
experimentalFeatures: null,
|
|
362
|
+
experimentalFeatures: cached?.experimentalFeatures ?? null,
|
|
363
|
+
wallpaperPath: cached?.wallpaperPath ?? null,
|
|
364
|
+
brightness: cached?.brightness ?? null,
|
|
365
|
+
animationEnabled: cached?.animationEnabled ?? null,
|
|
366
|
+
tapToWake: cached?.tapToWake ?? null,
|
|
367
|
+
hapticFeedback: cached?.hapticFeedback ?? null,
|
|
368
|
+
deviceNameDisplayEnabled: cached?.deviceNameDisplayEnabled ?? null,
|
|
369
|
+
airgapMode: cached?.airgapMode ?? null,
|
|
370
|
+
fidoEnabled: cached?.fidoEnabled ?? null,
|
|
371
|
+
usbLockEnabled: cached?.usbLockEnabled ?? null,
|
|
372
|
+
randomKeypad: cached?.randomKeypad ?? null,
|
|
316
373
|
firmwareVersion,
|
|
317
374
|
bootloaderVersion,
|
|
318
375
|
boardVersion,
|
|
319
376
|
bleVersion,
|
|
320
377
|
se01Version: firstMeaningfulVersion(
|
|
321
378
|
getImageVersion(info?.se1?.application),
|
|
322
|
-
|
|
379
|
+
cached?.se01Version
|
|
323
380
|
),
|
|
324
381
|
se02Version: firstMeaningfulVersion(
|
|
325
382
|
getImageVersion(info?.se2?.application),
|
|
326
|
-
|
|
383
|
+
cached?.se02Version
|
|
327
384
|
),
|
|
328
385
|
se03Version: firstMeaningfulVersion(
|
|
329
386
|
getImageVersion(info?.se3?.application),
|
|
330
|
-
|
|
387
|
+
cached?.se03Version
|
|
331
388
|
),
|
|
332
389
|
se04Version: firstMeaningfulVersion(
|
|
333
390
|
getImageVersion(info?.se4?.application),
|
|
334
|
-
|
|
391
|
+
cached?.se04Version
|
|
335
392
|
),
|
|
336
393
|
se01BootVersion: firstMeaningfulVersion(
|
|
337
394
|
getImageVersion(info?.se1?.bootloader),
|
|
338
|
-
|
|
395
|
+
cached?.se01BootVersion
|
|
339
396
|
),
|
|
340
397
|
se02BootVersion: firstMeaningfulVersion(
|
|
341
398
|
getImageVersion(info?.se2?.bootloader),
|
|
342
|
-
|
|
399
|
+
cached?.se02BootVersion
|
|
343
400
|
),
|
|
344
401
|
se03BootVersion: firstMeaningfulVersion(
|
|
345
402
|
getImageVersion(info?.se3?.bootloader),
|
|
346
|
-
|
|
403
|
+
cached?.se03BootVersion
|
|
347
404
|
),
|
|
348
405
|
se04BootVersion: firstMeaningfulVersion(
|
|
349
406
|
getImageVersion(info?.se4?.bootloader),
|
|
350
|
-
|
|
407
|
+
cached?.se04BootVersion
|
|
351
408
|
),
|
|
352
|
-
seVersion:
|
|
409
|
+
seVersion: cached?.seVersion ?? null,
|
|
353
410
|
verify: {
|
|
354
|
-
firmwareBuildId: getImageBuildId(fwApplication) ??
|
|
355
|
-
firmwareHash: getImageHash(fwApplication) ??
|
|
356
|
-
bootloaderBuildId: getImageBuildId(fwBootloader) ??
|
|
357
|
-
bootloaderHash: getImageHash(fwBootloader) ??
|
|
358
|
-
boardBuildId: getImageBuildId(fwBoard) ??
|
|
359
|
-
boardHash: getImageHash(fwBoard) ??
|
|
360
|
-
bleBuildId: getImageBuildId(bleApplication) ??
|
|
361
|
-
bleHash: getImageHash(bleApplication) ??
|
|
362
|
-
se01BuildId: getImageBuildId(info?.se1?.application) ??
|
|
363
|
-
se01Hash: getImageHash(info?.se1?.application) ??
|
|
364
|
-
se02BuildId: getImageBuildId(info?.se2?.application) ??
|
|
365
|
-
se02Hash: getImageHash(info?.se2?.application) ??
|
|
366
|
-
se03BuildId: getImageBuildId(info?.se3?.application) ??
|
|
367
|
-
se03Hash: getImageHash(info?.se3?.application) ??
|
|
368
|
-
se04BuildId: getImageBuildId(info?.se4?.application) ??
|
|
369
|
-
se04Hash: getImageHash(info?.se4?.application) ??
|
|
370
|
-
se01BootBuildId: getImageBuildId(info?.se1?.bootloader) ??
|
|
371
|
-
se01BootHash: getImageHash(info?.se1?.bootloader) ??
|
|
372
|
-
se02BootBuildId: getImageBuildId(info?.se2?.bootloader) ??
|
|
373
|
-
se02BootHash: getImageHash(info?.se2?.bootloader) ??
|
|
374
|
-
se03BootBuildId: getImageBuildId(info?.se3?.bootloader) ??
|
|
375
|
-
se03BootHash: getImageHash(info?.se3?.bootloader) ??
|
|
376
|
-
se04BootBuildId: getImageBuildId(info?.se4?.bootloader) ??
|
|
377
|
-
se04BootHash: getImageHash(info?.se4?.bootloader) ??
|
|
411
|
+
firmwareBuildId: getImageBuildId(fwApplication) ?? cached?.verify?.firmwareBuildId,
|
|
412
|
+
firmwareHash: getImageHash(fwApplication) ?? cached?.verify?.firmwareHash,
|
|
413
|
+
bootloaderBuildId: getImageBuildId(fwBootloader) ?? cached?.verify?.bootloaderBuildId,
|
|
414
|
+
bootloaderHash: getImageHash(fwBootloader) ?? cached?.verify?.bootloaderHash,
|
|
415
|
+
boardBuildId: getImageBuildId(fwBoard) ?? cached?.verify?.boardBuildId,
|
|
416
|
+
boardHash: getImageHash(fwBoard) ?? cached?.verify?.boardHash,
|
|
417
|
+
bleBuildId: getImageBuildId(bleApplication) ?? cached?.verify?.bleBuildId,
|
|
418
|
+
bleHash: getImageHash(bleApplication) ?? cached?.verify?.bleHash,
|
|
419
|
+
se01BuildId: getImageBuildId(info?.se1?.application) ?? cached?.verify?.se01BuildId,
|
|
420
|
+
se01Hash: getImageHash(info?.se1?.application) ?? cached?.verify?.se01Hash,
|
|
421
|
+
se02BuildId: getImageBuildId(info?.se2?.application) ?? cached?.verify?.se02BuildId,
|
|
422
|
+
se02Hash: getImageHash(info?.se2?.application) ?? cached?.verify?.se02Hash,
|
|
423
|
+
se03BuildId: getImageBuildId(info?.se3?.application) ?? cached?.verify?.se03BuildId,
|
|
424
|
+
se03Hash: getImageHash(info?.se3?.application) ?? cached?.verify?.se03Hash,
|
|
425
|
+
se04BuildId: getImageBuildId(info?.se4?.application) ?? cached?.verify?.se04BuildId,
|
|
426
|
+
se04Hash: getImageHash(info?.se4?.application) ?? cached?.verify?.se04Hash,
|
|
427
|
+
se01BootBuildId: getImageBuildId(info?.se1?.bootloader) ?? cached?.verify?.se01BootBuildId,
|
|
428
|
+
se01BootHash: getImageHash(info?.se1?.bootloader) ?? cached?.verify?.se01BootHash,
|
|
429
|
+
se02BootBuildId: getImageBuildId(info?.se2?.bootloader) ?? cached?.verify?.se02BootBuildId,
|
|
430
|
+
se02BootHash: getImageHash(info?.se2?.bootloader) ?? cached?.verify?.se02BootHash,
|
|
431
|
+
se03BootBuildId: getImageBuildId(info?.se3?.bootloader) ?? cached?.verify?.se03BootBuildId,
|
|
432
|
+
se03BootHash: getImageHash(info?.se3?.bootloader) ?? cached?.verify?.se03BootHash,
|
|
433
|
+
se04BootBuildId: getImageBuildId(info?.se4?.bootloader) ?? cached?.verify?.se04BootBuildId,
|
|
434
|
+
se04BootHash: getImageHash(info?.se4?.bootloader) ?? cached?.verify?.se04BootHash,
|
|
378
435
|
},
|
|
379
|
-
sessionId:
|
|
436
|
+
sessionId: cached?.sessionId ?? null,
|
|
380
437
|
device_id: deviceId ?? undefined,
|
|
381
|
-
session_id:
|
|
438
|
+
session_id: cached?.sessionId ?? undefined,
|
|
382
439
|
ble_name: bleName ?? undefined,
|
|
383
440
|
onekey_device_type: 'PRO2',
|
|
384
441
|
passphrase_protection: passphraseProtection ?? undefined,
|
|
385
442
|
bootloader_mode: bootloaderMode,
|
|
386
|
-
passphraseState:
|
|
443
|
+
passphraseState: cached?.passphraseState,
|
|
387
444
|
unlockedAttachPin,
|
|
388
445
|
raw: {
|
|
389
446
|
protocolV2DeviceInfo: deviceInfo,
|
package/src/events/device.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { MessageFactoryFn } from './utils';
|
|
2
2
|
import type { PROTO } from '../constants';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
KnownDevice as Device,
|
|
5
|
+
DeviceStateEvent,
|
|
6
|
+
Features,
|
|
7
|
+
SupportFeatures,
|
|
8
|
+
} from '../types/device';
|
|
4
9
|
|
|
5
10
|
export const DEVICE_EVENT = 'DEVICE_EVENT';
|
|
6
11
|
export const DEVICE = {
|
|
@@ -30,6 +35,7 @@ export const DEVICE = {
|
|
|
30
35
|
SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: 'select_device_for_switch_firmware_web_device',
|
|
31
36
|
|
|
32
37
|
FEATURES: 'features',
|
|
38
|
+
STATE: 'state',
|
|
33
39
|
} as const;
|
|
34
40
|
|
|
35
41
|
export interface DeviceConnnectRequest {
|
|
@@ -65,6 +71,11 @@ export interface DeviceSendFeatures {
|
|
|
65
71
|
payload: DeviceFeaturesPayload;
|
|
66
72
|
}
|
|
67
73
|
|
|
74
|
+
export interface DeviceSendState {
|
|
75
|
+
type: typeof DEVICE.STATE;
|
|
76
|
+
payload: DeviceStateEvent;
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
export type DeviceSupportFeaturesPayload = SupportFeatures & { device: Device | null };
|
|
69
80
|
export interface DeviceSendSupportFeatures {
|
|
70
81
|
type: typeof DEVICE.SUPPORT_FEATURES;
|
|
@@ -73,6 +84,7 @@ export interface DeviceSendSupportFeatures {
|
|
|
73
84
|
|
|
74
85
|
export type DeviceEvent =
|
|
75
86
|
| DeviceButtonRequest
|
|
87
|
+
| DeviceSendState
|
|
76
88
|
| DeviceSendFeatures
|
|
77
89
|
| DeviceSendSupportFeatures
|
|
78
90
|
| DeviceDisconnnectRequest
|
|
@@ -5,7 +5,7 @@ export const LogBlockEvent: Set<string> = new Set([
|
|
|
5
5
|
UI_RESPONSE.RECEIVE_PASSPHRASE,
|
|
6
6
|
]);
|
|
7
7
|
|
|
8
|
-
const LogBlockMethod: Set<string> = new Set(['evmSignTypedData']);
|
|
8
|
+
const LogBlockMethod: Set<string> = new Set(['evmSignTypedData', 'deviceSessionOpen']);
|
|
9
9
|
|
|
10
10
|
export function getLogBlockLabel(message: unknown): string | undefined {
|
|
11
11
|
if (!message || typeof message !== 'object') return undefined;
|
package/src/inject.ts
CHANGED
|
@@ -114,7 +114,10 @@ export const createCoreApi = (
|
|
|
114
114
|
* 获取设备信息
|
|
115
115
|
*/
|
|
116
116
|
getFeatures: (connectId, params) => call({ ...params, connectId, method: 'getFeatures' }),
|
|
117
|
-
|
|
117
|
+
getDeviceState: (connectId, params) => {
|
|
118
|
+
const { refresh: _refresh, includeRaw: _includeRaw, ...commonParams } = (params ?? {}) as any;
|
|
119
|
+
return call({ ...commonParams, connectId, method: 'getDeviceState' });
|
|
120
|
+
},
|
|
118
121
|
getOnekeyFeatures: (connectId, params) =>
|
|
119
122
|
call({ ...params, connectId, method: 'getOnekeyFeatures' }),
|
|
120
123
|
|
|
@@ -160,8 +163,6 @@ export const createCoreApi = (
|
|
|
160
163
|
call({ ...params, connectId, method: 'protocolInfoRequest' }),
|
|
161
164
|
ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
|
|
162
165
|
deviceReboot: (connectId, params) => call({ ...params, connectId, method: 'deviceReboot' }),
|
|
163
|
-
deviceInfoGet: (connectId, params) => call({ ...params, connectId, method: 'deviceInfoGet' }),
|
|
164
|
-
deviceStatusGet: (connectId, params) => call({ ...params, connectId, method: 'deviceStatusGet' }),
|
|
165
166
|
deviceGetOnboardingStatus: (connectId, params) =>
|
|
166
167
|
call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
|
|
167
168
|
deviceSessionOpen: (connectId, params) =>
|
|
@@ -174,8 +175,6 @@ export const createCoreApi = (
|
|
|
174
175
|
call({ ...params, connectId, method: 'deviceFactoryInfoSet' }),
|
|
175
176
|
deviceFactoryInfoGet: (connectId, params) =>
|
|
176
177
|
call({ ...params, connectId, method: 'deviceFactoryInfoGet' }),
|
|
177
|
-
deviceSettingsGet: (connectId, params) =>
|
|
178
|
-
call({ ...params, connectId, method: 'deviceSettingsGet' }),
|
|
179
178
|
deviceSettingsSet: (connectId, params) =>
|
|
180
179
|
call({ ...params, connectId, method: 'deviceSettingsSet' }),
|
|
181
180
|
deviceSettingsPageShow: (connectId, params) =>
|
|
@@ -32,7 +32,7 @@ const normalizeEnumValue = <T extends Record<string | number, string | number>>(
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* DeviceSEInfo.state → 可读标签。SDK 内唯一的 SE 状态映射实现,
|
|
35
|
-
*
|
|
35
|
+
* DeviceState Mapper 与老协议 Features 兼容投影都从这里取。
|
|
36
36
|
*/
|
|
37
37
|
export const getProtocolV2SeState = (se?: DeviceSEInfo): ProtocolV2SeStateLabel | null => {
|
|
38
38
|
const label = normalizeEnumValue(DeviceSEState, se?.state);
|
|
@@ -49,7 +49,7 @@ export const getProtocolV2SeState = (se?: DeviceSEInfo): ProtocolV2SeStateLabel
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* DeviceSEInfo.type → 可读标签(如 'THD89')。
|
|
52
|
+
* DeviceSEInfo.type → 可读标签(如 'THD89')。DeviceState / Features
|
|
53
53
|
* 的 SE 类型归一化从这里取。
|
|
54
54
|
*/
|
|
55
55
|
export const getProtocolV2SeType = (se?: DeviceSEInfo): string | null =>
|
|
@@ -58,8 +58,10 @@ export const getProtocolV2SeType = (se?: DeviceSEInfo): string | null =>
|
|
|
58
58
|
/**
|
|
59
59
|
* 兼容尚未提供显式 runtime mode 的 Protocol V2 固件。
|
|
60
60
|
*
|
|
61
|
-
* 当前 romloader 只上报 hw、fw.romloader 和 fw.bootloader
|
|
62
|
-
*
|
|
61
|
+
* 当前 romloader 只上报 hw、fw.romloader 和 fw.bootloader。普通版本读取也会
|
|
62
|
+
* 返回 SE 信息,因此 SE 不能作为 bootloader 判据;在没有显式 runtime mode 的
|
|
63
|
+
* 兼容固件上,只能把缺少 application/application_data 的非-romloader 形态视为
|
|
64
|
+
* bootloader。
|
|
63
65
|
*/
|
|
64
66
|
export const isProtocolV2RomloaderDeviceInfo = (
|
|
65
67
|
deviceInfo?: ProtocolV2DeviceInfo | null,
|
|
@@ -82,7 +84,16 @@ export const isProtocolV2BootloaderDeviceInfo = (
|
|
|
82
84
|
) =>
|
|
83
85
|
!!deviceInfo &&
|
|
84
86
|
deviceStatus == null &&
|
|
85
|
-
!isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus)
|
|
87
|
+
!isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) &&
|
|
88
|
+
deviceInfo.fw?.application == null &&
|
|
89
|
+
deviceInfo.fw?.application_data == null;
|
|
90
|
+
|
|
91
|
+
export const isProtocolV2LoaderDeviceInfo = (
|
|
92
|
+
deviceInfo?: ProtocolV2DeviceInfo | null,
|
|
93
|
+
deviceStatus?: DeviceStatus | null
|
|
94
|
+
) =>
|
|
95
|
+
isProtocolV2RomloaderDeviceInfo(deviceInfo, deviceStatus) ||
|
|
96
|
+
isProtocolV2BootloaderDeviceInfo(deviceInfo, deviceStatus);
|
|
86
97
|
|
|
87
98
|
export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
88
99
|
targets: {
|
|
@@ -97,10 +108,8 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
|
97
108
|
};
|
|
98
109
|
|
|
99
110
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* status 提供 init_states / passphrase_enabled 等会在设备端变化的字段;
|
|
103
|
-
* hw / coprocessor 提供 serialNo / bleName 等身份字段;不含 fw/SE targets,单帧请求开销很小。
|
|
111
|
+
* 固件升级完成后的版本探测请求。
|
|
112
|
+
* 仅读取硬件与各固件组件信息,不隐式请求 DeviceStatus。
|
|
104
113
|
*/
|
|
105
114
|
export const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
106
115
|
targets: {
|
|
@@ -123,12 +123,14 @@ export async function getProtocolV2WalletSession(
|
|
|
123
123
|
const expectedPassphraseState = options?.expectedPassphraseState ?? device.passphraseState;
|
|
124
124
|
|
|
125
125
|
try {
|
|
126
|
-
//
|
|
127
|
-
//
|
|
126
|
+
// 锁屏时先完成 PIN 解锁;解锁成功只更新已确认的 unlocked 字段,
|
|
127
|
+
// 不为了补全状态隐式轮询 DeviceStatus。
|
|
128
128
|
if (device.features?.unlocked === false) {
|
|
129
129
|
await device.unlockDevice();
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// 标准钱包不需要 DeviceSession。锁屏时先解锁刷新状态,
|
|
133
|
+
// 确认未开启 passphrase 后不得再生成或传递隐藏钱包 passphraseState。
|
|
132
134
|
if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
|
|
133
135
|
return {
|
|
134
136
|
passphraseState: undefined,
|
|
@@ -172,16 +174,12 @@ export async function getProtocolV2WalletSession(
|
|
|
172
174
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
173
175
|
}
|
|
174
176
|
|
|
175
|
-
if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
|
|
176
|
-
await refreshProtocolV2DeviceStatus(device);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
177
|
device.updateInternalState(
|
|
180
178
|
true,
|
|
181
179
|
message.btc_test_address,
|
|
182
180
|
device.getCurrentDeviceId(),
|
|
183
181
|
message.session_id,
|
|
184
|
-
options?.initSession ? null : device.features?.sessionId
|
|
182
|
+
options?.initSession ? null : device.features?.sessionId ?? null
|
|
185
183
|
);
|
|
186
184
|
|
|
187
185
|
return {
|
|
@@ -14,7 +14,15 @@ export type DeviceSettingsParams = {
|
|
|
14
14
|
experimentalFeatures?: boolean;
|
|
15
15
|
autoShutdownDelayMs?: number;
|
|
16
16
|
changeBrightness?: boolean;
|
|
17
|
+
brightness?: number;
|
|
17
18
|
hapticFeedback?: boolean;
|
|
19
|
+
bluetoothEnabled?: boolean;
|
|
20
|
+
animationEnabled?: boolean;
|
|
21
|
+
tapToWake?: boolean;
|
|
22
|
+
deviceNameDisplayEnabled?: boolean;
|
|
23
|
+
fidoEnabled?: boolean;
|
|
24
|
+
usbLockEnabled?: boolean;
|
|
25
|
+
randomKeypad?: boolean;
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
export declare function deviceSettings(
|