@onekeyfe/hd-core 1.2.0-alpha.52 → 1.2.0-alpha.53

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 (251) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +78 -0
  2. package/__tests__/DeviceCommands.test.ts +45 -0
  3. package/__tests__/DeviceEventRegistration.test.ts +6 -0
  4. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
  5. package/__tests__/connectSettings.test.ts +5 -47
  6. package/__tests__/device-lifecycle-events.test.ts +105 -3
  7. package/__tests__/deviceUploadNft.test.ts +293 -0
  8. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
  9. package/__tests__/get-device-state.test.ts +132 -12
  10. package/__tests__/homescreen.test.ts +41 -1
  11. package/__tests__/logBlockEvent.test.ts +1 -1
  12. package/__tests__/method-protocol-support.test.ts +19 -0
  13. package/__tests__/open-wallet-session.test.ts +446 -33
  14. package/__tests__/pro2Nft.test.ts +108 -0
  15. package/__tests__/protocol-binding.test.ts +89 -0
  16. package/__tests__/protocol-v2-resources.test.ts +284 -0
  17. package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
  18. package/__tests__/protocol-v2-unlock-policy.test.ts +201 -35
  19. package/__tests__/protocol-v2.test.ts +1349 -1005
  20. package/__tests__/protocolV2UiInteraction.test.ts +63 -0
  21. package/__tests__/public-pro2-api-boundary.test.ts +1 -0
  22. package/__tests__/search-devices.test.ts +12 -3
  23. package/__tests__/uiProgressThrottle.test.ts +74 -0
  24. package/__tests__/uiPromiseRegistry.test.ts +86 -0
  25. package/dist/api/BaseMethod.d.ts +3 -1
  26. package/dist/api/BaseMethod.d.ts.map +1 -1
  27. package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
  28. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  29. package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
  30. package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
  31. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  32. package/dist/api/FirmwareUpdateV2.d.ts +0 -11
  33. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  34. package/dist/api/FirmwareUpdateV3.d.ts +3 -7
  35. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  36. package/dist/api/FirmwareUpdateV4.d.ts +11 -25
  37. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  38. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  39. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  40. package/dist/api/SearchDevices.d.ts.map +1 -1
  41. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  42. package/dist/api/device/DeviceUnlock.d.ts +2 -2
  43. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  44. package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
  45. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  46. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -9
  47. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  48. package/dist/api/firmware/getBinary.d.ts +0 -7
  49. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  50. package/dist/api/firmware/updateBootloader.d.ts +0 -2
  51. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  52. package/dist/api/firmware/uploadFirmware.d.ts +1 -9
  53. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  54. package/dist/api/helpers/protocolV2FileWrite.d.ts +2 -0
  55. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  56. package/dist/api/index.d.ts +2 -0
  57. package/dist/api/index.d.ts.map +1 -1
  58. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
  59. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
  60. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  61. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  62. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  63. package/dist/core/deviceEventRegistration.d.ts +2 -0
  64. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/core/uiPromiseRegistry.d.ts +4 -0
  67. package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
  68. package/dist/data-manager/DataManager.d.ts +4 -2
  69. package/dist/data-manager/DataManager.d.ts.map +1 -1
  70. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  71. package/dist/device/Device.d.ts +29 -6
  72. package/dist/device/Device.d.ts.map +1 -1
  73. package/dist/device/DeviceCommands.d.ts +4 -4
  74. package/dist/device/DeviceCommands.d.ts.map +1 -1
  75. package/dist/device/DevicePool.d.ts.map +1 -1
  76. package/dist/events/device.d.ts +4 -0
  77. package/dist/events/device.d.ts.map +1 -1
  78. package/dist/events/logBlockEvent.d.ts.map +1 -1
  79. package/dist/events/ui-promise.d.ts +4 -2
  80. package/dist/events/ui-promise.d.ts.map +1 -1
  81. package/dist/events/ui-request.d.ts +31 -2
  82. package/dist/events/ui-request.d.ts.map +1 -1
  83. package/dist/events/ui-response.d.ts +10 -2
  84. package/dist/events/ui-response.d.ts.map +1 -1
  85. package/dist/index.d.ts +214 -231
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +2559 -3497
  88. package/dist/inject.d.ts +6 -1
  89. package/dist/inject.d.ts.map +1 -1
  90. package/dist/lowLevelInject.d.ts.map +1 -1
  91. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  92. package/dist/protocols/protocol-v2/resources.d.ts +30 -0
  93. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
  94. package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
  95. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  96. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
  97. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  98. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
  99. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
  100. package/dist/protocols/protocol-v2/walletSession.d.ts +5 -1
  101. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  102. package/dist/topLevelInject.d.ts.map +1 -1
  103. package/dist/types/api/checkAllFirmwareRelease.d.ts +2 -4
  104. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  105. package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
  106. package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
  107. package/dist/types/api/deviceUnlock.d.ts +5 -1
  108. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  109. package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
  110. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  111. package/dist/types/api/export.d.ts +2 -4
  112. package/dist/types/api/export.d.ts.map +1 -1
  113. package/dist/types/api/firmwareUpdate.d.ts +2 -70
  114. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  115. package/dist/types/api/index.d.ts +7 -10
  116. package/dist/types/api/index.d.ts.map +1 -1
  117. package/dist/types/api/protocolV2.d.ts +3 -0
  118. package/dist/types/api/protocolV2.d.ts.map +1 -1
  119. package/dist/types/device.d.ts.map +1 -1
  120. package/dist/types/params.d.ts +1 -0
  121. package/dist/types/params.d.ts.map +1 -1
  122. package/dist/types/settings.d.ts +22 -13
  123. package/dist/types/settings.d.ts.map +1 -1
  124. package/dist/utils/deviceFeaturesCompat.d.ts +0 -1
  125. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  126. package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
  127. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  128. package/dist/utils/homescreen.d.ts +4 -0
  129. package/dist/utils/homescreen.d.ts.map +1 -1
  130. package/dist/utils/index.d.ts +1 -1
  131. package/dist/utils/index.d.ts.map +1 -1
  132. package/dist/utils/patch.d.ts +1 -1
  133. package/dist/utils/patch.d.ts.map +1 -1
  134. package/dist/utils/pro2Nft.d.ts +31 -0
  135. package/dist/utils/pro2Nft.d.ts.map +1 -0
  136. package/dist/utils/pro2Wallpaper.d.ts +10 -0
  137. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  138. package/dist/utils/uiProgressThrottle.d.ts +3 -0
  139. package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
  140. package/package.json +4 -4
  141. package/src/api/BaseMethod.ts +8 -10
  142. package/src/api/CheckAllFirmwareRelease.ts +54 -57
  143. package/src/api/DetectDeviceConnectProtocol.ts +18 -0
  144. package/src/api/FirmwareUpdate.ts +7 -15
  145. package/src/api/FirmwareUpdateV2.ts +126 -316
  146. package/src/api/FirmwareUpdateV3.ts +63 -265
  147. package/src/api/FirmwareUpdateV4.ts +566 -965
  148. package/src/api/GetPassphraseState.ts +7 -1
  149. package/src/api/OpenWalletSession.ts +54 -17
  150. package/src/api/SearchDevices.ts +3 -1
  151. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +32 -11
  152. package/src/api/device/DeviceUnlock.ts +8 -3
  153. package/src/api/device/DeviceUpdateBootloader.ts +6 -122
  154. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +16 -83
  155. package/src/api/firmware/updateBootloader.ts +4 -19
  156. package/src/api/firmware/uploadFirmware.ts +39 -144
  157. package/src/api/helpers/protocolV2FileWrite.ts +11 -4
  158. package/src/api/index.ts +2 -0
  159. package/src/api/protocol-v2/DeviceUploadNft.ts +189 -0
  160. package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
  161. package/src/api/protocol-v2/helpers.ts +1 -0
  162. package/src/core/deviceEventRegistration.ts +4 -0
  163. package/src/core/index.ts +167 -83
  164. package/src/core/uiPromiseRegistry.ts +41 -0
  165. package/src/data/messages/messages-protocol-v2.json +25 -0
  166. package/src/data-manager/DataManager.ts +67 -38
  167. package/src/data-manager/connectSettings.ts +0 -11
  168. package/src/device/Device.ts +258 -42
  169. package/src/device/DeviceCommands.ts +7 -1
  170. package/src/device/DevicePool.ts +7 -2
  171. package/src/events/device.ts +4 -0
  172. package/src/events/logBlockEvent.ts +1 -0
  173. package/src/events/ui-promise.ts +4 -2
  174. package/src/events/ui-request.ts +36 -2
  175. package/src/events/ui-response.ts +12 -2
  176. package/src/index.ts +0 -5
  177. package/src/inject.ts +60 -24
  178. package/src/lowLevelInject.ts +7 -8
  179. package/src/protocols/protocol-v2/features.ts +10 -3
  180. package/src/protocols/protocol-v2/resources.ts +359 -0
  181. package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
  182. package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
  183. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +118 -0
  184. package/src/protocols/protocol-v2/walletSession.ts +180 -30
  185. package/src/topLevelInject.ts +7 -8
  186. package/src/types/api/checkAllFirmwareRelease.ts +2 -4
  187. package/src/types/api/detectDeviceConnectProtocol.ts +7 -0
  188. package/src/types/api/deviceUnlock.ts +12 -1
  189. package/src/types/api/deviceUpdateBootloader.ts +0 -6
  190. package/src/types/api/export.ts +1 -18
  191. package/src/types/api/firmwareUpdate.ts +3 -76
  192. package/src/types/api/index.ts +13 -14
  193. package/src/types/api/protocolV2.ts +13 -0
  194. package/src/types/device.ts +3 -0
  195. package/src/types/params.ts +7 -1
  196. package/src/types/settings.ts +42 -13
  197. package/src/utils/deviceFeaturesCompat.ts +0 -6
  198. package/src/utils/deviceFeaturesUtils.ts +8 -0
  199. package/src/utils/homescreen.ts +32 -6
  200. package/src/utils/index.ts +6 -1
  201. package/src/utils/pro2Nft.ts +142 -0
  202. package/src/utils/pro2Wallpaper.ts +35 -8
  203. package/src/utils/uiProgressThrottle.ts +63 -0
  204. package/__tests__/device-initialize-timeout.test.ts +0 -56
  205. package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
  206. package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
  207. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
  208. package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
  209. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +0 -200
  210. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
  211. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +0 -294
  212. package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
  213. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -213
  214. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -58
  215. package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
  216. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
  217. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
  218. package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
  219. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
  220. package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
  221. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
  222. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
  223. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
  224. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
  225. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
  226. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -32
  227. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
  228. package/dist/api/firmware/progressThrottle.d.ts +0 -3
  229. package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
  230. package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
  231. package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
  232. package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
  233. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
  234. package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
  235. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
  236. package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
  237. package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
  238. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
  239. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
  240. package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
  241. package/src/api/firmware/FirmwareHostBinding.ts +0 -100
  242. package/src/api/firmware/FirmwarePreparationError.ts +0 -12
  243. package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
  244. package/src/api/firmware/FirmwareUpdatePlan.ts +0 -772
  245. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -415
  246. package/src/api/firmware/progressThrottle.ts +0 -44
  247. package/src/protocols/protocol-v2/lockedError.ts +0 -10
  248. package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
  249. package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
  250. package/src/types/api/firmwareUpdatePlan.ts +0 -38
  251. package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
@@ -1,4 +1,5 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
3
 
3
4
  import { UI_REQUEST } from '../constants/ui-request';
4
5
  import { refreshProtocolV2DeviceStatus } from '../protocols/protocol-v2/walletSession';
@@ -24,7 +25,12 @@ export default class GetPassphraseState extends BaseMethod {
24
25
  if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
25
26
  const features = await refreshProtocolV2DeviceStatus(this.device);
26
27
  if (features.unlocked === false) {
27
- await this.device.unlockDevice();
28
+ await this.device.unlockDevice(DeviceSessionPinType.Main, {
29
+ source: 'unlock-coordinator',
30
+ reason: 'device-locked',
31
+ deviceOnly: true,
32
+ method: 'getPassphraseState',
33
+ });
28
34
  }
29
35
  }
30
36
  const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
@@ -1,4 +1,5 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
3
 
3
4
  import { deviceWalletSessionStore } from '../device/DeviceWalletSessionStore';
4
5
  import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
@@ -90,23 +91,40 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
90
91
 
91
92
  async run(): Promise<OpenWalletSessionPayload> {
92
93
  const isProtocolV2 = this.device.isProtocolV2();
93
- const state = await this.device.getDeviceState({ refreshSections: ['status'] });
94
+ let state = await this.device.getDeviceState({ refreshSections: ['status'] });
94
95
  let currentDeviceId = state.identity.deviceId;
96
+ const hasAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) =>
97
+ candidate.status.unlocked === true &&
98
+ typeof candidate.status.passphraseProtection === 'boolean' &&
99
+ typeof candidate.status.unlockedAttachPin === 'boolean';
100
+ const requireAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) => {
101
+ if (!hasAuthoritativeProtocolV2WalletStatus(candidate)) {
102
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
103
+ }
104
+ return candidate;
105
+ };
95
106
  const requireDeviceId = () => {
96
107
  if (!currentDeviceId) {
97
108
  throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
98
109
  }
99
110
  return currentDeviceId;
100
111
  };
101
- const refreshProtocolV2DeviceId = async () => {
102
- const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
103
- currentDeviceId = refreshedState.identity.deviceId;
104
- return requireDeviceId();
112
+ const refreshProtocolV2DeviceState = async () => {
113
+ state = await this.device.getDeviceState({ refreshSections: ['status'] });
114
+ currentDeviceId = state.identity.deviceId;
115
+ return state;
105
116
  };
106
- const unlockProtocolV2IfLocked = async () => {
107
- if (isProtocolV2 && state.status.unlocked === false) {
108
- await this.device.unlockDevice();
117
+ const ensureProtocolV2WalletStatus = async () => {
118
+ if (isProtocolV2 && !hasAuthoritativeProtocolV2WalletStatus(state)) {
119
+ await this.device.unlockDevice(DeviceSessionPinType.Main, {
120
+ source: 'unlock-coordinator',
121
+ reason: 'device-locked',
122
+ deviceOnly: true,
123
+ method: 'openWalletSession',
124
+ });
125
+ requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState());
109
126
  }
127
+ return state;
110
128
  };
111
129
 
112
130
  const protocol = isProtocolV2 ? 'V2' : 'V1';
@@ -114,13 +132,25 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
114
132
  if (this.params.mode === OpenWalletSessionMode.Standard) {
115
133
  this.device.passphraseState = undefined;
116
134
  const session = isProtocolV2
117
- ? await getProtocolV2WalletSession(this.device, { onlyMainPin: true })
135
+ ? await getProtocolV2WalletSession(this.device, {
136
+ onlyMainPin: true,
137
+ deriveCardano: this.payload.deriveCardano,
138
+ selectMainWalletBeforeRestore:
139
+ !hasAuthoritativeProtocolV2WalletStatus(state) ||
140
+ state.status.unlockedAttachPin === true,
141
+ })
118
142
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, {
119
143
  onlyMainPin: true,
120
144
  initSession: this.payload.initSession,
121
145
  });
122
- const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
123
- if (session.unlockedAttachPin) {
146
+ const refreshedState = isProtocolV2
147
+ ? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
148
+ : state;
149
+ const deviceId = requireDeviceId();
150
+ if (
151
+ session.unlockedAttachPin ||
152
+ (isProtocolV2 && refreshedState.status.unlockedAttachPin === true)
153
+ ) {
124
154
  try {
125
155
  await this.device.lockDevice();
126
156
  } catch {
@@ -140,8 +170,8 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
140
170
 
141
171
  if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
142
172
  if (isProtocolV2) {
143
- await unlockProtocolV2IfLocked();
144
- const refreshedDeviceId = await refreshProtocolV2DeviceId();
173
+ await ensureProtocolV2WalletStatus();
174
+ const refreshedDeviceId = requireDeviceId();
145
175
  if (refreshedDeviceId !== this.params.deviceId) {
146
176
  deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
147
177
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
@@ -166,6 +196,7 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
166
196
  const session = isProtocolV2
167
197
  ? await getProtocolV2WalletSession(this.device, {
168
198
  expectedPassphraseState: this.params.passphraseState,
199
+ deriveCardano: this.payload.deriveCardano,
169
200
  })
170
201
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, {
171
202
  expectPassphraseState: this.params.passphraseState,
@@ -185,12 +216,18 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
185
216
  }
186
217
 
187
218
  this.device.passphraseState = undefined;
188
- await unlockProtocolV2IfLocked();
219
+ await ensureProtocolV2WalletStatus();
189
220
  const session = isProtocolV2
190
- ? await getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
221
+ ? await getProtocolV2WalletSession(this.device, {
222
+ forceWalletSelection: true,
223
+ deriveCardano: this.payload.deriveCardano,
224
+ })
191
225
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
192
- const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
193
- if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
226
+ const refreshedState = isProtocolV2
227
+ ? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
228
+ : state;
229
+ const deviceId = requireDeviceId();
230
+ if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
194
231
  this.device.clearInternalState();
195
232
  throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
196
233
  }
@@ -59,7 +59,9 @@ export default class SearchDevices extends BaseMethod {
59
59
  // Discovery is best effort. Browsers may retain WebUSB grants for devices that
60
60
  // are offline, busy, or not ready, so one descriptor must not abort the scan.
61
61
  const result = await DevicePool.getDevices([descriptor], descriptor.path, {
62
- connectProtocol: this.payload.connectProtocol,
62
+ // Discovery must actively identify the protocol instead of trusting a caller hint.
63
+ connectProtocol: undefined,
64
+ forceProtocolDetection: true,
63
65
  refreshRuntimeState: true,
64
66
  });
65
67
  deviceList.push(...result.deviceList);
@@ -14,6 +14,7 @@ import { findMethod } from '../utils';
14
14
  import { DEVICE, IFRAME, createUiMessage } from '../../events';
15
15
  import { UI_REQUEST } from '../../constants/ui-request';
16
16
  import { onDeviceButtonHandler } from '../../core';
17
+ import { runMethodWithUnlockPolicy } from '../../protocols/protocol-v2/unlockPolicyRunner';
17
18
  import {
18
19
  completeRequestContext,
19
20
  createRequestContext,
@@ -375,16 +376,34 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
375
376
  this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
376
377
 
377
378
  preCheckDeviceSupport(this.device, method);
378
- if (this.temporarySafetyCheckPrompted) {
379
- method.temporarySafetyCheckPrompted = true;
380
- } else {
381
- const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
382
- if (appliedTemporarySafetyCheck) {
383
- this.temporarySafetyCheckPrompted = true;
384
- }
385
- }
386
-
387
- const response = await method.run();
379
+ const response = await runMethodWithUnlockPolicy<any[]>(method, this.device, {
380
+ context: this.protocolV2UnlockContext,
381
+ prepare: async () => {
382
+ if (this.temporarySafetyCheckPrompted) {
383
+ method.temporarySafetyCheckPrompted = true;
384
+ } else {
385
+ const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
386
+ if (appliedTemporarySafetyCheck) {
387
+ this.temporarySafetyCheckPrompted = true;
388
+ }
389
+ }
390
+
391
+ // Protocol V2 hands a wallet session to exactly one blockchain request.
392
+ // The parent all-network call consumes its first handoff while fetching
393
+ // the root fingerprint, so each nested chain method must resume the
394
+ // requested hidden wallet before it sends its own device command.
395
+ if (this.device.isProtocolV2() && this.payload.passphraseState) {
396
+ const passphraseStateSafety = await this.device.checkPassphraseStateSafety(
397
+ this.payload.passphraseState,
398
+ false,
399
+ this.payload.skipPassphraseCheck
400
+ );
401
+ if (!passphraseStateSafety) {
402
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
403
+ }
404
+ }
405
+ },
406
+ });
388
407
 
389
408
  if (!Array.isArray(response) || response.length === 0) {
390
409
  throw new Error('No response');
@@ -439,7 +458,9 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
439
458
  show_display: false,
440
459
  });
441
460
 
442
- this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
461
+ if (!this.device.isProtocolV2()) {
462
+ this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
463
+ }
443
464
 
444
465
  if (res.message.root_fingerprint == null) {
445
466
  throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
@@ -1,13 +1,18 @@
1
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
 
3
- import type { LockDevice } from '@onekeyfe/hd-transport';
5
+ import type { DeviceUnlockParams } from '../../types/api/deviceUnlock';
4
6
 
5
- export default class DeviceUnlock extends BaseMethod<LockDevice> {
7
+ export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
6
8
  getSupportedProtocols() {
7
9
  return ['V1', 'V2'] as const;
8
10
  }
9
11
 
10
12
  init() {
13
+ this.params = {
14
+ pinType: this.payload.pinType ?? DeviceSessionPinType.Main,
15
+ };
11
16
  this.useDevicePassphraseState = false;
12
17
  this.unlockPolicy = 'none';
13
18
  this.protocolV2UiInteraction = {
@@ -21,6 +26,6 @@ export default class DeviceUnlock extends BaseMethod<LockDevice> {
21
26
  }
22
27
 
23
28
  async run() {
24
- return this.device.unlockDevice();
29
+ return this.device.unlockDevice(this.params.pinType, { emitUiEvent: false });
25
30
  }
26
31
  }
@@ -5,23 +5,15 @@ import { UI_REQUEST } from '../../constants/ui-request';
5
5
  import { FirmwareUpdateTipMessage } from '../../events/ui-request';
6
6
  import { FirmwareUpdateBaseMethod } from '../firmware/FirmwareUpdateBaseMethod';
7
7
  import { getSysResourceBinary } from '../firmware/getBinary';
8
- import { updateBootloader, updateBootloaderFromSource } from '../firmware/uploadFirmware';
8
+ import { updateBootloader } from '../firmware/uploadFirmware';
9
9
  import { DeviceModelToTypes } from '../../types';
10
10
  import { DataManager } from '../../data-manager';
11
- import { checkBootloaderLength, checkBootloaderSourceLength } from '../firmware/updateBootloader';
12
- import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
13
- import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
14
- import {
15
- assertFirmwareUpdatePreparedPlanBinding,
16
- assertFirmwareUpdatePreparedPlanDeviceIdentity,
17
- } from '../firmware/FirmwareUpdatePreparedPlan';
18
- import { getDeviceUUID } from '../../utils';
11
+ import { checkBootloaderLength } from '../firmware/updateBootloader';
19
12
 
20
13
  import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
21
14
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
22
15
  import type { Device } from '../../device/Device';
23
16
  import type { Features } from '../../types';
24
- import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
25
17
 
26
18
  export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
27
19
  init() {
@@ -51,68 +43,17 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
51
43
  return true;
52
44
  }
53
45
 
54
- async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
55
- const filePath = '0:boot/bootloader.bin';
56
-
57
- this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
58
- await this.emmcCommonUpdateProcessFromSource({
59
- source,
60
- filePath,
61
- });
62
- this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
63
- await this.reboot(RebootType.Normal);
64
- this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
65
- return true;
66
- }
67
-
68
46
  async updateTouchBootloader({
69
47
  device,
70
48
  features,
71
49
  firmwareType,
72
- binary: preparedBinary,
73
- source: preparedSource,
74
50
  }: {
75
51
  device: Device;
76
52
  features?: Features;
77
53
  firmwareType: EFirmwareType;
78
- binary?: ArrayBuffer;
79
- source?: FirmwareByteSource;
80
54
  }) {
81
- if (preparedSource) {
82
- if (!(await checkBootloaderSourceLength(preparedSource))) {
83
- throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
84
- }
85
- if (features && device.isBootloader()) {
86
- this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
87
- const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
88
- device,
89
- preparedSource
90
- );
91
- return result;
92
- }
93
- if (features && !device.isBootloader()) {
94
- await updateBootloaderFromSource(
95
- this.device.getCommands().typedCall.bind(this.device.getCommands()),
96
- this.postMessage,
97
- device,
98
- preparedSource
99
- );
100
- return true;
101
- }
102
- }
103
-
104
- let binary = preparedBinary;
55
+ let { binary } = this.payload;
105
56
  if (!binary) {
106
- if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
107
- throw ERRORS.TypedError(
108
- HardwareErrorCode.RuntimeError,
109
- 'Bootloader must be prepared by the external firmware host',
110
- {
111
- firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
112
- artifactName: 'bootloader',
113
- }
114
- );
115
- }
116
57
  this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
117
58
  const resourceUrl = features
118
59
  ? DataManager.getBootloaderResource(features, firmwareType)
@@ -127,7 +68,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
127
68
  }
128
69
  }
129
70
 
130
- if (!binary || !checkBootloaderLength(binary)) {
71
+ if (!checkBootloaderLength(binary)) {
131
72
  throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
132
73
  }
133
74
 
@@ -135,8 +76,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
135
76
  if (features && device.isBootloader()) {
136
77
  // Use emmcFileWrite + reboot logic for bootloader mode
137
78
  this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
138
- const result = await this.updateBootloaderWithEmmcFileWrite(device, binary);
139
- return result;
79
+ return this.updateBootloaderWithEmmcFileWrite(device, binary);
140
80
  }
141
81
 
142
82
  if (features && !device.isBootloader()) {
@@ -156,69 +96,13 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
156
96
  const { features } = device;
157
97
 
158
98
  const payload = this.payload as DeviceUpdateBootloaderParams;
159
- const hostBinding = payload.artifact
160
- ? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
161
- : undefined;
162
- const executionParams = {
163
- ...payload,
164
- artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
165
- };
166
- if (payload.artifact) {
167
- assertFirmwareUpdatePreparedPlanDeviceIdentity({
168
- preparedPlan: payload.preparedPlan,
169
- deviceIdentity: getDeviceUUID(features) || undefined,
170
- });
171
- assertFirmwareUpdatePreparedPlanBinding({
172
- preparedPlan: payload.preparedPlan,
173
- executor: 'v2',
174
- scopeTargets: ['bootloader'],
175
- bindings: [
176
- {
177
- target: 'bootloader',
178
- artifact: payload.artifact,
179
- },
180
- ],
181
- });
182
- const source = await openFirmwareByteSource({
183
- artifact: payload.artifact,
184
- reader: executionParams.artifactReader,
185
- });
186
- if (!source) {
187
- throw ERRORS.TypedError(
188
- HardwareErrorCode.RuntimeError,
189
- 'Bootloader artifact is not prepared'
190
- );
191
- }
192
- try {
193
- const deviceType = device.getCurrentDeviceType();
194
- const deviceFirmwareType = device.getCurrentFirmwareType();
195
- const firmwareType = payload.firmwareType ?? deviceFirmwareType;
196
- if (DeviceModelToTypes.model_touch.includes(deviceType)) {
197
- return await this.updateTouchBootloader({
198
- device,
199
- features,
200
- firmwareType,
201
- source,
202
- });
203
- }
204
- return true;
205
- } finally {
206
- await source.close();
207
- }
208
- }
209
99
 
210
- const { binary } = payload;
211
100
  const deviceType = device.getCurrentDeviceType();
212
101
  const deviceFirmwareType = device.getCurrentFirmwareType();
213
102
  const firmwareType = payload.firmwareType ?? deviceFirmwareType;
214
103
 
215
104
  if (DeviceModelToTypes.model_touch.includes(deviceType)) {
216
- return this.updateTouchBootloader({
217
- device,
218
- features,
219
- firmwareType,
220
- binary,
221
- });
105
+ return this.updateTouchBootloader({ device, features, firmwareType });
222
106
  }
223
107
 
224
108
  return Promise.resolve(true);
@@ -13,8 +13,6 @@ import { DeviceModelToTypes } from '../../types';
13
13
  import { DataManager } from '../../data-manager';
14
14
  import { BaseMethod } from '../BaseMethod';
15
15
  import { DEVICE } from '../../events';
16
- import { createFirmwareProgressThrottle } from './progressThrottle';
17
- import { writeFirmwareByteSource } from './FirmwareArtifactSource';
18
16
 
19
17
  import type {
20
18
  IFirmwareUpdateProgressType,
@@ -25,22 +23,11 @@ import type { RebootType } from '@onekeyfe/hd-transport';
25
23
  import type { Deferred } from '@onekeyfe/hd-shared';
26
24
  import type { KnownDevice } from '../../types';
27
25
  import type { TypedResponseMessage } from '../../device/DeviceCommands';
28
- import type { FirmwareByteSource } from './FirmwareArtifactSource';
29
26
 
30
27
  const Log = getLogger(LoggerNames.Method);
31
28
  const SESSION_ERROR = 'session not found';
32
29
  const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
33
30
 
34
- /**
35
- * Response timeout for each Initialize probe while polling a rebooting device over BLE.
36
- * Overlap safety comes from the poll's in-flight guard, not from this value. Keep it
37
- * well below the 30s reboot budget so several attempts fit: a probe written into the
38
- * dying pre-reboot connection is never answered, and its timeout tears that stale link
39
- * down so the next tick reconnects fresh. Raise it only if a device model is proven to
40
- * answer bootloader Initialize slower than this on a fresh connection.
41
- */
42
- export const BOOTLOADER_POLL_INITIALIZE_TIMEOUT_MS = 5000;
43
-
44
31
  const isDeviceDisconnectedError = (error: unknown) => {
45
32
  const message = error instanceof Error ? error.message : String(error ?? '');
46
33
  return (
@@ -53,8 +40,6 @@ const isDeviceDisconnectedError = (error: unknown) => {
53
40
  export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
54
41
  checkPromise: Deferred<any> | null = null;
55
42
 
56
- private shouldPostFirmwareProgress = createFirmwareProgressThrottle();
57
-
58
43
  init(): void {}
59
44
 
60
45
  run(): Promise<any> {
@@ -98,10 +83,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
98
83
  * @param progress Post the percentage of the progress
99
84
  */
100
85
  postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
101
- if (!this.shouldPostFirmwareProgress(progress, progressType)) {
102
- return;
103
- }
104
-
105
86
  this.postMessage(
106
87
  createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
107
88
  device: this.device.toMessageObject() as KnownDevice,
@@ -151,10 +132,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
151
132
  this.checkPromise = createDeferred();
152
133
  const env = DataManager.getSettings('env');
153
134
  const isBleReconnect = connectId && DataManager.isBleConnect(env);
154
- // Tracks the in-flight BLE probe so interval ticks never overlap: a superseded
155
- // Initialize left pending on the V1 transport is exactly what later times out
156
- // and used to tear down the connection mid-firmware-upload.
157
- let bleProbeInFlight = false;
158
135
 
159
136
  Log.log('FirmwareUpdateBaseMethod [checkDeviceToBootloader] isBleReconnect: ', isBleReconnect);
160
137
 
@@ -210,18 +187,14 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
210
187
  }
211
188
 
212
189
  if (isBleReconnect) {
213
- if (bleProbeInFlight) return;
214
- bleProbeInFlight = true;
215
190
  try {
216
191
  await this.device.deviceConnector?.acquire(
217
192
  this.device.originalDescriptor.id,
218
193
  null,
219
- true
194
+ true,
195
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
220
196
  );
221
- // Bound each probe so a request the rebooting device never received
222
- // frees the slot for the next tick instead of hanging into the
223
- // 30s reboot budget.
224
- await this.device.initialize({ timeoutMs: BOOTLOADER_POLL_INITIALIZE_TIMEOUT_MS });
197
+ await this.device.initialize();
225
198
  if (this.device.isBootloader()) {
226
199
  clearInterval(intervalTimer);
227
200
  this.checkPromise?.resolve(true);
@@ -229,8 +202,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
229
202
  } catch (e) {
230
203
  // ignore error because of device is not connected
231
204
  Log.log('catch Bluetooth error when device is restarting: ', e);
232
- } finally {
233
- bleProbeInFlight = false;
234
205
  }
235
206
  } else {
236
207
  await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
@@ -255,7 +226,9 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
255
226
  ) {
256
227
  const deviceDiff = await this.device.deviceConnector?.enumerate();
257
228
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
258
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
229
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId, {
230
+ connectProtocol: this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
231
+ });
259
232
 
260
233
  if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
261
234
  // should update current device from cache
@@ -410,54 +383,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
410
383
  return totalSize !== undefined ? (processedSize ?? 0) + payload.byteLength : 0;
411
384
  }
412
385
 
413
- async emmcCommonUpdateProcessFromSource({
414
- source,
415
- filePath,
416
- processedSize,
417
- totalSize,
418
- }: {
419
- source: FirmwareByteSource;
420
- filePath: string;
421
- processedSize?: number;
422
- totalSize?: number;
423
- }) {
424
- if (!filePath.startsWith('0:')) {
425
- throw new Error('filePath must start with 0:');
426
- }
427
- const env = DataManager.getSettings('env');
428
- const chunkSize = 1024 * (DataManager.isBleConnect(env) ? 16 : 128);
429
-
430
- await writeFirmwareByteSource({
431
- source,
432
- chunkSize,
433
- write: async ({ data, sourceOffset, length, first }) => {
434
- const progress =
435
- totalSize !== undefined && processedSize !== undefined
436
- ? Math.min(Math.ceil(((processedSize + sourceOffset + length) / totalSize) * 100), 99)
437
- : Math.min(Math.ceil(((sourceOffset + length) / source.size) * 100), 99);
438
- const writeRes = await this.emmcFileWriteWithRetry(
439
- filePath,
440
- length,
441
- sourceOffset,
442
- data,
443
- first,
444
- progress
445
- );
446
- if (!writeRes) {
447
- throw ERRORS.TypedError(
448
- HardwareErrorCode.EmmcFileWriteFirmwareError,
449
- 'transfer data error'
450
- );
451
- }
452
- const processedBytes = Number(writeRes.message.processed_byte);
453
- this.postProgressMessage(progress, 'transferData');
454
- return Number.isFinite(processedBytes) ? processedBytes : length;
455
- },
456
- });
457
-
458
- return totalSize !== undefined ? (processedSize ?? 0) + source.size : 0;
459
- }
460
-
461
386
  async emmcFileWriteWithRetry(
462
387
  filePath: string,
463
388
  chunkLength: number,
@@ -512,7 +437,12 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
512
437
  const env = DataManager.getSettings('env');
513
438
  if (DataManager.isBleConnect(env)) {
514
439
  await wait(3000);
515
- await this.device.deviceConnector?.acquire(this.device.originalDescriptor.id, null, true);
440
+ await this.device.deviceConnector?.acquire(
441
+ this.device.originalDescriptor.id,
442
+ null,
443
+ true,
444
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
445
+ );
516
446
  await this.device.initialize();
517
447
  } else if (
518
448
  error?.message?.indexOf(SESSION_ERROR) > -1 ||
@@ -520,7 +450,10 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
520
450
  ) {
521
451
  const deviceDiff = await this.device.deviceConnector?.enumerate();
522
452
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
523
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined);
453
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, undefined, {
454
+ connectProtocol:
455
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
456
+ });
524
457
  if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
525
458
  this.device.updateFromCache(deviceList[0]);
526
459
  await this.device.acquire();
@@ -8,7 +8,6 @@ import { shouldUpdateBootloaderForClassicAndMini } from './bootloaderHelper';
8
8
 
9
9
  import type { Features } from '../../types';
10
10
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
11
- import type { FirmwareByteSource } from './FirmwareArtifactSource';
12
11
 
13
12
  export function checkNeedUpdateBootForTouch(features: Features, firmwareType: EFirmwareType) {
14
13
  const deviceType = getDeviceType(features);
@@ -63,7 +62,8 @@ export function checkNeedUpdateBootForClassicAndMini({
63
62
  }
64
63
 
65
64
  const INIT_DATA_CHUNK_SIZE = 16 * 1024;
66
- const readBootloaderLength = (chunk: Uint8Array) => {
65
+ export function checkBootloaderLength(data: ArrayBuffer) {
66
+ const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
67
67
  const buffer = ByteBuffer.wrap(chunk, undefined, undefined, true);
68
68
  buffer.LE();
69
69
  // byte 'O', 'K', 'T', 'B'
@@ -77,21 +77,6 @@ const readBootloaderLength = (chunk: Uint8Array) => {
77
77
  buffer.readUint32();
78
78
  // codelen
79
79
  const codelen = buffer.readUint32();
80
- return hdrlen + codelen;
81
- };
82
-
83
- export function checkBootloaderLength(data: ArrayBuffer) {
84
- if (data.byteLength < 16) {
85
- return false;
86
- }
87
- const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
88
- return readBootloaderLength(chunk) === data.byteLength;
80
+ const bootloaderLength = hdrlen + codelen;
81
+ return bootloaderLength === data.byteLength;
89
82
  }
90
-
91
- export const checkBootloaderSourceLength = async (source: FirmwareByteSource) => {
92
- if (source.size < 16) {
93
- return false;
94
- }
95
- const chunk = new Uint8Array(await source.readAt(0, Math.min(INIT_DATA_CHUNK_SIZE, source.size)));
96
- return readBootloaderLength(chunk) === source.size;
97
- };