@onekeyfe/hd-core 1.1.28 → 1.2.0-alpha.1

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 (394) hide show
  1. package/__tests__/evmLedgerLegacySafety.test.ts +15 -4
  2. package/__tests__/evmSignTransaction.test.ts +1 -1
  3. package/__tests__/evmSignTypedData.test.ts +1 -1
  4. package/__tests__/logBlockEvent.test.ts +37 -0
  5. package/__tests__/protocol-v2.test.ts +2908 -0
  6. package/dist/api/BaseMethod.d.ts +1 -0
  7. package/dist/api/BaseMethod.d.ts.map +1 -1
  8. package/dist/api/DirList.d.ts +10 -0
  9. package/dist/api/DirList.d.ts.map +1 -0
  10. package/dist/api/DirMake.d.ts +9 -0
  11. package/dist/api/DirMake.d.ts.map +1 -0
  12. package/dist/api/DirRemove.d.ts +9 -0
  13. package/dist/api/DirRemove.d.ts.map +1 -0
  14. package/dist/api/FileDelete.d.ts +9 -0
  15. package/dist/api/FileDelete.d.ts.map +1 -0
  16. package/dist/api/FileRead.d.ts +19 -0
  17. package/dist/api/FileRead.d.ts.map +1 -0
  18. package/dist/api/FileWrite.d.ts +24 -0
  19. package/dist/api/FileWrite.d.ts.map +1 -0
  20. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  21. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  22. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  23. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  24. package/dist/api/FirmwareUpdateV4.d.ts +35 -0
  25. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  26. package/dist/api/GetDeviceInfo.d.ts +9 -0
  27. package/dist/api/GetDeviceInfo.d.ts.map +1 -0
  28. package/dist/api/GetFeatures.d.ts +1 -1
  29. package/dist/api/GetFeatures.d.ts.map +1 -1
  30. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  31. package/dist/api/GetPassphraseState.d.ts +6 -1
  32. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  33. package/dist/api/PathInfo.d.ts +10 -0
  34. package/dist/api/PathInfo.d.ts.map +1 -0
  35. package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
  36. package/dist/api/SearchDevices.d.ts +2 -1
  37. package/dist/api/SearchDevices.d.ts.map +1 -1
  38. package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
  39. package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
  40. package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
  41. package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
  42. package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -8
  43. package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
  44. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
  45. package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
  46. package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
  47. package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
  48. package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
  49. package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
  50. package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
  51. package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
  52. package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
  53. package/dist/api/btc/BTCGetAddress.d.ts +1 -11
  54. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  55. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
  56. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  57. package/dist/api/btc/BTCSignMessage.d.ts +1 -15
  58. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  59. package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
  60. package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
  61. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  62. package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
  63. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  64. package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
  65. package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
  66. package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
  67. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  68. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  69. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  70. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  71. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  72. package/dist/api/device/DeviceSupportFeatures.d.ts.map +1 -1
  73. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  74. package/dist/api/device/DeviceUploadResource.d.ts.map +1 -1
  75. package/dist/api/device/DeviceVerify.d.ts.map +1 -1
  76. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  77. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  78. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  79. package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
  80. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  81. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  82. package/dist/api/evm/latest/signTypedData.d.ts +1 -1
  83. package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
  84. package/dist/api/evm/latest/signTypedHash.d.ts.map +1 -1
  85. package/dist/api/evm/legacyV1/getAddress.d.ts.map +1 -1
  86. package/dist/api/evm/legacyV1/getPublicKey.d.ts.map +1 -1
  87. package/dist/api/evm/legacyV1/signMessage.d.ts.map +1 -1
  88. package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
  89. package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
  90. package/dist/api/evm/legacyV1/signTypedHash.d.ts.map +1 -1
  91. package/dist/api/evm/legacyV1/verifyMessage.d.ts.map +1 -1
  92. package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
  93. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  94. package/dist/api/helpers/batchGetPublickeys.d.ts +3 -0
  95. package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
  96. package/dist/api/helpers/filesystemValidation.d.ts +7 -0
  97. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
  98. package/dist/api/index.d.ts +32 -0
  99. package/dist/api/index.d.ts.map +1 -1
  100. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  101. package/dist/api/lightning/LnurlAuth.d.ts +4 -0
  102. package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
  103. package/dist/api/neo/NeoGetAddress.d.ts +2 -8
  104. package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
  105. package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
  106. package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
  107. package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
  108. package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
  109. package/dist/api/nervos/NervosSignTransaction.d.ts +9 -12
  110. package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
  111. package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
  112. package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
  113. package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
  114. package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
  115. package/dist/api/polkadot/PolkadotGetAddress.d.ts +3 -0
  116. package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
  117. package/dist/api/polkadot/networks.d.ts +3 -0
  118. package/dist/api/polkadot/networks.d.ts.map +1 -1
  119. package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
  120. package/dist/api/protocol-v2/DevReboot.d.ts.map +1 -0
  121. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  122. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  123. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +29 -0
  124. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  125. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  126. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  127. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  128. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  129. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  130. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  131. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  132. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  133. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  134. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  135. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +13 -0
  136. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +1 -0
  137. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  138. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  139. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  140. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  141. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  142. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  143. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  144. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  145. package/dist/api/protocol-v2/helpers.d.ts +33 -0
  146. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  147. package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
  148. package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
  149. package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
  150. package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
  151. package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
  152. package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
  153. package/dist/api/solana/SolGetAddress.d.ts +1 -0
  154. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  155. package/dist/api/solana/SolSignMessage.d.ts +3 -0
  156. package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
  157. package/dist/api/solana/SolSignOffchainMessage.d.ts +3 -0
  158. package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
  159. package/dist/api/solana/SolSignTransaction.d.ts +6 -0
  160. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  161. package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
  162. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  163. package/dist/api/stellar/StellarSignTransaction.d.ts +3 -2
  164. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  165. package/dist/api/sui/SuiGetAddress.d.ts +3 -0
  166. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  167. package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
  168. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  169. package/dist/api/sui/SuiSignMessage.d.ts +3 -0
  170. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  171. package/dist/api/sui/SuiSignTransaction.d.ts +5 -2
  172. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  173. package/dist/api/ton/TonGetAddress.d.ts +3 -0
  174. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  175. package/dist/api/ton/TonSignData.d.ts +5 -0
  176. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  177. package/dist/api/ton/TonSignMessage.d.ts +3 -0
  178. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  179. package/dist/api/ton/TonSignProof.d.ts +3 -0
  180. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  181. package/dist/api/tron/TronSignMessage.d.ts +4 -0
  182. package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
  183. package/dist/api/tron/TronSignTransaction.d.ts +4 -0
  184. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
  185. package/dist/constants/index.d.ts +2 -1
  186. package/dist/constants/index.d.ts.map +1 -1
  187. package/dist/core/index.d.ts.map +1 -1
  188. package/dist/data-manager/DataManager.d.ts +7 -4
  189. package/dist/data-manager/DataManager.d.ts.map +1 -1
  190. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  191. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  192. package/dist/data-manager/TransportManager.d.ts +5 -4
  193. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  194. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  195. package/dist/device/Device.d.ts +33 -11
  196. package/dist/device/Device.d.ts.map +1 -1
  197. package/dist/device/DeviceCommands.d.ts +9 -9
  198. package/dist/device/DeviceCommands.d.ts.map +1 -1
  199. package/dist/device/DeviceConnector.d.ts +2 -1
  200. package/dist/device/DeviceConnector.d.ts.map +1 -1
  201. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
  202. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
  203. package/dist/deviceProfile/buildDeviceProfile.d.ts +21 -0
  204. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -0
  205. package/dist/deviceProfile/index.d.ts +3 -0
  206. package/dist/deviceProfile/index.d.ts.map +1 -0
  207. package/dist/events/logBlockEvent.d.ts +1 -0
  208. package/dist/events/logBlockEvent.d.ts.map +1 -1
  209. package/dist/events/ui-request.d.ts +8 -0
  210. package/dist/events/ui-request.d.ts.map +1 -1
  211. package/dist/index.d.ts +717 -302
  212. package/dist/index.js +17654 -1271
  213. package/dist/inject.d.ts.map +1 -1
  214. package/dist/protocols/protocol-v2/features.d.ts +93 -0
  215. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  216. package/dist/protocols/protocol-v2/firmware.d.ts +13 -0
  217. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  218. package/dist/protocols/protocol-v2/index.d.ts +4 -0
  219. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  220. package/dist/types/api/export.d.ts +1 -1
  221. package/dist/types/api/export.d.ts.map +1 -1
  222. package/dist/types/api/firmwareUpdate.d.ts +27 -0
  223. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  224. package/dist/types/api/getDeviceInfo.d.ts +85 -0
  225. package/dist/types/api/getDeviceInfo.d.ts.map +1 -0
  226. package/dist/types/api/getPassphraseState.d.ts +10 -1
  227. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  228. package/dist/types/api/index.d.ts +37 -1
  229. package/dist/types/api/index.d.ts.map +1 -1
  230. package/dist/types/api/protocolV2.d.ts +103 -0
  231. package/dist/types/api/protocolV2.d.ts.map +1 -0
  232. package/dist/types/api/searchDevices.d.ts +2 -2
  233. package/dist/types/api/searchDevices.d.ts.map +1 -1
  234. package/dist/types/device.d.ts +91 -5
  235. package/dist/types/device.d.ts.map +1 -1
  236. package/dist/types/params.d.ts +2 -0
  237. package/dist/types/params.d.ts.map +1 -1
  238. package/dist/types/settings.d.ts +2 -1
  239. package/dist/types/settings.d.ts.map +1 -1
  240. package/dist/utils/capabilitieUtils.d.ts.map +1 -1
  241. package/dist/utils/deviceFeaturesUtils.d.ts +6 -8
  242. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  243. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  244. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  245. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  246. package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
  247. package/dist/utils/index.d.ts +1 -1
  248. package/dist/utils/index.d.ts.map +1 -1
  249. package/dist/utils/patch.d.ts +1 -1
  250. package/dist/utils/patch.d.ts.map +1 -1
  251. package/package.json +4 -4
  252. package/src/api/BaseMethod.ts +26 -22
  253. package/src/api/DirList.ts +31 -0
  254. package/src/api/DirMake.ts +23 -0
  255. package/src/api/DirRemove.ts +23 -0
  256. package/src/api/FileDelete.ts +23 -0
  257. package/src/api/FileRead.ts +167 -0
  258. package/src/api/FileWrite.ts +216 -0
  259. package/src/api/FirmwareUpdate.ts +13 -5
  260. package/src/api/FirmwareUpdateV2.ts +22 -19
  261. package/src/api/FirmwareUpdateV3.ts +19 -5
  262. package/src/api/FirmwareUpdateV4.ts +820 -0
  263. package/src/api/GetDeviceInfo.ts +145 -0
  264. package/src/api/GetFeatures.ts +5 -2
  265. package/src/api/GetOnekeyFeatures.ts +84 -3
  266. package/src/api/GetPassphraseState.ts +16 -10
  267. package/src/api/PathInfo.ts +39 -0
  268. package/src/api/PromptWebDeviceAccess.ts +11 -1
  269. package/src/api/SearchDevices.ts +7 -2
  270. package/src/api/alephium/AlephiumGetAddress.ts +6 -2
  271. package/src/api/alephium/AlephiumSignMessage.ts +6 -1
  272. package/src/api/alephium/AlephiumSignTransaction.ts +15 -4
  273. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +21 -13
  274. package/src/api/aptos/AptosGetAddress.ts +2 -3
  275. package/src/api/benfen/BenfenGetAddress.ts +11 -7
  276. package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
  277. package/src/api/benfen/BenfenSignMessage.ts +6 -1
  278. package/src/api/benfen/BenfenSignTransaction.ts +6 -1
  279. package/src/api/btc/BTCGetPublicKey.ts +3 -2
  280. package/src/api/btc/BTCSignPsbt.ts +1 -2
  281. package/src/api/btc/helpers/versionLimit.ts +7 -1
  282. package/src/api/cardano/CardanoSignTransaction.ts +2 -4
  283. package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
  284. package/src/api/device/DeviceFullyUploadResource.ts +3 -3
  285. package/src/api/device/DeviceLock.ts +1 -3
  286. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  287. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  288. package/src/api/device/DeviceSupportFeatures.ts +2 -13
  289. package/src/api/device/DeviceUpdateBootloader.ts +4 -4
  290. package/src/api/device/DeviceUploadResource.ts +4 -5
  291. package/src/api/device/DeviceVerify.ts +1 -2
  292. package/src/api/dynex/DnxGetAddress.ts +6 -0
  293. package/src/api/dynex/DnxSignTransaction.ts +6 -0
  294. package/src/api/evm/EVMGetAddress.ts +1 -1
  295. package/src/api/evm/EVMGetPublicKey.ts +3 -4
  296. package/src/api/evm/EVMSignMessage.ts +1 -1
  297. package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
  298. package/src/api/evm/EVMSignTransaction.ts +1 -1
  299. package/src/api/evm/EVMSignTypedData.ts +32 -18
  300. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  301. package/src/api/evm/latest/signTypedHash.ts +2 -4
  302. package/src/api/evm/legacyV1/getAddress.ts +5 -3
  303. package/src/api/evm/legacyV1/getPublicKey.ts +5 -3
  304. package/src/api/evm/legacyV1/signMessage.ts +5 -3
  305. package/src/api/evm/legacyV1/signTypedData.ts +9 -8
  306. package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
  307. package/src/api/evm/legacyV1/verifyMessage.ts +5 -3
  308. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +8 -8
  309. package/src/api/firmware/bootloaderHelper.ts +3 -2
  310. package/src/api/firmware/getBinary.ts +1 -1
  311. package/src/api/firmware/releaseHelper.ts +3 -3
  312. package/src/api/firmware/uploadFirmware.ts +8 -12
  313. package/src/api/helpers/batchGetPublickeys.ts +51 -6
  314. package/src/api/helpers/filesystemValidation.ts +51 -0
  315. package/src/api/index.ts +34 -0
  316. package/src/api/kaspa/KaspaSignTransaction.ts +4 -5
  317. package/src/api/lightning/LnurlAuth.ts +4 -0
  318. package/src/api/neo/NeoGetAddress.ts +6 -1
  319. package/src/api/neo/NeoSignTransaction.ts +6 -1
  320. package/src/api/nervos/NervosGetAddress.ts +6 -2
  321. package/src/api/nervos/NervosSignTransaction.ts +14 -4
  322. package/src/api/nexa/NexaGetAddress.ts +6 -2
  323. package/src/api/nexa/NexaSignTransaction.ts +11 -12
  324. package/src/api/polkadot/networks.ts +9 -0
  325. package/src/api/protocol-v2/DevReboot.ts +24 -0
  326. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +63 -0
  327. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +118 -0
  328. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +20 -0
  329. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +16 -0
  330. package/src/api/protocol-v2/DeviceReboot.ts +24 -0
  331. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +29 -0
  332. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +20 -0
  333. package/src/api/protocol-v2/FilesystemDiskControl.ts +50 -0
  334. package/src/api/protocol-v2/FilesystemFixPermission.ts +16 -0
  335. package/src/api/protocol-v2/FilesystemFormat.ts +16 -0
  336. package/src/api/protocol-v2/GetProtoVersion.ts +16 -0
  337. package/src/api/protocol-v2/Ping.ts +18 -0
  338. package/src/api/protocol-v2/helpers.ts +182 -0
  339. package/src/api/scdo/ScdoGetAddress.ts +6 -2
  340. package/src/api/scdo/ScdoSignMessage.ts +6 -1
  341. package/src/api/scdo/ScdoSignTransaction.ts +6 -2
  342. package/src/api/solana/SolGetAddress.ts +4 -0
  343. package/src/api/solana/SolSignMessage.ts +3 -0
  344. package/src/api/solana/SolSignOffchainMessage.ts +3 -0
  345. package/src/api/solana/SolSignTransaction.ts +6 -0
  346. package/src/api/stellar/StellarGetAddress.ts +10 -1
  347. package/src/api/stellar/StellarSignTransaction.ts +14 -1
  348. package/src/api/sui/SuiGetAddress.ts +5 -3
  349. package/src/api/sui/SuiGetPublicKey.ts +3 -0
  350. package/src/api/sui/SuiSignMessage.ts +3 -0
  351. package/src/api/sui/SuiSignTransaction.ts +14 -12
  352. package/src/api/ton/TonGetAddress.ts +3 -0
  353. package/src/api/ton/TonSignData.ts +10 -3
  354. package/src/api/ton/TonSignMessage.ts +6 -5
  355. package/src/api/ton/TonSignProof.ts +3 -0
  356. package/src/api/tron/TronSignMessage.ts +5 -1
  357. package/src/api/tron/TronSignTransaction.ts +4 -0
  358. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  359. package/src/constants/index.ts +10 -1
  360. package/src/core/index.ts +91 -61
  361. package/src/data/messages/messages-protocol-v2.json +13375 -0
  362. package/src/data-manager/DataManager.ts +16 -11
  363. package/src/data-manager/MessagesConfig.ts +14 -14
  364. package/src/data-manager/TransportManager.ts +38 -12
  365. package/src/data-manager/connectSettings.ts +6 -0
  366. package/src/device/Device.ts +398 -76
  367. package/src/device/DeviceCommands.ts +195 -29
  368. package/src/device/DeviceConnector.ts +29 -4
  369. package/src/device/DevicePool.ts +8 -8
  370. package/src/deviceProfile/buildDeviceFeatures.ts +368 -0
  371. package/src/deviceProfile/buildDeviceProfile.ts +333 -0
  372. package/src/deviceProfile/index.ts +5 -0
  373. package/src/events/logBlockEvent.ts +23 -0
  374. package/src/events/ui-request.ts +8 -0
  375. package/src/inject.ts +52 -1
  376. package/src/protocols/protocol-v2/features.ts +178 -0
  377. package/src/protocols/protocol-v2/firmware.ts +43 -0
  378. package/src/protocols/protocol-v2/index.ts +16 -0
  379. package/src/types/api/export.ts +1 -0
  380. package/src/types/api/firmwareUpdate.ts +49 -0
  381. package/src/types/api/getDeviceInfo.ts +99 -0
  382. package/src/types/api/getPassphraseState.ts +13 -2
  383. package/src/types/api/index.ts +88 -1
  384. package/src/types/api/protocolV2.ts +200 -0
  385. package/src/types/api/searchDevices.ts +2 -2
  386. package/src/types/device.ts +102 -5
  387. package/src/types/params.ts +7 -0
  388. package/src/types/settings.ts +6 -1
  389. package/src/utils/capabilitieUtils.ts +1 -2
  390. package/src/utils/deviceFeaturesUtils.ts +75 -81
  391. package/src/utils/deviceInfoUtils.ts +23 -34
  392. package/src/utils/deviceVersionUtils.ts +7 -25
  393. package/src/utils/findDefectiveBatchDevice.ts +6 -6
  394. package/src/utils/index.ts +1 -0
@@ -19,21 +19,29 @@ import {
19
19
  getDeviceLabel,
20
20
  getDeviceType,
21
21
  getDeviceUUID,
22
+ getFirmwareType,
22
23
  getLogger,
23
- getMethodVersionRange,
24
24
  } from '../utils';
25
25
  import {
26
26
  fixFeaturesFirmwareVersion,
27
27
  getPassphraseStateWithRefreshDeviceInfo,
28
+ supportInputPinOnSoftware,
29
+ supportModifyHomescreen,
28
30
  } from '../utils/deviceFeaturesUtils';
29
31
  import { generateInstanceId } from '../utils/tracing';
30
32
  // eslint-disable-next-line import/no-cycle
31
33
  import { DeviceCommands } from './DeviceCommands';
32
34
  import {
33
35
  type DeviceFirmwareRange,
36
+ DeviceModelToTypes,
37
+ DeviceTypeToModels,
34
38
  type Device as DeviceTyped,
35
39
  EOneKeyDeviceMode,
36
40
  type Features,
41
+ type IDeviceModel,
42
+ type IDeviceType,
43
+ type IVersionRange,
44
+ type SupportFeatureType,
37
45
  type UnavailableCapabilities,
38
46
  } from '../types';
39
47
  import { DEVICE, UI_REQUEST } from '../events';
@@ -41,6 +49,11 @@ import { DataManager } from '../data-manager';
41
49
  import TransportManager from '../data-manager/TransportManager';
42
50
  import { toHardened } from '../api/helpers/pathUtils';
43
51
  import { existCapability } from '../utils/capabilitieUtils';
52
+ import {
53
+ PROTOCOL_V2_STATUS_DEVICE_INFO_REQUEST,
54
+ requestProtocolV2DeviceInfo,
55
+ } from '../protocols/protocol-v2/features';
56
+ import { buildProtocolV1FeaturesPayload, buildProtocolV2FeaturesPayload } from '../deviceProfile';
44
57
 
45
58
  import type { PROTO } from '../constants';
46
59
  import type {
@@ -49,8 +62,12 @@ import type {
49
62
  PassphraseRequestPayload,
50
63
  } from '../events';
51
64
  import type { PassphrasePromptResponse } from './DeviceCommands';
52
- import type { Deferred } from '@onekeyfe/hd-shared';
53
- import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
65
+ import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
66
+ import type {
67
+ OneKeyDeviceInfo as DeviceDescriptor,
68
+ ProtocolV2DeviceInfo,
69
+ Success,
70
+ } from '@onekeyfe/hd-transport';
54
71
  import type DeviceConnector from './DeviceConnector';
55
72
 
56
73
  export type InitOptions = {
@@ -58,6 +75,7 @@ export type InitOptions = {
58
75
  deviceId?: string;
59
76
  passphraseState?: string;
60
77
  deriveCardano?: boolean;
78
+ connectProtocol?: HardwareConnectProtocol;
61
79
  };
62
80
 
63
81
  export type RunOptions = {
@@ -167,12 +185,19 @@ export class Device extends EventEmitter {
167
185
  private deviceAcquired = false;
168
186
 
169
187
  /**
170
- * 设备信息
188
+ * 唯一设备状态缓存。
189
+ *
190
+ * V1 直接保存原生 Features;V2 保存由 DevGetDeviceInfo 映射出的
191
+ * Features 视图。Device 不再保存 profile,结构化 DeviceProfile 只作为
192
+ * getDeviceInfo() 的 API 返回值存在。
171
193
  */
172
194
  features: Features | undefined = undefined;
173
195
 
174
196
  /**
175
- * 是否需要更新设备信息
197
+ * 是否需要更新设备信息。
198
+ *
199
+ * 历史名称保留用于兼容现有调用语义;对 V2 表示 features 需要由
200
+ * DevGetDeviceInfo 刷新。
176
201
  */
177
202
  featuresNeedsReload = false;
178
203
 
@@ -228,32 +253,38 @@ export class Device extends EventEmitter {
228
253
 
229
254
  // simplified object to pass via postMessage
230
255
  toMessageObject(): DeviceTyped | null {
231
- if (this.isUnacquired() || !this.features) return null;
256
+ if (this.isUnacquired()) return null;
232
257
 
233
258
  const env = DataManager.getSettings('env');
234
- const deviceType = getDeviceType(this.features);
259
+ const deviceType = this.getCurrentDeviceType();
235
260
 
236
- const bleName = getDeviceBleName(this.features);
237
- const label = getDeviceLabel(this.features);
261
+ const bleName = this.getCurrentBleName();
262
+ const label = this.getCurrentLabel();
263
+ const serialNo = this.getCurrentSerialNo();
264
+ const connectId = this.getConnectId();
265
+ const deviceId = this.getCurrentDeviceId() || null;
266
+
267
+ const features = this.features;
238
268
 
239
269
  return {
240
270
  /** Android uses Mac address, iOS uses uuid, USB uses uuid */
241
- connectId: DataManager.isBleConnect(env) ? this.mainId || null : getDeviceUUID(this.features),
271
+ connectId: DataManager.isBleConnect(env) ? this.mainId || null : connectId,
242
272
  /** Hardware ID, will not change at any time */
243
- uuid: getDeviceUUID(this.features),
273
+ uuid: serialNo,
244
274
  commType: this.originalDescriptor.commType,
245
275
  sdkInstanceId: this.sdkInstanceId,
246
276
  instanceId: this.instanceId,
247
277
  createdAt: this.createdAt,
248
278
  deviceType,
249
279
  /** ID for current seeds, will clear after replace a new seed at device */
250
- deviceId: this.features.device_id || null,
280
+ deviceId,
251
281
  path: this.originalDescriptor?.path,
252
282
  bleName,
253
283
  name: bleName || label || `OneKey ${deviceType?.toUpperCase()}`,
254
284
  label: label || 'OneKey',
255
285
  mode: this.getMode(),
256
- features: this.features,
286
+ features,
287
+ sessionId: this.features?.sessionId ?? null,
257
288
  firmwareVersion: this.getFirmwareVersion(),
258
289
  bleFirmwareVersion: this.getBLEFirmwareVersion(),
259
290
  unavailableCapabilities: this.unavailableCapabilities,
@@ -264,13 +295,13 @@ export class Device extends EventEmitter {
264
295
  * Device connect
265
296
  * @returns {Promise<boolean>}
266
297
  */
267
- connect() {
298
+ connect(connectProtocol?: HardwareConnectProtocol) {
268
299
  const env = DataManager.getSettings('env');
269
300
  // eslint-disable-next-line no-async-promise-executor
270
301
  return new Promise<boolean>(async (resolve, reject) => {
271
302
  if (DataManager.isBleConnect(env)) {
272
303
  try {
273
- await this.acquire();
304
+ await this.acquire(connectProtocol);
274
305
  resolve(true);
275
306
  } catch (error) {
276
307
  reject(error);
@@ -280,7 +311,7 @@ export class Device extends EventEmitter {
280
311
  // 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
281
312
  if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
282
313
  try {
283
- await this.acquire();
314
+ await this.acquire(connectProtocol);
284
315
  resolve(true);
285
316
  } catch (error) {
286
317
  reject(error);
@@ -295,23 +326,49 @@ export class Device extends EventEmitter {
295
326
  });
296
327
  }
297
328
 
298
- async acquire() {
329
+ async acquire(connectProtocol?: HardwareConnectProtocol) {
299
330
  const env = DataManager.getSettings('env');
300
331
  const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
332
+ const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
301
333
  try {
334
+ let acquireResult: unknown;
302
335
  if (DataManager.isBleConnect(env)) {
303
- const res = await this.deviceConnector?.acquire(this.originalDescriptor.id);
304
- this.mainId = (res as unknown as any).uuid ?? '';
336
+ // forceCleanRunPromise=true(自 e21b83c6 引入,修复 Pro2 BLE 重连):
337
+ // acquire 意味着开启一个全新会话,transport 里残留的上一次 runPromise
338
+ // 必然属于已死亡的会话(如固件升级重启、探测中断),不清理会让新会话的
339
+ // 调用被旧 promise 卡死。无法在 Device 层面区分“重连恢复”与普通 acquire,
340
+ // 因此对 BLE acquire 恒清理是有意为之。
341
+ acquireResult = await this.deviceConnector?.acquire(
342
+ this.originalDescriptor.id,
343
+ undefined,
344
+ true,
345
+ expectedProtocol
346
+ );
347
+ this.mainId = (acquireResult as any)?.uuid ?? '';
305
348
  Log.debug('Expected uuid:', this.mainId);
306
349
  } else {
307
- this.mainId = await this.deviceConnector?.acquire(
350
+ acquireResult = await this.deviceConnector?.acquire(
308
351
  this.originalDescriptor.path,
309
- this.originalDescriptor.session
352
+ this.originalDescriptor.session,
353
+ undefined,
354
+ expectedProtocol
310
355
  );
356
+ this.mainId = acquireResult as string | undefined;
311
357
  Log.debug('Expected session id:', this.mainId);
312
358
  }
313
359
  this.deviceAcquired = true;
314
360
  this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
361
+
362
+ // Propagate protocol version detected during acquire.
363
+ const detectedProtocol =
364
+ (acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
365
+ TransportManager.transport?.getProtocolType?.(
366
+ DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
367
+ );
368
+ if (detectedProtocol) {
369
+ this.originalDescriptor.protocolType = detectedProtocol;
370
+ }
371
+
315
372
  if (this.commands) {
316
373
  await this.commands.dispose(false);
317
374
  }
@@ -368,12 +425,10 @@ export class Device extends EventEmitter {
368
425
  }
369
426
 
370
427
  /**
371
- * Pre-initialize: connect + Initialize ahead of the sign. Only runs the
372
- * fallback init when features are missing (gate on `!this.features`, not
373
- * isUsedHere which is always false on BLE); otherwise just records the mark.
428
+ * Pre-initialize: connect + Initialize ahead of the sign.
374
429
  */
375
430
  async preInitialize(initOptions?: InitOptions) {
376
- if (!this.features) {
431
+ if (this.isUnacquired()) {
377
432
  await this.acquire();
378
433
  await this.initialize(initOptions);
379
434
  }
@@ -419,6 +474,154 @@ export class Device extends EventEmitter {
419
474
  return this.commands;
420
475
  }
421
476
 
477
+ /**
478
+ * 唯一协议判别器。
479
+ *
480
+ * descriptor.protocolType 是协议探测后的结果;V2 features 由 DevGetDeviceInfo
481
+ * 映射产生。
482
+ * 全 SDK 的协议分支都必须走这里,不要直接读 originalDescriptor.protocolType
483
+ * 或从 features 反推。
484
+ */
485
+ getProtocol(): 'V1' | 'V2' {
486
+ return this.originalDescriptor.protocolType === 'V2' ? 'V2' : 'V1';
487
+ }
488
+
489
+ isProtocolV2() {
490
+ return this.getProtocol() === 'V2';
491
+ }
492
+
493
+ getCurrentDeviceType() {
494
+ return getDeviceType(this.features);
495
+ }
496
+
497
+ getCurrentDeviceId() {
498
+ return this.features?.deviceId || undefined;
499
+ }
500
+
501
+ getCurrentSerialNo() {
502
+ return this.features ? getDeviceUUID(this.features) : '';
503
+ }
504
+
505
+ getConnectId() {
506
+ const serialNo = this.getCurrentSerialNo();
507
+ if (serialNo) return serialNo;
508
+
509
+ // connectId 是 SDK 内部连接路由 key;Protocol V2 早期固件/mock
510
+ // 可能还没有 serial_no,此时用 transport descriptor 兜底,不改变
511
+ // features.serialNo / deviceId 的业务语义。
512
+ return this.originalDescriptor.path || this.originalDescriptor.id || '';
513
+ }
514
+
515
+ getCurrentBleName() {
516
+ return getDeviceBleName(this.features);
517
+ }
518
+
519
+ getCurrentLabel() {
520
+ return getDeviceLabel(this.features);
521
+ }
522
+
523
+ getCurrentPassphraseProtection() {
524
+ return this.features?.passphraseProtection;
525
+ }
526
+
527
+ getCurrentFirmwareType() {
528
+ return getFirmwareType(this.features);
529
+ }
530
+
531
+ getCurrentFirmwareVersionString() {
532
+ return getDeviceFirmwareVersion(this.features)?.join('.');
533
+ }
534
+
535
+ getCurrentBLEFirmwareVersionString() {
536
+ if (!this.features) return undefined;
537
+ return getDeviceBLEFirmwareVersion(this.features).join('.');
538
+ }
539
+
540
+ getCurrentSafetyChecks() {
541
+ return this.features?.safetyChecks;
542
+ }
543
+
544
+ getCurrentMethodVersionRange(
545
+ getVersionRange: (deviceModel: IDeviceType | IDeviceModel) => IVersionRange | undefined
546
+ ) {
547
+ const deviceType = this.getCurrentDeviceType();
548
+ const versionRange = getVersionRange(deviceType);
549
+ if (versionRange) return versionRange;
550
+
551
+ // Most-specific model first; must match getMethodVersionRange in deviceInfoUtils,
552
+ // otherwise e.g. Classic1s resolves the looser model_mini range before model_classic1s.
553
+ const modelFallbacks: IDeviceModel[] = [
554
+ 'model_classic1s',
555
+ 'model_classic',
556
+ 'model_mini',
557
+ 'model_touch',
558
+ ];
559
+ for (const model of modelFallbacks) {
560
+ if (DeviceTypeToModels[deviceType]?.includes(model)) {
561
+ const fallbackRange = getVersionRange(model);
562
+ if (fallbackRange) return fallbackRange;
563
+ }
564
+ }
565
+ return undefined;
566
+ }
567
+
568
+ supportNewPassphrase(): SupportFeatureType {
569
+ const deviceType = this.getCurrentDeviceType();
570
+ if (
571
+ deviceType === EDeviceType.Touch ||
572
+ deviceType === EDeviceType.Pro ||
573
+ deviceType === EDeviceType.Pro2
574
+ ) {
575
+ return { support: true };
576
+ }
577
+
578
+ const firmwareVersion = this.getCurrentFirmwareVersionString();
579
+ return {
580
+ support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.4.0')),
581
+ require: '2.4.0',
582
+ };
583
+ }
584
+
585
+ supportInputPinOnSoftware(): SupportFeatureType {
586
+ if (this.features) return supportInputPinOnSoftware(this.features);
587
+
588
+ const deviceType = this.getCurrentDeviceType();
589
+ if (
590
+ deviceType === EDeviceType.Touch ||
591
+ deviceType === EDeviceType.Pro ||
592
+ deviceType === EDeviceType.Pro2
593
+ ) {
594
+ return { support: false };
595
+ }
596
+
597
+ const firmwareVersion = this.getCurrentFirmwareVersionString();
598
+ return {
599
+ support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '2.3.0')),
600
+ require: '2.3.0',
601
+ };
602
+ }
603
+
604
+ supportModifyHomescreen(): SupportFeatureType {
605
+ // Pro2 走独立 1.x 版本线,不能套用 Touch/Pro 的 3.4.0 门槛(恒 false 且未来会误判)。
606
+ // 依据:firmware-pro2 协议 schema(messages-protocol-v2.json)的 ApplySettings
607
+ // 包含 homescreen 字段,V2 固件从首个版本即支持修改主屏。
608
+ if (this.isProtocolV2()) {
609
+ return { support: true };
610
+ }
611
+
612
+ if (this.features) return supportModifyHomescreen(this.features);
613
+
614
+ const deviceType = this.getCurrentDeviceType();
615
+ if (DeviceModelToTypes.model_mini.includes(deviceType)) {
616
+ return { support: true };
617
+ }
618
+
619
+ const firmwareVersion = this.getCurrentFirmwareVersionString();
620
+ return {
621
+ support: Boolean(firmwareVersion && semver.gte(firmwareVersion, '3.4.0')),
622
+ };
623
+ }
624
+
422
625
  private generateStateKey(deviceId: string, passphraseState?: string) {
423
626
  if (passphraseState) {
424
627
  return `${deviceId}@${passphraseState}`;
@@ -426,16 +629,25 @@ export class Device extends EventEmitter {
426
629
  return deviceId;
427
630
  }
428
631
 
632
+ private getSessionCacheDeviceKey(_deviceId?: string) {
633
+ const deviceId = _deviceId || this.getCurrentDeviceId();
634
+ if (deviceId) return deviceId;
635
+ if (this.isProtocolV2()) {
636
+ return this.originalDescriptor.path || this.originalDescriptor.id;
637
+ }
638
+ return undefined;
639
+ }
640
+
429
641
  getInternalState(_deviceId?: string) {
430
642
  Log.debug('getInternalState session cache: ', deviceSessionCache);
431
643
  Log.debug(
432
644
  'getInternalState session param: ',
433
645
  `device_id: ${_deviceId}`,
434
- `features.device_id: ${this.features?.device_id}`,
646
+ `features.deviceId: ${this.features?.deviceId}`,
435
647
  `passphraseState: ${this.passphraseState}`
436
648
  );
437
649
 
438
- const deviceId = _deviceId || this.features?.device_id;
650
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
439
651
  if (!deviceId) return undefined;
440
652
  // Security invariant: no passphraseState → no session lookup.
441
653
  // A previous fallback that scanned `${deviceId}@*` keys could silently
@@ -453,7 +665,7 @@ export class Device extends EventEmitter {
453
665
  updateInternalState(
454
666
  enablePassphrase: boolean,
455
667
  passphraseState: string | undefined,
456
- deviceId: string,
668
+ deviceId: string | undefined,
457
669
  sessionId: string | null = null,
458
670
  featuresSessionId: string | null = null
459
671
  ) {
@@ -466,17 +678,21 @@ export class Device extends EventEmitter {
466
678
  `featuresSessionId: ${featuresSessionId}`
467
679
  );
468
680
 
681
+ const cacheDeviceKey = this.getSessionCacheDeviceKey(deviceId);
682
+ if (!cacheDeviceKey) return;
683
+
469
684
  if (enablePassphrase) {
470
685
  // update the sessionId
471
686
  if (sessionId) {
472
- deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = sessionId;
687
+ deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] = sessionId;
473
688
  } else if (featuresSessionId) {
474
- deviceSessionCache[this.generateStateKey(deviceId, passphraseState)] = featuresSessionId;
689
+ deviceSessionCache[this.generateStateKey(cacheDeviceKey, passphraseState)] =
690
+ featuresSessionId;
475
691
  }
476
692
  }
477
693
 
478
694
  // delete the old sessionId
479
- const oldKey = `${deviceId}`;
695
+ const oldKey = `${cacheDeviceKey}`;
480
696
  if (deviceSessionCache[oldKey]) {
481
697
  delete deviceSessionCache[oldKey];
482
698
  }
@@ -489,14 +705,13 @@ export class Device extends EventEmitter {
489
705
  'setInternalState session param: ',
490
706
  `state: ${state}`,
491
707
  `initSession: ${initSession}`,
492
- `device_id: ${this.features?.device_id}`,
708
+ `deviceId: ${this.features?.deviceId}`,
493
709
  `passphraseState: ${this.passphraseState}`
494
710
  );
495
711
 
496
- if (!this.features) return;
497
712
  if (!this.passphraseState && !initSession) return;
498
713
 
499
- const deviceId = this.features?.device_id;
714
+ const deviceId = this.getSessionCacheDeviceKey();
500
715
  if (!deviceId) return;
501
716
 
502
717
  const key = this.generateStateKey(deviceId, this.passphraseState);
@@ -510,7 +725,7 @@ export class Device extends EventEmitter {
510
725
  clearInternalState(_deviceId?: string) {
511
726
  Log.debug('clearInternalState param: ', _deviceId);
512
727
 
513
- const deviceId = _deviceId || this.features?.device_id;
728
+ const deviceId = this.getSessionCacheDeviceKey(_deviceId);
514
729
  if (!deviceId) return;
515
730
  const key = `${deviceId}`;
516
731
  delete deviceSessionCache[key];
@@ -522,6 +737,20 @@ export class Device extends EventEmitter {
522
737
  }
523
738
 
524
739
  async initialize(options?: InitOptions) {
740
+ // Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
741
+ if (this.isProtocolV2()) {
742
+ 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();
748
+ return;
749
+ }
750
+ await this._initializeProtocolV2();
751
+ return;
752
+ }
753
+
525
754
  // Log.debug('initialize param:', options);
526
755
 
527
756
  this.passphraseState = options?.passphraseState;
@@ -565,18 +794,79 @@ export class Device extends EventEmitter {
565
794
  }
566
795
  }
567
796
 
797
+ /**
798
+ * Device initialization over Protocol V2.
799
+ *
800
+ * Protocol V2 不走传统 Initialize/GetFeatures;直接用 DevGetDeviceInfo
801
+ * 生成唯一的 features 状态。
802
+ */
803
+ private async _initializeProtocolV2() {
804
+ Log.debug('Initialize device via Protocol V2 features adapter');
805
+
806
+ try {
807
+ // 超时由 requestProtocolV2DeviceInfo 内部的 typedCall timeoutMs(默认 10s)负责,
808
+ // 不再额外包一层 Promise.race:外层 race 的 timer 不会清理,
809
+ // 且 reject 后底层调用仍会残留。
810
+ const deviceInfo = await requestProtocolV2DeviceInfo({
811
+ commands: this.commands,
812
+ });
813
+ // 默认请求不含 SE/hash 数据,scope 如实标注为 basic;
814
+ // 完整数据由 getDeviceInfo(scope:'verify'|'full') 获取。
815
+ const features = this.updateProtocolV2Features(deviceInfo);
816
+ Log.debug('Protocol V2 features:', features);
817
+ this.featuresNeedsReload = false;
818
+ } catch (error) {
819
+ Log.error('Protocol V2 initialization failed:', error);
820
+ throw error;
821
+ }
822
+ }
823
+
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
+
568
845
  async getFeatures() {
846
+ if (this.isProtocolV2()) {
847
+ const deviceInfo = await requestProtocolV2DeviceInfo({
848
+ commands: this.commands,
849
+ });
850
+ return this.updateProtocolV2Features(deviceInfo);
851
+ }
852
+
569
853
  const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
570
854
  this._updateFeatures(message);
855
+ return this.features;
571
856
  }
572
857
 
573
- _updateFeatures(feat: Features, initSession?: boolean) {
858
+ _updateFeatures(protoFeatures: PROTO.Features | Features, initSession?: boolean) {
859
+ let feat =
860
+ 'protocol' in protoFeatures
861
+ ? protoFeatures
862
+ : buildProtocolV1FeaturesPayload(protoFeatures, this.features);
863
+
574
864
  // GetFeatures doesn't return 'session_id'
575
- if (this.features && this.features.session_id && !feat.session_id) {
576
- feat.session_id = this.features.session_id;
865
+ if (this.features?.sessionId && !feat.sessionId) {
866
+ feat.sessionId = this.features.sessionId;
577
867
  }
578
- if (this.features && this.features.device_id && feat.session_id) {
579
- this.setInternalState(feat.session_id, initSession);
868
+ if (this.getCurrentDeviceId() && feat.sessionId) {
869
+ this.setInternalState(feat.sessionId, initSession);
580
870
  }
581
871
  feat.unlocked = feat.unlocked ?? true;
582
872
 
@@ -587,6 +877,16 @@ export class Device extends EventEmitter {
587
877
  this.emit(DEVICE.FEATURES, this, feat);
588
878
  }
589
879
 
880
+ updateProtocolV2Features(deviceInfo?: ProtocolV2DeviceInfo) {
881
+ const features = fixFeaturesFirmwareVersion(
882
+ buildProtocolV2FeaturesPayload(deviceInfo, this.features)
883
+ );
884
+ this.features = features;
885
+ this.featuresNeedsReload = false;
886
+ this.emit(DEVICE.FEATURES, this, features);
887
+ return features;
888
+ }
889
+
590
890
  /**
591
891
  * 暂时只在 acquire 后更新 Session ID
592
892
  * 后续看是否有需要依据 listen 返回结果更新
@@ -605,7 +905,12 @@ export class Device extends EventEmitter {
605
905
  }
606
906
 
607
907
  if (forceUpdate) {
608
- this.originalDescriptor = descriptor;
908
+ // 枚举得到的 descriptor 可能不带 protocolType(如 WebUSB enumerate),
909
+ // 不能让覆盖丢掉已探测的协议结果。
910
+ this.originalDescriptor = {
911
+ ...descriptor,
912
+ protocolType: descriptor.protocolType ?? this.originalDescriptor.protocolType,
913
+ };
609
914
  }
610
915
  }
611
916
 
@@ -635,7 +940,7 @@ export class Device extends EventEmitter {
635
940
  const env = DataManager.getSettings('env');
636
941
  if (env !== 'react-native') {
637
942
  try {
638
- await this.acquire();
943
+ await this.acquire(options.connectProtocol);
639
944
  } catch (error) {
640
945
  this.runPromise = null;
641
946
  return Promise.reject(error);
@@ -748,7 +1053,7 @@ export class Device extends EventEmitter {
748
1053
  }
749
1054
 
750
1055
  getMode() {
751
- if (this.features?.bootloader_mode) {
1056
+ if (this.features?.bootloaderMode) {
752
1057
  // bootloader mode
753
1058
  return EOneKeyDeviceMode.bootloader;
754
1059
  }
@@ -758,7 +1063,7 @@ export class Device extends EventEmitter {
758
1063
  return EOneKeyDeviceMode.notInitialized;
759
1064
  }
760
1065
 
761
- if (this.features?.no_backup) {
1066
+ if (this.features?.noBackup) {
762
1067
  // backup mode
763
1068
  return EOneKeyDeviceMode.backupMode;
764
1069
  }
@@ -802,7 +1107,7 @@ export class Device extends EventEmitter {
802
1107
  }
803
1108
 
804
1109
  isBootloader() {
805
- return this.features && !!this.features.bootloader_mode;
1110
+ return this.features && !!this.features.bootloaderMode;
806
1111
  }
807
1112
 
808
1113
  isInitialized() {
@@ -810,7 +1115,7 @@ export class Device extends EventEmitter {
810
1115
  }
811
1116
 
812
1117
  isSeedless() {
813
- return this.features && !!this.features.no_backup;
1118
+ return this.features && !!this.features.noBackup;
814
1119
  }
815
1120
 
816
1121
  isUnacquired(): boolean {
@@ -819,7 +1124,7 @@ export class Device extends EventEmitter {
819
1124
 
820
1125
  hasUnexpectedMode(allow: string[], require: string[]) {
821
1126
  // both allow and require cases might generate single unexpected mode
822
- if (this.features) {
1127
+ if (!this.isUnacquired()) {
823
1128
  // allow cases
824
1129
  if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
825
1130
  return UI_REQUEST.BOOTLOADER;
@@ -840,27 +1145,30 @@ export class Device extends EventEmitter {
840
1145
  }
841
1146
 
842
1147
  hasUsePassphrase() {
1148
+ const deviceType = this.getCurrentDeviceType();
843
1149
  const isModeT =
844
- getDeviceType(this.features) === EDeviceType.Touch ||
845
- getDeviceType(this.features) === EDeviceType.Pro;
846
- const preCheckTouch = isModeT && this.features?.unlocked === false;
847
-
848
- return this.features && (!!this.features.passphrase_protection || preCheckTouch);
1150
+ deviceType === EDeviceType.Touch ||
1151
+ deviceType === EDeviceType.Pro ||
1152
+ deviceType === EDeviceType.Pro2;
1153
+ const unlocked = this.features?.unlocked;
1154
+ const preCheckTouch = isModeT && unlocked === false;
1155
+ const passphraseProtection = this.getCurrentPassphraseProtection();
1156
+
1157
+ return Boolean(passphraseProtection === true || preCheckTouch);
849
1158
  }
850
1159
 
851
1160
  checkDeviceId(deviceId: string) {
852
- if (this.features) {
853
- return this.features.device_id === deviceId;
854
- }
855
- return false;
1161
+ return this.getCurrentDeviceId() === deviceId;
856
1162
  }
857
1163
 
858
- async lockDevice() {
1164
+ async lockDevice(): Promise<Success> {
859
1165
  const res = await this.commands.typedCall('LockDevice', 'Success', {});
860
1166
  return res.message;
861
1167
  }
862
1168
 
863
1169
  supportUnlockVersionRange(): DeviceFirmwareRange {
1170
+ // 仅适用于 Protocol V1 的 Pro 系列;Pro2 走独立版本线,
1171
+ // 且 Protocol V2 固件从首个版本即支持 UnLockDevice(见 unlockDevice 的 isProtocolV2 短路)。
864
1172
  return {
865
1173
  pro: {
866
1174
  min: '4.15.0',
@@ -869,9 +1177,8 @@ export class Device extends EventEmitter {
869
1177
  }
870
1178
 
871
1179
  async unlockDevice() {
872
- const firmwareVersion = getDeviceFirmwareVersion(this.features)?.join('.');
873
- const versionRange = getMethodVersionRange(
874
- this.features,
1180
+ const firmwareVersion = this.getCurrentFirmwareVersionString() ?? '0.0.0';
1181
+ const versionRange = this.getCurrentMethodVersionRange(
875
1182
  type => this.supportUnlockVersionRange()[type]
876
1183
  );
877
1184
 
@@ -879,25 +1186,36 @@ export class Device extends EventEmitter {
879
1186
  this.features,
880
1187
  Enum_Capability.Capability_AttachToPin
881
1188
  );
882
-
1189
+ // Pro2 (Protocol V2) 版本线独立于 Pro 系列,固件从首个版本即支持 UnLockDevice
883
1190
  const supportUnlock =
884
- supportAttachPinCapability || (versionRange && semver.gte(firmwareVersion, versionRange.min));
1191
+ this.isProtocolV2() ||
1192
+ supportAttachPinCapability ||
1193
+ (versionRange &&
1194
+ semver.valid(firmwareVersion) &&
1195
+ semver.gte(firmwareVersion, versionRange.min));
885
1196
 
886
1197
  if (supportUnlock) {
887
1198
  const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
888
1199
  if (this.features) {
889
1200
  this.features.unlocked = res.message.unlocked == null ? null : res.message.unlocked;
890
- this.features.unlocked_attach_pin =
1201
+ this.features.unlockedAttachPin =
891
1202
  res.message.unlocked_attach_pin == null ? undefined : res.message.unlocked_attach_pin;
892
- this.features.passphrase_protection =
1203
+ this.features.passphraseProtection =
893
1204
  res.message.passphrase_protection == null ? null : res.message.passphrase_protection;
894
1205
 
895
1206
  return Promise.resolve(this.features);
896
1207
  }
897
1208
 
898
- const featuresRes = await this.commands.typedCall('GetFeatures', 'Features');
899
- this._updateFeatures(featuresRes.message);
900
- return Promise.resolve(featuresRes.message);
1209
+ const features = await this.getFeatures();
1210
+ return Promise.resolve(features);
1211
+ }
1212
+
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
+ );
901
1219
  }
902
1220
 
903
1221
  const { type } = await this.commands.typedCall('GetAddress', 'Address', {
@@ -911,9 +1229,8 @@ export class Device extends EventEmitter {
911
1229
  if (type === 'CallMethodError') {
912
1230
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'unlock device error');
913
1231
  }
914
- const res = await this.commands.typedCall('GetFeatures', 'Features');
915
- this._updateFeatures(res.message);
916
- return Promise.resolve(res.message);
1232
+ const features = await this.getFeatures();
1233
+ return Promise.resolve(features);
917
1234
  }
918
1235
 
919
1236
  async checkPassphraseStateSafety(
@@ -921,7 +1238,7 @@ export class Device extends EventEmitter {
921
1238
  useEmptyPassphrase?: boolean,
922
1239
  skipPassphraseCheck?: boolean
923
1240
  ) {
924
- if (!this.features) return false;
1241
+ if (this.isUnacquired()) return false;
925
1242
 
926
1243
  const { passphraseState: newPassphraseState, unlockedAttachPin } =
927
1244
  await getPassphraseStateWithRefreshDeviceInfo(this, {
@@ -929,14 +1246,11 @@ export class Device extends EventEmitter {
929
1246
  onlyMainPin: useEmptyPassphrase,
930
1247
  });
931
1248
 
932
- if (skipPassphraseCheck) {
933
- return true;
934
- }
935
-
936
1249
  // Main wallet and unlock Attach Pin, throw safe error
937
1250
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
938
1251
  const useErrorAttachPin =
939
1252
  unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
1253
+ const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
940
1254
 
941
1255
  Log.debug('Check passphrase state safety: ', {
942
1256
  passphraseState,
@@ -945,6 +1259,14 @@ export class Device extends EventEmitter {
945
1259
  useEmptyPassphrase,
946
1260
  });
947
1261
 
1262
+ if (skipPassphraseCheck) {
1263
+ if (passphraseStateMismatch) {
1264
+ this.clearInternalState();
1265
+ return false;
1266
+ }
1267
+ return true;
1268
+ }
1269
+
948
1270
  if (mainWalletUseAttachPin || useErrorAttachPin) {
949
1271
  try {
950
1272
  await this.lockDevice();
@@ -956,7 +1278,7 @@ export class Device extends EventEmitter {
956
1278
  }
957
1279
 
958
1280
  // When exists passphraseState, check passphraseState
959
- if (passphraseState && passphraseState !== newPassphraseState) {
1281
+ if (passphraseStateMismatch) {
960
1282
  this.clearInternalState();
961
1283
  return false;
962
1284
  }