@onekeyfe/hd-core 1.2.0-alpha.2 → 1.2.0-alpha.4

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 (121) hide show
  1. package/__tests__/preInitialize.test.ts +33 -0
  2. package/__tests__/protocol-v2.test.ts +1577 -624
  3. package/dist/api/FileRead.d.ts.map +1 -1
  4. package/dist/api/FileWrite.d.ts.map +1 -1
  5. package/dist/api/FirmwareUpdateV4.d.ts +20 -2
  6. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  7. package/dist/api/GetPassphraseState.d.ts +4 -4
  8. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  9. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  10. package/dist/api/firmware/getBinary.d.ts +4 -0
  11. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  12. package/dist/api/index.d.ts +5 -10
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  15. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  16. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  17. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  18. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  19. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  20. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +1 -1
  21. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  22. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  23. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  24. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  25. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  26. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  27. package/dist/api/protocol-v2/helpers.d.ts +24 -19
  28. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  29. package/dist/api/ton/TonSignData.d.ts +1 -5
  30. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  31. package/dist/constants/index.d.ts +2 -1
  32. package/dist/constants/index.d.ts.map +1 -1
  33. package/dist/core/index.d.ts.map +1 -1
  34. package/dist/data-manager/DataManager.d.ts +1 -1
  35. package/dist/data-manager/DataManager.d.ts.map +1 -1
  36. package/dist/device/Device.d.ts +5 -1
  37. package/dist/device/Device.d.ts.map +1 -1
  38. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  39. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  40. package/dist/index.d.ts +85 -58
  41. package/dist/index.js +1672 -1640
  42. package/dist/inject.d.ts.map +1 -1
  43. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  44. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  45. package/dist/protocols/protocol-v2/firmware.d.ts +10 -9
  46. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  47. package/dist/types/api/firmwareUpdate.d.ts +1 -6
  48. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  49. package/dist/types/api/getDeviceInfo.d.ts +2 -0
  50. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  51. package/dist/types/api/getPassphraseState.d.ts +4 -4
  52. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  53. package/dist/types/api/index.d.ts +6 -11
  54. package/dist/types/api/index.d.ts.map +1 -1
  55. package/dist/types/api/protocolV2.d.ts +12 -17
  56. package/dist/types/api/protocolV2.d.ts.map +1 -1
  57. package/dist/types/device.d.ts +1 -0
  58. package/dist/types/device.d.ts.map +1 -1
  59. package/dist/types/params.d.ts +1 -0
  60. package/dist/types/params.d.ts.map +1 -1
  61. package/dist/types/settings.d.ts +29 -1
  62. package/dist/types/settings.d.ts.map +1 -1
  63. package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
  64. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  65. package/dist/utils/patch.d.ts +1 -1
  66. package/dist/utils/patch.d.ts.map +1 -1
  67. package/package.json +4 -4
  68. package/src/api/FileRead.ts +14 -1
  69. package/src/api/FileWrite.ts +14 -1
  70. package/src/api/FirmwareUpdateV4.ts +933 -197
  71. package/src/api/GetOnekeyFeatures.ts +1 -1
  72. package/src/api/GetPassphraseState.ts +7 -4
  73. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  74. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  75. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +11 -4
  76. package/src/api/index.ts +5 -10
  77. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  78. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  79. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  80. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +2 -2
  81. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  82. package/src/api/protocol-v2/DeviceReboot.ts +2 -2
  83. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  84. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  85. package/src/api/protocol-v2/helpers.ts +48 -57
  86. package/src/api/ton/TonSignData.ts +1 -5
  87. package/src/constants/index.ts +10 -1
  88. package/src/core/index.ts +19 -3
  89. package/src/data/messages/messages-protocol-v2.json +1224 -1804
  90. package/src/data-manager/DataManager.ts +7 -0
  91. package/src/device/Device.ts +34 -12
  92. package/src/device/DevicePool.ts +6 -6
  93. package/src/deviceProfile/buildDeviceFeatures.ts +61 -63
  94. package/src/deviceProfile/buildDeviceProfile.ts +78 -60
  95. package/src/inject.ts +10 -16
  96. package/src/protocols/protocol-v2/features.ts +26 -62
  97. package/src/protocols/protocol-v2/firmware.ts +11 -36
  98. package/src/types/api/firmwareUpdate.ts +10 -20
  99. package/src/types/api/getDeviceInfo.ts +2 -0
  100. package/src/types/api/getPassphraseState.ts +4 -4
  101. package/src/types/api/index.ts +10 -20
  102. package/src/types/api/protocolV2.ts +21 -42
  103. package/src/types/device.ts +1 -0
  104. package/src/types/params.ts +4 -0
  105. package/src/types/settings.ts +44 -30
  106. package/src/utils/deviceFeaturesUtils.ts +52 -11
  107. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  108. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  109. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  110. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  111. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  112. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  113. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  114. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  115. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  116. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  117. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  118. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  119. package/src/api/protocol-v2/DevReboot.ts +0 -24
  120. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  121. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
package/src/inject.ts CHANGED
@@ -151,28 +151,22 @@ export const createCoreApi = (
151
151
  deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
152
152
 
153
153
  // File system & device control API (Protocol V2 only)
154
- getProtoVersion: (connectId, params) => call({ ...params, connectId, method: 'getProtoVersion' }),
154
+ protocolInfoRequest: (connectId, params) =>
155
+ call({ ...params, connectId, method: 'protocolInfoRequest' }),
155
156
  ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
156
157
  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' }),
158
+ deviceInfoGet: (connectId, params) =>
159
+ call({ ...params, connectId, method: 'deviceInfoGet' }),
161
160
  deviceFirmwareUpdate: (connectId, params) =>
162
161
  call({ ...params, connectId, method: 'deviceFirmwareUpdate' }),
163
162
  deviceGetFirmwareUpdateStatus: (connectId, params) =>
164
163
  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' }),
164
+ deviceFactoryInfoSet: (connectId, params) =>
165
+ call({ ...params, connectId, method: 'deviceFactoryInfoSet' }),
166
+ deviceFactoryInfoGet: (connectId, params) =>
167
+ call({ ...params, connectId, method: 'deviceFactoryInfoGet' }),
168
+ filesystemPermissionFix: (connectId, params) =>
169
+ call({ ...params, connectId, method: 'filesystemPermissionFix' }),
176
170
  fileRead: (connectId, params) => call({ ...params, connectId, method: 'fileRead' }),
177
171
  fileWrite: (connectId, params) => call({ ...params, connectId, method: 'fileWrite' }),
178
172
  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 { DeviceGetDeviceInfo, 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,42 +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
- * 临时开关(默认开启):当前 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo,
125
- * 真实调用只会超时失败。开启时跳过 wire 调用,直接返回 mock DeviceInfo;
126
- * DevGetDeviceInfo 尚未返回的字段保持为空,不再用 transport path 兜底成设备身份。
127
- *
128
- * 固件实现 DevGetDeviceInfo 后:把默认值改回 false(或直接删除开关与 mock)。
129
- * 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
130
- * 不能作为升级成功的依据。
131
- */
132
- let protocolV2DeviceInfoMockEnabled = true;
133
-
134
- export const setProtocolV2DeviceInfoMock = (enabled: boolean) => {
135
- protocolV2DeviceInfoMockEnabled = enabled;
136
- };
137
-
138
- export const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockEnabled;
139
-
140
- /** 每次调用返回新对象,避免调用方原地修改互相污染。 */
141
- export const buildMockProtocolV2DeviceInfo = (): ProtocolV2DeviceInfo => ({
142
- protocol_version: 2,
143
- hw: {
144
- // 留空:协议未上报时 SDK 不再用 transport path 伪造身份字段
145
- serial_no: '',
146
- },
147
- fw: {
148
- app: { version: '0.1.0' },
149
- },
150
- bt: {},
151
- status: {
152
- init_states: true,
153
- language: 'en_US',
154
- passphrase_protection: false,
155
- bt_enable: true,
156
- },
157
- });
158
-
159
126
  export async function requestProtocolV2DeviceInfo({
160
127
  commands,
161
128
  timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS,
@@ -163,15 +130,12 @@ export async function requestProtocolV2DeviceInfo({
163
130
  }: {
164
131
  commands: DeviceCommands;
165
132
  timeoutMs?: number;
166
- request?: DeviceGetDeviceInfo;
133
+ request?: DeviceInfoGet;
167
134
  }): Promise<ProtocolV2DeviceInfo> {
168
- if (protocolV2DeviceInfoMockEnabled) {
169
- return buildMockProtocolV2DeviceInfo();
170
- }
171
- const { message } = await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
135
+ const { message } = await commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
172
136
  timeoutMs,
173
137
  });
174
138
  // 'DeviceInfo' 在生成类型里是 V1 DeviceInfo | ProtocolV2DeviceInfo 的合并;
175
- // DevGetDeviceInfo 是 V2-only 消息,这里收窄到 V2 形态。
139
+ // DeviceInfoGet 是 V2-only 消息,这里收窄到 V2 形态。
176
140
  return message as ProtocolV2DeviceInfo;
177
141
  }
@@ -1,43 +1,18 @@
1
1
  /**
2
- * 当前 firmware-pro2 子模块的 DevFirmwareTargetType
3
- *
4
- * 注意:仓库里的 hd-transport 生成物暂时仍带旧 target 名称;这里显式按
5
- * submodules/firmware-pro2/sys/protobuf/onekey_protocol/latest/messages_device.proto
6
- * 对齐当前子模块,避免运行时取到 undefined。
2
+ * 当前 firmware-pro2 子模块的 DeviceFirmwareTargetType
7
3
  */
8
4
  export const ProtocolV2FirmwareTargetType = {
9
- TARGET_MAIN_APP: 0,
10
- TARGET_MAIN_BOOT: 1,
11
- TARGET_BT: 2,
12
- TARGET_SE1: 3,
13
- TARGET_SE2: 4,
14
- TARGET_SE3: 5,
15
- TARGET_SE4: 6,
16
- TARGET_RESOURCE: 10,
5
+ FW_MGMT_TARGET_CRATE: 1,
6
+ FW_MGMT_TARGET_ROMLOADER: 2,
7
+ FW_MGMT_TARGET_BOOTLOADER: 3,
8
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
9
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
10
+ FW_MGMT_TARGET_COPROCESSOR: 6,
11
+ FW_MGMT_TARGET_SE01: 7,
12
+ FW_MGMT_TARGET_SE02: 8,
13
+ FW_MGMT_TARGET_SE03: 9,
14
+ FW_MGMT_TARGET_SE04: 10,
17
15
  } as const;
18
16
 
19
17
  export type ProtocolV2FirmwareTargetType =
20
18
  (typeof ProtocolV2FirmwareTargetType)[keyof typeof ProtocolV2FirmwareTargetType];
21
-
22
- /**
23
- * Map Protocol V2 firmware file name to DevFirmwareUpdate target_id.
24
- */
25
- export function protocolV2FileNameToTargetId(fileName: string): ProtocolV2FirmwareTargetType {
26
- const normalized = fileName.toLowerCase();
27
- if (normalized.includes('bootloader') || normalized.includes('update_rom')) {
28
- return ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT;
29
- }
30
- if (
31
- normalized.includes('coprocessor') ||
32
- normalized.includes('ble') ||
33
- normalized.includes('bluetooth') ||
34
- normalized.includes('bt')
35
- ) {
36
- return ProtocolV2FirmwareTargetType.TARGET_BT;
37
- }
38
- if (normalized.includes('se4')) return ProtocolV2FirmwareTargetType.TARGET_SE4;
39
- if (normalized.includes('se3')) return ProtocolV2FirmwareTargetType.TARGET_SE3;
40
- if (normalized.includes('se2')) return ProtocolV2FirmwareTargetType.TARGET_SE2;
41
- if (normalized.includes('se')) return ProtocolV2FirmwareTargetType.TARGET_SE1;
42
- return ProtocolV2FirmwareTargetType.TARGET_MAIN_APP;
43
- }
@@ -58,42 +58,32 @@ export interface FirmwareUpdateV3Params {
58
58
  }
59
59
 
60
60
  /**
61
- * firmwareUpdateV4(Protocol V2)按 DevFirmwareTargetType 拆分的目标二进制。
62
- * 每个字段对应一个固件升级 target,可单独更新,也可任意组合一次更新。
61
+ * firmwareUpdateV4(Protocol V2)按 DeviceFirmwareTargetType 拆分的目标二进制。
62
+ * romloader 外,每个字段对应一个 bootloader 可接受的固件升级 target
63
63
  */
64
64
  export interface FirmwareUpdateV4Params {
65
65
  platform: IPlatform;
66
66
  chunkSize?: number;
67
67
  firmwareType?: EFirmwareType;
68
68
 
69
- /** TARGET_MAIN_BOOT = 1 */
69
+ /** FW_MGMT_TARGET_ROMLOADER = 2;当前 Pro2 bootloader 不接受通过 firmwareUpdateV4 安装 */
70
70
  romloaderBinary?: ArrayBuffer;
71
- /** TARGET_MAIN_BOOT = 1 */
71
+ /** FW_MGMT_TARGET_BOOTLOADER = 3 */
72
72
  bootloaderBinary?: ArrayBuffer;
73
- /** TARGET_MAIN_APP = 0 */
73
+ /** FW_MGMT_TARGET_APPLICATION_P1 = 4 */
74
74
  applicationP1Binary?: ArrayBuffer;
75
- /** TARGET_MAIN_APP = 0 */
75
+ /** FW_MGMT_TARGET_APPLICATION_P2 = 5 */
76
76
  applicationP2Binary?: ArrayBuffer;
77
- /** TARGET_BT = 2 */
77
+ /** FW_MGMT_TARGET_COPROCESSOR = 6 */
78
78
  coprocessorBinary?: ArrayBuffer;
79
- /** TARGET_SE1-4 = 3-6 */
79
+ /** FW_MGMT_TARGET_SE01-04 = 7-10 */
80
80
  se01Binary?: ArrayBuffer;
81
81
  se02Binary?: ArrayBuffer;
82
82
  se03Binary?: ArrayBuffer;
83
83
  se04Binary?: ArrayBuffer;
84
- /** TARGET_RESOURCE = 10(zip 包,解压后逐文件上传) */
85
- resourceBinary?: ArrayBuffer;
84
+ /** 资源包通过 FW_MGMT_TARGET_CRATE = 1 安装;每个元素是一个独立 CRATE */
85
+ resourceBinaries?: ArrayBuffer[];
86
86
  forcedUpdateRes?: boolean;
87
-
88
- /** 按 release 配置自动下载 */
89
- firmwareVersion?: number[];
90
- bleVersion?: number[];
91
- bootloaderVersion?: number[];
92
-
93
- /** legacy 别名:等价 applicationP1Binary */
94
- firmwareBinary?: ArrayBuffer;
95
- /** legacy 别名:等价 coprocessorBinary */
96
- bleBinary?: ArrayBuffer;
97
87
  }
98
88
 
99
89
  export declare function firmwareUpdateV3(
@@ -24,6 +24,8 @@ export type DeviceInfoStatus = {
24
24
  bootloaderMode: boolean | null;
25
25
  unlocked: boolean | null;
26
26
  passphraseProtection: boolean | null;
27
+ attachToPinEnabled?: boolean | null;
28
+ unlockedAttachPin?: boolean | null;
27
29
  backupRequired: boolean | null;
28
30
  noBackup: boolean | null;
29
31
  language: string | null;
@@ -1,10 +1,10 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
 
3
3
  export type GetPassphraseStatePayload = {
4
- passphrase_state?: string;
5
- session_id?: string;
6
- unlocked_attach_pin?: boolean;
7
- passphrase_protection?: boolean | null;
4
+ passphraseState?: string;
5
+ sessionId?: string;
6
+ unlockedAttachPin?: boolean;
7
+ passphraseProtection?: boolean | null;
8
8
  };
9
9
 
10
10
  export type GetPassphraseStateParams = CommonParams & {
@@ -1,18 +1,13 @@
1
1
  import type {
2
2
  deviceFirmwareUpdate,
3
- deviceGetDeviceInfo,
3
+ deviceFactoryInfoGet,
4
+ deviceFactoryInfoSet,
5
+ deviceInfoGet,
4
6
  deviceGetFirmwareUpdateStatus,
5
- deviceGetOnboardingStatus,
6
7
  deviceReboot,
7
- devFirmwareUpdate,
8
- devGetDeviceInfo,
9
- devGetFirmwareUpdateStatus,
10
- devReboot,
11
8
  dirList,
12
9
  dirMake,
13
10
  dirRemove,
14
- factoryDeviceInfoSettings,
15
- factoryGetDeviceInfo,
16
11
  fileDelete,
17
12
  fileRead,
18
13
  fileWrite,
@@ -23,12 +18,12 @@ import type {
23
18
  filesystemFileDelete,
24
19
  filesystemFileRead,
25
20
  filesystemFileWrite,
26
- filesystemFixPermission,
21
+ filesystemPermissionFix,
27
22
  filesystemFormat,
28
23
  filesystemPathInfoQuery,
29
- getProtoVersion,
30
24
  pathInfo,
31
25
  ping,
26
+ protocolInfoRequest,
32
27
  } from './protocolV2';
33
28
  import type { off, on, removeAllListeners } from './event';
34
29
  import type { uiResponse } from './uiResponse';
@@ -255,20 +250,15 @@ export type CoreApi = {
255
250
  /**
256
251
  * File system & device control API (Protocol V2 only)
257
252
  */
258
- getProtoVersion: typeof getProtoVersion;
253
+ protocolInfoRequest: typeof protocolInfoRequest;
259
254
  ping: typeof ping;
260
255
  deviceReboot: typeof deviceReboot;
261
- deviceGetDeviceInfo: typeof deviceGetDeviceInfo;
262
- deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
256
+ deviceInfoGet: typeof deviceInfoGet;
263
257
  deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
264
258
  deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
265
- devReboot: typeof devReboot;
266
- devGetDeviceInfo: typeof devGetDeviceInfo;
267
- devFirmwareUpdate: typeof devFirmwareUpdate;
268
- devGetFirmwareUpdateStatus: typeof devGetFirmwareUpdateStatus;
269
- factoryDeviceInfoSettings: typeof factoryDeviceInfoSettings;
270
- factoryGetDeviceInfo: typeof factoryGetDeviceInfo;
271
- filesystemFixPermission: typeof filesystemFixPermission;
259
+ deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
260
+ deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
261
+ filesystemPermissionFix: typeof filesystemPermissionFix;
272
262
  fileRead: typeof fileRead;
273
263
  fileWrite: typeof fileWrite;
274
264
  fileDelete: typeof fileDelete;
@@ -1,33 +1,31 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type {
3
3
  DeviceFirmwareUpdateStatus,
4
- DevFirmwareUpdateStatus,
5
- FactoryDeviceInfo,
6
- OnboardingStatus,
7
- ProtoVersion,
4
+ DeviceFactoryInfo,
5
+ ProtocolInfo,
8
6
  ProtocolV2DeviceInfo,
9
7
  Success,
10
8
  } from '@onekeyfe/hd-transport';
11
9
  import type {
12
10
  DeviceFirmwareUpdateParams,
13
11
  DeviceRebootParams,
14
- FactoryDeviceInfoSettingsParams,
12
+ DeviceFactoryInfoSetParams,
15
13
  } from '../../api/protocol-v2/helpers';
16
- import type { DeviceGetDeviceInfoParams } from '../../api/protocol-v2/DeviceGetDeviceInfo';
14
+ import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
17
15
 
18
16
  // 参数类型单源:以 api/protocol-v2 的实现为准(type-only re-export,无运行时依赖)
19
17
  export type {
20
18
  DeviceFirmwareTargetInput,
21
19
  DeviceFirmwareUpdateParams,
22
20
  DeviceRebootParams,
23
- FactoryDeviceInfoSettingsParams,
21
+ DeviceFactoryInfoSetParams,
24
22
  RebootTypeInput,
25
23
  } from '../../api/protocol-v2/helpers';
26
24
  export type {
27
- DeviceGetDeviceInfoParams,
28
- DeviceGetDeviceInfoTargets,
29
- DeviceGetDeviceInfoTypes,
30
- } from '../../api/protocol-v2/DeviceGetDeviceInfo';
25
+ DeviceInfoGetParams,
26
+ DeviceInfoGetTargets,
27
+ DeviceInfoGetTypes,
28
+ } from '../../api/protocol-v2/DeviceInfoGet';
31
29
 
32
30
  // ── Shared response shapes (Protocol V2 file system) ────────────────────
33
31
 
@@ -68,10 +66,10 @@ export type PathInfoResult = {
68
66
 
69
67
  // ── Method signatures ─────────────────────────────────────────────────────
70
68
 
71
- export declare function getProtoVersion(
69
+ export declare function protocolInfoRequest(
72
70
  connectId: string,
73
71
  params?: CommonParams
74
- ): Response<ProtoVersion>;
72
+ ): Response<ProtocolInfo>;
75
73
 
76
74
  export declare function ping(
77
75
  connectId: string,
@@ -83,55 +81,36 @@ export declare function deviceReboot(
83
81
  params: CommonParams & DeviceRebootParams
84
82
  ): Response<Success>;
85
83
 
86
- export declare function deviceGetDeviceInfo(
84
+ export declare function deviceInfoGet(
87
85
  connectId: string,
88
- params?: CommonParams & DeviceGetDeviceInfoParams
86
+ params?: CommonParams & DeviceInfoGetParams
89
87
  ): Response<ProtocolV2DeviceInfo>;
90
88
 
91
- export declare function deviceGetOnboardingStatus(
92
- connectId: string,
93
- params?: CommonParams
94
- ): Response<OnboardingStatus>;
95
-
96
89
  export declare function deviceFirmwareUpdate(
97
90
  connectId: string,
98
91
  params: CommonParams & DeviceFirmwareUpdateParams
99
- ): Response<Success | DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
92
+ ): Response<Success | DeviceFirmwareUpdateStatus>;
100
93
 
101
94
  export declare function deviceGetFirmwareUpdateStatus(
102
95
  connectId: string,
103
96
  params?: CommonParams
104
- ): Response<DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
97
+ ): Response<DeviceFirmwareUpdateStatus>;
105
98
 
106
- export declare function devReboot(
99
+ export declare function deviceFactoryInfoSet(
107
100
  connectId: string,
108
- params: CommonParams & DeviceRebootParams
101
+ params: CommonParams & DeviceFactoryInfoSetParams
109
102
  ): Response<Success>;
110
103
 
111
- export declare function devGetDeviceInfo(
112
- connectId: string,
113
- params?: CommonParams & DeviceGetDeviceInfoParams
114
- ): Response<ProtocolV2DeviceInfo>;
115
-
116
- export declare function devFirmwareUpdate(
117
- connectId: string,
118
- params: CommonParams & DeviceFirmwareUpdateParams
119
- ): Response<Success | DevFirmwareUpdateStatus>;
120
-
121
- export declare function devGetFirmwareUpdateStatus(
104
+ export declare function deviceFactoryInfoGet(
122
105
  connectId: string,
123
106
  params?: CommonParams
124
- ): Response<DevFirmwareUpdateStatus>;
107
+ ): Response<DeviceFactoryInfo>;
125
108
 
126
- export declare function factoryDeviceInfoSettings(
109
+ export declare function filesystemPermissionFix(
127
110
  connectId: string,
128
- params: FactoryDeviceInfoSettingsParams
111
+ params?: CommonParams
129
112
  ): Response<Success>;
130
113
 
131
- export declare function factoryGetDeviceInfo(connectId: string): Response<FactoryDeviceInfo>;
132
-
133
- export declare function filesystemFixPermission(connectId: string): Response<Success>;
134
-
135
114
  export declare function fileRead(
136
115
  connectId: string,
137
116
  params: {
@@ -157,6 +157,7 @@ export type Features = {
157
157
  sdProtection: boolean | null;
158
158
  wipeCodeProtection: boolean | null;
159
159
  passphraseAlwaysOnDevice: boolean | null;
160
+ attachToPinEnabled?: boolean | null;
160
161
  safetyChecks: string | null;
161
162
  autoLockDelayMs: number | null;
162
163
  displayRotation: number | null;
@@ -14,6 +14,10 @@ export interface CommonParams {
14
14
  * Timeout time for single polling
15
15
  */
16
16
  timeout?: number;
17
+ /**
18
+ * Protocol V2 初始化阶段 DeviceInfoGet 超时时间
19
+ */
20
+ protocolV2DeviceInfoTimeoutMs?: number;
17
21
  /**
18
22
  * passphrase state
19
23
  */
@@ -40,6 +40,43 @@ export type IVersionArray = [number, number, number];
40
40
 
41
41
  export type ILocale = 'zh-CN' | 'en-US';
42
42
 
43
+ export type IProtocolV2FirmwareComponentTarget =
44
+ | 'ROMLOADER'
45
+ | 'BOOTLOADER'
46
+ | 'APPLICATION_P1'
47
+ | 'APPLICATION_P2'
48
+ | 'COPROCESSOR'
49
+ | 'SE01'
50
+ | 'SE02'
51
+ | 'SE03'
52
+ | 'SE04'
53
+ | 'CRATE';
54
+
55
+ export type IProtocolV2FirmwareComponent = {
56
+ target: IProtocolV2FirmwareComponentTarget;
57
+ url: string;
58
+ fingerprint?: string;
59
+ version?: IVersionArray;
60
+ resourceManifest?: IProtocolV2ResourceManifest;
61
+ };
62
+
63
+ export type IProtocolV2ResourceManifestPackage = {
64
+ name?: string;
65
+ path: string;
66
+ type?: string;
67
+ version?: IVersionArray;
68
+ sha256?: string;
69
+ payloadHash?: string;
70
+ headerHash?: string;
71
+ };
72
+
73
+ export type IProtocolV2ResourceManifest = {
74
+ format?: 'okpkg-crate' | string;
75
+ target?: 'CRATE' | string;
76
+ version?: IVersionArray;
77
+ packages: IProtocolV2ResourceManifestPackage[];
78
+ };
79
+
43
80
  /** STM32 firmware config */
44
81
  export type IFirmwareReleaseInfo = {
45
82
  required: boolean;
@@ -58,6 +95,10 @@ export type IFirmwareReleaseInfo = {
58
95
  bootloaderVersion?: IVersionArray;
59
96
  displayBootloaderVersion?: IVersionArray;
60
97
  bootloaderRelatedFirmwareVersion?: IVersionArray;
98
+ upgradeType?: 'payload-package-set' | string;
99
+ components?: Record<string, IProtocolV2FirmwareComponent>;
100
+ installOrder?: string[];
101
+ resourceManifest?: IProtocolV2ResourceManifest;
61
102
  bootloaderChangelog?: {
62
103
  [k in ILocale]: string;
63
104
  };
@@ -83,43 +124,16 @@ export type IBLEFirmwareReleaseInfo = {
83
124
  };
84
125
  };
85
126
 
86
- type IKnownDevice = Exclude<IDeviceType, 'unknown' | 'pro2'>;
127
+ type IKnownDevice = Exclude<IDeviceType, 'unknown'>;
87
128
 
88
- /**
89
- * Device firmware configuration map
90
- *
91
- * IMPORTANT: This type is used for firmware update logic.
92
- * - DO NOT remove existing firmware fields
93
- * - Only ADD new optional firmware fields for new versions
94
- * - 'firmware' field is required for backward compatibility
95
- * - 'ble' field is required for BLE firmware updates
96
- *
97
- * @example
98
- * // When adding firmware-v8:
99
- * // {
100
- * // firmware: IFirmwareReleaseInfo[];
101
- * // 'firmware-v2'?: IFirmwareReleaseInfo[];
102
- * // 'firmware-v8'?: IFirmwareReleaseInfo[];
103
- * // 'firmware-v8'?: IFirmwareReleaseInfo[]; // New
104
- * // 'firmware-btc-v8'?: IFirmwareReleaseInfo[];
105
- * // 'firmware-btc-v8'?: IFirmwareReleaseInfo[]; // New
106
- * // ble: IBLEFirmwareReleaseInfo[];
107
- * // }
108
- */
109
129
  export type DeviceTypeMap = {
110
130
  [k in IKnownDevice]: {
111
- /** Base firmware field (required for backward compatibility) */
112
131
  firmware: IFirmwareReleaseInfo[];
113
- /** Firmware v2 (Touch/Pro specific) */
132
+ /** Pro2 Protocol V2 payload package set */
133
+ 'firmware-v1'?: IFirmwareReleaseInfo[];
114
134
  'firmware-v2'?: IFirmwareReleaseInfo[];
115
- /** Universal firmware v7 */
116
135
  'firmware-v8'?: IFirmwareReleaseInfo[];
117
- /** Bitcoin-only firmware v7 */
118
136
  'firmware-btc-v8'?: IFirmwareReleaseInfo[];
119
- // Future firmware versions should be added here as optional fields:
120
- // 'firmware-v8'?: IFirmwareReleaseInfo[];
121
- // 'firmware-btc-v8'?: IFirmwareReleaseInfo[];
122
- /** BLE firmware (required) */
123
137
  ble: IBLEFirmwareReleaseInfo[];
124
138
  };
125
139
  };