@onekeyfe/hd-core 1.1.26 → 1.1.27-alpha.31

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 (186) hide show
  1. package/__tests__/evmSignTransaction.test.ts +1 -1
  2. package/__tests__/evmSignTypedData.test.ts +1 -1
  3. package/__tests__/protocol-v2.test.ts +1096 -0
  4. package/dist/api/BaseMethod.d.ts +1 -3
  5. package/dist/api/BaseMethod.d.ts.map +1 -1
  6. package/dist/api/DirList.d.ts +10 -0
  7. package/dist/api/DirList.d.ts.map +1 -0
  8. package/dist/api/DirMake.d.ts +9 -0
  9. package/dist/api/DirMake.d.ts.map +1 -0
  10. package/dist/api/DirRemove.d.ts +9 -0
  11. package/dist/api/DirRemove.d.ts.map +1 -0
  12. package/dist/api/FileDelete.d.ts +9 -0
  13. package/dist/api/FileDelete.d.ts.map +1 -0
  14. package/dist/api/FileRead.d.ts +19 -0
  15. package/dist/api/FileRead.d.ts.map +1 -0
  16. package/dist/api/FileWrite.d.ts +23 -0
  17. package/dist/api/FileWrite.d.ts.map +1 -0
  18. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  19. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  20. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  22. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  23. package/dist/api/GetPassphraseState.d.ts +6 -1
  24. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  25. package/dist/api/PathInfo.d.ts +9 -0
  26. package/dist/api/PathInfo.d.ts.map +1 -0
  27. package/dist/api/SearchDevices.d.ts +2 -1
  28. package/dist/api/SearchDevices.d.ts.map +1 -1
  29. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  30. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  31. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  32. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  33. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  34. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  35. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  36. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  37. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  38. package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
  39. package/dist/api/index.d.ts +26 -0
  40. package/dist/api/index.d.ts.map +1 -1
  41. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  42. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  43. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
  44. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  45. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  46. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  48. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  50. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  51. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  52. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  53. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  54. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  55. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  56. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  57. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  58. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  59. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  60. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  61. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  62. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  63. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  64. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/data-manager/DataManager.d.ts +7 -4
  67. package/dist/data-manager/DataManager.d.ts.map +1 -1
  68. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  69. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  70. package/dist/data-manager/TransportManager.d.ts +5 -4
  71. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  72. package/dist/device/Device.d.ts +5 -3
  73. package/dist/device/Device.d.ts.map +1 -1
  74. package/dist/device/DeviceCommands.d.ts +8 -8
  75. package/dist/device/DeviceCommands.d.ts.map +1 -1
  76. package/dist/device/DeviceConnector.d.ts +2 -1
  77. package/dist/device/DeviceConnector.d.ts.map +1 -1
  78. package/dist/events/ui-request.d.ts +8 -0
  79. package/dist/events/ui-request.d.ts.map +1 -1
  80. package/dist/index.d.ts +198 -23
  81. package/dist/index.js +15726 -806
  82. package/dist/inject.d.ts.map +1 -1
  83. package/dist/protocols/protocol-v2/features.d.ts +57 -0
  84. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  85. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  86. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  87. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  88. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  89. package/dist/types/api/export.d.ts +1 -1
  90. package/dist/types/api/export.d.ts.map +1 -1
  91. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  92. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  93. package/dist/types/api/getPassphraseState.d.ts +7 -1
  94. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  95. package/dist/types/api/index.d.ts +29 -1
  96. package/dist/types/api/index.d.ts.map +1 -1
  97. package/dist/types/api/protocolV2.d.ts +123 -0
  98. package/dist/types/api/protocolV2.d.ts.map +1 -0
  99. package/dist/types/api/searchDevices.d.ts +2 -2
  100. package/dist/types/api/searchDevices.d.ts.map +1 -1
  101. package/dist/types/device.d.ts +1 -1
  102. package/dist/types/device.d.ts.map +1 -1
  103. package/dist/types/params.d.ts +2 -0
  104. package/dist/types/params.d.ts.map +1 -1
  105. package/dist/types/settings.d.ts +1 -1
  106. package/dist/types/settings.d.ts.map +1 -1
  107. package/dist/utils/deviceFeaturesUtils.d.ts +3 -3
  108. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  109. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  110. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  111. package/dist/utils/index.d.ts +1 -1
  112. package/dist/utils/index.d.ts.map +1 -1
  113. package/dist/utils/patch.d.ts +1 -1
  114. package/dist/utils/patch.d.ts.map +1 -1
  115. package/dist/utils/versionUtils.d.ts +1 -1
  116. package/package.json +4 -4
  117. package/src/api/BaseMethod.ts +12 -60
  118. package/src/api/DirList.ts +25 -0
  119. package/src/api/DirMake.ts +20 -0
  120. package/src/api/DirRemove.ts +20 -0
  121. package/src/api/FileDelete.ts +20 -0
  122. package/src/api/FileRead.ts +158 -0
  123. package/src/api/FileWrite.ts +191 -0
  124. package/src/api/FirmwareUpdateV3.ts +21 -4
  125. package/src/api/FirmwareUpdateV4.ts +810 -0
  126. package/src/api/GetOnekeyFeatures.ts +75 -3
  127. package/src/api/GetPassphraseState.ts +14 -2
  128. package/src/api/PathInfo.ts +24 -0
  129. package/src/api/SearchDevices.ts +7 -2
  130. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -9
  131. package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
  132. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  133. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  134. package/src/api/dynex/DnxGetAddress.ts +7 -0
  135. package/src/api/dynex/DnxSignTransaction.ts +7 -0
  136. package/src/api/evm/EVMGetAddress.ts +1 -1
  137. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  138. package/src/api/evm/EVMSignMessage.ts +1 -1
  139. package/src/api/evm/EVMSignTransaction.ts +1 -1
  140. package/src/api/evm/EVMSignTypedData.ts +6 -6
  141. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  142. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  143. package/src/api/helpers/batchGetPublickeys.ts +4 -2
  144. package/src/api/index.ts +28 -0
  145. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +33 -0
  146. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
  147. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
  148. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
  149. package/src/api/protocol-v2/DeviceReboot.ts +22 -0
  150. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  151. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  152. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  153. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  154. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  155. package/src/api/protocol-v2/Ping.ts +16 -0
  156. package/src/api/protocol-v2/helpers.ts +138 -0
  157. package/src/api/tron/TronSignMessage.ts +1 -1
  158. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  159. package/src/core/index.ts +31 -5
  160. package/src/data/messages/messages-pro2.json +13106 -0
  161. package/src/data-manager/DataManager.ts +12 -7
  162. package/src/data-manager/MessagesConfig.ts +14 -14
  163. package/src/data-manager/TransportManager.ts +38 -12
  164. package/src/device/Device.ts +73 -9
  165. package/src/device/DeviceCommands.ts +162 -26
  166. package/src/device/DeviceConnector.ts +29 -4
  167. package/src/device/DevicePool.ts +1 -1
  168. package/src/events/ui-request.ts +8 -0
  169. package/src/inject.ts +42 -1
  170. package/src/protocols/protocol-v2/features.ts +267 -0
  171. package/src/protocols/protocol-v2/firmware.ts +26 -0
  172. package/src/protocols/protocol-v2/index.ts +2 -0
  173. package/src/types/api/export.ts +1 -0
  174. package/src/types/api/firmwareUpdate.ts +12 -0
  175. package/src/types/api/getPassphraseState.ts +10 -1
  176. package/src/types/api/index.ts +64 -1
  177. package/src/types/api/protocolV2.ts +221 -0
  178. package/src/types/api/searchDevices.ts +2 -2
  179. package/src/types/device.ts +3 -1
  180. package/src/types/params.ts +7 -0
  181. package/src/types/settings.ts +1 -1
  182. package/src/utils/deviceFeaturesUtils.ts +33 -15
  183. package/src/utils/deviceInfoUtils.ts +14 -5
  184. package/src/utils/index.ts +1 -0
  185. package/__tests__/DeviceCommands.test.ts +0 -99
  186. package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
@@ -0,0 +1,267 @@
1
+ import { EDeviceType } from '@onekeyfe/hd-shared';
2
+
3
+ import type { Features } from '../../types';
4
+ import type { DeviceCommands } from '../../device/DeviceCommands';
5
+ import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
6
+
7
+ type ProtocolV2Bytes = Uint8Array | number[] | string;
8
+
9
+ type ProtocolV2FirmwareImageInfo = {
10
+ version?: string;
11
+ build_id?: string;
12
+ hash?: ProtocolV2Bytes;
13
+ };
14
+
15
+ type ProtocolV2SEInfo = {
16
+ boot?: ProtocolV2FirmwareImageInfo;
17
+ app?: ProtocolV2FirmwareImageInfo;
18
+ type?: number;
19
+ state?: number;
20
+ };
21
+
22
+ type ProtocolV2DeviceInfo = {
23
+ protocol_version?: number;
24
+ hw?: {
25
+ Device_type?: number;
26
+ device_type?: number;
27
+ serial_no?: string;
28
+ hardware_version?: string;
29
+ hardware_version_raw_adc?: number;
30
+ };
31
+ fw?: {
32
+ board?: ProtocolV2FirmwareImageInfo;
33
+ boot?: ProtocolV2FirmwareImageInfo;
34
+ app?: ProtocolV2FirmwareImageInfo;
35
+ };
36
+ bt?: {
37
+ boot?: ProtocolV2FirmwareImageInfo;
38
+ app?: ProtocolV2FirmwareImageInfo;
39
+ adv_name?: string;
40
+ mac?: ProtocolV2Bytes;
41
+ };
42
+ se1?: ProtocolV2SEInfo;
43
+ se2?: ProtocolV2SEInfo;
44
+ se3?: ProtocolV2SEInfo;
45
+ se4?: ProtocolV2SEInfo;
46
+ status?: {
47
+ language?: string;
48
+ bt_enable?: boolean;
49
+ init_states?: boolean;
50
+ backup_required?: boolean;
51
+ passphrase_protection?: boolean;
52
+ label?: string;
53
+ };
54
+ };
55
+
56
+ // const PROTOCOL_V2_DEVICE_INFO_REQUEST = {
57
+ // targets: {
58
+ // hw: true,
59
+ // fw: true,
60
+ // bt: true,
61
+ // se1: true,
62
+ // se2: true,
63
+ // se3: true,
64
+ // se4: true,
65
+ // status: true,
66
+ // },
67
+ // types: {
68
+ // version: true,
69
+ // build_id: true,
70
+ // hash: true,
71
+ // specific: true,
72
+ // },
73
+ // };
74
+
75
+ function parseVersion(version?: string | null): [number, number, number] {
76
+ if (!version) return [0, 0, 0];
77
+ const [major = 0, minor = 0, patch = 0] = version.split('.').map(part => Number(part) || 0);
78
+ return [major, minor, patch];
79
+ }
80
+
81
+ function bytesToHex(value: unknown): string | undefined {
82
+ if (!value) return undefined;
83
+ if (typeof value === 'string') return value;
84
+ if (value instanceof Uint8Array) {
85
+ return Array.from(value)
86
+ .map(byte => byte.toString(16).padStart(2, '0'))
87
+ .join('');
88
+ }
89
+ if (Array.isArray(value)) {
90
+ return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
91
+ }
92
+ return undefined;
93
+ }
94
+
95
+ function getDescriptorId(descriptor: DeviceDescriptor) {
96
+ return descriptor.path || descriptor.id || '';
97
+ }
98
+
99
+ function getImageVersion(image?: ProtocolV2FirmwareImageInfo) {
100
+ return image?.version || undefined;
101
+ }
102
+
103
+ function getImageBuildId(image?: ProtocolV2FirmwareImageInfo) {
104
+ return image?.build_id || undefined;
105
+ }
106
+
107
+ function getImageHash(image?: ProtocolV2FirmwareImageInfo) {
108
+ return bytesToHex(image?.hash);
109
+ }
110
+
111
+ function getSeState(se?: ProtocolV2SEInfo) {
112
+ switch (se?.state) {
113
+ case 0:
114
+ return 'BOOT';
115
+ case 51:
116
+ return 'APP_FACTORY';
117
+ case 85:
118
+ return 'APP';
119
+ default:
120
+ return null;
121
+ }
122
+ }
123
+
124
+ function createBaseFeatures(descriptor: DeviceDescriptor): Features {
125
+ const descriptorId = getDescriptorId(descriptor);
126
+ return {
127
+ vendor: 'onekey.so',
128
+ major_version: 0,
129
+ minor_version: 0,
130
+ patch_version: 0,
131
+ bootloader_mode: false,
132
+ device_id: descriptorId,
133
+ pin_protection: null,
134
+ passphrase_protection: null,
135
+ language: null,
136
+ label: null,
137
+ initialized: false,
138
+ revision: null,
139
+ bootloader_hash: null,
140
+ imported: null,
141
+ unlocked: false,
142
+ firmware_present: false,
143
+ needs_backup: null,
144
+ flags: null,
145
+ model: 'pro2',
146
+ fw_major: 0,
147
+ fw_minor: 0,
148
+ fw_patch: 0,
149
+ fw_vendor: null,
150
+ unfinished_backup: null,
151
+ no_backup: null,
152
+ recovery_mode: null,
153
+ capabilities: [],
154
+ backup_type: null,
155
+ sd_card_present: null,
156
+ sd_protection: null,
157
+ wipe_code_protection: null,
158
+ session_id: null,
159
+ passphrase_always_on_device: null,
160
+ safety_checks: null,
161
+ auto_lock_delay_ms: null,
162
+ display_rotation: null,
163
+ experimental_features: null,
164
+ onekey_device_type: EDeviceType.Pro2,
165
+ onekey_serial_no: descriptorId,
166
+ serial_no: descriptorId,
167
+ };
168
+ }
169
+
170
+ export function normalizeProtocolV2Features(
171
+ descriptor: DeviceDescriptor,
172
+ deviceInfo?: ProtocolV2DeviceInfo
173
+ ): Features {
174
+ const features = createBaseFeatures(descriptor);
175
+ if (!deviceInfo) return features;
176
+
177
+ const serialNo =
178
+ deviceInfo.hw?.serial_no || features.onekey_serial_no || getDescriptorId(descriptor);
179
+ const firmwareVersion = getImageVersion(deviceInfo.fw?.app);
180
+ const [fwMajor, fwMinor, fwPatch] = parseVersion(firmwareVersion);
181
+
182
+ return {
183
+ ...features,
184
+ major_version: fwMajor,
185
+ minor_version: fwMinor,
186
+ patch_version: fwPatch,
187
+ fw_major: fwMajor,
188
+ fw_minor: fwMinor,
189
+ fw_patch: fwPatch,
190
+ device_id: serialNo,
191
+ serial_no: serialNo,
192
+ onekey_serial_no: serialNo,
193
+ label: deviceInfo.status?.label ?? features.label,
194
+ language: deviceInfo.status?.language ?? features.language,
195
+ initialized: deviceInfo.status?.init_states ?? features.initialized,
196
+ passphrase_protection:
197
+ deviceInfo.status?.passphrase_protection ?? features.passphrase_protection,
198
+ needs_backup: deviceInfo.status?.backup_required ?? features.needs_backup,
199
+ ble_enable: deviceInfo.status?.bt_enable,
200
+ onekey_ble_name: deviceInfo.bt?.adv_name,
201
+ ble_name: deviceInfo.bt?.adv_name,
202
+ onekey_firmware_version: firmwareVersion,
203
+ onekey_firmware_build_id: getImageBuildId(deviceInfo.fw?.app),
204
+ onekey_firmware_hash: getImageHash(deviceInfo.fw?.app),
205
+ onekey_boot_version: getImageVersion(deviceInfo.fw?.boot),
206
+ bootloader_version: getImageVersion(deviceInfo.fw?.boot),
207
+ onekey_boot_build_id: getImageBuildId(deviceInfo.fw?.boot),
208
+ onekey_boot_hash: getImageHash(deviceInfo.fw?.boot),
209
+ onekey_board_version: getImageVersion(deviceInfo.fw?.board),
210
+ onekey_board_hash: getImageHash(deviceInfo.fw?.board),
211
+ onekey_ble_version: getImageVersion(deviceInfo.bt?.app),
212
+ ble_ver: getImageVersion(deviceInfo.bt?.app),
213
+ onekey_ble_build_id: getImageBuildId(deviceInfo.bt?.app),
214
+ onekey_ble_hash: getImageHash(deviceInfo.bt?.app),
215
+ onekey_se01_version: getImageVersion(deviceInfo.se1?.app),
216
+ onekey_se01_hash: getImageHash(deviceInfo.se1?.app),
217
+ onekey_se01_build_id: getImageBuildId(deviceInfo.se1?.app),
218
+ onekey_se01_state: getSeState(deviceInfo.se1),
219
+ onekey_se02_version: getImageVersion(deviceInfo.se2?.app),
220
+ onekey_se02_state: getSeState(deviceInfo.se2),
221
+ onekey_se03_version: getImageVersion(deviceInfo.se3?.app),
222
+ onekey_se03_state: getSeState(deviceInfo.se3),
223
+ onekey_se04_version: getImageVersion(deviceInfo.se4?.app),
224
+ onekey_se04_state: getSeState(deviceInfo.se4),
225
+ };
226
+ }
227
+
228
+ export async function getProtocolV2Features({
229
+ commands,
230
+ descriptor,
231
+ // onDeviceInfoError,
232
+ timeoutMs,
233
+ }: {
234
+ commands: DeviceCommands;
235
+ descriptor: DeviceDescriptor;
236
+ onDeviceInfoError?: (error: unknown) => void;
237
+ timeoutMs?: number;
238
+ }) {
239
+ const callOptions = timeoutMs ? { timeoutMs } : undefined;
240
+ if (callOptions) {
241
+ await commands.typedCall('Ping', 'Success', { message: 'init' }, callOptions);
242
+ } else {
243
+ await commands.typedCall('Ping', 'Success', { message: 'init' });
244
+ }
245
+
246
+ // DeviceGetDeviceInfo 暂时关闭,避免初始化阶段依赖固件侧 DeviceInfo 支持。
247
+ // try {
248
+ // const { message } = callOptions
249
+ // ? await commands.typedCall(
250
+ // 'DeviceGetDeviceInfo',
251
+ // 'DeviceInfo',
252
+ // PROTOCOL_V2_DEVICE_INFO_REQUEST,
253
+ // callOptions
254
+ // )
255
+ // : await commands.typedCall(
256
+ // 'DeviceGetDeviceInfo',
257
+ // 'DeviceInfo',
258
+ // PROTOCOL_V2_DEVICE_INFO_REQUEST
259
+ // );
260
+ // return normalizeProtocolV2Features(descriptor, message as unknown as ProtocolV2DeviceInfo);
261
+ // } catch (error) {
262
+ // onDeviceInfoError?.(error);
263
+ // return normalizeProtocolV2Features(descriptor);
264
+ // }
265
+
266
+ return normalizeProtocolV2Features(descriptor);
267
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Protocol V2 DeviceFirmwareTargetType enum (from messages-pro2.json).
3
+ */
4
+ export const ProtocolV2FirmwareTargetType = {
5
+ TARGET_INVALID: 0,
6
+ TARGET_ROMLOADER: 1,
7
+ TARGET_BOOTLOADER: 2,
8
+ TARGET_FIRMWARE_P1: 3,
9
+ TARGET_FIRMWARE_P2: 4,
10
+ TARGET_COPROCESSOR: 5,
11
+ TARGET_SE: 6,
12
+ TARGET_RESOURCE: 10,
13
+ } as const;
14
+
15
+ /**
16
+ * Map Protocol V2 firmware file name to DeviceFirmwareUpdate target_id.
17
+ */
18
+ export function protocolV2FileNameToTargetId(fileName: string): number {
19
+ const normalized = fileName.toLowerCase();
20
+ if (normalized.includes('romloader')) return ProtocolV2FirmwareTargetType.TARGET_ROMLOADER;
21
+ if (normalized.includes('bootloader')) return ProtocolV2FirmwareTargetType.TARGET_BOOTLOADER;
22
+ if (normalized.includes('ble')) return ProtocolV2FirmwareTargetType.TARGET_COPROCESSOR;
23
+ if (normalized.includes('se')) return ProtocolV2FirmwareTargetType.TARGET_SE;
24
+ if (normalized.includes('p2')) return ProtocolV2FirmwareTargetType.TARGET_FIRMWARE_P2;
25
+ return ProtocolV2FirmwareTargetType.TARGET_FIRMWARE_P1;
26
+ }
@@ -0,0 +1,2 @@
1
+ export * from './features';
2
+ export * from './firmware';
@@ -28,6 +28,7 @@ export type {
28
28
  FirmwareUpdateParams,
29
29
  FirmwareUpdateBinaryParams,
30
30
  FirmwareUpdateV3Params,
31
+ FirmwareUpdateV4Params,
31
32
  } from './firmwareUpdate';
32
33
  export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
33
34
 
@@ -41,6 +41,7 @@ export declare function firmwareUpdateV2(
41
41
  export interface FirmwareUpdateV3Params {
42
42
  bleVersion?: number[];
43
43
  bleBinary?: ArrayBuffer;
44
+ chunkSize?: number;
44
45
 
45
46
  firmwareVersion?: number[];
46
47
  firmwareBinary?: ArrayBuffer;
@@ -56,6 +57,8 @@ export interface FirmwareUpdateV3Params {
56
57
  platform: IPlatform;
57
58
  }
58
59
 
60
+ export type FirmwareUpdateV4Params = FirmwareUpdateV3Params;
61
+
59
62
  export declare function firmwareUpdateV3(
60
63
  connectId: string | undefined,
61
64
  params: Params<FirmwareUpdateV3Params>
@@ -64,3 +67,12 @@ export declare function firmwareUpdateV3(
64
67
  firmwareVersion: string;
65
68
  bootloaderVersion: string;
66
69
  }>;
70
+
71
+ export declare function firmwareUpdateV4(
72
+ connectId: string | undefined,
73
+ params: Params<FirmwareUpdateV4Params>
74
+ ): Response<{
75
+ bleVersion: string;
76
+ firmwareVersion: string;
77
+ bootloaderVersion: string;
78
+ }>;
@@ -1,6 +1,15 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
 
3
+ export type GetPassphraseStatePayload =
4
+ | string
5
+ | {
6
+ passphrase_state?: string;
7
+ session_id?: string;
8
+ unlocked_attach_pin?: boolean;
9
+ passphrase_protection?: boolean | null;
10
+ };
11
+
3
12
  export declare function getPassphraseState(
4
13
  connectId?: string,
5
14
  params?: CommonParams
6
- ): Response<string>;
15
+ ): Response<GetPassphraseStatePayload>;
@@ -1,3 +1,30 @@
1
+ import type {
2
+ deviceFirmwareUpdate,
3
+ deviceGetDeviceInfo,
4
+ deviceGetFirmwareUpdateStatus,
5
+ deviceGetOnboardingStatus,
6
+ deviceReboot,
7
+ dirList,
8
+ dirMake,
9
+ dirRemove,
10
+ factoryDeviceInfoSettings,
11
+ factoryGetDeviceInfo,
12
+ fileDelete,
13
+ fileRead,
14
+ fileWrite,
15
+ filesystemDirList,
16
+ filesystemDirMake,
17
+ filesystemDirRemove,
18
+ filesystemFileDelete,
19
+ filesystemFileRead,
20
+ filesystemFileWrite,
21
+ filesystemFixPermission,
22
+ filesystemFormat,
23
+ filesystemPathInfoQuery,
24
+ getProtoVersion,
25
+ pathInfo,
26
+ ping,
27
+ } from './protocolV2';
1
28
  import type { off, on, removeAllListeners } from './event';
2
29
  import type { uiResponse } from './uiResponse';
3
30
  import type { init, updateSettings } from './init';
@@ -14,7 +41,12 @@ import type { getOnekeyFeatures } from './getOnekeyFeatures';
14
41
  import type { getPassphraseState } from './getPassphraseState';
15
42
  import type { checkFirmwareRelease } from './checkFirmwareRelease';
16
43
  import type { checkBLEFirmwareRelease } from './checkBLEFirmwareRelease';
17
- import type { firmwareUpdate, firmwareUpdateV2, firmwareUpdateV3 } from './firmwareUpdate';
44
+ import type {
45
+ firmwareUpdate,
46
+ firmwareUpdateV2,
47
+ firmwareUpdateV3,
48
+ firmwareUpdateV4,
49
+ } from './firmwareUpdate';
18
50
  import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
19
51
  import type { deviceReset } from './deviceReset';
20
52
  import type { deviceRecovery } from './deviceRecovery';
@@ -130,6 +162,7 @@ import type { neoSignTransaction } from './neoSignTransaction';
130
162
  import type { ConnectSettings } from '../settings';
131
163
 
132
164
  export * from './export';
165
+ export type { GetPassphraseStatePayload } from './getPassphraseState';
133
166
 
134
167
  export type CoreApi = {
135
168
  /**
@@ -195,8 +228,38 @@ export type CoreApi = {
195
228
  firmwareUpdate: typeof firmwareUpdate;
196
229
  firmwareUpdateV2: typeof firmwareUpdateV2;
197
230
  firmwareUpdateV3: typeof firmwareUpdateV3;
231
+ firmwareUpdateV4: typeof firmwareUpdateV4;
198
232
  cipherKeyValue: typeof cipherKeyValue;
199
233
 
234
+ /**
235
+ * File system & device control API (Protocol V2 only)
236
+ */
237
+ getProtoVersion: typeof getProtoVersion;
238
+ ping: typeof ping;
239
+ deviceReboot: typeof deviceReboot;
240
+ deviceGetDeviceInfo: typeof deviceGetDeviceInfo;
241
+ deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
242
+ deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
243
+ deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
244
+ factoryDeviceInfoSettings: typeof factoryDeviceInfoSettings;
245
+ factoryGetDeviceInfo: typeof factoryGetDeviceInfo;
246
+ filesystemFixPermission: typeof filesystemFixPermission;
247
+ fileRead: typeof fileRead;
248
+ fileWrite: typeof fileWrite;
249
+ fileDelete: typeof fileDelete;
250
+ dirList: typeof dirList;
251
+ dirMake: typeof dirMake;
252
+ dirRemove: typeof dirRemove;
253
+ pathInfo: typeof pathInfo;
254
+ filesystemFileRead: typeof filesystemFileRead;
255
+ filesystemFileWrite: typeof filesystemFileWrite;
256
+ filesystemFileDelete: typeof filesystemFileDelete;
257
+ filesystemDirList: typeof filesystemDirList;
258
+ filesystemDirMake: typeof filesystemDirMake;
259
+ filesystemDirRemove: typeof filesystemDirRemove;
260
+ filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
261
+ filesystemFormat: typeof filesystemFormat;
262
+
200
263
  /**
201
264
  * All network function
202
265
  */
@@ -0,0 +1,221 @@
1
+ import type { CommonParams, Response } from '../params';
2
+ import type {
3
+ DeviceFirmwareTarget,
4
+ DeviceFirmwareUpdateStatus,
5
+ DeviceOnboardingStatus,
6
+ DeviceInfoTargets,
7
+ DeviceInfoTypes,
8
+ DeviceRebootType,
9
+ FactoryDeviceInfo,
10
+ ProtoVersion,
11
+ ProtocolV2DeviceInfo,
12
+ Success,
13
+ } from '@onekeyfe/hd-transport';
14
+
15
+ // ── Shared response shapes (Protocol V2 file system) ────────────────────
16
+
17
+ export type FileOpSuccess = { message?: string };
18
+
19
+ export type FileInfo = {
20
+ path: string;
21
+ offset: number;
22
+ total_size: number;
23
+ data?: Uint8Array;
24
+ data_hash?: number;
25
+ processed_byte?: number;
26
+ chunks?: number;
27
+ };
28
+
29
+ export type DirInfo = {
30
+ path: string;
31
+ child_dirs?: string;
32
+ child_files?: string;
33
+ };
34
+
35
+ export type PathInfoResult = {
36
+ exist: boolean;
37
+ size: number;
38
+ year: number;
39
+ month: number;
40
+ day: number;
41
+ hour: number;
42
+ minute: number;
43
+ second: number;
44
+ readonly?: boolean;
45
+ hidden?: boolean;
46
+ system?: boolean;
47
+ archive?: boolean;
48
+ directory?: boolean;
49
+ };
50
+
51
+ export type DeviceRebootParams = {
52
+ rebootType?: DeviceRebootType | string | number;
53
+ reboot_type?: DeviceRebootType | string | number;
54
+ };
55
+
56
+ export type DeviceGetDeviceInfoParams = {
57
+ targets?: DeviceInfoTargets;
58
+ types?: DeviceInfoTypes;
59
+ targetHw?: boolean;
60
+ targetFw?: boolean;
61
+ targetBt?: boolean;
62
+ targetSe1?: boolean;
63
+ targetSe2?: boolean;
64
+ targetSe3?: boolean;
65
+ targetSe4?: boolean;
66
+ targetStatus?: boolean;
67
+ includeVersion?: boolean;
68
+ includeBuildId?: boolean;
69
+ includeHash?: boolean;
70
+ includeSpecific?: boolean;
71
+ };
72
+
73
+ export type DeviceFirmwareUpdateParams = {
74
+ targets?: DeviceFirmwareTarget[];
75
+ targetId?: DeviceFirmwareTarget['target_id'] | string | number;
76
+ target_id?: DeviceFirmwareTarget['target_id'] | string | number;
77
+ path?: string;
78
+ };
79
+
80
+ export type FactoryDeviceInfoSettingsParams = {
81
+ serial_no?: string;
82
+ serialNo?: string;
83
+ cpu_info?: string;
84
+ cpuInfo?: string;
85
+ pre_firmware?: string;
86
+ preFirmware?: string;
87
+ };
88
+
89
+ // ── Method signatures ─────────────────────────────────────────────────────
90
+
91
+ export declare function fileRead(
92
+ connectId: string,
93
+ params: {
94
+ path: string;
95
+ offset?: number;
96
+ totalSize?: number;
97
+ chunkLen?: number;
98
+ uiPercentage?: number;
99
+ }
100
+ ): Response<FileInfo>;
101
+
102
+ export declare function fileWrite(
103
+ connectId: string,
104
+ params: {
105
+ path: string;
106
+ offset?: number;
107
+ totalSize?: number;
108
+ chunkSize?: number;
109
+ chunkLen?: number;
110
+ data: ArrayBuffer | Uint8Array | Blob | string;
111
+ overwrite?: boolean;
112
+ append?: boolean;
113
+ uiPercentage?: number;
114
+ }
115
+ ): Response<FileInfo>;
116
+
117
+ export declare function fileDelete(
118
+ connectId: string,
119
+ params: { path: string }
120
+ ): Response<FileOpSuccess>;
121
+
122
+ export declare function dirList(
123
+ connectId: string,
124
+ params: { path: string; depth?: number }
125
+ ): Response<DirInfo>;
126
+
127
+ export declare function dirMake(
128
+ connectId: string,
129
+ params: { path: string }
130
+ ): Response<FileOpSuccess>;
131
+
132
+ export declare function dirRemove(
133
+ connectId: string,
134
+ params: { path: string }
135
+ ): Response<FileOpSuccess>;
136
+
137
+ export declare function pathInfo(
138
+ connectId: string,
139
+ params: { path: string }
140
+ ): Response<PathInfoResult>;
141
+
142
+ export declare function getProtoVersion(
143
+ connectId: string,
144
+ params?: CommonParams
145
+ ): Response<ProtoVersion>;
146
+
147
+ export declare function ping(
148
+ connectId: string,
149
+ params?: CommonParams & { message?: string }
150
+ ): Response<Success>;
151
+
152
+ export declare function deviceReboot(
153
+ connectId: string,
154
+ params: CommonParams & DeviceRebootParams
155
+ ): Response<Success>;
156
+
157
+ export declare function deviceGetDeviceInfo(
158
+ connectId: string,
159
+ params?: CommonParams & DeviceGetDeviceInfoParams
160
+ ): Response<ProtocolV2DeviceInfo>;
161
+
162
+ export declare function deviceGetOnboardingStatus(
163
+ connectId: string,
164
+ params?: CommonParams
165
+ ): Response<DeviceOnboardingStatus>;
166
+
167
+ export declare function deviceFirmwareUpdate(
168
+ connectId: string,
169
+ params: CommonParams & DeviceFirmwareUpdateParams
170
+ ): Response<Success | DeviceFirmwareUpdateStatus>;
171
+
172
+ export declare function deviceGetFirmwareUpdateStatus(
173
+ connectId: string,
174
+ params?: CommonParams
175
+ ): Response<DeviceFirmwareUpdateStatus>;
176
+
177
+ export declare function factoryDeviceInfoSettings(
178
+ connectId: string,
179
+ params: FactoryDeviceInfoSettingsParams
180
+ ): Response<Success>;
181
+
182
+ export declare function factoryGetDeviceInfo(connectId: string): Response<FactoryDeviceInfo>;
183
+
184
+ export declare function filesystemFixPermission(connectId: string): Response<Success>;
185
+
186
+ export declare function filesystemFileRead(
187
+ connectId: string,
188
+ params: Parameters<typeof fileRead>[1]
189
+ ): ReturnType<typeof fileRead>;
190
+
191
+ export declare function filesystemFileWrite(
192
+ connectId: string,
193
+ params: Parameters<typeof fileWrite>[1]
194
+ ): ReturnType<typeof fileWrite>;
195
+
196
+ export declare function filesystemFileDelete(
197
+ connectId: string,
198
+ params: Parameters<typeof fileDelete>[1]
199
+ ): ReturnType<typeof fileDelete>;
200
+
201
+ export declare function filesystemDirList(
202
+ connectId: string,
203
+ params: Parameters<typeof dirList>[1]
204
+ ): ReturnType<typeof dirList>;
205
+
206
+ export declare function filesystemDirMake(
207
+ connectId: string,
208
+ params: Parameters<typeof dirMake>[1]
209
+ ): ReturnType<typeof dirMake>;
210
+
211
+ export declare function filesystemDirRemove(
212
+ connectId: string,
213
+ params: Parameters<typeof dirRemove>[1]
214
+ ): ReturnType<typeof dirRemove>;
215
+
216
+ export declare function filesystemPathInfoQuery(
217
+ connectId: string,
218
+ params: Parameters<typeof pathInfo>[1]
219
+ ): ReturnType<typeof pathInfo>;
220
+
221
+ export declare function filesystemFormat(connectId: string): Response<Success>;
@@ -1,4 +1,4 @@
1
1
  import type { SearchDevice } from '../device';
2
- import type { Response } from '../params';
2
+ import type { CommonParams, Response } from '../params';
3
3
 
4
- export declare function searchDevices(): Response<SearchDevice[]>;
4
+ export declare function searchDevices(params?: CommonParams): Response<SearchDevice[]>;
@@ -96,7 +96,8 @@ export type IDeviceType =
96
96
  | EDeviceType.ClassicPure
97
97
  | EDeviceType.Mini
98
98
  | EDeviceType.Touch
99
- | EDeviceType.Pro;
99
+ | EDeviceType.Pro
100
+ | EDeviceType.Pro2;
100
101
 
101
102
  /**
102
103
  * model_classic: 'classic' | 'classic1s' | 'classicpure'
@@ -124,6 +125,7 @@ export const DeviceTypeToModels: { [deviceType in IDeviceType]: IDeviceModel[] }
124
125
  [EDeviceType.Mini]: ['model_mini'],
125
126
  [EDeviceType.Touch]: ['model_touch'],
126
127
  [EDeviceType.Pro]: ['model_touch'],
128
+ [EDeviceType.Pro2]: [],
127
129
  [EDeviceType.Unknown]: [],
128
130
  };
129
131