@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,9 +1,8 @@
1
- import { EDeviceType } from '@onekeyfe/hd-shared';
1
+ import { EDeviceType, type EFirmwareType } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import type { IVersionArray } from './settings';
4
4
  import type { PROTO } from '../constants';
5
- import type { OneKeyDeviceCommType } from '@onekeyfe/hd-transport';
6
- import type { DeviceProfile } from './api/getDeviceInfo';
5
+ import type { OneKeyDeviceCommType, ProtocolV2DeviceInfo } from '@onekeyfe/hd-transport';
7
6
 
8
7
  export type DeviceStatus = 'available' | 'occupied' | 'used';
9
8
 
@@ -34,8 +33,7 @@ export type KnownDevice = {
34
33
  name: string;
35
34
  error?: typeof undefined;
36
35
  mode: EOneKeyDeviceMode;
37
- profile?: DeviceProfile;
38
- features?: PROTO.Features;
36
+ features?: Features;
39
37
  sessionId?: string | null;
40
38
  unavailableCapabilities: UnavailableCapabilities;
41
39
  bleFirmwareVersion: IVersionArray | null;
@@ -88,35 +86,101 @@ export type SearchDevice = {
88
86
 
89
87
  export type Device = KnownDevice;
90
88
 
91
- type OnekeyFeatureExtensions = Partial<
92
- Pick<
93
- PROTO.OnekeyFeatures,
94
- | 'onekey_board_build_id'
95
- | 'onekey_se02_hash'
96
- | 'onekey_se03_hash'
97
- | 'onekey_se04_hash'
98
- | 'onekey_se02_build_id'
99
- | 'onekey_se03_build_id'
100
- | 'onekey_se04_build_id'
101
- | 'onekey_se01_boot_version'
102
- | 'onekey_se02_boot_version'
103
- | 'onekey_se03_boot_version'
104
- | 'onekey_se04_boot_version'
105
- | 'onekey_se01_boot_hash'
106
- | 'onekey_se02_boot_hash'
107
- | 'onekey_se03_boot_hash'
108
- | 'onekey_se04_boot_hash'
109
- | 'onekey_se01_boot_build_id'
110
- | 'onekey_se02_boot_build_id'
111
- | 'onekey_se03_boot_build_id'
112
- | 'onekey_se04_boot_build_id'
113
- >
114
- >;
115
-
116
- export type Features = PROTO.Features &
117
- OnekeyFeatureExtensions & {
118
- protocol_version?: number | null;
119
- };
89
+ export type DeviceFeaturesProtocol = 'V1' | 'V2' | 'unknown';
90
+
91
+ export type DeviceFeaturesMode =
92
+ | 'normal'
93
+ | 'bootloader'
94
+ | 'notInitialized'
95
+ | 'backupMode'
96
+ | 'unknown';
97
+
98
+ export type DeviceFeaturesVerify = {
99
+ firmwareBuildId?: string;
100
+ firmwareHash?: string;
101
+ bootloaderBuildId?: string;
102
+ bootloaderHash?: string;
103
+ boardBuildId?: string;
104
+ boardHash?: string;
105
+ bleBuildId?: string;
106
+ bleHash?: string;
107
+ se01BuildId?: string;
108
+ se01Hash?: string;
109
+ se02BuildId?: string;
110
+ se02Hash?: string;
111
+ se03BuildId?: string;
112
+ se03Hash?: string;
113
+ se04BuildId?: string;
114
+ se04Hash?: string;
115
+ se01BootBuildId?: string;
116
+ se01BootHash?: string;
117
+ se02BootBuildId?: string;
118
+ se02BootHash?: string;
119
+ se03BootBuildId?: string;
120
+ se03BootHash?: string;
121
+ se04BootBuildId?: string;
122
+ se04BootHash?: string;
123
+ };
124
+
125
+ export type DeviceFeaturesRaw = {
126
+ protocolV1Features?: PROTO.Features;
127
+ protocolV1OneKeyFeatures?: OnekeyFeatures;
128
+ protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
129
+ };
130
+
131
+ export type Features = {
132
+ protocol: DeviceFeaturesProtocol;
133
+ protocolVersion?: number | null;
134
+ deviceType: IDeviceType;
135
+ firmwareType: EFirmwareType;
136
+ model: string | null;
137
+ vendor: string | null;
138
+ deviceId: string | null;
139
+ serialNo: string;
140
+ label: string | null;
141
+ bleName: string | null;
142
+ capabilities: Array<number | string>;
143
+ mode: DeviceFeaturesMode;
144
+ initialized: boolean | null;
145
+ bootloaderMode: boolean | null;
146
+ unlocked: boolean | null;
147
+ firmwarePresent: boolean | null;
148
+ passphraseProtection: boolean | null;
149
+ pinProtection: boolean | null;
150
+ backupRequired: boolean | null;
151
+ noBackup: boolean | null;
152
+ unfinishedBackup: boolean | null;
153
+ recoveryMode: boolean | null;
154
+ language: string | null;
155
+ bleEnabled: boolean | null;
156
+ sdCardPresent: boolean | null;
157
+ sdProtection: boolean | null;
158
+ wipeCodeProtection: boolean | null;
159
+ passphraseAlwaysOnDevice: boolean | null;
160
+ attachToPinEnabled?: boolean | null;
161
+ safetyChecks: string | null;
162
+ autoLockDelayMs: number | null;
163
+ displayRotation: number | null;
164
+ experimentalFeatures: boolean | null;
165
+ firmwareVersion: string | null;
166
+ bootloaderVersion: string | null;
167
+ boardVersion: string | null;
168
+ bleVersion: string | null;
169
+ se01Version?: string | null;
170
+ se02Version?: string | null;
171
+ se03Version?: string | null;
172
+ se04Version?: string | null;
173
+ se01BootVersion?: string | null;
174
+ se02BootVersion?: string | null;
175
+ se03BootVersion?: string | null;
176
+ se04BootVersion?: string | null;
177
+ seVersion?: string | null;
178
+ verify?: DeviceFeaturesVerify;
179
+ sessionId: string | null;
180
+ passphraseState?: string;
181
+ unlockedAttachPin?: boolean;
182
+ raw?: DeviceFeaturesRaw;
183
+ };
120
184
 
121
185
  export type OnekeyFeatures = PROTO.OnekeyFeatures;
122
186
 
@@ -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,40 @@ 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
+
54
+ export type IProtocolV2FirmwareComponent = {
55
+ target: IProtocolV2FirmwareComponentTarget;
56
+ url: string;
57
+ fingerprint?: string;
58
+ version?: IVersionArray;
59
+ };
60
+
61
+ /** Pro2 RESC bundle okpkg 描述,用于 FileWrite 直写方式增量同步资源 */
62
+ export type IProtocolV2ResourceBundle = {
63
+ /** bundle 名称,如 images / animation / translations / fonts_roobert */
64
+ name: string;
65
+ /** 下载 URL */
66
+ url: string;
67
+ /** 设备上的目标路径,如 vol0:/bundles/images/images.okpkg */
68
+ devicePath: string;
69
+ /** okpkg container 的 payload_version(用于 FileRead 比对跳过) */
70
+ version?: IVersionArray;
71
+ /** okpkg container 的 payload_hash(SHA3-512,用于 FileRead 比对) */
72
+ payloadHash?: string;
73
+ /** okpkg container 的 header_hash(SHA3-512,用于 FileRead 比对) */
74
+ headerHash?: string;
75
+ };
76
+
43
77
  /** STM32 firmware config */
44
78
  export type IFirmwareReleaseInfo = {
45
79
  required: boolean;
@@ -58,6 +92,11 @@ export type IFirmwareReleaseInfo = {
58
92
  bootloaderVersion?: IVersionArray;
59
93
  displayBootloaderVersion?: IVersionArray;
60
94
  bootloaderRelatedFirmwareVersion?: IVersionArray;
95
+ upgradeType?: 'payload-package-set' | string;
96
+ components?: Record<string, IProtocolV2FirmwareComponent>;
97
+ installOrder?: string[];
98
+ /** Pro2 RESC bundle 列表(FileWrite 直写增量同步模式) */
99
+ resourceBundles?: IProtocolV2ResourceBundle[];
61
100
  bootloaderChangelog?: {
62
101
  [k in ILocale]: string;
63
102
  };
@@ -83,43 +122,16 @@ export type IBLEFirmwareReleaseInfo = {
83
122
  };
84
123
  };
85
124
 
86
- type IKnownDevice = Exclude<IDeviceType, 'unknown' | 'pro2'>;
125
+ type IKnownDevice = Exclude<IDeviceType, 'unknown'>;
87
126
 
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
127
  export type DeviceTypeMap = {
110
128
  [k in IKnownDevice]: {
111
- /** Base firmware field (required for backward compatibility) */
112
129
  firmware: IFirmwareReleaseInfo[];
113
- /** Firmware v2 (Touch/Pro specific) */
130
+ /** Pro2 Protocol V2 payload package set */
131
+ 'firmware-v1'?: IFirmwareReleaseInfo[];
114
132
  'firmware-v2'?: IFirmwareReleaseInfo[];
115
- /** Universal firmware v7 */
116
133
  'firmware-v8'?: IFirmwareReleaseInfo[];
117
- /** Bitcoin-only firmware v7 */
118
134
  '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
135
  ble: IBLEFirmwareReleaseInfo[];
124
136
  };
125
137
  };
@@ -2,8 +2,7 @@ import type { Enum_Capability } from '@onekeyfe/hd-transport';
2
2
  import type { Features } from '../types/device';
3
3
 
4
4
  export const existCapability = (features?: Features, capability?: Enum_Capability) =>
5
- // @ts-expect-error
6
- features?.capabilities?.includes(capability);
5
+ capability !== undefined && features?.capabilities?.includes(capability);
7
6
 
8
7
  export const requireCapability = (features: Features, capability: Enum_Capability) => {
9
8
  if (!existCapability(features, capability)) {
@@ -13,14 +13,11 @@ import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
13
13
  import { getDeviceType } from './deviceInfoUtils';
14
14
  import { getDeviceFirmwareVersion } from './deviceVersionUtils';
15
15
  import { existCapability } from './capabilitieUtils';
16
+ import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
16
17
 
17
18
  import type { Device } from '../device/Device';
18
19
  import type { Features, IDeviceType, SupportFeatureType } from '../types';
19
20
 
20
- // 生成的 GetPassphraseState 已包含 _only_main_pin / allow_create_attach_pin,
21
- // 不再需要手动扩展字段。
22
- type GetPassphraseStateMessage = GetPassphraseState;
23
-
24
21
  export const getSupportProtocolV1MessageSchema = (
25
22
  features: Features | undefined
26
23
  ): { messages: JSON; protocolV1MessageSchema: ProtocolV1MessageSchema } => {
@@ -93,12 +90,32 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
93
90
  expectPassphraseState?: string;
94
91
  onlyMainPin?: boolean;
95
92
  allowCreateAttachPin?: boolean;
93
+ initSession?: boolean;
96
94
  }
97
95
  ) => {
96
+ if (device.isProtocolV2()) {
97
+ if (!device.features) {
98
+ return {
99
+ passphraseState: undefined,
100
+ newSession: undefined,
101
+ unlockedAttachPin: undefined,
102
+ };
103
+ }
104
+
105
+ return getProtocolV2WalletSession(device, {
106
+ initSession: options?.initSession,
107
+ expectedPassphraseState: options?.expectPassphraseState,
108
+ });
109
+ }
110
+
98
111
  const { features } = device;
99
112
  const locked = features?.unlocked === false;
100
113
  const deviceType = device.getCurrentDeviceType();
101
114
 
115
+ if (options?.initSession) {
116
+ device.clearInternalState();
117
+ }
118
+
102
119
  const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(device, {
103
120
  ...options,
104
121
  });
@@ -123,21 +140,22 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
123
140
 
124
141
  // Attach to pin try to fix internal state
125
142
  const deviceId = device.getCurrentDeviceId();
126
- if (deviceId) {
127
- device.updateInternalState(
128
- device.getCurrentPassphraseProtection() ?? false,
129
- passphraseState,
130
- deviceId,
131
- newSession,
132
- device.features?.session_id
133
- );
134
- }
143
+ device.updateInternalState(
144
+ device.getCurrentPassphraseProtection() ?? false,
145
+ passphraseState,
146
+ deviceId,
147
+ newSession,
148
+ options?.initSession ? null : device.features?.sessionId
149
+ );
135
150
 
136
- return { passphraseState, newSession, unlockedAttachPin };
151
+ return {
152
+ passphraseState,
153
+ newSession,
154
+ unlockedAttachPin: unlockedAttachPin ?? device.features?.unlockedAttachPin,
155
+ };
137
156
  };
138
157
 
139
158
  // 仅适用于 Protocol V1 的 Pro:Pro2 走独立版本线,不能套用 4.15.0 门槛
140
- // (Pro2 在 getPassphraseState 中通过 isProtocolV2 直接判定支持)。
141
159
  const supportProSeriesAttachPinPassphrase = (deviceType: IDeviceType, firmwareVersion: string) =>
142
160
  deviceType === EDeviceType.Pro && semver.gte(firmwareVersion, '4.15.0');
143
161
 
@@ -147,6 +165,7 @@ export const getPassphraseState = async (
147
165
  expectPassphraseState?: string;
148
166
  onlyMainPin?: boolean;
149
167
  allowCreateAttachPin?: boolean;
168
+ initSession?: boolean;
150
169
  }
151
170
  ): Promise<{
152
171
  passphraseState: string | undefined;
@@ -155,26 +174,29 @@ export const getPassphraseState = async (
155
174
  }> => {
156
175
  const { features, commands } = device;
157
176
 
158
- // 设备尚未建立任何状态(V1 无 features 且无 profile)时无法判定,保持旧的空返回语义
159
- if (!features && !device.profile)
177
+ // 设备尚未建立任何状态时无法判定,保持旧的空返回语义
178
+ if (!features)
160
179
  return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
161
180
 
162
181
  const firmwareVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
163
182
  const deviceType = device.getCurrentDeviceType();
164
183
 
184
+ if (device.isProtocolV2()) {
185
+ return getProtocolV2WalletSession(device, {
186
+ initSession: options?.initSession,
187
+ expectedPassphraseState: options?.expectPassphraseState,
188
+ });
189
+ }
190
+
165
191
  const supportAttachPinCapability = existCapability(
166
192
  features,
167
193
  Enum_Capability.Capability_AttachToPin
168
194
  );
169
- // Pro2 (Protocol V2) 协议自带 GetPassphraseState(10028),固件从首个版本即支持,
170
- // 不依赖 Pro 系列的 4.15.0 版本线;V2 也没有 GetAddress Testnet 探测这条 legacy 回退路径。
171
195
  const supportGetPassphraseState =
172
- device.isProtocolV2() ||
173
- supportAttachPinCapability ||
174
- supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
196
+ supportAttachPinCapability || supportProSeriesAttachPinPassphrase(deviceType, firmwareVersion);
175
197
 
176
198
  if (supportGetPassphraseState) {
177
- const payload: GetPassphraseStateMessage = options?.onlyMainPin
199
+ const payload: GetPassphraseState = options?.onlyMainPin
178
200
  ? { _only_main_pin: true }
179
201
  : { passphrase_state: options?.expectPassphraseState };
180
202
  if (options?.allowCreateAttachPin) {
@@ -278,6 +300,9 @@ export const getFirmwareUpdateField = ({
278
300
  if (deviceType === EDeviceType.Pro) {
279
301
  return latestFirmwareField;
280
302
  }
303
+ if (deviceType === EDeviceType.Pro2) {
304
+ return 'firmware-v1';
305
+ }
281
306
  return 'firmware';
282
307
  };
283
308
  /**
@@ -321,6 +346,10 @@ export const getFirmwareUpdateFieldArray = (
321
346
  return ['firmware-v8'];
322
347
  }
323
348
 
349
+ if (deviceType === 'pro2') {
350
+ return ['firmware-v1'];
351
+ }
352
+
324
353
  return ['firmware'];
325
354
  };
326
355
 
@@ -340,12 +369,8 @@ export const fixFeaturesFirmwareVersion = (features: Features): Features => {
340
369
  // fix Touch、Pro device when bootloader version is lower than 2.5.2, the features returned do not have firmware_version error
341
370
  const tempFeatures = { ...features };
342
371
 
343
- if (tempFeatures.onekey_firmware_version && !semver.valid(tempFeatures.onekey_firmware_version)) {
344
- tempFeatures.onekey_firmware_version = fixVersion(tempFeatures.onekey_firmware_version);
345
- }
346
-
347
- if (tempFeatures.onekey_version && !semver.valid(tempFeatures.onekey_version)) {
348
- tempFeatures.onekey_version = fixVersion(tempFeatures.onekey_version);
372
+ if (tempFeatures.firmwareVersion && !semver.valid(tempFeatures.firmwareVersion)) {
373
+ tempFeatures.firmwareVersion = fixVersion(tempFeatures.firmwareVersion);
349
374
  }
350
375
 
351
376
  return tempFeatures;
@@ -14,30 +14,12 @@ export const getDeviceType = (features?: Features): IDeviceType => {
14
14
  if (!features || typeof features !== 'object') {
15
15
  return EDeviceType.Unknown;
16
16
  }
17
+ if (features.deviceType) {
18
+ return features.deviceType;
19
+ }
17
20
 
18
- // classic1s 3.5.0 pro 4.6.0
19
- switch (features.onekey_device_type) {
20
- case 'CLASSIC':
21
- return EDeviceType.Classic;
22
- case 'CLASSIC1S':
23
- return EDeviceType.Classic1s;
24
- case 'MINI':
25
- return EDeviceType.Mini;
26
- case 'TOUCH':
27
- return EDeviceType.Touch;
28
- case 'PRO':
29
- return EDeviceType.Pro;
30
- case 'PRO2':
31
- case 'pro2':
32
- return EDeviceType.Pro2;
33
- case 'PURE':
34
- return EDeviceType.ClassicPure;
35
- default:
36
- // future And old device onekey_device_type is empty
37
- if (!isEmpty(features.onekey_serial_no)) {
38
- return EDeviceType.Unknown;
39
- }
40
- // old device type
21
+ if (features.model === EDeviceType.Pro2 || features.model === 'pro2') {
22
+ return EDeviceType.Pro2;
41
23
  }
42
24
 
43
25
  // low version hardware
@@ -45,7 +27,7 @@ export const getDeviceType = (features?: Features): IDeviceType => {
45
27
  const serialNo = getDeviceUUID(features);
46
28
 
47
29
  // not exist serialNo, bootloader mode, model 1 is classic
48
- if (isEmpty(serialNo) && features.bootloader_mode === true && features.model === '1') {
30
+ if (isEmpty(serialNo) && features.bootloaderMode === true && features.model === '1') {
49
31
  return EDeviceType.Classic;
50
32
  }
51
33
 
@@ -59,6 +41,7 @@ export const getDeviceType = (features?: Features): IDeviceType => {
59
41
  if (miniFlag.toLowerCase() === 'mi') return EDeviceType.Mini;
60
42
  if (miniFlag.toLowerCase() === 'tc') return EDeviceType.Touch;
61
43
  if (miniFlag.toLowerCase() === 'pr') return EDeviceType.Pro;
44
+ if (miniFlag.toLowerCase() === 'p2') return EDeviceType.Pro2;
62
45
 
63
46
  // unknown device
64
47
  return EDeviceType.Unknown;
@@ -89,15 +72,14 @@ export const getDeviceTypeByBleName = (name?: string): IDeviceType => {
89
72
  */
90
73
  export const getDeviceBleName = (features?: Features): string | null => {
91
74
  if (features == null) return null;
92
- return features.onekey_ble_name || features.ble_name || null;
75
+ return features.bleName || null;
93
76
  };
94
77
 
95
78
  /**
96
79
  * Get Connected Device UUID by features
97
80
  */
98
81
  export const getDeviceUUID = (features: Features) => {
99
- const serialNo = features.onekey_serial_no || features.onekey_serial || features.serial_no;
100
- return serialNo ?? '';
82
+ return features.serialNo ?? '';
101
83
  };
102
84
 
103
85
  /**
@@ -163,8 +145,8 @@ export const getFirmwareType = (features: Features | undefined) => {
163
145
  if (!features) {
164
146
  return EFirmwareType.Universal;
165
147
  }
166
- if (features.fw_vendor === 'OneKey Bitcoin-only') {
167
- return EFirmwareType.BitcoinOnly;
148
+ if (features.firmwareType) {
149
+ return features.firmwareType;
168
150
  }
169
151
  // old firmware
170
152
  return features?.capabilities?.length > 0 &&
@@ -8,12 +8,8 @@ import type { Features, IVersionArray } from '../types';
8
8
  export const getDeviceFirmwareVersion = (features: Features | undefined): IVersionArray => {
9
9
  if (!features) return [0, 0, 0];
10
10
 
11
- if (semver.valid(features.onekey_firmware_version)) {
12
- return features.onekey_firmware_version?.split('.') as unknown as IVersionArray;
13
- }
14
-
15
- if (semver.valid(features.onekey_version)) {
16
- return features.onekey_version?.split('.') as unknown as IVersionArray;
11
+ if (features.firmwareVersion && semver.valid(features.firmwareVersion)) {
12
+ return features.firmwareVersion.split('.').map(Number) as IVersionArray;
17
13
  }
18
14
 
19
15
  return [0, 0, 0];
@@ -23,7 +19,7 @@ export const getDeviceFirmwareVersion = (features: Features | undefined): IVersi
23
19
  * Get Connected Device bluetooth firmware version by features
24
20
  */
25
21
  export const getDeviceBLEFirmwareVersion = (features: Features): IVersionArray => {
26
- const bleVer = features?.onekey_ble_version || features?.ble_ver;
22
+ const bleVer = features?.bleVersion;
27
23
 
28
24
  if (!bleVer) {
29
25
  return [0, 0, 0];
@@ -46,24 +42,10 @@ export const getDeviceBootloaderVersion = (features: Features | undefined): IVer
46
42
  if (!features) return [0, 0, 0];
47
43
 
48
44
  // classic1s 3.5.0 pro 4.6.0
49
- if (semver.valid(features.onekey_boot_version)) {
50
- return features.onekey_boot_version?.split('.') as unknown as IVersionArray;
45
+ if (features.bootloaderVersion && semver.valid(features.bootloaderVersion)) {
46
+ return features.bootloaderVersion.split('.').map(Number) as IVersionArray;
51
47
  }
52
48
 
53
- // low version hardware
54
- if (!features.bootloader_version) {
55
- if (features.bootloader_mode) {
56
- return [
57
- features?.major_version ?? 0,
58
- features?.minor_version ?? 0,
59
- features?.patch_version ?? 0,
60
- ];
61
- }
62
- return [0, 0, 0];
63
- }
64
- if (semver.valid(features.bootloader_version)) {
65
- return features.bootloader_version?.split('.') as unknown as IVersionArray;
66
- }
67
49
  return [0, 0, 0];
68
50
  };
69
51
 
@@ -71,8 +53,8 @@ export const getDeviceBootloaderVersion = (features: Features | undefined): IVer
71
53
  * Get Connected Device boardloader version by features
72
54
  */
73
55
  export const getDeviceBoardloaderVersion = (features: Features): IVersionArray => {
74
- if (semver.valid(features?.onekey_board_version)) {
75
- return features?.onekey_board_version?.split('.') as unknown as IVersionArray;
56
+ if (features?.boardVersion && semver.valid(features.boardVersion)) {
57
+ return features.boardVersion.split('.').map(Number) as IVersionArray;
76
58
  }
77
59
 
78
60
  return [0, 0, 0];
@@ -5,7 +5,7 @@ import type { Features } from '../types';
5
5
  /**
6
6
  * 检测故障固件设备
7
7
  * 检测规则:
8
- * - 序列号范围:21032200001 到 21032201500 (从 onekey_serial 字段提取)
8
+ * - 序列号范围:21032200001 到 21032201500
9
9
  * - SE版本为 1.1.0.2
10
10
  *
11
11
  * 对齐之前版本的检测逻辑
@@ -13,13 +13,13 @@ import type { Features } from '../types';
13
13
  export const findDefectiveBatchDevice = (features: Features) => {
14
14
  if (!features) return;
15
15
 
16
- const { onekey_serial: onekeySerial, se_ver: seVer } = features;
17
- if (!onekeySerial) return;
16
+ const { serialNo, seVersion } = features;
17
+ if (!serialNo) return;
18
18
 
19
- const versionNum = +onekeySerial.slice(5);
19
+ const versionNum = +serialNo.slice(5);
20
20
  if (Number.isNaN(versionNum)) return;
21
21
 
22
- return versionNum >= 21032200001 && versionNum <= 21032201500 && seVer === '1.1.0.2';
22
+ return versionNum >= 21032200001 && versionNum <= 21032201500 && seVersion === '1.1.0.2';
23
23
  };
24
24
 
25
25
  /**
@@ -29,7 +29,7 @@ export const getDefectiveDeviceInfo = (features: Features) => {
29
29
  if (!findDefectiveBatchDevice(features)) return null;
30
30
  const serialNo = getDeviceUUID(features);
31
31
  const deviceType = getDeviceType(features);
32
- const seVersion = features.se_ver;
32
+ const { seVersion } = features;
33
33
 
34
34
  return {
35
35
  serialNo,
@@ -1,7 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import type { DeviceRebootParams } from './helpers';
3
- export default class DevReboot extends BaseMethod<DeviceRebootParams> {
4
- init(): void;
5
- run(): Promise<import("packages/hd-transport/dist").Success>;
6
- }
7
- //# sourceMappingURL=DevReboot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DevReboot.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DevReboot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,UAAU,CAAC,kBAAkB,CAAC;IACnE,IAAI;IAWE,GAAG;CAMV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeviceGetDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetDeviceInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,KAAK,CAAC,EAAE,wBAAwB,CAAC;CAClC,CAAC;AAmDF,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU,CAAC;IAC1D,OAAO,EAAE,0BAA0B,CAAC;IACpC,KAAK,EAAE,wBAAwB,CAAC;CACjC,CAAC;IACA,IAAI;IAmBE,GAAG;CAgBV"}
@@ -1,6 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export default class DeviceGetOnboardingStatus extends BaseMethod {
3
- init(): void;
4
- run(): Promise<import("packages/hd-transport/dist").OnboardingStatus>;
5
- }
6
- //# sourceMappingURL=DeviceGetOnboardingStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeviceGetOnboardingStatus.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceGetOnboardingStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,UAAU;IAC/D,IAAI;IAQE,GAAG;CAIV"}
@@ -1,7 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import type { FactoryDeviceInfoSettingsParams } from './helpers';
3
- export default class FactoryDeviceInfoSettings extends BaseMethod<FactoryDeviceInfoSettingsParams> {
4
- init(): void;
5
- run(): Promise<import("packages/hd-transport/dist").Success>;
6
- }
7
- //# sourceMappingURL=FactoryDeviceInfoSettings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FactoryDeviceInfoSettings.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FactoryDeviceInfoSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,UAAU,CAAC,+BAA+B,CAAC;IAChG,IAAI;IAeE,GAAG;CAQV"}
@@ -1,6 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export default class FactoryGetDeviceInfo extends BaseMethod {
3
- init(): void;
4
- run(): Promise<import("packages/hd-transport/dist").FactoryDeviceInfo>;
5
- }
6
- //# sourceMappingURL=FactoryGetDeviceInfo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FactoryGetDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FactoryGetDeviceInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU;IAC1D,IAAI;IAQE,GAAG;CAQV"}