@onekeyfe/hd-core 1.2.0-alpha.20 → 1.2.0-alpha.22

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 (226) hide show
  1. package/__tests__/DeviceCommands.test.ts +87 -2
  2. package/__tests__/connectSettings.test.ts +47 -5
  3. package/__tests__/device-identity.test.ts +24 -2
  4. package/__tests__/device-lifecycle-events.test.ts +1 -1
  5. package/__tests__/device-settings.test.ts +111 -6
  6. package/__tests__/device-state-events.test.ts +3 -3
  7. package/__tests__/device-state-mapper.test.ts +15 -3
  8. package/__tests__/device-state-store.test.ts +1 -1
  9. package/__tests__/device-wallet-session-store.test.ts +111 -7
  10. package/__tests__/deviceSettings.test.ts +55 -15
  11. package/__tests__/evmLedgerLegacySafety.test.ts +6 -5
  12. package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
  13. package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
  14. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
  15. package/__tests__/firmware-update/firmware-update-plan.test.ts +326 -0
  16. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +200 -0
  17. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +39 -30
  18. package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
  19. package/__tests__/get-device-state.test.ts +7 -0
  20. package/__tests__/open-wallet-session.test.ts +253 -13
  21. package/__tests__/pro2Wallpaper.test.ts +7 -18
  22. package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
  23. package/__tests__/protocol-v2.test.ts +439 -282
  24. package/__tests__/public-device-state-api.test.ts +79 -68
  25. package/__tests__/public-pro2-api-boundary.test.ts +22 -29
  26. package/dist/api/BaseMethod.d.ts +2 -4
  27. package/dist/api/BaseMethod.d.ts.map +1 -1
  28. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  29. package/dist/api/ClearSessionCache.d.ts.map +1 -1
  30. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  31. package/dist/api/FirmwareUpdateV2.d.ts +11 -0
  32. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  33. package/dist/api/FirmwareUpdateV3.d.ts +7 -3
  34. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  35. package/dist/api/FirmwareUpdateV4.d.ts +29 -10
  36. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  37. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  38. package/dist/api/UploadPortfolio.d.ts +0 -1
  39. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  40. package/dist/api/conflux/ConfluxGetAddress.d.ts +1 -0
  41. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
  42. package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
  43. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  44. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
  45. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  46. package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
  47. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  48. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  49. package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
  50. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  51. package/dist/api/firmware/FirmwareArtifactSource.d.ts +26 -0
  52. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
  53. package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
  54. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
  55. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +7 -0
  56. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  57. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
  58. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
  59. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +24 -0
  60. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
  61. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +25 -0
  62. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
  63. package/dist/api/firmware/getBinary.d.ts +7 -0
  64. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  65. package/dist/api/firmware/updateBootloader.d.ts +2 -0
  66. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  67. package/dist/api/firmware/uploadFirmware.d.ts +9 -1
  68. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  69. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  70. package/dist/api/index.d.ts +0 -20
  71. package/dist/api/index.d.ts.map +1 -1
  72. package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
  73. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  74. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  75. package/dist/core/RequestQueue.d.ts +1 -19
  76. package/dist/core/RequestQueue.d.ts.map +1 -1
  77. package/dist/core/index.d.ts +0 -1
  78. package/dist/core/index.d.ts.map +1 -1
  79. package/dist/data-manager/DataManager.d.ts +1 -0
  80. package/dist/data-manager/DataManager.d.ts.map +1 -1
  81. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  82. package/dist/device/Device.d.ts +1 -1
  83. package/dist/device/Device.d.ts.map +1 -1
  84. package/dist/device/DeviceCommands.d.ts.map +1 -1
  85. package/dist/device/DeviceFeaturesState.d.ts +0 -1
  86. package/dist/device/DeviceFeaturesState.d.ts.map +1 -1
  87. package/dist/device/DeviceStateMapper.d.ts.map +1 -1
  88. package/dist/device/DeviceStateProjector.d.ts.map +1 -1
  89. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  90. package/dist/events/call.d.ts +0 -7
  91. package/dist/events/call.d.ts.map +1 -1
  92. package/dist/events/core.d.ts +2 -2
  93. package/dist/events/core.d.ts.map +1 -1
  94. package/dist/events/iframe.d.ts +0 -1
  95. package/dist/events/iframe.d.ts.map +1 -1
  96. package/dist/events/logBlockEvent.d.ts.map +1 -1
  97. package/dist/index.d.ts +320 -277
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +3210 -1856
  100. package/dist/inject.d.ts +2 -3
  101. package/dist/inject.d.ts.map +1 -1
  102. package/dist/lowLevelInject.d.ts +1 -2
  103. package/dist/lowLevelInject.d.ts.map +1 -1
  104. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
  105. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +4 -0
  106. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
  107. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
  108. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  109. package/dist/topLevelInject.d.ts.map +1 -1
  110. package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -0
  111. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  112. package/dist/types/api/deviceSettings.d.ts +2 -2
  113. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  114. package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
  115. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  116. package/dist/types/api/export.d.ts +4 -1
  117. package/dist/types/api/export.d.ts.map +1 -1
  118. package/dist/types/api/firmwareUpdate.d.ts +69 -0
  119. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  120. package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
  121. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
  122. package/dist/types/api/firmwareUpdatePlan.d.ts +27 -0
  123. package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
  124. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
  125. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
  126. package/dist/types/api/index.d.ts +10 -23
  127. package/dist/types/api/index.d.ts.map +1 -1
  128. package/dist/types/api/openWalletSession.d.ts +1 -0
  129. package/dist/types/api/openWalletSession.d.ts.map +1 -1
  130. package/dist/types/api/protocolV2.d.ts +3 -84
  131. package/dist/types/api/protocolV2.d.ts.map +1 -1
  132. package/dist/types/api/sessionCache.d.ts +4 -1
  133. package/dist/types/api/sessionCache.d.ts.map +1 -1
  134. package/dist/types/device.d.ts +4 -4
  135. package/dist/types/device.d.ts.map +1 -1
  136. package/dist/types/settings.d.ts +13 -0
  137. package/dist/types/settings.d.ts.map +1 -1
  138. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  139. package/dist/utils/deviceSettings.d.ts +36 -7
  140. package/dist/utils/deviceSettings.d.ts.map +1 -1
  141. package/dist/utils/index.d.ts +2 -1
  142. package/dist/utils/index.d.ts.map +1 -1
  143. package/dist/utils/patch.d.ts +1 -1
  144. package/dist/utils/patch.d.ts.map +1 -1
  145. package/package.json +4 -4
  146. package/src/api/BaseMethod.ts +11 -12
  147. package/src/api/CheckAllFirmwareRelease.ts +16 -3
  148. package/src/api/ClearSessionCache.ts +4 -0
  149. package/src/api/FirmwareUpdate.ts +8 -1
  150. package/src/api/FirmwareUpdateV2.ts +284 -119
  151. package/src/api/FirmwareUpdateV3.ts +248 -55
  152. package/src/api/FirmwareUpdateV4.ts +816 -328
  153. package/src/api/OpenWalletSession.ts +74 -25
  154. package/src/api/UploadPortfolio.ts +3 -13
  155. package/src/api/conflux/ConfluxGetAddress.ts +2 -0
  156. package/src/api/conflux/ConfluxSignMessage.ts +2 -0
  157. package/src/api/conflux/ConfluxSignMessageCIP23.ts +2 -0
  158. package/src/api/conflux/ConfluxSignTransaction.ts +2 -0
  159. package/src/api/device/DeviceChangePin.ts +1 -1
  160. package/src/api/device/DeviceSettings.ts +66 -5
  161. package/src/api/device/DeviceUpdateBootloader.ts +114 -6
  162. package/src/api/device/DeviceWipe.ts +1 -1
  163. package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
  164. package/src/api/firmware/FirmwareHostBinding.ts +100 -0
  165. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +50 -0
  166. package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
  167. package/src/api/firmware/FirmwareUpdatePlan.ts +621 -0
  168. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +378 -0
  169. package/src/api/firmware/updateBootloader.ts +19 -4
  170. package/src/api/firmware/uploadFirmware.ts +140 -22
  171. package/src/api/helpers/protocolV2FileWrite.ts +6 -0
  172. package/src/api/index.ts +0 -21
  173. package/src/api/nexa/NexaSignTransaction.ts +2 -0
  174. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
  175. package/src/core/RequestQueue.ts +4 -123
  176. package/src/core/index.ts +25 -31
  177. package/src/data/messages/messages-protocol-v2.json +77 -4
  178. package/src/data-manager/DataManager.ts +33 -33
  179. package/src/data-manager/connectSettings.ts +11 -0
  180. package/src/device/Device.ts +51 -61
  181. package/src/device/DeviceCommands.ts +58 -14
  182. package/src/device/DeviceFeaturesState.ts +0 -9
  183. package/src/device/DeviceStateMapper.ts +26 -8
  184. package/src/device/DeviceStateProjector.ts +7 -1
  185. package/src/deviceProfile/buildDeviceFeatures.ts +2 -1
  186. package/src/events/call.ts +0 -6
  187. package/src/events/core.ts +0 -2
  188. package/src/events/iframe.ts +0 -1
  189. package/src/events/logBlockEvent.ts +1 -0
  190. package/src/index.ts +5 -4
  191. package/src/inject.ts +22 -35
  192. package/src/lowLevelInject.ts +5 -4
  193. package/src/protocols/protocol-v2/deviceSession.ts +1 -1
  194. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +2 -2
  195. package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
  196. package/src/protocols/protocol-v2/unlockRetry.ts +1 -3
  197. package/src/protocols/protocol-v2/walletSession.ts +68 -12
  198. package/src/topLevelInject.ts +5 -3
  199. package/src/types/api/checkAllFirmwareRelease.ts +3 -0
  200. package/src/types/api/deviceSettings.ts +17 -2
  201. package/src/types/api/deviceUpdateBootloader.ts +6 -0
  202. package/src/types/api/export.ts +18 -0
  203. package/src/types/api/firmwareUpdate.ts +76 -0
  204. package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
  205. package/src/types/api/firmwareUpdatePlan.ts +36 -0
  206. package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
  207. package/src/types/api/index.ts +14 -41
  208. package/src/types/api/openWalletSession.ts +2 -0
  209. package/src/types/api/protocolV2.ts +3 -187
  210. package/src/types/api/sessionCache.ts +9 -4
  211. package/src/types/device.ts +5 -3
  212. package/src/types/settings.ts +13 -0
  213. package/src/utils/deviceFeaturesUtils.ts +5 -1
  214. package/src/utils/deviceSettings.ts +130 -56
  215. package/src/utils/index.ts +18 -1
  216. package/__tests__/RequestQueue.test.ts +0 -140
  217. package/__tests__/UploadPortfolio.test.ts +0 -46
  218. package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +0 -6
  219. package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +0 -1
  220. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +0 -16
  221. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +0 -1
  222. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +0 -12
  223. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +0 -1
  224. package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -18
  225. package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -70
  226. package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -44
@@ -1,27 +1,7 @@
1
1
  import type {
2
- deviceFactoryInfoGet,
3
- deviceFactoryInfoSet,
4
- deviceFirmwareUpdate,
5
- deviceGetFirmwareUpdateStatus,
6
2
  deviceGetOnboardingStatus,
7
- deviceInfoGet,
8
3
  deviceReboot,
9
- deviceSettingsGet,
10
- deviceSettingsPageShow,
11
- deviceSettingsSet,
12
- deviceStatusGet,
13
4
  deviceUploadWallpaper,
14
- dirList,
15
- dirMake,
16
- dirRemove,
17
- fileDelete,
18
- fileRead,
19
- fileWrite,
20
- filesystemFormat,
21
- filesystemPermissionFix,
22
- pathInfo,
23
- ping,
24
- protocolInfoRequest,
25
5
  uploadPortfolio,
26
6
  } from './protocolV2';
27
7
  import type { off, on, removeAllListeners } from './event';
@@ -49,7 +29,15 @@ import type {
49
29
  firmwareUpdateV2,
50
30
  firmwareUpdateV3,
51
31
  firmwareUpdateV4,
32
+ getFirmwareUpdateHostBindingGeneration,
33
+ registerFirmwareUpdateHostBinding,
34
+ unregisterFirmwareUpdateHostBinding,
52
35
  } from './firmwareUpdate';
36
+ import type { getFirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
37
+ import type {
38
+ prepareFirmwareUpdatePlan,
39
+ validateFirmwareUpdatePreparedPlan,
40
+ } from './firmwareUpdatePreparedPlan';
53
41
  import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
54
42
  import type { deviceReset } from './deviceReset';
55
43
  import type { deviceRecovery } from './deviceRecovery';
@@ -183,7 +171,6 @@ export type CoreApi = {
183
171
  call: (params: any) => Promise<any>;
184
172
  uiResponse: typeof uiResponse;
185
173
  cancel: (connectId?: string) => void;
186
- cancelOperation: (operationId: string) => void;
187
174
  updateSettings: typeof updateSettings;
188
175
  switchTransport: (env: ConnectSettings['env']) => Promise<{ success: boolean }>;
189
176
  getLogs: typeof getLogs;
@@ -240,6 +227,12 @@ export type CoreApi = {
240
227
  firmwareUpdateV2: typeof firmwareUpdateV2;
241
228
  firmwareUpdateV3: typeof firmwareUpdateV3;
242
229
  firmwareUpdateV4: typeof firmwareUpdateV4;
230
+ registerFirmwareUpdateHostBinding: typeof registerFirmwareUpdateHostBinding;
231
+ unregisterFirmwareUpdateHostBinding: typeof unregisterFirmwareUpdateHostBinding;
232
+ getFirmwareUpdateHostBindingGeneration: typeof getFirmwareUpdateHostBindingGeneration;
233
+ getFirmwareUpdateCapabilities: typeof getFirmwareUpdateCapabilities;
234
+ prepareFirmwareUpdatePlan: typeof prepareFirmwareUpdatePlan;
235
+ validateFirmwareUpdatePreparedPlan: typeof validateFirmwareUpdatePreparedPlan;
243
236
  cipherKeyValue: typeof cipherKeyValue;
244
237
 
245
238
  /**
@@ -248,27 +241,7 @@ export type CoreApi = {
248
241
  deviceReboot: typeof deviceReboot;
249
242
  deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
250
243
  deviceUploadWallpaper: typeof deviceUploadWallpaper;
251
- deviceInfoGet: typeof deviceInfoGet;
252
- deviceStatusGet: typeof deviceStatusGet;
253
- deviceSettingsGet: typeof deviceSettingsGet;
254
- protocolInfoRequest: typeof protocolInfoRequest;
255
- ping: typeof ping;
256
- deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
257
- deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
258
- deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
259
- deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
260
- deviceSettingsSet: typeof deviceSettingsSet;
261
- deviceSettingsPageShow: typeof deviceSettingsPageShow;
262
- filesystemPermissionFix: typeof filesystemPermissionFix;
263
- filesystemFormat: typeof filesystemFormat;
264
244
  uploadPortfolio: typeof uploadPortfolio;
265
- fileRead: typeof fileRead;
266
- fileWrite: typeof fileWrite;
267
- fileDelete: typeof fileDelete;
268
- dirList: typeof dirList;
269
- dirMake: typeof dirMake;
270
- dirRemove: typeof dirRemove;
271
- pathInfo: typeof pathInfo;
272
245
 
273
246
  /**
274
247
  * All network function
@@ -40,6 +40,8 @@ type OpenWalletSessionPayloadBase = {
40
40
  protocol: 'V1' | 'V2';
41
41
  deviceId: string;
42
42
  resumed: boolean;
43
+ /** Forwarded only when the firmware response contains a wallet session id. */
44
+ sessionId?: string;
43
45
  };
44
46
 
45
47
  export type OpenWalletSessionPayload = OpenWalletSessionPayloadBase &
@@ -1,47 +1,13 @@
1
1
  import type { CommonParams, Response } from '../params';
2
- import type {
3
- DevOnboardingStatus,
4
- DeviceFactoryInfo,
5
- DeviceFirmwareUpdateStatus,
6
- DeviceSettings,
7
- DeviceStatus,
8
- ProtocolInfo,
9
- ProtocolV2DeviceInfo,
10
- Success,
11
- } from '@onekeyfe/hd-transport';
12
- import type {
13
- DeviceFactoryInfoSetParams,
14
- DeviceFirmwareUpdateParams,
15
- DeviceFirmwareUpdateStatusGetParams,
16
- DeviceRebootParams,
17
- } from '../../api/protocol-v2/helpers';
18
- import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
19
- import type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
20
- import type { DeviceSettingsPageShowParams } from '../../api/protocol-v2/DeviceSettingsPageShow';
2
+ import type { DevOnboardingStatus, Success } from '@onekeyfe/hd-transport';
3
+ import type { DeviceRebootParams } from '../../api/protocol-v2/helpers';
21
4
  import type {
22
5
  DeviceUploadWallpaperParams,
23
6
  DeviceUploadWallpaperResponse,
24
7
  } from '../../api/protocol-v2/DeviceUploadWallpaper';
25
8
 
26
9
  // Re-export implementation parameter types as the single source of truth.
27
- export type {
28
- DeviceFirmwareTargetInput,
29
- DeviceFirmwareUpdateParams,
30
- DeviceFirmwareUpdateStatusGetParams,
31
- DeviceRebootParams,
32
- DeviceFactoryInfoSetParams,
33
- RebootTypeInput,
34
- } from '../../api/protocol-v2/helpers';
35
- export type {
36
- DeviceInfoGetParams,
37
- DeviceInfoGetTargets,
38
- DeviceInfoGetTypes,
39
- } from '../../api/protocol-v2/DeviceInfoGet';
40
- export type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
41
- export type {
42
- DeviceSettingsPageShowParams,
43
- SupportedDeviceSettingsPage,
44
- } from '../../api/protocol-v2/DeviceSettingsPageShow';
10
+ export type { DeviceRebootParams, RebootTypeInput } from '../../api/protocol-v2/helpers';
45
11
  export type {
46
12
  DeviceUploadWallpaperParams,
47
13
  DeviceUploadWallpaperResponse,
@@ -49,8 +15,6 @@ export type {
49
15
 
50
16
  // ── Shared response shapes (Protocol V2 file system) ────────────────────
51
17
 
52
- export type FileOpSuccess = { message?: string };
53
-
54
18
  export type FileInfo = {
55
19
  path: string;
56
20
  offset: number;
@@ -61,60 +25,8 @@ export type FileInfo = {
61
25
  chunks?: number;
62
26
  };
63
27
 
64
- export type DirInfo = {
65
- path: string;
66
- child_dirs?: string;
67
- child_files?: string;
68
- };
69
-
70
- // All FilesystemPathInfo proto fields are required; keep this type aligned.
71
- export type PathInfoResult = {
72
- exist: boolean;
73
- size: number;
74
- year: number;
75
- month: number;
76
- day: number;
77
- hour: number;
78
- minute: number;
79
- second: number;
80
- readonly: boolean;
81
- hidden: boolean;
82
- system: boolean;
83
- archive: boolean;
84
- directory: boolean;
85
- };
86
-
87
28
  // ── Method signatures ─────────────────────────────────────────────────────
88
29
 
89
- /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
90
- export declare function deviceInfoGet(
91
- connectId: string,
92
- params?: CommonParams & DeviceInfoGetParams
93
- ): Response<ProtocolV2DeviceInfo>;
94
-
95
- /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
96
- export declare function deviceStatusGet(
97
- connectId: string,
98
- params?: CommonParams
99
- ): Response<DeviceStatus>;
100
-
101
- /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
102
- export declare function deviceSettingsGet(
103
- connectId: string,
104
- params?: CommonParams
105
- ): Response<DeviceSettings>;
106
-
107
- /** @deprecated Development-only raw Protocol V2 command. */
108
- export declare function protocolInfoRequest(
109
- connectId: string,
110
- params?: CommonParams
111
- ): Response<ProtocolInfo>;
112
-
113
- export declare function ping(
114
- connectId: string,
115
- params?: CommonParams & { message?: string }
116
- ): Response<Success>;
117
-
118
30
  export declare function deviceReboot(
119
31
  connectId: string,
120
32
  params: CommonParams & DeviceRebootParams
@@ -125,111 +37,15 @@ export declare function deviceGetOnboardingStatus(
125
37
  params?: CommonParams
126
38
  ): Response<DevOnboardingStatus>;
127
39
 
128
- export declare function deviceFirmwareUpdate(
129
- connectId: string,
130
- params: CommonParams & DeviceFirmwareUpdateParams
131
- ): Response<Success | DeviceFirmwareUpdateStatus>;
132
-
133
- export declare function deviceGetFirmwareUpdateStatus(
134
- connectId: string,
135
- params?: CommonParams & DeviceFirmwareUpdateStatusGetParams
136
- ): Response<DeviceFirmwareUpdateStatus>;
137
-
138
- export declare function deviceFactoryInfoSet(
139
- connectId: string,
140
- params: CommonParams & DeviceFactoryInfoSetParams
141
- ): Response<Success>;
142
-
143
- export declare function deviceFactoryInfoGet(
144
- connectId: string,
145
- params?: CommonParams
146
- ): Response<DeviceFactoryInfo>;
147
-
148
- /**
149
- * @deprecated Use the protocol-independent `deviceSettings`.
150
- */
151
- export declare function deviceSettingsSet(
152
- connectId: string,
153
- params: CommonParams & DeviceSettingsSetParams
154
- ): Response<Success>;
155
-
156
- /**
157
- * @deprecated Use `deviceSettings`, `deviceChangePin`, or `deviceWipe`.
158
- */
159
- export declare function deviceSettingsPageShow(
160
- connectId: string,
161
- params: CommonParams & DeviceSettingsPageShowParams
162
- ): Response<Success>;
163
-
164
40
  export declare function deviceUploadWallpaper(
165
41
  connectId: string,
166
42
  params: CommonParams & DeviceUploadWallpaperParams
167
43
  ): Response<DeviceUploadWallpaperResponse>;
168
44
 
169
- export declare function filesystemPermissionFix(
170
- connectId: string,
171
- params?: CommonParams
172
- ): Response<Success>;
173
-
174
- export declare function fileRead(
175
- connectId: string,
176
- params: {
177
- path: string;
178
- offset?: number;
179
- totalSize?: number;
180
- chunkLen?: number;
181
- uiPercentage?: number;
182
- }
183
- ): Response<FileInfo>;
184
-
185
- export declare function fileWrite(
186
- connectId: string,
187
- params: {
188
- path: string;
189
- offset?: number;
190
- totalSize?: number;
191
- chunkSize?: number;
192
- chunkLen?: number;
193
- data: ArrayBuffer | Uint8Array | Blob | string;
194
- overwrite?: boolean;
195
- append?: boolean;
196
- uiPercentage?: number;
197
- timeoutMs?: number | string;
198
- }
199
- ): Response<FileInfo>;
200
-
201
- export declare function fileDelete(
202
- connectId: string,
203
- params: { path: string }
204
- ): Response<FileOpSuccess>;
205
-
206
- export declare function dirList(
207
- connectId: string,
208
- params: { path: string; depth?: number }
209
- ): Response<DirInfo>;
210
-
211
- export declare function dirMake(
212
- connectId: string,
213
- params: { path: string }
214
- ): Response<FileOpSuccess>;
215
-
216
- export declare function dirRemove(
217
- connectId: string,
218
- params: { path: string }
219
- ): Response<FileOpSuccess>;
220
-
221
- export declare function pathInfo(
222
- connectId: string,
223
- params: { path: string; timeoutMs?: number | string }
224
- ): Response<PathInfoResult>;
225
-
226
45
  export declare function uploadPortfolio(
227
46
  connectId: string,
228
47
  params: {
229
- operationId?: string;
230
48
  packageBytes: ArrayBuffer | Uint8Array | Blob;
231
49
  timeoutMs?: number | string;
232
50
  }
233
51
  ): Response<FileInfo & { portfolioUpdated: true }>;
234
-
235
- export declare function filesystemFormat(connectId: string): Response<Success>;
@@ -1,9 +1,14 @@
1
1
  import type { Response } from '../params';
2
2
 
3
- export type ClearSessionCacheParams = {
4
- deviceId?: string;
5
- passphraseState?: string;
6
- };
3
+ export type ClearSessionCacheParams =
4
+ | {
5
+ deviceId?: never;
6
+ passphraseState?: never;
7
+ }
8
+ | {
9
+ deviceId: string;
10
+ passphraseState?: string;
11
+ };
7
12
 
8
13
  export type ClearSessionCachePayload = {
9
14
  cleared: true;
@@ -3,6 +3,7 @@ import { EDeviceType, type EFirmwareType } from '@onekeyfe/hd-shared';
3
3
  import type { IVersionArray } from './settings';
4
4
  import type { PROTO } from '../constants';
5
5
  import type {
6
+ Enum_SafetyCheckLevel,
6
7
  OneKeyDeviceCommType,
7
8
  ProtocolV2DeviceInfo,
8
9
  DeviceStatus as ProtocolV2DeviceStatus,
@@ -164,7 +165,8 @@ export type DeviceStateUpdateSource =
164
165
  | 'initialize'
165
166
  | 'device-info'
166
167
  | 'device-status'
167
- | 'apply-settings'
168
+ | 'settings-read'
169
+ | 'settings-write'
168
170
  | 'change-pin'
169
171
  | 'lock'
170
172
  | 'unlock'
@@ -207,7 +209,7 @@ export type DeviceStateSettings = {
207
209
  sdProtection: boolean | null;
208
210
  wipeCodeProtection: boolean | null;
209
211
  passphraseAlwaysOnDevice: boolean | null;
210
- safetyChecks: string | null;
212
+ safetyChecks: Enum_SafetyCheckLevel | null;
211
213
  autoLockDelayMs: number | null;
212
214
  autoShutdownDelayMs: number | null;
213
215
  displayRotation: number | null;
@@ -306,7 +308,7 @@ export type NormalizedFeatures = {
306
308
  wipeCodeProtection: boolean | null;
307
309
  passphraseAlwaysOnDevice: boolean | null;
308
310
  attachToPinEnabled?: boolean | null;
309
- safetyChecks: string | null;
311
+ safetyChecks: Enum_SafetyCheckLevel | null;
310
312
  autoLockDelayMs: number | null;
311
313
  autoShutdownDelayMs: number | null;
312
314
  displayRotation: number | null;
@@ -31,6 +31,8 @@ export type ConnectSettings = {
31
31
  timestamp: number;
32
32
  isFrame?: boolean;
33
33
  preRelease?: boolean;
34
+ firmwareManifestMode?: 'sdk-managed' | 'external-only';
35
+ preloadedConfig?: RemoteConfigResponse;
34
36
  fetchConfig?: boolean;
35
37
  extension?: string;
36
38
  configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
@@ -55,6 +57,7 @@ export type IProtocolV2FirmwareComponent = {
55
57
  target: IProtocolV2FirmwareComponentTarget;
56
58
  url: string;
57
59
  fingerprint?: string;
60
+ expectedSize?: number;
58
61
  version?: IVersionArray;
59
62
  };
60
63
 
@@ -64,6 +67,8 @@ export type IProtocolV2ResourceBundle = {
64
67
  name: string;
65
68
  /** Download URL. */
66
69
  url: string;
70
+ fingerprint?: string;
71
+ expectedSize?: number;
67
72
  /** Device target path, such as vol0:/bundles/images/images.okpkg. */
68
73
  devicePath: string;
69
74
  /** okpkg payload_version used to skip matching content after FileRead. */
@@ -85,10 +90,16 @@ export type IFirmwareReleaseInfo = {
85
90
  firmwareType?: EFirmwareType;
86
91
  /** Firmware UI resource */
87
92
  resource?: string;
93
+ resourceFingerprint?: string;
94
+ resourceExpectedSize?: number;
88
95
  /** Firmware full UI resource */
89
96
  fullResource?: string;
97
+ fullResourceFingerprint?: string;
98
+ fullResourceExpectedSize?: number;
90
99
  fullResourceRange?: string[];
91
100
  bootloaderResource?: string;
101
+ bootloaderFingerprint?: string;
102
+ bootloaderExpectedSize?: number;
92
103
  bootloaderVersion?: IVersionArray;
93
104
  displayBootloaderVersion?: IVersionArray;
94
105
  bootloaderRelatedFirmwareVersion?: IVersionArray;
@@ -101,6 +112,7 @@ export type IFirmwareReleaseInfo = {
101
112
  [k in ILocale]: string;
102
113
  };
103
114
  fingerprint: string;
115
+ expectedSize?: number;
104
116
  version: IVersionArray;
105
117
  changelog: {
106
118
  [k in ILocale]: string;
@@ -116,6 +128,7 @@ export type IBLEFirmwareReleaseInfo = {
116
128
  webUpdate: string;
117
129
  fingerprint: string;
118
130
  fingerprintWeb: string;
131
+ expectedSize?: number;
119
132
  version: IVersionArray;
120
133
  changelog: {
121
134
  [k in ILocale]: string;
@@ -156,12 +156,16 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
156
156
 
157
157
  // Attach to pin try to fix internal state
158
158
  const deviceId = device.getCurrentDeviceId();
159
+ let existingSessionId: string | null | undefined;
160
+ if (!options?.initSession && typeof device.getInternalState === 'function') {
161
+ existingSessionId = device.getInternalState();
162
+ }
159
163
  device.updateInternalState(
160
164
  device.getCurrentPassphraseProtection() ?? false,
161
165
  passphraseState,
162
166
  deviceId,
163
167
  newSession,
164
- options?.initSession ? null : device.features?.sessionId
168
+ options?.initSession ? null : existingSessionId
165
169
  );
166
170
 
167
171
  return {
@@ -1,6 +1,52 @@
1
1
  import { EDeviceType } from '@onekeyfe/hd-shared';
2
+ import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
2
3
 
3
4
  import type { IDeviceType } from '../types';
5
+ import type { DeviceSettingsParams } from '../types/api/deviceSettings';
6
+ import type { SafetyCheckLevel } from '@onekeyfe/hd-transport';
7
+
8
+ export type DeviceSettingsProtocol = 'V1' | 'V2';
9
+ export type DeviceSettingsField = keyof DeviceSettingsParams;
10
+
11
+ export const DEVICE_SETTINGS_SHARED_FIELDS = [
12
+ 'language',
13
+ 'label',
14
+ 'usePassphrase',
15
+ 'autoLockDelayMs',
16
+ 'autoShutdownDelayMs',
17
+ 'hapticFeedback',
18
+ 'bluetoothEnabled',
19
+ ] as const satisfies readonly DeviceSettingsField[];
20
+
21
+ export const DEVICE_SETTINGS_V1_ONLY_FIELDS = [
22
+ 'homescreen',
23
+ 'passphraseSource',
24
+ 'displayRotation',
25
+ 'passphraseAlwaysOnDevice',
26
+ 'safetyChecks',
27
+ 'experimentalFeatures',
28
+ 'changeBrightness',
29
+ ] as const satisfies readonly DeviceSettingsField[];
30
+
31
+ export const DEVICE_SETTINGS_V2_ONLY_FIELDS = [
32
+ 'brightness',
33
+ 'airgapMode',
34
+ 'animationEnabled',
35
+ 'tapToWake',
36
+ 'deviceNameDisplayEnabled',
37
+ 'fidoEnabled',
38
+ 'usbLockEnabled',
39
+ 'randomKeypad',
40
+ ] as const satisfies readonly DeviceSettingsField[];
41
+
42
+ export const PROTOCOL_V2_NEVER_TIMEOUT_MS = 0x10000000;
43
+
44
+ export const normalizeSafetyCheckLevel = (
45
+ value: SafetyCheckLevel | null | undefined
46
+ ): Enum_SafetyCheckLevel | null | undefined => {
47
+ if (typeof value === 'number' || value === null || value === undefined) return value;
48
+ return Enum_SafetyCheckLevel[value];
49
+ };
4
50
 
5
51
  export const LANGUAGE_LABELS = {
6
52
  en: 'English',
@@ -36,6 +82,13 @@ export const PROTOCOL_V2_LANGUAGE_BY_KEY: Record<LanguageKey, string> = {
36
82
  export const mapLanguageToProtocolV2 = (language?: string) =>
37
83
  language ? PROTOCOL_V2_LANGUAGE_BY_KEY[language as LanguageKey] ?? language : undefined;
38
84
 
85
+ const PROTOCOL_V2_LANGUAGE_KEY_BY_TAG = Object.fromEntries(
86
+ Object.entries(PROTOCOL_V2_LANGUAGE_BY_KEY).map(([key, tag]) => [tag, key])
87
+ ) as Record<string, LanguageKey>;
88
+
89
+ export const mapLanguageFromProtocolV2 = (language?: string) =>
90
+ language ? PROTOCOL_V2_LANGUAGE_KEY_BY_TAG[language] ?? language : undefined;
91
+
39
92
  const PRO2_LANGUAGE_OPTIONS = [
40
93
  ...Object.entries(LANGUAGE_LABELS).map(([code, label]) => ({ code, label })),
41
94
  { code: 'zh-Hant-TW', label: '繁體中文(台灣)' },
@@ -73,85 +126,106 @@ export const getLanguageConfig = (deviceType: IDeviceType): Record<string, strin
73
126
  return keys.map(key => ({ code: key, label: LANGUAGE_LABELS[key] }));
74
127
  };
75
128
 
76
- export type DurationParts = {
77
- seconds: number;
78
- minute: number;
79
- hour: number;
80
- day: number;
129
+ export type DeviceSettingsDurationOption = {
130
+ label: string;
131
+ valueMs: number;
132
+ };
133
+
134
+ export type DeviceSettingsValueOption<T> = {
135
+ label: string;
136
+ value: T;
81
137
  };
82
138
 
83
- export const getAutoLockOptions = (_deviceType: IDeviceType): DurationParts[] => {
84
- switch (_deviceType) {
139
+ const durationOption = (valueMs: number): DeviceSettingsDurationOption => {
140
+ if (valueMs === 0 || valueMs === PROTOCOL_V2_NEVER_TIMEOUT_MS) {
141
+ return { label: 'Never', valueMs };
142
+ }
143
+ if (valueMs < 60_000) {
144
+ return { label: `${valueMs / 1000} seconds`, valueMs };
145
+ }
146
+ const minutes = valueMs / 60_000;
147
+ return { label: `${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`, valueMs };
148
+ };
149
+
150
+ const withNever = (
151
+ values: readonly number[],
152
+ protocol: DeviceSettingsProtocol
153
+ ): DeviceSettingsDurationOption[] =>
154
+ [...values, protocol === 'V2' ? PROTOCOL_V2_NEVER_TIMEOUT_MS : 0].map(durationOption);
155
+
156
+ export const getAutoLockOptions = (
157
+ deviceType: IDeviceType,
158
+ protocol: DeviceSettingsProtocol
159
+ ): DeviceSettingsDurationOption[] => {
160
+ switch (deviceType) {
85
161
  case EDeviceType.Mini:
86
162
  case EDeviceType.Classic:
87
163
  case EDeviceType.Classic1s:
88
164
  case EDeviceType.ClassicPure:
89
- return [
90
- { seconds: 0, minute: 1, hour: 0, day: 0 },
91
- { seconds: 0, minute: 2, hour: 0, day: 0 },
92
- { seconds: 0, minute: 5, hour: 0, day: 0 },
93
- { seconds: 0, minute: 10, hour: 0, day: 0 },
94
- { seconds: 0, minute: 0, hour: 0, day: 0 },
95
- ];
165
+ return withNever([60_000, 120_000, 300_000, 600_000], protocol);
96
166
  case EDeviceType.Touch:
97
167
  case EDeviceType.Pro:
98
- return [
99
- { seconds: 30, minute: 0, hour: 0, day: 0 },
100
- { seconds: 0, minute: 1, hour: 0, day: 0 },
101
- { seconds: 0, minute: 2, hour: 0, day: 0 },
102
- { seconds: 0, minute: 5, hour: 0, day: 0 },
103
- { seconds: 0, minute: 10, hour: 0, day: 0 },
104
- { seconds: 0, minute: 30, hour: 0, day: 0 },
105
- { seconds: 0, minute: 0, hour: 0, day: 0 },
106
- ];
107
168
  case EDeviceType.Pro2:
108
- return [
109
- { seconds: 30, minute: 0, hour: 0, day: 0 },
110
- { seconds: 0, minute: 1, hour: 0, day: 0 },
111
- { seconds: 0, minute: 2, hour: 0, day: 0 },
112
- { seconds: 0, minute: 5, hour: 0, day: 0 },
113
- { seconds: 0, minute: 10, hour: 0, day: 0 },
114
- { seconds: 0, minute: 30, hour: 0, day: 0 },
115
- { seconds: 0, minute: 0, hour: 0, day: 0 },
116
- ];
169
+ return withNever([30_000, 60_000, 120_000, 300_000, 600_000, 1_800_000], protocol);
117
170
  default:
118
171
  return [];
119
172
  }
120
173
  };
121
174
 
122
- export const getAutoShutDownOptions = (_deviceType: IDeviceType): DurationParts[] => {
123
- switch (_deviceType) {
175
+ export const getAutoShutDownOptions = (
176
+ deviceType: IDeviceType,
177
+ protocol: DeviceSettingsProtocol
178
+ ): DeviceSettingsDurationOption[] => {
179
+ switch (deviceType) {
124
180
  case EDeviceType.Mini:
125
181
  return [];
126
182
  case EDeviceType.Classic:
127
183
  case EDeviceType.Classic1s:
128
184
  case EDeviceType.ClassicPure:
129
- return [
130
- { seconds: 0, minute: 1, hour: 0, day: 0 },
131
- { seconds: 0, minute: 3, hour: 0, day: 0 },
132
- { seconds: 0, minute: 5, hour: 0, day: 0 },
133
- { seconds: 0, minute: 10, hour: 0, day: 0 },
134
- { seconds: 0, minute: 0, hour: 0, day: 0 },
135
- ];
185
+ return withNever([60_000, 180_000, 300_000, 600_000], protocol);
136
186
  case EDeviceType.Touch:
137
187
  case EDeviceType.Pro:
138
- return [
139
- { seconds: 0, minute: 1, hour: 0, day: 0 },
140
- { seconds: 0, minute: 2, hour: 0, day: 0 },
141
- { seconds: 0, minute: 5, hour: 0, day: 0 },
142
- { seconds: 0, minute: 10, hour: 0, day: 0 },
143
- { seconds: 0, minute: 0, hour: 0, day: 0 },
144
- ];
188
+ return withNever([60_000, 120_000, 300_000, 600_000], protocol);
145
189
  case EDeviceType.Pro2:
146
- return [
147
- { seconds: 0, minute: 1, hour: 0, day: 0 },
148
- { seconds: 0, minute: 2, hour: 0, day: 0 },
149
- { seconds: 0, minute: 5, hour: 0, day: 0 },
150
- { seconds: 0, minute: 10, hour: 0, day: 0 },
151
- { seconds: 0, minute: 30, hour: 0, day: 0 },
152
- { seconds: 0, minute: 0, hour: 0, day: 0 },
153
- ];
190
+ return withNever([60_000, 120_000, 300_000, 600_000, 1_800_000], protocol);
154
191
  default:
155
192
  return [];
156
193
  }
157
194
  };
195
+
196
+ export type DeviceSettingsCapabilities = {
197
+ protocol: DeviceSettingsProtocol;
198
+ supportedFields: readonly DeviceSettingsField[];
199
+ languageOptions: ReadonlyArray<Record<string, string>>;
200
+ autoLockDelayOptions: readonly DeviceSettingsDurationOption[];
201
+ autoShutdownDelayOptions: readonly DeviceSettingsDurationOption[];
202
+ ranges: {
203
+ brightness?: { min: number; max: number };
204
+ };
205
+ safetyCheckOptions: ReadonlyArray<DeviceSettingsValueOption<Enum_SafetyCheckLevel>>;
206
+ onDeviceConfirmationFields: readonly DeviceSettingsField[];
207
+ };
208
+
209
+ export const getDeviceSettingsCapabilities = (
210
+ deviceType: IDeviceType,
211
+ protocol: DeviceSettingsProtocol
212
+ ): DeviceSettingsCapabilities => ({
213
+ protocol,
214
+ supportedFields:
215
+ protocol === 'V2'
216
+ ? [...DEVICE_SETTINGS_SHARED_FIELDS, ...DEVICE_SETTINGS_V2_ONLY_FIELDS]
217
+ : [...DEVICE_SETTINGS_SHARED_FIELDS, ...DEVICE_SETTINGS_V1_ONLY_FIELDS],
218
+ languageOptions: getLanguageConfig(deviceType),
219
+ autoLockDelayOptions: getAutoLockOptions(deviceType, protocol),
220
+ autoShutdownDelayOptions: getAutoShutDownOptions(deviceType, protocol),
221
+ ranges: protocol === 'V2' ? { brightness: { min: 10, max: 100 } } : {},
222
+ safetyCheckOptions:
223
+ protocol === 'V1'
224
+ ? [
225
+ { label: 'Strict', value: Enum_SafetyCheckLevel.Strict },
226
+ { label: 'Prompt Always', value: Enum_SafetyCheckLevel.PromptAlways },
227
+ { label: 'Prompt Temporarily', value: Enum_SafetyCheckLevel.PromptTemporarily },
228
+ ]
229
+ : [],
230
+ onDeviceConfirmationFields: protocol === 'V2' ? ['usePassphrase', 'airgapMode'] : [],
231
+ });