@onekeyfe/hd-core 1.2.0-alpha.1 → 1.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/__tests__/connectSettings.test.ts +19 -0
  2. package/__tests__/device-wallet-session-store.test.ts +131 -0
  3. package/__tests__/preInitialize.test.ts +33 -0
  4. package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
  5. package/__tests__/protocol-v2.test.ts +1784 -502
  6. package/dist/api/ClearSessionCache.d.ts +9 -0
  7. package/dist/api/ClearSessionCache.d.ts.map +1 -0
  8. package/dist/api/FileRead.d.ts.map +1 -1
  9. package/dist/api/FileWrite.d.ts.map +1 -1
  10. package/dist/api/FirmwareUpdateV4.d.ts +24 -3
  11. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  12. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  13. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
  14. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  15. package/dist/api/firmware/getBinary.d.ts +4 -0
  16. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  17. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  18. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  19. package/dist/api/index.d.ts +8 -10
  20. package/dist/api/index.d.ts.map +1 -1
  21. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  22. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  23. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  24. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  25. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  26. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  27. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
  28. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  29. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  30. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  31. package/dist/api/protocol-v2/DeviceSessionGet.d.ts +9 -0
  32. package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
  33. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
  34. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
  35. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  36. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  37. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  38. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  39. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  40. package/dist/api/protocol-v2/helpers.d.ts +27 -18
  41. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  42. package/dist/api/ton/TonSignData.d.ts +1 -5
  43. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  44. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  45. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  46. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  47. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  48. package/dist/core/index.d.ts.map +1 -1
  49. package/dist/data-manager/DataManager.d.ts +1 -1
  50. package/dist/data-manager/DataManager.d.ts.map +1 -1
  51. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  52. package/dist/device/Device.d.ts +6 -3
  53. package/dist/device/Device.d.ts.map +1 -1
  54. package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
  55. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
  56. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  57. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  58. package/dist/index.d.ts +96 -55
  59. package/dist/index.js +2077 -1609
  60. package/dist/inject.d.ts.map +1 -1
  61. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  62. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  63. package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
  64. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  65. package/dist/protocols/protocol-v2/index.d.ts +1 -0
  66. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  67. package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
  68. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
  69. package/dist/types/api/firmwareUpdate.d.ts +4 -6
  70. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  71. package/dist/types/api/getDeviceInfo.d.ts +2 -0
  72. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  73. package/dist/types/api/index.d.ts +11 -11
  74. package/dist/types/api/index.d.ts.map +1 -1
  75. package/dist/types/api/protocolV2.d.ts +16 -17
  76. package/dist/types/api/protocolV2.d.ts.map +1 -1
  77. package/dist/types/api/sessionCache.d.ts +10 -0
  78. package/dist/types/api/sessionCache.d.ts.map +1 -0
  79. package/dist/types/device.d.ts +1 -0
  80. package/dist/types/device.d.ts.map +1 -1
  81. package/dist/types/params.d.ts +1 -0
  82. package/dist/types/params.d.ts.map +1 -1
  83. package/dist/types/settings.d.ts +21 -2
  84. package/dist/types/settings.d.ts.map +1 -1
  85. package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
  86. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  87. package/dist/utils/patch.d.ts +1 -1
  88. package/dist/utils/patch.d.ts.map +1 -1
  89. package/package.json +4 -4
  90. package/src/api/ClearSessionCache.ts +28 -0
  91. package/src/api/FileRead.ts +16 -3
  92. package/src/api/FileWrite.ts +14 -1
  93. package/src/api/FirmwareUpdateV4.ts +1075 -264
  94. package/src/api/GetOnekeyFeatures.ts +1 -1
  95. package/src/api/GetPassphraseState.ts +4 -1
  96. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  97. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  98. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
  99. package/src/api/firmware/progressThrottle.ts +44 -0
  100. package/src/api/index.ts +8 -10
  101. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  102. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  103. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  104. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
  105. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  106. package/src/api/protocol-v2/DeviceReboot.ts +1 -1
  107. package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
  108. package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
  109. package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
  110. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  111. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  112. package/src/api/protocol-v2/helpers.ts +71 -47
  113. package/src/api/ton/TonSignData.ts +1 -5
  114. package/src/api/tron/TronSignMessage.ts +0 -1
  115. package/src/api/tron/TronSignTransaction.ts +0 -1
  116. package/src/core/index.ts +19 -5
  117. package/src/data/messages/messages-protocol-v2.json +599 -1033
  118. package/src/data/messages/messages.json +8 -0
  119. package/src/data-manager/DataManager.ts +7 -0
  120. package/src/data-manager/connectSettings.ts +2 -4
  121. package/src/device/Device.ts +89 -70
  122. package/src/device/DeviceWalletSessionStore.ts +78 -0
  123. package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
  124. package/src/deviceProfile/buildDeviceProfile.ts +77 -58
  125. package/src/inject.ts +13 -16
  126. package/src/protocols/protocol-v2/features.ts +26 -63
  127. package/src/protocols/protocol-v2/firmware.ts +12 -36
  128. package/src/protocols/protocol-v2/index.ts +1 -0
  129. package/src/protocols/protocol-v2/walletSession.ts +83 -0
  130. package/src/types/api/firmwareUpdate.ts +16 -20
  131. package/src/types/api/getDeviceInfo.ts +2 -0
  132. package/src/types/api/index.ts +17 -20
  133. package/src/types/api/protocolV2.ts +36 -40
  134. package/src/types/api/sessionCache.ts +14 -0
  135. package/src/types/device.ts +1 -0
  136. package/src/types/params.ts +4 -0
  137. package/src/types/settings.ts +42 -35
  138. package/src/utils/deviceFeaturesUtils.ts +44 -13
  139. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  140. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  141. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  142. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  143. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  144. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  145. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  146. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  147. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  148. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  149. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  150. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  151. package/src/api/protocol-v2/DevReboot.ts +0 -24
  152. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  153. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
@@ -2,22 +2,8 @@ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import type { Features } from '../types';
4
4
  import type { PROTO } from '../constants';
5
- import type { DevFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
6
-
7
- type ProtocolV2DeviceInfoCompat = ProtocolV2DeviceInfo & {
8
- fw?: ProtocolV2DeviceInfo['fw'] & {
9
- application?: DevFirmwareImageInfo | null;
10
- application_data?: DevFirmwareImageInfo | null;
11
- bootloader?: DevFirmwareImageInfo | null;
12
- romloader?: DevFirmwareImageInfo | null;
13
- };
14
- coprocessor?: {
15
- application?: DevFirmwareImageInfo | null;
16
- bootloader?: DevFirmwareImageInfo | null;
17
- bt_adv_name?: string | null;
18
- bt_mac?: unknown;
19
- } | null;
20
- };
5
+ import type { DeviceFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
6
+ import { isProtocolV2BootloaderDeviceInfo } from '../protocols/protocol-v2/features';
21
7
 
22
8
  type ProtocolV1FeaturesCompat = PROTO.Features &
23
9
  Partial<PROTO.OnekeyFeatures> & {
@@ -26,7 +12,7 @@ type ProtocolV1FeaturesCompat = PROTO.Features &
26
12
  onekey_serial?: string;
27
13
  };
28
14
 
29
- const getImageVersion = (image?: DevFirmwareImageInfo | null) => image?.version ?? null;
15
+ const getImageVersion = (image?: DeviceFirmwareImageInfo | null) => image?.version ?? null;
30
16
 
31
17
  const bytesToHex = (value: unknown): string | undefined => {
32
18
  if (!value) return undefined;
@@ -42,9 +28,9 @@ const bytesToHex = (value: unknown): string | undefined => {
42
28
  return undefined;
43
29
  };
44
30
 
45
- const getImageBuildId = (image?: DevFirmwareImageInfo | null) => image?.build_id ?? undefined;
31
+ const getImageBuildId = (image?: DeviceFirmwareImageInfo | null) => image?.build_id ?? undefined;
46
32
 
47
- const getImageHash = (image?: DevFirmwareImageInfo | null) => bytesToHex(image?.hash);
33
+ const getImageHash = (image?: DeviceFirmwareImageInfo | null) => bytesToHex(image?.hash);
48
34
 
49
35
  const firstValue = <T>(...values: Array<T | null | undefined>) =>
50
36
  values.find(value => value !== undefined && value !== null);
@@ -226,7 +212,7 @@ export const buildProtocolV1FeaturesPayload = (
226
212
  /**
227
213
  * Protocol V2 的结构化 `Features` 构建器。
228
214
  *
229
- * 这是 Device 内部唯一缓存状态。字段只来自 DevGetDeviceInfo 或前一次 features
215
+ * 这是 Device 内部唯一缓存状态。字段只来自 DeviceInfoGet 或前一次 features
230
216
  * 缓存的同名字段级合并;不存在协议等价语义的字段保持 null/空值,不再通过
231
217
  * DeviceProfile 或 transport path 做身份兜底。
232
218
  */
@@ -234,11 +220,12 @@ export const buildProtocolV2FeaturesPayload = (
234
220
  deviceInfo?: ProtocolV2DeviceInfo,
235
221
  previous?: Features
236
222
  ): Features => {
237
- const info = deviceInfo as ProtocolV2DeviceInfoCompat | undefined;
238
- const fwApplication = firstValue(info?.fw?.application, info?.fw?.app);
239
- const fwBootloader = firstValue(info?.fw?.bootloader, info?.fw?.boot);
240
- const fwBoard = firstValue(info?.fw?.application_data, info?.fw?.board);
241
- const bleApplication = firstValue(info?.coprocessor?.application, info?.bt?.app);
223
+ const info = deviceInfo;
224
+ const fwApplication = info?.fw?.application;
225
+ const fwBootloader = info?.fw?.bootloader;
226
+ const fwBoard = firstValue(info?.fw?.application_data, info?.fw?.romloader);
227
+ const bleApplication = info?.coprocessor?.application;
228
+ const status = info?.status;
242
229
 
243
230
  const firmwareVersion = firstMeaningfulVersion(
244
231
  getImageVersion(fwApplication),
@@ -250,17 +237,26 @@ export const buildProtocolV2FeaturesPayload = (
250
237
  );
251
238
  const boardVersion = firstMeaningfulVersion(getImageVersion(fwBoard), previous?.boardVersion);
252
239
  const bleVersion = firstMeaningfulVersion(getImageVersion(bleApplication), previous?.bleVersion);
253
- const deviceId = firstValue(info?.hw?.device_id, previous?.deviceId) ?? null;
240
+ const deviceId = status?.device_id ?? null;
254
241
  const serialNo = firstValue(info?.hw?.serial_no, previous?.serialNo) ?? '';
255
- const label = firstValue(deviceInfo?.status?.label, previous?.label) ?? null;
256
- const bleName = firstValue(info?.coprocessor?.bt_adv_name, info?.bt?.adv_name, previous?.bleName);
257
- const initialized = firstValue(deviceInfo?.status?.init_states, previous?.initialized) ?? null;
258
- const passphraseProtection =
259
- firstValue(deviceInfo?.status?.passphrase_protection, previous?.passphraseProtection) ?? null;
260
- const language = firstValue(deviceInfo?.status?.language, previous?.language) ?? null;
261
- const backupRequired =
262
- firstValue(deviceInfo?.status?.backup_required, previous?.backupRequired) ?? null;
263
- const bleEnabled = firstValue(deviceInfo?.status?.bt_enable, previous?.bleEnabled);
242
+ const label = previous?.label ?? null;
243
+ const bleName = firstValue(info?.coprocessor?.bt_adv_name, previous?.bleName);
244
+ const initialized = firstValue(status?.init_states, previous?.initialized) ?? null;
245
+ const passphraseProtection = status?.passphrase_enabled ?? null;
246
+ const language = previous?.language ?? null;
247
+ const backupRequired = firstValue(status?.backup_required, previous?.backupRequired) ?? null;
248
+ const bleEnabled = previous?.bleEnabled;
249
+ const unlocked = firstValue(status?.unlocked, previous?.unlocked) ?? null;
250
+ const attachToPinEnabled = status?.attach_to_pin_enabled ?? null;
251
+ const unlockedAttachPin = status?.unlocked_by_attach_to_pin ?? undefined;
252
+ const bootloaderMode = isProtocolV2BootloaderDeviceInfo(info);
253
+ const mode = bootloaderMode
254
+ ? 'bootloader'
255
+ : initialized === false
256
+ ? 'notInitialized'
257
+ : initialized === true
258
+ ? 'normal'
259
+ : 'unknown';
264
260
 
265
261
  return {
266
262
  protocol: 'V2',
@@ -274,10 +270,10 @@ export const buildProtocolV2FeaturesPayload = (
274
270
  label,
275
271
  bleName: bleName ?? null,
276
272
  capabilities: [],
277
- mode: initialized === false ? 'notInitialized' : initialized === true ? 'normal' : 'unknown',
273
+ mode,
278
274
  initialized,
279
- bootloaderMode: false,
280
- unlocked: previous?.unlocked ?? null,
275
+ bootloaderMode,
276
+ unlocked,
281
277
  firmwarePresent: previous?.firmwarePresent ?? null,
282
278
  passphraseProtection,
283
279
  pinProtection: null,
@@ -291,6 +287,7 @@ export const buildProtocolV2FeaturesPayload = (
291
287
  sdProtection: null,
292
288
  wipeCodeProtection: null,
293
289
  passphraseAlwaysOnDevice: null,
290
+ attachToPinEnabled,
294
291
  safetyChecks: null,
295
292
  autoLockDelayMs: null,
296
293
  displayRotation: null,
@@ -300,35 +297,35 @@ export const buildProtocolV2FeaturesPayload = (
300
297
  boardVersion,
301
298
  bleVersion,
302
299
  se01Version: firstMeaningfulVersion(
303
- getImageVersion(deviceInfo?.se1?.app),
300
+ getImageVersion(info?.se1?.application),
304
301
  previous?.se01Version
305
302
  ),
306
303
  se02Version: firstMeaningfulVersion(
307
- getImageVersion(deviceInfo?.se2?.app),
304
+ getImageVersion(info?.se2?.application),
308
305
  previous?.se02Version
309
306
  ),
310
307
  se03Version: firstMeaningfulVersion(
311
- getImageVersion(deviceInfo?.se3?.app),
308
+ getImageVersion(info?.se3?.application),
312
309
  previous?.se03Version
313
310
  ),
314
311
  se04Version: firstMeaningfulVersion(
315
- getImageVersion(deviceInfo?.se4?.app),
312
+ getImageVersion(info?.se4?.application),
316
313
  previous?.se04Version
317
314
  ),
318
315
  se01BootVersion: firstMeaningfulVersion(
319
- getImageVersion(deviceInfo?.se1?.boot),
316
+ getImageVersion(info?.se1?.bootloader),
320
317
  previous?.se01BootVersion
321
318
  ),
322
319
  se02BootVersion: firstMeaningfulVersion(
323
- getImageVersion(deviceInfo?.se2?.boot),
320
+ getImageVersion(info?.se2?.bootloader),
324
321
  previous?.se02BootVersion
325
322
  ),
326
323
  se03BootVersion: firstMeaningfulVersion(
327
- getImageVersion(deviceInfo?.se3?.boot),
324
+ getImageVersion(info?.se3?.bootloader),
328
325
  previous?.se03BootVersion
329
326
  ),
330
327
  se04BootVersion: firstMeaningfulVersion(
331
- getImageVersion(deviceInfo?.se4?.boot),
328
+ getImageVersion(info?.se4?.bootloader),
332
329
  previous?.se04BootVersion
333
330
  ),
334
331
  seVersion: previous?.seVersion ?? null,
@@ -341,26 +338,26 @@ export const buildProtocolV2FeaturesPayload = (
341
338
  boardHash: getImageHash(fwBoard) ?? previous?.verify?.boardHash,
342
339
  bleBuildId: getImageBuildId(bleApplication) ?? previous?.verify?.bleBuildId,
343
340
  bleHash: getImageHash(bleApplication) ?? previous?.verify?.bleHash,
344
- se01BuildId: getImageBuildId(deviceInfo?.se1?.app) ?? previous?.verify?.se01BuildId,
345
- se01Hash: getImageHash(deviceInfo?.se1?.app) ?? previous?.verify?.se01Hash,
346
- se02BuildId: getImageBuildId(deviceInfo?.se2?.app) ?? previous?.verify?.se02BuildId,
347
- se02Hash: getImageHash(deviceInfo?.se2?.app) ?? previous?.verify?.se02Hash,
348
- se03BuildId: getImageBuildId(deviceInfo?.se3?.app) ?? previous?.verify?.se03BuildId,
349
- se03Hash: getImageHash(deviceInfo?.se3?.app) ?? previous?.verify?.se03Hash,
350
- se04BuildId: getImageBuildId(deviceInfo?.se4?.app) ?? previous?.verify?.se04BuildId,
351
- se04Hash: getImageHash(deviceInfo?.se4?.app) ?? previous?.verify?.se04Hash,
352
- se01BootBuildId: getImageBuildId(deviceInfo?.se1?.boot) ?? previous?.verify?.se01BootBuildId,
353
- se01BootHash: getImageHash(deviceInfo?.se1?.boot) ?? previous?.verify?.se01BootHash,
354
- se02BootBuildId: getImageBuildId(deviceInfo?.se2?.boot) ?? previous?.verify?.se02BootBuildId,
355
- se02BootHash: getImageHash(deviceInfo?.se2?.boot) ?? previous?.verify?.se02BootHash,
356
- se03BootBuildId: getImageBuildId(deviceInfo?.se3?.boot) ?? previous?.verify?.se03BootBuildId,
357
- se03BootHash: getImageHash(deviceInfo?.se3?.boot) ?? previous?.verify?.se03BootHash,
358
- se04BootBuildId: getImageBuildId(deviceInfo?.se4?.boot) ?? previous?.verify?.se04BootBuildId,
359
- se04BootHash: getImageHash(deviceInfo?.se4?.boot) ?? previous?.verify?.se04BootHash,
341
+ se01BuildId: getImageBuildId(info?.se1?.application) ?? previous?.verify?.se01BuildId,
342
+ se01Hash: getImageHash(info?.se1?.application) ?? previous?.verify?.se01Hash,
343
+ se02BuildId: getImageBuildId(info?.se2?.application) ?? previous?.verify?.se02BuildId,
344
+ se02Hash: getImageHash(info?.se2?.application) ?? previous?.verify?.se02Hash,
345
+ se03BuildId: getImageBuildId(info?.se3?.application) ?? previous?.verify?.se03BuildId,
346
+ se03Hash: getImageHash(info?.se3?.application) ?? previous?.verify?.se03Hash,
347
+ se04BuildId: getImageBuildId(info?.se4?.application) ?? previous?.verify?.se04BuildId,
348
+ se04Hash: getImageHash(info?.se4?.application) ?? previous?.verify?.se04Hash,
349
+ se01BootBuildId: getImageBuildId(info?.se1?.bootloader) ?? previous?.verify?.se01BootBuildId,
350
+ se01BootHash: getImageHash(info?.se1?.bootloader) ?? previous?.verify?.se01BootHash,
351
+ se02BootBuildId: getImageBuildId(info?.se2?.bootloader) ?? previous?.verify?.se02BootBuildId,
352
+ se02BootHash: getImageHash(info?.se2?.bootloader) ?? previous?.verify?.se02BootHash,
353
+ se03BootBuildId: getImageBuildId(info?.se3?.bootloader) ?? previous?.verify?.se03BootBuildId,
354
+ se03BootHash: getImageHash(info?.se3?.bootloader) ?? previous?.verify?.se03BootHash,
355
+ se04BootBuildId: getImageBuildId(info?.se4?.bootloader) ?? previous?.verify?.se04BootBuildId,
356
+ se04BootHash: getImageHash(info?.se4?.bootloader) ?? previous?.verify?.se04BootHash,
360
357
  },
361
358
  sessionId: previous?.sessionId ?? null,
362
359
  passphraseState: previous?.passphraseState,
363
- unlockedAttachPin: previous?.unlockedAttachPin,
360
+ unlockedAttachPin,
364
361
  raw: {
365
362
  protocolV2DeviceInfo: deviceInfo,
366
363
  },
@@ -25,7 +25,8 @@ import type {
25
25
  GetDeviceInfoParams,
26
26
  } from '../types/api/getDeviceInfo';
27
27
  import type { Features, OnekeyFeatures } from '../types';
28
- import type { DevFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
28
+ import type { DeviceFirmwareImageInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
29
+ import { isProtocolV2BootloaderDeviceInfo } from '../protocols/protocol-v2/features';
29
30
 
30
31
  type BuildProtocolV1ProfileParams = {
31
32
  protocol?: DeviceInfoProtocol;
@@ -68,11 +69,11 @@ const bytesToHex = (value: unknown): string | undefined => {
68
69
  return undefined;
69
70
  };
70
71
 
71
- const getImageVersion = (image?: DevFirmwareImageInfo | null) => image?.version ?? null;
72
+ const getImageVersion = (image?: DeviceFirmwareImageInfo | null) => image?.version ?? null;
72
73
 
73
- const getImageBuildId = (image?: DevFirmwareImageInfo | null) => image?.build_id ?? undefined;
74
+ const getImageBuildId = (image?: DeviceFirmwareImageInfo | null) => image?.build_id ?? undefined;
74
75
 
75
- const getImageHash = (image?: DevFirmwareImageInfo | null) => bytesToHex(image?.hash);
76
+ const getImageHash = (image?: DeviceFirmwareImageInfo | null) => bytesToHex(image?.hash);
76
77
 
77
78
  const shouldIncludeVerify = (scope?: GetDeviceInfoParams['scope']) =>
78
79
  scope === 'verify' || scope === 'full';
@@ -86,6 +87,7 @@ const getDeviceMode = (features?: Features): DeviceInfoStatus['mode'] => {
86
87
  };
87
88
 
88
89
  const getProtocolV2Mode = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus['mode'] => {
90
+ if (isProtocolV2BootloaderDeviceInfo(deviceInfo)) return 'bootloader';
89
91
  const initialized = deviceInfo?.status?.init_states;
90
92
  if (initialized === false) return 'notInitialized';
91
93
  if (initialized === true) return 'normal';
@@ -147,20 +149,25 @@ const normalizeV1Versions = (
147
149
  ),
148
150
  });
149
151
 
150
- const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions => ({
151
- firmware: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.app)),
152
- bootloader: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.boot)),
153
- board: firstMeaningfulVersion(getImageVersion(deviceInfo?.fw?.board)),
154
- ble: firstMeaningfulVersion(getImageVersion(deviceInfo?.bt?.app)),
155
- se01: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.app)),
156
- se02: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.app)),
157
- se03: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.app)),
158
- se04: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.app)),
159
- se01Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se1?.boot)),
160
- se02Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se2?.boot)),
161
- se03Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se3?.boot)),
162
- se04Boot: firstMeaningfulVersion(getImageVersion(deviceInfo?.se4?.boot)),
163
- });
152
+ const normalizeV2Versions = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVersions => {
153
+ const info = deviceInfo;
154
+ return {
155
+ firmware: firstMeaningfulVersion(getImageVersion(info?.fw?.application)),
156
+ bootloader: firstMeaningfulVersion(getImageVersion(info?.fw?.bootloader)),
157
+ board: firstMeaningfulVersion(
158
+ getImageVersion(info?.fw?.application_data ?? info?.fw?.romloader)
159
+ ),
160
+ ble: firstMeaningfulVersion(getImageVersion(info?.coprocessor?.application)),
161
+ se01: firstMeaningfulVersion(getImageVersion(info?.se1?.application)),
162
+ se02: firstMeaningfulVersion(getImageVersion(info?.se2?.application)),
163
+ se03: firstMeaningfulVersion(getImageVersion(info?.se3?.application)),
164
+ se04: firstMeaningfulVersion(getImageVersion(info?.se4?.application)),
165
+ se01Boot: firstMeaningfulVersion(getImageVersion(info?.se1?.bootloader)),
166
+ se02Boot: firstMeaningfulVersion(getImageVersion(info?.se2?.bootloader)),
167
+ se03Boot: firstMeaningfulVersion(getImageVersion(info?.se3?.bootloader)),
168
+ se04Boot: firstMeaningfulVersion(getImageVersion(info?.se4?.bootloader)),
169
+ };
170
+ };
164
171
 
165
172
  // V2 状态由 normalizeV2Status 处理,这里只服务 buildProfileFromProtocolV1 的 V1 路径。
166
173
  const normalizeV1Status = (features?: Features): DeviceInfoStatus => ({
@@ -169,23 +176,31 @@ const normalizeV1Status = (features?: Features): DeviceInfoStatus => ({
169
176
  bootloaderMode: features?.bootloaderMode ?? null,
170
177
  unlocked: features?.unlocked ?? null,
171
178
  passphraseProtection: features?.passphraseProtection ?? null,
179
+ attachToPinEnabled: features?.attachToPinEnabled ?? null,
180
+ unlockedAttachPin: features?.unlockedAttachPin ?? null,
172
181
  backupRequired: features?.backupRequired ?? null,
173
182
  noBackup: features?.noBackup ?? null,
174
183
  language: features?.language ?? null,
175
184
  bleEnabled: features?.bleEnabled ?? null,
176
185
  });
177
186
 
178
- const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus => ({
179
- mode: getProtocolV2Mode(deviceInfo),
180
- initialized: deviceInfo?.status?.init_states ?? null,
181
- bootloaderMode: false,
182
- unlocked: null,
183
- passphraseProtection: deviceInfo?.status?.passphrase_protection ?? null,
184
- backupRequired: deviceInfo?.status?.backup_required ?? null,
185
- noBackup: null,
186
- language: deviceInfo?.status?.language ?? null,
187
- bleEnabled: deviceInfo?.status?.bt_enable ?? null,
188
- });
187
+ const normalizeV2Status = (deviceInfo?: ProtocolV2DeviceInfo): DeviceInfoStatus => {
188
+ const status = deviceInfo?.status;
189
+ const bootloaderMode = isProtocolV2BootloaderDeviceInfo(deviceInfo);
190
+ return {
191
+ mode: getProtocolV2Mode(deviceInfo),
192
+ initialized: status?.init_states ?? null,
193
+ bootloaderMode,
194
+ unlocked: status?.unlocked ?? null,
195
+ passphraseProtection: status?.passphrase_enabled ?? null,
196
+ attachToPinEnabled: status?.attach_to_pin_enabled ?? null,
197
+ unlockedAttachPin: status?.unlocked_by_attach_to_pin ?? null,
198
+ backupRequired: status?.backup_required ?? null,
199
+ noBackup: null,
200
+ language: null,
201
+ bleEnabled: null,
202
+ };
203
+ };
189
204
 
190
205
  const normalizeV1Verify = (
191
206
  features?: Features,
@@ -223,32 +238,35 @@ const normalizeV1Verify = (
223
238
  se04BootHash: protocolV1OneKeyFeatures?.onekey_se04_boot_hash ?? features?.verify?.se04BootHash,
224
239
  });
225
240
 
226
- const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify => ({
227
- firmwareBuildId: getImageBuildId(deviceInfo?.fw?.app),
228
- firmwareHash: getImageHash(deviceInfo?.fw?.app),
229
- bootloaderBuildId: getImageBuildId(deviceInfo?.fw?.boot),
230
- bootloaderHash: getImageHash(deviceInfo?.fw?.boot),
231
- boardBuildId: getImageBuildId(deviceInfo?.fw?.board),
232
- boardHash: getImageHash(deviceInfo?.fw?.board),
233
- bleBuildId: getImageBuildId(deviceInfo?.bt?.app),
234
- bleHash: getImageHash(deviceInfo?.bt?.app),
235
- se01BuildId: getImageBuildId(deviceInfo?.se1?.app),
236
- se01Hash: getImageHash(deviceInfo?.se1?.app),
237
- se02BuildId: getImageBuildId(deviceInfo?.se2?.app),
238
- se02Hash: getImageHash(deviceInfo?.se2?.app),
239
- se03BuildId: getImageBuildId(deviceInfo?.se3?.app),
240
- se03Hash: getImageHash(deviceInfo?.se3?.app),
241
- se04BuildId: getImageBuildId(deviceInfo?.se4?.app),
242
- se04Hash: getImageHash(deviceInfo?.se4?.app),
243
- se01BootBuildId: getImageBuildId(deviceInfo?.se1?.boot),
244
- se01BootHash: getImageHash(deviceInfo?.se1?.boot),
245
- se02BootBuildId: getImageBuildId(deviceInfo?.se2?.boot),
246
- se02BootHash: getImageHash(deviceInfo?.se2?.boot),
247
- se03BootBuildId: getImageBuildId(deviceInfo?.se3?.boot),
248
- se03BootHash: getImageHash(deviceInfo?.se3?.boot),
249
- se04BootBuildId: getImageBuildId(deviceInfo?.se4?.boot),
250
- se04BootHash: getImageHash(deviceInfo?.se4?.boot),
251
- });
241
+ const normalizeV2Verify = (deviceInfo?: ProtocolV2DeviceInfo): DeviceProfileVerify => {
242
+ const info = deviceInfo;
243
+ return {
244
+ firmwareBuildId: getImageBuildId(info?.fw?.application),
245
+ firmwareHash: getImageHash(info?.fw?.application),
246
+ bootloaderBuildId: getImageBuildId(info?.fw?.bootloader),
247
+ bootloaderHash: getImageHash(info?.fw?.bootloader),
248
+ boardBuildId: getImageBuildId(info?.fw?.application_data ?? info?.fw?.romloader),
249
+ boardHash: getImageHash(info?.fw?.application_data ?? info?.fw?.romloader),
250
+ bleBuildId: getImageBuildId(info?.coprocessor?.application),
251
+ bleHash: getImageHash(info?.coprocessor?.application),
252
+ se01BuildId: getImageBuildId(info?.se1?.application),
253
+ se01Hash: getImageHash(info?.se1?.application),
254
+ se02BuildId: getImageBuildId(info?.se2?.application),
255
+ se02Hash: getImageHash(info?.se2?.application),
256
+ se03BuildId: getImageBuildId(info?.se3?.application),
257
+ se03Hash: getImageHash(info?.se3?.application),
258
+ se04BuildId: getImageBuildId(info?.se4?.application),
259
+ se04Hash: getImageHash(info?.se4?.application),
260
+ se01BootBuildId: getImageBuildId(info?.se1?.bootloader),
261
+ se01BootHash: getImageHash(info?.se1?.bootloader),
262
+ se02BootBuildId: getImageBuildId(info?.se2?.bootloader),
263
+ se02BootHash: getImageHash(info?.se2?.bootloader),
264
+ se03BootBuildId: getImageBuildId(info?.se3?.bootloader),
265
+ se03BootHash: getImageHash(info?.se3?.bootloader),
266
+ se04BootBuildId: getImageBuildId(info?.se4?.bootloader),
267
+ se04BootHash: getImageHash(info?.se4?.bootloader),
268
+ };
269
+ };
252
270
 
253
271
  const normalizeRaw = ({
254
272
  features,
@@ -304,10 +322,11 @@ export function buildProfileFromProtocolV2({
304
322
  scope = 'basic',
305
323
  includeRaw = false,
306
324
  }: BuildProtocolV2ProfileParams): DeviceProfile {
307
- const deviceId = deviceInfo?.hw?.device_id || '';
325
+ const info = deviceInfo;
326
+ const deviceId = info?.status?.device_id || '';
308
327
  const serialNo = deviceInfo?.hw?.serial_no || '';
309
- const label = deviceInfo?.status?.label ?? null;
310
- const bleName = deviceInfo?.bt?.adv_name ?? null;
328
+ const label = null;
329
+ const bleName = info?.coprocessor?.bt_adv_name ?? null;
311
330
  const verify = normalizeV2Verify(deviceInfo);
312
331
 
313
332
  return {
package/src/inject.ts CHANGED
@@ -100,6 +100,7 @@ export const createCoreApi = (
100
100
  | 'switchTransport'
101
101
  > => ({
102
102
  getLogs: () => call({ method: 'getLogs' }),
103
+ clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
103
104
  /**
104
105
  * 搜索设备
105
106
  */
@@ -151,28 +152,24 @@ export const createCoreApi = (
151
152
  deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
152
153
 
153
154
  // File system & device control API (Protocol V2 only)
154
- getProtoVersion: (connectId, params) => call({ ...params, connectId, method: 'getProtoVersion' }),
155
+ protocolInfoRequest: (connectId, params) =>
156
+ call({ ...params, connectId, method: 'protocolInfoRequest' }),
155
157
  ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
156
158
  deviceReboot: (connectId, params) => call({ ...params, connectId, method: 'deviceReboot' }),
157
- deviceGetDeviceInfo: (connectId, params) =>
158
- call({ ...params, connectId, method: 'deviceGetDeviceInfo' }),
159
- deviceGetOnboardingStatus: (connectId, params) =>
160
- call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
159
+ deviceInfoGet: (connectId, params) => call({ ...params, connectId, method: 'deviceInfoGet' }),
160
+ deviceStatusGet: (connectId, params) => call({ ...params, connectId, method: 'deviceStatusGet' }),
161
+ deviceSessionGet: (connectId, params) =>
162
+ call({ ...params, connectId, method: 'deviceSessionGet' }),
161
163
  deviceFirmwareUpdate: (connectId, params) =>
162
164
  call({ ...params, connectId, method: 'deviceFirmwareUpdate' }),
163
165
  deviceGetFirmwareUpdateStatus: (connectId, params) =>
164
166
  call({ ...params, connectId, method: 'deviceGetFirmwareUpdateStatus' }),
165
- devReboot: (connectId, params) => call({ ...params, connectId, method: 'devReboot' }),
166
- devGetDeviceInfo: (connectId, params) =>
167
- call({ ...params, connectId, method: 'devGetDeviceInfo' }),
168
- devFirmwareUpdate: (connectId, params) =>
169
- call({ ...params, connectId, method: 'devFirmwareUpdate' }),
170
- devGetFirmwareUpdateStatus: (connectId, params) =>
171
- call({ ...params, connectId, method: 'devGetFirmwareUpdateStatus' }),
172
- factoryDeviceInfoSettings: (connectId, params) =>
173
- call({ ...params, connectId, method: 'factoryDeviceInfoSettings' }),
174
- factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
175
- filesystemFixPermission: connectId => call({ connectId, method: 'filesystemFixPermission' }),
167
+ deviceFactoryInfoSet: (connectId, params) =>
168
+ call({ ...params, connectId, method: 'deviceFactoryInfoSet' }),
169
+ deviceFactoryInfoGet: (connectId, params) =>
170
+ call({ ...params, connectId, method: 'deviceFactoryInfoGet' }),
171
+ filesystemPermissionFix: (connectId, params) =>
172
+ call({ ...params, connectId, method: 'filesystemPermissionFix' }),
176
173
  fileRead: (connectId, params) => call({ ...params, connectId, method: 'fileRead' }),
177
174
  fileWrite: (connectId, params) => call({ ...params, connectId, method: 'fileWrite' }),
178
175
  fileDelete: (connectId, params) => call({ ...params, connectId, method: 'fileDelete' }),
@@ -1,19 +1,19 @@
1
- import { DevSEState, DevSeType } from '@onekeyfe/hd-transport';
1
+ import { DeviceSEState, DeviceSeType } from '@onekeyfe/hd-transport';
2
2
 
3
- import type { DevGetDeviceInfo, DevSEInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
3
+ import type { DeviceInfoGet, DeviceSEInfo, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
4
4
  import type { DeviceCommands } from '../../device/DeviceCommands';
5
5
 
6
- // 单源类型:直接使用 hd-transport 生成的 ProtocolV2DeviceInfo / DevSEInfo /
7
- // DevFirmwareImageInfo(与 firmware-pro2 proto 一致),不再维护手写副本。
6
+ // 单源类型:直接使用 hd-transport 生成的 ProtocolV2DeviceInfo / DeviceSEInfo /
7
+ // DeviceFirmwareImageInfo(与 firmware-pro2 proto 一致),不再维护手写副本。
8
8
  export type { ProtocolV2DeviceInfo };
9
- export type { DevFirmwareImageInfo as ProtocolV2FirmwareImageInfo } from '@onekeyfe/hd-transport';
10
- export type { DevSEInfo as ProtocolV2SEInfo } from '@onekeyfe/hd-transport';
9
+ export type { DeviceFirmwareImageInfo as ProtocolV2FirmwareImageInfo } from '@onekeyfe/hd-transport';
10
+ export type { DeviceSEInfo as ProtocolV2SEInfo } from '@onekeyfe/hd-transport';
11
11
 
12
12
  export type ProtocolV2SeStateLabel = 'BOOT' | 'APP_FACTORY' | 'APP';
13
13
 
14
14
  /**
15
- * 传输层解码会把 proto 枚举输出为名称字符串(见 hd-transport messageToJSON),
16
- * 但生成类型声明为数值枚举;这里统一兼容两种形态。
15
+ * 传输层沿用历史 decode 语义:单值 proto enum 输出为名称字符串。
16
+ * 这里按 SDK decode 后的字符串语义处理,同时接受数字枚举,便于低层调用复用。
17
17
  */
18
18
  const normalizeEnumValue = <T extends Record<string | number, string | number>>(
19
19
  enumObject: T,
@@ -26,11 +26,11 @@ const normalizeEnumValue = <T extends Record<string | number, string | number>>(
26
26
  };
27
27
 
28
28
  /**
29
- * DevSEInfo.state → 可读标签。SDK 内唯一的 SE 状态映射实现,
29
+ * DeviceSEInfo.state → 可读标签。SDK 内唯一的 SE 状态映射实现,
30
30
  * DeviceProfile 与标准 Features 构建都从这里取。
31
31
  */
32
- export const getProtocolV2SeState = (se?: DevSEInfo): ProtocolV2SeStateLabel | null => {
33
- const label = normalizeEnumValue(DevSEState, se?.state);
32
+ export const getProtocolV2SeState = (se?: DeviceSEInfo): ProtocolV2SeStateLabel | null => {
33
+ const label = normalizeEnumValue(DeviceSEState, se?.state);
34
34
  switch (label) {
35
35
  case 'BOOT':
36
36
  return 'BOOT';
@@ -44,17 +44,20 @@ export const getProtocolV2SeState = (se?: DevSEInfo): ProtocolV2SeStateLabel | n
44
44
  };
45
45
 
46
46
  /**
47
- * DevSEInfo.type → 可读标签(如 'THD89')。DeviceProfile / Features
47
+ * DeviceSEInfo.type → 可读标签(如 'THD89')。DeviceProfile / Features
48
48
  * 的 SE 类型归一化从这里取。
49
49
  */
50
- export const getProtocolV2SeType = (se?: DevSEInfo): string | null =>
51
- normalizeEnumValue(DevSeType, se?.type);
50
+ export const getProtocolV2SeType = (se?: DeviceSEInfo): string | null =>
51
+ normalizeEnumValue(DeviceSeType, se?.type);
52
+
53
+ export const isProtocolV2BootloaderDeviceInfo = (deviceInfo?: ProtocolV2DeviceInfo | null) =>
54
+ !!deviceInfo && deviceInfo.status == null;
52
55
 
53
56
  export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
54
57
  targets: {
55
58
  hw: true,
56
59
  fw: true,
57
- bt: true,
60
+ coprocessor: true,
58
61
  status: true,
59
62
  },
60
63
  types: {
@@ -66,13 +69,13 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
66
69
  /**
67
70
  * 轻量状态刷新请求(每次 run 前使用)。
68
71
  *
69
- * status 提供 init_states / label / passphrase_protection 等会在设备端变化的字段;
70
- * hw / bt 提供 serialNo / bleName 等身份字段;不含 fw/SE targets,单帧请求开销很小。
72
+ * status 提供 init_states / passphrase_enabled 等会在设备端变化的字段;
73
+ * hw / coprocessor 提供 serialNo / bleName 等身份字段;不含 fw/SE targets,单帧请求开销很小。
71
74
  */
72
75
  export const PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST = {
73
76
  targets: {
74
77
  hw: true,
75
- bt: true,
78
+ coprocessor: true,
76
79
  status: true,
77
80
  },
78
81
  types: {
@@ -85,7 +88,7 @@ export const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
85
88
  targets: {
86
89
  hw: true,
87
90
  fw: true,
88
- bt: true,
91
+ coprocessor: true,
89
92
  se1: true,
90
93
  se2: true,
91
94
  se3: true,
@@ -102,7 +105,7 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
102
105
  targets: {
103
106
  hw: true,
104
107
  fw: true,
105
- bt: true,
108
+ coprocessor: true,
106
109
  se1: true,
107
110
  se2: true,
108
111
  se3: true,
@@ -120,43 +123,6 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
120
123
  export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
121
124
  export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
122
125
 
123
- /**
124
- * 临时开关(默认关闭):当前正式链路直接调用 DevGetDeviceInfo。
125
- * 仅当 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo 时,才显式开启 mock。
126
- * 开启时跳过 wire 调用,直接返回 mock DeviceInfo;
127
- * DevGetDeviceInfo 尚未返回的字段保持为空,不再用 transport path 兜底成设备身份。
128
- *
129
- * 固件实现 DevGetDeviceInfo 稳定后:删除开关与 mock。
130
- * 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
131
- * 不能作为升级成功的依据。
132
- */
133
- let protocolV2DeviceInfoMockEnabled = false;
134
-
135
- export const setProtocolV2DeviceInfoMock = (enabled: boolean) => {
136
- protocolV2DeviceInfoMockEnabled = enabled;
137
- };
138
-
139
- export const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockEnabled;
140
-
141
- /** 每次调用返回新对象,避免调用方原地修改互相污染。 */
142
- export const buildMockProtocolV2DeviceInfo = (): ProtocolV2DeviceInfo => ({
143
- protocol_version: 2,
144
- hw: {
145
- // 留空:协议未上报时 SDK 不再用 transport path 伪造身份字段
146
- serial_no: '',
147
- },
148
- fw: {
149
- app: { version: '0.1.0' },
150
- },
151
- bt: {},
152
- status: {
153
- init_states: true,
154
- language: 'en_US',
155
- passphrase_protection: false,
156
- bt_enable: true,
157
- },
158
- });
159
-
160
126
  export async function requestProtocolV2DeviceInfo({
161
127
  commands,
162
128
  timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS,
@@ -164,15 +130,12 @@ export async function requestProtocolV2DeviceInfo({
164
130
  }: {
165
131
  commands: DeviceCommands;
166
132
  timeoutMs?: number;
167
- request?: DevGetDeviceInfo;
133
+ request?: DeviceInfoGet;
168
134
  }): Promise<ProtocolV2DeviceInfo> {
169
- if (isProtocolV2DeviceInfoMockEnabled()) {
170
- return buildMockProtocolV2DeviceInfo();
171
- }
172
- const { message } = await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
135
+ const { message } = await commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
173
136
  timeoutMs,
174
137
  });
175
138
  // 'DeviceInfo' 在生成类型里是 V1 DeviceInfo | ProtocolV2DeviceInfo 的合并;
176
- // DevGetDeviceInfo 是 V2-only 消息,这里收窄到 V2 形态。
139
+ // DeviceInfoGet 是 V2-only 消息,这里收窄到 V2 形态。
177
140
  return message as ProtocolV2DeviceInfo;
178
141
  }