@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.69

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 (316) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +313 -0
  2. package/__tests__/DeviceCommands.test.ts +59 -13
  3. package/__tests__/DeviceEventRegistration.test.ts +6 -0
  4. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +226 -3
  5. package/__tests__/connectSettings.test.ts +5 -47
  6. package/__tests__/core-initialization.test.ts +23 -0
  7. package/__tests__/device-connector-protocol.test.ts +81 -0
  8. package/__tests__/device-lifecycle-events.test.ts +105 -3
  9. package/__tests__/device-pool-state.test.ts +22 -0
  10. package/__tests__/device-settings.test.ts +39 -18
  11. package/__tests__/device-state-contract.test.ts +1 -0
  12. package/__tests__/device-state-mapper.test.ts +13 -1
  13. package/__tests__/device-utils.test.ts +48 -1
  14. package/__tests__/deviceSettings.test.ts +11 -1
  15. package/__tests__/deviceUploadNft.test.ts +316 -0
  16. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
  17. package/__tests__/get-device-state.test.ts +132 -12
  18. package/__tests__/homescreen.test.ts +41 -1
  19. package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
  20. package/__tests__/kaspaSignTransaction.test.ts +3 -26
  21. package/__tests__/logBlockEvent.test.ts +1 -1
  22. package/__tests__/method-protocol-support.test.ts +19 -0
  23. package/__tests__/open-wallet-session.test.ts +568 -37
  24. package/__tests__/pro2Nft.test.ts +108 -0
  25. package/__tests__/protocol-binding.test.ts +89 -0
  26. package/__tests__/protocol-v2-firmware-targets.test.ts +33 -1
  27. package/__tests__/protocol-v2-resources.test.ts +343 -0
  28. package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
  29. package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
  30. package/__tests__/protocol-v2.test.ts +1586 -1213
  31. package/__tests__/protocolV2FileWrite.test.ts +193 -0
  32. package/__tests__/protocolV2UiInteraction.test.ts +63 -0
  33. package/__tests__/public-pro2-api-boundary.test.ts +1 -0
  34. package/__tests__/search-devices.test.ts +12 -3
  35. package/__tests__/tron-sign-message-init.test.ts +2 -2
  36. package/__tests__/uiProgressThrottle.test.ts +74 -0
  37. package/__tests__/uiPromiseRegistry.test.ts +115 -0
  38. package/dist/api/BaseMethod.d.ts +3 -1
  39. package/dist/api/BaseMethod.d.ts.map +1 -1
  40. package/dist/api/CheckAllFirmwareRelease.d.ts +3 -1
  41. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  42. package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
  43. package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
  44. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  45. package/dist/api/FirmwareUpdateV2.d.ts +0 -10
  46. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  47. package/dist/api/FirmwareUpdateV3.d.ts +3 -7
  48. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  49. package/dist/api/FirmwareUpdateV4.d.ts +15 -27
  50. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  51. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  52. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  53. package/dist/api/SearchDevices.d.ts.map +1 -1
  54. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  55. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  56. package/dist/api/device/DeviceUnlock.d.ts +2 -2
  57. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  58. package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
  59. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  60. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -11
  61. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  62. package/dist/api/firmware/getBinary.d.ts +0 -7
  63. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  64. package/dist/api/firmware/updateBootloader.d.ts +0 -2
  65. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  66. package/dist/api/firmware/uploadFirmware.d.ts +1 -9
  67. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  68. package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
  69. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  70. package/dist/api/index.d.ts +2 -0
  71. package/dist/api/index.d.ts.map +1 -1
  72. package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
  73. package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
  74. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  75. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
  76. package/dist/api/polkadot/networks.d.ts +1 -1
  77. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
  78. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
  79. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  80. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  81. package/dist/api/solana/SolSignMessage.d.ts +1 -1
  82. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
  83. package/dist/api/solana/SolSignTransaction.d.ts +2 -2
  84. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  85. package/dist/api/sui/SuiGetAddress.d.ts +1 -1
  86. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
  87. package/dist/api/sui/SuiSignMessage.d.ts +1 -1
  88. package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
  89. package/dist/api/ton/TonGetAddress.d.ts +1 -1
  90. package/dist/api/ton/TonSignMessage.d.ts +1 -1
  91. package/dist/api/ton/TonSignProof.d.ts +1 -1
  92. package/dist/api/tron/TronSignMessage.d.ts +2 -2
  93. package/dist/api/tron/TronSignTransaction.d.ts +1 -1
  94. package/dist/core/deviceEventRegistration.d.ts +2 -0
  95. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  96. package/dist/core/index.d.ts.map +1 -1
  97. package/dist/core/uiPromiseRegistry.d.ts +6 -0
  98. package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
  99. package/dist/data-manager/DataManager.d.ts +9 -4
  100. package/dist/data-manager/DataManager.d.ts.map +1 -1
  101. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  102. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  103. package/dist/device/Device.d.ts +29 -6
  104. package/dist/device/Device.d.ts.map +1 -1
  105. package/dist/device/DeviceCommands.d.ts +4 -4
  106. package/dist/device/DeviceCommands.d.ts.map +1 -1
  107. package/dist/device/DeviceConnector.d.ts +2 -1
  108. package/dist/device/DeviceConnector.d.ts.map +1 -1
  109. package/dist/device/DevicePool.d.ts.map +1 -1
  110. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
  111. package/dist/events/device.d.ts +4 -0
  112. package/dist/events/device.d.ts.map +1 -1
  113. package/dist/events/logBlockEvent.d.ts.map +1 -1
  114. package/dist/events/ui-promise.d.ts +4 -2
  115. package/dist/events/ui-promise.d.ts.map +1 -1
  116. package/dist/events/ui-request.d.ts +31 -2
  117. package/dist/events/ui-request.d.ts.map +1 -1
  118. package/dist/events/ui-response.d.ts +10 -2
  119. package/dist/events/ui-response.d.ts.map +1 -1
  120. package/dist/index.d.ts +243 -247
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +3135 -3785
  123. package/dist/inject.d.ts +6 -1
  124. package/dist/inject.d.ts.map +1 -1
  125. package/dist/lowLevelInject.d.ts.map +1 -1
  126. package/dist/protocols/protocol-v2/features.d.ts +0 -4
  127. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  128. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  129. package/dist/protocols/protocol-v2/resources.d.ts +30 -0
  130. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
  131. package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
  132. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  133. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
  134. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  135. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
  136. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
  137. package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
  138. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  139. package/dist/topLevelInject.d.ts.map +1 -1
  140. package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -5
  141. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  142. package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
  143. package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
  144. package/dist/types/api/deviceUnlock.d.ts +5 -1
  145. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  146. package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
  147. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  148. package/dist/types/api/export.d.ts +2 -4
  149. package/dist/types/api/export.d.ts.map +1 -1
  150. package/dist/types/api/firmwareUpdate.d.ts +4 -70
  151. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  152. package/dist/types/api/index.d.ts +7 -10
  153. package/dist/types/api/index.d.ts.map +1 -1
  154. package/dist/types/api/protocolV2.d.ts +3 -0
  155. package/dist/types/api/protocolV2.d.ts.map +1 -1
  156. package/dist/types/device.d.ts +2 -2
  157. package/dist/types/device.d.ts.map +1 -1
  158. package/dist/types/params.d.ts +1 -0
  159. package/dist/types/params.d.ts.map +1 -1
  160. package/dist/types/settings.d.ts +38 -21
  161. package/dist/types/settings.d.ts.map +1 -1
  162. package/dist/utils/deviceFeaturesCompat.d.ts +0 -1
  163. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  164. package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
  165. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  166. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  167. package/dist/utils/deviceSettings.d.ts.map +1 -1
  168. package/dist/utils/homescreen.d.ts +4 -0
  169. package/dist/utils/homescreen.d.ts.map +1 -1
  170. package/dist/utils/index.d.ts +1 -1
  171. package/dist/utils/index.d.ts.map +1 -1
  172. package/dist/utils/patch.d.ts +1 -1
  173. package/dist/utils/patch.d.ts.map +1 -1
  174. package/dist/utils/pro2Nft.d.ts +31 -0
  175. package/dist/utils/pro2Nft.d.ts.map +1 -0
  176. package/dist/utils/pro2Wallpaper.d.ts +10 -0
  177. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  178. package/dist/utils/uiProgressThrottle.d.ts +3 -0
  179. package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
  180. package/package.json +4 -4
  181. package/src/api/BaseMethod.ts +8 -10
  182. package/src/api/CheckAllFirmwareRelease.ts +78 -64
  183. package/src/api/DetectDeviceConnectProtocol.ts +18 -0
  184. package/src/api/FirmwareUpdate.ts +7 -15
  185. package/src/api/FirmwareUpdateV2.ts +126 -298
  186. package/src/api/FirmwareUpdateV3.ts +63 -265
  187. package/src/api/FirmwareUpdateV4.ts +645 -1018
  188. package/src/api/GetPassphraseState.ts +7 -1
  189. package/src/api/OpenWalletSession.ts +71 -17
  190. package/src/api/SearchDevices.ts +3 -1
  191. package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
  192. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
  193. package/src/api/device/DeviceSettings.ts +5 -4
  194. package/src/api/device/DeviceUnlock.ts +8 -3
  195. package/src/api/device/DeviceUpdateBootloader.ts +6 -125
  196. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -83
  197. package/src/api/firmware/updateBootloader.ts +4 -19
  198. package/src/api/firmware/uploadFirmware.ts +39 -144
  199. package/src/api/helpers/protocolV2FileWrite.ts +252 -63
  200. package/src/api/index.ts +2 -0
  201. package/src/api/kaspa/KaspaGetAddress.ts +1 -1
  202. package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
  203. package/src/api/polkadot/networks.ts +3 -3
  204. package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
  205. package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
  206. package/src/api/protocol-v2/helpers.ts +1 -1
  207. package/src/api/solana/SolSignMessage.ts +1 -1
  208. package/src/api/solana/SolSignOffchainMessage.ts +1 -1
  209. package/src/api/solana/SolSignTransaction.ts +2 -2
  210. package/src/api/sui/SuiGetAddress.ts +1 -1
  211. package/src/api/sui/SuiGetPublicKey.ts +1 -1
  212. package/src/api/sui/SuiSignMessage.ts +1 -1
  213. package/src/api/sui/SuiSignTransaction.ts +1 -1
  214. package/src/api/ton/TonGetAddress.ts +1 -1
  215. package/src/api/ton/TonSignMessage.ts +1 -1
  216. package/src/api/ton/TonSignProof.ts +1 -1
  217. package/src/api/tron/TronSignMessage.ts +2 -2
  218. package/src/api/tron/TronSignTransaction.ts +1 -1
  219. package/src/core/deviceEventRegistration.ts +4 -0
  220. package/src/core/index.ts +213 -111
  221. package/src/core/uiPromiseRegistry.ts +63 -0
  222. package/src/data/messages/messages-protocol-v2.json +25 -0
  223. package/src/data-manager/DataManager.ts +113 -41
  224. package/src/data-manager/TransportManager.ts +6 -0
  225. package/src/data-manager/connectSettings.ts +0 -11
  226. package/src/device/Device.ts +274 -49
  227. package/src/device/DeviceCommands.ts +31 -4
  228. package/src/device/DeviceConnector.ts +33 -13
  229. package/src/device/DevicePool.ts +21 -7
  230. package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
  231. package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
  232. package/src/events/device.ts +4 -0
  233. package/src/events/logBlockEvent.ts +1 -0
  234. package/src/events/ui-promise.ts +4 -2
  235. package/src/events/ui-request.ts +36 -2
  236. package/src/events/ui-response.ts +12 -2
  237. package/src/index.ts +0 -5
  238. package/src/inject.ts +60 -24
  239. package/src/lowLevelInject.ts +7 -8
  240. package/src/protocols/protocol-v2/features.ts +10 -7
  241. package/src/protocols/protocol-v2/firmware.ts +2 -0
  242. package/src/protocols/protocol-v2/resources.ts +394 -0
  243. package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
  244. package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
  245. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
  246. package/src/protocols/protocol-v2/walletSession.ts +214 -36
  247. package/src/topLevelInject.ts +7 -8
  248. package/src/types/api/checkAllFirmwareRelease.ts +3 -5
  249. package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
  250. package/src/types/api/deviceUnlock.ts +12 -1
  251. package/src/types/api/deviceUpdateBootloader.ts +0 -6
  252. package/src/types/api/export.ts +1 -18
  253. package/src/types/api/firmwareUpdate.ts +6 -78
  254. package/src/types/api/index.ts +13 -14
  255. package/src/types/api/protocolV2.ts +13 -0
  256. package/src/types/device.ts +15 -3
  257. package/src/types/params.ts +7 -1
  258. package/src/types/settings.ts +61 -22
  259. package/src/utils/deviceFeaturesCompat.ts +5 -6
  260. package/src/utils/deviceFeaturesUtils.ts +14 -3
  261. package/src/utils/deviceInfoUtils.ts +2 -0
  262. package/src/utils/deviceSettings.ts +3 -0
  263. package/src/utils/homescreen.ts +32 -6
  264. package/src/utils/index.ts +6 -1
  265. package/src/utils/pro2Nft.ts +142 -0
  266. package/src/utils/pro2Wallpaper.ts +35 -8
  267. package/src/utils/uiProgressThrottle.ts +63 -0
  268. package/__tests__/device-initialize-timeout.test.ts +0 -56
  269. package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
  270. package/__tests__/firmware-update/device-update-bootloader.test.ts +0 -87
  271. package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
  272. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
  273. package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
  274. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +0 -200
  275. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
  276. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +0 -394
  277. package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
  278. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -231
  279. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -58
  280. package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
  281. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
  282. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
  283. package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
  284. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
  285. package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
  286. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
  287. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
  288. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
  289. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
  290. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
  291. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -32
  292. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
  293. package/dist/api/firmware/progressThrottle.d.ts +0 -3
  294. package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
  295. package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
  296. package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
  297. package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
  298. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
  299. package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
  300. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
  301. package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
  302. package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
  303. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
  304. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
  305. package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
  306. package/src/api/firmware/FirmwareHostBinding.ts +0 -100
  307. package/src/api/firmware/FirmwarePreparationError.ts +0 -12
  308. package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
  309. package/src/api/firmware/FirmwareUpdatePlan.ts +0 -772
  310. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -449
  311. package/src/api/firmware/progressThrottle.ts +0 -44
  312. package/src/protocols/protocol-v2/lockedError.ts +0 -10
  313. package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
  314. package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
  315. package/src/types/api/firmwareUpdatePlan.ts +0 -38
  316. package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
@@ -1,449 +0,0 @@
1
- import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
-
3
- import { assertFirmwareArtifactReference } from './FirmwareArtifactSource';
4
- import {
5
- FIRMWARE_UPDATE_PLAN_ROLES,
6
- FIRMWARE_UPDATE_PLAN_TARGETS,
7
- assertFirmwareUpdatePlan,
8
- digestFirmwareUpdateContract,
9
- } from './FirmwareUpdatePlan';
10
-
11
- import type {
12
- FirmwareUpdatePreparedArtifact,
13
- FirmwareUpdatePreparedArtifactInput,
14
- FirmwareUpdatePreparedEntry,
15
- FirmwareUpdatePreparedPlan,
16
- } from '../../types/api/firmwareUpdatePreparedPlan';
17
- import type { FirmwareArtifactReference } from '../../types/api/firmwareUpdate';
18
- import type { FirmwareUpdatePlan } from '../../types/api/firmwareUpdatePlan';
19
-
20
- const preparedPlanError = (message: string): never => {
21
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, message, {
22
- firmwareUpdateCode: 'FirmwarePreparedPlanInvalid',
23
- });
24
- };
25
-
26
- const digestPreparedPlan = (plan: Omit<FirmwareUpdatePreparedPlan, 'preparedPlanDigest'>): string =>
27
- digestFirmwareUpdateContract(plan);
28
-
29
- const assertOpaqueLeaseRef = (value: unknown): string => {
30
- if (
31
- typeof value !== 'string' ||
32
- value.length === 0 ||
33
- value.length > 160 ||
34
- value.includes('/') ||
35
- value.includes('\\')
36
- ) {
37
- return preparedPlanError('Firmware prepared plan leaseRef must be opaque');
38
- }
39
- return value;
40
- };
41
-
42
- export const getFirmwareUpdateResourceName = (value: unknown): string => {
43
- const normalized = typeof value === 'string' ? value.normalize('NFC') : undefined;
44
- const parts = normalized?.split('/');
45
- const resourceName = parts?.at(-1);
46
- if (
47
- typeof value !== 'string' ||
48
- value.length === 0 ||
49
- value.length > 512 ||
50
- value !== normalized ||
51
- value.startsWith('/') ||
52
- value.includes('\\') ||
53
- value.includes(':') ||
54
- [...value].some(char => {
55
- const code = char.charCodeAt(0);
56
- return code <= 0x1f || code === 0x7f;
57
- }) ||
58
- !parts?.every(
59
- part =>
60
- part.length > 0 &&
61
- part !== '.' &&
62
- part !== '..' &&
63
- !part.endsWith('.') &&
64
- !part.endsWith(' ')
65
- ) ||
66
- !resourceName ||
67
- resourceName.length > 128
68
- ) {
69
- return preparedPlanError('Firmware prepared plan entry name is invalid');
70
- }
71
- return resourceName;
72
- };
73
-
74
- const assertPreparedEntry = (value: unknown): FirmwareUpdatePreparedEntry => {
75
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
76
- return preparedPlanError('Firmware prepared plan entry must be an object');
77
- }
78
- const entry = value as Record<string, unknown>;
79
- if (
80
- Object.keys(entry).length !== 2 ||
81
- !Object.prototype.hasOwnProperty.call(entry, 'entryName') ||
82
- !Object.prototype.hasOwnProperty.call(entry, 'artifact')
83
- ) {
84
- return preparedPlanError('Firmware prepared plan entry fields are invalid');
85
- }
86
- getFirmwareUpdateResourceName(entry.entryName);
87
- assertFirmwareArtifactReference(entry.artifact as FirmwareUpdatePreparedEntry['artifact']);
88
- return value as FirmwareUpdatePreparedEntry;
89
- };
90
-
91
- const assertPreparedArtifacts = ({
92
- plan,
93
- artifacts,
94
- }: {
95
- plan: FirmwareUpdatePlan;
96
- artifacts: readonly FirmwareUpdatePreparedArtifactInput[];
97
- }): FirmwareUpdatePreparedArtifact[] => {
98
- if (artifacts.length !== plan.artifacts.length) {
99
- return preparedPlanError('Firmware prepared plan does not cover every artifact');
100
- }
101
- const inputs = new Map<string, FirmwareUpdatePreparedArtifactInput>();
102
- for (const input of artifacts) {
103
- if (
104
- !input ||
105
- typeof input !== 'object' ||
106
- typeof input.artifactId !== 'string' ||
107
- inputs.has(input.artifactId)
108
- ) {
109
- return preparedPlanError('Firmware prepared plan contains a duplicate artifact receipt');
110
- }
111
- inputs.set(input.artifactId, input);
112
- }
113
- return plan.artifacts.map(planArtifact => {
114
- const input = inputs.get(planArtifact.artifactId);
115
- if (!input) {
116
- return preparedPlanError('Firmware prepared plan artifact receipt is missing');
117
- }
118
- const artifact = assertFirmwareArtifactReference(input.artifact);
119
- if (
120
- (planArtifact.expectedSize !== undefined && artifact.size !== planArtifact.expectedSize) ||
121
- (planArtifact.expectedSha256 !== undefined &&
122
- artifact.sha256.toLowerCase() !== planArtifact.expectedSha256.toLowerCase())
123
- ) {
124
- return preparedPlanError('Firmware prepared plan receipt does not match the update plan');
125
- }
126
- const materializedEntries = input.materializedEntries?.map(value => {
127
- const entry = assertPreparedEntry(value);
128
- return {
129
- entryName: entry.entryName,
130
- artifact: {
131
- ...entry.artifact,
132
- sha256: entry.artifact.sha256.toLowerCase(),
133
- },
134
- };
135
- });
136
- if (
137
- (planArtifact.container === 'raw' && materializedEntries?.length) ||
138
- (planArtifact.container === 'zip' && !materializedEntries?.length)
139
- ) {
140
- return preparedPlanError('Firmware prepared plan materialization is incomplete');
141
- }
142
- if (
143
- materializedEntries &&
144
- new Set(
145
- materializedEntries.map(entry =>
146
- getFirmwareUpdateResourceName(entry.entryName).toLowerCase()
147
- )
148
- ).size !== materializedEntries.length
149
- ) {
150
- return preparedPlanError('Firmware prepared plan contains duplicate entry names');
151
- }
152
- return {
153
- artifactId: planArtifact.artifactId,
154
- role: planArtifact.role,
155
- target: planArtifact.target,
156
- container: planArtifact.container,
157
- ...(planArtifact.logicalName ? { logicalName: planArtifact.logicalName } : {}),
158
- ...(planArtifact.targetVersion ? { targetVersion: planArtifact.targetVersion } : {}),
159
- artifact: {
160
- ...artifact,
161
- sha256: artifact.sha256.toLowerCase(),
162
- },
163
- ...(materializedEntries?.length ? { materializedEntries } : {}),
164
- };
165
- });
166
- };
167
-
168
- export const prepareFirmwareUpdatePlan = ({
169
- plan: value,
170
- leaseRef,
171
- artifacts,
172
- }: {
173
- plan: FirmwareUpdatePlan;
174
- leaseRef: string;
175
- artifacts: FirmwareUpdatePreparedArtifactInput[];
176
- }): FirmwareUpdatePreparedPlan => {
177
- const plan = assertFirmwareUpdatePlan(value);
178
- const planWithoutDigest: Omit<FirmwareUpdatePreparedPlan, 'preparedPlanDigest'> = {
179
- schemaVersion: 2,
180
- planDigest: plan.planDigest,
181
- networkPolicy: 'forbid',
182
- executor: plan.executor,
183
- deviceIdentity: plan.deviceIdentity,
184
- deviceModel: plan.deviceModel,
185
- firmwareType: plan.firmwareType,
186
- platform: plan.platform,
187
- leaseRef: assertOpaqueLeaseRef(leaseRef),
188
- artifacts: assertPreparedArtifacts({ plan, artifacts }),
189
- targetsToUpdate: plan.targetsToUpdate,
190
- };
191
- return {
192
- ...planWithoutDigest,
193
- preparedPlanDigest: digestPreparedPlan(planWithoutDigest),
194
- };
195
- };
196
-
197
- export const validateFirmwareUpdatePreparedPlan = (value: unknown): FirmwareUpdatePreparedPlan => {
198
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
199
- return preparedPlanError('Firmware prepared plan must be an object');
200
- }
201
- const preparedPlan = value as FirmwareUpdatePreparedPlan;
202
- const exactKeys = [
203
- 'schemaVersion',
204
- 'preparedPlanDigest',
205
- 'planDigest',
206
- 'networkPolicy',
207
- 'executor',
208
- 'deviceIdentity',
209
- 'deviceModel',
210
- 'firmwareType',
211
- 'platform',
212
- 'leaseRef',
213
- 'artifacts',
214
- 'targetsToUpdate',
215
- ];
216
- if (
217
- Object.keys(value).length !== exactKeys.length ||
218
- exactKeys.some(key => !Object.prototype.hasOwnProperty.call(value, key)) ||
219
- preparedPlan.schemaVersion !== 2 ||
220
- preparedPlan.networkPolicy !== 'forbid' ||
221
- !/^[a-f0-9]{64}$/u.test(preparedPlan.planDigest) ||
222
- !/^[a-f0-9]{64}$/u.test(preparedPlan.preparedPlanDigest) ||
223
- !Array.isArray(preparedPlan.artifacts) ||
224
- !Array.isArray(preparedPlan.targetsToUpdate) ||
225
- (preparedPlan.executor !== 'v2' &&
226
- preparedPlan.executor !== 'v3' &&
227
- preparedPlan.executor !== 'v4') ||
228
- (preparedPlan.platform !== 'native' &&
229
- preparedPlan.platform !== 'desktop' &&
230
- preparedPlan.platform !== 'ext' &&
231
- preparedPlan.platform !== 'web' &&
232
- preparedPlan.platform !== 'web-embed') ||
233
- (preparedPlan.firmwareType !== 'universal' && preparedPlan.firmwareType !== 'bitcoinonly') ||
234
- typeof preparedPlan.deviceIdentity !== 'string' ||
235
- preparedPlan.deviceIdentity.length === 0 ||
236
- typeof preparedPlan.deviceModel !== 'string' ||
237
- preparedPlan.deviceModel.length === 0
238
- ) {
239
- return preparedPlanError('Firmware prepared plan header is invalid');
240
- }
241
- assertOpaqueLeaseRef(preparedPlan.leaseRef);
242
- const artifactIds = new Set<string>();
243
- const artifactTargets = new Set<string>();
244
- for (const artifact of preparedPlan.artifacts) {
245
- if (!artifact || typeof artifact !== 'object') {
246
- return preparedPlanError('Firmware prepared plan artifact is invalid');
247
- }
248
- const artifactKeys = [
249
- 'artifactId',
250
- 'role',
251
- 'target',
252
- 'container',
253
- 'artifact',
254
- ...(artifact.logicalName !== undefined ? ['logicalName'] : []),
255
- ...(artifact.targetVersion !== undefined ? ['targetVersion'] : []),
256
- ...(artifact.materializedEntries !== undefined ? ['materializedEntries'] : []),
257
- ];
258
- if (
259
- typeof artifact.artifactId !== 'string' ||
260
- artifact.artifactId.length === 0 ||
261
- artifactIds.has(artifact.artifactId) ||
262
- Object.keys(artifact).length !== artifactKeys.length ||
263
- artifactKeys.some(key => !Object.prototype.hasOwnProperty.call(artifact, key)) ||
264
- !FIRMWARE_UPDATE_PLAN_ROLES.has(artifact.role) ||
265
- !FIRMWARE_UPDATE_PLAN_TARGETS.has(artifact.target) ||
266
- (artifact.container !== 'raw' && artifact.container !== 'zip') ||
267
- (artifact.logicalName !== undefined &&
268
- (typeof artifact.logicalName !== 'string' || artifact.logicalName.length === 0)) ||
269
- (artifact.targetVersion !== undefined &&
270
- (typeof artifact.targetVersion !== 'string' || artifact.targetVersion.length === 0)) ||
271
- (artifact.materializedEntries !== undefined &&
272
- !Array.isArray(artifact.materializedEntries)) ||
273
- (artifact.container === 'raw' && Boolean(artifact.materializedEntries?.length)) ||
274
- (artifact.container === 'zip' && !artifact.materializedEntries?.length)
275
- ) {
276
- return preparedPlanError('Firmware prepared plan artifact is invalid');
277
- }
278
- artifactIds.add(artifact.artifactId);
279
- artifactTargets.add(artifact.target);
280
- assertFirmwareArtifactReference(artifact.artifact);
281
- artifact.materializedEntries?.forEach(assertPreparedEntry);
282
- }
283
- if (
284
- preparedPlan.targetsToUpdate.some(target => !FIRMWARE_UPDATE_PLAN_TARGETS.has(target)) ||
285
- new Set(preparedPlan.targetsToUpdate).size !== preparedPlan.targetsToUpdate.length ||
286
- preparedPlan.targetsToUpdate.length !== artifactTargets.size ||
287
- preparedPlan.targetsToUpdate.some(target => !artifactTargets.has(target))
288
- ) {
289
- return preparedPlanError('Firmware prepared plan targets are invalid');
290
- }
291
- const { preparedPlanDigest, ...withoutDigest } = preparedPlan;
292
- if (digestPreparedPlan(withoutDigest) !== preparedPlanDigest) {
293
- return preparedPlanError('Firmware prepared plan digest is invalid');
294
- }
295
- return preparedPlan;
296
- };
297
-
298
- /**
299
- * Identity observed on the live device while a degraded recovery plan runs, keyed by
300
- * the plan's opaque lease. Bootloader recovery starts with no serial and the device
301
- * reports one only after the firmware phase reboots it, so the later phases of the
302
- * SAME workflow must be allowed to continue — but only for the device that first
303
- * answered, never for a second one that appears mid-recovery.
304
- */
305
- const degradedPlanIdentityPins = new Map<string, string>();
306
- /** Keep the pin map from growing without bound across many workflows. */
307
- const DEGRADED_PLAN_IDENTITY_PIN_LIMIT = 32;
308
-
309
- const pinDegradedPlanIdentity = (leaseRef: string, deviceIdentity: string) => {
310
- if (degradedPlanIdentityPins.size >= DEGRADED_PLAN_IDENTITY_PIN_LIMIT) {
311
- const oldest = degradedPlanIdentityPins.keys().next();
312
- if (!oldest.done) {
313
- degradedPlanIdentityPins.delete(oldest.value);
314
- }
315
- }
316
- degradedPlanIdentityPins.set(leaseRef, deviceIdentity);
317
- };
318
-
319
- export const assertFirmwareUpdatePreparedPlanDeviceIdentity = ({
320
- preparedPlan: value,
321
- deviceIdentity: reportedIdentity,
322
- bootloaderMode,
323
- deviceModel,
324
- }: {
325
- preparedPlan: unknown;
326
- deviceIdentity: string | undefined;
327
- /** Live device mode; a degraded plan may only START while the device is in bootloader. */
328
- bootloaderMode?: boolean;
329
- /** Live device model; a degraded plan must target the same model. */
330
- deviceModel?: string;
331
- }): FirmwareUpdatePreparedPlan => {
332
- const preparedPlan = validateFirmwareUpdatePreparedPlan(value);
333
- // 'unavailable' is the reserved degraded sentinel — a device-reported serial equal
334
- // to it must never satisfy the exact-match branch below.
335
- const deviceIdentity = reportedIdentity === 'unavailable' ? undefined : reportedIdentity;
336
-
337
- if (preparedPlan.deviceIdentity === 'unavailable') {
338
- // Identity equality implies a model match in the strict branch; the degraded
339
- // branch has no identity to compare, so the model check must stand in for it.
340
- if (deviceModel === undefined || preparedPlan.deviceModel !== deviceModel) {
341
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
342
- }
343
- const pinnedIdentity = degradedPlanIdentityPins.get(preparedPlan.leaseRef);
344
- if (!deviceIdentity) {
345
- // Still identity-less: only legitimate while the device sits in bootloader.
346
- if (bootloaderMode !== true) {
347
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
348
- }
349
- return preparedPlan;
350
- }
351
- // The recovered device now reports a serial: bind this recovery to it, and hold
352
- // every later phase to the same one.
353
- if (!pinnedIdentity) {
354
- pinDegradedPlanIdentity(preparedPlan.leaseRef, deviceIdentity);
355
- return preparedPlan;
356
- }
357
- if (pinnedIdentity !== deviceIdentity) {
358
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
359
- }
360
- return preparedPlan;
361
- }
362
-
363
- if (!deviceIdentity || preparedPlan.deviceIdentity !== deviceIdentity) {
364
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
365
- }
366
- return preparedPlan;
367
- };
368
-
369
- type FirmwareUpdatePreparedBinding = {
370
- target: FirmwareUpdatePlan['targetsToUpdate'][number];
371
- artifact: FirmwareArtifactReference;
372
- logicalName?: string;
373
- entryName?: string;
374
- };
375
-
376
- const sameArtifactReference = (
377
- first: FirmwareArtifactReference,
378
- second: FirmwareArtifactReference
379
- ) =>
380
- first.artifactRef === second.artifactRef &&
381
- first.size === second.size &&
382
- first.sha256.toLowerCase() === second.sha256.toLowerCase();
383
-
384
- export const assertFirmwareUpdatePreparedPlanBinding = ({
385
- preparedPlan: value,
386
- executor,
387
- platform,
388
- deviceIdentity,
389
- scopeTargets,
390
- bindings,
391
- }: {
392
- preparedPlan: unknown;
393
- executor: FirmwareUpdatePreparedPlan['executor'];
394
- platform?: FirmwareUpdatePreparedPlan['platform'];
395
- deviceIdentity?: string;
396
- scopeTargets: FirmwareUpdatePreparedPlan['targetsToUpdate'];
397
- bindings: FirmwareUpdatePreparedBinding[];
398
- }): FirmwareUpdatePreparedPlan => {
399
- const preparedPlan = validateFirmwareUpdatePreparedPlan(value);
400
- if (
401
- preparedPlan.executor !== executor ||
402
- (platform !== undefined && preparedPlan.platform !== platform) ||
403
- (deviceIdentity !== undefined && preparedPlan.deviceIdentity !== deviceIdentity)
404
- ) {
405
- return preparedPlanError('Firmware prepared plan executor binding is invalid');
406
- }
407
- const scope = new Set(scopeTargets);
408
- const expectedBindings: FirmwareUpdatePreparedBinding[] = [];
409
- for (const artifact of preparedPlan.artifacts) {
410
- if (scope.has(artifact.target)) {
411
- if (artifact.container === 'zip') {
412
- for (const entry of artifact.materializedEntries ?? []) {
413
- expectedBindings.push({
414
- target: artifact.target,
415
- ...(artifact.target === 'resource' && artifact.logicalName
416
- ? { logicalName: artifact.logicalName }
417
- : {}),
418
- entryName: entry.entryName,
419
- artifact: entry.artifact,
420
- });
421
- }
422
- } else {
423
- expectedBindings.push({
424
- target: artifact.target,
425
- ...(artifact.target === 'resource' && artifact.logicalName
426
- ? { logicalName: artifact.logicalName }
427
- : {}),
428
- artifact: artifact.artifact,
429
- });
430
- }
431
- }
432
- }
433
- if (
434
- expectedBindings.length !== bindings.length ||
435
- expectedBindings.some(expected => {
436
- const matching = bindings.filter(
437
- binding =>
438
- binding.target === expected.target &&
439
- binding.logicalName === expected.logicalName &&
440
- binding.entryName === expected.entryName &&
441
- sameArtifactReference(binding.artifact, expected.artifact)
442
- );
443
- return matching.length !== 1;
444
- })
445
- ) {
446
- return preparedPlanError('Firmware prepared plan artifact binding is invalid');
447
- }
448
- return preparedPlan;
449
- };
@@ -1,44 +0,0 @@
1
- import type { IFirmwareUpdateProgressType } from '../../events/ui-request';
2
-
3
- const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
4
-
5
- type FirmwareProgressThrottleState = {
6
- lastEmittedAt: number;
7
- lastProgress?: number;
8
- };
9
-
10
- export const createFirmwareProgressThrottle = (
11
- intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS
12
- ) => {
13
- const stateByType = new Map<IFirmwareUpdateProgressType, FirmwareProgressThrottleState>();
14
-
15
- return (progress: number, progressType: IFirmwareUpdateProgressType) => {
16
- if (progressType !== 'transferData') {
17
- return true;
18
- }
19
-
20
- const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
21
- if (normalizedProgress === 0 || normalizedProgress === 100) {
22
- stateByType.set(progressType, {
23
- lastEmittedAt: Date.now(),
24
- lastProgress: normalizedProgress,
25
- });
26
- return true;
27
- }
28
-
29
- const now = Date.now();
30
- const state = stateByType.get(progressType);
31
- if (
32
- state &&
33
- (state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)
34
- ) {
35
- return false;
36
- }
37
-
38
- stateByType.set(progressType, {
39
- lastEmittedAt: now,
40
- lastProgress: normalizedProgress,
41
- });
42
- return true;
43
- };
44
- };
@@ -1,10 +0,0 @@
1
- import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
-
3
- export function isDeviceLockedError(error: unknown): boolean {
4
- return (
5
- typeof error === 'object' &&
6
- error !== null &&
7
- 'errorCode' in error &&
8
- error.errorCode === HardwareErrorCode.DeviceLocked
9
- );
10
- }
@@ -1,109 +0,0 @@
1
- import { LoggerNames, getLogger } from '../../utils';
2
- import { isDeviceLockedError } from './lockedError';
3
- import { isProtocolV2UiEnabled, resolveProtocolV2UiInteraction } from './uiInteraction';
4
- import { refreshProtocolV2DeviceStatus, restoreProtocolV2WalletSession } from './walletSession';
5
-
6
- import type { BaseMethod } from '../../api/BaseMethod';
7
- import type { Device } from '../../device/Device';
8
- import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
9
-
10
- const Log = getLogger(LoggerNames.Core);
11
-
12
- type RunnableMethod = Pick<
13
- BaseMethod,
14
- | 'run'
15
- | 'unlockPolicy'
16
- | 'protocolV2UiInteraction'
17
- | 'protocolV2UiMode'
18
- | 'params'
19
- | 'payload'
20
- | 'useDevicePassphraseState'
21
- > & { name?: string };
22
- type UiInteractionCoordinator = Pick<
23
- ProtocolV2UiInteractionCoordinator,
24
- 'enterMethodInteraction' | 'enterUnlockInteraction' | 'resumeMethodInteraction'
25
- >;
26
-
27
- const restoreExpectedWalletSessionAfterUnlock = async (method: RunnableMethod, device: Device) => {
28
- const expectedPassphraseState = method.payload?.useEmptyPassphrase
29
- ? undefined
30
- : method.payload?.passphraseState ?? device.passphraseState;
31
- if (
32
- !method.useDevicePassphraseState ||
33
- typeof expectedPassphraseState !== 'string' ||
34
- expectedPassphraseState.length === 0
35
- ) {
36
- return;
37
- }
38
-
39
- await restoreProtocolV2WalletSession(device, expectedPassphraseState);
40
- Log.debug('Protocol V2 wallet session restored after unlock', { method: method.name });
41
- };
42
-
43
- export async function runMethodWithUnlockRetry(
44
- method: RunnableMethod,
45
- device: Device,
46
- uiCoordinator?: UiInteractionCoordinator
47
- ) {
48
- const shouldEmitUi = isProtocolV2UiEnabled(method);
49
- const isProtocolV2 = device.isProtocolV2();
50
- const requiresFreshStatus =
51
- isProtocolV2 &&
52
- method.unlockPolicy === 'unlock-before-run' &&
53
- !device.isBootloader?.() &&
54
- !device.isRomloader?.();
55
-
56
- if (requiresFreshStatus) {
57
- await refreshProtocolV2DeviceStatus(device);
58
- }
59
-
60
- const shouldUnlockBeforeRun =
61
- isProtocolV2 &&
62
- method.unlockPolicy !== 'none' &&
63
- !device.isBootloader?.() &&
64
- !device.isRomloader?.() &&
65
- device.features?.unlocked === false;
66
-
67
- if (shouldUnlockBeforeRun) {
68
- if (shouldEmitUi) {
69
- uiCoordinator?.enterUnlockInteraction(method.name);
70
- }
71
- await device.unlockDevice();
72
- Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
73
- await restoreExpectedWalletSessionAfterUnlock(method, device);
74
- if (shouldEmitUi) {
75
- uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
76
- }
77
- return method.run();
78
- }
79
-
80
- if (shouldEmitUi) {
81
- uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
82
- }
83
- try {
84
- return await method.run();
85
- } catch (error) {
86
- if (!isProtocolV2 || method.unlockPolicy !== 'retry-on-locked' || !isDeviceLockedError(error)) {
87
- throw error;
88
- }
89
-
90
- Log.debug('Protocol V2 unlock retry triggered', { method: method.name });
91
- if (shouldEmitUi) {
92
- uiCoordinator?.enterUnlockInteraction(method.name);
93
- }
94
- await device.unlockDevice();
95
- Log.debug('Protocol V2 unlock completed', { method: method.name });
96
- await restoreExpectedWalletSessionAfterUnlock(method, device);
97
- if (shouldEmitUi) {
98
- uiCoordinator?.resumeMethodInteraction();
99
- }
100
- try {
101
- const response = await method.run();
102
- Log.debug('Protocol V2 method retry completed', { method: method.name, success: true });
103
- return response;
104
- } catch (retryError) {
105
- Log.debug('Protocol V2 method retry completed', { method: method.name, success: false });
106
- throw retryError;
107
- }
108
- }
109
- }
@@ -1,9 +0,0 @@
1
- export interface FirmwareUpdateCapabilities {
2
- planSchemaVersion: 2;
3
- preparedPlanSchemaVersion: 2;
4
- hostBindingProtocolVersion: 2;
5
- manifestModes: Array<'external-only' | 'sdk-managed'>;
6
- supportsArtifactReader: true;
7
- }
8
-
9
- export declare function getFirmwareUpdateCapabilities(): FirmwareUpdateCapabilities;
@@ -1,38 +0,0 @@
1
- import type { FirmwareUpdateV4Target } from './firmwareUpdate';
2
- import type { EFirmwareType } from '@onekeyfe/hd-shared';
3
-
4
- export type FirmwareUpdatePlanArtifactRole =
5
- | 'firmware'
6
- | 'ble'
7
- | 'bootloader'
8
- | 'resource'
9
- | 'component'
10
- | 'resourceBundle';
11
-
12
- export type FirmwareUpdatePlanTarget = 'firmware' | 'ble' | 'bootloader' | FirmwareUpdateV4Target;
13
-
14
- export type FirmwareUpdatePlanForceTarget = 'firmware' | 'ble' | 'bootloader' | 'resource';
15
-
16
- export interface FirmwareUpdatePlanArtifact {
17
- artifactId: string;
18
- role: FirmwareUpdatePlanArtifactRole;
19
- target: FirmwareUpdatePlanTarget;
20
- url: string;
21
- container: 'raw' | 'zip';
22
- logicalName?: string;
23
- expectedSize?: number;
24
- expectedSha256?: string;
25
- targetVersion?: string;
26
- }
27
-
28
- export interface FirmwareUpdatePlan {
29
- schemaVersion: 2;
30
- planDigest: string;
31
- executor: 'v2' | 'v3' | 'v4';
32
- deviceIdentity: string;
33
- deviceModel: string;
34
- firmwareType: EFirmwareType;
35
- platform: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
36
- artifacts: FirmwareUpdatePlanArtifact[];
37
- targetsToUpdate: FirmwareUpdatePlanTarget[];
38
- }