@onekeyfe/hd-core 1.2.0-alpha.0 → 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 (192) 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 +1930 -765
  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/FirmwareUpdateV2.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  12. package/dist/api/FirmwareUpdateV4.d.ts +26 -5
  13. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  14. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  15. package/dist/api/GetFeatures.d.ts +1 -1
  16. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  17. package/dist/api/GetPassphraseState.d.ts +4 -4
  18. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  19. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  20. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
  21. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  22. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  23. package/dist/api/firmware/getBinary.d.ts +4 -0
  24. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  25. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  26. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  27. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  28. package/dist/api/index.d.ts +8 -10
  29. package/dist/api/index.d.ts.map +1 -1
  30. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
  31. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  32. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
  33. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  34. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
  35. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  36. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
  37. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  38. package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
  39. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  40. package/dist/api/protocol-v2/DeviceSessionGet.d.ts +9 -0
  41. package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
  42. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
  43. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
  44. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  45. package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
  46. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
  48. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/helpers.d.ts +27 -19
  50. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  51. package/dist/api/ton/TonSignData.d.ts +1 -5
  52. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  53. package/dist/api/tron/TronSignMessage.d.ts +0 -1
  54. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  55. package/dist/api/tron/TronSignTransaction.d.ts +0 -1
  56. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  57. package/dist/constants/index.d.ts +2 -1
  58. package/dist/constants/index.d.ts.map +1 -1
  59. package/dist/core/index.d.ts.map +1 -1
  60. package/dist/data-manager/DataManager.d.ts +1 -1
  61. package/dist/data-manager/DataManager.d.ts.map +1 -1
  62. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  63. package/dist/device/Device.d.ts +17 -18
  64. package/dist/device/Device.d.ts.map +1 -1
  65. package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
  66. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
  67. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  68. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  69. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
  70. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  71. package/dist/deviceProfile/index.d.ts +1 -1
  72. package/dist/deviceProfile/index.d.ts.map +1 -1
  73. package/dist/index.d.ts +657 -539
  74. package/dist/index.js +2579 -2161
  75. package/dist/inject.d.ts.map +1 -1
  76. package/dist/protocols/protocol-v2/features.d.ts +12 -14
  77. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  78. package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
  79. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  80. package/dist/protocols/protocol-v2/index.d.ts +1 -0
  81. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  82. package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
  83. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
  84. package/dist/types/api/firmwareUpdate.d.ts +4 -6
  85. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  86. package/dist/types/api/getDeviceInfo.d.ts +4 -2
  87. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  88. package/dist/types/api/getPassphraseState.d.ts +4 -4
  89. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  90. package/dist/types/api/index.d.ts +11 -11
  91. package/dist/types/api/index.d.ts.map +1 -1
  92. package/dist/types/api/protocolV2.d.ts +16 -17
  93. package/dist/types/api/protocolV2.d.ts.map +1 -1
  94. package/dist/types/api/sessionCache.d.ts +10 -0
  95. package/dist/types/api/sessionCache.d.ts.map +1 -0
  96. package/dist/types/device.d.ts +88 -8
  97. package/dist/types/device.d.ts.map +1 -1
  98. package/dist/types/params.d.ts +1 -0
  99. package/dist/types/params.d.ts.map +1 -1
  100. package/dist/types/settings.d.ts +21 -1
  101. package/dist/types/settings.d.ts.map +1 -1
  102. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  103. package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
  104. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  105. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  106. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  107. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  108. package/dist/utils/patch.d.ts +1 -1
  109. package/dist/utils/patch.d.ts.map +1 -1
  110. package/package.json +4 -4
  111. package/src/api/ClearSessionCache.ts +28 -0
  112. package/src/api/FileRead.ts +16 -3
  113. package/src/api/FileWrite.ts +14 -1
  114. package/src/api/FirmwareUpdateV2.ts +9 -2
  115. package/src/api/FirmwareUpdateV3.ts +2 -1
  116. package/src/api/FirmwareUpdateV4.ts +1089 -285
  117. package/src/api/GetDeviceInfo.ts +6 -13
  118. package/src/api/GetOnekeyFeatures.ts +3 -14
  119. package/src/api/GetPassphraseState.ts +7 -4
  120. package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
  121. package/src/api/device/DeviceRebootToBootloader.ts +4 -4
  122. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
  123. package/src/api/firmware/bootloaderHelper.ts +3 -2
  124. package/src/api/firmware/getBinary.ts +1 -1
  125. package/src/api/firmware/progressThrottle.ts +44 -0
  126. package/src/api/firmware/releaseHelper.ts +3 -3
  127. package/src/api/firmware/uploadFirmware.ts +5 -2
  128. package/src/api/index.ts +8 -10
  129. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
  130. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
  131. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
  132. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
  133. package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
  134. package/src/api/protocol-v2/DeviceReboot.ts +2 -2
  135. package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
  136. package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
  137. package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
  138. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
  139. package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
  140. package/src/api/protocol-v2/helpers.ts +58 -59
  141. package/src/api/ton/TonSignData.ts +1 -5
  142. package/src/api/tron/TronSignMessage.ts +0 -1
  143. package/src/api/tron/TronSignTransaction.ts +0 -1
  144. package/src/constants/index.ts +10 -1
  145. package/src/core/index.ts +22 -10
  146. package/src/data/messages/messages-protocol-v2.json +992 -1420
  147. package/src/data/messages/messages.json +8 -0
  148. package/src/data-manager/DataManager.ts +11 -4
  149. package/src/data-manager/connectSettings.ts +4 -0
  150. package/src/device/Device.ts +158 -294
  151. package/src/device/DevicePool.ts +9 -9
  152. package/src/device/DeviceWalletSessionStore.ts +78 -0
  153. package/src/deviceProfile/buildDeviceFeatures.ts +365 -0
  154. package/src/deviceProfile/buildDeviceProfile.ts +165 -200
  155. package/src/deviceProfile/index.ts +4 -1
  156. package/src/inject.ts +13 -16
  157. package/src/protocols/protocol-v2/features.ts +28 -67
  158. package/src/protocols/protocol-v2/firmware.ts +12 -36
  159. package/src/protocols/protocol-v2/index.ts +1 -0
  160. package/src/protocols/protocol-v2/walletSession.ts +83 -0
  161. package/src/types/api/firmwareUpdate.ts +16 -20
  162. package/src/types/api/getDeviceInfo.ts +4 -2
  163. package/src/types/api/getPassphraseState.ts +4 -4
  164. package/src/types/api/index.ts +17 -20
  165. package/src/types/api/protocolV2.ts +35 -40
  166. package/src/types/api/sessionCache.ts +14 -0
  167. package/src/types/device.ts +98 -34
  168. package/src/types/params.ts +4 -0
  169. package/src/types/settings.ts +42 -30
  170. package/src/utils/capabilitieUtils.ts +1 -2
  171. package/src/utils/deviceFeaturesUtils.ts +54 -29
  172. package/src/utils/deviceInfoUtils.ts +11 -29
  173. package/src/utils/deviceVersionUtils.ts +7 -25
  174. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  175. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  176. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  177. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  178. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
  179. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
  180. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  181. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  182. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  183. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  184. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  185. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  186. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  187. package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
  188. package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
  189. package/src/api/protocol-v2/DevReboot.ts +0 -24
  190. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
  191. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
  192. package/src/deviceProfile/legacyFeaturesView.ts +0 -123
@@ -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 状态映射实现,
30
- * deviceProfile legacy Features 兼容视图都从这里取。
29
+ * DeviceSEInfo.state → 可读标签。SDK 内唯一的 SE 状态映射实现,
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')。legacy Features 兼容视图的
48
- * onekey_se_type 字段从这里取。
47
+ * DeviceSEInfo.type → 可读标签(如 'THD89')。DeviceProfile / Features
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,15 +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 等身份字段——applyProfileUpdate 对顶层字段是整体
71
- * 覆盖语义,缺少 hw/bt 会把已有 profile 的身份字段清空。不含 fw/SE targets,
72
- * 单帧请求开销很小。
72
+ * status 提供 init_states / passphrase_enabled 等会在设备端变化的字段;
73
+ * hw / coprocessor 提供 serialNo / bleName 等身份字段;不含 fw/SE targets,单帧请求开销很小。
73
74
  */
74
75
  export const PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST = {
75
76
  targets: {
76
77
  hw: true,
77
- bt: true,
78
+ coprocessor: true,
78
79
  status: true,
79
80
  },
80
81
  types: {
@@ -87,7 +88,7 @@ export const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
87
88
  targets: {
88
89
  hw: true,
89
90
  fw: true,
90
- bt: true,
91
+ coprocessor: true,
91
92
  se1: true,
92
93
  se2: true,
93
94
  se3: true,
@@ -104,7 +105,7 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
104
105
  targets: {
105
106
  hw: true,
106
107
  fw: true,
107
- bt: true,
108
+ coprocessor: true,
108
109
  se1: true,
109
110
  se2: true,
110
111
  se3: true,
@@ -122,43 +123,6 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
122
123
  export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
123
124
  export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
124
125
 
125
- /**
126
- * 临时开关(默认开启):当前 Pro2 测试固件 / 早期工程板尚未实现 DevGetDeviceInfo,
127
- * 真实调用只会超时失败。开启时跳过 wire 调用,直接返回 mock DeviceInfo;
128
- * profile 的身份字段(serialNo/deviceId)由 buildProfileFromProtocolV2 的
129
- * fallbackSerialNo(transport path)兜底。
130
- *
131
- * 固件实现 DevGetDeviceInfo 后:把默认值改回 false(或直接删除开关与 mock)。
132
- * 注意:开启期间 FirmwareUpdateV4 的“升级完成版本比对”拿到的也是 mock 版本,
133
- * 不能作为升级成功的依据。
134
- */
135
- let protocolV2DeviceInfoMockEnabled = true;
136
-
137
- export const setProtocolV2DeviceInfoMock = (enabled: boolean) => {
138
- protocolV2DeviceInfoMockEnabled = enabled;
139
- };
140
-
141
- export const isProtocolV2DeviceInfoMockEnabled = () => protocolV2DeviceInfoMockEnabled;
142
-
143
- /** 每次调用返回新对象,避免调用方原地修改互相污染。 */
144
- export const buildMockProtocolV2DeviceInfo = (): ProtocolV2DeviceInfo => ({
145
- protocol_version: 2,
146
- hw: {
147
- // 留空:profile 身份走 fallbackSerialNo(transport path)
148
- serial_no: '',
149
- },
150
- fw: {
151
- app: { version: '0.1.0' },
152
- },
153
- bt: {},
154
- status: {
155
- init_states: true,
156
- language: 'en_US',
157
- passphrase_protection: false,
158
- bt_enable: true,
159
- },
160
- });
161
-
162
126
  export async function requestProtocolV2DeviceInfo({
163
127
  commands,
164
128
  timeoutMs = PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS,
@@ -166,15 +130,12 @@ export async function requestProtocolV2DeviceInfo({
166
130
  }: {
167
131
  commands: DeviceCommands;
168
132
  timeoutMs?: number;
169
- request?: DeviceGetDeviceInfo;
133
+ request?: DeviceInfoGet;
170
134
  }): Promise<ProtocolV2DeviceInfo> {
171
- if (protocolV2DeviceInfoMockEnabled) {
172
- return buildMockProtocolV2DeviceInfo();
173
- }
174
- const { message } = await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', request, {
135
+ const { message } = await commands.typedCall('DeviceInfoGet', 'DeviceInfo', request, {
175
136
  timeoutMs,
176
137
  });
177
138
  // 'DeviceInfo' 在生成类型里是 V1 DeviceInfo | ProtocolV2DeviceInfo 的合并;
178
- // DevGetDeviceInfo 是 V2-only 消息,这里收窄到 V2 形态。
139
+ // DeviceInfoGet 是 V2-only 消息,这里收窄到 V2 形态。
179
140
  return message as ProtocolV2DeviceInfo;
180
141
  }
@@ -1,43 +1,19 @@
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_INVALID: 0,
6
+ FW_MGMT_TARGET_CRATE: 1,
7
+ FW_MGMT_TARGET_ROMLOADER: 2,
8
+ FW_MGMT_TARGET_BOOTLOADER: 3,
9
+ FW_MGMT_TARGET_APPLICATION_P1: 4,
10
+ FW_MGMT_TARGET_APPLICATION_P2: 5,
11
+ FW_MGMT_TARGET_COPROCESSOR: 6,
12
+ FW_MGMT_TARGET_SE01: 7,
13
+ FW_MGMT_TARGET_SE02: 8,
14
+ FW_MGMT_TARGET_SE03: 9,
15
+ FW_MGMT_TARGET_SE04: 10,
17
16
  } as const;
18
17
 
19
18
  export type ProtocolV2FirmwareTargetType =
20
19
  (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
- }
@@ -14,3 +14,4 @@ export type {
14
14
  ProtocolV2SeStateLabel,
15
15
  } from './features';
16
16
  export * from './firmware';
17
+ export * from './walletSession';
@@ -0,0 +1,83 @@
1
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+
3
+ import type { Device } from '../../device/Device';
4
+
5
+ const getErrorText = (error: unknown) => {
6
+ if (error instanceof Error) return `${error.name} ${error.message}`;
7
+ if (typeof error === 'string') return error;
8
+ if (error && typeof error === 'object') {
9
+ const record = error as Record<string, unknown>;
10
+ return [record.code, record.errorCode, record.message, record.reason]
11
+ .filter(value => value !== undefined && value !== null)
12
+ .join(' ');
13
+ }
14
+ return String(error ?? '');
15
+ };
16
+
17
+ export const isProtocolV2InvalidSessionError = (error: unknown) =>
18
+ getErrorText(error).toLowerCase().includes('failure_invalidsession');
19
+
20
+ export async function requestProtocolV2DeviceStatus(device: Device) {
21
+ const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
22
+ return message;
23
+ }
24
+
25
+ export async function refreshProtocolV2DeviceStatus(device: Device) {
26
+ const status = await requestProtocolV2DeviceStatus(device);
27
+ return device.updateProtocolV2Status(status);
28
+ }
29
+
30
+ export async function getProtocolV2WalletSession(
31
+ device: Device,
32
+ options?: { initSession?: boolean; expectedPassphraseState?: string }
33
+ ) {
34
+ if (device.features?.unlocked === false) {
35
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device is locked');
36
+ }
37
+
38
+ if (options?.initSession) {
39
+ device.clearInternalState();
40
+ }
41
+
42
+ const cachedSessionId =
43
+ typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
44
+
45
+ try {
46
+ const { message } = await device.commands.typedCall(
47
+ 'DeviceSessionGet',
48
+ 'DeviceSession',
49
+ cachedSessionId ? { session_id: cachedSessionId } : {}
50
+ );
51
+
52
+ if (
53
+ options?.expectedPassphraseState &&
54
+ options.expectedPassphraseState !== message.btc_test_address
55
+ ) {
56
+ device.clearInternalState();
57
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
58
+ }
59
+
60
+ if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
61
+ await refreshProtocolV2DeviceStatus(device);
62
+ }
63
+
64
+ device.updateInternalState(
65
+ (device.getCurrentPassphraseProtection() ?? false) || Boolean(message.btc_test_address),
66
+ message.btc_test_address,
67
+ device.getCurrentDeviceId(),
68
+ message.session_id,
69
+ options?.initSession ? null : device.features?.sessionId
70
+ );
71
+
72
+ return {
73
+ passphraseState: message.btc_test_address,
74
+ newSession: message.session_id,
75
+ unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
76
+ };
77
+ } catch (error) {
78
+ if (isProtocolV2InvalidSessionError(error)) {
79
+ device.clearInternalState();
80
+ }
81
+ throw error;
82
+ }
83
+ }
@@ -58,42 +58,38 @@ 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;
86
84
  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;
85
+ /**
86
+ * RESC bundle okpkg 列表,通过 FilesystemFileWrite 直写到 devicePath(vol0:/bundles/...)。
87
+ * 手动传入模式:SDK 直接 FileWrite 安装,不做版本比对。
88
+ */
89
+ resourceBundleFiles?: Array<{
90
+ binary: ArrayBuffer;
91
+ devicePath: string;
92
+ }>;
97
93
  }
98
94
 
99
95
  export declare function firmwareUpdateV3(
@@ -6,7 +6,7 @@ import type { ProtocolType, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport'
6
6
  // 协议类型单源:从 hd-transport 的 ProtocolType 派生,只额外允许 'unknown'。
7
7
  export type DeviceInfoProtocol = ProtocolType | 'unknown';
8
8
 
9
- export type DeviceInfoSource = 'features' | 'onekeyFeatures' | 'deviceInfo';
9
+ export type DeviceInfoSource = 'features' | 'protocolV1OneKeyFeatures' | 'deviceInfo';
10
10
 
11
11
  export type DeviceInfoScope = 'basic' | 'versions' | 'verify' | 'full';
12
12
 
@@ -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;
@@ -74,7 +76,7 @@ export type DeviceProfileVerify = {
74
76
 
75
77
  export type DeviceProfileRaw = {
76
78
  features?: Features;
77
- onekeyFeatures?: OnekeyFeatures;
79
+ protocolV1OneKeyFeatures?: OnekeyFeatures;
78
80
  protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
79
81
  };
80
82
 
@@ -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,15 @@
1
1
  import type {
2
+ deviceFactoryInfoGet,
3
+ deviceFactoryInfoSet,
2
4
  deviceFirmwareUpdate,
3
- deviceGetDeviceInfo,
4
5
  deviceGetFirmwareUpdateStatus,
5
- deviceGetOnboardingStatus,
6
+ deviceInfoGet,
6
7
  deviceReboot,
7
- devFirmwareUpdate,
8
- devGetDeviceInfo,
9
- devGetFirmwareUpdateStatus,
10
- devReboot,
8
+ deviceSessionGet,
9
+ deviceStatusGet,
11
10
  dirList,
12
11
  dirMake,
13
12
  dirRemove,
14
- factoryDeviceInfoSettings,
15
- factoryGetDeviceInfo,
16
13
  fileDelete,
17
14
  fileRead,
18
15
  fileWrite,
@@ -23,12 +20,12 @@ import type {
23
20
  filesystemFileDelete,
24
21
  filesystemFileRead,
25
22
  filesystemFileWrite,
26
- filesystemFixPermission,
27
23
  filesystemFormat,
28
24
  filesystemPathInfoQuery,
29
- getProtoVersion,
25
+ filesystemPermissionFix,
30
26
  pathInfo,
31
27
  ping,
28
+ protocolInfoRequest,
32
29
  } from './protocolV2';
33
30
  import type { off, on, removeAllListeners } from './event';
34
31
  import type { uiResponse } from './uiResponse';
@@ -36,6 +33,7 @@ import type { init, updateSettings } from './init';
36
33
  import type { testInitializeDeviceDuration } from './testInitializeDeviceDuration';
37
34
  import type { preInitialize } from './preInitialize';
38
35
  import type { getLogs } from './getLogs';
36
+ import type { clearSessionCache } from './sessionCache';
39
37
  import type { checkBridgeStatus } from './checkBridgeStatus';
40
38
  import type { checkBridgeRelease } from './checkBridgeRelease';
41
39
  import type { checkBootloaderRelease } from './checkBootloaderRelease';
@@ -182,6 +180,7 @@ export type {
182
180
  DeviceProfileVersions,
183
181
  } from './getDeviceInfo';
184
182
  export type { GetPassphraseStateParams, GetPassphraseStatePayload } from './getPassphraseState';
183
+ export type { ClearSessionCacheParams, ClearSessionCachePayload } from './sessionCache';
185
184
 
186
185
  export type CoreApi = {
187
186
  /**
@@ -199,6 +198,7 @@ export type CoreApi = {
199
198
  updateSettings: typeof updateSettings;
200
199
  switchTransport: (env: ConnectSettings['env']) => Promise<{ success: boolean }>;
201
200
  getLogs: typeof getLogs;
201
+ clearSessionCache: typeof clearSessionCache;
202
202
 
203
203
  /**
204
204
  * Test function
@@ -255,20 +255,17 @@ export type CoreApi = {
255
255
  /**
256
256
  * File system & device control API (Protocol V2 only)
257
257
  */
258
- getProtoVersion: typeof getProtoVersion;
258
+ protocolInfoRequest: typeof protocolInfoRequest;
259
259
  ping: typeof ping;
260
260
  deviceReboot: typeof deviceReboot;
261
- deviceGetDeviceInfo: typeof deviceGetDeviceInfo;
262
- deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
261
+ deviceInfoGet: typeof deviceInfoGet;
262
+ deviceStatusGet: typeof deviceStatusGet;
263
+ deviceSessionGet: typeof deviceSessionGet;
263
264
  deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
264
265
  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;
266
+ deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
267
+ deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
268
+ filesystemPermissionFix: typeof filesystemPermissionFix;
272
269
  fileRead: typeof fileRead;
273
270
  fileWrite: typeof fileWrite;
274
271
  fileDelete: typeof fileDelete;
@@ -1,33 +1,37 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type {
3
+ DeviceFactoryInfo,
3
4
  DeviceFirmwareUpdateStatus,
4
- DevFirmwareUpdateStatus,
5
- FactoryDeviceInfo,
6
- OnboardingStatus,
7
- ProtoVersion,
5
+ DeviceSession,
6
+ DeviceStatus,
7
+ ProtocolInfo,
8
8
  ProtocolV2DeviceInfo,
9
9
  Success,
10
10
  } from '@onekeyfe/hd-transport';
11
11
  import type {
12
+ DeviceFactoryInfoSetParams,
12
13
  DeviceFirmwareUpdateParams,
14
+ DeviceFirmwareUpdateStatusGetParams,
13
15
  DeviceRebootParams,
14
- FactoryDeviceInfoSettingsParams,
15
16
  } from '../../api/protocol-v2/helpers';
16
- import type { DeviceGetDeviceInfoParams } from '../../api/protocol-v2/DeviceGetDeviceInfo';
17
+ import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
18
+ import type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
17
19
 
18
20
  // 参数类型单源:以 api/protocol-v2 的实现为准(type-only re-export,无运行时依赖)
19
21
  export type {
20
22
  DeviceFirmwareTargetInput,
21
23
  DeviceFirmwareUpdateParams,
24
+ DeviceFirmwareUpdateStatusGetParams,
22
25
  DeviceRebootParams,
23
- FactoryDeviceInfoSettingsParams,
26
+ DeviceFactoryInfoSetParams,
24
27
  RebootTypeInput,
25
28
  } from '../../api/protocol-v2/helpers';
26
29
  export type {
27
- DeviceGetDeviceInfoParams,
28
- DeviceGetDeviceInfoTargets,
29
- DeviceGetDeviceInfoTypes,
30
- } from '../../api/protocol-v2/DeviceGetDeviceInfo';
30
+ DeviceInfoGetParams,
31
+ DeviceInfoGetTargets,
32
+ DeviceInfoGetTypes,
33
+ } from '../../api/protocol-v2/DeviceInfoGet';
34
+ export type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
31
35
 
32
36
  // ── Shared response shapes (Protocol V2 file system) ────────────────────
33
37
 
@@ -68,10 +72,10 @@ export type PathInfoResult = {
68
72
 
69
73
  // ── Method signatures ─────────────────────────────────────────────────────
70
74
 
71
- export declare function getProtoVersion(
75
+ export declare function protocolInfoRequest(
72
76
  connectId: string,
73
77
  params?: CommonParams
74
- ): Response<ProtoVersion>;
78
+ ): Response<ProtocolInfo>;
75
79
 
76
80
  export declare function ping(
77
81
  connectId: string,
@@ -83,55 +87,46 @@ export declare function deviceReboot(
83
87
  params: CommonParams & DeviceRebootParams
84
88
  ): Response<Success>;
85
89
 
86
- export declare function deviceGetDeviceInfo(
90
+ export declare function deviceInfoGet(
87
91
  connectId: string,
88
- params?: CommonParams & DeviceGetDeviceInfoParams
92
+ params?: CommonParams & DeviceInfoGetParams
89
93
  ): Response<ProtocolV2DeviceInfo>;
90
94
 
91
- export declare function deviceGetOnboardingStatus(
95
+ export declare function deviceStatusGet(
92
96
  connectId: string,
93
97
  params?: CommonParams
94
- ): Response<OnboardingStatus>;
98
+ ): Response<DeviceStatus>;
99
+
100
+ export declare function deviceSessionGet(
101
+ connectId: string,
102
+ params?: CommonParams & DeviceSessionGetParams
103
+ ): Response<DeviceSession>;
95
104
 
96
105
  export declare function deviceFirmwareUpdate(
97
106
  connectId: string,
98
107
  params: CommonParams & DeviceFirmwareUpdateParams
99
- ): Response<Success | DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
108
+ ): Response<Success | DeviceFirmwareUpdateStatus>;
100
109
 
101
110
  export declare function deviceGetFirmwareUpdateStatus(
102
111
  connectId: string,
103
- params?: CommonParams
104
- ): Response<DevFirmwareUpdateStatus | DeviceFirmwareUpdateStatus>;
112
+ params?: CommonParams & DeviceFirmwareUpdateStatusGetParams
113
+ ): Response<DeviceFirmwareUpdateStatus>;
105
114
 
106
- export declare function devReboot(
115
+ export declare function deviceFactoryInfoSet(
107
116
  connectId: string,
108
- params: CommonParams & DeviceRebootParams
117
+ params: CommonParams & DeviceFactoryInfoSetParams
109
118
  ): Response<Success>;
110
119
 
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(
120
+ export declare function deviceFactoryInfoGet(
122
121
  connectId: string,
123
122
  params?: CommonParams
124
- ): Response<DevFirmwareUpdateStatus>;
123
+ ): Response<DeviceFactoryInfo>;
125
124
 
126
- export declare function factoryDeviceInfoSettings(
125
+ export declare function filesystemPermissionFix(
127
126
  connectId: string,
128
- params: FactoryDeviceInfoSettingsParams
127
+ params?: CommonParams
129
128
  ): Response<Success>;
130
129
 
131
- export declare function factoryGetDeviceInfo(connectId: string): Response<FactoryDeviceInfo>;
132
-
133
- export declare function filesystemFixPermission(connectId: string): Response<Success>;
134
-
135
130
  export declare function fileRead(
136
131
  connectId: string,
137
132
  params: {
@@ -0,0 +1,14 @@
1
+ import type { Response } from '../params';
2
+
3
+ export type ClearSessionCacheParams = {
4
+ deviceId?: string;
5
+ passphraseState?: string;
6
+ };
7
+
8
+ export type ClearSessionCachePayload = {
9
+ cleared: true;
10
+ };
11
+
12
+ export declare function clearSessionCache(
13
+ params?: ClearSessionCacheParams
14
+ ): Response<ClearSessionCachePayload>;