@onekeyfe/hd-core 1.2.0-alpha.3 → 1.2.0-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (746) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +77 -0
  2. package/__tests__/DeviceCommands.test.ts +433 -0
  3. package/__tests__/DeviceEventRegistration.test.ts +43 -0
  4. package/__tests__/chain-params-onekey-compatibility.test.ts +229 -0
  5. package/__tests__/connectSettings.test.ts +61 -0
  6. package/__tests__/core-dispose.test.ts +34 -0
  7. package/__tests__/core-error-output.test.ts +39 -0
  8. package/__tests__/device-features-state.test.ts +78 -0
  9. package/__tests__/device-identity.test.ts +52 -0
  10. package/__tests__/device-lifecycle-events.test.ts +197 -0
  11. package/__tests__/device-pool-state.test.ts +132 -0
  12. package/__tests__/device-settings.test.ts +391 -0
  13. package/__tests__/device-state-contract.test.ts +27 -0
  14. package/__tests__/device-state-events.test.ts +286 -0
  15. package/__tests__/device-state-mapper.test.ts +241 -0
  16. package/__tests__/device-state-projector.test.ts +94 -0
  17. package/__tests__/device-state-store.test.ts +82 -0
  18. package/__tests__/device-utils.test.ts +106 -0
  19. package/__tests__/device-wallet-session-store.test.ts +358 -0
  20. package/__tests__/deviceFeaturesUtils.test.ts +39 -0
  21. package/__tests__/deviceSettings.test.ts +103 -0
  22. package/__tests__/evmLedgerLegacySafety.test.ts +12 -6
  23. package/__tests__/evmSignTypedData.test.ts +80 -0
  24. package/__tests__/filesystemValidation.test.ts +53 -0
  25. package/__tests__/firmware-update/check-all-firmware-release.test.ts +174 -0
  26. package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
  27. package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
  28. package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
  29. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
  30. package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
  31. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
  32. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +430 -0
  33. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
  34. package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
  35. package/__tests__/get-device-state.test.ts +410 -0
  36. package/__tests__/homescreen.test.ts +24 -0
  37. package/__tests__/kaspa-public-types.type-test.ts +16 -0
  38. package/__tests__/kaspa-use-tweak-pro2.test.ts +20 -0
  39. package/__tests__/kaspaSignTransaction.test.ts +592 -0
  40. package/__tests__/logBlockEvent.test.ts +43 -0
  41. package/__tests__/method-protocol-support.test.ts +113 -0
  42. package/__tests__/networkUtils.test.ts +386 -0
  43. package/__tests__/open-wallet-session-error-response.test.ts +43 -0
  44. package/__tests__/open-wallet-session.test.ts +915 -0
  45. package/__tests__/preInitialize.test.ts +33 -0
  46. package/__tests__/pro2Wallpaper.test.ts +39 -0
  47. package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
  48. package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
  49. package/__tests__/protocol-v2-ping.test.ts +28 -0
  50. package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
  51. package/__tests__/protocol-v2.test.ts +5310 -1856
  52. package/__tests__/protocolV2FileWrite.test.ts +92 -0
  53. package/__tests__/protocolV2UiInteraction.test.ts +266 -0
  54. package/__tests__/public-device-state-api.test.ts +266 -0
  55. package/__tests__/public-pro2-api-boundary.test.ts +106 -0
  56. package/__tests__/refresh-device-state.test.ts +101 -0
  57. package/__tests__/request-context-logging.test.ts +16 -0
  58. package/__tests__/search-devices.test.ts +136 -0
  59. package/__tests__/tron-sign-message-init.test.ts +74 -0
  60. package/dist/api/BaseMethod.d.ts +14 -1
  61. package/dist/api/BaseMethod.d.ts.map +1 -1
  62. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  63. package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
  64. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  65. package/dist/api/CipherKeyValue.d.ts +1 -0
  66. package/dist/api/CipherKeyValue.d.ts.map +1 -1
  67. package/dist/api/ClearSessionCache.d.ts +9 -0
  68. package/dist/api/ClearSessionCache.d.ts.map +1 -0
  69. package/dist/api/DirList.d.ts +1 -0
  70. package/dist/api/DirList.d.ts.map +1 -1
  71. package/dist/api/DirMake.d.ts +1 -0
  72. package/dist/api/DirMake.d.ts.map +1 -1
  73. package/dist/api/DirRemove.d.ts +1 -0
  74. package/dist/api/DirRemove.d.ts.map +1 -1
  75. package/dist/api/FileDelete.d.ts +1 -0
  76. package/dist/api/FileDelete.d.ts.map +1 -1
  77. package/dist/api/FileRead.d.ts +1 -0
  78. package/dist/api/FileRead.d.ts.map +1 -1
  79. package/dist/api/FileWrite.d.ts +2 -0
  80. package/dist/api/FileWrite.d.ts.map +1 -1
  81. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  82. package/dist/api/FirmwareUpdateV2.d.ts +13 -2
  83. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  84. package/dist/api/FirmwareUpdateV3.d.ts +7 -3
  85. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  86. package/dist/api/FirmwareUpdateV4.d.ts +47 -6
  87. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  88. package/dist/api/GetDeviceState.d.ts +8 -0
  89. package/dist/api/GetDeviceState.d.ts.map +1 -0
  90. package/dist/api/GetFeatures.d.ts +1 -1
  91. package/dist/api/GetFeatures.d.ts.map +1 -1
  92. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  93. package/dist/api/GetPassphraseState.d.ts +2 -6
  94. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  95. package/dist/api/OpenWalletSession.d.ts +8 -0
  96. package/dist/api/OpenWalletSession.d.ts.map +1 -0
  97. package/dist/api/PathInfo.d.ts +1 -0
  98. package/dist/api/PathInfo.d.ts.map +1 -1
  99. package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
  100. package/dist/api/SearchDevices.d.ts +3 -0
  101. package/dist/api/SearchDevices.d.ts.map +1 -1
  102. package/dist/api/UploadPortfolio.d.ts +17 -0
  103. package/dist/api/UploadPortfolio.d.ts.map +1 -0
  104. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  105. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  106. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  107. package/dist/api/algo/AlgoGetAddress.d.ts +1 -0
  108. package/dist/api/algo/AlgoGetAddress.d.ts.map +1 -1
  109. package/dist/api/algo/AlgoSignTransaction.d.ts +1 -0
  110. package/dist/api/algo/AlgoSignTransaction.d.ts.map +1 -1
  111. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts +1 -0
  112. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  113. package/dist/api/aptos/AptosGetAddress.d.ts +1 -0
  114. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
  115. package/dist/api/aptos/AptosGetPublicKey.d.ts +1 -0
  116. package/dist/api/aptos/AptosGetPublicKey.d.ts.map +1 -1
  117. package/dist/api/aptos/AptosSignInMessage.d.ts +1 -0
  118. package/dist/api/aptos/AptosSignInMessage.d.ts.map +1 -1
  119. package/dist/api/aptos/AptosSignMessage.d.ts +1 -0
  120. package/dist/api/aptos/AptosSignMessage.d.ts.map +1 -1
  121. package/dist/api/aptos/AptosSignTransaction.d.ts +1 -0
  122. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -1
  123. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  124. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  125. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  126. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  127. package/dist/api/btc/BTCGetAddress.d.ts +1 -0
  128. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  129. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -0
  130. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  131. package/dist/api/btc/BTCSignMessage.d.ts +1 -0
  132. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  133. package/dist/api/btc/BTCSignPsbt.d.ts +1 -0
  134. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  135. package/dist/api/btc/BTCSignTransaction.d.ts +1 -0
  136. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  137. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -0
  138. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  139. package/dist/api/btc/helpers/versionLimit.d.ts +2 -0
  140. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  141. package/dist/api/cardano/CardanoGetAddress.d.ts +1 -0
  142. package/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -1
  143. package/dist/api/cardano/CardanoGetPublicKey.d.ts +1 -0
  144. package/dist/api/cardano/CardanoGetPublicKey.d.ts.map +1 -1
  145. package/dist/api/cardano/CardanoSignMessage.d.ts +1 -0
  146. package/dist/api/cardano/CardanoSignMessage.d.ts.map +1 -1
  147. package/dist/api/cardano/CardanoSignTransaction.d.ts +1 -0
  148. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  149. package/dist/api/conflux/ConfluxGetAddress.d.ts +2 -0
  150. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
  151. package/dist/api/conflux/ConfluxSignMessage.d.ts +2 -0
  152. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
  153. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +2 -0
  154. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
  155. package/dist/api/conflux/ConfluxSignTransaction.d.ts +2 -0
  156. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  157. package/dist/api/cosmos/CosmosGetAddress.d.ts +1 -0
  158. package/dist/api/cosmos/CosmosGetAddress.d.ts.map +1 -1
  159. package/dist/api/cosmos/CosmosGetPublicKey.d.ts +1 -0
  160. package/dist/api/cosmos/CosmosGetPublicKey.d.ts.map +1 -1
  161. package/dist/api/cosmos/CosmosSignTransaction.d.ts +1 -0
  162. package/dist/api/cosmos/CosmosSignTransaction.d.ts.map +1 -1
  163. package/dist/api/device/DeviceCancel.d.ts +1 -0
  164. package/dist/api/device/DeviceCancel.d.ts.map +1 -1
  165. package/dist/api/device/DeviceChangePin.d.ts +1 -0
  166. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  167. package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
  168. package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
  169. package/dist/api/device/DeviceLock.d.ts +1 -0
  170. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  171. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -0
  172. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  173. package/dist/api/device/DeviceRebootToBootloader.d.ts +1 -0
  174. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  175. package/dist/api/device/DeviceSettings.d.ts +1 -0
  176. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  177. package/dist/api/device/DeviceSupportFeatures.d.ts +1 -0
  178. package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
  179. package/dist/api/device/DeviceUnlock.d.ts +1 -0
  180. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  181. package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
  182. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  183. package/dist/api/device/DeviceWipe.d.ts +1 -0
  184. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  185. package/dist/api/device/PreInitialize.d.ts +1 -0
  186. package/dist/api/device/PreInitialize.d.ts.map +1 -1
  187. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  188. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  189. package/dist/api/evm/EVMGetAddress.d.ts +1 -0
  190. package/dist/api/evm/EVMGetAddress.d.ts.map +1 -1
  191. package/dist/api/evm/EVMGetPublicKey.d.ts +1 -0
  192. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  193. package/dist/api/evm/EVMSignMessage.d.ts +1 -0
  194. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  195. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  196. package/dist/api/evm/EVMSignTransaction.d.ts +1 -0
  197. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  198. package/dist/api/evm/EVMSignTypedData.d.ts +1 -0
  199. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  200. package/dist/api/evm/EVMVerifyMessage.d.ts +1 -0
  201. package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -1
  202. package/dist/api/filecoin/FilecoinGetAddress.d.ts +1 -0
  203. package/dist/api/filecoin/FilecoinGetAddress.d.ts.map +1 -1
  204. package/dist/api/filecoin/FilecoinSignTransaction.d.ts +1 -0
  205. package/dist/api/filecoin/FilecoinSignTransaction.d.ts.map +1 -1
  206. package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
  207. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
  208. package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
  209. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
  210. package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
  211. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
  212. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +8 -0
  213. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  214. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
  215. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
  216. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
  217. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
  218. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +30 -0
  219. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
  220. package/dist/api/firmware/getBinary.d.ts +18 -3
  221. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  222. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  223. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  224. package/dist/api/firmware/updateBootloader.d.ts +2 -0
  225. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  226. package/dist/api/firmware/uploadFirmware.d.ts +9 -1
  227. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  228. package/dist/api/helpers/filesystemValidation.d.ts +3 -0
  229. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
  230. package/dist/api/helpers/paramsValidator.d.ts +1 -0
  231. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  232. package/dist/api/helpers/protocolV2FileWrite.d.ts +33 -0
  233. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
  234. package/dist/api/index.d.ts +6 -29
  235. package/dist/api/index.d.ts.map +1 -1
  236. package/dist/api/kaspa/KaspaGetAddress.d.ts +4 -0
  237. package/dist/api/kaspa/KaspaGetAddress.d.ts.map +1 -1
  238. package/dist/api/kaspa/KaspaSignTransaction.d.ts +9 -1
  239. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  240. package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
  241. package/dist/api/lightning/LnurlAuth.d.ts +0 -4
  242. package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
  243. package/dist/api/near/NearGetAddress.d.ts +1 -0
  244. package/dist/api/near/NearGetAddress.d.ts.map +1 -1
  245. package/dist/api/near/NearSignTransaction.d.ts +1 -0
  246. package/dist/api/near/NearSignTransaction.d.ts.map +1 -1
  247. package/dist/api/nem/NEMGetAddress.d.ts +1 -0
  248. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -1
  249. package/dist/api/nem/NEMSignTransaction.d.ts +1 -0
  250. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  251. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  252. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  253. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  254. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  255. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  256. package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
  257. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  258. package/dist/api/nostr/NostrDecryptMessage.d.ts +1 -0
  259. package/dist/api/nostr/NostrDecryptMessage.d.ts.map +1 -1
  260. package/dist/api/nostr/NostrEncryptMessage.d.ts +1 -0
  261. package/dist/api/nostr/NostrEncryptMessage.d.ts.map +1 -1
  262. package/dist/api/nostr/NostrGetPublicKey.d.ts +1 -0
  263. package/dist/api/nostr/NostrGetPublicKey.d.ts.map +1 -1
  264. package/dist/api/nostr/NostrSignEvent.d.ts +1 -0
  265. package/dist/api/nostr/NostrSignEvent.d.ts.map +1 -1
  266. package/dist/api/nostr/NostrSignSchnorr.d.ts +1 -0
  267. package/dist/api/nostr/NostrSignSchnorr.d.ts.map +1 -1
  268. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -0
  269. package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
  270. package/dist/api/polkadot/PolkadotSignTransaction.d.ts +1 -0
  271. package/dist/api/polkadot/PolkadotSignTransaction.d.ts.map +1 -1
  272. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +7 -0
  273. package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
  274. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +8 -0
  275. package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
  276. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +2 -1
  277. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
  278. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +4 -2
  279. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  280. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +2 -1
  281. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
  282. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +29 -0
  283. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
  284. package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -0
  285. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  286. package/dist/api/protocol-v2/DeviceStatusGet.d.ts +7 -0
  287. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
  288. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +27 -0
  289. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
  290. package/dist/api/protocol-v2/FilesystemFormat.d.ts +1 -0
  291. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
  292. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +7 -0
  293. package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
  294. package/dist/api/protocol-v2/Ping.d.ts +3 -0
  295. package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
  296. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +7 -0
  297. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
  298. package/dist/api/protocol-v2/helpers.d.ts +27 -18
  299. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  300. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  301. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  302. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  303. package/dist/api/solana/SolGetAddress.d.ts +1 -0
  304. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  305. package/dist/api/solana/SolSignMessage.d.ts +1 -0
  306. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  307. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -0
  308. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  309. package/dist/api/solana/SolSignTransaction.d.ts +1 -0
  310. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  311. package/dist/api/starcoin/StarcoinGetAddress.d.ts +1 -0
  312. package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -1
  313. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +1 -0
  314. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -1
  315. package/dist/api/starcoin/StarcoinSignMessage.d.ts +1 -0
  316. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  317. package/dist/api/starcoin/StarcoinSignTransaction.d.ts +1 -0
  318. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  319. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +1 -0
  320. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -1
  321. package/dist/api/stellar/StellarGetAddress.d.ts +1 -2
  322. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  323. package/dist/api/stellar/StellarSignTransaction.d.ts +2 -3
  324. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  325. package/dist/api/sui/SuiGetAddress.d.ts +1 -0
  326. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  327. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -0
  328. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  329. package/dist/api/sui/SuiSignMessage.d.ts +1 -0
  330. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  331. package/dist/api/sui/SuiSignTransaction.d.ts +1 -0
  332. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  333. package/dist/api/ton/TonGetAddress.d.ts +1 -0
  334. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  335. package/dist/api/ton/TonSignData.d.ts +2 -5
  336. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  337. package/dist/api/ton/TonSignMessage.d.ts +1 -0
  338. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  339. package/dist/api/ton/TonSignProof.d.ts +1 -0
  340. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  341. package/dist/api/tron/TronGetAddress.d.ts +1 -0
  342. package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
  343. package/dist/api/tron/TronSignMessage.d.ts +5 -0
  344. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  345. package/dist/api/tron/TronSignTransaction.d.ts +1 -0
  346. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  347. package/dist/api/utils.d.ts +2 -1
  348. package/dist/api/utils.d.ts.map +1 -1
  349. package/dist/api/xrp/XrpGetAddress.d.ts +1 -0
  350. package/dist/api/xrp/XrpGetAddress.d.ts.map +1 -1
  351. package/dist/api/xrp/XrpSignTransaction.d.ts +1 -0
  352. package/dist/api/xrp/XrpSignTransaction.d.ts.map +1 -1
  353. package/dist/constants/index.d.ts +1 -1
  354. package/dist/constants/index.d.ts.map +1 -1
  355. package/dist/core/RequestQueue.d.ts.map +1 -1
  356. package/dist/core/deviceEventRegistration.d.ts +11 -0
  357. package/dist/core/deviceEventRegistration.d.ts.map +1 -0
  358. package/dist/core/index.d.ts +3 -1
  359. package/dist/core/index.d.ts.map +1 -1
  360. package/dist/data-manager/DataManager.d.ts +2 -1
  361. package/dist/data-manager/DataManager.d.ts.map +1 -1
  362. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  363. package/dist/device/Device.d.ts +40 -13
  364. package/dist/device/Device.d.ts.map +1 -1
  365. package/dist/device/DeviceCommands.d.ts +8 -6
  366. package/dist/device/DeviceCommands.d.ts.map +1 -1
  367. package/dist/device/DeviceFeaturesState.d.ts +3 -0
  368. package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
  369. package/dist/device/DevicePool.d.ts +4 -2
  370. package/dist/device/DevicePool.d.ts.map +1 -1
  371. package/dist/device/DeviceStateMapper.d.ts +13 -0
  372. package/dist/device/DeviceStateMapper.d.ts.map +1 -0
  373. package/dist/device/DeviceStateProjector.d.ts +7 -0
  374. package/dist/device/DeviceStateProjector.d.ts.map +1 -0
  375. package/dist/device/DeviceStateStore.d.ts +21 -0
  376. package/dist/device/DeviceStateStore.d.ts.map +1 -0
  377. package/dist/device/DeviceWalletSessionStore.d.ts +20 -0
  378. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
  379. package/dist/device/cloneDeviceState.d.ts +2 -0
  380. package/dist/device/cloneDeviceState.d.ts.map +1 -0
  381. package/dist/device/deviceIdentity.d.ts +5 -0
  382. package/dist/device/deviceIdentity.d.ts.map +1 -0
  383. package/dist/deviceProfile/buildDeviceFeatures.d.ts +9 -3
  384. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  385. package/dist/deviceProfile/index.d.ts +0 -1
  386. package/dist/deviceProfile/index.d.ts.map +1 -1
  387. package/dist/events/device.d.ts +12 -2
  388. package/dist/events/device.d.ts.map +1 -1
  389. package/dist/events/logBlockEvent.d.ts.map +1 -1
  390. package/dist/events/ui-request.d.ts +19 -2
  391. package/dist/events/ui-request.d.ts.map +1 -1
  392. package/dist/index.d.ts +1487 -691
  393. package/dist/index.d.ts.map +1 -1
  394. package/dist/index.js +8831 -4014
  395. package/dist/inject.d.ts.map +1 -1
  396. package/dist/lowLevelInject.d.ts.map +1 -1
  397. package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
  398. package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
  399. package/dist/protocols/protocol-v2/features.d.ts +23 -28
  400. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  401. package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
  402. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  403. package/dist/protocols/protocol-v2/index.d.ts +3 -2
  404. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  405. package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
  406. package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
  407. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +16 -0
  408. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
  409. package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
  410. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
  411. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +4 -0
  412. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
  413. package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
  414. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
  415. package/dist/protocols/protocol-v2/walletSession.d.ts +31 -0
  416. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
  417. package/dist/topLevelInject.d.ts.map +1 -1
  418. package/dist/types/api/checkAllFirmwareRelease.d.ts +5 -2
  419. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  420. package/dist/types/api/deviceSettings.d.ts +11 -2
  421. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  422. package/dist/types/api/deviceUnlock.d.ts +1 -1
  423. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  424. package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
  425. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  426. package/dist/types/api/export.d.ts +5 -2
  427. package/dist/types/api/export.d.ts.map +1 -1
  428. package/dist/types/api/firmwareUpdate.d.ts +75 -6
  429. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  430. package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
  431. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
  432. package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
  433. package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
  434. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
  435. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
  436. package/dist/types/api/getDeviceState.d.ts +12 -0
  437. package/dist/types/api/getDeviceState.d.ts.map +1 -0
  438. package/dist/types/api/getFeatures.d.ts.map +1 -1
  439. package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
  440. package/dist/types/api/getPassphraseState.d.ts +2 -10
  441. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  442. package/dist/types/api/index.d.ts +25 -35
  443. package/dist/types/api/index.d.ts.map +1 -1
  444. package/dist/types/api/kaspaSignTransaction.d.ts +42 -4
  445. package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
  446. package/dist/types/api/openWalletSession.d.ts +29 -0
  447. package/dist/types/api/openWalletSession.d.ts.map +1 -0
  448. package/dist/types/api/protocolV2.d.ts +15 -89
  449. package/dist/types/api/protocolV2.d.ts.map +1 -1
  450. package/dist/types/api/sessionCache.d.ts +13 -0
  451. package/dist/types/api/sessionCache.d.ts.map +1 -0
  452. package/dist/types/device.d.ts +122 -6
  453. package/dist/types/device.d.ts.map +1 -1
  454. package/dist/types/params.d.ts +1 -0
  455. package/dist/types/params.d.ts.map +1 -1
  456. package/dist/types/settings.d.ts +34 -2
  457. package/dist/types/settings.d.ts.map +1 -1
  458. package/dist/utils/assets.d.ts +2 -1
  459. package/dist/utils/assets.d.ts.map +1 -1
  460. package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
  461. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
  462. package/dist/utils/deviceFeaturesUtils.d.ts +11 -3
  463. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  464. package/dist/utils/deviceInfoUtils.d.ts +9 -9
  465. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  466. package/dist/utils/deviceSettings.d.ts +38 -7
  467. package/dist/utils/deviceSettings.d.ts.map +1 -1
  468. package/dist/utils/deviceVersionUtils.d.ts +7 -5
  469. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  470. package/dist/utils/homescreen.d.ts.map +1 -1
  471. package/dist/utils/index.d.ts +5 -2
  472. package/dist/utils/index.d.ts.map +1 -1
  473. package/dist/utils/networkUtils.d.ts +9 -1
  474. package/dist/utils/networkUtils.d.ts.map +1 -1
  475. package/dist/utils/patch.d.ts +1 -1
  476. package/dist/utils/patch.d.ts.map +1 -1
  477. package/dist/utils/pro2Wallpaper.d.ts +12 -0
  478. package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
  479. package/dist/utils/tracing.d.ts.map +1 -1
  480. package/package.json +4 -4
  481. package/src/api/BaseMethod.ts +52 -17
  482. package/src/api/CheckAllFirmwareRelease.ts +51 -4
  483. package/src/api/CheckBootloaderRelease.ts +1 -2
  484. package/src/api/CheckFirmwareRelease.ts +1 -2
  485. package/src/api/CipherKeyValue.ts +4 -0
  486. package/src/api/ClearSessionCache.ts +32 -0
  487. package/src/api/DirList.ts +9 -4
  488. package/src/api/DirMake.ts +7 -4
  489. package/src/api/DirRemove.ts +7 -4
  490. package/src/api/FileDelete.ts +7 -4
  491. package/src/api/FileRead.ts +27 -8
  492. package/src/api/FileWrite.ts +26 -168
  493. package/src/api/FirmwareUpdate.ts +11 -12
  494. package/src/api/FirmwareUpdateV2.ts +370 -112
  495. package/src/api/FirmwareUpdateV3.ts +266 -68
  496. package/src/api/FirmwareUpdateV4.ts +1687 -397
  497. package/src/api/GetDeviceState.ts +59 -0
  498. package/src/api/GetFeatures.ts +6 -4
  499. package/src/api/GetOnekeyFeatures.ts +1 -75
  500. package/src/api/GetPassphraseState.ts +21 -21
  501. package/src/api/OpenWalletSession.ts +202 -0
  502. package/src/api/PathInfo.ts +9 -4
  503. package/src/api/PromptWebDeviceAccess.ts +2 -3
  504. package/src/api/SearchDevices.ts +29 -4
  505. package/src/api/UploadPortfolio.ts +40 -0
  506. package/src/api/alephium/AlephiumGetAddress.ts +0 -4
  507. package/src/api/alephium/AlephiumSignMessage.ts +0 -4
  508. package/src/api/alephium/AlephiumSignTransaction.ts +2 -6
  509. package/src/api/algo/AlgoGetAddress.ts +4 -0
  510. package/src/api/algo/AlgoSignTransaction.ts +4 -0
  511. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +9 -21
  512. package/src/api/aptos/AptosGetAddress.ts +4 -0
  513. package/src/api/aptos/AptosGetPublicKey.ts +4 -0
  514. package/src/api/aptos/AptosSignInMessage.ts +4 -0
  515. package/src/api/aptos/AptosSignMessage.ts +4 -0
  516. package/src/api/aptos/AptosSignTransaction.ts +4 -0
  517. package/src/api/benfen/BenfenGetAddress.ts +11 -7
  518. package/src/api/benfen/BenfenGetPublicKey.ts +0 -4
  519. package/src/api/benfen/BenfenSignMessage.ts +0 -4
  520. package/src/api/benfen/BenfenSignTransaction.ts +0 -4
  521. package/src/api/btc/BTCGetAddress.ts +8 -1
  522. package/src/api/btc/BTCGetPublicKey.ts +9 -2
  523. package/src/api/btc/BTCSignMessage.ts +8 -1
  524. package/src/api/btc/BTCSignPsbt.ts +4 -0
  525. package/src/api/btc/BTCSignTransaction.ts +8 -1
  526. package/src/api/btc/BTCVerifyMessage.ts +8 -1
  527. package/src/api/btc/helpers/versionLimit.ts +7 -4
  528. package/src/api/cardano/CardanoGetAddress.ts +4 -0
  529. package/src/api/cardano/CardanoGetPublicKey.ts +4 -0
  530. package/src/api/cardano/CardanoSignMessage.ts +5 -1
  531. package/src/api/cardano/CardanoSignTransaction.ts +5 -1
  532. package/src/api/conflux/ConfluxGetAddress.ts +6 -0
  533. package/src/api/conflux/ConfluxSignMessage.ts +6 -0
  534. package/src/api/conflux/ConfluxSignMessageCIP23.ts +6 -0
  535. package/src/api/conflux/ConfluxSignTransaction.ts +8 -5
  536. package/src/api/cosmos/CosmosGetAddress.ts +4 -0
  537. package/src/api/cosmos/CosmosGetPublicKey.ts +4 -0
  538. package/src/api/cosmos/CosmosSignTransaction.ts +4 -0
  539. package/src/api/device/DeviceCancel.ts +5 -0
  540. package/src/api/device/DeviceChangePin.ts +28 -0
  541. package/src/api/device/DeviceFullyUploadResource.ts +4 -5
  542. package/src/api/device/DeviceLock.ts +5 -0
  543. package/src/api/device/DeviceRebootToBoardloader.ts +9 -4
  544. package/src/api/device/DeviceRebootToBootloader.ts +9 -4
  545. package/src/api/device/DeviceSettings.ts +187 -1
  546. package/src/api/device/DeviceSupportFeatures.ts +4 -0
  547. package/src/api/device/DeviceUnlock.ts +13 -0
  548. package/src/api/device/DeviceUpdateBootloader.ts +123 -8
  549. package/src/api/device/DeviceWipe.ts +25 -0
  550. package/src/api/device/PreInitialize.ts +4 -0
  551. package/src/api/dynex/DnxGetAddress.ts +0 -6
  552. package/src/api/dynex/DnxSignTransaction.ts +0 -6
  553. package/src/api/evm/EVMGetAddress.ts +4 -0
  554. package/src/api/evm/EVMGetPublicKey.ts +4 -0
  555. package/src/api/evm/EVMSignMessage.ts +4 -0
  556. package/src/api/evm/EVMSignMessageEIP712.ts +1 -11
  557. package/src/api/evm/EVMSignTransaction.ts +4 -0
  558. package/src/api/evm/EVMSignTypedData.ts +7 -5
  559. package/src/api/evm/EVMVerifyMessage.ts +4 -0
  560. package/src/api/evm/legacyV1/getAddress.ts +2 -2
  561. package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
  562. package/src/api/evm/legacyV1/signMessage.ts +2 -2
  563. package/src/api/evm/legacyV1/signTypedData.ts +2 -2
  564. package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
  565. package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
  566. package/src/api/filecoin/FilecoinGetAddress.ts +4 -0
  567. package/src/api/filecoin/FilecoinSignTransaction.ts +4 -0
  568. package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
  569. package/src/api/firmware/FirmwareHostBinding.ts +100 -0
  570. package/src/api/firmware/FirmwarePreparationError.ts +12 -0
  571. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +71 -7
  572. package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
  573. package/src/api/firmware/FirmwareUpdatePlan.ts +745 -0
  574. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +392 -0
  575. package/src/api/firmware/getBinary.ts +8 -3
  576. package/src/api/firmware/progressThrottle.ts +44 -0
  577. package/src/api/firmware/updateBootloader.ts +19 -4
  578. package/src/api/firmware/uploadFirmware.ts +140 -22
  579. package/src/api/helpers/batchGetPublickeys.ts +2 -2
  580. package/src/api/helpers/filesystemValidation.ts +61 -0
  581. package/src/api/helpers/paramsValidator.ts +1 -1
  582. package/src/api/helpers/protocolV2FileWrite.ts +199 -0
  583. package/src/api/index.ts +7 -30
  584. package/src/api/kaspa/KaspaGetAddress.ts +7 -0
  585. package/src/api/kaspa/KaspaSignTransaction.ts +373 -29
  586. package/src/api/kaspa/helpers/TransferSerialize.ts +17 -7
  587. package/src/api/lightning/LnurlAuth.ts +0 -4
  588. package/src/api/near/NearGetAddress.ts +4 -0
  589. package/src/api/near/NearSignTransaction.ts +4 -0
  590. package/src/api/nem/NEMGetAddress.ts +4 -0
  591. package/src/api/nem/NEMSignTransaction.ts +4 -0
  592. package/src/api/neo/NeoGetAddress.ts +0 -4
  593. package/src/api/neo/NeoSignTransaction.ts +0 -4
  594. package/src/api/nervos/NervosGetAddress.ts +0 -4
  595. package/src/api/nervos/NervosSignTransaction.ts +2 -6
  596. package/src/api/nexa/NexaGetAddress.ts +0 -4
  597. package/src/api/nexa/NexaSignTransaction.ts +3 -5
  598. package/src/api/nostr/NostrDecryptMessage.ts +4 -0
  599. package/src/api/nostr/NostrEncryptMessage.ts +4 -0
  600. package/src/api/nostr/NostrGetPublicKey.ts +4 -0
  601. package/src/api/nostr/NostrSignEvent.ts +4 -0
  602. package/src/api/nostr/NostrSignSchnorr.ts +4 -0
  603. package/src/api/polkadot/PolkadotGetAddress.ts +4 -0
  604. package/src/api/polkadot/PolkadotSignTransaction.ts +4 -0
  605. package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +8 -5
  606. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +35 -0
  607. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +11 -10
  608. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +45 -7
  609. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +10 -5
  610. package/src/api/protocol-v2/DeviceInfoGet.ts +141 -0
  611. package/src/api/protocol-v2/DeviceReboot.ts +8 -4
  612. package/src/api/protocol-v2/DeviceStatusGet.ts +19 -0
  613. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +134 -0
  614. package/src/api/protocol-v2/FilesystemFormat.ts +9 -3
  615. package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +7 -4
  616. package/src/api/protocol-v2/Ping.ts +37 -3
  617. package/src/api/protocol-v2/ProtocolInfoRequest.ts +19 -0
  618. package/src/api/protocol-v2/helpers.ts +71 -50
  619. package/src/api/scdo/ScdoGetAddress.ts +0 -4
  620. package/src/api/scdo/ScdoSignMessage.ts +0 -4
  621. package/src/api/scdo/ScdoSignTransaction.ts +0 -4
  622. package/src/api/solana/SolGetAddress.ts +4 -0
  623. package/src/api/solana/SolSignMessage.ts +4 -0
  624. package/src/api/solana/SolSignOffchainMessage.ts +4 -0
  625. package/src/api/solana/SolSignTransaction.ts +4 -0
  626. package/src/api/starcoin/StarcoinGetAddress.ts +4 -0
  627. package/src/api/starcoin/StarcoinGetPublicKey.ts +4 -0
  628. package/src/api/starcoin/StarcoinSignMessage.ts +4 -0
  629. package/src/api/starcoin/StarcoinSignTransaction.ts +4 -0
  630. package/src/api/starcoin/StarcoinVerifyMessage.ts +4 -0
  631. package/src/api/stellar/StellarGetAddress.ts +1 -10
  632. package/src/api/stellar/StellarSignTransaction.ts +1 -14
  633. package/src/api/sui/SuiGetAddress.ts +4 -0
  634. package/src/api/sui/SuiGetPublicKey.ts +4 -0
  635. package/src/api/sui/SuiSignMessage.ts +4 -0
  636. package/src/api/sui/SuiSignTransaction.ts +4 -0
  637. package/src/api/ton/TonGetAddress.ts +4 -0
  638. package/src/api/ton/TonSignData.ts +6 -6
  639. package/src/api/ton/TonSignMessage.ts +4 -0
  640. package/src/api/ton/TonSignProof.ts +4 -0
  641. package/src/api/tron/TronGetAddress.ts +4 -0
  642. package/src/api/tron/TronSignMessage.ts +18 -7
  643. package/src/api/tron/TronSignTransaction.ts +4 -0
  644. package/src/api/utils.ts +7 -3
  645. package/src/api/xrp/XrpGetAddress.ts +4 -0
  646. package/src/api/xrp/XrpSignTransaction.ts +5 -1
  647. package/src/constants/index.ts +1 -4
  648. package/src/core/RequestQueue.ts +1 -0
  649. package/src/core/deviceEventRegistration.ts +23 -0
  650. package/src/core/index.ts +181 -58
  651. package/src/data/messages/messages-protocol-v2.json +796 -620
  652. package/src/data/messages/messages.json +286 -1
  653. package/src/data-manager/DataManager.ts +45 -38
  654. package/src/data-manager/TransportManager.ts +1 -1
  655. package/src/data-manager/connectSettings.ts +13 -4
  656. package/src/device/Device.ts +573 -278
  657. package/src/device/DeviceCommands.ts +154 -156
  658. package/src/device/DeviceFeaturesState.ts +25 -0
  659. package/src/device/DevicePool.ts +61 -13
  660. package/src/device/DeviceStateMapper.ts +366 -0
  661. package/src/device/DeviceStateProjector.ts +101 -0
  662. package/src/device/DeviceStateStore.ts +201 -0
  663. package/src/device/DeviceWalletSessionStore.ts +105 -0
  664. package/src/device/cloneDeviceState.ts +39 -0
  665. package/src/device/deviceIdentity.ts +18 -0
  666. package/src/deviceProfile/buildDeviceFeatures.ts +234 -210
  667. package/src/deviceProfile/index.ts +0 -1
  668. package/src/events/device.ts +18 -1
  669. package/src/events/logBlockEvent.ts +1 -7
  670. package/src/events/ui-request.ts +25 -2
  671. package/src/index.ts +5 -0
  672. package/src/inject.ts +35 -47
  673. package/src/lowLevelInject.ts +5 -1
  674. package/src/protocols/protocol-v2/deviceSession.ts +24 -0
  675. package/src/protocols/protocol-v2/features.ts +68 -83
  676. package/src/protocols/protocol-v2/firmware.ts +12 -36
  677. package/src/protocols/protocol-v2/index.ts +3 -1
  678. package/src/protocols/protocol-v2/lockedError.ts +10 -0
  679. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +60 -0
  680. package/src/protocols/protocol-v2/uiInteraction.ts +210 -0
  681. package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
  682. package/src/protocols/protocol-v2/unlockRetry.ts +98 -0
  683. package/src/protocols/protocol-v2/walletSession.ts +202 -0
  684. package/src/topLevelInject.ts +5 -1
  685. package/src/types/api/checkAllFirmwareRelease.ts +5 -2
  686. package/src/types/api/deviceSettings.ts +26 -2
  687. package/src/types/api/deviceUnlock.ts +1 -1
  688. package/src/types/api/deviceUpdateBootloader.ts +6 -0
  689. package/src/types/api/export.ts +21 -0
  690. package/src/types/api/firmwareUpdate.ts +103 -19
  691. package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
  692. package/src/types/api/firmwareUpdatePlan.ts +38 -0
  693. package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
  694. package/src/types/api/getDeviceState.ts +19 -0
  695. package/src/types/api/getFeatures.ts +3 -0
  696. package/src/types/api/getOnekeyFeatures.ts +3 -0
  697. package/src/types/api/getPassphraseState.ts +9 -11
  698. package/src/types/api/index.ts +33 -73
  699. package/src/types/api/kaspaSignTransaction.ts +60 -4
  700. package/src/types/api/openWalletSession.ts +45 -0
  701. package/src/types/api/protocolV2.ts +23 -162
  702. package/src/types/api/sessionCache.ts +19 -0
  703. package/src/types/device.ts +172 -5
  704. package/src/types/params.ts +4 -0
  705. package/src/types/settings.ts +55 -35
  706. package/src/utils/assets.ts +4 -1
  707. package/src/utils/deviceFeaturesCompat.ts +173 -0
  708. package/src/utils/deviceFeaturesUtils.ts +66 -24
  709. package/src/utils/deviceInfoUtils.ts +27 -69
  710. package/src/utils/deviceSettings.ts +171 -39
  711. package/src/utils/deviceVersionUtils.ts +25 -44
  712. package/src/utils/findDefectiveBatchDevice.ts +3 -3
  713. package/src/utils/homescreen.ts +10 -0
  714. package/src/utils/index.ts +21 -2
  715. package/src/utils/networkUtils.ts +270 -14
  716. package/src/utils/pro2Wallpaper.ts +109 -0
  717. package/src/utils/tracing.ts +3 -1
  718. package/tsconfig.type-tests.json +8 -0
  719. package/dist/api/GetDeviceInfo.d.ts +0 -9
  720. package/dist/api/GetDeviceInfo.d.ts.map +0 -1
  721. package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
  722. package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
  723. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +0 -29
  724. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
  725. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
  726. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
  727. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
  728. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
  729. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
  730. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
  731. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +0 -6
  732. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
  733. package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
  734. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
  735. package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -21
  736. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
  737. package/dist/types/api/getDeviceInfo.d.ts +0 -85
  738. package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
  739. package/src/api/GetDeviceInfo.ts +0 -145
  740. package/src/api/protocol-v2/DevReboot.ts +0 -24
  741. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +0 -118
  742. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
  743. package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
  744. package/src/api/protocol-v2/GetProtoVersion.ts +0 -16
  745. package/src/deviceProfile/buildDeviceProfile.ts +0 -333
  746. package/src/types/api/getDeviceInfo.ts +0 -99
@@ -1,39 +1,45 @@
1
1
  import EventEmitter from 'events';
2
2
  import semver from 'semver';
3
- import { Enum_Capability } from '@onekeyfe/hd-transport';
3
+ import { DeviceRebootType, DeviceSessionPinType, Enum_Capability } from '@onekeyfe/hd-transport';
4
4
  import {
5
5
  EDeviceType,
6
+ EFirmwareType,
6
7
  ERRORS,
7
8
  ERROR_CODES_REQUIRE_DISCONNECT,
8
9
  ERROR_CODES_REQUIRE_RELEASE,
9
10
  HardwareError,
10
11
  HardwareErrorCode,
11
12
  createDeferred,
13
+ createDeviceNotSupportMethodError,
12
14
  } from '@onekeyfe/hd-shared';
13
15
 
14
- import {
15
- LoggerNames,
16
- getDeviceBLEFirmwareVersion,
17
- getDeviceBleName,
18
- getDeviceFirmwareVersion,
19
- getDeviceLabel,
20
- getDeviceType,
21
- getDeviceUUID,
22
- getFirmwareType,
23
- getLogger,
24
- } from '../utils';
16
+ import { LoggerNames, getLogger } from '../utils';
25
17
  import {
26
18
  fixFeaturesFirmwareVersion,
27
19
  getPassphraseStateWithRefreshDeviceInfo,
28
- supportInputPinOnSoftware,
29
- supportModifyHomescreen,
30
20
  } from '../utils/deviceFeaturesUtils';
21
+ import { parseDeviceVersion } from '../utils/deviceVersionUtils';
31
22
  import { generateInstanceId } from '../utils/tracing';
32
23
  // eslint-disable-next-line import/no-cycle
33
24
  import { DeviceCommands } from './DeviceCommands';
25
+ import { mergeDeviceFeaturesPatch } from './DeviceFeaturesState';
26
+ import {
27
+ mapDeviceSettingsToState,
28
+ mapFeaturesToState,
29
+ mapProtocolV1OnekeyFeaturesToState,
30
+ mapProtocolV2DeviceInfoToState,
31
+ mapProtocolV2DeviceStatusToState,
32
+ } from './DeviceStateMapper';
33
+ import { projectFeatures } from './DeviceStateProjector';
34
+ import { DeviceStateStore, createPublicDeviceState } from './DeviceStateStore';
35
+ import { cloneDeviceState } from './cloneDeviceState';
36
+ import { deviceWalletSessionStore } from './DeviceWalletSessionStore';
34
37
  import {
35
38
  type DeviceFirmwareRange,
36
39
  DeviceModelToTypes,
40
+ type DeviceStateEvent,
41
+ type DeviceStatePatch,
42
+ type DeviceStateUpdateSource,
37
43
  DeviceTypeToModels,
38
44
  type Device as DeviceTyped,
39
45
  EOneKeyDeviceMode,
@@ -48,14 +54,19 @@ import { DEVICE, UI_REQUEST } from '../events';
48
54
  import { DataManager } from '../data-manager';
49
55
  import TransportManager from '../data-manager/TransportManager';
50
56
  import { toHardened } from '../api/helpers/pathUtils';
51
- import { existCapability } from '../utils/capabilitieUtils';
52
57
  import {
53
- PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
58
+ PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST,
59
+ PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST,
60
+ PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST,
61
+ type ProtocolV2RuntimeMode,
62
+ getProtocolV2RuntimeMode,
54
63
  requestProtocolV2DeviceInfo,
64
+ requestProtocolV2DeviceStatus,
55
65
  } from '../protocols/protocol-v2/features';
56
- import { buildProtocolV1FeaturesPayload, buildProtocolV2FeaturesPayload } from '../deviceProfile';
66
+ import { buildProtocolV1FeaturesPayload } from '../deviceProfile';
57
67
 
58
68
  import type { PROTO } from '../constants';
69
+ import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
59
70
  import type {
60
71
  DeviceButtonRequestPayload,
61
72
  DeviceFeaturesPayload,
@@ -65,6 +76,7 @@ import type { PassphrasePromptResponse } from './DeviceCommands';
65
76
  import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
66
77
  import type {
67
78
  OneKeyDeviceInfo as DeviceDescriptor,
79
+ DeviceStatus,
68
80
  ProtocolV2DeviceInfo,
69
81
  Success,
70
82
  } from '@onekeyfe/hd-transport';
@@ -76,6 +88,9 @@ export type InitOptions = {
76
88
  passphraseState?: string;
77
89
  deriveCardano?: boolean;
78
90
  connectProtocol?: HardwareConnectProtocol;
91
+ protocolV2DeviceInfoTimeoutMs?: number;
92
+ /** Refresh Protocol V2 runtime state before returning discovery results. */
93
+ refreshRuntimeState?: boolean;
79
94
  };
80
95
 
81
96
  export type RunOptions = {
@@ -92,9 +107,11 @@ const Log = getLogger(LoggerNames.Device);
92
107
 
93
108
  export interface DeviceEvents {
94
109
  [DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
95
- [DEVICE.PASSPHRASE_ON_DEVICE]: [Device, ((response: any) => void)?];
110
+ [DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
111
+ [DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
96
112
  [DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
97
113
  [DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
114
+ [DEVICE.STATE]: [Device, DeviceStateEvent];
98
115
  [DEVICE.PASSPHRASE]: [
99
116
  Device,
100
117
  PassphraseRequestPayload,
@@ -118,15 +135,14 @@ export interface Device {
118
135
  emit<K extends keyof DeviceEvents>(type: K, ...args: DeviceEvents[K]): boolean;
119
136
  }
120
137
 
121
- const deviceSessionCache: Record<string, string> = {};
122
-
123
138
  /**
124
139
  * Pre-populate the device session cache with a known session ID.
125
140
  *
126
141
  * This allows short-lived processes (e.g. CLI) to restore a previously
127
142
  * obtained session, avoiding the need to re-enter passphrase on every
128
143
  * invocation. The session must have been obtained from a prior
129
- * getPassphraseState() call on the same device.
144
+ * wallet-session call on the same device. This compatibility hook is intended
145
+ * for a trusted CLI process restoring its own OS-keychain entry.
130
146
  *
131
147
  * @param deviceId - The device's device_id (from features)
132
148
  * @param passphraseState - The passphrase state token
@@ -137,8 +153,7 @@ export function preloadSessionCache(
137
153
  passphraseState: string,
138
154
  sessionId: string
139
155
  ): void {
140
- const key = `${deviceId}@${passphraseState}`;
141
- deviceSessionCache[key] = sessionId;
156
+ deviceWalletSessionStore.set(deviceId, passphraseState, sessionId);
142
157
  }
143
158
 
144
159
  export class Device extends EventEmitter {
@@ -184,22 +199,34 @@ export class Device extends EventEmitter {
184
199
  */
185
200
  private deviceAcquired = false;
186
201
 
187
- /**
188
- * 唯一设备状态缓存。
189
- *
190
- * V1 直接保存原生 Features;V2 保存由 DevGetDeviceInfo 映射出的
191
- * Features 视图。Device 不再保存 profile,结构化 DeviceProfile 只作为
192
- * getDeviceInfo() 的 API 返回值存在。
193
- */
194
- features: Features | undefined = undefined;
202
+ /** Canonical device-state cache; legacy Features is a compatibility projection. */
203
+ private stateStore = new DeviceStateStore();
195
204
 
196
- /**
197
- * 是否需要更新设备信息。
198
- *
199
- * 历史名称保留用于兼容现有调用语义;对 V2 表示 features 需要由
200
- * DevGetDeviceInfo 刷新。
201
- */
202
- featuresNeedsReload = false;
205
+ /** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
206
+ private protocolV2StateNeedsReload = false;
207
+
208
+ get state() {
209
+ return this.stateStore.getState();
210
+ }
211
+
212
+ get features(): Features | undefined {
213
+ if (!this.state) return undefined;
214
+ return projectFeatures(this.state);
215
+ }
216
+
217
+ set features(features: Features | undefined) {
218
+ this.stateStore = new DeviceStateStore();
219
+ if (features) {
220
+ this.stateStore.update(mapFeaturesToState(features), 'compatibility');
221
+ const { passphraseState } = features;
222
+ const sessionId = features.sessionId ?? features.session_id;
223
+ const deviceKey = this.getSessionCacheDeviceKey(features.deviceId ?? undefined);
224
+ if (passphraseState && sessionId && deviceKey) {
225
+ this.passphraseState = passphraseState;
226
+ deviceWalletSessionStore.set(deviceKey, passphraseState, sessionId);
227
+ }
228
+ }
229
+ }
203
230
 
204
231
  runPromise?: Deferred<void> | null;
205
232
 
@@ -259,32 +286,38 @@ export class Device extends EventEmitter {
259
286
  const deviceType = this.getCurrentDeviceType();
260
287
 
261
288
  const bleName = this.getCurrentBleName();
262
- const label = this.getCurrentLabel();
289
+ const displayName = this.getCurrentDisplayName();
263
290
  const serialNo = this.getCurrentSerialNo();
264
291
  const connectId = this.getConnectId();
265
292
  const deviceId = this.getCurrentDeviceId() || null;
266
293
 
267
- const features = this.features;
294
+ const { features } = this;
295
+ const state = this.state ? createPublicDeviceState(this.state) : undefined;
268
296
 
269
297
  return {
270
- /** Android uses Mac address, iOS uses uuid, USB uses uuid */
298
+ /** Android uses a MAC address, while iOS and USB use transport-specific identifiers. */
271
299
  connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
272
- /** Hardware ID, will not change at any time */
300
+ /** Stable physical-device identity. */
301
+ serialNo,
302
+ /** @deprecated Use serialNo instead. */
273
303
  uuid: serialNo,
274
304
  commType: this.originalDescriptor.commType,
275
305
  sdkInstanceId: this.sdkInstanceId,
276
306
  instanceId: this.instanceId,
277
307
  createdAt: this.createdAt,
278
308
  deviceType,
279
- /** ID for current seeds, will clear after replace a new seed at device */
309
+ /** Wallet-lifecycle ID; changes after the device is wiped or reinitialized. */
280
310
  deviceId,
281
311
  path: this.originalDescriptor?.path,
282
312
  bleName,
283
- name: bleName || label || `OneKey ${deviceType?.toUpperCase()}`,
284
- label: label || 'OneKey',
313
+ name: displayName || bleName || `OneKey ${deviceType?.toUpperCase()}`,
314
+ // Keep the legacy top-level field string-compatible while preserving
315
+ // the canonical nullable value at state.identity.label.
316
+ label: displayName ?? '',
317
+ status: this.getStatus(),
285
318
  mode: this.getMode(),
286
319
  features,
287
- sessionId: this.features?.sessionId ?? null,
320
+ state,
288
321
  firmwareVersion: this.getFirmwareVersion(),
289
322
  bleFirmwareVersion: this.getBLEFirmwareVersion(),
290
323
  unavailableCapabilities: this.unavailableCapabilities,
@@ -300,6 +333,10 @@ export class Device extends EventEmitter {
300
333
  // eslint-disable-next-line no-async-promise-executor
301
334
  return new Promise<boolean>(async (resolve, reject) => {
302
335
  if (DataManager.isBleConnect(env)) {
336
+ if (this.hasDeviceAcquire() && this.commands && !this.commands.disposed) {
337
+ resolve(true);
338
+ return;
339
+ }
303
340
  try {
304
341
  await this.acquire(connectProtocol);
305
342
  resolve(true);
@@ -326,18 +363,20 @@ export class Device extends EventEmitter {
326
363
  });
327
364
  }
328
365
 
329
- async acquire(connectProtocol?: HardwareConnectProtocol) {
366
+ async acquire(
367
+ connectProtocol?: HardwareConnectProtocol,
368
+ options?: { throwOnRunPromiseError?: boolean }
369
+ ) {
330
370
  const env = DataManager.getSettings('env');
331
371
  const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
332
372
  const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
333
373
  try {
334
374
  let acquireResult: unknown;
335
375
  if (DataManager.isBleConnect(env)) {
336
- // forceCleanRunPromise=true(自 e21b83c6 引入,修复 Pro2 BLE 重连):
337
- // acquire 意味着开启一个全新会话,transport 里残留的上一次 runPromise
338
- // 必然属于已死亡的会话(如固件升级重启、探测中断),不清理会让新会话的
339
- // 调用被旧 promise 卡死。无法在 Device 层面区分“重连恢复”与普通 acquire,
340
- // 因此对 BLE acquire 恒清理是有意为之。
376
+ // acquire starts a new BLE session. Any previous runPromise belongs to a dead
377
+ // session, such as an interrupted probe or firmware-update reboot, and would
378
+ // otherwise block the new session. Device cannot distinguish recovery from a
379
+ // regular acquire, so BLE always clears it intentionally.
341
380
  acquireResult = await this.deviceConnector?.acquire(
342
381
  this.originalDescriptor.id,
343
382
  undefined,
@@ -375,6 +414,9 @@ export class Device extends EventEmitter {
375
414
 
376
415
  this.commands = new DeviceCommands(this, this.mainId ?? '');
377
416
  } catch (error) {
417
+ if (options?.throwOnRunPromiseError) {
418
+ throw error;
419
+ }
378
420
  if (this.runPromise) {
379
421
  this.runPromise.reject(error);
380
422
  } else {
@@ -475,12 +517,11 @@ export class Device extends EventEmitter {
475
517
  }
476
518
 
477
519
  /**
478
- * 唯一协议判别器。
520
+ * Canonical protocol discriminator.
479
521
  *
480
- * descriptor.protocolType 是协议探测后的结果;V2 features DevGetDeviceInfo
481
- * 映射产生。
482
- * SDK 的协议分支都必须走这里,不要直接读 originalDescriptor.protocolType
483
- * 或从 features 反推。
522
+ * descriptor.protocolType is established by active probing; V2 features are mapped
523
+ * from DeviceInfoGet. All protocol branches must use this method instead of reading
524
+ * originalDescriptor.protocolType directly or inferring a protocol from features.
484
525
  */
485
526
  getProtocol(): 'V1' | 'V2' {
486
527
  return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
@@ -491,54 +532,75 @@ export class Device extends EventEmitter {
491
532
  }
492
533
 
493
534
  getCurrentDeviceType() {
494
- return getDeviceType(this.features);
535
+ return this.state?.identity.deviceType ?? EDeviceType.Unknown;
495
536
  }
496
537
 
497
538
  getCurrentDeviceId() {
498
- return this.features?.deviceId || undefined;
539
+ return this.state?.identity.deviceId || undefined;
499
540
  }
500
541
 
501
542
  getCurrentSerialNo() {
502
- return this.features ? getDeviceUUID(this.features) : '';
543
+ return this.state?.identity.serialNo ?? '';
503
544
  }
504
545
 
505
546
  getConnectId() {
506
547
  const serialNo = this.getCurrentSerialNo();
507
548
  if (serialNo) return serialNo;
508
549
 
509
- // connectId SDK 内部连接路由 key;Protocol V2 早期固件/mock
510
- // 可能还没有 serial_no,此时用 transport descriptor 兜底,不改变
511
- // features.serialNo / deviceId 的业务语义。
550
+ // connectId is an internal routing key. Falling back to the transport descriptor
551
+ // does not change the business meaning of features.serialNo or deviceId.
512
552
  return this.originalDescriptor.path || this.originalDescriptor.id || '';
513
553
  }
514
554
 
515
555
  getCurrentBleName() {
516
- return getDeviceBleName(this.features);
556
+ return this.state?.identity.bleName ?? null;
517
557
  }
518
558
 
519
559
  getCurrentLabel() {
520
- return getDeviceLabel(this.features);
560
+ return this.state?.identity.label ?? null;
561
+ }
562
+
563
+ getCurrentDisplayName() {
564
+ if (!this.state) return null;
565
+
566
+ const label = this.getCurrentLabel();
567
+ if (label) return label;
568
+
569
+ const bleName = this.getCurrentBleName();
570
+ if (bleName) return bleName;
571
+
572
+ const deviceType = this.getCurrentDeviceType();
573
+ if (deviceType === EDeviceType.ClassicPure) {
574
+ return 'OneKey Classic 1S';
575
+ }
576
+
577
+ return `OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
521
578
  }
522
579
 
523
580
  getCurrentPassphraseProtection() {
524
- return this.features?.passphraseProtection;
581
+ return this.state?.status.passphraseProtection;
525
582
  }
526
583
 
527
584
  getCurrentFirmwareType() {
528
- return getFirmwareType(this.features);
585
+ return this.state?.identity.firmwareType ?? EFirmwareType.Universal;
529
586
  }
530
587
 
531
588
  getCurrentFirmwareVersionString() {
532
- return getDeviceFirmwareVersion(this.features)?.join('.');
589
+ return parseDeviceVersion(this.state?.versions.firmware).join('.');
533
590
  }
534
591
 
535
592
  getCurrentBLEFirmwareVersionString() {
536
- if (!this.features) return undefined;
537
- return getDeviceBLEFirmwareVersion(this.features).join('.');
593
+ if (!this.state) return undefined;
594
+ return parseDeviceVersion(this.state.versions.ble).join('.');
595
+ }
596
+
597
+ getCurrentBootloaderVersionString() {
598
+ if (!this.state) return undefined;
599
+ return parseDeviceVersion(this.state.versions.bootloader).join('.');
538
600
  }
539
601
 
540
602
  getCurrentSafetyChecks() {
541
- return this.features?.safetyChecks;
603
+ return this.state?.settings.safetyChecks;
542
604
  }
543
605
 
544
606
  getCurrentMethodVersionRange(
@@ -583,8 +645,6 @@ export class Device extends EventEmitter {
583
645
  }
584
646
 
585
647
  supportInputPinOnSoftware(): SupportFeatureType {
586
- if (this.features) return supportInputPinOnSoftware(this.features);
587
-
588
648
  const deviceType = this.getCurrentDeviceType();
589
649
  if (
590
650
  deviceType === EDeviceType.Touch ||
@@ -602,15 +662,12 @@ export class Device extends EventEmitter {
602
662
  }
603
663
 
604
664
  supportModifyHomescreen(): SupportFeatureType {
605
- // Pro2 走独立 1.x 版本线,不能套用 Touch/Pro 3.4.0 门槛(恒 false 且未来会误判)。
606
- // 依据:firmware-pro2 协议 schema(messages-protocol-v2.json)的 ApplySettings
607
- // 包含 homescreen 字段,V2 固件从首个版本即支持修改主屏。
665
+ // Pro2 has an independent 1.x version line and must not use the Touch/Pro 3.4.0
666
+ // threshold. ApplySettings includes homescreen from the first V2 firmware version.
608
667
  if (this.isProtocolV2()) {
609
668
  return { support: true };
610
669
  }
611
670
 
612
- if (this.features) return supportModifyHomescreen(this.features);
613
-
614
671
  const deviceType = this.getCurrentDeviceType();
615
672
  if (DeviceModelToTypes.model_mini.includes(deviceType)) {
616
673
  return { support: true };
@@ -622,29 +679,29 @@ export class Device extends EventEmitter {
622
679
  };
623
680
  }
624
681
 
625
- private generateStateKey(deviceId: string, passphraseState?: string) {
626
- if (passphraseState) {
627
- return `${deviceId}@${passphraseState}`;
628
- }
629
- return deviceId;
630
- }
631
-
632
682
  private getSessionCacheDeviceKey(_deviceId?: string) {
633
683
  const deviceId = _deviceId || this.getCurrentDeviceId();
634
684
  if (deviceId) return deviceId;
635
685
  if (this.isProtocolV2()) {
636
- return this.originalDescriptor.path || this.originalDescriptor.id;
686
+ return this.originalDescriptor.path;
637
687
  }
638
688
  return undefined;
639
689
  }
640
690
 
691
+ private reconcileSessionCacheDeviceIdentity(previousDeviceId?: string) {
692
+ deviceWalletSessionStore.reconcileDeviceIdentity({
693
+ temporaryKey: this.isProtocolV2() ? this.originalDescriptor.path : undefined,
694
+ previousDeviceId,
695
+ nextDeviceId: this.getCurrentDeviceId(),
696
+ });
697
+ }
698
+
641
699
  getInternalState(_deviceId?: string) {
642
- Log.debug('getInternalState session cache: ', deviceSessionCache);
643
700
  Log.debug(
644
701
  'getInternalState session param: ',
645
702
  `device_id: ${_deviceId}`,
646
- `features.deviceId: ${this.features?.deviceId}`,
647
- `passphraseState: ${this.passphraseState}`
703
+ `currentDeviceId: ${this.getCurrentDeviceId()}`,
704
+ `hasPassphraseState: ${Boolean(this.passphraseState)}`
648
705
  );
649
706
 
650
707
  const deviceId = this.getSessionCacheDeviceKey(_deviceId);
@@ -657,8 +714,7 @@ export class Device extends EventEmitter {
657
714
  // downstream call carries it and hits the primary lookup below.
658
715
  if (!this.passphraseState) return undefined;
659
716
 
660
- const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
661
- return deviceSessionCache[usePassKey];
717
+ return deviceWalletSessionStore.get(deviceId, this.passphraseState);
662
718
  }
663
719
 
664
720
  // attach to pin to fix internal state
@@ -673,40 +729,30 @@ export class Device extends EventEmitter {
673
729
  'updateInternalState session param: ',
674
730
  `device_id: ${deviceId}`,
675
731
  `enablePassphrase: ${enablePassphrase}`,
676
- `passphraseState: ${passphraseState}`,
677
- `sessionId: ${sessionId}`,
678
- `featuresSessionId: ${featuresSessionId}`
732
+ `hasPassphraseState: ${Boolean(passphraseState)}`,
733
+ `hasSessionId: ${Boolean(sessionId)}`,
734
+ `hasFeaturesSessionId: ${Boolean(featuresSessionId)}`
679
735
  );
680
736
 
681
737
  const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
682
738
  if (!cacheDeviceKey) return;
683
739
 
684
740
  if (enablePassphrase) {
685
- // update the sessionId
686
- if (sessionId) {
687
- deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] = sessionId;
688
- } else if (featuresSessionId) {
689
- deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] =
690
- featuresSessionId;
691
- }
692
- }
693
-
694
- // delete the old sessionId
695
- const oldKey = `${cacheDeviceKey}`;
696
- if (deviceSessionCache[oldKey]) {
697
- delete deviceSessionCache[oldKey];
741
+ const walletSessionId =
742
+ sessionId || featuresSessionId || deviceWalletSessionStore.getPending(cacheDeviceKey);
743
+ deviceWalletSessionStore.set(cacheDeviceKey, passphraseState, walletSessionId ?? undefined);
698
744
  }
699
745
 
700
- Log.debug('updateInternalState session cache: ', deviceSessionCache);
746
+ deviceWalletSessionStore.deletePending(cacheDeviceKey);
701
747
  }
702
748
 
703
749
  private setInternalState(state: string, initSession?: boolean) {
704
750
  Log.debug(
705
751
  'setInternalState session param: ',
706
- `state: ${state}`,
752
+ `hasState: ${Boolean(state)}`,
707
753
  `initSession: ${initSession}`,
708
- `deviceId: ${this.features?.deviceId}`,
709
- `passphraseState: ${this.passphraseState}`
754
+ `deviceId: ${this.getCurrentDeviceId()}`,
755
+ `hasPassphraseState: ${Boolean(this.passphraseState)}`
710
756
  );
711
757
 
712
758
  if (!this.passphraseState && !initSession) return;
@@ -714,12 +760,11 @@ export class Device extends EventEmitter {
714
760
  const deviceId = this.getSessionCacheDeviceKey();
715
761
  if (!deviceId) return;
716
762
 
717
- const key = this.generateStateKey(deviceId, this.passphraseState);
718
-
719
- if (state) {
720
- deviceSessionCache[key] = state;
763
+ if (this.passphraseState) {
764
+ deviceWalletSessionStore.set(deviceId, this.passphraseState, state);
765
+ } else if (initSession) {
766
+ deviceWalletSessionStore.setPending(deviceId, state);
721
767
  }
722
- Log.debug('setInternalState done session cache: ', deviceSessionCache);
723
768
  }
724
769
 
725
770
  clearInternalState(_deviceId?: string) {
@@ -727,67 +772,79 @@ export class Device extends EventEmitter {
727
772
 
728
773
  const deviceId = this.getSessionCacheDeviceKey(_deviceId);
729
774
  if (!deviceId) return;
730
- const key = `${deviceId}`;
731
- delete deviceSessionCache[key];
775
+ deviceWalletSessionStore.deletePending(deviceId);
732
776
 
733
777
  if (this.passphraseState) {
734
- const usePassKey = this.generateStateKey(deviceId, this.passphraseState);
735
- delete deviceSessionCache[usePassKey];
778
+ deviceWalletSessionStore.delete(deviceId, this.passphraseState);
736
779
  }
737
780
  }
738
781
 
739
782
  async initialize(options?: InitOptions) {
740
- // Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
783
+ // Protocol V2 does not support legacy Initialize; use its dedicated flow.
741
784
  if (this.isProtocolV2()) {
742
785
  this.passphraseState = options?.passphraseState;
743
- if (this.features && !this.featuresNeedsReload && !options?.initSession) {
744
- // 不能直接信任缓存 features:设备端 wipe / 完成初始化 / label 后
745
- // features 会永久陈旧。每次 run 做一次轻量 status 刷新(不含 fw/SE),
746
- // 用字段级合并保留已有版本和 SE 信息。
747
- await this._refreshProtocolV2Status();
786
+ if (this.state && !options?.initSession && !this.protocolV2StateNeedsReload) {
787
+ if (this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader') {
788
+ return;
789
+ }
790
+ // Normal calls reuse the cache. Explicit getDeviceState refreshes, unlock flow,
791
+ // and device events update dynamic state without polling on every SDK call.
748
792
  return;
749
793
  }
750
- await this._initializeProtocolV2();
794
+ await this._initializeProtocolV2(options);
795
+ this.protocolV2StateNeedsReload = false;
751
796
  return;
752
797
  }
753
798
 
754
- // Log.debug('initialize param:', options);
799
+ try {
800
+ const callInitialize = async (payload: Record<string, unknown>, initSession?: boolean) => {
801
+ const initStartAt = Date.now();
802
+ const { message } = await this.commands.typedCall('Initialize', 'Features', payload, {
803
+ // iOS BLE bound devices can need close to 20 seconds.
804
+ timeoutMs: 25 * 1000,
805
+ });
806
+ this.setLastInitializeDuration(Date.now() - initStartAt);
807
+ this._updateFeatures(message, initSession);
808
+ await TransportManager.reconfigure(this.features);
809
+ };
755
810
 
756
- this.passphraseState = options?.passphraseState;
811
+ const expectedDeviceId = options?.deviceId;
812
+ if (expectedDeviceId) {
813
+ // Establish the live physical identity before sending wallet-bound state.
814
+ this.passphraseState = undefined;
815
+ await callInitialize({ is_contains_attach: true });
816
+ if (!this.checkDeviceId(expectedDeviceId)) {
817
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
818
+ }
819
+ }
757
820
 
758
- if (options?.initSession) {
759
- this.clearInternalState(options?.deviceId);
760
- }
821
+ this.passphraseState = options?.passphraseState;
761
822
 
762
- const internalState = this.getInternalState(options?.deviceId);
763
- const payload: any = {};
764
- if (internalState) {
765
- payload.session_id = internalState;
766
- }
823
+ if (options?.initSession) {
824
+ this.clearInternalState(options?.deviceId);
825
+ }
767
826
 
768
- if (options?.deriveCardano) {
769
- payload.derive_cardano = true;
770
- }
771
- payload.passphrase_state = options?.passphraseState;
772
- payload.is_contains_attach = true;
827
+ const internalState = this.getInternalState(options?.deviceId);
828
+ const payload: Record<string, unknown> = {
829
+ passphrase_state: options?.passphraseState,
830
+ is_contains_attach: true,
831
+ };
832
+ if (internalState) {
833
+ payload.session_id = internalState;
834
+ }
835
+ if (options?.deriveCardano) {
836
+ payload.derive_cardano = true;
837
+ }
773
838
 
774
- const initStartAt = Date.now();
775
- try {
776
- // @ts-expect-error
777
- const { message } = await Promise.race([
778
- this.commands.typedCall('Initialize', 'Features', payload),
779
- new Promise((_, reject) => {
780
- setTimeout(() => {
781
- reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
782
- // iOS ble bound device timeout 20s
783
- }, 25 * 1000);
784
- }),
785
- ]);
786
-
787
- const initCostMs = Date.now() - initStartAt;
788
- this.setLastInitializeDuration(initCostMs);
789
- this._updateFeatures(message, options?.initSession);
790
- await TransportManager.reconfigure(this.features);
839
+ const requiresWalletInitialize =
840
+ !expectedDeviceId ||
841
+ Boolean(internalState) ||
842
+ Boolean(options?.passphraseState) ||
843
+ options?.deriveCardano === true ||
844
+ options?.initSession === true;
845
+ if (requiresWalletInitialize) {
846
+ await callInitialize(payload, options?.initSession);
847
+ }
791
848
  } catch (error) {
792
849
  Log.error('Initialization failed:', error);
793
850
  throw error;
@@ -797,57 +854,38 @@ export class Device extends EventEmitter {
797
854
  /**
798
855
  * Device initialization over Protocol V2.
799
856
  *
800
- * Protocol V2 不走传统 Initialize/GetFeatures;直接用 DevGetDeviceInfo
801
- * 生成唯一的 features 状态。
857
+ * Protocol V2 bypasses legacy Initialize/GetFeatures and builds its canonical
858
+ * features state directly from DeviceInfoGet.
802
859
  */
803
- private async _initializeProtocolV2() {
860
+ private async _initializeProtocolV2(options?: InitOptions) {
804
861
  Log.debug('Initialize device via Protocol V2 features adapter');
805
862
 
806
863
  try {
807
- // 超时由 requestProtocolV2DeviceInfo 内部的 typedCall timeoutMs(默认 10s)负责,
808
- // 不再额外包一层 Promise.race:外层 race timer 不会清理,
809
- // 且 reject 后底层调用仍会残留。
864
+ // typedCall applies the request timeout. An outer Promise.race would leak its
865
+ // timer and leave the underlying call active after rejection.
810
866
  const deviceInfo = await requestProtocolV2DeviceInfo({
811
867
  commands: this.commands,
868
+ timeoutMs: options?.protocolV2DeviceInfoTimeoutMs,
812
869
  });
813
- // 默认请求不含 SE/hash 数据,scope 如实标注为 basic
814
- // 完整数据由 getDeviceInfo(scope:'verify'|'full') 获取。
815
- const features = this.updateProtocolV2Features(deviceInfo);
870
+ // The default request excludes SE/hash data and therefore uses basic scope.
871
+ // Full version and verification data require getDeviceState({ scope: 'firmware' }).
872
+ const features = await this.probeProtocolV2RuntimeState(
873
+ deviceInfo,
874
+ options?.protocolV2DeviceInfoTimeoutMs
875
+ );
816
876
  Log.debug('Protocol V2 features:', features);
817
- this.featuresNeedsReload = false;
818
877
  } catch (error) {
819
878
  Log.error('Protocol V2 initialization failed:', error);
820
879
  throw error;
821
880
  }
822
881
  }
823
882
 
824
- /**
825
- * Protocol V2 的轻量状态刷新(每次 run 前调用)。
826
- *
827
- * 请求 hw + bt + status(不含 fw/SE target):status 提供 init_states / label /
828
- * passphrase_protection 等会在设备端变化的字段;hw/bt 提供 serialNo / bleName。
829
- * versions 为空时按字段级合并保留旧值,verify 数据不会被降级。
830
- */
831
- private async _refreshProtocolV2Status() {
832
- try {
833
- const deviceInfo = await requestProtocolV2DeviceInfo({
834
- commands: this.commands,
835
- request: PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
836
- });
837
- const features = this.updateProtocolV2Features(deviceInfo);
838
- Log.debug('Protocol V2 features (status refresh):', features);
839
- } catch (error) {
840
- Log.error('Protocol V2 status refresh failed:', error);
841
- throw error;
842
- }
843
- }
844
-
845
883
  async getFeatures() {
846
884
  if (this.isProtocolV2()) {
847
885
  const deviceInfo = await requestProtocolV2DeviceInfo({
848
886
  commands: this.commands,
849
887
  });
850
- return this.updateProtocolV2Features(deviceInfo);
888
+ return this.probeProtocolV2RuntimeState(deviceInfo);
851
889
  }
852
890
 
853
891
  const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
@@ -855,36 +893,249 @@ export class Device extends EventEmitter {
855
893
  return this.features;
856
894
  }
857
895
 
896
+ async getDeviceState(params: DeviceStateReadOptions = {}) {
897
+ const refresh = new Set(params.refreshSections ?? []);
898
+ const getProtocolV2DeviceInfoRequest = () => {
899
+ if (refresh.has('verification')) return PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
900
+ if (refresh.has('versions')) return PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST;
901
+ return PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST;
902
+ };
903
+ let initializedWithDeviceInfo = false;
904
+ let refreshedDeviceInfo: ProtocolV2DeviceInfo | undefined;
905
+
906
+ if (!this.state) {
907
+ if (this.isProtocolV2()) {
908
+ const deviceInfo = await requestProtocolV2DeviceInfo({
909
+ commands: this.commands,
910
+ request: getProtocolV2DeviceInfoRequest(),
911
+ });
912
+ await this.probeProtocolV2RuntimeState(deviceInfo);
913
+ refreshedDeviceInfo = deviceInfo;
914
+ initializedWithDeviceInfo = true;
915
+ } else {
916
+ await this.getFeatures();
917
+ }
918
+ } else if (!this.isProtocolV2() && refresh.size > 0) {
919
+ await this.getFeatures();
920
+ }
921
+
922
+ if (!this.isProtocolV2() && refresh.has('verification')) {
923
+ const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
924
+ this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
925
+ }
926
+
927
+ if (this.isProtocolV2()) {
928
+ const refreshDeviceInfo =
929
+ refresh.has('identity') || refresh.has('versions') || refresh.has('verification');
930
+ if (refreshDeviceInfo && !initializedWithDeviceInfo) {
931
+ const deviceInfo = await requestProtocolV2DeviceInfo({
932
+ commands: this.commands,
933
+ request: getProtocolV2DeviceInfoRequest(),
934
+ });
935
+ refreshedDeviceInfo = deviceInfo;
936
+ if (!refresh.has('status')) {
937
+ this.updateState(
938
+ mapProtocolV2DeviceInfoToState(deviceInfo, this.state?.status.mode),
939
+ 'device-info'
940
+ );
941
+ }
942
+ }
943
+
944
+ if (refresh.has('status') && !initializedWithDeviceInfo) {
945
+ const deviceInfo =
946
+ refreshedDeviceInfo ??
947
+ (await requestProtocolV2DeviceInfo({
948
+ commands: this.commands,
949
+ request: getProtocolV2DeviceInfoRequest(),
950
+ }));
951
+ await this.probeProtocolV2RuntimeState(deviceInfo);
952
+ }
953
+
954
+ if (refresh.has('settings') && this.state?.status.mode === 'normal') {
955
+ const { message } = await this.commands.typedCall(
956
+ 'DeviceSettingsGet',
957
+ 'DeviceSettings',
958
+ {}
959
+ );
960
+ this.updateState(mapDeviceSettingsToState(message), 'settings-read');
961
+ }
962
+ }
963
+
964
+ if (!this.state) {
965
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
966
+ }
967
+ return params.includeRaw ? cloneDeviceState(this.state) : createPublicDeviceState(this.state);
968
+ }
969
+
858
970
  _updateFeatures(protoFeatures: PROTO.Features | Features, initSession?: boolean) {
971
+ const previousDeviceId = this.getCurrentDeviceId();
859
972
  let feat =
860
973
  'protocol' in protoFeatures
861
974
  ? protoFeatures
862
975
  : buildProtocolV1FeaturesPayload(protoFeatures, this.features);
863
976
 
864
- // GetFeatures doesn't return 'session_id'
865
- if (this.features?.sessionId && !feat.sessionId) {
866
- feat.sessionId = this.features.sessionId;
867
- }
868
- if (this.getCurrentDeviceId() && feat.sessionId) {
869
- this.setInternalState(feat.sessionId, initSession);
870
- }
871
977
  feat.unlocked = feat.unlocked ?? true;
872
978
 
873
979
  feat = fixFeaturesFirmwareVersion(feat);
874
980
 
875
- this.features = feat;
876
- this.featuresNeedsReload = false;
877
- this.emit(DEVICE.FEATURES, this, feat);
981
+ this.updateState(mapFeaturesToState(feat), 'initialize');
982
+ this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
983
+ if (feat.deviceId && feat.sessionId) {
984
+ this.setInternalState(feat.sessionId, initSession);
985
+ }
986
+ }
987
+
988
+ updateState(patch: DeviceStatePatch, source: DeviceStateUpdateSource) {
989
+ const result = this.stateStore.update(patch, source);
990
+ if (result.changedKeys.length === 0) return result.state;
991
+
992
+ const event: DeviceStateEvent = {
993
+ connectId: this.getConnectId() ?? null,
994
+ state: createPublicDeviceState(result.state),
995
+ revision: result.revision,
996
+ source,
997
+ changedKeys: result.changedKeys,
998
+ };
999
+ Log.debug('Device state patch committed', {
1000
+ source,
1001
+ keys: result.changedKeys,
1002
+ });
1003
+ this.emit(DEVICE.STATE, this, event);
1004
+ if (result.state.protocol === 'V1') {
1005
+ this.emit(DEVICE.FEATURES, this, projectFeatures(result.state));
1006
+ }
1007
+ return result.state;
1008
+ }
1009
+
1010
+ updateFeaturesPatch(patch: Partial<Features>, source: DeviceStateUpdateSource) {
1011
+ const currentFeatures = this.features;
1012
+ if (!currentFeatures) return undefined;
1013
+
1014
+ const features = mergeDeviceFeaturesPatch(currentFeatures, patch);
1015
+ if (features === currentFeatures) return currentFeatures;
1016
+
1017
+ const normalized = fixFeaturesFirmwareVersion(features);
1018
+ this.updateState(mapFeaturesToState(normalized), source);
1019
+ return this.features;
1020
+ }
1021
+
1022
+ async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
1023
+ let deviceStatus: DeviceStatus;
1024
+ try {
1025
+ deviceStatus = await requestProtocolV2DeviceStatus({
1026
+ commands: this.commands,
1027
+ timeoutMs,
1028
+ });
1029
+ } catch (error) {
1030
+ const runtimeMode = getProtocolV2RuntimeMode({
1031
+ deviceInfo,
1032
+ deviceStatusAvailable: false,
1033
+ });
1034
+ Log.debug('Protocol V2 DeviceStatusGet unavailable; use temporary loader fallback', {
1035
+ runtimeMode,
1036
+ error: error instanceof Error ? error.message : String(error),
1037
+ });
1038
+ return this.updateProtocolV2Features(deviceInfo, null, runtimeMode);
1039
+ }
1040
+ return this.updateProtocolV2Features(deviceInfo, deviceStatus, 'normal');
1041
+ }
1042
+
1043
+ updateProtocolV2Features(
1044
+ deviceInfo?: ProtocolV2DeviceInfo,
1045
+ deviceStatus?: DeviceStatus | null,
1046
+ runtimeMode?: ProtocolV2RuntimeMode
1047
+ ) {
1048
+ const previousDeviceId = this.getCurrentDeviceId();
1049
+ const resolvedMode =
1050
+ runtimeMode ??
1051
+ (deviceStatus
1052
+ ? getProtocolV2RuntimeMode({ deviceInfo, deviceStatusAvailable: true })
1053
+ : this.state?.status.mode);
1054
+ if (deviceInfo) {
1055
+ this.updateState(mapProtocolV2DeviceInfoToState(deviceInfo, resolvedMode), 'device-info');
1056
+ }
1057
+ if (deviceStatus) {
1058
+ this.updateState(mapProtocolV2DeviceStatusToState(deviceStatus), 'device-status');
1059
+ }
1060
+ this.reconcileSessionCacheDeviceIdentity(previousDeviceId);
1061
+ return this.features as Features;
1062
+ }
1063
+
1064
+ updateProtocolV2Status(status: DeviceStatus) {
1065
+ const previousDeviceInfo = this.state?.raw?.protocolV2DeviceInfo;
1066
+ const previousStatus = this.state?.raw?.protocolV2DeviceStatus;
1067
+ return this.updateProtocolV2Features(previousDeviceInfo, {
1068
+ ...previousStatus,
1069
+ ...status,
1070
+ });
1071
+ }
1072
+
1073
+ markTransportDisconnected() {
1074
+ this.deviceAcquired = false;
1075
+ if (!this.isProtocolV2()) return;
1076
+ this.protocolV2StateNeedsReload = true;
1077
+ this.clearPreInitialized();
1078
+ }
1079
+
1080
+ invalidateAfterWipe() {
1081
+ const deviceId = this.getCurrentDeviceId();
1082
+ if (deviceId) {
1083
+ deviceWalletSessionStore.deleteDevice(deviceId);
1084
+ }
1085
+ if (this.isProtocolV2() && this.originalDescriptor.path !== deviceId) {
1086
+ deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
1087
+ this.protocolV2StateNeedsReload = true;
1088
+ }
1089
+
1090
+ this.passphraseState = undefined;
1091
+ this.stateStore = new DeviceStateStore();
1092
+ this.clearPreInitialized();
1093
+ this.needReloadDevice = true;
878
1094
  }
879
1095
 
880
- updateProtocolV2Features(deviceInfo?: ProtocolV2DeviceInfo) {
881
- const features = fixFeaturesFirmwareVersion(
882
- buildProtocolV2FeaturesPayload(deviceInfo, this.features)
1096
+ markProtocolV2Reboot(rebootType: DeviceRebootType) {
1097
+ if (!this.isProtocolV2()) return;
1098
+
1099
+ this.protocolV2StateNeedsReload = true;
1100
+ this.clearPreInitialized();
1101
+ let loaderMode: 'bootloader' | 'romloader' | undefined;
1102
+ if (rebootType === DeviceRebootType.Bootloader) {
1103
+ loaderMode = 'bootloader';
1104
+ } else if (rebootType === DeviceRebootType.Romloader) {
1105
+ loaderMode = 'romloader';
1106
+ }
1107
+ if (loaderMode) {
1108
+ this.updateState(
1109
+ {
1110
+ identity: { deviceId: null },
1111
+ status: {
1112
+ mode: loaderMode,
1113
+ initialized: null,
1114
+ unlocked: null,
1115
+ firmwarePresent: null,
1116
+ backupRequired: null,
1117
+ noBackup: null,
1118
+ unfinishedBackup: null,
1119
+ recoveryMode: null,
1120
+ passphraseProtection: null,
1121
+ pinProtection: null,
1122
+ attachToPinEnabled: null,
1123
+ unlockedAttachPin: null,
1124
+ },
1125
+ raw: { protocolV2DeviceStatus: null },
1126
+ },
1127
+ 'transport-reconnect'
1128
+ );
1129
+ return;
1130
+ }
1131
+
1132
+ this.updateState(
1133
+ {
1134
+ status: { mode: 'normal', unlocked: null },
1135
+ raw: { protocolV2DeviceStatus: null },
1136
+ },
1137
+ 'transport-reconnect'
883
1138
  );
884
- this.features = features;
885
- this.featuresNeedsReload = false;
886
- this.emit(DEVICE.FEATURES, this, features);
887
- return features;
888
1139
  }
889
1140
 
890
1141
  /**
@@ -905,8 +1156,7 @@ export class Device extends EventEmitter {
905
1156
  }
906
1157
 
907
1158
  if (forceUpdate) {
908
- // 枚举得到的 descriptor 可能不带 protocolType(如 WebUSB enumerate),
909
- // 不能让覆盖丢掉已探测的协议结果。
1159
+ // Enumerated descriptors may omit protocolType, so preserve an actively probed value.
910
1160
  this.originalDescriptor = {
911
1161
  ...descriptor,
912
1162
  protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
@@ -931,19 +1181,37 @@ export class Device extends EventEmitter {
931
1181
 
932
1182
  options = parseRunOptions(options);
933
1183
 
934
- this.runPromise = createDeferred(this._runInner.bind(this, fn, options));
935
- return this.runPromise.promise;
1184
+ const runPromise = createDeferred<void>();
1185
+ this.runPromise = runPromise;
1186
+ this._runInner(fn, options, runPromise).catch(error => {
1187
+ if (this.runPromise === runPromise) {
1188
+ this.runPromise = null;
1189
+ }
1190
+ runPromise.reject(error);
1191
+ });
1192
+ return runPromise.promise;
936
1193
  }
937
1194
 
938
- async _runInner<T>(fn: (() => Promise<T>) | undefined, options: RunOptions) {
1195
+ async _runInner<T>(
1196
+ fn: (() => Promise<T>) | undefined,
1197
+ options: RunOptions,
1198
+ runPromise: Deferred<void>
1199
+ ) {
1200
+ const clearRunPromise = () => {
1201
+ if (this.runPromise === runPromise) {
1202
+ this.runPromise = null;
1203
+ }
1204
+ };
1205
+
939
1206
  if (!this.isUsedHere() || this.commands.disposed) {
940
1207
  const env = DataManager.getSettings('env');
941
1208
  if (env !== 'react-native') {
942
1209
  try {
943
1210
  await this.acquire(options.connectProtocol);
944
1211
  } catch (error) {
945
- this.runPromise = null;
946
- return Promise.reject(error);
1212
+ clearRunPromise();
1213
+ runPromise.reject(error);
1214
+ return;
947
1215
  }
948
1216
 
949
1217
  try {
@@ -953,16 +1221,19 @@ export class Device extends EventEmitter {
953
1221
  }
954
1222
  }
955
1223
  } catch (error) {
956
- this.runPromise = null;
1224
+ await this.release();
1225
+ clearRunPromise();
957
1226
  if (error instanceof HardwareError) {
958
- return Promise.reject(error);
1227
+ runPromise.reject(error);
1228
+ return;
959
1229
  }
960
- return Promise.reject(
1230
+ runPromise.reject(
961
1231
  ERRORS.TypedError(
962
1232
  HardwareErrorCode.DeviceInitializeFailed,
963
1233
  `Initialize failed: ${error.message as string}, code: ${error.code as string}`
964
1234
  )
965
1235
  );
1236
+ return;
966
1237
  }
967
1238
  } else if (env === 'react-native') {
968
1239
  // TODO: implement react-native acquire
@@ -981,9 +1252,7 @@ export class Device extends EventEmitter {
981
1252
  try {
982
1253
  await fn();
983
1254
  } catch (e) {
984
- if (this.runPromise) {
985
- this.runPromise.reject(e);
986
- }
1255
+ runPromise.reject(e);
987
1256
 
988
1257
  if (
989
1258
  e instanceof HardwareError &&
@@ -996,7 +1265,7 @@ export class Device extends EventEmitter {
996
1265
  Log.debug(`error code ${e.errorCode} release device, mainId: ${this.mainId}`);
997
1266
  }
998
1267
 
999
- this.runPromise = null;
1268
+ clearRunPromise();
1000
1269
  return;
1001
1270
  }
1002
1271
  }
@@ -1010,11 +1279,8 @@ export class Device extends EventEmitter {
1010
1279
  Log.debug('release device, mainId: ', this.mainId);
1011
1280
  }
1012
1281
 
1013
- if (this.runPromise) {
1014
- this.runPromise.resolve();
1015
- }
1016
-
1017
- this.runPromise = null;
1282
+ runPromise.resolve();
1283
+ clearRunPromise();
1018
1284
  }
1019
1285
 
1020
1286
  async interruptionFromOutside() {
@@ -1053,33 +1319,37 @@ export class Device extends EventEmitter {
1053
1319
  }
1054
1320
 
1055
1321
  getMode() {
1056
- if (this.features?.bootloaderMode) {
1057
- // bootloader mode
1058
- return EOneKeyDeviceMode.bootloader;
1059
- }
1060
-
1061
- if (!this.features?.initialized) {
1062
- // not initialized
1063
- return EOneKeyDeviceMode.notInitialized;
1322
+ switch (this.state?.status.mode) {
1323
+ case 'bootloader':
1324
+ case 'romloader':
1325
+ return EOneKeyDeviceMode.bootloader;
1326
+ case 'notInitialized':
1327
+ return EOneKeyDeviceMode.notInitialized;
1328
+ case 'backupMode':
1329
+ return EOneKeyDeviceMode.backupMode;
1330
+ case 'normal':
1331
+ return EOneKeyDeviceMode.normal;
1332
+ default:
1333
+ break;
1064
1334
  }
1065
1335
 
1066
- if (this.features?.noBackup) {
1067
- // backup mode
1068
- return EOneKeyDeviceMode.backupMode;
1069
- }
1070
-
1071
- // normal mode
1072
1336
  return EOneKeyDeviceMode.normal;
1073
1337
  }
1074
1338
 
1339
+ getStatus() {
1340
+ if (this.isUsedElsewhere()) return 'occupied' as const;
1341
+ if (this.isUsedHere()) return 'used' as const;
1342
+ return 'available' as const;
1343
+ }
1344
+
1075
1345
  getFirmwareVersion() {
1076
- if (!this.features) return null;
1077
- return getDeviceFirmwareVersion(this.features);
1346
+ if (!this.state) return null;
1347
+ return parseDeviceVersion(this.state.versions.firmware);
1078
1348
  }
1079
1349
 
1080
1350
  getBLEFirmwareVersion() {
1081
- if (!this.features) return null;
1082
- return getDeviceBLEFirmwareVersion(this.features);
1351
+ if (!this.state) return null;
1352
+ return parseDeviceVersion(this.state.versions.ble);
1083
1353
  }
1084
1354
 
1085
1355
  isUsed() {
@@ -1097,7 +1367,7 @@ export class Device extends EventEmitter {
1097
1367
  isUsedHere() {
1098
1368
  const env = DataManager.getSettings('env');
1099
1369
  if (DataManager.isBleConnect(env)) {
1100
- return false;
1370
+ return this.deviceAcquired;
1101
1371
  }
1102
1372
  return this.isUsed() && this.originalDescriptor.session === this.mainId;
1103
1373
  }
@@ -1107,26 +1377,29 @@ export class Device extends EventEmitter {
1107
1377
  }
1108
1378
 
1109
1379
  isBootloader() {
1110
- return this.features && !!this.features.bootloaderMode;
1380
+ if (!this.state) return undefined;
1381
+ return this.state.status.mode === 'bootloader' || this.state.status.mode === 'romloader';
1111
1382
  }
1112
1383
 
1113
1384
  isInitialized() {
1114
- return this.features && !!this.features.initialized;
1385
+ if (!this.state) return undefined;
1386
+ return this.state.status.initialized === true;
1115
1387
  }
1116
1388
 
1117
1389
  isSeedless() {
1118
- return this.features && !!this.features.noBackup;
1390
+ if (!this.state) return undefined;
1391
+ return this.state.status.noBackup === true;
1119
1392
  }
1120
1393
 
1121
1394
  isUnacquired(): boolean {
1122
- return this.features === undefined;
1395
+ return this.state === undefined;
1123
1396
  }
1124
1397
 
1125
1398
  hasUnexpectedMode(allow: string[], require: string[]) {
1126
1399
  // both allow and require cases might generate single unexpected mode
1127
1400
  if (!this.isUnacquired()) {
1128
1401
  // allow cases
1129
- if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1402
+ if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1130
1403
  return UI_REQUEST.BOOTLOADER;
1131
1404
  }
1132
1405
  if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
@@ -1150,7 +1423,7 @@ export class Device extends EventEmitter {
1150
1423
  deviceType === EDeviceType.Touch ||
1151
1424
  deviceType === EDeviceType.Pro ||
1152
1425
  deviceType === EDeviceType.Pro2;
1153
- const unlocked = this.features?.unlocked;
1426
+ const unlocked = this.state?.status.unlocked;
1154
1427
  const preCheckTouch = isModeT && unlocked === false;
1155
1428
  const passphraseProtection = this.getCurrentPassphraseProtection();
1156
1429
 
@@ -1163,12 +1436,12 @@ export class Device extends EventEmitter {
1163
1436
 
1164
1437
  async lockDevice(): Promise<Success> {
1165
1438
  const res = await this.commands.typedCall('LockDevice', 'Success', {});
1439
+ this.updateState({ status: { unlocked: false } }, 'lock');
1166
1440
  return res.message;
1167
1441
  }
1168
1442
 
1169
1443
  supportUnlockVersionRange(): DeviceFirmwareRange {
1170
- // 仅适用于 Protocol V1 Pro 系列;Pro2 走独立版本线,
1171
- // 且 Protocol V2 固件从首个版本即支持 UnLockDevice(见 unlockDevice 的 isProtocolV2 短路)。
1444
+ // This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
1172
1445
  return {
1173
1446
  pro: {
1174
1447
  min: '4.15.0',
@@ -1176,19 +1449,34 @@ export class Device extends EventEmitter {
1176
1449
  };
1177
1450
  }
1178
1451
 
1179
- async unlockDevice() {
1452
+ async unlockDevice(pinType: DeviceSessionPinType = DeviceSessionPinType.Main) {
1453
+ if (this.isProtocolV2()) {
1454
+ try {
1455
+ await this.commands.typedCall('DeviceSessionAskPin', 'Success', { type: pinType });
1456
+ } catch (error) {
1457
+ const errorText =
1458
+ error instanceof Error
1459
+ ? `${error.name} ${error.message}`
1460
+ : String((error as { message?: unknown } | null)?.message ?? error ?? '');
1461
+ if (errorText.includes('Failure_UnexpectedMessage')) {
1462
+ throw createDeviceNotSupportMethodError('deviceUnlock', this.getCurrentFirmwareType());
1463
+ }
1464
+ throw error;
1465
+ }
1466
+
1467
+ const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
1468
+ return this.updateProtocolV2Status(status);
1469
+ }
1470
+
1180
1471
  const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
1181
1472
  const versionRange = this.getCurrentMethodVersionRange(
1182
1473
  type => this.supportUnlockVersionRange()[type]
1183
1474
  );
1184
1475
 
1185
- const supportAttachPinCapability = existCapability(
1186
- this.features,
1476
+ const supportAttachPinCapability = this.state?.capabilities.includes(
1187
1477
  Enum_Capability.Capability_AttachToPin
1188
1478
  );
1189
- // Pro2 (Protocol V2) 版本线独立于 Pro 系列,固件从首个版本即支持 UnLockDevice
1190
1479
  const supportUnlock =
1191
- this.isProtocolV2() ||
1192
1480
  supportAttachPinCapability ||
1193
1481
  (versionRange &&
1194
1482
  semver.valid(firmwareVersion) &&
@@ -1196,12 +1484,21 @@ export class Device extends EventEmitter {
1196
1484
 
1197
1485
  if (supportUnlock) {
1198
1486
  const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
1199
- if (this.features) {
1200
- this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
1201
- this.features.unlockedAttachPin =
1202
- res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
1203
- this.features.passphraseProtection =
1204
- res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
1487
+ if (this.state) {
1488
+ this.updateState(
1489
+ {
1490
+ status: {
1491
+ unlocked: res.message.unlocked == null ? null : res.message.unlocked,
1492
+ unlockedAttachPin:
1493
+ res.message.unlocked_attach_pin == null ? null : res.message.unlocked_attach_pin,
1494
+ passphraseProtection:
1495
+ res.message.passphrase_protection == null
1496
+ ? null
1497
+ : res.message.passphrase_protection,
1498
+ },
1499
+ },
1500
+ 'unlock'
1501
+ );
1205
1502
 
1206
1503
  return Promise.resolve(this.features);
1207
1504
  }
@@ -1210,14 +1507,6 @@ export class Device extends EventEmitter {
1210
1507
  return Promise.resolve(features);
1211
1508
  }
1212
1509
 
1213
- // legacy 解锁探测仅适用于 Protocol V1 老固件;V2 固件必然支持 UnLockDevice
1214
- if (this.isProtocolV2()) {
1215
- throw ERRORS.TypedError(
1216
- HardwareErrorCode.RuntimeError,
1217
- 'unlock device error: device firmware does not support UnLockDevice'
1218
- );
1219
- }
1220
-
1221
1510
  const { type } = await this.commands.typedCall('GetAddress', 'Address', {
1222
1511
  address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
1223
1512
  coin_name: 'Testnet',
@@ -1240,21 +1529,27 @@ export class Device extends EventEmitter {
1240
1529
  ) {
1241
1530
  if (this.isUnacquired()) return false;
1242
1531
 
1532
+ const expectedPassphraseState = useEmptyPassphrase ? undefined : passphraseState;
1243
1533
  const { passphraseState: newPassphraseState, unlockedAttachPin } =
1244
1534
  await getPassphraseStateWithRefreshDeviceInfo(this, {
1245
- expectPassphraseState: passphraseState,
1535
+ expectPassphraseState: expectedPassphraseState,
1246
1536
  onlyMainPin: useEmptyPassphrase,
1247
1537
  });
1248
1538
 
1249
1539
  // Main wallet and unlock Attach Pin, throw safe error
1250
1540
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
1251
1541
  const useErrorAttachPin =
1252
- unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
1253
- const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
1542
+ unlockedAttachPin &&
1543
+ expectedPassphraseState &&
1544
+ expectedPassphraseState !== newPassphraseState;
1545
+ const passphraseStateMismatch =
1546
+ !!expectedPassphraseState && expectedPassphraseState !== newPassphraseState;
1254
1547
 
1255
1548
  Log.debug('Check passphrase state safety: ', {
1256
- passphraseState,
1257
- newPassphraseState,
1549
+ hasExpectedPassphraseState: Boolean(expectedPassphraseState),
1550
+ hasNewPassphraseState: Boolean(newPassphraseState),
1551
+ passphraseStateMatches:
1552
+ Boolean(expectedPassphraseState) && expectedPassphraseState === newPassphraseState,
1258
1553
  unlockedAttachPin,
1259
1554
  useEmptyPassphrase,
1260
1555
  });